2 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
3 * Copyright (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz
7 * Mostly written by Mark Lord <mlord@pobox.com>
8 * and Gadi Oxman <gadio@netvision.net.il>
9 * and Andre Hedrick <andre@linux-ide.org>
11 * See linux/MAINTAINERS for address of current maintainer.
13 * This is the multiple IDE interface driver, as evolved from hd.c.
14 * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs
16 * There can be up to two drives per interface, as per the ATA-2 spec.
22 * | It traverses the request-list, using interrupts to jump between functions.
23 * | As nearly all functions can be called within interrupts, we may not sleep.
24 * | Special care is recommended. Have Fun!
26 * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
28 * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
29 * | in the early extended-partition checks and added DM partitions.
31 * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
33 * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
34 * | and general streamlining by Mark Lord (mlord@pobox.com).
36 * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
38 * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg)
39 * Delman Lee (delman@ieee.org) ("Mr. atdisk2")
40 * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom)
42 * This was a rewrite of just about everything from hd.c, though some original
43 * code is still sprinkled about. Think of it as a major evolution, with
44 * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
47 #include <linux/module.h>
48 #include <linux/types.h>
49 #include <linux/string.h>
50 #include <linux/kernel.h>
51 #include <linux/interrupt.h>
52 #include <linux/major.h>
53 #include <linux/errno.h>
54 #include <linux/genhd.h>
55 #include <linux/slab.h>
56 #include <linux/init.h>
57 #include <linux/pci.h>
58 #include <linux/ide.h>
59 #include <linux/hdreg.h>
60 #include <linux/completion.h>
61 #include <linux/device.h>
63 struct class *ide_port_class
;
66 * ide_device_get - get an additional reference to a ide_drive_t
67 * @drive: device to get a reference to
69 * Gets a reference to the ide_drive_t and increments the use count of the
70 * underlying LLDD module.
72 int ide_device_get(ide_drive_t
*drive
)
74 struct device
*host_dev
;
75 struct module
*module
;
77 if (!get_device(&drive
->gendev
))
80 host_dev
= drive
->hwif
->host
->dev
[0];
81 module
= host_dev
? host_dev
->driver
->owner
: NULL
;
83 if (module
&& !try_module_get(module
)) {
84 put_device(&drive
->gendev
);
90 EXPORT_SYMBOL_GPL(ide_device_get
);
93 * ide_device_put - release a reference to a ide_drive_t
94 * @drive: device to release a reference on
96 * Release a reference to the ide_drive_t and decrements the use count of
97 * the underlying LLDD module.
99 void ide_device_put(ide_drive_t
*drive
)
101 #ifdef CONFIG_MODULE_UNLOAD
102 struct device
*host_dev
= drive
->hwif
->host
->dev
[0];
103 struct module
*module
= host_dev
? host_dev
->driver
->owner
: NULL
;
108 put_device(&drive
->gendev
);
110 EXPORT_SYMBOL_GPL(ide_device_put
);
112 static int ide_bus_match(struct device
*dev
, struct device_driver
*drv
)
117 static int ide_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
119 ide_drive_t
*drive
= to_ide_device(dev
);
121 add_uevent_var(env
, "MEDIA=%s", ide_media_string(drive
));
122 add_uevent_var(env
, "DRIVENAME=%s", drive
->name
);
123 add_uevent_var(env
, "MODALIAS=ide:m-%s", ide_media_string(drive
));
127 static int generic_ide_probe(struct device
*dev
)
129 ide_drive_t
*drive
= to_ide_device(dev
);
130 struct ide_driver
*drv
= to_ide_driver(dev
->driver
);
132 return drv
->probe
? drv
->probe(drive
) : -ENODEV
;
135 static int generic_ide_remove(struct device
*dev
)
137 ide_drive_t
*drive
= to_ide_device(dev
);
138 struct ide_driver
*drv
= to_ide_driver(dev
->driver
);
146 static void generic_ide_shutdown(struct device
*dev
)
148 ide_drive_t
*drive
= to_ide_device(dev
);
149 struct ide_driver
*drv
= to_ide_driver(dev
->driver
);
151 if (dev
->driver
&& drv
->shutdown
)
152 drv
->shutdown(drive
);
155 struct bus_type ide_bus_type
= {
157 .match
= ide_bus_match
,
158 .uevent
= ide_uevent
,
159 .probe
= generic_ide_probe
,
160 .remove
= generic_ide_remove
,
161 .shutdown
= generic_ide_shutdown
,
162 .dev_attrs
= ide_dev_attrs
,
163 .suspend
= generic_ide_suspend
,
164 .resume
= generic_ide_resume
,
167 EXPORT_SYMBOL_GPL(ide_bus_type
);
170 EXPORT_SYMBOL_GPL(ide_vlb_clk
);
172 module_param_named(vlb_clock
, ide_vlb_clk
, int, 0);
173 MODULE_PARM_DESC(vlb_clock
, "VLB clock frequency (in MHz)");
176 EXPORT_SYMBOL_GPL(ide_pci_clk
);
178 module_param_named(pci_clock
, ide_pci_clk
, int, 0);
179 MODULE_PARM_DESC(pci_clock
, "PCI bus clock frequency (in MHz)");
181 static int ide_set_dev_param_mask(const char *s
, struct kernel_param
*kp
)
184 unsigned int *dev_param_mask
= (unsigned int *)kp
->arg
;
186 /* controller . device (0 or 1) [ : 1 (set) | 0 (clear) ] */
187 if (sscanf(s
, "%d.%d:%d", &a
, &b
, &j
) != 3 &&
188 sscanf(s
, "%d.%d", &a
, &b
) != 2)
191 i
= a
* MAX_DRIVES
+ b
;
193 if (i
>= MAX_HWIFS
* MAX_DRIVES
|| j
< 0 || j
> 1)
197 *dev_param_mask
|= (1 << i
);
199 *dev_param_mask
&= ~(1 << i
);
204 static unsigned int ide_nodma
;
206 module_param_call(nodma
, ide_set_dev_param_mask
, NULL
, &ide_nodma
, 0);
207 MODULE_PARM_DESC(nodma
, "disallow DMA for a device");
209 static unsigned int ide_noflush
;
211 module_param_call(noflush
, ide_set_dev_param_mask
, NULL
, &ide_noflush
, 0);
212 MODULE_PARM_DESC(noflush
, "disable flush requests for a device");
214 static unsigned int ide_noprobe
;
216 module_param_call(noprobe
, ide_set_dev_param_mask
, NULL
, &ide_noprobe
, 0);
217 MODULE_PARM_DESC(noprobe
, "skip probing for a device");
219 static unsigned int ide_nowerr
;
221 module_param_call(nowerr
, ide_set_dev_param_mask
, NULL
, &ide_nowerr
, 0);
222 MODULE_PARM_DESC(nowerr
, "ignore the ATA_DF bit for a device");
224 static unsigned int ide_cdroms
;
226 module_param_call(cdrom
, ide_set_dev_param_mask
, NULL
, &ide_cdroms
, 0);
227 MODULE_PARM_DESC(cdrom
, "force device as a CD-ROM");
235 static unsigned int ide_disks
;
236 static struct chs_geom ide_disks_chs
[MAX_HWIFS
* MAX_DRIVES
];
238 static int ide_set_disk_chs(const char *str
, struct kernel_param
*kp
)
240 int a
, b
, c
= 0, h
= 0, s
= 0, i
, j
= 1;
242 /* controller . device (0 or 1) : Cylinders , Heads , Sectors */
243 /* controller . device (0 or 1) : 1 (use CHS) | 0 (ignore CHS) */
244 if (sscanf(str
, "%d.%d:%d,%d,%d", &a
, &b
, &c
, &h
, &s
) != 5 &&
245 sscanf(str
, "%d.%d:%d", &a
, &b
, &j
) != 3)
248 i
= a
* MAX_DRIVES
+ b
;
250 if (i
>= MAX_HWIFS
* MAX_DRIVES
|| j
< 0 || j
> 1)
253 if (c
> INT_MAX
|| h
> 255 || s
> 255)
257 ide_disks
|= (1 << i
);
259 ide_disks
&= ~(1 << i
);
261 ide_disks_chs
[i
].cyl
= c
;
262 ide_disks_chs
[i
].head
= h
;
263 ide_disks_chs
[i
].sect
= s
;
268 module_param_call(chs
, ide_set_disk_chs
, NULL
, NULL
, 0);
269 MODULE_PARM_DESC(chs
, "force device as a disk (using CHS)");
271 static void ide_dev_apply_params(ide_drive_t
*drive
, u8 unit
)
273 int i
= drive
->hwif
->index
* MAX_DRIVES
+ unit
;
275 if (ide_nodma
& (1 << i
)) {
276 printk(KERN_INFO
"ide: disallowing DMA for %s\n", drive
->name
);
277 drive
->dev_flags
|= IDE_DFLAG_NODMA
;
279 if (ide_noflush
& (1 << i
)) {
280 printk(KERN_INFO
"ide: disabling flush requests for %s\n",
282 drive
->dev_flags
|= IDE_DFLAG_NOFLUSH
;
284 if (ide_noprobe
& (1 << i
)) {
285 printk(KERN_INFO
"ide: skipping probe for %s\n", drive
->name
);
286 drive
->dev_flags
|= IDE_DFLAG_NOPROBE
;
288 if (ide_nowerr
& (1 << i
)) {
289 printk(KERN_INFO
"ide: ignoring the ATA_DF bit for %s\n",
291 drive
->bad_wstat
= BAD_R_STAT
;
293 if (ide_cdroms
& (1 << i
)) {
294 printk(KERN_INFO
"ide: forcing %s as a CD-ROM\n", drive
->name
);
295 drive
->dev_flags
|= IDE_DFLAG_PRESENT
;
296 drive
->media
= ide_cdrom
;
297 /* an ATAPI device ignores DRDY */
298 drive
->ready_stat
= 0;
300 if (ide_disks
& (1 << i
)) {
301 drive
->cyl
= drive
->bios_cyl
= ide_disks_chs
[i
].cyl
;
302 drive
->head
= drive
->bios_head
= ide_disks_chs
[i
].head
;
303 drive
->sect
= drive
->bios_sect
= ide_disks_chs
[i
].sect
;
305 printk(KERN_INFO
"ide: forcing %s as a disk (%d/%d/%d)\n",
307 drive
->cyl
, drive
->head
, drive
->sect
);
309 drive
->dev_flags
|= IDE_DFLAG_FORCED_GEOM
| IDE_DFLAG_PRESENT
;
310 drive
->media
= ide_disk
;
311 drive
->ready_stat
= ATA_DRDY
;
315 static unsigned int ide_ignore_cable
;
317 static int ide_set_ignore_cable(const char *s
, struct kernel_param
*kp
)
321 /* controller (ignore) */
322 /* controller : 1 (ignore) | 0 (use) */
323 if (sscanf(s
, "%d:%d", &i
, &j
) != 2 && sscanf(s
, "%d", &i
) != 1)
326 if (i
>= MAX_HWIFS
|| j
< 0 || j
> 1)
330 ide_ignore_cable
|= (1 << i
);
332 ide_ignore_cable
&= ~(1 << i
);
337 module_param_call(ignore_cable
, ide_set_ignore_cable
, NULL
, NULL
, 0);
338 MODULE_PARM_DESC(ignore_cable
, "ignore cable detection");
340 void ide_port_apply_params(ide_hwif_t
*hwif
)
345 if (ide_ignore_cable
& (1 << hwif
->index
)) {
346 printk(KERN_INFO
"ide: ignoring cable detection for %s\n",
348 hwif
->cbl
= ATA_CBL_PATA40_SHORT
;
351 ide_port_for_each_dev(i
, drive
, hwif
)
352 ide_dev_apply_params(drive
, i
);
356 * This is gets invoked once during initialization, to set *everything* up
358 static int __init
ide_init(void)
362 printk(KERN_INFO
"Uniform Multi-Platform E-IDE driver\n");
364 ret
= bus_register(&ide_bus_type
);
366 printk(KERN_WARNING
"IDE: bus_register error: %d\n", ret
);
370 ide_port_class
= class_create(THIS_MODULE
, "ide_port");
371 if (IS_ERR(ide_port_class
)) {
372 ret
= PTR_ERR(ide_port_class
);
383 bus_unregister(&ide_bus_type
);
388 static void __exit
ide_exit(void)
392 class_destroy(ide_port_class
);
394 bus_unregister(&ide_bus_type
);
397 module_init(ide_init
);
398 module_exit(ide_exit
);
400 MODULE_LICENSE("GPL");