Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/pci.h> |
| 19 | #include <linux/stddef.h> |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 20 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Atsushi Nemoto | 6440fcf | 2007-09-04 23:02:02 +0900 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | static __inline__ int ide_default_irq(unsigned long base) |
| 60 | { |
Ralf Baechle | b543858 | 2007-08-07 17:18:28 +0100 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | default: |
| 69 | return 0; |
Ralf Baechle | b543858 | 2007-08-07 17:18:28 +0100 | [diff] [blame] | 70 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static __inline__ unsigned long ide_default_io_base(int index) |
| 74 | { |
Ralf Baechle | b543858 | 2007-08-07 17:18:28 +0100 | [diff] [blame] | 75 | /* |
| 76 | * If PCI is present then it is not safe to poke around |
| 77 | * the other legacy IDE ports. Only 0x1f0 and 0x170 are |
| 78 | * defined compatibility mode ports for PCI. A user can |
| 79 | * override this using ide= but we must default safe. |
| 80 | */ |
| 81 | if (no_pci_devices()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | switch (index) { |
Ralf Baechle | b543858 | 2007-08-07 17:18:28 +0100 | [diff] [blame] | 83 | case 2: return 0x1e8; |
| 84 | case 3: return 0x168; |
| 85 | case 4: return 0x1e0; |
| 86 | case 5: return 0x160; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
Ralf Baechle | b543858 | 2007-08-07 17:18:28 +0100 | [diff] [blame] | 88 | } |
| 89 | switch (index) { |
| 90 | case 0: return 0x1f0; |
| 91 | case 1: return 0x170; |
| 92 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | return 0; |
Ralf Baechle | b543858 | 2007-08-07 17:18:28 +0100 | [diff] [blame] | 94 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | /* MIPS port and memory-mapped I/O string operations. */ |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 98 | static inline void __ide_flush_prologue(void) |
| 99 | { |
| 100 | #ifdef CONFIG_SMP |
| 101 | if (cpu_has_dc_aliases) |
| 102 | preempt_disable(); |
| 103 | #endif |
| 104 | } |
| 105 | |
| 106 | static inline void __ide_flush_epilogue(void) |
| 107 | { |
| 108 | #ifdef CONFIG_SMP |
| 109 | if (cpu_has_dc_aliases) |
| 110 | preempt_enable(); |
| 111 | #endif |
| 112 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 114 | static inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size) |
| 115 | { |
| 116 | if (cpu_has_dc_aliases) { |
| 117 | unsigned long end = addr + size; |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 118 | |
| 119 | while (addr < end) { |
| 120 | local_flush_data_cache_page((void *)addr); |
| 121 | addr += PAGE_SIZE; |
| 122 | } |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 126 | /* |
| 127 | * insw() and gang might be called with interrupts disabled, so we can't |
| 128 | * send IPIs for flushing due to the potencial of deadlocks, see the comment |
| 129 | * above smp_call_function() in arch/mips/kernel/smp.c. We work around the |
| 130 | * problem by disabling preemption so we know we actually perform the flush |
| 131 | * on the processor that actually has the lines to be flushed which hopefully |
| 132 | * is even better for performance anyway. |
| 133 | */ |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 134 | static inline void __ide_insw(unsigned long port, void *addr, |
| 135 | unsigned int count) |
| 136 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 137 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 138 | insw(port, addr, count); |
| 139 | __ide_flush_dcache_range((unsigned long)addr, count * 2); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 140 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static inline void __ide_insl(unsigned long port, void *addr, unsigned int count) |
| 144 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 145 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 146 | insl(port, addr, count); |
| 147 | __ide_flush_dcache_range((unsigned long)addr, count * 4); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 148 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static inline void __ide_outsw(unsigned long port, const void *addr, |
| 152 | unsigned long count) |
| 153 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 154 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 155 | outsw(port, addr, count); |
| 156 | __ide_flush_dcache_range((unsigned long)addr, count * 2); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 157 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static inline void __ide_outsl(unsigned long port, const void *addr, |
| 161 | unsigned long count) |
| 162 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 163 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 164 | outsl(port, addr, count); |
| 165 | __ide_flush_dcache_range((unsigned long)addr, count * 4); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 166 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count) |
| 170 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 171 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 172 | readsw(port, addr, count); |
| 173 | __ide_flush_dcache_range((unsigned long)addr, count * 2); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 174 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count) |
| 178 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 179 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 180 | readsl(port, addr, count); |
| 181 | __ide_flush_dcache_range((unsigned long)addr, count * 4); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 182 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count) |
| 186 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 187 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 188 | writesw(port, addr, count); |
| 189 | __ide_flush_dcache_range((unsigned long)addr, count * 2); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 190 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count) |
| 194 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 195 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 196 | writesl(port, addr, count); |
| 197 | __ide_flush_dcache_range((unsigned long)addr, count * 4); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 198 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /* ide_insw calls insw, not __ide_insw. Why? */ |
| 202 | #undef insw |
| 203 | #undef insl |
Atsushi Nemoto | a06d61c | 2005-11-06 23:58:21 +0900 | [diff] [blame] | 204 | #undef outsw |
| 205 | #undef outsl |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 206 | #define insw(port, addr, count) __ide_insw(port, addr, count) |
| 207 | #define insl(port, addr, count) __ide_insl(port, addr, count) |
Atsushi Nemoto | a06d61c | 2005-11-06 23:58:21 +0900 | [diff] [blame] | 208 | #define outsw(port, addr, count) __ide_outsw(port, addr, count) |
| 209 | #define outsl(port, addr, count) __ide_outsl(port, addr, count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | #endif /* __KERNEL__ */ |
| 212 | |
| 213 | #endif /* __ASM_MACH_GENERIC_IDE_H */ |