mirror of https://github.com/ipxe/ipxe.git
Fix up find_pci_device so that it can be used for scanning for devices
*other* than the main boot device.pull/1/head
parent
eb8f730d63
commit
762fa9a478
|
@ -210,6 +210,24 @@ void exit(int status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* Note that this is deliberately in main.c rather than pci.c, because
|
||||||
|
* this function should generalise to other bus types (e.g. ISAPnP),
|
||||||
|
* and we don't want to end up dragging in pci.o unnecessarily.
|
||||||
|
*/
|
||||||
|
void set_pci_device ( uint16_t busdevfn ) {
|
||||||
|
dev.devid.bus_type = PCI_BUS_TYPE;
|
||||||
|
dev.pci.busdevfn = busdevfn;
|
||||||
|
dev.pci.already_tried = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
static int main_loop(int state)
|
static int main_loop(int state)
|
||||||
|
|
|
@ -11,9 +11,6 @@
|
||||||
#define DBG(...)
|
#define DBG(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct pci_device current;
|
|
||||||
static char used_current;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fill in parameters (vendor & device ids, class, membase etc.) for a
|
* Fill in parameters (vendor & device ids, class, membase etc.) for a
|
||||||
* PCI device based on bus & devfn.
|
* PCI device based on bus & devfn.
|
||||||
|
@ -114,77 +111,76 @@ static void adjust_pci_device ( struct pci_device *pci ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set PCI device to use.
|
* Obtain a struct pci * from a struct dev *
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
|
* If dev has not previously been used for a PCI device scan, blank
|
||||||
|
* out dev.pci
|
||||||
*/
|
*/
|
||||||
void set_pci_device ( uint16_t busdevfn ) {
|
struct pci_device * pci_device ( struct dev *dev ) {
|
||||||
current.busdevfn = busdevfn;
|
struct pci_device *pci = &dev->pci;
|
||||||
used_current = 0;
|
|
||||||
|
if ( dev->devid.bus_type != PCI_BUS_TYPE ) {
|
||||||
|
memset ( pci, 0, sizeof ( *pci ) );
|
||||||
|
}
|
||||||
|
pci->dev = dev;
|
||||||
|
return pci;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find a PCI device matching the specified driver
|
* Find a PCI device matching the specified driver
|
||||||
*
|
*
|
||||||
* If "dev" is non-NULL, the struct dev will be filled in with any
|
|
||||||
* relevant information.
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
struct pci_device * find_pci_device ( struct pci_driver *driver,
|
int find_pci_device ( struct pci_device *pci,
|
||||||
struct dev *dev ) {
|
struct pci_driver *driver ) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Iterate through all possible PCI bus:dev.fn combinations,
|
/* Iterate through all possible PCI bus:dev.fn combinations,
|
||||||
* starting where we left off.
|
* starting where we left off.
|
||||||
*/
|
*/
|
||||||
for ( ; current.busdevfn <= 0xffff ; current.busdevfn++ ) {
|
for ( ; pci->busdevfn <= 0xffff ; pci->busdevfn++ ) {
|
||||||
/* If we've already used this device, skip it */
|
/* If we've already used this device, skip it */
|
||||||
if ( used_current ) {
|
if ( pci->already_tried ) {
|
||||||
used_current = 0;
|
pci->already_tried = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill in device parameters, if device present */
|
/* Fill in device parameters, if device present */
|
||||||
if ( ! fill_pci_device ( ¤t ) ) {
|
if ( ! fill_pci_device ( pci ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fix up PCI device */
|
/* Fix up PCI device */
|
||||||
adjust_pci_device ( ¤t );
|
adjust_pci_device ( pci );
|
||||||
|
|
||||||
/* Fill in dev structure, if present */
|
/* Fill in dev structure, if present */
|
||||||
if ( dev ) {
|
if ( pci->dev ) {
|
||||||
dev->name = driver->name;
|
pci->dev->name = driver->name;
|
||||||
dev->devid.vendor_id = current.vendor;
|
pci->dev->devid.vendor_id = pci->vendor;
|
||||||
dev->devid.device_id = current.dev_id;
|
pci->dev->devid.device_id = pci->dev_id;
|
||||||
dev->devid.bus_type = PCI_BUS_TYPE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If driver has a class, and class matches, use it */
|
/* If driver has a class, and class matches, use it */
|
||||||
if ( driver->class &&
|
if ( driver->class &&
|
||||||
( driver->class == current.class ) ) {
|
( driver->class == pci->class ) ) {
|
||||||
DBG ( "Driver %s matches class %hx\n",
|
DBG ( "Driver %s matches class %hx\n",
|
||||||
driver->name, driver->class );
|
driver->name, driver->class );
|
||||||
used_current = 1;
|
pci->already_tried = 1;
|
||||||
return ¤t;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If any of driver's IDs match, use it */
|
/* If any of driver's IDs match, use it */
|
||||||
for ( i = 0 ; i < driver->id_count; i++ ) {
|
for ( i = 0 ; i < driver->id_count; i++ ) {
|
||||||
struct pci_id *id = &driver->ids[i];
|
struct pci_id *id = &driver->ids[i];
|
||||||
|
|
||||||
if ( ( current.vendor == id->vendor ) &&
|
if ( ( pci->vendor == id->vendor ) &&
|
||||||
( current.dev_id == id->dev_id ) ) {
|
( pci->dev_id == id->dev_id ) ) {
|
||||||
DBG ( "Device %s (driver %s) matches "
|
DBG ( "Device %s (driver %s) matches "
|
||||||
"ID %hx:%hx\n", id->name, driver->name,
|
"ID %hx:%hx\n", id->name, driver->name,
|
||||||
id->vendor, id->dev_id );
|
id->vendor, id->dev_id );
|
||||||
if ( dev )
|
if ( pci->dev )
|
||||||
dev->name = id->name;
|
pci->dev->name = id->name;
|
||||||
used_current = 1;
|
pci->already_tried = 1;
|
||||||
return ¤t;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,8 +188,7 @@ struct pci_device * find_pci_device ( struct pci_driver *driver,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No device found */
|
/* No device found */
|
||||||
memset ( ¤t, 0, sizeof ( current ) );
|
return 0;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "nic.h"
|
#include "nic.h"
|
||||||
|
#include "pci.h"
|
||||||
|
|
||||||
/* Need to check the packing of this struct if Etherboot is ported */
|
/* Need to check the packing of this struct if Etherboot is ported */
|
||||||
struct dev_id {
|
struct dev_id {
|
||||||
|
@ -17,9 +18,13 @@ struct dev_id {
|
||||||
#define DEV_ID_SIZE 8
|
#define DEV_ID_SIZE 8
|
||||||
|
|
||||||
struct dev {
|
struct dev {
|
||||||
|
struct dev_operations *dev_op;
|
||||||
const char *name;
|
const char *name;
|
||||||
struct dev_id devid; /* device ID string (sent to DHCP server) */
|
struct dev_id devid; /* device ID string (sent to DHCP server) */
|
||||||
struct dev_operations *dev_op;
|
/* All possible bus types */
|
||||||
|
union {
|
||||||
|
struct pci_device pci;
|
||||||
|
};
|
||||||
/* All possible device types */
|
/* All possible device types */
|
||||||
union {
|
union {
|
||||||
struct nic nic;
|
struct nic nic;
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
|
|
||||||
#include "dev.h"
|
#include "dev.h"
|
||||||
|
|
||||||
extern int main ( void );
|
|
||||||
|
|
||||||
extern struct dev dev;
|
extern struct dev dev;
|
||||||
|
|
||||||
|
extern int main ( void );
|
||||||
|
extern void set_pci_device ( uint16_t busdevfn );
|
||||||
|
|
||||||
#endif /* MAIN_H */
|
#endif /* MAIN_H */
|
||||||
|
|
|
@ -237,7 +237,9 @@
|
||||||
* A physical PCI device
|
* A physical PCI device
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
struct dev;
|
||||||
struct pci_device {
|
struct pci_device {
|
||||||
|
struct dev * dev;
|
||||||
uint32_t membase; /* BAR 1 */
|
uint32_t membase; /* BAR 1 */
|
||||||
uint32_t ioaddr; /* first IO BAR */
|
uint32_t ioaddr; /* first IO BAR */
|
||||||
uint16_t vendor, dev_id;
|
uint16_t vendor, dev_id;
|
||||||
|
@ -245,6 +247,7 @@ struct pci_device {
|
||||||
uint16_t busdevfn;
|
uint16_t busdevfn;
|
||||||
uint8_t revision;
|
uint8_t revision;
|
||||||
uint8_t irq;
|
uint8_t irq;
|
||||||
|
uint8_t already_tried;
|
||||||
};
|
};
|
||||||
#define PCI_BUS(busdevfn) ( ( (busdevfn) >> 8 ) & 0xff )
|
#define PCI_BUS(busdevfn) ( ( (busdevfn) >> 8 ) & 0xff )
|
||||||
#define PCI_DEV(busdevfn) ( ( (busdevfn) >> 3 ) & 0x1f )
|
#define PCI_DEV(busdevfn) ( ( (busdevfn) >> 3 ) & 0x1f )
|
||||||
|
@ -319,9 +322,9 @@ extern unsigned long pci_bus_base ( struct pci_device *dev );
|
||||||
* Functions in pci.c
|
* Functions in pci.c
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
extern void set_pci_device ( uint16_t busdevfn );
|
extern struct pci_device * pci_device ( struct dev *dev );
|
||||||
extern struct pci_device * find_pci_device ( struct pci_driver *driver,
|
extern int find_pci_device ( struct pci_device *pci,
|
||||||
struct dev *dev );
|
struct pci_driver *driver );
|
||||||
extern unsigned long pci_bar_start ( struct pci_device *pci,
|
extern unsigned long pci_bar_start ( struct pci_device *pci,
|
||||||
unsigned int bar );
|
unsigned int bar );
|
||||||
extern unsigned long pci_bar_size ( struct pci_device *pci, unsigned int bar );
|
extern unsigned long pci_bar_size ( struct pci_device *pci, unsigned int bar );
|
||||||
|
|
Loading…
Reference in New Issue