diff --git a/src/pci.cpp b/src/pci.cpp index 5b01dd34..1adad313 100644 --- a/src/pci.cpp +++ b/src/pci.cpp @@ -481,98 +481,6 @@ int PciHandle::openMcfgTable() { return handle; } -#ifndef PCM_USE_PCI_MM_LINUX - -PciHandleM::PciHandleM(uint32 bus_, uint32 device_, uint32 function_) : - fd(-1), - bus(bus_), - device(device_), - function(function_), - base_addr(0) -{ - int handle = ::open("/dev/mem", O_RDWR); - if (handle < 0) throw std::exception(); - fd = handle; - - int mcfg_handle = PciHandle::openMcfgTable(); - if (mcfg_handle < 0) throw std::runtime_error("Cannot open any of /[pcm]/sys/firmware/acpi/tables/MCFG* files!"); - - int32 result = ::pread(mcfg_handle, (void *)&base_addr, sizeof(uint64), 44); - - if (result != sizeof(uint64)) - { - ::close(mcfg_handle); - throw std::exception(); - } - - unsigned char max_bus = 0; - - result = ::pread(mcfg_handle, (void *)&max_bus, sizeof(unsigned char), 55); - - ::close(mcfg_handle); - if (result != sizeof(unsigned char)) - { - throw std::exception(); - } - - if (bus > (unsigned)max_bus) - { - std::cout << "WARNING: Requested bus number " << bus << " is larger than the max bus number " << (unsigned)max_bus << "\n"; - throw std::exception(); - } - - // std::cout << "PCI config base addr: "<< std::hex << base_addr<< "\n" << std::dec; - - base_addr += (bus * 1024ULL * 1024ULL + device * 32ULL * 1024ULL + function * 4ULL * 1024ULL); -} - - -bool PciHandleM::exists(uint32 /*groupnr_*/, uint32 /* bus_*/, uint32 /* device_ */, uint32 /* function_ */) -{ - int handle = ::open("/dev/mem", O_RDWR); - - if (handle < 0) { - perror("error opening /dev/mem"); - return false; - } - - ::close(handle); - - handle = PciHandle::openMcfgTable(); - if (handle < 0) { - return false; - } - - ::close(handle); - - return true; -} - -int32 PciHandleM::read32(uint64 offset, uint32 * value) -{ - warnAlignment<4>("PciHandleM::read32", false, offset); - return ::pread(fd, (void *)value, sizeof(uint32), offset + base_addr); -} - -int32 PciHandleM::write32(uint64 offset, uint32 value) -{ - warnAlignment<4>("PciHandleM::write32", false, offset); - return ::pwrite(fd, (const void *)&value, sizeof(uint32), offset + base_addr); -} - -int32 PciHandleM::read64(uint64 offset, uint64 * value) -{ - warnAlignment<4>("PciHandleM::read64", false, offset); - return ::pread(fd, (void *)value, sizeof(uint64), offset + base_addr); -} - -PciHandleM::~PciHandleM() -{ - if (fd >= 0) ::close(fd); -} - -#endif // PCM_USE_PCI_MM_LINUX - // mmapped I/O version MCFGHeader PciHandleMM::mcfgHeader; diff --git a/src/pci.h b/src/pci.h index b639b8a8..e771534c 100644 --- a/src/pci.h +++ b/src/pci.h @@ -49,7 +49,6 @@ class PciHandle DWORD pciAddress; #endif - friend class PciHandleM; friend class PciHandleMM; PciHandle(); // forbidden @@ -79,40 +78,7 @@ typedef PciHandle PciHandleType; typedef PciHandle PciHandleType; #elif defined(__FreeBSD__) || defined(__DragonFly__) typedef PciHandle PciHandleType; -#else - -// read/write PCI config space using physical memory -class PciHandleM -{ -#ifdef _MSC_VER - -#else - int32 fd; -#endif - - uint32 bus; - uint32 device; - uint32 function; - uint64 base_addr; - - PciHandleM() = delete; // forbidden - PciHandleM(PciHandleM &) = delete; // forbidden - PciHandleM & operator = (PciHandleM &) = delete; // forbidden - -public: - PciHandleM(uint32 bus_, uint32 device_, uint32 function_); - - static bool exists(uint32 groupnr_, uint32 bus_, uint32 device_, uint32 function_); - - int32 read32(uint64 offset, uint32 * value); - int32 write32(uint64 offset, uint32 value); - - int32 read64(uint64 offset, uint64 * value); - - virtual ~PciHandleM(); -}; - -#ifndef _MSC_VER +#elif defined(__linux__) // read/write PCI config space using physical memory using mmapped file I/O class PciHandleMM @@ -125,11 +91,9 @@ class PciHandleMM uint32 function; uint64 base_addr; -#ifdef __linux__ static MCFGHeader mcfgHeader; static std::vector mcfgRecords; static void readMCFG(); -#endif PciHandleMM() = delete; // forbidden PciHandleMM(const PciHandleMM &) = delete; // forbidden @@ -147,9 +111,7 @@ class PciHandleMM virtual ~PciHandleMM(); -#ifdef __linux__ static const std::vector & getMCFGRecords(); -#endif }; #ifdef PCM_USE_PCI_MM_LINUX @@ -158,8 +120,8 @@ class PciHandleMM #define PciHandleType PciHandle #endif -#endif // _MSC_VER - +#else +#error "Platform not supported" #endif template