Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
59bca8cc BZ |
2 | * Copyright (C) 1994-1998 Linus Torvalds & authors (see below) |
3 | * Copyrifht (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz | |
1da177e4 LT |
4 | */ |
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 | * | |
1da177e4 LT |
18 | * ... |
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 | |
1da177e4 LT |
45 | */ |
46 | ||
1da177e4 LT |
47 | #define _IDE_C /* Tell ide.h it's really us */ |
48 | ||
1da177e4 LT |
49 | #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> | |
1da177e4 LT |
65 | #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 | ||
f74c9141 BZ |
81 | struct class *ide_port_class; |
82 | ||
1da177e4 LT |
83 | static 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 | ||
89 | static int idebus_parameter; /* holds the "idebus=" parameter */ | |
90 | static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */ | |
1da177e4 | 91 | |
ef29888e | 92 | DEFINE_MUTEX(ide_cfg_mtx); |
1da177e4 LT |
93 | __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock); |
94 | ||
1da177e4 | 95 | int noautodma = 0; |
1da177e4 | 96 | |
e3a59b4d HR |
97 | #ifdef CONFIG_BLK_DEV_IDEACPI |
98 | int ide_noacpi = 0; | |
99 | int ide_noacpitfs = 1; | |
100 | int ide_noacpionboot = 1; | |
101 | #endif | |
102 | ||
1da177e4 LT |
103 | /* |
104 | * This is declared extern in ide.h, for access by other IDE modules: | |
105 | */ | |
106 | ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */ | |
107 | ||
108 | EXPORT_SYMBOL(ide_hwifs); | |
109 | ||
43514ed1 BZ |
110 | static void ide_port_init_devices_data(ide_hwif_t *); |
111 | ||
1da177e4 LT |
112 | /* |
113 | * Do not even *think* about calling this! | |
114 | */ | |
cbb010c1 | 115 | void ide_init_port_data(ide_hwif_t *hwif, unsigned int index) |
1da177e4 | 116 | { |
1da177e4 LT |
117 | /* 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 | ||
f36d4024 | 131 | init_completion(&hwif->gendev_rel_comp); |
1da177e4 LT |
132 | |
133 | default_hwif_iops(hwif); | |
134 | default_hwif_transport(hwif); | |
43514ed1 BZ |
135 | |
136 | ide_port_init_devices_data(hwif); | |
137 | } | |
138 | EXPORT_SYMBOL_GPL(ide_init_port_data); | |
139 | ||
140 | static void ide_port_init_devices_data(ide_hwif_t *hwif) | |
141 | { | |
142 | int unit; | |
143 | ||
1da177e4 LT |
144 | for (unit = 0; unit < MAX_DRIVES; ++unit) { |
145 | ide_drive_t *drive = &hwif->drives[unit]; | |
43514ed1 BZ |
146 | u8 j = (hwif->index * MAX_DRIVES) + unit; |
147 | ||
148 | memset(drive, 0, sizeof(*drive)); | |
1da177e4 LT |
149 | |
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'; | |
43514ed1 | 160 | drive->name[2] = 'a' + j; |
1da177e4 | 161 | drive->max_failures = IDE_DEFAULT_MAX_FAILURES; |
43514ed1 | 162 | |
1da177e4 | 163 | INIT_LIST_HEAD(&drive->list); |
f36d4024 | 164 | init_completion(&drive->gendev_rel_comp); |
1da177e4 LT |
165 | } |
166 | } | |
43514ed1 | 167 | |
1da177e4 LT |
168 | /* |
169 | * init_ide_data() sets reasonable default values into all fields | |
170 | * of all instances of the hwifs and drives, but only on the first call. | |
171 | * Subsequent calls have no effect (they don't wipe out anything). | |
172 | * | |
173 | * This routine is normally called at driver initialization time, | |
174 | * but may also be called MUCH earlier during kernel "command-line" | |
175 | * parameter processing. As such, we cannot depend on any other parts | |
176 | * of the kernel (such as memory allocation) to be functioning yet. | |
177 | * | |
178 | * This is too bad, as otherwise we could dynamically allocate the | |
179 | * ide_drive_t structs as needed, rather than always consuming memory | |
180 | * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them. | |
181 | * | |
182 | * FIXME: We should stuff the setup data into __init and copy the | |
183 | * relevant hwifs/allocate them properly during boot. | |
184 | */ | |
185 | #define MAGIC_COOKIE 0x12345678 | |
186 | static void __init init_ide_data (void) | |
187 | { | |
1da177e4 LT |
188 | unsigned int index; |
189 | static unsigned long magic_cookie = MAGIC_COOKIE; | |
190 | ||
191 | if (magic_cookie != MAGIC_COOKIE) | |
192 | return; /* already initialized */ | |
193 | magic_cookie = 0; | |
194 | ||
195 | /* Initialise all interface structures */ | |
196 | for (index = 0; index < MAX_HWIFS; ++index) { | |
05734266 BZ |
197 | ide_hwif_t *hwif = &ide_hwifs[index]; |
198 | ||
cbb010c1 | 199 | ide_init_port_data(hwif, index); |
1da177e4 | 200 | } |
1da177e4 LT |
201 | } |
202 | ||
203 | /** | |
204 | * ide_system_bus_speed - guess bus speed | |
205 | * | |
206 | * ide_system_bus_speed() returns what we think is the system VESA/PCI | |
207 | * bus speed (in MHz). This is used for calculating interface PIO timings. | |
208 | * The default is 40 for known PCI systems, 50 otherwise. | |
209 | * The "idebus=xx" parameter can be used to override this value. | |
210 | * The actual value to be used is computed/displayed the first time | |
211 | * through. Drivers should only use this as a last resort. | |
212 | * | |
213 | * Returns a guessed speed in MHz. | |
214 | */ | |
215 | ||
216 | static int ide_system_bus_speed(void) | |
217 | { | |
218 | #ifdef CONFIG_PCI | |
219 | static struct pci_device_id pci_default[] = { | |
220 | { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) }, | |
221 | { } | |
222 | }; | |
223 | #else | |
224 | #define pci_default 0 | |
225 | #endif /* CONFIG_PCI */ | |
226 | ||
537f06c5 BZ |
227 | /* user supplied value */ |
228 | if (idebus_parameter) | |
229 | return idebus_parameter; | |
230 | ||
231 | /* safe default value for PCI or VESA and PCI*/ | |
232 | return pci_dev_present(pci_default) ? 33 : 50; | |
1da177e4 LT |
233 | } |
234 | ||
baa8f3e9 BZ |
235 | ide_hwif_t * ide_find_port(unsigned long base) |
236 | { | |
237 | ide_hwif_t *hwif; | |
238 | int i; | |
239 | ||
240 | for (i = 0; i < MAX_HWIFS; i++) { | |
241 | hwif = &ide_hwifs[i]; | |
242 | if (hwif->io_ports[IDE_DATA_OFFSET] == base) | |
243 | goto found; | |
244 | } | |
245 | ||
246 | for (i = 0; i < MAX_HWIFS; i++) { | |
247 | hwif = &ide_hwifs[i]; | |
2625cd52 | 248 | if (hwif->chipset == ide_unknown) |
baa8f3e9 BZ |
249 | goto found; |
250 | } | |
251 | ||
252 | hwif = NULL; | |
253 | found: | |
254 | return hwif; | |
255 | } | |
256 | ||
257 | EXPORT_SYMBOL_GPL(ide_find_port); | |
258 | ||
1da177e4 LT |
259 | static struct resource* hwif_request_region(ide_hwif_t *hwif, |
260 | unsigned long addr, int num) | |
261 | { | |
262 | struct resource *res = request_region(addr, num, hwif->name); | |
263 | ||
264 | if (!res) | |
265 | printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n", | |
266 | hwif->name, addr, addr+num-1); | |
267 | return res; | |
268 | } | |
269 | ||
270 | /** | |
271 | * ide_hwif_request_regions - request resources for IDE | |
272 | * @hwif: interface to use | |
273 | * | |
274 | * Requests all the needed resources for an interface. | |
275 | * Right now core IDE code does this work which is deeply wrong. | |
276 | * MMIO leaves it to the controller driver, | |
277 | * PIO will migrate this way over time. | |
278 | */ | |
279 | ||
280 | int ide_hwif_request_regions(ide_hwif_t *hwif) | |
281 | { | |
282 | unsigned long addr; | |
283 | unsigned int i; | |
284 | ||
2ad1e558 | 285 | if (hwif->mmio) |
1da177e4 | 286 | return 0; |
1da177e4 LT |
287 | addr = hwif->io_ports[IDE_CONTROL_OFFSET]; |
288 | if (addr && !hwif_request_region(hwif, addr, 1)) | |
289 | goto control_region_busy; | |
290 | hwif->straight8 = 0; | |
291 | addr = hwif->io_ports[IDE_DATA_OFFSET]; | |
292 | if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) { | |
293 | if (!hwif_request_region(hwif, addr, 8)) | |
294 | goto data_region_busy; | |
295 | hwif->straight8 = 1; | |
296 | return 0; | |
297 | } | |
298 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) { | |
299 | addr = hwif->io_ports[i]; | |
300 | if (!hwif_request_region(hwif, addr, 1)) { | |
301 | while (--i) | |
302 | release_region(addr, 1); | |
303 | goto data_region_busy; | |
304 | } | |
305 | } | |
306 | return 0; | |
307 | ||
308 | data_region_busy: | |
309 | addr = hwif->io_ports[IDE_CONTROL_OFFSET]; | |
310 | if (addr) | |
311 | release_region(addr, 1); | |
312 | control_region_busy: | |
313 | /* If any errors are return, we drop the hwif interface. */ | |
314 | return -EBUSY; | |
315 | } | |
316 | ||
317 | /** | |
318 | * ide_hwif_release_regions - free IDE resources | |
319 | * | |
320 | * Note that we only release the standard ports, | |
321 | * and do not even try to handle any extra ports | |
322 | * allocated for weird IDE interface chipsets. | |
323 | * | |
324 | * Note also that we don't yet handle mmio resources here. More | |
325 | * importantly our caller should be doing this so we need to | |
326 | * restructure this as a helper function for drivers. | |
327 | */ | |
328 | ||
329 | void ide_hwif_release_regions(ide_hwif_t *hwif) | |
330 | { | |
331 | u32 i = 0; | |
332 | ||
2ad1e558 | 333 | if (hwif->mmio) |
1da177e4 LT |
334 | return; |
335 | if (hwif->io_ports[IDE_CONTROL_OFFSET]) | |
336 | release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1); | |
337 | if (hwif->straight8) { | |
338 | release_region(hwif->io_ports[IDE_DATA_OFFSET], 8); | |
339 | return; | |
340 | } | |
341 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) | |
342 | if (hwif->io_ports[i]) | |
343 | release_region(hwif->io_ports[i], 1); | |
344 | } | |
345 | ||
fbd13088 | 346 | void ide_remove_port_from_hwgroup(ide_hwif_t *hwif) |
96e5ad30 BZ |
347 | { |
348 | ide_hwgroup_t *hwgroup = hwif->hwgroup; | |
349 | ||
350 | spin_lock_irq(&ide_lock); | |
351 | /* | |
352 | * Remove us from the hwgroup, and free | |
353 | * the hwgroup if we were the only member | |
354 | */ | |
355 | if (hwif->next == hwif) { | |
356 | BUG_ON(hwgroup->hwif != hwif); | |
357 | kfree(hwgroup); | |
358 | } else { | |
359 | /* There is another interface in hwgroup. | |
360 | * Unlink us, and set hwgroup->drive and ->hwif to | |
361 | * something sane. | |
362 | */ | |
363 | ide_hwif_t *g = hwgroup->hwif; | |
364 | ||
365 | while (g->next != hwif) | |
366 | g = g->next; | |
367 | g->next = hwif->next; | |
368 | if (hwgroup->hwif == hwif) { | |
369 | /* Chose a random hwif for hwgroup->hwif. | |
370 | * It's guaranteed that there are no drives | |
371 | * left in the hwgroup. | |
372 | */ | |
373 | BUG_ON(hwgroup->drive != NULL); | |
374 | hwgroup->hwif = g; | |
375 | } | |
376 | BUG_ON(hwgroup->hwif == hwif); | |
377 | } | |
378 | spin_unlock_irq(&ide_lock); | |
379 | } | |
380 | ||
71bf9f6f | 381 | /* Called with ide_lock held. */ |
2dde7861 | 382 | static void __ide_port_unregister_devices(ide_hwif_t *hwif) |
71bf9f6f BZ |
383 | { |
384 | int i; | |
385 | ||
386 | for (i = 0; i < MAX_DRIVES; i++) { | |
387 | ide_drive_t *drive = &hwif->drives[i]; | |
388 | ||
389 | if (drive->present) { | |
390 | spin_unlock_irq(&ide_lock); | |
391 | device_unregister(&drive->gendev); | |
392 | wait_for_completion(&drive->gendev_rel_comp); | |
393 | spin_lock_irq(&ide_lock); | |
394 | } | |
395 | } | |
396 | } | |
397 | ||
2dde7861 BZ |
398 | void ide_port_unregister_devices(ide_hwif_t *hwif) |
399 | { | |
400 | mutex_lock(&ide_cfg_mtx); | |
401 | spin_lock_irq(&ide_lock); | |
402 | __ide_port_unregister_devices(hwif); | |
403 | hwif->present = 0; | |
404 | ide_port_init_devices_data(hwif); | |
405 | spin_unlock_irq(&ide_lock); | |
406 | mutex_unlock(&ide_cfg_mtx); | |
407 | } | |
408 | EXPORT_SYMBOL_GPL(ide_port_unregister_devices); | |
409 | ||
1da177e4 | 410 | /** |
020e322d | 411 | * ide_unregister - free an IDE interface |
1da177e4 LT |
412 | * @index: index of interface (will change soon to a pointer) |
413 | * | |
414 | * Perform the final unregister of an IDE interface. At the moment | |
415 | * we don't refcount interfaces so this will also get split up. | |
416 | * | |
417 | * Locking: | |
418 | * The caller must not hold the IDE locks | |
419 | * The drive present/vanishing is not yet properly locked | |
420 | * Take care with the callbacks. These have been split to avoid | |
421 | * deadlocking the IDE layer. The shutdown callback is called | |
422 | * before we take the lock and free resources. It is up to the | |
423 | * caller to be sure there is no pending I/O here, and that | |
020e322d SS |
424 | * the interface will not be reopened (present/vanishing locking |
425 | * isn't yet done BTW). After we commit to the final kill we | |
1da177e4 LT |
426 | * call the cleanup callback with the ide locks held. |
427 | * | |
428 | * Unregister restores the hwif structures to the default state. | |
429 | * This is raving bonkers. | |
430 | */ | |
431 | ||
93de00fd | 432 | void ide_unregister(unsigned int index) |
1da177e4 | 433 | { |
1da177e4 | 434 | ide_hwif_t *hwif, *g; |
1da177e4 | 435 | ide_hwgroup_t *hwgroup; |
71bf9f6f | 436 | int irq_count = 0; |
1da177e4 LT |
437 | |
438 | BUG_ON(index >= MAX_HWIFS); | |
439 | ||
440 | BUG_ON(in_interrupt()); | |
441 | BUG_ON(irqs_disabled()); | |
ef29888e | 442 | mutex_lock(&ide_cfg_mtx); |
1da177e4 LT |
443 | spin_lock_irq(&ide_lock); |
444 | hwif = &ide_hwifs[index]; | |
445 | if (!hwif->present) | |
446 | goto abort; | |
2dde7861 | 447 | __ide_port_unregister_devices(hwif); |
1da177e4 LT |
448 | hwif->present = 0; |
449 | ||
450 | spin_unlock_irq(&ide_lock); | |
451 | ||
5cbf79cd | 452 | ide_proc_unregister_port(hwif); |
1da177e4 LT |
453 | |
454 | hwgroup = hwif->hwgroup; | |
455 | /* | |
456 | * free the irq if we were the only hwif using it | |
457 | */ | |
458 | g = hwgroup->hwif; | |
459 | do { | |
460 | if (g->irq == hwif->irq) | |
461 | ++irq_count; | |
462 | g = g->next; | |
463 | } while (g != hwgroup->hwif); | |
464 | if (irq_count == 1) | |
465 | free_irq(hwif->irq, hwgroup); | |
466 | ||
96e5ad30 | 467 | ide_remove_port_from_hwgroup(hwif); |
1da177e4 | 468 | |
f74c9141 | 469 | device_unregister(hwif->portdev); |
1da177e4 | 470 | device_unregister(&hwif->gendev); |
f36d4024 | 471 | wait_for_completion(&hwif->gendev_rel_comp); |
1da177e4 LT |
472 | |
473 | /* | |
474 | * Remove us from the kernel's knowledge | |
475 | */ | |
476 | blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS); | |
477 | kfree(hwif->sg_table); | |
478 | unregister_blkdev(hwif->major, hwif->name); | |
479 | spin_lock_irq(&ide_lock); | |
480 | ||
93de00fd BZ |
481 | if (hwif->dma_base) |
482 | (void)ide_release_dma(hwif); | |
1da177e4 | 483 | |
7cba97f1 BZ |
484 | ide_hwif_release_regions(hwif); |
485 | ||
1da177e4 | 486 | /* restore hwif data to pristine status */ |
cbb010c1 | 487 | ide_init_port_data(hwif, index); |
1da177e4 | 488 | |
1da177e4 LT |
489 | abort: |
490 | spin_unlock_irq(&ide_lock); | |
ef29888e | 491 | mutex_unlock(&ide_cfg_mtx); |
1da177e4 LT |
492 | } |
493 | ||
494 | EXPORT_SYMBOL(ide_unregister); | |
495 | ||
57c802e8 BZ |
496 | void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw) |
497 | { | |
498 | memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports)); | |
499 | hwif->irq = hw->irq; | |
500 | hwif->noprobe = 0; | |
501 | hwif->chipset = hw->chipset; | |
502 | hwif->gendev.parent = hw->dev; | |
503 | hwif->ack_intr = hw->ack_intr; | |
504 | } | |
505 | EXPORT_SYMBOL_GPL(ide_init_port_hw); | |
506 | ||
1da177e4 LT |
507 | /* |
508 | * Locks for IDE setting functionality | |
509 | */ | |
510 | ||
f9383c42 | 511 | DEFINE_MUTEX(ide_setting_mtx); |
1da177e4 | 512 | |
f9383c42 | 513 | EXPORT_SYMBOL_GPL(ide_setting_mtx); |
1497943e | 514 | |
1da177e4 LT |
515 | /** |
516 | * ide_spin_wait_hwgroup - wait for group | |
517 | * @drive: drive in the group | |
518 | * | |
519 | * Wait for an IDE device group to go non busy and then return | |
520 | * holding the ide_lock which guards the hwgroup->busy status | |
521 | * and right to use it. | |
522 | */ | |
523 | ||
524 | int ide_spin_wait_hwgroup (ide_drive_t *drive) | |
525 | { | |
526 | ide_hwgroup_t *hwgroup = HWGROUP(drive); | |
527 | unsigned long timeout = jiffies + (3 * HZ); | |
528 | ||
529 | spin_lock_irq(&ide_lock); | |
530 | ||
531 | while (hwgroup->busy) { | |
532 | unsigned long lflags; | |
533 | spin_unlock_irq(&ide_lock); | |
534 | local_irq_set(lflags); | |
535 | if (time_after(jiffies, timeout)) { | |
536 | local_irq_restore(lflags); | |
537 | printk(KERN_ERR "%s: channel busy\n", drive->name); | |
538 | return -EBUSY; | |
539 | } | |
540 | local_irq_restore(lflags); | |
541 | spin_lock_irq(&ide_lock); | |
542 | } | |
543 | return 0; | |
544 | } | |
545 | ||
546 | EXPORT_SYMBOL(ide_spin_wait_hwgroup); | |
547 | ||
7662d046 | 548 | int set_io_32bit(ide_drive_t *drive, int arg) |
1da177e4 | 549 | { |
1497943e BZ |
550 | if (drive->no_io_32bit) |
551 | return -EPERM; | |
552 | ||
553 | if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1)) | |
554 | return -EINVAL; | |
555 | ||
644a9d76 BZ |
556 | if (ide_spin_wait_hwgroup(drive)) |
557 | return -EBUSY; | |
558 | ||
1da177e4 | 559 | drive->io_32bit = arg; |
644a9d76 BZ |
560 | |
561 | spin_unlock_irq(&ide_lock); | |
562 | ||
1da177e4 LT |
563 | return 0; |
564 | } | |
565 | ||
1497943e BZ |
566 | static int set_ksettings(ide_drive_t *drive, int arg) |
567 | { | |
568 | if (arg < 0 || arg > 1) | |
569 | return -EINVAL; | |
570 | ||
571 | if (ide_spin_wait_hwgroup(drive)) | |
572 | return -EBUSY; | |
573 | drive->keep_settings = arg; | |
574 | spin_unlock_irq(&ide_lock); | |
575 | ||
576 | return 0; | |
577 | } | |
578 | ||
7662d046 | 579 | int set_using_dma(ide_drive_t *drive, int arg) |
1da177e4 LT |
580 | { |
581 | #ifdef CONFIG_BLK_DEV_IDEDMA | |
87996204 BZ |
582 | ide_hwif_t *hwif = drive->hwif; |
583 | int err = -EPERM; | |
584 | ||
1497943e BZ |
585 | if (arg < 0 || arg > 1) |
586 | return -EINVAL; | |
587 | ||
1da177e4 | 588 | if (!drive->id || !(drive->id->capability & 1)) |
87996204 BZ |
589 | goto out; |
590 | ||
15ce926a | 591 | if (hwif->dma_host_set == NULL) |
87996204 BZ |
592 | goto out; |
593 | ||
594 | err = -EBUSY; | |
595 | if (ide_spin_wait_hwgroup(drive)) | |
596 | goto out; | |
597 | /* | |
598 | * set ->busy flag, unlock and let it ride | |
599 | */ | |
600 | hwif->hwgroup->busy = 1; | |
601 | spin_unlock_irq(&ide_lock); | |
602 | ||
603 | err = 0; | |
604 | ||
1da177e4 | 605 | if (arg) { |
23b1bd45 | 606 | if (ide_set_dma(drive)) |
87996204 | 607 | err = -EIO; |
7469aaf6 BZ |
608 | } else |
609 | ide_dma_off(drive); | |
87996204 BZ |
610 | |
611 | /* | |
612 | * lock, clear ->busy flag and unlock before leaving | |
613 | */ | |
614 | spin_lock_irq(&ide_lock); | |
615 | hwif->hwgroup->busy = 0; | |
616 | spin_unlock_irq(&ide_lock); | |
617 | out: | |
618 | return err; | |
1da177e4 | 619 | #else |
1497943e BZ |
620 | if (arg < 0 || arg > 1) |
621 | return -EINVAL; | |
622 | ||
1da177e4 LT |
623 | return -EPERM; |
624 | #endif | |
625 | } | |
626 | ||
7662d046 | 627 | int set_pio_mode(ide_drive_t *drive, int arg) |
1da177e4 LT |
628 | { |
629 | struct request rq; | |
630 | ||
1497943e BZ |
631 | if (arg < 0 || arg > 255) |
632 | return -EINVAL; | |
633 | ||
26bcb879 | 634 | if (drive->hwif->set_pio_mode == NULL) |
1da177e4 | 635 | return -ENOSYS; |
26bcb879 | 636 | |
1da177e4 LT |
637 | if (drive->special.b.set_tune) |
638 | return -EBUSY; | |
145b75e9 | 639 | |
1da177e4 | 640 | ide_init_drive_cmd(&rq); |
852738f3 | 641 | rq.cmd_type = REQ_TYPE_ATA_TASKFILE; |
145b75e9 | 642 | |
1da177e4 LT |
643 | drive->tune_req = (u8) arg; |
644 | drive->special.b.set_tune = 1; | |
645 | (void) ide_do_drive_cmd(drive, &rq, ide_wait); | |
646 | return 0; | |
647 | } | |
648 | ||
1497943e BZ |
649 | static int set_unmaskirq(ide_drive_t *drive, int arg) |
650 | { | |
651 | if (drive->no_unmask) | |
652 | return -EPERM; | |
653 | ||
654 | if (arg < 0 || arg > 1) | |
655 | return -EINVAL; | |
656 | ||
657 | if (ide_spin_wait_hwgroup(drive)) | |
658 | return -EBUSY; | |
659 | drive->unmask = arg; | |
660 | spin_unlock_irq(&ide_lock); | |
661 | ||
662 | return 0; | |
663 | } | |
664 | ||
1da177e4 LT |
665 | /** |
666 | * system_bus_clock - clock guess | |
667 | * | |
668 | * External version of the bus clock guess used by very old IDE drivers | |
669 | * for things like VLB timings. Should not be used. | |
670 | */ | |
671 | ||
672 | int system_bus_clock (void) | |
673 | { | |
537f06c5 | 674 | return system_bus_speed; |
1da177e4 LT |
675 | } |
676 | ||
677 | EXPORT_SYMBOL(system_bus_clock); | |
678 | ||
b887d2e6 | 679 | static int generic_ide_suspend(struct device *dev, pm_message_t mesg) |
1da177e4 LT |
680 | { |
681 | ide_drive_t *drive = dev->driver_data; | |
e3a59b4d | 682 | ide_hwif_t *hwif = HWIF(drive); |
1da177e4 LT |
683 | struct request rq; |
684 | struct request_pm_state rqpm; | |
685 | ide_task_t args; | |
5e32132b | 686 | int ret; |
1da177e4 | 687 | |
e3a59b4d HR |
688 | /* Call ACPI _GTM only once */ |
689 | if (!(drive->dn % 2)) | |
690 | ide_acpi_get_timing(hwif); | |
691 | ||
1da177e4 LT |
692 | memset(&rq, 0, sizeof(rq)); |
693 | memset(&rqpm, 0, sizeof(rqpm)); | |
694 | memset(&args, 0, sizeof(args)); | |
4aff5e23 | 695 | rq.cmd_type = REQ_TYPE_PM_SUSPEND; |
1da177e4 | 696 | rq.special = &args; |
c00895ab | 697 | rq.data = &rqpm; |
1da177e4 | 698 | rqpm.pm_step = ide_pm_state_start_suspend; |
b887d2e6 DB |
699 | if (mesg.event == PM_EVENT_PRETHAW) |
700 | mesg.event = PM_EVENT_FREEZE; | |
701 | rqpm.pm_state = mesg.event; | |
1da177e4 | 702 | |
5e32132b SL |
703 | ret = ide_do_drive_cmd(drive, &rq, ide_wait); |
704 | /* only call ACPI _PS3 after both drivers are suspended */ | |
705 | if (!ret && (((drive->dn % 2) && hwif->drives[0].present | |
706 | && hwif->drives[1].present) | |
707 | || !hwif->drives[0].present | |
708 | || !hwif->drives[1].present)) | |
709 | ide_acpi_set_state(hwif, 0); | |
710 | return ret; | |
1da177e4 LT |
711 | } |
712 | ||
713 | static int generic_ide_resume(struct device *dev) | |
714 | { | |
715 | ide_drive_t *drive = dev->driver_data; | |
e3a59b4d | 716 | ide_hwif_t *hwif = HWIF(drive); |
1da177e4 LT |
717 | struct request rq; |
718 | struct request_pm_state rqpm; | |
719 | ide_task_t args; | |
0d2157f7 | 720 | int err; |
1da177e4 | 721 | |
e3a59b4d | 722 | /* Call ACPI _STM only once */ |
5e32132b SL |
723 | if (!(drive->dn % 2)) { |
724 | ide_acpi_set_state(hwif, 1); | |
e3a59b4d | 725 | ide_acpi_push_timing(hwif); |
5e32132b | 726 | } |
e3a59b4d HR |
727 | |
728 | ide_acpi_exec_tfs(drive); | |
729 | ||
1da177e4 LT |
730 | memset(&rq, 0, sizeof(rq)); |
731 | memset(&rqpm, 0, sizeof(rqpm)); | |
732 | memset(&args, 0, sizeof(args)); | |
4aff5e23 | 733 | rq.cmd_type = REQ_TYPE_PM_RESUME; |
1da177e4 | 734 | rq.special = &args; |
c00895ab | 735 | rq.data = &rqpm; |
1da177e4 | 736 | rqpm.pm_step = ide_pm_state_start_resume; |
ca078bae | 737 | rqpm.pm_state = PM_EVENT_ON; |
1da177e4 | 738 | |
0d2157f7 LT |
739 | err = ide_do_drive_cmd(drive, &rq, ide_head_wait); |
740 | ||
ce9b2b0a RW |
741 | if (err == 0 && dev->driver) { |
742 | ide_driver_t *drv = to_ide_driver(dev->driver); | |
743 | ||
744 | if (drv->resume) | |
745 | drv->resume(drive); | |
746 | } | |
0d2157f7 LT |
747 | |
748 | return err; | |
1da177e4 LT |
749 | } |
750 | ||
751 | int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev, | |
752 | unsigned int cmd, unsigned long arg) | |
753 | { | |
1497943e | 754 | unsigned long flags; |
1da177e4 | 755 | ide_driver_t *drv; |
1da177e4 | 756 | void __user *p = (void __user *)arg; |
1985026d | 757 | int err = 0, (*setfunc)(ide_drive_t *, int); |
1497943e | 758 | u8 *val; |
1da177e4 | 759 | |
1497943e BZ |
760 | switch (cmd) { |
761 | case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val; | |
762 | case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val; | |
763 | case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val; | |
764 | case HDIO_GET_DMA: val = &drive->using_dma; goto read_val; | |
765 | case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val; | |
766 | case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val; | |
767 | case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val; | |
768 | case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val; | |
769 | case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val; | |
1da177e4 | 770 | } |
1da177e4 LT |
771 | |
772 | switch (cmd) { | |
1da177e4 LT |
773 | case HDIO_OBSOLETE_IDENTITY: |
774 | case HDIO_GET_IDENTITY: | |
775 | if (bdev != bdev->bd_contains) | |
776 | return -EINVAL; | |
777 | if (drive->id_read == 0) | |
778 | return -ENOMSG; | |
779 | if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142)) | |
780 | return -EFAULT; | |
781 | return 0; | |
782 | ||
783 | case HDIO_GET_NICE: | |
784 | return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP | | |
785 | drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP | | |
92b83c8f | 786 | drive->nice1 << IDE_NICE_1, |
1da177e4 | 787 | (long __user *) arg); |
1da177e4 LT |
788 | #ifdef CONFIG_IDE_TASK_IOCTL |
789 | case HDIO_DRIVE_TASKFILE: | |
790 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) | |
791 | return -EACCES; | |
792 | switch(drive->media) { | |
793 | case ide_disk: | |
794 | return ide_taskfile_ioctl(drive, cmd, arg); | |
795 | default: | |
796 | return -ENOMSG; | |
797 | } | |
798 | #endif /* CONFIG_IDE_TASK_IOCTL */ | |
799 | ||
800 | case HDIO_DRIVE_CMD: | |
801 | if (!capable(CAP_SYS_RAWIO)) | |
802 | return -EACCES; | |
803 | return ide_cmd_ioctl(drive, cmd, arg); | |
804 | ||
805 | case HDIO_DRIVE_TASK: | |
806 | if (!capable(CAP_SYS_RAWIO)) | |
807 | return -EACCES; | |
808 | return ide_task_ioctl(drive, cmd, arg); | |
1da177e4 LT |
809 | case HDIO_SET_NICE: |
810 | if (!capable(CAP_SYS_ADMIN)) return -EACCES; | |
811 | if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1)))) | |
812 | return -EPERM; | |
813 | drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1; | |
814 | drv = *(ide_driver_t **)bdev->bd_disk->private_data; | |
815 | if (drive->dsc_overlap && !drv->supports_dsc_overlap) { | |
816 | drive->dsc_overlap = 0; | |
817 | return -EPERM; | |
818 | } | |
819 | drive->nice1 = (arg >> IDE_NICE_1) & 1; | |
820 | return 0; | |
821 | case HDIO_DRIVE_RESET: | |
dbecebca BZ |
822 | if (!capable(CAP_SYS_ADMIN)) |
823 | return -EACCES; | |
824 | ||
1da177e4 LT |
825 | /* |
826 | * Abort the current command on the | |
827 | * group if there is one, taking | |
828 | * care not to allow anything else | |
829 | * to be queued and to die on the | |
830 | * spot if we miss one somehow | |
831 | */ | |
832 | ||
833 | spin_lock_irqsave(&ide_lock, flags); | |
834 | ||
913759ac AC |
835 | if (HWGROUP(drive)->resetting) { |
836 | spin_unlock_irqrestore(&ide_lock, flags); | |
837 | return -EBUSY; | |
838 | } | |
839 | ||
1da177e4 LT |
840 | ide_abort(drive, "drive reset"); |
841 | ||
125e1874 | 842 | BUG_ON(HWGROUP(drive)->handler); |
dbecebca | 843 | |
1da177e4 LT |
844 | /* Ensure nothing gets queued after we |
845 | drop the lock. Reset will clear the busy */ | |
dbecebca | 846 | |
1da177e4 LT |
847 | HWGROUP(drive)->busy = 1; |
848 | spin_unlock_irqrestore(&ide_lock, flags); | |
849 | (void) ide_do_reset(drive); | |
850 | ||
851 | return 0; | |
1da177e4 LT |
852 | case HDIO_GET_BUSSTATE: |
853 | if (!capable(CAP_SYS_ADMIN)) | |
854 | return -EACCES; | |
855 | if (put_user(HWIF(drive)->bus_state, (long __user *)arg)) | |
856 | return -EFAULT; | |
857 | return 0; | |
858 | ||
859 | case HDIO_SET_BUSSTATE: | |
860 | if (!capable(CAP_SYS_ADMIN)) | |
861 | return -EACCES; | |
1da177e4 LT |
862 | return -EOPNOTSUPP; |
863 | default: | |
864 | return -EINVAL; | |
865 | } | |
1497943e BZ |
866 | |
867 | read_val: | |
f9383c42 | 868 | mutex_lock(&ide_setting_mtx); |
1497943e BZ |
869 | spin_lock_irqsave(&ide_lock, flags); |
870 | err = *val; | |
871 | spin_unlock_irqrestore(&ide_lock, flags); | |
f9383c42 | 872 | mutex_unlock(&ide_setting_mtx); |
1497943e BZ |
873 | return err >= 0 ? put_user(err, (long __user *)arg) : err; |
874 | ||
875 | set_val: | |
876 | if (bdev != bdev->bd_contains) | |
877 | err = -EINVAL; | |
878 | else { | |
879 | if (!capable(CAP_SYS_ADMIN)) | |
880 | err = -EACCES; | |
881 | else { | |
f9383c42 | 882 | mutex_lock(&ide_setting_mtx); |
1497943e | 883 | err = setfunc(drive, arg); |
f9383c42 | 884 | mutex_unlock(&ide_setting_mtx); |
1497943e BZ |
885 | } |
886 | } | |
887 | return err; | |
1da177e4 LT |
888 | } |
889 | ||
890 | EXPORT_SYMBOL(generic_ide_ioctl); | |
891 | ||
892 | /* | |
893 | * stridx() returns the offset of c within s, | |
894 | * or -1 if c is '\0' or not found within s. | |
895 | */ | |
896 | static int __init stridx (const char *s, char c) | |
897 | { | |
898 | char *i = strchr(s, c); | |
899 | return (i && c) ? i - s : -1; | |
900 | } | |
901 | ||
902 | /* | |
903 | * match_parm() does parsing for ide_setup(): | |
904 | * | |
905 | * 1. the first char of s must be '='. | |
906 | * 2. if the remainder matches one of the supplied keywords, | |
907 | * the index (1 based) of the keyword is negated and returned. | |
908 | * 3. if the remainder is a series of no more than max_vals numbers | |
909 | * separated by commas, the numbers are saved in vals[] and a | |
910 | * count of how many were saved is returned. Base10 is assumed, | |
911 | * and base16 is allowed when prefixed with "0x". | |
912 | * 4. otherwise, zero is returned. | |
913 | */ | |
914 | static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals) | |
915 | { | |
916 | static const char *decimal = "0123456789"; | |
917 | static const char *hex = "0123456789abcdef"; | |
918 | int i, n; | |
919 | ||
920 | if (*s++ == '=') { | |
921 | /* | |
922 | * Try matching against the supplied keywords, | |
923 | * and return -(index+1) if we match one | |
924 | */ | |
925 | if (keywords != NULL) { | |
926 | for (i = 0; *keywords != NULL; ++i) { | |
927 | if (!strcmp(s, *keywords++)) | |
928 | return -(i+1); | |
929 | } | |
930 | } | |
931 | /* | |
932 | * Look for a series of no more than "max_vals" | |
933 | * numeric values separated by commas, in base10, | |
934 | * or base16 when prefixed with "0x". | |
935 | * Return a count of how many were found. | |
936 | */ | |
937 | for (n = 0; (i = stridx(decimal, *s)) >= 0;) { | |
938 | vals[n] = i; | |
939 | while ((i = stridx(decimal, *++s)) >= 0) | |
940 | vals[n] = (vals[n] * 10) + i; | |
941 | if (*s == 'x' && !vals[n]) { | |
942 | while ((i = stridx(hex, *++s)) >= 0) | |
943 | vals[n] = (vals[n] * 0x10) + i; | |
944 | } | |
945 | if (++n == max_vals) | |
946 | break; | |
947 | if (*s == ',' || *s == ';') | |
948 | ++s; | |
949 | } | |
950 | if (!*s) | |
951 | return n; | |
952 | } | |
953 | return 0; /* zero = nothing matched */ | |
954 | } | |
955 | ||
84913882 | 956 | extern int probe_ali14xx; |
84913882 | 957 | extern int probe_umc8672; |
84913882 | 958 | extern int probe_dtc2278; |
84913882 | 959 | extern int probe_ht6560b; |
84913882 | 960 | extern int probe_qd65xx; |
ade2daf9 | 961 | extern int cmd640_vlb; |
ffd4f6f0 | 962 | extern int probe_4drives; |
1da177e4 | 963 | |
9a0e77f2 | 964 | static int __initdata is_chipset_set; |
1da177e4 LT |
965 | |
966 | /* | |
967 | * ide_setup() gets called VERY EARLY during initialization, | |
968 | * to handle kernel "command line" strings beginning with "hdx=" or "ide". | |
969 | * | |
1c10e938 | 970 | * Remember to update Documentation/ide/ide.txt if you change something here. |
1da177e4 LT |
971 | */ |
972 | static int __init ide_setup(char *s) | |
973 | { | |
974 | int i, vals[3]; | |
975 | ide_hwif_t *hwif; | |
976 | ide_drive_t *drive; | |
977 | unsigned int hw, unit; | |
978 | const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1); | |
979 | const char max_hwif = '0' + (MAX_HWIFS - 1); | |
980 | ||
981 | ||
982 | if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */ | |
983 | return 0; /* driver and not us */ | |
984 | ||
985 | if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2)) | |
986 | return 0; | |
987 | ||
988 | printk(KERN_INFO "ide_setup: %s", s); | |
989 | init_ide_data (); | |
990 | ||
991 | #ifdef CONFIG_BLK_DEV_IDEDOUBLER | |
992 | if (!strcmp(s, "ide=doubler")) { | |
993 | extern int ide_doubler; | |
994 | ||
995 | printk(" : Enabled support for IDE doublers\n"); | |
996 | ide_doubler = 1; | |
997 | return 1; | |
998 | } | |
999 | #endif /* CONFIG_BLK_DEV_IDEDOUBLER */ | |
1000 | ||
1001 | if (!strcmp(s, "ide=nodma")) { | |
1002 | printk(" : Prevented DMA\n"); | |
1003 | noautodma = 1; | |
c223701c | 1004 | goto obsolete_option; |
1da177e4 LT |
1005 | } |
1006 | ||
e3a59b4d HR |
1007 | #ifdef CONFIG_BLK_DEV_IDEACPI |
1008 | if (!strcmp(s, "ide=noacpi")) { | |
1009 | //printk(" : Disable IDE ACPI support.\n"); | |
1010 | ide_noacpi = 1; | |
1011 | return 1; | |
1012 | } | |
1013 | if (!strcmp(s, "ide=acpigtf")) { | |
1014 | //printk(" : Enable IDE ACPI _GTF support.\n"); | |
1015 | ide_noacpitfs = 0; | |
1016 | return 1; | |
1017 | } | |
1018 | if (!strcmp(s, "ide=acpionboot")) { | |
1019 | //printk(" : Call IDE ACPI methods on boot.\n"); | |
1020 | ide_noacpionboot = 0; | |
1021 | return 1; | |
1022 | } | |
1023 | #endif /* CONFIG_BLK_DEV_IDEACPI */ | |
1024 | ||
1da177e4 LT |
1025 | /* |
1026 | * Look for drive options: "hdx=" | |
1027 | */ | |
1028 | if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) { | |
1029 | const char *hd_words[] = { | |
c223701c | 1030 | "none", "noprobe", "nowerr", "cdrom", "nodma", |
9e47be0c | 1031 | "autotune", "noautotune", "-8", "-9", "-10", |
36193484 | 1032 | "noflush", "remap", "remap63", "scsi", NULL }; |
1da177e4 LT |
1033 | unit = s[2] - 'a'; |
1034 | hw = unit / MAX_DRIVES; | |
1035 | unit = unit % MAX_DRIVES; | |
1036 | hwif = &ide_hwifs[hw]; | |
1037 | drive = &hwif->drives[unit]; | |
1038 | if (strncmp(s + 4, "ide-", 4) == 0) { | |
1039 | strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req)); | |
15220d9b | 1040 | goto obsolete_option; |
1da177e4 LT |
1041 | } |
1042 | switch (match_parm(&s[3], hd_words, vals, 3)) { | |
1043 | case -1: /* "none" */ | |
1044 | case -2: /* "noprobe" */ | |
1045 | drive->noprobe = 1; | |
1046 | goto done; | |
1047 | case -3: /* "nowerr" */ | |
1048 | drive->bad_wstat = BAD_R_STAT; | |
1049 | hwif->noprobe = 0; | |
1050 | goto done; | |
1051 | case -4: /* "cdrom" */ | |
1052 | drive->present = 1; | |
1053 | drive->media = ide_cdrom; | |
1054 | /* an ATAPI device ignores DRDY */ | |
1055 | drive->ready_stat = 0; | |
1056 | hwif->noprobe = 0; | |
1057 | goto done; | |
c223701c BZ |
1058 | case -5: /* nodma */ |
1059 | drive->nodma = 1; | |
1060 | goto done; | |
1da177e4 LT |
1061 | case -6: /* "autotune" */ |
1062 | drive->autotune = IDE_TUNE_AUTO; | |
1063 | goto obsolete_option; | |
1064 | case -7: /* "noautotune" */ | |
1065 | drive->autotune = IDE_TUNE_NOAUTO; | |
1066 | goto obsolete_option; | |
36193484 JA |
1067 | case -11: /* noflush */ |
1068 | drive->noflush = 1; | |
1069 | goto done; | |
1da177e4 LT |
1070 | case -12: /* "remap" */ |
1071 | drive->remap_0_to_1 = 1; | |
d708c40d | 1072 | goto obsolete_option; |
1da177e4 LT |
1073 | case -13: /* "remap63" */ |
1074 | drive->sect0 = 63; | |
d708c40d | 1075 | goto obsolete_option; |
1da177e4 LT |
1076 | case -14: /* "scsi" */ |
1077 | drive->scsi = 1; | |
15220d9b | 1078 | goto obsolete_option; |
1da177e4 LT |
1079 | case 3: /* cyl,head,sect */ |
1080 | drive->media = ide_disk; | |
1081 | drive->ready_stat = READY_STAT; | |
1082 | drive->cyl = drive->bios_cyl = vals[0]; | |
1083 | drive->head = drive->bios_head = vals[1]; | |
1084 | drive->sect = drive->bios_sect = vals[2]; | |
1085 | drive->present = 1; | |
1086 | drive->forced_geom = 1; | |
1087 | hwif->noprobe = 0; | |
1088 | goto done; | |
1089 | default: | |
1090 | goto bad_option; | |
1091 | } | |
1092 | } | |
1093 | ||
1094 | if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e') | |
1095 | goto bad_option; | |
1096 | /* | |
1097 | * Look for bus speed option: "idebus=" | |
1098 | */ | |
1099 | if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') { | |
1100 | if (match_parm(&s[6], NULL, vals, 1) != 1) | |
1101 | goto bad_option; | |
1102 | if (vals[0] >= 20 && vals[0] <= 66) { | |
1103 | idebus_parameter = vals[0]; | |
1104 | } else | |
1105 | printk(" -- BAD BUS SPEED! Expected value from 20 to 66"); | |
1106 | goto done; | |
1107 | } | |
1108 | /* | |
1109 | * Look for interface options: "idex=" | |
1110 | */ | |
1111 | if (s[3] >= '0' && s[3] <= max_hwif) { | |
1112 | /* | |
1113 | * Be VERY CAREFUL changing this: note hardcoded indexes below | |
1114 | * (-8, -9, -10) are reserved to ease the hardcoding. | |
1115 | */ | |
1116 | static const char *ide_words[] = { | |
f01674e4 | 1117 | "minus1", "serialize", "minus3", "minus4", |
1b516940 | 1118 | "reset", "minus6", "ata66", "minus8", "minus9", |
1da177e4 LT |
1119 | "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb", |
1120 | "dtc2278", "umc8672", "ali14xx", NULL }; | |
9239b333 | 1121 | |
1da177e4 LT |
1122 | hw = s[3] - '0'; |
1123 | hwif = &ide_hwifs[hw]; | |
1124 | i = match_parm(&s[4], ide_words, vals, 3); | |
1125 | ||
1126 | /* | |
1127 | * Cryptic check to ensure chipset not already set for hwif. | |
1128 | * Note: we can't depend on hwif->chipset here. | |
1129 | */ | |
9a0e77f2 | 1130 | if (i >= -18 && i <= -11) { |
1da177e4 | 1131 | /* chipset already specified */ |
9a0e77f2 | 1132 | if (is_chipset_set) |
1da177e4 | 1133 | goto bad_option; |
9a0e77f2 BZ |
1134 | /* these drivers are for "ide0=" only */ |
1135 | if (hw != 0) | |
1136 | goto bad_hwif; | |
1137 | is_chipset_set = 1; | |
1da177e4 LT |
1138 | printk("\n"); |
1139 | } | |
1140 | ||
1141 | switch (i) { | |
1142 | #ifdef CONFIG_BLK_DEV_ALI14XX | |
1143 | case -17: /* "ali14xx" */ | |
1144 | probe_ali14xx = 1; | |
9c027c68 | 1145 | goto obsolete_option; |
1da177e4 LT |
1146 | #endif |
1147 | #ifdef CONFIG_BLK_DEV_UMC8672 | |
1148 | case -16: /* "umc8672" */ | |
1149 | probe_umc8672 = 1; | |
9c027c68 | 1150 | goto obsolete_option; |
1da177e4 LT |
1151 | #endif |
1152 | #ifdef CONFIG_BLK_DEV_DTC2278 | |
1153 | case -15: /* "dtc2278" */ | |
1154 | probe_dtc2278 = 1; | |
9c027c68 | 1155 | goto obsolete_option; |
1da177e4 LT |
1156 | #endif |
1157 | #ifdef CONFIG_BLK_DEV_CMD640 | |
1158 | case -14: /* "cmd640_vlb" */ | |
1da177e4 | 1159 | cmd640_vlb = 1; |
9c027c68 | 1160 | goto obsolete_option; |
1da177e4 LT |
1161 | #endif |
1162 | #ifdef CONFIG_BLK_DEV_HT6560B | |
1163 | case -13: /* "ht6560b" */ | |
1164 | probe_ht6560b = 1; | |
9c027c68 | 1165 | goto obsolete_option; |
1da177e4 LT |
1166 | #endif |
1167 | #ifdef CONFIG_BLK_DEV_QD65XX | |
1168 | case -12: /* "qd65xx" */ | |
1169 | probe_qd65xx = 1; | |
9c027c68 | 1170 | goto obsolete_option; |
1da177e4 LT |
1171 | #endif |
1172 | #ifdef CONFIG_BLK_DEV_4DRIVES | |
1173 | case -11: /* "four" drives on one set of ports */ | |
ffd4f6f0 | 1174 | probe_4drives = 1; |
b6209a90 | 1175 | goto obsolete_option; |
ffd4f6f0 | 1176 | #endif |
1da177e4 LT |
1177 | case -10: /* minus10 */ |
1178 | case -9: /* minus9 */ | |
1179 | case -8: /* minus8 */ | |
1b516940 | 1180 | case -6: |
b6209a90 BZ |
1181 | case -4: |
1182 | case -3: | |
1da177e4 LT |
1183 | goto bad_option; |
1184 | case -7: /* ata66 */ | |
1185 | #ifdef CONFIG_BLK_DEV_IDEPCI | |
49521f97 BZ |
1186 | /* |
1187 | * Use ATA_CBL_PATA40_SHORT so drive side | |
1188 | * cable detection is also overriden. | |
1189 | */ | |
1190 | hwif->cbl = ATA_CBL_PATA40_SHORT; | |
1da177e4 LT |
1191 | goto obsolete_option; |
1192 | #else | |
1193 | goto bad_hwif; | |
1194 | #endif | |
1da177e4 LT |
1195 | case -5: /* "reset" */ |
1196 | hwif->reset = 1; | |
1197 | goto obsolete_option; | |
1da177e4 | 1198 | case -2: /* "serialize" */ |
1da177e4 LT |
1199 | hwif->mate = &ide_hwifs[hw^1]; |
1200 | hwif->mate->mate = hwif; | |
1201 | hwif->serialized = hwif->mate->serialized = 1; | |
1202 | goto obsolete_option; | |
1203 | ||
f01674e4 | 1204 | case -1: |
9a0e77f2 BZ |
1205 | case 0: |
1206 | case 1: | |
1207 | case 2: | |
1208 | case 3: | |
1209 | goto bad_option; | |
1da177e4 LT |
1210 | default: |
1211 | printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n"); | |
1212 | return 1; | |
1213 | } | |
1214 | } | |
1215 | bad_option: | |
1216 | printk(" -- BAD OPTION\n"); | |
1217 | return 1; | |
1218 | obsolete_option: | |
1219 | printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n"); | |
1220 | return 1; | |
1221 | bad_hwif: | |
1222 | printk("-- NOT SUPPORTED ON ide%d", hw); | |
1223 | done: | |
1224 | printk("\n"); | |
1225 | return 1; | |
1226 | } | |
1227 | ||
1da177e4 LT |
1228 | EXPORT_SYMBOL(ide_lock); |
1229 | ||
8604affd BZ |
1230 | static int ide_bus_match(struct device *dev, struct device_driver *drv) |
1231 | { | |
1232 | return 1; | |
1233 | } | |
1234 | ||
263756ec KS |
1235 | static char *media_string(ide_drive_t *drive) |
1236 | { | |
1237 | switch (drive->media) { | |
1238 | case ide_disk: | |
1239 | return "disk"; | |
1240 | case ide_cdrom: | |
1241 | return "cdrom"; | |
1242 | case ide_tape: | |
1243 | return "tape"; | |
1244 | case ide_floppy: | |
1245 | return "floppy"; | |
a7a832de DK |
1246 | case ide_optical: |
1247 | return "optical"; | |
263756ec KS |
1248 | default: |
1249 | return "UNKNOWN"; | |
1250 | } | |
1251 | } | |
1252 | ||
1253 | static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1254 | { | |
1255 | ide_drive_t *drive = to_ide_device(dev); | |
1256 | return sprintf(buf, "%s\n", media_string(drive)); | |
1257 | } | |
1258 | ||
1259 | static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1260 | { | |
1261 | ide_drive_t *drive = to_ide_device(dev); | |
1262 | return sprintf(buf, "%s\n", drive->name); | |
1263 | } | |
1264 | ||
1265 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf) | |
1266 | { | |
1267 | ide_drive_t *drive = to_ide_device(dev); | |
1268 | return sprintf(buf, "ide:m-%s\n", media_string(drive)); | |
1269 | } | |
1270 | ||
e11b9035 BZ |
1271 | static ssize_t model_show(struct device *dev, struct device_attribute *attr, |
1272 | char *buf) | |
1273 | { | |
1274 | ide_drive_t *drive = to_ide_device(dev); | |
1275 | return sprintf(buf, "%s\n", drive->id->model); | |
1276 | } | |
1277 | ||
1278 | static ssize_t firmware_show(struct device *dev, struct device_attribute *attr, | |
1279 | char *buf) | |
1280 | { | |
1281 | ide_drive_t *drive = to_ide_device(dev); | |
1282 | return sprintf(buf, "%s\n", drive->id->fw_rev); | |
1283 | } | |
1284 | ||
1285 | static ssize_t serial_show(struct device *dev, struct device_attribute *attr, | |
1286 | char *buf) | |
1287 | { | |
1288 | ide_drive_t *drive = to_ide_device(dev); | |
1289 | return sprintf(buf, "%s\n", drive->id->serial_no); | |
1290 | } | |
1291 | ||
263756ec KS |
1292 | static struct device_attribute ide_dev_attrs[] = { |
1293 | __ATTR_RO(media), | |
1294 | __ATTR_RO(drivename), | |
1295 | __ATTR_RO(modalias), | |
e11b9035 BZ |
1296 | __ATTR_RO(model), |
1297 | __ATTR_RO(firmware), | |
1298 | __ATTR(serial, 0400, serial_show, NULL), | |
263756ec KS |
1299 | __ATTR_NULL |
1300 | }; | |
1301 | ||
7eff2e7a | 1302 | static int ide_uevent(struct device *dev, struct kobj_uevent_env *env) |
263756ec KS |
1303 | { |
1304 | ide_drive_t *drive = to_ide_device(dev); | |
7eff2e7a KS |
1305 | |
1306 | add_uevent_var(env, "MEDIA=%s", media_string(drive)); | |
1307 | add_uevent_var(env, "DRIVENAME=%s", drive->name); | |
1308 | add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive)); | |
263756ec KS |
1309 | return 0; |
1310 | } | |
1311 | ||
4031bbe4 RK |
1312 | static int generic_ide_probe(struct device *dev) |
1313 | { | |
1314 | ide_drive_t *drive = to_ide_device(dev); | |
1315 | ide_driver_t *drv = to_ide_driver(dev->driver); | |
1316 | ||
1317 | return drv->probe ? drv->probe(drive) : -ENODEV; | |
1318 | } | |
1319 | ||
1320 | static int generic_ide_remove(struct device *dev) | |
1321 | { | |
1322 | ide_drive_t *drive = to_ide_device(dev); | |
1323 | ide_driver_t *drv = to_ide_driver(dev->driver); | |
1324 | ||
1325 | if (drv->remove) | |
1326 | drv->remove(drive); | |
1327 | ||
1328 | return 0; | |
1329 | } | |
1330 | ||
1331 | static void generic_ide_shutdown(struct device *dev) | |
1332 | { | |
1333 | ide_drive_t *drive = to_ide_device(dev); | |
1334 | ide_driver_t *drv = to_ide_driver(dev->driver); | |
1335 | ||
1336 | if (dev->driver && drv->shutdown) | |
1337 | drv->shutdown(drive); | |
1338 | } | |
1339 | ||
1da177e4 LT |
1340 | struct bus_type ide_bus_type = { |
1341 | .name = "ide", | |
8604affd | 1342 | .match = ide_bus_match, |
263756ec | 1343 | .uevent = ide_uevent, |
4031bbe4 RK |
1344 | .probe = generic_ide_probe, |
1345 | .remove = generic_ide_remove, | |
1346 | .shutdown = generic_ide_shutdown, | |
263756ec | 1347 | .dev_attrs = ide_dev_attrs, |
1da177e4 LT |
1348 | .suspend = generic_ide_suspend, |
1349 | .resume = generic_ide_resume, | |
1350 | }; | |
1351 | ||
8604affd BZ |
1352 | EXPORT_SYMBOL_GPL(ide_bus_type); |
1353 | ||
f74c9141 BZ |
1354 | static void ide_port_class_release(struct device *portdev) |
1355 | { | |
1356 | ide_hwif_t *hwif = dev_get_drvdata(portdev); | |
1357 | ||
1358 | put_device(&hwif->gendev); | |
1359 | } | |
1360 | ||
1da177e4 LT |
1361 | /* |
1362 | * This is gets invoked once during initialization, to set *everything* up | |
1363 | */ | |
1364 | static int __init ide_init(void) | |
1365 | { | |
349ae23f RD |
1366 | int ret; |
1367 | ||
eba8ff94 | 1368 | printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n"); |
1da177e4 LT |
1369 | system_bus_speed = ide_system_bus_speed(); |
1370 | ||
537f06c5 BZ |
1371 | printk(KERN_INFO "ide: Assuming %dMHz system bus speed " |
1372 | "for PIO modes%s\n", system_bus_speed, | |
1373 | idebus_parameter ? "" : "; override with idebus=xx"); | |
1374 | ||
349ae23f RD |
1375 | ret = bus_register(&ide_bus_type); |
1376 | if (ret < 0) { | |
1377 | printk(KERN_WARNING "IDE: bus_register error: %d\n", ret); | |
1378 | return ret; | |
1379 | } | |
1da177e4 | 1380 | |
f74c9141 BZ |
1381 | ide_port_class = class_create(THIS_MODULE, "ide_port"); |
1382 | if (IS_ERR(ide_port_class)) { | |
1383 | ret = PTR_ERR(ide_port_class); | |
1384 | goto out_port_class; | |
1385 | } | |
1386 | ide_port_class->dev_release = ide_port_class_release; | |
1387 | ||
1da177e4 LT |
1388 | init_ide_data(); |
1389 | ||
5cbf79cd | 1390 | proc_ide_create(); |
1da177e4 | 1391 | |
1da177e4 | 1392 | return 0; |
f74c9141 BZ |
1393 | |
1394 | out_port_class: | |
1395 | bus_unregister(&ide_bus_type); | |
1396 | ||
1397 | return ret; | |
1da177e4 LT |
1398 | } |
1399 | ||
1400 | #ifdef MODULE | |
1401 | static char *options = NULL; | |
1402 | module_param(options, charp, 0); | |
1403 | MODULE_LICENSE("GPL"); | |
1404 | ||
1405 | static void __init parse_options (char *line) | |
1406 | { | |
1407 | char *next = line; | |
1408 | ||
1409 | if (line == NULL || !*line) | |
1410 | return; | |
1411 | while ((line = next) != NULL) { | |
1412 | if ((next = strchr(line,' ')) != NULL) | |
1413 | *next++ = 0; | |
1414 | if (!ide_setup(line)) | |
1415 | printk (KERN_INFO "Unknown option '%s'\n", line); | |
1416 | } | |
1417 | } | |
1418 | ||
fbd8ad30 | 1419 | int __init init_module (void) |
1da177e4 LT |
1420 | { |
1421 | parse_options(options); | |
1422 | return ide_init(); | |
1423 | } | |
1424 | ||
eb797227 | 1425 | void __exit cleanup_module (void) |
1da177e4 LT |
1426 | { |
1427 | int index; | |
1428 | ||
1429 | for (index = 0; index < MAX_HWIFS; ++index) | |
93de00fd | 1430 | ide_unregister(index); |
1da177e4 | 1431 | |
1da177e4 | 1432 | proc_ide_destroy(); |
1da177e4 | 1433 | |
f74c9141 BZ |
1434 | class_destroy(ide_port_class); |
1435 | ||
1da177e4 LT |
1436 | bus_unregister(&ide_bus_type); |
1437 | } | |
1438 | ||
1439 | #else /* !MODULE */ | |
1440 | ||
1441 | __setup("", ide_setup); | |
1442 | ||
1443 | module_init(ide_init); | |
1444 | ||
1445 | #endif /* MODULE */ |