2 * linux/drivers/block/ide-probe.c Version 1.05 July 3, 1999
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>
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
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)
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>
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>
47 #include <asm/uaccess.h>
50 static inline void do_identify (ide_drive_t
*drive
, byte cmd
)
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 */
59 if (!drive
->forced_lun
)
60 drive
->last_lun
= id
->last_lun
& 0x7;
61 #if defined (CONFIG_SCSI_EATA_DMA) || defined (CONFIG_SCSI_EATA_PIO) || defined (CONFIG_SCSI_EATA)
63 * EATA SCSI controllers do a hardware ATA emulation:
64 * Ignore them if there is a driver for them available.
66 if ((id
->model
[0] == 'P' && id
->model
[1] == 'M')
67 || (id
->model
[0] == 'S' && id
->model
[1] == 'K')) {
68 printk("%s: EATA SCSI HBA %.10s\n", drive
->name
, id
->model
);
72 #endif /* CONFIG_SCSI_EATA_DMA || CONFIG_SCSI_EATA_PIO */
75 * WIN_IDENTIFY returns little-endian info,
76 * WIN_PIDENTIFY *usually* returns little-endian info.
78 if (cmd
== WIN_PIDENTIFY
) {
79 if ((id
->model
[0] == 'N' && id
->model
[1] == 'E') /* NEC */
80 || (id
->model
[0] == 'F' && id
->model
[1] == 'X') /* Mitsumi */
81 || (id
->model
[0] == 'P' && id
->model
[1] == 'i'))/* Pioneer */
82 bswap
^= 1; /* Vertos drives may still be weird */
84 ide_fixstring (id
->model
, sizeof(id
->model
), bswap
);
85 ide_fixstring (id
->fw_rev
, sizeof(id
->fw_rev
), bswap
);
86 ide_fixstring (id
->serial_no
, sizeof(id
->serial_no
), bswap
);
88 if (strstr(id
->model
, "E X A B Y T E N E S T"))
91 id
->model
[sizeof(id
->model
)-1] = '\0'; /* we depend on this a lot! */
92 printk("%s: %s, ", drive
->name
, id
->model
);
96 * Check for an ATAPI device
98 if (cmd
== WIN_PIDENTIFY
) {
99 byte type
= (id
->config
>> 8) & 0x1f;
101 #ifdef CONFIG_BLK_DEV_PDC4030
102 if (HWIF(drive
)->channel
== 1 && HWIF(drive
)->chipset
== ide_pdc4030
) {
103 printk(" -- not supported on 2nd Promise port\n");
107 #endif /* CONFIG_BLK_DEV_PDC4030 */
110 if (!strstr(id
->model
, "CD-ROM")) {
111 if (!strstr(id
->model
, "oppy") && !strstr(id
->model
, "poyp") && !strstr(id
->model
, "ZIP"))
112 printk("cdrom or floppy?, assuming ");
113 if (drive
->media
!= ide_cdrom
) {
118 type
= ide_cdrom
; /* Early cdrom models used zero */
120 drive
->removable
= 1;
122 /* kludge for Apple PowerBook internal zip */
123 if (!strstr(id
->model
, "CD-ROM") && strstr(id
->model
, "ZIP")) {
136 drive
->removable
= 1;
139 printk("UNKNOWN (type %d)", type
);
148 * Not an ATAPI device: looks like a "regular" hard disk
150 if (id
->config
& (1<<7))
151 drive
->removable
= 1;
153 * Prevent long system lockup probing later for non-existant
154 * slave drive if the hwif is actually a flash memory card of some variety:
156 if (drive_is_flashcard(drive
)) {
157 ide_drive_t
*mate
= &HWIF(drive
)->drives
[1^drive
->select
.b
.unit
];
158 if (!mate
->ata_flash
) {
163 drive
->media
= ide_disk
;
164 printk("ATA DISK drive\n");
169 * try_to_identify() sends an ATA(PI) IDENTIFY request to a drive
170 * and waits for a response. It also monitors irqs while this is
171 * happening, in hope of automatically determining which one is
172 * being used by the interface.
174 * Returns: 0 device was identified
175 * 1 device timed-out (no response to identify request)
176 * 2 device aborted the command (refused to identify itself)
178 static int try_to_identify (ide_drive_t
*drive
, byte cmd
)
181 ide_ioreg_t hd_status
;
182 unsigned long timeout
;
183 unsigned long irqs
= 0;
186 if (IDE_CONTROL_REG
) {
187 if (!HWIF(drive
)->irq
) { /* already got an IRQ? */
188 probe_irq_off(probe_irq_on()); /* clear dangling irqs */
189 irqs
= probe_irq_on(); /* start monitoring irqs */
190 OUT_BYTE(drive
->ctl
,IDE_CONTROL_REG
); /* enable device irq */
193 ide_delay_50ms(); /* take a deep breath */
194 a
= IN_BYTE(IDE_ALTSTATUS_REG
);
195 s
= IN_BYTE(IDE_STATUS_REG
);
196 if ((a
^ s
) & ~INDEX_STAT
) {
197 printk("%s: probing with STATUS(0x%02x) instead of ALTSTATUS(0x%02x)\n", drive
->name
, s
, a
);
198 hd_status
= IDE_STATUS_REG
; /* ancient Seagate drives, broken interfaces */
200 hd_status
= IDE_ALTSTATUS_REG
; /* use non-intrusive polling */
204 hd_status
= IDE_STATUS_REG
;
207 #if CONFIG_BLK_DEV_PDC4030
208 if (HWIF(drive
)->chipset
== ide_pdc4030
) {
209 /* DC4030 hosted drives need their own identify... */
210 extern int pdc4030_identify(ide_drive_t
*);
211 if (pdc4030_identify(drive
)) {
213 (void) probe_irq_off(irqs
);
217 #endif /* CONFIG_BLK_DEV_PDC4030 */
218 OUT_BYTE(cmd
,IDE_COMMAND_REG
); /* ask drive for ID */
219 timeout
= ((cmd
== WIN_IDENTIFY
) ? WAIT_WORSTCASE
: WAIT_PIDENTIFY
) / 2;
222 if (0 < (signed long)(jiffies
- timeout
)) {
224 (void) probe_irq_off(irqs
);
225 return 1; /* drive timed-out */
227 ide_delay_50ms(); /* give drive a breather */
228 } while (IN_BYTE(hd_status
) & BUSY_STAT
);
230 ide_delay_50ms(); /* wait for IRQ and DRQ_STAT */
231 if (OK_STAT(GET_STAT(),DRQ_STAT
,BAD_R_STAT
)) {
233 __save_flags(flags
); /* local CPU only */
234 __cli(); /* local CPU only; some systems need this */
235 do_identify(drive
, cmd
); /* drive returned ID */
236 rc
= 0; /* drive responded with ID */
237 (void) GET_STAT(); /* clear drive IRQ */
238 __restore_flags(flags
); /* local CPU only */
240 rc
= 2; /* drive refused ID */
241 if (IDE_CONTROL_REG
&& !HWIF(drive
)->irq
) {
242 irqs
= probe_irq_off(irqs
); /* get our irq number */
244 HWIF(drive
)->irq
= irqs
; /* save it for later */
245 irqs
= probe_irq_on();
246 OUT_BYTE(drive
->ctl
|2,IDE_CONTROL_REG
); /* mask device irq */
248 (void) probe_irq_off(irqs
);
249 (void) probe_irq_off(probe_irq_on()); /* clear self-inflicted irq */
250 (void) GET_STAT(); /* clear drive IRQ */
252 } else { /* Mmmm.. multiple IRQs.. don't know which was ours */
253 printk("%s: IRQ probe failed (%ld)\n", drive
->name
, irqs
);
254 #ifdef CONFIG_BLK_DEV_CMD640
255 #ifdef CMD640_DUMP_REGS
256 if (HWIF(drive
)->chipset
== ide_cmd640
) {
257 printk("%s: Hmmm.. probably a driver problem.\n", drive
->name
);
260 #endif /* CMD640_DUMP_REGS */
261 #endif /* CONFIG_BLK_DEV_CMD640 */
268 * do_probe() has the difficult job of finding a drive if it exists,
269 * without getting hung up if it doesn't exist, without trampling on
270 * ethernet cards, and without leaving any IRQs dangling to haunt us later.
272 * If a drive is "known" to exist (from CMOS or kernel parameters),
273 * but does not respond right away, the probe will "hang in there"
274 * for the maximum wait time (about 30 seconds), otherwise it will
275 * exit much more quickly.
277 * Returns: 0 device was identified
278 * 1 device timed-out (no response to identify request)
279 * 2 device aborted the command (refused to identify itself)
280 * 3 bad status from device (possible for ATAPI drives)
281 * 4 probe was not attempted because failure was obvious
283 static int do_probe (ide_drive_t
*drive
, byte cmd
)
286 ide_hwif_t
*hwif
= HWIF(drive
);
287 if (drive
->present
) { /* avoid waiting for inappropriate probes */
288 if ((drive
->media
!= ide_disk
) && (cmd
== WIN_IDENTIFY
))
292 printk("probing for %s: present=%d, media=%d, probetype=%s\n",
293 drive
->name
, drive
->present
, drive
->media
,
294 (cmd
== WIN_IDENTIFY
) ? "ATA" : "ATAPI");
296 ide_delay_50ms(); /* needed for some systems (e.g. crw9624 as drive0 with disk as slave) */
297 SELECT_DRIVE(hwif
,drive
);
299 if (IN_BYTE(IDE_SELECT_REG
) != drive
->select
.all
&& !drive
->present
) {
300 if (drive
->select
.b
.unit
!= 0) {
301 SELECT_DRIVE(hwif
,&hwif
->drives
[0]); /* exit with drive0 selected */
302 ide_delay_50ms(); /* allow BUSY_STAT to assert & clear */
304 return 3; /* no i/f present: mmm.. this should be a 4 -ml */
307 if (OK_STAT(GET_STAT(),READY_STAT
,BUSY_STAT
)
308 || drive
->present
|| cmd
== WIN_PIDENTIFY
)
310 if ((rc
= try_to_identify(drive
,cmd
))) /* send cmd and wait */
311 rc
= try_to_identify(drive
,cmd
); /* failed: try again */
312 if (rc
== 1 && cmd
== WIN_PIDENTIFY
&& drive
->autotune
!= 2) {
313 unsigned long timeout
;
314 printk("%s: no response (status = 0x%02x), resetting drive\n", drive
->name
, GET_STAT());
316 OUT_BYTE (drive
->select
.all
, IDE_SELECT_REG
);
318 OUT_BYTE(WIN_SRST
, IDE_COMMAND_REG
);
320 while ((GET_STAT() & BUSY_STAT
) && time_before(jiffies
, timeout
+ WAIT_WORSTCASE
))
322 rc
= try_to_identify(drive
, cmd
);
325 printk("%s: no response (status = 0x%02x)\n", drive
->name
, GET_STAT());
326 (void) GET_STAT(); /* ensure drive irq is clear */
328 rc
= 3; /* not present or maybe ATAPI */
330 if (drive
->select
.b
.unit
!= 0) {
331 SELECT_DRIVE(hwif
,&hwif
->drives
[0]); /* exit with drive0 selected */
333 (void) GET_STAT(); /* ensure drive irq is clear */
341 static void enable_nest (ide_drive_t
*drive
)
343 unsigned long timeout
;
345 printk("%s: enabling %s -- ", HWIF(drive
)->name
, drive
->id
->model
);
346 SELECT_DRIVE(HWIF(drive
), drive
);
348 OUT_BYTE(EXABYTE_ENABLE_NEST
, IDE_COMMAND_REG
);
349 timeout
= jiffies
+ WAIT_WORSTCASE
;
351 if (jiffies
> timeout
) {
352 printk("failed (timeout)\n");
356 } while (GET_STAT() & BUSY_STAT
);
358 if (!OK_STAT(GET_STAT(), 0, BAD_STAT
))
359 printk("failed (status = 0x%02x)\n", GET_STAT());
362 if (do_probe(drive
, WIN_IDENTIFY
) >= 2) { /* if !(success||timed-out) */
363 (void) do_probe(drive
, WIN_PIDENTIFY
); /* look for ATAPI device */
368 * probe_for_drive() tests for existence of a given drive using do_probe().
370 * Returns: 0 no device was found
371 * 1 device was found (note: drive->present might still be 0)
373 static inline byte
probe_for_drive (ide_drive_t
*drive
)
375 if (drive
->noprobe
) /* skip probing? */
376 return drive
->present
;
377 if (do_probe(drive
, WIN_IDENTIFY
) >= 2) { /* if !(success||timed-out) */
378 (void) do_probe(drive
, WIN_PIDENTIFY
); /* look for ATAPI device */
380 if (drive
->id
&& strstr(drive
->id
->model
, "E X A B Y T E N E S T"))
383 return 0; /* drive not found */
384 if (drive
->id
== NULL
) { /* identification failed? */
385 if (drive
->media
== ide_disk
) {
386 printk ("%s: non-IDE drive, CHS=%d/%d/%d\n",
387 drive
->name
, drive
->cyl
, drive
->head
, drive
->sect
);
388 } else if (drive
->media
== ide_cdrom
) {
389 printk("%s: ATAPI cdrom (?)\n", drive
->name
);
391 drive
->present
= 0; /* nuke it */
394 return 1; /* drive was found */
398 * Calculate the region that this interface occupies,
399 * handling interfaces where the registers may not be
400 * ordered sanely. We deal with the CONTROL register
403 static int hwif_check_regions (ide_hwif_t
*hwif
)
405 int region_errors
= 0;
407 region_errors
= ide_check_region(hwif
->io_ports
[IDE_DATA_OFFSET
], 1);
408 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_ERROR_OFFSET
], 1);
409 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_NSECTOR_OFFSET
], 1);
410 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_SECTOR_OFFSET
], 1);
411 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_LCYL_OFFSET
], 1);
412 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_HCYL_OFFSET
], 1);
413 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_SELECT_OFFSET
], 1);
414 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_STATUS_OFFSET
], 1);
415 if (hwif
->io_ports
[IDE_CONTROL_OFFSET
])
416 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_CONTROL_OFFSET
], 1);
417 if (hwif
->io_ports
[IDE_IRQ_OFFSET
])
418 region_errors
+= ide_check_region(hwif
->io_ports
[IDE_IRQ_OFFSET
], 1);
420 return(region_errors
);
423 static void hwif_register (ide_hwif_t
*hwif
)
425 if (hwif
->io_ports
[IDE_DATA_OFFSET
])
426 ide_request_region(hwif
->io_ports
[IDE_DATA_OFFSET
], 1, hwif
->name
);
427 if (hwif
->io_ports
[IDE_ERROR_OFFSET
])
428 ide_request_region(hwif
->io_ports
[IDE_ERROR_OFFSET
], 1, hwif
->name
);
429 if (hwif
->io_ports
[IDE_NSECTOR_OFFSET
])
430 ide_request_region(hwif
->io_ports
[IDE_NSECTOR_OFFSET
], 1, hwif
->name
);
431 if (hwif
->io_ports
[IDE_SECTOR_OFFSET
])
432 ide_request_region(hwif
->io_ports
[IDE_SECTOR_OFFSET
], 1, hwif
->name
);
433 if (hwif
->io_ports
[IDE_LCYL_OFFSET
])
434 ide_request_region(hwif
->io_ports
[IDE_LCYL_OFFSET
], 1, hwif
->name
);
435 if (hwif
->io_ports
[IDE_HCYL_OFFSET
])
436 ide_request_region(hwif
->io_ports
[IDE_HCYL_OFFSET
], 1, hwif
->name
);
437 if (hwif
->io_ports
[IDE_SELECT_OFFSET
])
438 ide_request_region(hwif
->io_ports
[IDE_SELECT_OFFSET
], 1, hwif
->name
);
439 if (hwif
->io_ports
[IDE_STATUS_OFFSET
])
440 ide_request_region(hwif
->io_ports
[IDE_STATUS_OFFSET
], 1, hwif
->name
);
441 if (hwif
->io_ports
[IDE_CONTROL_OFFSET
])
442 ide_request_region(hwif
->io_ports
[IDE_CONTROL_OFFSET
], 1, hwif
->name
);
443 if (hwif
->io_ports
[IDE_IRQ_OFFSET
])
444 ide_request_region(hwif
->io_ports
[IDE_IRQ_OFFSET
], 1, hwif
->name
);
448 * This routine only knows how to look for drive units 0 and 1
449 * on an interface, so any setting of MAX_DRIVES > 2 won't work here.
451 static void probe_hwif (ide_hwif_t
*hwif
)
458 if (hwif
->io_ports
[IDE_DATA_OFFSET
] == HD_DATA
) {
459 extern void probe_cmos_for_drives(ide_hwif_t
*);
461 probe_cmos_for_drives (hwif
);
464 if ((hwif
->chipset
!= ide_4drives
|| !hwif
->mate
->present
) &&
465 #if CONFIG_BLK_DEV_PDC4030
466 (hwif
->chipset
!= ide_pdc4030
|| hwif
->channel
== 0) &&
467 #endif /* CONFIG_BLK_DEV_PDC4030 */
468 (hwif_check_regions(hwif
))) {
470 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
471 ide_drive_t
*drive
= &hwif
->drives
[unit
];
472 if (drive
->present
) {
474 printk("%s: ERROR, PORTS ALREADY IN USE\n", drive
->name
);
479 printk("%s: ports already in use, skipping probe\n", hwif
->name
);
483 __save_flags(flags
); /* local CPU only */
484 __sti(); /* local CPU only; needed for jiffies and irq probing */
486 * Second drive should only exist if first drive was found,
487 * but a lot of cdrom drives are configured as single slaves.
489 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
490 ide_drive_t
*drive
= &hwif
->drives
[unit
];
491 (void) probe_for_drive (drive
);
492 if (drive
->present
&& !hwif
->present
) {
494 if (hwif
->chipset
!= ide_4drives
|| !hwif
->mate
->present
) {
499 if (hwif
->io_ports
[IDE_CONTROL_OFFSET
] && hwif
->reset
) {
500 unsigned long timeout
= jiffies
+ WAIT_WORSTCASE
;
503 printk("%s: reset\n", hwif
->name
);
504 OUT_BYTE(12, hwif
->io_ports
[IDE_CONTROL_OFFSET
]);
506 OUT_BYTE(8, hwif
->io_ports
[IDE_CONTROL_OFFSET
]);
509 stat
= IN_BYTE(hwif
->io_ports
[IDE_STATUS_OFFSET
]);
510 } while ((stat
& BUSY_STAT
) && 0 < (signed long)(timeout
- jiffies
));
513 __restore_flags(flags
); /* local CPU only */
514 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
515 ide_drive_t
*drive
= &hwif
->drives
[unit
];
516 if (drive
->present
) {
517 ide_tuneproc_t
*tuneproc
= HWIF(drive
)->tuneproc
;
518 if (tuneproc
!= NULL
&& drive
->autotune
== 1)
519 tuneproc(drive
, 255); /* auto-tune PIO mode */
526 * save_match() is used to simplify logic in init_irq() below.
528 * A loophole here is that we may not know about a particular
529 * hwif's irq until after that hwif is actually probed/initialized..
530 * This could be a problem for the case where an hwif is on a
531 * dual interface that requires serialization (eg. cmd640) and another
532 * hwif using one of the same irqs is initialized beforehand.
534 * This routine detects and reports such situations, but does not fix them.
536 static void save_match (ide_hwif_t
*hwif
, ide_hwif_t
*new, ide_hwif_t
**match
)
538 ide_hwif_t
*m
= *match
;
540 if (m
&& m
->hwgroup
&& m
->hwgroup
!= new->hwgroup
) {
543 printk("%s: potential irq problem with %s and %s\n", hwif
->name
, new->name
, m
->name
);
545 if (!m
|| m
->irq
!= hwif
->irq
) /* don't undo a prior perfect match */
548 #endif /* MAX_HWIFS > 1 */
551 * This routine sets up the irq for an ide interface, and creates a new
552 * hwgroup for the irq/hwif if none was previously assigned.
554 * Much of the code is for correctly detecting/handling irq sharing
555 * and irq serialization situations. This is somewhat complex because
556 * it handles static as well as dynamic (PCMCIA) IDE interfaces.
558 * The SA_INTERRUPT in sa_flags means ide_intr() is always entered with
559 * interrupts completely disabled. This can be bad for interrupt latency,
560 * but anything else has led to problems on some machines. We re-enable
561 * interrupts as much as we can safely do in most places.
563 static int init_irq (ide_hwif_t
*hwif
)
567 ide_hwgroup_t
*hwgroup
;
568 ide_hwif_t
*match
= NULL
;
570 save_flags(flags
); /* all CPUs */
571 cli(); /* all CPUs */
573 hwif
->hwgroup
= NULL
;
576 * Group up with any other hwifs that share our irq(s).
578 for (index
= 0; index
< MAX_HWIFS
; index
++) {
579 ide_hwif_t
*h
= &ide_hwifs
[index
];
580 if (h
->hwgroup
) { /* scan only initialized hwif's */
581 if (hwif
->irq
== h
->irq
) {
582 hwif
->sharing_irq
= h
->sharing_irq
= 1;
583 if (hwif
->chipset
!= ide_pci
|| h
->chipset
!= ide_pci
) {
584 save_match(hwif
, h
, &match
);
587 if (hwif
->serialized
) {
588 if (hwif
->mate
&& hwif
->mate
->irq
== h
->irq
)
589 save_match(hwif
, h
, &match
);
592 if (h
->mate
&& hwif
->irq
== h
->mate
->irq
)
593 save_match(hwif
, h
, &match
);
597 #endif /* MAX_HWIFS > 1 */
599 * If we are still without a hwgroup, then form a new one
602 hwgroup
= match
->hwgroup
;
604 hwgroup
= kmalloc(sizeof(ide_hwgroup_t
), GFP_KERNEL
);
605 memset(hwgroup
, 0, sizeof(ide_hwgroup_t
));
606 hwgroup
->hwif
= hwif
->next
= hwif
;
608 hwgroup
->handler
= NULL
;
609 hwgroup
->drive
= NULL
;
611 init_timer(&hwgroup
->timer
);
612 hwgroup
->timer
.function
= &ide_timer_expiry
;
613 hwgroup
->timer
.data
= (unsigned long) hwgroup
;
617 * Allocate the irq, if not already obtained for another hwif
619 if (!match
|| match
->irq
!= hwif
->irq
) {
620 #ifdef CONFIG_IDEPCI_SHARE_IRQ
621 int sa
= (hwif
->chipset
== ide_pci
) ? SA_SHIRQ
: SA_INTERRUPT
;
622 #else /* !CONFIG_IDEPCI_SHARE_IRQ */
623 int sa
= (hwif
->chipset
== ide_pci
) ? SA_INTERRUPT
|SA_SHIRQ
: SA_INTERRUPT
;
624 #endif /* CONFIG_IDEPCI_SHARE_IRQ */
625 if (ide_request_irq(hwif
->irq
, &ide_intr
, sa
, hwif
->name
, hwgroup
)) {
628 restore_flags(flags
); /* all CPUs */
634 * Everything is okay, so link us into the hwgroup
636 hwif
->hwgroup
= hwgroup
;
637 hwif
->next
= hwgroup
->hwif
->next
;
638 hwgroup
->hwif
->next
= hwif
;
640 for (index
= 0; index
< MAX_DRIVES
; ++index
) {
641 ide_drive_t
*drive
= &hwif
->drives
[index
];
645 hwgroup
->drive
= drive
;
646 drive
->next
= hwgroup
->drive
->next
;
647 hwgroup
->drive
->next
= drive
;
649 if (!hwgroup
->hwif
) {
650 hwgroup
->hwif
= HWIF(hwgroup
->drive
);
652 printk("%s : Adding missed hwif to hwgroup!!\n", hwif
->name
);
655 restore_flags(flags
); /* all CPUs; safe now that hwif->hwgroup is set up */
657 #if !defined(__mc68000__) && !defined(CONFIG_APUS) && !defined(__sparc__)
658 printk("%s at 0x%03x-0x%03x,0x%03x on irq %d", hwif
->name
,
659 hwif
->io_ports
[IDE_DATA_OFFSET
],
660 hwif
->io_ports
[IDE_DATA_OFFSET
]+7,
661 hwif
->io_ports
[IDE_CONTROL_OFFSET
], hwif
->irq
);
662 #elif defined(__sparc__)
663 printk("%s at 0x%03lx-0x%03lx,0x%03lx on irq %s", hwif
->name
,
664 hwif
->io_ports
[IDE_DATA_OFFSET
],
665 hwif
->io_ports
[IDE_DATA_OFFSET
]+7,
666 hwif
->io_ports
[IDE_CONTROL_OFFSET
], __irq_itoa(hwif
->irq
));
668 printk("%s at %p on irq 0x%08x", hwif
->name
,
669 hwif
->io_ports
[IDE_DATA_OFFSET
], hwif
->irq
);
670 #endif /* __mc68000__ && CONFIG_APUS */
672 printk(" (%sed with %s)",
673 hwif
->sharing_irq
? "shar" : "serializ", match
->name
);
679 * init_gendisk() (as opposed to ide_geninit) is called for each major device,
680 * after probing for drives, to allocate partition tables and other data
681 * structures needed for the routines in genhd.c. ide_geninit() gets called
682 * somewhat later, during the partition check.
684 static void init_gendisk (ide_hwif_t
*hwif
)
686 struct gendisk
*gd
, **gdp
;
687 unsigned int unit
, units
, minors
;
688 int *bs
, *max_sect
, *max_ra
;
690 /* figure out maximum drive number on the interface */
691 for (units
= MAX_DRIVES
; units
> 0; --units
) {
692 if (hwif
->drives
[units
-1].present
)
695 minors
= units
* (1<<PARTN_BITS
);
696 gd
= kmalloc (sizeof(struct gendisk
), GFP_KERNEL
);
697 gd
->sizes
= kmalloc (minors
* sizeof(int), GFP_KERNEL
);
698 gd
->part
= kmalloc (minors
* sizeof(struct hd_struct
), GFP_KERNEL
);
699 bs
= kmalloc (minors
*sizeof(int), GFP_KERNEL
);
700 max_sect
= kmalloc (minors
*sizeof(int), GFP_KERNEL
);
701 max_ra
= kmalloc (minors
*sizeof(int), GFP_KERNEL
);
703 memset(gd
->part
, 0, minors
* sizeof(struct hd_struct
));
705 /* cdroms and msdos f/s are examples of non-1024 blocksizes */
706 blksize_size
[hwif
->major
] = bs
;
707 max_sectors
[hwif
->major
] = max_sect
;
708 max_readahead
[hwif
->major
] = max_ra
;
709 for (unit
= 0; unit
< minors
; ++unit
) {
711 #ifdef CONFIG_BLK_DEV_PDC4030
712 *max_sect
++ = ((hwif
->chipset
== ide_pdc4030
) ? 127 : MAX_SECTORS
);
714 *max_sect
++ = MAX_SECTORS
;
716 *max_ra
++ = MAX_READAHEAD
;
719 for (unit
= 0; unit
< units
; ++unit
)
720 hwif
->drives
[unit
].part
= &gd
->part
[unit
<< PARTN_BITS
];
722 gd
->major
= hwif
->major
; /* our major device number */
723 gd
->major_name
= IDE_MAJOR_NAME
; /* treated special in genhd.c */
724 gd
->minor_shift
= PARTN_BITS
; /* num bits for partitions */
725 gd
->max_p
= 1<<PARTN_BITS
; /* 1 + max partitions / drive */
726 gd
->nr_real
= units
; /* current num real drives */
727 gd
->real_devices
= hwif
; /* ptr to internal data */
728 gd
->next
= NULL
; /* linked list of major devs */
729 gd
->fops
= ide_fops
; /* file operations */
730 gd
->de_arr
= kmalloc (sizeof *gd
->de_arr
* units
, GFP_KERNEL
);
731 gd
->flags
= kmalloc (sizeof *gd
->flags
* units
, GFP_KERNEL
);
733 memset (gd
->de_arr
, 0, sizeof *gd
->de_arr
* units
);
735 memset (gd
->flags
, 0, sizeof *gd
->flags
* units
);
737 for (gdp
= &gendisk_head
; *gdp
; gdp
= &((*gdp
)->next
)) ;
738 hwif
->gd
= *gdp
= gd
; /* link onto tail of list */
740 for (unit
= 0; unit
< units
; ++unit
) {
741 if (hwif
->drives
[unit
].present
) {
744 ide_add_generic_settings(hwif
->drives
+ unit
);
745 sprintf (name
, "ide/host%d/bus%d/target%d/lun%d",
746 hwif
->channel
? hwif
->mate
->index
: hwif
->index
,
747 hwif
->channel
, unit
, 0);
748 hwif
->drives
[unit
].de
=
749 devfs_mk_dir (NULL
, name
, 0, NULL
);
754 static int hwif_init (ide_hwif_t
*hwif
)
757 void (*rfn
)(request_queue_t
*);
762 if (!(hwif
->irq
= ide_default_irq(hwif
->io_ports
[IDE_DATA_OFFSET
])))
764 printk("%s: DISABLED, NO IRQ\n", hwif
->name
);
765 return (hwif
->present
= 0);
768 #ifdef CONFIG_BLK_DEV_HD
769 if (hwif
->irq
== HD_IRQ
&& hwif
->io_ports
[IDE_DATA_OFFSET
] != HD_DATA
) {
770 printk("%s: CANNOT SHARE IRQ WITH OLD HARDDISK DRIVER (hd.c)\n", hwif
->name
);
771 return (hwif
->present
= 0);
773 #endif /* CONFIG_BLK_DEV_HD */
775 hwif
->present
= 0; /* we set it back to 1 if all is ok below */
776 switch (hwif
->major
) {
777 case IDE0_MAJOR
: rfn
= &do_ide0_request
; break;
779 case IDE1_MAJOR
: rfn
= &do_ide1_request
; break;
782 case IDE2_MAJOR
: rfn
= &do_ide2_request
; break;
785 case IDE3_MAJOR
: rfn
= &do_ide3_request
; break;
788 case IDE4_MAJOR
: rfn
= &do_ide4_request
; break;
791 case IDE5_MAJOR
: rfn
= &do_ide5_request
; break;
794 case IDE6_MAJOR
: rfn
= &do_ide6_request
; break;
797 case IDE7_MAJOR
: rfn
= &do_ide7_request
; break;
800 case IDE8_MAJOR
: rfn
= &do_ide8_request
; break;
803 case IDE9_MAJOR
: rfn
= &do_ide9_request
; break;
806 printk("%s: request_fn NOT DEFINED\n", hwif
->name
);
807 return (hwif
->present
= 0);
809 if (devfs_register_blkdev (hwif
->major
, hwif
->name
, ide_fops
)) {
810 printk("%s: UNABLE TO GET MAJOR NUMBER %d\n", hwif
->name
, hwif
->major
);
811 return (hwif
->present
= 0);
814 if (init_irq(hwif
)) {
817 * It failed to initialise. Find the default IRQ for
818 * this port and try that.
820 if (!(hwif
->irq
= ide_default_irq(hwif
->io_ports
[IDE_DATA_OFFSET
]))) {
821 printk("%s: Disabled unable to get IRQ %d.\n", hwif
->name
, i
);
822 (void) unregister_blkdev (hwif
->major
, hwif
->name
);
823 return (hwif
->present
= 0);
825 if (init_irq(hwif
)) {
826 printk("%s: probed IRQ %d and default IRQ %d failed.\n",
827 hwif
->name
, i
, hwif
->irq
);
828 (void) unregister_blkdev (hwif
->major
, hwif
->name
);
829 return (hwif
->present
= 0);
831 printk("%s: probed IRQ %d failed, using default.\n",
832 hwif
->name
, hwif
->irq
);
836 blk_dev
[hwif
->major
].data
= hwif
;
837 blk_dev
[hwif
->major
].queue
= ide_get_queue
;
838 read_ahead
[hwif
->major
] = 8; /* (4kB) */
839 hwif
->present
= 1; /* success */
842 * FIXME(eric) - This needs to be tested. I *think* that this
843 * is correct. Also, I believe that there is no longer any
844 * reason to have multiple functions (do_ide[0-7]_request)
845 * functions - the queuedata field could be used to indicate
846 * the correct hardware group - either this, or we could add
847 * a new field to request_queue_t to hold this information.
849 drive
= &hwif
->drives
[0];
850 blk_init_queue(&drive
->queue
, rfn
);
852 drive
= &hwif
->drives
[1];
853 blk_init_queue(&drive
->queue
, rfn
);
855 #if (DEBUG_SPINLOCK > 0)
859 printk("io_request_lock is %p\n", &io_request_lock
); /* FIXME */
862 return hwif
->present
;
865 int ideprobe_init (void);
866 static ide_module_t ideprobe_module
= {
872 int ideprobe_init (void)
875 int probe
[MAX_HWIFS
];
878 memset(probe
, 0, MAX_HWIFS
* sizeof(int));
879 for (index
= 0; index
< MAX_HWIFS
; ++index
)
880 probe
[index
] = !ide_hwifs
[index
].present
;
883 * Probe for drives in the usual way.. CMOS/BIOS, then poke at ports
885 for (index
= 0; index
< MAX_HWIFS
; ++index
)
887 probe_hwif(&ide_hwifs
[index
]);
888 for (index
= 0; index
< MAX_HWIFS
; ++index
)
890 hwif_init(&ide_hwifs
[index
]);
892 ide_probe
= &ideprobe_module
;
898 int init_module (void)
902 for (index
= 0; index
< MAX_HWIFS
; ++index
)
903 ide_unregister(index
);
905 create_proc_ide_interfaces();
909 void cleanup_module (void)