patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / ide / ide-probe.c
1 /*
2  *  linux/drivers/ide/ide-probe.c       Version 1.11    Mar 05, 2003
3  *
4  *  Copyright (C) 1994-1998  Linus Torvalds & authors (see below)
5  */
6
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>
11  *
12  *  See linux/MAINTAINERS for address of current maintainer.
13  *
14  * This is the IDE probe module, as evolved from hd.c and ide.c.
15  *
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
22  *
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
32  */
33
34 #undef REALLY_SLOW_IO           /* most systems can safely undef this */
35
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/kmod.h>
52 #include <linux/pci.h>
53
54 #include <asm/byteorder.h>
55 #include <asm/irq.h>
56 #include <asm/uaccess.h>
57 #include <asm/io.h>
58
59 /**
60  *      generic_id              -       add a generic drive id
61  *      @drive: drive to make an ID block for
62  *      
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
66  */
67  
68 static void generic_id(ide_drive_t *drive)
69 {
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;
76 }
77                 
78 /**
79  *      drive_is_flashcard      -       check for compact flash
80  *      @drive: drive to check
81  *
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.
88  *
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
95  */
96  
97 static inline int drive_is_flashcard (ide_drive_t *drive)
98 {
99         struct hd_driveid *id = drive->id;
100
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)    /* old SanDisk */
106                  || !strncmp(id->model, "SanDisk SDCFB", 13)    /* SanDisk */
107                  || !strncmp(id->model, "HAGIWARA HPC", 12)     /* Hagiwara */
108                  || !strncmp(id->model, "LEXAR ATA_FLASH", 15)  /* Lexar */
109                  || !strncmp(id->model, "ATA_FLASH", 9))        /* Simple Tech */
110                 {
111                         return 1;       /* yes, it is a flash memory card */
112                 }
113         }
114         return 0;       /* no, it is not a flash memory card */
115 }
116
117 /**
118  *      do_identify     -       identify a drive
119  *      @drive: drive to identify 
120  *      @cmd: command used
121  *
122  *      Called when we have issued a drive identify command to
123  *      read and parse the results. This function is run with
124  *      interrupts disabled. 
125  */
126  
127 static inline void do_identify (ide_drive_t *drive, u8 cmd)
128 {
129         ide_hwif_t *hwif = HWIF(drive);
130         int bswap = 1;
131         struct hd_driveid *id;
132
133         id = drive->id;
134         /* read 512 bytes of id info */
135         hwif->ata_input_data(drive, id, SECTOR_WORDS);
136
137         drive->id_read = 1;
138         local_irq_enable();
139         ide_fix_driveid(id);
140
141 #if defined (CONFIG_SCSI_EATA_DMA) || defined (CONFIG_SCSI_EATA_PIO) || defined (CONFIG_SCSI_EATA)
142         /*
143          * EATA SCSI controllers do a hardware ATA emulation:
144          * Ignore them if there is a driver for them available.
145          */
146         if ((id->model[0] == 'P' && id->model[1] == 'M') ||
147             (id->model[0] == 'S' && id->model[1] == 'K')) {
148                 printk("%s: EATA SCSI HBA %.10s\n", drive->name, id->model);
149                 goto err_misc;
150         }
151 #endif /* CONFIG_SCSI_EATA_DMA || CONFIG_SCSI_EATA_PIO */
152
153         /*
154          *  WIN_IDENTIFY returns little-endian info,
155          *  WIN_PIDENTIFY *usually* returns little-endian info.
156          */
157         if (cmd == WIN_PIDENTIFY) {
158                 if ((id->model[0] == 'N' && id->model[1] == 'E') /* NEC */
159                  || (id->model[0] == 'F' && id->model[1] == 'X') /* Mitsumi */
160                  || (id->model[0] == 'P' && id->model[1] == 'i'))/* Pioneer */
161                         /* Vertos drives may still be weird */
162                         bswap ^= 1;     
163         }
164         ide_fixstring(id->model,     sizeof(id->model),     bswap);
165         ide_fixstring(id->fw_rev,    sizeof(id->fw_rev),    bswap);
166         ide_fixstring(id->serial_no, sizeof(id->serial_no), bswap);
167
168         if (strstr(id->model, "E X A B Y T E N E S T"))
169                 goto err_misc;
170
171         /* we depend on this a lot! */
172         id->model[sizeof(id->model)-1] = '\0';
173         printk("%s: %s, ", drive->name, id->model);
174         drive->present = 1;
175         drive->dead = 0;
176
177         /*
178          * Check for an ATAPI device
179          */
180         if (cmd == WIN_PIDENTIFY) {
181                 u8 type = (id->config >> 8) & 0x1f;
182                 printk("ATAPI ");
183 #ifdef CONFIG_BLK_DEV_PDC4030
184                 if (hwif->channel == 1 && hwif->chipset == ide_pdc4030) {
185                         printk(" -- not supported on 2nd Promise port\n");
186                         goto err_misc;
187                 }
188 #endif /* CONFIG_BLK_DEV_PDC4030 */
189                 switch (type) {
190                         case ide_floppy:
191                                 if (!strstr(id->model, "CD-ROM")) {
192                                         if (!strstr(id->model, "oppy") &&
193                                             !strstr(id->model, "poyp") &&
194                                             !strstr(id->model, "ZIP"))
195                                                 printk("cdrom or floppy?, assuming ");
196                                         if (drive->media != ide_cdrom) {
197                                                 printk ("FLOPPY");
198                                                 drive->removable = 1;
199                                                 break;
200                                         }
201                                 }
202                                 /* Early cdrom models used zero */
203                                 type = ide_cdrom;
204                         case ide_cdrom:
205                                 drive->removable = 1;
206 #ifdef CONFIG_PPC
207                                 /* kludge for Apple PowerBook internal zip */
208                                 if (!strstr(id->model, "CD-ROM") &&
209                                     strstr(id->model, "ZIP")) {
210                                         printk ("FLOPPY");
211                                         type = ide_floppy;
212                                         break;
213                                 }
214 #endif
215                                 printk ("CD/DVD-ROM");
216                                 break;
217                         case ide_tape:
218                                 printk ("TAPE");
219                                 break;
220                         case ide_optical:
221                                 printk ("OPTICAL");
222                                 drive->removable = 1;
223                                 break;
224                         default:
225                                 printk("UNKNOWN (type %d)", type);
226                                 break;
227                 }
228                 printk (" drive\n");
229                 drive->media = type;
230                 return;
231         }
232
233         /*
234          * Not an ATAPI device: looks like a "regular" hard disk
235          */
236         if (id->config & (1<<7))
237                 drive->removable = 1;
238
239         if (drive_is_flashcard(drive))
240                 drive->is_flash = 1;
241         drive->media = ide_disk;
242         printk("%s DISK drive\n", (drive->is_flash) ? "CFA" : "ATA" );
243         QUIRK_LIST(drive);
244         return;
245
246 err_misc:
247         kfree(id);
248         drive->present = 0;
249         return;
250 }
251
252 /**
253  *      actual_try_to_identify  -       send ata/atapi identify
254  *      @drive: drive to identify
255  *      @cmd: command to use
256  *
257  *      try_to_identify() sends an ATA(PI) IDENTIFY request to a drive
258  *      and waits for a response.  It also monitors irqs while this is
259  *      happening, in hope of automatically determining which one is
260  *      being used by the interface.
261  *
262  *      Returns:        0  device was identified
263  *                      1  device timed-out (no response to identify request)
264  *                      2  device aborted the command (refused to identify itself)
265  */
266
267 static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
268 {
269         ide_hwif_t *hwif = HWIF(drive);
270         int rc;
271         unsigned long hd_status;
272         unsigned long timeout;
273         u8 s = 0, a = 0;
274
275         /* take a deep breath */
276         msleep(50);
277
278         if (IDE_CONTROL_REG) {
279                 a = hwif->INB(IDE_ALTSTATUS_REG);
280                 s = hwif->INB(IDE_STATUS_REG);
281                 if ((a ^ s) & ~INDEX_STAT) {
282                         printk(KERN_INFO "%s: probing with STATUS(0x%02x) instead of "
283                                 "ALTSTATUS(0x%02x)\n", drive->name, s, a);
284                         /* ancient Seagate drives, broken interfaces */
285                         hd_status = IDE_STATUS_REG;
286                 } else {
287                         /* use non-intrusive polling */
288                         hd_status = IDE_ALTSTATUS_REG;
289                 }
290         } else
291                 hd_status = IDE_STATUS_REG;
292
293         /* set features register for atapi
294          * identify command to be sure of reply
295          */
296         if ((cmd == WIN_PIDENTIFY))
297                 /* disable dma & overlap */
298                 hwif->OUTB(0, IDE_FEATURE_REG);
299
300         if (hwif->identify != NULL) {
301                 if (hwif->identify(drive))
302                         return 1;
303         } else {
304                 /* ask drive for ID */
305                 hwif->OUTB(cmd, IDE_COMMAND_REG);
306         }
307         timeout = ((cmd == WIN_IDENTIFY) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
308         timeout += jiffies;
309         do {
310                 if (time_after(jiffies, timeout)) {
311                         /* drive timed-out */
312                         return 1;
313                 }
314                 /* give drive a breather */
315                 msleep(50);
316         } while ((hwif->INB(hd_status)) & BUSY_STAT);
317
318         /* wait for IRQ and DRQ_STAT */
319         msleep(50);
320         if (OK_STAT((hwif->INB(IDE_STATUS_REG)), DRQ_STAT, BAD_R_STAT)) {
321                 unsigned long flags;
322
323                 /* local CPU only; some systems need this */
324                 local_irq_save(flags);
325                 /* drive returned ID */
326                 do_identify(drive, cmd);
327                 /* drive responded with ID */
328                 rc = 0;
329                 /* clear drive IRQ */
330                 (void) hwif->INB(IDE_STATUS_REG);
331                 local_irq_restore(flags);
332         } else {
333                 /* drive refused ID */
334                 rc = 2;
335         }
336         return rc;
337 }
338
339 /**
340  *      try_to_identify -       try to identify a drive
341  *      @drive: drive to probe
342  *      @cmd: command to use
343  *
344  *      Issue the identify command and then do IRQ probing to
345  *      complete the identification when needed by finding the
346  *      IRQ the drive is attached to
347  */
348  
349 static int try_to_identify (ide_drive_t *drive, u8 cmd)
350 {
351         ide_hwif_t *hwif = HWIF(drive);
352         int retval;
353         int autoprobe = 0;
354         unsigned long cookie = 0;
355
356         /*
357          * Disable device irq unless we need to
358          * probe for it. Otherwise we'll get spurious
359          * interrupts during the identify-phase that
360          * the irq handler isn't expecting.
361          */
362         if (IDE_CONTROL_REG) {
363                 u8 ctl = drive->ctl | 2;
364                 if (!hwif->irq) {
365                         autoprobe = 1;
366                         cookie = probe_irq_on();
367                         /* enable device irq */
368                         ctl &= ~2;
369                 }
370                 hwif->OUTB(ctl, IDE_CONTROL_REG);
371         }
372
373         retval = actual_try_to_identify(drive, cmd);
374
375         if (autoprobe) {
376                 int irq;
377                 /* mask device irq */
378                 hwif->OUTB(drive->ctl|2, IDE_CONTROL_REG);
379                 /* clear drive IRQ */
380                 (void) hwif->INB(IDE_STATUS_REG);
381                 udelay(5);
382                 irq = probe_irq_off(cookie);
383                 if (!hwif->irq) {
384                         if (irq > 0) {
385                                 hwif->irq = irq;
386                         } else {
387                                 /* Mmmm.. multiple IRQs..
388                                  * don't know which was ours
389                                  */
390                                 printk("%s: IRQ probe failed (0x%lx)\n",
391                                         drive->name, cookie);
392 #ifdef CONFIG_BLK_DEV_CMD640
393 #ifdef CMD640_DUMP_REGS
394                                 if (hwif->chipset == ide_cmd640) {
395                                         printk("%s: Hmmm.. probably a driver "
396                                                 "problem.\n", drive->name);
397                                         CMD640_DUMP_REGS;
398                                 }
399 #endif /* CMD640_DUMP_REGS */
400 #endif /* CONFIG_BLK_DEV_CMD640 */
401                         }
402                 }
403         }
404         return retval;
405 }
406
407
408 /**
409  *      do_probe                -       probe an IDE device
410  *      @drive: drive to probe
411  *      @cmd: command to use
412  *
413  *      do_probe() has the difficult job of finding a drive if it exists,
414  *      without getting hung up if it doesn't exist, without trampling on
415  *      ethernet cards, and without leaving any IRQs dangling to haunt us later.
416  *
417  *      If a drive is "known" to exist (from CMOS or kernel parameters),
418  *      but does not respond right away, the probe will "hang in there"
419  *      for the maximum wait time (about 30 seconds), otherwise it will
420  *      exit much more quickly.
421  *
422  * Returns:     0  device was identified
423  *              1  device timed-out (no response to identify request)
424  *              2  device aborted the command (refused to identify itself)
425  *              3  bad status from device (possible for ATAPI drives)
426  *              4  probe was not attempted because failure was obvious
427  */
428
429 static int do_probe (ide_drive_t *drive, u8 cmd)
430 {
431         int rc;
432         ide_hwif_t *hwif = HWIF(drive);
433
434         if (drive->present) {
435                 /* avoid waiting for inappropriate probes */
436                 if ((drive->media != ide_disk) && (cmd == WIN_IDENTIFY))
437                         return 4;
438         }
439 #ifdef DEBUG
440         printk("probing for %s: present=%d, media=%d, probetype=%s\n",
441                 drive->name, drive->present, drive->media,
442                 (cmd == WIN_IDENTIFY) ? "ATA" : "ATAPI");
443 #endif
444
445         /* needed for some systems
446          * (e.g. crw9624 as drive0 with disk as slave)
447          */
448         msleep(50);
449         SELECT_DRIVE(drive);
450         msleep(50);
451         if (hwif->INB(IDE_SELECT_REG) != drive->select.all && !drive->present) {
452                 if (drive->select.b.unit != 0) {
453                         /* exit with drive0 selected */
454                         SELECT_DRIVE(&hwif->drives[0]);
455                         /* allow BUSY_STAT to assert & clear */
456                         msleep(50);
457                 }
458                 /* no i/f present: mmm.. this should be a 4 -ml */
459                 return 3;
460         }
461
462         if (OK_STAT((hwif->INB(IDE_STATUS_REG)), READY_STAT, BUSY_STAT) ||
463             drive->present || cmd == WIN_PIDENTIFY) {
464                 /* send cmd and wait */
465                 if ((rc = try_to_identify(drive, cmd))) {
466                         /* failed: try again */
467                         rc = try_to_identify(drive,cmd);
468                 }
469                 if (hwif->INB(IDE_STATUS_REG) == (BUSY_STAT|READY_STAT))
470                         return 4;
471
472                 if ((rc == 1 && cmd == WIN_PIDENTIFY) &&
473                         ((drive->autotune == IDE_TUNE_DEFAULT) ||
474                         (drive->autotune == IDE_TUNE_AUTO))) {
475                         unsigned long timeout;
476                         printk("%s: no response (status = 0x%02x), "
477                                 "resetting drive\n", drive->name,
478                                 hwif->INB(IDE_STATUS_REG));
479                         msleep(50);
480                         hwif->OUTB(drive->select.all, IDE_SELECT_REG);
481                         msleep(50);
482                         hwif->OUTB(WIN_SRST, IDE_COMMAND_REG);
483                         timeout = jiffies;
484                         while (((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) &&
485                                time_before(jiffies, timeout + WAIT_WORSTCASE))
486                                 msleep(50);
487                         rc = try_to_identify(drive, cmd);
488                 }
489                 if (rc == 1)
490                         printk("%s: no response (status = 0x%02x)\n",
491                                 drive->name, hwif->INB(IDE_STATUS_REG));
492                 /* ensure drive irq is clear */
493                 (void) hwif->INB(IDE_STATUS_REG);
494         } else {
495                 /* not present or maybe ATAPI */
496                 rc = 3;
497         }
498         if (drive->select.b.unit != 0) {
499                 /* exit with drive0 selected */
500                 SELECT_DRIVE(&hwif->drives[0]);
501                 msleep(50);
502                 /* ensure drive irq is clear */
503                 (void) hwif->INB(IDE_STATUS_REG);
504         }
505         return rc;
506 }
507
508 /*
509  *
510  */
511 static void enable_nest (ide_drive_t *drive)
512 {
513         ide_hwif_t *hwif = HWIF(drive);
514         unsigned long timeout;
515
516         printk("%s: enabling %s -- ", hwif->name, drive->id->model);
517         SELECT_DRIVE(drive);
518         msleep(50);
519         hwif->OUTB(EXABYTE_ENABLE_NEST, IDE_COMMAND_REG);
520         timeout = jiffies + WAIT_WORSTCASE;
521         do {
522                 if (time_after(jiffies, timeout)) {
523                         printk("failed (timeout)\n");
524                         return;
525                 }
526                 msleep(50);
527         } while ((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT);
528
529         msleep(50);
530
531         if (!OK_STAT((hwif->INB(IDE_STATUS_REG)), 0, BAD_STAT)) {
532                 printk("failed (status = 0x%02x)\n", hwif->INB(IDE_STATUS_REG));
533         } else {
534                 printk("success\n");
535         }
536
537         /* if !(success||timed-out) */
538         if (do_probe(drive, WIN_IDENTIFY) >= 2) {
539                 /* look for ATAPI device */
540                 (void) do_probe(drive, WIN_PIDENTIFY);
541         }
542 }
543
544 /**
545  *      probe_for_drives        -       upper level drive probe
546  *      @drive: drive to probe for
547  *
548  *      probe_for_drive() tests for existence of a given drive using do_probe()
549  *      and presents things to the user as needed.
550  *
551  *      Returns:        0  no device was found
552  *                      1  device was found (note: drive->present might
553  *                         still be 0)
554  */
555  
556 static inline u8 probe_for_drive (ide_drive_t *drive)
557 {
558         /*
559          *      In order to keep things simple we have an id
560          *      block for all drives at all times. If the device
561          *      is pre ATA or refuses ATA/ATAPI identify we
562          *      will add faked data to this.
563          *
564          *      Also note that 0 everywhere means "can't do X"
565          */
566  
567         drive->id = kmalloc(SECTOR_WORDS *4, GFP_KERNEL);
568         drive->id_read = 0;
569         if(drive->id == NULL)
570         {
571                 printk(KERN_ERR "ide: out of memory for id data.\n");
572                 return 0;
573         }
574         memset(drive->id, 0, SECTOR_WORDS * 4);
575         strcpy(drive->id->model, "UNKNOWN");
576         
577         /* skip probing? */
578         if (!drive->noprobe)
579         {
580                 /* if !(success||timed-out) */
581                 if (do_probe(drive, WIN_IDENTIFY) >= 2) {
582                         /* look for ATAPI device */
583                         (void) do_probe(drive, WIN_PIDENTIFY);
584                 }
585                 if (strstr(drive->id->model, "E X A B Y T E N E S T"))
586                         enable_nest(drive);
587                 if (!drive->present)
588                         /* drive not found */
589                         return 0;
590         
591                 /* identification failed? */
592                 if (!drive->id_read) {
593                         if (drive->media == ide_disk) {
594                                 printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n",
595                                         drive->name, drive->cyl,
596                                         drive->head, drive->sect);
597                         } else if (drive->media == ide_cdrom) {
598                                 printk(KERN_INFO "%s: ATAPI cdrom (?)\n", drive->name);
599                         } else {
600                                 /* nuke it */
601                                 printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name);
602                                 drive->present = 0;
603                         }
604                 }
605                 /* drive was found */
606         }
607         if(!drive->present)
608                 return 0;
609         /* The drive wasn't being helpful. Add generic info only */
610         if(!drive->id_read)
611                 generic_id(drive);
612         return drive->present;
613 }
614
615 static void hwif_release_dev (struct device *dev)
616 {
617         ide_hwif_t *hwif = container_of(dev, ide_hwif_t, gendev);
618
619         up(&hwif->gendev_rel_sem);
620 }
621
622 static void hwif_register (ide_hwif_t *hwif)
623 {
624         /* register with global device tree */
625         strlcpy(hwif->gendev.bus_id,hwif->name,BUS_ID_SIZE);
626         hwif->gendev.driver_data = hwif;
627         if (hwif->gendev.parent == NULL) {
628                 if (hwif->pci_dev)
629                         hwif->gendev.parent = &hwif->pci_dev->dev;
630                 else
631                         /* Would like to do = &device_legacy */
632                         hwif->gendev.parent = NULL;
633         }
634         hwif->gendev.release = hwif_release_dev;
635         device_register(&hwif->gendev);
636 }
637
638 #ifdef CONFIG_PPC
639 static int wait_hwif_ready(ide_hwif_t *hwif)
640 {
641         int rc;
642
643         printk(KERN_INFO "Probing IDE interface %s...\n", hwif->name);
644
645         /* Let HW settle down a bit from whatever init state we
646          * come from */
647         mdelay(2);
648
649         /* Wait for BSY bit to go away, spec timeout is 30 seconds,
650          * I know of at least one disk who takes 31 seconds, I use 35
651          * here to be safe
652          */
653         rc = ide_wait_not_busy(hwif, 35000);
654         if (rc)
655                 return rc;
656
657         /* Now make sure both master & slave are ready */
658         SELECT_DRIVE(&hwif->drives[0]);
659         hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);
660         mdelay(2);
661         rc = ide_wait_not_busy(hwif, 10000);
662         if (rc)
663                 return rc;
664         SELECT_DRIVE(&hwif->drives[1]);
665         hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);
666         mdelay(2);
667         rc = ide_wait_not_busy(hwif, 10000);
668
669         /* Exit function with master reselected (let's be sane) */
670         SELECT_DRIVE(&hwif->drives[0]);
671         
672         return rc;
673 }
674 #endif
675
676 /*
677  * This routine only knows how to look for drive units 0 and 1
678  * on an interface, so any setting of MAX_DRIVES > 2 won't work here.
679  */
680 static void probe_hwif(ide_hwif_t *hwif)
681 {
682         unsigned int unit;
683         unsigned long flags;
684         unsigned int irqd;
685
686         if (hwif->noprobe)
687                 return;
688
689         if ((hwif->chipset != ide_4drives || !hwif->mate || !hwif->mate->present) &&
690 #ifdef CONFIG_BLK_DEV_PDC4030
691             (hwif->chipset != ide_pdc4030 || hwif->channel == 0) &&
692 #endif /* CONFIG_BLK_DEV_PDC4030 */
693             (ide_hwif_request_regions(hwif))) {
694                 u16 msgout = 0;
695                 for (unit = 0; unit < MAX_DRIVES; ++unit) {
696                         ide_drive_t *drive = &hwif->drives[unit];
697                         if (drive->present) {
698                                 drive->present = 0;
699                                 printk(KERN_ERR "%s: ERROR, PORTS ALREADY IN USE\n",
700                                         drive->name);
701                                 msgout = 1;
702                         }
703                 }
704                 if (!msgout)
705                         printk(KERN_ERR "%s: ports already in use, skipping probe\n",
706                                 hwif->name);
707                 return; 
708         }
709
710         /*
711          * We must always disable IRQ, as probe_for_drive will assert IRQ, but
712          * we'll install our IRQ driver much later...
713          */
714         irqd = hwif->irq;
715         if (irqd)
716                 disable_irq(hwif->irq);
717
718         local_irq_set(flags);
719
720 #ifdef CONFIG_PPC
721         /* This is needed on some PPCs and a bunch of BIOS-less embedded
722          * platforms. Typical cases are:
723          * 
724          *  - The firmware hard reset the disk before booting the kernel,
725          *    the drive is still doing it's poweron-reset sequence, that
726          *    can take up to 30 seconds
727          *  - The firmware does nothing (or no firmware), the device is
728          *    still in POST state (same as above actually).
729          *  - Some CD/DVD/Writer combo drives tend to drive the bus during
730          *    their reset sequence even when they are non-selected slave
731          *    devices, thus preventing discovery of the main HD
732          *    
733          *  Doing this wait-for-busy should not harm any existing configuration
734          *  (at least things won't be worse than what current code does, that
735          *  is blindly go & talk to the drive) and fix some issues like the
736          *  above.
737          *  
738          *  BenH.
739          */
740         if (wait_hwif_ready(hwif))
741                 printk(KERN_WARNING "%s: Wait for ready failed before probe !\n", hwif->name);
742 #endif /* CONFIG_PPC */
743
744         /*
745          * Second drive should only exist if first drive was found,
746          * but a lot of cdrom drives are configured as single slaves.
747          */
748         for (unit = 0; unit < MAX_DRIVES; ++unit) {
749                 ide_drive_t *drive = &hwif->drives[unit];
750                 drive->dn = (hwif->channel ? 2 : 0) + unit;
751                 (void) probe_for_drive(drive);
752                 if (drive->present && !hwif->present) {
753                         hwif->present = 1;
754                         if (hwif->chipset != ide_4drives ||
755                             !hwif->mate || 
756                             !hwif->mate->present) {
757                                 hwif_register(hwif);
758                         }
759                 }
760         }
761         if (hwif->io_ports[IDE_CONTROL_OFFSET] && hwif->reset) {
762                 unsigned long timeout = jiffies + WAIT_WORSTCASE;
763                 u8 stat;
764
765                 printk(KERN_WARNING "%s: reset\n", hwif->name);
766                 hwif->OUTB(12, hwif->io_ports[IDE_CONTROL_OFFSET]);
767                 udelay(10);
768                 hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);
769                 do {
770                         msleep(50);
771                         stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
772                 } while ((stat & BUSY_STAT) && time_after(timeout, jiffies));
773
774         }
775         local_irq_restore(flags);
776         /*
777          * Use cached IRQ number. It might be (and is...) changed by probe
778          * code above
779          */
780         if (irqd)
781                 enable_irq(irqd);
782
783         if (!hwif->present) {
784                 ide_hwif_release_regions(hwif);
785                 return;
786         }
787
788         for (unit = 0; unit < MAX_DRIVES; ++unit) {
789                 ide_drive_t *drive = &hwif->drives[unit];
790
791                 if (drive->present) {
792                         if (hwif->tuneproc != NULL && 
793                                 drive->autotune == IDE_TUNE_AUTO)
794                                 /* auto-tune PIO mode */
795                                 hwif->tuneproc(drive, 255);
796                         /*
797                          * MAJOR HACK BARF :-/
798                          *
799                          * FIXME: chipsets own this cruft!
800                          */
801                         /*
802                          * Move here to prevent module loading clashing.
803                          */
804         //              drive->autodma = hwif->autodma;
805                         if ((hwif->ide_dma_check) &&
806                                 ((drive->autotune == IDE_TUNE_DEFAULT) ||
807                                 (drive->autotune == IDE_TUNE_AUTO))) {
808                                 /*
809                                  * Force DMAing for the beginning of the check.
810                                  * Some chipsets appear to do interesting
811                                  * things, if not checked and cleared.
812                                  *   PARANOIA!!!
813                                  */
814                                 hwif->ide_dma_off_quietly(drive);
815 #ifdef CONFIG_IDEDMA_ONLYDISK
816                                 if (drive->media == ide_disk)
817 #endif
818                                         hwif->ide_dma_check(drive);
819                         }
820                 }
821         }
822 }
823
824 static int hwif_init(ide_hwif_t *hwif);
825 int probe_hwif_init (ide_hwif_t *hwif)
826 {
827         probe_hwif(hwif);
828         hwif_init(hwif);
829
830         if (hwif->present) {
831                 u16 unit = 0;
832                 for (unit = 0; unit < MAX_DRIVES; ++unit) {
833                         ide_drive_t *drive = &hwif->drives[unit];
834                         /* For now don't attach absent drives, we may
835                            want them on default or a new "empty" class
836                            for hotplug reprobing ? */
837                         if (drive->present) {
838                                 ata_attach(drive);
839                         }
840                 }
841         }
842         return 0;
843 }
844
845 EXPORT_SYMBOL(probe_hwif_init);
846
847 #if MAX_HWIFS > 1
848 /*
849  * save_match() is used to simplify logic in init_irq() below.
850  *
851  * A loophole here is that we may not know about a particular
852  * hwif's irq until after that hwif is actually probed/initialized..
853  * This could be a problem for the case where an hwif is on a
854  * dual interface that requires serialization (eg. cmd640) and another
855  * hwif using one of the same irqs is initialized beforehand.
856  *
857  * This routine detects and reports such situations, but does not fix them.
858  */
859 static void save_match(ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match)
860 {
861         ide_hwif_t *m = *match;
862
863         if (m && m->hwgroup && m->hwgroup != new->hwgroup) {
864                 if (!new->hwgroup)
865                         return;
866                 printk("%s: potential irq problem with %s and %s\n",
867                         hwif->name, new->name, m->name);
868         }
869         if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */
870                 *match = new;
871 }
872 #endif /* MAX_HWIFS > 1 */
873
874 /*
875  * init request queue
876  */
877 static int ide_init_queue(ide_drive_t *drive)
878 {
879         request_queue_t *q;
880         ide_hwif_t *hwif = HWIF(drive);
881         int max_sectors = 256;
882         int max_sg_entries = PRD_ENTRIES;
883
884         /*
885          *      Our default set up assumes the normal IDE case,
886          *      that is 64K segmenting, standard PRD setup
887          *      and LBA28. Some drivers then impose their own
888          *      limits and LBA48 we could raise it but as yet
889          *      do not.
890          */
891          
892         q = blk_init_queue(do_ide_request, &ide_lock);
893         if (!q)
894                 return 1;
895
896         q->queuedata = HWGROUP(drive);
897         blk_queue_segment_boundary(q, 0xffff);
898
899         if (!hwif->rqsize)
900                 hwif->rqsize = hwif->no_lba48 ? 256 : 65536;
901         if (hwif->rqsize < max_sectors)
902                 max_sectors = hwif->rqsize;
903         blk_queue_max_sectors(q, max_sectors);
904
905 #ifdef CONFIG_PCI
906         /* When we have an IOMMU, we may have a problem where pci_map_sg()
907          * creates segments that don't completely match our boundary
908          * requirements and thus need to be broken up again. Because it
909          * doesn't align properly neither, we may actually have to break up
910          * to more segments than what was we got in the first place, a max
911          * worst case is twice as many.
912          * This will be fixed once we teach pci_map_sg() about our boundary
913          * requirements, hopefully soon
914          */
915         if (!PCI_DMA_BUS_IS_PHYS)
916                 max_sg_entries >>= 1;
917 #endif /* CONFIG_PCI */
918
919         blk_queue_max_hw_segments(q, max_sg_entries);
920         blk_queue_max_phys_segments(q, max_sg_entries);
921
922         /* assign drive and gendisk queue */
923         drive->queue = q;
924         if (drive->disk)
925                 drive->disk->queue = drive->queue;
926
927         /* needs drive->queue to be set */
928         ide_toggle_bounce(drive, 1);
929
930         /* enable led activity for disk drives only */
931         if (drive->media == ide_disk && hwif->led_act)
932                 blk_queue_activity_fn(q, hwif->led_act, drive);
933
934         return 0;
935 }
936
937 /*
938  * This routine sets up the irq for an ide interface, and creates a new
939  * hwgroup for the irq/hwif if none was previously assigned.
940  *
941  * Much of the code is for correctly detecting/handling irq sharing
942  * and irq serialization situations.  This is somewhat complex because
943  * it handles static as well as dynamic (PCMCIA) IDE interfaces.
944  *
945  * The SA_INTERRUPT in sa_flags means ide_intr() is always entered with
946  * interrupts completely disabled.  This can be bad for interrupt latency,
947  * but anything else has led to problems on some machines.  We re-enable
948  * interrupts as much as we can safely do in most places.
949  */
950 static int init_irq (ide_hwif_t *hwif)
951 {
952         unsigned int index;
953         ide_hwgroup_t *hwgroup;
954         ide_hwif_t *match = NULL;
955
956
957         BUG_ON(in_interrupt());
958         BUG_ON(irqs_disabled());        
959         down(&ide_cfg_sem);
960         hwif->hwgroup = NULL;
961 #if MAX_HWIFS > 1
962         /*
963          * Group up with any other hwifs that share our irq(s).
964          */
965         for (index = 0; index < MAX_HWIFS; index++) {
966                 ide_hwif_t *h = &ide_hwifs[index];
967                 if (h->hwgroup) {  /* scan only initialized hwif's */
968                         if (hwif->irq == h->irq) {
969                                 hwif->sharing_irq = h->sharing_irq = 1;
970                                 if (hwif->chipset != ide_pci ||
971                                     h->chipset != ide_pci) {
972                                         save_match(hwif, h, &match);
973                                 }
974                         }
975                         if (hwif->serialized) {
976                                 if (hwif->mate && hwif->mate->irq == h->irq)
977                                         save_match(hwif, h, &match);
978                         }
979                         if (h->serialized) {
980                                 if (h->mate && hwif->irq == h->mate->irq)
981                                         save_match(hwif, h, &match);
982                         }
983                 }
984         }
985 #endif /* MAX_HWIFS > 1 */
986         /*
987          * If we are still without a hwgroup, then form a new one
988          */
989         if (match) {
990                 hwgroup = match->hwgroup;
991                 hwif->hwgroup = hwgroup;
992                 /*
993                  * Link us into the hwgroup.
994                  * This must be done early, do ensure that unexpected_intr
995                  * can find the hwif and prevent irq storms.
996                  * No drives are attached to the new hwif, choose_drive
997                  * can't do anything stupid (yet).
998                  * Add ourself as the 2nd entry to the hwgroup->hwif
999                  * linked list, the first entry is the hwif that owns
1000                  * hwgroup->handler - do not change that.
1001                  */
1002                 spin_lock_irq(&ide_lock);
1003                 hwif->next = hwgroup->hwif->next;
1004                 hwgroup->hwif->next = hwif;
1005                 spin_unlock_irq(&ide_lock);
1006         } else {
1007                 hwgroup = kmalloc(sizeof(ide_hwgroup_t),GFP_KERNEL);
1008                 if (!hwgroup)
1009                         goto out_up;
1010
1011                 hwif->hwgroup = hwgroup;
1012
1013                 memset(hwgroup, 0, sizeof(ide_hwgroup_t));
1014                 hwgroup->hwif     = hwif->next = hwif;
1015                 hwgroup->rq       = NULL;
1016                 hwgroup->handler  = NULL;
1017                 hwgroup->drive    = NULL;
1018                 hwgroup->busy     = 0;
1019                 init_timer(&hwgroup->timer);
1020                 hwgroup->timer.function = &ide_timer_expiry;
1021                 hwgroup->timer.data = (unsigned long) hwgroup;
1022         }
1023
1024         /*
1025          * Allocate the irq, if not already obtained for another hwif
1026          */
1027         if (!match || match->irq != hwif->irq) {
1028                 int sa = SA_INTERRUPT;
1029 #if defined(__mc68000__) || defined(CONFIG_APUS)
1030                 sa = SA_SHIRQ;
1031 #endif /* __mc68000__ || CONFIG_APUS */
1032
1033                 if (IDE_CHIPSET_IS_PCI(hwif->chipset)) {
1034                         sa = SA_SHIRQ;
1035 #ifndef CONFIG_IDEPCI_SHARE_IRQ
1036                         sa |= SA_INTERRUPT;
1037 #endif /* CONFIG_IDEPCI_SHARE_IRQ */
1038                 }
1039
1040                 if (hwif->io_ports[IDE_CONTROL_OFFSET])
1041                         /* clear nIEN */
1042                         hwif->OUTB(0x08, hwif->io_ports[IDE_CONTROL_OFFSET]);
1043
1044                 if (request_irq(hwif->irq,&ide_intr,sa,hwif->name,hwgroup))
1045                         goto out_unlink;
1046         }
1047
1048         /*
1049          * For any present drive:
1050          * - allocate the block device queue
1051          * - link drive into the hwgroup
1052          */
1053         for (index = 0; index < MAX_DRIVES; ++index) {
1054                 ide_drive_t *drive = &hwif->drives[index];
1055                 if (!drive->present)
1056                         continue;
1057                 if (ide_init_queue(drive)) {
1058                         printk(KERN_ERR "ide: failed to init %s\n",drive->name);
1059                         continue;
1060                 }
1061                 spin_lock_irq(&ide_lock);
1062                 if (!hwgroup->drive) {
1063                         /* first drive for hwgroup. */
1064                         drive->next = drive;
1065                         hwgroup->drive = drive;
1066                         hwgroup->hwif = HWIF(hwgroup->drive);
1067                 } else {
1068                         drive->next = hwgroup->drive->next;
1069                         hwgroup->drive->next = drive;
1070                 }
1071                 spin_unlock_irq(&ide_lock);
1072         }
1073
1074 #if !defined(__mc68000__) && !defined(CONFIG_APUS) && !defined(__sparc__)
1075         printk("%s at 0x%03lx-0x%03lx,0x%03lx on irq %d", hwif->name,
1076                 hwif->io_ports[IDE_DATA_OFFSET],
1077                 hwif->io_ports[IDE_DATA_OFFSET]+7,
1078                 hwif->io_ports[IDE_CONTROL_OFFSET], hwif->irq);
1079 #elif defined(__sparc__)
1080         printk("%s at 0x%03lx-0x%03lx,0x%03lx on irq %s", hwif->name,
1081                 hwif->io_ports[IDE_DATA_OFFSET],
1082                 hwif->io_ports[IDE_DATA_OFFSET]+7,
1083                 hwif->io_ports[IDE_CONTROL_OFFSET], __irq_itoa(hwif->irq));
1084 #else
1085         printk("%s at 0x%08lx on irq %d", hwif->name,
1086                 hwif->io_ports[IDE_DATA_OFFSET], hwif->irq);
1087 #endif /* __mc68000__ && CONFIG_APUS */
1088         if (match)
1089                 printk(" (%sed with %s)",
1090                         hwif->sharing_irq ? "shar" : "serializ", match->name);
1091         printk("\n");
1092         up(&ide_cfg_sem);
1093         return 0;
1094 out_unlink:
1095         spin_lock_irq(&ide_lock);
1096         if (hwif->next == hwif) {
1097                 BUG_ON(match);
1098                 BUG_ON(hwgroup->hwif != hwif);
1099                 kfree(hwgroup);
1100         } else {
1101                 ide_hwif_t *g;
1102                 g = hwgroup->hwif;
1103                 while (g->next != hwif)
1104                         g = g->next;
1105                 g->next = hwif->next;
1106                 if (hwgroup->hwif == hwif) {
1107                         /* Impossible. */
1108                         printk(KERN_ERR "Duh. Uninitialized hwif listed as active hwif.\n");
1109                         hwgroup->hwif = g;
1110                 }
1111                 BUG_ON(hwgroup->hwif == hwif);
1112         }
1113         spin_unlock_irq(&ide_lock);
1114 out_up:
1115         up(&ide_cfg_sem);
1116         return 1;
1117 }
1118
1119 static int ata_lock(dev_t dev, void *data)
1120 {
1121         /* FIXME: we want to pin hwif down */
1122         return 0;
1123 }
1124
1125 extern ide_driver_t idedefault_driver;
1126
1127 struct kobject *ata_probe(dev_t dev, int *part, void *data)
1128 {
1129         ide_hwif_t *hwif = data;
1130         int unit = *part >> PARTN_BITS;
1131         ide_drive_t *drive = &hwif->drives[unit];
1132         if (!drive->present)
1133                 return NULL;
1134         if (drive->driver == &idedefault_driver) {
1135                 if (drive->media == ide_disk)
1136                         (void) request_module("ide-disk");
1137                 if (drive->scsi)
1138                         (void) request_module("ide-scsi");
1139                 if (drive->media == ide_cdrom || drive->media == ide_optical)
1140                         (void) request_module("ide-cd");
1141                 if (drive->media == ide_tape)
1142                         (void) request_module("ide-tape");
1143                 if (drive->media == ide_floppy)
1144                         (void) request_module("ide-floppy");
1145         }
1146         if (drive->driver == &idedefault_driver)
1147                 return NULL;
1148         *part &= (1 << PARTN_BITS) - 1;
1149         return get_disk(drive->disk);
1150 }
1151
1152 static int alloc_disks(ide_hwif_t *hwif)
1153 {
1154         unsigned int unit;
1155         struct gendisk *disks[MAX_DRIVES];
1156
1157         for (unit = 0; unit < MAX_DRIVES; unit++) {
1158                 disks[unit] = alloc_disk(1 << PARTN_BITS);
1159                 if (!disks[unit])
1160                         goto Enomem;
1161         }
1162         for (unit = 0; unit < MAX_DRIVES; ++unit) {
1163                 ide_drive_t *drive = &hwif->drives[unit];
1164                 struct gendisk *disk = disks[unit];
1165                 disk->major  = hwif->major;
1166                 disk->first_minor = unit << PARTN_BITS;
1167                 sprintf(disk->disk_name,"hd%c",'a'+hwif->index*MAX_DRIVES+unit);
1168                 disk->fops = ide_fops;
1169                 disk->private_data = drive;
1170                 drive->disk = disk;
1171         }
1172         return 0;
1173 Enomem:
1174         printk(KERN_WARNING "(ide::init_gendisk) Out of memory\n");
1175         while (unit--)
1176                 put_disk(disks[unit]);
1177         return -ENOMEM;
1178 }
1179
1180 static void drive_release_dev (struct device *dev)
1181 {
1182         ide_drive_t *drive = container_of(dev, ide_drive_t, gendev);
1183
1184         up(&drive->gendev_rel_sem);
1185 }
1186
1187 /*
1188  * init_gendisk() (as opposed to ide_geninit) is called for each major device,
1189  * after probing for drives, to allocate partition tables and other data
1190  * structures needed for the routines in genhd.c.  ide_geninit() gets called
1191  * somewhat later, during the partition check.
1192  */
1193 static void init_gendisk (ide_hwif_t *hwif)
1194 {
1195         unsigned int unit;
1196
1197         for (unit = 0; unit < MAX_DRIVES; ++unit) {
1198                 ide_drive_t * drive = &hwif->drives[unit];
1199                 ide_add_generic_settings(drive);
1200                 snprintf(drive->gendev.bus_id,BUS_ID_SIZE,"%u.%u",
1201                          hwif->index,unit);
1202                 drive->gendev.parent = &hwif->gendev;
1203                 drive->gendev.bus = &ide_bus_type;
1204                 drive->gendev.driver_data = drive;
1205                 drive->gendev.release = drive_release_dev;
1206                 if (drive->present) {
1207                         device_register(&drive->gendev);
1208                         sprintf(drive->devfs_name, "ide/host%d/bus%d/target%d/lun%d",
1209                                 (hwif->channel && hwif->mate) ?
1210                                 hwif->mate->index : hwif->index,
1211                                 hwif->channel, unit, drive->lun);
1212                 }
1213         }
1214         blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS,
1215                         THIS_MODULE, ata_probe, ata_lock, hwif);
1216 }
1217
1218 static int hwif_init(ide_hwif_t *hwif)
1219 {
1220         int old_irq, unit;
1221
1222         if (!hwif->present)
1223                 return 0;
1224
1225         if (!hwif->irq) {
1226                 if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET])))
1227                 {
1228                         printk("%s: DISABLED, NO IRQ\n", hwif->name);
1229                         return (hwif->present = 0);
1230                 }
1231         }
1232 #ifdef CONFIG_BLK_DEV_HD
1233         if (hwif->irq == HD_IRQ && hwif->io_ports[IDE_DATA_OFFSET] != HD_DATA) {
1234                 printk("%s: CANNOT SHARE IRQ WITH OLD "
1235                         "HARDDISK DRIVER (hd.c)\n", hwif->name);
1236                 return (hwif->present = 0);
1237         }
1238 #endif /* CONFIG_BLK_DEV_HD */
1239
1240         /* we set it back to 1 if all is ok below */    
1241         hwif->present = 0;
1242
1243         if (register_blkdev(hwif->major, hwif->name))
1244                 return 0;
1245
1246         if (alloc_disks(hwif) < 0)
1247                 goto out;
1248         
1249         if (init_irq(hwif) == 0)
1250                 goto done;
1251
1252         old_irq = hwif->irq;
1253         /*
1254          *      It failed to initialise. Find the default IRQ for 
1255          *      this port and try that.
1256          */
1257         if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET]))) {
1258                 printk("%s: Disabled unable to get IRQ %d.\n",
1259                         hwif->name, old_irq);
1260                 goto out_disks;
1261         }
1262         if (init_irq(hwif)) {
1263                 printk("%s: probed IRQ %d and default IRQ %d failed.\n",
1264                         hwif->name, old_irq, hwif->irq);
1265                 goto out_disks;
1266         }
1267         printk("%s: probed IRQ %d failed, using default.\n",
1268                 hwif->name, hwif->irq);
1269
1270 done:
1271         init_gendisk(hwif);
1272         hwif->present = 1;      /* success */
1273         return 1;
1274
1275 out_disks:
1276         for (unit = 0; unit < MAX_DRIVES; unit++) {
1277                 struct gendisk *disk = hwif->drives[unit].disk;
1278                 hwif->drives[unit].disk = NULL;
1279                 put_disk(disk);
1280         }
1281 out:
1282         unregister_blkdev(hwif->major, hwif->name);
1283         return 0;
1284 }
1285
1286 int ideprobe_init (void)
1287 {
1288         unsigned int index;
1289         int probe[MAX_HWIFS];
1290
1291         memset(probe, 0, MAX_HWIFS * sizeof(int));
1292         for (index = 0; index < MAX_HWIFS; ++index)
1293                 probe[index] = !ide_hwifs[index].present;
1294
1295         /*
1296          * Probe for drives in the usual way.. CMOS/BIOS, then poke at ports
1297          */
1298         for (index = 0; index < MAX_HWIFS; ++index)
1299                 if (probe[index])
1300                         probe_hwif(&ide_hwifs[index]);
1301         for (index = 0; index < MAX_HWIFS; ++index)
1302                 if (probe[index])
1303                         hwif_init(&ide_hwifs[index]);
1304         for (index = 0; index < MAX_HWIFS; ++index) {
1305                 if (probe[index]) {
1306                         ide_hwif_t *hwif = &ide_hwifs[index];
1307                         int unit;
1308                         if (!hwif->present)
1309                                 continue;
1310                         if (hwif->chipset == ide_unknown || hwif->chipset == ide_forced)
1311                                 hwif->chipset = ide_generic;
1312                         for (unit = 0; unit < MAX_DRIVES; ++unit)
1313                                 if (hwif->drives[unit].present)
1314                                         ata_attach(&hwif->drives[unit]);
1315                 }
1316         }
1317         return 0;
1318 }
1319
1320 EXPORT_SYMBOL_GPL(ideprobe_init);