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>
46 #include <asm/byteorder.h>
48 #include <asm/uaccess.h>
51 static inline void do_identify (ide_drive_t
*drive
, byte cmd
)
54 struct hd_driveid
*id
;
56 id
= drive
->id
= kmalloc (SECTOR_WORDS
*4, GFP_ATOMIC
); /* called with interrupts disabled! */
57 ide_input_data(drive
, id
, SECTOR_WORDS
); /* read 512 bytes of id info */
58 ide__sti(); /* local CPU only */
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 id
->model
[sizeof(id
->model
)-1] = '\0'; /* we depend on this a lot! */
89 printk("%s: %s, ", drive
->name
, id
->model
);
93 * Check for an ATAPI device
95 if (cmd
== WIN_PIDENTIFY
) {
96 byte type
= (id
->config
>> 8) & 0x1f;
98 #ifdef CONFIG_BLK_DEV_PDC4030
99 if (HWIF(drive
)->channel
== 1 && HWIF(drive
)->chipset
== ide_pdc4030
) {
100 printk(" -- not supported on 2nd Promise port\n");
104 #endif /* CONFIG_BLK_DEV_PDC4030 */
107 if (!strstr(id
->model
, "CD-ROM")) {
108 if (!strstr(id
->model
, "oppy") && !strstr(id
->model
, "poyp") && !strstr(id
->model
, "ZIP"))
109 printk("cdrom or floppy?, assuming ");
110 if (drive
->media
!= ide_cdrom
) {
115 type
= ide_cdrom
; /* Early cdrom models used zero */
118 drive
->removable
= 1;
125 drive
->removable
= 1;
128 printk("UNKNOWN (type %d)", type
);
137 * Not an ATAPI device: looks like a "regular" hard disk
139 if (id
->config
& (1<<7))
140 drive
->removable
= 1;
142 * Prevent long system lockup probing later for non-existant
143 * slave drive if the hwif is actually a flash memory card of some variety:
145 if (drive_is_flashcard(drive
)) {
146 ide_drive_t
*mate
= &HWIF(drive
)->drives
[1^drive
->select
.b
.unit
];
147 if (!mate
->ata_flash
) {
152 drive
->media
= ide_disk
;
153 printk("ATA DISK drive\n");
158 * try_to_identify() sends an ATA(PI) IDENTIFY request to a drive
159 * and waits for a response. It also monitors irqs while this is
160 * happening, in hope of automatically determining which one is
161 * being used by the interface.
163 * Returns: 0 device was identified
164 * 1 device timed-out (no response to identify request)
165 * 2 device aborted the command (refused to identify itself)
167 static int try_to_identify (ide_drive_t
*drive
, byte cmd
)
170 ide_ioreg_t hd_status
;
171 unsigned long timeout
;
172 unsigned long irqs
= 0;
175 if (IDE_CONTROL_REG
) {
176 if (!HWIF(drive
)->irq
) { /* already got an IRQ? */
177 probe_irq_off(probe_irq_on()); /* clear dangling irqs */
178 irqs
= probe_irq_on(); /* start monitoring irqs */
179 OUT_BYTE(drive
->ctl
,IDE_CONTROL_REG
); /* enable device irq */
182 ide_delay_50ms(); /* take a deep breath */
183 a
= IN_BYTE(IDE_ALTSTATUS_REG
);
184 s
= IN_BYTE(IDE_STATUS_REG
);
185 if ((a
^ s
) & ~INDEX_STAT
) {
186 printk("%s: probing with STATUS(0x%02x) instead of ALTSTATUS(0x%02x)\n", drive
->name
, s
, a
);
187 hd_status
= IDE_STATUS_REG
; /* ancient Seagate drives, broken interfaces */
189 hd_status
= IDE_ALTSTATUS_REG
; /* use non-intrusive polling */
193 hd_status
= IDE_STATUS_REG
;
196 #if CONFIG_BLK_DEV_PDC4030
197 if (HWIF(drive
)->chipset
== ide_pdc4030
) {
198 /* DC4030 hosted drives need their own identify... */
199 extern int pdc4030_identify(ide_drive_t
*);
200 if (pdc4030_identify(drive
)) {
202 (void) probe_irq_off(irqs
);
206 #endif /* CONFIG_BLK_DEV_PDC4030 */
207 OUT_BYTE(cmd
,IDE_COMMAND_REG
); /* ask drive for ID */
208 timeout
= ((cmd
== WIN_IDENTIFY
) ? WAIT_WORSTCASE
: WAIT_PIDENTIFY
) / 2;
211 if (0 < (signed long)(jiffies
- timeout
)) {
213 (void) probe_irq_off(irqs
);
214 return 1; /* drive timed-out */
216 ide_delay_50ms(); /* give drive a breather */
217 } while (IN_BYTE(hd_status
) & BUSY_STAT
);
219 ide_delay_50ms(); /* wait for IRQ and DRQ_STAT */
220 if (OK_STAT(GET_STAT(),DRQ_STAT
,BAD_R_STAT
)) {
222 __save_flags(flags
); /* local CPU only */
223 __cli(); /* local CPU only; some systems need this */
224 do_identify(drive
, cmd
); /* drive returned ID */
225 rc
= 0; /* drive responded with ID */
226 (void) GET_STAT(); /* clear drive IRQ */
227 __restore_flags(flags
); /* local CPU only */
229 rc
= 2; /* drive refused ID */
230 if (IDE_CONTROL_REG
&& !HWIF(drive
)->irq
) {
231 irqs
= probe_irq_off(irqs
); /* get our irq number */
233 HWIF(drive
)->irq
= irqs
; /* save it for later */
234 irqs
= probe_irq_on();
235 OUT_BYTE(drive
->ctl
|2,IDE_CONTROL_REG
); /* mask device irq */
237 (void) probe_irq_off(irqs
);
238 (void) probe_irq_off(probe_irq_on()); /* clear self-inflicted irq */
239 (void) GET_STAT(); /* clear drive IRQ */
241 } else { /* Mmmm.. multiple IRQs.. don't know which was ours */
242 printk("%s: IRQ probe failed (%ld)\n", drive
->name
, irqs
);
243 #ifdef CONFIG_BLK_DEV_CMD640
244 #ifdef CMD640_DUMP_REGS
245 if (HWIF(drive
)->chipset
== ide_cmd640
) {
246 printk("%s: Hmmm.. probably a driver problem.\n", drive
->name
);
249 #endif /* CMD640_DUMP_REGS */
250 #endif /* CONFIG_BLK_DEV_CMD640 */
257 * do_probe() has the difficult job of finding a drive if it exists,
258 * without getting hung up if it doesn't exist, without trampling on
259 * ethernet cards, and without leaving any IRQs dangling to haunt us later.
261 * If a drive is "known" to exist (from CMOS or kernel parameters),
262 * but does not respond right away, the probe will "hang in there"
263 * for the maximum wait time (about 30 seconds), otherwise it will
264 * exit much more quickly.
266 * Returns: 0 device was identified
267 * 1 device timed-out (no response to identify request)
268 * 2 device aborted the command (refused to identify itself)
269 * 3 bad status from device (possible for ATAPI drives)
270 * 4 probe was not attempted because failure was obvious
272 static int do_probe (ide_drive_t
*drive
, byte cmd
)
275 ide_hwif_t
*hwif
= HWIF(drive
);
276 if (drive
->present
) { /* avoid waiting for inappropriate probes */
277 if ((drive
->media
!= ide_disk
) && (cmd
== WIN_IDENTIFY
))
281 printk("probing for %s: present=%d, media=%d, probetype=%s\n",
282 drive
->name
, drive
->present
, drive
->media
,
283 (cmd
== WIN_IDENTIFY
) ? "ATA" : "ATAPI");
285 SELECT_DRIVE(hwif
,drive
);
287 if (IN_BYTE(IDE_SELECT_REG
) != drive
->select
.all
&& !drive
->present
) {
288 if (drive
->select
.b
.unit
!= 0) {
289 SELECT_DRIVE(hwif
,&hwif
->drives
[0]); /* exit with drive0 selected */
290 ide_delay_50ms(); /* allow BUSY_STAT to assert & clear */
292 return 3; /* no i/f present: mmm.. this should be a 4 -ml */
295 if (OK_STAT(GET_STAT(),READY_STAT
,BUSY_STAT
)
296 || drive
->present
|| cmd
== WIN_PIDENTIFY
)
298 if ((rc
= try_to_identify(drive
,cmd
))) /* send cmd and wait */
299 rc
= try_to_identify(drive
,cmd
); /* failed: try again */
300 if (rc
== 1 && cmd
== WIN_PIDENTIFY
&& drive
->autotune
!= 2) {
301 unsigned long timeout
;
302 printk("%s: no response (status = 0x%02x), resetting drive\n", drive
->name
, GET_STAT());
304 OUT_BYTE (drive
->select
.all
, IDE_SELECT_REG
);
306 OUT_BYTE(WIN_SRST
, IDE_COMMAND_REG
);
308 while ((GET_STAT() & BUSY_STAT
) && time_before(jiffies
, timeout
+ WAIT_WORSTCASE
))
310 rc
= try_to_identify(drive
, cmd
);
313 printk("%s: no response (status = 0x%02x)\n", drive
->name
, GET_STAT());
314 (void) GET_STAT(); /* ensure drive irq is clear */
316 rc
= 3; /* not present or maybe ATAPI */
318 if (drive
->select
.b
.unit
!= 0) {
319 SELECT_DRIVE(hwif
,&hwif
->drives
[0]); /* exit with drive0 selected */
321 (void) GET_STAT(); /* ensure drive irq is clear */
327 * probe_for_drive() tests for existence of a given drive using do_probe().
329 * Returns: 0 no device was found
330 * 1 device was found (note: drive->present might still be 0)
332 static inline byte
probe_for_drive (ide_drive_t
*drive
)
334 if (drive
->noprobe
) /* skip probing? */
335 return drive
->present
;
336 if (do_probe(drive
, WIN_IDENTIFY
) >= 2) { /* if !(success||timed-out) */
337 (void) do_probe(drive
, WIN_PIDENTIFY
); /* look for ATAPI device */
340 return 0; /* drive not found */
341 if (drive
->id
== NULL
) { /* identification failed? */
342 if (drive
->media
== ide_disk
) {
343 printk ("%s: non-IDE drive, CHS=%d/%d/%d\n",
344 drive
->name
, drive
->cyl
, drive
->head
, drive
->sect
);
345 } else if (drive
->media
== ide_cdrom
) {
346 printk("%s: ATAPI cdrom (?)\n", drive
->name
);
348 drive
->present
= 0; /* nuke it */
351 return 1; /* drive was found */
355 * This routine only knows how to look for drive units 0 and 1
356 * on an interface, so any setting of MAX_DRIVES > 2 won't work here.
358 static void probe_hwif (ide_hwif_t
*hwif
)
363 ide_ioreg_t ide_control_reg
= hwif
->io_ports
[IDE_CONTROL_OFFSET
];
364 ide_ioreg_t region_low
= hwif
->io_ports
[IDE_DATA_OFFSET
];
365 ide_ioreg_t region_high
= region_low
;
366 ide_ioreg_t region_request
= 8;
371 if (hwif
->io_ports
[IDE_DATA_OFFSET
] == HD_DATA
) {
372 extern void probe_cmos_for_drives(ide_hwif_t
*hwif
);
374 probe_cmos_for_drives (hwif
);
378 * Calculate the region that this interface occupies,
379 * handling interfaces where the registers may not be
380 * ordered sanely. We deal with the CONTROL register
383 for (i
= IDE_DATA_OFFSET
; i
<= IDE_STATUS_OFFSET
; i
++) {
384 if (hwif
->io_ports
[i
]) {
385 if (hwif
->io_ports
[i
] < region_low
)
386 region_low
= hwif
->io_ports
[i
];
387 if (hwif
->io_ports
[i
] > region_high
)
388 region_high
= hwif
->io_ports
[i
];
391 region_request
= (region_high
- region_low
);
392 if (region_request
== 0x0007)
394 if ((hwif
->chipset
!= ide_4drives
|| !hwif
->mate
->present
) &&
395 #if CONFIG_BLK_DEV_PDC4030
396 (hwif
->chipset
!= ide_pdc4030
|| hwif
->channel
== 0) &&
397 #endif /* CONFIG_BLK_DEV_PDC4030 */
398 (ide_check_region(region_low
, region_request
) ||
399 (ide_control_reg
&& ide_check_region(ide_control_reg
,1))))
402 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
403 ide_drive_t
*drive
= &hwif
->drives
[unit
];
404 if (drive
->present
) {
406 printk("%s: ERROR, PORTS ALREADY IN USE\n", drive
->name
);
411 printk("%s: ports already in use, skipping probe\n", hwif
->name
);
415 __save_flags(flags
); /* local CPU only */
416 __sti(); /* local CPU only; needed for jiffies and irq probing */
418 * Second drive should only exist if first drive was found,
419 * but a lot of cdrom drives are configured as single slaves.
421 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
422 ide_drive_t
*drive
= &hwif
->drives
[unit
];
423 (void) probe_for_drive (drive
);
424 if (drive
->present
&& !hwif
->present
) {
426 if (hwif
->chipset
!= ide_4drives
|| !hwif
->mate
->present
) {
427 ide_request_region(region_low
, region_request
, hwif
->name
);
429 ide_request_region(ide_control_reg
, 1, hwif
->name
);
433 if (ide_control_reg
&& hwif
->reset
) {
434 unsigned long timeout
= jiffies
+ WAIT_WORSTCASE
;
437 printk("%s: reset\n", hwif
->name
);
438 OUT_BYTE(12, ide_control_reg
);
440 OUT_BYTE(8, ide_control_reg
);
443 stat
= IN_BYTE(hwif
->io_ports
[IDE_STATUS_OFFSET
]);
444 } while ((stat
& BUSY_STAT
) && 0 < (signed long)(timeout
- jiffies
));
447 __restore_flags(flags
); /* local CPU only */
448 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
449 ide_drive_t
*drive
= &hwif
->drives
[unit
];
450 if (drive
->present
) {
451 ide_tuneproc_t
*tuneproc
= HWIF(drive
)->tuneproc
;
452 if (tuneproc
!= NULL
&& drive
->autotune
== 1)
453 tuneproc(drive
, 255); /* auto-tune PIO mode */
460 * save_match() is used to simplify logic in init_irq() below.
462 * A loophole here is that we may not know about a particular
463 * hwif's irq until after that hwif is actually probed/initialized..
464 * This could be a problem for the case where an hwif is on a
465 * dual interface that requires serialization (eg. cmd640) and another
466 * hwif using one of the same irqs is initialized beforehand.
468 * This routine detects and reports such situations, but does not fix them.
470 static void save_match (ide_hwif_t
*hwif
, ide_hwif_t
*new, ide_hwif_t
**match
)
472 ide_hwif_t
*m
= *match
;
474 if (m
&& m
->hwgroup
&& m
->hwgroup
!= new->hwgroup
) {
477 printk("%s: potential irq problem with %s and %s\n", hwif
->name
, new->name
, m
->name
);
479 if (!m
|| m
->irq
!= hwif
->irq
) /* don't undo a prior perfect match */
482 #endif /* MAX_HWIFS > 1 */
485 * This routine sets up the irq for an ide interface, and creates a new
486 * hwgroup for the irq/hwif if none was previously assigned.
488 * Much of the code is for correctly detecting/handling irq sharing
489 * and irq serialization situations. This is somewhat complex because
490 * it handles static as well as dynamic (PCMCIA) IDE interfaces.
492 * The SA_INTERRUPT in sa_flags means ide_intr() is always entered with
493 * interrupts completely disabled. This can be bad for interrupt latency,
494 * but anything else has led to problems on some machines. We re-enable
495 * interrupts as much as we can safely do in most places.
497 static int init_irq (ide_hwif_t
*hwif
)
501 ide_hwgroup_t
*hwgroup
;
502 ide_hwif_t
*match
= NULL
;
504 save_flags(flags
); /* all CPUs */
505 cli(); /* all CPUs */
507 hwif
->hwgroup
= NULL
;
510 * Group up with any other hwifs that share our irq(s).
512 for (index
= 0; index
< MAX_HWIFS
; index
++) {
513 ide_hwif_t
*h
= &ide_hwifs
[index
];
514 if (h
->hwgroup
) { /* scan only initialized hwif's */
515 if (hwif
->irq
== h
->irq
) {
516 hwif
->sharing_irq
= h
->sharing_irq
= 1;
517 if (hwif
->chipset
!= ide_pci
|| h
->chipset
!= ide_pci
) {
518 save_match(hwif
, h
, &match
);
521 if (hwif
->serialized
) {
522 if (hwif
->mate
&& hwif
->mate
->irq
== h
->irq
)
523 save_match(hwif
, h
, &match
);
526 if (h
->mate
&& hwif
->irq
== h
->mate
->irq
)
527 save_match(hwif
, h
, &match
);
531 #endif /* MAX_HWIFS > 1 */
533 * If we are still without a hwgroup, then form a new one
536 hwgroup
= match
->hwgroup
;
538 hwgroup
= kmalloc(sizeof(ide_hwgroup_t
), GFP_KERNEL
);
539 memset(hwgroup
, 0, sizeof(ide_hwgroup_t
));
540 hwgroup
->hwif
= hwif
->next
= hwif
;
542 hwgroup
->handler
= NULL
;
543 hwgroup
->drive
= NULL
;
545 hwgroup
->spinlock
= (spinlock_t
)SPIN_LOCK_UNLOCKED
;
546 #if (DEBUG_SPINLOCK > 0)
547 printk("hwgroup(%s) spinlock is %p\n", hwif
->name
, &hwgroup
->spinlock
); /* FIXME */
549 init_timer(&hwgroup
->timer
);
550 hwgroup
->timer
.function
= &ide_timer_expiry
;
551 hwgroup
->timer
.data
= (unsigned long) hwgroup
;
555 * Allocate the irq, if not already obtained for another hwif
557 if (!match
|| match
->irq
!= hwif
->irq
) {
558 int sa
= (hwif
->chipset
== ide_pci
) ? SA_INTERRUPT
|SA_SHIRQ
: SA_INTERRUPT
;
559 if (ide_request_irq(hwif
->irq
, &ide_intr
, sa
, hwif
->name
, hwgroup
)) {
562 restore_flags(flags
); /* all CPUs */
568 * Everything is okay, so link us into the hwgroup
570 hwif
->hwgroup
= hwgroup
;
571 hwif
->next
= hwgroup
->hwif
->next
;
572 hwgroup
->hwif
->next
= hwif
;
574 for (index
= 0; index
< MAX_DRIVES
; ++index
) {
575 ide_drive_t
*drive
= &hwif
->drives
[index
];
579 hwgroup
->drive
= drive
;
580 drive
->next
= hwgroup
->drive
->next
;
581 hwgroup
->drive
->next
= drive
;
583 if (!hwgroup
->hwif
) {
584 hwgroup
->hwif
= HWIF(hwgroup
->drive
);
586 printk("%s : Adding missed hwif to hwgroup!!\n", hwif
->name
);
589 restore_flags(flags
); /* all CPUs; safe now that hwif->hwgroup is set up */
591 #if !defined(__mc68000__) && !defined(CONFIG_APUS) && !defined(__sparc__)
592 printk("%s at 0x%03x-0x%03x,0x%03x on irq %d", hwif
->name
,
593 hwif
->io_ports
[IDE_DATA_OFFSET
],
594 hwif
->io_ports
[IDE_DATA_OFFSET
]+7,
595 hwif
->io_ports
[IDE_CONTROL_OFFSET
], hwif
->irq
);
596 #elif defined(__sparc__)
597 printk("%s at 0x%03x-0x%03x,0x%03x on irq %s", hwif
->name
,
598 hwif
->io_ports
[IDE_DATA_OFFSET
],
599 hwif
->io_ports
[IDE_DATA_OFFSET
]+7,
600 hwif
->io_ports
[IDE_CONTROL_OFFSET
], __irq_itoa(hwif
->irq
));
602 printk("%s at %p on irq 0x%08x", hwif
->name
,
603 hwif
->io_ports
[IDE_DATA_OFFSET
], hwif
->irq
);
604 #endif /* __mc68000__ && CONFIG_APUS */
606 printk(" (%sed with %s)",
607 hwif
->sharing_irq
? "shar" : "serializ", match
->name
);
613 * init_gendisk() (as opposed to ide_geninit) is called for each major device,
614 * after probing for drives, to allocate partition tables and other data
615 * structures needed for the routines in genhd.c. ide_geninit() gets called
616 * somewhat later, during the partition check.
618 static void init_gendisk (ide_hwif_t
*hwif
)
620 struct gendisk
*gd
, **gdp
;
621 unsigned int unit
, units
, minors
;
622 int *bs
, *max_sect
, *max_ra
;
624 /* figure out maximum drive number on the interface */
625 for (units
= MAX_DRIVES
; units
> 0; --units
) {
626 if (hwif
->drives
[units
-1].present
)
629 minors
= units
* (1<<PARTN_BITS
);
630 gd
= kmalloc (sizeof(struct gendisk
), GFP_KERNEL
);
631 gd
->sizes
= kmalloc (minors
* sizeof(int), GFP_KERNEL
);
632 gd
->part
= kmalloc (minors
* sizeof(struct hd_struct
), GFP_KERNEL
);
633 bs
= kmalloc (minors
*sizeof(int), GFP_KERNEL
);
634 max_sect
= kmalloc (minors
*sizeof(int), GFP_KERNEL
);
635 max_ra
= kmalloc (minors
*sizeof(int), GFP_KERNEL
);
637 memset(gd
->part
, 0, minors
* sizeof(struct hd_struct
));
639 /* cdroms and msdos f/s are examples of non-1024 blocksizes */
640 blksize_size
[hwif
->major
] = bs
;
641 max_sectors
[hwif
->major
] = max_sect
;
642 max_readahead
[hwif
->major
] = max_ra
;
643 for (unit
= 0; unit
< minors
; ++unit
) {
645 #ifdef CONFIG_BLK_DEV_PDC4030
646 *max_sect
++ = ((hwif
->chipset
== ide_pdc4030
) ? 127 : MAX_SECTORS
);
648 *max_sect
++ = MAX_SECTORS
;
650 *max_ra
++ = MAX_READAHEAD
;
653 for (unit
= 0; unit
< units
; ++unit
)
654 hwif
->drives
[unit
].part
= &gd
->part
[unit
<< PARTN_BITS
];
656 gd
->major
= hwif
->major
; /* our major device number */
657 gd
->major_name
= IDE_MAJOR_NAME
; /* treated special in genhd.c */
658 gd
->minor_shift
= PARTN_BITS
; /* num bits for partitions */
659 gd
->max_p
= 1<<PARTN_BITS
; /* 1 + max partitions / drive */
660 gd
->max_nr
= units
; /* max num real drives */
661 gd
->nr_real
= units
; /* current num real drives */
662 gd
->init
= &ide_geninit
; /* initialization function */
663 gd
->real_devices
= hwif
; /* ptr to internal data */
664 gd
->next
= NULL
; /* linked list of major devs */
666 for (gdp
= &gendisk_head
; *gdp
; gdp
= &((*gdp
)->next
)) ;
667 hwif
->gd
= *gdp
= gd
; /* link onto tail of list */
669 for (unit
= 0; unit
< units
; ++unit
) {
670 if (hwif
->drives
[unit
].present
)
671 ide_add_generic_settings(hwif
->drives
+ unit
);
675 static int hwif_init (ide_hwif_t
*hwif
)
682 if (!(hwif
->irq
= ide_default_irq(hwif
->io_ports
[IDE_DATA_OFFSET
])))
684 printk("%s: DISABLED, NO IRQ\n", hwif
->name
);
685 return (hwif
->present
= 0);
688 #ifdef CONFIG_BLK_DEV_HD
689 if (hwif
->irq
== HD_IRQ
&& hwif
->io_ports
[IDE_DATA_OFFSET
] != HD_DATA
) {
690 printk("%s: CANNOT SHARE IRQ WITH OLD HARDDISK DRIVER (hd.c)\n", hwif
->name
);
691 return (hwif
->present
= 0);
693 #endif /* CONFIG_BLK_DEV_HD */
695 hwif
->present
= 0; /* we set it back to 1 if all is ok below */
696 switch (hwif
->major
) {
697 case IDE0_MAJOR
: rfn
= &do_ide0_request
; break;
699 case IDE1_MAJOR
: rfn
= &do_ide1_request
; break;
702 case IDE2_MAJOR
: rfn
= &do_ide2_request
; break;
705 case IDE3_MAJOR
: rfn
= &do_ide3_request
; break;
708 case IDE4_MAJOR
: rfn
= &do_ide4_request
; break;
711 case IDE5_MAJOR
: rfn
= &do_ide5_request
; break;
714 case IDE6_MAJOR
: rfn
= &do_ide6_request
; break;
717 case IDE7_MAJOR
: rfn
= &do_ide7_request
; break;
720 case IDE8_MAJOR
: rfn
= &do_ide8_request
; break;
723 case IDE9_MAJOR
: rfn
= &do_ide9_request
; break;
726 printk("%s: request_fn NOT DEFINED\n", hwif
->name
);
727 return (hwif
->present
= 0);
729 if (register_blkdev (hwif
->major
, hwif
->name
, ide_fops
)) {
730 printk("%s: UNABLE TO GET MAJOR NUMBER %d\n", hwif
->name
, hwif
->major
);
731 return (hwif
->present
= 0);
734 if (init_irq (hwif
)) {
737 * It failed to initialise. Find the default IRQ for
738 * this port and try that.
740 if (!(hwif
->irq
= ide_default_irq(hwif
->io_ports
[IDE_DATA_OFFSET
])))
742 printk("%s: Disabled unable to get IRQ %d.\n", hwif
->name
, i
);
743 (void) unregister_blkdev (hwif
->major
, hwif
->name
);
744 return (hwif
->present
= 0);
748 printk("%s: probed IRQ %d and default IRQ %d failed.\n",
749 hwif
->name
, i
, hwif
->irq
);
750 (void) unregister_blkdev (hwif
->major
, hwif
->name
);
751 return (hwif
->present
= 0);
753 printk("%s: probed IRQ %d failed, using default.\n",
754 hwif
->name
, hwif
->irq
);
758 blk_dev
[hwif
->major
].data
= hwif
;
759 blk_dev
[hwif
->major
].request_fn
= rfn
;
760 blk_dev
[hwif
->major
].queue
= ide_get_queue
;
761 read_ahead
[hwif
->major
] = 8; /* (4kB) */
762 hwif
->present
= 1; /* success */
764 #if (DEBUG_SPINLOCK > 0)
768 printk("io_request_lock is %p\n", &io_request_lock
); /* FIXME */
771 return hwif
->present
;
774 int ideprobe_init (void);
775 static ide_module_t ideprobe_module
= {
781 int ideprobe_init (void)
784 int probe
[MAX_HWIFS
];
787 memset(probe
, 0, MAX_HWIFS
* sizeof(int));
788 for (index
= 0; index
< MAX_HWIFS
; ++index
)
789 probe
[index
] = !ide_hwifs
[index
].present
;
792 * Probe for drives in the usual way.. CMOS/BIOS, then poke at ports
794 for (index
= 0; index
< MAX_HWIFS
; ++index
)
796 probe_hwif(&ide_hwifs
[index
]);
797 for (index
= 0; index
< MAX_HWIFS
; ++index
)
799 hwif_init(&ide_hwifs
[index
]);
800 ide_register_module(&ideprobe_module
);
806 int init_module (void)
810 for (index
= 0; index
< MAX_HWIFS
; ++index
)
811 ide_unregister(index
);
813 create_proc_ide_interfaces();
817 void cleanup_module (void)
819 ide_unregister_module(&ideprobe_module
);