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 | |
Atsushi Nemoto | 6440fcf | 2007-09-04 23:02:02 +0900 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* MIPS port and memory-mapped I/O string operations. */ |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 52 | static inline void __ide_flush_prologue(void) |
| 53 | { |
| 54 | #ifdef CONFIG_SMP |
| 55 | if (cpu_has_dc_aliases) |
| 56 | preempt_disable(); |
| 57 | #endif |
| 58 | } |
| 59 | |
| 60 | static inline void __ide_flush_epilogue(void) |
| 61 | { |
| 62 | #ifdef CONFIG_SMP |
| 63 | if (cpu_has_dc_aliases) |
| 64 | preempt_enable(); |
| 65 | #endif |
| 66 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 68 | static inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size) |
| 69 | { |
| 70 | if (cpu_has_dc_aliases) { |
| 71 | unsigned long end = addr + size; |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 72 | |
| 73 | while (addr < end) { |
| 74 | local_flush_data_cache_page((void *)addr); |
| 75 | addr += PAGE_SIZE; |
| 76 | } |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 80 | /* |
| 81 | * insw() and gang might be called with interrupts disabled, so we can't |
| 82 | * send IPIs for flushing due to the potencial of deadlocks, see the comment |
| 83 | * above smp_call_function() in arch/mips/kernel/smp.c. We work around the |
| 84 | * problem by disabling preemption so we know we actually perform the flush |
| 85 | * on the processor that actually has the lines to be flushed which hopefully |
| 86 | * is even better for performance anyway. |
| 87 | */ |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 88 | static inline void __ide_insw(unsigned long port, void *addr, |
| 89 | unsigned int count) |
| 90 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 91 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 92 | insw(port, addr, count); |
| 93 | __ide_flush_dcache_range((unsigned long)addr, count * 2); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 94 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static inline void __ide_insl(unsigned long port, void *addr, unsigned int count) |
| 98 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 99 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 100 | insl(port, addr, count); |
| 101 | __ide_flush_dcache_range((unsigned long)addr, count * 4); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 102 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static inline void __ide_outsw(unsigned long port, const void *addr, |
| 106 | unsigned long count) |
| 107 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 108 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 109 | outsw(port, addr, count); |
| 110 | __ide_flush_dcache_range((unsigned long)addr, count * 2); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 111 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static inline void __ide_outsl(unsigned long port, const void *addr, |
| 115 | unsigned long count) |
| 116 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 117 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 118 | outsl(port, addr, count); |
| 119 | __ide_flush_dcache_range((unsigned long)addr, count * 4); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 120 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count) |
| 124 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 125 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 126 | readsw(port, addr, count); |
| 127 | __ide_flush_dcache_range((unsigned long)addr, count * 2); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 128 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count) |
| 132 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 133 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 134 | readsl(port, addr, count); |
| 135 | __ide_flush_dcache_range((unsigned long)addr, count * 4); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 136 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count) |
| 140 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 141 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 142 | writesw(port, addr, count); |
| 143 | __ide_flush_dcache_range((unsigned long)addr, count * 2); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 144 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count) |
| 148 | { |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 149 | __ide_flush_prologue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 150 | writesl(port, addr, count); |
| 151 | __ide_flush_dcache_range((unsigned long)addr, count * 4); |
Ralf Baechle | 7e3bfc7 | 2006-04-05 20:42:04 +0100 | [diff] [blame] | 152 | __ide_flush_epilogue(); |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /* ide_insw calls insw, not __ide_insw. Why? */ |
| 156 | #undef insw |
| 157 | #undef insl |
Atsushi Nemoto | a06d61c | 2005-11-06 23:58:21 +0900 | [diff] [blame] | 158 | #undef outsw |
| 159 | #undef outsl |
Ralf Baechle | 9447cbf | 2005-04-19 12:26:59 +0000 | [diff] [blame] | 160 | #define insw(port, addr, count) __ide_insw(port, addr, count) |
| 161 | #define insl(port, addr, count) __ide_insl(port, addr, count) |
Atsushi Nemoto | a06d61c | 2005-11-06 23:58:21 +0900 | [diff] [blame] | 162 | #define outsw(port, addr, count) __ide_outsw(port, addr, count) |
| 163 | #define outsl(port, addr, count) __ide_outsl(port, addr, count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | #endif /* __KERNEL__ */ |
| 166 | |
| 167 | #endif /* __ASM_MACH_GENERIC_IDE_H */ |