blob: e3315359500abba1617bb13f4abd17be79dc2f66 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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/config.h>
19#include <linux/pci.h>
20#include <linux/stddef.h>
Ralf Baechle9447cbf2005-04-19 12:26:59 +000021#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#ifndef MAX_HWIFS
24# ifdef CONFIG_BLK_DEV_IDEPCI
25#define MAX_HWIFS 10
26# else
27#define MAX_HWIFS 6
28# endif
29#endif
30
31#define IDE_ARCH_OBSOLETE_DEFAULTS
32
33static __inline__ int ide_probe_legacy(void)
34{
35#ifdef CONFIG_PCI
36 struct pci_dev *dev;
37 if ((dev = pci_get_class(PCI_CLASS_BRIDGE_EISA << 8, NULL)) != NULL ||
38 (dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL)) != NULL) {
39 pci_dev_put(dev);
40
41 return 1;
42 }
43 return 0;
44#elif defined(CONFIG_EISA) || defined(CONFIG_ISA)
45 return 1;
46#else
47 return 0;
48#endif
49}
50
51static __inline__ int ide_default_irq(unsigned long base)
52{
53 if (ide_probe_legacy())
54 switch (base) {
55 case 0x1f0:
56 return 14;
57 case 0x170:
58 return 15;
59 case 0x1e8:
60 return 11;
61 case 0x168:
62 return 10;
63 case 0x1e0:
64 return 8;
65 case 0x160:
66 return 12;
67 default:
68 return 0;
69 }
70 else
71 return 0;
72}
73
74static __inline__ unsigned long ide_default_io_base(int index)
75{
76 if (ide_probe_legacy())
77 switch (index) {
78 case 0:
79 return 0x1f0;
80 case 1:
81 return 0x170;
82 case 2:
83 return 0x1e8;
84 case 3:
85 return 0x168;
86 case 4:
87 return 0x1e0;
88 case 5:
89 return 0x160;
90 default:
91 return 0;
92 }
93 else
94 return 0;
95}
96
97#define IDE_ARCH_OBSOLETE_INIT
98#define ide_default_io_ctl(base) ((base) + 0x206) /* obsolete */
99
100#ifdef CONFIG_BLK_DEV_IDEPCI
101#define ide_init_default_irq(base) (0)
102#else
103#define ide_init_default_irq(base) ide_default_irq(base)
104#endif
105
106/* MIPS port and memory-mapped I/O string operations. */
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100107static inline void __ide_flush_prologue(void)
108{
109#ifdef CONFIG_SMP
110 if (cpu_has_dc_aliases)
111 preempt_disable();
112#endif
113}
114
115static inline void __ide_flush_epilogue(void)
116{
117#ifdef CONFIG_SMP
118 if (cpu_has_dc_aliases)
119 preempt_enable();
120#endif
121}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000123static inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size)
124{
125 if (cpu_has_dc_aliases) {
126 unsigned long end = addr + size;
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100127
128 while (addr < end) {
129 local_flush_data_cache_page((void *)addr);
130 addr += PAGE_SIZE;
131 }
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000132 }
133}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100135/*
136 * insw() and gang might be called with interrupts disabled, so we can't
137 * send IPIs for flushing due to the potencial of deadlocks, see the comment
138 * above smp_call_function() in arch/mips/kernel/smp.c. We work around the
139 * problem by disabling preemption so we know we actually perform the flush
140 * on the processor that actually has the lines to be flushed which hopefully
141 * is even better for performance anyway.
142 */
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000143static inline void __ide_insw(unsigned long port, void *addr,
144 unsigned int count)
145{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100146 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000147 insw(port, addr, count);
148 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100149 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000150}
151
152static inline void __ide_insl(unsigned long port, void *addr, unsigned int count)
153{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100154 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000155 insl(port, addr, count);
156 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100157 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000158}
159
160static inline void __ide_outsw(unsigned long port, const void *addr,
161 unsigned long count)
162{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100163 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000164 outsw(port, addr, count);
165 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100166 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000167}
168
169static inline void __ide_outsl(unsigned long port, const void *addr,
170 unsigned long count)
171{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100172 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000173 outsl(port, addr, count);
174 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100175 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000176}
177
178static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count)
179{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100180 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000181 readsw(port, addr, count);
182 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100183 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000184}
185
186static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count)
187{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100188 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000189 readsl(port, addr, count);
190 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100191 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000192}
193
194static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count)
195{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100196 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000197 writesw(port, addr, count);
198 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100199 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000200}
201
202static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
203{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100204 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000205 writesl(port, addr, count);
206 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100207 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000208}
209
210/* ide_insw calls insw, not __ide_insw. Why? */
211#undef insw
212#undef insl
Atsushi Nemotoa06d61c2005-11-06 23:58:21 +0900213#undef outsw
214#undef outsl
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000215#define insw(port, addr, count) __ide_insw(port, addr, count)
216#define insl(port, addr, count) __ide_insl(port, addr, count)
Atsushi Nemotoa06d61c2005-11-06 23:58:21 +0900217#define outsw(port, addr, count) __ide_outsw(port, addr, count)
218#define outsl(port, addr, count) __ide_outsl(port, addr, count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220#endif /* __KERNEL__ */
221
222#endif /* __ASM_MACH_GENERIC_IDE_H */