2 * linux/drivers/block/ide.c Version 6.19 January 29, 1999
4 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
8 * Mostly written by Mark Lord <mlord@pobox.com>
9 * and Gadi Oxman <gadio@netvision.net.il>
11 * See linux/MAINTAINERS for address of current maintainer.
13 * This is the multiple IDE interface driver, as evolved from hd.c.
14 * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs (usually 14 & 15).
15 * There can be up to two drives per interface, as per the ATA-2 spec.
17 * Primary: ide0, port 0x1f0; major=3; hda is minor=0; hdb is minor=64
18 * Secondary: ide1, port 0x170; major=22; hdc is minor=0; hdd is minor=64
19 * Tertiary: ide2, port 0x???; major=33; hde is minor=0; hdf is minor=64
20 * Quaternary: ide3, port 0x???; major=34; hdg is minor=0; hdh is minor=64
25 * | It traverses the request-list, using interrupts to jump between functions.
26 * | As nearly all functions can be called within interrupts, we may not sleep.
27 * | Special care is recommended. Have Fun!
29 * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
31 * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
32 * | in the early extended-partition checks and added DM partitions.
34 * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
36 * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
37 * | and general streamlining by Mark Lord (mlord@pobox.com).
39 * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
41 * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg)
42 * Delman Lee (delman@mipg.upenn.edu) ("Mr. atdisk2")
43 * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom)
45 * This was a rewrite of just about everything from hd.c, though some original
46 * code is still sprinkled about. Think of it as a major evolution, with
47 * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
49 * Version 1.0 ALPHA initial code, primary i/f working okay
50 * Version 1.3 BETA dual i/f on shared irq tested & working!
51 * Version 1.4 BETA added auto probing for irq(s)
52 * Version 1.5 BETA added ALPHA (untested) support for IDE cd-roms,
54 * Version 5.50 allow values as small as 20 for idebus=
55 * Version 5.51 force non io_32bit in drive_cmd_intr()
56 * change delay_10ms() to delay_50ms() to fix problems
57 * Version 5.52 fix incorrect invalidation of removable devices
58 * add "hdx=slow" command line option
59 * Version 5.60 start to modularize the driver; the disk and ATAPI
60 * drivers can be compiled as loadable modules.
61 * move IDE probe code to ide-probe.c
62 * move IDE disk code to ide-disk.c
63 * add support for generic IDE device subdrivers
64 * add m68k code from Geert Uytterhoeven
65 * probe all interfaces by default
66 * add ioctl to (re)probe an interface
67 * Version 6.00 use per device request queues
68 * attempt to optimize shared hwgroup performance
69 * add ioctl to manually adjust bandwidth algorithms
70 * add kerneld support for the probe module
71 * fix bug in ide_error()
72 * fix bug in the first ide_get_lock() call for Atari
73 * don't flush leftover data for ATAPI devices
74 * Version 6.01 clear hwgroup->active while the hwgroup sleeps
75 * support HDIO_GETGEO for floppies
76 * Version 6.02 fix ide_ack_intr() call
77 * check partition table on floppies
78 * Version 6.03 handle bad status bit sequencing in ide_wait_stat()
79 * Version 6.10 deleted old entries from this list of updates
80 * replaced triton.c with ide-dma.c generic PCI DMA
81 * added support for BIOS-enabled UltraDMA
82 * rename all "promise" things to "pdc4030"
83 * fix EZ-DRIVE handling on small disks
84 * Version 6.11 fix probe error in ide_scan_devices()
85 * fix ancient "jiffies" polling bugs
86 * mask all hwgroup interrupts on each irq entry
87 * Version 6.12 integrate ioctl and proc interfaces
88 * fix parsing of "idex=" command line parameter
89 * Version 6.13 add support for ide4/ide5 courtesy rjones@orchestream.com
90 * Version 6.14 fixed IRQ sharing among PCI devices
91 * Version 6.15 added SMP awareness to IDE drivers
92 * Version 6.16 fixed various bugs; even more SMP friendly
93 * Version 6.17 fix for newest EZ-Drive problem
94 * Version 6.18 default unpartitioned-disk translation now "BIOS LBA"
95 * Version 6.19 Re-design for a UNIFORM driver for all platforms,
96 * model based on suggestions from Russell King and
98 * Promise DC4030VL now supported.
99 * delay_50ms() changed to ide_delay_50ms() and exported.
101 * Some additional driver compile-time options are in ide.h
103 * To do, in likely order of completion:
104 * - modify kernel to obtain BIOS geometry for drives on 2nd/3rd/4th i/f
107 #define REVISION "Revision: 6.19"
108 #define VERSION "Id: ide.c 6.19 1999/01/29"
110 #undef REALLY_SLOW_IO /* most systems can safely undef this */
112 #define _IDE_C /* Tell ide.h it's really us */
114 #include <linux/config.h>
115 #include <linux/module.h>
116 #include <linux/types.h>
117 #include <linux/string.h>
118 #include <linux/kernel.h>
119 #include <linux/timer.h>
120 #include <linux/mm.h>
121 #include <linux/interrupt.h>
122 #include <linux/major.h>
123 #include <linux/errno.h>
124 #include <linux/genhd.h>
125 #include <linux/blkpg.h>
126 #include <linux/malloc.h>
127 #include <linux/pci.h>
128 #include <linux/delay.h>
129 #include <linux/ide.h>
131 #include <asm/byteorder.h>
133 #include <asm/uaccess.h>
135 #include <asm/bitops.h>
137 #include "ide_modes.h"
140 #include <linux/kmod.h>
141 #endif /* CONFIG_KMOD */
143 #ifdef CONFIG_BLK_DEV_VIA82C586
144 extern byte fifoconfig
; /* defined in via82c586.c used by ide_setup()*/
147 static const byte ide_hwif_to_major
[] = {IDE0_MAJOR
, IDE1_MAJOR
, IDE2_MAJOR
, IDE3_MAJOR
, IDE4_MAJOR
, IDE5_MAJOR
, IDE6_MAJOR
, IDE7_MAJOR
};
149 static int idebus_parameter
; /* holds the "idebus=" parameter */
150 static int system_bus_speed
; /* holds what we think is VESA/PCI bus speed */
151 static int initializing
; /* set while initializing built-in drivers */
153 #if defined(__mc68000__) || defined(CONFIG_APUS)
155 * ide_lock is used by the Atari code to obtain access to the IDE interrupt,
156 * which is shared between several drivers.
158 static int ide_lock
= 0;
159 #endif /* __mc68000__ || CONFIG_APUS */
162 * ide_modules keeps track of the available IDE chipset/probe/driver modules.
164 ide_module_t
*ide_modules
= NULL
;
167 * This is declared extern in ide.h, for access by other IDE modules:
169 ide_hwif_t ide_hwifs
[MAX_HWIFS
]; /* master data repository */
171 #if (DISK_RECOVERY_TIME > 0)
173 * For really screwy hardware (hey, at least it *can* be used with Linux)
174 * we can enforce a minimum delay time between successive operations.
176 static unsigned long read_timer(void)
178 unsigned long t
, flags
;
181 __save_flags(flags
); /* local CPU only */
182 __cli(); /* local CPU only */
187 __restore_flags(flags
); /* local CPU only */
190 #endif /* DISK_RECOVERY_TIME */
192 static inline void set_recovery_timer (ide_hwif_t
*hwif
)
194 #if (DISK_RECOVERY_TIME > 0)
195 hwif
->last_time
= read_timer();
196 #endif /* DISK_RECOVERY_TIME */
200 * Do not even *think* about calling this!
202 static void init_hwif_data (unsigned int index
)
206 ide_hwif_t
*hwif
= &ide_hwifs
[index
];
208 /* bulk initialize hwif & drive info with zeros */
209 memset(hwif
, 0, sizeof(ide_hwif_t
));
210 memset(&hw
, 0, sizeof(hw_regs_t
));
212 /* fill in any non-zero initial values */
214 ide_init_hwif_ports(&hw
, ide_default_io_base(index
), 0, &hwif
->irq
);
215 memcpy(&hwif
->hw
, &hw
, sizeof(hw
));
216 memcpy(hwif
->io_ports
, hw
.io_ports
, sizeof(hw
.io_ports
));
217 hwif
->noprobe
= !hwif
->io_ports
[IDE_DATA_OFFSET
];
218 #ifdef CONFIG_BLK_DEV_HD
219 if (hwif
->io_ports
[IDE_DATA_OFFSET
] == HD_DATA
)
220 hwif
->noprobe
= 1; /* may be overridden by ide_setup() */
221 #endif /* CONFIG_BLK_DEV_HD */
222 hwif
->major
= ide_hwif_to_major
[index
];
226 hwif
->name
[3] = '0' + index
;
227 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
228 ide_drive_t
*drive
= &hwif
->drives
[unit
];
230 drive
->media
= ide_disk
;
231 drive
->select
.all
= (unit
<<4)|0xa0;
234 drive
->ready_stat
= READY_STAT
;
235 drive
->bad_wstat
= BAD_W_STAT
;
236 drive
->special
.b
.recalibrate
= 1;
237 drive
->special
.b
.set_geometry
= 1;
238 drive
->name
[0] = 'h';
239 drive
->name
[1] = 'd';
240 drive
->name
[2] = 'a' + (index
* MAX_DRIVES
) + unit
;
241 init_waitqueue_head(&drive
->wqueue
);
246 * init_ide_data() sets reasonable default values into all fields
247 * of all instances of the hwifs and drives, but only on the first call.
248 * Subsequent calls have no effect (they don't wipe out anything).
250 * This routine is normally called at driver initialization time,
251 * but may also be called MUCH earlier during kernel "command-line"
252 * parameter processing. As such, we cannot depend on any other parts
253 * of the kernel (such as memory allocation) to be functioning yet.
255 * This is too bad, as otherwise we could dynamically allocate the
256 * ide_drive_t structs as needed, rather than always consuming memory
257 * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
259 #define MAGIC_COOKIE 0x12345678
260 static void init_ide_data (void)
263 static unsigned long magic_cookie
= MAGIC_COOKIE
;
265 if (magic_cookie
!= MAGIC_COOKIE
)
266 return; /* already initialized */
269 /* Initialise all interface structures */
270 for (index
= 0; index
< MAX_HWIFS
; ++index
)
271 init_hwif_data(index
);
273 /* Add default hw interfaces */
274 ide_init_default_hwifs();
276 idebus_parameter
= 0;
277 system_bus_speed
= 0;
281 * CompactFlash cards and their brethern pretend to be removable hard disks, except:
282 * (1) they never have a slave unit, and
283 * (2) they don't have doorlock mechanisms.
284 * This test catches them, and is invoked elsewhere when setting appropriate config bits.
286 * FIXME: This treatment is probably applicable for *all* PCMCIA (PC CARD) devices,
287 * so in linux 2.3.x we should change this to just treat all PCMCIA drives this way,
288 * and get rid of the model-name tests below (too big of an interface change for 2.2.x).
289 * At that time, we might also consider parameterizing the timeouts and retries,
290 * since these are MUCH faster than mechanical drives. -M.Lord
292 int drive_is_flashcard (ide_drive_t
*drive
)
294 struct hd_driveid
*id
= drive
->id
;
296 if (drive
->removable
&& id
!= NULL
) {
297 if (!strncmp(id
->model
, "KODAK ATA_FLASH", 15) /* Kodak */
298 || !strncmp(id
->model
, "Hitachi CV", 10) /* Hitachi */
299 || !strncmp(id
->model
, "SunDisk SDCFB", 13)) /* SunDisk */
301 return 1; /* yes, it is a flash memory card */
304 return 0; /* no, it is not a flash memory card */
308 * ide_system_bus_speed() returns what we think is the system VESA/PCI
309 * bus speed (in MHz). This is used for calculating interface PIO timings.
310 * The default is 40 for known PCI systems, 50 otherwise.
311 * The "idebus=xx" parameter can be used to override this value.
312 * The actual value to be used is computed/displayed the first time through.
314 int ide_system_bus_speed (void)
316 if (!system_bus_speed
) {
317 if (idebus_parameter
)
318 system_bus_speed
= idebus_parameter
; /* user supplied value */
320 else if (pci_present())
321 system_bus_speed
= 40; /* safe default value for PCI */
322 #endif /* CONFIG_PCI */
324 system_bus_speed
= 50; /* safe default value for VESA and PCI */
325 printk("ide: Assuming %dMHz system bus speed for PIO modes%s\n", system_bus_speed
,
326 idebus_parameter
? "" : "; override with idebus=xx");
328 return system_bus_speed
;
333 * Some localbus EIDE interfaces require a special access sequence
334 * when using 32-bit I/O instructions to transfer data. We call this
335 * the "vlb_sync" sequence, which consists of three successive reads
336 * of the sector count register location, with interrupts disabled
337 * to ensure that the reads all happen together.
339 static inline void do_vlb_sync (ide_ioreg_t port
) {
344 #endif /* SUPPORT_VLB_SYNC */
347 * This is used for most PIO data transfers *from* the IDE interface
349 void ide_input_data (ide_drive_t
*drive
, void *buffer
, unsigned int wcount
)
351 byte io_32bit
= drive
->io_32bit
;
357 __save_flags(flags
); /* local CPU only */
358 __cli(); /* local CPU only */
359 do_vlb_sync(IDE_NSECTOR_REG
);
360 insl(IDE_DATA_REG
, buffer
, wcount
);
361 __restore_flags(flags
); /* local CPU only */
363 #endif /* SUPPORT_VLB_SYNC */
364 insl(IDE_DATA_REG
, buffer
, wcount
);
366 #if SUPPORT_SLOW_DATA_PORTS
368 unsigned short *ptr
= (unsigned short *) buffer
;
370 *ptr
++ = inw_p(IDE_DATA_REG
);
371 *ptr
++ = inw_p(IDE_DATA_REG
);
374 #endif /* SUPPORT_SLOW_DATA_PORTS */
375 insw(IDE_DATA_REG
, buffer
, wcount
<<1);
380 * This is used for most PIO data transfers *to* the IDE interface
382 void ide_output_data (ide_drive_t
*drive
, void *buffer
, unsigned int wcount
)
384 byte io_32bit
= drive
->io_32bit
;
390 __save_flags(flags
); /* local CPU only */
391 __cli(); /* local CPU only */
392 do_vlb_sync(IDE_NSECTOR_REG
);
393 outsl(IDE_DATA_REG
, buffer
, wcount
);
394 __restore_flags(flags
); /* local CPU only */
396 #endif /* SUPPORT_VLB_SYNC */
397 outsl(IDE_DATA_REG
, buffer
, wcount
);
399 #if SUPPORT_SLOW_DATA_PORTS
401 unsigned short *ptr
= (unsigned short *) buffer
;
403 outw_p(*ptr
++, IDE_DATA_REG
);
404 outw_p(*ptr
++, IDE_DATA_REG
);
407 #endif /* SUPPORT_SLOW_DATA_PORTS */
408 outsw(IDE_DATA_REG
, buffer
, wcount
<<1);
413 * The following routines are mainly used by the ATAPI drivers.
415 * These routines will round up any request for an odd number of bytes,
416 * so if an odd bytecount is specified, be sure that there's at least one
417 * extra byte allocated for the buffer.
419 void atapi_input_bytes (ide_drive_t
*drive
, void *buffer
, unsigned int bytecount
)
424 /* Atari has a byte-swapped IDE interface */
425 insw_swapw(IDE_DATA_REG
, buffer
, bytecount
/ 2);
428 #endif /* CONFIG_ATARI */
429 ide_input_data (drive
, buffer
, bytecount
/ 4);
430 if ((bytecount
& 0x03) >= 2)
431 insw (IDE_DATA_REG
, ((byte
*)buffer
) + (bytecount
& ~0x03), 1);
434 void atapi_output_bytes (ide_drive_t
*drive
, void *buffer
, unsigned int bytecount
)
439 /* Atari has a byte-swapped IDE interface */
440 outsw_swapw(IDE_DATA_REG
, buffer
, bytecount
/ 2);
443 #endif /* CONFIG_ATARI */
444 ide_output_data (drive
, buffer
, bytecount
/ 4);
445 if ((bytecount
& 0x03) >= 2)
446 outsw (IDE_DATA_REG
, ((byte
*)buffer
) + (bytecount
& ~0x03), 1);
450 * Needed for PCI irq sharing
452 static inline int drive_is_ready (ide_drive_t
*drive
)
454 if (drive
->waiting_for_dma
)
455 return HWIF(drive
)->dmaproc(ide_dma_test_irq
, drive
);
457 udelay(1); /* need to guarantee 400ns since last command was issued */
459 if (GET_STAT() & BUSY_STAT
)
460 return 0; /* drive busy: definitely not interrupting */
461 return 1; /* drive ready: *might* be interrupting */
465 * This is our end_request replacement function.
467 void ide_end_request(byte uptodate
, ide_hwgroup_t
*hwgroup
)
472 spin_lock_irqsave(&io_request_lock
, flags
);
475 if (!end_that_request_first(rq
, uptodate
, hwgroup
->drive
->name
)) {
476 add_blkdev_randomness(MAJOR(rq
->rq_dev
));
477 hwgroup
->drive
->queue
= rq
->next
;
478 blk_dev
[MAJOR(rq
->rq_dev
)].current_request
= NULL
;
480 end_that_request_last(rq
);
482 spin_unlock_irqrestore(&io_request_lock
, flags
);
486 * This should get invoked any time we exit the driver to
487 * wait for an interrupt response from a drive. handler() points
488 * at the appropriate code to handle the next interrupt, and a
489 * timer is started to prevent us from waiting forever in case
490 * something goes wrong (see the ide_timer_expiry() handler later on).
492 void ide_set_handler (ide_drive_t
*drive
, ide_handler_t
*handler
, unsigned int timeout
)
495 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
497 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
499 if (hwgroup
->handler
!= NULL
) {
500 printk("%s: ide_set_handler: handler not null; old=%p, new=%p\n",
501 drive
->name
, hwgroup
->handler
, handler
);
504 hwgroup
->handler
= handler
;
505 hwgroup
->timer
.expires
= jiffies
+ timeout
;
506 add_timer(&(hwgroup
->timer
));
507 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
511 * current_capacity() returns the capacity (in sectors) of a drive
512 * according to its current geometry/LBA settings.
514 static unsigned long current_capacity (ide_drive_t
*drive
)
518 if (drive
->driver
!= NULL
)
519 return DRIVER(drive
)->capacity(drive
);
524 * ide_geninit() is called exactly *once* for each major, from genhd.c,
525 * at the beginning of the initial partition check for the drives.
527 void ide_geninit (struct gendisk
*gd
)
530 ide_hwif_t
*hwif
= gd
->real_devices
;
532 for (unit
= 0; unit
< gd
->nr_real
; ++unit
) {
533 ide_drive_t
*drive
= &hwif
->drives
[unit
];
535 drive
->part
[0].nr_sects
= current_capacity(drive
);
536 if (!drive
->present
|| (drive
->media
!= ide_disk
&& drive
->media
!= ide_floppy
) ||
537 drive
->driver
== NULL
|| !drive
->part
[0].nr_sects
)
538 drive
->part
[0].start_sect
= -1; /* skip partition check */
542 static void do_reset1 (ide_drive_t
*, int); /* needed below */
545 * atapi_reset_pollfunc() gets invoked to poll the interface for completion every 50ms
546 * during an atapi drive reset operation. If the drive has not yet responded,
547 * and we have not yet hit our maximum waiting time, then the timer is restarted
550 static void atapi_reset_pollfunc (ide_drive_t
*drive
)
552 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
555 SELECT_DRIVE(HWIF(drive
),drive
);
558 if (OK_STAT(stat
=GET_STAT(), 0, BUSY_STAT
)) {
559 printk("%s: ATAPI reset complete\n", drive
->name
);
561 if (0 < (signed long)(hwgroup
->poll_timeout
- jiffies
)) {
562 ide_set_handler (drive
, &atapi_reset_pollfunc
, HZ
/20);
563 return; /* continue polling */
565 hwgroup
->poll_timeout
= 0; /* end of polling */
566 printk("%s: ATAPI reset timed-out, status=0x%02x\n", drive
->name
, stat
);
567 do_reset1 (drive
, 1); /* do it the old fashioned way */
570 hwgroup
->poll_timeout
= 0; /* done polling */
574 * reset_pollfunc() gets invoked to poll the interface for completion every 50ms
575 * during an ide reset operation. If the drives have not yet responded,
576 * and we have not yet hit our maximum waiting time, then the timer is restarted
579 static void reset_pollfunc (ide_drive_t
*drive
)
581 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
582 ide_hwif_t
*hwif
= HWIF(drive
);
585 if (!OK_STAT(tmp
=GET_STAT(), 0, BUSY_STAT
)) {
586 if (0 < (signed long)(hwgroup
->poll_timeout
- jiffies
)) {
587 ide_set_handler (drive
, &reset_pollfunc
, HZ
/20);
588 return; /* continue polling */
590 printk("%s: reset timed-out, status=0x%02x\n", hwif
->name
, tmp
);
592 printk("%s: reset: ", hwif
->name
);
593 if ((tmp
= GET_ERR()) == 1)
596 #if FANCY_STATUS_DUMPS
598 switch (tmp
& 0x7f) {
599 case 1: printk("passed");
601 case 2: printk("formatter device error");
603 case 3: printk("sector buffer error");
605 case 4: printk("ECC circuitry error");
607 case 5: printk("controlling MPU error");
609 default:printk("error (0x%02x?)", tmp
);
612 printk("; slave: failed");
616 #endif /* FANCY_STATUS_DUMPS */
619 hwgroup
->poll_timeout
= 0; /* done polling */
622 static void pre_reset (ide_drive_t
*drive
)
624 if (!drive
->keep_settings
) {
627 if (drive
->using_dma
)
628 (void) HWIF(drive
)->dmaproc(ide_dma_off
, drive
);
630 if (drive
->driver
!= NULL
)
631 DRIVER(drive
)->pre_reset(drive
);
635 * do_reset1() attempts to recover a confused drive by resetting it.
636 * Unfortunately, resetting a disk drive actually resets all devices on
637 * the same interface, so it can really be thought of as resetting the
638 * interface rather than resetting the drive.
640 * ATAPI devices have their own reset mechanism which allows them to be
641 * individually reset without clobbering other devices on the same interface.
643 * Unfortunately, the IDE interface does not generate an interrupt to let
644 * us know when the reset operation has finished, so we must poll for this.
645 * Equally poor, though, is the fact that this may a very long time to complete,
646 * (up to 30 seconds worstcase). So, instead of busy-waiting here for it,
647 * we set a timer to poll at 50ms intervals.
649 static void do_reset1 (ide_drive_t
*drive
, int do_not_try_atapi
)
653 ide_hwif_t
*hwif
= HWIF(drive
);
654 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
656 __save_flags(flags
); /* local CPU only */
657 __cli(); /* local CPU only */
659 /* For an ATAPI device, first try an ATAPI SRST. */
660 if (drive
->media
!= ide_disk
&& !do_not_try_atapi
) {
662 SELECT_DRIVE(hwif
,drive
);
664 OUT_BYTE (WIN_SRST
, IDE_COMMAND_REG
);
665 hwgroup
->poll_timeout
= jiffies
+ WAIT_WORSTCASE
;
666 ide_set_handler (drive
, &atapi_reset_pollfunc
, HZ
/20);
667 __restore_flags (flags
); /* local CPU only */
672 * First, reset any device state data we were maintaining
673 * for any of the drives on this interface.
675 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
)
676 pre_reset(&hwif
->drives
[unit
]);
678 #if OK_TO_RESET_CONTROLLER
679 if (!IDE_CONTROL_REG
) {
680 __restore_flags(flags
);
684 * Note that we also set nIEN while resetting the device,
685 * to mask unwanted interrupts from the interface during the reset.
686 * However, due to the design of PC hardware, this will cause an
687 * immediate interrupt due to the edge transition it produces.
688 * This single interrupt gives us a "fast poll" for drives that
689 * recover from reset very quickly, saving us the first 50ms wait time.
691 OUT_BYTE(drive
->ctl
|6,IDE_CONTROL_REG
); /* set SRST and nIEN */
692 udelay(10); /* more than enough time */
693 OUT_BYTE(drive
->ctl
|2,IDE_CONTROL_REG
); /* clear SRST, leave nIEN */
694 udelay(10); /* more than enough time */
695 hwgroup
->poll_timeout
= jiffies
+ WAIT_WORSTCASE
;
696 ide_set_handler (drive
, &reset_pollfunc
, HZ
/20);
697 #endif /* OK_TO_RESET_CONTROLLER */
699 __restore_flags (flags
); /* local CPU only */
703 * ide_do_reset() is the entry point to the drive/interface reset code.
705 void ide_do_reset (ide_drive_t
*drive
)
707 do_reset1 (drive
, 0);
711 * Clean up after success/failure of an explicit drive cmd
713 void ide_end_drive_cmd (ide_drive_t
*drive
, byte stat
, byte err
)
716 struct request
*rq
= HWGROUP(drive
)->rq
;
718 if (rq
->cmd
== IDE_DRIVE_CMD
) {
719 byte
*args
= (byte
*) rq
->buffer
;
720 rq
->errors
= !OK_STAT(stat
,READY_STAT
,BAD_STAT
);
724 args
[2] = IN_BYTE(IDE_NSECTOR_REG
);
727 spin_lock_irqsave(&io_request_lock
, flags
);
728 drive
->queue
= rq
->next
;
729 blk_dev
[MAJOR(rq
->rq_dev
)].current_request
= NULL
;
730 HWGROUP(drive
)->rq
= NULL
;
731 rq
->rq_status
= RQ_INACTIVE
;
732 spin_unlock_irqrestore(&io_request_lock
, flags
);
733 save_flags(flags
); /* all CPUs; overkill? */
734 cli(); /* all CPUs; overkill? */
736 up(rq
->sem
); /* inform originator that rq has been serviced */
737 restore_flags(flags
); /* all CPUs; overkill? */
741 * Error reporting, in human readable form (luxurious, but a memory hog).
743 byte
ide_dump_status (ide_drive_t
*drive
, const char *msg
, byte stat
)
748 __save_flags (flags
); /* local CPU only */
749 ide__sti(); /* local CPU only */
750 printk("%s: %s: status=0x%02x", drive
->name
, msg
, stat
);
751 #if FANCY_STATUS_DUMPS
753 if (stat
& BUSY_STAT
)
756 if (stat
& READY_STAT
) printk("DriveReady ");
757 if (stat
& WRERR_STAT
) printk("DeviceFault ");
758 if (stat
& SEEK_STAT
) printk("SeekComplete ");
759 if (stat
& DRQ_STAT
) printk("DataRequest ");
760 if (stat
& ECC_STAT
) printk("CorrectedError ");
761 if (stat
& INDEX_STAT
) printk("Index ");
762 if (stat
& ERR_STAT
) printk("Error ");
765 #endif /* FANCY_STATUS_DUMPS */
767 if ((stat
& (BUSY_STAT
|ERR_STAT
)) == ERR_STAT
) {
769 printk("%s: %s: error=0x%02x", drive
->name
, msg
, err
);
770 #if FANCY_STATUS_DUMPS
771 if (drive
->media
== ide_disk
) {
773 if (err
& ABRT_ERR
) printk("DriveStatusError ");
774 if (err
& ICRC_ERR
) printk((err
& ABRT_ERR
) ? "BadCRC " : "BadSector ");
775 if (err
& ECC_ERR
) printk("UncorrectableError ");
776 if (err
& ID_ERR
) printk("SectorIdNotFound ");
777 if (err
& TRK0_ERR
) printk("TrackZeroNotFound ");
778 if (err
& MARK_ERR
) printk("AddrMarkNotFound ");
780 if ((err
& (BBD_ERR
| ABRT_ERR
)) == BBD_ERR
|| (err
& (ECC_ERR
|ID_ERR
|MARK_ERR
))) {
781 byte cur
= IN_BYTE(IDE_SELECT_REG
);
782 if (cur
& 0x40) { /* using LBA? */
783 printk(", LBAsect=%ld", (unsigned long)
785 |(IN_BYTE(IDE_HCYL_REG
)<<16)
786 |(IN_BYTE(IDE_LCYL_REG
)<<8)
787 | IN_BYTE(IDE_SECTOR_REG
));
789 printk(", CHS=%d/%d/%d",
790 (IN_BYTE(IDE_HCYL_REG
)<<8) +
791 IN_BYTE(IDE_LCYL_REG
),
793 IN_BYTE(IDE_SECTOR_REG
));
795 if (HWGROUP(drive
)->rq
)
796 printk(", sector=%ld", HWGROUP(drive
)->rq
->sector
);
799 #endif /* FANCY_STATUS_DUMPS */
802 __restore_flags (flags
); /* local CPU only */
807 * try_to_flush_leftover_data() is invoked in response to a drive
808 * unexpectedly having its DRQ_STAT bit set. As an alternative to
809 * resetting the drive, this routine tries to clear the condition
810 * by read a sector's worth of data from the drive. Of course,
811 * this may not help if the drive is *waiting* for data from *us*.
813 static void try_to_flush_leftover_data (ide_drive_t
*drive
)
815 int i
= (drive
->mult_count
? drive
->mult_count
: 1) * SECTOR_WORDS
;
817 if (drive
->media
!= ide_disk
)
820 unsigned long buffer
[16];
821 unsigned int wcount
= (i
> 16) ? 16 : i
;
823 ide_input_data (drive
, buffer
, wcount
);
828 * ide_error() takes action based on the error returned by the drive.
830 void ide_error (ide_drive_t
*drive
, const char *msg
, byte stat
)
835 err
= ide_dump_status(drive
, msg
, stat
);
836 if (drive
== NULL
|| (rq
= HWGROUP(drive
)->rq
) == NULL
)
838 /* retry only "normal" I/O: */
839 if (rq
->cmd
== IDE_DRIVE_CMD
) {
841 ide_end_drive_cmd(drive
, stat
, err
);
844 if (stat
& BUSY_STAT
|| ((stat
& WRERR_STAT
) && !drive
->nowerr
)) { /* other bits are useless when BUSY */
845 rq
->errors
|= ERROR_RESET
;
847 if (drive
->media
== ide_disk
&& (stat
& ERR_STAT
)) {
848 /* err has different meaning on cdrom and tape */
849 if (err
== ABRT_ERR
) {
850 if (drive
->select
.b
.lba
&& IN_BYTE(IDE_COMMAND_REG
) == WIN_SPECIFY
)
851 return; /* some newer drives don't support WIN_SPECIFY */
852 } else if ((err
& (ABRT_ERR
| ICRC_ERR
)) == (ABRT_ERR
| ICRC_ERR
))
853 ; /* UDMA crc error -- just retry the operation */
854 else if (err
& (BBD_ERR
| ECC_ERR
)) /* retries won't help these */
855 rq
->errors
= ERROR_MAX
;
856 else if (err
& TRK0_ERR
) /* help it find track zero */
857 rq
->errors
|= ERROR_RECAL
;
859 if ((stat
& DRQ_STAT
) && rq
->cmd
!= WRITE
)
860 try_to_flush_leftover_data(drive
);
862 if (GET_STAT() & (BUSY_STAT
|DRQ_STAT
))
863 rq
->errors
|= ERROR_RESET
; /* Mmmm.. timing problem */
865 if (rq
->errors
>= ERROR_MAX
) {
866 if (drive
->driver
!= NULL
)
867 DRIVER(drive
)->end_request(0, HWGROUP(drive
));
869 ide_end_request(0, HWGROUP(drive
));
871 if ((rq
->errors
& ERROR_RESET
) == ERROR_RESET
) {
875 } else if ((rq
->errors
& ERROR_RECAL
) == ERROR_RECAL
)
876 drive
->special
.b
.recalibrate
= 1;
882 * Issue a simple drive command
883 * The drive must be selected beforehand.
885 void ide_cmd(ide_drive_t
*drive
, byte cmd
, byte nsect
, ide_handler_t
*handler
)
887 ide_set_handler (drive
, handler
, WAIT_CMD
);
889 OUT_BYTE(drive
->ctl
,IDE_CONTROL_REG
); /* clear nIEN */
890 OUT_BYTE(nsect
,IDE_NSECTOR_REG
);
891 OUT_BYTE(cmd
,IDE_COMMAND_REG
);
895 * drive_cmd_intr() is invoked on completion of a special DRIVE_CMD.
897 static void drive_cmd_intr (ide_drive_t
*drive
)
899 struct request
*rq
= HWGROUP(drive
)->rq
;
900 byte
*args
= (byte
*) rq
->buffer
;
901 byte stat
= GET_STAT();
904 ide__sti(); /* local CPU only */
905 if ((stat
& DRQ_STAT
) && args
&& args
[3]) {
906 byte io_32bit
= drive
->io_32bit
;
908 ide_input_data(drive
, &args
[4], args
[3] * SECTOR_WORDS
);
909 drive
->io_32bit
= io_32bit
;
910 while (((stat
= GET_STAT()) & BUSY_STAT
) && retries
--)
914 if (OK_STAT(stat
, READY_STAT
, BAD_STAT
))
915 ide_end_drive_cmd (drive
, stat
, GET_ERR());
917 ide_error(drive
, "drive_cmd", stat
); /* calls ide_end_drive_cmd */
921 * do_special() is used to issue WIN_SPECIFY, WIN_RESTORE, and WIN_SETMULT
922 * commands to a drive. It used to do much more, but has been scaled back.
924 static inline void do_special (ide_drive_t
*drive
)
926 special_t
*s
= &drive
->special
;
929 printk("%s: do_special: 0x%02x\n", drive
->name
, s
->all
);
932 ide_tuneproc_t
*tuneproc
= HWIF(drive
)->tuneproc
;
934 if (tuneproc
!= NULL
)
935 tuneproc(drive
, drive
->tune_req
);
936 } else if (drive
->driver
!= NULL
) {
937 DRIVER(drive
)->special(drive
);
939 printk("%s: bad special flag: 0x%02x\n", drive
->name
, s
->all
);
945 * This routine busy-waits for the drive status to be not "busy".
946 * It then checks the status for all of the "good" bits and none
947 * of the "bad" bits, and if all is okay it returns 0. All other
948 * cases return 1 after invoking ide_error() -- caller should just return.
950 * This routine should get fixed to not hog the cpu during extra long waits..
951 * That could be done by busy-waiting for the first jiffy or two, and then
952 * setting a timer to wake up at half second intervals thereafter,
953 * until timeout is achieved, before timing out.
955 int ide_wait_stat (ide_drive_t
*drive
, byte good
, byte bad
, unsigned long timeout
)
961 udelay(1); /* spec allows drive 400ns to assert "BUSY" */
962 if ((stat
= GET_STAT()) & BUSY_STAT
) {
963 __save_flags(flags
); /* local CPU only */
964 ide__sti(); /* local CPU only */
966 while ((stat
= GET_STAT()) & BUSY_STAT
) {
967 if (0 < (signed long)(jiffies
- timeout
)) {
968 __restore_flags(flags
); /* local CPU only */
969 ide_error(drive
, "status timeout", stat
);
973 __restore_flags(flags
); /* local CPU only */
976 * Allow status to settle, then read it again.
977 * A few rare drives vastly violate the 400ns spec here,
978 * so we'll wait up to 10usec for a "good" status
979 * rather than expensively fail things immediately.
980 * This fix courtesy of Matthew Faupel & Niccolo Rigacci.
982 for (i
= 0; i
< 10; i
++) {
984 if (OK_STAT((stat
= GET_STAT()), good
, bad
))
987 ide_error(drive
, "status error", stat
);
992 * execute_drive_cmd() issues a special drive command,
993 * usually initiated by ioctl() from the external hdparm program.
995 static void execute_drive_cmd (ide_drive_t
*drive
, struct request
*rq
)
997 byte
*args
= rq
->buffer
;
1000 printk("%s: DRIVE_CMD cmd=0x%02x sc=0x%02x fr=0x%02x xx=0x%02x\n",
1001 drive
->name
, args
[0], args
[1], args
[2], args
[3]);
1003 if (args
[0] == WIN_SMART
) {
1004 OUT_BYTE(0x4f, IDE_LCYL_REG
);
1005 OUT_BYTE(0xc2, IDE_HCYL_REG
);
1007 OUT_BYTE(args
[2],IDE_FEATURE_REG
);
1008 ide_cmd(drive
, args
[0], args
[1], &drive_cmd_intr
);
1012 * NULL is actually a valid way of waiting for
1013 * all current requests to be flushed from the queue.
1016 printk("%s: DRIVE_CMD (null)\n", drive
->name
);
1018 ide_end_drive_cmd(drive
, GET_STAT(), GET_ERR());
1024 * start_request() initiates handling of a new I/O request
1026 static inline void start_request (ide_drive_t
*drive
)
1028 unsigned long block
, blockend
;
1029 struct request
*rq
= drive
->queue
;
1030 unsigned int minor
= MINOR(rq
->rq_dev
), unit
= minor
>> PARTN_BITS
;
1031 ide_hwif_t
*hwif
= HWIF(drive
);
1033 ide__sti(); /* local CPU only */
1035 printk("%s: start_request: current=0x%08lx\n", hwif
->name
, (unsigned long) rq
);
1037 if (unit
>= MAX_DRIVES
) {
1038 printk("%s: bad device number: %s\n", hwif
->name
, kdevname(rq
->rq_dev
));
1042 if (rq
->bh
&& !buffer_locked(rq
->bh
)) {
1043 printk("%s: block not locked\n", drive
->name
);
1048 blockend
= block
+ rq
->nr_sectors
;
1049 if ((blockend
< block
) || (blockend
> drive
->part
[minor
&PARTN_MASK
].nr_sects
)) {
1050 printk("%s%c: bad access: block=%ld, count=%ld\n", drive
->name
,
1051 (minor
&PARTN_MASK
)?'0'+(minor
&PARTN_MASK
):' ', block
, rq
->nr_sectors
);
1054 block
+= drive
->part
[minor
&PARTN_MASK
].start_sect
+ drive
->sect0
;
1055 #if FAKE_FDISK_FOR_EZDRIVE
1056 if (block
== 0 && drive
->remap_0_to_1
)
1057 block
= 1; /* redirect MBR access to EZ-Drive partn table */
1058 #endif /* FAKE_FDISK_FOR_EZDRIVE */
1059 #if (DISK_RECOVERY_TIME > 0)
1060 while ((read_timer() - hwif
->last_time
) < DISK_RECOVERY_TIME
);
1062 SELECT_DRIVE(hwif
, drive
);
1063 if (ide_wait_stat(drive
, drive
->ready_stat
, BUSY_STAT
|DRQ_STAT
, WAIT_READY
)) {
1064 printk("%s: drive not ready for command\n", drive
->name
);
1067 if (!drive
->special
.all
) {
1068 if (rq
->cmd
== IDE_DRIVE_CMD
) {
1069 execute_drive_cmd(drive
, rq
);
1072 if (drive
->driver
!= NULL
) {
1073 DRIVER(drive
)->do_request(drive
, rq
, block
);
1076 printk("%s: media type %d not supported\n", drive
->name
, drive
->media
);
1082 if (drive
->driver
!= NULL
)
1083 DRIVER(drive
)->end_request(0, HWGROUP(drive
));
1085 ide_end_request(0, HWGROUP(drive
));
1089 * ide_stall_queue() can be used by a drive to give excess bandwidth back
1090 * to the hwgroup by sleeping for timeout jiffies.
1092 void ide_stall_queue (ide_drive_t
*drive
, unsigned long timeout
)
1094 if (timeout
> WAIT_WORSTCASE
)
1095 timeout
= WAIT_WORSTCASE
;
1096 drive
->sleep
= timeout
+ jiffies
;
1099 #define WAKEUP(drive) ((drive)->service_start + 2 * (drive)->service_time)
1102 * choose_drive() selects the next drive which will be serviced.
1104 static inline ide_drive_t
*choose_drive (ide_hwgroup_t
*hwgroup
)
1106 ide_drive_t
*drive
, *best
;
1110 drive
= hwgroup
->drive
;
1112 if (drive
->queue
&& (!drive
->sleep
|| 0 <= (signed long)(jiffies
- drive
->sleep
))) {
1114 || (drive
->sleep
&& (!best
->sleep
|| 0 < (signed long)(best
->sleep
- drive
->sleep
)))
1115 || (!best
->sleep
&& 0 < (signed long)(WAKEUP(best
) - WAKEUP(drive
))))
1117 struct blk_dev_struct
*bdev
= &blk_dev
[HWIF(drive
)->major
];
1118 if (bdev
->current_request
!= &bdev
->plug
)
1122 } while ((drive
= drive
->next
) != hwgroup
->drive
);
1123 if (best
&& best
->nice1
&& !best
->sleep
&& best
!= hwgroup
->drive
&& best
->service_time
> WAIT_MIN_SLEEP
) {
1124 long t
= (signed long)(WAKEUP(best
) - jiffies
);
1125 if (t
>= WAIT_MIN_SLEEP
) {
1127 * We *may* have some time to spare, but first let's see if
1128 * someone can potentially benefit from our nice mood today..
1133 && 0 < (signed long)(WAKEUP(drive
) - (jiffies
- best
->service_time
))
1134 && 0 < (signed long)((jiffies
+ t
) - WAKEUP(drive
)))
1136 ide_stall_queue(best
, IDE_MIN(t
, 10 * WAIT_MIN_SLEEP
));
1139 } while ((drive
= drive
->next
) != best
);
1146 * Caller must have already acquired spinlock using *spinflags
1148 static void ide_do_request (ide_hwgroup_t
*hwgroup
, unsigned long *hwgroup_flags
, int masked_irq
)
1150 struct blk_dev_struct
*bdev
;
1153 unsigned long io_flags
;
1156 while (hwgroup
->handler
== NULL
) {
1157 spin_lock_irqsave(&io_request_lock
, io_flags
);
1158 drive
= choose_drive(hwgroup
);
1159 if (drive
== NULL
) {
1160 unsigned long sleep
= 0;
1163 drive
= hwgroup
->drive
;
1165 bdev
= &blk_dev
[HWIF(drive
)->major
];
1166 if (bdev
->current_request
!= &bdev
->plug
) /* FIXME: this will do for now */
1167 bdev
->current_request
= NULL
; /* (broken since patch-2.1.15) */
1168 if (drive
->sleep
&& (!sleep
|| 0 < (signed long)(sleep
- drive
->sleep
)))
1169 sleep
= drive
->sleep
;
1170 } while ((drive
= drive
->next
) != hwgroup
->drive
);
1171 spin_unlock_irqrestore(&io_request_lock
, io_flags
);
1173 if (0 < (signed long)(jiffies
+ WAIT_MIN_SLEEP
- sleep
))
1174 sleep
= jiffies
+ WAIT_MIN_SLEEP
;
1176 if (hwgroup
->timer
.next
|| hwgroup
->timer
.prev
)
1177 printk("ide_set_handler: timer already active\n");
1179 mod_timer(&hwgroup
->timer
, sleep
);
1181 /* Ugly, but how can we sleep for the lock otherwise? perhaps from tq_scheduler? */
1182 ide_release_lock(&ide_lock
); /* for atari only */
1188 if (hwgroup
->hwif
->sharing_irq
&& hwif
!= hwgroup
->hwif
) /* set nIEN for previous hwif */
1189 OUT_BYTE(hwgroup
->drive
->ctl
|2, hwgroup
->hwif
->io_ports
[IDE_CONTROL_OFFSET
]);
1190 hwgroup
->hwif
= hwif
;
1191 hwgroup
->drive
= drive
;
1193 drive
->service_start
= jiffies
;
1195 bdev
= &blk_dev
[hwif
->major
];
1196 if (bdev
->current_request
== &bdev
->plug
) /* FIXME: paranoia */
1197 printk("%s: Huh? nuking plugged queue\n", drive
->name
);
1198 bdev
->current_request
= hwgroup
->rq
= drive
->queue
;
1199 spin_unlock_irqrestore(&io_request_lock
, io_flags
);
1201 if (hwif
->irq
!= masked_irq
)
1202 disable_irq(hwif
->irq
);
1203 spin_unlock_irqrestore(&hwgroup
->spinlock
, *hwgroup_flags
);
1204 start_request(drive
);
1205 spin_lock_irqsave(&hwgroup
->spinlock
, *hwgroup_flags
);
1206 if (hwif
->irq
!= masked_irq
)
1207 enable_irq(hwif
->irq
);
1212 * ide_get_queue() returns the queue which corresponds to a given device.
1214 struct request
**ide_get_queue (kdev_t dev
)
1216 ide_hwif_t
*hwif
= (ide_hwif_t
*)blk_dev
[MAJOR(dev
)].data
;
1218 return &hwif
->drives
[DEVICE_NR(dev
) & 1].queue
;
1222 * do_hwgroup_request() invokes ide_do_request() after claiming hwgroup->busy.
1224 static void do_hwgroup_request (ide_hwgroup_t
*hwgroup
)
1226 unsigned long flags
;
1228 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
1229 if (hwgroup
->busy
) {
1230 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1233 del_timer(&hwgroup
->timer
);
1234 ide_get_lock(&ide_lock
, ide_intr
, hwgroup
); /* for atari only */
1235 ide_do_request(hwgroup
, &flags
, 0);
1236 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1240 * ll_rw_blk.c invokes our do_idex_request() function
1241 * with the io_request_spinlock already grabbed.
1242 * Since we need to do our own spinlock's internally,
1243 * on paths that don't necessarily originate through the
1244 * do_idex_request() path, we have to undo the spinlock on entry,
1245 * and restore it again on exit.
1246 * Fortunately, this is mostly a nop for non-SMP kernels.
1248 static inline void unlock_do_hwgroup_request (ide_hwgroup_t
*hwgroup
)
1250 spin_unlock(&io_request_lock
);
1251 do_hwgroup_request (hwgroup
);
1252 spin_lock_irq(&io_request_lock
);
1255 void do_ide0_request (void)
1257 unlock_do_hwgroup_request (ide_hwifs
[0].hwgroup
);
1261 void do_ide1_request (void)
1263 unlock_do_hwgroup_request (ide_hwifs
[1].hwgroup
);
1265 #endif /* MAX_HWIFS > 1 */
1268 void do_ide2_request (void)
1270 unlock_do_hwgroup_request (ide_hwifs
[2].hwgroup
);
1272 #endif /* MAX_HWIFS > 2 */
1275 void do_ide3_request (void)
1277 unlock_do_hwgroup_request (ide_hwifs
[3].hwgroup
);
1279 #endif /* MAX_HWIFS > 3 */
1282 void do_ide4_request (void)
1284 unlock_do_hwgroup_request (ide_hwifs
[4].hwgroup
);
1286 #endif /* MAX_HWIFS > 4 */
1289 void do_ide5_request (void)
1291 unlock_do_hwgroup_request (ide_hwifs
[5].hwgroup
);
1293 #endif /* MAX_HWIFS > 5 */
1296 void do_ide6_request (void)
1298 unlock_do_hwgroup_request (ide_hwifs
[6].hwgroup
);
1300 #endif /* MAX_HWIFS > 6 */
1303 void do_ide7_request (void)
1305 unlock_do_hwgroup_request (ide_hwifs
[7].hwgroup
);
1307 #endif /* MAX_HWIFS > 7 */
1309 static void start_next_request (ide_hwgroup_t
*hwgroup
, int masked_irq
)
1311 unsigned long flags
;
1314 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
1315 if (hwgroup
->handler
!= NULL
) {
1316 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1319 drive
= hwgroup
->drive
;
1320 set_recovery_timer(HWIF(drive
));
1321 drive
->service_time
= jiffies
- drive
->service_start
;
1322 ide_do_request(hwgroup
, &flags
, masked_irq
);
1323 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1326 void ide_timer_expiry (unsigned long data
)
1328 ide_hwgroup_t
*hwgroup
= (ide_hwgroup_t
*) data
;
1330 ide_handler_t
*handler
;
1331 unsigned long flags
;
1333 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
1334 drive
= hwgroup
->drive
;
1335 if ((handler
= hwgroup
->handler
) == NULL
) {
1336 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1337 do_hwgroup_request(hwgroup
);
1340 hwgroup
->busy
= 1; /* should already be "1" */
1341 hwgroup
->handler
= NULL
;
1342 del_timer(&hwgroup
->timer
); /* Is this needed?? */
1343 if (hwgroup
->poll_timeout
!= 0) { /* polling in progress? */
1344 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1346 } else if (drive_is_ready(drive
)) {
1347 printk("%s: lost interrupt\n", drive
->name
);
1348 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1351 if (drive
->waiting_for_dma
) {
1352 (void) hwgroup
->hwif
->dmaproc(ide_dma_end
, drive
);
1353 printk("%s: timeout waiting for DMA\n", drive
->name
);
1355 * need something here for HX PIIX3 UDMA and HPT343.......AMH
1356 * irq timeout: status=0x58 { DriveReady SeekComplete DataRequest }
1359 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1360 ide_error(drive
, "irq timeout", GET_STAT());
1362 start_next_request(hwgroup
, 0);
1366 * There's nothing really useful we can do with an unexpected interrupt,
1367 * other than reading the status register (to clear it), and logging it.
1368 * There should be no way that an irq can happen before we're ready for it,
1369 * so we needn't worry much about losing an "important" interrupt here.
1371 * On laptops (and "green" PCs), an unexpected interrupt occurs whenever the
1372 * drive enters "idle", "standby", or "sleep" mode, so if the status looks
1373 * "good", we just ignore the interrupt completely.
1375 * This routine assumes __cli() is in effect when called.
1377 * If an unexpected interrupt happens on irq15 while we are handling irq14
1378 * and if the two interfaces are "serialized" (CMD640), then it looks like
1379 * we could screw up by interfering with a new request being set up for irq15.
1381 * In reality, this is a non-issue. The new command is not sent unless the
1382 * drive is ready to accept one, in which case we know the drive is not
1383 * trying to interrupt us. And ide_set_handler() is always invoked before
1384 * completing the issuance of any new drive command, so we will not be
1385 * accidently invoked as a result of any valid command completion interrupt.
1388 static void unexpected_intr (int irq
, ide_hwgroup_t
*hwgroup
)
1391 ide_hwif_t
*hwif
= hwgroup
->hwif
;
1394 * handle the unexpected interrupt
1397 if (hwif
->irq
== irq
) {
1398 stat
= IN_BYTE(hwif
->io_ports
[IDE_STATUS_OFFSET
]);
1399 if (!OK_STAT(stat
, READY_STAT
, BAD_STAT
)) {
1400 /* Try to not flood the console with msgs */
1401 static unsigned long last_msgtime
= 0, count
= 0;
1403 if (0 < (signed long)(jiffies
- (last_msgtime
+ HZ
))) {
1404 last_msgtime
= jiffies
;
1405 printk("%s%s: unexpected interrupt, status=0x%02x, count=%ld\n",
1406 hwif
->name
, (hwif
->next
== hwgroup
->hwif
) ? "" : "(?)", stat
, count
);
1410 } while ((hwif
= hwif
->next
) != hwgroup
->hwif
);
1413 * entry point for all interrupts, caller does __cli() for us
1415 void ide_intr (int irq
, void *dev_id
, struct pt_regs
*regs
)
1417 unsigned long flags
;
1418 ide_hwgroup_t
*hwgroup
= (ide_hwgroup_t
*)dev_id
;
1421 ide_handler_t
*handler
;
1423 __cli(); /* local CPU only */
1424 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
1425 hwif
= hwgroup
->hwif
;
1427 if (!ide_ack_intr(hwif
)) {
1428 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1432 if ((handler
= hwgroup
->handler
) == NULL
|| hwgroup
->poll_timeout
!= 0) {
1434 * Not expecting an interrupt from this drive.
1435 * That means this could be:
1436 * (1) an interrupt from another PCI device
1437 * sharing the same PCI INT# as us.
1438 * or (2) a drive just entered sleep or standby mode,
1439 * and is interrupting to let us know.
1440 * or (3) a spurious interrupt of unknown origin.
1442 * For PCI, we cannot tell the difference,
1443 * so in that case we just ignore it and hope it goes away.
1445 #ifdef CONFIG_BLK_DEV_IDEPCI
1446 if (IDE_PCI_DEVID_EQ(hwif
->pci_devid
, IDE_PCI_DEVID_NULL
))
1447 #endif /* CONFIG_BLK_DEV_IDEPCI */
1450 * Probably not a shared PCI interrupt,
1451 * so we can safely try to do something about it:
1453 unexpected_intr(irq
, hwgroup
);
1455 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1458 drive
= hwgroup
->drive
;
1459 if (!drive
|| !drive_is_ready(drive
)) {
1460 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1463 hwgroup
->handler
= NULL
;
1464 del_timer(&(hwgroup
->timer
));
1465 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1467 ide__sti(); /* local CPU only */
1468 handler(drive
); /* service this interrupt, may set handler for next interrupt */
1470 * Note that handler() may have set things up for another
1471 * interrupt to occur soon, but it cannot happen until
1472 * we exit from this routine, because it will be the
1473 * same irq as is currently being serviced here,
1474 * and Linux won't allow another (on any CPU) until we return.
1476 start_next_request(hwgroup
, hwif
->irq
);
1480 * get_info_ptr() returns the (ide_drive_t *) for a given device number.
1481 * It returns NULL if the given device number does not match any present drives.
1483 static ide_drive_t
*get_info_ptr (kdev_t i_rdev
)
1485 int major
= MAJOR(i_rdev
);
1488 for (h
= 0; h
< MAX_HWIFS
; ++h
) {
1489 ide_hwif_t
*hwif
= &ide_hwifs
[h
];
1490 if (hwif
->present
&& major
== hwif
->major
) {
1491 unsigned unit
= DEVICE_NR(i_rdev
);
1492 if (unit
< MAX_DRIVES
) {
1493 ide_drive_t
*drive
= &hwif
->drives
[unit
];
1504 * This function is intended to be used prior to invoking ide_do_drive_cmd().
1506 void ide_init_drive_cmd (struct request
*rq
)
1509 rq
->cmd
= IDE_DRIVE_CMD
;
1512 rq
->current_nr_sectors
= 0;
1520 * This function issues a special IDE device request
1521 * onto the request queue.
1523 * If action is ide_wait, then the rq is queued at the end of the
1524 * request queue, and the function sleeps until it has been processed.
1525 * This is for use when invoked from an ioctl handler.
1527 * If action is ide_preempt, then the rq is queued at the head of
1528 * the request queue, displacing the currently-being-processed
1529 * request and this function returns immediately without waiting
1530 * for the new rq to be completed. This is VERY DANGEROUS, and is
1531 * intended for careful use by the ATAPI tape/cdrom driver code.
1533 * If action is ide_next, then the rq is queued immediately after
1534 * the currently-being-processed-request (if any), and the function
1535 * returns without waiting for the new rq to be completed. As above,
1536 * This is VERY DANGEROUS, and is intended for careful use by the
1537 * ATAPI tape/cdrom driver code.
1539 * If action is ide_end, then the rq is queued at the end of the
1540 * request queue, and the function returns immediately without waiting
1541 * for the new rq to be completed. This is again intended for careful
1542 * use by the ATAPI tape/cdrom driver code.
1544 int ide_do_drive_cmd (ide_drive_t
*drive
, struct request
*rq
, ide_action_t action
)
1546 unsigned long flags
;
1547 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
1548 unsigned int major
= HWIF(drive
)->major
;
1549 struct request
*cur_rq
;
1550 DECLARE_MUTEX_LOCKED(sem
);
1552 if (IS_PDC4030_DRIVE
&& rq
->buffer
!= NULL
)
1553 return -ENOSYS
; /* special drive cmds not supported */
1555 rq
->rq_status
= RQ_ACTIVE
;
1556 rq
->rq_dev
= MKDEV(major
,(drive
->select
.b
.unit
)<<PARTN_BITS
);
1557 if (action
== ide_wait
)
1560 spin_lock_irqsave(&io_request_lock
, flags
);
1561 cur_rq
= drive
->queue
;
1562 if (cur_rq
== NULL
|| action
== ide_preempt
) {
1565 if (action
== ide_preempt
)
1568 if (action
== ide_wait
|| action
== ide_end
) {
1569 while (cur_rq
->next
!= NULL
) /* find end of list */
1570 cur_rq
= cur_rq
->next
;
1572 rq
->next
= cur_rq
->next
;
1575 spin_unlock_irqrestore(&io_request_lock
, flags
);
1576 do_hwgroup_request(hwgroup
);
1577 save_flags(flags
); /* all CPUs; overkill? */
1578 cli(); /* all CPUs; overkill? */
1579 if (action
== ide_wait
&& rq
->rq_status
!= RQ_INACTIVE
)
1580 down(&sem
); /* wait for it to be serviced */
1581 restore_flags(flags
); /* all CPUs; overkill? */
1582 return rq
->errors
? -EIO
: 0; /* return -EIO if errors */
1586 * This routine is called to flush all partitions and partition tables
1587 * for a changed disk, and then re-read the new partition table.
1588 * If we are revalidating a disk because of a media change, then we
1589 * enter with usage == 0. If we are using an ioctl, we automatically have
1590 * usage == 1 (we need an open channel to use an ioctl :-), so this
1593 int ide_revalidate_disk(kdev_t i_rdev
)
1596 ide_hwgroup_t
*hwgroup
;
1597 unsigned int p
, major
, minor
;
1600 if ((drive
= get_info_ptr(i_rdev
)) == NULL
)
1602 major
= MAJOR(i_rdev
);
1603 minor
= drive
->select
.b
.unit
<< PARTN_BITS
;
1604 hwgroup
= HWGROUP(drive
);
1605 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
1606 if (drive
->busy
|| (drive
->usage
> 1)) {
1607 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1612 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1614 for (p
= 0; p
< (1<<PARTN_BITS
); ++p
) {
1615 if (drive
->part
[p
].nr_sects
> 0) {
1616 kdev_t devp
= MKDEV(major
, minor
+p
);
1617 struct super_block
* sb
= get_super(devp
);
1620 invalidate_inodes(sb
);
1621 invalidate_buffers (devp
);
1622 set_blocksize(devp
, 1024);
1624 drive
->part
[p
].start_sect
= 0;
1625 drive
->part
[p
].nr_sects
= 0;
1628 drive
->part
[0].nr_sects
= current_capacity(drive
);
1629 if ((drive
->media
!= ide_disk
&& drive
->media
!= ide_floppy
) ||
1630 drive
->driver
== NULL
|| !drive
->part
[0].nr_sects
)
1631 drive
->part
[0].start_sect
= -1;
1632 resetup_one_dev(HWIF(drive
)->gd
, drive
->select
.b
.unit
);
1635 wake_up(&drive
->wqueue
);
1640 static void revalidate_drives (void)
1646 for (index
= 0; index
< MAX_HWIFS
; ++index
) {
1647 hwif
= &ide_hwifs
[index
];
1648 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
1649 drive
= &ide_hwifs
[index
].drives
[unit
];
1650 if (drive
->revalidate
) {
1651 drive
->revalidate
= 0;
1653 (void) ide_revalidate_disk(MKDEV(hwif
->major
, unit
<<PARTN_BITS
));
1659 static void ide_init_module (int type
)
1662 ide_module_t
*module
= ide_modules
;
1665 if (module
->type
== type
) {
1667 (void) module
->init();
1669 module
= module
->next
;
1671 revalidate_drives();
1673 if (!found
&& type
== IDE_PROBE_MODULE
)
1674 (void) request_module("ide-probe");
1675 #endif /* CONFIG_KMOD */
1678 static int ide_open(struct inode
* inode
, struct file
* filp
)
1683 if ((drive
= get_info_ptr(inode
->i_rdev
)) == NULL
)
1686 if (drive
->driver
== NULL
)
1687 ide_init_module(IDE_DRIVER_MODULE
);
1689 if (drive
->driver
== NULL
) {
1690 if (drive
->media
== ide_disk
)
1691 (void) request_module("ide-disk");
1692 if (drive
->media
== ide_cdrom
)
1693 (void) request_module("ide-cd");
1694 if (drive
->media
== ide_tape
)
1695 (void) request_module("ide-tape");
1696 if (drive
->media
== ide_floppy
)
1697 (void) request_module("ide-floppy");
1699 #endif /* CONFIG_KMOD */
1701 sleep_on(&drive
->wqueue
);
1703 if (drive
->driver
!= NULL
) {
1704 if ((rc
= DRIVER(drive
)->open(inode
, filp
, drive
)))
1708 printk ("%s: driver not present\n", drive
->name
);
1715 * Releasing a block device means we sync() it, so that it can safely
1716 * be forgotten about...
1718 static int ide_release(struct inode
* inode
, struct file
* file
)
1722 if ((drive
= get_info_ptr(inode
->i_rdev
)) != NULL
) {
1723 fsync_dev(inode
->i_rdev
);
1725 if (drive
->driver
!= NULL
)
1726 DRIVER(drive
)->release(inode
, file
, drive
);
1732 int ide_replace_subdriver(ide_drive_t
*drive
, const char *driver
)
1734 if (!drive
->present
|| drive
->busy
|| drive
->usage
)
1736 if (drive
->driver
!= NULL
&& DRIVER(drive
)->cleanup(drive
))
1738 strncpy(drive
->driver_req
, driver
, 9);
1739 ide_init_module(IDE_DRIVER_MODULE
);
1740 drive
->driver_req
[0] = 0;
1741 ide_init_module(IDE_DRIVER_MODULE
);
1742 if (DRIVER(drive
) && !strcmp(DRIVER(drive
)->name
, driver
))
1748 void ide_unregister (unsigned int index
)
1750 struct gendisk
*gd
, **gdp
;
1751 ide_drive_t
*drive
, *d
;
1752 ide_hwif_t
*hwif
, *g
;
1753 ide_hwgroup_t
*hwgroup
;
1754 int irq_count
= 0, unit
, i
;
1755 unsigned long flags
;
1756 unsigned int p
, minor
;
1758 if (index
>= MAX_HWIFS
)
1760 save_flags(flags
); /* all CPUs */
1761 cli(); /* all CPUs */
1762 hwif
= &ide_hwifs
[index
];
1765 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
1766 drive
= &hwif
->drives
[unit
];
1767 if (!drive
->present
)
1769 if (drive
->busy
|| drive
->usage
)
1771 if (drive
->driver
!= NULL
&& DRIVER(drive
)->cleanup(drive
))
1777 * All clear? Then blow away the buffer cache
1780 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
1781 drive
= &hwif
->drives
[unit
];
1782 minor
= drive
->select
.b
.unit
<< PARTN_BITS
;
1783 for (p
= 0; p
< (1<<PARTN_BITS
); ++p
) {
1784 if (drive
->part
[p
].nr_sects
> 0) {
1785 kdev_t devp
= MKDEV(hwif
->major
, minor
+p
);
1786 struct super_block
* sb
= get_super(devp
);
1787 if (sb
) invalidate_inodes(sb
);
1788 invalidate_buffers (devp
);
1793 hwgroup
= hwif
->hwgroup
;
1796 * free the irq if we were the only hwif using it
1800 if (g
->irq
== hwif
->irq
)
1803 } while (g
!= hwgroup
->hwif
);
1805 free_irq(hwif
->irq
, hwgroup
);
1808 * Note that we only release the standard ports,
1809 * and do not even try to handle any extra ports
1810 * allocated for weird IDE interface chipsets.
1812 ide_release_region(hwif
->io_ports
[IDE_DATA_OFFSET
], 8);
1813 if (hwif
->io_ports
[IDE_CONTROL_OFFSET
])
1814 ide_release_region(hwif
->io_ports
[IDE_CONTROL_OFFSET
], 1);
1817 * Remove us from the hwgroup, and free
1818 * the hwgroup if we were the only member
1821 for (i
= 0; i
< MAX_DRIVES
; ++i
) {
1822 drive
= &hwif
->drives
[i
];
1823 if (!drive
->present
)
1825 while (hwgroup
->drive
->next
!= drive
)
1826 hwgroup
->drive
= hwgroup
->drive
->next
;
1827 hwgroup
->drive
->next
= drive
->next
;
1828 if (hwgroup
->drive
== drive
)
1829 hwgroup
->drive
= NULL
;
1830 if (drive
->id
!= NULL
) {
1838 while (hwgroup
->hwif
->next
!= hwif
)
1839 hwgroup
->hwif
= hwgroup
->hwif
->next
;
1840 hwgroup
->hwif
->next
= hwif
->next
;
1841 if (hwgroup
->hwif
== hwif
)
1844 hwgroup
->hwif
= HWIF(hwgroup
->drive
);
1846 #ifdef CONFIG_BLK_DEV_IDEDMA
1848 (void) ide_release_dma(hwif
);
1849 #endif /* CONFIG_BLK_DEV_IDEDMA */
1852 * Remove us from the kernel's knowledge
1854 unregister_blkdev(hwif
->major
, hwif
->name
);
1855 kfree(blksize_size
[hwif
->major
]);
1856 kfree(max_sectors
[hwif
->major
]);
1857 kfree(max_readahead
[hwif
->major
]);
1858 blk_dev
[hwif
->major
].request_fn
= NULL
;
1859 blk_dev
[hwif
->major
].data
= NULL
;
1860 blk_dev
[hwif
->major
].queue
= NULL
;
1861 blksize_size
[hwif
->major
] = NULL
;
1862 for (gdp
= &gendisk_head
; *gdp
; gdp
= &((*gdp
)->next
))
1863 if (*gdp
== hwif
->gd
)
1866 printk("gd not in disk chain!\n");
1868 gd
= *gdp
; *gdp
= gd
->next
;
1873 init_hwif_data (index
); /* restore hwif data to pristine status */
1875 restore_flags(flags
); /* all CPUs */
1879 * Setup hw_regs_t structure described by parameters. You
1880 * may set up the hw structure yourself OR use this routine to
1883 void ide_setup_ports ( hw_regs_t
*hw
,
1884 ide_ioreg_t base
, int *offsets
,
1885 ide_ioreg_t ctrl
, ide_ioreg_t intr
,
1886 ide_ack_intr_t
*ack_intr
, int irq
)
1890 for (i
= 0; i
< IDE_NR_PORTS
; i
++) {
1891 if (offsets
[i
] == -1) {
1893 case IDE_CONTROL_OFFSET
:
1894 hw
->io_ports
[i
] = ctrl
;
1896 case IDE_IRQ_OFFSET
:
1897 hw
->io_ports
[i
] = intr
;
1900 hw
->io_ports
[i
] = 0;
1904 hw
->io_ports
[i
] = base
+ offsets
[i
];
1908 hw
->ack_intr
= ack_intr
;
1912 * Register an IDE interface, specifing exactly the registers etc
1913 * Set init=1 iff calling before probes have taken place.
1915 int ide_register_hw (hw_regs_t
*hw
, ide_hwif_t
**hwifp
)
1917 int index
, retry
= 1;
1921 for (index
= 0; index
< MAX_HWIFS
; ++index
) {
1922 hwif
= &ide_hwifs
[index
];
1923 if (hwif
->hw
.io_ports
[IDE_DATA_OFFSET
] == hw
->io_ports
[IDE_DATA_OFFSET
])
1926 for (index
= 0; index
< MAX_HWIFS
; ++index
) {
1927 hwif
= &ide_hwifs
[index
];
1928 if ((!hwif
->present
&& !initializing
) ||
1929 (!hwif
->hw
.io_ports
[IDE_DATA_OFFSET
] && initializing
))
1932 for (index
= 0; index
< MAX_HWIFS
; index
++)
1933 ide_unregister(index
);
1938 ide_unregister(index
);
1941 memcpy(&hwif
->hw
, hw
, sizeof(*hw
));
1942 memcpy(hwif
->io_ports
, hwif
->hw
.io_ports
, sizeof(hwif
->hw
.io_ports
));
1943 hwif
->irq
= hw
->irq
;
1946 if (!initializing
) {
1947 ide_init_module(IDE_PROBE_MODULE
);
1948 ide_init_module(IDE_DRIVER_MODULE
);
1954 return (initializing
|| hwif
->present
) ? index
: -1;
1958 * Compatability function with existing drivers. If you want
1959 * something different, use the function above.
1961 int ide_register (int arg1
, int arg2
, int irq
)
1965 ide_init_hwif_ports(&hw
, (ide_ioreg_t
) arg1
, (ide_ioreg_t
) arg2
, NULL
);
1967 return ide_register_hw(&hw
, NULL
);
1970 void 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
)
1972 ide_settings_t
**p
= (ide_settings_t
**) &drive
->settings
, *setting
= NULL
;
1974 while ((*p
) && strcmp((*p
)->name
, name
) < 0)
1976 if ((setting
= kmalloc(sizeof(*setting
), GFP_KERNEL
)) == NULL
)
1978 memset(setting
, 0, sizeof(*setting
));
1979 if ((setting
->name
= kmalloc(strlen(name
) + 1, GFP_KERNEL
)) == NULL
)
1981 strcpy(setting
->name
, name
); setting
->rw
= rw
;
1982 setting
->read_ioctl
= read_ioctl
; setting
->write_ioctl
= write_ioctl
;
1983 setting
->data_type
= data_type
; setting
->min
= min
;
1984 setting
->max
= max
; setting
->mul_factor
= mul_factor
;
1985 setting
->div_factor
= div_factor
; setting
->data
= data
;
1986 setting
->set
= set
; setting
->next
= *p
;
1988 setting
->auto_remove
= 1;
1996 void ide_remove_setting(ide_drive_t
*drive
, char *name
)
1998 ide_settings_t
**p
= (ide_settings_t
**) &drive
->settings
, *setting
;
2000 while ((*p
) && strcmp((*p
)->name
, name
))
2002 if ((setting
= (*p
)) == NULL
)
2004 (*p
) = setting
->next
;
2005 kfree(setting
->name
);
2009 static ide_settings_t
*ide_find_setting_by_ioctl(ide_drive_t
*drive
, int cmd
)
2011 ide_settings_t
*setting
= drive
->settings
;
2014 if (setting
->read_ioctl
== cmd
|| setting
->write_ioctl
== cmd
)
2016 setting
= setting
->next
;
2021 ide_settings_t
*ide_find_setting_by_name(ide_drive_t
*drive
, char *name
)
2023 ide_settings_t
*setting
= drive
->settings
;
2026 if (strcmp(setting
->name
, name
) == 0)
2028 setting
= setting
->next
;
2033 static void auto_remove_settings(ide_drive_t
*drive
)
2035 ide_settings_t
*setting
;
2037 setting
= drive
->settings
;
2039 if (setting
->auto_remove
) {
2040 ide_remove_setting(drive
, setting
->name
);
2043 setting
= setting
->next
;
2047 int ide_read_setting(ide_drive_t
*drive
, ide_settings_t
*setting
)
2050 unsigned long flags
;
2052 if ((setting
->rw
& SETTING_READ
)) {
2053 spin_lock_irqsave(&HWGROUP(drive
)->spinlock
, flags
);
2054 switch(setting
->data_type
) {
2056 val
= *((u8
*) setting
->data
);
2059 val
= *((u16
*) setting
->data
);
2063 val
= *((u32
*) setting
->data
);
2066 spin_unlock_irqrestore(&HWGROUP(drive
)->spinlock
, flags
);
2071 int ide_spin_wait_hwgroup (ide_drive_t
*drive
, unsigned long *flags
)
2073 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
2074 unsigned long timeout
= jiffies
+ (3 * HZ
);
2076 spin_lock_irqsave(&hwgroup
->spinlock
, *flags
);
2077 while (hwgroup
->busy
) {
2078 spin_unlock_irqrestore(&hwgroup
->spinlock
, *flags
);
2079 __sti(); /* local CPU only; needed for jiffies */
2080 if (0 < (signed long)(jiffies
- timeout
)) {
2081 printk("%s: channel busy\n", drive
->name
);
2084 spin_lock_irqsave(&hwgroup
->spinlock
, *flags
);
2089 int ide_write_setting(ide_drive_t
*drive
, ide_settings_t
*setting
, int val
)
2091 unsigned long flags
;
2095 if (!capable(CAP_SYS_ADMIN
))
2097 if (!(setting
->rw
& SETTING_WRITE
))
2099 if (val
< setting
->min
|| val
> setting
->max
)
2102 return setting
->set(drive
, val
);
2103 if (ide_spin_wait_hwgroup(drive
, &flags
))
2105 switch (setting
->data_type
) {
2107 *((u8
*) setting
->data
) = val
;
2110 *((u16
*) setting
->data
) = val
;
2113 *((u32
*) setting
->data
) = val
;
2116 p
= (u32
*) setting
->data
;
2117 for (i
= 0; i
< 1 << PARTN_BITS
; i
++, p
++)
2121 spin_unlock_irqrestore(&HWGROUP(drive
)->spinlock
, flags
);
2125 static int set_io_32bit(ide_drive_t
*drive
, int arg
)
2127 drive
->io_32bit
= arg
;
2128 #ifdef CONFIG_BLK_DEV_DTC2278
2129 if (HWIF(drive
)->chipset
== ide_dtc2278
)
2130 HWIF(drive
)->drives
[!drive
->select
.b
.unit
].io_32bit
= arg
;
2131 #endif /* CONFIG_BLK_DEV_DTC2278 */
2135 static int set_using_dma(ide_drive_t
*drive
, int arg
)
2137 if (!drive
->driver
|| !DRIVER(drive
)->supports_dma
)
2139 if (!drive
->id
|| !(drive
->id
->capability
& 1) || !HWIF(drive
)->dmaproc
)
2141 if (HWIF(drive
)->dmaproc(arg
? ide_dma_on
: ide_dma_off
, drive
))
2146 static int set_pio_mode(ide_drive_t
*drive
, int arg
)
2150 if (!HWIF(drive
)->tuneproc
)
2152 if (drive
->special
.b
.set_tune
)
2154 ide_init_drive_cmd(&rq
);
2155 drive
->tune_req
= (byte
) arg
;
2156 drive
->special
.b
.set_tune
= 1;
2157 (void) ide_do_drive_cmd (drive
, &rq
, ide_wait
);
2161 void ide_add_generic_settings(ide_drive_t
*drive
)
2164 * drive setting name read/write access read ioctl write ioctl data type min max mul_factor div_factor data pointer set function
2166 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
);
2167 ide_add_setting(drive
, "keepsettings", SETTING_RW
, HDIO_GET_KEEPSETTINGS
, HDIO_SET_KEEPSETTINGS
, TYPE_BYTE
, 0, 1, 1, 1, &drive
->keep_settings
, NULL
);
2168 ide_add_setting(drive
, "nice1", SETTING_RW
, -1, -1, TYPE_BYTE
, 0, 1, 1, 1, &drive
->nice1
, NULL
);
2169 ide_add_setting(drive
, "pio_mode", SETTING_WRITE
, -1, HDIO_SET_PIO_MODE
, TYPE_BYTE
, 0, 255, 1, 1, NULL
, set_pio_mode
);
2170 ide_add_setting(drive
, "slow", SETTING_RW
, -1, -1, TYPE_BYTE
, 0, 1, 1, 1, &drive
->slow
, NULL
);
2171 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
);
2172 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
);
2175 int ide_wait_cmd (ide_drive_t
*drive
, int cmd
, int nsect
, int feature
, int sectors
, byte
*buf
)
2182 memset(buf
, 0, 4 + SECTOR_WORDS
* 4 * sectors
);
2183 ide_init_drive_cmd(&rq
);
2189 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
2193 * Delay for *at least* 50ms. As we don't know how much time is left
2194 * until the next tick occurs, we wait an extra tick to be safe.
2195 * This is used only during the probing/polling for drives at boot time.
2197 * However, its usefullness may be needed in other places, thus we export it now.
2198 * The future may change this to a millisecond setable delay.
2200 void ide_delay_50ms (void)
2202 unsigned long timeout
= jiffies
+ ((HZ
+ 19)/20) + 1;
2203 while (0 < (signed long)(timeout
- jiffies
));
2206 static int ide_ioctl (struct inode
*inode
, struct file
*file
,
2207 unsigned int cmd
, unsigned long arg
)
2209 int err
= 0, major
, minor
;
2213 ide_settings_t
*setting
;
2215 if (!inode
|| !(dev
= inode
->i_rdev
))
2217 major
= MAJOR(dev
); minor
= MINOR(dev
);
2218 if ((drive
= get_info_ptr(inode
->i_rdev
)) == NULL
)
2221 if ((setting
= ide_find_setting_by_ioctl(drive
, cmd
)) != NULL
) {
2222 if (cmd
== setting
->read_ioctl
) {
2223 err
= ide_read_setting(drive
, setting
);
2224 return err
>= 0 ? put_user(err
, (long *) arg
) : err
;
2226 if ((MINOR(inode
->i_rdev
) & PARTN_MASK
))
2228 return ide_write_setting(drive
, setting
, arg
);
2232 ide_init_drive_cmd (&rq
);
2236 struct hd_geometry
*loc
= (struct hd_geometry
*) arg
;
2237 if (!loc
|| (drive
->media
!= ide_disk
&& drive
->media
!= ide_floppy
)) return -EINVAL
;
2238 if (put_user(drive
->bios_head
, (byte
*) &loc
->heads
)) return -EFAULT
;
2239 if (put_user(drive
->bios_sect
, (byte
*) &loc
->sectors
)) return -EFAULT
;
2240 if (put_user(drive
->bios_cyl
, (unsigned short *) &loc
->cylinders
)) return -EFAULT
;
2241 if (put_user((unsigned)drive
->part
[MINOR(inode
->i_rdev
)&PARTN_MASK
].start_sect
,
2242 (unsigned long *) &loc
->start
)) return -EFAULT
;
2246 case BLKGETSIZE
: /* Return device size */
2247 return put_user(drive
->part
[MINOR(inode
->i_rdev
)&PARTN_MASK
].nr_sects
, (long *) arg
);
2249 case BLKRRPART
: /* Re-read partition tables */
2250 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
2251 return ide_revalidate_disk(inode
->i_rdev
);
2253 case HDIO_OBSOLETE_IDENTITY
:
2254 case HDIO_GET_IDENTITY
:
2255 if (MINOR(inode
->i_rdev
) & PARTN_MASK
)
2257 if (drive
->id
== NULL
)
2259 if (copy_to_user((char *)arg
, (char *)drive
->id
, (cmd
== HDIO_GET_IDENTITY
) ? sizeof(*drive
->id
) : 142))
2264 return put_user(drive
->dsc_overlap
<< IDE_NICE_DSC_OVERLAP
|
2265 drive
->atapi_overlap
<< IDE_NICE_ATAPI_OVERLAP
|
2266 drive
->nice0
<< IDE_NICE_0
|
2267 drive
->nice1
<< IDE_NICE_1
|
2268 drive
->nice2
<< IDE_NICE_2
,
2270 case HDIO_DRIVE_CMD
:
2272 byte args
[4], *argbuf
= args
;
2274 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
2275 if (NULL
== (void *) arg
)
2276 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
2277 if (copy_from_user(args
, (void *)arg
, 4))
2280 argsize
= 4 + (SECTOR_WORDS
* 4 * args
[3]);
2281 argbuf
= kmalloc(argsize
, GFP_KERNEL
);
2284 memcpy(argbuf
, args
, 4);
2286 if ((((byte
*)arg
)[0] == WIN_SETFEATURES
) &&
2287 (((byte
*)arg
)[1] > 66) &&
2288 (((byte
*)arg
)[2] == 3) &&
2289 ((drive
->id
->word93
& 0x2000) == 0)) {
2290 printk("%s: Speed warnings UDMA 3/4 is not functional.\n", drive
->name
);
2293 err
= ide_wait_cmd(drive
, args
[0], args
[1], args
[2], args
[3], argbuf
);
2295 (((byte
*)arg
)[0] == WIN_SETFEATURES
) &&
2296 (((byte
*)arg
)[1] >= 16) &&
2297 (((byte
*)arg
)[2] == 3) &&
2298 (drive
->id
->dma_ultra
||
2299 drive
->id
->dma_mword
||
2300 drive
->id
->dma_1word
)) {
2303 * Re-read drive->id for possible DMA mode
2304 * change (copied from ide-probe.c)
2306 struct hd_driveid
*id
;
2307 unsigned long timeout
, irqs
, flags
;
2309 probe_irq_off(probe_irq_on());
2310 irqs
= probe_irq_on();
2311 if (IDE_CONTROL_REG
)
2312 OUT_BYTE(drive
->ctl
,IDE_CONTROL_REG
);
2314 OUT_BYTE(WIN_IDENTIFY
, IDE_COMMAND_REG
);
2315 timeout
= jiffies
+ WAIT_WORSTCASE
;
2317 if (0 < (signed long)(jiffies
- timeout
)) {
2319 (void) probe_irq_off(irqs
);
2320 goto abort
; /* drive timed-out */
2322 ide_delay_50ms(); /* give drive a breather */
2323 } while (IN_BYTE(IDE_ALTSTATUS_REG
) & BUSY_STAT
);
2324 ide_delay_50ms(); /* wait for IRQ and DRQ_STAT */
2325 if (!OK_STAT(GET_STAT(),DRQ_STAT
,BAD_R_STAT
))
2327 __save_flags(flags
); /* local CPU only */
2328 __cli(); /* local CPU only; some systems need this */
2329 id
= kmalloc(SECTOR_WORDS
*4, GFP_ATOMIC
);
2330 ide_input_data(drive
, id
, SECTOR_WORDS
);
2331 (void) GET_STAT(); /* clear drive IRQ */
2332 ide__sti(); /* local CPU only */
2333 __restore_flags(flags
); /* local CPU only */
2334 ide_fix_driveid(id
);
2335 if (id
&& id
->cyls
) {
2336 drive
->id
->dma_ultra
= id
->dma_ultra
;
2337 drive
->id
->dma_mword
= id
->dma_mword
;
2338 drive
->id
->dma_1word
= id
->dma_1word
;
2339 /* anything more ? */
2341 printk("%s: dma_ultra=%04X, dma_mword=%04X, dma_1word=%04X\n",
2342 drive
->name
, id
->dma_ultra
, id
->dma_mword
, id
->dma_1word
);
2348 if (copy_to_user((void *)arg
, argbuf
, argsize
))
2355 case HDIO_SCAN_HWIF
:
2358 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
2359 if (copy_from_user(args
, (void *)arg
, 3 * sizeof(int)))
2361 if (ide_register(args
[0], args
[1], args
[2]) == -1)
2365 case HDIO_UNREGISTER_HWIF
:
2366 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
2367 /* should I check here for arg > MAX_HWIFS, or
2368 just let ide_unregister fail silently? -- shaver */
2369 ide_unregister(arg
);
2372 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
2373 if (drive
->driver
== NULL
)
2375 if (arg
!= (arg
& ((1 << IDE_NICE_DSC_OVERLAP
) | (1 << IDE_NICE_1
))))
2377 drive
->dsc_overlap
= (arg
>> IDE_NICE_DSC_OVERLAP
) & 1;
2378 if (drive
->dsc_overlap
&& !DRIVER(drive
)->supports_dsc_overlap
) {
2379 drive
->dsc_overlap
= 0;
2382 drive
->nice1
= (arg
>> IDE_NICE_1
) & 1;
2390 return blk_ioctl(inode
->i_rdev
, cmd
, arg
);
2393 if (drive
->driver
!= NULL
)
2394 return DRIVER(drive
)->ioctl(drive
, inode
, file
, cmd
, arg
);
2399 static int ide_check_media_change (kdev_t i_rdev
)
2403 if ((drive
= get_info_ptr(i_rdev
)) == NULL
)
2405 if (drive
->driver
!= NULL
)
2406 return DRIVER(drive
)->media_change(drive
);
2410 void ide_fixstring (byte
*s
, const int bytecount
, const int byteswap
)
2412 byte
*p
= s
, *end
= &s
[bytecount
& ~1]; /* bytecount must be even */
2415 /* convert from big-endian to host byte order */
2416 for (p
= end
; p
!= s
;) {
2417 unsigned short *pp
= (unsigned short *) (p
-= 2);
2422 /* strip leading blanks */
2423 while (s
!= end
&& *s
== ' ')
2426 /* compress internal blanks and strip trailing blanks */
2427 while (s
!= end
&& *s
) {
2428 if (*s
++ != ' ' || (s
!= end
&& *s
&& *s
!= ' '))
2432 /* wipe out trailing garbage */
2440 char *ide_xfer_verbose (byte xfer_rate
) {
2442 case XFER_UDMA_4
: return("UDMA 4");
2443 case XFER_UDMA_3
: return("UDMA 3");
2444 case XFER_UDMA_2
: return("UDMA 2");
2445 case XFER_UDMA_1
: return("UDMA 1");
2446 case XFER_UDMA_0
: return("UDMA 0");
2447 case XFER_MW_DMA_2
: return("MW DMA 2");
2448 case XFER_MW_DMA_1
: return("MW DMA 1");
2449 case XFER_MW_DMA_0
: return("MW DMA 0");
2450 case XFER_SW_DMA_2
: return("SW DMA 2");
2451 case XFER_SW_DMA_1
: return("SW DMA 1");
2452 case XFER_SW_DMA_0
: return("SW DMA 0");
2453 case XFER_PIO_4
: return("PIO 4");
2454 case XFER_PIO_3
: return("PIO 3");
2455 case XFER_PIO_2
: return("PIO 2");
2456 case XFER_PIO_1
: return("PIO 1");
2457 case XFER_PIO_0
: return("PIO 0");
2458 case XFER_PIO_SLOW
: return("PIO SLOW");
2459 default: return("XFER ERROR");
2464 * stridx() returns the offset of c within s,
2465 * or -1 if c is '\0' or not found within s.
2467 __initfunc(static int stridx (const char *s
, char c
))
2469 char *i
= strchr(s
, c
);
2470 return (i
&& c
) ? i
- s
: -1;
2474 * match_parm() does parsing for ide_setup():
2476 * 1. the first char of s must be '='.
2477 * 2. if the remainder matches one of the supplied keywords,
2478 * the index (1 based) of the keyword is negated and returned.
2479 * 3. if the remainder is a series of no more than max_vals numbers
2480 * separated by commas, the numbers are saved in vals[] and a
2481 * count of how many were saved is returned. Base10 is assumed,
2482 * and base16 is allowed when prefixed with "0x".
2483 * 4. otherwise, zero is returned.
2485 __initfunc(static int match_parm (char *s
, const char *keywords
[], int vals
[], int max_vals
))
2487 static const char *decimal
= "0123456789";
2488 static const char *hex
= "0123456789abcdef";
2493 * Try matching against the supplied keywords,
2494 * and return -(index+1) if we match one
2496 if (keywords
!= NULL
) {
2497 for (i
= 0; *keywords
!= NULL
; ++i
) {
2498 if (!strcmp(s
, *keywords
++))
2503 * Look for a series of no more than "max_vals"
2504 * numeric values separated by commas, in base10,
2505 * or base16 when prefixed with "0x".
2506 * Return a count of how many were found.
2508 for (n
= 0; (i
= stridx(decimal
, *s
)) >= 0;) {
2510 while ((i
= stridx(decimal
, *++s
)) >= 0)
2511 vals
[n
] = (vals
[n
] * 10) + i
;
2512 if (*s
== 'x' && !vals
[n
]) {
2513 while ((i
= stridx(hex
, *++s
)) >= 0)
2514 vals
[n
] = (vals
[n
] * 0x10) + i
;
2516 if (++n
== max_vals
)
2518 if (*s
== ',' || *s
== ';')
2524 return 0; /* zero = nothing matched */
2528 * ide_setup() gets called VERY EARLY during initialization,
2529 * to handle kernel "command line" strings beginning with "hdx="
2530 * or "ide". Here is the complete set currently supported:
2532 * "hdx=" is recognized for all "x" from "a" to "h", such as "hdc".
2533 * "idex=" is recognized for all "x" from "0" to "3", such as "ide1".
2535 * "hdx=noprobe" : drive may be present, but do not probe for it
2536 * "hdx=none" : drive is NOT present, ignore cmos and do not probe
2537 * "hdx=nowerr" : ignore the WRERR_STAT bit on this drive
2538 * "hdx=cdrom" : drive is present, and is a cdrom drive
2539 * "hdx=cyl,head,sect" : disk drive is present, with specified geometry
2540 * "hdx=autotune" : driver will attempt to tune interface speed
2541 * to the fastest PIO mode supported,
2542 * if possible for this drive only.
2543 * Not fully supported by all chipset types,
2544 * and quite likely to cause trouble with
2545 * older/odd IDE drives.
2547 * "hdx=slow" : insert a huge pause after each access to the data
2548 * port. Should be used only as a last resort.
2550 * "hdx=swapdata" : when the drive is a disk, byte swap all data
2551 * "hdx=bswap" : same as above..........
2553 * "idebus=xx" : inform IDE driver of VESA/PCI bus speed in MHz,
2554 * where "xx" is between 20 and 66 inclusive,
2555 * used when tuning chipset PIO modes.
2556 * For PCI bus, 25 is correct for a P75 system,
2557 * 30 is correct for P90,P120,P180 systems,
2558 * and 33 is used for P100,P133,P166 systems.
2559 * If in doubt, use idebus=33 for PCI.
2560 * As for VLB, it is safest to not specify it.
2562 * "idex=noprobe" : do not attempt to access/use this interface
2563 * "idex=base" : probe for an interface at the addr specified,
2564 * where "base" is usually 0x1f0 or 0x170
2565 * and "ctl" is assumed to be "base"+0x206
2566 * "idex=base,ctl" : specify both base and ctl
2567 * "idex=base,ctl,irq" : specify base, ctl, and irq number
2568 * "idex=autotune" : driver will attempt to tune interface speed
2569 * to the fastest PIO mode supported,
2570 * for all drives on this interface.
2571 * Not fully supported by all chipset types,
2572 * and quite likely to cause trouble with
2573 * older/odd IDE drives.
2574 * "idex=noautotune" : driver will NOT attempt to tune interface speed
2575 * This is the default for most chipsets,
2576 * except the cmd640.
2577 * "idex=serialize" : do not overlap operations on idex and ide(x^1)
2578 * "idex=four" : four drives on idex and ide(x^1) share same ports
2579 * "idex=reset" : reset interface before first use
2580 * "idex=dma" : enable DMA by default on both drives if possible
2582 * "splitfifo=betweenChan"
2583 * : FIFO Configuration of VIA 82c586(<nothing>,"A"or"B").
2584 * --see what follows...
2585 * "splitfifo=betweenChan,thresholdprim,thresholdsec"
2586 * : FIFO Configuration of VIA 82c586(<nothing>,"A" or "B").
2587 * betweenChan = 1(all FIFO's to primary channel)
2588 * , 2(all FIFO's to secondary channel)
2589 * , 3 or 4(evenly shared between them).
2590 * note: without FIFO, a channel is (u)dma disabled!
2591 * thresholdprim = 4, 3, 2 or 1
2592 * (standing for 1, 3/4, 1/2, 1/4).
2593 * Sets the threshold of FIFO to begin dma
2594 * transfer on the primary channel.
2595 * thresholdsec = cf upper, but for secondary channel.
2597 * The following are valid ONLY on ide0, (except dc4030)
2598 * and the defaults for the base,ctl ports must not be altered.
2600 * "ide0=dtc2278" : probe/support DTC2278 interface
2601 * "ide0=ht6560b" : probe/support HT6560B interface
2602 * "ide0=cmd640_vlb" : *REQUIRED* for VLB cards with the CMD640 chip
2603 * (not for PCI -- automatically detected)
2604 * "ide0=qd6580" : probe/support qd6580 interface
2605 * "ide0=ali14xx" : probe/support ali14xx chipsets (ALI M1439, M1443, M1445)
2606 * "ide0=umc8672" : probe/support umc8672 chipsets
2607 * "idex=dc4030" : probe/support Promise DC4030VL interface
2609 __initfunc(void ide_setup (char *s
))
2614 unsigned int hw
, unit
;
2615 const char max_drive
= 'a' + ((MAX_HWIFS
* MAX_DRIVES
) - 1);
2616 const char max_hwif
= '0' + (MAX_HWIFS
- 1);
2618 printk("ide_setup: %s", s
);
2620 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
2621 if (!strcmp(s
, "ide=doubler")) {
2622 extern int ide_doubler
;
2624 printk("ide: Enabled support for IDE doublers\n");
2628 #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
2633 * Look for drive options: "hdx="
2635 if (s
[0] == 'h' && s
[1] == 'd' && s
[2] >= 'a' && s
[2] <= max_drive
) {
2636 const char *hd_words
[] = {"none", "noprobe", "nowerr", "cdrom",
2637 "serialize", "autotune", "noautotune",
2638 "slow", "swapdata", "bswap", NULL
};
2640 hw
= unit
/ MAX_DRIVES
;
2641 unit
= unit
% MAX_DRIVES
;
2642 hwif
= &ide_hwifs
[hw
];
2643 drive
= &hwif
->drives
[unit
];
2644 if (strncmp(s
+ 4, "ide-", 4) == 0) {
2645 strncpy(drive
->driver_req
, s
+ 4, 9);
2648 switch (match_parm(&s
[3], hd_words
, vals
, 3)) {
2649 case -1: /* "none" */
2650 drive
->nobios
= 1; /* drop into "noprobe" */
2651 case -2: /* "noprobe" */
2654 case -3: /* "nowerr" */
2655 drive
->bad_wstat
= BAD_R_STAT
;
2658 case -4: /* "cdrom" */
2660 drive
->media
= ide_cdrom
;
2663 case -5: /* "serialize" */
2664 printk(" -- USE \"ide%d=serialize\" INSTEAD", hw
);
2666 case -6: /* "autotune" */
2667 drive
->autotune
= 1;
2669 case -7: /* "noautotune" */
2670 drive
->autotune
= 2;
2672 case -8: /* "slow" */
2675 case -9: /* swapdata or bswap */
2679 case 3: /* cyl,head,sect */
2680 drive
->media
= ide_disk
;
2681 drive
->cyl
= drive
->bios_cyl
= vals
[0];
2682 drive
->head
= drive
->bios_head
= vals
[1];
2683 drive
->sect
= drive
->bios_sect
= vals
[2];
2685 drive
->forced_geom
= 1;
2693 #if defined(CONFIG_BLK_DEV_VIA82C586)
2695 * Look for drive option "splitfifo=..."
2698 if (s
[0] == 's' && s
[1] == 'p' && s
[2] == 'l' &&
2699 s
[3] == 'i' && s
[4] == 't' && s
[5] == 'f' &&
2700 s
[6] == 'i' && s
[7] == 'f' && s
[8] == 'o') {
2701 byte tmp
= 0x3a; /* default config byte */
2703 i
= match_parm(&s
[9], NULL
, vals
, 3);
2707 if ((vals
[1] > 0) && (vals
[1] < 5)) {
2708 /* sets threshold for primary Channel: */
2709 byte x
= 4 - vals
[1];
2714 if ((vals
[2] > 0) && (vals
[2] < 5)) {
2715 /* sets threshold for secondary Channel: */
2716 byte x
= 4 - vals
[2];
2722 /* set the FIFO config between channels to 0: */
2724 /* set the needed FIFO config between channels: */
2725 if (vals
[0] == 1) /* primary fifo only */
2727 else if (vals
[0] == 2) /* secondary fifo only */
2729 else if (vals
[0] == 4) /* other shared fifo config */
2731 else if (vals
[0] == 3) /* default config */
2739 /* set the found option in fifoconfig */
2743 #endif /* defined(CONFIG_BLK_DEV_VIA82C586) */
2745 if (s
[0] != 'i' || s
[1] != 'd' || s
[2] != 'e')
2748 * Look for bus speed option: "idebus="
2750 if (s
[3] == 'b' && s
[4] == 'u' && s
[5] == 's') {
2751 if (match_parm(&s
[6], NULL
, vals
, 1) != 1)
2753 if (vals
[0] >= 20 && vals
[0] <= 66)
2754 idebus_parameter
= vals
[0];
2756 printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
2760 * Look for interface options: "idex="
2762 if (s
[3] >= '0' && s
[3] <= max_hwif
) {
2764 * Be VERY CAREFUL changing this: note hardcoded indexes below
2766 const char *ide_words
[] = {"noprobe", "serialize", "autotune", "noautotune", "reset", "dma", "four",
2767 "qd6580", "ht6560b", "cmd640_vlb", "dtc2278", "umc8672", "ali14xx", "dc4030", NULL
};
2769 hwif
= &ide_hwifs
[hw
];
2770 i
= match_parm(&s
[4], ide_words
, vals
, 3);
2773 * Cryptic check to ensure chipset not already set for hwif:
2775 if (i
> 0 || i
<= -7) { /* is parameter a chipset name? */
2776 if (hwif
->chipset
!= ide_unknown
)
2777 goto bad_option
; /* chipset already specified */
2778 if (i
<= -7 && i
!= -14 && hw
!= 0)
2779 goto bad_hwif
; /* chipset drivers are for "ide0=" only */
2780 if (i
<= -7 && i
!= -14 && ide_hwifs
[hw
+1].chipset
!= ide_unknown
)
2781 goto bad_option
; /* chipset for 2nd port already specified */
2786 #ifdef CONFIG_BLK_DEV_PDC4030
2787 case -14: /* "dc4030" */
2789 extern void setup_pdc4030(ide_hwif_t
*);
2790 setup_pdc4030(hwif
);
2793 #endif /* CONFIG_BLK_DEV_PDC4030 */
2794 #ifdef CONFIG_BLK_DEV_ALI14XX
2795 case -13: /* "ali14xx" */
2797 extern void init_ali14xx (void);
2801 #endif /* CONFIG_BLK_DEV_ALI14XX */
2802 #ifdef CONFIG_BLK_DEV_UMC8672
2803 case -12: /* "umc8672" */
2805 extern void init_umc8672 (void);
2809 #endif /* CONFIG_BLK_DEV_UMC8672 */
2810 #ifdef CONFIG_BLK_DEV_DTC2278
2811 case -11: /* "dtc2278" */
2813 extern void init_dtc2278 (void);
2817 #endif /* CONFIG_BLK_DEV_DTC2278 */
2818 #ifdef CONFIG_BLK_DEV_CMD640
2819 case -10: /* "cmd640_vlb" */
2821 extern int cmd640_vlb
; /* flag for cmd640.c */
2825 #endif /* CONFIG_BLK_DEV_CMD640 */
2826 #ifdef CONFIG_BLK_DEV_HT6560B
2827 case -9: /* "ht6560b" */
2829 extern void init_ht6560b (void);
2833 #endif /* CONFIG_BLK_DEV_HT6560B */
2834 #if CONFIG_BLK_DEV_QD6580
2835 case -8: /* "qd6580" */
2837 extern void init_qd6580 (void);
2841 #endif /* CONFIG_BLK_DEV_QD6580 */
2842 #ifdef CONFIG_BLK_DEV_4DRIVES
2843 case -7: /* "four" drives on one set of ports */
2845 ide_hwif_t
*mate
= &ide_hwifs
[hw
^1];
2846 mate
->drives
[0].select
.all
^= 0x20;
2847 mate
->drives
[1].select
.all
^= 0x20;
2848 hwif
->chipset
= mate
->chipset
= ide_4drives
;
2849 mate
->irq
= hwif
->irq
;
2850 memcpy(mate
->io_ports
, hwif
->io_ports
, sizeof(hwif
->io_ports
));
2853 #endif /* CONFIG_BLK_DEV_4DRIVES */
2857 case -5: /* "reset" */
2860 case -4: /* "noautotune" */
2861 hwif
->drives
[0].autotune
= 2;
2862 hwif
->drives
[1].autotune
= 2;
2864 case -3: /* "autotune" */
2865 hwif
->drives
[0].autotune
= 1;
2866 hwif
->drives
[1].autotune
= 1;
2868 case -2: /* "serialize" */
2870 hwif
->mate
= &ide_hwifs
[hw
^1];
2871 hwif
->mate
->mate
= hwif
;
2872 hwif
->serialized
= hwif
->mate
->serialized
= 1;
2875 case -1: /* "noprobe" */
2880 vals
[1] = vals
[0] + 0x206; /* default ctl */
2881 case 2: /* base,ctl */
2882 vals
[2] = 0; /* default irq = probe for it */
2883 case 3: /* base,ctl,irq */
2884 hwif
->hw
.irq
= vals
[2];
2885 ide_init_hwif_ports(&hwif
->hw
, (ide_ioreg_t
) vals
[0], (ide_ioreg_t
) vals
[1], &hwif
->irq
);
2886 memcpy(hwif
->io_ports
, hwif
->hw
.io_ports
, sizeof(hwif
->io_ports
));
2887 hwif
->irq
= vals
[2];
2889 hwif
->chipset
= ide_generic
;
2892 case 0: goto bad_option
;
2894 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
2899 printk(" -- BAD OPTION\n");
2902 printk("-- NOT SUPPORTED ON ide%d", hw
);
2908 * This routine is called from the partition-table code in genhd.c
2909 * to "convert" a drive to a logical geometry with fewer than 1024 cyls.
2911 * The second parameter, "xparm", determines exactly how the translation
2913 * 0 = convert to CHS with fewer than 1024 cyls
2914 * using the same method as Ontrack DiskManager.
2915 * 1 = same as "0", plus offset everything by 63 sectors.
2916 * -1 = similar to "0", plus redirect sector 0 to sector 1.
2917 * >1 = convert to a CHS geometry with "xparm" heads.
2919 * Returns 0 if the translation was not possible, if the device was not
2920 * an IDE disk drive, or if a geometry was "forced" on the commandline.
2921 * Returns 1 if the geometry translation was successful.
2924 int ide_xlate_1024 (kdev_t i_rdev
, int xparm
, const char *msg
)
2928 static const byte head_vals
[] = {4, 8, 16, 32, 64, 128, 255, 0};
2929 const byte
*heads
= head_vals
;
2930 unsigned long tracks
;
2932 drive
= get_info_ptr(i_rdev
);
2936 if (drive
->forced_geom
) {
2938 * Update the current 3D drive values.
2940 drive
->id
->cur_cyls
= drive
->bios_cyl
;
2941 drive
->id
->cur_heads
= drive
->bios_head
;
2942 drive
->id
->cur_sectors
= drive
->bios_sect
;
2946 if (xparm
> 1 && xparm
<= drive
->bios_head
&& drive
->bios_sect
== 63) {
2948 * Update the current 3D drive values.
2950 drive
->id
->cur_cyls
= drive
->bios_cyl
;
2951 drive
->id
->cur_heads
= drive
->bios_head
;
2952 drive
->id
->cur_sectors
= drive
->bios_sect
;
2953 return 0; /* we already have a translation */
2958 if (xparm
< 0 && (drive
->bios_cyl
* drive
->bios_head
* drive
->bios_sect
) < (1024 * 16 * 63)) {
2960 * Update the current 3D drive values.
2962 drive
->id
->cur_cyls
= drive
->bios_cyl
;
2963 drive
->id
->cur_heads
= drive
->bios_head
;
2964 drive
->id
->cur_sectors
= drive
->bios_sect
;
2965 return 0; /* small disk: no translation needed */
2969 drive
->cyl
= drive
->id
->cyls
;
2970 drive
->head
= drive
->id
->heads
;
2971 drive
->sect
= drive
->id
->sectors
;
2973 drive
->bios_cyl
= drive
->cyl
;
2974 drive
->bios_head
= drive
->head
;
2975 drive
->bios_sect
= drive
->sect
;
2976 drive
->special
.b
.set_geometry
= 1;
2978 tracks
= drive
->bios_cyl
* drive
->bios_head
* drive
->bios_sect
/ 63;
2979 drive
->bios_sect
= 63;
2981 drive
->bios_head
= xparm
;
2982 drive
->bios_cyl
= tracks
/ drive
->bios_head
;
2984 while (drive
->bios_cyl
>= 1024) {
2985 drive
->bios_head
= *heads
;
2986 drive
->bios_cyl
= tracks
/ drive
->bios_head
;
2990 #if FAKE_FDISK_FOR_EZDRIVE
2992 drive
->remap_0_to_1
= 1;
2993 printk("[remap 0->1] ");
2995 #endif /* FAKE_FDISK_FOR_EZDRIVE */
2998 drive
->bios_cyl
= (tracks
- 1) / drive
->bios_head
;
2999 printk("[remap +63] ");
3003 drive
->part
[0].nr_sects
= current_capacity(drive
);
3004 printk("[%d/%d/%d]", drive
->bios_cyl
, drive
->bios_head
, drive
->bios_sect
);
3006 * Update the current 3D drive values.
3008 drive
->id
->cur_cyls
= drive
->bios_cyl
;
3009 drive
->id
->cur_heads
= drive
->bios_head
;
3010 drive
->id
->cur_sectors
= drive
->bios_sect
;
3015 * probe_for_hwifs() finds/initializes "known" IDE interfaces
3017 __initfunc(static void probe_for_hwifs (void))
3022 #ifdef CONFIG_BLK_DEV_IDEPCI
3025 #ifdef CONFIG_BLK_DEV_RZ1000
3027 extern void ide_probe_for_rz100x(void);
3028 ide_probe_for_rz100x();
3030 #endif /* CONFIG_BLK_DEV_RZ1000 */
3031 #endif /* CONFIG_BLK_DEV_IDEPCI */
3033 #endif /* CONFIG_PCI */
3035 #ifdef CONFIG_BLK_DEV_CMD640
3037 extern void ide_probe_for_cmd640x(void);
3038 ide_probe_for_cmd640x();
3040 #endif /* CONFIG_BLK_DEV_CMD640 */
3041 #ifdef CONFIG_BLK_DEV_PDC4030
3043 extern int init_pdc4030(void);
3044 (void) init_pdc4030();
3046 #endif /* CONFIG_BLK_DEV_PDC4030 */
3047 #ifdef CONFIG_BLK_DEV_IDE_PMAC
3049 extern void pmac_ide_probe(void);
3052 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
3053 #ifdef CONFIG_BLK_DEV_IDE_ICSIDE
3055 extern void icside_init(void);
3058 #endif /* CONFIG_BLK_DEV_IDE_ICSIDE */
3059 #ifdef CONFIG_BLK_DEV_IDE_RAPIDE
3061 extern void rapide_init(void);
3064 #endif /* CONFIG_BLK_DEV_IDE_RAPIDE */
3065 #ifdef CONFIG_BLK_DEV_GAYLE
3067 extern void gayle_init(void);
3070 #endif /* CONFIG_BLK_DEV_GAYLE */
3071 #ifdef CONFIG_BLK_DEV_FALCON_IDE
3073 extern void falconide_init(void);
3076 #endif /* CONFIG_BLK_DEV_FALCON_IDE */
3077 #ifdef CONFIG_BLK_DEV_MAC_IDE
3079 extern void macide_init(void);
3082 #endif /* CONFIG_BLK_DEV_MAC_IDE */
3083 #ifdef CONFIG_BLK_DEV_BUDDHA
3085 extern void buddha_init(void);
3088 #endif /* CONFIG_BLK_DEV_BUDDHA */
3091 __initfunc(void ide_init_builtin_drivers (void))
3094 * Probe for special PCI and other "known" interface chipsets
3098 #ifdef CONFIG_BLK_DEV_IDE
3099 #if defined(__mc68000__) || defined(CONFIG_APUS)
3100 if (ide_hwifs
[0].io_ports
[IDE_DATA_OFFSET
]) {
3101 ide_get_lock(&ide_lock
, NULL
, NULL
); /* for atari only */
3102 disable_irq(ide_hwifs
[0].irq
);
3104 #endif /* __mc68000__ || CONFIG_APUS */
3106 (void) ideprobe_init();
3108 #if defined(__mc68000__) || defined(CONFIG_APUS)
3109 if (ide_hwifs
[0].io_ports
[IDE_DATA_OFFSET
]) {
3110 enable_irq(ide_hwifs
[0].irq
);
3111 ide_release_lock(&ide_lock
); /* for atari only */
3113 #endif /* __mc68000__ || CONFIG_APUS */
3114 #endif /* CONFIG_BLK_DEV_IDE */
3116 #ifdef CONFIG_PROC_FS
3121 * Attempt to match drivers for the available drives
3123 #ifdef CONFIG_BLK_DEV_IDEDISK
3124 (void) idedisk_init();
3125 #endif /* CONFIG_BLK_DEV_IDEDISK */
3126 #ifdef CONFIG_BLK_DEV_IDECD
3127 (void) ide_cdrom_init();
3128 #endif /* CONFIG_BLK_DEV_IDECD */
3129 #ifdef CONFIG_BLK_DEV_IDETAPE
3130 (void) idetape_init();
3131 #endif /* CONFIG_BLK_DEV_IDETAPE */
3132 #ifdef CONFIG_BLK_DEV_IDEFLOPPY
3133 (void) idefloppy_init();
3134 #endif /* CONFIG_BLK_DEV_IDEFLOPPY */
3135 #ifdef CONFIG_BLK_DEV_IDESCSI
3137 (void) idescsi_init();
3139 #warning ide scsi-emulation selected but no SCSI-subsystem in kernel
3141 #endif /* CONFIG_BLK_DEV_IDESCSI */
3144 static int default_cleanup (ide_drive_t
*drive
)
3146 return ide_unregister_subdriver(drive
);
3149 static void default_do_request(ide_drive_t
*drive
, struct request
*rq
, unsigned long block
)
3151 ide_end_request(0, HWGROUP(drive
));
3154 static void default_end_request (byte uptodate
, ide_hwgroup_t
*hwgroup
)
3156 ide_end_request(uptodate
, hwgroup
);
3159 static int default_ioctl (ide_drive_t
*drive
, struct inode
*inode
, struct file
*file
,
3160 unsigned int cmd
, unsigned long arg
)
3165 static int default_open (struct inode
*inode
, struct file
*filp
, ide_drive_t
*drive
)
3171 static void default_release (struct inode
*inode
, struct file
*filp
, ide_drive_t
*drive
)
3175 static int default_check_media_change (ide_drive_t
*drive
)
3180 static void default_pre_reset (ide_drive_t
*drive
)
3184 static unsigned long default_capacity (ide_drive_t
*drive
)
3186 return 0x7fffffff; /* cdrom or tape */
3189 static void default_special (ide_drive_t
*drive
)
3191 special_t
*s
= &drive
->special
;
3194 drive
->mult_req
= 0;
3197 static void setup_driver_defaults (ide_drive_t
*drive
)
3199 ide_driver_t
*d
= drive
->driver
;
3201 if (d
->cleanup
== NULL
) d
->cleanup
= default_cleanup
;
3202 if (d
->do_request
== NULL
) d
->do_request
= default_do_request
;
3203 if (d
->end_request
== NULL
) d
->end_request
= default_end_request
;
3204 if (d
->ioctl
== NULL
) d
->ioctl
= default_ioctl
;
3205 if (d
->open
== NULL
) d
->open
= default_open
;
3206 if (d
->release
== NULL
) d
->release
= default_release
;
3207 if (d
->media_change
== NULL
) d
->media_change
= default_check_media_change
;
3208 if (d
->pre_reset
== NULL
) d
->pre_reset
= default_pre_reset
;
3209 if (d
->capacity
== NULL
) d
->capacity
= default_capacity
;
3210 if (d
->special
== NULL
) d
->special
= default_special
;
3213 ide_drive_t
*ide_scan_devices (byte media
, const char *name
, ide_driver_t
*driver
, int n
)
3215 unsigned int unit
, index
, i
;
3217 for (index
= 0; index
< MAX_HWIFS
; ++index
)
3218 if (ide_hwifs
[index
].present
) goto search
;
3219 ide_init_module(IDE_PROBE_MODULE
);
3221 for (index
= 0, i
= 0; index
< MAX_HWIFS
; ++index
) {
3222 ide_hwif_t
*hwif
= &ide_hwifs
[index
];
3225 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
3226 ide_drive_t
*drive
= &hwif
->drives
[unit
];
3227 char *req
= drive
->driver_req
;
3228 if (*req
&& !strstr(name
, req
))
3230 if (drive
->present
&& drive
->media
== media
&& drive
->driver
== driver
&& ++i
> n
)
3237 #ifdef CONFIG_PROC_FS
3238 static ide_proc_entry_t generic_subdriver_entries
[] = {
3239 { "capacity", S_IFREG
|S_IRUGO
, proc_ide_read_capacity
, NULL
},
3240 { NULL
, 0, NULL
, NULL
}
3244 int ide_register_subdriver (ide_drive_t
*drive
, ide_driver_t
*driver
, int version
)
3246 unsigned long flags
;
3248 save_flags(flags
); /* all CPUs */
3249 cli(); /* all CPUs */
3250 if (version
!= IDE_SUBDRIVER_VERSION
|| !drive
->present
|| drive
->driver
!= NULL
|| drive
->busy
|| drive
->usage
) {
3251 restore_flags(flags
); /* all CPUs */
3254 drive
->driver
= driver
;
3255 setup_driver_defaults(drive
);
3256 restore_flags(flags
); /* all CPUs */
3257 if (drive
->autotune
!= 2) {
3258 if (driver
->supports_dma
&& HWIF(drive
)->dmaproc
!= NULL
)
3259 (void) (HWIF(drive
)->dmaproc(ide_dma_check
, drive
));
3260 drive
->dsc_overlap
= (drive
->next
!= drive
&& driver
->supports_dsc_overlap
);
3263 drive
->revalidate
= 1;
3264 #ifdef CONFIG_PROC_FS
3265 ide_add_proc_entries(drive
->proc
, generic_subdriver_entries
, drive
);
3266 ide_add_proc_entries(drive
->proc
, driver
->proc
, drive
);
3271 int ide_unregister_subdriver (ide_drive_t
*drive
)
3273 unsigned long flags
;
3275 save_flags(flags
); /* all CPUs */
3276 cli(); /* all CPUs */
3277 if (drive
->usage
|| drive
->busy
|| drive
->driver
== NULL
|| DRIVER(drive
)->busy
) {
3278 restore_flags(flags
); /* all CPUs */
3281 #ifdef CONFIG_PROC_FS
3282 ide_remove_proc_entries(drive
->proc
, DRIVER(drive
)->proc
);
3283 ide_remove_proc_entries(drive
->proc
, generic_subdriver_entries
);
3285 auto_remove_settings(drive
);
3286 drive
->driver
= NULL
;
3287 restore_flags(flags
); /* all CPUs */
3291 int ide_register_module (ide_module_t
*module
)
3293 ide_module_t
*p
= ide_modules
;
3300 module
->next
= ide_modules
;
3301 ide_modules
= module
;
3302 revalidate_drives();
3306 void ide_unregister_module (ide_module_t
*module
)
3310 for (p
= &ide_modules
; (*p
) && (*p
) != module
; p
= &((*p
)->next
));
3315 struct file_operations ide_fops
[] = {{
3316 NULL
, /* lseek - default */
3317 block_read
, /* read - general block-dev read */
3318 block_write
, /* write - general block-dev write */
3319 NULL
, /* readdir - bad */
3321 ide_ioctl
, /* ioctl */
3323 ide_open
, /* open */
3325 ide_release
, /* release */
3326 block_fsync
, /* fsync */
3328 ide_check_media_change
, /* check_media_change */
3329 ide_revalidate_disk
/* revalidate */
3332 EXPORT_SYMBOL(ide_hwifs
);
3333 EXPORT_SYMBOL(ide_register_module
);
3334 EXPORT_SYMBOL(ide_unregister_module
);
3335 EXPORT_SYMBOL(ide_spin_wait_hwgroup
);
3340 EXPORT_SYMBOL(drive_is_flashcard
);
3341 EXPORT_SYMBOL(ide_timer_expiry
);
3342 EXPORT_SYMBOL(ide_intr
);
3343 EXPORT_SYMBOL(ide_geninit
);
3344 EXPORT_SYMBOL(ide_fops
);
3345 EXPORT_SYMBOL(ide_get_queue
);
3346 EXPORT_SYMBOL(do_ide0_request
);
3347 EXPORT_SYMBOL(ide_add_generic_settings
);
3349 EXPORT_SYMBOL(do_ide1_request
);
3350 #endif /* MAX_HWIFS > 1 */
3352 EXPORT_SYMBOL(do_ide2_request
);
3353 #endif /* MAX_HWIFS > 2 */
3355 EXPORT_SYMBOL(do_ide3_request
);
3356 #endif /* MAX_HWIFS > 3 */
3358 EXPORT_SYMBOL(do_ide4_request
);
3359 #endif /* MAX_HWIFS > 4 */
3361 EXPORT_SYMBOL(do_ide5_request
);
3362 #endif /* MAX_HWIFS > 5 */
3364 EXPORT_SYMBOL(do_ide6_request
);
3365 #endif /* MAX_HWIFS > 6 */
3367 EXPORT_SYMBOL(do_ide7_request
);
3368 #endif /* MAX_HWIFS > 7 */
3373 EXPORT_SYMBOL(ide_scan_devices
);
3374 EXPORT_SYMBOL(ide_register_subdriver
);
3375 EXPORT_SYMBOL(ide_unregister_subdriver
);
3376 EXPORT_SYMBOL(ide_input_data
);
3377 EXPORT_SYMBOL(ide_output_data
);
3378 EXPORT_SYMBOL(atapi_input_bytes
);
3379 EXPORT_SYMBOL(atapi_output_bytes
);
3380 EXPORT_SYMBOL(ide_set_handler
);
3381 EXPORT_SYMBOL(ide_dump_status
);
3382 EXPORT_SYMBOL(ide_error
);
3383 EXPORT_SYMBOL(ide_fixstring
);
3384 EXPORT_SYMBOL(ide_wait_stat
);
3385 EXPORT_SYMBOL(ide_do_reset
);
3386 EXPORT_SYMBOL(ide_init_drive_cmd
);
3387 EXPORT_SYMBOL(ide_do_drive_cmd
);
3388 EXPORT_SYMBOL(ide_end_drive_cmd
);
3389 EXPORT_SYMBOL(ide_end_request
);
3390 EXPORT_SYMBOL(ide_revalidate_disk
);
3391 EXPORT_SYMBOL(ide_cmd
);
3392 EXPORT_SYMBOL(ide_wait_cmd
);
3393 EXPORT_SYMBOL(ide_delay_50ms
);
3394 EXPORT_SYMBOL(ide_stall_queue
);
3395 #ifdef CONFIG_PROC_FS
3396 EXPORT_SYMBOL(ide_add_proc_entries
);
3397 EXPORT_SYMBOL(ide_remove_proc_entries
);
3398 EXPORT_SYMBOL(proc_ide_read_geometry
);
3400 EXPORT_SYMBOL(ide_add_setting
);
3401 EXPORT_SYMBOL(ide_remove_setting
);
3403 EXPORT_SYMBOL(ide_register_hw
);
3404 EXPORT_SYMBOL(ide_register
);
3405 EXPORT_SYMBOL(ide_unregister
);
3406 EXPORT_SYMBOL(ide_setup_ports
);
3409 * This is gets invoked once during initialization, to set *everything* up
3411 __initfunc(int ide_init (void))
3413 static char banner_printed
= 0;
3415 if (!banner_printed
) {
3416 printk(KERN_INFO
"Uniform Multi-Platform E-IDE driver " REVISION
"\n");
3423 ide_init_builtin_drivers();
3430 char *options
= NULL
;
3431 MODULE_PARM(options
,"s");
3433 __initfunc(static void parse_options (char *line
))
3437 if (line
== NULL
|| !*line
)
3439 while ((line
= next
) != NULL
) {
3440 if ((next
= strchr(line
,' ')) != NULL
)
3442 if (!strncmp(line
,"ide",3) || (!strncmp(line
,"hd",2) && line
[2] != '='))
3447 int init_module (void)
3449 parse_options(options
);
3453 void cleanup_module (void)
3457 for (index
= 0; index
< MAX_HWIFS
; ++index
) {
3458 ide_unregister(index
);
3459 #ifdef CONFIG_BLK_DEV_IDEDMA
3460 if (ide_hwifs
[index
].dma_base
)
3461 (void) ide_release_dma(&ide_hwifs
[index
]);
3462 #endif /* CONFIG_BLK_DEV_IDEDMA */
3464 #ifdef CONFIG_PROC_FS