blob: c779aa24dbe66a28d8a96a146c75177c5cff7330 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Bartlomiej Zolnierkiewicz59bca8c2008-02-01 23:09:33 +01002 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
Pavel Machekfc410692008-07-23 19:56:02 +02003 * Copyright (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
5
6/*
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>
10 *
11 * See linux/MAINTAINERS for address of current maintainer.
12 *
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
15 * (usually 14 & 15).
16 * There can be up to two drives per interface, as per the ATA-2 spec.
17 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * ...
19 *
20 * From hd.c:
21 * |
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!
25 * |
26 * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
27 * |
28 * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
29 * | in the early extended-partition checks and added DM partitions.
30 * |
31 * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
32 * |
33 * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
34 * | and general streamlining by Mark Lord (mlord@pobox.com).
35 *
36 * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
37 *
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)
41 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 */
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/module.h>
48#include <linux/types.h>
49#include <linux/string.h>
50#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/interrupt.h>
52#include <linux/major.h>
53#include <linux/errno.h>
54#include <linux/genhd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <linux/slab.h>
56#include <linux/init.h>
57#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include <linux/ide.h>
Bartlomiej Zolnierkiewicz3ceca722008-10-10 22:39:27 +020059#include <linux/hdreg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <linux/completion.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Bartlomiej Zolnierkiewiczf74c9142008-04-18 00:46:23 +020063struct class *ide_port_class;
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065/*
66 * Locks for IDE setting functionality
67 */
68
Matthias Kaehlckef9383c42007-07-09 23:17:56 +020069DEFINE_MUTEX(ide_setting_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Bartlomiej Zolnierkiewicz8185d5a2008-10-10 22:39:28 +020071ide_devset_get(io_32bit, io_32bit);
72
Elias Oltmanns92f1f8f2008-10-10 22:39:40 +020073static int set_io_32bit(ide_drive_t *drive, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +020075 if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +020076 return -EPERM;
77
78 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
79 return -EINVAL;
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 drive->io_32bit = arg;
Bartlomiej Zolnierkiewicz644a9d72007-12-12 23:32:00 +010082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 return 0;
84}
85
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +020086ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
Bartlomiej Zolnierkiewicz8185d5a2008-10-10 22:39:28 +020087
Elias Oltmanns92f1f8f2008-10-10 22:39:40 +020088static int set_ksettings(ide_drive_t *drive, int arg)
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +020089{
90 if (arg < 0 || arg > 1)
91 return -EINVAL;
92
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +020093 if (arg)
94 drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
95 else
96 drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +020097
98 return 0;
99}
100
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200101ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
Bartlomiej Zolnierkiewicz8185d5a2008-10-10 22:39:28 +0200102
Elias Oltmanns92f1f8f2008-10-10 22:39:40 +0200103static int set_using_dma(ide_drive_t *drive, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
105#ifdef CONFIG_BLK_DEV_IDEDMA
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200106 int err = -EPERM;
107
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200108 if (arg < 0 || arg > 1)
109 return -EINVAL;
110
Bartlomiej Zolnierkiewicz48fb2682008-10-10 22:39:19 +0200111 if (ata_id_has_dma(drive->id) == 0)
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200112 goto out;
113
Elias Oltmanns92f1f8f2008-10-10 22:39:40 +0200114 if (drive->hwif->dma_ops == NULL)
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200115 goto out;
116
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200117 err = 0;
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if (arg) {
Bartlomiej Zolnierkiewicz23b1bd42008-01-25 22:17:19 +0100120 if (ide_set_dma(drive))
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200121 err = -EIO;
Bartlomiej Zolnierkiewicz7469aaf2007-02-17 02:40:26 +0100122 } else
123 ide_dma_off(drive);
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200124
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200125out:
126 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#else
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200128 if (arg < 0 || arg > 1)
129 return -EINVAL;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 return -EPERM;
132#endif
133}
134
Bartlomiej Zolnierkiewicz6982daf2008-10-13 21:39:40 +0200135/*
136 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
137 */
138static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
139{
140 switch (req_pio) {
141 case 202:
142 case 201:
143 case 200:
144 case 102:
145 case 101:
146 case 100:
147 return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
148 case 9:
149 case 8:
150 return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
151 case 7:
152 case 6:
153 return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
154 default:
155 return 0;
156 }
157}
158
Elias Oltmanns92f1f8f2008-10-10 22:39:40 +0200159static int set_pio_mode(ide_drive_t *drive, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Bartlomiej Zolnierkiewicz784506c2008-04-26 17:36:43 +0200161 ide_hwif_t *hwif = drive->hwif;
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200162 const struct ide_port_ops *port_ops = hwif->port_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200164 if (arg < 0 || arg > 255)
165 return -EINVAL;
166
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200167 if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
Bartlomiej Zolnierkiewicz784506c2008-04-26 17:36:43 +0200168 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return -ENOSYS;
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200170
Bartlomiej Zolnierkiewicz6982daf2008-10-13 21:39:40 +0200171 if (set_pio_mode_abuse(drive->hwif, arg)) {
172 if (arg == 8 || arg == 9) {
173 unsigned long flags;
Bartlomiej Zolnierkiewicz145b75e2008-01-26 20:13:11 +0100174
Bartlomiej Zolnierkiewicz6982daf2008-10-13 21:39:40 +0200175 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
Bartlomiej Zolnierkiewiczb65fac32009-01-06 17:20:50 +0100176 spin_lock_irqsave(&hwif->lock, flags);
Bartlomiej Zolnierkiewicz6982daf2008-10-13 21:39:40 +0200177 port_ops->set_pio_mode(drive, arg);
Bartlomiej Zolnierkiewiczb65fac32009-01-06 17:20:50 +0100178 spin_unlock_irqrestore(&hwif->lock, flags);
Bartlomiej Zolnierkiewicz6982daf2008-10-13 21:39:40 +0200179 } else
180 port_ops->set_pio_mode(drive, arg);
181 } else {
182 int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
Bartlomiej Zolnierkiewicz145b75e2008-01-26 20:13:11 +0100183
Bartlomiej Zolnierkiewicz6982daf2008-10-13 21:39:40 +0200184 ide_set_pio(drive, arg);
FUJITA Tomonori5b114712008-07-15 21:21:44 +0200185
Bartlomiej Zolnierkiewicz6982daf2008-10-13 21:39:40 +0200186 if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
187 if (keep_dma)
188 ide_dma_on(drive);
189 }
190 }
FUJITA Tomonori5b114712008-07-15 21:21:44 +0200191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return 0;
193}
194
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200195ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
Bartlomiej Zolnierkiewicz8185d5a2008-10-10 22:39:28 +0200196
Elias Oltmanns92f1f8f2008-10-10 22:39:40 +0200197static int set_unmaskirq(ide_drive_t *drive, int arg)
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200198{
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200199 if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200200 return -EPERM;
201
202 if (arg < 0 || arg > 1)
203 return -EINVAL;
204
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200205 if (arg)
206 drive->dev_flags |= IDE_DFLAG_UNMASK;
207 else
208 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200209
210 return 0;
211}
212
Bartlomiej Zolnierkiewiczf8790482008-10-13 21:39:45 +0200213ide_ext_devset_rw_sync(io_32bit, io_32bit);
214ide_ext_devset_rw_sync(keepsettings, ksettings);
215ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
216ide_ext_devset_rw_sync(using_dma, using_dma);
Bartlomiej Zolnierkiewicz6982daf2008-10-13 21:39:40 +0200217__IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
Elias Oltmanns92f1f8f2008-10-10 22:39:40 +0200218
Bartlomiej Zolnierkiewicz08da5912008-07-24 22:53:15 +0200219/**
220 * ide_device_get - get an additional reference to a ide_drive_t
221 * @drive: device to get a reference to
222 *
223 * Gets a reference to the ide_drive_t and increments the use count of the
224 * underlying LLDD module.
225 */
226int ide_device_get(ide_drive_t *drive)
227{
228 struct device *host_dev;
229 struct module *module;
230
231 if (!get_device(&drive->gendev))
232 return -ENXIO;
233
234 host_dev = drive->hwif->host->dev[0];
235 module = host_dev ? host_dev->driver->owner : NULL;
236
237 if (module && !try_module_get(module)) {
238 put_device(&drive->gendev);
239 return -ENXIO;
240 }
241
242 return 0;
243}
244EXPORT_SYMBOL_GPL(ide_device_get);
245
246/**
247 * ide_device_put - release a reference to a ide_drive_t
248 * @drive: device to release a reference on
249 *
250 * Release a reference to the ide_drive_t and decrements the use count of
251 * the underlying LLDD module.
252 */
253void ide_device_put(ide_drive_t *drive)
254{
255#ifdef CONFIG_MODULE_UNLOAD
256 struct device *host_dev = drive->hwif->host->dev[0];
257 struct module *module = host_dev ? host_dev->driver->owner : NULL;
258
259 if (module)
260 module_put(module);
261#endif
262 put_device(&drive->gendev);
263}
264EXPORT_SYMBOL_GPL(ide_device_put);
265
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +0200266static int ide_bus_match(struct device *dev, struct device_driver *drv)
267{
268 return 1;
269}
270
Kay Sievers7eff2e72007-08-14 15:15:12 +0200271static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
Kay Sievers263756e2005-12-12 18:03:44 +0100272{
273 ide_drive_t *drive = to_ide_device(dev);
Kay Sievers263756e2005-12-12 18:03:44 +0100274
Bartlomiej Zolnierkiewiczebdab072009-01-02 16:12:48 +0100275 add_uevent_var(env, "MEDIA=%s", ide_media_string(drive));
Kay Sievers7eff2e72007-08-14 15:15:12 +0200276 add_uevent_var(env, "DRIVENAME=%s", drive->name);
Bartlomiej Zolnierkiewiczebdab072009-01-02 16:12:48 +0100277 add_uevent_var(env, "MODALIAS=ide:m-%s", ide_media_string(drive));
Kay Sievers263756e2005-12-12 18:03:44 +0100278 return 0;
279}
280
Russell King4031bbe2006-01-06 11:41:00 +0000281static int generic_ide_probe(struct device *dev)
282{
283 ide_drive_t *drive = to_ide_device(dev);
Bartlomiej Zolnierkiewicz7f3c8682009-01-06 17:20:53 +0100284 struct ide_driver *drv = to_ide_driver(dev->driver);
Russell King4031bbe2006-01-06 11:41:00 +0000285
286 return drv->probe ? drv->probe(drive) : -ENODEV;
287}
288
289static int generic_ide_remove(struct device *dev)
290{
291 ide_drive_t *drive = to_ide_device(dev);
Bartlomiej Zolnierkiewicz7f3c8682009-01-06 17:20:53 +0100292 struct ide_driver *drv = to_ide_driver(dev->driver);
Russell King4031bbe2006-01-06 11:41:00 +0000293
294 if (drv->remove)
295 drv->remove(drive);
296
297 return 0;
298}
299
300static void generic_ide_shutdown(struct device *dev)
301{
302 ide_drive_t *drive = to_ide_device(dev);
Bartlomiej Zolnierkiewicz7f3c8682009-01-06 17:20:53 +0100303 struct ide_driver *drv = to_ide_driver(dev->driver);
Russell King4031bbe2006-01-06 11:41:00 +0000304
305 if (dev->driver && drv->shutdown)
306 drv->shutdown(drive);
307}
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309struct bus_type ide_bus_type = {
310 .name = "ide",
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +0200311 .match = ide_bus_match,
Kay Sievers263756e2005-12-12 18:03:44 +0100312 .uevent = ide_uevent,
Russell King4031bbe2006-01-06 11:41:00 +0000313 .probe = generic_ide_probe,
314 .remove = generic_ide_remove,
315 .shutdown = generic_ide_shutdown,
Kay Sievers263756e2005-12-12 18:03:44 +0100316 .dev_attrs = ide_dev_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 .suspend = generic_ide_suspend,
318 .resume = generic_ide_resume,
319};
320
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +0200321EXPORT_SYMBOL_GPL(ide_bus_type);
322
Bartlomiej Zolnierkiewiczebae41a2008-04-27 15:38:29 +0200323int ide_vlb_clk;
324EXPORT_SYMBOL_GPL(ide_vlb_clk);
325
326module_param_named(vlb_clock, ide_vlb_clk, int, 0);
327MODULE_PARM_DESC(vlb_clock, "VLB clock frequency (in MHz)");
328
329int ide_pci_clk;
330EXPORT_SYMBOL_GPL(ide_pci_clk);
331
332module_param_named(pci_clock, ide_pci_clk, int, 0);
333MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)");
334
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200335static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp)
336{
337 int a, b, i, j = 1;
338 unsigned int *dev_param_mask = (unsigned int *)kp->arg;
339
David Fries0af80c02009-02-25 20:28:21 +0100340 /* controller . device (0 or 1) [ : 1 (set) | 0 (clear) ] */
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200341 if (sscanf(s, "%d.%d:%d", &a, &b, &j) != 3 &&
342 sscanf(s, "%d.%d", &a, &b) != 2)
343 return -EINVAL;
344
345 i = a * MAX_DRIVES + b;
346
347 if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
348 return -EINVAL;
349
350 if (j)
351 *dev_param_mask |= (1 << i);
352 else
David Fries0af80c02009-02-25 20:28:21 +0100353 *dev_param_mask &= ~(1 << i);
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200354
355 return 0;
356}
357
358static unsigned int ide_nodma;
359
360module_param_call(nodma, ide_set_dev_param_mask, NULL, &ide_nodma, 0);
361MODULE_PARM_DESC(nodma, "disallow DMA for a device");
362
363static unsigned int ide_noflush;
364
365module_param_call(noflush, ide_set_dev_param_mask, NULL, &ide_noflush, 0);
366MODULE_PARM_DESC(noflush, "disable flush requests for a device");
367
368static unsigned int ide_noprobe;
369
370module_param_call(noprobe, ide_set_dev_param_mask, NULL, &ide_noprobe, 0);
371MODULE_PARM_DESC(noprobe, "skip probing for a device");
372
373static unsigned int ide_nowerr;
374
375module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0);
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200376MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device");
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200377
Bartlomiej Zolnierkiewicz4706a7e2008-04-27 15:38:30 +0200378static unsigned int ide_cdroms;
379
380module_param_call(cdrom, ide_set_dev_param_mask, NULL, &ide_cdroms, 0);
381MODULE_PARM_DESC(cdrom, "force device as a CD-ROM");
382
383struct chs_geom {
384 unsigned int cyl;
385 u8 head;
386 u8 sect;
387};
388
389static unsigned int ide_disks;
390static struct chs_geom ide_disks_chs[MAX_HWIFS * MAX_DRIVES];
391
392static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
393{
394 int a, b, c = 0, h = 0, s = 0, i, j = 1;
395
David Fries0af80c02009-02-25 20:28:21 +0100396 /* controller . device (0 or 1) : Cylinders , Heads , Sectors */
397 /* controller . device (0 or 1) : 1 (use CHS) | 0 (ignore CHS) */
Bartlomiej Zolnierkiewicz4706a7e2008-04-27 15:38:30 +0200398 if (sscanf(str, "%d.%d:%d,%d,%d", &a, &b, &c, &h, &s) != 5 &&
399 sscanf(str, "%d.%d:%d", &a, &b, &j) != 3)
400 return -EINVAL;
401
402 i = a * MAX_DRIVES + b;
403
404 if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1)
405 return -EINVAL;
406
407 if (c > INT_MAX || h > 255 || s > 255)
408 return -EINVAL;
409
410 if (j)
411 ide_disks |= (1 << i);
412 else
David Fries0af80c02009-02-25 20:28:21 +0100413 ide_disks &= ~(1 << i);
Bartlomiej Zolnierkiewicz4706a7e2008-04-27 15:38:30 +0200414
415 ide_disks_chs[i].cyl = c;
416 ide_disks_chs[i].head = h;
417 ide_disks_chs[i].sect = s;
418
419 return 0;
420}
421
422module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0);
423MODULE_PARM_DESC(chs, "force device as a disk (using CHS)");
424
Bartlomiej Zolnierkiewicz123995b2008-10-13 21:39:40 +0200425static void ide_dev_apply_params(ide_drive_t *drive, u8 unit)
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200426{
Bartlomiej Zolnierkiewicz123995b2008-10-13 21:39:40 +0200427 int i = drive->hwif->index * MAX_DRIVES + unit;
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200428
429 if (ide_nodma & (1 << i)) {
430 printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200431 drive->dev_flags |= IDE_DFLAG_NODMA;
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200432 }
433 if (ide_noflush & (1 << i)) {
434 printk(KERN_INFO "ide: disabling flush requests for %s\n",
435 drive->name);
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200436 drive->dev_flags |= IDE_DFLAG_NOFLUSH;
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200437 }
438 if (ide_noprobe & (1 << i)) {
439 printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200440 drive->dev_flags |= IDE_DFLAG_NOPROBE;
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200441 }
442 if (ide_nowerr & (1 << i)) {
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200443 printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200444 drive->name);
445 drive->bad_wstat = BAD_R_STAT;
446 }
Bartlomiej Zolnierkiewicz4706a7e2008-04-27 15:38:30 +0200447 if (ide_cdroms & (1 << i)) {
448 printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200449 drive->dev_flags |= IDE_DFLAG_PRESENT;
Bartlomiej Zolnierkiewicz4706a7e2008-04-27 15:38:30 +0200450 drive->media = ide_cdrom;
451 /* an ATAPI device ignores DRDY */
452 drive->ready_stat = 0;
453 }
454 if (ide_disks & (1 << i)) {
455 drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl;
456 drive->head = drive->bios_head = ide_disks_chs[i].head;
457 drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200458
Bartlomiej Zolnierkiewicz4706a7e2008-04-27 15:38:30 +0200459 printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
460 drive->name,
461 drive->cyl, drive->head, drive->sect);
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +0200462
463 drive->dev_flags |= IDE_DFLAG_FORCED_GEOM | IDE_DFLAG_PRESENT;
Bartlomiej Zolnierkiewicz4706a7e2008-04-27 15:38:30 +0200464 drive->media = ide_disk;
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200465 drive->ready_stat = ATA_DRDY;
Bartlomiej Zolnierkiewicz4706a7e2008-04-27 15:38:30 +0200466 }
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200467}
468
Bartlomiej Zolnierkiewicz9fd91d92008-04-27 15:38:23 +0200469static unsigned int ide_ignore_cable;
470
471static int ide_set_ignore_cable(const char *s, struct kernel_param *kp)
472{
473 int i, j = 1;
474
David Fries0af80c02009-02-25 20:28:21 +0100475 /* controller (ignore) */
476 /* controller : 1 (ignore) | 0 (use) */
Bartlomiej Zolnierkiewicz9fd91d92008-04-27 15:38:23 +0200477 if (sscanf(s, "%d:%d", &i, &j) != 2 && sscanf(s, "%d", &i) != 1)
478 return -EINVAL;
479
480 if (i >= MAX_HWIFS || j < 0 || j > 1)
481 return -EINVAL;
482
483 if (j)
484 ide_ignore_cable |= (1 << i);
485 else
David Fries0af80c02009-02-25 20:28:21 +0100486 ide_ignore_cable &= ~(1 << i);
Bartlomiej Zolnierkiewicz9fd91d92008-04-27 15:38:23 +0200487
488 return 0;
489}
490
491module_param_call(ignore_cable, ide_set_ignore_cable, NULL, NULL, 0);
492MODULE_PARM_DESC(ignore_cable, "ignore cable detection");
493
494void ide_port_apply_params(ide_hwif_t *hwif)
495{
Bartlomiej Zolnierkiewicz2bd24a12009-01-06 17:20:56 +0100496 ide_drive_t *drive;
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200497 int i;
498
Bartlomiej Zolnierkiewicz9fd91d92008-04-27 15:38:23 +0200499 if (ide_ignore_cable & (1 << hwif->index)) {
500 printk(KERN_INFO "ide: ignoring cable detection for %s\n",
501 hwif->name);
502 hwif->cbl = ATA_CBL_PATA40_SHORT;
503 }
Bartlomiej Zolnierkiewicz6e875432008-04-27 15:38:30 +0200504
Bartlomiej Zolnierkiewicz2bd24a12009-01-06 17:20:56 +0100505 ide_port_for_each_dev(i, drive, hwif)
506 ide_dev_apply_params(drive, i);
Bartlomiej Zolnierkiewicz9fd91d92008-04-27 15:38:23 +0200507}
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509/*
510 * This is gets invoked once during initialization, to set *everything* up
511 */
512static int __init ide_init(void)
513{
Randy Dunlap349ae232006-10-03 01:14:23 -0700514 int ret;
515
Bartlomiej Zolnierkiewiczeba8ff92008-02-11 00:32:13 +0100516 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
Bartlomiej Zolnierkiewicz537f06c2008-02-01 23:09:35 +0100517
Randy Dunlap349ae232006-10-03 01:14:23 -0700518 ret = bus_register(&ide_bus_type);
519 if (ret < 0) {
520 printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
521 return ret;
522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Bartlomiej Zolnierkiewiczf74c9142008-04-18 00:46:23 +0200524 ide_port_class = class_create(THIS_MODULE, "ide_port");
525 if (IS_ERR(ide_port_class)) {
526 ret = PTR_ERR(ide_port_class);
527 goto out_port_class;
528 }
Bartlomiej Zolnierkiewiczf74c9142008-04-18 00:46:23 +0200529
Bartlomiej Zolnierkiewicz8b803bd2009-03-24 23:22:41 +0100530 ide_acpi_init();
531
Bartlomiej Zolnierkiewicz5cbf79c2007-05-10 00:01:11 +0200532 proc_ide_create();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 return 0;
Bartlomiej Zolnierkiewiczf74c9142008-04-18 00:46:23 +0200535
536out_port_class:
537 bus_unregister(&ide_bus_type);
538
539 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540}
541
Bartlomiej Zolnierkiewicz931ee0d2008-07-15 21:21:47 +0200542static void __exit ide_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 proc_ide_destroy();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Bartlomiej Zolnierkiewiczf74c9142008-04-18 00:46:23 +0200546 class_destroy(ide_port_class);
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 bus_unregister(&ide_bus_type);
549}
550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551module_init(ide_init);
Bartlomiej Zolnierkiewicz931ee0d2008-07-15 21:21:47 +0200552module_exit(ide_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Bartlomiej Zolnierkiewicz931ee0d2008-07-15 21:21:47 +0200554MODULE_LICENSE("GPL");