blob: c2fb5c964a518cf4b4d52c4a5aaed6a5c2e8ba72 [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)
3 * Copyrifht (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#define _IDE_C /* Tell ide.h it's really us */
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/module.h>
50#include <linux/types.h>
51#include <linux/string.h>
52#include <linux/kernel.h>
53#include <linux/timer.h>
54#include <linux/mm.h>
55#include <linux/interrupt.h>
56#include <linux/major.h>
57#include <linux/errno.h>
58#include <linux/genhd.h>
59#include <linux/blkpg.h>
60#include <linux/slab.h>
61#include <linux/init.h>
62#include <linux/pci.h>
63#include <linux/delay.h>
64#include <linux/ide.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#include <linux/completion.h>
66#include <linux/reboot.h>
67#include <linux/cdrom.h>
68#include <linux/seq_file.h>
69#include <linux/device.h>
70#include <linux/bitops.h>
71
72#include <asm/byteorder.h>
73#include <asm/irq.h>
74#include <asm/uaccess.h>
75#include <asm/io.h>
76
77
78/* default maximum number of failures */
79#define IDE_DEFAULT_MAX_FAILURES 1
80
Bartlomiej Zolnierkiewiczf74c9142008-04-18 00:46:23 +020081struct class *ide_port_class;
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
84 IDE2_MAJOR, IDE3_MAJOR,
85 IDE4_MAJOR, IDE5_MAJOR,
86 IDE6_MAJOR, IDE7_MAJOR,
87 IDE8_MAJOR, IDE9_MAJOR };
88
89static int idebus_parameter; /* holds the "idebus=" parameter */
90static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Matthias Kaehlckeef298882007-07-09 23:17:55 +020092DEFINE_MUTEX(ide_cfg_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095int noautodma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Hannes Reineckee3a59b42007-02-07 18:19:37 +010097#ifdef CONFIG_BLK_DEV_IDEACPI
98int ide_noacpi = 0;
99int ide_noacpitfs = 1;
100int ide_noacpionboot = 1;
101#endif
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/*
104 * This is declared extern in ide.h, for access by other IDE modules:
105 */
106ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
107
108EXPORT_SYMBOL(ide_hwifs);
109
Bartlomiej Zolnierkiewicz43514ed2008-04-18 00:46:22 +0200110static void ide_port_init_devices_data(ide_hwif_t *);
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/*
113 * Do not even *think* about calling this!
114 */
Bartlomiej Zolnierkiewiczcbb010c2008-01-26 20:13:06 +0100115void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 /* bulk initialize hwif & drive info with zeros */
118 memset(hwif, 0, sizeof(ide_hwif_t));
119
120 /* fill in any non-zero initial values */
121 hwif->index = index;
122 hwif->major = ide_hwif_to_major[index];
123
124 hwif->name[0] = 'i';
125 hwif->name[1] = 'd';
126 hwif->name[2] = 'e';
127 hwif->name[3] = '0' + index;
128
129 hwif->bus_state = BUSSTATE_ON;
130
Aleksey Makarovf36d4022006-01-09 15:59:27 -0800131 init_completion(&hwif->gendev_rel_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 default_hwif_iops(hwif);
134 default_hwif_transport(hwif);
Bartlomiej Zolnierkiewicz43514ed2008-04-18 00:46:22 +0200135
136 ide_port_init_devices_data(hwif);
137}
138EXPORT_SYMBOL_GPL(ide_init_port_data);
139
140static void ide_port_init_devices_data(ide_hwif_t *hwif)
141{
142 int unit;
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 for (unit = 0; unit < MAX_DRIVES; ++unit) {
145 ide_drive_t *drive = &hwif->drives[unit];
Bartlomiej Zolnierkiewicz43514ed2008-04-18 00:46:22 +0200146 u8 j = (hwif->index * MAX_DRIVES) + unit;
147
148 memset(drive, 0, sizeof(*drive));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 drive->media = ide_disk;
151 drive->select.all = (unit<<4)|0xa0;
152 drive->hwif = hwif;
153 drive->ctl = 0x08;
154 drive->ready_stat = READY_STAT;
155 drive->bad_wstat = BAD_W_STAT;
156 drive->special.b.recalibrate = 1;
157 drive->special.b.set_geometry = 1;
158 drive->name[0] = 'h';
159 drive->name[1] = 'd';
Bartlomiej Zolnierkiewicz43514ed2008-04-18 00:46:22 +0200160 drive->name[2] = 'a' + j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
Bartlomiej Zolnierkiewicz43514ed2008-04-18 00:46:22 +0200162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 INIT_LIST_HEAD(&drive->list);
Aleksey Makarovf36d4022006-01-09 15:59:27 -0800164 init_completion(&drive->gendev_rel_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166}
Bartlomiej Zolnierkiewicz43514ed2008-04-18 00:46:22 +0200167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169/*
170 * init_ide_data() sets reasonable default values into all fields
171 * of all instances of the hwifs and drives, but only on the first call.
172 * Subsequent calls have no effect (they don't wipe out anything).
173 *
174 * This routine is normally called at driver initialization time,
175 * but may also be called MUCH earlier during kernel "command-line"
176 * parameter processing. As such, we cannot depend on any other parts
177 * of the kernel (such as memory allocation) to be functioning yet.
178 *
179 * This is too bad, as otherwise we could dynamically allocate the
180 * ide_drive_t structs as needed, rather than always consuming memory
181 * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
182 *
183 * FIXME: We should stuff the setup data into __init and copy the
184 * relevant hwifs/allocate them properly during boot.
185 */
186#define MAGIC_COOKIE 0x12345678
187static void __init init_ide_data (void)
188{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 unsigned int index;
190 static unsigned long magic_cookie = MAGIC_COOKIE;
Bartlomiej Zolnierkiewicz05734262008-04-18 00:46:25 +0200191 hw_regs_t hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 if (magic_cookie != MAGIC_COOKIE)
194 return; /* already initialized */
195 magic_cookie = 0;
196
197 /* Initialise all interface structures */
198 for (index = 0; index < MAX_HWIFS; ++index) {
Bartlomiej Zolnierkiewicz05734262008-04-18 00:46:25 +0200199 ide_hwif_t *hwif = &ide_hwifs[index];
Bartlomiej Zolnierkiewicze6bfa382008-04-18 00:46:25 +0200200 unsigned long io_addr = ide_default_io_base(index);
201 unsigned long ctl_addr = ide_default_io_ctl(io_addr);
Bartlomiej Zolnierkiewicz05734262008-04-18 00:46:25 +0200202
Bartlomiej Zolnierkiewiczcbb010c2008-01-26 20:13:06 +0100203 ide_init_port_data(hwif, index);
Bartlomiej Zolnierkiewicz05734262008-04-18 00:46:25 +0200204
Bartlomiej Zolnierkiewicze6bfa382008-04-18 00:46:25 +0200205#ifdef CONFIG_IDE_ARCH_OBSOLETE_INIT
Bartlomiej Zolnierkiewicz05734262008-04-18 00:46:25 +0200206 memset(&hw, 0, sizeof(hw));
Bartlomiej Zolnierkiewicze6bfa382008-04-18 00:46:25 +0200207 ide_std_init_ports(&hw, io_addr, ctl_addr);
Bartlomiej Zolnierkiewicz05734262008-04-18 00:46:25 +0200208 memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
Bartlomiej Zolnierkiewicze6bfa382008-04-18 00:46:25 +0200209#endif
Bartlomiej Zolnierkiewicz05734262008-04-18 00:46:25 +0200210 hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
Bartlomiej Zolnierkiewicz5d682e42008-04-18 00:46:31 +0200211#if !defined(CONFIG_PPC32) || defined(CONFIG_PPLUS) || !defined(CONFIG_PCI)
Bartlomiej Zolnierkiewicz9239b332007-10-20 00:32:33 +0200212 hwif->irq =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]);
214#endif
215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
218/**
219 * ide_system_bus_speed - guess bus speed
220 *
221 * ide_system_bus_speed() returns what we think is the system VESA/PCI
222 * bus speed (in MHz). This is used for calculating interface PIO timings.
223 * The default is 40 for known PCI systems, 50 otherwise.
224 * The "idebus=xx" parameter can be used to override this value.
225 * The actual value to be used is computed/displayed the first time
226 * through. Drivers should only use this as a last resort.
227 *
228 * Returns a guessed speed in MHz.
229 */
230
231static int ide_system_bus_speed(void)
232{
233#ifdef CONFIG_PCI
234 static struct pci_device_id pci_default[] = {
235 { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) },
236 { }
237 };
238#else
239#define pci_default 0
240#endif /* CONFIG_PCI */
241
Bartlomiej Zolnierkiewicz537f06c2008-02-01 23:09:35 +0100242 /* user supplied value */
243 if (idebus_parameter)
244 return idebus_parameter;
245
246 /* safe default value for PCI or VESA and PCI*/
247 return pci_dev_present(pci_default) ? 33 : 50;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248}
249
Bartlomiej Zolnierkiewiczbaa8f3e2007-10-20 00:32:31 +0200250ide_hwif_t * ide_find_port(unsigned long base)
251{
252 ide_hwif_t *hwif;
253 int i;
254
255 for (i = 0; i < MAX_HWIFS; i++) {
256 hwif = &ide_hwifs[i];
257 if (hwif->io_ports[IDE_DATA_OFFSET] == base)
258 goto found;
259 }
260
261 for (i = 0; i < MAX_HWIFS; i++) {
262 hwif = &ide_hwifs[i];
Bartlomiej Zolnierkiewicz2625cd52008-04-18 00:46:21 +0200263 if (hwif->chipset == ide_unknown)
Bartlomiej Zolnierkiewiczbaa8f3e2007-10-20 00:32:31 +0200264 goto found;
265 }
266
267 hwif = NULL;
268found:
269 return hwif;
270}
271
272EXPORT_SYMBOL_GPL(ide_find_port);
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274static struct resource* hwif_request_region(ide_hwif_t *hwif,
275 unsigned long addr, int num)
276{
277 struct resource *res = request_region(addr, num, hwif->name);
278
279 if (!res)
280 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
281 hwif->name, addr, addr+num-1);
282 return res;
283}
284
285/**
286 * ide_hwif_request_regions - request resources for IDE
287 * @hwif: interface to use
288 *
289 * Requests all the needed resources for an interface.
290 * Right now core IDE code does this work which is deeply wrong.
291 * MMIO leaves it to the controller driver,
292 * PIO will migrate this way over time.
293 */
294
295int ide_hwif_request_regions(ide_hwif_t *hwif)
296{
297 unsigned long addr;
298 unsigned int i;
299
Bartlomiej Zolnierkiewicz2ad1e552007-02-17 02:40:25 +0100300 if (hwif->mmio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
303 if (addr && !hwif_request_region(hwif, addr, 1))
304 goto control_region_busy;
305 hwif->straight8 = 0;
306 addr = hwif->io_ports[IDE_DATA_OFFSET];
307 if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
308 if (!hwif_request_region(hwif, addr, 8))
309 goto data_region_busy;
310 hwif->straight8 = 1;
311 return 0;
312 }
313 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
314 addr = hwif->io_ports[i];
315 if (!hwif_request_region(hwif, addr, 1)) {
316 while (--i)
317 release_region(addr, 1);
318 goto data_region_busy;
319 }
320 }
321 return 0;
322
323data_region_busy:
324 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
325 if (addr)
326 release_region(addr, 1);
327control_region_busy:
328 /* If any errors are return, we drop the hwif interface. */
329 return -EBUSY;
330}
331
332/**
333 * ide_hwif_release_regions - free IDE resources
334 *
335 * Note that we only release the standard ports,
336 * and do not even try to handle any extra ports
337 * allocated for weird IDE interface chipsets.
338 *
339 * Note also that we don't yet handle mmio resources here. More
340 * importantly our caller should be doing this so we need to
341 * restructure this as a helper function for drivers.
342 */
343
344void ide_hwif_release_regions(ide_hwif_t *hwif)
345{
346 u32 i = 0;
347
Bartlomiej Zolnierkiewicz2ad1e552007-02-17 02:40:25 +0100348 if (hwif->mmio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 return;
350 if (hwif->io_ports[IDE_CONTROL_OFFSET])
351 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
352 if (hwif->straight8) {
353 release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
354 return;
355 }
356 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
357 if (hwif->io_ports[i])
358 release_region(hwif->io_ports[i], 1);
359}
360
Bartlomiej Zolnierkiewiczfbd13082008-02-01 23:09:36 +0100361void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
Bartlomiej Zolnierkiewicz96e5ad32008-02-01 23:09:35 +0100362{
363 ide_hwgroup_t *hwgroup = hwif->hwgroup;
364
365 spin_lock_irq(&ide_lock);
366 /*
367 * Remove us from the hwgroup, and free
368 * the hwgroup if we were the only member
369 */
370 if (hwif->next == hwif) {
371 BUG_ON(hwgroup->hwif != hwif);
372 kfree(hwgroup);
373 } else {
374 /* There is another interface in hwgroup.
375 * Unlink us, and set hwgroup->drive and ->hwif to
376 * something sane.
377 */
378 ide_hwif_t *g = hwgroup->hwif;
379
380 while (g->next != hwif)
381 g = g->next;
382 g->next = hwif->next;
383 if (hwgroup->hwif == hwif) {
384 /* Chose a random hwif for hwgroup->hwif.
385 * It's guaranteed that there are no drives
386 * left in the hwgroup.
387 */
388 BUG_ON(hwgroup->drive != NULL);
389 hwgroup->hwif = g;
390 }
391 BUG_ON(hwgroup->hwif == hwif);
392 }
393 spin_unlock_irq(&ide_lock);
394}
395
Bartlomiej Zolnierkiewicz71bf9f62008-04-18 00:46:22 +0200396/* Called with ide_lock held. */
Bartlomiej Zolnierkiewicz2dde7862008-04-18 00:46:23 +0200397static void __ide_port_unregister_devices(ide_hwif_t *hwif)
Bartlomiej Zolnierkiewicz71bf9f62008-04-18 00:46:22 +0200398{
399 int i;
400
401 for (i = 0; i < MAX_DRIVES; i++) {
402 ide_drive_t *drive = &hwif->drives[i];
403
404 if (drive->present) {
405 spin_unlock_irq(&ide_lock);
406 device_unregister(&drive->gendev);
407 wait_for_completion(&drive->gendev_rel_comp);
408 spin_lock_irq(&ide_lock);
409 }
410 }
411}
412
Bartlomiej Zolnierkiewicz2dde7862008-04-18 00:46:23 +0200413void ide_port_unregister_devices(ide_hwif_t *hwif)
414{
415 mutex_lock(&ide_cfg_mtx);
416 spin_lock_irq(&ide_lock);
417 __ide_port_unregister_devices(hwif);
418 hwif->present = 0;
419 ide_port_init_devices_data(hwif);
420 spin_unlock_irq(&ide_lock);
421 mutex_unlock(&ide_cfg_mtx);
422}
423EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425/**
Sergei Shtylylov020e3222006-10-03 01:14:13 -0700426 * ide_unregister - free an IDE interface
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 * @index: index of interface (will change soon to a pointer)
428 *
429 * Perform the final unregister of an IDE interface. At the moment
430 * we don't refcount interfaces so this will also get split up.
431 *
432 * Locking:
433 * The caller must not hold the IDE locks
434 * The drive present/vanishing is not yet properly locked
435 * Take care with the callbacks. These have been split to avoid
436 * deadlocking the IDE layer. The shutdown callback is called
437 * before we take the lock and free resources. It is up to the
438 * caller to be sure there is no pending I/O here, and that
Sergei Shtylylov020e3222006-10-03 01:14:13 -0700439 * the interface will not be reopened (present/vanishing locking
440 * isn't yet done BTW). After we commit to the final kill we
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 * call the cleanup callback with the ide locks held.
442 *
443 * Unregister restores the hwif structures to the default state.
444 * This is raving bonkers.
445 */
446
Bartlomiej Zolnierkiewicz93de00f2008-04-18 00:46:24 +0200447void ide_unregister(unsigned int index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 ide_hwif_t *hwif, *g;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 ide_hwgroup_t *hwgroup;
Bartlomiej Zolnierkiewicz71bf9f62008-04-18 00:46:22 +0200451 int irq_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 BUG_ON(index >= MAX_HWIFS);
454
455 BUG_ON(in_interrupt());
456 BUG_ON(irqs_disabled());
Matthias Kaehlckeef298882007-07-09 23:17:55 +0200457 mutex_lock(&ide_cfg_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 spin_lock_irq(&ide_lock);
459 hwif = &ide_hwifs[index];
460 if (!hwif->present)
461 goto abort;
Bartlomiej Zolnierkiewicz2dde7862008-04-18 00:46:23 +0200462 __ide_port_unregister_devices(hwif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 hwif->present = 0;
464
465 spin_unlock_irq(&ide_lock);
466
Bartlomiej Zolnierkiewicz5cbf79c2007-05-10 00:01:11 +0200467 ide_proc_unregister_port(hwif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 hwgroup = hwif->hwgroup;
470 /*
471 * free the irq if we were the only hwif using it
472 */
473 g = hwgroup->hwif;
474 do {
475 if (g->irq == hwif->irq)
476 ++irq_count;
477 g = g->next;
478 } while (g != hwgroup->hwif);
479 if (irq_count == 1)
480 free_irq(hwif->irq, hwgroup);
481
Bartlomiej Zolnierkiewicz96e5ad32008-02-01 23:09:35 +0100482 ide_remove_port_from_hwgroup(hwif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Bartlomiej Zolnierkiewiczf74c9142008-04-18 00:46:23 +0200484 device_unregister(hwif->portdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 device_unregister(&hwif->gendev);
Aleksey Makarovf36d4022006-01-09 15:59:27 -0800486 wait_for_completion(&hwif->gendev_rel_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 /*
489 * Remove us from the kernel's knowledge
490 */
491 blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
492 kfree(hwif->sg_table);
493 unregister_blkdev(hwif->major, hwif->name);
494 spin_lock_irq(&ide_lock);
495
Bartlomiej Zolnierkiewicz93de00f2008-04-18 00:46:24 +0200496 if (hwif->dma_base)
497 (void)ide_release_dma(hwif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Bartlomiej Zolnierkiewicz7cba97f2008-02-01 23:09:35 +0100499 ide_hwif_release_regions(hwif);
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 /* restore hwif data to pristine status */
Bartlomiej Zolnierkiewiczcbb010c2008-01-26 20:13:06 +0100502 ide_init_port_data(hwif, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504abort:
505 spin_unlock_irq(&ide_lock);
Matthias Kaehlckeef298882007-07-09 23:17:55 +0200506 mutex_unlock(&ide_cfg_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507}
508
509EXPORT_SYMBOL(ide_unregister);
510
Bartlomiej Zolnierkiewicz57c802e2008-01-26 20:13:05 +0100511void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
512{
513 memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
514 hwif->irq = hw->irq;
515 hwif->noprobe = 0;
516 hwif->chipset = hw->chipset;
517 hwif->gendev.parent = hw->dev;
518 hwif->ack_intr = hw->ack_intr;
519}
520EXPORT_SYMBOL_GPL(ide_init_port_hw);
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522/*
523 * Locks for IDE setting functionality
524 */
525
Matthias Kaehlckef9383c42007-07-09 23:17:56 +0200526DEFINE_MUTEX(ide_setting_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Matthias Kaehlckef9383c42007-07-09 23:17:56 +0200528EXPORT_SYMBOL_GPL(ide_setting_mtx);
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 * ide_spin_wait_hwgroup - wait for group
532 * @drive: drive in the group
533 *
534 * Wait for an IDE device group to go non busy and then return
535 * holding the ide_lock which guards the hwgroup->busy status
536 * and right to use it.
537 */
538
539int ide_spin_wait_hwgroup (ide_drive_t *drive)
540{
541 ide_hwgroup_t *hwgroup = HWGROUP(drive);
542 unsigned long timeout = jiffies + (3 * HZ);
543
544 spin_lock_irq(&ide_lock);
545
546 while (hwgroup->busy) {
547 unsigned long lflags;
548 spin_unlock_irq(&ide_lock);
549 local_irq_set(lflags);
550 if (time_after(jiffies, timeout)) {
551 local_irq_restore(lflags);
552 printk(KERN_ERR "%s: channel busy\n", drive->name);
553 return -EBUSY;
554 }
555 local_irq_restore(lflags);
556 spin_lock_irq(&ide_lock);
557 }
558 return 0;
559}
560
561EXPORT_SYMBOL(ide_spin_wait_hwgroup);
562
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +0200563int set_io_32bit(ide_drive_t *drive, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200565 if (drive->no_io_32bit)
566 return -EPERM;
567
568 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
569 return -EINVAL;
570
Bartlomiej Zolnierkiewicz644a9d72007-12-12 23:32:00 +0100571 if (ide_spin_wait_hwgroup(drive))
572 return -EBUSY;
573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 drive->io_32bit = arg;
Bartlomiej Zolnierkiewicz644a9d72007-12-12 23:32:00 +0100575
576 spin_unlock_irq(&ide_lock);
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 return 0;
579}
580
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200581static int set_ksettings(ide_drive_t *drive, int arg)
582{
583 if (arg < 0 || arg > 1)
584 return -EINVAL;
585
586 if (ide_spin_wait_hwgroup(drive))
587 return -EBUSY;
588 drive->keep_settings = arg;
589 spin_unlock_irq(&ide_lock);
590
591 return 0;
592}
593
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +0200594int set_using_dma(ide_drive_t *drive, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
596#ifdef CONFIG_BLK_DEV_IDEDMA
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200597 ide_hwif_t *hwif = drive->hwif;
598 int err = -EPERM;
599
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200600 if (arg < 0 || arg > 1)
601 return -EINVAL;
602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 if (!drive->id || !(drive->id->capability & 1))
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200604 goto out;
605
Bartlomiej Zolnierkiewicz15ce9262008-01-26 20:13:03 +0100606 if (hwif->dma_host_set == NULL)
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200607 goto out;
608
609 err = -EBUSY;
610 if (ide_spin_wait_hwgroup(drive))
611 goto out;
612 /*
613 * set ->busy flag, unlock and let it ride
614 */
615 hwif->hwgroup->busy = 1;
616 spin_unlock_irq(&ide_lock);
617
618 err = 0;
619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 if (arg) {
Bartlomiej Zolnierkiewicz23b1bd42008-01-25 22:17:19 +0100621 if (ide_set_dma(drive))
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200622 err = -EIO;
Bartlomiej Zolnierkiewicz7469aaf2007-02-17 02:40:26 +0100623 } else
624 ide_dma_off(drive);
Bartlomiej Zolnierkiewicz87996202007-03-26 23:03:19 +0200625
626 /*
627 * lock, clear ->busy flag and unlock before leaving
628 */
629 spin_lock_irq(&ide_lock);
630 hwif->hwgroup->busy = 0;
631 spin_unlock_irq(&ide_lock);
632out:
633 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634#else
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200635 if (arg < 0 || arg > 1)
636 return -EINVAL;
637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 return -EPERM;
639#endif
640}
641
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +0200642int set_pio_mode(ide_drive_t *drive, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
644 struct request rq;
645
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200646 if (arg < 0 || arg > 255)
647 return -EINVAL;
648
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200649 if (drive->hwif->set_pio_mode == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 return -ENOSYS;
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if (drive->special.b.set_tune)
653 return -EBUSY;
Bartlomiej Zolnierkiewicz145b75e2008-01-26 20:13:11 +0100654
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 ide_init_drive_cmd(&rq);
Bartlomiej Zolnierkiewicz852738f2008-01-26 20:13:12 +0100656 rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
Bartlomiej Zolnierkiewicz145b75e2008-01-26 20:13:11 +0100657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 drive->tune_req = (u8) arg;
659 drive->special.b.set_tune = 1;
660 (void) ide_do_drive_cmd(drive, &rq, ide_wait);
661 return 0;
662}
663
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200664static int set_unmaskirq(ide_drive_t *drive, int arg)
665{
666 if (drive->no_unmask)
667 return -EPERM;
668
669 if (arg < 0 || arg > 1)
670 return -EINVAL;
671
672 if (ide_spin_wait_hwgroup(drive))
673 return -EBUSY;
674 drive->unmask = arg;
675 spin_unlock_irq(&ide_lock);
676
677 return 0;
678}
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680/**
681 * system_bus_clock - clock guess
682 *
683 * External version of the bus clock guess used by very old IDE drivers
684 * for things like VLB timings. Should not be used.
685 */
686
687int system_bus_clock (void)
688{
Bartlomiej Zolnierkiewicz537f06c2008-02-01 23:09:35 +0100689 return system_bus_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690}
691
692EXPORT_SYMBOL(system_bus_clock);
693
David Brownellb887d2e2006-08-14 23:11:05 -0700694static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
696 ide_drive_t *drive = dev->driver_data;
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100697 ide_hwif_t *hwif = HWIF(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 struct request rq;
699 struct request_pm_state rqpm;
700 ide_task_t args;
Shaohua Li5e321322007-10-11 23:53:58 +0200701 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100703 /* Call ACPI _GTM only once */
704 if (!(drive->dn % 2))
705 ide_acpi_get_timing(hwif);
706
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 memset(&rq, 0, sizeof(rq));
708 memset(&rqpm, 0, sizeof(rqpm));
709 memset(&args, 0, sizeof(args));
Jens Axboe4aff5e22006-08-10 08:44:47 +0200710 rq.cmd_type = REQ_TYPE_PM_SUSPEND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 rq.special = &args;
Jens Axboec00895a2006-09-30 20:29:12 +0200712 rq.data = &rqpm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 rqpm.pm_step = ide_pm_state_start_suspend;
David Brownellb887d2e2006-08-14 23:11:05 -0700714 if (mesg.event == PM_EVENT_PRETHAW)
715 mesg.event = PM_EVENT_FREEZE;
716 rqpm.pm_state = mesg.event;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Shaohua Li5e321322007-10-11 23:53:58 +0200718 ret = ide_do_drive_cmd(drive, &rq, ide_wait);
719 /* only call ACPI _PS3 after both drivers are suspended */
720 if (!ret && (((drive->dn % 2) && hwif->drives[0].present
721 && hwif->drives[1].present)
722 || !hwif->drives[0].present
723 || !hwif->drives[1].present))
724 ide_acpi_set_state(hwif, 0);
725 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726}
727
728static int generic_ide_resume(struct device *dev)
729{
730 ide_drive_t *drive = dev->driver_data;
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100731 ide_hwif_t *hwif = HWIF(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 struct request rq;
733 struct request_pm_state rqpm;
734 ide_task_t args;
Lee Trager0d2157f2007-06-08 15:14:30 +0200735 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100737 /* Call ACPI _STM only once */
Shaohua Li5e321322007-10-11 23:53:58 +0200738 if (!(drive->dn % 2)) {
739 ide_acpi_set_state(hwif, 1);
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100740 ide_acpi_push_timing(hwif);
Shaohua Li5e321322007-10-11 23:53:58 +0200741 }
Hannes Reineckee3a59b42007-02-07 18:19:37 +0100742
743 ide_acpi_exec_tfs(drive);
744
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 memset(&rq, 0, sizeof(rq));
746 memset(&rqpm, 0, sizeof(rqpm));
747 memset(&args, 0, sizeof(args));
Jens Axboe4aff5e22006-08-10 08:44:47 +0200748 rq.cmd_type = REQ_TYPE_PM_RESUME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 rq.special = &args;
Jens Axboec00895a2006-09-30 20:29:12 +0200750 rq.data = &rqpm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 rqpm.pm_step = ide_pm_state_start_resume;
Pavel Machekca078ba2005-09-03 15:56:57 -0700752 rqpm.pm_state = PM_EVENT_ON;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Lee Trager0d2157f2007-06-08 15:14:30 +0200754 err = ide_do_drive_cmd(drive, &rq, ide_head_wait);
755
Rafael J. Wysockice9b2b02007-06-16 02:24:43 +0200756 if (err == 0 && dev->driver) {
757 ide_driver_t *drv = to_ide_driver(dev->driver);
758
759 if (drv->resume)
760 drv->resume(drive);
761 }
Lee Trager0d2157f2007-06-08 15:14:30 +0200762
763 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764}
765
766int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
767 unsigned int cmd, unsigned long arg)
768{
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200769 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 ide_driver_t *drv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 void __user *p = (void __user *)arg;
Linus Torvalds19850262007-07-17 15:57:42 -0700772 int err = 0, (*setfunc)(ide_drive_t *, int);
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200773 u8 *val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200775 switch (cmd) {
776 case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val;
777 case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
778 case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val;
779 case HDIO_GET_DMA: val = &drive->using_dma; goto read_val;
780 case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val;
781 case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val;
782 case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val;
783 case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val;
784 case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 case HDIO_OBSOLETE_IDENTITY:
789 case HDIO_GET_IDENTITY:
790 if (bdev != bdev->bd_contains)
791 return -EINVAL;
792 if (drive->id_read == 0)
793 return -ENOMSG;
794 if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
795 return -EFAULT;
796 return 0;
797
798 case HDIO_GET_NICE:
799 return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
800 drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
Bartlomiej Zolnierkiewicz92b83c82008-02-02 19:56:45 +0100801 drive->nice1 << IDE_NICE_1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 (long __user *) arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803#ifdef CONFIG_IDE_TASK_IOCTL
804 case HDIO_DRIVE_TASKFILE:
805 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
806 return -EACCES;
807 switch(drive->media) {
808 case ide_disk:
809 return ide_taskfile_ioctl(drive, cmd, arg);
810 default:
811 return -ENOMSG;
812 }
813#endif /* CONFIG_IDE_TASK_IOCTL */
814
815 case HDIO_DRIVE_CMD:
816 if (!capable(CAP_SYS_RAWIO))
817 return -EACCES;
818 return ide_cmd_ioctl(drive, cmd, arg);
819
820 case HDIO_DRIVE_TASK:
821 if (!capable(CAP_SYS_RAWIO))
822 return -EACCES;
823 return ide_task_ioctl(drive, cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 case HDIO_SET_NICE:
825 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
826 if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
827 return -EPERM;
828 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
829 drv = *(ide_driver_t **)bdev->bd_disk->private_data;
830 if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
831 drive->dsc_overlap = 0;
832 return -EPERM;
833 }
834 drive->nice1 = (arg >> IDE_NICE_1) & 1;
835 return 0;
836 case HDIO_DRIVE_RESET:
Bartlomiej Zolnierkiewiczdbecebc2008-02-26 21:50:35 +0100837 if (!capable(CAP_SYS_ADMIN))
838 return -EACCES;
839
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 /*
841 * Abort the current command on the
842 * group if there is one, taking
843 * care not to allow anything else
844 * to be queued and to die on the
845 * spot if we miss one somehow
846 */
847
848 spin_lock_irqsave(&ide_lock, flags);
849
Alan Cox913759a2006-10-03 01:14:33 -0700850 if (HWGROUP(drive)->resetting) {
851 spin_unlock_irqrestore(&ide_lock, flags);
852 return -EBUSY;
853 }
854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 ide_abort(drive, "drive reset");
856
Eric Sesterhenn125e1872006-06-23 02:06:06 -0700857 BUG_ON(HWGROUP(drive)->handler);
Bartlomiej Zolnierkiewiczdbecebc2008-02-26 21:50:35 +0100858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 /* Ensure nothing gets queued after we
860 drop the lock. Reset will clear the busy */
Bartlomiej Zolnierkiewiczdbecebc2008-02-26 21:50:35 +0100861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 HWGROUP(drive)->busy = 1;
863 spin_unlock_irqrestore(&ide_lock, flags);
864 (void) ide_do_reset(drive);
865
866 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 case HDIO_GET_BUSSTATE:
868 if (!capable(CAP_SYS_ADMIN))
869 return -EACCES;
870 if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
871 return -EFAULT;
872 return 0;
873
874 case HDIO_SET_BUSSTATE:
875 if (!capable(CAP_SYS_ADMIN))
876 return -EACCES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 return -EOPNOTSUPP;
878 default:
879 return -EINVAL;
880 }
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200881
882read_val:
Matthias Kaehlckef9383c42007-07-09 23:17:56 +0200883 mutex_lock(&ide_setting_mtx);
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200884 spin_lock_irqsave(&ide_lock, flags);
885 err = *val;
886 spin_unlock_irqrestore(&ide_lock, flags);
Matthias Kaehlckef9383c42007-07-09 23:17:56 +0200887 mutex_unlock(&ide_setting_mtx);
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200888 return err >= 0 ? put_user(err, (long __user *)arg) : err;
889
890set_val:
891 if (bdev != bdev->bd_contains)
892 err = -EINVAL;
893 else {
894 if (!capable(CAP_SYS_ADMIN))
895 err = -EACCES;
896 else {
Matthias Kaehlckef9383c42007-07-09 23:17:56 +0200897 mutex_lock(&ide_setting_mtx);
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200898 err = setfunc(drive, arg);
Matthias Kaehlckef9383c42007-07-09 23:17:56 +0200899 mutex_unlock(&ide_setting_mtx);
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +0200900 }
901 }
902 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903}
904
905EXPORT_SYMBOL(generic_ide_ioctl);
906
907/*
908 * stridx() returns the offset of c within s,
909 * or -1 if c is '\0' or not found within s.
910 */
911static int __init stridx (const char *s, char c)
912{
913 char *i = strchr(s, c);
914 return (i && c) ? i - s : -1;
915}
916
917/*
918 * match_parm() does parsing for ide_setup():
919 *
920 * 1. the first char of s must be '='.
921 * 2. if the remainder matches one of the supplied keywords,
922 * the index (1 based) of the keyword is negated and returned.
923 * 3. if the remainder is a series of no more than max_vals numbers
924 * separated by commas, the numbers are saved in vals[] and a
925 * count of how many were saved is returned. Base10 is assumed,
926 * and base16 is allowed when prefixed with "0x".
927 * 4. otherwise, zero is returned.
928 */
929static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
930{
931 static const char *decimal = "0123456789";
932 static const char *hex = "0123456789abcdef";
933 int i, n;
934
935 if (*s++ == '=') {
936 /*
937 * Try matching against the supplied keywords,
938 * and return -(index+1) if we match one
939 */
940 if (keywords != NULL) {
941 for (i = 0; *keywords != NULL; ++i) {
942 if (!strcmp(s, *keywords++))
943 return -(i+1);
944 }
945 }
946 /*
947 * Look for a series of no more than "max_vals"
948 * numeric values separated by commas, in base10,
949 * or base16 when prefixed with "0x".
950 * Return a count of how many were found.
951 */
952 for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
953 vals[n] = i;
954 while ((i = stridx(decimal, *++s)) >= 0)
955 vals[n] = (vals[n] * 10) + i;
956 if (*s == 'x' && !vals[n]) {
957 while ((i = stridx(hex, *++s)) >= 0)
958 vals[n] = (vals[n] * 0x10) + i;
959 }
960 if (++n == max_vals)
961 break;
962 if (*s == ',' || *s == ';')
963 ++s;
964 }
965 if (!*s)
966 return n;
967 }
968 return 0; /* zero = nothing matched */
969}
970
Bartlomiej Zolnierkiewicz84913882007-03-03 17:48:55 +0100971extern int probe_ali14xx;
Bartlomiej Zolnierkiewicz84913882007-03-03 17:48:55 +0100972extern int probe_umc8672;
Bartlomiej Zolnierkiewicz84913882007-03-03 17:48:55 +0100973extern int probe_dtc2278;
Bartlomiej Zolnierkiewicz84913882007-03-03 17:48:55 +0100974extern int probe_ht6560b;
Bartlomiej Zolnierkiewicz84913882007-03-03 17:48:55 +0100975extern int probe_qd65xx;
Bartlomiej Zolnierkiewiczade2daf2008-01-26 20:13:07 +0100976extern int cmd640_vlb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Bartlomiej Zolnierkiewicz9a0e77f2008-04-18 00:46:24 +0200978static int __initdata is_chipset_set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980/*
981 * ide_setup() gets called VERY EARLY during initialization,
982 * to handle kernel "command line" strings beginning with "hdx=" or "ide".
983 *
Randy Dunlap1c10e932008-03-07 21:53:50 +0100984 * Remember to update Documentation/ide/ide.txt if you change something here.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 */
986static int __init ide_setup(char *s)
987{
988 int i, vals[3];
989 ide_hwif_t *hwif;
990 ide_drive_t *drive;
991 unsigned int hw, unit;
992 const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
993 const char max_hwif = '0' + (MAX_HWIFS - 1);
994
995
996 if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
997 return 0; /* driver and not us */
998
999 if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
1000 return 0;
1001
1002 printk(KERN_INFO "ide_setup: %s", s);
1003 init_ide_data ();
1004
1005#ifdef CONFIG_BLK_DEV_IDEDOUBLER
1006 if (!strcmp(s, "ide=doubler")) {
1007 extern int ide_doubler;
1008
1009 printk(" : Enabled support for IDE doublers\n");
1010 ide_doubler = 1;
1011 return 1;
1012 }
1013#endif /* CONFIG_BLK_DEV_IDEDOUBLER */
1014
1015 if (!strcmp(s, "ide=nodma")) {
1016 printk(" : Prevented DMA\n");
1017 noautodma = 1;
Bartlomiej Zolnierkiewiczc2237012007-10-16 22:29:58 +02001018 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 }
1020
Hannes Reineckee3a59b42007-02-07 18:19:37 +01001021#ifdef CONFIG_BLK_DEV_IDEACPI
1022 if (!strcmp(s, "ide=noacpi")) {
1023 //printk(" : Disable IDE ACPI support.\n");
1024 ide_noacpi = 1;
1025 return 1;
1026 }
1027 if (!strcmp(s, "ide=acpigtf")) {
1028 //printk(" : Enable IDE ACPI _GTF support.\n");
1029 ide_noacpitfs = 0;
1030 return 1;
1031 }
1032 if (!strcmp(s, "ide=acpionboot")) {
1033 //printk(" : Call IDE ACPI methods on boot.\n");
1034 ide_noacpionboot = 0;
1035 return 1;
1036 }
1037#endif /* CONFIG_BLK_DEV_IDEACPI */
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 /*
1040 * Look for drive options: "hdx="
1041 */
1042 if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
1043 const char *hd_words[] = {
Bartlomiej Zolnierkiewiczc2237012007-10-16 22:29:58 +02001044 "none", "noprobe", "nowerr", "cdrom", "nodma",
Bartlomiej Zolnierkiewicz9e47be02008-01-26 20:13:09 +01001045 "autotune", "noautotune", "-8", "-9", "-10",
Jens Axboe36193482006-07-28 08:54:59 +02001046 "noflush", "remap", "remap63", "scsi", NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 unit = s[2] - 'a';
1048 hw = unit / MAX_DRIVES;
1049 unit = unit % MAX_DRIVES;
1050 hwif = &ide_hwifs[hw];
1051 drive = &hwif->drives[unit];
1052 if (strncmp(s + 4, "ide-", 4) == 0) {
1053 strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
Bartlomiej Zolnierkiewicz15220d92008-03-22 16:40:21 +01001054 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 }
1056 switch (match_parm(&s[3], hd_words, vals, 3)) {
1057 case -1: /* "none" */
1058 case -2: /* "noprobe" */
1059 drive->noprobe = 1;
1060 goto done;
1061 case -3: /* "nowerr" */
1062 drive->bad_wstat = BAD_R_STAT;
1063 hwif->noprobe = 0;
1064 goto done;
1065 case -4: /* "cdrom" */
1066 drive->present = 1;
1067 drive->media = ide_cdrom;
1068 /* an ATAPI device ignores DRDY */
1069 drive->ready_stat = 0;
1070 hwif->noprobe = 0;
1071 goto done;
Bartlomiej Zolnierkiewiczc2237012007-10-16 22:29:58 +02001072 case -5: /* nodma */
1073 drive->nodma = 1;
1074 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 case -6: /* "autotune" */
1076 drive->autotune = IDE_TUNE_AUTO;
1077 goto obsolete_option;
1078 case -7: /* "noautotune" */
1079 drive->autotune = IDE_TUNE_NOAUTO;
1080 goto obsolete_option;
Jens Axboe36193482006-07-28 08:54:59 +02001081 case -11: /* noflush */
1082 drive->noflush = 1;
1083 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 case -12: /* "remap" */
1085 drive->remap_0_to_1 = 1;
Bartlomiej Zolnierkiewiczd708c402008-03-22 16:40:22 +01001086 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 case -13: /* "remap63" */
1088 drive->sect0 = 63;
Bartlomiej Zolnierkiewiczd708c402008-03-22 16:40:22 +01001089 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 case -14: /* "scsi" */
1091 drive->scsi = 1;
Bartlomiej Zolnierkiewicz15220d92008-03-22 16:40:21 +01001092 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 case 3: /* cyl,head,sect */
1094 drive->media = ide_disk;
1095 drive->ready_stat = READY_STAT;
1096 drive->cyl = drive->bios_cyl = vals[0];
1097 drive->head = drive->bios_head = vals[1];
1098 drive->sect = drive->bios_sect = vals[2];
1099 drive->present = 1;
1100 drive->forced_geom = 1;
1101 hwif->noprobe = 0;
1102 goto done;
1103 default:
1104 goto bad_option;
1105 }
1106 }
1107
1108 if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
1109 goto bad_option;
1110 /*
1111 * Look for bus speed option: "idebus="
1112 */
1113 if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
1114 if (match_parm(&s[6], NULL, vals, 1) != 1)
1115 goto bad_option;
1116 if (vals[0] >= 20 && vals[0] <= 66) {
1117 idebus_parameter = vals[0];
1118 } else
1119 printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
1120 goto done;
1121 }
1122 /*
1123 * Look for interface options: "idex="
1124 */
1125 if (s[3] >= '0' && s[3] <= max_hwif) {
1126 /*
1127 * Be VERY CAREFUL changing this: note hardcoded indexes below
1128 * (-8, -9, -10) are reserved to ease the hardcoding.
1129 */
1130 static const char *ide_words[] = {
Bartlomiej Zolnierkiewiczb6209a92007-03-03 17:48:55 +01001131 "noprobe", "serialize", "minus3", "minus4",
Bartlomiej Zolnierkiewicz1b516942007-10-16 22:29:57 +02001132 "reset", "minus6", "ata66", "minus8", "minus9",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
1134 "dtc2278", "umc8672", "ali14xx", NULL };
Bartlomiej Zolnierkiewicz9239b332007-10-20 00:32:33 +02001135
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 hw = s[3] - '0';
1137 hwif = &ide_hwifs[hw];
1138 i = match_parm(&s[4], ide_words, vals, 3);
1139
1140 /*
1141 * Cryptic check to ensure chipset not already set for hwif.
1142 * Note: we can't depend on hwif->chipset here.
1143 */
Bartlomiej Zolnierkiewicz9a0e77f2008-04-18 00:46:24 +02001144 if (i >= -18 && i <= -11) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 /* chipset already specified */
Bartlomiej Zolnierkiewicz9a0e77f2008-04-18 00:46:24 +02001146 if (is_chipset_set)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 goto bad_option;
Bartlomiej Zolnierkiewicz9a0e77f2008-04-18 00:46:24 +02001148 /* these drivers are for "ide0=" only */
1149 if (hw != 0)
1150 goto bad_hwif;
1151 is_chipset_set = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 printk("\n");
1153 }
1154
1155 switch (i) {
1156#ifdef CONFIG_BLK_DEV_ALI14XX
1157 case -17: /* "ali14xx" */
1158 probe_ali14xx = 1;
Bartlomiej Zolnierkiewicz9c027c62008-03-22 16:40:21 +01001159 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160#endif
1161#ifdef CONFIG_BLK_DEV_UMC8672
1162 case -16: /* "umc8672" */
1163 probe_umc8672 = 1;
Bartlomiej Zolnierkiewicz9c027c62008-03-22 16:40:21 +01001164 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165#endif
1166#ifdef CONFIG_BLK_DEV_DTC2278
1167 case -15: /* "dtc2278" */
1168 probe_dtc2278 = 1;
Bartlomiej Zolnierkiewicz9c027c62008-03-22 16:40:21 +01001169 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170#endif
1171#ifdef CONFIG_BLK_DEV_CMD640
1172 case -14: /* "cmd640_vlb" */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 cmd640_vlb = 1;
Bartlomiej Zolnierkiewicz9c027c62008-03-22 16:40:21 +01001174 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175#endif
1176#ifdef CONFIG_BLK_DEV_HT6560B
1177 case -13: /* "ht6560b" */
1178 probe_ht6560b = 1;
Bartlomiej Zolnierkiewicz9c027c62008-03-22 16:40:21 +01001179 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180#endif
1181#ifdef CONFIG_BLK_DEV_QD65XX
1182 case -12: /* "qd65xx" */
1183 probe_qd65xx = 1;
Bartlomiej Zolnierkiewicz9c027c62008-03-22 16:40:21 +01001184 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185#endif
1186#ifdef CONFIG_BLK_DEV_4DRIVES
1187 case -11: /* "four" drives on one set of ports */
1188 {
1189 ide_hwif_t *mate = &ide_hwifs[hw^1];
1190 mate->drives[0].select.all ^= 0x20;
1191 mate->drives[1].select.all ^= 0x20;
1192 hwif->chipset = mate->chipset = ide_4drives;
1193 mate->irq = hwif->irq;
1194 memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
Bartlomiej Zolnierkiewiczb6209a92007-03-03 17:48:55 +01001195 hwif->mate = mate;
1196 mate->mate = hwif;
1197 hwif->serialized = mate->serialized = 1;
1198 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 }
1200#endif /* CONFIG_BLK_DEV_4DRIVES */
1201 case -10: /* minus10 */
1202 case -9: /* minus9 */
1203 case -8: /* minus8 */
Bartlomiej Zolnierkiewicz1b516942007-10-16 22:29:57 +02001204 case -6:
Bartlomiej Zolnierkiewiczb6209a92007-03-03 17:48:55 +01001205 case -4:
1206 case -3:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 goto bad_option;
1208 case -7: /* ata66 */
1209#ifdef CONFIG_BLK_DEV_IDEPCI
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +02001210 /*
1211 * Use ATA_CBL_PATA40_SHORT so drive side
1212 * cable detection is also overriden.
1213 */
1214 hwif->cbl = ATA_CBL_PATA40_SHORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 goto obsolete_option;
1216#else
1217 goto bad_hwif;
1218#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 case -5: /* "reset" */
1220 hwif->reset = 1;
1221 goto obsolete_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 case -2: /* "serialize" */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 hwif->mate = &ide_hwifs[hw^1];
1224 hwif->mate->mate = hwif;
1225 hwif->serialized = hwif->mate->serialized = 1;
1226 goto obsolete_option;
1227
1228 case -1: /* "noprobe" */
1229 hwif->noprobe = 1;
Bartlomiej Zolnierkiewiczc53ea182008-02-26 21:50:34 +01001230 goto obsolete_option;
Bartlomiej Zolnierkiewicz9a0e77f2008-04-18 00:46:24 +02001231 case 0:
1232 case 1:
1233 case 2:
1234 case 3:
1235 goto bad_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 default:
1237 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
1238 return 1;
1239 }
1240 }
1241bad_option:
1242 printk(" -- BAD OPTION\n");
1243 return 1;
1244obsolete_option:
1245 printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
1246 return 1;
1247bad_hwif:
1248 printk("-- NOT SUPPORTED ON ide%d", hw);
1249done:
1250 printk("\n");
1251 return 1;
1252}
1253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254EXPORT_SYMBOL(ide_lock);
1255
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001256static int ide_bus_match(struct device *dev, struct device_driver *drv)
1257{
1258 return 1;
1259}
1260
Kay Sievers263756e2005-12-12 18:03:44 +01001261static char *media_string(ide_drive_t *drive)
1262{
1263 switch (drive->media) {
1264 case ide_disk:
1265 return "disk";
1266 case ide_cdrom:
1267 return "cdrom";
1268 case ide_tape:
1269 return "tape";
1270 case ide_floppy:
1271 return "floppy";
Danny Kukawkaa7a832d2007-04-10 22:39:14 +02001272 case ide_optical:
1273 return "optical";
Kay Sievers263756e2005-12-12 18:03:44 +01001274 default:
1275 return "UNKNOWN";
1276 }
1277}
1278
1279static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
1280{
1281 ide_drive_t *drive = to_ide_device(dev);
1282 return sprintf(buf, "%s\n", media_string(drive));
1283}
1284
1285static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
1286{
1287 ide_drive_t *drive = to_ide_device(dev);
1288 return sprintf(buf, "%s\n", drive->name);
1289}
1290
1291static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
1292{
1293 ide_drive_t *drive = to_ide_device(dev);
1294 return sprintf(buf, "ide:m-%s\n", media_string(drive));
1295}
1296
Bartlomiej Zolnierkiewicze11b9032007-12-12 23:31:58 +01001297static ssize_t model_show(struct device *dev, struct device_attribute *attr,
1298 char *buf)
1299{
1300 ide_drive_t *drive = to_ide_device(dev);
1301 return sprintf(buf, "%s\n", drive->id->model);
1302}
1303
1304static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
1305 char *buf)
1306{
1307 ide_drive_t *drive = to_ide_device(dev);
1308 return sprintf(buf, "%s\n", drive->id->fw_rev);
1309}
1310
1311static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
1312 char *buf)
1313{
1314 ide_drive_t *drive = to_ide_device(dev);
1315 return sprintf(buf, "%s\n", drive->id->serial_no);
1316}
1317
Kay Sievers263756e2005-12-12 18:03:44 +01001318static struct device_attribute ide_dev_attrs[] = {
1319 __ATTR_RO(media),
1320 __ATTR_RO(drivename),
1321 __ATTR_RO(modalias),
Bartlomiej Zolnierkiewicze11b9032007-12-12 23:31:58 +01001322 __ATTR_RO(model),
1323 __ATTR_RO(firmware),
1324 __ATTR(serial, 0400, serial_show, NULL),
Kay Sievers263756e2005-12-12 18:03:44 +01001325 __ATTR_NULL
1326};
1327
Kay Sievers7eff2e72007-08-14 15:15:12 +02001328static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
Kay Sievers263756e2005-12-12 18:03:44 +01001329{
1330 ide_drive_t *drive = to_ide_device(dev);
Kay Sievers263756e2005-12-12 18:03:44 +01001331
Kay Sievers7eff2e72007-08-14 15:15:12 +02001332 add_uevent_var(env, "MEDIA=%s", media_string(drive));
1333 add_uevent_var(env, "DRIVENAME=%s", drive->name);
1334 add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive));
Kay Sievers263756e2005-12-12 18:03:44 +01001335 return 0;
1336}
1337
Russell King4031bbe2006-01-06 11:41:00 +00001338static int generic_ide_probe(struct device *dev)
1339{
1340 ide_drive_t *drive = to_ide_device(dev);
1341 ide_driver_t *drv = to_ide_driver(dev->driver);
1342
1343 return drv->probe ? drv->probe(drive) : -ENODEV;
1344}
1345
1346static int generic_ide_remove(struct device *dev)
1347{
1348 ide_drive_t *drive = to_ide_device(dev);
1349 ide_driver_t *drv = to_ide_driver(dev->driver);
1350
1351 if (drv->remove)
1352 drv->remove(drive);
1353
1354 return 0;
1355}
1356
1357static void generic_ide_shutdown(struct device *dev)
1358{
1359 ide_drive_t *drive = to_ide_device(dev);
1360 ide_driver_t *drv = to_ide_driver(dev->driver);
1361
1362 if (dev->driver && drv->shutdown)
1363 drv->shutdown(drive);
1364}
1365
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366struct bus_type ide_bus_type = {
1367 .name = "ide",
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001368 .match = ide_bus_match,
Kay Sievers263756e2005-12-12 18:03:44 +01001369 .uevent = ide_uevent,
Russell King4031bbe2006-01-06 11:41:00 +00001370 .probe = generic_ide_probe,
1371 .remove = generic_ide_remove,
1372 .shutdown = generic_ide_shutdown,
Kay Sievers263756e2005-12-12 18:03:44 +01001373 .dev_attrs = ide_dev_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 .suspend = generic_ide_suspend,
1375 .resume = generic_ide_resume,
1376};
1377
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001378EXPORT_SYMBOL_GPL(ide_bus_type);
1379
Bartlomiej Zolnierkiewiczf74c9142008-04-18 00:46:23 +02001380static void ide_port_class_release(struct device *portdev)
1381{
1382 ide_hwif_t *hwif = dev_get_drvdata(portdev);
1383
1384 put_device(&hwif->gendev);
1385}
1386
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387/*
1388 * This is gets invoked once during initialization, to set *everything* up
1389 */
1390static int __init ide_init(void)
1391{
Randy Dunlap349ae232006-10-03 01:14:23 -07001392 int ret;
1393
Bartlomiej Zolnierkiewiczeba8ff92008-02-11 00:32:13 +01001394 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 system_bus_speed = ide_system_bus_speed();
1396
Bartlomiej Zolnierkiewicz537f06c2008-02-01 23:09:35 +01001397 printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
1398 "for PIO modes%s\n", system_bus_speed,
1399 idebus_parameter ? "" : "; override with idebus=xx");
1400
Randy Dunlap349ae232006-10-03 01:14:23 -07001401 ret = bus_register(&ide_bus_type);
1402 if (ret < 0) {
1403 printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
1404 return ret;
1405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Bartlomiej Zolnierkiewiczf74c9142008-04-18 00:46:23 +02001407 ide_port_class = class_create(THIS_MODULE, "ide_port");
1408 if (IS_ERR(ide_port_class)) {
1409 ret = PTR_ERR(ide_port_class);
1410 goto out_port_class;
1411 }
1412 ide_port_class->dev_release = ide_port_class_release;
1413
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 init_ide_data();
1415
Bartlomiej Zolnierkiewicz5cbf79c2007-05-10 00:01:11 +02001416 proc_ide_create();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 return 0;
Bartlomiej Zolnierkiewiczf74c9142008-04-18 00:46:23 +02001419
1420out_port_class:
1421 bus_unregister(&ide_bus_type);
1422
1423 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424}
1425
1426#ifdef MODULE
1427static char *options = NULL;
1428module_param(options, charp, 0);
1429MODULE_LICENSE("GPL");
1430
1431static void __init parse_options (char *line)
1432{
1433 char *next = line;
1434
1435 if (line == NULL || !*line)
1436 return;
1437 while ((line = next) != NULL) {
1438 if ((next = strchr(line,' ')) != NULL)
1439 *next++ = 0;
1440 if (!ide_setup(line))
1441 printk (KERN_INFO "Unknown option '%s'\n", line);
1442 }
1443}
1444
Sam Ravnborgfbd8ad32006-03-25 03:07:11 -08001445int __init init_module (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446{
1447 parse_options(options);
1448 return ide_init();
1449}
1450
Al Viroeb797222007-02-01 13:52:38 +00001451void __exit cleanup_module (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452{
1453 int index;
1454
1455 for (index = 0; index < MAX_HWIFS; ++index)
Bartlomiej Zolnierkiewicz93de00f2008-04-18 00:46:24 +02001456 ide_unregister(index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 proc_ide_destroy();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Bartlomiej Zolnierkiewiczf74c9142008-04-18 00:46:23 +02001460 class_destroy(ide_port_class);
1461
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 bus_unregister(&ide_bus_type);
1463}
1464
1465#else /* !MODULE */
1466
1467__setup("", ide_setup);
1468
1469module_init(ide_init);
1470
1471#endif /* MODULE */