Generic hardware access library
|
00001 #include "hal/PCIHardwareAddress.hh" 00002 #include <iomanip> 00003 #include <sstream> 00004 00005 HAL::PCIHardwareAddress::PCIHardwareAddress( uint32_t address, 00006 enum AddressSpace pciSpace, 00007 uint32_t barId ) 00008 throw (HAL::IllegalValueException) 00009 : HAL::GeneralHardwareAddress( address, 4 ) { 00010 00011 if ( pciSpace == (AddressSpace)MEMORY && barId > 5 ) { 00012 std::stringstream text; 00013 text << "barId of " << barId 00014 << " is illegal\n (HAL::PCIHardwareAddress::PCIHardwareAddress)" 00015 << std::ends; 00016 throw( HAL::IllegalValueException( text.str(), __FILE__, __LINE__, __FUNCTION__ ) ); 00017 } 00018 mapId_ = barId; 00019 addressSpace_ = pciSpace; 00020 addressModifier_ = 0; // not used in PCI 00021 } 00022 00023 uint32_t HAL::PCIHardwareAddress::getAddressModifier() const 00024 throw( HAL::IllegalOperationException ) { 00025 std::string text = "There are no AddressModifiers in PCI\n (HAL::PCIHardwareAddress::getAddressModifier)"; 00026 throw( HAL::IllegalOperationException( text, __FILE__, __LINE__, __FUNCTION__ ) ); 00027 } 00028 00029 00030 bool HAL::PCIHardwareAddress::isIOSpace() const throw() { 00031 return ( addressSpace_ == (AddressSpace)IO ) ; 00032 } 00033 00034 std::string HAL::PCIHardwareAddress::getAddressSpaceString() const { 00035 std::string resultString = "UNDEFINED"; 00036 if (addressSpace_ == (AddressSpace)MEMORY) { 00037 resultString = "memory"; 00038 } else if (addressSpace_ == (AddressSpace)CONFIGURATION) { 00039 resultString = "configuration"; 00040 } else if (addressSpace_ == (AddressSpace)IO) { 00041 resultString = "I/O"; 00042 } 00043 return resultString; 00044 } 00045 00046 void HAL::PCIHardwareAddress::print( std::ostream& os ) const { 00047 std::string pciSpaceString = getAddressSpaceString(); 00048 os << std::setw(13) << pciSpaceString.c_str() << " "; 00049 if ( addressSpace_ == (AddressSpace)MEMORY) { 00050 os << std::setw(1) << std::hex << mapId_ << " "; 00051 } else { 00052 os << " "; 00053 } 00054 os << std::setfill('0') << std::setw(8) << std::hex << address_ << " "; 00055 } 00056 00057 HAL::GeneralHardwareAddress* HAL::PCIHardwareAddress::clone() const { 00058 return new PCIHardwareAddress( *this ); 00059 }