summaryrefslogtreecommitdiffstats
path: root/src/drivers/bus
diff options
context:
space:
mode:
authorMichael Brown2005-04-14 12:10:54 +0200
committerMichael Brown2005-04-14 12:10:54 +0200
commit75d864432cc41c45d46df9ea7d3afd7cccbc0148 (patch)
tree8b98bce9c01b2f99f16d5da9f93a4e147dfe1865 /src/drivers/bus
parentStripped references to variables in C code. (diff)
downloadipxe-75d864432cc41c45d46df9ea7d3afd7cccbc0148.tar.gz
ipxe-75d864432cc41c45d46df9ea7d3afd7cccbc0148.tar.xz
ipxe-75d864432cc41c45d46df9ea7d3afd7cccbc0148.zip
Use the magic of common symbols to allow struct dev to effectively grow at
link time to accommodate whatever bus objects are included.
Diffstat (limited to 'src/drivers/bus')
-rw-r--r--src/drivers/bus/eisa.c26
-rw-r--r--src/drivers/bus/mca.c22
-rw-r--r--src/drivers/bus/pci.c31
3 files changed, 63 insertions, 16 deletions
diff --git a/src/drivers/bus/eisa.c b/src/drivers/bus/eisa.c
index a294895d3..c80974a8a 100644
--- a/src/drivers/bus/eisa.c
+++ b/src/drivers/bus/eisa.c
@@ -14,6 +14,14 @@
#endif
/*
+ * Ensure that there is sufficient space in the shared dev_bus
+ * structure for a struct pci_device.
+ *
+ */
+DEV_BUS( struct eisa_device, eisa_dev );
+static char eisa_magic[0]; /* guaranteed unique symbol */
+
+/*
* Fill in parameters for an EISA device based on slot number
*
* Return 1 if device present, 0 otherwise
@@ -52,15 +60,14 @@ static int fill_eisa_device ( struct eisa_device *eisa ) {
* Obtain a struct eisa * from a struct dev *
*
* If dev has not previously been used for an EISA device scan, blank
- * out dev.eisa
+ * out struct eisa
*/
struct eisa_device * eisa_device ( struct dev *dev ) {
- struct eisa_device *eisa = &dev->eisa;
+ struct eisa_device *eisa = dev->bus;;
- if ( dev->devid.bus_type != EISA_BUS_TYPE ) {
+ if ( eisa->magic != eisa_magic ) {
memset ( eisa, 0, sizeof ( *eisa ) );
- dev->devid.bus_type = EISA_BUS_TYPE;
- eisa->slot = EISA_MIN_SLOT;
+ eisa->magic = eisa_magic;
}
eisa->dev = dev;
return eisa;
@@ -74,8 +81,13 @@ int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
unsigned int i;
/* Iterate through all possible EISA slots, starting where we
- * left off/
+ * left off. If eisa->slot is zero (which it will be if we
+ * have a zeroed structure), start from slot EISA_MIN_SLOT,
+ * since slot 0 doesn't exist.
*/
+ if ( ! eisa->slot ) {
+ eisa->slot = EISA_MIN_SLOT;
+ }
for ( ; eisa->slot <= EISA_MAX_SLOT ; eisa->slot++ ) {
/* If we've already used this device, skip it */
if ( eisa->already_tried ) {
@@ -101,6 +113,8 @@ int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
eisa->prod_id ) );
if ( eisa->dev ) {
eisa->dev->name = driver->name;
+ eisa->dev->devid.bus_type
+ = ISA_BUS_TYPE;
eisa->dev->devid.vendor_id
= eisa->mfg_id;
eisa->dev->devid.device_id
diff --git a/src/drivers/bus/mca.c b/src/drivers/bus/mca.c
index 28b99f77a..1715c5883 100644
--- a/src/drivers/bus/mca.c
+++ b/src/drivers/bus/mca.c
@@ -20,6 +20,14 @@
#endif
/*
+ * Ensure that there is sufficient space in the shared dev_bus
+ * structure for a struct pci_device.
+ *
+ */
+DEV_BUS( struct mca_device, mca_dev );
+static char mca_magic[0]; /* guaranteed unique symbol */
+
+/*
* Fill in parameters for an MCA device based on slot number
*
*/
@@ -53,14 +61,14 @@ static int fill_mca_device ( struct mca_device *mca ) {
* Obtain a struct mca * from a struct dev *
*
* If dev has not previously been used for an MCA device scan, blank
- * out dev.mca
+ * out struct mca
*/
struct mca_device * mca_device ( struct dev *dev ) {
- struct mca_device *mca = &dev->mca;
+ struct mca_device *mca = dev->bus;
- if ( dev->devid.bus_type != MCA_BUS_TYPE ) {
+ if ( mca->magic != mca_magic ) {
memset ( mca, 0, sizeof ( *mca ) );
- dev->devid.bus_type = MCA_BUS_TYPE;
+ mca->magic = mca_magic;
}
mca->dev = dev;
return mca;
@@ -97,8 +105,10 @@ int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
id->name, driver->name, id->id );
if ( mca->dev ) {
mca->dev->name = driver->name;
- mca->dev->devid.vendor_id =
- GENERIC_MCA_VENDOR;
+ mca->dev->devid.bus_type
+ = MCA_BUS_TYPE;
+ mca->dev->devid.vendor_id
+ = GENERIC_MCA_VENDOR;
mca->dev->devid.device_id = id->id;
}
mca->already_tried = 1;
diff --git a/src/drivers/bus/pci.c b/src/drivers/bus/pci.c
index 4b4e9a151..d23a647a8 100644
--- a/src/drivers/bus/pci.c
+++ b/src/drivers/bus/pci.c
@@ -10,6 +10,14 @@
#endif
/*
+ * Ensure that there is sufficient space in the shared dev_bus
+ * structure for a struct pci_device.
+ *
+ */
+DEV_BUS( struct pci_device, pci_dev );
+static char pci_magic[0]; /* guaranteed unique symbol */
+
+/*
* Fill in parameters (vendor & device ids, class, membase etc.) for a
* PCI device based on bus & devfn.
*
@@ -112,20 +120,34 @@ void adjust_pci_device ( struct pci_device *pci ) {
* Obtain a struct pci * from a struct dev *
*
* If dev has not previously been used for a PCI device scan, blank
- * out dev.pci
+ * out struct pci
*/
struct pci_device * pci_device ( struct dev *dev ) {
- struct pci_device *pci = &dev->pci;
+ struct pci_device *pci = dev->bus;
- if ( dev->devid.bus_type != PCI_BUS_TYPE ) {
+ if ( pci->magic != pci_magic ) {
memset ( pci, 0, sizeof ( *pci ) );
- dev->devid.bus_type = PCI_BUS_TYPE;
+ pci->magic = pci_magic;
}
pci->dev = dev;
return pci;
}
/*
+ * Set PCI device to use.
+ *
+ * This routine can be called by e.g. the ROM prefix to specify that
+ * the first device to be tried should be the device on which the ROM
+ * was physically located.
+ *
+ */
+void set_pci_device ( uint16_t busdevfn ) {
+ pci_dev.magic = pci_magic;
+ pci_dev.busdevfn = busdevfn;
+ pci_dev.already_tried = 0;
+}
+
+/*
* Find a PCI device matching the specified driver
*
*/
@@ -154,6 +176,7 @@ int find_pci_device ( struct pci_device *pci,
/* Fill in dev structure, if present */
if ( pci->dev ) {
pci->dev->name = driver->name;
+ pci->dev->devid.bus_type = PCI_BUS_TYPE;
pci->dev->devid.vendor_id = pci->vendor;
pci->dev->devid.device_id = pci->dev_id;
}