Import 2.3.25pre1
[davej-history.git] / drivers / block / ide-probe.c
blobd430c5b1d97a817afe5c9f0776e502f004e8b923
1 /*
2 * linux/drivers/block/ide-probe.c Version 1.05 July 3, 1999
4 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
5 */
7 /*
8 * Mostly written by Mark Lord <mlord@pobox.com>
9 * and Gadi Oxman <gadio@netvision.net.il>
11 * See linux/MAINTAINERS for address of current maintainer.
13 * This is the IDE probe module, as evolved from hd.c and ide.c.
15 * Version 1.00 move drive probing code from ide.c to ide-probe.c
16 * Version 1.01 fix compilation problem for m68k
17 * Version 1.02 increase WAIT_PIDENTIFY to avoid CD-ROM locking at boot
18 * by Andrea Arcangeli
19 * Version 1.03 fix for (hwif->chipset == ide_4drives)
20 * Version 1.04 fixed buggy treatments of known flash memory cards
22 * Version 1.05 fix for (hwif->chipset == ide_pdc4030)
23 * added ide6/7/8/9
24 * allowed for secondary flash card to be detectable
25 * with new flag : drive->ata_flash : 1;
28 #undef REALLY_SLOW_IO /* most systems can safely undef this */
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/types.h>
33 #include <linux/string.h>
34 #include <linux/kernel.h>
35 #include <linux/timer.h>
36 #include <linux/mm.h>
37 #include <linux/interrupt.h>
38 #include <linux/major.h>
39 #include <linux/errno.h>
40 #include <linux/genhd.h>
41 #include <linux/malloc.h>
42 #include <linux/delay.h>
43 #include <linux/ide.h>
45 #include <asm/byteorder.h>
46 #include <asm/irq.h>
47 #include <asm/uaccess.h>
48 #include <asm/io.h>
50 static inline void do_identify (ide_drive_t *drive, byte cmd)
52 int bswap = 1;
53 struct hd_driveid *id;
55 id = drive->id = kmalloc (SECTOR_WORDS*4, GFP_ATOMIC); /* called with interrupts disabled! */
56 ide_input_data(drive, id, SECTOR_WORDS); /* read 512 bytes of id info */
57 ide__sti(); /* local CPU only */
58 ide_fix_driveid(id);
60 #if defined (CONFIG_SCSI_EATA_DMA) || defined (CONFIG_SCSI_EATA_PIO) || defined (CONFIG_SCSI_EATA)
62 * EATA SCSI controllers do a hardware ATA emulation:
63 * Ignore them if there is a driver for them available.
65 if ((id->model[0] == 'P' && id->model[1] == 'M')
66 || (id->model[0] == 'S' && id->model[1] == 'K')) {
67 printk("%s: EATA SCSI HBA %.10s\n", drive->name, id->model);
68 drive->present = 0;
69 return;
71 #endif /* CONFIG_SCSI_EATA_DMA || CONFIG_SCSI_EATA_PIO */
74 * WIN_IDENTIFY returns little-endian info,
75 * WIN_PIDENTIFY *usually* returns little-endian info.
77 if (cmd == WIN_PIDENTIFY) {
78 if ((id->model[0] == 'N' && id->model[1] == 'E') /* NEC */
79 || (id->model[0] == 'F' && id->model[1] == 'X') /* Mitsumi */
80 || (id->model[0] == 'P' && id->model[1] == 'i'))/* Pioneer */
81 bswap ^= 1; /* Vertos drives may still be weird */
83 ide_fixstring (id->model, sizeof(id->model), bswap);
84 ide_fixstring (id->fw_rev, sizeof(id->fw_rev), bswap);
85 ide_fixstring (id->serial_no, sizeof(id->serial_no), bswap);
87 if (strstr(id->model, "E X A B Y T E N E S T"))
88 return;
90 id->model[sizeof(id->model)-1] = '\0'; /* we depend on this a lot! */
91 printk("%s: %s, ", drive->name, id->model);
92 drive->present = 1;
95 * Check for an ATAPI device
97 if (cmd == WIN_PIDENTIFY) {
98 byte type = (id->config >> 8) & 0x1f;
99 printk("ATAPI ");
100 #ifdef CONFIG_BLK_DEV_PDC4030
101 if (HWIF(drive)->channel == 1 && HWIF(drive)->chipset == ide_pdc4030) {
102 printk(" -- not supported on 2nd Promise port\n");
103 drive->present = 0;
104 return;
106 #endif /* CONFIG_BLK_DEV_PDC4030 */
107 switch (type) {
108 case ide_floppy:
109 if (!strstr(id->model, "CD-ROM")) {
110 if (!strstr(id->model, "oppy") && !strstr(id->model, "poyp") && !strstr(id->model, "ZIP"))
111 printk("cdrom or floppy?, assuming ");
112 if (drive->media != ide_cdrom) {
113 printk ("FLOPPY");
114 break;
117 type = ide_cdrom; /* Early cdrom models used zero */
118 case ide_cdrom:
119 printk ("CDROM");
120 drive->removable = 1;
121 break;
122 case ide_tape:
123 printk ("TAPE");
124 break;
125 case ide_optical:
126 printk ("OPTICAL");
127 drive->removable = 1;
128 break;
129 default:
130 printk("UNKNOWN (type %d)", type);
131 break;
133 printk (" drive\n");
134 drive->media = type;
135 return;
139 * Not an ATAPI device: looks like a "regular" hard disk
141 if (id->config & (1<<7))
142 drive->removable = 1;
144 * Prevent long system lockup probing later for non-existant
145 * slave drive if the hwif is actually a flash memory card of some variety:
147 if (drive_is_flashcard(drive)) {
148 ide_drive_t *mate = &HWIF(drive)->drives[1^drive->select.b.unit];
149 if (!mate->ata_flash) {
150 mate->present = 0;
151 mate->noprobe = 1;
154 drive->media = ide_disk;
155 printk("ATA DISK drive\n");
156 return;
160 * try_to_identify() sends an ATA(PI) IDENTIFY request to a drive
161 * and waits for a response. It also monitors irqs while this is
162 * happening, in hope of automatically determining which one is
163 * being used by the interface.
165 * Returns: 0 device was identified
166 * 1 device timed-out (no response to identify request)
167 * 2 device aborted the command (refused to identify itself)
169 static int try_to_identify (ide_drive_t *drive, byte cmd)
171 int rc;
172 ide_ioreg_t hd_status;
173 unsigned long timeout;
174 unsigned long irqs = 0;
175 byte s, a;
177 if (IDE_CONTROL_REG) {
178 if (!HWIF(drive)->irq) { /* already got an IRQ? */
179 probe_irq_off(probe_irq_on()); /* clear dangling irqs */
180 irqs = probe_irq_on(); /* start monitoring irqs */
181 OUT_BYTE(drive->ctl,IDE_CONTROL_REG); /* enable device irq */
184 ide_delay_50ms(); /* take a deep breath */
185 a = IN_BYTE(IDE_ALTSTATUS_REG);
186 s = IN_BYTE(IDE_STATUS_REG);
187 if ((a ^ s) & ~INDEX_STAT) {
188 printk("%s: probing with STATUS(0x%02x) instead of ALTSTATUS(0x%02x)\n", drive->name, s, a);
189 hd_status = IDE_STATUS_REG; /* ancient Seagate drives, broken interfaces */
190 } else {
191 hd_status = IDE_ALTSTATUS_REG; /* use non-intrusive polling */
193 } else {
194 ide_delay_50ms();
195 hd_status = IDE_STATUS_REG;
198 #if CONFIG_BLK_DEV_PDC4030
199 if (HWIF(drive)->chipset == ide_pdc4030) {
200 /* DC4030 hosted drives need their own identify... */
201 extern int pdc4030_identify(ide_drive_t *);
202 if (pdc4030_identify(drive)) {
203 if (irqs)
204 (void) probe_irq_off(irqs);
205 return 1;
207 } else
208 #endif /* CONFIG_BLK_DEV_PDC4030 */
209 OUT_BYTE(cmd,IDE_COMMAND_REG); /* ask drive for ID */
210 timeout = ((cmd == WIN_IDENTIFY) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
211 timeout += jiffies;
212 do {
213 if (0 < (signed long)(jiffies - timeout)) {
214 if (irqs)
215 (void) probe_irq_off(irqs);
216 return 1; /* drive timed-out */
218 ide_delay_50ms(); /* give drive a breather */
219 } while (IN_BYTE(hd_status) & BUSY_STAT);
221 ide_delay_50ms(); /* wait for IRQ and DRQ_STAT */
222 if (OK_STAT(GET_STAT(),DRQ_STAT,BAD_R_STAT)) {
223 unsigned long flags;
224 __save_flags(flags); /* local CPU only */
225 __cli(); /* local CPU only; some systems need this */
226 do_identify(drive, cmd); /* drive returned ID */
227 rc = 0; /* drive responded with ID */
228 (void) GET_STAT(); /* clear drive IRQ */
229 __restore_flags(flags); /* local CPU only */
230 } else
231 rc = 2; /* drive refused ID */
232 if (IDE_CONTROL_REG && !HWIF(drive)->irq) {
233 irqs = probe_irq_off(irqs); /* get our irq number */
234 if (irqs > 0) {
235 HWIF(drive)->irq = irqs; /* save it for later */
236 irqs = probe_irq_on();
237 OUT_BYTE(drive->ctl|2,IDE_CONTROL_REG); /* mask device irq */
238 udelay(5);
239 (void) probe_irq_off(irqs);
240 (void) probe_irq_off(probe_irq_on()); /* clear self-inflicted irq */
241 (void) GET_STAT(); /* clear drive IRQ */
243 } else { /* Mmmm.. multiple IRQs.. don't know which was ours */
244 printk("%s: IRQ probe failed (%ld)\n", drive->name, irqs);
245 #ifdef CONFIG_BLK_DEV_CMD640
246 #ifdef CMD640_DUMP_REGS
247 if (HWIF(drive)->chipset == ide_cmd640) {
248 printk("%s: Hmmm.. probably a driver problem.\n", drive->name);
249 CMD640_DUMP_REGS;
251 #endif /* CMD640_DUMP_REGS */
252 #endif /* CONFIG_BLK_DEV_CMD640 */
255 return rc;
259 * do_probe() has the difficult job of finding a drive if it exists,
260 * without getting hung up if it doesn't exist, without trampling on
261 * ethernet cards, and without leaving any IRQs dangling to haunt us later.
263 * If a drive is "known" to exist (from CMOS or kernel parameters),
264 * but does not respond right away, the probe will "hang in there"
265 * for the maximum wait time (about 30 seconds), otherwise it will
266 * exit much more quickly.
268 * Returns: 0 device was identified
269 * 1 device timed-out (no response to identify request)
270 * 2 device aborted the command (refused to identify itself)
271 * 3 bad status from device (possible for ATAPI drives)
272 * 4 probe was not attempted because failure was obvious
274 static int do_probe (ide_drive_t *drive, byte cmd)
276 int rc;
277 ide_hwif_t *hwif = HWIF(drive);
278 if (drive->present) { /* avoid waiting for inappropriate probes */
279 if ((drive->media != ide_disk) && (cmd == WIN_IDENTIFY))
280 return 4;
282 #ifdef DEBUG
283 printk("probing for %s: present=%d, media=%d, probetype=%s\n",
284 drive->name, drive->present, drive->media,
285 (cmd == WIN_IDENTIFY) ? "ATA" : "ATAPI");
286 #endif
287 SELECT_DRIVE(hwif,drive);
288 ide_delay_50ms();
289 if (IN_BYTE(IDE_SELECT_REG) != drive->select.all && !drive->present) {
290 if (drive->select.b.unit != 0) {
291 SELECT_DRIVE(hwif,&hwif->drives[0]); /* exit with drive0 selected */
292 ide_delay_50ms(); /* allow BUSY_STAT to assert & clear */
294 return 3; /* no i/f present: mmm.. this should be a 4 -ml */
297 if (OK_STAT(GET_STAT(),READY_STAT,BUSY_STAT)
298 || drive->present || cmd == WIN_PIDENTIFY)
300 if ((rc = try_to_identify(drive,cmd))) /* send cmd and wait */
301 rc = try_to_identify(drive,cmd); /* failed: try again */
302 if (rc == 1 && cmd == WIN_PIDENTIFY && drive->autotune != 2) {
303 unsigned long timeout;
304 printk("%s: no response (status = 0x%02x), resetting drive\n", drive->name, GET_STAT());
305 ide_delay_50ms();
306 OUT_BYTE (drive->select.all, IDE_SELECT_REG);
307 ide_delay_50ms();
308 OUT_BYTE(WIN_SRST, IDE_COMMAND_REG);
309 timeout = jiffies;
310 while ((GET_STAT() & BUSY_STAT) && time_before(jiffies, timeout + WAIT_WORSTCASE))
311 ide_delay_50ms();
312 rc = try_to_identify(drive, cmd);
314 if (rc == 1)
315 printk("%s: no response (status = 0x%02x)\n", drive->name, GET_STAT());
316 (void) GET_STAT(); /* ensure drive irq is clear */
317 } else {
318 rc = 3; /* not present or maybe ATAPI */
320 if (drive->select.b.unit != 0) {
321 SELECT_DRIVE(hwif,&hwif->drives[0]); /* exit with drive0 selected */
322 ide_delay_50ms();
323 (void) GET_STAT(); /* ensure drive irq is clear */
325 return rc;
331 static void enable_nest (ide_drive_t *drive)
333 unsigned long timeout;
335 printk("%s: enabling %s -- ", HWIF(drive)->name, drive->id->model);
336 SELECT_DRIVE(HWIF(drive), drive);
337 ide_delay_50ms();
338 OUT_BYTE(EXABYTE_ENABLE_NEST, IDE_COMMAND_REG);
339 timeout = jiffies + WAIT_WORSTCASE;
340 do {
341 if (jiffies > timeout) {
342 printk("failed (timeout)\n");
343 return;
345 ide_delay_50ms();
346 } while (GET_STAT() & BUSY_STAT);
347 ide_delay_50ms();
348 if (!OK_STAT(GET_STAT(), 0, BAD_STAT))
349 printk("failed (status = 0x%02x)\n", GET_STAT());
350 else
351 printk("success\n");
352 if (do_probe(drive, WIN_IDENTIFY) >= 2) { /* if !(success||timed-out) */
353 (void) do_probe(drive, WIN_PIDENTIFY); /* look for ATAPI device */
358 * probe_for_drive() tests for existence of a given drive using do_probe().
360 * Returns: 0 no device was found
361 * 1 device was found (note: drive->present might still be 0)
363 static inline byte probe_for_drive (ide_drive_t *drive)
365 if (drive->noprobe) /* skip probing? */
366 return drive->present;
367 if (do_probe(drive, WIN_IDENTIFY) >= 2) { /* if !(success||timed-out) */
368 (void) do_probe(drive, WIN_PIDENTIFY); /* look for ATAPI device */
370 if (drive->id && strstr(drive->id->model, "E X A B Y T E N E S T"))
371 enable_nest(drive);
372 if (!drive->present)
373 return 0; /* drive not found */
374 if (drive->id == NULL) { /* identification failed? */
375 if (drive->media == ide_disk) {
376 printk ("%s: non-IDE drive, CHS=%d/%d/%d\n",
377 drive->name, drive->cyl, drive->head, drive->sect);
378 } else if (drive->media == ide_cdrom) {
379 printk("%s: ATAPI cdrom (?)\n", drive->name);
380 } else {
381 drive->present = 0; /* nuke it */
384 return 1; /* drive was found */
388 * This routine only knows how to look for drive units 0 and 1
389 * on an interface, so any setting of MAX_DRIVES > 2 won't work here.
391 static void probe_hwif (ide_hwif_t *hwif)
393 unsigned int unit;
394 unsigned long flags;
396 ide_ioreg_t ide_control_reg = hwif->io_ports[IDE_CONTROL_OFFSET];
397 ide_ioreg_t region_low = hwif->io_ports[IDE_DATA_OFFSET];
398 ide_ioreg_t region_high = region_low;
399 ide_ioreg_t region_request = 8;
400 int i;
402 if (hwif->noprobe)
403 return;
404 if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA) {
405 extern void probe_cmos_for_drives(ide_hwif_t *hwif);
407 probe_cmos_for_drives (hwif);
411 * Calculate the region that this interface occupies,
412 * handling interfaces where the registers may not be
413 * ordered sanely. We deal with the CONTROL register
414 * separately.
416 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
417 if (hwif->io_ports[i]) {
418 if (hwif->io_ports[i] < region_low)
419 region_low = hwif->io_ports[i];
420 if (hwif->io_ports[i] > region_high)
421 region_high = hwif->io_ports[i];
424 region_request = (region_high - region_low);
425 if (region_request == 0x0007)
426 region_request++;
427 if ((hwif->chipset != ide_4drives || !hwif->mate->present) &&
428 #if CONFIG_BLK_DEV_PDC4030
429 (hwif->chipset != ide_pdc4030 || hwif->channel == 0) &&
430 #endif /* CONFIG_BLK_DEV_PDC4030 */
431 (ide_check_region(region_low, region_request) ||
432 (ide_control_reg && ide_check_region(ide_control_reg,1))))
434 int msgout = 0;
435 for (unit = 0; unit < MAX_DRIVES; ++unit) {
436 ide_drive_t *drive = &hwif->drives[unit];
437 if (drive->present) {
438 drive->present = 0;
439 printk("%s: ERROR, PORTS ALREADY IN USE\n", drive->name);
440 msgout = 1;
443 if (!msgout)
444 printk("%s: ports already in use, skipping probe\n", hwif->name);
445 return;
448 __save_flags(flags); /* local CPU only */
449 __sti(); /* local CPU only; needed for jiffies and irq probing */
451 * Second drive should only exist if first drive was found,
452 * but a lot of cdrom drives are configured as single slaves.
454 for (unit = 0; unit < MAX_DRIVES; ++unit) {
455 ide_drive_t *drive = &hwif->drives[unit];
456 (void) probe_for_drive (drive);
457 if (drive->present && !hwif->present) {
458 hwif->present = 1;
459 if (hwif->chipset != ide_4drives || !hwif->mate->present) {
460 ide_request_region(region_low, region_request, hwif->name);
461 if (ide_control_reg)
462 ide_request_region(ide_control_reg, 1, hwif->name);
466 if (ide_control_reg && hwif->reset) {
467 unsigned long timeout = jiffies + WAIT_WORSTCASE;
468 byte stat;
470 printk("%s: reset\n", hwif->name);
471 OUT_BYTE(12, ide_control_reg);
472 udelay(10);
473 OUT_BYTE(8, ide_control_reg);
474 do {
475 ide_delay_50ms();
476 stat = IN_BYTE(hwif->io_ports[IDE_STATUS_OFFSET]);
477 } while ((stat & BUSY_STAT) && 0 < (signed long)(timeout - jiffies));
480 __restore_flags(flags); /* local CPU only */
481 for (unit = 0; unit < MAX_DRIVES; ++unit) {
482 ide_drive_t *drive = &hwif->drives[unit];
483 if (drive->present) {
484 ide_tuneproc_t *tuneproc = HWIF(drive)->tuneproc;
485 if (tuneproc != NULL && drive->autotune == 1)
486 tuneproc(drive, 255); /* auto-tune PIO mode */
491 #if MAX_HWIFS > 1
493 * save_match() is used to simplify logic in init_irq() below.
495 * A loophole here is that we may not know about a particular
496 * hwif's irq until after that hwif is actually probed/initialized..
497 * This could be a problem for the case where an hwif is on a
498 * dual interface that requires serialization (eg. cmd640) and another
499 * hwif using one of the same irqs is initialized beforehand.
501 * This routine detects and reports such situations, but does not fix them.
503 static void save_match (ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match)
505 ide_hwif_t *m = *match;
507 if (m && m->hwgroup && m->hwgroup != new->hwgroup) {
508 if (!new->hwgroup)
509 return;
510 printk("%s: potential irq problem with %s and %s\n", hwif->name, new->name, m->name);
512 if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */
513 *match = new;
515 #endif /* MAX_HWIFS > 1 */
518 * This routine sets up the irq for an ide interface, and creates a new
519 * hwgroup for the irq/hwif if none was previously assigned.
521 * Much of the code is for correctly detecting/handling irq sharing
522 * and irq serialization situations. This is somewhat complex because
523 * it handles static as well as dynamic (PCMCIA) IDE interfaces.
525 * The SA_INTERRUPT in sa_flags means ide_intr() is always entered with
526 * interrupts completely disabled. This can be bad for interrupt latency,
527 * but anything else has led to problems on some machines. We re-enable
528 * interrupts as much as we can safely do in most places.
530 static int init_irq (ide_hwif_t *hwif)
532 unsigned long flags;
533 unsigned int index;
534 ide_hwgroup_t *hwgroup;
535 ide_hwif_t *match = NULL;
537 save_flags(flags); /* all CPUs */
538 cli(); /* all CPUs */
540 hwif->hwgroup = NULL;
541 #if MAX_HWIFS > 1
543 * Group up with any other hwifs that share our irq(s).
545 for (index = 0; index < MAX_HWIFS; index++) {
546 ide_hwif_t *h = &ide_hwifs[index];
547 if (h->hwgroup) { /* scan only initialized hwif's */
548 if (hwif->irq == h->irq) {
549 hwif->sharing_irq = h->sharing_irq = 1;
550 if (hwif->chipset != ide_pci || h->chipset != ide_pci) {
551 save_match(hwif, h, &match);
554 if (hwif->serialized) {
555 if (hwif->mate && hwif->mate->irq == h->irq)
556 save_match(hwif, h, &match);
558 if (h->serialized) {
559 if (h->mate && hwif->irq == h->mate->irq)
560 save_match(hwif, h, &match);
564 #endif /* MAX_HWIFS > 1 */
566 * If we are still without a hwgroup, then form a new one
568 if (match) {
569 hwgroup = match->hwgroup;
570 } else {
571 hwgroup = kmalloc(sizeof(ide_hwgroup_t), GFP_KERNEL);
572 memset(hwgroup, 0, sizeof(ide_hwgroup_t));
573 hwgroup->hwif = hwif->next = hwif;
574 hwgroup->rq = NULL;
575 hwgroup->handler = NULL;
576 hwgroup->drive = NULL;
577 hwgroup->busy = 0;
578 hwgroup->spinlock = (spinlock_t)SPIN_LOCK_UNLOCKED;
579 #if (DEBUG_SPINLOCK > 0)
580 printk("hwgroup(%s) spinlock is %p\n", hwif->name, &hwgroup->spinlock); /* FIXME */
581 #endif
582 init_timer(&hwgroup->timer);
583 hwgroup->timer.function = &ide_timer_expiry;
584 hwgroup->timer.data = (unsigned long) hwgroup;
588 * Allocate the irq, if not already obtained for another hwif
590 if (!match || match->irq != hwif->irq) {
591 int sa = (hwif->chipset == ide_pci) ? SA_INTERRUPT|SA_SHIRQ : SA_INTERRUPT;
592 if (ide_request_irq(hwif->irq, &ide_intr, sa, hwif->name, hwgroup)) {
593 if (!match)
594 kfree(hwgroup);
595 restore_flags(flags); /* all CPUs */
596 return 1;
601 * Everything is okay, so link us into the hwgroup
603 hwif->hwgroup = hwgroup;
604 hwif->next = hwgroup->hwif->next;
605 hwgroup->hwif->next = hwif;
607 for (index = 0; index < MAX_DRIVES; ++index) {
608 ide_drive_t *drive = &hwif->drives[index];
609 if (!drive->present)
610 continue;
611 if (!hwgroup->drive)
612 hwgroup->drive = drive;
613 drive->next = hwgroup->drive->next;
614 hwgroup->drive->next = drive;
616 if (!hwgroup->hwif) {
617 hwgroup->hwif = HWIF(hwgroup->drive);
618 #ifdef DEBUG
619 printk("%s : Adding missed hwif to hwgroup!!\n", hwif->name);
620 #endif
622 restore_flags(flags); /* all CPUs; safe now that hwif->hwgroup is set up */
624 #if !defined(__mc68000__) && !defined(CONFIG_APUS) && !defined(__sparc__)
625 printk("%s at 0x%03x-0x%03x,0x%03x on irq %d", hwif->name,
626 hwif->io_ports[IDE_DATA_OFFSET],
627 hwif->io_ports[IDE_DATA_OFFSET]+7,
628 hwif->io_ports[IDE_CONTROL_OFFSET], hwif->irq);
629 #elif defined(__sparc__)
630 printk("%s at 0x%03x-0x%03x,0x%03x on irq %s", hwif->name,
631 hwif->io_ports[IDE_DATA_OFFSET],
632 hwif->io_ports[IDE_DATA_OFFSET]+7,
633 hwif->io_ports[IDE_CONTROL_OFFSET], __irq_itoa(hwif->irq));
634 #else
635 printk("%s at %p on irq 0x%08x", hwif->name,
636 hwif->io_ports[IDE_DATA_OFFSET], hwif->irq);
637 #endif /* __mc68000__ && CONFIG_APUS */
638 if (match)
639 printk(" (%sed with %s)",
640 hwif->sharing_irq ? "shar" : "serializ", match->name);
641 printk("\n");
642 return 0;
646 * init_gendisk() (as opposed to ide_geninit) is called for each major device,
647 * after probing for drives, to allocate partition tables and other data
648 * structures needed for the routines in genhd.c. ide_geninit() gets called
649 * somewhat later, during the partition check.
651 static void init_gendisk (ide_hwif_t *hwif)
653 struct gendisk *gd, **gdp;
654 unsigned int unit, units, minors;
655 int *bs, *max_sect, *max_ra;
657 /* figure out maximum drive number on the interface */
658 for (units = MAX_DRIVES; units > 0; --units) {
659 if (hwif->drives[units-1].present)
660 break;
662 minors = units * (1<<PARTN_BITS);
663 gd = kmalloc (sizeof(struct gendisk), GFP_KERNEL);
664 gd->sizes = kmalloc (minors * sizeof(int), GFP_KERNEL);
665 gd->part = kmalloc (minors * sizeof(struct hd_struct), GFP_KERNEL);
666 bs = kmalloc (minors*sizeof(int), GFP_KERNEL);
667 max_sect = kmalloc (minors*sizeof(int), GFP_KERNEL);
668 max_ra = kmalloc (minors*sizeof(int), GFP_KERNEL);
670 memset(gd->part, 0, minors * sizeof(struct hd_struct));
672 /* cdroms and msdos f/s are examples of non-1024 blocksizes */
673 blksize_size[hwif->major] = bs;
674 max_sectors[hwif->major] = max_sect;
675 max_readahead[hwif->major] = max_ra;
676 for (unit = 0; unit < minors; ++unit) {
677 *bs++ = BLOCK_SIZE;
678 #ifdef CONFIG_BLK_DEV_PDC4030
679 *max_sect++ = ((hwif->chipset == ide_pdc4030) ? 127 : MAX_SECTORS);
680 #else
681 *max_sect++ = MAX_SECTORS;
682 #endif
683 *max_ra++ = MAX_READAHEAD;
686 for (unit = 0; unit < units; ++unit)
687 hwif->drives[unit].part = &gd->part[unit << PARTN_BITS];
689 gd->major = hwif->major; /* our major device number */
690 gd->major_name = IDE_MAJOR_NAME; /* treated special in genhd.c */
691 gd->minor_shift = PARTN_BITS; /* num bits for partitions */
692 gd->max_p = 1<<PARTN_BITS; /* 1 + max partitions / drive */
693 gd->max_nr = units; /* max num real drives */
694 gd->nr_real = units; /* current num real drives */
695 gd->init = &ide_geninit; /* initialization function */
696 gd->real_devices= hwif; /* ptr to internal data */
697 gd->next = NULL; /* linked list of major devs */
699 for (gdp = &gendisk_head; *gdp; gdp = &((*gdp)->next)) ;
700 hwif->gd = *gdp = gd; /* link onto tail of list */
702 for (unit = 0; unit < units; ++unit) {
703 if (hwif->drives[unit].present)
704 ide_add_generic_settings(hwif->drives + unit);
708 static int hwif_init (ide_hwif_t *hwif)
710 void (*rfn)(void);
712 if (!hwif->present)
713 return 0;
714 if (!hwif->irq) {
715 if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET])))
717 printk("%s: DISABLED, NO IRQ\n", hwif->name);
718 return (hwif->present = 0);
721 #ifdef CONFIG_BLK_DEV_HD
722 if (hwif->irq == HD_IRQ && hwif->io_ports[IDE_DATA_OFFSET] != HD_DATA) {
723 printk("%s: CANNOT SHARE IRQ WITH OLD HARDDISK DRIVER (hd.c)\n", hwif->name);
724 return (hwif->present = 0);
726 #endif /* CONFIG_BLK_DEV_HD */
728 hwif->present = 0; /* we set it back to 1 if all is ok below */
729 switch (hwif->major) {
730 case IDE0_MAJOR: rfn = &do_ide0_request; break;
731 #if MAX_HWIFS > 1
732 case IDE1_MAJOR: rfn = &do_ide1_request; break;
733 #endif
734 #if MAX_HWIFS > 2
735 case IDE2_MAJOR: rfn = &do_ide2_request; break;
736 #endif
737 #if MAX_HWIFS > 3
738 case IDE3_MAJOR: rfn = &do_ide3_request; break;
739 #endif
740 #if MAX_HWIFS > 4
741 case IDE4_MAJOR: rfn = &do_ide4_request; break;
742 #endif
743 #if MAX_HWIFS > 5
744 case IDE5_MAJOR: rfn = &do_ide5_request; break;
745 #endif
746 #if MAX_HWIFS > 6
747 case IDE6_MAJOR: rfn = &do_ide6_request; break;
748 #endif
749 #if MAX_HWIFS > 7
750 case IDE7_MAJOR: rfn = &do_ide7_request; break;
751 #endif
752 #if MAX_HWIFS > 8
753 case IDE8_MAJOR: rfn = &do_ide8_request; break;
754 #endif
755 #if MAX_HWIFS > 9
756 case IDE9_MAJOR: rfn = &do_ide9_request; break;
757 #endif
758 default:
759 printk("%s: request_fn NOT DEFINED\n", hwif->name);
760 return (hwif->present = 0);
762 if (register_blkdev (hwif->major, hwif->name, ide_fops)) {
763 printk("%s: UNABLE TO GET MAJOR NUMBER %d\n", hwif->name, hwif->major);
764 return (hwif->present = 0);
767 if (init_irq (hwif)) {
768 int i = hwif->irq;
770 * It failed to initialise. Find the default IRQ for
771 * this port and try that.
773 if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET])))
775 printk("%s: Disabled unable to get IRQ %d.\n", hwif->name, i);
776 (void) unregister_blkdev (hwif->major, hwif->name);
777 return (hwif->present = 0);
779 if(init_irq (hwif))
781 printk("%s: probed IRQ %d and default IRQ %d failed.\n",
782 hwif->name, i, hwif->irq);
783 (void) unregister_blkdev (hwif->major, hwif->name);
784 return (hwif->present = 0);
786 printk("%s: probed IRQ %d failed, using default.\n",
787 hwif->name, hwif->irq);
790 init_gendisk(hwif);
791 blk_dev[hwif->major].data = hwif;
792 blk_dev[hwif->major].request_fn = rfn;
793 blk_dev[hwif->major].queue = ide_get_queue;
794 read_ahead[hwif->major] = 8; /* (4kB) */
795 hwif->present = 1; /* success */
797 #if (DEBUG_SPINLOCK > 0)
799 static int done = 0;
800 if (!done++)
801 printk("io_request_lock is %p\n", &io_request_lock); /* FIXME */
803 #endif
804 return hwif->present;
807 int ideprobe_init (void);
808 static ide_module_t ideprobe_module = {
809 IDE_PROBE_MODULE,
810 ideprobe_init,
811 NULL
814 int ideprobe_init (void)
816 unsigned int index;
817 int probe[MAX_HWIFS];
819 MOD_INC_USE_COUNT;
820 memset(probe, 0, MAX_HWIFS * sizeof(int));
821 for (index = 0; index < MAX_HWIFS; ++index)
822 probe[index] = !ide_hwifs[index].present;
825 * Probe for drives in the usual way.. CMOS/BIOS, then poke at ports
827 for (index = 0; index < MAX_HWIFS; ++index)
828 if (probe[index])
829 probe_hwif(&ide_hwifs[index]);
830 for (index = 0; index < MAX_HWIFS; ++index)
831 if (probe[index])
832 hwif_init(&ide_hwifs[index]);
833 ide_register_module(&ideprobe_module);
834 MOD_DEC_USE_COUNT;
835 return 0;
838 #ifdef MODULE
839 int init_module (void)
841 unsigned int index;
843 for (index = 0; index < MAX_HWIFS; ++index)
844 ide_unregister(index);
845 ideprobe_init();
846 create_proc_ide_interfaces();
847 return 0;
850 void cleanup_module (void)
852 ide_unregister_module(&ideprobe_module);
854 #endif /* MODULE */