4 * Abstracted from 3c509.c.
17 static struct mca_driver mca_drivers[0]
18 __table_start ( struct mca_driver, mca_drivers );
19 static struct mca_driver mca_drivers_end[0]
20 __table_end ( struct mca_driver, mca_drivers );
22 static void mcabus_remove ( struct root_device *rootdev );
28 * @ret rc Return status code
30 * Searches for a driver for the MCA device. If a driver is found,
31 * its probe() routine is called.
33 static int mca_probe ( struct mca_device *mca ) {
34 struct mca_driver *driver;
35 struct mca_device_id *id;
39 DBG ( "Adding MCA slot %02x (ID %04x POS "
40 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x)\n",
41 mca->slot, MCA_ID ( mca ),
42 mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3],
43 mca->pos[4], mca->pos[5], mca->pos[6], mca->pos[7] );
45 for ( driver = mca_drivers; driver < mca_drivers_end; driver++ ){
46 for ( i = 0 ; i < driver->id_count ; i++ ) {
48 if ( id->id != MCA_ID ( mca ) )
51 mca->driver_name = id->name;
52 DBG ( "...using driver %s\n", mca->driver_name );
53 if ( ( rc = driver->probe ( mca, id ) ) != 0 ) {
54 DBG ( "......probe failed\n" );
61 DBG ( "...no driver found\n" );
66 * Remove an MCA device
70 static void mca_remove ( struct mca_device *mca ) {
71 mca->driver->remove ( mca );
72 DBG ( "Removed MCA device %02x\n", mca->slot );
78 * @v rootdev MCA bus root device
80 * Scans the MCA bus for devices and registers all devices it can
83 static int mcabus_probe ( struct root_device *rootdev ) {
84 struct mca_device *mca = NULL;
90 for ( slot = 0 ; slot <= MCA_MAX_SLOT_NR ; slot++ ) {
91 /* Allocate struct mca_device */
93 mca = malloc ( sizeof ( *mca ) );
98 memset ( mca, 0, sizeof ( *mca ) );
101 /* Make sure motherboard setup is off */
102 outb_p ( 0xff, MCA_MOTHERBOARD_SETUP_REG );
104 /* Select the slot */
105 outb_p ( 0x8 | ( mca->slot & 0xf ), MCA_ADAPTER_SETUP_REG );
107 /* Read the POS registers */
109 for ( i = 0 ; i < ( sizeof ( mca->pos ) /
110 sizeof ( mca->pos[0] ) ) ; i++ ) {
111 mca->pos[i] = inb_p ( MCA_POS_REG ( i ) );
112 if ( mca->pos[i] != 0xff )
116 /* Kill all setup modes */
117 outb_p ( 0, MCA_ADAPTER_SETUP_REG );
119 /* If all POS registers are 0xff, this means there's no device
125 /* Add to device hierarchy */
126 snprintf ( mca->dev.name, sizeof ( mca->dev.name ),
128 mca->dev.desc.bus_type = BUS_TYPE_MCA;
129 mca->dev.desc.vendor = GENERIC_MCA_VENDOR;
130 mca->dev.desc.device = MCA_ID ( mca );
131 mca->dev.parent = &rootdev->dev;
132 list_add ( &mca->dev.siblings, &rootdev->dev.children );
133 INIT_LIST_HEAD ( &mca->dev.children );
135 /* Look for a driver */
136 if ( mca_probe ( mca ) == 0 ) {
137 /* mcadev registered, we can drop our ref */
140 /* Not registered; re-use struct */
141 list_del ( &mca->dev.siblings );
150 mcabus_remove ( rootdev );
155 * Remove MCA root bus
157 * @v rootdev MCA bus root device
159 static void mcabus_remove ( struct root_device *rootdev ) {
160 struct mca_device *mca;
161 struct mca_device *tmp;
163 list_for_each_entry_safe ( mca, tmp, &rootdev->dev.children,
166 list_del ( &mca->dev.siblings );
171 /** MCA bus root device driver */
172 static struct root_driver mca_root_driver = {
173 .probe = mcabus_probe,
174 .remove = mcabus_remove,
177 /** MCA bus root device */
178 struct root_device mca_root_device __root_device = {
179 .dev = { .name = "MCA" },
180 .driver = &mca_root_driver,