blob: f34740ee6775ba77a80019b7277790b17dc76484 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/pci.h>
19#include <linux/stddef.h>
Ralf Baechle9447cbf2005-04-19 12:26:59 +000020#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
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 Nemoto6440fcf2007-09-04 23:02:02 +090030static __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;
49found:
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 Torvalds1da177e2005-04-16 15:20:36 -070059static __inline__ int ide_default_irq(unsigned long base)
60{
Ralf Baechleb5438582007-08-07 17:18:28 +010061 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 Torvalds1da177e2005-04-16 15:20:36 -070068 default:
69 return 0;
Ralf Baechleb5438582007-08-07 17:18:28 +010070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
73static __inline__ unsigned long ide_default_io_base(int index)
74{
Ralf Baechleb5438582007-08-07 17:18:28 +010075 switch (index) {
76 case 0: return 0x1f0;
77 case 1: return 0x170;
Bartlomiej Zolnierkiewiczb6cd7da2008-07-24 22:53:28 +020078 case 2: return 0x1e8;
79 case 3: return 0x168;
80 case 4: return 0x1e0;
81 case 5: return 0x160;
Ralf Baechleb5438582007-08-07 17:18:28 +010082 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 return 0;
Ralf Baechleb5438582007-08-07 17:18:28 +010084 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087/* MIPS port and memory-mapped I/O string operations. */
Ralf Baechle7e3bfc72006-04-05 20:42:04 +010088static inline void __ide_flush_prologue(void)
89{
90#ifdef CONFIG_SMP
91 if (cpu_has_dc_aliases)
92 preempt_disable();
93#endif
94}
95
96static inline void __ide_flush_epilogue(void)
97{
98#ifdef CONFIG_SMP
99 if (cpu_has_dc_aliases)
100 preempt_enable();
101#endif
102}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000104static inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size)
105{
106 if (cpu_has_dc_aliases) {
107 unsigned long end = addr + size;
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100108
109 while (addr < end) {
110 local_flush_data_cache_page((void *)addr);
111 addr += PAGE_SIZE;
112 }
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000113 }
114}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100116/*
117 * insw() and gang might be called with interrupts disabled, so we can't
118 * send IPIs for flushing due to the potencial of deadlocks, see the comment
119 * above smp_call_function() in arch/mips/kernel/smp.c. We work around the
120 * problem by disabling preemption so we know we actually perform the flush
121 * on the processor that actually has the lines to be flushed which hopefully
122 * is even better for performance anyway.
123 */
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000124static inline void __ide_insw(unsigned long port, void *addr,
125 unsigned int count)
126{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100127 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000128 insw(port, addr, count);
129 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100130 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000131}
132
133static inline void __ide_insl(unsigned long port, void *addr, unsigned int count)
134{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100135 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000136 insl(port, addr, count);
137 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100138 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000139}
140
141static inline void __ide_outsw(unsigned long port, const void *addr,
142 unsigned long count)
143{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100144 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000145 outsw(port, addr, count);
146 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100147 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000148}
149
150static inline void __ide_outsl(unsigned long port, const void *addr,
151 unsigned long count)
152{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100153 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000154 outsl(port, addr, count);
155 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100156 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000157}
158
159static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count)
160{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100161 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000162 readsw(port, addr, count);
163 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100164 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000165}
166
167static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count)
168{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100169 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000170 readsl(port, addr, count);
171 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100172 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000173}
174
175static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count)
176{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100177 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000178 writesw(port, addr, count);
179 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100180 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000181}
182
183static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
184{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100185 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000186 writesl(port, addr, count);
187 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100188 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000189}
190
191/* ide_insw calls insw, not __ide_insw. Why? */
192#undef insw
193#undef insl
Atsushi Nemotoa06d61c2005-11-06 23:58:21 +0900194#undef outsw
195#undef outsl
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000196#define insw(port, addr, count) __ide_insw(port, addr, count)
197#define insl(port, addr, count) __ide_insl(port, addr, count)
Atsushi Nemotoa06d61c2005-11-06 23:58:21 +0900198#define outsw(port, addr, count) __ide_outsw(port, addr, count)
199#define outsl(port, addr, count) __ide_outsl(port, addr, count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201#endif /* __KERNEL__ */
202
203#endif /* __ASM_MACH_GENERIC_IDE_H */