mirror of https://github.com/ipxe/ipxe.git
If preloaded device matches, use that rather than going via the UNDI
loader.pull/1/head
parent
2436dac281
commit
f2f492a536
|
@ -24,6 +24,7 @@
|
||||||
#include <undirom.h>
|
#include <undirom.h>
|
||||||
#include <undiload.h>
|
#include <undiload.h>
|
||||||
#include <undinet.h>
|
#include <undinet.h>
|
||||||
|
#include <undipreload.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
*
|
*
|
||||||
|
@ -31,35 +32,44 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find UNDI ROM for PCI device
|
||||||
|
*
|
||||||
|
* @v pci PCI device
|
||||||
|
* @ret undirom UNDI ROM, or NULL
|
||||||
|
*
|
||||||
|
* Try to find a driver for this device. Try an exact match on the
|
||||||
|
* ROM address first, then fall back to a vendor/device ID match only
|
||||||
|
*/
|
||||||
|
static struct undi_rom * undipci_find_rom ( struct pci_device *pci ) {
|
||||||
|
struct undi_rom *undirom;
|
||||||
|
unsigned long rombase;
|
||||||
|
|
||||||
|
rombase = pci_bar_start ( pci, PCI_ROM_ADDRESS );
|
||||||
|
undirom = undirom_find_pci ( pci->vendor, pci->device, rombase );
|
||||||
|
if ( ! undirom )
|
||||||
|
undirom = undirom_find_pci ( pci->vendor, pci->device, 0 );
|
||||||
|
return undirom;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Probe PCI device
|
* Probe PCI device
|
||||||
*
|
*
|
||||||
* @v pci PCI device
|
* @v pci PCI device
|
||||||
* @v id PCI ID
|
* @v id PCI ID
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
static int undipci_probe ( struct pci_device *pci,
|
static int undipci_probe ( struct pci_device *pci,
|
||||||
const struct pci_device_id *id __unused ) {
|
const struct pci_device_id *id __unused ) {
|
||||||
struct undi_device *undi;
|
struct undi_device *undi;
|
||||||
struct undi_rom *undirom;
|
struct undi_rom *undirom;
|
||||||
unsigned long rombase;
|
unsigned int busdevfn = ( ( pci->bus << 8 ) | pci->devfn );
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Ignore non-network devices */
|
/* Ignore non-network devices */
|
||||||
if ( PCI_BASE_CLASS ( pci->class ) != PCI_BASE_CLASS_NETWORK )
|
if ( PCI_BASE_CLASS ( pci->class ) != PCI_BASE_CLASS_NETWORK )
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
|
|
||||||
/* Try to find a driver for this device. Try an exact match
|
|
||||||
* on the ROM address first, then fall back to a vendor/device
|
|
||||||
* ID match only
|
|
||||||
*/
|
|
||||||
rombase = pci_bar_start ( pci, PCI_ROM_ADDRESS );
|
|
||||||
undirom = undirom_find_pci ( pci->vendor, pci->device, rombase );
|
|
||||||
if ( ! undirom )
|
|
||||||
undirom = undirom_find_pci ( pci->vendor, pci->device, 0 );
|
|
||||||
if ( ! undirom )
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
/* Allocate UNDI device structure */
|
/* Allocate UNDI device structure */
|
||||||
undi = malloc ( sizeof ( *undi ) );
|
undi = malloc ( sizeof ( *undi ) );
|
||||||
if ( ! undi )
|
if ( ! undi )
|
||||||
|
@ -67,16 +77,30 @@ static int undipci_probe ( struct pci_device *pci,
|
||||||
memset ( undi, 0, sizeof ( *undi ) );
|
memset ( undi, 0, sizeof ( *undi ) );
|
||||||
pci_set_drvdata ( pci, undi );
|
pci_set_drvdata ( pci, undi );
|
||||||
|
|
||||||
|
/* Find/create our pixie */
|
||||||
|
if ( preloaded_undi.pci_busdevfn == busdevfn ) {
|
||||||
|
/* Claim preloaded UNDI device */
|
||||||
|
DBGC ( undi, "UNDI %p using preloaded UNDI device\n", undi );
|
||||||
|
memcpy ( undi, &preloaded_undi, sizeof ( *undi ) );
|
||||||
|
memset ( &preloaded_undi, 0, sizeof ( preloaded_undi ) );
|
||||||
|
} else {
|
||||||
|
/* Find UNDI ROM for PCI device */
|
||||||
|
if ( ! ( undirom = undipci_find_rom ( pci ) ) ) {
|
||||||
|
rc = -ENODEV;
|
||||||
|
goto err_find_rom;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Call UNDI ROM loader to create pixie */
|
||||||
|
if ( ( rc = undi_load_pci ( undi, undirom, pci->bus,
|
||||||
|
pci->devfn ) ) != 0 )
|
||||||
|
goto err_load_pci;
|
||||||
|
}
|
||||||
|
|
||||||
/* Add to device hierarchy */
|
/* Add to device hierarchy */
|
||||||
undi->dev.parent = &pci->dev;
|
undi->dev.parent = &pci->dev;
|
||||||
INIT_LIST_HEAD ( &undi->dev.children );
|
INIT_LIST_HEAD ( &undi->dev.children );
|
||||||
list_add ( &undi->dev.siblings, &pci->dev.children );
|
list_add ( &undi->dev.siblings, &pci->dev.children );
|
||||||
|
|
||||||
/* Call UNDI ROM loader to create pixie */
|
|
||||||
if ( ( rc = undi_load_pci ( undi, undirom, pci->bus,
|
|
||||||
pci->devfn ) ) != 0 )
|
|
||||||
goto err_load_pci;
|
|
||||||
|
|
||||||
/* Create network device */
|
/* Create network device */
|
||||||
if ( ( rc = undinet_probe ( undi ) ) != 0 )
|
if ( ( rc = undinet_probe ( undi ) ) != 0 )
|
||||||
goto err_undinet_probe;
|
goto err_undinet_probe;
|
||||||
|
@ -85,8 +109,9 @@ static int undipci_probe ( struct pci_device *pci,
|
||||||
|
|
||||||
err_undinet_probe:
|
err_undinet_probe:
|
||||||
undi_unload ( undi );
|
undi_unload ( undi );
|
||||||
err_load_pci:
|
|
||||||
list_del ( &undi->dev.siblings );
|
list_del ( &undi->dev.siblings );
|
||||||
|
err_find_rom:
|
||||||
|
err_load_pci:
|
||||||
free ( undi );
|
free ( undi );
|
||||||
pci_set_drvdata ( pci, NULL );
|
pci_set_drvdata ( pci, NULL );
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Reference in New Issue