david/ipxe
Archived
1
0
This repository has been archived on 2020-12-06. You can view files and clone it, but cannot push or open issues or pull requests.
ipxe/src/drivers/bus/mca.c

162 lines
3.8 KiB
C
Raw Normal View History

2005-04-13 04:59:13 +02:00
/*
* MCA bus driver code
*
* Abstracted from 3c509.c.
*
*/
2005-04-17 12:51:05 +02:00
#include "string.h"
2005-04-13 04:59:13 +02:00
#include "io.h"
2005-04-22 04:28:16 +02:00
#include "console.h"
#include "dev.h"
2005-04-13 04:59:13 +02:00
#include "mca.h"
/*
2005-04-22 04:28:16 +02:00
* Increment a bus_loc structure to the next possible MCA location.
* Leave the structure zeroed and return 0 if there are no more valid
* locations.
*
*/
2005-04-22 04:28:16 +02:00
static int mca_next_location ( struct bus_loc *bus_loc ) {
struct mca_loc *mca_loc = ( struct mca_loc * ) bus_loc;
/*
* Ensure that there is sufficient space in the shared bus
* structures for a struct mca_loc and a struct
* mca_dev, as mandated by bus.h.
*
*/
BUS_LOC_CHECK ( struct mca_loc );
BUS_DEV_CHECK ( struct mca_device );
2005-04-22 17:33:35 +02:00
return ( mca_loc->slot = ( ++mca_loc->slot & MCA_MAX_SLOT_NR ) );
2005-04-22 04:28:16 +02:00
}
2005-04-13 04:59:13 +02:00
/*
* Fill in parameters for an MCA device based on slot number
*
*/
2005-04-22 04:28:16 +02:00
static int mca_fill_device ( struct bus_dev *bus_dev,
struct bus_loc *bus_loc ) {
struct mca_loc *mca_loc = ( struct mca_loc * ) bus_loc;
struct mca_device *mca = ( struct mca_device * ) bus_dev;
2005-04-16 12:19:13 +02:00
unsigned int i, seen_non_ff;
2005-04-13 04:59:13 +02:00
2005-04-22 04:28:16 +02:00
/* Store slot in struct mca, set default values */
mca->slot = mca_loc->slot;
mca->name = "?";
2005-04-13 04:59:13 +02:00
/* Make sure motherboard setup is off */
outb_p ( 0xff, MCA_MOTHERBOARD_SETUP_REG );
/* Select the slot */
outb_p ( 0x8 | ( mca->slot & 0xf ), MCA_ADAPTER_SETUP_REG );
/* Read the POS registers */
2005-04-16 12:19:13 +02:00
seen_non_ff = 0;
2005-04-13 04:59:13 +02:00
for ( i = 0 ; i < ( sizeof ( mca->pos ) / sizeof ( mca->pos[0] ) ) ;
i++ ) {
mca->pos[i] = inb_p ( MCA_POS_REG ( i ) );
2005-04-16 12:19:13 +02:00
if ( mca->pos[i] != 0xff )
seen_non_ff = 1;
2005-04-13 04:59:13 +02:00
}
2005-04-16 12:19:13 +02:00
/* If all POS registers are 0xff, this means there's no device
* present
*/
if ( ! seen_non_ff )
return 0;
2005-04-13 04:59:13 +02:00
/* Kill all setup modes */
outb_p ( 0, MCA_ADAPTER_SETUP_REG );
DBG ( "MCA found slot %d id %hx "
"(POS %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx)\n",
2005-04-13 04:59:13 +02:00
mca->slot, MCA_ID ( mca ),
mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3],
mca->pos[4], mca->pos[5], mca->pos[6], mca->pos[7] );
return 1;
}
/*
2005-04-22 04:28:16 +02:00
* Test whether or not a driver is capable of driving the device.
2005-04-13 04:59:13 +02:00
*
*/
2005-04-22 04:28:16 +02:00
static int mca_check_driver ( struct bus_dev *bus_dev,
struct device_driver *device_driver ) {
struct mca_device *mca = ( struct mca_device * ) bus_dev;
struct mca_driver *driver
= ( struct mca_driver * ) device_driver->bus_driver_info;
unsigned int i;
2005-04-13 04:59:13 +02:00
2005-04-22 04:28:16 +02:00
/* Compare against driver's ID list */
for ( i = 0 ; i < driver->id_count ; i++ ) {
struct mca_id *id = &driver->ids[i];
if ( MCA_ID ( mca ) == id->id ) {
DBG ( "MCA found ID %hx (device %s) "
"matching driver %s\n",
2005-04-22 17:56:57 +02:00
id->name, id->id, device_driver->name );
2005-04-22 04:28:16 +02:00
mca->name = id->name;
return 1;
2005-04-13 04:59:13 +02:00
}
}
/* No device found */
return 0;
}
/*
2005-04-22 04:28:16 +02:00
* Describe an MCA device
*
*/
2005-04-25 20:54:15 +02:00
static char * mca_describe_device ( struct bus_dev *bus_dev ) {
2005-04-22 04:28:16 +02:00
struct mca_device *mca = ( struct mca_device * ) bus_dev;
static char mca_description[] = "MCA 00";
2005-04-22 04:28:16 +02:00
sprintf ( mca_description + 4, "%hhx", mca->slot );
return mca_description;
}
/*
* Name an MCA device
*
*/
2005-04-25 20:54:15 +02:00
static const char * mca_name_device ( struct bus_dev *bus_dev ) {
2005-04-22 04:28:16 +02:00
struct mca_device *mca = ( struct mca_device * ) bus_dev;
return mca->name;
}
2005-04-22 04:28:16 +02:00
/*
* MCA bus operations table
*
*/
struct bus_driver mca_driver __bus_driver = {
2005-04-25 20:54:15 +02:00
.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,
2005-04-22 04:28:16 +02:00
};
2005-04-22 04:28:16 +02:00
/*
* Fill in a nic structure
*
*/
2005-04-22 13:56:27 +02:00
void mca_fill_nic ( struct nic *nic, struct mca_device *mca ) {
2005-04-22 04:28:16 +02:00
/* ioaddr and irqno must be read in a device-dependent way
* from the POS registers
*/
nic->ioaddr = 0;
nic->irqno = 0;
/* Fill in DHCP device ID structure */
nic->dhcp_dev_id.bus_type = MCA_BUS_TYPE;
nic->dhcp_dev_id.vendor_id = htons ( GENERIC_MCA_VENDOR );
nic->dhcp_dev_id.device_id = htons ( MCA_ID ( mca ) );
}