2 * linux/arch/i386/kernel/mca.c
3 * Written by Martin Kolinek, February 1996
7 * Chris Beauregard July 28th, 1996
8 * - Fixed up integrated SCSI detection
10 * Chris Beauregard August 3rd, 1996
11 * - Made mca_info local
12 * - Made integrated registers accessible through standard function calls
14 * - More sanity checking
16 * Chris Beauregard August 9th, 1996
19 * Chris Beauregard January 7th, 1997
20 * - Added basic NMI-processing
21 * - Added more information to mca_info structure
23 * David Weinehall October 12th, 1998
24 * - Made a lot of cleaning up in the source
25 * - Added use of save_flags / restore_flags
26 * - Added the 'driver_loaded' flag in MCA_adapter
27 * - Added an alternative implemention of ZP Gu's mca_find_unused_adapter
29 * David Weinehall March 24th, 1999
30 * - Fixed the output of 'Driver Installed' in /proc/mca/pos
31 * - Made the Integrated Video & SCSI show up even if they have id 0000
33 * Alexander Viro November 9th, 1999
34 * - Switched to regular procfs methods
36 * Alfred Arnold & David Weinehall August 23rd, 2000
37 * - Added support for Planar POS-registers
40 #include <linux/module.h>
41 #include <linux/types.h>
42 #include <linux/errno.h>
43 #include <linux/kernel.h>
44 #include <linux/mca.h>
45 #include <asm/system.h>
47 #include <linux/proc_fs.h>
48 #include <linux/mman.h>
49 #include <linux/config.h>
51 #include <linux/pagemap.h>
52 #include <linux/ioport.h>
53 #include <asm/uaccess.h>
54 #include <linux/init.h>
55 #include <asm/arch_hooks.h>
57 static unsigned char which_scsi = 0;
60 * Motherboard register spinlock. Untested on SMP at the moment, but
61 * are there any MCA SMP boxes?
65 spinlock_t mca_lock = SPIN_LOCK_UNLOCKED;
67 /* Build the status info for the adapter */
69 static void mca_configure_adapter_status(struct mca_device *mca_dev) {
70 mca_dev->status = MCA_ADAPTER_NONE;
72 mca_dev->pos_id = mca_dev->pos[0]
73 + (mca_dev->pos[1] << 8);
75 if(!mca_dev->pos_id && mca_dev->slot < MCA_MAX_SLOT_NR) {
77 /* id = 0x0000 usually indicates hardware failure,
78 * however, ZP Gu (zpg@castle.net> reports that his 9556
79 * has 0x0000 as id and everything still works. There
80 * also seem to be an adapter with id = 0x0000; the
81 * NCR Parallel Bus Memory Card. Until this is confirmed,
82 * however, this code will stay.
85 mca_dev->status = MCA_ADAPTER_ERROR;
88 } else if(mca_dev->pos_id != 0xffff) {
90 /* 0xffff usually indicates that there's no adapter,
91 * however, some integrated adapters may have 0xffff as
92 * their id and still be valid. Examples are on-board
93 * VGA of the 55sx, the integrated SCSI of the 56 & 57,
94 * and possibly also the 95 ULTIMEDIA.
97 mca_dev->status = MCA_ADAPTER_NORMAL;
100 if((mca_dev->pos_id == 0xffff ||
101 mca_dev->pos_id == 0x0000) && mca_dev->slot >= MCA_MAX_SLOT_NR) {
104 for(j = 2; j < 8; j++) {
105 if(mca_dev->pos[j] != 0xff) {
106 mca_dev->status = MCA_ADAPTER_NORMAL;
112 if(!(mca_dev->pos[2] & MCA_ENABLED)) {
114 /* enabled bit is in POS 2 */
116 mca_dev->status = MCA_ADAPTER_DISABLED;
118 } /* mca_configure_adapter_status */
120 /*--------------------------------------------------------------------*/
122 struct resource mca_standard_resources[] = {
123 { "system control port B (MCA)", 0x60, 0x60 },
124 { "arbitration (MCA)", 0x90, 0x90 },
125 { "card Select Feedback (MCA)", 0x91, 0x91 },
126 { "system Control port A (MCA)", 0x92, 0x92 },
127 { "system board setup (MCA)", 0x94, 0x94 },
128 { "POS (MCA)", 0x96, 0x97 },
129 { "POS (MCA)", 0x100, 0x107 }
132 #define MCA_STANDARD_RESOURCES (sizeof(mca_standard_resources)/sizeof(struct resource))
135 * mca_read_and_store_pos - read the POS registers into a memory buffer
136 * @pos: a char pointer to 8 bytes, contains the POS register value on
139 * Returns 1 if a card actually exists (i.e. the pos isn't
140 * all 0xff) or 0 otherwise
142 static int mca_read_and_store_pos(unsigned char *pos) {
147 if((pos[j] = inb_p(MCA_POS_REG(j))) != 0xff) {
148 /* 0xff all across means no device. 0x00 means
149 * something's broken, but a device is
150 * probably there. However, if you get 0x00
151 * from a motherboard register it won't matter
152 * what we find. For the record, on the
153 * 57SLC, the integrated SCSI adapter has
154 * 0xffff for the adapter ID, but nonzero for
155 * other registers. */
163 static unsigned char mca_pc_read_pos(struct mca_device *mca_dev, int reg)
168 if(reg < 0 || reg >= 8)
171 spin_lock_irqsave(&mca_lock, flags);
172 if(mca_dev->pos_register) {
173 /* Disable adapter setup, enable motherboard setup */
175 outb_p(0, MCA_ADAPTER_SETUP_REG);
176 outb_p(mca_dev->pos_register, MCA_MOTHERBOARD_SETUP_REG);
178 byte = inb_p(MCA_POS_REG(reg));
179 outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
182 /* Make sure motherboard setup is off */
184 outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
186 /* Read the appropriate register */
188 outb_p(0x8|(mca_dev->slot & 0xf), MCA_ADAPTER_SETUP_REG);
189 byte = inb_p(MCA_POS_REG(reg));
190 outb_p(0, MCA_ADAPTER_SETUP_REG);
192 spin_unlock_irqrestore(&mca_lock, flags);
194 mca_dev->pos[reg] = byte;
199 static void mca_pc_write_pos(struct mca_device *mca_dev, int reg,
204 if(reg < 0 || reg >= 8)
207 spin_lock_irqsave(&mca_lock, flags);
209 /* Make sure motherboard setup is off */
211 outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
213 /* Read in the appropriate register */
215 outb_p(0x8|(mca_dev->slot&0xf), MCA_ADAPTER_SETUP_REG);
216 outb_p(byte, MCA_POS_REG(reg));
217 outb_p(0, MCA_ADAPTER_SETUP_REG);
219 spin_unlock_irqrestore(&mca_lock, flags);
221 /* Update the global register list, while we have the byte */
223 mca_dev->pos[reg] = byte;
227 /* for the primary MCA bus, we have identity transforms */
228 static int mca_dummy_transform_irq(struct mca_device * mca_dev, int irq)
233 static int mca_dummy_transform_ioport(struct mca_device * mca_dev, int port)
238 static void *mca_dummy_transform_memory(struct mca_device * mca_dev, void *mem)
244 static int __init mca_init(void)
247 struct mca_device *mca_dev;
248 unsigned char pos[8];
249 short mca_builtin_scsi_ports[] = {0xf7, 0xfd, 0x00};
252 /* WARNING: Be careful when making changes here. Putting an adapter
253 * and the motherboard simultaneously into setup mode may result in
254 * damage to chips (according to The Indispensible PC Hardware Book
255 * by Hans-Peter Messmer). Also, we disable system interrupts (so
256 * that we are not disturbed in the middle of this).
259 /* Make sure the MCA bus is present */
261 if (mca_system_init()) {
262 printk(KERN_ERR "MCA bus system initialisation failed\n");
269 printk(KERN_INFO "Micro Channel bus detected.\n");
271 /* All MCA systems have at least a primary bus */
272 bus = mca_attach_bus(MCA_PRIMARY_BUS);
275 bus->default_dma_mask = 0xffffffffLL;
276 bus->f.mca_write_pos = mca_pc_write_pos;
277 bus->f.mca_read_pos = mca_pc_read_pos;
278 bus->f.mca_transform_irq = mca_dummy_transform_irq;
279 bus->f.mca_transform_ioport = mca_dummy_transform_ioport;
280 bus->f.mca_transform_memory = mca_dummy_transform_memory;
282 /* get the motherboard device */
283 mca_dev = kmalloc(sizeof(struct mca_device), GFP_KERNEL);
284 if(unlikely(!mca_dev))
286 memset(mca_dev, 0, sizeof(struct mca_device));
289 * We do not expect many MCA interrupts during initialization,
290 * but let us be safe:
292 spin_lock_irq(&mca_lock);
294 /* Make sure adapter setup is off */
296 outb_p(0, MCA_ADAPTER_SETUP_REG);
298 /* Read motherboard POS registers */
300 mca_dev->pos_register = 0x7f;
301 outb_p(mca_dev->pos_register, MCA_MOTHERBOARD_SETUP_REG);
302 mca_dev->name[0] = 0;
303 mca_read_and_store_pos(mca_dev->pos);
304 mca_configure_adapter_status(mca_dev);
305 /* fake POS and slot for a motherboard */
306 mca_dev->pos_id = MCA_MOTHERBOARD_POS;
307 mca_dev->slot = MCA_MOTHERBOARD;
308 mca_register_device(MCA_PRIMARY_BUS, mca_dev);
310 mca_dev = kmalloc(sizeof(struct mca_device), GFP_ATOMIC);
311 if(unlikely(!mca_dev))
312 goto out_unlock_nomem;
313 memset(mca_dev, 0, sizeof(struct mca_device));
316 /* Put motherboard into video setup mode, read integrated video
317 * POS registers, and turn motherboard setup off.
320 mca_dev->pos_register = 0xdf;
321 outb_p(mca_dev->pos_register, MCA_MOTHERBOARD_SETUP_REG);
322 mca_dev->name[0] = 0;
323 mca_read_and_store_pos(mca_dev->pos);
324 mca_configure_adapter_status(mca_dev);
325 /* fake POS and slot for the integrated video */
326 mca_dev->pos_id = MCA_INTEGVIDEO_POS;
327 mca_dev->slot = MCA_INTEGVIDEO;
328 mca_register_device(MCA_PRIMARY_BUS, mca_dev);
330 /* Put motherboard into scsi setup mode, read integrated scsi
331 * POS registers, and turn motherboard setup off.
333 * It seems there are two possible SCSI registers. Martin says that
334 * for the 56,57, 0xf7 is the one, but fails on the 76.
335 * Alfredo (apena@vnet.ibm.com) says
336 * 0xfd works on his machine. We'll try both of them. I figure it's
337 * a good bet that only one could be valid at a time. This could
338 * screw up though if one is used for something else on the other
342 for(i = 0; (which_scsi = mca_builtin_scsi_ports[i]) != 0; i++) {
343 outb_p(which_scsi, MCA_MOTHERBOARD_SETUP_REG);
344 if(mca_read_and_store_pos(pos))
348 /* found a scsi card */
349 mca_dev = kmalloc(sizeof(struct mca_device), GFP_ATOMIC);
350 if(unlikely(!mca_dev))
351 goto out_unlock_nomem;
352 memset(mca_dev, 0, sizeof(struct mca_device));
354 for(j = 0; j < 8; j++)
355 mca_dev->pos[j] = pos[j];
357 mca_configure_adapter_status(mca_dev);
358 /* fake POS and slot for integrated SCSI controller */
359 mca_dev->pos_id = MCA_INTEGSCSI_POS;
360 mca_dev->slot = MCA_INTEGSCSI;
361 mca_dev->pos_register = which_scsi;
362 mca_register_device(MCA_PRIMARY_BUS, mca_dev);
365 /* Turn off motherboard setup */
367 outb_p(0xff, MCA_MOTHERBOARD_SETUP_REG);
369 /* Now loop over MCA slots: put each adapter into setup mode, and
370 * read its POS registers. Then put adapter setup off.
373 for(i=0; i<MCA_MAX_SLOT_NR; i++) {
374 outb_p(0x8|(i&0xf), MCA_ADAPTER_SETUP_REG);
375 if(!mca_read_and_store_pos(pos))
378 mca_dev = kmalloc(sizeof(struct mca_device), GFP_ATOMIC);
379 if(unlikely(!mca_dev))
380 goto out_unlock_nomem;
381 memset(mca_dev, 0, sizeof(struct mca_device));
384 mca_dev->pos[j]=pos[j];
386 mca_dev->driver_loaded = 0;
388 mca_dev->pos_register = 0;
389 mca_configure_adapter_status(mca_dev);
390 mca_register_device(MCA_PRIMARY_BUS, mca_dev);
392 outb_p(0, MCA_ADAPTER_SETUP_REG);
394 /* Enable interrupts and return memory start */
395 spin_unlock_irq(&mca_lock);
397 for (i = 0; i < MCA_STANDARD_RESOURCES; i++)
398 request_resource(&ioport_resource, mca_standard_resources + i);
405 spin_unlock_irq(&mca_lock);
407 printk(KERN_EMERG "Failed memory allocation in MCA setup!\n");
411 subsys_initcall(mca_init);
413 /*--------------------------------------------------------------------*/
415 static void mca_handle_nmi_device(struct mca_device *mca_dev, int check_flag)
417 int slot = mca_dev->slot;
419 if(slot == MCA_INTEGSCSI) {
420 printk(KERN_CRIT "NMI: caused by MCA integrated SCSI adapter (%s)\n",
422 } else if(slot == MCA_INTEGVIDEO) {
423 printk(KERN_CRIT "NMI: caused by MCA integrated video adapter (%s)\n",
425 } else if(slot == MCA_MOTHERBOARD) {
426 printk(KERN_CRIT "NMI: caused by motherboard (%s)\n",
430 /* More info available in POS 6 and 7? */
433 unsigned char pos6, pos7;
435 pos6 = mca_device_read_pos(mca_dev, 6);
436 pos7 = mca_device_read_pos(mca_dev, 7);
438 printk(KERN_CRIT "NMI: POS 6 = 0x%x, POS 7 = 0x%x\n", pos6, pos7);
441 } /* mca_handle_nmi_slot */
443 /*--------------------------------------------------------------------*/
445 static int mca_handle_nmi_callback(struct device *dev, void *data)
447 struct mca_device *mca_dev = to_mca_device(dev);
450 pos5 = mca_device_read_pos(mca_dev, 5);
453 /* Bit 7 of POS 5 is reset when this adapter has a hardware
454 * error. Bit 7 it reset if there's error information
455 * available in POS 6 and 7.
457 mca_handle_nmi_device(mca_dev, !(pos5 & 0x40));
463 void mca_handle_nmi(void)
465 /* First try - scan the various adapters and see if a specific
466 * adapter was responsible for the error.
468 bus_for_each_dev(&mca_bus_type, NULL, NULL, mca_handle_nmi_callback);
471 } /* mca_handle_nmi */