Skip to content

Commit 343b725

Browse files
mgurtovoyAlex Williamson
authored andcommitted
PCI: Add 'override_only' field to struct pci_device_id
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>
1 parent c61302a commit 343b725

4 files changed

Lines changed: 39 additions & 7 deletions

File tree

Documentation/PCI/pci.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ need pass only as many optional fields as necessary:
103103
- subvendor and subdevice fields default to PCI_ANY_ID (FFFFFFFF)
104104
- class and classmask fields default to 0
105105
- driver_data defaults to 0UL.
106+
- override_only field defaults to 0.
106107

107108
Note that driver_data must match the value used by any of the pci_device_id
108109
entries defined in the driver. This makes the driver_data field mandatory

drivers/pci/pci-driver.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
136136
struct pci_dev *dev)
137137
{
138138
struct pci_dynid *dynid;
139-
const struct pci_device_id *found_id = NULL;
139+
const struct pci_device_id *found_id = NULL, *ids;
140140

141141
/* When driver_override is set, only bind to the matching driver */
142142
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,
152152
}
153153
spin_unlock(&drv->dynids.lock);
154154

155-
if (!found_id)
156-
found_id = pci_match_id(drv->id_table, dev);
155+
if (found_id)
156+
return found_id;
157157

158-
/* driver_override will always match, send a dummy id */
159-
if (!found_id && dev->driver_override)
160-
found_id = &pci_device_id_any;
158+
for (ids = drv->id_table; (found_id = pci_match_id(ids, dev));
159+
ids = found_id + 1) {
160+
/*
161+
* The match table is split based on driver_override.
162+
* In case override_only was set, enforce driver_override
163+
* matching.
164+
*/
165+
if (found_id->override_only) {
166+
if (dev->driver_override)
167+
return found_id;
168+
} else {
169+
return found_id;
170+
}
171+
}
161172

162-
return found_id;
173+
/* driver_override will always match, send a dummy id */
174+
if (dev->driver_override)
175+
return &pci_device_id_any;
176+
return NULL;
163177
}
164178

165179
/**

include/linux/mod_devicetable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ typedef unsigned long kernel_ulong_t;
3434
* Best practice is to use driver_data as an index
3535
* into a static list of equivalent device types,
3636
* instead of using it as a pointer.
37+
* @override_only: Match only when dev->driver_override is this driver.
3738
*/
3839
struct pci_device_id {
3940
__u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
4041
__u32 subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
4142
__u32 class, class_mask; /* (class,subclass,prog-if) triplet */
4243
kernel_ulong_t driver_data; /* Data private to the driver */
44+
__u32 override_only;
4345
};
4446

4547

include/linux/pci.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,21 @@ struct pci_driver {
901901
.vendor = (vend), .device = (dev), \
902902
.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
903903

904+
/**
905+
* PCI_DEVICE_DRIVER_OVERRIDE - macro used to describe a PCI device with
906+
* override_only flags.
907+
* @vend: the 16 bit PCI Vendor ID
908+
* @dev: the 16 bit PCI Device ID
909+
* @driver_override: the 32 bit PCI Device override_only
910+
*
911+
* This macro is used to create a struct pci_device_id that matches only a
912+
* driver_override device. The subvendor and subdevice fields will be set to
913+
* PCI_ANY_ID.
914+
*/
915+
#define PCI_DEVICE_DRIVER_OVERRIDE(vend, dev, driver_override) \
916+
.vendor = (vend), .device = (dev), .subvendor = PCI_ANY_ID, \
917+
.subdevice = PCI_ANY_ID, .override_only = (driver_override)
918+
904919
/**
905920
* PCI_DEVICE_SUB - macro used to describe a specific PCI device with subsystem
906921
* @vend: the 16 bit PCI Vendor ID

0 commit comments

Comments
 (0)