ide.h 5.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 1994-1996  Linus Torvalds & authors
 *
 * Copied from i386; many of the especially older MIPS or ISA-based platforms
 * are basically identical.  Using this file probably implies i8259 PIC
 * support in a system but the very least interrupt numbers 0 - 15 need to
 * be put aside for legacy devices.
 */
#ifndef __ASM_MACH_GENERIC_IDE_H
#define __ASM_MACH_GENERIC_IDE_H

#ifdef __KERNEL__

#include <linux/config.h>
#include <linux/pci.h>
#include <linux/stddef.h>
21
#include <asm/processor.h>
L
Linus Torvalds 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

#ifndef MAX_HWIFS
# ifdef CONFIG_BLK_DEV_IDEPCI
#define MAX_HWIFS	10
# else
#define MAX_HWIFS	6
# endif
#endif

#define IDE_ARCH_OBSOLETE_DEFAULTS

static __inline__ int ide_probe_legacy(void)
{
#ifdef CONFIG_PCI
	struct pci_dev *dev;
	if ((dev = pci_get_class(PCI_CLASS_BRIDGE_EISA << 8, NULL)) != NULL ||
	    (dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL)) != NULL) {
		pci_dev_put(dev);

		return 1;
	}
	return 0;
#elif defined(CONFIG_EISA) || defined(CONFIG_ISA)
	return 1;
#else
	return 0;
#endif
}

static __inline__ int ide_default_irq(unsigned long base)
{
	if (ide_probe_legacy())
		switch (base) {
		case 0x1f0:
			return 14;
		case 0x170:
			return 15;
		case 0x1e8:
			return 11;
		case 0x168:
			return 10;
		case 0x1e0:
			return 8;
		case 0x160:
			return 12;
		default:
			return 0;
		}
	else
		return 0;
}

static __inline__ unsigned long ide_default_io_base(int index)
{
	if (ide_probe_legacy())
		switch (index) {
		case 0:
			return 0x1f0;
		case 1:
			return 0x170;
		case 2:
			return 0x1e8;
		case 3:
			return 0x168;
		case 4:
			return 0x1e0;
		case 5:
			return 0x160;
		default:
			return 0;
		}
	else
		return 0;
}

#define IDE_ARCH_OBSOLETE_INIT
#define ide_default_io_ctl(base)	((base) + 0x206) /* obsolete */

#ifdef CONFIG_BLK_DEV_IDEPCI
#define ide_init_default_irq(base)	(0)
#else
#define ide_init_default_irq(base)	ide_default_irq(base)
#endif

/* MIPS port and memory-mapped I/O string operations.  */
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
static inline void __ide_flush_prologue(void)
{
#ifdef CONFIG_SMP
	if (cpu_has_dc_aliases)
		preempt_disable();
#endif
}

static inline void __ide_flush_epilogue(void)
{
#ifdef CONFIG_SMP
	if (cpu_has_dc_aliases)
		preempt_enable();
#endif
}
L
Linus Torvalds 已提交
122

123 124 125 126
static inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size)
{
	if (cpu_has_dc_aliases) {
		unsigned long end = addr + size;
127 128 129 130 131

		while (addr < end) {
			local_flush_data_cache_page((void *)addr);
			addr += PAGE_SIZE;
		}
132 133 134
	}
}

135 136 137 138 139 140 141 142
/*
 * insw() and gang might be called with interrupts disabled, so we can't
 * send IPIs for flushing due to the potencial of deadlocks, see the comment
 * above smp_call_function() in arch/mips/kernel/smp.c.  We work around the
 * problem by disabling preemption so we know we actually perform the flush
 * on the processor that actually has the lines to be flushed which hopefully
 * is even better for performance anyway.
 */
143 144 145
static inline void __ide_insw(unsigned long port, void *addr,
	unsigned int count)
{
146
	__ide_flush_prologue();
147 148
	insw(port, addr, count);
	__ide_flush_dcache_range((unsigned long)addr, count * 2);
149
	__ide_flush_epilogue();
150 151 152 153
}

static inline void __ide_insl(unsigned long port, void *addr, unsigned int count)
{
154
	__ide_flush_prologue();
155 156
	insl(port, addr, count);
	__ide_flush_dcache_range((unsigned long)addr, count * 4);
157
	__ide_flush_epilogue();
158 159 160 161 162
}

static inline void __ide_outsw(unsigned long port, const void *addr,
	unsigned long count)
{
163
	__ide_flush_prologue();
164 165
	outsw(port, addr, count);
	__ide_flush_dcache_range((unsigned long)addr, count * 2);
166
	__ide_flush_epilogue();
167 168 169 170 171
}

static inline void __ide_outsl(unsigned long port, const void *addr,
	unsigned long count)
{
172
	__ide_flush_prologue();
173 174
	outsl(port, addr, count);
	__ide_flush_dcache_range((unsigned long)addr, count * 4);
175
	__ide_flush_epilogue();
176 177 178 179
}

static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count)
{
180
	__ide_flush_prologue();
181 182
	readsw(port, addr, count);
	__ide_flush_dcache_range((unsigned long)addr, count * 2);
183
	__ide_flush_epilogue();
184 185 186 187
}

static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count)
{
188
	__ide_flush_prologue();
189 190
	readsl(port, addr, count);
	__ide_flush_dcache_range((unsigned long)addr, count * 4);
191
	__ide_flush_epilogue();
192 193 194 195
}

static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count)
{
196
	__ide_flush_prologue();
197 198
	writesw(port, addr, count);
	__ide_flush_dcache_range((unsigned long)addr, count * 2);
199
	__ide_flush_epilogue();
200 201 202 203
}

static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
{
204
	__ide_flush_prologue();
205 206
	writesl(port, addr, count);
	__ide_flush_dcache_range((unsigned long)addr, count * 4);
207
	__ide_flush_epilogue();
208
}
L
Linus Torvalds 已提交
209

210 211 212
/* ide_insw calls insw, not __ide_insw.  Why? */
#undef insw
#undef insl
213 214
#undef outsw
#undef outsl
215 216
#define insw(port, addr, count) __ide_insw(port, addr, count)
#define insl(port, addr, count) __ide_insl(port, addr, count)
217 218
#define outsw(port, addr, count) __ide_outsw(port, addr, count)
#define outsl(port, addr, count) __ide_outsl(port, addr, count)
L
Linus Torvalds 已提交
219 220 221 222

#endif /* __KERNEL__ */

#endif /* __ASM_MACH_GENERIC_IDE_H */