OSDN Git Service

PCI: Add 'override_only' field to struct pci_device_id
authorMax Gurtovoy <mgurtovoy@nvidia.com>
Thu, 26 Aug 2021 10:39:08 +0000 (13:39 +0300)
committerAlex Williamson <alex.williamson@redhat.com>
Thu, 26 Aug 2021 16:36:51 +0000 (10:36 -0600)
Add 'override_only' field to struct pci_device_id to be used as part of
pci_match_device().

When set, a driver only matches the entry when dev->driver_override is
set to that driver.

In addition, add a helper macro named 'PCI_DEVICE_DRIVER_OVERRIDE' to
enable setting some data on it.

Next patch from this series will use the above functionality.

Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
Link: https://lore.kernel.org/r/20210826103912.128972-10-yishaih@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Documentation/PCI/pci.rst
drivers/pci/pci-driver.c
include/linux/mod_devicetable.h
include/linux/pci.h

index fa651e2..87c6f4a 100644 (file)
@@ -103,6 +103,7 @@ need pass only as many optional fields as necessary:
   - subvendor and subdevice fields default to PCI_ANY_ID (FFFFFFFF)
   - class and classmask fields default to 0
   - driver_data defaults to 0UL.
+  - override_only field defaults to 0.
 
 Note that driver_data must match the value used by any of the pci_device_id
 entries defined in the driver. This makes the driver_data field mandatory
index 3a72352..123c590 100644 (file)
@@ -136,7 +136,7 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
                                                    struct pci_dev *dev)
 {
        struct pci_dynid *dynid;
-       const struct pci_device_id *found_id = NULL;
+       const struct pci_device_id *found_id = NULL, *ids;
 
        /* When driver_override is set, only bind to the matching driver */
        if (dev->driver_override && strcmp(dev->driver_override, drv->name))
@@ -152,14 +152,28 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
        }
        spin_unlock(&drv->dynids.lock);
 
-       if (!found_id)
-               found_id = pci_match_id(drv->id_table, dev);
+       if (found_id)
+               return found_id;
 
-       /* driver_override will always match, send a dummy id */
-       if (!found_id && dev->driver_override)
-               found_id = &pci_device_id_any;
+       for (ids = drv->id_table; (found_id = pci_match_id(ids, dev));
+            ids = found_id + 1) {
+               /*
+                * The match table is split based on driver_override.
+                * In case override_only was set, enforce driver_override
+                * matching.
+                */
+               if (found_id->override_only) {
+                       if (dev->driver_override)
+                               return found_id;
+               } else {
+                       return found_id;
+               }
+       }
 
-       return found_id;
+       /* driver_override will always match, send a dummy id */
+       if (dev->driver_override)
+               return &pci_device_id_any;
+       return NULL;
 }
 
 /**
index 8e291cf..2e3ba6d 100644 (file)
@@ -34,12 +34,14 @@ typedef unsigned long kernel_ulong_t;
  *                     Best practice is to use driver_data as an index
  *                     into a static list of equivalent device types,
  *                     instead of using it as a pointer.
+ * @override_only:     Match only when dev->driver_override is this driver.
  */
 struct pci_device_id {
        __u32 vendor, device;           /* Vendor and device ID or PCI_ANY_ID*/
        __u32 subvendor, subdevice;     /* Subsystem ID's or PCI_ANY_ID */
        __u32 class, class_mask;        /* (class,subclass,prog-if) triplet */
        kernel_ulong_t driver_data;     /* Data private to the driver */
+       __u32 override_only;
 };
 
 
index 540b377..0506b1a 100644 (file)
@@ -902,6 +902,21 @@ struct pci_driver {
        .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
 
 /**
+ * PCI_DEVICE_DRIVER_OVERRIDE - macro used to describe a PCI device with
+ *                              override_only flags.
+ * @vend: the 16 bit PCI Vendor ID
+ * @dev: the 16 bit PCI Device ID
+ * @driver_override: the 32 bit PCI Device override_only
+ *
+ * This macro is used to create a struct pci_device_id that matches only a
+ * driver_override device. The subvendor and subdevice fields will be set to
+ * PCI_ANY_ID.
+ */
+#define PCI_DEVICE_DRIVER_OVERRIDE(vend, dev, driver_override) \
+       .vendor = (vend), .device = (dev), .subvendor = PCI_ANY_ID, \
+       .subdevice = PCI_ANY_ID, .override_only = (driver_override)
+
+/**
  * PCI_DEVICE_SUB - macro used to describe a specific PCI device with subsystem
  * @vend: the 16 bit PCI Vendor ID
  * @dev: the 16 bit PCI Device ID