1 /**** vi:set ts=8 sts=8 sw=8:************************************************
3 * Copyright (C) 1994-1998,2002 Linus Torvalds and authors:
5 * Mark Lord <mlord@pobox.com>
6 * Gadi Oxman <gadio@netvision.net.il>
7 * Andre Hedrick <andre@linux-ide.org>
8 * Jens Axboe <axboe@suse.de>
9 * Marcin Dalecki <martin@dalecki.de>
11 * See linux/MAINTAINERS for address of current maintainer.
15 * Handle overall infrastructure of the driver
18 #define VERSION "7.0.0"
20 #include <linux/config.h>
21 #include <linux/module.h>
22 #include <linux/types.h>
23 #include <linux/string.h>
24 #include <linux/kernel.h>
25 #include <linux/timer.h>
27 #include <linux/interrupt.h>
28 #include <linux/major.h>
29 #include <linux/errno.h>
30 #include <linux/genhd.h>
31 #include <linux/blkpg.h>
32 #include <linux/slab.h>
34 # include <linux/init.h>
36 #include <linux/pci.h>
37 #include <linux/delay.h>
38 #include <linux/devfs_fs_kernel.h>
39 #include <linux/reboot.h>
40 #include <linux/cdrom.h>
41 #include <linux/device.h>
42 #include <linux/kmod.h>
43 #include <linux/hdreg.h>
44 #include <linux/ide.h>
46 #include <asm/byteorder.h>
48 #include <asm/uaccess.h>
50 #include <asm/bitops.h>
57 MODULE_DESCRIPTION("ATA/ATAPI driver infrastructure");
58 MODULE_PARM(options
,"s");
59 MODULE_LICENSE("GPL");
62 * Those will be moved into separate header files eventually.
64 #ifdef CONFIG_ETRAX_IDE
65 extern void init_e100_ide(void);
67 #ifdef CONFIG_BLK_DEV_CMD640
68 extern void ide_probe_for_cmd640x(void);
70 #ifdef CONFIG_BLK_DEV_PDC4030
71 extern int ide_probe_for_pdc4030(void);
73 #ifdef CONFIG_BLK_DEV_IDE_PMAC
74 extern void pmac_ide_probe(void);
76 #ifdef CONFIG_BLK_DEV_IDE_ICSIDE
77 extern void icside_init(void);
79 #ifdef CONFIG_BLK_DEV_IDE_RAPIDE
80 extern void rapide_init(void);
82 #ifdef CONFIG_BLK_DEV_GAYLE
83 extern void gayle_init(void);
85 #ifdef CONFIG_BLK_DEV_FALCON_IDE
86 extern void falconide_init(void);
88 #ifdef CONFIG_BLK_DEV_MAC_IDE
89 extern void macide_init(void);
91 #ifdef CONFIG_BLK_DEV_Q40IDE
92 extern void q40ide_init(void);
94 #ifdef CONFIG_BLK_DEV_BUDDHA
95 extern void buddha_init(void);
97 #if defined(CONFIG_BLK_DEV_ISAPNP) && defined(CONFIG_ISAPNP)
98 extern void pnpide_init(int);
101 /* default maximum number of failures */
102 #define IDE_DEFAULT_MAX_FAILURES 1
104 int system_bus_speed
; /* holds what we think is VESA/PCI bus speed */
106 static int initializing
; /* set while initializing built-in drivers */
107 static int idebus_parameter
; /* the "idebus=" parameter */
110 * Protects access to global structures etc.
112 spinlock_t ide_lock __cacheline_aligned
= SPIN_LOCK_UNLOCKED
;
115 static int ide_scan_direction
; /* THIS was formerly 2.2.x pci=reverse */
120 * This is used by the Atari code to obtain access to the IDE interrupt,
121 * which is shared between several drivers.
128 /* Single linked list of sub device type drivers */
129 static struct ata_operations
*ata_drivers
; /* = NULL */
130 static spinlock_t ata_drivers_lock
= SPIN_LOCK_UNLOCKED
;
133 * This is declared extern in ide.h, for access by other IDE modules:
135 struct ata_channel ide_hwifs
[MAX_HWIFS
]; /* master data repository */
138 * FIXME: This function should be unrolled in the palces where it get's used,
139 * since in reality it's simple architecture specific initialization.
141 * Setup hw_regs_t structure described by parameters. You may set up the hw
142 * structure yourself OR use this routine to do it for you.
144 void ide_setup_ports(hw_regs_t
*hw
, ide_ioreg_t base
, int *offsets
,
145 ide_ioreg_t ctrl
, ide_ioreg_t intr
,
146 int (*ack_intr
)(struct ata_channel
*),
151 for (i
= 0; i
< IDE_NR_PORTS
; i
++) {
152 if (offsets
[i
] != -1)
153 hw
->io_ports
[i
] = base
+ offsets
[i
];
157 if (offsets
[IDE_CONTROL_OFFSET
] == -1)
158 hw
->io_ports
[IDE_CONTROL_OFFSET
] = ctrl
;
160 /* FIMXE: check if we can remove this ifdef */
161 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
162 if (offsets
[IDE_IRQ_OFFSET
] == -1)
163 hw
->io_ports
[IDE_IRQ_OFFSET
] = intr
;
168 hw
->ack_intr
= ack_intr
;
171 static void init_hwif_data(struct ata_channel
*ch
, unsigned int index
)
173 static const unsigned int majors
[] = {
174 IDE0_MAJOR
, IDE1_MAJOR
, IDE2_MAJOR
, IDE3_MAJOR
, IDE4_MAJOR
,
175 IDE5_MAJOR
, IDE6_MAJOR
, IDE7_MAJOR
, IDE8_MAJOR
, IDE9_MAJOR
180 /* bulk initialize channel & drive info with zeros */
181 memset(ch
, 0, sizeof(struct ata_channel
));
183 /* fill in any non-zero initial values */
185 ide_init_hwif_ports(&ch
->hw
, ide_default_io_base(index
), 0, &ch
->irq
);
187 memcpy(ch
->io_ports
, ch
->hw
.io_ports
, sizeof(ch
->hw
.io_ports
));
189 /* Most controllers cannot do transfers across 64kB boundaries.
190 trm290 can do transfers within a 4GB boundary, so it changes
191 this mask accordingly. */
192 ch
->seg_boundary_mask
= 0xffff;
194 /* Some chipsets (cs5530, any others?) think a 64kB transfer
195 is 0 byte transfer, so set the limit one sector smaller.
196 In the future, we may default to 64kB transfers and let
197 invidual chipsets with this problem change ch->max_segment_size. */
198 ch
->max_segment_size
= (1<<16) - 512;
200 ch
->noprobe
= !ch
->io_ports
[IDE_DATA_OFFSET
];
201 #ifdef CONFIG_BLK_DEV_HD
203 /* Ignore disks for which handling by the legacy driver was requested
206 if (ch
->io_ports
[IDE_DATA_OFFSET
] == 0x1f0)
207 ch
->noprobe
= 1; /* may be overridden by ide_setup() */
210 ch
->major
= majors
[index
];
211 sprintf(ch
->name
, "ide%d", index
);
212 ch
->bus_state
= BUSSTATE_ON
;
214 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
215 struct ata_device
*drive
= &ch
->drives
[unit
];
217 drive
->type
= ATA_DISK
;
218 drive
->select
.all
= (unit
<< 4) | 0xa0;
220 drive
->ready_stat
= READY_STAT
;
221 drive
->bad_wstat
= BAD_W_STAT
;
222 sprintf(drive
->name
, "hd%c", 'a' + (index
* MAX_DRIVES
) + unit
);
223 drive
->max_failures
= IDE_DEFAULT_MAX_FAILURES
;
225 init_waitqueue_head(&drive
->wqueue
);
229 extern struct block_device_operations ide_fops
[];
232 * Returns the (struct ata_device *) for a given device number. Return
233 * NULL if the given device number does not match any present drives.
235 struct ata_device
*get_info_ptr(kdev_t i_rdev
)
237 unsigned int major
= major(i_rdev
);
240 for (h
= 0; h
< MAX_HWIFS
; ++h
) {
241 struct ata_channel
*ch
= &ide_hwifs
[h
];
242 if (ch
->present
&& major
== ch
->major
) {
243 int unit
= DEVICE_NR(i_rdev
);
244 if (unit
< MAX_DRIVES
) {
245 struct ata_device
*drive
= &ch
->drives
[unit
];
256 * This routine is called to flush all partitions and partition tables
257 * for a changed disk, and then re-read the new partition table.
258 * If we are revalidating a disk because of a media change, then we
259 * enter with usage == 0. If we are using an ioctl, we automatically have
260 * usage == 1 (we need an open channel to use an ioctl :-), so this
263 int ide_revalidate(kdev_t dev
)
265 struct ata_device
*drive
;
266 struct ata_channel
*channel
;
267 struct gendisk
*disk
;
270 if ((drive
= get_info_ptr(dev
)) == NULL
)
272 if (ata_ops(drive
) && ata_ops(drive
)->revalidate
) {
273 ata_get(ata_ops(drive
));
274 ata_ops(drive
)->revalidate(drive
);
275 ata_put(ata_ops(drive
));
277 channel
= drive
->channel
;
278 unit
= drive
- channel
->drives
;
279 disk
= channel
->gd
[unit
];
280 disk
->part
[0].nr_sects
= ata_capacity(drive
);
284 void ide_driver_module(void)
288 /* Don't reinit the probe if there is already one channel detected. */
289 for (i
= 0; i
< MAX_HWIFS
; ++i
) {
290 if (ide_hwifs
[i
].present
)
298 * Release the data associated with a channel.
300 void ide_unregister(struct ata_channel
*ch
)
303 struct ata_device
*d
;
308 unsigned int p
, minor
;
309 struct ata_channel old
;
313 spin_lock_irqsave(&ide_lock
, flags
);
318 put_device(&ch
->dev
);
319 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
320 struct ata_device
* drive
= &ch
->drives
[unit
];
325 if (drive
->busy
|| drive
->usage
)
328 if (ata_ops(drive
)) {
329 if (ata_ops(drive
)->cleanup
) {
330 if (ata_ops(drive
)->cleanup(drive
))
333 ata_unregister_device(drive
);
339 * All clear? Then blow away the buffer cache
341 spin_unlock_irqrestore(&ide_lock
, flags
);
343 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
344 struct ata_device
* drive
= &ch
->drives
[unit
];
349 minor
= drive
->select
.b
.unit
<< PARTN_BITS
;
350 for (p
= 0; p
< (1<<PARTN_BITS
); ++p
) {
351 if (drive
->part
[p
].nr_sects
> 0) {
352 kdev_t devp
= mk_kdev(ch
->major
, minor
+p
);
353 invalidate_device(devp
, 0);
358 spin_lock_irqsave(&ide_lock
, flags
);
361 * Note that we only release the standard ports, and do not even try to
362 * handle any extra ports allocated for weird IDE interface chipsets.
366 release_region(ch
->io_ports
[IDE_DATA_OFFSET
], 8);
368 for (i
= 0; i
< 8; i
++)
370 release_region(ch
->io_ports
[i
], 1);
372 if (ch
->io_ports
[IDE_CONTROL_OFFSET
])
373 release_region(ch
->io_ports
[IDE_CONTROL_OFFSET
], 1);
374 /* FIXME: check if we can remove this ifdef */
375 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
376 if (ch
->io_ports
[IDE_IRQ_OFFSET
])
377 release_region(ch
->io_ports
[IDE_IRQ_OFFSET
], 1);
381 * Remove us from the lock group.
386 for (i
= 0; i
< MAX_DRIVES
; ++i
) {
387 struct ata_device
*drive
= &ch
->drives
[i
];
390 devfs_unregister(drive
->de
);
396 /* FIXME: possibly unneccessary */
397 if (ch
->drive
== drive
)
400 if (drive
->id
!= NULL
) {
405 blk_cleanup_queue(&drive
->queue
);
412 * Free the irq if we were the only channel using it.
414 * Free the lock group if we were the only member.
417 for (i
= 0; i
< MAX_HWIFS
; ++i
) {
418 struct ata_channel
*tmp
= &ide_hwifs
[i
];
423 if (tmp
->irq
== ch
->irq
)
425 if (tmp
->lock
== ch
->lock
)
429 free_irq(ch
->irq
, ch
);
437 #ifdef CONFIG_BLK_DEV_IDEDMA
442 * Remove us from the kernel's knowledge.
444 unregister_blkdev(ch
->major
, ch
->name
);
445 blk_dev
[ch
->major
].data
= NULL
;
446 blk_dev
[ch
->major
].queue
= NULL
;
447 blk_clear(ch
->major
);
451 for (i
= 0; i
< MAX_DRIVES
; i
++)
453 kfree(gd
->major_name
);
460 for (i
= 0; i
< MAX_DRIVES
; i
++)
465 * Reinitialize the channel handler, but preserve any special methods for
470 init_hwif_data(ch
, ch
->index
);
472 ch
->tuneproc
= old
.tuneproc
;
473 ch
->speedproc
= old
.speedproc
;
474 ch
->selectproc
= old
.selectproc
;
475 ch
->resetproc
= old
.resetproc
;
476 ch
->intrproc
= old
.intrproc
;
477 ch
->maskproc
= old
.maskproc
;
478 ch
->quirkproc
= old
.quirkproc
;
479 ch
->ata_read
= old
.ata_read
;
480 ch
->ata_write
= old
.ata_write
;
481 ch
->atapi_read
= old
.atapi_read
;
482 ch
->atapi_write
= old
.atapi_write
;
483 ch
->udma_setup
= old
.udma_setup
;
484 ch
->udma_enable
= old
.udma_enable
;
485 ch
->udma_start
= old
.udma_start
;
486 ch
->udma_stop
= old
.udma_stop
;
487 ch
->udma_init
= old
.udma_init
;
488 ch
->udma_irq_status
= old
.udma_irq_status
;
489 ch
->udma_timeout
= old
.udma_timeout
;
490 ch
->udma_irq_lost
= old
.udma_irq_lost
;
491 ch
->busproc
= old
.busproc
;
492 ch
->bus_state
= old
.bus_state
;
493 ch
->dma_base
= old
.dma_base
;
494 ch
->dma_extra
= old
.dma_extra
;
495 ch
->config_data
= old
.config_data
;
496 ch
->select_data
= old
.select_data
;
498 /* FIXME: most propably this is always right:! */
499 #ifndef CONFIG_BLK_DEV_IDECS
502 ch
->major
= old
.major
;
503 ch
->chipset
= old
.chipset
;
504 ch
->autodma
= old
.autodma
;
505 ch
->udma_four
= old
.udma_four
;
507 ch
->pci_dev
= old
.pci_dev
;
509 ch
->straight8
= old
.straight8
;
512 spin_unlock_irqrestore(&ide_lock
, flags
);
515 static int subdriver_match(struct ata_channel
*channel
, struct ata_operations
*ops
)
519 if (!channel
->present
)
523 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
524 struct ata_device
*drive
= &channel
->drives
[unit
];
525 if (drive
->present
&& !drive
->driver
) {
526 (*ops
->attach
)(drive
);
527 if (drive
->driver
!= NULL
)
535 * Register an IDE interface, specifing exactly the registers etc
536 * Set initializing=1 iff calling before probes have taken place.
538 int ide_register_hw(hw_regs_t
*hw
)
542 struct ata_channel
*ch
;
545 for (h
= 0; h
< MAX_HWIFS
; ++h
) {
547 if (ch
->hw
.io_ports
[IDE_DATA_OFFSET
] == hw
->io_ports
[IDE_DATA_OFFSET
])
550 for (h
= 0; h
< MAX_HWIFS
; ++h
) {
552 if ((!ch
->present
&& (ch
->unit
== ATA_PRIMARY
) && !initializing
) ||
553 (!ch
->hw
.io_ports
[IDE_DATA_OFFSET
] && initializing
))
556 for (h
= 0; h
< MAX_HWIFS
; ++h
)
557 ide_unregister(&ide_hwifs
[h
]);
566 memcpy(&ch
->hw
, hw
, sizeof(*hw
));
567 memcpy(ch
->io_ports
, ch
->hw
.io_ports
, sizeof(ch
->hw
.io_ports
));
570 ch
->chipset
= hw
->chipset
;
574 /* FIXME: Do we really have to call it second time here?! */
578 /* Look up whatever there is a subdriver, which will serve this
579 * device and execute the attach method it is providing.
582 struct ata_operations
*tmp
;
585 spin_lock_irqsave(&ata_drivers_lock
, flags
);
586 for(tmp
= ata_drivers
; tmp
; tmp
= tmp
->next
) {
587 if (subdriver_match(ch
, tmp
) > 0)
590 spin_unlock_irqrestore(&ata_drivers_lock
, flags
);
593 return (initializing
|| ch
->present
) ? h
: -1;
596 /****************************************************************************
597 * FIXME: rewrite the following crap:
601 * Parsing for ide_setup():
603 * 1. the first char of s must be '='.
604 * 2. if the remainder matches one of the supplied keywords,
605 * the index (1 based) of the keyword is negated and returned.
606 * 3. if the remainder is a series of no more than max_vals numbers
607 * separated by commas, the numbers are saved in vals[] and a
608 * count of how many were saved is returned. Base10 is assumed,
609 * and base16 is allowed when prefixed with "0x". The number of
610 * values read will be placed in vals[0], and the values read will
611 * placed in vals[1] to vals[max_vals].
612 * 4. otherwise, zero is returned.
614 static int __init
match_parm (char *s
, const char *keywords
[], int vals
[], int max_vals
)
620 * Try matching against the supplied keywords,
621 * and return -(index+1) if we match one
623 if (keywords
!= NULL
) {
624 for (i
= 0; *keywords
!= NULL
; ++i
) {
625 if (!strcmp(s
, *keywords
++))
630 * Look for a series of no more than "max_vals"
631 * numeric values separated by commas, in base10,
632 * or base16 when prefixed with "0x".
633 * Return a count of how many were found.
635 get_options(s
, max_vals
+1, vals
);
642 * This sets reasonable default values into all fields of all instances of the
643 * channles and drives, but only on the first call. Subsequent calls have no
644 * effect (they don't wipe out anything).
646 * This routine is normally called at driver initialization time, but may also
647 * be called MUCH earlier during kernel "command-line" parameter processing.
648 * As such, we cannot depend on any other parts of the kernel (such as memory
649 * allocation) to be functioning yet.
651 * This is too bad, as otherwise we could dynamically allocate the ata_device
652 * structs as needed, rather than always consuming memory for the max possible
653 * number (MAX_HWIFS * MAX_DRIVES) of them.
655 #define MAGIC_COOKIE 0x12345678
656 static void __init
init_global_data(void)
659 static unsigned long magic_cookie
= MAGIC_COOKIE
;
661 if (magic_cookie
!= MAGIC_COOKIE
)
662 return; /* already initialized */
665 /* Initialize all interface structures */
666 for (h
= 0; h
< MAX_HWIFS
; ++h
)
667 init_hwif_data(&ide_hwifs
[h
], h
);
669 /* Add default hw interfaces */
670 ide_init_default_hwifs();
674 * This gets called VERY EARLY during initialization, to handle kernel "command
675 * line" strings beginning with "hdx=". It gets called even before the actual
676 * module gets initialized.
678 * Please look at Documentation/ide.txt to see the complete list of supported
681 static int __init
ata_hd_setup(char *s
)
684 struct ata_channel
*ch
; /* FIXME: Channel parms should not be accessed in ata_hd_setup */
685 struct ata_device
*drive
;
686 unsigned int hw
, unit
;
687 const char max_drive
= 'a' + ((MAX_HWIFS
* MAX_DRIVES
) - 1);
689 if (s
[0] == '=') /* hd= is for hd.c driver and not us */
692 printk(KERN_INFO
"hd%s", s
);
695 if (s
[0] >= 'a' && s
[0] <= max_drive
) {
696 static const char *hd_words
[] = {"none", "noprobe", "nowerr", "cdrom",
697 "serialize", "autotune", "noautotune",
698 "slow", "flash", "scsi", NULL
};
700 hw
= unit
/ MAX_DRIVES
;
701 unit
= unit
% MAX_DRIVES
;
703 drive
= &ch
->drives
[unit
];
705 /* Look for hdx=ide-* */
706 if (!strncmp(s
+1, "=ide-", 5)) {
707 strncpy(drive
->driver_req
, s
+2, 9);
711 * Look for last lun option: "hdxlun="
713 if (!strncmp(s
+1, "lun=", 4)) {
714 if (*get_options(s
+5, 2, vals
) || vals
[0]!=1)
716 if (vals
[1] >= 0 && vals
[1] <= 7) {
717 drive
->last_lun
= vals
[1];
718 drive
->forced_lun
= 1;
720 printk(" -- BAD LAST LUN! Expected value from 0 to 7");
723 switch (match_parm(s
+1, hd_words
, vals
, 3)) {
724 case -1: /* "none" */
725 drive
->nobios
= 1; /* drop into "noprobe" */
726 case -2: /* "noprobe" */
729 case -3: /* "nowerr" */
730 drive
->bad_wstat
= BAD_R_STAT
;
731 ch
->noprobe
= 0; /* FIXME: Channel parm */
733 case -4: /* "cdrom" */
735 drive
->type
= ATA_ROM
;
736 ch
->noprobe
= 0; /* FIXME: Channel parm */
738 case -5: /* "serialize" */
739 printk(" -- USE \"ide%d=serialize\" INSTEAD", hw
);
741 case -6: /* "autotune" */
744 case -7: /* "noautotune" */
747 case -8: /* "slow" */
748 ch
->slow
= 1; /* FIXME: Channel parm */
750 case -9: /* "flash" */
751 drive
->ata_flash
= 1;
753 case -10: /* "scsi" */
754 #if defined(CONFIG_BLK_DEV_IDESCSI) && defined(CONFIG_SCSI)
761 case 3: /* cyl,head,sect */
762 drive
->type
= ATA_DISK
;
763 drive
->cyl
= drive
->bios_cyl
= vals
[1];
764 drive
->head
= drive
->bios_head
= vals
[2];
765 drive
->sect
= drive
->bios_sect
= vals
[3];
767 drive
->forced_geom
= 1;
776 printk(" -- BAD OPTION\n");
786 * This gets called VERY EARLY during initialization, to handle kernel "command
787 * line" strings beginning with "ide". It gets called even before the actual
788 * module gets initialized.
790 * Please look at Documentation/ide.txt to see the complete list of supported
793 int __init
ide_setup(char *s
)
796 struct ata_channel
*ch
;
798 const char max_ch
= '0' + (MAX_HWIFS
- 1);
800 printk(KERN_INFO
"ide%s", s
);
803 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
804 if (!strcmp(s
, "=doubler")) {
805 extern int ide_doubler
;
807 printk(KERN_INFO
" : Enabled support for ATA doublers\n");
813 if (!strcmp(s
, "=nodma")) {
814 printk(KERN_INFO
"ATA: Prevented DMA\n");
820 if (!strcmp(s
, "=reverse")) {
821 ide_scan_direction
= 1;
822 printk(" : Enabled support for IDE inverse scan order.\n");
828 * Look for bus speed option: "idebus="
830 if (!strncmp(s
, "bus=", 4)) {
831 if (*get_options(s
+4, 2, vals
) || vals
[0] != 1)
833 idebus_parameter
= vals
[1];
838 * Look for interface options: "idex="
840 if (s
[0] >= '0' && s
[0] <= max_ch
) {
842 * Be VERY CAREFUL changing this: note hardcoded indexes below
844 const char *ide_options
[] = {
845 "noprobe", "serialize", "autotune", "noautotune", "reset", "dma", "ata66", NULL
};
846 const char *ide_words
[] = {
847 "qd65xx", "ht6560b", "cmd640_vlb", "dtc2278", "umc8672", "ali14xx", "dc4030", NULL
};
852 switch (match_parm(s
+ 1, ide_options
, vals
, 1)) {
867 case -4: /* noautotune */
868 ch
->drives
[0].autotune
= 2;
869 ch
->drives
[1].autotune
= 2;
871 case -3: /* autotune */
872 ch
->drives
[0].autotune
= 1;
873 ch
->drives
[1].autotune
= 1;
875 case -2: /* "serialize" */
877 struct ata_channel
*mate
;
879 mate
= &ide_hwifs
[hw
^ 1];
881 mate
->serialized
= 1;
885 case -1: /* "noprobe" */
891 * Check for specific chipset name
893 i
= match_parm(s
+ 1, ide_words
, vals
, 3);
896 * Cryptic check to ensure chipset not already set for a channel:
898 if (i
) { /* is parameter a chipset name? */
899 if (ide_hwifs
[hw
].chipset
!= ide_unknown
)
900 goto bad_option
; /* chipset already specified */
901 if (i
!= -7 && hw
!= 0)
902 goto bad_channel
; /* chipset drivers are for "ide0=" only */
903 if (i
!= -7 && ide_hwifs
[1].chipset
!= ide_unknown
)
904 goto bad_option
; /* chipset for 2nd port already specified */
909 #ifdef CONFIG_BLK_DEV_PDC4030
910 case -7: /* "dc4030" */
912 extern void init_pdc4030(void);
917 #ifdef CONFIG_BLK_DEV_ALI14XX
918 case -6: /* "ali14xx" */
920 extern void init_ali14xx(void);
925 #ifdef CONFIG_BLK_DEV_UMC8672
926 case -5: /* "umc8672" */
928 extern void init_umc8672(void);
933 #ifdef CONFIG_BLK_DEV_DTC2278
934 case -4: /* "dtc2278" */
936 extern void init_dtc2278(void);
941 #ifdef CONFIG_BLK_DEV_CMD640
942 case -3: /* "cmd640_vlb" */
944 extern int cmd640_vlb
; /* flag for cmd640.c */
949 #ifdef CONFIG_BLK_DEV_HT6560B
950 case -2: /* "ht6560b" */
952 extern void init_ht6560b(void);
957 #if CONFIG_BLK_DEV_QD65XX
958 case -1: /* "qd65xx" */
960 extern void init_qd65xx(void);
966 vals
[2] = vals
[1] + 0x206; /* default ctl */
967 case 2: /* base,ctl */
968 vals
[3] = 0; /* default irq = probe for it */
969 case 3: /* base,ctl,irq */
970 ch
->hw
.irq
= vals
[3];
971 ide_init_hwif_ports(&ch
->hw
, (ide_ioreg_t
) vals
[1], (ide_ioreg_t
) vals
[2], &ch
->irq
);
972 memcpy(ch
->io_ports
, ch
->hw
.io_ports
, sizeof(ch
->io_ports
));
975 ch
->chipset
= ide_generic
;
981 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
987 printk(" -- BAD OPTION\n");
991 printk("-- NOT SUPPORTED ON ide%d", hw
);
999 /****************************************************************************/
1001 int ata_register_device(struct ata_device
*drive
, struct ata_operations
*driver
)
1003 unsigned long flags
;
1005 /* FIXME: The locking here doesn't make the slightest sense! */
1006 spin_lock_irqsave(&ide_lock
, flags
);
1008 if (!drive
->present
|| drive
->driver
!= NULL
|| drive
->busy
|| drive
->usage
) {
1009 spin_unlock_irqrestore(&ide_lock
, flags
);
1013 drive
->driver
= driver
;
1014 spin_unlock_irqrestore(&ide_lock
, flags
);
1016 /* Default autotune or requested autotune */
1017 if (drive
->autotune
!= 2) {
1018 struct ata_channel
*ch
= drive
->channel
;
1019 if (ch
->udma_setup
) {
1022 * Force DMAing for the beginning of the check. Some
1023 * chipsets appear to do interesting things, if not
1024 * checked and cleared.
1029 spin_lock_irqsave(ch
->lock
, flags
);
1030 udma_enable(drive
, 0, 0);
1031 ch
->udma_setup(drive
, ch
->modes_map
);
1032 #ifdef CONFIG_BLK_DEV_IDE_TCQ_DEFAULT
1033 udma_tcq_enable(drive
, 1);
1035 spin_unlock_irqrestore(ch
->lock
, flags
);
1038 /* Only CD-ROMs and tape drives support DSC overlap. But only
1039 * if they are alone on a channel. */
1040 if (drive
->type
== ATA_ROM
|| drive
->type
== ATA_TAPE
) {
1044 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
)
1045 if (drive
->channel
->drives
[unit
].present
)
1048 drive
->dsc_overlap
= (single
== 1);
1050 drive
->dsc_overlap
= 0;
1057 * This is in fact the default cleanup routine.
1059 * FIXME: Check whatever we maybe don't call it twice!.
1061 int ata_unregister_device(struct ata_device
*drive
)
1063 if (drive
->usage
|| drive
->busy
|| !ata_ops(drive
))
1066 #if defined(CONFIG_BLK_DEV_ISAPNP) && defined(CONFIG_ISAPNP) && defined(MODULE)
1069 drive
->driver
= NULL
;
1076 * Register an ATA subdriver for a particular device type.
1078 int register_ata_driver(struct ata_operations
*driver
)
1080 unsigned long flags
;
1084 spin_lock_irqsave(&ata_drivers_lock
, flags
);
1085 driver
->next
= ata_drivers
;
1086 ata_drivers
= driver
;
1087 spin_unlock_irqrestore(&ata_drivers_lock
, flags
);
1089 for (index
= 0; index
< MAX_HWIFS
; ++index
)
1090 count
+= subdriver_match(&ide_hwifs
[index
], driver
);
1095 EXPORT_SYMBOL(register_ata_driver
);
1098 * Unregister an ATA sub-driver for a particular device type.
1100 void unregister_ata_driver(struct ata_operations
*driver
)
1102 struct ata_operations
**tmp
;
1103 unsigned long flags
;
1107 spin_lock_irqsave(&ata_drivers_lock
, flags
);
1108 for (tmp
= &ata_drivers
; *tmp
!= NULL
; tmp
= &(*tmp
)->next
) {
1109 if (*tmp
== driver
) {
1110 *tmp
= driver
->next
;
1114 spin_unlock_irqrestore(&ata_drivers_lock
, flags
);
1116 for (index
= 0; index
< MAX_HWIFS
; ++index
) {
1117 struct ata_channel
*ch
= &ide_hwifs
[index
];
1118 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
1119 struct ata_device
*drive
= &ch
->drives
[unit
];
1121 if (drive
->driver
== driver
)
1122 (*ata_ops(drive
)->cleanup
)(drive
);
1127 EXPORT_SYMBOL(ide_hwifs
);
1128 EXPORT_SYMBOL(ide_lock
);
1130 devfs_handle_t ide_devfs_handle
;
1132 EXPORT_SYMBOL(ata_register_device
);
1133 EXPORT_SYMBOL(ata_unregister_device
);
1134 EXPORT_SYMBOL(ide_register_hw
);
1135 EXPORT_SYMBOL(ide_unregister
);
1136 EXPORT_SYMBOL(get_info_ptr
);
1139 * Handle power handling related events ths system informs us about.
1141 static int ata_sys_notify(struct notifier_block
*this, unsigned long event
, void *x
)
1154 printk(KERN_INFO
"flushing ATA/ATAPI devices: ");
1156 for (i
= 0; i
< MAX_HWIFS
; i
++) {
1158 struct ata_channel
*ch
= &ide_hwifs
[i
];
1163 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
1164 struct ata_device
*drive
= &ch
->drives
[unit
];
1166 if (!drive
->present
)
1169 /* set the drive to standby */
1170 printk("%s ", drive
->name
);
1171 if (ata_ops(drive
)) {
1172 if (event
!= SYS_RESTART
) {
1173 if (ata_ops(drive
)->standby
&& ata_ops(drive
)->standby(drive
))
1177 if (ata_ops(drive
)->cleanup
)
1178 ata_ops(drive
)->cleanup(drive
);
1186 static struct notifier_block ata_notifier
= {
1193 * This is the global initialization entry point.
1195 static int __init
ata_module_init(void)
1197 printk(KERN_INFO
"ATA/ATAPI device driver v" VERSION
"\n");
1199 ide_devfs_handle
= devfs_mk_dir(NULL
, "ide", NULL
);
1202 * Because most of the ATA adapters represent the timings in unit of
1203 * bus clocks, and there is no known reliable way to detect the bus
1204 * clock frequency, we assume 50 MHz for non-PCI (VLB, EISA) and 33 MHz
1205 * for PCI based systems. Since assuming only hurts performance and not
1206 * stability, this is OK. The user can change this on the command line
1207 * by using the "idebus=XX" parameter. While the system_bus_speed
1208 * variable is in kHz units, we accept both MHz and kHz entry on the
1209 * command line for backward compatibility.
1212 system_bus_speed
= 50000;
1215 system_bus_speed
= 33333;
1217 if (idebus_parameter
>= 20 && idebus_parameter
<= 80) {
1219 system_bus_speed
= idebus_parameter
* 1000;
1221 switch (system_bus_speed
) {
1222 case 33000: system_bus_speed
= 33333; break;
1223 case 37000: system_bus_speed
= 37500; break;
1224 case 41000: system_bus_speed
= 41666; break;
1225 case 66000: system_bus_speed
= 66666; break;
1229 if (idebus_parameter
>= 20000 && idebus_parameter
<= 80000)
1230 system_bus_speed
= idebus_parameter
;
1232 printk(KERN_INFO
"ATA: %s bus speed %d.%dMHz\n",
1233 pci_present() ? "PCI" : "System", system_bus_speed
/ 1000, system_bus_speed
/ 100 % 10);
1241 * Register the host chip drivers.
1243 # ifdef CONFIG_BLK_DEV_PIIX
1246 # ifdef CONFIG_BLK_DEV_VIA82CXXX
1249 # ifdef CONFIG_BLK_DEV_PDC202XX
1252 # ifdef CONFIG_BLK_DEV_RZ1000
1255 # ifdef CONFIG_BLK_DEV_SIS5513
1258 # ifdef CONFIG_BLK_DEV_CMD64X
1261 # ifdef CONFIG_BLK_DEV_OPTI621
1264 # ifdef CONFIG_BLK_DEV_TRM290
1267 # ifdef CONFIG_BLK_DEV_NS87415
1270 # ifdef CONFIG_BLK_DEV_AEC62XX
1273 # ifdef CONFIG_BLK_DEV_SL82C105
1276 # ifdef CONFIG_BLK_DEV_HPT34X
1279 # ifdef CONFIG_BLK_DEV_HPT366
1282 # ifdef CONFIG_BLK_DEV_ALI15X3
1285 # ifdef CONFIG_BLK_DEV_CY82C693
1288 # ifdef CONFIG_BLK_DEV_CS5530
1291 # ifdef CONFIG_BLK_DEV_AMD74XX
1294 # ifdef CONFIG_BLK_DEV_SVWKS
1297 # ifdef CONFIG_BLK_DEV_IT8172
1301 init_ata_pci_misc();
1304 * Detect and initialize "known" IDE host chip types.
1306 if (pci_present()) {
1308 ide_scan_pcibus(ide_scan_direction
);
1310 # ifdef CONFIG_BLK_DEV_RZ1000
1311 ide_probe_for_rz100x();
1317 #ifdef CONFIG_ETRAX_IDE
1320 #ifdef CONFIG_BLK_DEV_CMD640
1321 ide_probe_for_cmd640x();
1323 #ifdef CONFIG_BLK_DEV_PDC4030
1324 ide_probe_for_pdc4030();
1326 #ifdef CONFIG_BLK_DEV_IDE_PMAC
1329 #ifdef CONFIG_BLK_DEV_IDE_ICSIDE
1332 #ifdef CONFIG_BLK_DEV_IDE_RAPIDE
1335 #ifdef CONFIG_BLK_DEV_GAYLE
1338 #ifdef CONFIG_BLK_DEV_FALCON_IDE
1341 #ifdef CONFIG_BLK_DEV_MAC_IDE
1344 #ifdef CONFIG_BLK_DEV_Q40IDE
1347 #ifdef CONFIG_BLK_DEV_BUDDHA
1350 #if defined(CONFIG_BLK_DEV_ISAPNP) && defined(CONFIG_ISAPNP)
1354 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
1355 # if defined(__mc68000__) || defined(CONFIG_APUS)
1356 if (ide_hwifs
[0].io_ports
[IDE_DATA_OFFSET
]) {
1357 ide_get_lock(&ide_irq_lock
, NULL
, NULL
);/* for atari only */
1358 disable_irq(ide_hwifs
[0].irq
); /* disable_irq_nosync ?? */
1359 // disable_irq_nosync(ide_hwifs[0].irq);
1365 # if defined(__mc68000__) || defined(CONFIG_APUS)
1366 if (ide_hwifs
[0].io_ports
[IDE_DATA_OFFSET
]) {
1367 enable_irq(ide_hwifs
[0].irq
);
1368 ide_release_lock(&ide_irq_lock
);/* for atari only */
1374 * Initialize all device type driver modules.
1376 #ifdef CONFIG_BLK_DEV_IDEDISK
1379 #ifdef CONFIG_BLK_DEV_IDECD
1382 #ifdef CONFIG_BLK_DEV_IDETAPE
1385 #ifdef CONFIG_BLK_DEV_IDEFLOPPY
1391 register_reboot_notifier(&ata_notifier
);
1396 static char *options
= NULL
;
1398 static int __init
init_ata(void)
1401 if (options
!= NULL
&& *options
) {
1402 char *next
= options
;
1404 while ((options
= next
) != NULL
) {
1405 if ((next
= strchr(options
,' ')) != NULL
)
1407 if (!strncmp(options
,"hd",2)) {
1408 if (!ata_hd_setup(options
+2))
1409 printk(KERN_ERR
"Unknown option '%s'\n", options
);
1411 else if (!strncmp(options
,"ide",3)) {
1412 if (!ide_setup(options
+3))
1413 printk(KERN_ERR
"Unknown option '%s'\n", options
);
1417 return ata_module_init();
1420 static void __exit
cleanup_ata(void)
1424 unregister_reboot_notifier(&ata_notifier
);
1425 for (h
= 0; h
< MAX_HWIFS
; ++h
) {
1426 ide_unregister(&ide_hwifs
[h
]);
1429 devfs_unregister(ide_devfs_handle
);
1432 module_init(init_ata
);
1433 module_exit(cleanup_ata
);
1437 /* command line option parser */
1438 __setup("ide", ide_setup
);
1439 __setup("hd", ata_hd_setup
);