ThePhD / infoware

C++ Library for pulling system and hardware information, without hitting the command line.
Creative Commons Zero v1.0 Universal
410 stars 84 forks source link

Expose PCI vendor/device-by-id funxions to the public? #34

Closed nabijaczleweli closed 4 years ago

nabijaczleweli commented 4 years ago

As of now we have them in iware::detail::identify_{vendor,device}(), but moving them to iware::[subsystem]::idenify_pci_{vendor,device}()/pci_{vendor,device}_id() where [subsystem] is system maybe but it's not strictly a discovery method so maybe new data? or straight up pci module? would be nice.

ThePhD commented 4 years ago

My (currently flawed?) impression is that users rarely have a PCI ID handy of the things inside of their machines. We use these functions mostly to coordinate with information returned by internal APIs -- are there cases where the user knows their vendor / PCI ID before-hand and just want to look it up?

nabijaczleweli commented 4 years ago

Off the top of my head, consider sysfs on Linux (though granted, I'm not a linux expert, and there's definitely some non-fs APIs that return these), too:

nabijaczleweli@tarta:~$ cat /sys/devices/pci0000\:00/0000\:00\:00.0/device
0x3406
nabijaczleweli@tarta:~$ cat /sys/devices/pci0000\:00/0000\:00\:00.0/vendor
0x8086
nabijaczleweli@tarta:~$ cat /sys/devices/pci0000\:fe/0000\:fe\:02.5/{vendor,device}
0x8086
0x2d95

And a bunch of Windows APIs: IDXGIAdapter::GetDesc() (yielding DXGI_ADAPTER_DESC, we use this internally), GAMING_DEVICE_MODEL_INFORMATION, &c.

It'd be really handy to have a first-class way of parsing these in-library (and a helper in examples would be nice and simple, too), especially given that we already ship this.

ThePhD commented 4 years ago

Well, heck. Guess we're just gonna promote it to the public namespace, then.

Would it make sense to do iware::pci:: ... ? It's not like the context (system, graphics, etc.) in which it happens changes the PCI-ness of it all.

nabijaczleweli commented 4 years ago

This is a simple CLI I arrived at, but I'm not sure what to do for unrecognised IDs formatting-wise?

$ bin\infoware_pci_example.exe 0xFFFFFFFFFFFFFFFF 16
Infoware version 0.3.1
Unrecognised vendor with ID 0xFFFFFFFFFFFFFFFF
Unrecognised device with ID 0x0000000000000010

$ bin\infoware_pci_example.exe 0x8086 0x2d95
Infoware version 0.3.1
Vendor 0x0000000000008086 Intel Corporation
Device 0x0000000000002D95 Xeon 5600 Series QPI Physical 1

$ bin\infoware_pci_example.exe 0x8086 0x3406
Infoware version 0.3.1
Vendor 0x0000000000008086 Intel Corporation
Device 0x0000000000003406 5520 I/O Hub to ESI Port

$ bin\infoware_pci_example.exe 0x8086
Infoware version 0.3.1
Vendor 0x0000000000008086 Intel Corporation

$ bin\infoware_pci_example.exe 0x8086 1319038103
Infoware version 0.3.1
Vendor 0x0000000000008086 Intel Corporation
Unrecognised device with ID 0x000000004E9EEC97
ThePhD commented 4 years ago

Looks fine to me.

nabijaczleweli commented 4 years ago

Delightful!

Released in v0.4.0