update x86 config and move some config defaults to the config template
[openwrt.git] / target / linux / magicbox-2.6 / patches / 100-cf_slot.patch
1 diff -purN linux.old/drivers/ide/ide.c linux.dev/drivers/ide/ide.c
2 --- linux.old/drivers/ide/ide.c 2007-01-10 20:10:37.000000000 +0100
3 +++ linux.dev/drivers/ide/ide.c 2007-04-09 01:25:30.866800288 +0200
4 @@ -1783,6 +1783,7 @@ done:
5
6 extern void pnpide_init(void);
7 extern void h8300_ide_init(void);
8 +extern void ide_magicbox_init(void);
9
10 /*
11 * probe_for_hwifs() finds/initializes "known" IDE interfaces
12 @@ -1847,6 +1848,9 @@ static void __init probe_for_hwifs (void
13 #ifdef CONFIG_H8300
14 h8300_ide_init();
15 #endif
16 +#ifdef CONFIG_BLK_DEV_MAGICBOX_IDE
17 + ide_magicbox_init();
18 +#endif
19 }
20
21 void ide_register_subdriver(ide_drive_t *drive, ide_driver_t *driver)
22 diff -purN linux.old/drivers/ide/ide.c.orig linux.dev/drivers/ide/ide.c.orig
23 --- linux.old/drivers/ide/ide.c.orig 1970-01-01 01:00:00.000000000 +0100
24 +++ linux.dev/drivers/ide/ide.c.orig 2007-01-10 20:10:37.000000000 +0100
25 @@ -0,0 +1,2099 @@
26 +/*
27 + * linux/drivers/ide/ide.c Version 7.00beta2 Mar 05 2003
28 + *
29 + * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
30 + */
31 +
32 +/*
33 + * Mostly written by Mark Lord <mlord@pobox.com>
34 + * and Gadi Oxman <gadio@netvision.net.il>
35 + * and Andre Hedrick <andre@linux-ide.org>
36 + *
37 + * See linux/MAINTAINERS for address of current maintainer.
38 + *
39 + * This is the multiple IDE interface driver, as evolved from hd.c.
40 + * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs
41 + * (usually 14 & 15).
42 + * There can be up to two drives per interface, as per the ATA-2 spec.
43 + *
44 + * Primary: ide0, port 0x1f0; major=3; hda is minor=0; hdb is minor=64
45 + * Secondary: ide1, port 0x170; major=22; hdc is minor=0; hdd is minor=64
46 + * Tertiary: ide2, port 0x???; major=33; hde is minor=0; hdf is minor=64
47 + * Quaternary: ide3, port 0x???; major=34; hdg is minor=0; hdh is minor=64
48 + * ...
49 + *
50 + * From hd.c:
51 + * |
52 + * | It traverses the request-list, using interrupts to jump between functions.
53 + * | As nearly all functions can be called within interrupts, we may not sleep.
54 + * | Special care is recommended. Have Fun!
55 + * |
56 + * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
57 + * |
58 + * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
59 + * | in the early extended-partition checks and added DM partitions.
60 + * |
61 + * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
62 + * |
63 + * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
64 + * | and general streamlining by Mark Lord (mlord@pobox.com).
65 + *
66 + * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
67 + *
68 + * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg)
69 + * Delman Lee (delman@ieee.org) ("Mr. atdisk2")
70 + * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom)
71 + *
72 + * This was a rewrite of just about everything from hd.c, though some original
73 + * code is still sprinkled about. Think of it as a major evolution, with
74 + * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
75 + *
76 + * Version 1.0 ALPHA initial code, primary i/f working okay
77 + * Version 1.3 BETA dual i/f on shared irq tested & working!
78 + * Version 1.4 BETA added auto probing for irq(s)
79 + * Version 1.5 BETA added ALPHA (untested) support for IDE cd-roms,
80 + * ...
81 + * Version 5.50 allow values as small as 20 for idebus=
82 + * Version 5.51 force non io_32bit in drive_cmd_intr()
83 + * change delay_10ms() to delay_50ms() to fix problems
84 + * Version 5.52 fix incorrect invalidation of removable devices
85 + * add "hdx=slow" command line option
86 + * Version 5.60 start to modularize the driver; the disk and ATAPI
87 + * drivers can be compiled as loadable modules.
88 + * move IDE probe code to ide-probe.c
89 + * move IDE disk code to ide-disk.c
90 + * add support for generic IDE device subdrivers
91 + * add m68k code from Geert Uytterhoeven
92 + * probe all interfaces by default
93 + * add ioctl to (re)probe an interface
94 + * Version 6.00 use per device request queues
95 + * attempt to optimize shared hwgroup performance
96 + * add ioctl to manually adjust bandwidth algorithms
97 + * add kerneld support for the probe module
98 + * fix bug in ide_error()
99 + * fix bug in the first ide_get_lock() call for Atari
100 + * don't flush leftover data for ATAPI devices
101 + * Version 6.01 clear hwgroup->active while the hwgroup sleeps
102 + * support HDIO_GETGEO for floppies
103 + * Version 6.02 fix ide_ack_intr() call
104 + * check partition table on floppies
105 + * Version 6.03 handle bad status bit sequencing in ide_wait_stat()
106 + * Version 6.10 deleted old entries from this list of updates
107 + * replaced triton.c with ide-dma.c generic PCI DMA
108 + * added support for BIOS-enabled UltraDMA
109 + * rename all "promise" things to "pdc4030"
110 + * fix EZ-DRIVE handling on small disks
111 + * Version 6.11 fix probe error in ide_scan_devices()
112 + * fix ancient "jiffies" polling bugs
113 + * mask all hwgroup interrupts on each irq entry
114 + * Version 6.12 integrate ioctl and proc interfaces
115 + * fix parsing of "idex=" command line parameter
116 + * Version 6.13 add support for ide4/ide5 courtesy rjones@orchestream.com
117 + * Version 6.14 fixed IRQ sharing among PCI devices
118 + * Version 6.15 added SMP awareness to IDE drivers
119 + * Version 6.16 fixed various bugs; even more SMP friendly
120 + * Version 6.17 fix for newest EZ-Drive problem
121 + * Version 6.18 default unpartitioned-disk translation now "BIOS LBA"
122 + * Version 6.19 Re-design for a UNIFORM driver for all platforms,
123 + * model based on suggestions from Russell King and
124 + * Geert Uytterhoeven
125 + * Promise DC4030VL now supported.
126 + * add support for ide6/ide7
127 + * delay_50ms() changed to ide_delay_50ms() and exported.
128 + * Version 6.20 Added/Fixed Generic ATA-66 support and hwif detection.
129 + * Added hdx=flash to allow for second flash disk
130 + * detection w/o the hang loop.
131 + * Added support for ide8/ide9
132 + * Added idex=ata66 for the quirky chipsets that are
133 + * ATA-66 compliant, but have yet to determine a method
134 + * of verification of the 80c cable presence.
135 + * Specifically Promise's PDC20262 chipset.
136 + * Version 6.21 Fixing/Fixed SMP spinlock issue with insight from an old
137 + * hat that clarified original low level driver design.
138 + * Version 6.30 Added SMP support; fixed multmode issues. -ml
139 + * Version 6.31 Debug Share INTR's and request queue streaming
140 + * Native ATA-100 support
141 + * Prep for Cascades Project
142 + * Version 7.00alpha First named revision of ide rearrange
143 + *
144 + * Some additional driver compile-time options are in ./include/linux/ide.h
145 + *
146 + * To do, in likely order of completion:
147 + * - modify kernel to obtain BIOS geometry for drives on 2nd/3rd/4th i/f
148 + *
149 + */
150 +
151 +#define REVISION "Revision: 7.00alpha2"
152 +#define VERSION "Id: ide.c 7.00a2 20020906"
153 +
154 +#undef REALLY_SLOW_IO /* most systems can safely undef this */
155 +
156 +#define _IDE_C /* Tell ide.h it's really us */
157 +
158 +#include <linux/module.h>
159 +#include <linux/types.h>
160 +#include <linux/string.h>
161 +#include <linux/kernel.h>
162 +#include <linux/timer.h>
163 +#include <linux/mm.h>
164 +#include <linux/interrupt.h>
165 +#include <linux/major.h>
166 +#include <linux/errno.h>
167 +#include <linux/genhd.h>
168 +#include <linux/blkpg.h>
169 +#include <linux/slab.h>
170 +#include <linux/init.h>
171 +#include <linux/pci.h>
172 +#include <linux/delay.h>
173 +#include <linux/ide.h>
174 +#include <linux/completion.h>
175 +#include <linux/reboot.h>
176 +#include <linux/cdrom.h>
177 +#include <linux/seq_file.h>
178 +#include <linux/device.h>
179 +#include <linux/bitops.h>
180 +
181 +#include <asm/byteorder.h>
182 +#include <asm/irq.h>
183 +#include <asm/uaccess.h>
184 +#include <asm/io.h>
185 +
186 +
187 +/* default maximum number of failures */
188 +#define IDE_DEFAULT_MAX_FAILURES 1
189 +
190 +static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
191 + IDE2_MAJOR, IDE3_MAJOR,
192 + IDE4_MAJOR, IDE5_MAJOR,
193 + IDE6_MAJOR, IDE7_MAJOR,
194 + IDE8_MAJOR, IDE9_MAJOR };
195 +
196 +static int idebus_parameter; /* holds the "idebus=" parameter */
197 +static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
198 +static int initializing; /* set while initializing built-in drivers */
199 +
200 +DECLARE_MUTEX(ide_cfg_sem);
201 + __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
202 +
203 +#ifdef CONFIG_BLK_DEV_IDEPCI
204 +static int ide_scan_direction; /* THIS was formerly 2.2.x pci=reverse */
205 +#endif
206 +
207 +#ifdef CONFIG_IDEDMA_AUTO
208 +int noautodma = 0;
209 +#else
210 +int noautodma = 1;
211 +#endif
212 +
213 +EXPORT_SYMBOL(noautodma);
214 +
215 +/*
216 + * This is declared extern in ide.h, for access by other IDE modules:
217 + */
218 +ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
219 +
220 +EXPORT_SYMBOL(ide_hwifs);
221 +
222 +/*
223 + * Do not even *think* about calling this!
224 + */
225 +static void init_hwif_data(ide_hwif_t *hwif, unsigned int index)
226 +{
227 + unsigned int unit;
228 +
229 + /* bulk initialize hwif & drive info with zeros */
230 + memset(hwif, 0, sizeof(ide_hwif_t));
231 +
232 + /* fill in any non-zero initial values */
233 + hwif->index = index;
234 + hwif->major = ide_hwif_to_major[index];
235 +
236 + hwif->name[0] = 'i';
237 + hwif->name[1] = 'd';
238 + hwif->name[2] = 'e';
239 + hwif->name[3] = '0' + index;
240 +
241 + hwif->bus_state = BUSSTATE_ON;
242 +
243 + hwif->atapi_dma = 0; /* disable all atapi dma */
244 + hwif->ultra_mask = 0x80; /* disable all ultra */
245 + hwif->mwdma_mask = 0x80; /* disable all mwdma */
246 + hwif->swdma_mask = 0x80; /* disable all swdma */
247 +
248 + init_completion(&hwif->gendev_rel_comp);
249 +
250 + default_hwif_iops(hwif);
251 + default_hwif_transport(hwif);
252 + for (unit = 0; unit < MAX_DRIVES; ++unit) {
253 + ide_drive_t *drive = &hwif->drives[unit];
254 +
255 + drive->media = ide_disk;
256 + drive->select.all = (unit<<4)|0xa0;
257 + drive->hwif = hwif;
258 + drive->ctl = 0x08;
259 + drive->ready_stat = READY_STAT;
260 + drive->bad_wstat = BAD_W_STAT;
261 + drive->special.b.recalibrate = 1;
262 + drive->special.b.set_geometry = 1;
263 + drive->name[0] = 'h';
264 + drive->name[1] = 'd';
265 + drive->name[2] = 'a' + (index * MAX_DRIVES) + unit;
266 + drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
267 + drive->using_dma = 0;
268 + drive->vdma = 0;
269 + INIT_LIST_HEAD(&drive->list);
270 + init_completion(&drive->gendev_rel_comp);
271 + }
272 +}
273 +
274 +static void init_hwif_default(ide_hwif_t *hwif, unsigned int index)
275 +{
276 + hw_regs_t hw;
277 +
278 + memset(&hw, 0, sizeof(hw_regs_t));
279 +
280 + ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
281 +
282 + memcpy(&hwif->hw, &hw, sizeof(hw));
283 + memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
284 +
285 + hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
286 +#ifdef CONFIG_BLK_DEV_HD
287 + if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
288 + hwif->noprobe = 1; /* may be overridden by ide_setup() */
289 +#endif
290 +}
291 +
292 +extern void ide_arm_init(void);
293 +
294 +/*
295 + * init_ide_data() sets reasonable default values into all fields
296 + * of all instances of the hwifs and drives, but only on the first call.
297 + * Subsequent calls have no effect (they don't wipe out anything).
298 + *
299 + * This routine is normally called at driver initialization time,
300 + * but may also be called MUCH earlier during kernel "command-line"
301 + * parameter processing. As such, we cannot depend on any other parts
302 + * of the kernel (such as memory allocation) to be functioning yet.
303 + *
304 + * This is too bad, as otherwise we could dynamically allocate the
305 + * ide_drive_t structs as needed, rather than always consuming memory
306 + * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
307 + *
308 + * FIXME: We should stuff the setup data into __init and copy the
309 + * relevant hwifs/allocate them properly during boot.
310 + */
311 +#define MAGIC_COOKIE 0x12345678
312 +static void __init init_ide_data (void)
313 +{
314 + ide_hwif_t *hwif;
315 + unsigned int index;
316 + static unsigned long magic_cookie = MAGIC_COOKIE;
317 +
318 + if (magic_cookie != MAGIC_COOKIE)
319 + return; /* already initialized */
320 + magic_cookie = 0;
321 +
322 + /* Initialise all interface structures */
323 + for (index = 0; index < MAX_HWIFS; ++index) {
324 + hwif = &ide_hwifs[index];
325 + init_hwif_data(hwif, index);
326 + init_hwif_default(hwif, index);
327 +#if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI)
328 + hwif->irq = hwif->hw.irq =
329 + ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]);
330 +#endif
331 + }
332 +#ifdef CONFIG_IDE_ARM
333 + initializing = 1;
334 + ide_arm_init();
335 + initializing = 0;
336 +#endif
337 +}
338 +
339 +/**
340 + * ide_system_bus_speed - guess bus speed
341 + *
342 + * ide_system_bus_speed() returns what we think is the system VESA/PCI
343 + * bus speed (in MHz). This is used for calculating interface PIO timings.
344 + * The default is 40 for known PCI systems, 50 otherwise.
345 + * The "idebus=xx" parameter can be used to override this value.
346 + * The actual value to be used is computed/displayed the first time
347 + * through. Drivers should only use this as a last resort.
348 + *
349 + * Returns a guessed speed in MHz.
350 + */
351 +
352 +static int ide_system_bus_speed(void)
353 +{
354 +#ifdef CONFIG_PCI
355 + static struct pci_device_id pci_default[] = {
356 + { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) },
357 + { }
358 + };
359 +#else
360 +#define pci_default 0
361 +#endif /* CONFIG_PCI */
362 +
363 + if (!system_bus_speed) {
364 + if (idebus_parameter) {
365 + /* user supplied value */
366 + system_bus_speed = idebus_parameter;
367 + } else if (pci_dev_present(pci_default)) {
368 + /* safe default value for PCI */
369 + system_bus_speed = 33;
370 + } else {
371 + /* safe default value for VESA and PCI */
372 + system_bus_speed = 50;
373 + }
374 + printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
375 + "for PIO modes%s\n", system_bus_speed,
376 + idebus_parameter ? "" : "; override with idebus=xx");
377 + }
378 + return system_bus_speed;
379 +}
380 +
381 +#ifdef CONFIG_PROC_FS
382 +struct proc_dir_entry *proc_ide_root;
383 +#endif
384 +
385 +static struct resource* hwif_request_region(ide_hwif_t *hwif,
386 + unsigned long addr, int num)
387 +{
388 + struct resource *res = request_region(addr, num, hwif->name);
389 +
390 + if (!res)
391 + printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
392 + hwif->name, addr, addr+num-1);
393 + return res;
394 +}
395 +
396 +/**
397 + * ide_hwif_request_regions - request resources for IDE
398 + * @hwif: interface to use
399 + *
400 + * Requests all the needed resources for an interface.
401 + * Right now core IDE code does this work which is deeply wrong.
402 + * MMIO leaves it to the controller driver,
403 + * PIO will migrate this way over time.
404 + */
405 +
406 +int ide_hwif_request_regions(ide_hwif_t *hwif)
407 +{
408 + unsigned long addr;
409 + unsigned int i;
410 +
411 + if (hwif->mmio == 2)
412 + return 0;
413 + BUG_ON(hwif->mmio == 1);
414 + addr = hwif->io_ports[IDE_CONTROL_OFFSET];
415 + if (addr && !hwif_request_region(hwif, addr, 1))
416 + goto control_region_busy;
417 + hwif->straight8 = 0;
418 + addr = hwif->io_ports[IDE_DATA_OFFSET];
419 + if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
420 + if (!hwif_request_region(hwif, addr, 8))
421 + goto data_region_busy;
422 + hwif->straight8 = 1;
423 + return 0;
424 + }
425 + for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
426 + addr = hwif->io_ports[i];
427 + if (!hwif_request_region(hwif, addr, 1)) {
428 + while (--i)
429 + release_region(addr, 1);
430 + goto data_region_busy;
431 + }
432 + }
433 + return 0;
434 +
435 +data_region_busy:
436 + addr = hwif->io_ports[IDE_CONTROL_OFFSET];
437 + if (addr)
438 + release_region(addr, 1);
439 +control_region_busy:
440 + /* If any errors are return, we drop the hwif interface. */
441 + return -EBUSY;
442 +}
443 +
444 +/**
445 + * ide_hwif_release_regions - free IDE resources
446 + *
447 + * Note that we only release the standard ports,
448 + * and do not even try to handle any extra ports
449 + * allocated for weird IDE interface chipsets.
450 + *
451 + * Note also that we don't yet handle mmio resources here. More
452 + * importantly our caller should be doing this so we need to
453 + * restructure this as a helper function for drivers.
454 + */
455 +
456 +void ide_hwif_release_regions(ide_hwif_t *hwif)
457 +{
458 + u32 i = 0;
459 +
460 + if (hwif->mmio == 2)
461 + return;
462 + if (hwif->io_ports[IDE_CONTROL_OFFSET])
463 + release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
464 + if (hwif->straight8) {
465 + release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
466 + return;
467 + }
468 + for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
469 + if (hwif->io_ports[i])
470 + release_region(hwif->io_ports[i], 1);
471 +}
472 +
473 +/**
474 + * ide_hwif_restore - restore hwif to template
475 + * @hwif: hwif to update
476 + * @tmp_hwif: template
477 + *
478 + * Restore hwif to a previous state by copying most settings
479 + * from the template.
480 + */
481 +
482 +static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
483 +{
484 + hwif->hwgroup = tmp_hwif->hwgroup;
485 +
486 + hwif->gendev.parent = tmp_hwif->gendev.parent;
487 +
488 + hwif->proc = tmp_hwif->proc;
489 +
490 + hwif->major = tmp_hwif->major;
491 + hwif->straight8 = tmp_hwif->straight8;
492 + hwif->bus_state = tmp_hwif->bus_state;
493 +
494 + hwif->atapi_dma = tmp_hwif->atapi_dma;
495 + hwif->ultra_mask = tmp_hwif->ultra_mask;
496 + hwif->mwdma_mask = tmp_hwif->mwdma_mask;
497 + hwif->swdma_mask = tmp_hwif->swdma_mask;
498 +
499 + hwif->chipset = tmp_hwif->chipset;
500 + hwif->hold = tmp_hwif->hold;
501 +
502 +#ifdef CONFIG_BLK_DEV_IDEPCI
503 + hwif->pci_dev = tmp_hwif->pci_dev;
504 + hwif->cds = tmp_hwif->cds;
505 +#endif
506 +
507 + hwif->tuneproc = tmp_hwif->tuneproc;
508 + hwif->speedproc = tmp_hwif->speedproc;
509 + hwif->selectproc = tmp_hwif->selectproc;
510 + hwif->reset_poll = tmp_hwif->reset_poll;
511 + hwif->pre_reset = tmp_hwif->pre_reset;
512 + hwif->resetproc = tmp_hwif->resetproc;
513 + hwif->intrproc = tmp_hwif->intrproc;
514 + hwif->maskproc = tmp_hwif->maskproc;
515 + hwif->quirkproc = tmp_hwif->quirkproc;
516 + hwif->busproc = tmp_hwif->busproc;
517 +
518 + hwif->ata_input_data = tmp_hwif->ata_input_data;
519 + hwif->ata_output_data = tmp_hwif->ata_output_data;
520 + hwif->atapi_input_bytes = tmp_hwif->atapi_input_bytes;
521 + hwif->atapi_output_bytes = tmp_hwif->atapi_output_bytes;
522 +
523 + hwif->dma_setup = tmp_hwif->dma_setup;
524 + hwif->dma_exec_cmd = tmp_hwif->dma_exec_cmd;
525 + hwif->dma_start = tmp_hwif->dma_start;
526 + hwif->ide_dma_end = tmp_hwif->ide_dma_end;
527 + hwif->ide_dma_check = tmp_hwif->ide_dma_check;
528 + hwif->ide_dma_on = tmp_hwif->ide_dma_on;
529 + hwif->ide_dma_off_quietly = tmp_hwif->ide_dma_off_quietly;
530 + hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq;
531 + hwif->ide_dma_host_on = tmp_hwif->ide_dma_host_on;
532 + hwif->ide_dma_host_off = tmp_hwif->ide_dma_host_off;
533 + hwif->ide_dma_lostirq = tmp_hwif->ide_dma_lostirq;
534 + hwif->ide_dma_timeout = tmp_hwif->ide_dma_timeout;
535 +
536 + hwif->OUTB = tmp_hwif->OUTB;
537 + hwif->OUTBSYNC = tmp_hwif->OUTBSYNC;
538 + hwif->OUTW = tmp_hwif->OUTW;
539 + hwif->OUTL = tmp_hwif->OUTL;
540 + hwif->OUTSW = tmp_hwif->OUTSW;
541 + hwif->OUTSL = tmp_hwif->OUTSL;
542 +
543 + hwif->INB = tmp_hwif->INB;
544 + hwif->INW = tmp_hwif->INW;
545 + hwif->INL = tmp_hwif->INL;
546 + hwif->INSW = tmp_hwif->INSW;
547 + hwif->INSL = tmp_hwif->INSL;
548 +
549 + hwif->sg_max_nents = tmp_hwif->sg_max_nents;
550 +
551 + hwif->mmio = tmp_hwif->mmio;
552 + hwif->rqsize = tmp_hwif->rqsize;
553 + hwif->no_lba48 = tmp_hwif->no_lba48;
554 +
555 +#ifndef CONFIG_BLK_DEV_IDECS
556 + hwif->irq = tmp_hwif->irq;
557 +#endif
558 +
559 + hwif->dma_base = tmp_hwif->dma_base;
560 + hwif->dma_master = tmp_hwif->dma_master;
561 + hwif->dma_command = tmp_hwif->dma_command;
562 + hwif->dma_vendor1 = tmp_hwif->dma_vendor1;
563 + hwif->dma_status = tmp_hwif->dma_status;
564 + hwif->dma_vendor3 = tmp_hwif->dma_vendor3;
565 + hwif->dma_prdtable = tmp_hwif->dma_prdtable;
566 +
567 + hwif->config_data = tmp_hwif->config_data;
568 + hwif->select_data = tmp_hwif->select_data;
569 + hwif->extra_base = tmp_hwif->extra_base;
570 + hwif->extra_ports = tmp_hwif->extra_ports;
571 + hwif->autodma = tmp_hwif->autodma;
572 + hwif->udma_four = tmp_hwif->udma_four;
573 + hwif->no_dsc = tmp_hwif->no_dsc;
574 +
575 + hwif->hwif_data = tmp_hwif->hwif_data;
576 +}
577 +
578 +/**
579 + * ide_unregister - free an IDE interface
580 + * @index: index of interface (will change soon to a pointer)
581 + *
582 + * Perform the final unregister of an IDE interface. At the moment
583 + * we don't refcount interfaces so this will also get split up.
584 + *
585 + * Locking:
586 + * The caller must not hold the IDE locks
587 + * The drive present/vanishing is not yet properly locked
588 + * Take care with the callbacks. These have been split to avoid
589 + * deadlocking the IDE layer. The shutdown callback is called
590 + * before we take the lock and free resources. It is up to the
591 + * caller to be sure there is no pending I/O here, and that
592 + * the interface will not be reopened (present/vanishing locking
593 + * isn't yet done BTW). After we commit to the final kill we
594 + * call the cleanup callback with the ide locks held.
595 + *
596 + * Unregister restores the hwif structures to the default state.
597 + * This is raving bonkers.
598 + */
599 +
600 +void ide_unregister(unsigned int index)
601 +{
602 + ide_drive_t *drive;
603 + ide_hwif_t *hwif, *g;
604 + static ide_hwif_t tmp_hwif; /* protected by ide_cfg_sem */
605 + ide_hwgroup_t *hwgroup;
606 + int irq_count = 0, unit;
607 +
608 + BUG_ON(index >= MAX_HWIFS);
609 +
610 + BUG_ON(in_interrupt());
611 + BUG_ON(irqs_disabled());
612 + down(&ide_cfg_sem);
613 + spin_lock_irq(&ide_lock);
614 + hwif = &ide_hwifs[index];
615 + if (!hwif->present)
616 + goto abort;
617 + for (unit = 0; unit < MAX_DRIVES; ++unit) {
618 + drive = &hwif->drives[unit];
619 + if (!drive->present)
620 + continue;
621 + spin_unlock_irq(&ide_lock);
622 + device_unregister(&drive->gendev);
623 + wait_for_completion(&drive->gendev_rel_comp);
624 + spin_lock_irq(&ide_lock);
625 + }
626 + hwif->present = 0;
627 +
628 + spin_unlock_irq(&ide_lock);
629 +
630 + destroy_proc_ide_interface(hwif);
631 +
632 + hwgroup = hwif->hwgroup;
633 + /*
634 + * free the irq if we were the only hwif using it
635 + */
636 + g = hwgroup->hwif;
637 + do {
638 + if (g->irq == hwif->irq)
639 + ++irq_count;
640 + g = g->next;
641 + } while (g != hwgroup->hwif);
642 + if (irq_count == 1)
643 + free_irq(hwif->irq, hwgroup);
644 +
645 + spin_lock_irq(&ide_lock);
646 + /*
647 + * Note that we only release the standard ports,
648 + * and do not even try to handle any extra ports
649 + * allocated for weird IDE interface chipsets.
650 + */
651 + ide_hwif_release_regions(hwif);
652 +
653 + /*
654 + * Remove us from the hwgroup, and free
655 + * the hwgroup if we were the only member
656 + */
657 + if (hwif->next == hwif) {
658 + BUG_ON(hwgroup->hwif != hwif);
659 + kfree(hwgroup);
660 + } else {
661 + /* There is another interface in hwgroup.
662 + * Unlink us, and set hwgroup->drive and ->hwif to
663 + * something sane.
664 + */
665 + g = hwgroup->hwif;
666 + while (g->next != hwif)
667 + g = g->next;
668 + g->next = hwif->next;
669 + if (hwgroup->hwif == hwif) {
670 + /* Chose a random hwif for hwgroup->hwif.
671 + * It's guaranteed that there are no drives
672 + * left in the hwgroup.
673 + */
674 + BUG_ON(hwgroup->drive != NULL);
675 + hwgroup->hwif = g;
676 + }
677 + BUG_ON(hwgroup->hwif == hwif);
678 + }
679 +
680 + /* More messed up locking ... */
681 + spin_unlock_irq(&ide_lock);
682 + device_unregister(&hwif->gendev);
683 + wait_for_completion(&hwif->gendev_rel_comp);
684 +
685 + /*
686 + * Remove us from the kernel's knowledge
687 + */
688 + blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
689 + kfree(hwif->sg_table);
690 + unregister_blkdev(hwif->major, hwif->name);
691 + spin_lock_irq(&ide_lock);
692 +
693 + if (hwif->dma_base) {
694 + (void) ide_release_dma(hwif);
695 +
696 + hwif->dma_base = 0;
697 + hwif->dma_master = 0;
698 + hwif->dma_command = 0;
699 + hwif->dma_vendor1 = 0;
700 + hwif->dma_status = 0;
701 + hwif->dma_vendor3 = 0;
702 + hwif->dma_prdtable = 0;
703 +
704 + hwif->extra_base = 0;
705 + hwif->extra_ports = 0;
706 + }
707 +
708 + /* copy original settings */
709 + tmp_hwif = *hwif;
710 +
711 + /* restore hwif data to pristine status */
712 + init_hwif_data(hwif, index);
713 + init_hwif_default(hwif, index);
714 +
715 + ide_hwif_restore(hwif, &tmp_hwif);
716 +
717 +abort:
718 + spin_unlock_irq(&ide_lock);
719 + up(&ide_cfg_sem);
720 +}
721 +
722 +EXPORT_SYMBOL(ide_unregister);
723 +
724 +
725 +/**
726 + * ide_setup_ports - set up IDE interface ports
727 + * @hw: register descriptions
728 + * @base: base register
729 + * @offsets: table of register offsets
730 + * @ctrl: control register
731 + * @ack_irq: IRQ ack
732 + * @irq: interrupt lie
733 + *
734 + * Setup hw_regs_t structure described by parameters. You
735 + * may set up the hw structure yourself OR use this routine to
736 + * do it for you. This is basically a helper
737 + *
738 + */
739 +
740 +void ide_setup_ports ( hw_regs_t *hw,
741 + unsigned long base, int *offsets,
742 + unsigned long ctrl, unsigned long intr,
743 + ide_ack_intr_t *ack_intr,
744 +/*
745 + * ide_io_ops_t *iops,
746 + */
747 + int irq)
748 +{
749 + int i;
750 +
751 + memset(hw, 0, sizeof(hw_regs_t));
752 + for (i = 0; i < IDE_NR_PORTS; i++) {
753 + if (offsets[i] == -1) {
754 + switch(i) {
755 + case IDE_CONTROL_OFFSET:
756 + hw->io_ports[i] = ctrl;
757 + break;
758 +#if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
759 + case IDE_IRQ_OFFSET:
760 + hw->io_ports[i] = intr;
761 + break;
762 +#endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
763 + default:
764 + hw->io_ports[i] = 0;
765 + break;
766 + }
767 + } else {
768 + hw->io_ports[i] = base + offsets[i];
769 + }
770 + }
771 + hw->irq = irq;
772 + hw->dma = NO_DMA;
773 + hw->ack_intr = ack_intr;
774 +/*
775 + * hw->iops = iops;
776 + */
777 +}
778 +
779 +/**
780 + * ide_register_hw_with_fixup - register IDE interface
781 + * @hw: hardware registers
782 + * @hwifp: pointer to returned hwif
783 + * @fixup: fixup function
784 + *
785 + * Register an IDE interface, specifying exactly the registers etc.
786 + * Set init=1 iff calling before probes have taken place.
787 + *
788 + * Returns -1 on error.
789 + */
790 +
791 +int ide_register_hw_with_fixup(hw_regs_t *hw, ide_hwif_t **hwifp, void(*fixup)(ide_hwif_t *hwif))
792 +{
793 + int index, retry = 1;
794 + ide_hwif_t *hwif;
795 +
796 + do {
797 + for (index = 0; index < MAX_HWIFS; ++index) {
798 + hwif = &ide_hwifs[index];
799 + if (hwif->hw.io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
800 + goto found;
801 + }
802 + for (index = 0; index < MAX_HWIFS; ++index) {
803 + hwif = &ide_hwifs[index];
804 + if (hwif->hold)
805 + continue;
806 + if ((!hwif->present && !hwif->mate && !initializing) ||
807 + (!hwif->hw.io_ports[IDE_DATA_OFFSET] && initializing))
808 + goto found;
809 + }
810 + for (index = 0; index < MAX_HWIFS; index++)
811 + ide_unregister(index);
812 + } while (retry--);
813 + return -1;
814 +found:
815 + if (hwif->present)
816 + ide_unregister(index);
817 + else if (!hwif->hold) {
818 + init_hwif_data(hwif, index);
819 + init_hwif_default(hwif, index);
820 + }
821 + if (hwif->present)
822 + return -1;
823 + memcpy(&hwif->hw, hw, sizeof(*hw));
824 + memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports));
825 + hwif->irq = hw->irq;
826 + hwif->noprobe = 0;
827 + hwif->chipset = hw->chipset;
828 + hwif->gendev.parent = hw->dev;
829 +
830 + if (!initializing) {
831 + probe_hwif_init_with_fixup(hwif, fixup);
832 + create_proc_ide_interfaces();
833 + }
834 +
835 + if (hwifp)
836 + *hwifp = hwif;
837 +
838 + return (initializing || hwif->present) ? index : -1;
839 +}
840 +
841 +EXPORT_SYMBOL(ide_register_hw_with_fixup);
842 +
843 +int ide_register_hw(hw_regs_t *hw, ide_hwif_t **hwifp)
844 +{
845 + return ide_register_hw_with_fixup(hw, hwifp, NULL);
846 +}
847 +
848 +EXPORT_SYMBOL(ide_register_hw);
849 +
850 +/*
851 + * Locks for IDE setting functionality
852 + */
853 +
854 +DECLARE_MUTEX(ide_setting_sem);
855 +
856 +/**
857 + * __ide_add_setting - add an ide setting option
858 + * @drive: drive to use
859 + * @name: setting name
860 + * @rw: true if the function is read write
861 + * @read_ioctl: function to call on read
862 + * @write_ioctl: function to call on write
863 + * @data_type: type of data
864 + * @min: range minimum
865 + * @max: range maximum
866 + * @mul_factor: multiplication scale
867 + * @div_factor: divison scale
868 + * @data: private data field
869 + * @set: setting
870 + * @auto_remove: setting auto removal flag
871 + *
872 + * Removes the setting named from the device if it is present.
873 + * The function takes the settings_lock to protect against
874 + * parallel changes. This function must not be called from IRQ
875 + * context. Returns 0 on success or -1 on failure.
876 + *
877 + * BUGS: This code is seriously over-engineered. There is also
878 + * magic about how the driver specific features are setup. If
879 + * a driver is attached we assume the driver settings are auto
880 + * remove.
881 + */
882 +
883 +static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set, int auto_remove)
884 +{
885 + ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
886 +
887 + down(&ide_setting_sem);
888 + while ((*p) && strcmp((*p)->name, name) < 0)
889 + p = &((*p)->next);
890 + if ((setting = kzalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
891 + goto abort;
892 + if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
893 + goto abort;
894 + strcpy(setting->name, name);
895 + setting->rw = rw;
896 + setting->read_ioctl = read_ioctl;
897 + setting->write_ioctl = write_ioctl;
898 + setting->data_type = data_type;
899 + setting->min = min;
900 + setting->max = max;
901 + setting->mul_factor = mul_factor;
902 + setting->div_factor = div_factor;
903 + setting->data = data;
904 + setting->set = set;
905 +
906 + setting->next = *p;
907 + if (auto_remove)
908 + setting->auto_remove = 1;
909 + *p = setting;
910 + up(&ide_setting_sem);
911 + return 0;
912 +abort:
913 + up(&ide_setting_sem);
914 + kfree(setting);
915 + return -1;
916 +}
917 +
918 +int ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set)
919 +{
920 + return __ide_add_setting(drive, name, rw, read_ioctl, write_ioctl, data_type, min, max, mul_factor, div_factor, data, set, 1);
921 +}
922 +
923 +EXPORT_SYMBOL(ide_add_setting);
924 +
925 +/**
926 + * __ide_remove_setting - remove an ide setting option
927 + * @drive: drive to use
928 + * @name: setting name
929 + *
930 + * Removes the setting named from the device if it is present.
931 + * The caller must hold the setting semaphore.
932 + */
933 +
934 +static void __ide_remove_setting (ide_drive_t *drive, char *name)
935 +{
936 + ide_settings_t **p, *setting;
937 +
938 + p = (ide_settings_t **) &drive->settings;
939 +
940 + while ((*p) && strcmp((*p)->name, name))
941 + p = &((*p)->next);
942 + if ((setting = (*p)) == NULL)
943 + return;
944 +
945 + (*p) = setting->next;
946 +
947 + kfree(setting->name);
948 + kfree(setting);
949 +}
950 +
951 +/**
952 + * ide_find_setting_by_ioctl - find a drive specific ioctl
953 + * @drive: drive to scan
954 + * @cmd: ioctl command to handle
955 + *
956 + * Scan's the device setting table for a matching entry and returns
957 + * this or NULL if no entry is found. The caller must hold the
958 + * setting semaphore
959 + */
960 +
961 +static ide_settings_t *ide_find_setting_by_ioctl (ide_drive_t *drive, int cmd)
962 +{
963 + ide_settings_t *setting = drive->settings;
964 +
965 + while (setting) {
966 + if (setting->read_ioctl == cmd || setting->write_ioctl == cmd)
967 + break;
968 + setting = setting->next;
969 + }
970 +
971 + return setting;
972 +}
973 +
974 +/**
975 + * ide_find_setting_by_name - find a drive specific setting
976 + * @drive: drive to scan
977 + * @name: setting name
978 + *
979 + * Scan's the device setting table for a matching entry and returns
980 + * this or NULL if no entry is found. The caller must hold the
981 + * setting semaphore
982 + */
983 +
984 +ide_settings_t *ide_find_setting_by_name (ide_drive_t *drive, char *name)
985 +{
986 + ide_settings_t *setting = drive->settings;
987 +
988 + while (setting) {
989 + if (strcmp(setting->name, name) == 0)
990 + break;
991 + setting = setting->next;
992 + }
993 + return setting;
994 +}
995 +
996 +/**
997 + * auto_remove_settings - remove driver specific settings
998 + * @drive: drive
999 + *
1000 + * Automatically remove all the driver specific settings for this
1001 + * drive. This function may sleep and must not be called from IRQ
1002 + * context. The caller must hold ide_setting_sem.
1003 + */
1004 +
1005 +static void auto_remove_settings (ide_drive_t *drive)
1006 +{
1007 + ide_settings_t *setting;
1008 +repeat:
1009 + setting = drive->settings;
1010 + while (setting) {
1011 + if (setting->auto_remove) {
1012 + __ide_remove_setting(drive, setting->name);
1013 + goto repeat;
1014 + }
1015 + setting = setting->next;
1016 + }
1017 +}
1018 +
1019 +/**
1020 + * ide_read_setting - read an IDE setting
1021 + * @drive: drive to read from
1022 + * @setting: drive setting
1023 + *
1024 + * Read a drive setting and return the value. The caller
1025 + * must hold the ide_setting_sem when making this call.
1026 + *
1027 + * BUGS: the data return and error are the same return value
1028 + * so an error -EINVAL and true return of the same value cannot
1029 + * be told apart
1030 + */
1031 +
1032 +int ide_read_setting (ide_drive_t *drive, ide_settings_t *setting)
1033 +{
1034 + int val = -EINVAL;
1035 + unsigned long flags;
1036 +
1037 + if ((setting->rw & SETTING_READ)) {
1038 + spin_lock_irqsave(&ide_lock, flags);
1039 + switch(setting->data_type) {
1040 + case TYPE_BYTE:
1041 + val = *((u8 *) setting->data);
1042 + break;
1043 + case TYPE_SHORT:
1044 + val = *((u16 *) setting->data);
1045 + break;
1046 + case TYPE_INT:
1047 + case TYPE_INTA:
1048 + val = *((u32 *) setting->data);
1049 + break;
1050 + }
1051 + spin_unlock_irqrestore(&ide_lock, flags);
1052 + }
1053 + return val;
1054 +}
1055 +
1056 +/**
1057 + * ide_spin_wait_hwgroup - wait for group
1058 + * @drive: drive in the group
1059 + *
1060 + * Wait for an IDE device group to go non busy and then return
1061 + * holding the ide_lock which guards the hwgroup->busy status
1062 + * and right to use it.
1063 + */
1064 +
1065 +int ide_spin_wait_hwgroup (ide_drive_t *drive)
1066 +{
1067 + ide_hwgroup_t *hwgroup = HWGROUP(drive);
1068 + unsigned long timeout = jiffies + (3 * HZ);
1069 +
1070 + spin_lock_irq(&ide_lock);
1071 +
1072 + while (hwgroup->busy) {
1073 + unsigned long lflags;
1074 + spin_unlock_irq(&ide_lock);
1075 + local_irq_set(lflags);
1076 + if (time_after(jiffies, timeout)) {
1077 + local_irq_restore(lflags);
1078 + printk(KERN_ERR "%s: channel busy\n", drive->name);
1079 + return -EBUSY;
1080 + }
1081 + local_irq_restore(lflags);
1082 + spin_lock_irq(&ide_lock);
1083 + }
1084 + return 0;
1085 +}
1086 +
1087 +EXPORT_SYMBOL(ide_spin_wait_hwgroup);
1088 +
1089 +/**
1090 + * ide_write_setting - read an IDE setting
1091 + * @drive: drive to read from
1092 + * @setting: drive setting
1093 + * @val: value
1094 + *
1095 + * Write a drive setting if it is possible. The caller
1096 + * must hold the ide_setting_sem when making this call.
1097 + *
1098 + * BUGS: the data return and error are the same return value
1099 + * so an error -EINVAL and true return of the same value cannot
1100 + * be told apart
1101 + *
1102 + * FIXME: This should be changed to enqueue a special request
1103 + * to the driver to change settings, and then wait on a sema for completion.
1104 + * The current scheme of polling is kludgy, though safe enough.
1105 + */
1106 +
1107 +int ide_write_setting (ide_drive_t *drive, ide_settings_t *setting, int val)
1108 +{
1109 + int i;
1110 + u32 *p;
1111 +
1112 + if (!capable(CAP_SYS_ADMIN))
1113 + return -EACCES;
1114 + if (!(setting->rw & SETTING_WRITE))
1115 + return -EPERM;
1116 + if (val < setting->min || val > setting->max)
1117 + return -EINVAL;
1118 + if (setting->set)
1119 + return setting->set(drive, val);
1120 + if (ide_spin_wait_hwgroup(drive))
1121 + return -EBUSY;
1122 + switch (setting->data_type) {
1123 + case TYPE_BYTE:
1124 + *((u8 *) setting->data) = val;
1125 + break;
1126 + case TYPE_SHORT:
1127 + *((u16 *) setting->data) = val;
1128 + break;
1129 + case TYPE_INT:
1130 + *((u32 *) setting->data) = val;
1131 + break;
1132 + case TYPE_INTA:
1133 + p = (u32 *) setting->data;
1134 + for (i = 0; i < 1 << PARTN_BITS; i++, p++)
1135 + *p = val;
1136 + break;
1137 + }
1138 + spin_unlock_irq(&ide_lock);
1139 + return 0;
1140 +}
1141 +
1142 +static int set_io_32bit(ide_drive_t *drive, int arg)
1143 +{
1144 + drive->io_32bit = arg;
1145 +#ifdef CONFIG_BLK_DEV_DTC2278
1146 + if (HWIF(drive)->chipset == ide_dtc2278)
1147 + HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
1148 +#endif /* CONFIG_BLK_DEV_DTC2278 */
1149 + return 0;
1150 +}
1151 +
1152 +static int set_using_dma (ide_drive_t *drive, int arg)
1153 +{
1154 +#ifdef CONFIG_BLK_DEV_IDEDMA
1155 + if (!drive->id || !(drive->id->capability & 1))
1156 + return -EPERM;
1157 + if (HWIF(drive)->ide_dma_check == NULL)
1158 + return -EPERM;
1159 + if (arg) {
1160 + if (HWIF(drive)->ide_dma_check(drive)) return -EIO;
1161 + if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
1162 + } else {
1163 + if (__ide_dma_off(drive))
1164 + return -EIO;
1165 + }
1166 + return 0;
1167 +#else
1168 + return -EPERM;
1169 +#endif
1170 +}
1171 +
1172 +static int set_pio_mode (ide_drive_t *drive, int arg)
1173 +{
1174 + struct request rq;
1175 +
1176 + if (!HWIF(drive)->tuneproc)
1177 + return -ENOSYS;
1178 + if (drive->special.b.set_tune)
1179 + return -EBUSY;
1180 + ide_init_drive_cmd(&rq);
1181 + drive->tune_req = (u8) arg;
1182 + drive->special.b.set_tune = 1;
1183 + (void) ide_do_drive_cmd(drive, &rq, ide_wait);
1184 + return 0;
1185 +}
1186 +
1187 +static int set_xfer_rate (ide_drive_t *drive, int arg)
1188 +{
1189 + int err = ide_wait_cmd(drive,
1190 + WIN_SETFEATURES, (u8) arg,
1191 + SETFEATURES_XFER, 0, NULL);
1192 +
1193 + if (!err && arg) {
1194 + ide_set_xfer_rate(drive, (u8) arg);
1195 + ide_driveid_update(drive);
1196 + }
1197 + return err;
1198 +}
1199 +
1200 +/**
1201 + * ide_add_generic_settings - generic ide settings
1202 + * @drive: drive being configured
1203 + *
1204 + * Add the generic parts of the system settings to the /proc files and
1205 + * ioctls for this IDE device. The caller must not be holding the
1206 + * ide_setting_sem.
1207 + */
1208 +
1209 +void ide_add_generic_settings (ide_drive_t *drive)
1210 +{
1211 +/*
1212 + * drive setting name read/write access read ioctl write ioctl data type min max mul_factor div_factor data pointer set function
1213 + */
1214 + __ide_add_setting(drive, "io_32bit", drive->no_io_32bit ? SETTING_READ : SETTING_RW, HDIO_GET_32BIT, HDIO_SET_32BIT, TYPE_BYTE, 0, 1 + (SUPPORT_VLB_SYNC << 1), 1, 1, &drive->io_32bit, set_io_32bit, 0);
1215 + __ide_add_setting(drive, "keepsettings", SETTING_RW, HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL, 0);
1216 + __ide_add_setting(drive, "nice1", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL, 0);
1217 + __ide_add_setting(drive, "pio_mode", SETTING_WRITE, -1, HDIO_SET_PIO_MODE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode, 0);
1218 + __ide_add_setting(drive, "unmaskirq", drive->no_unmask ? SETTING_READ : SETTING_RW, HDIO_GET_UNMASKINTR, HDIO_SET_UNMASKINTR, TYPE_BYTE, 0, 1, 1, 1, &drive->unmask, NULL, 0);
1219 + __ide_add_setting(drive, "using_dma", SETTING_RW, HDIO_GET_DMA, HDIO_SET_DMA, TYPE_BYTE, 0, 1, 1, 1, &drive->using_dma, set_using_dma, 0);
1220 + __ide_add_setting(drive, "init_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL, 0);
1221 + __ide_add_setting(drive, "current_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate, 0);
1222 + __ide_add_setting(drive, "number", SETTING_RW, -1, -1, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL, 0);
1223 +}
1224 +
1225 +/**
1226 + * system_bus_clock - clock guess
1227 + *
1228 + * External version of the bus clock guess used by very old IDE drivers
1229 + * for things like VLB timings. Should not be used.
1230 + */
1231 +
1232 +int system_bus_clock (void)
1233 +{
1234 + return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
1235 +}
1236 +
1237 +EXPORT_SYMBOL(system_bus_clock);
1238 +
1239 +static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
1240 +{
1241 + ide_drive_t *drive = dev->driver_data;
1242 + struct request rq;
1243 + struct request_pm_state rqpm;
1244 + ide_task_t args;
1245 +
1246 + memset(&rq, 0, sizeof(rq));
1247 + memset(&rqpm, 0, sizeof(rqpm));
1248 + memset(&args, 0, sizeof(args));
1249 + rq.cmd_type = REQ_TYPE_PM_SUSPEND;
1250 + rq.special = &args;
1251 + rq.data = &rqpm;
1252 + rqpm.pm_step = ide_pm_state_start_suspend;
1253 + if (mesg.event == PM_EVENT_PRETHAW)
1254 + mesg.event = PM_EVENT_FREEZE;
1255 + rqpm.pm_state = mesg.event;
1256 +
1257 + return ide_do_drive_cmd(drive, &rq, ide_wait);
1258 +}
1259 +
1260 +static int generic_ide_resume(struct device *dev)
1261 +{
1262 + ide_drive_t *drive = dev->driver_data;
1263 + struct request rq;
1264 + struct request_pm_state rqpm;
1265 + ide_task_t args;
1266 +
1267 + memset(&rq, 0, sizeof(rq));
1268 + memset(&rqpm, 0, sizeof(rqpm));
1269 + memset(&args, 0, sizeof(args));
1270 + rq.cmd_type = REQ_TYPE_PM_RESUME;
1271 + rq.special = &args;
1272 + rq.data = &rqpm;
1273 + rqpm.pm_step = ide_pm_state_start_resume;
1274 + rqpm.pm_state = PM_EVENT_ON;
1275 +
1276 + return ide_do_drive_cmd(drive, &rq, ide_head_wait);
1277 +}
1278 +
1279 +int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
1280 + unsigned int cmd, unsigned long arg)
1281 +{
1282 + ide_settings_t *setting;
1283 + ide_driver_t *drv;
1284 + int err = 0;
1285 + void __user *p = (void __user *)arg;
1286 +
1287 + down(&ide_setting_sem);
1288 + if ((setting = ide_find_setting_by_ioctl(drive, cmd)) != NULL) {
1289 + if (cmd == setting->read_ioctl) {
1290 + err = ide_read_setting(drive, setting);
1291 + up(&ide_setting_sem);
1292 + return err >= 0 ? put_user(err, (long __user *)arg) : err;
1293 + } else {
1294 + if (bdev != bdev->bd_contains)
1295 + err = -EINVAL;
1296 + else
1297 + err = ide_write_setting(drive, setting, arg);
1298 + up(&ide_setting_sem);
1299 + return err;
1300 + }
1301 + }
1302 + up(&ide_setting_sem);
1303 +
1304 + switch (cmd) {
1305 + case HDIO_OBSOLETE_IDENTITY:
1306 + case HDIO_GET_IDENTITY:
1307 + if (bdev != bdev->bd_contains)
1308 + return -EINVAL;
1309 + if (drive->id_read == 0)
1310 + return -ENOMSG;
1311 + if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
1312 + return -EFAULT;
1313 + return 0;
1314 +
1315 + case HDIO_GET_NICE:
1316 + return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
1317 + drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
1318 + drive->nice0 << IDE_NICE_0 |
1319 + drive->nice1 << IDE_NICE_1 |
1320 + drive->nice2 << IDE_NICE_2,
1321 + (long __user *) arg);
1322 +
1323 +#ifdef CONFIG_IDE_TASK_IOCTL
1324 + case HDIO_DRIVE_TASKFILE:
1325 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1326 + return -EACCES;
1327 + switch(drive->media) {
1328 + case ide_disk:
1329 + return ide_taskfile_ioctl(drive, cmd, arg);
1330 + default:
1331 + return -ENOMSG;
1332 + }
1333 +#endif /* CONFIG_IDE_TASK_IOCTL */
1334 +
1335 + case HDIO_DRIVE_CMD:
1336 + if (!capable(CAP_SYS_RAWIO))
1337 + return -EACCES;
1338 + return ide_cmd_ioctl(drive, cmd, arg);
1339 +
1340 + case HDIO_DRIVE_TASK:
1341 + if (!capable(CAP_SYS_RAWIO))
1342 + return -EACCES;
1343 + return ide_task_ioctl(drive, cmd, arg);
1344 +
1345 + case HDIO_SCAN_HWIF:
1346 + {
1347 + hw_regs_t hw;
1348 + int args[3];
1349 + if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1350 + if (copy_from_user(args, p, 3 * sizeof(int)))
1351 + return -EFAULT;
1352 + memset(&hw, 0, sizeof(hw));
1353 + ide_init_hwif_ports(&hw, (unsigned long) args[0],
1354 + (unsigned long) args[1], NULL);
1355 + hw.irq = args[2];
1356 + if (ide_register_hw(&hw, NULL) == -1)
1357 + return -EIO;
1358 + return 0;
1359 + }
1360 + case HDIO_UNREGISTER_HWIF:
1361 + if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1362 + /* (arg > MAX_HWIFS) checked in function */
1363 + ide_unregister(arg);
1364 + return 0;
1365 + case HDIO_SET_NICE:
1366 + if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1367 + if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
1368 + return -EPERM;
1369 + drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
1370 + drv = *(ide_driver_t **)bdev->bd_disk->private_data;
1371 + if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
1372 + drive->dsc_overlap = 0;
1373 + return -EPERM;
1374 + }
1375 + drive->nice1 = (arg >> IDE_NICE_1) & 1;
1376 + return 0;
1377 + case HDIO_DRIVE_RESET:
1378 + {
1379 + unsigned long flags;
1380 + if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1381 +
1382 + /*
1383 + * Abort the current command on the
1384 + * group if there is one, taking
1385 + * care not to allow anything else
1386 + * to be queued and to die on the
1387 + * spot if we miss one somehow
1388 + */
1389 +
1390 + spin_lock_irqsave(&ide_lock, flags);
1391 +
1392 + if (HWGROUP(drive)->resetting) {
1393 + spin_unlock_irqrestore(&ide_lock, flags);
1394 + return -EBUSY;
1395 + }
1396 +
1397 + ide_abort(drive, "drive reset");
1398 +
1399 + BUG_ON(HWGROUP(drive)->handler);
1400 +
1401 + /* Ensure nothing gets queued after we
1402 + drop the lock. Reset will clear the busy */
1403 +
1404 + HWGROUP(drive)->busy = 1;
1405 + spin_unlock_irqrestore(&ide_lock, flags);
1406 + (void) ide_do_reset(drive);
1407 +
1408 + return 0;
1409 + }
1410 +
1411 + case CDROMEJECT:
1412 + case CDROMCLOSETRAY:
1413 + return scsi_cmd_ioctl(file, bdev->bd_disk, cmd, p);
1414 +
1415 + case HDIO_GET_BUSSTATE:
1416 + if (!capable(CAP_SYS_ADMIN))
1417 + return -EACCES;
1418 + if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
1419 + return -EFAULT;
1420 + return 0;
1421 +
1422 + case HDIO_SET_BUSSTATE:
1423 + if (!capable(CAP_SYS_ADMIN))
1424 + return -EACCES;
1425 + if (HWIF(drive)->busproc)
1426 + return HWIF(drive)->busproc(drive, (int)arg);
1427 + return -EOPNOTSUPP;
1428 + default:
1429 + return -EINVAL;
1430 + }
1431 +}
1432 +
1433 +EXPORT_SYMBOL(generic_ide_ioctl);
1434 +
1435 +/*
1436 + * stridx() returns the offset of c within s,
1437 + * or -1 if c is '\0' or not found within s.
1438 + */
1439 +static int __init stridx (const char *s, char c)
1440 +{
1441 + char *i = strchr(s, c);
1442 + return (i && c) ? i - s : -1;
1443 +}
1444 +
1445 +/*
1446 + * match_parm() does parsing for ide_setup():
1447 + *
1448 + * 1. the first char of s must be '='.
1449 + * 2. if the remainder matches one of the supplied keywords,
1450 + * the index (1 based) of the keyword is negated and returned.
1451 + * 3. if the remainder is a series of no more than max_vals numbers
1452 + * separated by commas, the numbers are saved in vals[] and a
1453 + * count of how many were saved is returned. Base10 is assumed,
1454 + * and base16 is allowed when prefixed with "0x".
1455 + * 4. otherwise, zero is returned.
1456 + */
1457 +static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
1458 +{
1459 + static const char *decimal = "0123456789";
1460 + static const char *hex = "0123456789abcdef";
1461 + int i, n;
1462 +
1463 + if (*s++ == '=') {
1464 + /*
1465 + * Try matching against the supplied keywords,
1466 + * and return -(index+1) if we match one
1467 + */
1468 + if (keywords != NULL) {
1469 + for (i = 0; *keywords != NULL; ++i) {
1470 + if (!strcmp(s, *keywords++))
1471 + return -(i+1);
1472 + }
1473 + }
1474 + /*
1475 + * Look for a series of no more than "max_vals"
1476 + * numeric values separated by commas, in base10,
1477 + * or base16 when prefixed with "0x".
1478 + * Return a count of how many were found.
1479 + */
1480 + for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
1481 + vals[n] = i;
1482 + while ((i = stridx(decimal, *++s)) >= 0)
1483 + vals[n] = (vals[n] * 10) + i;
1484 + if (*s == 'x' && !vals[n]) {
1485 + while ((i = stridx(hex, *++s)) >= 0)
1486 + vals[n] = (vals[n] * 0x10) + i;
1487 + }
1488 + if (++n == max_vals)
1489 + break;
1490 + if (*s == ',' || *s == ';')
1491 + ++s;
1492 + }
1493 + if (!*s)
1494 + return n;
1495 + }
1496 + return 0; /* zero = nothing matched */
1497 +}
1498 +
1499 +#ifdef CONFIG_BLK_DEV_ALI14XX
1500 +static int __initdata probe_ali14xx;
1501 +extern int ali14xx_init(void);
1502 +#endif
1503 +#ifdef CONFIG_BLK_DEV_UMC8672
1504 +static int __initdata probe_umc8672;
1505 +extern int umc8672_init(void);
1506 +#endif
1507 +#ifdef CONFIG_BLK_DEV_DTC2278
1508 +static int __initdata probe_dtc2278;
1509 +extern int dtc2278_init(void);
1510 +#endif
1511 +#ifdef CONFIG_BLK_DEV_HT6560B
1512 +static int __initdata probe_ht6560b;
1513 +extern int ht6560b_init(void);
1514 +#endif
1515 +#ifdef CONFIG_BLK_DEV_QD65XX
1516 +static int __initdata probe_qd65xx;
1517 +extern int qd65xx_init(void);
1518 +#endif
1519 +
1520 +static int __initdata is_chipset_set[MAX_HWIFS];
1521 +
1522 +/*
1523 + * ide_setup() gets called VERY EARLY during initialization,
1524 + * to handle kernel "command line" strings beginning with "hdx=" or "ide".
1525 + *
1526 + * Remember to update Documentation/ide.txt if you change something here.
1527 + */
1528 +static int __init ide_setup(char *s)
1529 +{
1530 + int i, vals[3];
1531 + ide_hwif_t *hwif;
1532 + ide_drive_t *drive;
1533 + unsigned int hw, unit;
1534 + const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
1535 + const char max_hwif = '0' + (MAX_HWIFS - 1);
1536 +
1537 +
1538 + if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
1539 + return 0; /* driver and not us */
1540 +
1541 + if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
1542 + return 0;
1543 +
1544 + printk(KERN_INFO "ide_setup: %s", s);
1545 + init_ide_data ();
1546 +
1547 +#ifdef CONFIG_BLK_DEV_IDEDOUBLER
1548 + if (!strcmp(s, "ide=doubler")) {
1549 + extern int ide_doubler;
1550 +
1551 + printk(" : Enabled support for IDE doublers\n");
1552 + ide_doubler = 1;
1553 + return 1;
1554 + }
1555 +#endif /* CONFIG_BLK_DEV_IDEDOUBLER */
1556 +
1557 + if (!strcmp(s, "ide=nodma")) {
1558 + printk(" : Prevented DMA\n");
1559 + noautodma = 1;
1560 + return 1;
1561 + }
1562 +
1563 +#ifdef CONFIG_BLK_DEV_IDEPCI
1564 + if (!strcmp(s, "ide=reverse")) {
1565 + ide_scan_direction = 1;
1566 + printk(" : Enabled support for IDE inverse scan order.\n");
1567 + return 1;
1568 + }
1569 +#endif /* CONFIG_BLK_DEV_IDEPCI */
1570 +
1571 + /*
1572 + * Look for drive options: "hdx="
1573 + */
1574 + if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
1575 + const char *hd_words[] = {
1576 + "none", "noprobe", "nowerr", "cdrom", "serialize",
1577 + "autotune", "noautotune", "minus8", "swapdata", "bswap",
1578 + "noflush", "remap", "remap63", "scsi", NULL };
1579 + unit = s[2] - 'a';
1580 + hw = unit / MAX_DRIVES;
1581 + unit = unit % MAX_DRIVES;
1582 + hwif = &ide_hwifs[hw];
1583 + drive = &hwif->drives[unit];
1584 + if (strncmp(s + 4, "ide-", 4) == 0) {
1585 + strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
1586 + goto done;
1587 + }
1588 + switch (match_parm(&s[3], hd_words, vals, 3)) {
1589 + case -1: /* "none" */
1590 + case -2: /* "noprobe" */
1591 + drive->noprobe = 1;
1592 + goto done;
1593 + case -3: /* "nowerr" */
1594 + drive->bad_wstat = BAD_R_STAT;
1595 + hwif->noprobe = 0;
1596 + goto done;
1597 + case -4: /* "cdrom" */
1598 + drive->present = 1;
1599 + drive->media = ide_cdrom;
1600 + /* an ATAPI device ignores DRDY */
1601 + drive->ready_stat = 0;
1602 + hwif->noprobe = 0;
1603 + goto done;
1604 + case -5: /* "serialize" */
1605 + printk(" -- USE \"ide%d=serialize\" INSTEAD", hw);
1606 + goto do_serialize;
1607 + case -6: /* "autotune" */
1608 + drive->autotune = IDE_TUNE_AUTO;
1609 + goto obsolete_option;
1610 + case -7: /* "noautotune" */
1611 + drive->autotune = IDE_TUNE_NOAUTO;
1612 + goto obsolete_option;
1613 + case -9: /* "swapdata" */
1614 + case -10: /* "bswap" */
1615 + drive->bswap = 1;
1616 + goto done;
1617 + case -11: /* noflush */
1618 + drive->noflush = 1;
1619 + goto done;
1620 + case -12: /* "remap" */
1621 + drive->remap_0_to_1 = 1;
1622 + goto done;
1623 + case -13: /* "remap63" */
1624 + drive->sect0 = 63;
1625 + goto done;
1626 + case -14: /* "scsi" */
1627 + drive->scsi = 1;
1628 + goto done;
1629 + case 3: /* cyl,head,sect */
1630 + drive->media = ide_disk;
1631 + drive->ready_stat = READY_STAT;
1632 + drive->cyl = drive->bios_cyl = vals[0];
1633 + drive->head = drive->bios_head = vals[1];
1634 + drive->sect = drive->bios_sect = vals[2];
1635 + drive->present = 1;
1636 + drive->forced_geom = 1;
1637 + hwif->noprobe = 0;
1638 + goto done;
1639 + default:
1640 + goto bad_option;
1641 + }
1642 + }
1643 +
1644 + if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
1645 + goto bad_option;
1646 + /*
1647 + * Look for bus speed option: "idebus="
1648 + */
1649 + if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
1650 + if (match_parm(&s[6], NULL, vals, 1) != 1)
1651 + goto bad_option;
1652 + if (vals[0] >= 20 && vals[0] <= 66) {
1653 + idebus_parameter = vals[0];
1654 + } else
1655 + printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
1656 + goto done;
1657 + }
1658 + /*
1659 + * Look for interface options: "idex="
1660 + */
1661 + if (s[3] >= '0' && s[3] <= max_hwif) {
1662 + /*
1663 + * Be VERY CAREFUL changing this: note hardcoded indexes below
1664 + * (-8, -9, -10) are reserved to ease the hardcoding.
1665 + */
1666 + static const char *ide_words[] = {
1667 + "noprobe", "serialize", "autotune", "noautotune",
1668 + "reset", "dma", "ata66", "minus8", "minus9",
1669 + "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
1670 + "dtc2278", "umc8672", "ali14xx", NULL };
1671 + hw = s[3] - '0';
1672 + hwif = &ide_hwifs[hw];
1673 + i = match_parm(&s[4], ide_words, vals, 3);
1674 +
1675 + /*
1676 + * Cryptic check to ensure chipset not already set for hwif.
1677 + * Note: we can't depend on hwif->chipset here.
1678 + */
1679 + if ((i >= -18 && i <= -11) || (i > 0 && i <= 3)) {
1680 + /* chipset already specified */
1681 + if (is_chipset_set[hw])
1682 + goto bad_option;
1683 + if (i > -18 && i <= -11) {
1684 + /* these drivers are for "ide0=" only */
1685 + if (hw != 0)
1686 + goto bad_hwif;
1687 + /* chipset already specified for 2nd port */
1688 + if (is_chipset_set[hw+1])
1689 + goto bad_option;
1690 + }
1691 + is_chipset_set[hw] = 1;
1692 + printk("\n");
1693 + }
1694 +
1695 + switch (i) {
1696 +#ifdef CONFIG_BLK_DEV_ALI14XX
1697 + case -17: /* "ali14xx" */
1698 + probe_ali14xx = 1;
1699 + goto done;
1700 +#endif
1701 +#ifdef CONFIG_BLK_DEV_UMC8672
1702 + case -16: /* "umc8672" */
1703 + probe_umc8672 = 1;
1704 + goto done;
1705 +#endif
1706 +#ifdef CONFIG_BLK_DEV_DTC2278
1707 + case -15: /* "dtc2278" */
1708 + probe_dtc2278 = 1;
1709 + goto done;
1710 +#endif
1711 +#ifdef CONFIG_BLK_DEV_CMD640
1712 + case -14: /* "cmd640_vlb" */
1713 + {
1714 + extern int cmd640_vlb; /* flag for cmd640.c */
1715 + cmd640_vlb = 1;
1716 + goto done;
1717 + }
1718 +#endif
1719 +#ifdef CONFIG_BLK_DEV_HT6560B
1720 + case -13: /* "ht6560b" */
1721 + probe_ht6560b = 1;
1722 + goto done;
1723 +#endif
1724 +#ifdef CONFIG_BLK_DEV_QD65XX
1725 + case -12: /* "qd65xx" */
1726 + probe_qd65xx = 1;
1727 + goto done;
1728 +#endif
1729 +#ifdef CONFIG_BLK_DEV_4DRIVES
1730 + case -11: /* "four" drives on one set of ports */
1731 + {
1732 + ide_hwif_t *mate = &ide_hwifs[hw^1];
1733 + mate->drives[0].select.all ^= 0x20;
1734 + mate->drives[1].select.all ^= 0x20;
1735 + hwif->chipset = mate->chipset = ide_4drives;
1736 + mate->irq = hwif->irq;
1737 + memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
1738 + goto do_serialize;
1739 + }
1740 +#endif /* CONFIG_BLK_DEV_4DRIVES */
1741 + case -10: /* minus10 */
1742 + case -9: /* minus9 */
1743 + case -8: /* minus8 */
1744 + goto bad_option;
1745 + case -7: /* ata66 */
1746 +#ifdef CONFIG_BLK_DEV_IDEPCI
1747 + hwif->udma_four = 1;
1748 + goto obsolete_option;
1749 +#else
1750 + goto bad_hwif;
1751 +#endif
1752 + case -6: /* dma */
1753 + hwif->autodma = 1;
1754 + goto obsolete_option;
1755 + case -5: /* "reset" */
1756 + hwif->reset = 1;
1757 + goto obsolete_option;
1758 + case -4: /* "noautotune" */
1759 + hwif->drives[0].autotune = IDE_TUNE_NOAUTO;
1760 + hwif->drives[1].autotune = IDE_TUNE_NOAUTO;
1761 + goto obsolete_option;
1762 + case -3: /* "autotune" */
1763 + hwif->drives[0].autotune = IDE_TUNE_AUTO;
1764 + hwif->drives[1].autotune = IDE_TUNE_AUTO;
1765 + goto obsolete_option;
1766 + case -2: /* "serialize" */
1767 + do_serialize:
1768 + hwif->mate = &ide_hwifs[hw^1];
1769 + hwif->mate->mate = hwif;
1770 + hwif->serialized = hwif->mate->serialized = 1;
1771 + goto obsolete_option;
1772 +
1773 + case -1: /* "noprobe" */
1774 + hwif->noprobe = 1;
1775 + goto done;
1776 +
1777 + case 1: /* base */
1778 + vals[1] = vals[0] + 0x206; /* default ctl */
1779 + case 2: /* base,ctl */
1780 + vals[2] = 0; /* default irq = probe for it */
1781 + case 3: /* base,ctl,irq */
1782 + hwif->hw.irq = vals[2];
1783 + ide_init_hwif_ports(&hwif->hw, (unsigned long) vals[0], (unsigned long) vals[1], &hwif->irq);
1784 + memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
1785 + hwif->irq = vals[2];
1786 + hwif->noprobe = 0;
1787 + hwif->chipset = ide_forced;
1788 + goto obsolete_option;
1789 +
1790 + case 0: goto bad_option;
1791 + default:
1792 + printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
1793 + return 1;
1794 + }
1795 + }
1796 +bad_option:
1797 + printk(" -- BAD OPTION\n");
1798 + return 1;
1799 +obsolete_option:
1800 + printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
1801 + return 1;
1802 +bad_hwif:
1803 + printk("-- NOT SUPPORTED ON ide%d", hw);
1804 +done:
1805 + printk("\n");
1806 + return 1;
1807 +}
1808 +
1809 +extern void pnpide_init(void);
1810 +extern void h8300_ide_init(void);
1811 +
1812 +/*
1813 + * probe_for_hwifs() finds/initializes "known" IDE interfaces
1814 + */
1815 +static void __init probe_for_hwifs (void)
1816 +{
1817 +#ifdef CONFIG_BLK_DEV_IDEPCI
1818 + ide_scan_pcibus(ide_scan_direction);
1819 +#endif /* CONFIG_BLK_DEV_IDEPCI */
1820 +
1821 +#ifdef CONFIG_ETRAX_IDE
1822 + {
1823 + extern void init_e100_ide(void);
1824 + init_e100_ide();
1825 + }
1826 +#endif /* CONFIG_ETRAX_IDE */
1827 +#ifdef CONFIG_BLK_DEV_CMD640
1828 + {
1829 + extern void ide_probe_for_cmd640x(void);
1830 + ide_probe_for_cmd640x();
1831 + }
1832 +#endif /* CONFIG_BLK_DEV_CMD640 */
1833 +#ifdef CONFIG_BLK_DEV_IDE_PMAC
1834 + {
1835 + extern void pmac_ide_probe(void);
1836 + pmac_ide_probe();
1837 + }
1838 +#endif /* CONFIG_BLK_DEV_IDE_PMAC */
1839 +#ifdef CONFIG_BLK_DEV_GAYLE
1840 + {
1841 + extern void gayle_init(void);
1842 + gayle_init();
1843 + }
1844 +#endif /* CONFIG_BLK_DEV_GAYLE */
1845 +#ifdef CONFIG_BLK_DEV_FALCON_IDE
1846 + {
1847 + extern void falconide_init(void);
1848 + falconide_init();
1849 + }
1850 +#endif /* CONFIG_BLK_DEV_FALCON_IDE */
1851 +#ifdef CONFIG_BLK_DEV_MAC_IDE
1852 + {
1853 + extern void macide_init(void);
1854 + macide_init();
1855 + }
1856 +#endif /* CONFIG_BLK_DEV_MAC_IDE */
1857 +#ifdef CONFIG_BLK_DEV_Q40IDE
1858 + {
1859 + extern void q40ide_init(void);
1860 + q40ide_init();
1861 + }
1862 +#endif /* CONFIG_BLK_DEV_Q40IDE */
1863 +#ifdef CONFIG_BLK_DEV_BUDDHA
1864 + {
1865 + extern void buddha_init(void);
1866 + buddha_init();
1867 + }
1868 +#endif /* CONFIG_BLK_DEV_BUDDHA */
1869 +#ifdef CONFIG_BLK_DEV_IDEPNP
1870 + pnpide_init();
1871 +#endif
1872 +#ifdef CONFIG_H8300
1873 + h8300_ide_init();
1874 +#endif
1875 +}
1876 +
1877 +void ide_register_subdriver(ide_drive_t *drive, ide_driver_t *driver)
1878 +{
1879 +#ifdef CONFIG_PROC_FS
1880 + ide_add_proc_entries(drive->proc, driver->proc, drive);
1881 +#endif
1882 +}
1883 +
1884 +EXPORT_SYMBOL(ide_register_subdriver);
1885 +
1886 +/**
1887 + * ide_unregister_subdriver - disconnect drive from driver
1888 + * @drive: drive to unplug
1889 + * @driver: driver
1890 + *
1891 + * Disconnect a drive from the driver it was attached to and then
1892 + * clean up the various proc files and other objects attached to it.
1893 + *
1894 + * Takes ide_setting_sem and ide_lock.
1895 + * Caller must hold none of the locks.
1896 + */
1897 +
1898 +void ide_unregister_subdriver(ide_drive_t *drive, ide_driver_t *driver)
1899 +{
1900 + unsigned long flags;
1901 +
1902 + down(&ide_setting_sem);
1903 + spin_lock_irqsave(&ide_lock, flags);
1904 +#ifdef CONFIG_PROC_FS
1905 + ide_remove_proc_entries(drive->proc, driver->proc);
1906 +#endif
1907 + auto_remove_settings(drive);
1908 + spin_unlock_irqrestore(&ide_lock, flags);
1909 + up(&ide_setting_sem);
1910 +}
1911 +
1912 +EXPORT_SYMBOL(ide_unregister_subdriver);
1913 +
1914 +/*
1915 + * Probe module
1916 + */
1917 +
1918 +EXPORT_SYMBOL(ide_lock);
1919 +
1920 +static int ide_bus_match(struct device *dev, struct device_driver *drv)
1921 +{
1922 + return 1;
1923 +}
1924 +
1925 +static char *media_string(ide_drive_t *drive)
1926 +{
1927 + switch (drive->media) {
1928 + case ide_disk:
1929 + return "disk";
1930 + case ide_cdrom:
1931 + return "cdrom";
1932 + case ide_tape:
1933 + return "tape";
1934 + case ide_floppy:
1935 + return "floppy";
1936 + default:
1937 + return "UNKNOWN";
1938 + }
1939 +}
1940 +
1941 +static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
1942 +{
1943 + ide_drive_t *drive = to_ide_device(dev);
1944 + return sprintf(buf, "%s\n", media_string(drive));
1945 +}
1946 +
1947 +static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
1948 +{
1949 + ide_drive_t *drive = to_ide_device(dev);
1950 + return sprintf(buf, "%s\n", drive->name);
1951 +}
1952 +
1953 +static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
1954 +{
1955 + ide_drive_t *drive = to_ide_device(dev);
1956 + return sprintf(buf, "ide:m-%s\n", media_string(drive));
1957 +}
1958 +
1959 +static struct device_attribute ide_dev_attrs[] = {
1960 + __ATTR_RO(media),
1961 + __ATTR_RO(drivename),
1962 + __ATTR_RO(modalias),
1963 + __ATTR_NULL
1964 +};
1965 +
1966 +static int ide_uevent(struct device *dev, char **envp, int num_envp,
1967 + char *buffer, int buffer_size)
1968 +{
1969 + ide_drive_t *drive = to_ide_device(dev);
1970 + int i = 0;
1971 + int length = 0;
1972 +
1973 + add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
1974 + "MEDIA=%s", media_string(drive));
1975 + add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
1976 + "DRIVENAME=%s", drive->name);
1977 + add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
1978 + "MODALIAS=ide:m-%s", media_string(drive));
1979 + envp[i] = NULL;
1980 + return 0;
1981 +}
1982 +
1983 +static int generic_ide_probe(struct device *dev)
1984 +{
1985 + ide_drive_t *drive = to_ide_device(dev);
1986 + ide_driver_t *drv = to_ide_driver(dev->driver);
1987 +
1988 + return drv->probe ? drv->probe(drive) : -ENODEV;
1989 +}
1990 +
1991 +static int generic_ide_remove(struct device *dev)
1992 +{
1993 + ide_drive_t *drive = to_ide_device(dev);
1994 + ide_driver_t *drv = to_ide_driver(dev->driver);
1995 +
1996 + if (drv->remove)
1997 + drv->remove(drive);
1998 +
1999 + return 0;
2000 +}
2001 +
2002 +static void generic_ide_shutdown(struct device *dev)
2003 +{
2004 + ide_drive_t *drive = to_ide_device(dev);
2005 + ide_driver_t *drv = to_ide_driver(dev->driver);
2006 +
2007 + if (dev->driver && drv->shutdown)
2008 + drv->shutdown(drive);
2009 +}
2010 +
2011 +struct bus_type ide_bus_type = {
2012 + .name = "ide",
2013 + .match = ide_bus_match,
2014 + .uevent = ide_uevent,
2015 + .probe = generic_ide_probe,
2016 + .remove = generic_ide_remove,
2017 + .shutdown = generic_ide_shutdown,
2018 + .dev_attrs = ide_dev_attrs,
2019 + .suspend = generic_ide_suspend,
2020 + .resume = generic_ide_resume,
2021 +};
2022 +
2023 +EXPORT_SYMBOL_GPL(ide_bus_type);
2024 +
2025 +/*
2026 + * This is gets invoked once during initialization, to set *everything* up
2027 + */
2028 +static int __init ide_init(void)
2029 +{
2030 + int ret;
2031 +
2032 + printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
2033 + system_bus_speed = ide_system_bus_speed();
2034 +
2035 + ret = bus_register(&ide_bus_type);
2036 + if (ret < 0) {
2037 + printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
2038 + return ret;
2039 + }
2040 +
2041 + init_ide_data();
2042 +
2043 +#ifdef CONFIG_PROC_FS
2044 + proc_ide_root = proc_mkdir("ide", NULL);
2045 +#endif
2046 +
2047 +#ifdef CONFIG_BLK_DEV_ALI14XX
2048 + if (probe_ali14xx)
2049 + (void)ali14xx_init();
2050 +#endif
2051 +#ifdef CONFIG_BLK_DEV_UMC8672
2052 + if (probe_umc8672)
2053 + (void)umc8672_init();
2054 +#endif
2055 +#ifdef CONFIG_BLK_DEV_DTC2278
2056 + if (probe_dtc2278)
2057 + (void)dtc2278_init();
2058 +#endif
2059 +#ifdef CONFIG_BLK_DEV_HT6560B
2060 + if (probe_ht6560b)
2061 + (void)ht6560b_init();
2062 +#endif
2063 +#ifdef CONFIG_BLK_DEV_QD65XX
2064 + if (probe_qd65xx)
2065 + (void)qd65xx_init();
2066 +#endif
2067 +
2068 + initializing = 1;
2069 + /* Probe for special PCI and other "known" interface chipsets. */
2070 + probe_for_hwifs();
2071 + initializing = 0;
2072 +
2073 +#ifdef CONFIG_PROC_FS
2074 + proc_ide_create();
2075 +#endif
2076 + return 0;
2077 +}
2078 +
2079 +#ifdef MODULE
2080 +static char *options = NULL;
2081 +module_param(options, charp, 0);
2082 +MODULE_LICENSE("GPL");
2083 +
2084 +static void __init parse_options (char *line)
2085 +{
2086 + char *next = line;
2087 +
2088 + if (line == NULL || !*line)
2089 + return;
2090 + while ((line = next) != NULL) {
2091 + if ((next = strchr(line,' ')) != NULL)
2092 + *next++ = 0;
2093 + if (!ide_setup(line))
2094 + printk (KERN_INFO "Unknown option '%s'\n", line);
2095 + }
2096 +}
2097 +
2098 +int __init init_module (void)
2099 +{
2100 + parse_options(options);
2101 + return ide_init();
2102 +}
2103 +
2104 +void cleanup_module (void)
2105 +{
2106 + int index;
2107 +
2108 + for (index = 0; index < MAX_HWIFS; ++index)
2109 + ide_unregister(index);
2110 +
2111 +#ifdef CONFIG_PROC_FS
2112 + proc_ide_destroy();
2113 +#endif
2114 +
2115 + bus_unregister(&ide_bus_type);
2116 +}
2117 +
2118 +#else /* !MODULE */
2119 +
2120 +__setup("", ide_setup);
2121 +
2122 +module_init(ide_init);
2123 +
2124 +#endif /* MODULE */
2125 diff -purN linux.old/drivers/ide/Kconfig linux.dev/drivers/ide/Kconfig
2126 --- linux.old/drivers/ide/Kconfig 2007-01-10 20:10:37.000000000 +0100
2127 +++ linux.dev/drivers/ide/Kconfig 2007-04-09 01:15:27.570515264 +0200
2128 @@ -925,6 +925,14 @@ config BLK_DEV_MPC8xx_IDE
2129
2130 If unsure, say N.
2131
2132 +config BLK_DEV_MAGICBOX_IDE
2133 + bool "MagicBox 2.0 CF IDE support"
2134 + depends on 4xx && IDE
2135 + help
2136 + This option provides support for IDE on MagicBox 2.0 boards.
2137 +
2138 + If unsure, say N.
2139 +
2140 choice
2141 prompt "Type of MPC8xx IDE interface"
2142 depends on BLK_DEV_MPC8xx_IDE
2143 diff -purN linux.old/drivers/ide/Makefile linux.dev/drivers/ide/Makefile
2144 --- linux.old/drivers/ide/Makefile 2007-01-10 20:10:37.000000000 +0100
2145 +++ linux.dev/drivers/ide/Makefile 2007-04-09 00:23:29.332559488 +0200
2146 @@ -36,6 +36,7 @@ ide-core-$(CONFIG_BLK_DEV_Q40IDE) += leg
2147 # built-in only drivers from ppc/
2148 ide-core-$(CONFIG_BLK_DEV_MPC8xx_IDE) += ppc/mpc8xx.o
2149 ide-core-$(CONFIG_BLK_DEV_IDE_PMAC) += ppc/pmac.o
2150 +ide-core-$(CONFIG_BLK_DEV_MAGICBOX_IDE) += ppc/magicbox_ide.o
2151
2152 # built-in only drivers from h8300/
2153 ide-core-$(CONFIG_H8300) += h8300/ide-h8300.o
2154 diff -purN linux.old/drivers/ide/ppc/magicbox_ide.c linux.dev/drivers/ide/ppc/magicbox_ide.c
2155 --- linux.old/drivers/ide/ppc/magicbox_ide.c 1970-01-01 01:00:00.000000000 +0100
2156 +++ linux.dev/drivers/ide/ppc/magicbox_ide.c 2007-04-09 01:25:39.119545680 +0200
2157 @@ -0,0 +1,149 @@
2158 +/* Driver for MagicBox 2.0 onboard CompactFlash adapter.
2159 + * Written by Wojtek Kaniewski <wojtekka@toxygen.net>
2160 + *
2161 + * GNU General Public License.
2162 + */
2163 +
2164 +#include <linux/types.h>
2165 +#include <linux/mm.h>
2166 +#include <linux/interrupt.h>
2167 +#include <linux/blkdev.h>
2168 +#include <linux/hdreg.h>
2169 +#include <linux/ide.h>
2170 +#include <linux/delay.h>
2171 +#include <linux/platform_device.h>
2172 +
2173 +
2174 +#define UIC0_PR 0xc4
2175 +#define UIC0_TR 0xc5
2176 +#define IRQ 25
2177 +
2178 +static int ide_offsets[IDE_NR_PORTS] = {0, 2, 4, 6, 8, 10, 12, 14, -1, -1};
2179 +
2180 +static u8 magicbox_ide_inb (unsigned long port)
2181 +{
2182 + return (u8) (readw((void __iomem *) port) >> 8) & 255;
2183 +}
2184 +
2185 +static u16 magicbox_ide_inw (unsigned long port)
2186 +{
2187 + return (u16) readw((void __iomem *) port);
2188 +}
2189 +
2190 +static void magicbox_ide_insw (unsigned long port, void *addr, u32 count)
2191 +{
2192 + u16 *ptr;
2193 +
2194 + for (ptr = addr; count--; ptr++)
2195 + *ptr = readw((void __iomem *) port);
2196 +}
2197 +
2198 +static u32 magicbox_ide_inl (unsigned long port)
2199 +{
2200 + return (u32) readl((void __iomem *) port);
2201 +}
2202 +
2203 +static void magicbox_ide_insl (unsigned long port, void *addr, u32 count)
2204 +{
2205 + u32 *ptr;
2206 +
2207 + for (ptr = addr; count--; ptr++)
2208 + *ptr = readl((void __iomem *) port);
2209 +}
2210 +
2211 +static void magicbox_ide_outb (u8 value, unsigned long port)
2212 +{
2213 + writew(value << 8, (void __iomem *) port);
2214 +}
2215 +
2216 +static void magicbox_ide_outbsync (ide_drive_t *drive, u8 value, unsigned long port)
2217 +{
2218 + writew(value << 8, (void __iomem *) port);
2219 +}
2220 +
2221 +static void magicbox_ide_outw (u16 value, unsigned long port)
2222 +{
2223 + writew(value, (void __iomem *) port);
2224 +}
2225 +
2226 +static void magicbox_ide_outsw (unsigned long port, void *addr, u32 count)
2227 +{
2228 + u16 *ptr;
2229 +
2230 + for (ptr = addr; count--; ptr++)
2231 + writew(*ptr, (void __iomem *) port);
2232 +}
2233 +
2234 +static void magicbox_ide_outl (u32 value, unsigned long port)
2235 +{
2236 + writel(value, (void __iomem *) port);
2237 +}
2238 +
2239 +static void magicbox_ide_outsl (unsigned long port, void *addr, u32 count)
2240 +{
2241 + u32 *ptr;
2242 +
2243 + for (ptr = addr; count--; ptr++)
2244 + writel(*ptr, (void __iomem *) port);
2245 +}
2246 +
2247 +
2248 +static void __init ide_magicbox_register(unsigned long addr,
2249 + unsigned long caddr, int irq)
2250 +{
2251 + hw_regs_t hw;
2252 + ide_hwif_t *hwif;
2253 +
2254 + memset(&hw, 0, sizeof(hw));
2255 + ide_setup_ports(&hw, addr, ide_offsets, caddr + 12, 0, NULL,irq);
2256 +
2257 + if (ide_register_hw(&hw, &hwif) != -1)
2258 + {
2259 + printk(KERN_NOTICE "magicbox-ide: Registered IDE-CF driver\n");
2260 + hwif->mmio = 2;
2261 + hwif->drives[0].unmask = 1;
2262 + hwif->OUTB = magicbox_ide_outb;
2263 + hwif->OUTBSYNC = magicbox_ide_outbsync;
2264 + hwif->OUTW = magicbox_ide_outw;
2265 + hwif->OUTL = magicbox_ide_outl;
2266 + hwif->OUTSW = magicbox_ide_outsw;
2267 + hwif->OUTSL = magicbox_ide_outsl;
2268 + hwif->INB = magicbox_ide_inb;
2269 + hwif->INW = magicbox_ide_inw;
2270 + hwif->INL = magicbox_ide_inl;
2271 + hwif->INSW = magicbox_ide_insw;
2272 + hwif->INSL = magicbox_ide_insl;
2273 + }
2274 +}
2275 +
2276 +void __init ide_magicbox_init(void)
2277 +{
2278 + volatile u16 *addr;
2279 + volatile u16 *caddr;
2280 +
2281 + /* Turn on PerWE instead of PCIsomething */
2282 + mtdcr(DCRN_CPC0_PCI_BASE, mfdcr(DCRN_CPC0_PCI_BASE) | (0x80000000L >> 27));
2283 +
2284 + /* PerCS1 (CF's CS0): base 0xff100000, 16-bit, rw */
2285 + mtdcr(DCRN_EBC_BASE, 1);
2286 + mtdcr(DCRN_EBC_BASE + 1, 0xff11a000);
2287 + mtdcr(DCRN_EBC_BASE, 0x11);
2288 + mtdcr(DCRN_EBC_BASE + 1, 0x080bd800);
2289 +
2290 + /* PerCS2 (CF's CS1): base 0xff200000, 16-bit, rw */
2291 + mtdcr(DCRN_EBC_BASE, 2);
2292 + mtdcr(DCRN_EBC_BASE + 1, 0xff21a000);
2293 + mtdcr(DCRN_EBC_BASE, 0x12);
2294 + mtdcr(DCRN_EBC_BASE + 1, 0x080bd800);
2295 +
2296 + /* Remap physical address space */
2297 + addr = ioremap_nocache(0xff100000, 4096);
2298 + caddr = ioremap_nocache(0xff200000, 4096);
2299 +
2300 + /* Set interrupt to low-to-high-edge-triggered */
2301 + mtdcr(UIC0_TR, mfdcr(UIC0_TR) & ~(0x80000000L >> IRQ));
2302 + mtdcr(UIC0_PR, mfdcr(UIC0_PR) | (0x80000000L >> IRQ));
2303 +
2304 + ide_magicbox_register((unsigned long)addr, (unsigned long)caddr, IRQ);
2305 +}
2306 +
This page took 0.128272 seconds and 5 git commands to generate.