Mac OS X, C Facilities for reading PCI device information
문제
I'm trying to learn how to get information from PCI devices in Mac OS X. So far I haven't been able to find anything about it in sysctl(3) and it seems the old devinfo(3) facilities from BSD are not available.
I need a C facility for this, I know there is an I/O kit framework for Objective C but I cannot use this.
The specific information I'm after is pretty basic, just vendor and device ID's.
해결책
I/O Kit is the system framework for device information. It is not an Objective-C API; instead, Apple use a restricted subset of C++. Quoting the I/O Kit Fundamentals document,
Apple considered several programming languages for the I/O Kit and chose a restricted subset of C++.
C++ was chosen for several reasons. The C++ compiler is mature and the language provides support for system programming. In addition, there is already a large community of Macintosh (and BSD) developers with C++ experience.
The restricted subset disallows certain features of C++, including
- Exceptions
- Multiple inheritance
- Templates
- Runtime type information (RTTI)—the I/O Kit uses its own implementation of a runtime typing system
These features were dropped because they were deemed unsuitable for use within a multithreaded kernel. If you feel you need these features, you should reconsider your design. You should be able to write any driver you require using I/O Kit with these restrictions in place.
If you cannot use C++ then one alternative is to have your C program call /usr/bin/ioreg
and parse its results.
Edit: you might want to take a look at the Accessing Hardware from Applications document. It looks like accessing the I/O registry can be done with C code for the most part (if not all), with a bit of Core Foundation.