@@ -106,6 +106,11 @@ extern pci_dev_t dev_zero;
106106#define DEVICE_PER_BUS 32
107107#define FUNCTION_PER_DEVICE 32
108108
109+ /**
110+ * Generic scoring callback: return a signed score; <0 means "reject". Higher wins.
111+ */
112+ typedef int (* pci_score_fn )(pci_dev_t dev , void * ctx );
113+
109114/**
110115 * @brief Read a value from a PCI configuration space field.
111116 * @param dev PCI device descriptor.
@@ -188,8 +193,22 @@ pci_dev_t pci_scan_bus(uint16_t vendor_id, uint16_t device_id,
188193 * @param device_type Device class/type to match (-1 = any).
189194 * @return Matching PCI device or dev_zero if none.
190195 */
191- pci_dev_t pci_get_device (uint16_t vendor_id , uint16_t device_id ,
192- int device_type );
196+ pci_dev_t pci_get_device (uint16_t vendor_id , uint16_t device_id , int device_type );
197+
198+ /**
199+ * @brief Find the best PCI function matching an optional filter (vendor/device/class),
200+ * selected by a driver-supplied scoring callback. All params are optional.
201+ *
202+ * @param vendor_id Vendor ID to match (0 = any).
203+ * @param device_id Device ID to match (0 = any).
204+ * @param device_type Device class/type to match (-1 = any).
205+ * @param score Scoring function to rank devices
206+ * @param ctx User defined context to pass to scoring function
207+ * @return dev_zero if nothing acceptable was found
208+ */
209+ pci_dev_t pci_get_best (uint16_t vendor_id , uint16_t device_id , int device_type , pci_score_fn score , void * ctx );
210+
211+ pci_dev_t pci_get_device_nth (uint16_t vendor_id , uint16_t device_id , int device_type , size_t nth );
193212
194213/**
195214 * @brief Initialise the PCI subsystem and enumerate devices.
0 commit comments