added a lot of printk output to ease writing of emulator
[linux-2.4.21-pre4.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/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>
24 #include <asm/io.h>
25
26 #define CLASSIC_BUILTINS_METHOD                         1
27 //#undef CLASSIC_BUILTINS_METHOD
28 #define HWIF_PROBE_CLASSIC_METHOD                       1
29 //#undef HWIF_PROBE_CLASSIC_METHOD
30
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 */
48
49 /*
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.
53  *
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
58  */
59
60 /******************************************************************************
61  * IDE driver configuration options (play with these as desired):
62  *
63  * REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary
64  */
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.. */
67
68 #ifndef SUPPORT_SLOW_DATA_PORTS         /* 1 to support slow data ports */
69 #define SUPPORT_SLOW_DATA_PORTS 1       /* 0 to reduce kernel size */
70 #endif
71 #ifndef SUPPORT_VLB_SYNC                /* 1 to support weird 32-bit chips */
72 #define SUPPORT_VLB_SYNC        1       /* 0 to reduce kernel size */
73 #endif
74 #ifndef DISK_RECOVERY_TIME              /* off=0; on=access_delay_time */
75 #define DISK_RECOVERY_TIME      0       /*  for hardware that needs it */
76 #endif
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 */
79 #endif
80 #ifndef FANCY_STATUS_DUMPS              /* 1 for human-readable drive errors */
81 #define FANCY_STATUS_DUMPS      1       /* 0 to reduce kernel size */
82 #endif
83
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 */
88 #endif
89 #endif  /* CONFIG_BLK_DEV_CMD640 */
90
91 #ifndef DISABLE_IRQ_NOSYNC
92 #define DISABLE_IRQ_NOSYNC      0
93 #endif
94
95 /*
96  * IDE_DRIVE_CMD is used to implement many features of the hdparm utility
97  */
98 #define IDE_DRIVE_CMD                   99      /* (magic) undef to reduce kernel size*/
99
100 #define IDE_DRIVE_TASK                  98
101
102 /*
103  * IDE_DRIVE_TASKFILE is used to implement many features needed for raw tasks
104  */
105 #define IDE_DRIVE_TASKFILE              97
106
107 /*
108  *  "No user-serviceable parts" beyond this point  :)
109  *****************************************************************************/
110
111 typedef unsigned char   byte;   /* used everywhere */
112
113 /*
114  * Probably not wise to fiddle with these
115  */
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 */
119
120 /*
121  * Tune flags
122  */
123 #define IDE_TUNE_BIOS           3
124 #define IDE_TUNE_NOAUTO         2
125 #define IDE_TUNE_AUTO           1
126 #define IDE_TUNE_DEFAULT        0
127
128 /*
129  * state flags
130  */
131
132 #define DMA_PIO_RETRY   1       /* retrying in PIO */
133
134 /*
135  * Ensure that various configuration flags have compatible settings
136  */
137 #ifdef REALLY_SLOW_IO
138 #undef REALLY_FAST_IO
139 #endif
140
141 #define HWIF(drive)             ((ide_hwif_t *)((drive)->hwif))
142 #define HWGROUP(drive)          ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
143
144 /*
145  * Definitions for accessing IDE controller registers
146  */
147 #define IDE_NR_PORTS            (10)
148
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)
159
160 #define IDE_FEATURE_OFFSET      IDE_ERROR_OFFSET
161 #define IDE_COMMAND_OFFSET      IDE_STATUS_OFFSET
162
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)
171
172 #define IDE_FEATURE_OFFSET_HOB  IDE_ERROR_OFFSET_HOB
173
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])
184
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])
194
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
201
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)
208
209 #define BAD_CRC                 (ABRT_ERR    | ICRC_ERR)
210
211 #define SATA_NR_PORTS           (3)     /* 16 possible ?? */
212
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])
219
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])
226
227 /*
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.
234  *
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.
238  *
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.
242  */
243 #define PRD_BYTES       8
244 #define PRD_ENTRIES     (PAGE_SIZE / (2 * PRD_BYTES))
245
246 /*
247  * Some more useful definitions
248  */
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))
259
260 /*
261  * Timeouts for various operations:
262  */
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 */
266 #else
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 */
273
274 #define HOST(hwif,chipset)                                      \
275 {                                                               \
276         return ((hwif)->chipset == chipset) ? 1 : 0;            \
277 }
278
279 #define IDE_DEBUG(lineno) \
280         printk("%s,%s,line=%d\n", __FILE__, __FUNCTION__, (lineno))
281
282 /*
283  * Check for an interrupt and acknowledge the interrupt status
284  */
285 struct hwif_s;
286 typedef int (ide_ack_intr_t)(struct hwif_s *);
287
288 #ifndef NO_DMA
289 #define NO_DMA  255
290 #endif
291
292 /*
293  * hwif_chipset_t is used to keep track of the specific hardware
294  * chipset used by each IDE interface, if known.
295  */
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
302 } hwif_chipset_t;
303
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);
311
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);
317 } ide_io_ops_t;
318
319 /*
320  * Structure to hold all information about the location of this port
321  */
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;
329 #if 0
330         ide_io_ops_t    *iops;                  /* */
331 #endif
332         sata_ioreg_t    sata_scr[SATA_NR_PORTS];
333         sata_ioreg_t    sata_misc[SATA_NR_PORTS];
334 } hw_regs_t;
335
336 /*
337  * Register new hardware with ide
338  */
339 int ide_register_hw(hw_regs_t *hw, struct hwif_s **hwifp);
340
341 /*
342  * Set up hw_regs_t structure before calling ide_register_hw (optional)
343  */
344 void ide_setup_ports(   hw_regs_t *hw,
345                         ide_ioreg_t base,
346                         int *offsets,
347                         ide_ioreg_t ctrl,
348                         ide_ioreg_t intr,
349                         ide_ack_intr_t *ack_intr,
350 #if 0
351                         ide_io_ops_t *iops,
352 #endif
353                         int irq);
354
355 #include <asm/ide.h>
356
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)
361 #else
362 # define ide_ack_intr(hwif) (1)
363 #endif
364
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 */
370
371 /*
372  * Now for the data we need to maintain per-drive:  ide_drive_t
373  */
374
375 #define ide_scsi        0x21
376 #define ide_disk        0x20
377 #define ide_optical     0x7
378 #define ide_cdrom       0x5
379 #define ide_tape        0x1
380 #define ide_floppy      0x0
381
382 /*
383  * Special Driver Flags
384  *
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
390  * reserved     : unused
391  */
392 typedef union {
393         unsigned all                    : 8;
394         struct {
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;
409 #else
410 #error "Please fix <asm/byteorder.h>"
411 #endif
412         } b;
413 } special_t;
414
415 /*
416  * ATA DATA Register Special.
417  * ATA NSECTOR Count Register().
418  * ATAPI Byte Count Register.
419  * Channel index ordering pairs.
420  */
421 typedef union {
422         unsigned all                    :16;
423         struct {
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 */
430 #else
431 #error "Please fix <asm/byteorder.h>"
432 #endif
433         } b;
434 } ata_nsector_t, ata_data_t, atapi_bcount_t, ata_index_t;
435
436 /*
437  * ATA-IDE Error Register
438  *
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
446  * bdd          : dual meaing
447  */
448 typedef union {
449         unsigned all                    :8;
450         struct {
451 #if defined(__LITTLE_ENDIAN_BITFIELD)
452                 unsigned mark           :1;
453                 unsigned tzero          :1;
454                 unsigned abrt           :1;
455                 unsigned mcr            :1;
456                 unsigned id             :1;
457                 unsigned mce            :1;
458                 unsigned ecc            :1;
459                 unsigned bdd            :1;
460 #elif defined(__BIG_ENDIAN_BITFIELD)
461                 unsigned bdd            :1;
462                 unsigned ecc            :1;
463                 unsigned mce            :1;
464                 unsigned id             :1;
465                 unsigned mcr            :1;
466                 unsigned abrt           :1;
467                 unsigned tzero          :1;
468                 unsigned mark           :1;
469 #else
470 #error "Please fix <asm/byteorder.h>"
471 #endif
472         } b;
473 } ata_error_t;
474
475 /*
476  * ATA-IDE Select Register, aka Device-Head
477  *
478  * head         : always zeros here
479  * unit         : drive select number: 0/1
480  * bit5         : always 1
481  * lba          : using LBA instead of CHS
482  * bit7         : always 1
483  */
484 typedef union {
485         unsigned all                    : 8;
486         struct {
487 #if defined(__LITTLE_ENDIAN_BITFIELD)
488                 unsigned head           : 4;
489                 unsigned unit           : 1;
490                 unsigned bit5           : 1;
491                 unsigned lba            : 1;
492                 unsigned bit7           : 1;
493 #elif defined(__BIG_ENDIAN_BITFIELD)
494                 unsigned bit7           : 1;
495                 unsigned lba            : 1;
496                 unsigned bit5           : 1;
497                 unsigned unit           : 1;
498                 unsigned head           : 4;
499 #else
500 #error "Please fix <asm/byteorder.h>"
501 #endif
502         } b;
503 } select_t, ata_select_t;
504
505 /*
506  * The ATA-IDE Status Register.
507  * The ATAPI Status Register.
508  *
509  * check        : Error occurred
510  * idx          : Index Error
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
516  *              : Reserved                              : atapi
517  * drdy         : Ready, Command Mode Capable           : ata
518  *              : Ignored for ATAPI commands            : atapi
519  * bsy          : Disk is Busy
520  *              : The device has access to the command block
521  */
522 typedef union {
523         unsigned all                    :8;
524         struct {
525 #if defined(__LITTLE_ENDIAN_BITFIELD)
526                 unsigned check          :1;
527                 unsigned idx            :1;
528                 unsigned corr           :1;
529                 unsigned drq            :1;
530                 unsigned dsc            :1;
531                 unsigned df             :1;
532                 unsigned drdy           :1;
533                 unsigned bsy            :1;
534 #elif defined(__BIG_ENDIAN_BITFIELD)
535                 unsigned bsy            :1;
536                 unsigned drdy           :1;
537                 unsigned df             :1;
538                 unsigned dsc            :1;
539                 unsigned drq            :1;
540                 unsigned corr           :1;
541                 unsigned idx            :1;
542                 unsigned check          :1;
543 #else
544 #error "Please fix <asm/byteorder.h>"
545 #endif
546         } b;
547 } ata_status_t, atapi_status_t;
548
549 /*
550  * ATA-IDE Control Register
551  *
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
558  */
559 typedef union {
560         unsigned all                    : 8;
561         struct {
562 #if defined(__LITTLE_ENDIAN_BITFIELD)
563                 unsigned bit0           : 1;
564                 unsigned nIEN           : 1;
565                 unsigned SRST           : 1;
566                 unsigned bit3           : 1;
567                 unsigned reserved456    : 3;
568                 unsigned HOB            : 1;
569 #elif defined(__BIG_ENDIAN_BITFIELD)
570                 unsigned HOB            : 1;
571                 unsigned reserved456    : 3;
572                 unsigned bit3           : 1;
573                 unsigned SRST           : 1;
574                 unsigned nIEN           : 1;
575                 unsigned bit0           : 1;
576 #else
577 #error "Please fix <asm/byteorder.h>"
578 #endif
579         } b;
580 } ata_control_t;
581
582 /*
583  * ATAPI Feature Register
584  *
585  * dma          : Using DMA or PIO
586  * reserved321  : Reserved
587  * reserved654  : Reserved (Tag Type)
588  * reserved7    : Reserved
589  */
590 typedef union {
591         unsigned all                    :8;
592         struct {
593 #if defined(__LITTLE_ENDIAN_BITFIELD)
594                 unsigned dma            :1;
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;
602                 unsigned dma            :1;
603 #else
604 #error "Please fix <asm/byteorder.h>"
605 #endif
606         } b;
607 } atapi_feature_t;
608
609 /*
610  * ATAPI Interrupt Reason Register.
611  *
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
615  */
616 typedef union {
617         unsigned all                    :8;
618         struct {
619 #if defined(__LITTLE_ENDIAN_BITFIELD)
620                 unsigned cod            :1;
621                 unsigned io             :1;
622                 unsigned reserved       :6;
623 #elif defined(__BIG_ENDIAN_BITFIELD)
624                 unsigned reserved       :6;
625                 unsigned io             :1;
626                 unsigned cod            :1;
627 #else
628 #error "Please fix <asm/byteorder.h>"
629 #endif
630         } b;
631 } atapi_ireason_t;
632
633 /*
634  * The ATAPI error register.
635  *
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
641  */
642 typedef union {
643         unsigned all                    :8;
644         struct {
645 #if defined(__LITTLE_ENDIAN_BITFIELD)
646                 unsigned ili            :1;
647                 unsigned eom            :1;
648                 unsigned abrt           :1;
649                 unsigned mcr            :1;
650                 unsigned sense_key      :4;
651 #elif defined(__BIG_ENDIAN_BITFIELD)
652                 unsigned sense_key      :4;
653                 unsigned mcr            :1;
654                 unsigned abrt           :1;
655                 unsigned eom            :1;
656                 unsigned ili            :1;
657 #else
658 #error "Please fix <asm/byteorder.h>"
659 #endif
660         } b;
661 } atapi_error_t;
662
663 /*
664  * ATAPI floppy Drive Select Register
665  *
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
672  */
673 typedef union {
674         unsigned all                    :8;
675         struct {
676 #if defined(__LITTLE_ENDIAN_BITFIELD)
677                 unsigned sam_lun        :3;
678                 unsigned reserved3      :1;
679                 unsigned drv            :1;
680                 unsigned one5           :1;
681                 unsigned reserved6      :1;
682                 unsigned one7           :1;
683 #elif defined(__BIG_ENDIAN_BITFIELD)
684                 unsigned one7           :1;
685                 unsigned reserved6      :1;
686                 unsigned one5           :1;
687                 unsigned drv            :1;
688                 unsigned reserved3      :1;
689                 unsigned sam_lun        :3;
690 #else
691 #error "Please fix <asm/byteorder.h>"
692 #endif
693         } b;
694 } atapi_select_t;
695
696 struct ide_driver_s;
697 struct ide_settings_s;
698
699 typedef struct ide_drive_s {
700         char            name[4];        /* drive name, such as "hda" */
701         char            driver_req[10]; /* requests specific driver */
702
703         request_queue_t         queue;  /* request queue */
704
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 */
715
716         struct hwif_s           *hwif;  /* actually (ide_hwif_t *) */
717
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 */
722
723         special_t       special;        /* special action flags */
724         select_t        select;         /* basic drive/head select reg value */
725
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 */
738
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;
758                                          *  0=28-bit
759                                          *  1=48-bit
760                                          *  2=48-bit doing 28-bit
761                                          *  3=64-bit
762                                          */
763
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 */
787
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 */
794
795         u32             capacity;       /* total number of sectors */
796         u64             capacity48;     /* total number of sectors */
797
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 */
802 } ide_drive_t;
803
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);
807
808         void (*atapi_input_bytes)(ide_drive_t *, void *, u32);
809         void (*atapi_output_bytes)(ide_drive_t *, void *, u32);
810 } ide_pio_ops_t;
811
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);
832 } ide_dma_ops_t;
833
834 /*
835  * mapping stuff, prepare for highmem...
836  *
837  * temporarily mapping a (possible) highmem bio for PIO transfer
838  */
839 #define ide_rq_offset(rq) \
840         (((rq)->hard_cur_sectors - (rq)->current_nr_sectors) << 9)
841
842 extern inline void *ide_map_buffer(struct request *rq, unsigned long *flags)
843 {
844         return bh_kmap_irq(rq->bh, flags) + ide_rq_offset(rq);
845 }
846
847 extern inline void ide_unmap_buffer(char *buffer, unsigned long *flags)
848 {
849         bh_kunmap_irq(buffer, flags);
850 }
851
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)
855
856 struct ide_pci_device_s;
857
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 */
864
865         char name[6];                   /* name of interface, eg. "ide0" */
866
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];
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 #if 0
892         ide_hwif_ops_t  *hwifops;
893 #else
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);
920 #endif
921
922 #if 0
923         ide_pio_ops_t   *pioops;
924 #else
925         void (*ata_input_data)(ide_drive_t *, void *, u32);
926         void (*ata_output_data)(ide_drive_t *, void *, u32);
927
928         void (*atapi_input_bytes)(ide_drive_t *, void *, u32);
929         void (*atapi_output_bytes)(ide_drive_t *, void *, u32);
930 #endif
931
932 #if 0
933         ide_dma_ops_t   *dmaops;
934 #else
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);
953 #endif
954
955 #if 0
956         ide_io_ops_t    *iops;
957 #else
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);
963
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);
969 #endif
970
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 */
980
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 */
986
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 */
995
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 */
1001 #endif
1002
1003
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 */
1013
1014         void            *hwif_data;     /* extra hwif data */
1015 } ide_hwif_t;
1016
1017 /*
1018  * Status returned from various ide_ functions
1019  */
1020 typedef enum {
1021         ide_stopped,    /* no drive operation was started */
1022         ide_started     /* a drive operation was started, handler was set */
1023 } ide_startstop_t;
1024
1025 /*
1026  *  internal ide interrupt handler type
1027  */
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 *);
1032
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 */
1039         volatile int busy;
1040                 /* BOOL: wake us up on timer expiry */
1041         int sleeping;
1042                 /* current drive */
1043         ide_drive_t *drive;
1044                 /* ptr to current hwif in linked-list */
1045         ide_hwif_t *hwif;
1046
1047                 /* for pci chipsets */
1048         struct pci_dev *pci_dev;
1049                 /* chipset device struct */
1050         struct ide_pci_device_s *cds;
1051
1052                 /* current request */
1053         struct request *rq;
1054                 /* failsafe timer */
1055         struct timer_list timer;
1056                 /* local copy of current write rq */
1057         struct request wrq;
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 */
1063         int pio_clock;
1064 } ide_hwgroup_t;
1065
1066 /* structure attached to the request for IDE_TASK_CMDS */
1067
1068 /*
1069  * configurable drive settings
1070  */
1071
1072 #define TYPE_INT        0
1073 #define TYPE_INTA       1
1074 #define TYPE_BYTE       2
1075 #define TYPE_SHORT      3
1076
1077 #define SETTING_READ    (1 << 0)
1078 #define SETTING_WRITE   (1 << 1)
1079 #define SETTING_RW      (SETTING_READ | SETTING_WRITE)
1080
1081 typedef int (ide_procset_t)(ide_drive_t *, int);
1082 typedef struct ide_settings_s {
1083         char                    *name;
1084         int                     rw;
1085         int                     read_ioctl;
1086         int                     write_ioctl;
1087         int                     data_type;
1088         int                     min;
1089         int                     max;
1090         int                     mul_factor;
1091         int                     div_factor;
1092         void                    *data;
1093         ide_procset_t           *set;
1094         int                     auto_remove;
1095         struct ide_settings_s   *next;
1096 } ide_settings_t;
1097
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);
1104
1105 /*
1106  * /proc/ide interface
1107  */
1108 typedef struct {
1109         const char      *name;
1110         mode_t          mode;
1111         read_proc_t     *read_proc;
1112         write_proc_t    *write_proc;
1113 } ide_proc_entry_t;
1114
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;
1126
1127 /*
1128  * Standard exit stuff:
1129  */
1130 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \
1131 {                                       \
1132         len -= off;                     \
1133         if (len < count) {              \
1134                 *eof = 1;               \
1135                 if (len <= 0)           \
1136                         return 0;       \
1137         } else                          \
1138                 len = count;            \
1139         *start = page + off;            \
1140         return len;                     \
1141 }
1142 #else
1143 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
1144 #endif
1145
1146 /*
1147  * Subdrivers support.
1148  */
1149 #define IDE_SUBDRIVER_VERSION   1
1150
1151 typedef struct ide_driver_s {
1152         const char                      *name;
1153         const char                      *version;
1154         u8                              media;
1155         unsigned busy                   : 1;
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;
1177         int             (*init)(void);
1178         int             (*attach)(ide_drive_t *);
1179         void            (*ata_prebuilder)(ide_drive_t *);
1180         void            (*atapi_prebuilder)(ide_drive_t *);
1181 } ide_driver_t;
1182
1183 #define DRIVER(drive)           ((drive)->driver)
1184
1185 /*
1186  * IDE modules.
1187  */
1188 #define IDE_CHIPSET_MODULE              0       /* not supported yet */
1189 #define IDE_PROBE_MODULE                1
1190 #define IDE_DRIVER_MODULE               2
1191
1192 typedef int     (ide_module_init_proc)(void);
1193
1194 typedef struct ide_module_s {
1195         int                             type;
1196         ide_module_init_proc            *init;
1197         void                            *info;
1198         struct ide_module_s             *next;
1199 } ide_module_t;
1200
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;
1206 } ide_devices_t;
1207
1208 #if 0
1209 typedef enum {
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,
1216 } ide_media_type;
1217
1218 struct ide_media {
1219         ide_media_type type;
1220         char name[4];
1221         atomic_t refcount;      /* Maybe this should be a struct module*
1222                                    with MOD_INC instead */
1223         struct list_head devices;
1224 };
1225
1226 struct {
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;
1233 } ide_medias;
1234
1235 void __init init_media(void)
1236 {
1237         memset(&ide_medias, 0, sizeof(ide_medias));
1238
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;
1245 };
1246 #endif
1247
1248 /*
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!).
1254  *
1255  */
1256 #ifndef _IDE_C
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;
1261
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;
1267
1268 #endif
1269 extern int noautodma;
1270
1271 /*
1272  * We need blk.h, but we replace its end_request by our own version.
1273  */
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>
1278
1279 extern int ide_end_request(ide_drive_t *, int /* uptodate */);
1280
1281 /*
1282  * This is used on exit from the driver, to designate the next irq handler
1283  * and also to start the safety timer.
1284  */
1285 extern void ide_set_handler(ide_drive_t *, ide_handler_t *, unsigned int, ide_expiry_t *);
1286
1287 /*
1288  * Error reporting, in human readable form (luxurious, but a memory hog).
1289  *
1290  * (drive, msg, status)
1291  */
1292 extern u8 ide_dump_status(ide_drive_t *, const char *, u8);
1293
1294 /*
1295  * ide_error() takes action based on the error returned by the controller.
1296  * The caller should return immediately after invoking this.
1297  *
1298  * (drive, msg, status)
1299  */
1300 extern ide_startstop_t ide_error(ide_drive_t *, const char *, u8);
1301
1302 /*
1303  * Issue a simple drive command
1304  * The drive must be selected beforehand.
1305  *
1306  * (drive, command, nsector, handler)
1307  */
1308 extern void ide_cmd(ide_drive_t *, u8, u8, ide_handler_t *);
1309
1310 extern void ide_fix_driveid(struct hd_driveid *);
1311 /*
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.
1316  *
1317  * (s, bytecount, byteswap)
1318  */
1319 extern void ide_fixstring(u8 *, const int, const int);
1320
1321 /*
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)
1329  */
1330 extern int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long);
1331
1332 /*
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.
1335  */
1336 extern int ide_xlate_1024(kdev_t, int, int, const char *);
1337
1338 /*
1339  * Convert kdev_t structure into ide_drive_t * one.
1340  */
1341 extern ide_drive_t *get_info_ptr(kdev_t i_rdev);
1342
1343 /*
1344  * Return the current idea about the total capacity of this drive.
1345  */
1346 extern unsigned long current_capacity(ide_drive_t *);
1347
1348 extern void ide_revalidate_drive(ide_drive_t *);
1349
1350 /*
1351  * Start a reset operation for an IDE interface.
1352  * The caller should return immediately after invoking this.
1353  */
1354 extern ide_startstop_t ide_do_reset(ide_drive_t *);
1355
1356 /*
1357  * Re-Start an operation for an IDE interface.
1358  * The caller should return immediately after invoking this.
1359  */
1360 extern int restart_request(ide_drive_t *, struct request *);
1361
1362 /*
1363  * This function is intended to be used prior to invoking ide_do_drive_cmd().
1364  */
1365 extern void ide_init_drive_cmd(struct request *);
1366
1367 /*
1368  * "action" parameter type for ide_do_drive_cmd() below.
1369  */
1370 typedef enum {
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 */
1375 } ide_action_t;
1376
1377 /*
1378  * This function issues a special IDE device request
1379  * onto the request queue.
1380  *
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.
1384  *
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.
1390  *
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.
1396  *
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.
1401  */
1402 extern int ide_do_drive_cmd(ide_drive_t *, struct request *, ide_action_t);
1403
1404 /*
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).
1408  *
1409  * (ide_drive_t *drive, u8 stat, u8 err)
1410  */
1411 extern void ide_end_drive_cmd(ide_drive_t *, u8, u8);
1412
1413 /*
1414  * Issue ATA command and wait for completion.
1415  * Use for implementing commands in kernel
1416  *
1417  *  (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
1418  */
1419 extern int ide_wait_cmd(ide_drive_t *, u8, u8, u8, u8, u8 *);
1420
1421 /* (ide_drive_t *drive, u8 *buf) */
1422 extern int ide_wait_cmd_task(ide_drive_t *, u8 *);
1423
1424 typedef struct ide_task_s {
1425 /*
1426  *      struct hd_drive_task_hdr        tf;
1427  *      task_struct_t           tf;
1428  *      struct hd_drive_hob_hdr         hobf;
1429  *      hob_struct_t            hobf;
1430  */
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;
1435         int                     data_phase;
1436         int                     command_type;
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 */
1442 } ide_task_t;
1443
1444 typedef struct pkt_task_s {
1445 /*
1446  *      struct hd_drive_task_hdr        pktf;
1447  *      task_struct_t           pktf;
1448  *      u8                      pkcdb[12];
1449  */
1450         task_ioreg_t            tfRegister[8];
1451         int                     data_phase;
1452         int                     command_type;
1453         ide_handler_t           *handler;
1454         struct request          *rq;            /* copy of request */
1455         void                    *special;
1456 } pkt_task_t;
1457
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 *);
1462
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);
1469
1470 extern int drive_is_ready(ide_drive_t *);
1471 extern int wait_for_ready(ide_drive_t *, int /* timeout */);
1472
1473 /*
1474  * taskfile io for disks for now...and builds request from ide_ioctl
1475  */
1476 extern ide_startstop_t do_rw_taskfile(ide_drive_t *, ide_task_t *);
1477
1478 /* (ide_drive_t *drive, u8 stat, u8 err) */
1479 extern void ide_end_taskfile(ide_drive_t *, u8, u8);
1480
1481 /*
1482  * Special Flagged Register Validation Caller
1483  */
1484 extern ide_startstop_t flagged_taskfile(ide_drive_t *, ide_task_t *);
1485
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 *);
1497
1498 extern int ide_raw_taskfile(ide_drive_t *, ide_task_t *, u8 *);
1499
1500 extern ide_pre_handler_t * ide_pre_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1501
1502 extern ide_handler_t * ide_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1503
1504 extern ide_post_handler_t * ide_post_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1505
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 *);
1508
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);
1512
1513 #if 0
1514
1515 #define IDEFLOPPY_PC_BUFFER_SIZE        256
1516 #define IDETAPE_PC_BUFFER_SIZE          256
1517 #define IDE_PC_BUFFER_SIZE          256
1518
1519 typedef struct ide_packet_command_s {
1520                 /* Actual packet bytes */
1521         u8 c[12];
1522                 /* On each retry, we increment retries */
1523         int retries;
1524                 /* Error code */
1525         int error;
1526                 /* Bytes to transfer */
1527         int request_transfer;
1528                 /* Bytes actually transferred */
1529         int actually_transferred;
1530                 /* Size of our data buffer */
1531         int buffer_size;
1532
1533         struct buffer_head *bh;
1534         u8 *b_data;
1535                 /* The corresponding request */
1536         struct request *rq;
1537 # if 0
1538                 /* Scatter gather table */
1539         struct scatterlist *sg;
1540 # endif
1541         int b_count;
1542                 /* Data buffer */
1543         u8 *buffer;
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;
1552 } ide_pc_t;
1553
1554 ide-cd orthoginal :-/
1555 struct packet_command {
1556         char *buffer;
1557         int buflen;
1558         int stat;
1559         int quiet;
1560         int timeout;
1561         struct request_sense *sense;
1562         unsigned char c[12];
1563 };
1564
1565 #endif
1566
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 */
1570
1571 extern void ide_delay_50ms(void);
1572 extern int system_bus_clock(void);
1573
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 *);
1581
1582 /*
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.
1587  */
1588 extern int ide_system_bus_speed(void);
1589
1590 /*
1591  * ide_stall_queue() can be used by a drive to give excess bandwidth back
1592  * to the hwgroup by sleeping for timeout jiffies.
1593  */
1594 extern void ide_stall_queue(ide_drive_t *, unsigned long);
1595
1596 /*
1597  * ide_get_queue() returns the queue which corresponds to a given device.
1598  */
1599 extern request_queue_t *ide_get_queue(kdev_t dev);
1600
1601 /*
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
1605  * config bits.
1606  */
1607 extern int drive_is_flashcard(ide_drive_t *);
1608
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);
1614
1615 extern struct block_device_operations ide_fops[];
1616 extern ide_proc_entry_t generic_subdriver_entries[];
1617
1618 extern int ide_attach_drive(ide_drive_t *);
1619
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);
1631
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);
1635
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 *);
1639
1640
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*/);
1647
1648 #ifdef CONFIG_PROC_FS
1649 typedef struct ide_pci_host_proc_s {
1650         char                            *name;
1651         u8                              set;
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;
1656
1657 void ide_pci_register_host_proc(ide_pci_host_proc_t *);
1658 #endif /* CONFIG_PROC_FS */
1659
1660 #define ON_BOARD                1
1661 #define NEVER_BOARD             0
1662
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 */
1668
1669 #define NODMA 0
1670 #define NOAUTODMA 1
1671 #define AUTODMA 2
1672 #define EOL 255
1673
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;
1679
1680 typedef struct ide_pci_device_s {
1681         u16                     vendor;
1682         u16                     device;
1683         char                    *name;
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);
1689         u8                      channels;
1690         u8                      autodma;
1691         ide_pci_enablebit_t     enablebits[2];
1692         u8                      bootable;
1693         unsigned int            extra;
1694         struct ide_pci_device_s *next;
1695 } ide_pci_device_t;
1696
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 *);
1699
1700 #define BAD_DMA_DRIVE           0
1701 #define GOOD_DMA_DRIVE          1
1702
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);
1709
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 *);
1728 #else
1729 static inline void ide_release_dma(ide_hwif_t *x) {;}
1730 #endif
1731
1732 extern void hwif_unregister(ide_hwif_t *);
1733
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 *);
1737
1738 static inline void *ide_get_hwifdata (ide_hwif_t * hwif)
1739 {
1740         return hwif->hwif_data;
1741 }
1742
1743 static inline void ide_set_hwifdata (ide_hwif_t * hwif, void *data)
1744 {
1745         hwif->hwif_data = data;
1746 }
1747
1748 /* ide-lib.c */
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);
1755
1756 #define ide_lock                (io_request_lock)
1757 #define DRIVE_LOCK(drive)       ((drive)->queue.queue_lock)
1758
1759
1760 #endif /* _IDE_H */