source: svn/trunk/newcon3bcm2_21bu/toolchain/mipsel-linux-uclibc/include/linux/ide.h @ 52

Last change on this file since 52 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 13.9 KB
Line 
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/init.h>
10#include <linux/ioport.h>
11#include <linux/hdreg.h>
12#include <linux/hdsmart.h>
13#include <linux/proc_fs.h>
14#include <linux/interrupt.h>
15#include <linux/bitops.h>
16#include <linux/device.h>
17#include <linux/pci.h>
18#include <endian.h>
19#include <byteswap.h>
20#include <asm/system.h>
21#include <asm/io.h>
22#include <asm/semaphore.h>
23
24/*
25 * This is the multiple IDE interface driver, as evolved from hd.c.
26 * It supports up to four IDE interfaces, on one or more IRQs (usually 14 & 15).
27 * There can be up to two drives per interface, as per the ATA-2 spec.
28 *
29 * Primary i/f:    ide0: major=3;  (hda)         minor=0; (hdb)         minor=64
30 * Secondary i/f:  ide1: major=22; (hdc or hd1a) minor=0; (hdd or hd1b) minor=64
31 * Tertiary i/f:   ide2: major=33; (hde)         minor=0; (hdf)         minor=64
32 * Quaternary i/f: ide3: major=34; (hdg)         minor=0; (hdh)         minor=64
33 */
34
35/******************************************************************************
36 * IDE driver configuration options (play with these as desired):
37 *
38 * REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary
39 */
40#define INITIAL_MULT_COUNT      0       /* off=0; on=2,4,8,16,32, etc.. */
41
42#ifndef SUPPORT_SLOW_DATA_PORTS         /* 1 to support slow data ports */
43#define SUPPORT_SLOW_DATA_PORTS 1       /* 0 to reduce kernel size */
44#endif
45#ifndef SUPPORT_VLB_SYNC                /* 1 to support weird 32-bit chips */
46#define SUPPORT_VLB_SYNC        1       /* 0 to reduce kernel size */
47#endif
48#ifndef OK_TO_RESET_CONTROLLER          /* 1 needed for good error recovery */
49#define OK_TO_RESET_CONTROLLER  1       /* 0 for use with AH2372A/B interface */
50#endif
51
52#ifndef DISABLE_IRQ_NOSYNC
53#define DISABLE_IRQ_NOSYNC      0
54#endif
55
56/*
57 * Used to indicate "no IRQ", should be a value that cannot be an IRQ
58 * number.
59 */
60 
61#define IDE_NO_IRQ              (-1)
62
63/*
64 *  "No user-serviceable parts" beyond this point  :)
65 *****************************************************************************/
66
67typedef unsigned char   byte;   /* used everywhere */
68
69/*
70 * Probably not wise to fiddle with these
71 */
72#define ERROR_MAX       8       /* Max read/write errors per sector */
73#define ERROR_RESET     3       /* Reset controller every 4th retry */
74#define ERROR_RECAL     1       /* Recalibrate every 2nd retry */
75
76/*
77 * Tune flags
78 */
79#define IDE_TUNE_NOAUTO         2
80#define IDE_TUNE_AUTO           1
81#define IDE_TUNE_DEFAULT        0
82
83/*
84 * state flags
85 */
86
87#define DMA_PIO_RETRY   1       /* retrying in PIO */
88
89#define HWIF(drive)             ((ide_hwif_t *)((drive)->hwif))
90#define HWGROUP(drive)          ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
91
92/*
93 * Definitions for accessing IDE controller registers
94 */
95#define IDE_NR_PORTS            (10)
96
97#define IDE_DATA_OFFSET         (0)
98#define IDE_ERROR_OFFSET        (1)
99#define IDE_NSECTOR_OFFSET      (2)
100#define IDE_SECTOR_OFFSET       (3)
101#define IDE_LCYL_OFFSET         (4)
102#define IDE_HCYL_OFFSET         (5)
103#define IDE_SELECT_OFFSET       (6)
104#define IDE_STATUS_OFFSET       (7)
105#define IDE_CONTROL_OFFSET      (8)
106#define IDE_IRQ_OFFSET          (9)
107
108#define IDE_FEATURE_OFFSET      IDE_ERROR_OFFSET
109#define IDE_COMMAND_OFFSET      IDE_STATUS_OFFSET
110
111#define IDE_CONTROL_OFFSET_HOB  (7)
112
113#define IDE_DATA_REG            (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
114#define IDE_ERROR_REG           (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
115#define IDE_NSECTOR_REG         (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
116#define IDE_SECTOR_REG          (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
117#define IDE_LCYL_REG            (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
118#define IDE_HCYL_REG            (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
119#define IDE_SELECT_REG          (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
120#define IDE_STATUS_REG          (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
121#define IDE_CONTROL_REG         (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
122#define IDE_IRQ_REG             (HWIF(drive)->io_ports[IDE_IRQ_OFFSET])
123
124#define IDE_FEATURE_REG         IDE_ERROR_REG
125#define IDE_COMMAND_REG         IDE_STATUS_REG
126#define IDE_ALTSTATUS_REG       IDE_CONTROL_REG
127#define IDE_IREASON_REG         IDE_NSECTOR_REG
128#define IDE_BCOUNTL_REG         IDE_LCYL_REG
129#define IDE_BCOUNTH_REG         IDE_HCYL_REG
130
131#define OK_STAT(stat,good,bad)  (((stat)&((good)|(bad)))==(good))
132#define BAD_R_STAT              (BUSY_STAT   | ERR_STAT)
133#define BAD_W_STAT              (BAD_R_STAT  | WRERR_STAT)
134#define BAD_STAT                (BAD_R_STAT  | DRQ_STAT)
135#define DRIVE_READY             (READY_STAT  | SEEK_STAT)
136#define DATA_READY              (DRQ_STAT)
137
138#define BAD_CRC                 (ABRT_ERR    | ICRC_ERR)
139
140#define SATA_NR_PORTS           (3)     /* 16 possible ?? */
141
142#define SATA_STATUS_OFFSET      (0)
143#define SATA_STATUS_REG         (HWIF(drive)->sata_scr[SATA_STATUS_OFFSET])
144#define SATA_ERROR_OFFSET       (1)
145#define SATA_ERROR_REG          (HWIF(drive)->sata_scr[SATA_ERROR_OFFSET])
146#define SATA_CONTROL_OFFSET     (2)
147#define SATA_CONTROL_REG        (HWIF(drive)->sata_scr[SATA_CONTROL_OFFSET])
148
149#define SATA_MISC_OFFSET        (0)
150#define SATA_MISC_REG           (HWIF(drive)->sata_misc[SATA_MISC_OFFSET])
151#define SATA_PHY_OFFSET         (1)
152#define SATA_PHY_REG            (HWIF(drive)->sata_misc[SATA_PHY_OFFSET])
153#define SATA_IEN_OFFSET         (2)
154#define SATA_IEN_REG            (HWIF(drive)->sata_misc[SATA_IEN_OFFSET])
155
156/*
157 * Our Physical Region Descriptor (PRD) table should be large enough
158 * to handle the biggest I/O request we are likely to see.  Since requests
159 * can have no more than 256 sectors, and since the typical blocksize is
160 * two or more sectors, we could get by with a limit of 128 entries here for
161 * the usual worst case.  Most requests seem to include some contiguous blocks,
162 * further reducing the number of table entries required.
163 *
164 * The driver reverts to PIO mode for individual requests that exceed
165 * this limit (possible with 512 byte blocksizes, eg. MSDOS f/s), so handling
166 * 100% of all crazy scenarios here is not necessary.
167 *
168 * As it turns out though, we must allocate a full 4KB page for this,
169 * so the two PRD tables (ide0 & ide1) will each get half of that,
170 * allowing each to have about 256 entries (8 bytes each) from this.
171 */
172#define PRD_BYTES       8
173#define PRD_ENTRIES     256
174
175/*
176 * Some more useful definitions
177 */
178#define PARTN_BITS      6       /* number of minor dev bits for partitions */
179#define MAX_DRIVES      2       /* per interface; 2 assumed by lots of code */
180#define SECTOR_SIZE     512
181#define SECTOR_WORDS    (SECTOR_SIZE / 4)       /* number of 32bit words per sector */
182#define IDE_LARGE_SEEK(b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t)))
183
184/*
185 * Timeouts for various operations:
186 */
187#define WAIT_DRQ        (HZ/10)         /* 100msec - spec allows up to 20ms */
188#define WAIT_READY      (5*HZ)          /* 5sec - some laptops are very slow */
189#define WAIT_PIDENTIFY  (10*HZ) /* 10sec  - should be less than 3ms (?), if all ATAPI CD is closed at boot */
190#define WAIT_WORSTCASE  (30*HZ) /* 30sec  - worst case when spinning up */
191#define WAIT_CMD        (10*HZ) /* 10sec  - maximum wait for an IRQ to happen */
192#define WAIT_MIN_SLEEP  (2*HZ/100)      /* 20msec - minimum sleep time */
193
194#ifndef NO_DMA
195#define NO_DMA  255
196#endif
197
198#include <asm/ide.h>
199
200/*
201 * Now for the data we need to maintain per-drive:  ide_drive_t
202 */
203
204#define ide_scsi        0x21
205#define ide_disk        0x20
206#define ide_optical     0x7
207#define ide_cdrom       0x5
208#define ide_tape        0x1
209#define ide_floppy      0x0
210
211/*
212 * Special Driver Flags
213 *
214 * set_geometry : respecify drive geometry
215 * recalibrate  : seek to cyl 0
216 * set_multmode : set multmode count
217 * set_tune     : tune interface for drive
218 * serviced     : service command
219 * reserved     : unused
220 */
221typedef union {
222        unsigned all                    : 8;
223        struct {
224#if defined(__LITTLE_ENDIAN)
225                unsigned set_geometry   : 1;
226                unsigned recalibrate    : 1;
227                unsigned set_multmode   : 1;
228                unsigned set_tune       : 1;
229                unsigned serviced       : 1;
230                unsigned reserved       : 3;
231#elif defined(__BIG_ENDIAN)
232                unsigned reserved       : 3;
233                unsigned serviced       : 1;
234                unsigned set_tune       : 1;
235                unsigned set_multmode   : 1;
236                unsigned recalibrate    : 1;
237                unsigned set_geometry   : 1;
238#else
239#error "Endian problem - this didn't happen"
240#endif
241        } b;
242} special_t;
243
244/*
245 * ATA DATA Register Special.
246 * ATA NSECTOR Count Register().
247 * ATAPI Byte Count Register.
248 * Channel index ordering pairs.
249 */
250typedef union {
251        unsigned all                    :16;
252        struct {
253#if defined(__LITTLE_ENDIAN)
254                unsigned low            :8;     /* LSB */
255                unsigned high           :8;     /* MSB */
256#elif defined(__BIG_ENDIAN)
257                unsigned high           :8;     /* MSB */
258                unsigned low            :8;     /* LSB */
259#else
260#error "Endian problem - this didn't happen"
261#endif
262        } b;
263} ata_nsector_t, ata_data_t, atapi_bcount_t, ata_index_t;
264
265/*
266 * ATA-IDE Error Register
267 *
268 * mark         : Bad address mark
269 * tzero        : Couldn't find track 0
270 * abrt         : Aborted Command
271 * mcr          : Media Change Request
272 * id           : ID field not found
273 * mce          : Media Change Event
274 * ecc          : Uncorrectable ECC error
275 * bdd          : dual meaing
276 */
277typedef union {
278        unsigned all                    :8;
279        struct {
280#if defined(__LITTLE_ENDIAN)
281                unsigned mark           :1;
282                unsigned tzero          :1;
283                unsigned abrt           :1;
284                unsigned mcr            :1;
285                unsigned id             :1;
286                unsigned mce            :1;
287                unsigned ecc            :1;
288                unsigned bdd            :1;
289#elif defined(__BIG_ENDIAN)
290                unsigned bdd            :1;
291                unsigned ecc            :1;
292                unsigned mce            :1;
293                unsigned id             :1;
294                unsigned mcr            :1;
295                unsigned abrt           :1;
296                unsigned tzero          :1;
297                unsigned mark           :1;
298#else
299#error "Endian problem - this didn't happen"
300#endif
301        } b;
302} ata_error_t;
303
304/*
305 * ATA-IDE Select Register, aka Device-Head
306 *
307 * head         : always zeros here
308 * unit         : drive select number: 0/1
309 * bit5         : always 1
310 * lba          : using LBA instead of CHS
311 * bit7         : always 1
312 */
313typedef union {
314        unsigned all                    : 8;
315        struct {
316#if defined(__LITTLE_ENDIAN)
317                unsigned head           : 4;
318                unsigned unit           : 1;
319                unsigned bit5           : 1;
320                unsigned lba            : 1;
321                unsigned bit7           : 1;
322#elif defined(__BIG_ENDIAN)
323                unsigned bit7           : 1;
324                unsigned lba            : 1;
325                unsigned bit5           : 1;
326                unsigned unit           : 1;
327                unsigned head           : 4;
328#else
329#error "Endian problem - this didn't happen"
330#endif
331        } b;
332} select_t, ata_select_t;
333
334/*
335 * The ATA-IDE Status Register.
336 * The ATAPI Status Register.
337 *
338 * check        : Error occurred
339 * idx          : Index Error
340 * corr         : Correctable error occurred
341 * drq          : Data is request by the device
342 * dsc          : Disk Seek Complete                    : ata
343 *              : Media access command finished         : atapi
344 * df           : Device Fault                          : ata
345 *              : Reserved                              : atapi
346 * drdy         : Ready, Command Mode Capable           : ata
347 *              : Ignored for ATAPI commands            : atapi
348 * bsy          : Disk is Busy
349 *              : The device has access to the command block
350 */
351typedef union {
352        unsigned all                    :8;
353        struct {
354#if defined(__LITTLE_ENDIAN)
355                unsigned check          :1;
356                unsigned idx            :1;
357                unsigned corr           :1;
358                unsigned drq            :1;
359                unsigned dsc            :1;
360                unsigned df             :1;
361                unsigned drdy           :1;
362                unsigned bsy            :1;
363#elif defined(__BIG_ENDIAN)
364                unsigned bsy            :1;
365                unsigned drdy           :1;
366                unsigned df             :1;
367                unsigned dsc            :1;
368                unsigned drq            :1;
369                unsigned corr           :1;
370                unsigned idx            :1;
371                unsigned check          :1;
372#else
373#error "Endian problem - this didn't happen"
374#endif
375        } b;
376} ata_status_t, atapi_status_t;
377
378/*
379 * ATA-IDE Control Register
380 *
381 * bit0         : Should be set to zero
382 * nIEN         : device INTRQ to host
383 * SRST         : host soft reset bit
384 * bit3         : ATA-2 thingy, Should be set to 1
385 * reserved456  : Reserved
386 * HOB          : 48-bit address ordering, High Ordered Bit
387 */
388typedef union {
389        unsigned all                    : 8;
390        struct {
391#if defined(__LITTLE_ENDIAN)
392                unsigned bit0           : 1;
393                unsigned nIEN           : 1;
394                unsigned SRST           : 1;
395                unsigned bit3           : 1;
396                unsigned reserved456    : 3;
397                unsigned HOB            : 1;
398#elif defined(__BIG_ENDIAN)
399                unsigned HOB            : 1;
400                unsigned reserved456    : 3;
401                unsigned bit3           : 1;
402                unsigned SRST           : 1;
403                unsigned nIEN           : 1;
404                unsigned bit0           : 1;
405#else
406#error "Endian problem - this didn't happen"
407#endif
408        } b;
409} ata_control_t;
410
411/*
412 * ATAPI Feature Register
413 *
414 * dma          : Using DMA or PIO
415 * reserved321  : Reserved
416 * reserved654  : Reserved (Tag Type)
417 * reserved7    : Reserved
418 */
419typedef union {
420        unsigned all                    :8;
421        struct {
422#if defined(__LITTLE_ENDIAN)
423                unsigned dma            :1;
424                unsigned reserved321    :3;
425                unsigned reserved654    :3;
426                unsigned reserved7      :1;
427#elif defined(__BIG_ENDIAN)
428                unsigned reserved7      :1;
429                unsigned reserved654    :3;
430                unsigned reserved321    :3;
431                unsigned dma            :1;
432#else
433#error "Endian problem - this didn't happen"
434#endif
435        } b;
436} atapi_feature_t;
437
438/*
439 * ATAPI Interrupt Reason Register.
440 *
441 * cod          : Information transferred is command (1) or data (0)
442 * io           : The device requests us to read (1) or write (0)
443 * reserved     : Reserved
444 */
445typedef union {
446        unsigned all                    :8;
447        struct {
448#if defined(__LITTLE_ENDIAN)
449                unsigned cod            :1;
450                unsigned io             :1;
451                unsigned reserved       :6;
452#elif defined(__BIG_ENDIAN)
453                unsigned reserved       :6;
454                unsigned io             :1;
455                unsigned cod            :1;
456#else
457#error "Endian problem - this didn't happen"
458#endif
459        } b;
460} atapi_ireason_t;
461
462/*
463 * The ATAPI error register.
464 *
465 * ili          : Illegal Length Indication
466 * eom          : End Of Media Detected
467 * abrt         : Aborted command - As defined by ATA
468 * mcr          : Media Change Requested - As defined by ATA
469 * sense_key    : Sense key of the last failed packet command
470 */
471typedef union {
472        unsigned all                    :8;
473        struct {
474#if defined(__LITTLE_ENDIAN)
475                unsigned ili            :1;
476                unsigned eom            :1;
477                unsigned abrt           :1;
478                unsigned mcr            :1;
479                unsigned sense_key      :4;
480#elif defined(__BIG_ENDIAN)
481                unsigned sense_key      :4;
482                unsigned mcr            :1;
483                unsigned abrt           :1;
484                unsigned eom            :1;
485                unsigned ili            :1;
486#else
487#error "Endian problem - this didn't happen"
488#endif
489        } b;
490} atapi_error_t;
491
492#ifdef CONFIG_BLK_DEV_IDEPCI
493void ide_pci_create_host_proc(const char *, get_info_t *);
494#endif
495
496/*
497 * ATAPI floppy Drive Select Register
498 *
499 * sam_lun      : Logical unit number
500 * reserved3    : Reserved
501 * drv          : The responding drive will be drive 0 (0) or drive 1 (1)
502 * one5         : Should be set to 1
503 * reserved6    : Reserved
504 * one7         : Should be set to 1
505 */
506typedef union {
507        unsigned all                    :8;
508        struct {
509#if defined(__LITTLE_ENDIAN)
510                unsigned sam_lun        :3;
511                unsigned reserved3      :1;
512                unsigned drv            :1;
513                unsigned one5           :1;
514                unsigned reserved6      :1;
515                unsigned one7           :1;
516#elif defined(__BIG_ENDIAN)
517                unsigned one7           :1;
518                unsigned reserved6      :1;
519                unsigned one5           :1;
520                unsigned drv            :1;
521                unsigned reserved3      :1;
522                unsigned sam_lun        :3;
523#else
524#error "Endian problem - this didn't happen"
525#endif
526        } b;
527} atapi_select_t;
528
529#define ON_BOARD                1
530#define NEVER_BOARD             0
531
532#define NODMA 0
533#define NOAUTODMA 1
534#define AUTODMA 2
535
536#define BAD_DMA_DRIVE           0
537#define GOOD_DMA_DRIVE          1
538
539typedef struct ide_pio_timings_s {
540        int     setup_time;     /* Address setup (ns) minimum */
541        int     active_time;    /* Active pulse (ns) minimum */
542        int     cycle_time;     /* Cycle time (ns) minimum = (setup + active + recovery) */
543} ide_pio_timings_t;
544
545#endif /* _IDE_H */
Note: See TracBrowser for help on using the repository browser.