18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
38c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
48c2ecf20Sopenharmony_ci * for more details.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 1994-1996  Linus Torvalds & authors
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copied from i386; many of the especially older MIPS or ISA-based platforms
98c2ecf20Sopenharmony_ci * are basically identical.  Using this file probably implies i8259 PIC
108c2ecf20Sopenharmony_ci * support in a system but the very least interrupt numbers 0 - 15 need to
118c2ecf20Sopenharmony_ci * be put aside for legacy devices.
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci#ifndef __ASM_MACH_GENERIC_IDE_H
148c2ecf20Sopenharmony_ci#define __ASM_MACH_GENERIC_IDE_H
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#ifdef __KERNEL__
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <linux/pci.h>
198c2ecf20Sopenharmony_ci#include <linux/stddef.h>
208c2ecf20Sopenharmony_ci#include <asm/processor.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/* MIPS port and memory-mapped I/O string operations.  */
238c2ecf20Sopenharmony_cistatic inline void __ide_flush_prologue(void)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
268c2ecf20Sopenharmony_ci	if (cpu_has_dc_aliases || !cpu_has_ic_fills_f_dc)
278c2ecf20Sopenharmony_ci		preempt_disable();
288c2ecf20Sopenharmony_ci#endif
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic inline void __ide_flush_epilogue(void)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
348c2ecf20Sopenharmony_ci	if (cpu_has_dc_aliases || !cpu_has_ic_fills_f_dc)
358c2ecf20Sopenharmony_ci		preempt_enable();
368c2ecf20Sopenharmony_ci#endif
378c2ecf20Sopenharmony_ci}
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistatic inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size)
408c2ecf20Sopenharmony_ci{
418c2ecf20Sopenharmony_ci	if (cpu_has_dc_aliases || !cpu_has_ic_fills_f_dc) {
428c2ecf20Sopenharmony_ci		unsigned long end = addr + size;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci		while (addr < end) {
458c2ecf20Sopenharmony_ci			local_flush_data_cache_page((void *)addr);
468c2ecf20Sopenharmony_ci			addr += PAGE_SIZE;
478c2ecf20Sopenharmony_ci		}
488c2ecf20Sopenharmony_ci	}
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/*
528c2ecf20Sopenharmony_ci * insw() and gang might be called with interrupts disabled, so we can't
538c2ecf20Sopenharmony_ci * send IPIs for flushing due to the potencial of deadlocks, see the comment
548c2ecf20Sopenharmony_ci * above smp_call_function() in arch/mips/kernel/smp.c.	 We work around the
558c2ecf20Sopenharmony_ci * problem by disabling preemption so we know we actually perform the flush
568c2ecf20Sopenharmony_ci * on the processor that actually has the lines to be flushed which hopefully
578c2ecf20Sopenharmony_ci * is even better for performance anyway.
588c2ecf20Sopenharmony_ci */
598c2ecf20Sopenharmony_cistatic inline void __ide_insw(unsigned long port, void *addr,
608c2ecf20Sopenharmony_ci	unsigned int count)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci	__ide_flush_prologue();
638c2ecf20Sopenharmony_ci	insw(port, addr, count);
648c2ecf20Sopenharmony_ci	__ide_flush_dcache_range((unsigned long)addr, count * 2);
658c2ecf20Sopenharmony_ci	__ide_flush_epilogue();
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic inline void __ide_insl(unsigned long port, void *addr, unsigned int count)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	__ide_flush_prologue();
718c2ecf20Sopenharmony_ci	insl(port, addr, count);
728c2ecf20Sopenharmony_ci	__ide_flush_dcache_range((unsigned long)addr, count * 4);
738c2ecf20Sopenharmony_ci	__ide_flush_epilogue();
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistatic inline void __ide_outsw(unsigned long port, const void *addr,
778c2ecf20Sopenharmony_ci	unsigned long count)
788c2ecf20Sopenharmony_ci{
798c2ecf20Sopenharmony_ci	__ide_flush_prologue();
808c2ecf20Sopenharmony_ci	outsw(port, addr, count);
818c2ecf20Sopenharmony_ci	__ide_flush_dcache_range((unsigned long)addr, count * 2);
828c2ecf20Sopenharmony_ci	__ide_flush_epilogue();
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic inline void __ide_outsl(unsigned long port, const void *addr,
868c2ecf20Sopenharmony_ci	unsigned long count)
878c2ecf20Sopenharmony_ci{
888c2ecf20Sopenharmony_ci	__ide_flush_prologue();
898c2ecf20Sopenharmony_ci	outsl(port, addr, count);
908c2ecf20Sopenharmony_ci	__ide_flush_dcache_range((unsigned long)addr, count * 4);
918c2ecf20Sopenharmony_ci	__ide_flush_epilogue();
928c2ecf20Sopenharmony_ci}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistatic inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci	__ide_flush_prologue();
978c2ecf20Sopenharmony_ci	readsw(port, addr, count);
988c2ecf20Sopenharmony_ci	__ide_flush_dcache_range((unsigned long)addr, count * 2);
998c2ecf20Sopenharmony_ci	__ide_flush_epilogue();
1008c2ecf20Sopenharmony_ci}
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistatic inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count)
1038c2ecf20Sopenharmony_ci{
1048c2ecf20Sopenharmony_ci	__ide_flush_prologue();
1058c2ecf20Sopenharmony_ci	readsl(port, addr, count);
1068c2ecf20Sopenharmony_ci	__ide_flush_dcache_range((unsigned long)addr, count * 4);
1078c2ecf20Sopenharmony_ci	__ide_flush_epilogue();
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	__ide_flush_prologue();
1138c2ecf20Sopenharmony_ci	writesw(port, addr, count);
1148c2ecf20Sopenharmony_ci	__ide_flush_dcache_range((unsigned long)addr, count * 2);
1158c2ecf20Sopenharmony_ci	__ide_flush_epilogue();
1168c2ecf20Sopenharmony_ci}
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistatic inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
1198c2ecf20Sopenharmony_ci{
1208c2ecf20Sopenharmony_ci	__ide_flush_prologue();
1218c2ecf20Sopenharmony_ci	writesl(port, addr, count);
1228c2ecf20Sopenharmony_ci	__ide_flush_dcache_range((unsigned long)addr, count * 4);
1238c2ecf20Sopenharmony_ci	__ide_flush_epilogue();
1248c2ecf20Sopenharmony_ci}
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci/* ide_insw calls insw, not __ide_insw.	 Why? */
1278c2ecf20Sopenharmony_ci#undef insw
1288c2ecf20Sopenharmony_ci#undef insl
1298c2ecf20Sopenharmony_ci#undef outsw
1308c2ecf20Sopenharmony_ci#undef outsl
1318c2ecf20Sopenharmony_ci#define insw(port, addr, count) __ide_insw(port, addr, count)
1328c2ecf20Sopenharmony_ci#define insl(port, addr, count) __ide_insl(port, addr, count)
1338c2ecf20Sopenharmony_ci#define outsw(port, addr, count) __ide_outsw(port, addr, count)
1348c2ecf20Sopenharmony_ci#define outsl(port, addr, count) __ide_outsl(port, addr, count)
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#endif /* __ASM_MACH_GENERIC_IDE_H */
139