2 * linux/drivers/block/ide.c Version 6.18 August 16, 1998
4 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
8 * Maintained by Mark Lord <mlord@pobox.com>
9 * and Gadi Oxman <gadio@netvision.net.il>
11 * This is the multiple IDE interface driver, as evolved from hd.c.
12 * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs (usually 14 & 15).
13 * There can be up to two drives per interface, as per the ATA-2 spec.
15 * Primary: ide0, port 0x1f0; major=3; hda is minor=0; hdb is minor=64
16 * Secondary: ide1, port 0x170; major=22; hdc is minor=0; hdd is minor=64
17 * Tertiary: ide2, port 0x???; major=33; hde is minor=0; hdf is minor=64
18 * Quaternary: ide3, port 0x???; major=34; hdg is minor=0; hdh is minor=64
23 * | It traverses the request-list, using interrupts to jump between functions.
24 * | As nearly all functions can be called within interrupts, we may not sleep.
25 * | Special care is recommended. Have Fun!
27 * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
29 * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
30 * | in the early extended-partition checks and added DM partitions.
32 * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
34 * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
35 * | and general streamlining by Mark Lord (mlord@pobox.com).
37 * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
39 * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg)
40 * Delman Lee (delman@mipg.upenn.edu) ("Mr. atdisk2")
41 * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom)
43 * This was a rewrite of just about everything from hd.c, though some original
44 * code is still sprinkled about. Think of it as a major evolution, with
45 * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
47 * Version 1.0 ALPHA initial code, primary i/f working okay
48 * Version 1.3 BETA dual i/f on shared irq tested & working!
49 * Version 1.4 BETA added auto probing for irq(s)
50 * Version 1.5 BETA added ALPHA (untested) support for IDE cd-roms,
52 * Version 5.50 allow values as small as 20 for idebus=
53 * Version 5.51 force non io_32bit in drive_cmd_intr()
54 * change delay_10ms() to delay_50ms() to fix problems
55 * Version 5.52 fix incorrect invalidation of removable devices
56 * add "hdx=slow" command line option
57 * Version 5.60 start to modularize the driver; the disk and ATAPI
58 * drivers can be compiled as loadable modules.
59 * move IDE probe code to ide-probe.c
60 * move IDE disk code to ide-disk.c
61 * add support for generic IDE device subdrivers
62 * add m68k code from Geert Uytterhoeven
63 * probe all interfaces by default
64 * add ioctl to (re)probe an interface
65 * Version 6.00 use per device request queues
66 * attempt to optimize shared hwgroup performance
67 * add ioctl to manually adjust bandwidth algorithms
68 * add kerneld support for the probe module
69 * fix bug in ide_error()
70 * fix bug in the first ide_get_lock() call for Atari
71 * don't flush leftover data for ATAPI devices
72 * Version 6.01 clear hwgroup->active while the hwgroup sleeps
73 * support HDIO_GETGEO for floppies
74 * Version 6.02 fix ide_ack_intr() call
75 * check partition table on floppies
76 * Version 6.03 handle bad status bit sequencing in ide_wait_stat()
77 * Version 6.10 deleted old entries from this list of updates
78 * replaced triton.c with ide-dma.c generic PCI DMA
79 * added support for BIOS-enabled UltraDMA
80 * rename all "promise" things to "pdc4030"
81 * fix EZ-DRIVE handling on small disks
82 * Version 6.11 fix probe error in ide_scan_devices()
83 * fix ancient "jiffies" polling bugs
84 * mask all hwgroup interrupts on each irq entry
85 * Version 6.12 integrate ioctl and proc interfaces
86 * fix parsing of "idex=" command line parameter
87 * Version 6.13 add support for ide4/ide5 courtesy rjones@orchestream.com
88 * Version 6.14 fixed IRQ sharing among PCI devices
89 * Version 6.15 added SMP awareness to IDE drivers
90 * Version 6.16 fixed various bugs; even more SMP friendly
91 * Version 6.17 fix for newest EZ-Drive problem
92 * Version 6.18 default unpartitioned-disk translation now "BIOS LBA"
94 * Some additional driver compile-time options are in ide.h
96 * To do, in likely order of completion:
97 * - modify kernel to obtain BIOS geometry for drives on 2nd/3rd/4th i/f
100 #undef REALLY_SLOW_IO /* most systems can safely undef this */
102 #define _IDE_C /* Tell ide.h it's really us */
104 #include <linux/config.h>
105 #include <linux/module.h>
106 #include <linux/types.h>
107 #include <linux/string.h>
108 #include <linux/kernel.h>
109 #include <linux/timer.h>
110 #include <linux/mm.h>
111 #include <linux/interrupt.h>
112 #include <linux/major.h>
113 #include <linux/errno.h>
114 #include <linux/genhd.h>
115 #include <linux/malloc.h>
116 #include <linux/pci.h>
117 #include <linux/delay.h>
119 #include <asm/byteorder.h>
121 #include <asm/uaccess.h>
123 #include <asm/bitops.h>
126 #include "ide_modes.h"
129 #include <linux/kmod.h>
130 #endif /* CONFIG_KMOD */
132 static const byte ide_hwif_to_major
[] = {IDE0_MAJOR
, IDE1_MAJOR
, IDE2_MAJOR
, IDE3_MAJOR
, IDE4_MAJOR
, IDE5_MAJOR
};
134 static int idebus_parameter
; /* holds the "idebus=" parameter */
135 static int system_bus_speed
; /* holds what we think is VESA/PCI bus speed */
136 static int initializing
; /* set while initializing built-in drivers */
139 * ide_lock is used by the Atari code to obtain access to the IDE interrupt,
140 * which is shared between several drivers.
142 static int ide_lock
= 0;
145 * ide_modules keeps track of the available IDE chipset/probe/driver modules.
147 ide_module_t
*ide_modules
= NULL
;
150 * This is declared extern in ide.h, for access by other IDE modules:
152 ide_hwif_t ide_hwifs
[MAX_HWIFS
]; /* master data repository */
154 #if (DISK_RECOVERY_TIME > 0)
156 * For really screwy hardware (hey, at least it *can* be used with Linux)
157 * we can enforce a minimum delay time between successive operations.
159 static unsigned long read_timer(void)
161 unsigned long t
, flags
;
164 __save_flags(flags
); /* local CPU only */
165 __cli(); /* local CPU only */
170 __restore_flags(flags
); /* local CPU only */
173 #endif /* DISK_RECOVERY_TIME */
175 static inline void set_recovery_timer (ide_hwif_t
*hwif
)
177 #if (DISK_RECOVERY_TIME > 0)
178 hwif
->last_time
= read_timer();
179 #endif /* DISK_RECOVERY_TIME */
183 * Do not even *think* about calling this!
185 static void init_hwif_data (unsigned int index
)
188 ide_hwif_t
*hwif
= &ide_hwifs
[index
];
190 /* bulk initialize hwif & drive info with zeros */
191 memset(hwif
, 0, sizeof(ide_hwif_t
));
193 /* fill in any non-zero initial values */
195 ide_init_hwif_ports(hwif
->io_ports
, ide_default_io_base(index
), &hwif
->irq
);
196 hwif
->noprobe
= !hwif
->io_ports
[IDE_DATA_OFFSET
];
197 #ifdef CONFIG_BLK_DEV_HD
198 if (hwif
->io_ports
[IDE_DATA_OFFSET
] == HD_DATA
)
199 hwif
->noprobe
= 1; /* may be overridden by ide_setup() */
200 #endif /* CONFIG_BLK_DEV_HD */
201 hwif
->major
= ide_hwif_to_major
[index
];
205 hwif
->name
[3] = '0' + index
;
206 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
207 ide_drive_t
*drive
= &hwif
->drives
[unit
];
209 drive
->media
= ide_disk
;
210 drive
->select
.all
= (unit
<<4)|0xa0;
213 drive
->ready_stat
= READY_STAT
;
214 drive
->bad_wstat
= BAD_W_STAT
;
215 drive
->special
.b
.recalibrate
= 1;
216 drive
->special
.b
.set_geometry
= 1;
217 drive
->name
[0] = 'h';
218 drive
->name
[1] = 'd';
219 drive
->name
[2] = 'a' + (index
* MAX_DRIVES
) + unit
;
224 * init_ide_data() sets reasonable default values into all fields
225 * of all instances of the hwifs and drives, but only on the first call.
226 * Subsequent calls have no effect (they don't wipe out anything).
228 * This routine is normally called at driver initialization time,
229 * but may also be called MUCH earlier during kernel "command-line"
230 * parameter processing. As such, we cannot depend on any other parts
231 * of the kernel (such as memory allocation) to be functioning yet.
233 * This is too bad, as otherwise we could dynamically allocate the
234 * ide_drive_t structs as needed, rather than always consuming memory
235 * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
237 #define MAGIC_COOKIE 0x12345678
238 static void init_ide_data (void)
241 static unsigned long magic_cookie
= MAGIC_COOKIE
;
243 if (magic_cookie
!= MAGIC_COOKIE
)
244 return; /* already initialized */
247 for (index
= 0; index
< MAX_HWIFS
; ++index
)
248 init_hwif_data(index
);
250 idebus_parameter
= 0;
251 system_bus_speed
= 0;
255 * ide_system_bus_speed() returns what we think is the system VESA/PCI
256 * bus speed (in MHz). This is used for calculating interface PIO timings.
257 * The default is 40 for known PCI systems, 50 otherwise.
258 * The "idebus=xx" parameter can be used to override this value.
259 * The actual value to be used is computed/displayed the first time through.
261 int ide_system_bus_speed (void)
263 if (!system_bus_speed
) {
264 if (idebus_parameter
)
265 system_bus_speed
= idebus_parameter
; /* user supplied value */
267 else if (pci_present())
268 system_bus_speed
= 40; /* safe default value for PCI */
269 #endif /* CONFIG_PCI */
271 system_bus_speed
= 50; /* safe default value for VESA and PCI */
272 printk("ide: Assuming %dMHz system bus speed for PIO modes%s\n", system_bus_speed
,
273 idebus_parameter
? "" : "; override with idebus=xx");
275 return system_bus_speed
;
280 * Some localbus EIDE interfaces require a special access sequence
281 * when using 32-bit I/O instructions to transfer data. We call this
282 * the "vlb_sync" sequence, which consists of three successive reads
283 * of the sector count register location, with interrupts disabled
284 * to ensure that the reads all happen together.
286 static inline void do_vlb_sync (ide_ioreg_t port
) {
291 #endif /* SUPPORT_VLB_SYNC */
294 * This is used for most PIO data transfers *from* the IDE interface
296 void ide_input_data (ide_drive_t
*drive
, void *buffer
, unsigned int wcount
)
298 byte io_32bit
= drive
->io_32bit
;
304 __save_flags(flags
); /* local CPU only */
305 __cli(); /* local CPU only */
306 do_vlb_sync(IDE_NSECTOR_REG
);
307 insl(IDE_DATA_REG
, buffer
, wcount
);
308 __restore_flags(flags
); /* local CPU only */
310 #endif /* SUPPORT_VLB_SYNC */
311 insl(IDE_DATA_REG
, buffer
, wcount
);
313 #if SUPPORT_SLOW_DATA_PORTS
315 unsigned short *ptr
= (unsigned short *) buffer
;
317 *ptr
++ = inw_p(IDE_DATA_REG
);
318 *ptr
++ = inw_p(IDE_DATA_REG
);
321 #endif /* SUPPORT_SLOW_DATA_PORTS */
322 insw(IDE_DATA_REG
, buffer
, wcount
<<1);
327 * This is used for most PIO data transfers *to* the IDE interface
329 void ide_output_data (ide_drive_t
*drive
, void *buffer
, unsigned int wcount
)
331 byte io_32bit
= drive
->io_32bit
;
337 __save_flags(flags
); /* local CPU only */
338 __cli(); /* local CPU only */
339 do_vlb_sync(IDE_NSECTOR_REG
);
340 outsl(IDE_DATA_REG
, buffer
, wcount
);
341 __restore_flags(flags
); /* local CPU only */
343 #endif /* SUPPORT_VLB_SYNC */
344 outsl(IDE_DATA_REG
, buffer
, wcount
);
346 #if SUPPORT_SLOW_DATA_PORTS
348 unsigned short *ptr
= (unsigned short *) buffer
;
350 outw_p(*ptr
++, IDE_DATA_REG
);
351 outw_p(*ptr
++, IDE_DATA_REG
);
354 #endif /* SUPPORT_SLOW_DATA_PORTS */
355 outsw(IDE_DATA_REG
, buffer
, wcount
<<1);
360 * The following routines are mainly used by the ATAPI drivers.
362 * These routines will round up any request for an odd number of bytes,
363 * so if an odd bytecount is specified, be sure that there's at least one
364 * extra byte allocated for the buffer.
366 void atapi_input_bytes (ide_drive_t
*drive
, void *buffer
, unsigned int bytecount
)
371 /* Atari has a byte-swapped IDE interface */
372 insw_swapw(IDE_DATA_REG
, buffer
, bytecount
/ 2);
375 #endif /* CONFIG_ATARI */
376 ide_input_data (drive
, buffer
, bytecount
/ 4);
377 if ((bytecount
& 0x03) >= 2)
378 insw (IDE_DATA_REG
, ((byte
*)buffer
) + (bytecount
& ~0x03), 1);
381 void atapi_output_bytes (ide_drive_t
*drive
, void *buffer
, unsigned int bytecount
)
386 /* Atari has a byte-swapped IDE interface */
387 outsw_swapw(IDE_DATA_REG
, buffer
, bytecount
/ 2);
390 #endif /* CONFIG_ATARI */
391 ide_output_data (drive
, buffer
, bytecount
/ 4);
392 if ((bytecount
& 0x03) >= 2)
393 outsw (IDE_DATA_REG
, ((byte
*)buffer
) + (bytecount
& ~0x03), 1);
397 * Needed for PCI irq sharing
399 static inline int drive_is_ready (ide_drive_t
*drive
)
401 if (drive
->waiting_for_dma
)
402 return HWIF(drive
)->dmaproc(ide_dma_test_irq
, drive
);
404 udelay(1); /* need to guarantee 400ns since last command was issued */
406 if (GET_STAT() & BUSY_STAT
)
407 return 0; /* drive busy: definitely not interrupting */
408 return 1; /* drive ready: *might* be interrupting */
412 * This is our end_request replacement function.
414 void ide_end_request(byte uptodate
, ide_hwgroup_t
*hwgroup
)
419 spin_lock_irqsave(&io_request_lock
, flags
);
422 if (!end_that_request_first(rq
, uptodate
, hwgroup
->drive
->name
)) {
423 add_blkdev_randomness(MAJOR(rq
->rq_dev
));
424 hwgroup
->drive
->queue
= rq
->next
;
425 blk_dev
[MAJOR(rq
->rq_dev
)].current_request
= NULL
;
427 end_that_request_last(rq
);
429 spin_unlock_irqrestore(&io_request_lock
, flags
);
433 * This should get invoked any time we exit the driver to
434 * wait for an interrupt response from a drive. handler() points
435 * at the appropriate code to handle the next interrupt, and a
436 * timer is started to prevent us from waiting forever in case
437 * something goes wrong (see the ide_timer_expiry() handler later on).
439 void ide_set_handler (ide_drive_t
*drive
, ide_handler_t
*handler
, unsigned int timeout
)
442 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
444 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
446 if (hwgroup
->handler
!= NULL
) {
447 printk("%s: ide_set_handler: handler not null; old=%p, new=%p\n",
448 drive
->name
, hwgroup
->handler
, handler
);
451 hwgroup
->handler
= handler
;
452 hwgroup
->timer
.expires
= jiffies
+ timeout
;
453 add_timer(&(hwgroup
->timer
));
454 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
458 * current_capacity() returns the capacity (in sectors) of a drive
459 * according to its current geometry/LBA settings.
461 static unsigned long current_capacity (ide_drive_t
*drive
)
465 if (drive
->driver
!= NULL
)
466 return DRIVER(drive
)->capacity(drive
);
471 * ide_geninit() is called exactly *once* for each major, from genhd.c,
472 * at the beginning of the initial partition check for the drives.
474 void ide_geninit (struct gendisk
*gd
)
477 ide_hwif_t
*hwif
= gd
->real_devices
;
479 for (unit
= 0; unit
< gd
->nr_real
; ++unit
) {
480 ide_drive_t
*drive
= &hwif
->drives
[unit
];
482 drive
->part
[0].nr_sects
= current_capacity(drive
);
483 if (!drive
->present
|| (drive
->media
!= ide_disk
&& drive
->media
!= ide_floppy
) ||
484 drive
->driver
== NULL
|| !drive
->part
[0].nr_sects
)
485 drive
->part
[0].start_sect
= -1; /* skip partition check */
489 static void do_reset1 (ide_drive_t
*, int); /* needed below */
492 * atapi_reset_pollfunc() gets invoked to poll the interface for completion every 50ms
493 * during an atapi drive reset operation. If the drive has not yet responded,
494 * and we have not yet hit our maximum waiting time, then the timer is restarted
497 static void atapi_reset_pollfunc (ide_drive_t
*drive
)
499 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
502 SELECT_DRIVE(HWIF(drive
),drive
);
505 if (OK_STAT(stat
=GET_STAT(), 0, BUSY_STAT
)) {
506 printk("%s: ATAPI reset complete\n", drive
->name
);
508 if (0 < (signed long)(hwgroup
->poll_timeout
- jiffies
)) {
509 ide_set_handler (drive
, &atapi_reset_pollfunc
, HZ
/20);
510 return; /* continue polling */
512 hwgroup
->poll_timeout
= 0; /* end of polling */
513 printk("%s: ATAPI reset timed-out, status=0x%02x\n", drive
->name
, stat
);
514 do_reset1 (drive
, 1); /* do it the old fashioned way */
517 hwgroup
->poll_timeout
= 0; /* done polling */
521 * reset_pollfunc() gets invoked to poll the interface for completion every 50ms
522 * during an ide reset operation. If the drives have not yet responded,
523 * and we have not yet hit our maximum waiting time, then the timer is restarted
526 static void reset_pollfunc (ide_drive_t
*drive
)
528 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
529 ide_hwif_t
*hwif
= HWIF(drive
);
532 if (!OK_STAT(tmp
=GET_STAT(), 0, BUSY_STAT
)) {
533 if (0 < (signed long)(hwgroup
->poll_timeout
- jiffies
)) {
534 ide_set_handler (drive
, &reset_pollfunc
, HZ
/20);
535 return; /* continue polling */
537 printk("%s: reset timed-out, status=0x%02x\n", hwif
->name
, tmp
);
539 printk("%s: reset: ", hwif
->name
);
540 if ((tmp
= GET_ERR()) == 1)
543 #if FANCY_STATUS_DUMPS
545 switch (tmp
& 0x7f) {
546 case 1: printk("passed");
548 case 2: printk("formatter device error");
550 case 3: printk("sector buffer error");
552 case 4: printk("ECC circuitry error");
554 case 5: printk("controlling MPU error");
556 default:printk("error (0x%02x?)", tmp
);
559 printk("; slave: failed");
563 #endif /* FANCY_STATUS_DUMPS */
566 hwgroup
->poll_timeout
= 0; /* done polling */
569 static void pre_reset (ide_drive_t
*drive
)
571 if (!drive
->keep_settings
) {
574 if (drive
->using_dma
)
575 (void) HWIF(drive
)->dmaproc(ide_dma_off
, drive
);
577 if (drive
->driver
!= NULL
)
578 DRIVER(drive
)->pre_reset(drive
);
582 * do_reset1() attempts to recover a confused drive by resetting it.
583 * Unfortunately, resetting a disk drive actually resets all devices on
584 * the same interface, so it can really be thought of as resetting the
585 * interface rather than resetting the drive.
587 * ATAPI devices have their own reset mechanism which allows them to be
588 * individually reset without clobbering other devices on the same interface.
590 * Unfortunately, the IDE interface does not generate an interrupt to let
591 * us know when the reset operation has finished, so we must poll for this.
592 * Equally poor, though, is the fact that this may a very long time to complete,
593 * (up to 30 seconds worstcase). So, instead of busy-waiting here for it,
594 * we set a timer to poll at 50ms intervals.
596 static void do_reset1 (ide_drive_t
*drive
, int do_not_try_atapi
)
600 ide_hwif_t
*hwif
= HWIF(drive
);
601 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
603 __save_flags(flags
); /* local CPU only */
604 __cli(); /* local CPU only */
606 /* For an ATAPI device, first try an ATAPI SRST. */
607 if (drive
->media
!= ide_disk
&& !do_not_try_atapi
) {
609 SELECT_DRIVE(hwif
,drive
);
611 OUT_BYTE (WIN_SRST
, IDE_COMMAND_REG
);
612 hwgroup
->poll_timeout
= jiffies
+ WAIT_WORSTCASE
;
613 ide_set_handler (drive
, &atapi_reset_pollfunc
, HZ
/20);
614 __restore_flags (flags
); /* local CPU only */
619 * First, reset any device state data we were maintaining
620 * for any of the drives on this interface.
622 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
)
623 pre_reset(&hwif
->drives
[unit
]);
625 #if OK_TO_RESET_CONTROLLER
627 * Note that we also set nIEN while resetting the device,
628 * to mask unwanted interrupts from the interface during the reset.
629 * However, due to the design of PC hardware, this will cause an
630 * immediate interrupt due to the edge transition it produces.
631 * This single interrupt gives us a "fast poll" for drives that
632 * recover from reset very quickly, saving us the first 50ms wait time.
634 OUT_BYTE(drive
->ctl
|6,IDE_CONTROL_REG
); /* set SRST and nIEN */
635 udelay(10); /* more than enough time */
636 OUT_BYTE(drive
->ctl
|2,IDE_CONTROL_REG
); /* clear SRST, leave nIEN */
637 udelay(10); /* more than enough time */
638 hwgroup
->poll_timeout
= jiffies
+ WAIT_WORSTCASE
;
639 ide_set_handler (drive
, &reset_pollfunc
, HZ
/20);
640 #endif /* OK_TO_RESET_CONTROLLER */
642 __restore_flags (flags
); /* local CPU only */
646 * ide_do_reset() is the entry point to the drive/interface reset code.
648 void ide_do_reset (ide_drive_t
*drive
)
650 do_reset1 (drive
, 0);
654 * Clean up after success/failure of an explicit drive cmd
656 void ide_end_drive_cmd (ide_drive_t
*drive
, byte stat
, byte err
)
659 struct request
*rq
= HWGROUP(drive
)->rq
;
661 if (rq
->cmd
== IDE_DRIVE_CMD
) {
662 byte
*args
= (byte
*) rq
->buffer
;
663 rq
->errors
= !OK_STAT(stat
,READY_STAT
,BAD_STAT
);
667 args
[2] = IN_BYTE(IDE_NSECTOR_REG
);
670 spin_lock_irqsave(&io_request_lock
, flags
);
671 drive
->queue
= rq
->next
;
672 blk_dev
[MAJOR(rq
->rq_dev
)].current_request
= NULL
;
673 HWGROUP(drive
)->rq
= NULL
;
674 rq
->rq_status
= RQ_INACTIVE
;
675 spin_unlock_irqrestore(&io_request_lock
, flags
);
676 save_flags(flags
); /* all CPUs; overkill? */
677 cli(); /* all CPUs; overkill? */
679 up(rq
->sem
); /* inform originator that rq has been serviced */
680 restore_flags(flags
); /* all CPUs; overkill? */
684 * Error reporting, in human readable form (luxurious, but a memory hog).
686 byte
ide_dump_status (ide_drive_t
*drive
, const char *msg
, byte stat
)
691 __save_flags (flags
); /* local CPU only */
692 ide__sti(); /* local CPU only */
693 printk("%s: %s: status=0x%02x", drive
->name
, msg
, stat
);
694 #if FANCY_STATUS_DUMPS
696 if (stat
& BUSY_STAT
)
699 if (stat
& READY_STAT
) printk("DriveReady ");
700 if (stat
& WRERR_STAT
) printk("DeviceFault ");
701 if (stat
& SEEK_STAT
) printk("SeekComplete ");
702 if (stat
& DRQ_STAT
) printk("DataRequest ");
703 if (stat
& ECC_STAT
) printk("CorrectedError ");
704 if (stat
& INDEX_STAT
) printk("Index ");
705 if (stat
& ERR_STAT
) printk("Error ");
708 #endif /* FANCY_STATUS_DUMPS */
710 if ((stat
& (BUSY_STAT
|ERR_STAT
)) == ERR_STAT
) {
712 printk("%s: %s: error=0x%02x", drive
->name
, msg
, err
);
713 #if FANCY_STATUS_DUMPS
714 if (drive
->media
== ide_disk
) {
716 if (err
& ABRT_ERR
) printk("DriveStatusError ");
717 if (err
& ICRC_ERR
) printk((err
& ABRT_ERR
) ? "BadCRC " : "BadSector ");
718 if (err
& ECC_ERR
) printk("UncorrectableError ");
719 if (err
& ID_ERR
) printk("SectorIdNotFound ");
720 if (err
& TRK0_ERR
) printk("TrackZeroNotFound ");
721 if (err
& MARK_ERR
) printk("AddrMarkNotFound ");
723 if ((err
& (BBD_ERR
| ABRT_ERR
)) == BBD_ERR
|| (err
& (ECC_ERR
|ID_ERR
|MARK_ERR
))) {
724 byte cur
= IN_BYTE(IDE_SELECT_REG
);
725 if (cur
& 0x40) { /* using LBA? */
726 printk(", LBAsect=%ld", (unsigned long)
728 |(IN_BYTE(IDE_HCYL_REG
)<<16)
729 |(IN_BYTE(IDE_LCYL_REG
)<<8)
730 | IN_BYTE(IDE_SECTOR_REG
));
732 printk(", CHS=%d/%d/%d",
733 (IN_BYTE(IDE_HCYL_REG
)<<8) +
734 IN_BYTE(IDE_LCYL_REG
),
736 IN_BYTE(IDE_SECTOR_REG
));
738 if (HWGROUP(drive
)->rq
)
739 printk(", sector=%ld", HWGROUP(drive
)->rq
->sector
);
742 #endif /* FANCY_STATUS_DUMPS */
745 __restore_flags (flags
); /* local CPU only */
750 * try_to_flush_leftover_data() is invoked in response to a drive
751 * unexpectedly having its DRQ_STAT bit set. As an alternative to
752 * resetting the drive, this routine tries to clear the condition
753 * by read a sector's worth of data from the drive. Of course,
754 * this may not help if the drive is *waiting* for data from *us*.
756 static void try_to_flush_leftover_data (ide_drive_t
*drive
)
758 int i
= (drive
->mult_count
? drive
->mult_count
: 1) * SECTOR_WORDS
;
760 if (drive
->media
!= ide_disk
)
763 unsigned long buffer
[16];
764 unsigned int wcount
= (i
> 16) ? 16 : i
;
766 ide_input_data (drive
, buffer
, wcount
);
771 * ide_error() takes action based on the error returned by the drive.
773 void ide_error (ide_drive_t
*drive
, const char *msg
, byte stat
)
778 err
= ide_dump_status(drive
, msg
, stat
);
779 if (drive
== NULL
|| (rq
= HWGROUP(drive
)->rq
) == NULL
)
781 /* retry only "normal" I/O: */
782 if (rq
->cmd
== IDE_DRIVE_CMD
) {
784 ide_end_drive_cmd(drive
, stat
, err
);
787 if (stat
& BUSY_STAT
) { /* other bits are useless when BUSY */
788 rq
->errors
|= ERROR_RESET
;
790 if (drive
->media
== ide_disk
&& (stat
& ERR_STAT
)) {
791 /* err has different meaning on cdrom and tape */
792 if (err
== ABRT_ERR
) {
793 if (drive
->select
.b
.lba
&& IN_BYTE(IDE_COMMAND_REG
) == WIN_SPECIFY
)
794 return; /* some newer drives don't support WIN_SPECIFY */
795 } else if ((err
& (ABRT_ERR
| ICRC_ERR
)) == (ABRT_ERR
| ICRC_ERR
))
796 ; /* UDMA crc error -- just retry the operation */
797 else if (err
& (BBD_ERR
| ECC_ERR
)) /* retries won't help these */
798 rq
->errors
= ERROR_MAX
;
799 else if (err
& TRK0_ERR
) /* help it find track zero */
800 rq
->errors
|= ERROR_RECAL
;
802 if ((stat
& DRQ_STAT
) && rq
->cmd
!= WRITE
)
803 try_to_flush_leftover_data(drive
);
805 if (GET_STAT() & (BUSY_STAT
|DRQ_STAT
))
806 rq
->errors
|= ERROR_RESET
; /* Mmmm.. timing problem */
808 if (rq
->errors
>= ERROR_MAX
) {
809 if (drive
->driver
!= NULL
)
810 DRIVER(drive
)->end_request(0, HWGROUP(drive
));
812 ide_end_request(0, HWGROUP(drive
));
814 if ((rq
->errors
& ERROR_RESET
) == ERROR_RESET
) {
818 } else if ((rq
->errors
& ERROR_RECAL
) == ERROR_RECAL
)
819 drive
->special
.b
.recalibrate
= 1;
825 * Issue a simple drive command
826 * The drive must be selected beforehand.
828 void ide_cmd(ide_drive_t
*drive
, byte cmd
, byte nsect
, ide_handler_t
*handler
)
830 ide_set_handler (drive
, handler
, WAIT_CMD
);
831 OUT_BYTE(drive
->ctl
,IDE_CONTROL_REG
); /* clear nIEN */
832 OUT_BYTE(nsect
,IDE_NSECTOR_REG
);
833 OUT_BYTE(cmd
,IDE_COMMAND_REG
);
837 * drive_cmd_intr() is invoked on completion of a special DRIVE_CMD.
839 static void drive_cmd_intr (ide_drive_t
*drive
)
841 struct request
*rq
= HWGROUP(drive
)->rq
;
842 byte
*args
= (byte
*) rq
->buffer
;
843 byte stat
= GET_STAT();
846 ide__sti(); /* local CPU only */
847 if ((stat
& DRQ_STAT
) && args
&& args
[3]) {
848 byte io_32bit
= drive
->io_32bit
;
850 ide_input_data(drive
, &args
[4], args
[3] * SECTOR_WORDS
);
851 drive
->io_32bit
= io_32bit
;
852 while (((stat
= GET_STAT()) & BUSY_STAT
) && retries
--)
856 if (OK_STAT(stat
, READY_STAT
, BAD_STAT
))
857 ide_end_drive_cmd (drive
, stat
, GET_ERR());
859 ide_error(drive
, "drive_cmd", stat
); /* calls ide_end_drive_cmd */
863 * do_special() is used to issue WIN_SPECIFY, WIN_RESTORE, and WIN_SETMULT
864 * commands to a drive. It used to do much more, but has been scaled back.
866 static inline void do_special (ide_drive_t
*drive
)
868 special_t
*s
= &drive
->special
;
871 printk("%s: do_special: 0x%02x\n", drive
->name
, s
->all
);
874 ide_tuneproc_t
*tuneproc
= HWIF(drive
)->tuneproc
;
876 if (tuneproc
!= NULL
)
877 tuneproc(drive
, drive
->tune_req
);
878 } else if (drive
->driver
!= NULL
) {
879 DRIVER(drive
)->special(drive
);
881 printk("%s: bad special flag: 0x%02x\n", drive
->name
, s
->all
);
887 * This routine busy-waits for the drive status to be not "busy".
888 * It then checks the status for all of the "good" bits and none
889 * of the "bad" bits, and if all is okay it returns 0. All other
890 * cases return 1 after invoking ide_error() -- caller should just return.
892 * This routine should get fixed to not hog the cpu during extra long waits..
893 * That could be done by busy-waiting for the first jiffy or two, and then
894 * setting a timer to wake up at half second intervals thereafter,
895 * until timeout is achieved, before timing out.
897 int ide_wait_stat (ide_drive_t
*drive
, byte good
, byte bad
, unsigned long timeout
)
902 udelay(1); /* spec allows drive 400ns to assert "BUSY" */
903 if ((stat
= GET_STAT()) & BUSY_STAT
) {
904 __save_flags(flags
); /* local CPU only */
905 ide__sti(); /* local CPU only */
907 while ((stat
= GET_STAT()) & BUSY_STAT
) {
908 if (0 < (signed long)(jiffies
- timeout
)) {
909 __restore_flags(flags
); /* local CPU only */
910 ide_error(drive
, "status timeout", stat
);
914 __restore_flags(flags
); /* local CPU only */
916 udelay(1); /* allow status to settle, then read it again */
917 if (OK_STAT((stat
= GET_STAT()), good
, bad
))
919 ide_error(drive
, "status error", stat
);
924 * execute_drive_cmd() issues a special drive command,
925 * usually initiated by ioctl() from the external hdparm program.
927 static void execute_drive_cmd (ide_drive_t
*drive
, struct request
*rq
)
929 byte
*args
= rq
->buffer
;
932 printk("%s: DRIVE_CMD cmd=0x%02x sc=0x%02x fr=0x%02x xx=0x%02x\n",
933 drive
->name
, args
[0], args
[1], args
[2], args
[3]);
935 if (args
[0] == WIN_SMART
) {
936 OUT_BYTE(0x4f, IDE_LCYL_REG
);
937 OUT_BYTE(0xc2, IDE_HCYL_REG
);
939 OUT_BYTE(args
[2],IDE_FEATURE_REG
);
940 ide_cmd(drive
, args
[0], args
[1], &drive_cmd_intr
);
944 * NULL is actually a valid way of waiting for
945 * all current requests to be flushed from the queue.
948 printk("%s: DRIVE_CMD (null)\n", drive
->name
);
950 ide_end_drive_cmd(drive
, GET_STAT(), GET_ERR());
956 * start_request() initiates handling of a new I/O request
958 static inline void start_request (ide_drive_t
*drive
)
960 unsigned long block
, blockend
;
961 struct request
*rq
= drive
->queue
;
962 unsigned int minor
= MINOR(rq
->rq_dev
), unit
= minor
>> PARTN_BITS
;
963 ide_hwif_t
*hwif
= HWIF(drive
);
965 ide__sti(); /* local CPU only */
967 printk("%s: start_request: current=0x%08lx\n", hwif
->name
, (unsigned long) rq
);
969 if (unit
>= MAX_DRIVES
) {
970 printk("%s: bad device number: %s\n", hwif
->name
, kdevname(rq
->rq_dev
));
974 if (rq
->bh
&& !buffer_locked(rq
->bh
)) {
975 printk("%s: block not locked\n", drive
->name
);
980 blockend
= block
+ rq
->nr_sectors
;
981 if ((blockend
< block
) || (blockend
> drive
->part
[minor
&PARTN_MASK
].nr_sects
)) {
982 printk("%s%c: bad access: block=%ld, count=%ld\n", drive
->name
,
983 (minor
&PARTN_MASK
)?'0'+(minor
&PARTN_MASK
):' ', block
, rq
->nr_sectors
);
986 block
+= drive
->part
[minor
&PARTN_MASK
].start_sect
+ drive
->sect0
;
987 #if FAKE_FDISK_FOR_EZDRIVE
988 if (block
== 0 && drive
->remap_0_to_1
)
989 block
= 1; /* redirect MBR access to EZ-Drive partn table */
990 #endif /* FAKE_FDISK_FOR_EZDRIVE */
991 #if (DISK_RECOVERY_TIME > 0)
992 while ((read_timer() - hwif
->last_time
) < DISK_RECOVERY_TIME
);
994 SELECT_DRIVE(hwif
, drive
);
995 if (ide_wait_stat(drive
, drive
->ready_stat
, BUSY_STAT
|DRQ_STAT
, WAIT_READY
)) {
996 printk("%s: drive not ready for command\n", drive
->name
);
999 if (!drive
->special
.all
) {
1000 if (rq
->cmd
== IDE_DRIVE_CMD
) {
1001 execute_drive_cmd(drive
, rq
);
1004 if (drive
->driver
!= NULL
) {
1005 DRIVER(drive
)->do_request(drive
, rq
, block
);
1008 printk("%s: media type %d not supported\n", drive
->name
, drive
->media
);
1014 if (drive
->driver
!= NULL
)
1015 DRIVER(drive
)->end_request(0, HWGROUP(drive
));
1017 ide_end_request(0, HWGROUP(drive
));
1021 * ide_stall_queue() can be used by a drive to give excess bandwidth back
1022 * to the hwgroup by sleeping for timeout jiffies.
1024 void ide_stall_queue (ide_drive_t
*drive
, unsigned long timeout
)
1026 if (timeout
> WAIT_WORSTCASE
)
1027 timeout
= WAIT_WORSTCASE
;
1028 drive
->sleep
= timeout
+ jiffies
;
1031 #define WAKEUP(drive) ((drive)->service_start + 2 * (drive)->service_time)
1034 * choose_drive() selects the next drive which will be serviced.
1036 static inline ide_drive_t
*choose_drive (ide_hwgroup_t
*hwgroup
)
1038 ide_drive_t
*drive
, *best
;
1042 drive
= hwgroup
->drive
;
1044 if (drive
->queue
&& (!drive
->sleep
|| 0 <= (signed long)(jiffies
- drive
->sleep
))) {
1046 || (drive
->sleep
&& (!best
->sleep
|| 0 < (signed long)(best
->sleep
- drive
->sleep
)))
1047 || (!best
->sleep
&& 0 < (signed long)(WAKEUP(best
) - WAKEUP(drive
))))
1049 struct blk_dev_struct
*bdev
= &blk_dev
[HWIF(drive
)->major
];
1050 if (bdev
->current_request
!= &bdev
->plug
)
1054 } while ((drive
= drive
->next
) != hwgroup
->drive
);
1055 if (best
&& best
->nice1
&& !best
->sleep
&& best
!= hwgroup
->drive
&& best
->service_time
> WAIT_MIN_SLEEP
) {
1056 long t
= (signed long)(WAKEUP(best
) - jiffies
);
1057 if (t
>= WAIT_MIN_SLEEP
) {
1059 * We *may* have some time to spare, but first let's see if
1060 * someone can potentially benefit from our nice mood today..
1065 && 0 < (signed long)(WAKEUP(drive
) - (jiffies
- best
->service_time
))
1066 && 0 < (signed long)((jiffies
+ t
) - WAKEUP(drive
)))
1068 ide_stall_queue(best
, IDE_MIN(t
, 10 * WAIT_MIN_SLEEP
));
1071 } while ((drive
= drive
->next
) != best
);
1078 * Caller must have already acquired spinlock using *spinflags
1080 static void ide_do_request (ide_hwgroup_t
*hwgroup
, unsigned long *hwgroup_flags
, int masked_irq
)
1082 struct blk_dev_struct
*bdev
;
1085 unsigned long io_flags
;
1088 while (hwgroup
->handler
== NULL
) {
1089 spin_lock_irqsave(&io_request_lock
, io_flags
);
1090 drive
= choose_drive(hwgroup
);
1091 if (drive
== NULL
) {
1092 unsigned long sleep
= 0;
1095 drive
= hwgroup
->drive
;
1097 bdev
= &blk_dev
[HWIF(drive
)->major
];
1098 if (bdev
->current_request
!= &bdev
->plug
) /* FIXME: this will do for now */
1099 bdev
->current_request
= NULL
; /* (broken since patch-2.1.15) */
1100 if (drive
->sleep
&& (!sleep
|| 0 < (signed long)(sleep
- drive
->sleep
)))
1101 sleep
= drive
->sleep
;
1102 } while ((drive
= drive
->next
) != hwgroup
->drive
);
1103 spin_unlock_irqrestore(&io_request_lock
, io_flags
);
1105 if (0 < (signed long)(jiffies
+ WAIT_MIN_SLEEP
- sleep
))
1106 sleep
= jiffies
+ WAIT_MIN_SLEEP
;
1108 if (hwgroup
->timer
.next
|| hwgroup
->timer
.prev
)
1109 printk("ide_set_handler: timer already active\n");
1111 mod_timer(&hwgroup
->timer
, sleep
);
1113 /* Ugly, but how can we sleep for the lock otherwise? perhaps from tq_scheduler? */
1114 ide_release_lock(&ide_lock
); /* for atari only */
1120 if (hwgroup
->hwif
->sharing_irq
&& hwif
!= hwgroup
->hwif
) /* set nIEN for previous hwif */
1121 OUT_BYTE(hwgroup
->drive
->ctl
|2, hwgroup
->hwif
->io_ports
[IDE_CONTROL_OFFSET
]);
1122 hwgroup
->hwif
= hwif
;
1123 hwgroup
->drive
= drive
;
1125 drive
->service_start
= jiffies
;
1127 bdev
= &blk_dev
[hwif
->major
];
1128 if (bdev
->current_request
== &bdev
->plug
) /* FIXME: paranoia */
1129 printk("%s: Huh? nuking plugged queue\n", drive
->name
);
1130 bdev
->current_request
= hwgroup
->rq
= drive
->queue
;
1131 spin_unlock_irqrestore(&io_request_lock
, io_flags
);
1133 if (hwif
->irq
!= masked_irq
)
1134 disable_irq(hwif
->irq
);
1135 spin_unlock_irqrestore(&hwgroup
->spinlock
, *hwgroup_flags
);
1136 start_request(drive
);
1137 spin_lock_irqsave(&hwgroup
->spinlock
, *hwgroup_flags
);
1138 if (hwif
->irq
!= masked_irq
)
1139 enable_irq(hwif
->irq
);
1144 * ide_get_queue() returns the queue which corresponds to a given device.
1146 struct request
**ide_get_queue (kdev_t dev
)
1148 ide_hwif_t
*hwif
= (ide_hwif_t
*)blk_dev
[MAJOR(dev
)].data
;
1150 return &hwif
->drives
[DEVICE_NR(dev
) & 1].queue
;
1154 * do_hwgroup_request() invokes ide_do_request() after claiming hwgroup->busy.
1156 static void do_hwgroup_request (ide_hwgroup_t
*hwgroup
)
1158 unsigned long flags
;
1160 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
1161 if (hwgroup
->busy
) {
1162 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1165 del_timer(&hwgroup
->timer
);
1166 ide_get_lock(&ide_lock
, ide_intr
, hwgroup
); /* for atari only */
1167 ide_do_request(hwgroup
, &flags
, 0);
1168 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1172 * ll_rw_blk.c invokes our do_idex_request() function
1173 * with the io_request_spinlock already grabbed.
1174 * Since we need to do our own spinlock's internally,
1175 * on paths that don't necessarily originate through the
1176 * do_idex_request() path, we have to undo the spinlock on entry,
1177 * and restore it again on exit.
1178 * Fortunately, this is mostly a nop for non-SMP kernels.
1180 static inline void unlock_do_hwgroup_request (ide_hwgroup_t
*hwgroup
)
1182 spin_unlock(&io_request_lock
);
1183 do_hwgroup_request (hwgroup
);
1184 spin_lock_irq(&io_request_lock
);
1187 void do_ide0_request (void)
1189 unlock_do_hwgroup_request (ide_hwifs
[0].hwgroup
);
1193 void do_ide1_request (void)
1195 unlock_do_hwgroup_request (ide_hwifs
[1].hwgroup
);
1197 #endif /* MAX_HWIFS > 1 */
1200 void do_ide2_request (void)
1202 unlock_do_hwgroup_request (ide_hwifs
[2].hwgroup
);
1204 #endif /* MAX_HWIFS > 2 */
1207 void do_ide3_request (void)
1209 unlock_do_hwgroup_request (ide_hwifs
[3].hwgroup
);
1211 #endif /* MAX_HWIFS > 3 */
1214 void do_ide4_request (void)
1216 unlock_do_hwgroup_request (ide_hwifs
[4].hwgroup
);
1218 #endif /* MAX_HWIFS > 4 */
1221 void do_ide5_request (void)
1223 unlock_do_hwgroup_request (ide_hwifs
[5].hwgroup
);
1225 #endif /* MAX_HWIFS > 5 */
1227 static void start_next_request (ide_hwgroup_t
*hwgroup
, int masked_irq
)
1229 unsigned long flags
;
1232 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
1233 if (hwgroup
->handler
!= NULL
) {
1234 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1237 drive
= hwgroup
->drive
;
1238 set_recovery_timer(HWIF(drive
));
1239 drive
->service_time
= jiffies
- drive
->service_start
;
1240 ide_do_request(hwgroup
, &flags
, masked_irq
);
1241 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1244 void ide_timer_expiry (unsigned long data
)
1246 ide_hwgroup_t
*hwgroup
= (ide_hwgroup_t
*) data
;
1248 ide_handler_t
*handler
;
1249 unsigned long flags
;
1251 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
1252 drive
= hwgroup
->drive
;
1253 if ((handler
= hwgroup
->handler
) == NULL
) {
1254 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1255 do_hwgroup_request(hwgroup
);
1258 hwgroup
->busy
= 1; /* should already be "1" */
1259 hwgroup
->handler
= NULL
;
1260 del_timer(&hwgroup
->timer
); /* Is this needed?? */
1261 if (hwgroup
->poll_timeout
!= 0) { /* polling in progress? */
1262 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1264 } else if (drive_is_ready(drive
)) {
1265 printk("%s: lost interrupt\n", drive
->name
);
1266 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1269 if (drive
->waiting_for_dma
) {
1270 (void) hwgroup
->hwif
->dmaproc(ide_dma_end
, drive
);
1271 printk("%s: timeout waiting for DMA\n", drive
->name
);
1273 * need something here for HX PIIX3 UDMA and HPT343.......AMH
1274 * irq timeout: status=0x58 { DriveReady SeekComplete DataRequest }
1277 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1278 ide_error(drive
, "irq timeout", GET_STAT());
1280 start_next_request(hwgroup
, 0);
1284 * There's nothing really useful we can do with an unexpected interrupt,
1285 * other than reading the status register (to clear it), and logging it.
1286 * There should be no way that an irq can happen before we're ready for it,
1287 * so we needn't worry much about losing an "important" interrupt here.
1289 * On laptops (and "green" PCs), an unexpected interrupt occurs whenever the
1290 * drive enters "idle", "standby", or "sleep" mode, so if the status looks
1291 * "good", we just ignore the interrupt completely.
1293 * This routine assumes __cli() is in effect when called.
1295 * If an unexpected interrupt happens on irq15 while we are handling irq14
1296 * and if the two interfaces are "serialized" (CMD640), then it looks like
1297 * we could screw up by interfering with a new request being set up for irq15.
1299 * In reality, this is a non-issue. The new command is not sent unless the
1300 * drive is ready to accept one, in which case we know the drive is not
1301 * trying to interrupt us. And ide_set_handler() is always invoked before
1302 * completing the issuance of any new drive command, so we will not be
1303 * accidently invoked as a result of any valid command completion interrupt.
1306 static void unexpected_intr (int irq
, ide_hwgroup_t
*hwgroup
)
1309 ide_hwif_t
*hwif
= hwgroup
->hwif
;
1312 * handle the unexpected interrupt
1315 if (hwif
->irq
== irq
) {
1316 stat
= IN_BYTE(hwif
->io_ports
[IDE_STATUS_OFFSET
]);
1317 if (!OK_STAT(stat
, READY_STAT
, BAD_STAT
)) {
1318 /* Try to not flood the console with msgs */
1319 static unsigned long last_msgtime
= 0, count
= 0;
1321 if (0 < (signed long)(jiffies
- (last_msgtime
+ HZ
))) {
1322 last_msgtime
= jiffies
;
1323 printk("%s%s: unexpected interrupt, status=0x%02x, count=%ld\n",
1324 hwif
->name
, (hwif
->next
== hwgroup
->hwif
) ? "" : "(?)", stat
, count
);
1328 } while ((hwif
= hwif
->next
) != hwgroup
->hwif
);
1331 * entry point for all interrupts, caller does __cli() for us
1333 void ide_intr (int irq
, void *dev_id
, struct pt_regs
*regs
)
1335 unsigned long flags
;
1336 ide_hwgroup_t
*hwgroup
= (ide_hwgroup_t
*)dev_id
;
1339 ide_handler_t
*handler
;
1341 __cli(); /* local CPU only */
1342 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
1343 hwif
= hwgroup
->hwif
;
1344 if ((handler
= hwgroup
->handler
) == NULL
|| hwgroup
->poll_timeout
!= 0) {
1346 * Not expecting an interrupt from this drive.
1347 * That means this could be:
1348 * (1) an interrupt from another PCI device
1349 * sharing the same PCI INT# as us.
1350 * or (2) a drive just entered sleep or standby mode,
1351 * and is interrupting to let us know.
1352 * or (3) a spurious interrupt of unknown origin.
1354 * For PCI, we cannot tell the difference,
1355 * so in that case we just ignore it and hope it goes away.
1357 #ifdef CONFIG_BLK_DEV_IDEPCI
1358 if (IDE_PCI_DEVID_EQ(hwif
->pci_devid
, IDE_PCI_DEVID_NULL
))
1359 #endif /* CONFIG_BLK_DEV_IDEPCI */
1362 * Probably not a shared PCI interrupt,
1363 * so we can safely try to do something about it:
1365 (void)ide_ack_intr(hwif
->io_ports
[IDE_STATUS_OFFSET
], hwif
->io_ports
[IDE_IRQ_OFFSET
]);
1366 unexpected_intr(irq
, hwgroup
);
1368 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1371 drive
= hwgroup
->drive
;
1372 if (!drive
|| !drive_is_ready(drive
)) {
1373 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1376 hwgroup
->handler
= NULL
;
1377 (void)ide_ack_intr(hwif
->io_ports
[IDE_STATUS_OFFSET
], hwif
->io_ports
[IDE_IRQ_OFFSET
]);
1378 del_timer(&(hwgroup
->timer
));
1379 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1381 ide__sti(); /* local CPU only */
1382 handler(drive
); /* service this interrupt, may set handler for next interrupt */
1384 * Note that handler() may have set things up for another
1385 * interrupt to occur soon, but it cannot happen until
1386 * we exit from this routine, because it will be the
1387 * same irq as is currently being serviced here,
1388 * and Linux won't allow another (on any CPU) until we return.
1390 start_next_request(hwgroup
, hwif
->irq
);
1394 * get_info_ptr() returns the (ide_drive_t *) for a given device number.
1395 * It returns NULL if the given device number does not match any present drives.
1397 static ide_drive_t
*get_info_ptr (kdev_t i_rdev
)
1399 int major
= MAJOR(i_rdev
);
1402 for (h
= 0; h
< MAX_HWIFS
; ++h
) {
1403 ide_hwif_t
*hwif
= &ide_hwifs
[h
];
1404 if (hwif
->present
&& major
== hwif
->major
) {
1405 unsigned unit
= DEVICE_NR(i_rdev
);
1406 if (unit
< MAX_DRIVES
) {
1407 ide_drive_t
*drive
= &hwif
->drives
[unit
];
1418 * This function is intended to be used prior to invoking ide_do_drive_cmd().
1420 void ide_init_drive_cmd (struct request
*rq
)
1423 rq
->cmd
= IDE_DRIVE_CMD
;
1426 rq
->current_nr_sectors
= 0;
1434 * This function issues a special IDE device request
1435 * onto the request queue.
1437 * If action is ide_wait, then then rq is queued at the end of
1438 * the request queue, and the function sleeps until it has been
1439 * processed. This is for use when invoked from an ioctl handler.
1441 * If action is ide_preempt, then the rq is queued at the head of
1442 * the request queue, displacing the currently-being-processed
1443 * request and this function returns immediately without waiting
1444 * for the new rq to be completed. This is VERY DANGEROUS, and is
1445 * intended for careful use by the ATAPI tape/cdrom driver code.
1447 * If action is ide_next, then the rq is queued immediately after
1448 * the currently-being-processed-request (if any), and the function
1449 * returns without waiting for the new rq to be completed. As above,
1450 * This is VERY DANGEROUS, and is intended for careful use by the
1451 * ATAPI tape/cdrom driver code.
1453 * If action is ide_end, then the rq is queued at the end of the
1454 * request queue, and the function returns immediately without waiting
1455 * for the new rq to be completed. This is again intended for careful
1456 * use by the ATAPI tape/cdrom driver code.
1458 int ide_do_drive_cmd (ide_drive_t
*drive
, struct request
*rq
, ide_action_t action
)
1460 unsigned long flags
;
1461 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
1462 unsigned int major
= HWIF(drive
)->major
;
1463 struct request
*cur_rq
;
1464 struct semaphore sem
= MUTEX_LOCKED
;
1466 if (IS_PDC4030_DRIVE
&& rq
->buffer
!= NULL
)
1467 return -ENOSYS
; /* special drive cmds not supported */
1469 rq
->rq_status
= RQ_ACTIVE
;
1470 rq
->rq_dev
= MKDEV(major
,(drive
->select
.b
.unit
)<<PARTN_BITS
);
1471 if (action
== ide_wait
)
1474 spin_lock_irqsave(&io_request_lock
, flags
);
1475 cur_rq
= drive
->queue
;
1476 if (cur_rq
== NULL
|| action
== ide_preempt
) {
1479 if (action
== ide_preempt
)
1482 if (action
== ide_wait
|| action
== ide_end
) {
1483 while (cur_rq
->next
!= NULL
) /* find end of list */
1484 cur_rq
= cur_rq
->next
;
1486 rq
->next
= cur_rq
->next
;
1489 spin_unlock_irqrestore(&io_request_lock
, flags
);
1490 do_hwgroup_request(hwgroup
);
1491 save_flags(flags
); /* all CPUs; overkill? */
1492 cli(); /* all CPUs; overkill? */
1493 if (action
== ide_wait
&& rq
->rq_status
!= RQ_INACTIVE
)
1494 down(&sem
); /* wait for it to be serviced */
1495 restore_flags(flags
); /* all CPUs; overkill? */
1496 return rq
->errors
? -EIO
: 0; /* return -EIO if errors */
1500 * This routine is called to flush all partitions and partition tables
1501 * for a changed disk, and then re-read the new partition table.
1502 * If we are revalidating a disk because of a media change, then we
1503 * enter with usage == 0. If we are using an ioctl, we automatically have
1504 * usage == 1 (we need an open channel to use an ioctl :-), so this
1507 int ide_revalidate_disk(kdev_t i_rdev
)
1510 ide_hwgroup_t
*hwgroup
;
1511 unsigned int p
, major
, minor
;
1514 if ((drive
= get_info_ptr(i_rdev
)) == NULL
)
1516 major
= MAJOR(i_rdev
);
1517 minor
= drive
->select
.b
.unit
<< PARTN_BITS
;
1518 hwgroup
= HWGROUP(drive
);
1519 spin_lock_irqsave(&hwgroup
->spinlock
, flags
);
1520 if (drive
->busy
|| (drive
->usage
> 1)) {
1521 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1526 spin_unlock_irqrestore(&hwgroup
->spinlock
, flags
);
1528 for (p
= 0; p
< (1<<PARTN_BITS
); ++p
) {
1529 if (drive
->part
[p
].nr_sects
> 0) {
1530 kdev_t devp
= MKDEV(major
, minor
+p
);
1531 struct super_block
* sb
= get_super(devp
);
1534 invalidate_inodes(sb
);
1535 invalidate_buffers (devp
);
1536 set_blocksize(devp
, 1024);
1538 drive
->part
[p
].start_sect
= 0;
1539 drive
->part
[p
].nr_sects
= 0;
1542 drive
->part
[0].nr_sects
= current_capacity(drive
);
1543 if ((drive
->media
!= ide_disk
&& drive
->media
!= ide_floppy
) ||
1544 drive
->driver
== NULL
|| !drive
->part
[0].nr_sects
)
1545 drive
->part
[0].start_sect
= -1;
1546 resetup_one_dev(HWIF(drive
)->gd
, drive
->select
.b
.unit
);
1549 wake_up(&drive
->wqueue
);
1554 static void revalidate_drives (void)
1560 for (index
= 0; index
< MAX_HWIFS
; ++index
) {
1561 hwif
= &ide_hwifs
[index
];
1562 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
1563 drive
= &ide_hwifs
[index
].drives
[unit
];
1564 if (drive
->revalidate
) {
1565 drive
->revalidate
= 0;
1567 (void) ide_revalidate_disk(MKDEV(hwif
->major
, unit
<<PARTN_BITS
));
1573 static void ide_init_module (int type
)
1576 ide_module_t
*module
= ide_modules
;
1579 if (module
->type
== type
) {
1581 (void) module
->init();
1583 module
= module
->next
;
1585 revalidate_drives();
1587 if (!found
&& type
== IDE_PROBE_MODULE
)
1588 (void) request_module("ide-probe");
1589 #endif /* CONFIG_KMOD */
1592 static int ide_open(struct inode
* inode
, struct file
* filp
)
1597 if ((drive
= get_info_ptr(inode
->i_rdev
)) == NULL
)
1600 if (drive
->driver
== NULL
)
1601 ide_init_module(IDE_DRIVER_MODULE
);
1603 if (drive
->driver
== NULL
) {
1604 if (drive
->media
== ide_disk
)
1605 (void) request_module("ide-disk");
1606 if (drive
->media
== ide_cdrom
)
1607 (void) request_module("ide-cd");
1608 if (drive
->media
== ide_tape
)
1609 (void) request_module("ide-tape");
1610 if (drive
->media
== ide_floppy
)
1611 (void) request_module("ide-floppy");
1613 #endif /* CONFIG_KMOD */
1615 sleep_on(&drive
->wqueue
);
1617 if (drive
->driver
!= NULL
) {
1618 if ((rc
= DRIVER(drive
)->open(inode
, filp
, drive
)))
1622 printk ("%s: driver not present\n", drive
->name
);
1629 * Releasing a block device means we sync() it, so that it can safely
1630 * be forgotten about...
1632 static int ide_release(struct inode
* inode
, struct file
* file
)
1636 if ((drive
= get_info_ptr(inode
->i_rdev
)) != NULL
) {
1637 fsync_dev(inode
->i_rdev
);
1639 if (drive
->driver
!= NULL
)
1640 DRIVER(drive
)->release(inode
, file
, drive
);
1646 int ide_replace_subdriver(ide_drive_t
*drive
, const char *driver
)
1648 if (!drive
->present
|| drive
->busy
|| drive
->usage
)
1650 if (drive
->driver
!= NULL
&& DRIVER(drive
)->cleanup(drive
))
1652 strncpy(drive
->driver_req
, driver
, 9);
1653 ide_init_module(IDE_DRIVER_MODULE
);
1654 drive
->driver_req
[0] = 0;
1655 ide_init_module(IDE_DRIVER_MODULE
);
1656 if (DRIVER(drive
) && !strcmp(DRIVER(drive
)->name
, driver
))
1662 void ide_unregister (unsigned int index
)
1664 struct gendisk
*gd
, **gdp
;
1665 ide_drive_t
*drive
, *d
;
1666 ide_hwif_t
*hwif
, *g
;
1667 ide_hwgroup_t
*hwgroup
;
1668 int irq_count
= 0, unit
, i
;
1669 unsigned long flags
;
1671 if (index
>= MAX_HWIFS
)
1673 save_flags(flags
); /* all CPUs */
1674 cli(); /* all CPUs */
1675 hwif
= &ide_hwifs
[index
];
1678 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
1679 drive
= &hwif
->drives
[unit
];
1680 if (!drive
->present
)
1682 if (drive
->busy
|| drive
->usage
)
1684 if (drive
->driver
!= NULL
&& DRIVER(drive
)->cleanup(drive
))
1688 hwgroup
= hwif
->hwgroup
;
1691 * free the irq if we were the only hwif using it
1695 if (g
->irq
== hwif
->irq
)
1698 } while (g
!= hwgroup
->hwif
);
1700 free_irq(hwif
->irq
, hwgroup
);
1703 * Note that we only release the standard ports,
1704 * and do not even try to handle any extra ports
1705 * allocated for weird IDE interface chipsets.
1707 ide_release_region(hwif
->io_ports
[IDE_DATA_OFFSET
], 8);
1708 ide_release_region(hwif
->io_ports
[IDE_CONTROL_OFFSET
], 1);
1711 * Remove us from the hwgroup, and free
1712 * the hwgroup if we were the only member
1715 for (i
= 0; i
< MAX_DRIVES
; ++i
) {
1716 drive
= &hwif
->drives
[i
];
1717 if (!drive
->present
)
1719 while (hwgroup
->drive
->next
!= drive
)
1720 hwgroup
->drive
= hwgroup
->drive
->next
;
1721 hwgroup
->drive
->next
= drive
->next
;
1722 if (hwgroup
->drive
== drive
)
1723 hwgroup
->drive
= NULL
;
1724 if (drive
->id
!= NULL
) {
1732 while (hwgroup
->hwif
->next
!= hwif
)
1733 hwgroup
->hwif
= hwgroup
->hwif
->next
;
1734 hwgroup
->hwif
->next
= hwif
->next
;
1735 if (hwgroup
->hwif
== hwif
)
1738 hwgroup
->hwif
= HWIF(hwgroup
->drive
);
1741 * Remove us from the kernel's knowledge
1743 unregister_blkdev(hwif
->major
, hwif
->name
);
1744 kfree(blksize_size
[hwif
->major
]);
1745 kfree(max_sectors
[hwif
->major
]);
1746 kfree(max_readahead
[hwif
->major
]);
1747 blk_dev
[hwif
->major
].request_fn
= NULL
;
1748 blk_dev
[hwif
->major
].data
= NULL
;
1749 blk_dev
[hwif
->major
].queue
= NULL
;
1750 blksize_size
[hwif
->major
] = NULL
;
1751 for (gdp
= &gendisk_head
; *gdp
; gdp
= &((*gdp
)->next
))
1752 if (*gdp
== hwif
->gd
)
1755 printk("gd not in disk chain!\n");
1757 gd
= *gdp
; *gdp
= gd
->next
;
1762 init_hwif_data (index
); /* restore hwif data to pristine status */
1764 restore_flags(flags
); /* all CPUs */
1767 int ide_register (int arg1
, int arg2
, int irq
)
1769 int index
, retry
= 1;
1771 ide_ioreg_t data_port
= (ide_ioreg_t
) arg1
, ctl_port
= (ide_ioreg_t
) arg2
;
1774 for (index
= 0; index
< MAX_HWIFS
; ++index
) {
1775 hwif
= &ide_hwifs
[index
];
1776 if (hwif
->io_ports
[IDE_DATA_OFFSET
] == data_port
)
1779 for (index
= 0; index
< MAX_HWIFS
; ++index
) {
1780 hwif
= &ide_hwifs
[index
];
1784 for (index
= 0; index
< MAX_HWIFS
; index
++)
1785 ide_unregister(index
);
1790 ide_unregister(index
);
1793 ide_init_hwif_ports(hwif
->io_ports
, data_port
, &hwif
->irq
);
1795 hwif
->io_ports
[IDE_CONTROL_OFFSET
] = ctl_port
;
1798 ide_init_module(IDE_PROBE_MODULE
);
1799 ide_init_module(IDE_DRIVER_MODULE
);
1800 return hwif
->present
? index
: -1;
1803 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
)
1805 ide_settings_t
**p
= (ide_settings_t
**) &drive
->settings
, *setting
= NULL
;
1807 while ((*p
) && strcmp((*p
)->name
, name
) < 0)
1809 if ((setting
= kmalloc(sizeof(*setting
), GFP_KERNEL
)) == NULL
)
1811 memset(setting
, 0, sizeof(*setting
));
1812 if ((setting
->name
= kmalloc(strlen(name
) + 1, GFP_KERNEL
)) == NULL
)
1814 strcpy(setting
->name
, name
); setting
->rw
= rw
;
1815 setting
->read_ioctl
= read_ioctl
; setting
->write_ioctl
= write_ioctl
;
1816 setting
->data_type
= data_type
; setting
->min
= min
;
1817 setting
->max
= max
; setting
->mul_factor
= mul_factor
;
1818 setting
->div_factor
= div_factor
; setting
->data
= data
;
1819 setting
->set
= set
; setting
->next
= *p
;
1821 setting
->auto_remove
= 1;
1829 void ide_remove_setting(ide_drive_t
*drive
, char *name
)
1831 ide_settings_t
**p
= (ide_settings_t
**) &drive
->settings
, *setting
;
1833 while ((*p
) && strcmp((*p
)->name
, name
))
1835 if ((setting
= (*p
)) == NULL
)
1837 (*p
) = setting
->next
;
1838 kfree(setting
->name
);
1842 static ide_settings_t
*ide_find_setting_by_ioctl(ide_drive_t
*drive
, int cmd
)
1844 ide_settings_t
*setting
= drive
->settings
;
1847 if (setting
->read_ioctl
== cmd
|| setting
->write_ioctl
== cmd
)
1849 setting
= setting
->next
;
1854 ide_settings_t
*ide_find_setting_by_name(ide_drive_t
*drive
, char *name
)
1856 ide_settings_t
*setting
= drive
->settings
;
1859 if (strcmp(setting
->name
, name
) == 0)
1861 setting
= setting
->next
;
1866 static void auto_remove_settings(ide_drive_t
*drive
)
1868 ide_settings_t
*setting
;
1870 setting
= drive
->settings
;
1872 if (setting
->auto_remove
) {
1873 ide_remove_setting(drive
, setting
->name
);
1876 setting
= setting
->next
;
1880 int ide_read_setting(ide_drive_t
*drive
, ide_settings_t
*setting
)
1883 unsigned long flags
;
1885 if ((setting
->rw
& SETTING_READ
)) {
1886 spin_lock_irqsave(&HWGROUP(drive
)->spinlock
, flags
);
1887 switch(setting
->data_type
) {
1889 val
= *((u8
*) setting
->data
);
1892 val
= *((u16
*) setting
->data
);
1896 val
= *((u32
*) setting
->data
);
1899 spin_unlock_irqrestore(&HWGROUP(drive
)->spinlock
, flags
);
1904 int ide_spin_wait_hwgroup (ide_drive_t
*drive
, unsigned long *flags
)
1906 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
1907 unsigned long timeout
= jiffies
+ (3 * HZ
);
1909 spin_lock_irqsave(&hwgroup
->spinlock
, *flags
);
1910 while (hwgroup
->busy
) {
1911 spin_unlock_irqrestore(&hwgroup
->spinlock
, *flags
);
1912 __sti(); /* local CPU only; needed for jiffies */
1913 if (0 < (signed long)(jiffies
- timeout
)) {
1914 printk("%s: channel busy\n", drive
->name
);
1917 spin_lock_irqsave(&hwgroup
->spinlock
, *flags
);
1922 int ide_write_setting(ide_drive_t
*drive
, ide_settings_t
*setting
, int val
)
1924 unsigned long flags
;
1928 if (!capable(CAP_SYS_ADMIN
))
1930 if (!(setting
->rw
& SETTING_WRITE
))
1932 if (val
< setting
->min
|| val
> setting
->max
)
1935 return setting
->set(drive
, val
);
1936 if (ide_spin_wait_hwgroup(drive
, &flags
))
1938 switch (setting
->data_type
) {
1940 *((u8
*) setting
->data
) = val
;
1943 *((u16
*) setting
->data
) = val
;
1946 *((u32
*) setting
->data
) = val
;
1949 p
= (u32
*) setting
->data
;
1950 for (i
= 0; i
< 1 << PARTN_BITS
; i
++, p
++)
1954 spin_unlock_irqrestore(&HWGROUP(drive
)->spinlock
, flags
);
1958 static int set_io_32bit(ide_drive_t
*drive
, int arg
)
1960 drive
->io_32bit
= arg
;
1961 #ifdef CONFIG_BLK_DEV_DTC2278
1962 if (HWIF(drive
)->chipset
== ide_dtc2278
)
1963 HWIF(drive
)->drives
[!drive
->select
.b
.unit
].io_32bit
= arg
;
1964 #endif /* CONFIG_BLK_DEV_DTC2278 */
1968 static int set_using_dma(ide_drive_t
*drive
, int arg
)
1970 if (!drive
->driver
|| !DRIVER(drive
)->supports_dma
)
1972 if (!drive
->id
|| !(drive
->id
->capability
& 1) || !HWIF(drive
)->dmaproc
)
1974 if (HWIF(drive
)->dmaproc(arg
? ide_dma_on
: ide_dma_off
, drive
))
1979 static int set_pio_mode(ide_drive_t
*drive
, int arg
)
1983 if (!HWIF(drive
)->tuneproc
)
1985 if (drive
->special
.b
.set_tune
)
1987 ide_init_drive_cmd(&rq
);
1988 drive
->tune_req
= (byte
) arg
;
1989 drive
->special
.b
.set_tune
= 1;
1990 (void) ide_do_drive_cmd (drive
, &rq
, ide_wait
);
1994 void ide_add_generic_settings(ide_drive_t
*drive
)
1997 * drive setting name read/write access read ioctl write ioctl data type min max mul_factor div_factor data pointer set function
1999 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
);
2000 ide_add_setting(drive
, "keepsettings", SETTING_RW
, HDIO_GET_KEEPSETTINGS
, HDIO_SET_KEEPSETTINGS
, TYPE_BYTE
, 0, 1, 1, 1, &drive
->keep_settings
, NULL
);
2001 ide_add_setting(drive
, "nice1", SETTING_RW
, -1, -1, TYPE_BYTE
, 0, 1, 1, 1, &drive
->nice1
, NULL
);
2002 ide_add_setting(drive
, "pio_mode", SETTING_WRITE
, -1, HDIO_SET_PIO_MODE
, TYPE_BYTE
, 0, 255, 1, 1, NULL
, set_pio_mode
);
2003 ide_add_setting(drive
, "slow", SETTING_RW
, -1, -1, TYPE_BYTE
, 0, 1, 1, 1, &drive
->slow
, NULL
);
2004 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
);
2005 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
);
2008 int ide_wait_cmd (ide_drive_t
*drive
, int cmd
, int nsect
, int feature
, int sectors
, byte
*buf
)
2015 memset(buf
, 0, 4 + SECTOR_WORDS
* 4 * sectors
);
2016 ide_init_drive_cmd(&rq
);
2022 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
2025 static int ide_ioctl (struct inode
*inode
, struct file
*file
,
2026 unsigned int cmd
, unsigned long arg
)
2028 int err
, major
, minor
;
2032 ide_settings_t
*setting
;
2034 if (!inode
|| !(dev
= inode
->i_rdev
))
2036 major
= MAJOR(dev
); minor
= MINOR(dev
);
2037 if ((drive
= get_info_ptr(inode
->i_rdev
)) == NULL
)
2040 if ((setting
= ide_find_setting_by_ioctl(drive
, cmd
)) != NULL
) {
2041 if (cmd
== setting
->read_ioctl
) {
2042 err
= ide_read_setting(drive
, setting
);
2043 return err
>= 0 ? put_user(err
, (long *) arg
) : err
;
2045 if ((MINOR(inode
->i_rdev
) & PARTN_MASK
))
2047 return ide_write_setting(drive
, setting
, arg
);
2051 ide_init_drive_cmd (&rq
);
2055 struct hd_geometry
*loc
= (struct hd_geometry
*) arg
;
2056 if (!loc
|| (drive
->media
!= ide_disk
&& drive
->media
!= ide_floppy
)) return -EINVAL
;
2057 if (put_user(drive
->bios_head
, (byte
*) &loc
->heads
)) return -EFAULT
;
2058 if (put_user(drive
->bios_sect
, (byte
*) &loc
->sectors
)) return -EFAULT
;
2059 if (put_user(drive
->bios_cyl
, (unsigned short *) &loc
->cylinders
)) return -EFAULT
;
2060 if (put_user((unsigned)drive
->part
[MINOR(inode
->i_rdev
)&PARTN_MASK
].start_sect
,
2061 (unsigned long *) &loc
->start
)) return -EFAULT
;
2065 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
2066 fsync_dev(inode
->i_rdev
);
2067 invalidate_buffers(inode
->i_rdev
);
2070 case BLKGETSIZE
: /* Return device size */
2071 return put_user(drive
->part
[MINOR(inode
->i_rdev
)&PARTN_MASK
].nr_sects
, (long *) arg
);
2073 case BLKRRPART
: /* Re-read partition tables */
2074 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
2075 return ide_revalidate_disk(inode
->i_rdev
);
2077 case HDIO_OBSOLETE_IDENTITY
:
2078 case HDIO_GET_IDENTITY
:
2079 if (MINOR(inode
->i_rdev
) & PARTN_MASK
)
2081 if (drive
->id
== NULL
)
2083 if (copy_to_user((char *)arg
, (char *)drive
->id
, (cmd
== HDIO_GET_IDENTITY
) ? sizeof(*drive
->id
) : 142))
2088 return put_user(drive
->dsc_overlap
<< IDE_NICE_DSC_OVERLAP
|
2089 drive
->atapi_overlap
<< IDE_NICE_ATAPI_OVERLAP
|
2090 drive
->nice0
<< IDE_NICE_0
|
2091 drive
->nice1
<< IDE_NICE_1
|
2092 drive
->nice2
<< IDE_NICE_2
,
2094 case HDIO_DRIVE_CMD
:
2096 byte args
[4], *argbuf
= args
;
2098 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
2099 if (NULL
== (void *) arg
)
2100 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
2101 if (copy_from_user(args
, (void *)arg
, 4))
2104 argsize
= 4 + (SECTOR_WORDS
* 4 * args
[3]);
2105 argbuf
= kmalloc(argsize
, GFP_KERNEL
);
2108 memcpy(argbuf
, args
, 4);
2110 err
= ide_wait_cmd(drive
, args
[0], args
[1], args
[2], args
[3], argbuf
);
2111 if (copy_to_user((void *)arg
, argbuf
, argsize
))
2118 case HDIO_SCAN_HWIF
:
2121 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
2122 if (copy_from_user(args
, (void *)arg
, 3 * sizeof(int)))
2124 if (ide_register(args
[0], args
[1], args
[2]) == -1)
2129 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
2130 if (drive
->driver
== NULL
)
2132 if (arg
!= (arg
& ((1 << IDE_NICE_DSC_OVERLAP
) | (1 << IDE_NICE_1
))))
2134 drive
->dsc_overlap
= (arg
>> IDE_NICE_DSC_OVERLAP
) & 1;
2135 if (drive
->dsc_overlap
&& !DRIVER(drive
)->supports_dsc_overlap
) {
2136 drive
->dsc_overlap
= 0;
2139 drive
->nice1
= (arg
>> IDE_NICE_1
) & 1;
2142 RO_IOCTLS(inode
->i_rdev
, arg
);
2145 if (drive
->driver
!= NULL
)
2146 return DRIVER(drive
)->ioctl(drive
, inode
, file
, cmd
, arg
);
2151 static int ide_check_media_change (kdev_t i_rdev
)
2155 if ((drive
= get_info_ptr(i_rdev
)) == NULL
)
2157 if (drive
->driver
!= NULL
)
2158 return DRIVER(drive
)->media_change(drive
);
2162 void ide_fixstring (byte
*s
, const int bytecount
, const int byteswap
)
2164 byte
*p
= s
, *end
= &s
[bytecount
& ~1]; /* bytecount must be even */
2167 /* convert from big-endian to host byte order */
2168 for (p
= end
; p
!= s
;) {
2169 unsigned short *pp
= (unsigned short *) (p
-= 2);
2174 /* strip leading blanks */
2175 while (s
!= end
&& *s
== ' ')
2178 /* compress internal blanks and strip trailing blanks */
2179 while (s
!= end
&& *s
) {
2180 if (*s
++ != ' ' || (s
!= end
&& *s
&& *s
!= ' '))
2184 /* wipe out trailing garbage */
2190 * stridx() returns the offset of c within s,
2191 * or -1 if c is '\0' or not found within s.
2193 __initfunc(static int stridx (const char *s
, char c
))
2195 char *i
= strchr(s
, c
);
2196 return (i
&& c
) ? i
- s
: -1;
2200 * match_parm() does parsing for ide_setup():
2202 * 1. the first char of s must be '='.
2203 * 2. if the remainder matches one of the supplied keywords,
2204 * the index (1 based) of the keyword is negated and returned.
2205 * 3. if the remainder is a series of no more than max_vals numbers
2206 * separated by commas, the numbers are saved in vals[] and a
2207 * count of how many were saved is returned. Base10 is assumed,
2208 * and base16 is allowed when prefixed with "0x".
2209 * 4. otherwise, zero is returned.
2211 __initfunc(static int match_parm (char *s
, const char *keywords
[], int vals
[], int max_vals
))
2213 static const char *decimal
= "0123456789";
2214 static const char *hex
= "0123456789abcdef";
2219 * Try matching against the supplied keywords,
2220 * and return -(index+1) if we match one
2222 if (keywords
!= NULL
) {
2223 for (i
= 0; *keywords
!= NULL
; ++i
) {
2224 if (!strcmp(s
, *keywords
++))
2229 * Look for a series of no more than "max_vals"
2230 * numeric values separated by commas, in base10,
2231 * or base16 when prefixed with "0x".
2232 * Return a count of how many were found.
2234 for (n
= 0; (i
= stridx(decimal
, *s
)) >= 0;) {
2236 while ((i
= stridx(decimal
, *++s
)) >= 0)
2237 vals
[n
] = (vals
[n
] * 10) + i
;
2238 if (*s
== 'x' && !vals
[n
]) {
2239 while ((i
= stridx(hex
, *++s
)) >= 0)
2240 vals
[n
] = (vals
[n
] * 0x10) + i
;
2242 if (++n
== max_vals
)
2244 if (*s
== ',' || *s
== ';')
2250 return 0; /* zero = nothing matched */
2254 * ide_setup() gets called VERY EARLY during initialization,
2255 * to handle kernel "command line" strings beginning with "hdx="
2256 * or "ide". Here is the complete set currently supported:
2258 * "hdx=" is recognized for all "x" from "a" to "h", such as "hdc".
2259 * "idex=" is recognized for all "x" from "0" to "3", such as "ide1".
2261 * "hdx=noprobe" : drive may be present, but do not probe for it
2262 * "hdx=none" : drive is NOT present, ignore cmos and do not probe
2263 * "hdx=nowerr" : ignore the WRERR_STAT bit on this drive
2264 * "hdx=cdrom" : drive is present, and is a cdrom drive
2265 * "hdx=cyl,head,sect" : disk drive is present, with specified geometry
2266 * "hdx=autotune" : driver will attempt to tune interface speed
2267 * to the fastest PIO mode supported,
2268 * if possible for this drive only.
2269 * Not fully supported by all chipset types,
2270 * and quite likely to cause trouble with
2271 * older/odd IDE drives.
2273 * "idebus=xx" : inform IDE driver of VESA/PCI bus speed in MHz,
2274 * where "xx" is between 20 and 66 inclusive,
2275 * used when tuning chipset PIO modes.
2276 * For PCI bus, 25 is correct for a P75 system,
2277 * 30 is correct for P90,P120,P180 systems,
2278 * and 33 is used for P100,P133,P166 systems.
2279 * If in doubt, use idebus=33 for PCI.
2280 * As for VLB, it is safest to not specify it.
2282 * "idex=noprobe" : do not attempt to access/use this interface
2283 * "idex=base" : probe for an interface at the addr specified,
2284 * where "base" is usually 0x1f0 or 0x170
2285 * and "ctl" is assumed to be "base"+0x206
2286 * "idex=base,ctl" : specify both base and ctl
2287 * "idex=base,ctl,irq" : specify base, ctl, and irq number
2288 * "idex=autotune" : driver will attempt to tune interface speed
2289 * to the fastest PIO mode supported,
2290 * for all drives on this interface.
2291 * Not fully supported by all chipset types,
2292 * and quite likely to cause trouble with
2293 * older/odd IDE drives.
2294 * "idex=noautotune" : driver will NOT attempt to tune interface speed
2295 * This is the default for most chipsets,
2296 * except the cmd640.
2297 * "idex=serialize" : do not overlap operations on idex and ide(x^1)
2298 * "idex=four" : four drives on idex and ide(x^1) share same ports
2299 * "idex=reset" : reset interface before first use
2300 * "idex=dma" : enable DMA by default on both drives if possible
2302 * The following are valid ONLY on ide0,
2303 * and the defaults for the base,ctl ports must not be altered.
2305 * "ide0=dtc2278" : probe/support DTC2278 interface
2306 * "ide0=ht6560b" : probe/support HT6560B interface
2307 * "ide0=cmd640_vlb" : *REQUIRED* for VLB cards with the CMD640 chip
2308 * (not for PCI -- automatically detected)
2309 * "ide0=qd6580" : probe/support qd6580 interface
2310 * "ide0=ali14xx" : probe/support ali14xx chipsets (ALI M1439, M1443, M1445)
2311 * "ide0=umc8672" : probe/support umc8672 chipsets
2313 __initfunc(void ide_setup (char *s
))
2318 unsigned int hw
, unit
;
2319 const char max_drive
= 'a' + ((MAX_HWIFS
* MAX_DRIVES
) - 1);
2320 const char max_hwif
= '0' + (MAX_HWIFS
- 1);
2322 printk("ide_setup: %s", s
);
2326 * Look for drive options: "hdx="
2328 if (s
[0] == 'h' && s
[1] == 'd' && s
[2] >= 'a' && s
[2] <= max_drive
) {
2329 const char *hd_words
[] = {"none", "noprobe", "nowerr", "cdrom",
2330 "serialize", "autotune", "noautotune",
2331 "slow", "swapdata", NULL
};
2333 hw
= unit
/ MAX_DRIVES
;
2334 unit
= unit
% MAX_DRIVES
;
2335 hwif
= &ide_hwifs
[hw
];
2336 drive
= &hwif
->drives
[unit
];
2337 switch (match_parm(&s
[3], hd_words
, vals
, 3)) {
2338 case -1: /* "none" */
2339 drive
->nobios
= 1; /* drop into "noprobe" */
2340 case -2: /* "noprobe" */
2343 case -3: /* "nowerr" */
2344 drive
->bad_wstat
= BAD_R_STAT
;
2347 case -4: /* "cdrom" */
2349 drive
->media
= ide_cdrom
;
2352 case -5: /* "serialize" */
2353 printk(" -- USE \"ide%d=serialize\" INSTEAD", hw
);
2355 case -6: /* "autotune" */
2356 drive
->autotune
= 1;
2358 case -7: /* "noautotune" */
2359 drive
->autotune
= 2;
2361 case -8: /* "slow" */
2364 case -9: /* swapdata */
2367 case 3: /* cyl,head,sect */
2368 drive
->media
= ide_disk
;
2369 drive
->cyl
= drive
->bios_cyl
= vals
[0];
2370 drive
->head
= drive
->bios_head
= vals
[1];
2371 drive
->sect
= drive
->bios_sect
= vals
[2];
2373 drive
->forced_geom
= 1;
2381 if (s
[0] != 'i' || s
[1] != 'd' || s
[2] != 'e')
2384 * Look for bus speed option: "idebus="
2386 if (s
[3] == 'b' && s
[4] == 'u' && s
[5] == 's') {
2387 if (match_parm(&s
[6], NULL
, vals
, 1) != 1)
2389 if (vals
[0] >= 20 && vals
[0] <= 66)
2390 idebus_parameter
= vals
[0];
2392 printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
2396 * Look for interface options: "idex="
2398 if (s
[3] >= '0' && s
[3] <= max_hwif
) {
2400 * Be VERY CAREFUL changing this: note hardcoded indexes below
2402 const char *ide_words
[] = {"noprobe", "serialize", "autotune", "noautotune", "reset", "dma", "four",
2403 "qd6580", "ht6560b", "cmd640_vlb", "dtc2278", "umc8672", "ali14xx", "dc4030", NULL
};
2405 hwif
= &ide_hwifs
[hw
];
2406 i
= match_parm(&s
[4], ide_words
, vals
, 3);
2409 * Cryptic check to ensure chipset not already set for hwif:
2411 if (i
> 0 || i
<= -7) { /* is parameter a chipset name? */
2412 if (hwif
->chipset
!= ide_unknown
)
2413 goto bad_option
; /* chipset already specified */
2414 if (i
<= -7 && hw
!= 0)
2415 goto bad_hwif
; /* chipset drivers are for "ide0=" only */
2416 if (i
<= -7 && ide_hwifs
[hw
^1].chipset
!= ide_unknown
)
2417 goto bad_option
; /* chipset for 2nd port already specified */
2422 #ifdef CONFIG_BLK_DEV_PDC4030
2423 case -14: /* "dc4030" */
2425 extern void setup_pdc4030(ide_hwif_t
*);
2426 setup_pdc4030(hwif
);
2429 #endif /* CONFIG_BLK_DEV_PDC4030 */
2430 #ifdef CONFIG_BLK_DEV_ALI14XX
2431 case -13: /* "ali14xx" */
2433 extern void init_ali14xx (void);
2437 #endif /* CONFIG_BLK_DEV_ALI14XX */
2438 #ifdef CONFIG_BLK_DEV_UMC8672
2439 case -12: /* "umc8672" */
2441 extern void init_umc8672 (void);
2445 #endif /* CONFIG_BLK_DEV_UMC8672 */
2446 #ifdef CONFIG_BLK_DEV_DTC2278
2447 case -11: /* "dtc2278" */
2449 extern void init_dtc2278 (void);
2453 #endif /* CONFIG_BLK_DEV_DTC2278 */
2454 #ifdef CONFIG_BLK_DEV_CMD640
2455 case -10: /* "cmd640_vlb" */
2457 extern int cmd640_vlb
; /* flag for cmd640.c */
2461 #endif /* CONFIG_BLK_DEV_CMD640 */
2462 #ifdef CONFIG_BLK_DEV_HT6560B
2463 case -9: /* "ht6560b" */
2465 extern void init_ht6560b (void);
2469 #endif /* CONFIG_BLK_DEV_HT6560B */
2470 #if CONFIG_BLK_DEV_QD6580
2471 case -8: /* "qd6580" */
2473 extern void init_qd6580 (void);
2477 #endif /* CONFIG_BLK_DEV_QD6580 */
2478 #ifdef CONFIG_BLK_DEV_4DRIVES
2479 case -7: /* "four" drives on one set of ports */
2481 ide_hwif_t
*mate
= &ide_hwifs
[hw
^1];
2482 mate
->drives
[0].select
.all
^= 0x20;
2483 mate
->drives
[1].select
.all
^= 0x20;
2484 hwif
->chipset
= mate
->chipset
= ide_4drives
;
2485 mate
->irq
= hwif
->irq
;
2486 memcpy(mate
->io_ports
, hwif
->io_ports
, sizeof(hwif
->io_ports
));
2489 #endif /* CONFIG_BLK_DEV_4DRIVES */
2493 case -5: /* "reset" */
2496 case -4: /* "noautotune" */
2497 hwif
->drives
[0].autotune
= 2;
2498 hwif
->drives
[1].autotune
= 2;
2500 case -3: /* "autotune" */
2501 hwif
->drives
[0].autotune
= 1;
2502 hwif
->drives
[1].autotune
= 1;
2504 case -2: /* "serialize" */
2506 hwif
->mate
= &ide_hwifs
[hw
^1];
2507 hwif
->mate
->mate
= hwif
;
2508 hwif
->serialized
= hwif
->mate
->serialized
= 1;
2511 case -1: /* "noprobe" */
2516 vals
[1] = vals
[0] + 0x206; /* default ctl */
2517 case 2: /* base,ctl */
2518 vals
[2] = 0; /* default irq = probe for it */
2519 case 3: /* base,ctl,irq */
2520 ide_init_hwif_ports(hwif
->io_ports
, (ide_ioreg_t
) vals
[0], &hwif
->irq
);
2521 hwif
->io_ports
[IDE_CONTROL_OFFSET
] = (ide_ioreg_t
) vals
[1];
2522 hwif
->irq
= vals
[2];
2524 hwif
->chipset
= ide_generic
;
2527 case 0: goto bad_option
;
2529 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
2534 printk(" -- BAD OPTION\n");
2537 printk("-- NOT SUPPORTED ON ide%d", hw
);
2543 * This routine is called from the partition-table code in genhd.c
2544 * to "convert" a drive to a logical geometry with fewer than 1024 cyls.
2546 * The second parameter, "xparm", determines exactly how the translation
2548 * 0 = convert to CHS with fewer than 1024 cyls
2549 * using the same method as Ontrack DiskManager.
2550 * 1 = same as "0", plus offset everything by 63 sectors.
2551 * -1 = similar to "0", plus redirect sector 0 to sector 1.
2552 * >1 = convert to a CHS geometry with "xparm" heads.
2554 * Returns 0 if the translation was not possible, if the device was not
2555 * an IDE disk drive, or if a geometry was "forced" on the commandline.
2556 * Returns 1 if the geometry translation was successful.
2558 int ide_xlate_1024 (kdev_t i_rdev
, int xparm
, const char *msg
)
2561 static const byte head_vals
[] = {4, 8, 16, 32, 64, 128, 255, 0};
2562 const byte
*heads
= head_vals
;
2563 unsigned long tracks
;
2565 if ((drive
= get_info_ptr(i_rdev
)) == NULL
|| drive
->forced_geom
)
2568 if (xparm
> 1 && xparm
<= drive
->bios_head
&& drive
->bios_sect
== 63)
2569 return 0; /* we already have a translation */
2573 if (xparm
< 0 && (drive
->bios_cyl
* drive
->bios_head
* drive
->bios_sect
) < (1024 * 16 * 63))
2574 return 0; /* small disk: no translation needed */
2577 drive
->cyl
= drive
->id
->cyls
;
2578 drive
->head
= drive
->id
->heads
;
2579 drive
->sect
= drive
->id
->sectors
;
2581 drive
->bios_cyl
= drive
->cyl
;
2582 drive
->bios_head
= drive
->head
;
2583 drive
->bios_sect
= drive
->sect
;
2584 drive
->special
.b
.set_geometry
= 1;
2586 tracks
= drive
->bios_cyl
* drive
->bios_head
* drive
->bios_sect
/ 63;
2587 drive
->bios_sect
= 63;
2589 drive
->bios_head
= xparm
;
2590 drive
->bios_cyl
= tracks
/ drive
->bios_head
;
2592 while (drive
->bios_cyl
>= 1024) {
2593 drive
->bios_head
= *heads
;
2594 drive
->bios_cyl
= tracks
/ drive
->bios_head
;
2598 #if FAKE_FDISK_FOR_EZDRIVE
2600 drive
->remap_0_to_1
= 1;
2601 printk("[remap 0->1] ");
2603 #endif /* FAKE_FDISK_FOR_EZDRIVE */
2606 drive
->bios_cyl
= (tracks
- 1) / drive
->bios_head
;
2607 printk("[remap +63] ");
2610 drive
->part
[0].nr_sects
= current_capacity(drive
);
2611 printk("[%d/%d/%d]", drive
->bios_cyl
, drive
->bios_head
, drive
->bios_sect
);
2616 * probe_for_hwifs() finds/initializes "known" IDE interfaces
2618 __initfunc(static void probe_for_hwifs (void))
2623 #ifdef CONFIG_BLK_DEV_IDEPCI
2626 #ifdef CONFIG_BLK_DEV_RZ1000
2628 extern void ide_probe_for_rz100x(void);
2629 ide_probe_for_rz100x();
2631 #endif /* CONFIG_BLK_DEV_RZ1000 */
2632 #endif /* CONFIG_BLK_DEV_IDEPCI */
2634 #endif /* CONFIG_PCI */
2636 #ifdef CONFIG_BLK_DEV_CMD640
2638 extern void ide_probe_for_cmd640x(void);
2639 ide_probe_for_cmd640x();
2641 #endif /* CONFIG_BLK_DEV_CMD640 */
2642 #ifdef CONFIG_BLK_DEV_PDC4030
2644 extern int init_pdc4030(void);
2645 (void) init_pdc4030();
2647 #endif /* CONFIG_BLK_DEV_PDC4030 */
2648 #ifdef CONFIG_BLK_DEV_IDE_PMAC
2650 extern void pmac_ide_probe(void);
2653 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
2656 __initfunc(void ide_init_builtin_drivers (void))
2659 * Probe for special PCI and other "known" interface chipsets
2663 #ifdef CONFIG_BLK_DEV_IDE
2664 #if defined(__mc68000__) || defined(CONFIG_APUS)
2665 if (ide_hwifs
[0].io_ports
[IDE_DATA_OFFSET
]) {
2666 ide_get_lock(&ide_lock
, NULL
, NULL
); /* for atari only */
2667 disable_irq(ide_hwifs
[0].irq
);
2669 #endif /* __mc68000__ || CONFIG_APUS */
2671 (void) ideprobe_init();
2673 #if defined(__mc68000__) || defined(CONFIG_APUS)
2674 if (ide_hwifs
[0].io_ports
[IDE_DATA_OFFSET
]) {
2675 enable_irq(ide_hwifs
[0].irq
);
2676 ide_release_lock(&ide_lock
); /* for atari only */
2678 #endif /* __mc68000__ || CONFIG_APUS */
2679 #endif /* CONFIG_BLK_DEV_IDE */
2681 #ifdef CONFIG_PROC_FS
2686 * Attempt to match drivers for the available drives
2688 #ifdef CONFIG_BLK_DEV_IDEDISK
2689 (void) idedisk_init();
2690 #endif /* CONFIG_BLK_DEV_IDEDISK */
2691 #ifdef CONFIG_BLK_DEV_IDECD
2692 (void) ide_cdrom_init();
2693 #endif /* CONFIG_BLK_DEV_IDECD */
2694 #ifdef CONFIG_BLK_DEV_IDETAPE
2695 (void) idetape_init();
2696 #endif /* CONFIG_BLK_DEV_IDETAPE */
2697 #ifdef CONFIG_BLK_DEV_IDEFLOPPY
2698 (void) idefloppy_init();
2699 #endif /* CONFIG_BLK_DEV_IDEFLOPPY */
2700 #ifdef CONFIG_BLK_DEV_IDESCSI
2701 (void) idescsi_init();
2702 #endif /* CONFIG_BLK_DEV_IDESCSI */
2705 static int default_cleanup (ide_drive_t
*drive
)
2707 return ide_unregister_subdriver(drive
);
2710 static void default_do_request(ide_drive_t
*drive
, struct request
*rq
, unsigned long block
)
2712 ide_end_request(0, HWGROUP(drive
));
2715 static void default_end_request (byte uptodate
, ide_hwgroup_t
*hwgroup
)
2717 ide_end_request(uptodate
, hwgroup
);
2720 static int default_ioctl (ide_drive_t
*drive
, struct inode
*inode
, struct file
*file
,
2721 unsigned int cmd
, unsigned long arg
)
2726 static int default_open (struct inode
*inode
, struct file
*filp
, ide_drive_t
*drive
)
2732 static void default_release (struct inode
*inode
, struct file
*filp
, ide_drive_t
*drive
)
2736 static int default_check_media_change (ide_drive_t
*drive
)
2741 static void default_pre_reset (ide_drive_t
*drive
)
2745 static unsigned long default_capacity (ide_drive_t
*drive
)
2747 return 0x7fffffff; /* cdrom or tape */
2750 static void default_special (ide_drive_t
*drive
)
2752 special_t
*s
= &drive
->special
;
2755 drive
->mult_req
= 0;
2758 static void setup_driver_defaults (ide_drive_t
*drive
)
2760 ide_driver_t
*d
= drive
->driver
;
2762 if (d
->cleanup
== NULL
) d
->cleanup
= default_cleanup
;
2763 if (d
->do_request
== NULL
) d
->do_request
= default_do_request
;
2764 if (d
->end_request
== NULL
) d
->end_request
= default_end_request
;
2765 if (d
->ioctl
== NULL
) d
->ioctl
= default_ioctl
;
2766 if (d
->open
== NULL
) d
->open
= default_open
;
2767 if (d
->release
== NULL
) d
->release
= default_release
;
2768 if (d
->media_change
== NULL
) d
->media_change
= default_check_media_change
;
2769 if (d
->pre_reset
== NULL
) d
->pre_reset
= default_pre_reset
;
2770 if (d
->capacity
== NULL
) d
->capacity
= default_capacity
;
2771 if (d
->special
== NULL
) d
->special
= default_special
;
2774 ide_drive_t
*ide_scan_devices (byte media
, const char *name
, ide_driver_t
*driver
, int n
)
2776 unsigned int unit
, index
, i
;
2778 for (index
= 0; index
< MAX_HWIFS
; ++index
)
2779 if (ide_hwifs
[index
].present
) goto search
;
2780 ide_init_module(IDE_PROBE_MODULE
);
2782 for (index
= 0, i
= 0; index
< MAX_HWIFS
; ++index
) {
2783 ide_hwif_t
*hwif
= &ide_hwifs
[index
];
2786 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
2787 ide_drive_t
*drive
= &hwif
->drives
[unit
];
2788 char *req
= drive
->driver_req
;
2789 if (*req
&& !strstr(name
, req
))
2791 if (drive
->present
&& drive
->media
== media
&& drive
->driver
== driver
&& ++i
> n
)
2798 #ifdef CONFIG_PROC_FS
2799 static ide_proc_entry_t generic_subdriver_entries
[] = {
2800 { "capacity", S_IFREG
|S_IRUGO
, proc_ide_read_capacity
, NULL
},
2801 { NULL
, 0, NULL
, NULL
}
2805 int ide_register_subdriver (ide_drive_t
*drive
, ide_driver_t
*driver
, int version
)
2807 unsigned long flags
;
2809 save_flags(flags
); /* all CPUs */
2810 cli(); /* all CPUs */
2811 if (version
!= IDE_SUBDRIVER_VERSION
|| !drive
->present
|| drive
->driver
!= NULL
|| drive
->busy
|| drive
->usage
) {
2812 restore_flags(flags
); /* all CPUs */
2815 drive
->driver
= driver
;
2816 setup_driver_defaults(drive
);
2817 restore_flags(flags
); /* all CPUs */
2818 if (drive
->autotune
!= 2) {
2819 if (driver
->supports_dma
&& HWIF(drive
)->dmaproc
!= NULL
)
2820 (void) (HWIF(drive
)->dmaproc(ide_dma_check
, drive
));
2821 drive
->dsc_overlap
= (drive
->next
!= drive
&& driver
->supports_dsc_overlap
);
2824 drive
->revalidate
= 1;
2825 #ifdef CONFIG_PROC_FS
2826 ide_add_proc_entries(drive
->proc
, generic_subdriver_entries
, drive
);
2827 ide_add_proc_entries(drive
->proc
, driver
->proc
, drive
);
2832 int ide_unregister_subdriver (ide_drive_t
*drive
)
2834 unsigned long flags
;
2836 save_flags(flags
); /* all CPUs */
2837 cli(); /* all CPUs */
2838 if (drive
->usage
|| drive
->busy
|| drive
->driver
== NULL
|| DRIVER(drive
)->busy
) {
2839 restore_flags(flags
); /* all CPUs */
2842 #ifdef CONFIG_PROC_FS
2843 ide_remove_proc_entries(drive
->proc
, DRIVER(drive
)->proc
);
2844 ide_remove_proc_entries(drive
->proc
, generic_subdriver_entries
);
2846 auto_remove_settings(drive
);
2847 drive
->driver
= NULL
;
2848 restore_flags(flags
); /* all CPUs */
2852 int ide_register_module (ide_module_t
*module
)
2854 ide_module_t
*p
= ide_modules
;
2861 module
->next
= ide_modules
;
2862 ide_modules
= module
;
2863 revalidate_drives();
2867 void ide_unregister_module (ide_module_t
*module
)
2871 for (p
= &ide_modules
; (*p
) && (*p
) != module
; p
= &((*p
)->next
));
2876 struct file_operations ide_fops
[] = {{
2877 NULL
, /* lseek - default */
2878 block_read
, /* read - general block-dev read */
2879 block_write
, /* write - general block-dev write */
2880 NULL
, /* readdir - bad */
2882 ide_ioctl
, /* ioctl */
2884 ide_open
, /* open */
2886 ide_release
, /* release */
2887 block_fsync
, /* fsync */
2889 ide_check_media_change
, /* check_media_change */
2890 ide_revalidate_disk
/* revalidate */
2893 EXPORT_SYMBOL(ide_hwifs
);
2894 EXPORT_SYMBOL(ide_register_module
);
2895 EXPORT_SYMBOL(ide_unregister_module
);
2896 EXPORT_SYMBOL(ide_spin_wait_hwgroup
);
2901 EXPORT_SYMBOL(ide_timer_expiry
);
2902 EXPORT_SYMBOL(ide_intr
);
2903 EXPORT_SYMBOL(ide_geninit
);
2904 EXPORT_SYMBOL(ide_fops
);
2905 EXPORT_SYMBOL(ide_get_queue
);
2906 EXPORT_SYMBOL(do_ide0_request
);
2907 EXPORT_SYMBOL(ide_add_generic_settings
);
2909 EXPORT_SYMBOL(do_ide1_request
);
2910 #endif /* MAX_HWIFS > 1 */
2912 EXPORT_SYMBOL(do_ide2_request
);
2913 #endif /* MAX_HWIFS > 2 */
2915 EXPORT_SYMBOL(do_ide3_request
);
2916 #endif /* MAX_HWIFS > 3 */
2918 EXPORT_SYMBOL(do_ide4_request
);
2919 #endif /* MAX_HWIFS > 4 */
2921 EXPORT_SYMBOL(do_ide5_request
);
2922 #endif /* MAX_HWIFS > 5 */
2927 EXPORT_SYMBOL(ide_scan_devices
);
2928 EXPORT_SYMBOL(ide_register_subdriver
);
2929 EXPORT_SYMBOL(ide_unregister_subdriver
);
2930 EXPORT_SYMBOL(ide_input_data
);
2931 EXPORT_SYMBOL(ide_output_data
);
2932 EXPORT_SYMBOL(atapi_input_bytes
);
2933 EXPORT_SYMBOL(atapi_output_bytes
);
2934 EXPORT_SYMBOL(ide_set_handler
);
2935 EXPORT_SYMBOL(ide_dump_status
);
2936 EXPORT_SYMBOL(ide_error
);
2937 EXPORT_SYMBOL(ide_fixstring
);
2938 EXPORT_SYMBOL(ide_wait_stat
);
2939 EXPORT_SYMBOL(ide_do_reset
);
2940 EXPORT_SYMBOL(ide_init_drive_cmd
);
2941 EXPORT_SYMBOL(ide_do_drive_cmd
);
2942 EXPORT_SYMBOL(ide_end_drive_cmd
);
2943 EXPORT_SYMBOL(ide_end_request
);
2944 EXPORT_SYMBOL(ide_revalidate_disk
);
2945 EXPORT_SYMBOL(ide_cmd
);
2946 EXPORT_SYMBOL(ide_wait_cmd
);
2947 EXPORT_SYMBOL(ide_stall_queue
);
2948 #ifdef CONFIG_PROC_FS
2949 EXPORT_SYMBOL(ide_add_proc_entries
);
2950 EXPORT_SYMBOL(ide_remove_proc_entries
);
2951 EXPORT_SYMBOL(proc_ide_read_geometry
);
2953 EXPORT_SYMBOL(ide_add_setting
);
2954 EXPORT_SYMBOL(ide_remove_setting
);
2956 EXPORT_SYMBOL(ide_register
);
2957 EXPORT_SYMBOL(ide_unregister
);
2960 * This is gets invoked once during initialization, to set *everything* up
2962 __initfunc(int ide_init (void))
2967 ide_init_builtin_drivers();
2974 char *options
= NULL
;
2975 MODULE_PARM(options
,"s");
2977 __initfunc(static void parse_options (char *line
))
2981 if (line
== NULL
|| !*line
)
2983 while ((line
= next
) != NULL
) {
2984 if ((next
= strchr(line
,' ')) != NULL
)
2986 if (!strncmp(line
,"ide",3) || (!strncmp(line
,"hd",2) && line
[2] != '='))
2991 int init_module (void)
2993 parse_options(options
);
2997 void cleanup_module (void)
3001 for (index
= 0; index
< MAX_HWIFS
; ++index
)
3002 ide_unregister(index
);
3003 #ifdef CONFIG_PROC_FS