fe10ca8d3dd83eda6300a58509e33f4c5e72d718
[linux-flexiantxendom0-3.2.10.git] / include / linux / ide.h
1 #ifndef _IDE_H
2 #define _IDE_H
3 /*
4  *  linux/include/linux/ide.h
5  *
6  *  Copyright (C) 1994-2002  Linus Torvalds & authors
7  */
8
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/interrupt.h>
17 #include <linux/bitops.h>
18 #include <linux/bio.h>
19 #include <linux/device.h>
20 #include <linux/pci.h>
21 #include <asm/byteorder.h>
22 #include <asm/system.h>
23 #include <asm/hdreg.h>
24 #include <asm/io.h>
25 #include <asm/semaphore.h>
26
27 #define DEBUG_PM
28
29 /*
30  * This is the multiple IDE interface driver, as evolved from hd.c.
31  * It supports up to four IDE interfaces, on one or more IRQs (usually 14 & 15).
32  * There can be up to two drives per interface, as per the ATA-2 spec.
33  *
34  * Primary i/f:    ide0: major=3;  (hda)         minor=0; (hdb)         minor=64
35  * Secondary i/f:  ide1: major=22; (hdc or hd1a) minor=0; (hdd or hd1b) minor=64
36  * Tertiary i/f:   ide2: major=33; (hde)         minor=0; (hdf)         minor=64
37  * Quaternary i/f: ide3: major=34; (hdg)         minor=0; (hdh)         minor=64
38  */
39
40 /******************************************************************************
41  * IDE driver configuration options (play with these as desired):
42  *
43  * REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary
44  */
45 #define REALLY_FAST_IO                  /* define if ide ports are perfect */
46 #define INITIAL_MULT_COUNT      0       /* off=0; on=2,4,8,16,32, etc.. */
47
48 #ifndef SUPPORT_SLOW_DATA_PORTS         /* 1 to support slow data ports */
49 #define SUPPORT_SLOW_DATA_PORTS 1       /* 0 to reduce kernel size */
50 #endif
51 #ifndef SUPPORT_VLB_SYNC                /* 1 to support weird 32-bit chips */
52 #define SUPPORT_VLB_SYNC        1       /* 0 to reduce kernel size */
53 #endif
54 #ifndef DISK_RECOVERY_TIME              /* off=0; on=access_delay_time */
55 #define DISK_RECOVERY_TIME      0       /*  for hardware that needs it */
56 #endif
57 #ifndef OK_TO_RESET_CONTROLLER          /* 1 needed for good error recovery */
58 #define OK_TO_RESET_CONTROLLER  1       /* 0 for use with AH2372A/B interface */
59 #endif
60 #ifndef FANCY_STATUS_DUMPS              /* 1 for human-readable drive errors */
61 #define FANCY_STATUS_DUMPS      1       /* 0 to reduce kernel size */
62 #endif
63
64 #ifdef CONFIG_BLK_DEV_CMD640
65 #if 0   /* change to 1 when debugging cmd640 problems */
66 void cmd640_dump_regs (void);
67 #define CMD640_DUMP_REGS cmd640_dump_regs() /* for debugging cmd640 chipset */
68 #endif
69 #endif  /* CONFIG_BLK_DEV_CMD640 */
70
71 #ifndef DISABLE_IRQ_NOSYNC
72 #define DISABLE_IRQ_NOSYNC      0
73 #endif
74
75 /*
76  * Used to indicate "no IRQ", should be a value that cannot be an IRQ
77  * number.
78  */
79  
80 #define IDE_NO_IRQ              (-1)
81
82 /*
83  * IDE_DRIVE_CMD is used to implement many features of the hdparm utility
84  */
85 #define IDE_DRIVE_CMD                   99      /* (magic) undef to reduce kernel size*/
86
87 #define IDE_DRIVE_TASK                  98
88
89 /*
90  * IDE_DRIVE_TASKFILE is used to implement many features needed for raw tasks
91  */
92 #define IDE_DRIVE_TASKFILE              97
93
94 /*
95  *  "No user-serviceable parts" beyond this point  :)
96  *****************************************************************************/
97
98 typedef unsigned char   byte;   /* used everywhere */
99
100 /*
101  * Probably not wise to fiddle with these
102  */
103 #define ERROR_MAX       8       /* Max read/write errors per sector */
104 #define ERROR_RESET     3       /* Reset controller every 4th retry */
105 #define ERROR_RECAL     1       /* Recalibrate every 2nd retry */
106
107 /*
108  * Tune flags
109  */
110 #define IDE_TUNE_NOAUTO         2
111 #define IDE_TUNE_AUTO           1
112 #define IDE_TUNE_DEFAULT        0
113
114 /*
115  * state flags
116  */
117
118 #define DMA_PIO_RETRY   1       /* retrying in PIO */
119
120 /*
121  * Ensure that various configuration flags have compatible settings
122  */
123 #ifdef REALLY_SLOW_IO
124 #undef REALLY_FAST_IO
125 #endif
126
127 #define HWIF(drive)             ((ide_hwif_t *)((drive)->hwif))
128 #define HWGROUP(drive)          ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
129
130 /*
131  * Definitions for accessing IDE controller registers
132  */
133 #define IDE_NR_PORTS            (10)
134
135 #define IDE_DATA_OFFSET         (0)
136 #define IDE_ERROR_OFFSET        (1)
137 #define IDE_NSECTOR_OFFSET      (2)
138 #define IDE_SECTOR_OFFSET       (3)
139 #define IDE_LCYL_OFFSET         (4)
140 #define IDE_HCYL_OFFSET         (5)
141 #define IDE_SELECT_OFFSET       (6)
142 #define IDE_STATUS_OFFSET       (7)
143 #define IDE_CONTROL_OFFSET      (8)
144 #define IDE_IRQ_OFFSET          (9)
145
146 #define IDE_FEATURE_OFFSET      IDE_ERROR_OFFSET
147 #define IDE_COMMAND_OFFSET      IDE_STATUS_OFFSET
148
149 #define IDE_DATA_OFFSET_HOB     (0)
150 #define IDE_ERROR_OFFSET_HOB    (1)
151 #define IDE_NSECTOR_OFFSET_HOB  (2)
152 #define IDE_SECTOR_OFFSET_HOB   (3)
153 #define IDE_LCYL_OFFSET_HOB     (4)
154 #define IDE_HCYL_OFFSET_HOB     (5)
155 #define IDE_SELECT_OFFSET_HOB   (6)
156 #define IDE_CONTROL_OFFSET_HOB  (7)
157
158 #define IDE_FEATURE_OFFSET_HOB  IDE_ERROR_OFFSET_HOB
159
160 #define IDE_DATA_REG            (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
161 #define IDE_ERROR_REG           (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
162 #define IDE_NSECTOR_REG         (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
163 #define IDE_SECTOR_REG          (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
164 #define IDE_LCYL_REG            (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
165 #define IDE_HCYL_REG            (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
166 #define IDE_SELECT_REG          (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
167 #define IDE_STATUS_REG          (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
168 #define IDE_CONTROL_REG         (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
169 #define IDE_IRQ_REG             (HWIF(drive)->io_ports[IDE_IRQ_OFFSET])
170
171 #define IDE_DATA_REG_HOB        (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
172 #define IDE_ERROR_REG_HOB       (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
173 #define IDE_NSECTOR_REG_HOB     (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
174 #define IDE_SECTOR_REG_HOB      (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
175 #define IDE_LCYL_REG_HOB        (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
176 #define IDE_HCYL_REG_HOB        (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
177 #define IDE_SELECT_REG_HOB      (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
178 #define IDE_STATUS_REG_HOB      (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
179 #define IDE_CONTROL_REG_HOB     (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
180
181 #define IDE_FEATURE_REG         IDE_ERROR_REG
182 #define IDE_COMMAND_REG         IDE_STATUS_REG
183 #define IDE_ALTSTATUS_REG       IDE_CONTROL_REG
184 #define IDE_IREASON_REG         IDE_NSECTOR_REG
185 #define IDE_BCOUNTL_REG         IDE_LCYL_REG
186 #define IDE_BCOUNTH_REG         IDE_HCYL_REG
187
188 #define OK_STAT(stat,good,bad)  (((stat)&((good)|(bad)))==(good))
189 #define BAD_R_STAT              (BUSY_STAT   | ERR_STAT)
190 #define BAD_W_STAT              (BAD_R_STAT  | WRERR_STAT)
191 #define BAD_STAT                (BAD_R_STAT  | DRQ_STAT)
192 #define DRIVE_READY             (READY_STAT  | SEEK_STAT)
193 #define DATA_READY              (DRQ_STAT)
194
195 #define BAD_CRC                 (ABRT_ERR    | ICRC_ERR)
196
197 #define SATA_NR_PORTS           (3)     /* 16 possible ?? */
198
199 #define SATA_STATUS_OFFSET      (0)
200 #define SATA_STATUS_REG         (HWIF(drive)->sata_scr[SATA_STATUS_OFFSET])
201 #define SATA_ERROR_OFFSET       (1)
202 #define SATA_ERROR_REG          (HWIF(drive)->sata_scr[SATA_ERROR_OFFSET])
203 #define SATA_CONTROL_OFFSET     (2)
204 #define SATA_CONTROL_REG        (HWIF(drive)->sata_scr[SATA_CONTROL_OFFSET])
205
206 #define SATA_MISC_OFFSET        (0)
207 #define SATA_MISC_REG           (HWIF(drive)->sata_misc[SATA_MISC_OFFSET])
208 #define SATA_PHY_OFFSET         (1)
209 #define SATA_PHY_REG            (HWIF(drive)->sata_misc[SATA_PHY_OFFSET])
210 #define SATA_IEN_OFFSET         (2)
211 #define SATA_IEN_REG            (HWIF(drive)->sata_misc[SATA_IEN_OFFSET])
212
213 /*
214  * Our Physical Region Descriptor (PRD) table should be large enough
215  * to handle the biggest I/O request we are likely to see.  Since requests
216  * can have no more than 256 sectors, and since the typical blocksize is
217  * two or more sectors, we could get by with a limit of 128 entries here for
218  * the usual worst case.  Most requests seem to include some contiguous blocks,
219  * further reducing the number of table entries required.
220  *
221  * The driver reverts to PIO mode for individual requests that exceed
222  * this limit (possible with 512 byte blocksizes, eg. MSDOS f/s), so handling
223  * 100% of all crazy scenarios here is not necessary.
224  *
225  * As it turns out though, we must allocate a full 4KB page for this,
226  * so the two PRD tables (ide0 & ide1) will each get half of that,
227  * allowing each to have about 256 entries (8 bytes each) from this.
228  */
229 #define PRD_BYTES       8
230 #define PRD_ENTRIES     (PAGE_SIZE / (2 * PRD_BYTES))
231
232 /*
233  * Some more useful definitions
234  */
235 #define IDE_MAJOR_NAME  "hd"    /* the same for all i/f; see also genhd.c */
236 #define MAJOR_NAME      IDE_MAJOR_NAME
237 #define PARTN_BITS      6       /* number of minor dev bits for partitions */
238 #define PARTN_MASK      ((1<<PARTN_BITS)-1)     /* a useful bit mask */
239 #define MAX_DRIVES      2       /* per interface; 2 assumed by lots of code */
240 #define SECTOR_SIZE     512
241 #define SECTOR_WORDS    (SECTOR_SIZE / 4)       /* number of 32bit words per sector */
242 #define IDE_LARGE_SEEK(b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t)))
243 #define IDE_MIN(a,b)    ((a)<(b) ? (a):(b))
244 #define IDE_MAX(a,b)    ((a)>(b) ? (a):(b))
245
246 /*
247  * Timeouts for various operations:
248  */
249 #define WAIT_DRQ        (5*HZ/100)      /* 50msec - spec allows up to 20ms */
250 #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
251 #define WAIT_READY      (5*HZ)          /* 5sec - some laptops are very slow */
252 #else
253 #define WAIT_READY      (3*HZ/100)      /* 30msec - should be instantaneous */
254 #endif /* CONFIG_APM || CONFIG_APM_MODULE */
255 #define WAIT_PIDENTIFY  (10*HZ) /* 10sec  - should be less than 3ms (?), if all ATAPI CD is closed at boot */
256 #define WAIT_WORSTCASE  (30*HZ) /* 30sec  - worst case when spinning up */
257 #define WAIT_CMD        (10*HZ) /* 10sec  - maximum wait for an IRQ to happen */
258 #define WAIT_MIN_SLEEP  (2*HZ/100)      /* 20msec - minimum sleep time */
259
260 #define HOST(hwif,chipset)                                      \
261 {                                                               \
262         return ((hwif)->chipset == chipset) ? 1 : 0;            \
263 }
264
265 /*
266  * Check for an interrupt and acknowledge the interrupt status
267  */
268 struct hwif_s;
269 typedef int (ide_ack_intr_t)(struct hwif_s *);
270
271 #ifndef NO_DMA
272 #define NO_DMA  255
273 #endif
274
275 /*
276  * hwif_chipset_t is used to keep track of the specific hardware
277  * chipset used by each IDE interface, if known.
278  */
279 typedef enum {  ide_unknown,    ide_generic,    ide_pci,
280                 ide_cmd640,     ide_dtc2278,    ide_ali14xx,
281                 ide_qd65xx,     ide_umc8672,    ide_ht6560b,
282                 ide_pdc4030,    ide_rz1000,     ide_trm290,
283                 ide_cmd646,     ide_cy82c693,   ide_4drives,
284                 ide_pmac,       ide_etrax100,   ide_acorn,
285                 ide_pc9800
286 } hwif_chipset_t;
287
288 /*
289  * Structure to hold all information about the location of this port
290  */
291 typedef struct hw_regs_s {
292         unsigned long   io_ports[IDE_NR_PORTS]; /* task file registers */
293         int             irq;                    /* our irq number */
294         int             dma;                    /* our dma entry */
295         ide_ack_intr_t  *ack_intr;              /* acknowledge interrupt */
296         void            *priv;                  /* interface specific data */
297         hwif_chipset_t  chipset;
298         unsigned long   sata_scr[SATA_NR_PORTS];
299         unsigned long   sata_misc[SATA_NR_PORTS];
300 } hw_regs_t;
301
302 /*
303  * Register new hardware with ide
304  */
305 int ide_register_hw(hw_regs_t *hw, struct hwif_s **hwifp);
306
307 /*
308  * Set up hw_regs_t structure before calling ide_register_hw (optional)
309  */
310 void ide_setup_ports(   hw_regs_t *hw,
311                         unsigned long base,
312                         int *offsets,
313                         unsigned long ctrl,
314                         unsigned long intr,
315                         ide_ack_intr_t *ack_intr,
316 #if 0
317                         ide_io_ops_t *iops,
318 #endif
319                         int irq);
320
321 #include <asm/ide.h>
322
323 /* Currently only m68k, apus and m8xx need it */
324 #ifndef IDE_ARCH_ACK_INTR
325 # define ide_ack_intr(hwif) (1)
326 #endif
327
328 /* Currently only Atari needs it */
329 #ifndef IDE_ARCH_LOCK
330 # define ide_release_lock()                     do {} while (0)
331 # define ide_get_lock(hdlr, data)               do {} while (0)
332 #endif /* IDE_ARCH_LOCK */
333
334 /*
335  * Now for the data we need to maintain per-drive:  ide_drive_t
336  */
337
338 #define ide_scsi        0x21
339 #define ide_disk        0x20
340 #define ide_optical     0x7
341 #define ide_cdrom       0x5
342 #define ide_tape        0x1
343 #define ide_floppy      0x0
344
345 /*
346  * Special Driver Flags
347  *
348  * set_geometry : respecify drive geometry
349  * recalibrate  : seek to cyl 0
350  * set_multmode : set multmode count
351  * set_tune     : tune interface for drive
352  * serviced     : service command
353  * reserved     : unused
354  */
355 typedef union {
356         unsigned all                    : 8;
357         struct {
358 #if defined(__LITTLE_ENDIAN_BITFIELD)
359                 unsigned set_geometry   : 1;
360                 unsigned recalibrate    : 1;
361                 unsigned set_multmode   : 1;
362                 unsigned set_tune       : 1;
363                 unsigned serviced       : 1;
364                 unsigned reserved       : 3;
365 #elif defined(__BIG_ENDIAN_BITFIELD)
366                 unsigned reserved       : 3;
367                 unsigned serviced       : 1;
368                 unsigned set_tune       : 1;
369                 unsigned set_multmode   : 1;
370                 unsigned recalibrate    : 1;
371                 unsigned set_geometry   : 1;
372 #else
373 #error "Please fix <asm/byteorder.h>"
374 #endif
375         } b;
376 } special_t;
377
378 /*
379  * ATA DATA Register Special.
380  * ATA NSECTOR Count Register().
381  * ATAPI Byte Count Register.
382  * Channel index ordering pairs.
383  */
384 typedef union {
385         unsigned all                    :16;
386         struct {
387 #if defined(__LITTLE_ENDIAN_BITFIELD)
388                 unsigned low            :8;     /* LSB */
389                 unsigned high           :8;     /* MSB */
390 #elif defined(__BIG_ENDIAN_BITFIELD)
391                 unsigned high           :8;     /* MSB */
392                 unsigned low            :8;     /* LSB */
393 #else
394 #error "Please fix <asm/byteorder.h>"
395 #endif
396         } b;
397 } ata_nsector_t, ata_data_t, atapi_bcount_t, ata_index_t;
398
399 /*
400  * ATA-IDE Error Register
401  *
402  * mark         : Bad address mark
403  * tzero        : Couldn't find track 0
404  * abrt         : Aborted Command
405  * mcr          : Media Change Request
406  * id           : ID field not found
407  * mce          : Media Change Event
408  * ecc          : Uncorrectable ECC error
409  * bdd          : dual meaing
410  */
411 typedef union {
412         unsigned all                    :8;
413         struct {
414 #if defined(__LITTLE_ENDIAN_BITFIELD)
415                 unsigned mark           :1;
416                 unsigned tzero          :1;
417                 unsigned abrt           :1;
418                 unsigned mcr            :1;
419                 unsigned id             :1;
420                 unsigned mce            :1;
421                 unsigned ecc            :1;
422                 unsigned bdd            :1;
423 #elif defined(__BIG_ENDIAN_BITFIELD)
424                 unsigned bdd            :1;
425                 unsigned ecc            :1;
426                 unsigned mce            :1;
427                 unsigned id             :1;
428                 unsigned mcr            :1;
429                 unsigned abrt           :1;
430                 unsigned tzero          :1;
431                 unsigned mark           :1;
432 #else
433 #error "Please fix <asm/byteorder.h>"
434 #endif
435         } b;
436 } ata_error_t;
437
438 /*
439  * ATA-IDE Select Register, aka Device-Head
440  *
441  * head         : always zeros here
442  * unit         : drive select number: 0/1
443  * bit5         : always 1
444  * lba          : using LBA instead of CHS
445  * bit7         : always 1
446  */
447 typedef union {
448         unsigned all                    : 8;
449         struct {
450 #if defined(__LITTLE_ENDIAN_BITFIELD)
451                 unsigned head           : 4;
452                 unsigned unit           : 1;
453                 unsigned bit5           : 1;
454                 unsigned lba            : 1;
455                 unsigned bit7           : 1;
456 #elif defined(__BIG_ENDIAN_BITFIELD)
457                 unsigned bit7           : 1;
458                 unsigned lba            : 1;
459                 unsigned bit5           : 1;
460                 unsigned unit           : 1;
461                 unsigned head           : 4;
462 #else
463 #error "Please fix <asm/byteorder.h>"
464 #endif
465         } b;
466 } select_t, ata_select_t;
467
468 /*
469  * The ATA-IDE Status Register.
470  * The ATAPI Status Register.
471  *
472  * check        : Error occurred
473  * idx          : Index Error
474  * corr         : Correctable error occurred
475  * drq          : Data is request by the device
476  * dsc          : Disk Seek Complete                    : ata
477  *              : Media access command finished         : atapi
478  * df           : Device Fault                          : ata
479  *              : Reserved                              : atapi
480  * drdy         : Ready, Command Mode Capable           : ata
481  *              : Ignored for ATAPI commands            : atapi
482  * bsy          : Disk is Busy
483  *              : The device has access to the command block
484  */
485 typedef union {
486         unsigned all                    :8;
487         struct {
488 #if defined(__LITTLE_ENDIAN_BITFIELD)
489                 unsigned check          :1;
490                 unsigned idx            :1;
491                 unsigned corr           :1;
492                 unsigned drq            :1;
493                 unsigned dsc            :1;
494                 unsigned df             :1;
495                 unsigned drdy           :1;
496                 unsigned bsy            :1;
497 #elif defined(__BIG_ENDIAN_BITFIELD)
498                 unsigned bsy            :1;
499                 unsigned drdy           :1;
500                 unsigned df             :1;
501                 unsigned dsc            :1;
502                 unsigned drq            :1;
503                 unsigned corr           :1;
504                 unsigned idx            :1;
505                 unsigned check          :1;
506 #else
507 #error "Please fix <asm/byteorder.h>"
508 #endif
509         } b;
510 } ata_status_t, atapi_status_t;
511
512 /*
513  * ATA-IDE Control Register
514  *
515  * bit0         : Should be set to zero
516  * nIEN         : device INTRQ to host
517  * SRST         : host soft reset bit
518  * bit3         : ATA-2 thingy, Should be set to 1
519  * reserved456  : Reserved
520  * HOB          : 48-bit address ordering, High Ordered Bit
521  */
522 typedef union {
523         unsigned all                    : 8;
524         struct {
525 #if defined(__LITTLE_ENDIAN_BITFIELD)
526                 unsigned bit0           : 1;
527                 unsigned nIEN           : 1;
528                 unsigned SRST           : 1;
529                 unsigned bit3           : 1;
530                 unsigned reserved456    : 3;
531                 unsigned HOB            : 1;
532 #elif defined(__BIG_ENDIAN_BITFIELD)
533                 unsigned HOB            : 1;
534                 unsigned reserved456    : 3;
535                 unsigned bit3           : 1;
536                 unsigned SRST           : 1;
537                 unsigned nIEN           : 1;
538                 unsigned bit0           : 1;
539 #else
540 #error "Please fix <asm/byteorder.h>"
541 #endif
542         } b;
543 } ata_control_t;
544
545 /*
546  * ATAPI Feature Register
547  *
548  * dma          : Using DMA or PIO
549  * reserved321  : Reserved
550  * reserved654  : Reserved (Tag Type)
551  * reserved7    : Reserved
552  */
553 typedef union {
554         unsigned all                    :8;
555         struct {
556 #if defined(__LITTLE_ENDIAN_BITFIELD)
557                 unsigned dma            :1;
558                 unsigned reserved321    :3;
559                 unsigned reserved654    :3;
560                 unsigned reserved7      :1;
561 #elif defined(__BIG_ENDIAN_BITFIELD)
562                 unsigned reserved7      :1;
563                 unsigned reserved654    :3;
564                 unsigned reserved321    :3;
565                 unsigned dma            :1;
566 #else
567 #error "Please fix <asm/byteorder.h>"
568 #endif
569         } b;
570 } atapi_feature_t;
571
572 /*
573  * ATAPI Interrupt Reason Register.
574  *
575  * cod          : Information transferred is command (1) or data (0)
576  * io           : The device requests us to read (1) or write (0)
577  * reserved     : Reserved
578  */
579 typedef union {
580         unsigned all                    :8;
581         struct {
582 #if defined(__LITTLE_ENDIAN_BITFIELD)
583                 unsigned cod            :1;
584                 unsigned io             :1;
585                 unsigned reserved       :6;
586 #elif defined(__BIG_ENDIAN_BITFIELD)
587                 unsigned reserved       :6;
588                 unsigned io             :1;
589                 unsigned cod            :1;
590 #else
591 #error "Please fix <asm/byteorder.h>"
592 #endif
593         } b;
594 } atapi_ireason_t;
595
596 /*
597  * The ATAPI error register.
598  *
599  * ili          : Illegal Length Indication
600  * eom          : End Of Media Detected
601  * abrt         : Aborted command - As defined by ATA
602  * mcr          : Media Change Requested - As defined by ATA
603  * sense_key    : Sense key of the last failed packet command
604  */
605 typedef union {
606         unsigned all                    :8;
607         struct {
608 #if defined(__LITTLE_ENDIAN_BITFIELD)
609                 unsigned ili            :1;
610                 unsigned eom            :1;
611                 unsigned abrt           :1;
612                 unsigned mcr            :1;
613                 unsigned sense_key      :4;
614 #elif defined(__BIG_ENDIAN_BITFIELD)
615                 unsigned sense_key      :4;
616                 unsigned mcr            :1;
617                 unsigned abrt           :1;
618                 unsigned eom            :1;
619                 unsigned ili            :1;
620 #else
621 #error "Please fix <asm/byteorder.h>"
622 #endif
623         } b;
624 } atapi_error_t;
625
626 /*
627  * ATAPI floppy Drive Select Register
628  *
629  * sam_lun      : Logical unit number
630  * reserved3    : Reserved
631  * drv          : The responding drive will be drive 0 (0) or drive 1 (1)
632  * one5         : Should be set to 1
633  * reserved6    : Reserved
634  * one7         : Should be set to 1
635  */
636 typedef union {
637         unsigned all                    :8;
638         struct {
639 #if defined(__LITTLE_ENDIAN_BITFIELD)
640                 unsigned sam_lun        :3;
641                 unsigned reserved3      :1;
642                 unsigned drv            :1;
643                 unsigned one5           :1;
644                 unsigned reserved6      :1;
645                 unsigned one7           :1;
646 #elif defined(__BIG_ENDIAN_BITFIELD)
647                 unsigned one7           :1;
648                 unsigned reserved6      :1;
649                 unsigned one5           :1;
650                 unsigned drv            :1;
651                 unsigned reserved3      :1;
652                 unsigned sam_lun        :3;
653 #else
654 #error "Please fix <asm/byteorder.h>"
655 #endif
656         } b;
657 } atapi_select_t;
658
659 /*
660  * Status returned from various ide_ functions
661  */
662 typedef enum {
663         ide_stopped,    /* no drive operation was started */
664         ide_started,    /* a drive operation was started, handler was set */
665         ide_released,   /* as ide_started, but bus also released */
666 } ide_startstop_t;
667
668 struct ide_driver_s;
669 struct ide_settings_s;
670
671 typedef struct ide_drive_s {
672         char            name[4];        /* drive name, such as "hda" */
673         char            driver_req[10]; /* requests specific driver */
674
675         request_queue_t         *queue; /* request queue */
676
677         struct request          *rq;    /* current request */
678         struct ide_drive_s      *next;  /* circular list of hwgroup drives */
679         struct ide_driver_s     *driver;/* (ide_driver_t *) */
680         void            *driver_data;   /* extra driver data */
681         struct hd_driveid       *id;    /* drive model identification info */
682         struct proc_dir_entry *proc;    /* /proc/ide/ directory entry */
683         struct ide_settings_s *settings;/* /proc/ide/ drive settings */
684         char            devfs_name[64]; /* devfs crap */
685
686         struct hwif_s           *hwif;  /* actually (ide_hwif_t *) */
687
688         unsigned long sleep;            /* sleep until this time */
689         unsigned long service_start;    /* time we started last request */
690         unsigned long service_time;     /* service time of last request */
691         unsigned long timeout;          /* max time to wait for irq */
692
693         special_t       special;        /* special action flags */
694         select_t        select;         /* basic drive/head select reg value */
695
696         u8      keep_settings;          /* restore settings after drive reset */
697         u8      autodma;                /* device can safely use dma on host */
698         u8      using_dma;              /* disk is using dma for read/write */
699         u8      using_tcq;              /* disk is using queueing */
700         u8      retry_pio;              /* retrying dma capable host in pio */
701         u8      state;                  /* retry state */
702         u8      waiting_for_dma;        /* dma currently in progress */
703         u8      unmask;                 /* okay to unmask other irqs */
704         u8      slow;                   /* slow data port */
705         u8      bswap;                  /* byte swap data */
706         u8      dsc_overlap;            /* DSC overlap */
707         u8      nice1;                  /* give potential excess bandwidth */
708
709         unsigned present        : 1;    /* drive is physically present */
710         unsigned dead           : 1;    /* device ejected hint */
711         unsigned id_read        : 1;    /* 1=id read from disk 0 = synthetic */
712         unsigned noprobe        : 1;    /* from:  hdx=noprobe */
713         unsigned removable      : 1;    /* 1 if need to do check_media_change */
714         unsigned attach         : 1;    /* needed for removable devices */
715         unsigned is_flash       : 1;    /* 1 if probed as flash */
716         unsigned forced_geom    : 1;    /* 1 if hdx=c,h,s was given at boot */
717         unsigned no_unmask      : 1;    /* disallow setting unmask bit */
718         unsigned no_io_32bit    : 1;    /* disallow enabling 32bit I/O */
719         unsigned nobios         : 1;    /* do not probe bios for drive */
720         unsigned atapi_overlap  : 1;    /* ATAPI overlap (not supported) */
721         unsigned nice0          : 1;    /* give obvious excess bandwidth */
722         unsigned nice2          : 1;    /* give a share in our own bandwidth */
723         unsigned doorlocking    : 1;    /* for removable only: door lock/unlock works */
724         unsigned autotune       : 2;    /* 0=default, 1=autotune, 2=noautotune */
725         unsigned remap_0_to_1   : 1;    /* 0=noremap, 1=remap 0->1 (for EZDrive) */
726         unsigned ata_flash      : 1;    /* 1=present, 0=default */
727         unsigned blocked        : 1;    /* 1=powermanagment told us not to do anything, so sleep nicely */
728         unsigned vdma           : 1;    /* 1=doing PIO over DMA 0=doing normal DMA */
729         unsigned addressing;            /*      : 3;
730                                          *  0=28-bit
731                                          *  1=48-bit
732                                          *  2=48-bit doing 28-bit
733                                          *  3=64-bit
734                                          */
735
736         u8      scsi;           /* 0=default, 1=skip current ide-subdriver for ide-scsi emulation */
737         u8      quirk_list;     /* considered quirky, set for a specific host */
738         u8      suspend_reset;  /* drive suspend mode flag, soft-reset recovers */
739         u8      init_speed;     /* transfer rate set at boot */
740         u8      pio_speed;      /* unused by core, used by some drivers for fallback from DMA */
741         u8      current_speed;  /* current transfer rate set */
742         u8      dn;             /* now wide spread use */
743         u8      wcache;         /* status of write cache */
744         u8      acoustic;       /* acoustic management */
745         u8      media;          /* disk, cdrom, tape, floppy, ... */
746         u8      ctl;            /* "normal" value for IDE_CONTROL_REG */
747         u8      ready_stat;     /* min status value for drive ready */
748         u8      mult_count;     /* current multiple sector setting */
749         u8      mult_req;       /* requested multiple sector setting */
750         u8      tune_req;       /* requested drive tuning setting */
751         u8      io_32bit;       /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
752         u8      bad_wstat;      /* used for ignoring WRERR_STAT */
753         u8      nowerr;         /* used for ignoring WRERR_STAT */
754         u8      sect0;          /* offset of first sector for DM6:DDO */
755         u8      head;           /* "real" number of heads */
756         u8      sect;           /* "real" sectors per track */
757         u8      bios_head;      /* BIOS/fdisk/LILO number of heads */
758         u8      bios_sect;      /* BIOS/fdisk/LILO sectors per track */
759         u8      queue_depth;    /* max queue depth */
760
761         unsigned int    bios_cyl;       /* BIOS/fdisk/LILO number of cyls */
762         unsigned int    cyl;            /* "real" number of cyls */
763         unsigned int    drive_data;     /* use by tuneproc/selectproc */
764         unsigned int    usage;          /* current "open()" count for drive */
765         unsigned int    failures;       /* current failure count */
766         unsigned int    max_failures;   /* maximum allowed failure count */
767
768         u64             capacity64;     /* total number of sectors */
769
770         int             last_lun;       /* last logical unit */
771         int             forced_lun;     /* if hdxlun was given at boot */
772         int             lun;            /* logical unit */
773         int             crc_count;      /* crc counter to reduce drive speed */
774         struct list_head list;
775         struct device   gendev;
776         struct semaphore gendev_rel_sem;        /* to deal with device release() */
777         struct gendisk *disk;
778 } ide_drive_t;
779
780 typedef struct ide_pio_ops_s {
781         void (*ata_input_data)(ide_drive_t *, void *, u32);
782         void (*ata_output_data)(ide_drive_t *, void *, u32);
783
784         void (*atapi_input_bytes)(ide_drive_t *, void *, u32);
785         void (*atapi_output_bytes)(ide_drive_t *, void *, u32);
786 } ide_pio_ops_t;
787
788 typedef struct ide_dma_ops_s {
789         /* insert dma operations here! */
790         int (*ide_dma_read)(ide_drive_t *drive);
791         int (*ide_dma_write)(ide_drive_t *drive);
792         int (*ide_dma_begin)(ide_drive_t *drive);
793         int (*ide_dma_end)(ide_drive_t *drive);
794         int (*ide_dma_check)(ide_drive_t *drive);
795         int (*ide_dma_on)(ide_drive_t *drive);
796         int (*ide_dma_off)(ide_drive_t *drive);
797         int (*ide_dma_off_quietly)(ide_drive_t *drive);
798         int (*ide_dma_test_irq)(ide_drive_t *drive);
799         int (*ide_dma_host_on)(ide_drive_t *drive);
800         int (*ide_dma_host_off)(ide_drive_t *drive);
801         int (*ide_dma_bad_drive)(ide_drive_t *drive);
802         int (*ide_dma_good_drive)(ide_drive_t *drive);
803         int (*ide_dma_count)(ide_drive_t *drive);
804         int (*ide_dma_verbose)(ide_drive_t *drive);
805         int (*ide_dma_retune)(ide_drive_t *drive);
806         int (*ide_dma_lostirq)(ide_drive_t *drive);
807         int (*ide_dma_timeout)(ide_drive_t *drive);
808         /* dma queued operations */
809         int (*ide_dma_queued_on)(ide_drive_t *drive);
810         int (*ide_dma_queued_off)(ide_drive_t *drive);
811         ide_startstop_t (*ide_dma_queued_read)(ide_drive_t *drive);
812         ide_startstop_t (*ide_dma_queued_write)(ide_drive_t *drive);
813         ide_startstop_t (*ide_dma_queued_start)(ide_drive_t *drive);
814 } ide_dma_ops_t;
815
816 /*
817  * mapping stuff, prepare for highmem...
818  * 
819  * temporarily mapping a (possible) highmem bio for PIO transfer
820  */
821 #ifndef CONFIG_IDE_TASKFILE_IO
822
823 #define ide_rq_offset(rq) \
824         (((rq)->hard_cur_sectors - (rq)->current_nr_sectors) << 9)
825
826 /*
827  * taskfiles really should use hard_cur_sectors as well!
828  */
829 #define task_rq_offset(rq) \
830         (((rq)->nr_sectors - (rq)->current_nr_sectors) * SECTOR_SIZE)
831
832 static inline void *ide_map_buffer(struct request *rq, unsigned long *flags)
833 {
834         /*
835          * fs request
836          */
837         if (rq->bio)
838                 return bio_kmap_irq(rq->bio, flags) + ide_rq_offset(rq);
839
840         /*
841          * task request
842          */
843         return rq->buffer + task_rq_offset(rq);
844 }
845
846 static inline void ide_unmap_buffer(struct request *rq, char *buffer, unsigned long *flags)
847 {
848         if (rq->bio)
849                 bio_kunmap_irq(buffer, flags);
850 }
851 #endif /* !CONFIG_IDE_TASKFILE_IO */
852
853 #define IDE_CHIPSET_PCI_MASK    \
854     ((1<<ide_pci)|(1<<ide_cmd646)|(1<<ide_ali14xx))
855 #define IDE_CHIPSET_IS_PCI(c)   ((IDE_CHIPSET_PCI_MASK >> (c)) & 1)
856
857 struct ide_pci_device_s;
858
859 typedef struct hwif_s {
860         struct hwif_s *next;            /* for linked-list in ide_hwgroup_t */
861         struct hwif_s *mate;            /* other hwif from same PCI chip */
862         struct hwgroup_s *hwgroup;      /* actually (ide_hwgroup_t *) */
863         struct proc_dir_entry *proc;    /* /proc/ide/ directory entry */
864
865         char name[6];                   /* name of interface, eg. "ide0" */
866
867                 /* task file registers for pata and sata */
868         unsigned long   io_ports[IDE_NR_PORTS];
869         unsigned long   sata_scr[SATA_NR_PORTS];
870         unsigned long   sata_misc[SATA_NR_PORTS];
871
872         hw_regs_t       hw;             /* Hardware info */
873         ide_drive_t     drives[MAX_DRIVES];     /* drive info */
874
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 */
880
881         u8 atapi_dma;   /* host supports atapi_dma */
882         u8 ultra_mask;
883         u8 mwdma_mask;
884         u8 swdma_mask;
885
886         hwif_chipset_t chipset; /* sub-module for tuning.. */
887
888         struct pci_dev  *pci_dev;       /* for pci chipsets */
889         struct ide_pci_device_s *cds;   /* chipset device struct */
890         
891         struct pnp_dev  *pnp_dev;       /* for PnP devices */
892
893         ide_startstop_t (*rw_disk)(ide_drive_t *, struct request *, sector_t);
894
895 #if 0
896         ide_hwif_ops_t  *hwifops;
897 #else
898         /* routine is for HBA specific IDENTITY operations */
899         int     (*identify)(ide_drive_t *);
900         /* routine to tune PIO mode for drives */
901         void    (*tuneproc)(ide_drive_t *, u8);
902         /* routine to retune DMA modes for drives */
903         int     (*speedproc)(ide_drive_t *, u8);
904         /* tweaks hardware to select drive */
905         void    (*selectproc)(ide_drive_t *);
906         /* chipset polling based on hba specifics */
907         int     (*reset_poll)(ide_drive_t *);
908         /* chipset specific changes to default for device-hba resets */
909         void    (*pre_reset)(ide_drive_t *);
910         /* routine to reset controller after a disk reset */
911         void    (*resetproc)(ide_drive_t *);
912         /* special interrupt handling for shared pci interrupts */
913         void    (*intrproc)(ide_drive_t *);
914         /* special host masking for drive selection */
915         void    (*maskproc)(ide_drive_t *, int);
916         /* check host's drive quirk list */
917         int     (*quirkproc)(ide_drive_t *);
918         /* driver soft-power interface */
919         int     (*busproc)(ide_drive_t *, int);
920 //      /* host rate limiter */
921 //      u8      (*ratemask)(ide_drive_t *);
922 //      /* device rate limiter */
923 //      u8      (*ratefilter)(ide_drive_t *, u8);
924 #endif
925
926 #if 0
927         ide_pio_ops_t   *pioops;
928 #else
929         void (*ata_input_data)(ide_drive_t *, void *, u32);
930         void (*ata_output_data)(ide_drive_t *, void *, u32);
931
932         void (*atapi_input_bytes)(ide_drive_t *, void *, u32);
933         void (*atapi_output_bytes)(ide_drive_t *, void *, u32);
934 #endif
935
936         int (*ide_dma_read)(ide_drive_t *drive);
937         int (*ide_dma_write)(ide_drive_t *drive);
938         int (*ide_dma_begin)(ide_drive_t *drive);
939         int (*ide_dma_end)(ide_drive_t *drive);
940         int (*ide_dma_check)(ide_drive_t *drive);
941         int (*ide_dma_on)(ide_drive_t *drive);
942         int (*ide_dma_off)(ide_drive_t *drive);
943         int (*ide_dma_off_quietly)(ide_drive_t *drive);
944         int (*ide_dma_test_irq)(ide_drive_t *drive);
945         int (*ide_dma_host_on)(ide_drive_t *drive);
946         int (*ide_dma_host_off)(ide_drive_t *drive);
947         int (*ide_dma_bad_drive)(ide_drive_t *drive);
948         int (*ide_dma_good_drive)(ide_drive_t *drive);
949         int (*ide_dma_count)(ide_drive_t *drive);
950         int (*ide_dma_verbose)(ide_drive_t *drive);
951         int (*ide_dma_retune)(ide_drive_t *drive);
952         int (*ide_dma_lostirq)(ide_drive_t *drive);
953         int (*ide_dma_timeout)(ide_drive_t *drive);
954
955         /* dma queued operations */
956         int (*ide_dma_queued_on)(ide_drive_t *drive);
957         int (*ide_dma_queued_off)(ide_drive_t *drive);
958         ide_startstop_t (*ide_dma_queued_read)(ide_drive_t *drive);
959         ide_startstop_t (*ide_dma_queued_write)(ide_drive_t *drive);
960         ide_startstop_t (*ide_dma_queued_start)(ide_drive_t *drive);
961
962         void (*OUTB)(u8 addr, unsigned long port);
963         void (*OUTBSYNC)(ide_drive_t *drive, u8 addr, unsigned long port);
964         void (*OUTW)(u16 addr, unsigned long port);
965         void (*OUTL)(u32 addr, unsigned long port);
966         void (*OUTSW)(unsigned long port, void *addr, u32 count);
967         void (*OUTSL)(unsigned long port, void *addr, u32 count);
968
969         u8  (*INB)(unsigned long port);
970         u16 (*INW)(unsigned long port);
971         u32 (*INL)(unsigned long port);
972         void (*INSW)(unsigned long port, void *addr, u32 count);
973         void (*INSL)(unsigned long port, void *addr, u32 count);
974
975         /* dma physical region descriptor table (cpu view) */
976         unsigned int    *dmatable_cpu;
977         /* dma physical region descriptor table (dma view) */
978         dma_addr_t      dmatable_dma;
979         /* Scatter-gather list used to build the above */
980         struct scatterlist *sg_table;
981         int sg_nents;                   /* Current number of entries in it */
982         int sg_dma_direction;           /* dma transfer direction */
983         int sg_dma_active;              /* is it in use */
984
985         int             mmio;           /* hosts iomio (0), mmio (1) or custom (2) select */
986         int             rqsize;         /* max sectors per request */
987         int             irq;            /* our irq number */
988         int             initializing;   /* set while initializing self */
989
990         unsigned long   dma_master;     /* reference base addr dmabase */
991         unsigned long   dma_base;       /* base addr for dma ports */
992         unsigned long   dma_command;    /* dma command register */
993         unsigned long   dma_vendor1;    /* dma vendor 1 register */
994         unsigned long   dma_status;     /* dma status register */
995         unsigned long   dma_vendor3;    /* dma vendor 3 register */
996         unsigned long   dma_prdtable;   /* actual prd table address */
997         unsigned long   dma_base2;      /* extended base addr for dma ports */
998
999         unsigned        dma_extra;      /* extra addr for dma ports */
1000         unsigned long   config_data;    /* for use by chipset-specific code */
1001         unsigned long   select_data;    /* for use by chipset-specific code */
1002 #if (DISK_RECOVERY_TIME > 0)
1003         unsigned long   last_time;      /* time when previous rq was done */
1004 #endif
1005
1006
1007         unsigned        noprobe    : 1; /* don't probe for this interface */
1008         unsigned        present    : 1; /* this interface exists */
1009         unsigned        hold       : 1; /* this interface is always present */
1010         unsigned        serialized : 1; /* serialized all channel operation */
1011         unsigned        sharing_irq: 1; /* 1 = sharing irq with another hwif */
1012         unsigned        reset      : 1; /* reset after probe */
1013         unsigned        autodma    : 1; /* auto-attempt using DMA at boot */
1014         unsigned        udma_four  : 1; /* 1=ATA-66 capable, 0=default */
1015         unsigned        no_lba48   : 1; /* 1 = cannot do LBA48 */
1016         unsigned        no_dsc     : 1; /* 0 default, 1 dsc_overlap disabled */
1017         unsigned        auto_poll  : 1; /* supports nop auto-poll */
1018
1019         struct device   gendev;
1020         struct semaphore gendev_rel_sem; /* To deal with device release() */
1021
1022         void            *hwif_data;     /* extra hwif data */
1023
1024         unsigned dma;
1025
1026         void (*led_act)(void *data, int rw);
1027 } ide_hwif_t;
1028
1029 /*
1030  *  internal ide interrupt handler type
1031  */
1032 typedef ide_startstop_t (ide_pre_handler_t)(ide_drive_t *, struct request *);
1033 typedef ide_startstop_t (ide_handler_t)(ide_drive_t *);
1034 typedef ide_startstop_t (ide_post_handler_t)(ide_drive_t *);
1035 typedef int (ide_expiry_t)(ide_drive_t *);
1036
1037 typedef struct hwgroup_s {
1038                 /* irq handler, if active */
1039         ide_startstop_t (*handler)(ide_drive_t *);
1040                 /* irq handler, suspended if active */
1041         ide_startstop_t (*handler_save)(ide_drive_t *);
1042                 /* BOOL: protects all fields below */
1043         volatile int busy;
1044                 /* BOOL: wake us up on timer expiry */
1045         int sleeping;
1046                 /* current drive */
1047         ide_drive_t *drive;
1048                 /* ptr to current hwif in linked-list */
1049         ide_hwif_t *hwif;
1050
1051                 /* for pci chipsets */
1052         struct pci_dev *pci_dev;
1053                 /* chipset device struct */
1054         struct ide_pci_device_s *cds;
1055
1056                 /* current request */
1057         struct request *rq;
1058                 /* failsafe timer */
1059         struct timer_list timer;
1060                 /* local copy of current write rq */
1061         struct request wrq;
1062                 /* timeout value during long polls */
1063         unsigned long poll_timeout;
1064                 /* queried upon timeouts */
1065         int (*expiry)(ide_drive_t *);
1066                 /* ide_system_bus_speed */
1067         int pio_clock;
1068
1069         unsigned char cmd_buf[4];
1070 } ide_hwgroup_t;
1071
1072 /* structure attached to the request for IDE_TASK_CMDS */
1073
1074 /*
1075  * configurable drive settings
1076  */
1077
1078 #define TYPE_INT        0
1079 #define TYPE_INTA       1
1080 #define TYPE_BYTE       2
1081 #define TYPE_SHORT      3
1082
1083 #define SETTING_READ    (1 << 0)
1084 #define SETTING_WRITE   (1 << 1)
1085 #define SETTING_RW      (SETTING_READ | SETTING_WRITE)
1086
1087 typedef int (ide_procset_t)(ide_drive_t *, int);
1088 typedef struct ide_settings_s {
1089         char                    *name;
1090         int                     rw;
1091         int                     read_ioctl;
1092         int                     write_ioctl;
1093         int                     data_type;
1094         int                     min;
1095         int                     max;
1096         int                     mul_factor;
1097         int                     div_factor;
1098         void                    *data;
1099         ide_procset_t           *set;
1100         int                     auto_remove;
1101         struct ide_settings_s   *next;
1102 } ide_settings_t;
1103
1104 extern struct semaphore ide_setting_sem;
1105 extern int ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set);
1106 extern void ide_remove_setting(ide_drive_t *drive, char *name);
1107 extern ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name);
1108 extern int ide_read_setting(ide_drive_t *t, ide_settings_t *setting);
1109 extern int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int val);
1110 extern void ide_add_generic_settings(ide_drive_t *drive);
1111
1112 /*
1113  * /proc/ide interface
1114  */
1115 typedef struct {
1116         const char      *name;
1117         mode_t          mode;
1118         read_proc_t     *read_proc;
1119         write_proc_t    *write_proc;
1120 } ide_proc_entry_t;
1121
1122 #ifdef CONFIG_PROC_FS
1123 extern void proc_ide_create(void);
1124 extern void proc_ide_destroy(void);
1125 extern void destroy_proc_ide_device(ide_hwif_t *, ide_drive_t *);
1126 extern void destroy_proc_ide_drives(ide_hwif_t *);
1127 extern void create_proc_ide_interfaces(void);
1128 extern void ide_add_proc_entries(struct proc_dir_entry *, ide_proc_entry_t *, void *);
1129 extern void ide_remove_proc_entries(struct proc_dir_entry *, ide_proc_entry_t *);
1130 read_proc_t proc_ide_read_capacity;
1131 read_proc_t proc_ide_read_geometry;
1132
1133 /*
1134  * Standard exit stuff:
1135  */
1136 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \
1137 {                                       \
1138         len -= off;                     \
1139         if (len < count) {              \
1140                 *eof = 1;               \
1141                 if (len <= 0)           \
1142                         return 0;       \
1143         } else                          \
1144                 len = count;            \
1145         *start = page + off;            \
1146         return len;                     \
1147 }
1148 #else
1149 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
1150 #endif
1151
1152 /*
1153  * Power Management step value (rq->pm->pm_step).
1154  *
1155  * The step value starts at 0 (ide_pm_state_start_suspend) for a
1156  * suspend operation or 1000 (ide_pm_state_start_resume) for a
1157  * resume operation.
1158  *
1159  * For each step, the core calls the subdriver start_power_step() first.
1160  * This can return:
1161  *      - ide_stopped : In this case, the core calls us back again unless
1162  *                      step have been set to ide_power_state_completed.
1163  *      - ide_started : In this case, the channel is left busy until an
1164  *                      async event (interrupt) occurs.
1165  * Typically, start_power_step() will issue a taskfile request with
1166  * do_rw_taskfile().
1167  *
1168  * Upon reception of the interrupt, the core will call complete_power_step()
1169  * with the error code if any. This routine should update the step value
1170  * and return. It should not start a new request. The core will call
1171  * start_power_step for the new step value, unless step have been set to
1172  * ide_power_state_completed.
1173  *
1174  * Subdrivers are expected to define their own additional power
1175  * steps from 1..999 for suspend and from 1001..1999 for resume,
1176  * other values are reserved for future use.
1177  */
1178
1179 enum {
1180         ide_pm_state_completed          = -1,
1181         ide_pm_state_start_suspend      = 0,
1182         ide_pm_state_start_resume       = 1000,
1183 };
1184
1185 /*
1186  * Subdrivers support.
1187  */
1188 #define IDE_SUBDRIVER_VERSION   1
1189
1190 typedef struct ide_driver_s {
1191         struct module                   *owner;
1192         const char                      *name;
1193         const char                      *version;
1194         u8                              media;
1195         unsigned busy                   : 1;
1196         unsigned supports_dsc_overlap   : 1;
1197         int             (*cleanup)(ide_drive_t *);
1198         int             (*shutdown)(ide_drive_t *);
1199         int             (*flushcache)(ide_drive_t *);
1200         ide_startstop_t (*do_request)(ide_drive_t *, struct request *, sector_t);
1201         int             (*end_request)(ide_drive_t *, int, int);
1202         u8              (*sense)(ide_drive_t *, const char *, u8);
1203         ide_startstop_t (*error)(ide_drive_t *, const char *, u8);
1204         ide_startstop_t (*abort)(ide_drive_t *, const char *);
1205         int             (*ioctl)(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
1206         void            (*pre_reset)(ide_drive_t *);
1207         sector_t        (*capacity)(ide_drive_t *);
1208         ide_startstop_t (*special)(ide_drive_t *);
1209         ide_proc_entry_t        *proc;
1210         int             (*attach)(ide_drive_t *);
1211         void            (*ata_prebuilder)(ide_drive_t *);
1212         void            (*atapi_prebuilder)(ide_drive_t *);
1213         ide_startstop_t (*start_power_step)(ide_drive_t *, struct request *);
1214         void            (*complete_power_step)(ide_drive_t *, struct request *, u8, u8);
1215         struct device_driver    gen_driver;
1216         struct list_head drives;
1217         struct list_head drivers;
1218 } ide_driver_t;
1219
1220 #define DRIVER(drive)           ((drive)->driver)
1221
1222 extern int generic_ide_ioctl(struct block_device *, unsigned, unsigned long);
1223
1224 typedef struct ide_devices_s {
1225         char                    name[4];                /* hdX */
1226         unsigned                attached        : 1;    /* native */
1227         unsigned                alttached       : 1;    /* alternate */
1228         struct ide_devices_s    *next;
1229 } ide_devices_t;
1230
1231 /*
1232  * ide_hwifs[] is the master data structure used to keep track
1233  * of just about everything in ide.c.  Whenever possible, routines
1234  * should be using pointers to a drive (ide_drive_t *) or
1235  * pointers to a hwif (ide_hwif_t *), rather than indexing this
1236  * structure directly (the allocation/layout may change!).
1237  *
1238  */
1239 #ifndef _IDE_C
1240 extern  ide_hwif_t      ide_hwifs[];            /* master data repository */
1241 extern int (*ide_probe)(void);
1242
1243 extern ide_devices_t   *idedisk;
1244 extern ide_devices_t   *idecd;
1245 extern ide_devices_t   *idefloppy;
1246 extern ide_devices_t   *idetape;
1247 extern ide_devices_t   *idescsi;
1248
1249 #endif
1250 extern int noautodma;
1251
1252 extern int ide_end_request (ide_drive_t *drive, int uptodate, int nrsecs);
1253
1254 /*
1255  * This is used on exit from the driver to designate the next irq handler
1256  * and also to start the safety timer.
1257  */
1258 extern void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry);
1259
1260 /*
1261  * This is used on exit from the driver to designate the next irq handler
1262  * and start the safety time safely and atomically from the IRQ handler
1263  * with respect to the command issue (which it also does)
1264  */
1265 extern void ide_execute_command(ide_drive_t *, task_ioreg_t cmd, ide_handler_t *, unsigned int, ide_expiry_t *);
1266
1267 /*
1268  * Error reporting, in human readable form (luxurious, but a memory hog).
1269  *
1270  * (drive, msg, status)
1271  */
1272 byte ide_dump_status (ide_drive_t *drive, const char *msg, byte stat);
1273
1274 /*
1275  * ide_error() takes action based on the error returned by the controller.
1276  * The caller should return immediately after invoking this.
1277  *
1278  * (drive, msg, status)
1279  */
1280 ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, byte stat);
1281
1282 /*
1283  * Abort a running command on the controller triggering the abort
1284  * from a host side, non error situation
1285  * (drive, msg)
1286  */
1287 extern ide_startstop_t ide_abort(ide_drive_t *, const char *);
1288
1289 /*
1290  * Issue a simple drive command
1291  * The drive must be selected beforehand.
1292  *
1293  * (drive, command, nsector, handler)
1294  */
1295 extern void ide_cmd(ide_drive_t *, u8, u8, ide_handler_t *);
1296
1297 extern void ide_fix_driveid(struct hd_driveid *);
1298 /*
1299  * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
1300  * removing leading/trailing blanks and compressing internal blanks.
1301  * It is primarily used to tidy up the model name/number fields as
1302  * returned by the WIN_[P]IDENTIFY commands.
1303  *
1304  * (s, bytecount, byteswap)
1305  */
1306 extern void ide_fixstring(u8 *, const int, const int);
1307
1308 /*
1309  * This routine busy-waits for the drive status to be not "busy".
1310  * It then checks the status for all of the "good" bits and none
1311  * of the "bad" bits, and if all is okay it returns 0.  All other
1312  * cases return 1 after doing "*startstop = ide_error()", and the
1313  * caller should return the updated value of "startstop" in this case.
1314  * "startstop" is unchanged when the function returns 0;
1315  * (startstop, drive, good, bad, timeout)
1316  */
1317 extern int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long);
1318
1319 /*
1320  * Return the current idea about the total capacity of this drive.
1321  */
1322 extern sector_t current_capacity (ide_drive_t *drive);
1323
1324 /*
1325  * Start a reset operation for an IDE interface.
1326  * The caller should return immediately after invoking this.
1327  */
1328 extern ide_startstop_t ide_do_reset (ide_drive_t *);
1329
1330 /*
1331  * This function is intended to be used prior to invoking ide_do_drive_cmd().
1332  */
1333 extern void ide_init_drive_cmd (struct request *rq);
1334
1335 /*
1336  * "action" parameter type for ide_do_drive_cmd() below.
1337  */
1338 typedef enum {
1339         ide_wait,       /* insert rq at end of list, and wait for it */
1340         ide_next,       /* insert rq immediately after current request */
1341         ide_preempt,    /* insert rq in front of current request */
1342         ide_head_wait,  /* insert rq in front of current request and wait for it */
1343         ide_end         /* insert rq at end of list, but don't wait for it */
1344 } ide_action_t;
1345
1346 /*
1347  * This function issues a special IDE device request
1348  * onto the request queue.
1349  *
1350  * If action is ide_wait, then the rq is queued at the end of the
1351  * request queue, and the function sleeps until it has been processed.
1352  * This is for use when invoked from an ioctl handler.
1353  *
1354  * If action is ide_preempt, then the rq is queued at the head of
1355  * the request queue, displacing the currently-being-processed
1356  * request and this function returns immediately without waiting
1357  * for the new rq to be completed.  This is VERY DANGEROUS, and is
1358  * intended for careful use by the ATAPI tape/cdrom driver code.
1359  *
1360  * If action is ide_next, then the rq is queued immediately after
1361  * the currently-being-processed-request (if any), and the function
1362  * returns without waiting for the new rq to be completed.  As above,
1363  * This is VERY DANGEROUS, and is intended for careful use by the
1364  * ATAPI tape/cdrom driver code.
1365  *
1366  * If action is ide_end, then the rq is queued at the end of the
1367  * request queue, and the function returns immediately without waiting
1368  * for the new rq to be completed. This is again intended for careful
1369  * use by the ATAPI tape/cdrom driver code.
1370  */
1371 extern int ide_do_drive_cmd(ide_drive_t *, struct request *, ide_action_t);
1372
1373 /*
1374  * Clean up after success/failure of an explicit drive cmd.
1375  * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_CMD).
1376  * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_TASK_MASK).
1377  *
1378  * (ide_drive_t *drive, u8 stat, u8 err)
1379  */
1380 extern void ide_end_drive_cmd(ide_drive_t *, u8, u8);
1381
1382 /*
1383  * Issue ATA command and wait for completion.
1384  * Use for implementing commands in kernel
1385  *
1386  *  (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
1387  */
1388 extern int ide_wait_cmd(ide_drive_t *, u8, u8, u8, u8, u8 *);
1389
1390 /* (ide_drive_t *drive, u8 *buf) */
1391 extern int ide_wait_cmd_task(ide_drive_t *, u8 *);
1392
1393 typedef struct ide_task_s {
1394 /*
1395  *      struct hd_drive_task_hdr        tf;
1396  *      task_struct_t           tf;
1397  *      struct hd_drive_hob_hdr         hobf;
1398  *      hob_struct_t            hobf;
1399  */
1400         task_ioreg_t            tfRegister[8];
1401         task_ioreg_t            hobRegister[8];
1402         ide_reg_valid_t         tf_out_flags;
1403         ide_reg_valid_t         tf_in_flags;
1404         int                     data_phase;
1405         int                     command_type;
1406         ide_pre_handler_t       *prehandler;
1407         ide_handler_t           *handler;
1408         ide_post_handler_t      *posthandler;
1409         struct request          *rq;            /* copy of request */
1410         void                    *special;       /* valid_t generally */
1411 } ide_task_t;
1412
1413 typedef struct pkt_task_s {
1414 /*
1415  *      struct hd_drive_task_hdr        pktf;
1416  *      task_struct_t           pktf;
1417  *      u8                      pkcdb[12];
1418  */
1419         task_ioreg_t            tfRegister[8];
1420         int                     data_phase;
1421         int                     command_type;
1422         ide_handler_t           *handler;
1423         struct request          *rq;            /* copy of request */
1424         void                    *special;
1425 } pkt_task_t;
1426
1427 extern inline u32 ide_read_24(ide_drive_t *);
1428
1429 extern inline void SELECT_DRIVE(ide_drive_t *);
1430 extern inline void SELECT_INTERRUPT(ide_drive_t *);
1431 extern inline void SELECT_MASK(ide_drive_t *, int);
1432 extern inline void QUIRK_LIST(ide_drive_t *);
1433
1434 extern void ata_input_data(ide_drive_t *, void *, u32);
1435 extern void ata_output_data(ide_drive_t *, void *, u32);
1436 extern void atapi_input_bytes(ide_drive_t *, void *, u32);
1437 extern void atapi_output_bytes(ide_drive_t *, void *, u32);
1438 extern void taskfile_input_data(ide_drive_t *, void *, u32);
1439 extern void taskfile_output_data(ide_drive_t *, void *, u32);
1440
1441 #ifdef CONFIG_IDE_TASKFILE_IO
1442
1443 #define IDE_PIO_IN      0
1444 #define IDE_PIO_OUT     1
1445
1446 static inline void task_sectors(ide_drive_t *drive, struct request *rq,
1447                                 unsigned nsect, int rw)
1448 {
1449         unsigned long flags;
1450         unsigned int bio_rq;
1451         char *buf;
1452
1453         /*
1454          * bio_rq flag is needed because we can call
1455          * rq_unmap_buffer() with rq->cbio == NULL
1456          */
1457         bio_rq = rq->cbio ? 1 : 0;
1458
1459         if (bio_rq)
1460                 buf = rq_map_buffer(rq, &flags);        /* fs request */
1461         else
1462                 buf = rq->buffer + blk_rq_offset(rq);   /* task request */
1463
1464         /*
1465          * IRQ can happen instantly after reading/writing
1466          * last sector of the datablock.
1467          */
1468         process_that_request_first(rq, nsect);
1469
1470         if (rw == IDE_PIO_OUT)
1471                 taskfile_output_data(drive, buf, nsect * SECTOR_WORDS);
1472         else
1473                 taskfile_input_data(drive, buf, nsect * SECTOR_WORDS);
1474
1475         if (bio_rq)
1476                 rq_unmap_buffer(buf, &flags);
1477 }
1478 #endif /* CONFIG_IDE_TASKFILE_IO */
1479
1480 extern int drive_is_ready(ide_drive_t *);
1481 extern int wait_for_ready(ide_drive_t *, int /* timeout */);
1482
1483 /*
1484  * taskfile io for disks for now...and builds request from ide_ioctl
1485  */
1486 extern ide_startstop_t do_rw_taskfile(ide_drive_t *, ide_task_t *);
1487
1488 /* (ide_drive_t *drive, u8 stat, u8 err) */
1489 extern void ide_end_taskfile(ide_drive_t *, u8, u8);
1490
1491 /*
1492  * Special Flagged Register Validation Caller
1493  */
1494 extern ide_startstop_t flagged_taskfile(ide_drive_t *, ide_task_t *);
1495
1496 extern ide_startstop_t set_multmode_intr(ide_drive_t *);
1497 extern ide_startstop_t set_geometry_intr(ide_drive_t *);
1498 extern ide_startstop_t recal_intr(ide_drive_t *);
1499 extern ide_startstop_t task_no_data_intr(ide_drive_t *);
1500 extern ide_startstop_t task_in_intr(ide_drive_t *);
1501 extern ide_startstop_t task_mulin_intr(ide_drive_t *);
1502 extern ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *);
1503 extern ide_startstop_t task_out_intr(ide_drive_t *);
1504 extern ide_startstop_t pre_task_mulout_intr(ide_drive_t *, struct request *);
1505 extern ide_startstop_t task_mulout_intr(ide_drive_t *);
1506 extern void ide_init_drive_taskfile(struct request *);
1507
1508 extern int ide_raw_taskfile(ide_drive_t *, ide_task_t *, u8 *);
1509
1510 extern ide_pre_handler_t * ide_pre_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1511
1512 extern ide_handler_t * ide_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1513
1514 extern ide_post_handler_t * ide_post_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1515
1516 /* Expects args is a full set of TF registers and parses the command type */
1517 extern int ide_cmd_type_parser(ide_task_t *);
1518
1519 int ide_taskfile_ioctl(ide_drive_t *, unsigned int, unsigned long);
1520 int ide_cmd_ioctl(ide_drive_t *, unsigned int, unsigned long);
1521 int ide_task_ioctl(ide_drive_t *, unsigned int, unsigned long);
1522
1523 #if 0
1524
1525 #define IDEFLOPPY_PC_BUFFER_SIZE        256
1526 #define IDETAPE_PC_BUFFER_SIZE          256
1527 #define IDE_PC_BUFFER_SIZE          256
1528
1529 typedef struct ide_packet_command_s {
1530                 /* Actual packet bytes */
1531         u8 c[12];
1532                 /* On each retry, we increment retries */
1533         int retries;
1534                 /* Error code */
1535         int error;
1536                 /* Bytes to transfer */
1537         int request_transfer;
1538                 /* Bytes actually transferred */
1539         int actually_transferred;
1540                 /* Size of our data buffer */
1541         int buffer_size;
1542
1543         struct buffer_head *bh;
1544         u8 *b_data;
1545                 /* The corresponding request */
1546         struct request *rq;
1547 # if 0
1548                 /* Scatter gather table */
1549         struct scatterlist *sg;
1550 # endif
1551         int b_count;
1552                 /* Data buffer */
1553         u8 *buffer;
1554                 /* Pointer into the above buffer */
1555         u8 *current_position;
1556                 /* Called when this packet command is completed */
1557         ide_startstop_t (*callback) (ide_drive_t *);
1558                 /* Temporary buffer */
1559         u8 pc_buffer[IDE_PC_BUFFER_SIZE];
1560                 /* Status/Action bit flags: long for set_bit */
1561         unsigned long flags;
1562 } ide_pc_t;
1563
1564 ide-cd orthoginal :-/
1565 struct packet_command {
1566         char *buffer;
1567         int buflen;
1568         int stat;
1569         int quiet;
1570         int timeout;
1571         struct request_sense *sense;
1572         unsigned char c[12];
1573 };
1574
1575 #endif
1576
1577 #ifdef CONFIG_PKT_TASK_IOCTL
1578 extern int pkt_taskfile_ioctl(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
1579 #endif /* CONFIG_PKT_TASK_IOCTL */
1580
1581 extern void ide_delay_50ms(void);
1582 extern int system_bus_clock(void);
1583
1584 extern u8 ide_auto_reduce_xfer(ide_drive_t *);
1585 extern int ide_driveid_update(ide_drive_t *);
1586 extern int ide_ata66_check(ide_drive_t *, ide_task_t *);
1587 extern int ide_config_drive_speed(ide_drive_t *, u8);
1588 extern u8 eighty_ninty_three (ide_drive_t *);
1589 extern int set_transfer(ide_drive_t *, ide_task_t *);
1590 extern int taskfile_lib_get_identify(ide_drive_t *drive, u8 *);
1591
1592 extern int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout);
1593 ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq, sector_t block);
1594
1595 /*
1596  * ide_system_bus_speed() returns what we think is the system VESA/PCI
1597  * bus speed (in MHz).  This is used for calculating interface PIO timings.
1598  * The default is 40 for known PCI systems, 50 otherwise.
1599  * The "idebus=xx" parameter can be used to override this value.
1600  */
1601 extern int ide_system_bus_speed(void);
1602
1603 /*
1604  * ide_stall_queue() can be used by a drive to give excess bandwidth back
1605  * to the hwgroup by sleeping for timeout jiffies.
1606  */
1607 extern void ide_stall_queue(ide_drive_t *drive, unsigned long timeout);
1608
1609 extern int ide_spin_wait_hwgroup(ide_drive_t *);
1610 extern void ide_timer_expiry(unsigned long);
1611 extern irqreturn_t 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);
1614
1615 extern struct block_device_operations ide_fops[];
1616 extern ide_proc_entry_t generic_subdriver_entries[];
1617
1618 extern int ata_attach(ide_drive_t *);
1619
1620 extern int ideprobe_init(void);
1621
1622 extern void ide_scan_pcibus(int scan_direction) __init;
1623 extern int ide_pci_register_driver(struct pci_driver *driver);
1624 extern void ide_pci_unregister_driver(struct pci_driver *driver);
1625 extern void ide_pci_setup_ports(struct pci_dev *dev, struct ide_pci_device_s *d, int autodma, int pciirq, ata_index_t *index);
1626 extern void ide_setup_pci_noise (struct pci_dev *dev, struct ide_pci_device_s *d);
1627
1628 extern void default_hwif_iops(ide_hwif_t *);
1629 extern void default_hwif_mmiops(ide_hwif_t *);
1630 extern void default_hwif_transport(ide_hwif_t *);
1631
1632 int ide_register_driver(ide_driver_t *driver);
1633 void ide_unregister_driver(ide_driver_t *driver);
1634 int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version);
1635 int ide_unregister_subdriver (ide_drive_t *drive);
1636 int ide_replace_subdriver(ide_drive_t *drive, const char *driver);
1637
1638 #ifdef CONFIG_PROC_FS
1639 typedef struct ide_pci_host_proc_s {
1640         char                            *name;
1641         u8                              set;
1642         get_info_t                      *get_info;
1643         struct proc_dir_entry           *parent;
1644         struct ide_pci_host_proc_s      *next;
1645 } ide_pci_host_proc_t;
1646
1647 void ide_pci_register_host_proc(ide_pci_host_proc_t *);
1648 #endif /* CONFIG_PROC_FS */
1649
1650 #define ON_BOARD                1
1651 #define NEVER_BOARD             0
1652
1653 #ifdef CONFIG_BLK_DEV_OFFBOARD
1654 #  define OFF_BOARD             ON_BOARD
1655 #else /* CONFIG_BLK_DEV_OFFBOARD */
1656 #  define OFF_BOARD             NEVER_BOARD
1657 #endif /* CONFIG_BLK_DEV_OFFBOARD */
1658
1659 #define NODMA 0
1660 #define NOAUTODMA 1
1661 #define AUTODMA 2
1662 #define EOL 255
1663
1664 typedef struct ide_pci_enablebit_s {
1665         u8      reg;    /* byte pci reg holding the enable-bit */
1666         u8      mask;   /* mask to isolate the enable-bit */
1667         u8      val;    /* value of masked reg when "enabled" */
1668 } ide_pci_enablebit_t;
1669
1670 typedef struct ide_pci_device_s {
1671         u16                     vendor;
1672         u16                     device;
1673         char                    *name;
1674         void                    (*init_setup)(struct pci_dev *, struct ide_pci_device_s *);
1675         void                    (*init_setup_dma)(struct pci_dev *, struct ide_pci_device_s *, ide_hwif_t *);
1676         unsigned int            (*init_chipset)(struct pci_dev *, const char *);
1677         void                    (*init_iops)(ide_hwif_t *);
1678         void                    (*init_hwif)(ide_hwif_t *);
1679         void                    (*init_dma)(ide_hwif_t *, unsigned long);
1680         u8                      channels;
1681         u8                      autodma;
1682         ide_pci_enablebit_t     enablebits[2];
1683         u8                      bootable;
1684         unsigned int            extra;
1685         struct ide_pci_device_s *next;
1686         u8                      isa_ports;      /* Uses ISA control ports not PCI ones */
1687 } ide_pci_device_t;
1688
1689 extern void ide_setup_pci_device(struct pci_dev *, ide_pci_device_t *);
1690 extern void ide_setup_pci_devices(struct pci_dev *, struct pci_dev *, ide_pci_device_t *);
1691
1692 #define BAD_DMA_DRIVE           0
1693 #define GOOD_DMA_DRIVE          1
1694
1695 #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
1696 extern int ide_build_dmatable(ide_drive_t *, struct request *);
1697 extern void ide_destroy_dmatable(ide_drive_t *);
1698 extern ide_startstop_t ide_dma_intr(ide_drive_t *);
1699 extern int ide_release_dma(ide_hwif_t *);
1700 extern void ide_setup_dma(ide_hwif_t *, unsigned long, unsigned int);
1701 extern int ide_start_dma(ide_hwif_t *, ide_drive_t *, int);
1702
1703 extern int __ide_dma_host_off(ide_drive_t *);
1704 extern int __ide_dma_off_quietly(ide_drive_t *);
1705 extern int __ide_dma_off(ide_drive_t *);
1706 extern int __ide_dma_host_on(ide_drive_t *);
1707 extern int __ide_dma_on(ide_drive_t *);
1708 extern int __ide_dma_check(ide_drive_t *);
1709 extern int __ide_dma_read(ide_drive_t *);
1710 extern int __ide_dma_write(ide_drive_t *);
1711 extern int __ide_dma_begin(ide_drive_t *);
1712 extern int __ide_dma_end(ide_drive_t *);
1713 extern int __ide_dma_test_irq(ide_drive_t *);
1714 extern int __ide_dma_bad_drive(ide_drive_t *);
1715 extern int __ide_dma_good_drive(ide_drive_t *);
1716 extern int __ide_dma_count(ide_drive_t *);
1717 extern int __ide_dma_verbose(ide_drive_t *);
1718 extern int __ide_dma_retune(ide_drive_t *);
1719 extern int __ide_dma_lostirq(ide_drive_t *);
1720 extern int __ide_dma_timeout(ide_drive_t *);
1721
1722 #ifdef CONFIG_BLK_DEV_IDE_TCQ
1723 extern int __ide_dma_queued_on(ide_drive_t *drive);
1724 extern int __ide_dma_queued_off(ide_drive_t *drive);
1725 extern ide_startstop_t __ide_dma_queued_read(ide_drive_t *drive);
1726 extern ide_startstop_t __ide_dma_queued_write(ide_drive_t *drive);
1727 extern ide_startstop_t __ide_dma_queued_start(ide_drive_t *drive);
1728 #else
1729 static inline int __ide_dma_queued_on(ide_drive_t *drive)
1730 {
1731         return 1;
1732 }
1733
1734 static inline int __ide_dma_queued_off(ide_drive_t *drive)
1735 {
1736         return 1;
1737 }
1738 #endif
1739
1740 #else
1741 static inline void ide_release_dma(ide_hwif_t *drive) {;}
1742 #endif
1743
1744 extern int ide_hwif_request_regions(ide_hwif_t *hwif);
1745 extern void ide_hwif_release_regions(ide_hwif_t* hwif);
1746 extern void ide_unregister (unsigned int index);
1747
1748 extern int probe_hwif_init(ide_hwif_t *);
1749
1750 static inline void *ide_get_hwifdata (ide_hwif_t * hwif)
1751 {
1752         return hwif->hwif_data;
1753 }
1754
1755 static inline void ide_set_hwifdata (ide_hwif_t * hwif, void *data)
1756 {
1757         hwif->hwif_data = data;
1758 }
1759
1760 /* ide-lib.c */
1761 extern u8 ide_dma_speed(ide_drive_t *drive, u8 mode);
1762 extern u8 ide_rate_filter(u8 mode, u8 speed); 
1763 extern int ide_dma_enable(ide_drive_t *drive);
1764 extern char *ide_xfer_verbose(u8 xfer_rate);
1765 extern void ide_toggle_bounce(ide_drive_t *drive, int on);
1766 extern int ide_set_xfer_rate(ide_drive_t *drive, u8 rate);
1767
1768 typedef struct ide_pio_timings_s {
1769         int     setup_time;     /* Address setup (ns) minimum */
1770         int     active_time;    /* Active pulse (ns) minimum */
1771         int     cycle_time;     /* Cycle time (ns) minimum = (setup + active + recovery) */
1772 } ide_pio_timings_t;
1773
1774 typedef struct ide_pio_data_s {
1775         u8 pio_mode;
1776         u8 use_iordy;
1777         u8 overridden;
1778         u8 blacklisted;
1779         unsigned int cycle_time;
1780 } ide_pio_data_t;
1781
1782 extern u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d);
1783 extern const ide_pio_timings_t ide_pio_timings[6];
1784
1785
1786 extern spinlock_t ide_lock;
1787 extern struct semaphore ide_cfg_sem;
1788 /*
1789  * Structure locking:
1790  *
1791  * ide_cfg_sem and ide_lock together protect changes to
1792  * ide_hwif_t->{next,hwgroup}
1793  * ide_drive_t->next
1794  *
1795  * ide_hwgroup_t->busy: ide_lock
1796  * ide_hwgroup_t->hwif: ide_lock
1797  * ide_hwif_t->mate: constant, no locking
1798  * ide_drive_t->hwif: constant, no locking
1799  */
1800
1801 #define local_irq_set(flags)    do { local_save_flags((flags)); local_irq_enable(); } while (0)
1802
1803 #define IDE_MAX_TAG     32
1804 #ifdef CONFIG_BLK_DEV_IDE_TCQ
1805 static inline int ata_pending_commands(ide_drive_t *drive)
1806 {
1807         if (drive->using_tcq)
1808                 return blk_queue_tag_depth(drive->queue);
1809
1810         return 0;
1811 }
1812
1813 static inline int ata_can_queue(ide_drive_t *drive)
1814 {
1815         if (drive->using_tcq)
1816                 return blk_queue_tag_queue(drive->queue);
1817
1818         return 1;
1819 }
1820 #else
1821 #define ata_pending_commands(drive)     (0)
1822 #define ata_can_queue(drive)            (1)
1823 #endif
1824
1825 extern struct bus_type ide_bus_type;
1826
1827 #endif /* _IDE_H */