Skip to content

Commit 8d47369

Browse files
ogbruggerdementi
authored andcommitted
Remove PciHandleM since it is no longer used
Redo the platform logic in the preprocessor statements Create a not supported branch Remove the now superfluous _MSC_VER and __linux__ checks from Linux
1 parent 1b9e3b7 commit 8d47369

File tree

2 files changed

+3
-133
lines changed

2 files changed

+3
-133
lines changed

src/pci.cpp

-92
Original file line numberDiff line numberDiff line change
@@ -481,98 +481,6 @@ int PciHandle::openMcfgTable() {
481481
return handle;
482482
}
483483

484-
#ifndef PCM_USE_PCI_MM_LINUX
485-
486-
PciHandleM::PciHandleM(uint32 bus_, uint32 device_, uint32 function_) :
487-
fd(-1),
488-
bus(bus_),
489-
device(device_),
490-
function(function_),
491-
base_addr(0)
492-
{
493-
int handle = ::open("/dev/mem", O_RDWR);
494-
if (handle < 0) throw std::exception();
495-
fd = handle;
496-
497-
int mcfg_handle = PciHandle::openMcfgTable();
498-
if (mcfg_handle < 0) throw std::runtime_error("Cannot open any of /[pcm]/sys/firmware/acpi/tables/MCFG* files!");
499-
500-
int32 result = ::pread(mcfg_handle, (void *)&base_addr, sizeof(uint64), 44);
501-
502-
if (result != sizeof(uint64))
503-
{
504-
::close(mcfg_handle);
505-
throw std::exception();
506-
}
507-
508-
unsigned char max_bus = 0;
509-
510-
result = ::pread(mcfg_handle, (void *)&max_bus, sizeof(unsigned char), 55);
511-
512-
::close(mcfg_handle);
513-
if (result != sizeof(unsigned char))
514-
{
515-
throw std::exception();
516-
}
517-
518-
if (bus > (unsigned)max_bus)
519-
{
520-
std::cout << "WARNING: Requested bus number " << bus << " is larger than the max bus number " << (unsigned)max_bus << "\n";
521-
throw std::exception();
522-
}
523-
524-
// std::cout << "PCI config base addr: "<< std::hex << base_addr<< "\n" << std::dec;
525-
526-
base_addr += (bus * 1024ULL * 1024ULL + device * 32ULL * 1024ULL + function * 4ULL * 1024ULL);
527-
}
528-
529-
530-
bool PciHandleM::exists(uint32 /*groupnr_*/, uint32 /* bus_*/, uint32 /* device_ */, uint32 /* function_ */)
531-
{
532-
int handle = ::open("/dev/mem", O_RDWR);
533-
534-
if (handle < 0) {
535-
perror("error opening /dev/mem");
536-
return false;
537-
}
538-
539-
::close(handle);
540-
541-
handle = PciHandle::openMcfgTable();
542-
if (handle < 0) {
543-
return false;
544-
}
545-
546-
::close(handle);
547-
548-
return true;
549-
}
550-
551-
int32 PciHandleM::read32(uint64 offset, uint32 * value)
552-
{
553-
warnAlignment<4>("PciHandleM::read32", false, offset);
554-
return ::pread(fd, (void *)value, sizeof(uint32), offset + base_addr);
555-
}
556-
557-
int32 PciHandleM::write32(uint64 offset, uint32 value)
558-
{
559-
warnAlignment<4>("PciHandleM::write32", false, offset);
560-
return ::pwrite(fd, (const void *)&value, sizeof(uint32), offset + base_addr);
561-
}
562-
563-
int32 PciHandleM::read64(uint64 offset, uint64 * value)
564-
{
565-
warnAlignment<4>("PciHandleM::read64", false, offset);
566-
return ::pread(fd, (void *)value, sizeof(uint64), offset + base_addr);
567-
}
568-
569-
PciHandleM::~PciHandleM()
570-
{
571-
if (fd >= 0) ::close(fd);
572-
}
573-
574-
#endif // PCM_USE_PCI_MM_LINUX
575-
576484
// mmapped I/O version
577485

578486
MCFGHeader PciHandleMM::mcfgHeader;

src/pci.h

+3-41
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class PciHandle
4949
DWORD pciAddress;
5050
#endif
5151

52-
friend class PciHandleM;
5352
friend class PciHandleMM;
5453

5554
PciHandle(); // forbidden
@@ -79,40 +78,7 @@ typedef PciHandle PciHandleType;
7978
typedef PciHandle PciHandleType;
8079
#elif defined(__FreeBSD__) || defined(__DragonFly__)
8180
typedef PciHandle PciHandleType;
82-
#else
83-
84-
// read/write PCI config space using physical memory
85-
class PciHandleM
86-
{
87-
#ifdef _MSC_VER
88-
89-
#else
90-
int32 fd;
91-
#endif
92-
93-
uint32 bus;
94-
uint32 device;
95-
uint32 function;
96-
uint64 base_addr;
97-
98-
PciHandleM() = delete; // forbidden
99-
PciHandleM(PciHandleM &) = delete; // forbidden
100-
PciHandleM & operator = (PciHandleM &) = delete; // forbidden
101-
102-
public:
103-
PciHandleM(uint32 bus_, uint32 device_, uint32 function_);
104-
105-
static bool exists(uint32 groupnr_, uint32 bus_, uint32 device_, uint32 function_);
106-
107-
int32 read32(uint64 offset, uint32 * value);
108-
int32 write32(uint64 offset, uint32 value);
109-
110-
int32 read64(uint64 offset, uint64 * value);
111-
112-
virtual ~PciHandleM();
113-
};
114-
115-
#ifndef _MSC_VER
81+
#elif defined(__linux__)
11682

11783
// read/write PCI config space using physical memory using mmapped file I/O
11884
class PciHandleMM
@@ -125,11 +91,9 @@ class PciHandleMM
12591
uint32 function;
12692
uint64 base_addr;
12793

128-
#ifdef __linux__
12994
static MCFGHeader mcfgHeader;
13095
static std::vector<MCFGRecord> mcfgRecords;
13196
static void readMCFG();
132-
#endif
13397

13498
PciHandleMM() = delete; // forbidden
13599
PciHandleMM(const PciHandleMM &) = delete; // forbidden
@@ -147,9 +111,7 @@ class PciHandleMM
147111

148112
virtual ~PciHandleMM();
149113

150-
#ifdef __linux__
151114
static const std::vector<MCFGRecord> & getMCFGRecords();
152-
#endif
153115
};
154116

155117
#ifdef PCM_USE_PCI_MM_LINUX
@@ -158,8 +120,8 @@ class PciHandleMM
158120
#define PciHandleType PciHandle
159121
#endif
160122

161-
#endif // _MSC_VER
162-
123+
#else
124+
#error "Platform not supported"
163125
#endif
164126

165127
template <class F>

0 commit comments

Comments
 (0)