aboutsummaryrefslogtreecommitdiffstats
path: root/stubs.h
diff options
context:
space:
mode:
Diffstat (limited to 'stubs.h')
-rw-r--r--stubs.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/stubs.h b/stubs.h
new file mode 100644
index 0000000..bfcc0d7
--- /dev/null
+++ b/stubs.h
@@ -0,0 +1,80 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Helpful private functions copied from elsewhere in the kernel tree
4 * DO NOT MODIFY
5 */
6#include <linux/version.h>
7
8// Functions from drivers/pci/pci.h
9/**
10 * pci_match_one_device - Tell if a PCI device structure has a matching
11 * PCI device id structure
12 * @id: single PCI device id structure to match
13 * @dev: the PCI device structure to match against
14 *
15 * Returns the matching pci_device_id structure or %NULL if there is no match.
16 */
17static inline const struct pci_device_id *
18pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
19{
20 if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
21 (id->device == PCI_ANY_ID || id->device == dev->device) &&
22 (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
23 (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
24 !((id->class ^ dev->class) & id->class_mask))
25 return id;
26 return NULL;
27}
28
29// Functions from drivers/pci/search.h
30#include <linux/device.h>
31#include <linux/pci.h>
32extern struct bus_type pci_bus_type;
33
34#if LINUX_VERSION_CODE < KERNEL_VERSION(5,3,0)
35static int match_pci_dev_by_id(struct device *dev, void *data)
36#else
37static int match_pci_dev_by_id(struct device *dev, const void *data)
38#endif
39{
40 struct pci_dev *pdev = to_pci_dev(dev);
41 const struct pci_device_id *id = data;
42
43 if (pci_match_one_device(id, pdev))
44 return 1;
45 return 0;
46}
47
48/*
49 * pci_get_dev_by_id - begin or continue searching for a PCI device by id
50 * @id: pointer to struct pci_device_id to match for the device
51 * @from: Previous PCI device found in search, or %NULL for new search.
52 *
53 * Iterates through the list of known PCI devices. If a PCI device is found
54 * with a matching id a pointer to its device structure is returned, and the
55 * reference count to the device is incremented. Otherwise, %NULL is returned.
56 * A new search is initiated by passing %NULL as the @from argument. Otherwise
57 * if @from is not %NULL, searches continue from next device on the global
58 * list. The reference count for @from is always decremented if it is not
59 * %NULL.
60 *
61 * This is an internal function for use by the other search functions in
62 * this file.
63 */
64static struct pci_dev *pci_get_dev_by_id(const struct pci_device_id *id,
65 struct pci_dev *from)
66{
67 struct device *dev;
68 struct device *dev_start = NULL;
69 struct pci_dev *pdev = NULL;
70
71 if (from)
72 dev_start = &from->dev;
73 dev = bus_find_device(&pci_bus_type, dev_start, (void *)id,
74 match_pci_dev_by_id);
75 if (dev)
76 pdev = to_pci_dev(dev);
77 pci_dev_put(from);
78 return pdev;
79}
80