]> err.no Git - linux-2.6/blob - include/asm-mips/mach-generic/ide.h
ide: add CONFIG_IDE_ARCH_OBSOLETE_DEFAULTS (take 2)
[linux-2.6] / include / asm-mips / mach-generic / 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  * Copyright (C) 1994-1996  Linus Torvalds & authors
7  *
8  * Copied from i386; many of the especially older MIPS or ISA-based platforms
9  * are basically identical.  Using this file probably implies i8259 PIC
10  * support in a system but the very least interrupt numbers 0 - 15 need to
11  * be put aside for legacy devices.
12  */
13 #ifndef __ASM_MACH_GENERIC_IDE_H
14 #define __ASM_MACH_GENERIC_IDE_H
15
16 #ifdef __KERNEL__
17
18 #include <linux/pci.h>
19 #include <linux/stddef.h>
20 #include <asm/processor.h>
21
22 #ifndef MAX_HWIFS
23 # ifdef CONFIG_BLK_DEV_IDEPCI
24 #define MAX_HWIFS       10
25 # else
26 #define MAX_HWIFS       6
27 # endif
28 #endif
29
30 static __inline__ int ide_probe_legacy(void)
31 {
32 #ifdef CONFIG_PCI
33         struct pci_dev *dev;
34         /*
35          * This can be called on the ide_setup() path, super-early in
36          * boot.  But the down_read() will enable local interrupts,
37          * which can cause some machines to crash.  So here we detect
38          * and flag that situation and bail out early.
39          */
40         if (no_pci_devices())
41                 return 0;
42         dev = pci_get_class(PCI_CLASS_BRIDGE_EISA << 8, NULL);
43         if (dev)
44                 goto found;
45         dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
46         if (dev)
47                 goto found;
48         return 0;
49 found:
50         pci_dev_put(dev);
51         return 1;
52 #elif defined(CONFIG_EISA) || defined(CONFIG_ISA)
53         return 1;
54 #else
55         return 0;
56 #endif
57 }
58
59 static __inline__ int ide_default_irq(unsigned long base)
60 {
61         switch (base) {
62                 case 0x1f0: return 14;
63                 case 0x170: return 15;
64                 case 0x1e8: return 11;
65                 case 0x168: return 10;
66                 case 0x1e0: return 8;
67                 case 0x160: return 12;
68                 default:
69                         return 0;
70         }
71 }
72
73 static __inline__ unsigned long ide_default_io_base(int index)
74 {
75         if (!ide_probe_legacy())
76                 return 0;
77         /*
78          *      If PCI is present then it is not safe to poke around
79          *      the other legacy IDE ports. Only 0x1f0 and 0x170 are
80          *      defined compatibility mode ports for PCI. A user can
81          *      override this using ide= but we must default safe.
82          */
83         if (no_pci_devices()) {
84                 switch (index) {
85                 case 2: return 0x1e8;
86                 case 3: return 0x168;
87                 case 4: return 0x1e0;
88                 case 5: return 0x160;
89                 }
90         }
91         switch (index) {
92         case 0: return 0x1f0;
93         case 1: return 0x170;
94         default:
95                 return 0;
96         }
97 }
98
99 #define ide_default_io_ctl(base)        ((base) + 0x206) /* obsolete */
100
101 #ifdef CONFIG_BLK_DEV_IDEPCI
102 #define ide_init_default_irq(base)      (0)
103 #else
104 #define ide_init_default_irq(base)      ide_default_irq(base)
105 #endif
106
107 /* MIPS port and memory-mapped I/O string operations.  */
108 static inline void __ide_flush_prologue(void)
109 {
110 #ifdef CONFIG_SMP
111         if (cpu_has_dc_aliases)
112                 preempt_disable();
113 #endif
114 }
115
116 static inline void __ide_flush_epilogue(void)
117 {
118 #ifdef CONFIG_SMP
119         if (cpu_has_dc_aliases)
120                 preempt_enable();
121 #endif
122 }
123
124 static inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size)
125 {
126         if (cpu_has_dc_aliases) {
127                 unsigned long end = addr + size;
128
129                 while (addr < end) {
130                         local_flush_data_cache_page((void *)addr);
131                         addr += PAGE_SIZE;
132                 }
133         }
134 }
135
136 /*
137  * insw() and gang might be called with interrupts disabled, so we can't
138  * send IPIs for flushing due to the potencial of deadlocks, see the comment
139  * above smp_call_function() in arch/mips/kernel/smp.c.  We work around the
140  * problem by disabling preemption so we know we actually perform the flush
141  * on the processor that actually has the lines to be flushed which hopefully
142  * is even better for performance anyway.
143  */
144 static inline void __ide_insw(unsigned long port, void *addr,
145         unsigned int count)
146 {
147         __ide_flush_prologue();
148         insw(port, addr, count);
149         __ide_flush_dcache_range((unsigned long)addr, count * 2);
150         __ide_flush_epilogue();
151 }
152
153 static inline void __ide_insl(unsigned long port, void *addr, unsigned int count)
154 {
155         __ide_flush_prologue();
156         insl(port, addr, count);
157         __ide_flush_dcache_range((unsigned long)addr, count * 4);
158         __ide_flush_epilogue();
159 }
160
161 static inline void __ide_outsw(unsigned long port, const void *addr,
162         unsigned long count)
163 {
164         __ide_flush_prologue();
165         outsw(port, addr, count);
166         __ide_flush_dcache_range((unsigned long)addr, count * 2);
167         __ide_flush_epilogue();
168 }
169
170 static inline void __ide_outsl(unsigned long port, const void *addr,
171         unsigned long count)
172 {
173         __ide_flush_prologue();
174         outsl(port, addr, count);
175         __ide_flush_dcache_range((unsigned long)addr, count * 4);
176         __ide_flush_epilogue();
177 }
178
179 static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count)
180 {
181         __ide_flush_prologue();
182         readsw(port, addr, count);
183         __ide_flush_dcache_range((unsigned long)addr, count * 2);
184         __ide_flush_epilogue();
185 }
186
187 static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count)
188 {
189         __ide_flush_prologue();
190         readsl(port, addr, count);
191         __ide_flush_dcache_range((unsigned long)addr, count * 4);
192         __ide_flush_epilogue();
193 }
194
195 static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count)
196 {
197         __ide_flush_prologue();
198         writesw(port, addr, count);
199         __ide_flush_dcache_range((unsigned long)addr, count * 2);
200         __ide_flush_epilogue();
201 }
202
203 static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
204 {
205         __ide_flush_prologue();
206         writesl(port, addr, count);
207         __ide_flush_dcache_range((unsigned long)addr, count * 4);
208         __ide_flush_epilogue();
209 }
210
211 /* ide_insw calls insw, not __ide_insw.  Why? */
212 #undef insw
213 #undef insl
214 #undef outsw
215 #undef outsl
216 #define insw(port, addr, count) __ide_insw(port, addr, count)
217 #define insl(port, addr, count) __ide_insl(port, addr, count)
218 #define outsw(port, addr, count) __ide_outsw(port, addr, count)
219 #define outsl(port, addr, count) __ide_outsl(port, addr, count)
220
221 #endif /* __KERNEL__ */
222
223 #endif /* __ASM_MACH_GENERIC_IDE_H */