aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIsaku Yamahata <yamahata@valinux.co.jp>2010-07-07 12:14:01 +0900
committerKevin O'Connor <kevin@koconnor.net>2010-07-10 12:39:47 -0400
commit968d3a889cc35fd647e6e05ec7537fffad09227d (patch)
tree90d3f57b58600f0bb07f1f9fd8e82fc1b6588e4d
parent4e0daae583aeaac8e2a7fb25d02533bf40ecf29b (diff)
downloadseabios-968d3a889cc35fd647e6e05ec7537fffad09227d.tar.gz
seabios: pci: introduce helper function to initialize a given device.
introduce helper function to initialize a given device, This will be used later. Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
-rw-r--r--src/pci.c20
-rw-r--r--src/pci.h34
2 files changed, 54 insertions, 0 deletions
diff --git a/src/pci.c b/src/pci.c
index 1ab3c2c5..c54b084c 100644
--- a/src/pci.c
+++ b/src/pci.c
@@ -183,3 +183,23 @@ pci_find_class(u16 classid)
}
return -1;
}
+
+int pci_init_device(const struct pci_device_id *ids, u16 bdf, void *arg)
+{
+ u16 vendor_id = pci_config_readw(bdf, PCI_VENDOR_ID);
+ u16 device_id = pci_config_readw(bdf, PCI_DEVICE_ID);
+ u16 class = pci_config_readw(bdf, PCI_CLASS_DEVICE);
+
+ while (ids->vendid || ids->class_mask) {
+ if ((ids->vendid == PCI_ANY_ID || ids->vendid == vendor_id) &&
+ (ids->devid == PCI_ANY_ID || ids->devid == device_id) &&
+ !((ids->class ^ class) & ids->class_mask)) {
+ if (ids->func) {
+ ids->func(bdf, arg);
+ }
+ return 0;
+ }
+ ids++;
+ }
+ return -1;
+}
diff --git a/src/pci.h b/src/pci.h
index e40e1169..fa6a32d8 100644
--- a/src/pci.h
+++ b/src/pci.h
@@ -60,6 +60,40 @@ int pci_next(int bdf, int *pmax);
; MAX = pci_bus_devfn_to_bdf(BUS, 0) + 0x0100, \
BDF = pci_next(BDF + 1, &MAX))
+#define PCI_ANY_ID (~0)
+struct pci_device_id {
+ u32 vendid;
+ u32 devid;
+ u32 class;
+ u32 class_mask;
+ void (*func)(u16 bdf, void *arg);
+};
+
+#define PCI_DEVICE(vendor_id, device_id, init_func) \
+ { \
+ .vendid = (vendor_id), \
+ .devid = (device_id), \
+ .class = PCI_ANY_ID, \
+ .class_mask = 0, \
+ .func = (init_func) \
+ }
+
+#define PCI_DEVICE_CLASS(vendor_id, device_id, class_code, init_func) \
+ { \
+ .vendid = (vendor_id), \
+ .devid = (device_id), \
+ .class = (class_code), \
+ .class_mask = ~0, \
+ .func = (init_func) \
+ }
+
+#define PCI_DEVICE_END \
+ { \
+ .vendid = 0, \
+ }
+
+int pci_init_device(const struct pci_device_id *table, u16 bdf, void *arg);
+
// pirtable.c
void create_pirtable(void);