blob: 73008f7bdc93708281e647889a7e3d6c6be87c41 [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
Atsushi Nemoto6440fcf2007-09-04 23:02:02 +090022static __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;
41found:
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 Torvalds1da177e2005-04-16 15:20:36 -070051/* MIPS port and memory-mapped I/O string operations. */
Ralf Baechle7e3bfc72006-04-05 20:42:04 +010052static inline void __ide_flush_prologue(void)
53{
54#ifdef CONFIG_SMP
55 if (cpu_has_dc_aliases)
56 preempt_disable();
57#endif
58}
59
60static inline void __ide_flush_epilogue(void)
61{
62#ifdef CONFIG_SMP
63 if (cpu_has_dc_aliases)
64 preempt_enable();
65#endif
66}
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Ralf Baechle9447cbf2005-04-19 12:26:59 +000068static 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 Baechle7e3bfc72006-04-05 20:42:04 +010072
73 while (addr < end) {
74 local_flush_data_cache_page((void *)addr);
75 addr += PAGE_SIZE;
76 }
Ralf Baechle9447cbf2005-04-19 12:26:59 +000077 }
78}
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Ralf Baechle7e3bfc72006-04-05 20:42:04 +010080/*
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 Baechle9447cbf2005-04-19 12:26:59 +000088static inline void __ide_insw(unsigned long port, void *addr,
89 unsigned int count)
90{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +010091 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +000092 insw(port, addr, count);
93 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +010094 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +000095}
96
97static inline void __ide_insl(unsigned long port, void *addr, unsigned int count)
98{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +010099 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000100 insl(port, addr, count);
101 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100102 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000103}
104
105static inline void __ide_outsw(unsigned long port, const void *addr,
106 unsigned long count)
107{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100108 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000109 outsw(port, addr, count);
110 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100111 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000112}
113
114static inline void __ide_outsl(unsigned long port, const void *addr,
115 unsigned long count)
116{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100117 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000118 outsl(port, addr, count);
119 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100120 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000121}
122
123static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count)
124{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100125 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000126 readsw(port, addr, count);
127 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100128 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000129}
130
131static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count)
132{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100133 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000134 readsl(port, addr, count);
135 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100136 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000137}
138
139static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count)
140{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100141 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000142 writesw(port, addr, count);
143 __ide_flush_dcache_range((unsigned long)addr, count * 2);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100144 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000145}
146
147static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
148{
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100149 __ide_flush_prologue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000150 writesl(port, addr, count);
151 __ide_flush_dcache_range((unsigned long)addr, count * 4);
Ralf Baechle7e3bfc72006-04-05 20:42:04 +0100152 __ide_flush_epilogue();
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000153}
154
155/* ide_insw calls insw, not __ide_insw. Why? */
156#undef insw
157#undef insl
Atsushi Nemotoa06d61c2005-11-06 23:58:21 +0900158#undef outsw
159#undef outsl
Ralf Baechle9447cbf2005-04-19 12:26:59 +0000160#define insw(port, addr, count) __ide_insw(port, addr, count)
161#define insl(port, addr, count) __ide_insl(port, addr, count)
Atsushi Nemotoa06d61c2005-11-06 23:58:21 +0900162#define outsw(port, addr, count) __ide_outsw(port, addr, count)
163#define outsl(port, addr, count) __ide_outsl(port, addr, count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165#endif /* __KERNEL__ */
166
167#endif /* __ASM_MACH_GENERIC_IDE_H */