More meth updates.
[linux-2.6/linux-mips.git] / drivers / ide / ide-probe.c
blob8a6826761a2da5aab9fb49a404b3ad62d9284fd9
1 /*
2 * linux/drivers/ide/ide-probe.c Version 1.11 Mar 05, 2003
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>
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
19 * by Andrea Arcangeli
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)
24 * added ide6/7/8/9
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.
28 * Version 1.07 max_sect <= 255; slower disks would get behind and
29 * then fall over when they get to 256. Paul G.
30 * Version 1.10 Update set for new IDE. drive->id is now always
31 * valid after probe time even with noprobe
34 #undef REALLY_SLOW_IO /* most systems can safely undef this */
36 #include <linux/config.h>
37 #include <linux/module.h>
38 #include <linux/types.h>
39 #include <linux/string.h>
40 #include <linux/kernel.h>
41 #include <linux/timer.h>
42 #include <linux/mm.h>
43 #include <linux/interrupt.h>
44 #include <linux/major.h>
45 #include <linux/errno.h>
46 #include <linux/genhd.h>
47 #include <linux/slab.h>
48 #include <linux/delay.h>
49 #include <linux/ide.h>
50 #include <linux/spinlock.h>
51 #include <linux/pci.h>
52 #include <linux/kmod.h>
54 #include <asm/byteorder.h>
55 #include <asm/irq.h>
56 #include <asm/uaccess.h>
57 #include <asm/io.h>
59 /**
60 * generic_id - add a generic drive id
61 * @drive: drive to make an ID block for
63 * Add a fake id field to the drive we are passed. This allows
64 * use to skip a ton of NULL checks (which people always miss)
65 * and make drive properties unconditional outside of this file
68 static void generic_id(ide_drive_t *drive)
70 drive->id->cyls = drive->cyl;
71 drive->id->heads = drive->head;
72 drive->id->sectors = drive->sect;
73 drive->id->cur_cyls = drive->cyl;
74 drive->id->cur_heads = drive->head;
75 drive->id->cur_sectors = drive->sect;
78 /**
79 * drive_is_flashcard - check for compact flash
80 * @drive: drive to check
82 * CompactFlash cards and their brethern pretend to be removable
83 * hard disks, except:
84 * (1) they never have a slave unit, and
85 * (2) they don't have doorlock mechanisms.
86 * This test catches them, and is invoked elsewhere when setting
87 * appropriate config bits.
89 * FIXME: This treatment is probably applicable for *all* PCMCIA (PC CARD)
90 * devices, so in linux 2.3.x we should change this to just treat all
91 * PCMCIA drives this way, and get rid of the model-name tests below
92 * (too big of an interface change for 2.4.x).
93 * At that time, we might also consider parameterizing the timeouts and
94 * retries, since these are MUCH faster than mechanical drives. -M.Lord
97 static inline int drive_is_flashcard (ide_drive_t *drive)
99 struct hd_driveid *id = drive->id;
101 if (drive->removable) {
102 if (id->config == 0x848a) return 1; /* CompactFlash */
103 if (!strncmp(id->model, "KODAK ATA_FLASH", 15) /* Kodak */
104 || !strncmp(id->model, "Hitachi CV", 10) /* Hitachi */
105 || !strncmp(id->model, "SunDisk SDCFB", 13) /* SunDisk */
106 || !strncmp(id->model, "HAGIWARA HPC", 12) /* Hagiwara */
107 || !strncmp(id->model, "LEXAR ATA_FLASH", 15) /* Lexar */
108 || !strncmp(id->model, "ATA_FLASH", 9)) /* Simple Tech */
110 return 1; /* yes, it is a flash memory card */
113 return 0; /* no, it is not a flash memory card */
117 * do_identify - identify a drive
118 * @drive: drive to identify
119 * @cmd: command used
121 * Called when we have issued a drive identify command to
122 * read and parse the results. This function is run with
123 * interrupts disabled.
126 static inline void do_identify (ide_drive_t *drive, u8 cmd)
128 ide_hwif_t *hwif = HWIF(drive);
129 int bswap = 1;
130 struct hd_driveid *id;
132 id = drive->id;
133 /* read 512 bytes of id info */
134 hwif->ata_input_data(drive, id, SECTOR_WORDS);
136 drive->id_read = 1;
137 local_irq_enable();
138 ide_fix_driveid(id);
140 if (!drive->forced_lun)
141 drive->last_lun = id->last_lun & 0x7;
143 #if defined (CONFIG_SCSI_EATA_DMA) || defined (CONFIG_SCSI_EATA_PIO) || defined (CONFIG_SCSI_EATA)
145 * EATA SCSI controllers do a hardware ATA emulation:
146 * Ignore them if there is a driver for them available.
148 if ((id->model[0] == 'P' && id->model[1] == 'M') ||
149 (id->model[0] == 'S' && id->model[1] == 'K')) {
150 printk("%s: EATA SCSI HBA %.10s\n", drive->name, id->model);
151 goto err_misc;
153 #endif /* CONFIG_SCSI_EATA_DMA || CONFIG_SCSI_EATA_PIO */
156 * WIN_IDENTIFY returns little-endian info,
157 * WIN_PIDENTIFY *usually* returns little-endian info.
159 if (cmd == WIN_PIDENTIFY) {
160 if ((id->model[0] == 'N' && id->model[1] == 'E') /* NEC */
161 || (id->model[0] == 'F' && id->model[1] == 'X') /* Mitsumi */
162 || (id->model[0] == 'P' && id->model[1] == 'i'))/* Pioneer */
163 /* Vertos drives may still be weird */
164 bswap ^= 1;
166 ide_fixstring(id->model, sizeof(id->model), bswap);
167 ide_fixstring(id->fw_rev, sizeof(id->fw_rev), bswap);
168 ide_fixstring(id->serial_no, sizeof(id->serial_no), bswap);
170 if (strstr(id->model, "E X A B Y T E N E S T"))
171 goto err_misc;
173 /* we depend on this a lot! */
174 id->model[sizeof(id->model)-1] = '\0';
175 printk("%s: %s, ", drive->name, id->model);
176 drive->present = 1;
177 drive->dead = 0;
180 * Check for an ATAPI device
182 if (cmd == WIN_PIDENTIFY) {
183 u8 type = (id->config >> 8) & 0x1f;
184 printk("ATAPI ");
185 #ifdef CONFIG_BLK_DEV_PDC4030
186 if (hwif->channel == 1 && hwif->chipset == ide_pdc4030) {
187 printk(" -- not supported on 2nd Promise port\n");
188 goto err_misc;
190 #endif /* CONFIG_BLK_DEV_PDC4030 */
191 switch (type) {
192 case ide_floppy:
193 if (!strstr(id->model, "CD-ROM")) {
194 if (!strstr(id->model, "oppy") &&
195 !strstr(id->model, "poyp") &&
196 !strstr(id->model, "ZIP"))
197 printk("cdrom or floppy?, assuming ");
198 if (drive->media != ide_cdrom) {
199 printk ("FLOPPY");
200 drive->removable = 1;
201 break;
204 /* Early cdrom models used zero */
205 type = ide_cdrom;
206 case ide_cdrom:
207 drive->removable = 1;
208 #ifdef CONFIG_PPC
209 /* kludge for Apple PowerBook internal zip */
210 if (!strstr(id->model, "CD-ROM") &&
211 strstr(id->model, "ZIP")) {
212 printk ("FLOPPY");
213 type = ide_floppy;
214 break;
216 #endif
217 printk ("CD/DVD-ROM");
218 break;
219 case ide_tape:
220 printk ("TAPE");
221 break;
222 case ide_optical:
223 printk ("OPTICAL");
224 drive->removable = 1;
225 break;
226 default:
227 printk("UNKNOWN (type %d)", type);
228 break;
230 printk (" drive\n");
231 drive->media = type;
232 return;
236 * Not an ATAPI device: looks like a "regular" hard disk
238 if (id->config & (1<<7))
239 drive->removable = 1;
242 * Prevent long system lockup probing later for non-existant
243 * slave drive if the hwif is actually a flash memory card of
244 * some variety:
246 drive->is_flash = 0;
247 if (drive_is_flashcard(drive)) {
248 #if 0
249 /* The new IDE adapter widgets don't follow this heuristic
250 so we must nowdays just bite the bullet and take the
251 probe hit */
252 ide_drive_t *mate = &hwif->drives[1^drive->select.b.unit];
253 ide_drive_t *mate = &hwif->drives[1^drive->select.b.unit];
254 if (!mate->ata_flash) {
255 mate->present = 0;
256 mate->noprobe = 1;
258 #endif
259 drive->is_flash = 1;
261 drive->media = ide_disk;
262 printk("%s DISK drive\n", (drive->is_flash) ? "CFA" : "ATA" );
263 QUIRK_LIST(drive);
265 /* Initialize queue depth settings */
266 drive->queue_depth = 1;
267 #ifdef CONFIG_BLK_DEV_IDE_TCQ_DEPTH
268 drive->queue_depth = CONFIG_BLK_DEV_IDE_TCQ_DEPTH;
269 #else
270 drive->queue_depth = drive->id->queue_depth + 1;
271 #endif
272 if (drive->queue_depth < 1 || drive->queue_depth > IDE_MAX_TAG)
273 drive->queue_depth = IDE_MAX_TAG;
275 return;
277 err_misc:
278 kfree(id);
279 drive->present = 0;
280 return;
284 * actual_try_to_identify - send ata/atapi identify
285 * @drive: drive to identify
286 * @cmd: command to use
288 * try_to_identify() sends an ATA(PI) IDENTIFY request to a drive
289 * and waits for a response. It also monitors irqs while this is
290 * happening, in hope of automatically determining which one is
291 * being used by the interface.
293 * Returns: 0 device was identified
294 * 1 device timed-out (no response to identify request)
295 * 2 device aborted the command (refused to identify itself)
298 static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
300 ide_hwif_t *hwif = HWIF(drive);
301 int rc;
302 unsigned long hd_status;
303 unsigned long timeout;
304 u8 s = 0, a = 0;
306 if (IDE_CONTROL_REG) {
307 /* take a deep breath */
308 ide_delay_50ms();
309 a = hwif->INB(IDE_ALTSTATUS_REG);
310 s = hwif->INB(IDE_STATUS_REG);
311 if ((a ^ s) & ~INDEX_STAT) {
312 printk(KERN_INFO "%s: probing with STATUS(0x%02x) instead of "
313 "ALTSTATUS(0x%02x)\n", drive->name, s, a);
314 /* ancient Seagate drives, broken interfaces */
315 hd_status = IDE_STATUS_REG;
316 } else {
317 /* use non-intrusive polling */
318 hd_status = IDE_ALTSTATUS_REG;
320 } else {
321 ide_delay_50ms();
322 hd_status = IDE_STATUS_REG;
325 /* set features register for atapi
326 * identify command to be sure of reply
328 if ((cmd == WIN_PIDENTIFY))
329 /* disable dma & overlap */
330 hwif->OUTB(0, IDE_FEATURE_REG);
332 if (hwif->identify != NULL) {
333 if (hwif->identify(drive))
334 return 1;
335 } else {
336 /* ask drive for ID */
337 hwif->OUTB(cmd, IDE_COMMAND_REG);
339 timeout = ((cmd == WIN_IDENTIFY) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
340 timeout += jiffies;
341 do {
342 if (time_after(jiffies, timeout)) {
343 /* drive timed-out */
344 return 1;
346 /* give drive a breather */
347 ide_delay_50ms();
348 } while ((hwif->INB(hd_status)) & BUSY_STAT);
350 /* wait for IRQ and DRQ_STAT */
351 ide_delay_50ms();
352 if (OK_STAT((hwif->INB(IDE_STATUS_REG)), DRQ_STAT, BAD_R_STAT)) {
353 unsigned long flags;
355 /* local CPU only; some systems need this */
356 local_irq_save(flags);
357 /* drive returned ID */
358 do_identify(drive, cmd);
359 /* drive responded with ID */
360 rc = 0;
361 /* clear drive IRQ */
362 (void) hwif->INB(IDE_STATUS_REG);
363 local_irq_restore(flags);
364 } else {
365 /* drive refused ID */
366 rc = 2;
368 return rc;
372 * try_to_identify - try to identify a drive
373 * @drive: drive to probe
374 * @cmd: command to use
376 * Issue the identify command and then do IRQ probing to
377 * complete the identification when needed by finding the
378 * IRQ the drive is attached to
381 static int try_to_identify (ide_drive_t *drive, u8 cmd)
383 ide_hwif_t *hwif = HWIF(drive);
384 int retval;
385 int autoprobe = 0;
386 unsigned long cookie = 0;
388 if (IDE_CONTROL_REG && !hwif->irq) {
389 autoprobe = 1;
390 cookie = probe_irq_on();
391 /* enable device irq */
392 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
395 retval = actual_try_to_identify(drive, cmd);
397 if (autoprobe) {
398 int irq;
399 /* mask device irq */
400 hwif->OUTB(drive->ctl|2, IDE_CONTROL_REG);
401 /* clear drive IRQ */
402 (void) hwif->INB(IDE_STATUS_REG);
403 udelay(5);
404 irq = probe_irq_off(cookie);
405 if (!hwif->irq) {
406 if (irq > 0) {
407 hwif->irq = irq;
408 } else {
409 /* Mmmm.. multiple IRQs..
410 * don't know which was ours
412 printk("%s: IRQ probe failed (0x%lx)\n",
413 drive->name, cookie);
414 #ifdef CONFIG_BLK_DEV_CMD640
415 #ifdef CMD640_DUMP_REGS
416 if (hwif->chipset == ide_cmd640) {
417 printk("%s: Hmmm.. probably a driver "
418 "problem.\n", drive->name);
419 CMD640_DUMP_REGS;
421 #endif /* CMD640_DUMP_REGS */
422 #endif /* CONFIG_BLK_DEV_CMD640 */
426 return retval;
431 * do_probe - probe an IDE device
432 * @drive: drive to probe
433 * @cmd: command to use
435 * do_probe() has the difficult job of finding a drive if it exists,
436 * without getting hung up if it doesn't exist, without trampling on
437 * ethernet cards, and without leaving any IRQs dangling to haunt us later.
439 * If a drive is "known" to exist (from CMOS or kernel parameters),
440 * but does not respond right away, the probe will "hang in there"
441 * for the maximum wait time (about 30 seconds), otherwise it will
442 * exit much more quickly.
444 * Returns: 0 device was identified
445 * 1 device timed-out (no response to identify request)
446 * 2 device aborted the command (refused to identify itself)
447 * 3 bad status from device (possible for ATAPI drives)
448 * 4 probe was not attempted because failure was obvious
451 static int do_probe (ide_drive_t *drive, u8 cmd)
453 int rc;
454 ide_hwif_t *hwif = HWIF(drive);
456 if (drive->present) {
457 /* avoid waiting for inappropriate probes */
458 if ((drive->media != ide_disk) && (cmd == WIN_IDENTIFY))
459 return 4;
461 #ifdef DEBUG
462 printk("probing for %s: present=%d, media=%d, probetype=%s\n",
463 drive->name, drive->present, drive->media,
464 (cmd == WIN_IDENTIFY) ? "ATA" : "ATAPI");
465 #endif
467 /* needed for some systems
468 * (e.g. crw9624 as drive0 with disk as slave)
470 ide_delay_50ms();
471 SELECT_DRIVE(drive);
472 ide_delay_50ms();
473 if (hwif->INB(IDE_SELECT_REG) != drive->select.all && !drive->present) {
474 if (drive->select.b.unit != 0) {
475 /* exit with drive0 selected */
476 SELECT_DRIVE(&hwif->drives[0]);
477 /* allow BUSY_STAT to assert & clear */
478 ide_delay_50ms();
480 /* no i/f present: mmm.. this should be a 4 -ml */
481 return 3;
484 if (OK_STAT((hwif->INB(IDE_STATUS_REG)), READY_STAT, BUSY_STAT) ||
485 drive->present || cmd == WIN_PIDENTIFY) {
486 /* send cmd and wait */
487 if ((rc = try_to_identify(drive, cmd))) {
488 /* failed: try again */
489 rc = try_to_identify(drive,cmd);
491 if (hwif->INB(IDE_STATUS_REG) == (BUSY_STAT|READY_STAT))
492 return 4;
494 if ((rc == 1 && cmd == WIN_PIDENTIFY) &&
495 ((drive->autotune == IDE_TUNE_DEFAULT) ||
496 (drive->autotune == IDE_TUNE_AUTO))) {
497 unsigned long timeout;
498 printk("%s: no response (status = 0x%02x), "
499 "resetting drive\n", drive->name,
500 hwif->INB(IDE_STATUS_REG));
501 ide_delay_50ms();
502 hwif->OUTB(drive->select.all, IDE_SELECT_REG);
503 ide_delay_50ms();
504 hwif->OUTB(WIN_SRST, IDE_COMMAND_REG);
505 timeout = jiffies;
506 while (((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) &&
507 time_before(jiffies, timeout + WAIT_WORSTCASE))
508 ide_delay_50ms();
509 rc = try_to_identify(drive, cmd);
511 if (rc == 1)
512 printk("%s: no response (status = 0x%02x)\n",
513 drive->name, hwif->INB(IDE_STATUS_REG));
514 /* ensure drive irq is clear */
515 (void) hwif->INB(IDE_STATUS_REG);
516 } else {
517 /* not present or maybe ATAPI */
518 rc = 3;
520 if (drive->select.b.unit != 0) {
521 /* exit with drive0 selected */
522 SELECT_DRIVE(&hwif->drives[0]);
523 ide_delay_50ms();
524 /* ensure drive irq is clear */
525 (void) hwif->INB(IDE_STATUS_REG);
527 return rc;
533 static void enable_nest (ide_drive_t *drive)
535 ide_hwif_t *hwif = HWIF(drive);
536 unsigned long timeout;
538 printk("%s: enabling %s -- ", hwif->name, drive->id->model);
539 SELECT_DRIVE(drive);
540 ide_delay_50ms();
541 hwif->OUTB(EXABYTE_ENABLE_NEST, IDE_COMMAND_REG);
542 timeout = jiffies + WAIT_WORSTCASE;
543 do {
544 if (time_after(jiffies, timeout)) {
545 printk("failed (timeout)\n");
546 return;
548 ide_delay_50ms();
549 } while ((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT);
551 ide_delay_50ms();
553 if (!OK_STAT((hwif->INB(IDE_STATUS_REG)), 0, BAD_STAT)) {
554 printk("failed (status = 0x%02x)\n", hwif->INB(IDE_STATUS_REG));
555 } else {
556 printk("success\n");
559 /* if !(success||timed-out) */
560 if (do_probe(drive, WIN_IDENTIFY) >= 2) {
561 /* look for ATAPI device */
562 (void) do_probe(drive, WIN_PIDENTIFY);
567 * probe_for_drives - upper level drive probe
568 * @drive: drive to probe for
570 * probe_for_drive() tests for existence of a given drive using do_probe()
571 * and presents things to the user as needed.
573 * Returns: 0 no device was found
574 * 1 device was found (note: drive->present might
575 * still be 0)
578 static inline u8 probe_for_drive (ide_drive_t *drive)
581 * In order to keep things simple we have an id
582 * block for all drives at all times. If the device
583 * is pre ATA or refuses ATA/ATAPI identify we
584 * will add faked data to this.
586 * Also note that 0 everywhere means "can't do X"
589 drive->id = kmalloc(SECTOR_WORDS *4, GFP_KERNEL);
590 drive->id_read = 0;
591 if(drive->id == NULL)
593 printk(KERN_ERR "ide: out of memory for id data.\n");
594 return 0;
596 memset(drive->id, 0, SECTOR_WORDS * 4);
597 strcpy(drive->id->model, "UNKNOWN");
599 /* skip probing? */
600 if (!drive->noprobe)
602 /* if !(success||timed-out) */
603 if (do_probe(drive, WIN_IDENTIFY) >= 2) {
604 /* look for ATAPI device */
605 (void) do_probe(drive, WIN_PIDENTIFY);
607 if (strstr(drive->id->model, "E X A B Y T E N E S T"))
608 enable_nest(drive);
609 if (!drive->present)
610 /* drive not found */
611 return 0;
613 /* identification failed? */
614 if (!drive->id_read) {
615 if (drive->media == ide_disk) {
616 printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n",
617 drive->name, drive->cyl,
618 drive->head, drive->sect);
619 } else if (drive->media == ide_cdrom) {
620 printk(KERN_INFO "%s: ATAPI cdrom (?)\n", drive->name);
621 } else {
622 /* nuke it */
623 printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name);
624 drive->present = 0;
627 /* drive was found */
629 if(!drive->present)
630 return 0;
631 /* The drive wasn't being helpful. Add generic info only */
632 if(!drive->id_read)
633 generic_id(drive);
634 return drive->present;
637 static int hwif_check_region(ide_hwif_t *hwif, unsigned long addr, int num)
639 int err;
641 if(hwif->mmio)
642 err = check_mem_region(addr, num);
643 else
644 err = check_region(addr, num);
646 if(err)
648 printk("%s: %s resource 0x%lX-0x%lX not free.\n",
649 hwif->name, hwif->mmio?"MMIO":"I/O", addr, addr+num-1);
651 return err;
656 * hwif_check_regions - check resources for IDE
657 * @hwif: interface to use
659 * Checks if all the needed resources for an interface are free
660 * providing the interface is PIO. Right now core IDE code does
661 * this work which is deeply wrong. MMIO leaves it to the controller
662 * driver, PIO will migrate this way over time
665 static int hwif_check_regions (ide_hwif_t *hwif)
667 u32 i = 0;
668 int addr_errs = 0;
670 if (hwif->mmio == 2)
671 return 0;
672 addr_errs = hwif_check_region(hwif, hwif->io_ports[IDE_DATA_OFFSET], 1);
673 for (i = IDE_ERROR_OFFSET; i <= IDE_STATUS_OFFSET; i++)
674 addr_errs += hwif_check_region(hwif, hwif->io_ports[i], 1);
675 if (hwif->io_ports[IDE_CONTROL_OFFSET])
676 addr_errs += hwif_check_region(hwif, hwif->io_ports[IDE_CONTROL_OFFSET], 1);
677 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
678 if (hwif->io_ports[IDE_IRQ_OFFSET])
679 addr_errs += hwif_check_region(hwif, hwif->io_ports[IDE_IRQ_OFFSET], 1);
680 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
681 /* If any errors are return, we drop the hwif interface. */
682 hwif->straight8 = 0;
683 return(addr_errs);
686 //EXPORT_SYMBOL(hwif_check_regions);
688 #define hwif_request_region(addr, num, name) \
689 ((hwif->mmio) ? request_mem_region((addr),(num),(name)) : request_region((addr),(num),(name)))
691 static void hwif_register (ide_hwif_t *hwif)
693 u32 i = 0;
695 /* register with global device tree */
696 strlcpy(hwif->gendev.bus_id,hwif->name,BUS_ID_SIZE);
697 snprintf(hwif->gendev.name,DEVICE_NAME_SIZE,"IDE Controller");
698 hwif->gendev.driver_data = hwif;
699 if (hwif->pci_dev)
700 hwif->gendev.parent = &hwif->pci_dev->dev;
701 else
702 hwif->gendev.parent = NULL; /* Would like to do = &device_legacy */
703 device_register(&hwif->gendev);
705 if (hwif->mmio == 2)
706 return;
707 if (hwif->io_ports[IDE_CONTROL_OFFSET])
708 hwif_request_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1, hwif->name);
709 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
710 if (hwif->io_ports[IDE_IRQ_OFFSET])
711 hwif_request_region(hwif->io_ports[IDE_IRQ_OFFSET], 1, hwif->name);
712 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
713 if (((unsigned long)hwif->io_ports[IDE_DATA_OFFSET] | 7) ==
714 ((unsigned long)hwif->io_ports[IDE_STATUS_OFFSET])) {
715 hwif_request_region(hwif->io_ports[IDE_DATA_OFFSET], 8, hwif->name);
716 hwif->straight8 = 1;
717 return;
720 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
721 hwif_request_region(hwif->io_ports[i], 1, hwif->name);
724 //EXPORT_SYMBOL(hwif_register);
726 #ifdef CONFIG_PPC
727 static int wait_hwif_ready(ide_hwif_t *hwif)
729 int rc;
731 printk(KERN_INFO "Probing IDE interface %s...\n", hwif->name);
733 /* Let HW settle down a bit from whatever init state we
734 * come from */
735 mdelay(2);
737 /* Wait for BSY bit to go away, spec timeout is 30 seconds,
738 * I know of at least one disk who takes 31 seconds, I use 35
739 * here to be safe
741 rc = ide_wait_not_busy(hwif, 35000);
742 if (rc)
743 return rc;
745 /* Now make sure both master & slave are ready */
746 SELECT_DRIVE(&hwif->drives[0]);
747 hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);
748 mdelay(2);
749 rc = ide_wait_not_busy(hwif, 10000);
750 if (rc)
751 return rc;
752 SELECT_DRIVE(&hwif->drives[1]);
753 hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);
754 mdelay(2);
755 rc = ide_wait_not_busy(hwif, 10000);
757 /* Exit function with master reselected (let's be sane) */
758 SELECT_DRIVE(&hwif->drives[0]);
760 return rc;
762 #endif
765 * This routine only knows how to look for drive units 0 and 1
766 * on an interface, so any setting of MAX_DRIVES > 2 won't work here.
768 void probe_hwif (ide_hwif_t *hwif)
770 unsigned int unit;
771 unsigned long flags;
772 unsigned int irqd;
774 if (hwif->noprobe)
775 return;
777 if ((hwif->chipset != ide_4drives || !hwif->mate || !hwif->mate->present) &&
778 #ifdef CONFIG_BLK_DEV_PDC4030
779 (hwif->chipset != ide_pdc4030 || hwif->channel == 0) &&
780 #endif /* CONFIG_BLK_DEV_PDC4030 */
781 (hwif_check_regions(hwif))) {
782 u16 msgout = 0;
783 for (unit = 0; unit < MAX_DRIVES; ++unit) {
784 ide_drive_t *drive = &hwif->drives[unit];
785 if (drive->present) {
786 drive->present = 0;
787 printk(KERN_ERR "%s: ERROR, PORTS ALREADY IN USE\n",
788 drive->name);
789 msgout = 1;
792 if (!msgout)
793 printk(KERN_ERR "%s: ports already in use, skipping probe\n",
794 hwif->name);
795 return;
799 * We must always disable IRQ, as probe_for_drive will assert IRQ, but
800 * we'll install our IRQ driver much later...
802 irqd = hwif->irq;
803 if (irqd)
804 disable_irq(hwif->irq);
806 local_irq_set(flags);
808 #ifdef CONFIG_PPC
809 /* This is needed on some PPCs and a bunch of BIOS-less embedded
810 * platforms. Typical cases are:
812 * - The firmware hard reset the disk before booting the kernel,
813 * the drive is still doing it's poweron-reset sequence, that
814 * can take up to 30 seconds
815 * - The firmware does nothing (or no firmware), the device is
816 * still in POST state (same as above actually).
817 * - Some CD/DVD/Writer combo drives tend to drive the bus during
818 * their reset sequence even when they are non-selected slave
819 * devices, thus preventing discovery of the main HD
821 * Doing this wait-for-busy should not harm any existing configuration
822 * (at least things won't be worse than what current code does, that
823 * is blindly go & talk to the drive) and fix some issues like the
824 * above.
826 * BenH.
828 if (wait_hwif_ready(hwif))
829 printk(KERN_WARNING "%s: Wait for ready failed before probe !\n", hwif->name);
830 #endif /* CONFIG_PPC */
833 * Second drive should only exist if first drive was found,
834 * but a lot of cdrom drives are configured as single slaves.
836 for (unit = 0; unit < MAX_DRIVES; ++unit) {
837 ide_drive_t *drive = &hwif->drives[unit];
838 drive->dn = ((hwif->channel ? 2 : 0) + unit);
839 hwif->drives[unit].dn = ((hwif->channel ? 2 : 0) + unit);
840 (void) probe_for_drive(drive);
841 if (drive->present && !hwif->present) {
842 hwif->present = 1;
843 if (hwif->chipset != ide_4drives ||
844 !hwif->mate ||
845 !hwif->mate->present) {
846 hwif_register(hwif);
850 if (hwif->io_ports[IDE_CONTROL_OFFSET] && hwif->reset) {
851 unsigned long timeout = jiffies + WAIT_WORSTCASE;
852 u8 stat;
854 printk(KERN_WARNING "%s: reset\n", hwif->name);
855 hwif->OUTB(12, hwif->io_ports[IDE_CONTROL_OFFSET]);
856 udelay(10);
857 hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);
858 do {
859 ide_delay_50ms();
860 stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
861 } while ((stat & BUSY_STAT) && time_after(timeout, jiffies));
864 local_irq_restore(flags);
866 * Use cached IRQ number. It might be (and is...) changed by probe
867 * code above
869 if (irqd)
870 enable_irq(irqd);
872 for (unit = 0; unit < MAX_DRIVES; ++unit) {
873 ide_drive_t *drive = &hwif->drives[unit];
874 int enable_dma = 1;
876 if (drive->present) {
877 if (hwif->tuneproc != NULL &&
878 drive->autotune == IDE_TUNE_AUTO)
879 /* auto-tune PIO mode */
880 hwif->tuneproc(drive, 255);
882 #ifdef CONFIG_IDEDMA_ONLYDISK
883 if (drive->media != ide_disk)
884 enable_dma = 0;
885 #endif
887 * MAJOR HACK BARF :-/
889 * FIXME: chipsets own this cruft!
892 * Move here to prevent module loading clashing.
894 // drive->autodma = hwif->autodma;
895 if ((hwif->ide_dma_check) &&
896 ((drive->autotune == IDE_TUNE_DEFAULT) ||
897 (drive->autotune == IDE_TUNE_AUTO))) {
899 * Force DMAing for the beginning of the check.
900 * Some chipsets appear to do interesting
901 * things, if not checked and cleared.
902 * PARANOIA!!!
904 hwif->ide_dma_off_quietly(drive);
905 if (enable_dma)
906 hwif->ide_dma_check(drive);
912 EXPORT_SYMBOL(probe_hwif);
914 int hwif_init (ide_hwif_t *hwif);
915 int probe_hwif_init (ide_hwif_t *hwif)
917 hwif->initializing = 1;
918 probe_hwif(hwif);
919 hwif_init(hwif);
921 if (hwif->present) {
922 u16 unit = 0;
923 for (unit = 0; unit < MAX_DRIVES; ++unit) {
924 ide_drive_t *drive = &hwif->drives[unit];
925 /* For now don't attach absent drives, we may
926 want them on default or a new "empty" class
927 for hotplug reprobing ? */
928 if (drive->present) {
929 ata_attach(drive);
933 hwif->initializing = 0;
934 return 0;
937 EXPORT_SYMBOL(probe_hwif_init);
939 #if MAX_HWIFS > 1
941 * save_match() is used to simplify logic in init_irq() below.
943 * A loophole here is that we may not know about a particular
944 * hwif's irq until after that hwif is actually probed/initialized..
945 * This could be a problem for the case where an hwif is on a
946 * dual interface that requires serialization (eg. cmd640) and another
947 * hwif using one of the same irqs is initialized beforehand.
949 * This routine detects and reports such situations, but does not fix them.
951 void save_match (ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match)
953 ide_hwif_t *m = *match;
955 if (m && m->hwgroup && m->hwgroup != new->hwgroup) {
956 if (!new->hwgroup)
957 return;
958 printk("%s: potential irq problem with %s and %s\n",
959 hwif->name, new->name, m->name);
961 if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */
962 *match = new;
964 EXPORT_SYMBOL(save_match);
965 #endif /* MAX_HWIFS > 1 */
968 * init request queue
970 static void ide_init_queue(ide_drive_t *drive)
972 request_queue_t *q = &drive->queue;
973 ide_hwif_t *hwif = HWIF(drive);
974 int max_sectors = 256;
977 * Our default set up assumes the normal IDE case,
978 * that is 64K segmenting, standard PRD setup
979 * and LBA28. Some drivers then impose their own
980 * limits and LBA48 we could raise it but as yet
981 * do not.
984 blk_init_queue(q, do_ide_request, &ide_lock);
985 q->queuedata = HWGROUP(drive);
986 drive->queue_setup = 1;
987 blk_queue_segment_boundary(q, 0xffff);
989 if (!hwif->rqsize)
990 hwif->rqsize = hwif->addressing ? 256 : 65536;
991 if (hwif->rqsize < max_sectors)
992 max_sectors = hwif->rqsize;
993 blk_queue_max_sectors(q, max_sectors);
995 /* IDE DMA can do PRD_ENTRIES number of segments. */
996 blk_queue_max_hw_segments(q, PRD_ENTRIES);
998 /* This is a driver limit and could be eliminated. */
999 blk_queue_max_phys_segments(q, PRD_ENTRIES);
1003 * Setup the drive for request handling.
1005 static void ide_init_drive(ide_drive_t *drive)
1007 ide_toggle_bounce(drive, 1);
1009 #ifdef CONFIG_BLK_DEV_IDE_TCQ_DEFAULT
1010 HWIF(drive)->ide_dma_queued_on(drive);
1011 #endif
1015 * This routine sets up the irq for an ide interface, and creates a new
1016 * hwgroup for the irq/hwif if none was previously assigned.
1018 * Much of the code is for correctly detecting/handling irq sharing
1019 * and irq serialization situations. This is somewhat complex because
1020 * it handles static as well as dynamic (PCMCIA) IDE interfaces.
1022 * The SA_INTERRUPT in sa_flags means ide_intr() is always entered with
1023 * interrupts completely disabled. This can be bad for interrupt latency,
1024 * but anything else has led to problems on some machines. We re-enable
1025 * interrupts as much as we can safely do in most places.
1027 static int init_irq (ide_hwif_t *hwif)
1029 unsigned int index;
1030 ide_hwgroup_t *hwgroup;
1031 ide_hwif_t *match = NULL;
1034 BUG_ON(in_interrupt());
1035 BUG_ON(irqs_disabled());
1036 down(&ide_cfg_sem);
1037 hwif->hwgroup = NULL;
1038 #if MAX_HWIFS > 1
1040 * Group up with any other hwifs that share our irq(s).
1042 for (index = 0; index < MAX_HWIFS; index++) {
1043 ide_hwif_t *h = &ide_hwifs[index];
1044 if (h->hwgroup) { /* scan only initialized hwif's */
1045 if (hwif->irq == h->irq) {
1046 hwif->sharing_irq = h->sharing_irq = 1;
1047 if (hwif->chipset != ide_pci ||
1048 h->chipset != ide_pci) {
1049 save_match(hwif, h, &match);
1052 if (hwif->serialized) {
1053 if (hwif->mate && hwif->mate->irq == h->irq)
1054 save_match(hwif, h, &match);
1056 if (h->serialized) {
1057 if (h->mate && hwif->irq == h->mate->irq)
1058 save_match(hwif, h, &match);
1062 #endif /* MAX_HWIFS > 1 */
1064 * If we are still without a hwgroup, then form a new one
1066 if (match) {
1067 hwgroup = match->hwgroup;
1068 hwif->hwgroup = hwgroup;
1070 * Link us into the hwgroup.
1071 * This must be done early, do ensure that unexpected_intr
1072 * can find the hwif and prevent irq storms.
1073 * No drives are attached to the new hwif, choose_drive
1074 * can't do anything stupid (yet).
1075 * Add ourself as the 2nd entry to the hwgroup->hwif
1076 * linked list, the first entry is the hwif that owns
1077 * hwgroup->handler - do not change that.
1079 spin_lock_irq(&ide_lock);
1080 hwif->next = hwgroup->hwif->next;
1081 hwgroup->hwif->next = hwif;
1082 spin_unlock_irq(&ide_lock);
1083 } else {
1084 hwgroup = kmalloc(sizeof(ide_hwgroup_t),GFP_KERNEL);
1085 if (!hwgroup)
1086 goto out_up;
1088 hwif->hwgroup = hwgroup;
1090 memset(hwgroup, 0, sizeof(ide_hwgroup_t));
1091 hwgroup->hwif = hwif->next = hwif;
1092 hwgroup->rq = NULL;
1093 hwgroup->handler = NULL;
1094 hwgroup->drive = NULL;
1095 hwgroup->busy = 0;
1096 init_timer(&hwgroup->timer);
1097 hwgroup->timer.function = &ide_timer_expiry;
1098 hwgroup->timer.data = (unsigned long) hwgroup;
1102 * Allocate the irq, if not already obtained for another hwif
1104 if (!match || match->irq != hwif->irq) {
1105 int sa = SA_INTERRUPT;
1106 #if defined(__mc68000__) || defined(CONFIG_APUS)
1107 sa = SA_SHIRQ;
1108 #endif /* __mc68000__ || CONFIG_APUS */
1110 if (IDE_CHIPSET_IS_PCI(hwif->chipset)) {
1111 sa = SA_SHIRQ;
1112 #ifndef CONFIG_IDEPCI_SHARE_IRQ
1113 sa |= SA_INTERRUPT;
1114 #endif /* CONFIG_IDEPCI_SHARE_IRQ */
1117 if (hwif->io_ports[IDE_CONTROL_OFFSET])
1118 /* clear nIEN */
1119 hwif->OUTB(0x08, hwif->io_ports[IDE_CONTROL_OFFSET]);
1121 if (request_irq(hwif->irq,&ide_intr,sa,hwif->name,hwgroup))
1122 goto out_unlink;
1126 * Link any new drives into the hwgroup, allocate
1127 * the block device queue and initialize the drive.
1128 * Note that ide_init_drive sends commands to the new
1129 * drive.
1131 for (index = 0; index < MAX_DRIVES; ++index) {
1132 ide_drive_t *drive = &hwif->drives[index];
1133 if (!drive->present)
1134 continue;
1135 ide_init_queue(drive);
1136 spin_lock_irq(&ide_lock);
1137 if (!hwgroup->drive) {
1138 /* first drive for hwgroup. */
1139 drive->next = drive;
1140 hwgroup->drive = drive;
1141 hwgroup->hwif = HWIF(hwgroup->drive);
1142 } else {
1143 drive->next = hwgroup->drive->next;
1144 hwgroup->drive->next = drive;
1146 spin_unlock_irq(&ide_lock);
1147 ide_init_drive(drive);
1150 #if !defined(__mc68000__) && !defined(CONFIG_APUS) && !defined(__sparc__)
1151 printk("%s at 0x%03lx-0x%03lx,0x%03lx on irq %d", hwif->name,
1152 hwif->io_ports[IDE_DATA_OFFSET],
1153 hwif->io_ports[IDE_DATA_OFFSET]+7,
1154 hwif->io_ports[IDE_CONTROL_OFFSET], hwif->irq);
1155 #elif defined(__sparc__)
1156 printk("%s at 0x%03lx-0x%03lx,0x%03lx on irq %s", hwif->name,
1157 hwif->io_ports[IDE_DATA_OFFSET],
1158 hwif->io_ports[IDE_DATA_OFFSET]+7,
1159 hwif->io_ports[IDE_CONTROL_OFFSET], __irq_itoa(hwif->irq));
1160 #else
1161 printk("%s at 0x%08lx on irq %d", hwif->name,
1162 hwif->io_ports[IDE_DATA_OFFSET], hwif->irq);
1163 #endif /* __mc68000__ && CONFIG_APUS */
1164 if (match)
1165 printk(" (%sed with %s)",
1166 hwif->sharing_irq ? "shar" : "serializ", match->name);
1167 printk("\n");
1168 up(&ide_cfg_sem);
1169 return 0;
1170 out_unlink:
1171 spin_lock_irq(&ide_lock);
1172 if (hwif->next == hwif) {
1173 BUG_ON(match);
1174 BUG_ON(hwgroup->hwif != hwif);
1175 kfree(hwgroup);
1176 } else {
1177 ide_hwif_t *g;
1178 g = hwgroup->hwif;
1179 while (g->next != hwif)
1180 g = g->next;
1181 g->next = hwif->next;
1182 if (hwgroup->hwif == hwif) {
1183 /* Impossible. */
1184 printk(KERN_ERR "Duh. Uninitialized hwif listed as active hwif.\n");
1185 hwgroup->hwif = g;
1187 BUG_ON(hwgroup->hwif == hwif);
1189 spin_unlock_irq(&ide_lock);
1190 out_up:
1191 up(&ide_cfg_sem);
1192 return 1;
1195 static int ata_lock(dev_t dev, void *data)
1197 /* FIXME: we want to pin hwif down */
1198 return 0;
1201 struct kobject *ata_probe(dev_t dev, int *part, void *data)
1203 ide_hwif_t *hwif = data;
1204 int unit = *part >> PARTN_BITS;
1205 ide_drive_t *drive = &hwif->drives[unit];
1206 if (!drive->present)
1207 return NULL;
1208 if (!drive->driver) {
1209 if (drive->media == ide_disk)
1210 (void) request_module("ide-disk");
1211 if (drive->scsi)
1212 (void) request_module("ide-scsi");
1213 if (drive->media == ide_cdrom || drive->media == ide_optical)
1214 (void) request_module("ide-cd");
1215 if (drive->media == ide_tape)
1216 (void) request_module("ide-tape");
1217 if (drive->media == ide_floppy)
1218 (void) request_module("ide-floppy");
1220 if (!drive->driver)
1221 return NULL;
1222 *part &= (1 << PARTN_BITS) - 1;
1223 return get_disk(drive->disk);
1226 static int alloc_disks(ide_hwif_t *hwif)
1228 unsigned int unit;
1229 struct gendisk *disks[MAX_DRIVES];
1231 for (unit = 0; unit < MAX_DRIVES; unit++) {
1232 disks[unit] = alloc_disk(1 << PARTN_BITS);
1233 if (!disks[unit])
1234 goto Enomem;
1236 for (unit = 0; unit < MAX_DRIVES; ++unit) {
1237 ide_drive_t *drive = &hwif->drives[unit];
1238 struct gendisk *disk = disks[unit];
1239 disk->major = hwif->major;
1240 disk->first_minor = unit << PARTN_BITS;
1241 sprintf(disk->disk_name,"hd%c",'a'+hwif->index*MAX_DRIVES+unit);
1242 disk->fops = ide_fops;
1243 disk->private_data = drive;
1244 disk->queue = &drive->queue;
1245 drive->disk = disk;
1247 return 0;
1248 Enomem:
1249 printk(KERN_WARNING "(ide::init_gendisk) Out of memory\n");
1250 while (unit--)
1251 put_disk(disks[unit]);
1252 return -ENOMEM;
1256 * init_gendisk() (as opposed to ide_geninit) is called for each major device,
1257 * after probing for drives, to allocate partition tables and other data
1258 * structures needed for the routines in genhd.c. ide_geninit() gets called
1259 * somewhat later, during the partition check.
1261 static void init_gendisk (ide_hwif_t *hwif)
1263 unsigned int unit;
1265 for (unit = 0; unit < MAX_DRIVES; ++unit) {
1266 ide_drive_t * drive = &hwif->drives[unit];
1267 ide_add_generic_settings(drive);
1268 snprintf(drive->gendev.bus_id,BUS_ID_SIZE,"%u.%u",
1269 hwif->index,unit);
1270 snprintf(drive->gendev.name,DEVICE_NAME_SIZE,
1271 "%s","IDE Drive");
1272 drive->gendev.parent = &hwif->gendev;
1273 drive->gendev.bus = &ide_bus_type;
1274 drive->gendev.driver_data = drive;
1275 if (drive->present) {
1276 device_register(&drive->gendev);
1277 sprintf(drive->devfs_name, "ide/host%d/bus%d/target%d/lun%d",
1278 (hwif->channel && hwif->mate) ?
1279 hwif->mate->index : hwif->index,
1280 hwif->channel, unit, drive->lun);
1283 blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS,
1284 THIS_MODULE, ata_probe, ata_lock, hwif);
1287 EXPORT_SYMBOL(init_gendisk);
1289 int hwif_init (ide_hwif_t *hwif)
1291 int old_irq, unit;
1293 if (!hwif->present)
1294 return 0;
1296 if (!hwif->irq) {
1297 if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET])))
1299 printk("%s: DISABLED, NO IRQ\n", hwif->name);
1300 return (hwif->present = 0);
1303 #ifdef CONFIG_BLK_DEV_HD
1304 if (hwif->irq == HD_IRQ && hwif->io_ports[IDE_DATA_OFFSET] != HD_DATA) {
1305 printk("%s: CANNOT SHARE IRQ WITH OLD "
1306 "HARDDISK DRIVER (hd.c)\n", hwif->name);
1307 return (hwif->present = 0);
1309 #endif /* CONFIG_BLK_DEV_HD */
1311 /* we set it back to 1 if all is ok below */
1312 hwif->present = 0;
1314 if (register_blkdev(hwif->major, hwif->name))
1315 return 0;
1317 if (alloc_disks(hwif) < 0)
1318 goto out;
1320 if (init_irq(hwif) == 0)
1321 goto done;
1323 old_irq = hwif->irq;
1325 * It failed to initialise. Find the default IRQ for
1326 * this port and try that.
1328 if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET]))) {
1329 printk("%s: Disabled unable to get IRQ %d.\n",
1330 hwif->name, old_irq);
1331 goto out_disks;
1333 if (init_irq(hwif)) {
1334 printk("%s: probed IRQ %d and default IRQ %d failed.\n",
1335 hwif->name, old_irq, hwif->irq);
1336 goto out_disks;
1338 printk("%s: probed IRQ %d failed, using default.\n",
1339 hwif->name, hwif->irq);
1341 done:
1342 init_gendisk(hwif);
1343 hwif->present = 1; /* success */
1344 return 1;
1346 out_disks:
1347 for (unit = 0; unit < MAX_DRIVES; unit++) {
1348 struct gendisk *disk = hwif->drives[unit].disk;
1349 hwif->drives[unit].disk = NULL;
1350 put_disk(disk);
1352 out:
1353 unregister_blkdev(hwif->major, hwif->name);
1354 return 0;
1357 EXPORT_SYMBOL(hwif_init);
1359 void export_ide_init_queue (ide_drive_t *drive)
1361 ide_init_queue(drive);
1362 ide_init_drive(drive);
1365 EXPORT_SYMBOL(export_ide_init_queue);
1367 u8 export_probe_for_drive (ide_drive_t *drive)
1369 return probe_for_drive(drive);
1372 EXPORT_SYMBOL(export_probe_for_drive);
1374 int ideprobe_init (void);
1375 static ide_module_t ideprobe_module = {
1376 IDE_PROBE_MODULE,
1377 ideprobe_init,
1378 NULL
1381 int ideprobe_init (void)
1383 unsigned int index;
1384 int probe[MAX_HWIFS];
1386 MOD_INC_USE_COUNT;
1387 memset(probe, 0, MAX_HWIFS * sizeof(int));
1388 for (index = 0; index < MAX_HWIFS; ++index)
1389 probe[index] = !ide_hwifs[index].present;
1392 * Probe for drives in the usual way.. CMOS/BIOS, then poke at ports
1394 for (index = 0; index < MAX_HWIFS; ++index)
1395 if (probe[index])
1396 probe_hwif(&ide_hwifs[index]);
1397 for (index = 0; index < MAX_HWIFS; ++index)
1398 if (probe[index])
1399 hwif_init(&ide_hwifs[index]);
1400 for (index = 0; index < MAX_HWIFS; ++index) {
1401 if (probe[index]) {
1402 ide_hwif_t *hwif = &ide_hwifs[index];
1403 int unit;
1404 if (!hwif->present)
1405 continue;
1406 for (unit = 0; unit < MAX_DRIVES; ++unit)
1407 if (hwif->drives[unit].present)
1408 ata_attach(&hwif->drives[unit]);
1411 if (!ide_probe)
1412 ide_probe = &ideprobe_module;
1413 MOD_DEC_USE_COUNT;
1414 return 0;
1417 #ifdef MODULE
1418 int init_module (void)
1420 unsigned int index;
1422 for (index = 0; index < MAX_HWIFS; ++index)
1423 ide_unregister(index);
1424 ideprobe_init();
1425 create_proc_ide_interfaces();
1426 return 0;
1429 void cleanup_module (void)
1431 ide_probe = NULL;
1433 MODULE_LICENSE("GPL");
1434 #endif /* MODULE */