ide: define MAX_HWIFS in <linux/ide.h>
[safe/jmp/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 static __inline__ int ide_probe_legacy(void)
23 {
24 #ifdef CONFIG_PCI
25         struct pci_dev *dev;
26         /*
27          * This can be called on the ide_setup() path, super-early in
28          * boot.  But the down_read() will enable local interrupts,
29          * which can cause some machines to crash.  So here we detect
30          * and flag that situation and bail out early.
31          */
32         if (no_pci_devices())
33                 return 0;
34         dev = pci_get_class(PCI_CLASS_BRIDGE_EISA << 8, NULL);
35         if (dev)
36                 goto found;
37         dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
38         if (dev)
39                 goto found;
40         return 0;
41 found:
42         pci_dev_put(dev);
43         return 1;
44 #elif defined(CONFIG_EISA) || defined(CONFIG_ISA)
45         return 1;
46 #else
47         return 0;
48 #endif
49 }
50
51 static __inline__ int ide_default_irq(unsigned long base)
52 {
53         switch (base) {
54                 case 0x1f0: return 14;
55                 case 0x170: return 15;
56                 case 0x1e8: return 11;
57                 case 0x168: return 10;
58                 case 0x1e0: return 8;
59                 case 0x160: return 12;
60                 default:
61                         return 0;
62         }
63 }
64
65 static __inline__ unsigned long ide_default_io_base(int index)
66 {
67         switch (index) {
68         case 0: return 0x1f0;
69         case 1: return 0x170;
70         case 2: return 0x1e8;
71         case 3: return 0x168;
72         case 4: return 0x1e0;
73         case 5: return 0x160;
74         default:
75                 return 0;
76         }
77 }
78
79 /* MIPS port and memory-mapped I/O string operations.  */
80 static inline void __ide_flush_prologue(void)
81 {
82 #ifdef CONFIG_SMP
83         if (cpu_has_dc_aliases)
84                 preempt_disable();
85 #endif
86 }
87
88 static inline void __ide_flush_epilogue(void)
89 {
90 #ifdef CONFIG_SMP
91         if (cpu_has_dc_aliases)
92                 preempt_enable();
93 #endif
94 }
95
96 static inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size)
97 {
98         if (cpu_has_dc_aliases) {
99                 unsigned long end = addr + size;
100
101                 while (addr < end) {
102                         local_flush_data_cache_page((void *)addr);
103                         addr += PAGE_SIZE;
104                 }
105         }
106 }
107
108 /*
109  * insw() and gang might be called with interrupts disabled, so we can't
110  * send IPIs for flushing due to the potencial of deadlocks, see the comment
111  * above smp_call_function() in arch/mips/kernel/smp.c.  We work around the
112  * problem by disabling preemption so we know we actually perform the flush
113  * on the processor that actually has the lines to be flushed which hopefully
114  * is even better for performance anyway.
115  */
116 static inline void __ide_insw(unsigned long port, void *addr,
117         unsigned int count)
118 {
119         __ide_flush_prologue();
120         insw(port, addr, count);
121         __ide_flush_dcache_range((unsigned long)addr, count * 2);
122         __ide_flush_epilogue();
123 }
124
125 static inline void __ide_insl(unsigned long port, void *addr, unsigned int count)
126 {
127         __ide_flush_prologue();
128         insl(port, addr, count);
129         __ide_flush_dcache_range((unsigned long)addr, count * 4);
130         __ide_flush_epilogue();
131 }
132
133 static inline void __ide_outsw(unsigned long port, const void *addr,
134         unsigned long count)
135 {
136         __ide_flush_prologue();
137         outsw(port, addr, count);
138         __ide_flush_dcache_range((unsigned long)addr, count * 2);
139         __ide_flush_epilogue();
140 }
141
142 static inline void __ide_outsl(unsigned long port, const void *addr,
143         unsigned long count)
144 {
145         __ide_flush_prologue();
146         outsl(port, addr, count);
147         __ide_flush_dcache_range((unsigned long)addr, count * 4);
148         __ide_flush_epilogue();
149 }
150
151 static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count)
152 {
153         __ide_flush_prologue();
154         readsw(port, addr, count);
155         __ide_flush_dcache_range((unsigned long)addr, count * 2);
156         __ide_flush_epilogue();
157 }
158
159 static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count)
160 {
161         __ide_flush_prologue();
162         readsl(port, addr, count);
163         __ide_flush_dcache_range((unsigned long)addr, count * 4);
164         __ide_flush_epilogue();
165 }
166
167 static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count)
168 {
169         __ide_flush_prologue();
170         writesw(port, addr, count);
171         __ide_flush_dcache_range((unsigned long)addr, count * 2);
172         __ide_flush_epilogue();
173 }
174
175 static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
176 {
177         __ide_flush_prologue();
178         writesl(port, addr, count);
179         __ide_flush_dcache_range((unsigned long)addr, count * 4);
180         __ide_flush_epilogue();
181 }
182
183 /* ide_insw calls insw, not __ide_insw.  Why? */
184 #undef insw
185 #undef insl
186 #undef outsw
187 #undef outsl
188 #define insw(port, addr, count) __ide_insw(port, addr, count)
189 #define insl(port, addr, count) __ide_insl(port, addr, count)
190 #define outsw(port, addr, count) __ide_outsw(port, addr, count)
191 #define outsl(port, addr, count) __ide_outsl(port, addr, count)
192
193 #endif /* __KERNEL__ */
194
195 #endif /* __ASM_MACH_GENERIC_IDE_H */