4 * Abstracted from 3c509.c.
16 static struct mca_driver mca_drivers[0]
17 __table_start ( struct mca_driver, mca_drivers );
18 static struct mca_driver mca_drivers_end[0]
19 __table_end ( struct mca_driver, mca_drivers );
21 static void mcabus_remove ( struct root_device *rootdev );
27 * @ret rc Return status code
29 * Searches for a driver for the MCA device. If a driver is found,
30 * its probe() routine is called.
32 static int mca_probe ( struct mca_device *mca ) {
33 struct mca_driver *driver;
34 struct mca_device_id *id;
38 DBG ( "Adding MCA slot %02x (ID %04x POS "
39 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x)\n",
40 mca->slot, MCA_ID ( mca ),
41 mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3],
42 mca->pos[4], mca->pos[5], mca->pos[6], mca->pos[7] );
44 for ( driver = mca_drivers; driver < mca_drivers_end; driver++ ){
45 for ( i = 0 ; i < driver->id_count ; i++ ) {
47 if ( id->id != MCA_ID ( mca ) )
50 mca->driver_name = id->name;
51 DBG ( "...using driver %s\n", mca->driver_name );
52 if ( ( rc = driver->probe ( mca, id ) ) != 0 ) {
53 DBG ( "......probe failed\n" );
60 DBG ( "...no driver found\n" );
65 * Remove an MCA device
69 static void mca_remove ( struct mca_device *mca ) {
70 mca->driver->remove ( mca );
71 DBG ( "Removed MCA device %02x\n", mca->slot );
77 * @v rootdev MCA bus root device
79 * Scans the MCA bus for devices and registers all devices it can
82 static int mcabus_probe ( struct root_device *rootdev ) {
83 struct mca_device *mca = NULL;
89 for ( slot = 0 ; slot <= MCA_MAX_SLOT_NR ; slot++ ) {
90 /* Allocate struct mca_device */
92 mca = malloc ( sizeof ( *mca ) );
97 memset ( mca, 0, sizeof ( *mca ) );
100 /* Make sure motherboard setup is off */
101 outb_p ( 0xff, MCA_MOTHERBOARD_SETUP_REG );
103 /* Select the slot */
104 outb_p ( 0x8 | ( mca->slot & 0xf ), MCA_ADAPTER_SETUP_REG );
106 /* Read the POS registers */
108 for ( i = 0 ; i < ( sizeof ( mca->pos ) /
109 sizeof ( mca->pos[0] ) ) ; i++ ) {
110 mca->pos[i] = inb_p ( MCA_POS_REG ( i ) );
111 if ( mca->pos[i] != 0xff )
115 /* Kill all setup modes */
116 outb_p ( 0, MCA_ADAPTER_SETUP_REG );
118 /* If all POS registers are 0xff, this means there's no device
124 /* Add to device hierarchy */
125 snprintf ( mca->dev.name, sizeof ( mca->dev.name ),
127 mca->dev.desc.bus_type = BUS_TYPE_MCA;
128 mca->dev.desc.vendor = GENERIC_MCA_VENDOR;
129 mca->dev.desc.device = MCA_ID ( mca );
130 mca->dev.parent = &rootdev->dev;
131 list_add ( &mca->dev.siblings, &rootdev->dev.children );
132 INIT_LIST_HEAD ( &mca->dev.children );
134 /* Look for a driver */
135 if ( mca_probe ( mca ) == 0 ) {
136 /* mcadev registered, we can drop our ref */
139 /* Not registered; re-use struct */
140 list_del ( &mca->dev.siblings );
149 mcabus_remove ( rootdev );
154 * Remove MCA root bus
156 * @v rootdev MCA bus root device
158 static void mcabus_remove ( struct root_device *rootdev ) {
159 struct mca_device *mca;
160 struct mca_device *tmp;
162 list_for_each_entry_safe ( mca, tmp, &rootdev->dev.children,
165 list_del ( &mca->dev.siblings );
170 /** MCA bus root device driver */
171 static struct root_driver mca_root_driver = {
172 .probe = mcabus_probe,
173 .remove = mcabus_remove,
176 /** MCA bus root device */
177 struct root_device mca_root_device __root_device = {
178 .dev = { .name = "MCA" },
179 .driver = &mca_root_driver,