File: /usr/src/linux/include/asm-mips/ide.h

1     /*
2      * This file is subject to the terms and conditions of the GNU General Public
3      * License.  See the file "COPYING" in the main directory of this archive
4      * for more details.
5      *
6      * This file contains the MIPS architecture specific IDE code.
7      *
8      * Copyright (C) 1994-1996  Linus Torvalds & authors
9      */
10     
11     #ifndef __ASM_IDE_H
12     #define __ASM_IDE_H
13     
14     #ifdef __KERNEL__
15     
16     #include <linux/config.h>
17     #include <asm/io.h>
18     
19     #ifndef MAX_HWIFS
20     # ifdef CONFIG_BLK_DEV_IDEPCI
21     #define MAX_HWIFS	10
22     # else
23     #define MAX_HWIFS	6
24     # endif
25     #endif
26     
27     #define ide__sti()	__sti()
28     
29     struct ide_ops {
30     	int (*ide_default_irq)(ide_ioreg_t base);
31     	ide_ioreg_t (*ide_default_io_base)(int index);
32     	void (*ide_init_hwif_ports)(hw_regs_t *hw, ide_ioreg_t data_port,
33     	                            ide_ioreg_t ctrl_port, int *irq);
34     	int (*ide_request_irq)(unsigned int irq, void (*handler)(int, void *,
35     	                       struct pt_regs *), unsigned long flags,
36     	                       const char *device, void *dev_id);
37     	void (*ide_free_irq)(unsigned int irq, void *dev_id);
38     	int (*ide_check_region) (ide_ioreg_t from, unsigned int extent);
39     	void (*ide_request_region)(ide_ioreg_t from, unsigned int extent,
40     	                        const char *name);
41     	void (*ide_release_region)(ide_ioreg_t from, unsigned int extent);
42     };
43     
44     extern struct ide_ops *ide_ops;
45     
46     static __inline__ int ide_default_irq(ide_ioreg_t base)
47     {
48     	return ide_ops->ide_default_irq(base);
49     }
50     
51     static __inline__ ide_ioreg_t ide_default_io_base(int index)
52     {
53     	return ide_ops->ide_default_io_base(index);
54     }
55     
56     static inline void ide_init_hwif_ports(hw_regs_t *hw, ide_ioreg_t data_port,
57                                            ide_ioreg_t ctrl_port, int *irq)
58     {
59     	ide_ops->ide_init_hwif_ports(hw, data_port, ctrl_port, irq);
60     }
61     
62     static __inline__ void ide_init_default_hwifs(void)
63     {
64     #ifndef CONFIG_BLK_DEV_IDEPCI
65     	hw_regs_t hw;
66     	int index;
67     
68     	for(index = 0; index < MAX_HWIFS; index++) {
69     		ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, NULL);
70     		hw.irq = ide_default_irq(ide_default_io_base(index));
71     		ide_register_hw(&hw, NULL);
72     	}
73     #endif /* CONFIG_BLK_DEV_IDEPCI */
74     }
75     
76     typedef union {
77     	unsigned all			: 8;	/* all of the bits together */
78     	struct {
79     #ifdef __MIPSEB__
80     		unsigned bit7		: 1;	/* always 1 */
81     		unsigned lba		: 1;	/* using LBA instead of CHS */
82     		unsigned bit5		: 1;	/* always 1 */
83     		unsigned unit		: 1;	/* drive select number, 0 or 1 */
84     		unsigned head		: 4;	/* always zeros here */
85     #else
86     		unsigned head		: 4;	/* always zeros here */
87     		unsigned unit		: 1;	/* drive select number, 0 or 1 */
88     		unsigned bit5		: 1;	/* always 1 */
89     		unsigned lba		: 1;	/* using LBA instead of CHS */
90     		unsigned bit7		: 1;	/* always 1 */
91     #endif
92     	} b;
93     } select_t;
94     
95     static __inline__ int ide_request_irq(unsigned int irq, void (*handler)(int,void *, struct pt_regs *),
96     			unsigned long flags, const char *device, void *dev_id)
97     {
98     	return ide_ops->ide_request_irq(irq, handler, flags, device, dev_id);
99     }
100     
101     static __inline__ void ide_free_irq(unsigned int irq, void *dev_id)
102     {
103     	ide_ops->ide_free_irq(irq, dev_id);
104     }
105     
106     static __inline__ int ide_check_region (ide_ioreg_t from, unsigned int extent)
107     {
108     	return ide_ops->ide_check_region(from, extent);
109     }
110     
111     static __inline__ void ide_request_region(ide_ioreg_t from,
112                                               unsigned int extent, const char *name)
113     {
114     	ide_ops->ide_request_region(from, extent, name);
115     }
116     
117     static __inline__ void ide_release_region(ide_ioreg_t from,
118                                               unsigned int extent)
119     {
120     	ide_ops->ide_release_region(from, extent);
121     }
122     
123     #undef  SUPPORT_VLB_SYNC
124     #define SUPPORT_VLB_SYNC 0
125     
126     #if defined(__MIPSEB__)
127     
128     #define T_CHAR          (0x0000)        /* char:  don't touch  */
129     #define T_SHORT         (0x4000)        /* short: 12 -> 21     */
130     #define T_INT           (0x8000)        /* int:   1234 -> 4321 */
131     #define T_TEXT          (0xc000)        /* text:  12 -> 21     */
132     
133     #define T_MASK_TYPE     (0xc000)
134     #define T_MASK_COUNT    (0x3fff)
135     
136     #define D_CHAR(cnt)     (T_CHAR  | (cnt))
137     #define D_SHORT(cnt)    (T_SHORT | (cnt))
138     #define D_INT(cnt)      (T_INT   | (cnt))
139     #define D_TEXT(cnt)     (T_TEXT  | (cnt))
140     
141     static u_short driveid_types[] = {
142     	D_SHORT(10),	/* config - vendor2 */
143     	D_TEXT(20),	/* serial_no */
144     	D_SHORT(3),	/* buf_type - ecc_bytes */
145     	D_TEXT(48),	/* fw_rev - model */
146     	D_CHAR(2),	/* max_multsect - vendor3 */
147     	D_SHORT(1),	/* dword_io */
148     	D_CHAR(2),	/* vendor4 - capability */
149     	D_SHORT(1),	/* reserved50 */
150     	D_CHAR(4),	/* vendor5 - tDMA */
151     	D_SHORT(4),	/* field_valid - cur_sectors */
152     	D_INT(1),	/* cur_capacity */
153     	D_CHAR(2),	/* multsect - multsect_valid */
154     	D_INT(1),	/* lba_capacity */
155     	D_SHORT(194)	/* dma_1word - reservedyy */
156     };
157     
158     #define num_driveid_types       (sizeof(driveid_types)/sizeof(*driveid_types))
159     
160     static __inline__ void ide_fix_driveid(struct hd_driveid *id)
161     {
162     	u_char *p = (u_char *)id;
163     	int i, j, cnt;
164     	u_char t;
165     
166     	for (i = 0; i < num_driveid_types; i++) {
167     		cnt = driveid_types[i] & T_MASK_COUNT;
168     		switch (driveid_types[i] & T_MASK_TYPE) {
169     		case T_CHAR:
170     			p += cnt;
171     			break;
172     		case T_SHORT:
173     			for (j = 0; j < cnt; j++) {
174     				t = p[0];
175     				p[0] = p[1];
176     				p[1] = t;
177     				p += 2;
178     			}
179     			break;
180     		case T_INT:
181     			for (j = 0; j < cnt; j++) {
182     				t = p[0];
183     				p[0] = p[3];
184     				p[3] = t;
185     				t = p[1];
186     				p[1] = p[2];
187     				p[2] = t;
188     				p += 4;
189     			}
190     			break;
191     		case T_TEXT:
192     			for (j = 0; j < cnt; j += 2) {
193     				t = p[0];
194     				p[0] = p[1];
195     				p[1] = t;
196     				p += 2;
197     			}
198     			break;
199     		};
200     	}
201     }
202     
203     #else /* defined(CONFIG_SWAP_IO_SPACE) && defined(__MIPSEB__)  */
204     
205     #define ide_fix_driveid(id)		do {} while (0)
206     
207     #endif
208     
209     /*
210      * The following are not needed for the non-m68k ports
211      */
212     #define ide_ack_intr(hwif)		(1)
213     #define ide_release_lock(lock)		do {} while (0)
214     #define ide_get_lock(lock, hdlr, data)	do {} while (0)
215     
216     #endif /* __KERNEL__ */
217     
218     #endif /* __ASM_IDE_H */
219