kexts: pci: score driver matches, allow fallback class drivers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <socks/device.h>
|
||||
#include <socks/printk.h>
|
||||
#include <socks/pci.h>
|
||||
|
||||
static struct vm_cache pci_driver_cache = {
|
||||
@@ -70,24 +71,37 @@ kern_status_t pci_driver_unregister(struct pci_driver *driver)
|
||||
return driver_unregister(&driver->pci_base);
|
||||
}
|
||||
|
||||
static bool scan_device_id_list(const struct pci_device_id *device_ids, uint16_t vendor_id, uint16_t device_id)
|
||||
static int scan_device_id_list(const struct pci_device_id *device_ids, const struct pci_device_id *query)
|
||||
{
|
||||
int best_score = 0;
|
||||
|
||||
for (unsigned int i = 0; ; i++) {
|
||||
if (device_ids[i].pci_device_id == PCI_NONE && device_ids[i].pci_vendor_id == PCI_NONE) {
|
||||
if (device_ids[i].pci_device_id == PCI_NONE && device_ids[i].pci_vendor_id == PCI_NONE && device_ids[i].pci_class_id == PCI_CLASS_ANY && device_ids[i].pci_subclass_id == PCI_CLASS_ANY) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (device_ids[i].pci_device_id == device_id && device_ids[i].pci_vendor_id == vendor_id) {
|
||||
return true;
|
||||
int score = 0;
|
||||
|
||||
if (device_ids[i].pci_class_id == query->pci_class_id && device_ids[i].pci_subclass_id == query->pci_subclass_id && device_ids[i].pci_vendor_id == PCI_NONE && device_ids[i].pci_device_id == PCI_NONE) {
|
||||
score = 1;
|
||||
}
|
||||
|
||||
if (device_ids[i].pci_device_id == query->pci_device_id && device_ids[i].pci_vendor_id == query->pci_vendor_id) {
|
||||
score = 2;
|
||||
}
|
||||
|
||||
if (score > best_score) {
|
||||
best_score = score;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return best_score;
|
||||
}
|
||||
|
||||
struct pci_driver *find_driver_for_pci_device(uint16_t vendor_id, uint16_t device_id)
|
||||
struct pci_driver *find_driver_for_pci_device(const struct pci_device_id *query)
|
||||
{
|
||||
struct pci_driver *out = NULL;
|
||||
struct pci_driver *best_match = NULL;
|
||||
int best_score = 0;
|
||||
|
||||
unsigned long flags;
|
||||
spin_lock_irqsave(&pci_drivers_lock, &flags);
|
||||
@@ -98,12 +112,13 @@ struct pci_driver *find_driver_for_pci_device(uint16_t vendor_id, uint16_t devic
|
||||
continue;
|
||||
}
|
||||
|
||||
if (scan_device_id_list(device_ids, vendor_id, device_id)) {
|
||||
out = driver;
|
||||
break;
|
||||
int score = scan_device_id_list(device_ids, query);
|
||||
if (score > best_score) {
|
||||
best_score = score;
|
||||
best_match = driver;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&pci_drivers_lock, flags);
|
||||
return out;
|
||||
return best_match;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user