2 * linux/drivers/ide/ide-probe.c Version 1.06 June 9, 2000
4 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
8 * Mostly written by Mark Lord <mlord@pobox.com>
9 * and Gadi Oxman <gadio@netvision.net.il>
10 * and Andre Hedrick <andre@linux-ide.org>
12 * See linux/MAINTAINERS for address of current maintainer.
14 * This is the IDE probe module, as evolved from hd.c and ide.c.
16 * Version 1.00 move drive probing code from ide.c to ide-probe.c
17 * Version 1.01 fix compilation problem for m68k
18 * Version 1.02 increase WAIT_PIDENTIFY to avoid CD-ROM locking at boot
20 * Version 1.03 fix for (hwif->chipset == ide_4drives)
21 * Version 1.04 fixed buggy treatments of known flash memory cards
23 * Version 1.05 fix for (hwif->chipset == ide_pdc4030)
25 * allowed for secondary flash card to be detectable
26 * with new flag : drive->ata_flash : 1;
27 * Version 1.06 stream line request queue and prep for cascade project.
30 #undef REALLY_SLOW_IO /* most systems can safely undef this */
32 #include <linux/config.h>
33 #include <linux/module.h>
34 #include <linux/types.h>
35 #include <linux/string.h>
36 #include <linux/kernel.h>
37 #include <linux/timer.h>
39 #include <linux/interrupt.h>
40 #include <linux/major.h>
41 #include <linux/errno.h>
42 #include <linux/genhd.h>
43 #include <linux/malloc.h>
44 #include <linux/delay.h>
45 #include <linux/ide.h>
46 #include <linux/spinlock.h>
48 #include <asm/byteorder.h>
50 #include <asm/uaccess.h>
53 static inline void do_identify (ide_drive_t
*drive
, byte cmd
)
56 struct hd_driveid
*id
;
58 id
= drive
->id
= kmalloc (SECTOR_WORDS
*4, GFP_ATOMIC
); /* called with interrupts disabled! */
59 ide_input_data(drive
, id
, SECTOR_WORDS
); /* read 512 bytes of id info */
60 ide__sti(); /* local CPU only */
63 if (id
->word156
== 0x4d42) {
64 printk("%s: drive->id->word156 == 0x%04x \n", drive
->name
, drive
->id
->word156
);
67 if (!drive
->forced_lun
)
68 drive
->last_lun
= id
->last_lun
& 0x7;
69 #if defined (CONFIG_SCSI_EATA_DMA) || defined (CONFIG_SCSI_EATA_PIO) || defined (CONFIG_SCSI_EATA)
71 * EATA SCSI controllers do a hardware ATA emulation:
72 * Ignore them if there is a driver for them available.
74 if ((id
->model
[0] == 'P' && id
->model
[1] == 'M')
75 || (id
->model
[0] == 'S' && id
->model
[1] == 'K')) {
76 printk("%s: EATA SCSI HBA %.10s\n", drive
->name
, id
->model
);
80 #endif /* CONFIG_SCSI_EATA_DMA || CONFIG_SCSI_EATA_PIO */
83 * WIN_IDENTIFY returns little-endian info,
84 * WIN_PIDENTIFY *usually* returns little-endian info.
86 if (cmd
== WIN_PIDENTIFY
) {
87 if ((id
->model
[0] == 'N' && id
->model
[1] == 'E') /* NEC */
88 || (id
->model
[0] == 'F' && id
->model
[1] == 'X') /* Mitsumi */
89 || (id
->model
[0] == 'P' && id
->model
[1] == 'i'))/* Pioneer */
90 bswap
^= 1; /* Vertos drives may still be weird */
92 ide_fixstring (id
->model
, sizeof(id
->model
), bswap
);
93 ide_fixstring (id
->fw_rev
, sizeof(id
->fw_rev
), bswap
);
94 ide_fixstring (id
->serial_no
, sizeof(id
->serial_no
), bswap
);
96 if (strstr(id
->model
, "E X A B Y T E N E S T"))
99 id
->model
[sizeof(id
->model
)-1] = '\0'; /* we depend on this a lot! */
100 printk("%s: %s, ", drive
->name
, id
->model
);
104 * Check for an ATAPI device
106 if (cmd
== WIN_PIDENTIFY
) {
107 byte type
= (id
->config
>> 8) & 0x1f;
109 #ifdef CONFIG_BLK_DEV_PDC4030
110 if (HWIF(drive
)->channel
== 1 && HWIF(drive
)->chipset
== ide_pdc4030
) {
111 printk(" -- not supported on 2nd Promise port\n");
115 #endif /* CONFIG_BLK_DEV_PDC4030 */
118 if (!strstr(id
->model
, "CD-ROM")) {
119 if (!strstr(id
->model
, "oppy") && !strstr(id
->model
, "poyp") && !strstr(id
->model
, "ZIP"))
120 printk("cdrom or floppy?, assuming ");
121 if (drive
->media
!= ide_cdrom
) {
126 type
= ide_cdrom
; /* Early cdrom models used zero */
128 drive
->removable
= 1;
130 /* kludge for Apple PowerBook internal zip */
131 if (!strstr(id
->model
, "CD-ROM") && strstr(id
->model
, "ZIP")) {
144 drive
->removable
= 1;
147 printk("UNKNOWN (type %d)", type
);
156 * Not an ATAPI device: looks like a "regular" hard disk
158 if (id
->config
& (1<<7))
159 drive
->removable
= 1;
161 * Prevent long system lockup probing later for non-existant
162 * slave drive if the hwif is actually a flash memory card of some variety:
164 if (drive_is_flashcard(drive
)) {
165 ide_drive_t
*mate
= &HWIF(drive
)->drives
[1^drive
->select
.b
.unit
];
166 if (!mate
->ata_flash
) {
171 drive
->media
= ide_disk
;
172 printk("ATA DISK drive\n");
173 QUIRK_LIST(HWIF(drive
),drive
);
178 * try_to_identify() sends an ATA(PI) IDENTIFY request to a drive
179 * and waits for a response. It also monitors irqs while this is
180 * happening, in hope of automatically determining which one is
181 * being used by the interface.
183 * Returns: 0 device was identified
184 * 1 device timed-out (no response to identify request)
185 * 2 device aborted the command (refused to identify itself)
187 static int actual_try_to_identify (ide_drive_t
*drive
, byte cmd
)
190 ide_ioreg_t hd_status
;
191 unsigned long timeout
;
194 if (IDE_CONTROL_REG
) {
195 /* take a deep breath */
197 a
= IN_BYTE(IDE_ALTSTATUS_REG
);
198 s
= IN_BYTE(IDE_STATUS_REG
);
199 if ((a
^ s
) & ~INDEX_STAT
) {
200 printk("%s: probing with STATUS(0x%02x) instead of ALTSTATUS(0x%02x)\n", drive
->name
, s
, a
);
201 hd_status
= IDE_STATUS_REG
; /* ancient Seagate drives, broken interfaces */
203 hd_status
= IDE_ALTSTATUS_REG
; /* use non-intrusive polling */
207 hd_status
= IDE_STATUS_REG
;
210 /* set features register for atapi identify command to be sure of reply */
211 if ((cmd
== WIN_PIDENTIFY
))
212 OUT_BYTE(0,IDE_FEATURE_REG
); /* disable dma & overlap */
214 #if CONFIG_BLK_DEV_PDC4030
215 if (HWIF(drive
)->chipset
== ide_pdc4030
) {
216 /* DC4030 hosted drives need their own identify... */
217 extern int pdc4030_identify(ide_drive_t
*);
218 if (pdc4030_identify(drive
)) {
222 #endif /* CONFIG_BLK_DEV_PDC4030 */
223 OUT_BYTE(cmd
,IDE_COMMAND_REG
); /* ask drive for ID */
224 timeout
= ((cmd
== WIN_IDENTIFY
) ? WAIT_WORSTCASE
: WAIT_PIDENTIFY
) / 2;
227 if (0 < (signed long)(jiffies
- timeout
)) {
228 return 1; /* drive timed-out */
230 ide_delay_50ms(); /* give drive a breather */
231 } while (IN_BYTE(hd_status
) & BUSY_STAT
);
233 ide_delay_50ms(); /* wait for IRQ and DRQ_STAT */
234 if (OK_STAT(GET_STAT(),DRQ_STAT
,BAD_R_STAT
)) {
236 __save_flags(flags
); /* local CPU only */
237 __cli(); /* local CPU only; some systems need this */
238 do_identify(drive
, cmd
); /* drive returned ID */
239 rc
= 0; /* drive responded with ID */
240 (void) GET_STAT(); /* clear drive IRQ */
241 __restore_flags(flags
); /* local CPU only */
243 rc
= 2; /* drive refused ID */
247 static int try_to_identify (ide_drive_t
*drive
, byte cmd
)
251 unsigned long cookie
= 0;
253 if (IDE_CONTROL_REG
&& !HWIF(drive
)->irq
) {
255 cookie
= probe_irq_on();
256 OUT_BYTE(drive
->ctl
,IDE_CONTROL_REG
); /* enable device irq */
259 retval
= actual_try_to_identify(drive
, cmd
);
263 OUT_BYTE(drive
->ctl
|2,IDE_CONTROL_REG
); /* mask device irq */
264 (void) GET_STAT(); /* clear drive IRQ */
266 irq
= probe_irq_off(cookie
);
267 if (!HWIF(drive
)->irq
) {
269 HWIF(drive
)->irq
= irq
;
270 } else { /* Mmmm.. multiple IRQs.. don't know which was ours */
271 printk("%s: IRQ probe failed (0x%lx)\n", drive
->name
, cookie
);
272 #ifdef CONFIG_BLK_DEV_CMD640
273 #ifdef CMD640_DUMP_REGS
274 if (HWIF(drive
)->chipset
== ide_cmd640
) {
275 printk("%s: Hmmm.. probably a driver problem.\n", drive
->name
);
278 #endif /* CMD640_DUMP_REGS */
279 #endif /* CONFIG_BLK_DEV_CMD640 */
288 * do_probe() has the difficult job of finding a drive if it exists,
289 * without getting hung up if it doesn't exist, without trampling on
290 * ethernet cards, and without leaving any IRQs dangling to haunt us later.
292 * If a drive is "known" to exist (from CMOS or kernel parameters),
293 * but does not respond right away, the probe will "hang in there"
294 * for the maximum wait time (about 30 seconds), otherwise it will
295 * exit much more quickly.
297 * Returns: 0 device was identified
298 * 1 device timed-out (no response to identify request)
299 * 2 device aborted the command (refused to identify itself)
300 * 3 bad status from device (possible for ATAPI drives)
301 * 4 probe was not attempted because failure was obvious
303 static int do_probe (ide_drive_t
*drive
, byte cmd
)
306 ide_hwif_t
*hwif
= HWIF(drive
);
307 if (drive
->present
) { /* avoid waiting for inappropriate probes */
308 if ((drive
->media
!= ide_disk
) && (cmd
== WIN_IDENTIFY
))
312 printk("probing for %s: present=%d, media=%d, probetype=%s\n",
313 drive
->name
, drive
->present
, drive
->media
,
314 (cmd
== WIN_IDENTIFY
) ? "ATA" : "ATAPI");
316 ide_delay_50ms(); /* needed for some systems (e.g. crw9624 as drive0 with disk as slave) */
317 SELECT_DRIVE(hwif
,drive
);
319 if (IN_BYTE(IDE_SELECT_REG
) != drive
->select
.all
&& !drive
->present
) {
320 if (drive
->select
.b
.unit
!= 0) {
321 SELECT_DRIVE(hwif
,&hwif
->drives
[0]); /* exit with drive0 selected */
322 ide_delay_50ms(); /* allow BUSY_STAT to assert & clear */
324 return 3; /* no i/f present: mmm.. this should be a 4 -ml */
327 if (OK_STAT(GET_STAT(),READY_STAT
,BUSY_STAT
)
328 || drive
->present
|| cmd
== WIN_PIDENTIFY
)
330 if ((rc
= try_to_identify(drive
,cmd
))) /* send cmd and wait */
331 rc
= try_to_identify(drive
,cmd
); /* failed: try again */
332 if (rc
== 1 && cmd
== WIN_PIDENTIFY
&& drive
->autotune
!= 2) {
333 unsigned long timeout
;
334 printk("%s: no response (status = 0x%02x), resetting drive\n", drive
->name
, GET_STAT());
336 OUT_BYTE (drive
->select
.all
, IDE_SELECT_REG
);
338 OUT_BYTE(WIN_SRST
, IDE_COMMAND_REG
);
340 while ((GET_STAT() & BUSY_STAT
) && time_before(jiffies
, timeout
+ WAIT_WORSTCASE
))
342 rc
= try_to_identify(drive
, cmd
);
345 printk("%s: no response (status = 0x%02x)\n", drive
->name
, GET_STAT());
346 (void) GET_STAT(); /* ensure drive irq is clear */
348 rc
= 3; /* not present or maybe ATAPI */
350 if (drive
->select
.b
.unit
!= 0) {
351 SELECT_DRIVE(hwif
,&hwif
->drives
[0]); /* exit with drive0 selected */
353 (void) GET_STAT(); /* ensure drive irq is clear */
361 static void enable_nest (ide_drive_t
*drive
)
363 unsigned long timeout
;
365 printk("%s: enabling %s -- ", HWIF(drive
)->name
, drive
->id
->model
);
366 SELECT_DRIVE(HWIF(drive
), drive
);
368 OUT_BYTE(EXABYTE_ENABLE_NEST
, IDE_COMMAND_REG
);
369 timeout
= jiffies
+ WAIT_WORSTCASE
;
371 if (jiffies
> timeout
) {
372 printk("failed (timeout)\n");
376 } while (GET_STAT() & BUSY_STAT
);
378 if (!OK_STAT(GET_STAT(), 0, BAD_STAT
))
379 printk("failed (status = 0x%02x)\n", GET_STAT());
382 if (do_probe(drive
, WIN_IDENTIFY
) >= 2) { /* if !(success||timed-out) */
383 (void) do_probe(drive
, WIN_PIDENTIFY
); /* look for ATAPI device */
388 * probe_for_drive() tests for existence of a given drive using do_probe().
390 * Returns: 0 no device was found
391 * 1 device was found (note: drive->present might still be 0)
393 static inline byte
probe_for_drive (ide_drive_t
*drive
)
395 if (drive
->noprobe
) /* skip probing? */
396 return drive
->present
;
397 if (do_probe(drive
, WIN_IDENTIFY
) >= 2) { /* if !(success||timed-out) */
398 (void) do_probe(drive
, WIN_PIDENTIFY
); /* look for ATAPI device */
400 if (drive
->id
&& strstr(drive
->id
->model
, "E X A B Y T E N E S T"))
403 return 0; /* drive not found */
404 if (drive
->id
== NULL
) { /* identification failed? */
405 if (drive
->media
== ide_disk
) {
406 printk ("%s: non-IDE drive, CHS=%d/%d/%d\n",
407 drive
->name
, drive
->cyl
, drive
->head
, drive
->sect
);
408 } else if (drive
->media
== ide_cdrom
) {
409 printk("%s: ATAPI cdrom (?)\n", drive
->name
);
411 drive
->present
= 0; /* nuke it */
414 return 1; /* drive was found */
418 * Calculate the region that this interface occupies,
419 * handling interfaces where the registers may not be
420 * ordered sanely. We deal with the CONTROL register
423 static int hwif_check_regions (ide_hwif_t
*hwif
)
425 int region_errors
= 0;
428 region_errors
= ide_check_region(hwif
->io_ports
[IDE_DATA_OFFSET
], 1);
429 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_ERROR_OFFSET
], 1);
430 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_NSECTOR_OFFSET
], 1);
431 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_SECTOR_OFFSET
], 1);
432 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_LCYL_OFFSET
], 1);
433 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_HCYL_OFFSET
], 1);
434 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_SELECT_OFFSET
], 1);
435 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_STATUS_OFFSET
], 1);
437 if (hwif
->io_ports
[IDE_CONTROL_OFFSET
])
438 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_CONTROL_OFFSET
], 1);
439 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
440 if (hwif
->io_ports
[IDE_IRQ_OFFSET
])
441 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_IRQ_OFFSET
], 1);
442 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
444 * If any errors are return, we drop the hwif interface.
446 return(region_errors
);
449 static void hwif_register (ide_hwif_t
*hwif
)
451 if (((unsigned long)hwif
->io_ports
[IDE_DATA_OFFSET
] | 7) ==
452 ((unsigned long)hwif
->io_ports
[IDE_STATUS_OFFSET
])) {
453 ide_request_region(hwif
->io_ports
[IDE_DATA_OFFSET
], 8, hwif
->name
);
458 if (hwif
->io_ports
[IDE_DATA_OFFSET
])
459 ide_request_region(hwif
->io_ports
[IDE_DATA_OFFSET
], 1, hwif
->name
);
460 if (hwif
->io_ports
[IDE_ERROR_OFFSET
])
461 ide_request_region(hwif
->io_ports
[IDE_ERROR_OFFSET
], 1, hwif
->name
);
462 if (hwif
->io_ports
[IDE_NSECTOR_OFFSET
])
463 ide_request_region(hwif
->io_ports
[IDE_NSECTOR_OFFSET
], 1, hwif
->name
);
464 if (hwif
->io_ports
[IDE_SECTOR_OFFSET
])
465 ide_request_region(hwif
->io_ports
[IDE_SECTOR_OFFSET
], 1, hwif
->name
);
466 if (hwif
->io_ports
[IDE_LCYL_OFFSET
])
467 ide_request_region(hwif
->io_ports
[IDE_LCYL_OFFSET
], 1, hwif
->name
);
468 if (hwif
->io_ports
[IDE_HCYL_OFFSET
])
469 ide_request_region(hwif
->io_ports
[IDE_HCYL_OFFSET
], 1, hwif
->name
);
470 if (hwif
->io_ports
[IDE_SELECT_OFFSET
])
471 ide_request_region(hwif
->io_ports
[IDE_SELECT_OFFSET
], 1, hwif
->name
);
472 if (hwif
->io_ports
[IDE_STATUS_OFFSET
])
473 ide_request_region(hwif
->io_ports
[IDE_STATUS_OFFSET
], 1, hwif
->name
);
476 if (hwif
->io_ports
[IDE_CONTROL_OFFSET
])
477 ide_request_region(hwif
->io_ports
[IDE_CONTROL_OFFSET
], 1, hwif
->name
);
478 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
479 if (hwif
->io_ports
[IDE_IRQ_OFFSET
])
480 ide_request_region(hwif
->io_ports
[IDE_IRQ_OFFSET
], 1, hwif
->name
);
481 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
485 * This routine only knows how to look for drive units 0 and 1
486 * on an interface, so any setting of MAX_DRIVES > 2 won't work here.
488 static void probe_hwif (ide_hwif_t
*hwif
)
495 #ifdef CONFIG_BLK_DEV_IDE
496 if (hwif
->io_ports
[IDE_DATA_OFFSET
] == HD_DATA
) {
497 extern void probe_cmos_for_drives(ide_hwif_t
*);
499 probe_cmos_for_drives (hwif
);
503 if ((hwif
->chipset
!= ide_4drives
|| !hwif
->mate
->present
) &&
504 #if CONFIG_BLK_DEV_PDC4030
505 (hwif
->chipset
!= ide_pdc4030
|| hwif
->channel
== 0) &&
506 #endif /* CONFIG_BLK_DEV_PDC4030 */
507 (hwif_check_regions(hwif
))) {
509 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
510 ide_drive_t
*drive
= &hwif
->drives
[unit
];
511 if (drive
->present
) {
513 printk("%s: ERROR, PORTS ALREADY IN USE\n", drive
->name
);
518 printk("%s: ports already in use, skipping probe\n", hwif
->name
);
522 __save_flags(flags
); /* local CPU only */
523 __sti(); /* local CPU only; needed for jiffies and irq probing */
525 * Second drive should only exist if first drive was found,
526 * but a lot of cdrom drives are configured as single slaves.
528 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
529 ide_drive_t
*drive
= &hwif
->drives
[unit
];
530 (void) probe_for_drive (drive
);
531 if (drive
->present
&& !hwif
->present
) {
533 if (hwif
->chipset
!= ide_4drives
|| !hwif
->mate
->present
) {
538 if (hwif
->io_ports
[IDE_CONTROL_OFFSET
] && hwif
->reset
) {
539 unsigned long timeout
= jiffies
+ WAIT_WORSTCASE
;
542 printk("%s: reset\n", hwif
->name
);
543 OUT_BYTE(12, hwif
->io_ports
[IDE_CONTROL_OFFSET
]);
545 OUT_BYTE(8, hwif
->io_ports
[IDE_CONTROL_OFFSET
]);
548 stat
= IN_BYTE(hwif
->io_ports
[IDE_STATUS_OFFSET
]);
549 } while ((stat
& BUSY_STAT
) && 0 < (signed long)(timeout
- jiffies
));
552 __restore_flags(flags
); /* local CPU only */
553 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
554 ide_drive_t
*drive
= &hwif
->drives
[unit
];
555 if (drive
->present
) {
556 ide_tuneproc_t
*tuneproc
= HWIF(drive
)->tuneproc
;
557 if (tuneproc
!= NULL
&& drive
->autotune
== 1)
558 tuneproc(drive
, 255); /* auto-tune PIO mode */
565 * save_match() is used to simplify logic in init_irq() below.
567 * A loophole here is that we may not know about a particular
568 * hwif's irq until after that hwif is actually probed/initialized..
569 * This could be a problem for the case where an hwif is on a
570 * dual interface that requires serialization (eg. cmd640) and another
571 * hwif using one of the same irqs is initialized beforehand.
573 * This routine detects and reports such situations, but does not fix them.
575 static void save_match (ide_hwif_t
*hwif
, ide_hwif_t
*new, ide_hwif_t
**match
)
577 ide_hwif_t
*m
= *match
;
579 if (m
&& m
->hwgroup
&& m
->hwgroup
!= new->hwgroup
) {
582 printk("%s: potential irq problem with %s and %s\n", hwif
->name
, new->name
, m
->name
);
584 if (!m
|| m
->irq
!= hwif
->irq
) /* don't undo a prior perfect match */
587 #endif /* MAX_HWIFS > 1 */
592 static void ide_init_queue(ide_drive_t
*drive
)
594 request_queue_t
*q
= &drive
->queue
;
596 q
->queuedata
= HWGROUP(drive
);
597 blk_init_queue(q
, do_ide_request
);
601 * This routine sets up the irq for an ide interface, and creates a new
602 * hwgroup for the irq/hwif if none was previously assigned.
604 * Much of the code is for correctly detecting/handling irq sharing
605 * and irq serialization situations. This is somewhat complex because
606 * it handles static as well as dynamic (PCMCIA) IDE interfaces.
608 * The SA_INTERRUPT in sa_flags means ide_intr() is always entered with
609 * interrupts completely disabled. This can be bad for interrupt latency,
610 * but anything else has led to problems on some machines. We re-enable
611 * interrupts as much as we can safely do in most places.
613 static int init_irq (ide_hwif_t
*hwif
)
617 ide_hwgroup_t
*hwgroup
;
618 ide_hwif_t
*match
= NULL
;
620 save_flags(flags
); /* all CPUs */
621 cli(); /* all CPUs */
623 hwif
->hwgroup
= NULL
;
626 * Group up with any other hwifs that share our irq(s).
628 for (index
= 0; index
< MAX_HWIFS
; index
++) {
629 ide_hwif_t
*h
= &ide_hwifs
[index
];
630 if (h
->hwgroup
) { /* scan only initialized hwif's */
631 if (hwif
->irq
== h
->irq
) {
632 hwif
->sharing_irq
= h
->sharing_irq
= 1;
633 if (hwif
->chipset
!= ide_pci
|| h
->chipset
!= ide_pci
) {
634 save_match(hwif
, h
, &match
);
637 if (hwif
->serialized
) {
638 if (hwif
->mate
&& hwif
->mate
->irq
== h
->irq
)
639 save_match(hwif
, h
, &match
);
642 if (h
->mate
&& hwif
->irq
== h
->mate
->irq
)
643 save_match(hwif
, h
, &match
);
647 #endif /* MAX_HWIFS > 1 */
649 * If we are still without a hwgroup, then form a new one
652 hwgroup
= match
->hwgroup
;
654 hwgroup
= kmalloc(sizeof(ide_hwgroup_t
), GFP_KERNEL
);
655 memset(hwgroup
, 0, sizeof(ide_hwgroup_t
));
656 hwgroup
->hwif
= hwif
->next
= hwif
;
658 hwgroup
->handler
= NULL
;
659 hwgroup
->drive
= NULL
;
661 init_timer(&hwgroup
->timer
);
662 hwgroup
->timer
.function
= &ide_timer_expiry
;
663 hwgroup
->timer
.data
= (unsigned long) hwgroup
;
667 * Allocate the irq, if not already obtained for another hwif
669 if (!match
|| match
->irq
!= hwif
->irq
) {
670 #ifdef CONFIG_IDEPCI_SHARE_IRQ
671 int sa
= (hwif
->chipset
== ide_pci
) ? SA_SHIRQ
: SA_INTERRUPT
;
672 #else /* !CONFIG_IDEPCI_SHARE_IRQ */
673 int sa
= (hwif
->chipset
== ide_pci
) ? SA_INTERRUPT
|SA_SHIRQ
: SA_INTERRUPT
;
674 #endif /* CONFIG_IDEPCI_SHARE_IRQ */
675 if (ide_request_irq(hwif
->irq
, &ide_intr
, sa
, hwif
->name
, hwgroup
)) {
678 restore_flags(flags
); /* all CPUs */
684 * Everything is okay, so link us into the hwgroup
686 hwif
->hwgroup
= hwgroup
;
687 hwif
->next
= hwgroup
->hwif
->next
;
688 hwgroup
->hwif
->next
= hwif
;
690 for (index
= 0; index
< MAX_DRIVES
; ++index
) {
691 ide_drive_t
*drive
= &hwif
->drives
[index
];
695 hwgroup
->drive
= drive
;
696 drive
->next
= hwgroup
->drive
->next
;
697 hwgroup
->drive
->next
= drive
;
698 ide_init_queue(drive
);
700 if (!hwgroup
->hwif
) {
701 hwgroup
->hwif
= HWIF(hwgroup
->drive
);
703 printk("%s : Adding missed hwif to hwgroup!!\n", hwif
->name
);
706 restore_flags(flags
); /* all CPUs; safe now that hwif->hwgroup is set up */
708 #if !defined(__mc68000__) && !defined(CONFIG_APUS) && !defined(__sparc__)
709 printk("%s at 0x%03x-0x%03x,0x%03x on irq %d", hwif
->name
,
710 hwif
->io_ports
[IDE_DATA_OFFSET
],
711 hwif
->io_ports
[IDE_DATA_OFFSET
]+7,
712 hwif
->io_ports
[IDE_CONTROL_OFFSET
], hwif
->irq
);
713 #elif defined(__sparc__)
714 printk("%s at 0x%03lx-0x%03lx,0x%03lx on irq %s", hwif
->name
,
715 hwif
->io_ports
[IDE_DATA_OFFSET
],
716 hwif
->io_ports
[IDE_DATA_OFFSET
]+7,
717 hwif
->io_ports
[IDE_CONTROL_OFFSET
], __irq_itoa(hwif
->irq
));
719 printk("%s at %p on irq 0x%08x", hwif
->name
,
720 hwif
->io_ports
[IDE_DATA_OFFSET
], hwif
->irq
);
721 #endif /* __mc68000__ && CONFIG_APUS */
723 printk(" (%sed with %s)",
724 hwif
->sharing_irq
? "shar" : "serializ", match
->name
);
730 * init_gendisk() (as opposed to ide_geninit) is called for each major device,
731 * after probing for drives, to allocate partition tables and other data
732 * structures needed for the routines in genhd.c. ide_geninit() gets called
733 * somewhat later, during the partition check.
735 static void init_gendisk (ide_hwif_t
*hwif
)
737 struct gendisk
*gd
, **gdp
;
738 unsigned int unit
, units
, minors
;
739 int *bs
, *max_sect
, *max_ra
;
740 extern devfs_handle_t ide_devfs_handle
;
742 /* figure out maximum drive number on the interface */
743 for (units
= MAX_DRIVES
; units
> 0; --units
) {
744 if (hwif
->drives
[units
-1].present
)
747 minors
= units
* (1<<PARTN_BITS
);
748 gd
= kmalloc (sizeof(struct gendisk
), GFP_KERNEL
);
749 gd
->sizes
= kmalloc (minors
* sizeof(int), GFP_KERNEL
);
750 gd
->part
= kmalloc (minors
* sizeof(struct hd_struct
), GFP_KERNEL
);
751 bs
= kmalloc (minors
*sizeof(int), GFP_KERNEL
);
752 max_sect
= kmalloc (minors
*sizeof(int), GFP_KERNEL
);
753 max_ra
= kmalloc (minors
*sizeof(int), GFP_KERNEL
);
755 memset(gd
->part
, 0, minors
* sizeof(struct hd_struct
));
757 /* cdroms and msdos f/s are examples of non-1024 blocksizes */
758 blksize_size
[hwif
->major
] = bs
;
759 max_sectors
[hwif
->major
] = max_sect
;
760 max_readahead
[hwif
->major
] = max_ra
;
761 for (unit
= 0; unit
< minors
; ++unit
) {
763 #ifdef CONFIG_BLK_DEV_PDC4030
764 *max_sect
++ = ((hwif
->chipset
== ide_pdc4030
) ? 127 : MAX_SECTORS
);
766 *max_sect
++ = MAX_SECTORS
;
768 *max_ra
++ = MAX_READAHEAD
;
771 for (unit
= 0; unit
< units
; ++unit
)
772 hwif
->drives
[unit
].part
= &gd
->part
[unit
<< PARTN_BITS
];
774 gd
->major
= hwif
->major
; /* our major device number */
775 gd
->major_name
= IDE_MAJOR_NAME
; /* treated special in genhd.c */
776 gd
->minor_shift
= PARTN_BITS
; /* num bits for partitions */
777 gd
->max_p
= 1<<PARTN_BITS
; /* 1 + max partitions / drive */
778 gd
->nr_real
= units
; /* current num real drives */
779 gd
->real_devices
= hwif
; /* ptr to internal data */
780 gd
->next
= NULL
; /* linked list of major devs */
781 gd
->fops
= ide_fops
; /* file operations */
782 gd
->de_arr
= kmalloc (sizeof *gd
->de_arr
* units
, GFP_KERNEL
);
783 gd
->flags
= kmalloc (sizeof *gd
->flags
* units
, GFP_KERNEL
);
785 memset (gd
->de_arr
, 0, sizeof *gd
->de_arr
* units
);
787 memset (gd
->flags
, 0, sizeof *gd
->flags
* units
);
789 for (gdp
= &gendisk_head
; *gdp
; gdp
= &((*gdp
)->next
)) ;
790 hwif
->gd
= *gdp
= gd
; /* link onto tail of list */
792 for (unit
= 0; unit
< units
; ++unit
) {
793 if (hwif
->drives
[unit
].present
) {
796 ide_add_generic_settings(hwif
->drives
+ unit
);
797 hwif
->drives
[unit
].dn
= ((hwif
->channel
? 2 : 0) + unit
);
798 sprintf (name
, "host%d/bus%d/target%d/lun%d",
799 (hwif
->channel
&& hwif
->mate
) ? hwif
->mate
->index
: hwif
->index
,
800 hwif
->channel
, unit
, hwif
->drives
[unit
].lun
);
801 hwif
->drives
[unit
].de
=
802 devfs_mk_dir (ide_devfs_handle
, name
, NULL
);
807 static int hwif_init (ide_hwif_t
*hwif
)
812 if (!(hwif
->irq
= ide_default_irq(hwif
->io_ports
[IDE_DATA_OFFSET
])))
814 printk("%s: DISABLED, NO IRQ\n", hwif
->name
);
815 return (hwif
->present
= 0);
818 #ifdef CONFIG_BLK_DEV_HD
819 if (hwif
->irq
== HD_IRQ
&& hwif
->io_ports
[IDE_DATA_OFFSET
] != HD_DATA
) {
820 printk("%s: CANNOT SHARE IRQ WITH OLD HARDDISK DRIVER (hd.c)\n", hwif
->name
);
821 return (hwif
->present
= 0);
823 #endif /* CONFIG_BLK_DEV_HD */
825 hwif
->present
= 0; /* we set it back to 1 if all is ok below */
827 if (devfs_register_blkdev (hwif
->major
, hwif
->name
, ide_fops
)) {
828 printk("%s: UNABLE TO GET MAJOR NUMBER %d\n", hwif
->name
, hwif
->major
);
829 return (hwif
->present
= 0);
832 if (init_irq(hwif
)) {
835 * It failed to initialise. Find the default IRQ for
836 * this port and try that.
838 if (!(hwif
->irq
= ide_default_irq(hwif
->io_ports
[IDE_DATA_OFFSET
]))) {
839 printk("%s: Disabled unable to get IRQ %d.\n", hwif
->name
, i
);
840 (void) unregister_blkdev (hwif
->major
, hwif
->name
);
841 return (hwif
->present
= 0);
843 if (init_irq(hwif
)) {
844 printk("%s: probed IRQ %d and default IRQ %d failed.\n",
845 hwif
->name
, i
, hwif
->irq
);
846 (void) unregister_blkdev (hwif
->major
, hwif
->name
);
847 return (hwif
->present
= 0);
849 printk("%s: probed IRQ %d failed, using default.\n",
850 hwif
->name
, hwif
->irq
);
854 blk_dev
[hwif
->major
].data
= hwif
;
855 blk_dev
[hwif
->major
].queue
= ide_get_queue
;
856 read_ahead
[hwif
->major
] = 8; /* (4kB) */
857 hwif
->present
= 1; /* success */
859 #if (DEBUG_SPINLOCK > 0)
863 printk("io_request_lock is %p\n", &io_request_lock
); /* FIXME */
866 return hwif
->present
;
869 int ideprobe_init (void);
870 static ide_module_t ideprobe_module
= {
876 int ideprobe_init (void)
879 int probe
[MAX_HWIFS
];
882 memset(probe
, 0, MAX_HWIFS
* sizeof(int));
883 for (index
= 0; index
< MAX_HWIFS
; ++index
)
884 probe
[index
] = !ide_hwifs
[index
].present
;
887 * Probe for drives in the usual way.. CMOS/BIOS, then poke at ports
889 for (index
= 0; index
< MAX_HWIFS
; ++index
)
891 probe_hwif(&ide_hwifs
[index
]);
892 for (index
= 0; index
< MAX_HWIFS
; ++index
)
894 hwif_init(&ide_hwifs
[index
]);
896 ide_probe
= &ideprobe_module
;
902 int init_module (void)
906 for (index
= 0; index
< MAX_HWIFS
; ++index
)
907 ide_unregister(index
);
909 create_proc_ide_interfaces();
913 void cleanup_module (void)