4 * linux/include/linux/ide.h
6 * Copyright (C) 1994-2002 Linus Torvalds & authors
9 #include <linux/config.h>
10 #include <linux/init.h>
11 #include <linux/ioport.h>
12 #include <linux/hdreg.h>
13 #include <linux/hdsmart.h>
14 #include <linux/blkdev.h>
15 #include <linux/proc_fs.h>
16 #include <linux/devfs_fs_kernel.h>
17 #include <linux/interrupt.h>
18 #include <linux/bitops.h>
19 #include <linux/highmem.h>
20 #include <linux/pci.h>
21 #include <asm/byteorder.h>
22 #include <asm/system.h>
23 #include <asm/hdreg.h>
26 #define CLASSIC_BUILTINS_METHOD 1
27 //#undef CLASSIC_BUILTINS_METHOD
28 #define HWIF_PROBE_CLASSIC_METHOD 1
29 //#undef HWIF_PROBE_CLASSIC_METHOD
31 #ifdef CLASSIC_BUILTINS_METHOD
32 # undef FAKE_CLASSIC_ATTACH_METHOD
33 # undef DIRECT_HWIF_PROBE_ATTACH_METHOD
34 #else /* ! CLASSIC_BUILTINS_METHOD */
35 # ifdef HWIF_PROBE_CLASSIC_METHOD
36 # undef FAKE_CLASSIC_ATTACH_METHOD
37 # undef DIRECT_HWIF_PROBE_ATTACH_METHOD
38 # else /* ! HWIF_PROBE_CLASSIC_METHOD */
39 //# define FAKE_CLASSIC_ATTACH_METHOD 1
40 # undef FAKE_CLASSIC_ATTACH_METHOD
41 # ifdef FAKE_CLASSIC_ATTACH_METHOD
42 # undef DIRECT_HWIF_PROBE_ATTACH_METHOD
43 # else /* ! FAKE_CLASSIC_ATTACH_METHOD */
44 # define DIRECT_HWIF_PROBE_ATTACH_METHOD 1
45 # endif /* FAKE_CLASSIC_ATTACH_METHOD */
46 # endif /* HWIF_PROBE_CLASSIC_METHOD */
47 #endif /* CLASSIC_BUILTINS_METHOD */
50 * This is the multiple IDE interface driver, as evolved from hd.c.
51 * It supports up to four IDE interfaces, on one or more IRQs (usually 14 & 15).
52 * There can be up to two drives per interface, as per the ATA-2 spec.
54 * Primary i/f: ide0: major=3; (hda) minor=0; (hdb) minor=64
55 * Secondary i/f: ide1: major=22; (hdc or hd1a) minor=0; (hdd or hd1b) minor=64
56 * Tertiary i/f: ide2: major=33; (hde) minor=0; (hdf) minor=64
57 * Quaternary i/f: ide3: major=34; (hdg) minor=0; (hdh) minor=64
60 /******************************************************************************
61 * IDE driver configuration options (play with these as desired):
63 * REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary
65 #undef REALLY_FAST_IO /* define if ide ports are perfect */
66 #define INITIAL_MULT_COUNT 0 /* off=0; on=2,4,8,16,32, etc.. */
68 #ifndef SUPPORT_SLOW_DATA_PORTS /* 1 to support slow data ports */
69 #define SUPPORT_SLOW_DATA_PORTS 1 /* 0 to reduce kernel size */
71 #ifndef SUPPORT_VLB_SYNC /* 1 to support weird 32-bit chips */
72 #define SUPPORT_VLB_SYNC 1 /* 0 to reduce kernel size */
74 #ifndef DISK_RECOVERY_TIME /* off=0; on=access_delay_time */
75 #define DISK_RECOVERY_TIME 0 /* for hardware that needs it */
77 #ifndef OK_TO_RESET_CONTROLLER /* 1 needed for good error recovery */
78 #define OK_TO_RESET_CONTROLLER 1 /* 0 for use with AH2372A/B interface */
80 #ifndef FANCY_STATUS_DUMPS /* 1 for human-readable drive errors */
81 #define FANCY_STATUS_DUMPS 1 /* 0 to reduce kernel size */
84 #ifdef CONFIG_BLK_DEV_CMD640
85 #if 0 /* change to 1 when debugging cmd640 problems */
86 void cmd640_dump_regs (void);
87 #define CMD640_DUMP_REGS cmd640_dump_regs() /* for debugging cmd640 chipset */
89 #endif /* CONFIG_BLK_DEV_CMD640 */
91 #ifndef DISABLE_IRQ_NOSYNC
92 #define DISABLE_IRQ_NOSYNC 0
96 * IDE_DRIVE_CMD is used to implement many features of the hdparm utility
98 #define IDE_DRIVE_CMD 99 /* (magic) undef to reduce kernel size*/
100 #define IDE_DRIVE_TASK 98
103 * IDE_DRIVE_TASKFILE is used to implement many features needed for raw tasks
105 #define IDE_DRIVE_TASKFILE 97
108 * "No user-serviceable parts" beyond this point :)
109 *****************************************************************************/
111 typedef unsigned char byte; /* used everywhere */
114 * Probably not wise to fiddle with these
116 #define ERROR_MAX 8 /* Max read/write errors per sector */
117 #define ERROR_RESET 3 /* Reset controller every 4th retry */
118 #define ERROR_RECAL 1 /* Recalibrate every 2nd retry */
123 #define IDE_TUNE_BIOS 3
124 #define IDE_TUNE_NOAUTO 2
125 #define IDE_TUNE_AUTO 1
126 #define IDE_TUNE_DEFAULT 0
132 #define DMA_PIO_RETRY 1 /* retrying in PIO */
135 * Ensure that various configuration flags have compatible settings
137 #ifdef REALLY_SLOW_IO
138 #undef REALLY_FAST_IO
141 #define HWIF(drive) ((ide_hwif_t *)((drive)->hwif))
142 #define HWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
145 * Definitions for accessing IDE controller registers
147 #define IDE_NR_PORTS (10)
149 #define IDE_DATA_OFFSET (0)
150 #define IDE_ERROR_OFFSET (1)
151 #define IDE_NSECTOR_OFFSET (2)
152 #define IDE_SECTOR_OFFSET (3)
153 #define IDE_LCYL_OFFSET (4)
154 #define IDE_HCYL_OFFSET (5)
155 #define IDE_SELECT_OFFSET (6)
156 #define IDE_STATUS_OFFSET (7)
157 #define IDE_CONTROL_OFFSET (8)
158 #define IDE_IRQ_OFFSET (9)
160 #define IDE_FEATURE_OFFSET IDE_ERROR_OFFSET
161 #define IDE_COMMAND_OFFSET IDE_STATUS_OFFSET
163 #define IDE_DATA_OFFSET_HOB (0)
164 #define IDE_ERROR_OFFSET_HOB (1)
165 #define IDE_NSECTOR_OFFSET_HOB (2)
166 #define IDE_SECTOR_OFFSET_HOB (3)
167 #define IDE_LCYL_OFFSET_HOB (4)
168 #define IDE_HCYL_OFFSET_HOB (5)
169 #define IDE_SELECT_OFFSET_HOB (6)
170 #define IDE_CONTROL_OFFSET_HOB (7)
172 #define IDE_FEATURE_OFFSET_HOB IDE_ERROR_OFFSET_HOB
174 #define IDE_DATA_REG (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
175 #define IDE_ERROR_REG (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
176 #define IDE_NSECTOR_REG (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
177 #define IDE_SECTOR_REG (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
178 #define IDE_LCYL_REG (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
179 #define IDE_HCYL_REG (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
180 #define IDE_SELECT_REG (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
181 #define IDE_STATUS_REG (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
182 #define IDE_CONTROL_REG (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
183 #define IDE_IRQ_REG (HWIF(drive)->io_ports[IDE_IRQ_OFFSET])
185 #define IDE_DATA_REG_HOB (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
186 #define IDE_ERROR_REG_HOB (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
187 #define IDE_NSECTOR_REG_HOB (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
188 #define IDE_SECTOR_REG_HOB (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
189 #define IDE_LCYL_REG_HOB (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
190 #define IDE_HCYL_REG_HOB (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
191 #define IDE_SELECT_REG_HOB (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
192 #define IDE_STATUS_REG_HOB (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
193 #define IDE_CONTROL_REG_HOB (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
195 #define IDE_FEATURE_REG IDE_ERROR_REG
196 #define IDE_COMMAND_REG IDE_STATUS_REG
197 #define IDE_ALTSTATUS_REG IDE_CONTROL_REG
198 #define IDE_IREASON_REG IDE_NSECTOR_REG
199 #define IDE_BCOUNTL_REG IDE_LCYL_REG
200 #define IDE_BCOUNTH_REG IDE_HCYL_REG
202 #define OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
203 #define BAD_R_STAT (BUSY_STAT | ERR_STAT)
204 #define BAD_W_STAT (BAD_R_STAT | WRERR_STAT)
205 #define BAD_STAT (BAD_R_STAT | DRQ_STAT)
206 #define DRIVE_READY (READY_STAT | SEEK_STAT)
207 #define DATA_READY (DRQ_STAT)
209 #define BAD_CRC (ABRT_ERR | ICRC_ERR)
211 #define SATA_NR_PORTS (3) /* 16 possible ?? */
213 #define SATA_STATUS_OFFSET (0)
214 #define SATA_STATUS_REG (HWIF(drive)->sata_scr[SATA_STATUS_OFFSET])
215 #define SATA_ERROR_OFFSET (1)
216 #define SATA_ERROR_REG (HWIF(drive)->sata_scr[SATA_ERROR_OFFSET])
217 #define SATA_CONTROL_OFFSET (2)
218 #define SATA_CONTROL_REG (HWIF(drive)->sata_scr[SATA_CONTROL_OFFSET])
220 #define SATA_MISC_OFFSET (0)
221 #define SATA_MISC_REG (HWIF(drive)->sata_misc[SATA_MISC_OFFSET])
222 #define SATA_PHY_OFFSET (1)
223 #define SATA_PHY_REG (HWIF(drive)->sata_misc[SATA_PHY_OFFSET])
224 #define SATA_IEN_OFFSET (2)
225 #define SATA_IEN_REG (HWIF(drive)->sata_misc[SATA_IEN_OFFSET])
228 * Our Physical Region Descriptor (PRD) table should be large enough
229 * to handle the biggest I/O request we are likely to see. Since requests
230 * can have no more than 256 sectors, and since the typical blocksize is
231 * two or more sectors, we could get by with a limit of 128 entries here for
232 * the usual worst case. Most requests seem to include some contiguous blocks,
233 * further reducing the number of table entries required.
235 * The driver reverts to PIO mode for individual requests that exceed
236 * this limit (possible with 512 byte blocksizes, eg. MSDOS f/s), so handling
237 * 100% of all crazy scenarios here is not necessary.
239 * As it turns out though, we must allocate a full 4KB page for this,
240 * so the two PRD tables (ide0 & ide1) will each get half of that,
241 * allowing each to have about 256 entries (8 bytes each) from this.
244 #define PRD_ENTRIES (PAGE_SIZE / (2 * PRD_BYTES))
247 * Some more useful definitions
249 #define IDE_MAJOR_NAME "hd" /* the same for all i/f; see also genhd.c */
250 #define MAJOR_NAME IDE_MAJOR_NAME
251 #define PARTN_BITS 6 /* number of minor dev bits for partitions */
252 #define PARTN_MASK ((1<<PARTN_BITS)-1) /* a useful bit mask */
253 #define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */
254 #define SECTOR_SIZE 512
255 #define SECTOR_WORDS (SECTOR_SIZE / 4) /* number of 32bit words per sector */
256 #define IDE_LARGE_SEEK(b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t)))
257 #define IDE_MIN(a,b) ((a)<(b) ? (a):(b))
258 #define IDE_MAX(a,b) ((a)>(b) ? (a):(b))
261 * Timeouts for various operations:
263 #define WAIT_DRQ (5*HZ/100) /* 50msec - spec allows up to 20ms */
264 #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
265 #define WAIT_READY (5*HZ) /* 5sec - some laptops are very slow */
267 #define WAIT_READY (3*HZ/100) /* 30msec - should be instantaneous */
268 #endif /* CONFIG_APM || CONFIG_APM_MODULE */
269 #define WAIT_PIDENTIFY (10*HZ) /* 10sec - should be less than 3ms (?), if all ATAPI CD is closed at boot */
270 #define WAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */
271 #define WAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */
272 #define WAIT_MIN_SLEEP (2*HZ/100) /* 20msec - minimum sleep time */
274 #define HOST(hwif,chipset) \
276 return ((hwif)->chipset == chipset) ? 1 : 0; \
279 #define IDE_DEBUG(lineno) \
280 printk("%s,%s,line=%d\n", __FILE__, __FUNCTION__, (lineno))
283 * Check for an interrupt and acknowledge the interrupt status
286 typedef int (ide_ack_intr_t)(struct hwif_s *);
293 * hwif_chipset_t is used to keep track of the specific hardware
294 * chipset used by each IDE interface, if known.
296 typedef enum { ide_unknown, ide_generic, ide_pci,
297 ide_cmd640, ide_dtc2278, ide_ali14xx,
298 ide_qd65xx, ide_umc8672, ide_ht6560b,
299 ide_pdc4030, ide_rz1000, ide_trm290,
300 ide_cmd646, ide_cy82c693, ide_4drives,
301 ide_pmac, ide_etrax100, ide_acorn
304 typedef struct ide_io_ops_s {
305 /* insert io operations here! */
306 void (*OUTB)(u8 addr, unsigned long port);
307 void (*OUTW)(u16 addr, unsigned long port);
308 void (*OUTL)(u32 addr, unsigned long port);
309 void (*OUTSW)(unsigned long port, void *addr, u32 count);
310 void (*OUTSL)(unsigned long port, void *addr, u32 count);
312 u8 (*INB)(unsigned long port);
313 u16 (*INW)(unsigned long port);
314 u32 (*INL)(unsigned long port);
315 void (*INSW)(unsigned long port, void *addr, u32 count);
316 void (*INSL)(unsigned long port, void *addr, u32 count);
320 * Structure to hold all information about the location of this port
322 typedef struct hw_regs_s {
323 ide_ioreg_t io_ports[IDE_NR_PORTS]; /* task file registers */
324 int irq; /* our irq number */
325 int dma; /* our dma entry */
326 ide_ack_intr_t *ack_intr; /* acknowledge interrupt */
327 void *priv; /* interface specific data */
328 hwif_chipset_t chipset;
330 ide_io_ops_t *iops; /* */
332 sata_ioreg_t sata_scr[SATA_NR_PORTS];
333 sata_ioreg_t sata_misc[SATA_NR_PORTS];
337 * Register new hardware with ide
339 int ide_register_hw(hw_regs_t *hw, struct hwif_s **hwifp);
342 * Set up hw_regs_t structure before calling ide_register_hw (optional)
344 void ide_setup_ports( hw_regs_t *hw,
349 ide_ack_intr_t *ack_intr,
357 /* Currently only m68k, apus and m8xx need it */
358 #ifdef IDE_ARCH_ACK_INTR
359 extern int ide_irq_lock;
360 # define ide_ack_intr(hwif) (hwif->hw.ack_intr ? hwif->hw.ack_intr(hwif) : 1)
362 # define ide_ack_intr(hwif) (1)
365 /* Currently only Atari needs it */
366 #ifndef IDE_ARCH_LOCK
367 # define ide_release_lock(lock) do {} while (0)
368 # define ide_get_lock(lock, hdlr, data) do {} while (0)
369 #endif /* IDE_ARCH_LOCK */
372 * Now for the data we need to maintain per-drive: ide_drive_t
375 #define ide_scsi 0x21
376 #define ide_disk 0x20
377 #define ide_optical 0x7
378 #define ide_cdrom 0x5
380 #define ide_floppy 0x0
383 * Special Driver Flags
385 * set_geometry : respecify drive geometry
386 * recalibrate : seek to cyl 0
387 * set_multmode : set multmode count
388 * set_tune : tune interface for drive
389 * serviced : service command
395 #if defined(__LITTLE_ENDIAN_BITFIELD)
396 unsigned set_geometry : 1;
397 unsigned recalibrate : 1;
398 unsigned set_multmode : 1;
399 unsigned set_tune : 1;
400 unsigned serviced : 1;
401 unsigned reserved : 3;
402 #elif defined(__BIG_ENDIAN_BITFIELD)
403 unsigned reserved : 3;
404 unsigned serviced : 1;
405 unsigned set_tune : 1;
406 unsigned set_multmode : 1;
407 unsigned recalibrate : 1;
408 unsigned set_geometry : 1;
410 #error "Please fix <asm/byteorder.h>"
416 * ATA DATA Register Special.
417 * ATA NSECTOR Count Register().
418 * ATAPI Byte Count Register.
419 * Channel index ordering pairs.
424 #if defined(__LITTLE_ENDIAN_BITFIELD)
425 unsigned low :8; /* LSB */
426 unsigned high :8; /* MSB */
427 #elif defined(__BIG_ENDIAN_BITFIELD)
428 unsigned high :8; /* MSB */
429 unsigned low :8; /* LSB */
431 #error "Please fix <asm/byteorder.h>"
434 } ata_nsector_t, ata_data_t, atapi_bcount_t, ata_index_t;
437 * ATA-IDE Error Register
439 * mark : Bad address mark
440 * tzero : Couldn't find track 0
441 * abrt : Aborted Command
442 * mcr : Media Change Request
443 * id : ID field not found
444 * mce : Media Change Event
445 * ecc : Uncorrectable ECC error
451 #if defined(__LITTLE_ENDIAN_BITFIELD)
460 #elif defined(__BIG_ENDIAN_BITFIELD)
470 #error "Please fix <asm/byteorder.h>"
476 * ATA-IDE Select Register, aka Device-Head
478 * head : always zeros here
479 * unit : drive select number: 0/1
481 * lba : using LBA instead of CHS
487 #if defined(__LITTLE_ENDIAN_BITFIELD)
493 #elif defined(__BIG_ENDIAN_BITFIELD)
500 #error "Please fix <asm/byteorder.h>"
503 } select_t, ata_select_t;
506 * The ATA-IDE Status Register.
507 * The ATAPI Status Register.
509 * check : Error occurred
511 * corr : Correctable error occurred
512 * drq : Data is request by the device
513 * dsc : Disk Seek Complete : ata
514 * : Media access command finished : atapi
515 * df : Device Fault : ata
517 * drdy : Ready, Command Mode Capable : ata
518 * : Ignored for ATAPI commands : atapi
520 * : The device has access to the command block
525 #if defined(__LITTLE_ENDIAN_BITFIELD)
534 #elif defined(__BIG_ENDIAN_BITFIELD)
544 #error "Please fix <asm/byteorder.h>"
547 } ata_status_t, atapi_status_t;
550 * ATA-IDE Control Register
552 * bit0 : Should be set to zero
553 * nIEN : device INTRQ to host
554 * SRST : host soft reset bit
555 * bit3 : ATA-2 thingy, Should be set to 1
556 * reserved456 : Reserved
557 * HOB : 48-bit address ordering, High Ordered Bit
562 #if defined(__LITTLE_ENDIAN_BITFIELD)
567 unsigned reserved456 : 3;
569 #elif defined(__BIG_ENDIAN_BITFIELD)
571 unsigned reserved456 : 3;
577 #error "Please fix <asm/byteorder.h>"
583 * ATAPI Feature Register
585 * dma : Using DMA or PIO
586 * reserved321 : Reserved
587 * reserved654 : Reserved (Tag Type)
588 * reserved7 : Reserved
593 #if defined(__LITTLE_ENDIAN_BITFIELD)
595 unsigned reserved321 :3;
596 unsigned reserved654 :3;
597 unsigned reserved7 :1;
598 #elif defined(__BIG_ENDIAN_BITFIELD)
599 unsigned reserved7 :1;
600 unsigned reserved654 :3;
601 unsigned reserved321 :3;
604 #error "Please fix <asm/byteorder.h>"
610 * ATAPI Interrupt Reason Register.
612 * cod : Information transferred is command (1) or data (0)
613 * io : The device requests us to read (1) or write (0)
614 * reserved : Reserved
619 #if defined(__LITTLE_ENDIAN_BITFIELD)
622 unsigned reserved :6;
623 #elif defined(__BIG_ENDIAN_BITFIELD)
624 unsigned reserved :6;
628 #error "Please fix <asm/byteorder.h>"
634 * The ATAPI error register.
636 * ili : Illegal Length Indication
637 * eom : End Of Media Detected
638 * abrt : Aborted command - As defined by ATA
639 * mcr : Media Change Requested - As defined by ATA
640 * sense_key : Sense key of the last failed packet command
645 #if defined(__LITTLE_ENDIAN_BITFIELD)
650 unsigned sense_key :4;
651 #elif defined(__BIG_ENDIAN_BITFIELD)
652 unsigned sense_key :4;
658 #error "Please fix <asm/byteorder.h>"
664 * ATAPI floppy Drive Select Register
666 * sam_lun : Logical unit number
667 * reserved3 : Reserved
668 * drv : The responding drive will be drive 0 (0) or drive 1 (1)
669 * one5 : Should be set to 1
670 * reserved6 : Reserved
671 * one7 : Should be set to 1
676 #if defined(__LITTLE_ENDIAN_BITFIELD)
678 unsigned reserved3 :1;
681 unsigned reserved6 :1;
683 #elif defined(__BIG_ENDIAN_BITFIELD)
685 unsigned reserved6 :1;
688 unsigned reserved3 :1;
691 #error "Please fix <asm/byteorder.h>"
697 struct ide_settings_s;
699 typedef struct ide_drive_s {
700 char name[4]; /* drive name, such as "hda" */
701 char driver_req[10]; /* requests specific driver */
703 request_queue_t queue; /* request queue */
705 wait_queue_head_t wqueue; /* used to wait for drive in open() */
706 struct request *rq; /* current request */
707 struct ide_drive_s *next; /* circular list of hwgroup drives */
708 struct ide_driver_s *driver;/* (ide_driver_t *) */
709 void *driver_data; /* extra driver data */
710 struct hd_driveid *id; /* drive model identification info */
711 struct hd_struct *part; /* drive partition table */
712 struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
713 struct ide_settings_s *settings;/* /proc/ide/ drive settings */
714 devfs_handle_t de; /* directory for device */
716 struct hwif_s *hwif; /* actually (ide_hwif_t *) */
718 unsigned long sleep; /* sleep until this time */
719 unsigned long service_start; /* time we started last request */
720 unsigned long service_time; /* service time of last request */
721 unsigned long timeout; /* max time to wait for irq */
723 special_t special; /* special action flags */
724 select_t select; /* basic drive/head select reg value */
726 u8 keep_settings; /* restore settings after drive reset */
727 u8 autodma; /* device can safely use dma on host */
728 u8 using_dma; /* disk is using dma for read/write */
729 u8 using_tcq; /* disk is using queueing */
730 u8 retry_pio; /* retrying dma capable host in pio */
731 u8 state; /* retry state */
732 u8 waiting_for_dma; /* dma currently in progress */
733 u8 unmask; /* okay to unmask other irqs */
734 u8 slow; /* slow data port */
735 u8 bswap; /* byte swap data */
736 u8 dsc_overlap; /* DSC overlap */
737 u8 nice1; /* give potential excess bandwidth */
739 unsigned present : 1; /* drive is physically present */
740 unsigned noprobe : 1; /* from: hdx=noprobe */
741 unsigned busy : 1; /* currently doing revalidate_disk() */
742 unsigned removable : 1; /* 1 if need to do check_media_change */
743 unsigned is_flash : 1; /* 1 if probed as flash */
744 unsigned forced_geom : 1; /* 1 if hdx=c,h,s was given at boot */
745 unsigned no_unmask : 1; /* disallow setting unmask bit */
746 unsigned no_io_32bit : 1; /* disallow enabling 32bit I/O */
747 unsigned nobios : 1; /* do not probe bios for drive */
748 unsigned revalidate : 1; /* request revalidation */
749 unsigned atapi_overlap : 1; /* ATAPI overlap (not supported) */
750 unsigned nice0 : 1; /* give obvious excess bandwidth */
751 unsigned nice2 : 1; /* give a share in our own bandwidth */
752 unsigned doorlocking : 1; /* for removable only: door lock/unlock works */
753 unsigned autotune : 2; /* 1=autotune, 2=noautotune, 0=default */
754 unsigned remap_0_to_1 : 2; /* 0=remap if ezdrive, 1=remap, 2=noremap */
755 unsigned ata_flash : 1; /* 1=present, 0=default */
756 unsigned dead : 1; /* 1=dead, no new attachments */
757 unsigned addressing; /* : 3;
760 * 2=48-bit doing 28-bit
764 u8 scsi; /* 0=default, 1=skip current ide-subdriver for ide-scsi emulation */
765 u8 quirk_list; /* considered quirky, set for a specific host */
766 u8 suspend_reset; /* drive suspend mode flag, soft-reset recovers */
767 u8 init_speed; /* transfer rate set at boot */
768 u8 pio_speed; /* unused by core, used by some drivers for fallback from DMA */
769 u8 current_speed; /* current transfer rate set */
770 u8 dn; /* now wide spread use */
771 u8 wcache; /* status of write cache */
772 u8 acoustic; /* acoustic management */
773 u8 media; /* disk, cdrom, tape, floppy, ... */
774 u8 ctl; /* "normal" value for IDE_CONTROL_REG */
775 u8 ready_stat; /* min status value for drive ready */
776 u8 mult_count; /* current multiple sector setting */
777 u8 mult_req; /* requested multiple sector setting */
778 u8 tune_req; /* requested drive tuning setting */
779 u8 io_32bit; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
780 u8 bad_wstat; /* used for ignoring WRERR_STAT */
781 u8 nowerr; /* used for ignoring WRERR_STAT */
782 u8 sect0; /* offset of first sector for DM6:DDO */
783 u8 head; /* "real" number of heads */
784 u8 sect; /* "real" sectors per track */
785 u8 bios_head; /* BIOS/fdisk/LILO number of heads */
786 u8 bios_sect; /* BIOS/fdisk/LILO sectors per track */
788 unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */
789 unsigned int cyl; /* "real" number of cyls */
790 unsigned int drive_data; /* use by tuneproc/selectproc */
791 unsigned int usage; /* current "open()" count for drive */
792 unsigned int failures; /* current failure count */
793 unsigned int max_failures; /* maximum allowed failure count */
795 u32 capacity; /* total number of sectors */
796 u64 capacity48; /* total number of sectors */
798 int last_lun; /* last logical unit */
799 int forced_lun; /* if hdxlun was given at boot */
800 int lun; /* logical unit */
801 int crc_count; /* crc counter to reduce drive speed */
804 typedef struct ide_pio_ops_s {
805 void (*ata_input_data)(ide_drive_t *, void *, u32);
806 void (*ata_output_data)(ide_drive_t *, void *, u32);
808 void (*atapi_input_bytes)(ide_drive_t *, void *, u32);
809 void (*atapi_output_bytes)(ide_drive_t *, void *, u32);
812 typedef struct ide_dma_ops_s {
813 /* insert dma operations here! */
814 int (*ide_dma_read)(ide_drive_t *drive);
815 int (*ide_dma_write)(ide_drive_t *drive);
816 int (*ide_dma_begin)(ide_drive_t *drive);
817 int (*ide_dma_end)(ide_drive_t *drive);
818 int (*ide_dma_check)(ide_drive_t *drive);
819 int (*ide_dma_on)(ide_drive_t *drive);
820 int (*ide_dma_off)(ide_drive_t *drive);
821 int (*ide_dma_off_quietly)(ide_drive_t *drive);
822 int (*ide_dma_test_irq)(ide_drive_t *drive);
823 int (*ide_dma_host_on)(ide_drive_t *drive);
824 int (*ide_dma_host_off)(ide_drive_t *drive);
825 int (*ide_dma_bad_drive)(ide_drive_t *drive);
826 int (*ide_dma_good_drive)(ide_drive_t *drive);
827 int (*ide_dma_count)(ide_drive_t *drive);
828 int (*ide_dma_verbose)(ide_drive_t *drive);
829 int (*ide_dma_retune)(ide_drive_t *drive);
830 int (*ide_dma_lostirq)(ide_drive_t *drive);
831 int (*ide_dma_timeout)(ide_drive_t *drive);
835 * mapping stuff, prepare for highmem...
837 * temporarily mapping a (possible) highmem bio for PIO transfer
839 #define ide_rq_offset(rq) \
840 (((rq)->hard_cur_sectors - (rq)->current_nr_sectors) << 9)
842 extern inline void *ide_map_buffer(struct request *rq, unsigned long *flags)
844 return bh_kmap_irq(rq->bh, flags) + ide_rq_offset(rq);
847 extern inline void ide_unmap_buffer(char *buffer, unsigned long *flags)
849 bh_kunmap_irq(buffer, flags);
852 #define IDE_CHIPSET_PCI_MASK \
853 ((1<<ide_pci)|(1<<ide_cmd646)|(1<<ide_ali14xx))
854 #define IDE_CHIPSET_IS_PCI(c) ((IDE_CHIPSET_PCI_MASK >> (c)) & 1)
856 struct ide_pci_device_s;
858 typedef struct hwif_s {
859 struct hwif_s *next; /* for linked-list in ide_hwgroup_t */
860 struct hwif_s *mate; /* other hwif from same PCI chip */
861 struct hwgroup_s *hwgroup; /* actually (ide_hwgroup_t *) */
862 struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
863 struct gendisk *gd; /* gendisk structure */
865 char name[6]; /* name of interface, eg. "ide0" */
867 /* task file registers for pata and sata */
868 ide_ioreg_t io_ports[IDE_NR_PORTS];
869 sata_ioreg_t sata_scr[SATA_NR_PORTS];
870 sata_ioreg_t sata_misc[SATA_NR_PORTS];
872 hw_regs_t hw; /* Hardware info */
873 ide_drive_t drives[MAX_DRIVES]; /* drive info */
875 u8 major; /* our major number */
876 u8 index; /* 0 for ide0; 1 for ide1; ... */
877 u8 channel; /* for dual-port chips: 0=primary, 1=secondary */
878 u8 straight8; /* Alan's straight 8 check */
879 u8 bus_state; /* power state of the IDE bus */
881 u8 atapi_dma; /* host supports atapi_dma */
886 hwif_chipset_t chipset; /* sub-module for tuning.. */
888 struct pci_dev *pci_dev; /* for pci chipsets */
889 struct ide_pci_device_s *cds; /* chipset device struct */
892 ide_hwif_ops_t *hwifops;
894 /* routine is for HBA specific IDENTITY operations */
895 int (*identify)(ide_drive_t *);
896 /* routine to tune PIO mode for drives */
897 void (*tuneproc)(ide_drive_t *, u8);
898 /* routine to retune DMA modes for drives */
899 int (*speedproc)(ide_drive_t *, u8);
900 /* tweaks hardware to select drive */
901 void (*selectproc)(ide_drive_t *);
902 /* chipset polling based on hba specifics */
903 int (*reset_poll)(ide_drive_t *);
904 /* chipset specific changes to default for device-hba resets */
905 void (*pre_reset)(ide_drive_t *);
906 /* routine to reset controller after a disk reset */
907 void (*resetproc)(ide_drive_t *);
908 /* special interrupt handling for shared pci interrupts */
909 void (*intrproc)(ide_drive_t *);
910 /* special host masking for drive selection */
911 void (*maskproc)(ide_drive_t *, int);
912 /* check host's drive quirk list */
913 int (*quirkproc)(ide_drive_t *);
914 /* driver soft-power interface */
915 int (*busproc)(ide_drive_t *, int);
916 // /* host rate limiter */
917 // u8 (*ratemask)(ide_drive_t *);
918 // /* device rate limiter */
919 // u8 (*ratefilter)(ide_drive_t *, u8);
923 ide_pio_ops_t *pioops;
925 void (*ata_input_data)(ide_drive_t *, void *, u32);
926 void (*ata_output_data)(ide_drive_t *, void *, u32);
928 void (*atapi_input_bytes)(ide_drive_t *, void *, u32);
929 void (*atapi_output_bytes)(ide_drive_t *, void *, u32);
933 ide_dma_ops_t *dmaops;
935 int (*ide_dma_read)(ide_drive_t *drive);
936 int (*ide_dma_write)(ide_drive_t *drive);
937 int (*ide_dma_begin)(ide_drive_t *drive);
938 int (*ide_dma_end)(ide_drive_t *drive);
939 int (*ide_dma_check)(ide_drive_t *drive);
940 int (*ide_dma_on)(ide_drive_t *drive);
941 int (*ide_dma_off)(ide_drive_t *drive);
942 int (*ide_dma_off_quietly)(ide_drive_t *drive);
943 int (*ide_dma_test_irq)(ide_drive_t *drive);
944 int (*ide_dma_host_on)(ide_drive_t *drive);
945 int (*ide_dma_host_off)(ide_drive_t *drive);
946 int (*ide_dma_bad_drive)(ide_drive_t *drive);
947 int (*ide_dma_good_drive)(ide_drive_t *drive);
948 int (*ide_dma_count)(ide_drive_t *drive);
949 int (*ide_dma_verbose)(ide_drive_t *drive);
950 int (*ide_dma_retune)(ide_drive_t *drive);
951 int (*ide_dma_lostirq)(ide_drive_t *drive);
952 int (*ide_dma_timeout)(ide_drive_t *drive);
958 void (*OUTB)(u8 addr, unsigned long port);
959 void (*OUTW)(u16 addr, unsigned long port);
960 void (*OUTL)(u32 addr, unsigned long port);
961 void (*OUTSW)(unsigned long port, void *addr, u32 count);
962 void (*OUTSL)(unsigned long port, void *addr, u32 count);
964 u8 (*INB)(unsigned long port);
965 u16 (*INW)(unsigned long port);
966 u32 (*INL)(unsigned long port);
967 void (*INSW)(unsigned long port, void *addr, u32 count);
968 void (*INSL)(unsigned long port, void *addr, u32 count);
971 /* dma physical region descriptor table (cpu view) */
972 unsigned int *dmatable_cpu;
973 /* dma physical region descriptor table (dma view) */
974 dma_addr_t dmatable_dma;
975 /* Scatter-gather list used to build the above */
976 struct scatterlist *sg_table;
977 int sg_nents; /* Current number of entries in it */
978 int sg_dma_direction; /* dma transfer direction */
979 int sg_dma_active; /* is it in use */
981 int mmio; /* hosts iomio (0), mmio (1) or custom (2) select */
982 int rqsize; /* max sectors per request */
983 int addressing; /* hosts addressing */
984 int irq; /* our irq number */
985 int initializing; /* set while initializing self */
987 unsigned long dma_master; /* reference base addr dmabase */
988 unsigned long dma_base; /* base addr for dma ports */
989 unsigned long dma_command; /* dma command register */
990 unsigned long dma_vendor1; /* dma vendor 1 register */
991 unsigned long dma_status; /* dma status register */
992 unsigned long dma_vendor3; /* dma vendor 3 register */
993 unsigned long dma_prdtable; /* actual prd table address */
994 unsigned long dma_base2; /* extended base addr for dma ports */
996 unsigned dma_extra; /* extra addr for dma ports */
997 unsigned long config_data; /* for use by chipset-specific code */
998 unsigned long select_data; /* for use by chipset-specific code */
999 #if (DISK_RECOVERY_TIME > 0)
1000 unsigned long last_time; /* time when previous rq was done */
1004 unsigned noprobe : 1; /* don't probe for this interface */
1005 unsigned present : 1; /* this interface exists */
1006 unsigned serialized : 1; /* serialized all channel operation */
1007 unsigned sharing_irq: 1; /* 1 = sharing irq with another hwif */
1008 unsigned reset : 1; /* reset after probe */
1009 unsigned autodma : 1; /* auto-attempt using DMA at boot */
1010 unsigned udma_four : 1; /* 1=ATA-66 capable, 0=default */
1011 unsigned highmem : 1; /* can do full 32-bit dma */
1012 unsigned no_dsc : 1; /* 0 default, 1 dsc_overlap disabled */
1014 void *hwif_data; /* extra hwif data */
1018 * Status returned from various ide_ functions
1021 ide_stopped, /* no drive operation was started */
1022 ide_started /* a drive operation was started, handler was set */
1026 * internal ide interrupt handler type
1028 typedef ide_startstop_t (ide_pre_handler_t)(ide_drive_t *, struct request *);
1029 typedef ide_startstop_t (ide_handler_t)(ide_drive_t *);
1030 typedef ide_startstop_t (ide_post_handler_t)(ide_drive_t *);
1031 typedef int (ide_expiry_t)(ide_drive_t *);
1033 typedef struct hwgroup_s {
1034 /* irq handler, if active */
1035 ide_startstop_t (*handler)(ide_drive_t *);
1036 /* irq handler, suspended if active */
1037 ide_startstop_t (*handler_save)(ide_drive_t *);
1038 /* BOOL: protects all fields below */
1040 /* BOOL: wake us up on timer expiry */
1044 /* ptr to current hwif in linked-list */
1047 /* for pci chipsets */
1048 struct pci_dev *pci_dev;
1049 /* chipset device struct */
1050 struct ide_pci_device_s *cds;
1052 /* current request */
1054 /* failsafe timer */
1055 struct timer_list timer;
1056 /* local copy of current write rq */
1058 /* timeout value during long polls */
1059 unsigned long poll_timeout;
1060 /* queried upon timeouts */
1061 int (*expiry)(ide_drive_t *);
1062 /* ide_system_bus_speed */
1066 /* structure attached to the request for IDE_TASK_CMDS */
1069 * configurable drive settings
1075 #define TYPE_SHORT 3
1077 #define SETTING_READ (1 << 0)
1078 #define SETTING_WRITE (1 << 1)
1079 #define SETTING_RW (SETTING_READ | SETTING_WRITE)
1081 typedef int (ide_procset_t)(ide_drive_t *, int);
1082 typedef struct ide_settings_s {
1095 struct ide_settings_s *next;
1098 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);
1099 void ide_remove_setting(ide_drive_t *drive, char *name);
1100 ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name);
1101 int ide_read_setting(ide_drive_t *t, ide_settings_t *setting);
1102 int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int val);
1103 void ide_add_generic_settings(ide_drive_t *drive);
1106 * /proc/ide interface
1111 read_proc_t *read_proc;
1112 write_proc_t *write_proc;
1115 #ifdef CONFIG_PROC_FS
1116 extern void proc_ide_create(void);
1117 extern void proc_ide_destroy(void);
1118 extern void recreate_proc_ide_device(ide_hwif_t *, ide_drive_t *);
1119 extern void destroy_proc_ide_device(ide_hwif_t *, ide_drive_t *);
1120 extern void destroy_proc_ide_drives(ide_hwif_t *);
1121 extern void create_proc_ide_interfaces(void);
1122 extern void ide_add_proc_entries(struct proc_dir_entry *, ide_proc_entry_t *, void *);
1123 extern void ide_remove_proc_entries(struct proc_dir_entry *, ide_proc_entry_t *);
1124 read_proc_t proc_ide_read_capacity;
1125 read_proc_t proc_ide_read_geometry;
1128 * Standard exit stuff:
1130 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \
1133 if (len < count) { \
1139 *start = page + off; \
1143 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
1147 * Subdrivers support.
1149 #define IDE_SUBDRIVER_VERSION 1
1151 typedef struct ide_driver_s {
1153 const char *version;
1156 unsigned supports_dma : 1;
1157 unsigned supports_dsc_overlap : 1;
1158 int (*cleanup)(ide_drive_t *);
1159 int (*shutdown)(ide_drive_t *);
1160 int (*standby)(ide_drive_t *);
1161 int (*suspend)(ide_drive_t *);
1162 int (*resume)(ide_drive_t *);
1163 int (*flushcache)(ide_drive_t *);
1164 ide_startstop_t (*do_request)(ide_drive_t *, struct request *, unsigned long);
1165 int (*end_request)(ide_drive_t *, int);
1166 u8 (*sense)(ide_drive_t *, const char *, u8);
1167 ide_startstop_t (*error)(ide_drive_t *, const char *, u8);
1168 int (*ioctl)(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
1169 int (*open)(struct inode *, struct file *, ide_drive_t *);
1170 void (*release)(struct inode *, struct file *, ide_drive_t *);
1171 int (*media_change)(ide_drive_t *);
1172 void (*revalidate)(ide_drive_t *);
1173 void (*pre_reset)(ide_drive_t *);
1174 unsigned long (*capacity)(ide_drive_t *);
1175 ide_startstop_t (*special)(ide_drive_t *);
1176 ide_proc_entry_t *proc;
1178 int (*attach)(ide_drive_t *);
1179 void (*ata_prebuilder)(ide_drive_t *);
1180 void (*atapi_prebuilder)(ide_drive_t *);
1183 #define DRIVER(drive) ((drive)->driver)
1188 #define IDE_CHIPSET_MODULE 0 /* not supported yet */
1189 #define IDE_PROBE_MODULE 1
1190 #define IDE_DRIVER_MODULE 2
1192 typedef int (ide_module_init_proc)(void);
1194 typedef struct ide_module_s {
1196 ide_module_init_proc *init;
1198 struct ide_module_s *next;
1201 typedef struct ide_devices_s {
1202 char name[4]; /* hdX */
1203 unsigned attached : 1; /* native */
1204 unsigned alttached : 1; /* alternate */
1205 struct ide_devices_s *next;
1210 IDE_MEDIA_FLOPPY = ide_floppy,
1211 IDE_MEDIA_TAPE = ide_tape,
1212 IDE_MEDIA_CDROM = ide_cdrom,
1213 IDE_MEDIA_OPTICAL = ide_optical,
1214 IDE_MEDIA_DISK = ide_disk,
1215 IDE_MEDIA_SCSI = ide_scsi,
1219 ide_media_type type;
1221 atomic_t refcount; /* Maybe this should be a struct module*
1222 with MOD_INC instead */
1223 struct list_head devices;
1227 struct ide_media floppy;
1228 struct ide_media tape;
1229 struct ide_media cdrom;
1230 struct ide_media optical;
1231 struct ide_media disk;
1232 struct ide_media scsi;
1235 void __init init_media(void)
1237 memset(&ide_medias, 0, sizeof(ide_medias));
1239 ide_medias.floppy.type = IDE_MEDIA_FLOPPY;
1240 ide_medias.tape.type = IDE_MEDIA_TAPE;
1241 ide_medias.cdrom.type = IDE_MEDIA_CDROM;
1242 ide_medias.optical.type = IDE_MEDIA_OPTICAL;
1243 ide_medias.disk.type = IDE_MEDIA_DISK;
1244 ide_medias.scsi.type = IDE_MEDIA_SCSI;
1249 * ide_hwifs[] is the master data structure used to keep track
1250 * of just about everything in ide.c. Whenever possible, routines
1251 * should be using pointers to a drive (ide_drive_t *) or
1252 * pointers to a hwif (ide_hwif_t *), rather than indexing this
1253 * structure directly (the allocation/layout may change!).
1257 extern ide_hwif_t ide_hwifs[]; /* master data repository */
1258 extern ide_module_t *ide_chipsets;
1259 extern ide_module_t *ide_modules;
1260 extern ide_module_t *ide_probe;
1262 extern ide_devices_t *idedisk;
1263 extern ide_devices_t *idecd;
1264 extern ide_devices_t *idefloppy;
1265 extern ide_devices_t *idetape;
1266 extern ide_devices_t *idescsi;
1269 extern int noautodma;
1272 * We need blk.h, but we replace its end_request by our own version.
1274 #define IDE_DRIVER /* Toggle some magic bits in blk.h */
1275 #define LOCAL_END_REQUEST /* Don't generate end_request in blk.h */
1276 //#define DEVICE_NR(device) (MINOR(device) >> PARTN_BITS)
1277 #include <linux/blk.h>
1279 extern int ide_end_request(ide_drive_t *, int /* uptodate */);
1282 * This is used on exit from the driver, to designate the next irq handler
1283 * and also to start the safety timer.
1285 extern void ide_set_handler(ide_drive_t *, ide_handler_t *, unsigned int, ide_expiry_t *);
1288 * Error reporting, in human readable form (luxurious, but a memory hog).
1290 * (drive, msg, status)
1292 extern u8 ide_dump_status(ide_drive_t *, const char *, u8);
1295 * ide_error() takes action based on the error returned by the controller.
1296 * The caller should return immediately after invoking this.
1298 * (drive, msg, status)
1300 extern ide_startstop_t ide_error(ide_drive_t *, const char *, u8);
1303 * Issue a simple drive command
1304 * The drive must be selected beforehand.
1306 * (drive, command, nsector, handler)
1308 extern void ide_cmd(ide_drive_t *, u8, u8, ide_handler_t *);
1310 extern void ide_fix_driveid(struct hd_driveid *);
1312 * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
1313 * removing leading/trailing blanks and compressing internal blanks.
1314 * It is primarily used to tidy up the model name/number fields as
1315 * returned by the WIN_[P]IDENTIFY commands.
1317 * (s, bytecount, byteswap)
1319 extern void ide_fixstring(u8 *, const int, const int);
1322 * This routine busy-waits for the drive status to be not "busy".
1323 * It then checks the status for all of the "good" bits and none
1324 * of the "bad" bits, and if all is okay it returns 0. All other
1325 * cases return 1 after doing "*startstop = ide_error()", and the
1326 * caller should return the updated value of "startstop" in this case.
1327 * "startstop" is unchanged when the function returns 0;
1328 * (startstop, drive, good, bad, timeout)
1330 extern int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long);
1333 * This routine is called from the partition-table code in genhd.c
1334 * to "convert" a drive to a logical geometry with fewer than 1024 cyls.
1336 extern int ide_xlate_1024(kdev_t, int, int, const char *);
1339 * Convert kdev_t structure into ide_drive_t * one.
1341 extern ide_drive_t *get_info_ptr(kdev_t i_rdev);
1344 * Return the current idea about the total capacity of this drive.
1346 extern unsigned long current_capacity(ide_drive_t *);
1348 extern void ide_revalidate_drive(ide_drive_t *);
1351 * Start a reset operation for an IDE interface.
1352 * The caller should return immediately after invoking this.
1354 extern ide_startstop_t ide_do_reset(ide_drive_t *);
1357 * Re-Start an operation for an IDE interface.
1358 * The caller should return immediately after invoking this.
1360 extern int restart_request(ide_drive_t *, struct request *);
1363 * This function is intended to be used prior to invoking ide_do_drive_cmd().
1365 extern void ide_init_drive_cmd(struct request *);
1368 * "action" parameter type for ide_do_drive_cmd() below.
1371 ide_wait, /* insert rq at end of list, and wait for it */
1372 ide_next, /* insert rq immediately after current request */
1373 ide_preempt, /* insert rq in front of current request */
1374 ide_end /* insert rq at end of list, but don't wait for it */
1378 * This function issues a special IDE device request
1379 * onto the request queue.
1381 * If action is ide_wait, then the rq is queued at the end of the
1382 * request queue, and the function sleeps until it has been processed.
1383 * This is for use when invoked from an ioctl handler.
1385 * If action is ide_preempt, then the rq is queued at the head of
1386 * the request queue, displacing the currently-being-processed
1387 * request and this function returns immediately without waiting
1388 * for the new rq to be completed. This is VERY DANGEROUS, and is
1389 * intended for careful use by the ATAPI tape/cdrom driver code.
1391 * If action is ide_next, then the rq is queued immediately after
1392 * the currently-being-processed-request (if any), and the function
1393 * returns without waiting for the new rq to be completed. As above,
1394 * This is VERY DANGEROUS, and is intended for careful use by the
1395 * ATAPI tape/cdrom driver code.
1397 * If action is ide_end, then the rq is queued at the end of the
1398 * request queue, and the function returns immediately without waiting
1399 * for the new rq to be completed. This is again intended for careful
1400 * use by the ATAPI tape/cdrom driver code.
1402 extern int ide_do_drive_cmd(ide_drive_t *, struct request *, ide_action_t);
1405 * Clean up after success/failure of an explicit drive cmd.
1406 * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_CMD).
1407 * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_TASK_MASK).
1409 * (ide_drive_t *drive, u8 stat, u8 err)
1411 extern void ide_end_drive_cmd(ide_drive_t *, u8, u8);
1414 * Issue ATA command and wait for completion.
1415 * Use for implementing commands in kernel
1417 * (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
1419 extern int ide_wait_cmd(ide_drive_t *, u8, u8, u8, u8, u8 *);
1421 /* (ide_drive_t *drive, u8 *buf) */
1422 extern int ide_wait_cmd_task(ide_drive_t *, u8 *);
1424 typedef struct ide_task_s {
1426 * struct hd_drive_task_hdr tf;
1428 * struct hd_drive_hob_hdr hobf;
1429 * hob_struct_t hobf;
1431 task_ioreg_t tfRegister[8];
1432 task_ioreg_t hobRegister[8];
1433 ide_reg_valid_t tf_out_flags;
1434 ide_reg_valid_t tf_in_flags;
1437 ide_pre_handler_t *prehandler;
1438 ide_handler_t *handler;
1439 ide_post_handler_t *posthandler;
1440 struct request *rq; /* copy of request */
1441 void *special; /* valid_t generally */
1444 typedef struct pkt_task_s {
1446 * struct hd_drive_task_hdr pktf;
1447 * task_struct_t pktf;
1450 task_ioreg_t tfRegister[8];
1453 ide_handler_t *handler;
1454 struct request *rq; /* copy of request */
1458 extern inline void SELECT_DRIVE(ide_drive_t *);
1459 extern inline void SELECT_INTERRUPT(ide_drive_t *);
1460 extern inline void SELECT_MASK(ide_drive_t *, int);
1461 extern inline void QUIRK_LIST(ide_drive_t *);
1463 extern void ata_input_data(ide_drive_t *, void *, u32);
1464 extern void ata_output_data(ide_drive_t *, void *, u32);
1465 extern void atapi_input_bytes(ide_drive_t *, void *, u32);
1466 extern void atapi_output_bytes(ide_drive_t *, void *, u32);
1467 extern void taskfile_input_data(ide_drive_t *, void *, u32);
1468 extern void taskfile_output_data(ide_drive_t *, void *, u32);
1470 extern int drive_is_ready(ide_drive_t *);
1471 extern int wait_for_ready(ide_drive_t *, int /* timeout */);
1474 * taskfile io for disks for now...and builds request from ide_ioctl
1476 extern ide_startstop_t do_rw_taskfile(ide_drive_t *, ide_task_t *);
1478 /* (ide_drive_t *drive, u8 stat, u8 err) */
1479 extern void ide_end_taskfile(ide_drive_t *, u8, u8);
1482 * Special Flagged Register Validation Caller
1484 extern ide_startstop_t flagged_taskfile(ide_drive_t *, ide_task_t *);
1486 extern ide_startstop_t set_multmode_intr(ide_drive_t *);
1487 extern ide_startstop_t set_geometry_intr(ide_drive_t *);
1488 extern ide_startstop_t recal_intr(ide_drive_t *);
1489 extern ide_startstop_t task_no_data_intr(ide_drive_t *);
1490 extern ide_startstop_t task_in_intr(ide_drive_t *);
1491 extern ide_startstop_t task_mulin_intr(ide_drive_t *);
1492 extern ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *);
1493 extern ide_startstop_t task_out_intr(ide_drive_t *);
1494 extern ide_startstop_t pre_task_mulout_intr(ide_drive_t *, struct request *);
1495 extern ide_startstop_t task_mulout_intr(ide_drive_t *);
1496 extern void ide_init_drive_taskfile(struct request *);
1498 extern int ide_raw_taskfile(ide_drive_t *, ide_task_t *, u8 *);
1500 extern ide_pre_handler_t * ide_pre_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1502 extern ide_handler_t * ide_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1504 extern ide_post_handler_t * ide_post_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1506 /* Expects args is a full set of TF registers and parses the command type */
1507 extern int ide_cmd_type_parser(ide_task_t *);
1509 int ide_taskfile_ioctl(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
1510 int ide_cmd_ioctl(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
1511 int ide_task_ioctl(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
1515 #define IDEFLOPPY_PC_BUFFER_SIZE 256
1516 #define IDETAPE_PC_BUFFER_SIZE 256
1517 #define IDE_PC_BUFFER_SIZE 256
1519 typedef struct ide_packet_command_s {
1520 /* Actual packet bytes */
1522 /* On each retry, we increment retries */
1526 /* Bytes to transfer */
1527 int request_transfer;
1528 /* Bytes actually transferred */
1529 int actually_transferred;
1530 /* Size of our data buffer */
1533 struct buffer_head *bh;
1535 /* The corresponding request */
1538 /* Scatter gather table */
1539 struct scatterlist *sg;
1544 /* Pointer into the above buffer */
1545 u8 *current_position;
1546 /* Called when this packet command is completed */
1547 ide_startstop_t (*callback) (ide_drive_t *);
1548 /* Temporary buffer */
1549 u8 pc_buffer[IDE_PC_BUFFER_SIZE];
1550 /* Status/Action bit flags: long for set_bit */
1551 unsigned long flags;
1554 ide-cd orthoginal :-/
1555 struct packet_command {
1561 struct request_sense *sense;
1562 unsigned char c[12];
1567 #ifdef CONFIG_PKT_TASK_IOCTL
1568 extern int pkt_taskfile_ioctl(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
1569 #endif /* CONFIG_PKT_TASK_IOCTL */
1571 extern void ide_delay_50ms(void);
1572 extern int system_bus_clock(void);
1574 extern u8 ide_auto_reduce_xfer(ide_drive_t *);
1575 extern int ide_driveid_update(ide_drive_t *);
1576 extern int ide_ata66_check(ide_drive_t *, ide_task_t *);
1577 extern int ide_config_drive_speed(ide_drive_t *, u8);
1578 extern u8 eighty_ninty_three (ide_drive_t *);
1579 extern int set_transfer(ide_drive_t *, ide_task_t *);
1580 extern int taskfile_lib_get_identify(ide_drive_t *drive, u8 *);
1583 * ide_system_bus_speed() returns what we think is the system VESA/PCI
1584 * bus speed (in MHz). This is used for calculating interface PIO timings.
1585 * The default is 40 for known PCI systems, 50 otherwise.
1586 * The "idebus=xx" parameter can be used to override this value.
1588 extern int ide_system_bus_speed(void);
1591 * ide_stall_queue() can be used by a drive to give excess bandwidth back
1592 * to the hwgroup by sleeping for timeout jiffies.
1594 extern void ide_stall_queue(ide_drive_t *, unsigned long);
1597 * ide_get_queue() returns the queue which corresponds to a given device.
1599 extern request_queue_t *ide_get_queue(kdev_t dev);
1602 * CompactFlash cards and their brethern pretend to be removable hard disks,
1603 * but they never have a slave unit, and they don't have doorlock mechanisms.
1604 * This test catches them, and is invoked elsewhere when setting appropriate
1607 extern int drive_is_flashcard(ide_drive_t *);
1609 extern int ide_spin_wait_hwgroup(ide_drive_t *);
1610 extern void ide_timer_expiry(unsigned long);
1611 extern void ide_intr(int irq, void *dev_id, struct pt_regs *regs);
1612 extern void do_ide_request(request_queue_t *);
1613 extern void ide_init_subdrivers(void);
1615 extern struct block_device_operations ide_fops[];
1616 extern ide_proc_entry_t generic_subdriver_entries[];
1618 extern int ide_attach_drive(ide_drive_t *);
1620 extern int ideprobe_init(void);
1621 extern int idedisk_attach(ide_drive_t *);
1622 extern int idedisk_init(void);
1623 extern int ide_cdrom_attach(ide_drive_t *);
1624 extern int ide_cdrom_init(void);
1625 extern int idetape_attach(ide_drive_t *);
1626 extern int idetape_init(void);
1627 extern int idefloppy_attach(ide_drive_t *);
1628 extern int idefloppy_init(void);
1629 extern int idescsi_attach(ide_drive_t *);
1630 extern int idescsi_init(void);
1632 extern void ide_scan_pcibus(int scan_direction) __init;
1633 extern int ide_pci_register_driver(struct pci_driver *driver);
1634 extern void ide_pci_unregister_driver(struct pci_driver *driver);
1636 extern void default_hwif_iops(ide_hwif_t *);
1637 extern void default_hwif_mmiops(ide_hwif_t *);
1638 extern void default_hwif_transport(ide_hwif_t *);
1641 extern int ide_register_module(ide_module_t *module);
1642 extern void ide_unregister_module(ide_module_t *module);
1643 extern ide_drive_t *ide_scan_devices(u8, const char *, ide_driver_t *, int);
1644 extern int ide_register_subdriver(ide_drive_t *, ide_driver_t *, int /* ver */);
1645 extern int ide_unregister_subdriver(ide_drive_t *);
1646 extern int ide_replace_subdriver(ide_drive_t *, const char * /* driver*/);
1648 #ifdef CONFIG_PROC_FS
1649 typedef struct ide_pci_host_proc_s {
1652 get_info_t *get_info;
1653 struct proc_dir_entry *parent;
1654 struct ide_pci_host_proc_s *next;
1655 } ide_pci_host_proc_t;
1657 void ide_pci_register_host_proc(ide_pci_host_proc_t *);
1658 #endif /* CONFIG_PROC_FS */
1661 #define NEVER_BOARD 0
1663 #ifdef CONFIG_BLK_DEV_OFFBOARD
1664 # define OFF_BOARD ON_BOARD
1665 #else /* CONFIG_BLK_DEV_OFFBOARD */
1666 # define OFF_BOARD NEVER_BOARD
1667 #endif /* CONFIG_BLK_DEV_OFFBOARD */
1674 typedef struct ide_pci_enablebit_s {
1675 u8 reg; /* byte pci reg holding the enable-bit */
1676 u8 mask; /* mask to isolate the enable-bit */
1677 u8 val; /* value of masked reg when "enabled" */
1678 } ide_pci_enablebit_t;
1680 typedef struct ide_pci_device_s {
1684 void (*init_setup)(struct pci_dev *, struct ide_pci_device_s *);
1685 unsigned int (*init_chipset)(struct pci_dev *, const char *);
1686 void (*init_iops)(ide_hwif_t *);
1687 void (*init_hwif)(ide_hwif_t *);
1688 void (*init_dma)(ide_hwif_t *, unsigned long);
1691 ide_pci_enablebit_t enablebits[2];
1694 struct ide_pci_device_s *next;
1697 extern void ide_setup_pci_device(struct pci_dev *, ide_pci_device_t *);
1698 extern void ide_setup_pci_devices(struct pci_dev *, struct pci_dev *, ide_pci_device_t *);
1700 #define BAD_DMA_DRIVE 0
1701 #define GOOD_DMA_DRIVE 1
1703 #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
1704 extern int ide_build_dmatable(ide_drive_t *, struct request *, int);
1705 extern void ide_destroy_dmatable(ide_drive_t *);
1706 extern ide_startstop_t ide_dma_intr(ide_drive_t *);
1707 extern int ide_release_dma(ide_hwif_t *);
1708 extern void ide_setup_dma(ide_hwif_t *, unsigned long, unsigned int);
1710 extern int __ide_dma_host_off(ide_drive_t *);
1711 extern int __ide_dma_off_quietly(ide_drive_t *);
1712 extern int __ide_dma_off(ide_drive_t *);
1713 extern int __ide_dma_host_on(ide_drive_t *);
1714 extern int __ide_dma_on(ide_drive_t *);
1715 extern int __ide_dma_check(ide_drive_t *);
1716 extern int __ide_dma_read(ide_drive_t *);
1717 extern int __ide_dma_write(ide_drive_t *);
1718 extern int __ide_dma_begin(ide_drive_t *);
1719 extern int __ide_dma_end(ide_drive_t *);
1720 extern int __ide_dma_test_irq(ide_drive_t *);
1721 extern int __ide_dma_bad_drive(ide_drive_t *);
1722 extern int __ide_dma_good_drive(ide_drive_t *);
1723 extern int __ide_dma_count(ide_drive_t *);
1724 extern int __ide_dma_verbose(ide_drive_t *);
1725 extern int __ide_dma_retune(ide_drive_t *);
1726 extern int __ide_dma_lostirq(ide_drive_t *);
1727 extern int __ide_dma_timeout(ide_drive_t *);
1729 static inline void ide_release_dma(ide_hwif_t *x) {;}
1732 extern void hwif_unregister(ide_hwif_t *);
1734 extern void export_ide_init_queue(ide_drive_t *);
1735 extern u8 export_probe_for_drive(ide_drive_t *);
1736 extern int probe_hwif_init(ide_hwif_t *);
1738 static inline void *ide_get_hwifdata (ide_hwif_t * hwif)
1740 return hwif->hwif_data;
1743 static inline void ide_set_hwifdata (ide_hwif_t * hwif, void *data)
1745 hwif->hwif_data = data;
1749 extern u8 ide_dma_speed(ide_drive_t *drive, u8 mode);
1750 extern u8 ide_rate_filter(u8 mode, u8 speed);
1751 extern int ide_dma_enable(ide_drive_t *drive);
1752 extern char *ide_xfer_verbose(u8 xfer_rate);
1753 extern void ide_toggle_bounce(ide_drive_t *drive, int on);
1754 extern int ide_set_xfer_rate(ide_drive_t *drive, u8 rate);
1756 #define ide_lock (io_request_lock)
1757 #define DRIVE_LOCK(drive) ((drive)->queue.queue_lock)