david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Added "name" field to bus structure.

This commit is contained in:
Michael Brown 2005-04-25 18:54:15 +00:00
parent f972f256e6
commit 5bace628ae
7 changed files with 213 additions and 160 deletions

View File

@ -1,24 +1,17 @@
#include "realmode.h"
#include "isa_ids.h"
#include "console.h"
#include "disk.h"
#include "bios_disks.h"
#define CF ( 1 << 0 )
#define BIOS_DISK_NONE 0
/*
* Ensure that there is sufficient space in the shared dev_bus
* structure for a struct bios_disk_device.
*
*/
DEV_BUS( struct bios_disk_device, bios_disk_dev );
static char bios_disk_magic[0]; /* guaranteed unique symbol */
/*
* Reset the disk system using INT 13,0. Forces both hard disks and
* floppy disks to seek back to track 0.
*
*/
void bios_disk_init ( void ) {
static void bios_disk_init ( void ) {
REAL_EXEC ( rm_bios_disk_init,
"sti\n\t"
"xorw %%ax,%%ax\n\t"
@ -36,45 +29,82 @@ void bios_disk_init ( void ) {
* Read a single sector from a disk using INT 13,2.
*
* Returns the BIOS status code (%ah) - 0 indicates success.
* Automatically retries up to three times to allow time for floppy
* disks to spin up, calling bios_disk_init() after each failure.
*
*/
unsigned int bios_disk_read_once ( struct bios_disk_device *bios_disk,
unsigned int cylinder,
unsigned int head,
unsigned int sector,
struct bios_disk_sector *buf ) {
uint16_t basemem_buf, status, flags;
int discard_c, discard_d;
static unsigned int bios_disk_read ( struct bios_disk_device *bios_disk,
unsigned int cylinder,
unsigned int head,
unsigned int sector,
struct bios_disk_sector *buf ) {
uint16_t basemem_buf, ax, flags;
unsigned int status, discard_c, discard_d;
int retry = 3;
basemem_buf = BASEMEM_PARAMETER_INIT ( *buf );
REAL_EXEC ( rm_bios_disk_read,
"sti\n\t"
"movw $0x0201, %%ax\n\t" /* Read a single sector */
"int $0x13\n\t"
"pushfw\n\t"
"popw %%bx\n\t"
"cli\n\t",
4,
OUT_CONSTRAINTS ( "=a" ( status ), "=b" ( flags ),
"=c" ( discard_c ),
"=d" ( discard_d ) ),
IN_CONSTRAINTS ( "c" ( ( ( cylinder & 0xff ) << 8 ) |
( ( cylinder >> 8 ) & 0x3 ) |
sector ),
"d" ( ( head << 8 ) | bios_disk->drive ),
"b" ( basemem_buf ) ),
CLOBBER ( "ebp", "esi", "edi" ) );
do {
REAL_EXEC ( rm_bios_disk_read,
"sti\n\t"
"movw $0x0201, %%ax\n\t" /* Read a single sector */
"int $0x13\n\t"
"pushfw\n\t"
"popw %%bx\n\t"
"cli\n\t",
4,
OUT_CONSTRAINTS ( "=a" ( ax ), "=b" ( flags ),
"=c" ( discard_c ),
"=d" ( discard_d ) ),
IN_CONSTRAINTS ( "c" ( ( (cylinder & 0xff) << 8 ) |
( (cylinder >> 8) & 0x3 ) |
sector ),
"d" ( ( head << 8 ) |
bios_disk->drive ),
"b" ( basemem_buf ) ),
CLOBBER ( "ebp", "esi", "edi" ) );
status = ( flags & CF ) ? ( ax >> 8 ) : 0;
} while ( ( status != 0 ) && ( bios_disk_init(), retry-- ) );
BASEMEM_PARAMETER_DONE ( *buf );
return ( flags & CF ) ? ( status >> 8 ) : 0;
return status;
}
/*
* Increment a bus_loc structure to the next possible BIOS disk
* location. Leave the structure zeroed and return 0 if there are no
* more valid locations.
*
*/
static int bios_disk_next_location ( struct bus_loc *bus_loc ) {
struct bios_disk_loc *bios_disk_loc
= ( struct bios_disk_loc * ) bus_loc;
/*
* Ensure that there is sufficient space in the shared bus
* structures for a struct bios_disk_loc and a struct
* bios_disk_dev, as mandated by bus.h.
*
*/
BUS_LOC_CHECK ( struct bios_disk_loc );
BUS_DEV_CHECK ( struct bios_disk_device );
return ( ++bios_disk_loc->drive );
}
/*
* Fill in parameters for a BIOS disk device based on drive number
*
*/
static int fill_bios_disk_device ( struct bios_disk_device *bios_disk ) {
uint16_t type, flags;
static int bios_disk_fill_device ( struct bus_dev *bus_dev,
struct bus_loc *bus_loc ) {
struct bios_disk_loc *bios_disk_loc
= ( struct bios_disk_loc * ) bus_loc;
struct bios_disk_device *bios_disk
= ( struct bios_disk_device * ) bus_dev;
uint16_t flags;
/* Store drive in struct bios_disk_device */
bios_disk->drive = bios_disk_loc->drive;
REAL_EXEC ( rm_bios_disk_exists,
"sti\n\t"
@ -82,14 +112,15 @@ static int fill_bios_disk_device ( struct bios_disk_device *bios_disk ) {
"int $0x13\n\t"
"pushfw\n\t"
"popw %%dx\n\t"
"movb %%ah, %%al\n\t"
"cli\n\t",
2,
OUT_CONSTRAINTS ( "=a" ( type ), "=d" ( flags ) ),
OUT_CONSTRAINTS ( "=a" ( bios_disk->type ),
"=d" ( flags ) ),
IN_CONSTRAINTS ( "d" ( bios_disk->drive ) ),
CLOBBER ( "ebx", "ecx", "esi", "edi", "ebp" ) );
if ( ( flags & CF ) ||
( ( type >> 8 ) == BIOS_DISK_NONE ) )
if ( ( flags & CF ) || ( bios_disk->type == BIOS_DISK_NONE ) )
return 0;
DBG ( "BIOS disk found valid drive %hhx\n", bios_disk->drive );
@ -97,72 +128,72 @@ static int fill_bios_disk_device ( struct bios_disk_device *bios_disk ) {
}
/*
* Find a BIOS disk device matching the specified driver
* Test whether or not a driver is capable of driving the device.
*
*/
int find_bios_disk_device ( struct bios_disk_device *bios_disk,
struct bios_disk_driver *driver ) {
static int bios_disk_check_driver ( struct bus_dev *bus_dev,
struct device_driver *device_driver ) {
struct bios_disk_device *bios_disk
= ( struct bios_disk_device * ) bus_dev;
struct bios_disk_driver *driver
= ( struct bios_disk_driver * ) device_driver->bus_driver_info;
/* Initialise struct bios_disk if it's the first time it's been used.
*/
if ( bios_disk->magic != bios_disk_magic ) {
memset ( bios_disk, 0, sizeof ( *bios_disk ) );
bios_disk->magic = bios_disk_magic;
/* Compare against driver's valid ID range */
if ( ( bios_disk->drive >= driver->min_drive ) &&
( bios_disk->drive <= driver->max_drive ) ) {
driver->fill_drive_name ( bios_disk->name, bios_disk->drive );
DBG ( "BIOS disk found drive %hhx (\"%s\") "
"matching driver %s\n",
bios_disk->drive, bios_disk->name,
driver->name );
return 1;
}
/* Iterate through all possible BIOS drives, starting where we
* left off
*/
DBG ( "BIOS disk searching for device matching driver %s\n",
driver->name );
do {
/* If we've already used this device, skip it */
if ( bios_disk->already_tried ) {
bios_disk->already_tried = 0;
continue;
}
/* Fill in device parameters */
if ( ! fill_bios_disk_device ( bios_disk ) ) {
continue;
}
/* Compare against driver's valid ID range */
if ( ( bios_disk->drive >= driver->min_drive ) &&
( bios_disk->drive <= driver->max_drive ) ) {
driver->fill_drive_name ( bios_disk->drive,
bios_disk->name );
DBG ( "BIOS_DISK found drive %hhx (\"%s\") "
"matching driver %s\n",
bios_disk->drive, bios_disk->name,
driver->name );
bios_disk->already_tried = 1;
return 1;
}
} while ( ++bios_disk->drive );
/* No device found */
DBG ( "BIOS disk found no device matching driver %s\n", driver->name );
return 0;
}
/*
* Find the next MCA device that can be used to boot using the
* specified driver.
* Describe a BIOS disk device
*
*/
int find_bios_disk_boot_device ( struct dev *dev,
struct bios_disk_driver *driver ) {
static char * bios_disk_describe_device ( struct bus_dev *bus_dev ) {
struct bios_disk_device *bios_disk
= ( struct bios_disk_device * ) dev->bus;
= ( struct bios_disk_device * ) bus_dev;
static char bios_disk_description[] = "BIOS disk 00";
sprintf ( bios_disk_description + 10, "%hhx", bios_disk->drive );
return bios_disk_description;
}
/*
* Name a BIOS disk device
*
*/
static const char * bios_disk_name_device ( struct bus_dev *bus_dev ) {
struct bios_disk_device *bios_disk
= ( struct bios_disk_device * ) bus_dev;
return bios_disk->name;
}
/*
* BIOS disk bus operations table
*
*/
struct bus_driver bios_disk_driver __bus_driver = {
.name = "BIOS DISK",
.next_location = bios_disk_next_location,
.fill_device = bios_disk_fill_device,
.check_driver = bios_disk_check_driver,
.describe_device = bios_disk_describe_device,
.name_device = bios_disk_name_device,
};
/*
* Fill in a disk structure
*
*/
void bios_disk_fill_disk ( struct disk *disk __unused,
struct bios_disk_device *bios_disk __unused ) {
if ( ! find_bios_disk_device ( bios_disk, driver ) )
return 0;
dev->name = bios_disk->name;
dev->devid.bus_type = ISA_BUS_TYPE;
dev->devid.vendor_id = ISA_VENDOR ( 'D', 'S', 'K' );
dev->devid.device_id = bios_disk->drive;
return 1;
}

View File

@ -108,7 +108,7 @@ static int eisa_check_driver ( struct bus_dev *bus_dev,
* Describe an EISA device
*
*/
static char * eisa_describe ( struct bus_dev *bus_dev ) {
static char * eisa_describe_device ( struct bus_dev *bus_dev ) {
struct eisa_device *eisa = ( struct eisa_device * ) bus_dev;
static char eisa_description[] = "EISA 00";
@ -120,7 +120,7 @@ static char * eisa_describe ( struct bus_dev *bus_dev ) {
* Name an EISA device
*
*/
static const char * eisa_name ( struct bus_dev *bus_dev ) {
static const char * eisa_name_device ( struct bus_dev *bus_dev ) {
struct eisa_device *eisa = ( struct eisa_device * ) bus_dev;
return eisa->name;
@ -131,11 +131,12 @@ static const char * eisa_name ( struct bus_dev *bus_dev ) {
*
*/
struct bus_driver eisa_driver __bus_driver = {
.next_location = eisa_next_location,
.fill_device = eisa_fill_device,
.check_driver = eisa_check_driver,
.describe = eisa_describe,
.name = eisa_name,
.name = "EISA",
.next_location = eisa_next_location,
.fill_device = eisa_fill_device,
.check_driver = eisa_check_driver,
.describe_device = eisa_describe_device,
.name_device = eisa_name_device,
};
/*

View File

@ -126,7 +126,7 @@ int isa_check_driver ( struct bus_dev *bus_dev,
* Describe a ISA device
*
*/
static char * isa_describe ( struct bus_dev *bus_dev ) {
static char * isa_describe_device ( struct bus_dev *bus_dev ) {
struct isa_device *isa = ( struct isa_device * ) bus_dev;
static char isa_description[] = "ISA 0000";
@ -138,7 +138,7 @@ static char * isa_describe ( struct bus_dev *bus_dev ) {
* Name a ISA device
*
*/
static const char * isa_name ( struct bus_dev *bus_dev ) {
static const char * isa_name_device ( struct bus_dev *bus_dev ) {
struct isa_device *isa = ( struct isa_device * ) bus_dev;
return isa->name;
@ -149,11 +149,12 @@ static const char * isa_name ( struct bus_dev *bus_dev ) {
*
*/
struct bus_driver isa_driver __bus_driver = {
.next_location = isa_next_location,
.fill_device = isa_fill_device,
.check_driver = isa_check_driver,
.describe = isa_describe,
.name = isa_name,
.name = "ISA",
.next_location = isa_next_location,
.fill_device = isa_fill_device,
.check_driver = isa_check_driver,
.describe_device = isa_describe_device,
.name_device = isa_name_device,
};
/*

View File

@ -262,7 +262,7 @@ static int isapnp_find_tag ( uint8_t wanted_tag, uint8_t *buf ) {
uint8_t tag;
uint16_t len;
DBG ( "ISAPnP read tag" );
DBG2 ( "ISAPnP read tag" );
do {
tag = isapnp_peek_byte();
if ( ISAPNP_IS_SMALL_TAG ( tag ) ) {
@ -272,22 +272,23 @@ static int isapnp_find_tag ( uint8_t wanted_tag, uint8_t *buf ) {
len = isapnp_peek_byte() + ( isapnp_peek_byte() << 8 );
tag = ISAPNP_LARGE_TAG_NAME ( tag );
}
DBG ( " %hhx (%hhx)", tag, len );
DBG2 ( " %hhx (%hhx)", tag, len );
if ( tag == wanted_tag ) {
isapnp_peek ( buf, len );
DBG ( "\n" );
DBG2 ( "\n" );
return 1;
} else {
isapnp_peek ( NULL, len );
}
} while ( tag != ISAPNP_TAG_END );
DBG ( "\n" );
DBG2 ( "\n" );
return 0;
}
/*
* Try isolating ISAPnP cards at the current read port. Return the
* number of ISAPnP cards found.
* number of ISAPnP cards found. <0 indicates "try a new read port",
* 0 indicates "definitely no cards".
*
* The state diagram on page 18 (PDF page 24) of the PnP ISA spec
* gives the best overview of what happens here.
@ -295,7 +296,8 @@ static int isapnp_find_tag ( uint8_t wanted_tag, uint8_t *buf ) {
*/
static int isapnp_try_isolate ( void ) {
struct isapnp_identifier identifier;
unsigned int i, j, seen55aa;
unsigned int i, j;
unsigned int seen_55aa, seen_life;
unsigned int csn = 0;
uint16_t data;
uint8_t byte;
@ -336,7 +338,7 @@ static int isapnp_try_isolate ( void ) {
/* Read identifier serially via the ISAPnP read port. */
memset ( &identifier, 0, sizeof ( identifier ) );
seen55aa = 0;
seen_55aa = seen_life = 0;
for ( i = 0 ; i < 9 ; i++ ) {
byte = 0;
for ( j = 0 ; j < 8 ; j++ ) {
@ -345,18 +347,31 @@ static int isapnp_try_isolate ( void ) {
data = ( data << 8 ) | isapnp_read_data ();
isapnp_delay();
byte >>= 1;
if ( data == 0x55aa ) {
byte |= 0x80;
seen55aa = 1;
if ( data != 0xffff ) {
seen_life++;
if ( data == 0x55aa ) {
byte |= 0x80;
seen_55aa++;
}
}
}
( (char *) &identifier )[i] = byte;
}
/* If we didn't see any 55aa patterns, stop here */
if ( ! seen55aa ) {
DBG ( "ISAPnP saw %s signs of life\n",
csn ? "no futher" : "no" );
if ( ! seen_55aa ) {
if ( csn ) {
DBG ( "ISAPnP found no more cards\n" );
} else {
if ( seen_life ) {
DBG ( "ISAPnP saw life but no cards, "
"trying new read port\n" );
csn = -1;
} else {
DBG ( "ISAPnP saw no signs of life, "
"abandoning isolation\n" );
}
}
break;
}
@ -364,11 +379,12 @@ static int isapnp_try_isolate ( void ) {
if ( identifier.checksum != isapnp_checksum ( &identifier) ) {
DBG ( "ISAPnP found malformed card "
ISAPNP_CARD_ID_FMT "\n with checksum %hhx "
"(should be %hhx), abandoning isolation\n",
"(should be %hhx), trying new read port\n",
ISAPNP_CARD_ID_DATA ( &identifier ),
identifier.checksum,
isapnp_checksum ( &identifier) );
/* break; */
csn = -1;
break;
}
/* Give the device a CSN */
@ -391,8 +407,10 @@ static int isapnp_try_isolate ( void ) {
isapnp_wait_for_key ();
/* Return number of cards found */
DBG ( "ISAPnP found %d cards at read port %hx\n",
csn, isapnp_read_port );
if ( csn > 0 ) {
DBG ( "ISAPnP found %d cards at read port %hx\n",
csn, isapnp_read_port );
}
return csn;
}
@ -412,7 +430,7 @@ static void isapnp_isolate ( void ) {
continue;
/* If we detect any ISAPnP cards at this location, stop */
if ( isapnp_try_isolate () )
if ( isapnp_try_isolate () >= 0 )
return;
}
}
@ -486,7 +504,6 @@ static int isapnp_fill_device ( struct bus_dev *bus_dev,
/* Need to return 0 if no device exists at this CSN */
if ( identifier.vendor_id & 0x80 ) {
DBG ( "ISAPnP found no card %hhx\n", isapnp->csn );
cache.csn = isapnp->csn;
cache.first_nonexistent_logdev = 0;
return 0;
@ -497,10 +514,11 @@ static int isapnp_fill_device ( struct bus_dev *bus_dev,
if ( ! isapnp_find_tag ( ISAPNP_TAG_LOGDEVID,
( char * ) &logdevid ) ) {
/* No tag for this device */
DBG ( "ISAPnP found no device %hhx.%hhx on "
"card " ISAPNP_CARD_ID_FMT "\n",
isapnp->csn, isapnp->logdev,
ISAPNP_CARD_ID_DATA ( &identifier ) );
if ( isapnp->logdev == 0 ) {
DBG ( "ISAPnP found no device %hhx.0 on card "
ISAPNP_CARD_ID_FMT "\n", isapnp->csn,
ISAPNP_CARD_ID_DATA ( &identifier ) );
}
cache.csn = isapnp->csn;
cache.first_nonexistent_logdev = isapnp->logdev;
return 0;
@ -548,11 +566,9 @@ static int isapnp_check_driver ( struct bus_dev *bus_dev,
if ( ( isapnp->vendor_id == id->vendor_id ) &&
( ISA_PROD_ID ( isapnp->prod_id ) ==
ISA_PROD_ID ( id->prod_id ) ) ) {
DBG ( "ISAPnP found ID %hx:%hx "
"(\"%s\") (device %s) "
DBG ( "ISAPnP found ID %hx:%hx (\"%s\") (device %s) "
"matching driver %s\n",
isapnp->vendor_id,
isapnp->prod_id,
isapnp->vendor_id, isapnp->prod_id,
isa_id_string( isapnp->vendor_id,
isapnp->prod_id ),
id->name, device_driver->name );
@ -568,7 +584,7 @@ static int isapnp_check_driver ( struct bus_dev *bus_dev,
* Describe an ISAPnP device
*
*/
static char * isapnp_describe ( struct bus_dev *bus_dev ) {
static char * isapnp_describe_device ( struct bus_dev *bus_dev ) {
struct isapnp_device *isapnp = ( struct isapnp_device * ) bus_dev;
static char isapnp_description[] = "ISAPnP 00:00";
@ -581,7 +597,7 @@ static char * isapnp_describe ( struct bus_dev *bus_dev ) {
* Name an ISAPnP device
*
*/
static const char * isapnp_name ( struct bus_dev *bus_dev ) {
static const char * isapnp_name_device ( struct bus_dev *bus_dev ) {
struct isapnp_device *isapnp = ( struct isapnp_device * ) bus_dev;
return isapnp->name;
@ -592,11 +608,12 @@ static const char * isapnp_name ( struct bus_dev *bus_dev ) {
*
*/
struct bus_driver isapnp_driver __bus_driver = {
.next_location = isapnp_next_location,
.fill_device = isapnp_fill_device,
.check_driver = isapnp_check_driver,
.describe = isapnp_describe,
.name = isapnp_name,
.name = "ISAPnP",
.next_location = isapnp_next_location,
.fill_device = isapnp_fill_device,
.check_driver = isapnp_check_driver,
.describe_device = isapnp_describe_device,
.name_device = isapnp_name_device,
};
/*

View File

@ -110,7 +110,7 @@ static int mca_check_driver ( struct bus_dev *bus_dev,
* Describe an MCA device
*
*/
static char * mca_describe ( struct bus_dev *bus_dev ) {
static char * mca_describe_device ( struct bus_dev *bus_dev ) {
struct mca_device *mca = ( struct mca_device * ) bus_dev;
static char mca_description[] = "MCA 00";
@ -122,7 +122,7 @@ static char * mca_describe ( struct bus_dev *bus_dev ) {
* Name an MCA device
*
*/
static const char * mca_name ( struct bus_dev *bus_dev ) {
static const char * mca_name_device ( struct bus_dev *bus_dev ) {
struct mca_device *mca = ( struct mca_device * ) bus_dev;
return mca->name;
@ -133,11 +133,12 @@ static const char * mca_name ( struct bus_dev *bus_dev ) {
*
*/
struct bus_driver mca_driver __bus_driver = {
.next_location = mca_next_location,
.fill_device = mca_fill_device,
.check_driver = mca_check_driver,
.describe = mca_describe,
.name = mca_name,
.name = "MCA",
.next_location = mca_next_location,
.fill_device = mca_fill_device,
.check_driver = mca_check_driver,
.describe_device = mca_describe_device,
.name_device = mca_name_device,
};
/*

View File

@ -179,7 +179,7 @@ static int pci_check_driver ( struct bus_dev *bus_dev,
* Describe a PCI device
*
*/
static char * pci_describe ( struct bus_dev *bus_dev ) {
static char * pci_describe_device ( struct bus_dev *bus_dev ) {
struct pci_device *pci = ( struct pci_device * ) bus_dev;
static char pci_description[] = "PCI 00:00.0";
@ -193,7 +193,7 @@ static char * pci_describe ( struct bus_dev *bus_dev ) {
* Name a PCI device
*
*/
static const char * pci_name ( struct bus_dev *bus_dev ) {
static const char * pci_name_device ( struct bus_dev *bus_dev ) {
struct pci_device *pci = ( struct pci_device * ) bus_dev;
return pci->name;
@ -204,11 +204,12 @@ static const char * pci_name ( struct bus_dev *bus_dev ) {
*
*/
struct bus_driver pci_driver __bus_driver = {
.next_location = pci_next_location,
.fill_device = pci_fill_device,
.check_driver = pci_check_driver,
.describe = pci_describe,
.name = pci_name,
.name = "PCI",
.next_location = pci_next_location,
.fill_device = pci_fill_device,
.check_driver = pci_check_driver,
.describe_device = pci_describe_device,
.name_device = pci_name_device,
};
/*

View File

@ -148,13 +148,14 @@ struct bus_dev {
*
*/
struct bus_driver {
const char *name;
int ( *next_location ) ( struct bus_loc *bus_loc );
int ( *fill_device ) ( struct bus_dev *bus_dev,
struct bus_loc *bus_loc );
int ( *check_driver ) ( struct bus_dev *bus_dev,
struct device_driver *device_driver );
char * ( *describe ) ( struct bus_dev *bus_dev );
const char * ( *name ) ( struct bus_dev *bus_dev );
char * ( *describe_device ) ( struct bus_dev *bus_dev );
const char * ( *name_device ) ( struct bus_dev *bus_dev );
};
#define __bus_driver __attribute__ (( used, __section__ ( ".drivers.bus" ) ))