Locate a device that matches the specified criteria
#include <pci/pci.h> pci_bdf_t pci_device_find( const uint_t idx, const pci_vid_t vid, const pci_did_t did, const pci_ccode_t classcode );
The pci_device_find() function kets you locate a specific device by specifying any combination of the vendor ID vid, device ID did, and class (and subclass) code classcode filter parameters. Any parameter can be wild-carded by using PCI_VID_ANY, PCI_DID_ANY, or PCI_CCODE_ANY, respectively.
The class code is of type pci_ccode_t, which contains 3 bytes as defined in the PCI specification:
MSb LSb 0000 0000 CCCC CCCC cccc cccc rrrr rrrr C - represents the base class c - represents the sub class r - represents a register level programming interface
To encode and decode the class code, you can use the macros defined in <pci/pci_ccode.h>, as well as the following macros, defined in <pci/pci.h>:
Wild cards for the subclass and register interface let you widen the search for class codes. You can use the following values independently or together for the subclass and register interface respectively when constructing a classcode to search for:
For example:
You can find the defined vendor IDs in <pci/pci_id.h>. In addition, the idx parameter lets you select from multiple instances of devices meeting the search criteria. By calling pci_device_find() repeatedly with an incrementing idx value, you can find all instances of a device meeting the search criteria.
The search criteria parameters allow the following filter combinations:
vid | did | classcode | Result |
---|---|---|---|
PCI_VID_ANY | PCI_DID_ANY | PCI_CCODE_ANY | All devices |
PCI_VID_ANY | PCI_DID_ANY | A class code | All devices of a specified class |
PCI_VID_ANY | A device ID | PCI_CCODE_ANY | All devices with a specific device ID |
PCI_VID_ANY | A device ID | A class code | All devices of a specified class with a specific device ID |
A vendor ID | PCI_DID_ANY | PCI_CCODE_ANY | All devices from a specific vendor |
A vendor ID | PCI_DID_ANY | A class code | All devices of a specified class from a specific vendor |
A vendor ID | A device ID | PCI_CCODE_ANY | All devices with a specific device ID from a specific vendor |
A vendor ID | A device ID | A class code | All devices of a specified class with a specific device ID from a specific vendor |
A pci_bdf_t value that uniquely identifies a specific device and which you can use to attach to the device or to perform various read operations (see pci_device_read_*()), or PCI_BDF_NONE if a device couldn't be found based on the search criteria.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |