ide.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #ifdef __KERNEL__
  16. #include <linux/pci.h>
  17. #include <linux/stddef.h>
  18. #include <asm/processor.h>
  19. #ifndef MAX_HWIFS
  20. # ifdef CONFIG_BLK_DEV_IDEPCI
  21. #define MAX_HWIFS 10
  22. # else
  23. #define MAX_HWIFS 6
  24. # endif
  25. #endif
  26. #define IDE_ARCH_OBSOLETE_DEFAULTS
  27. static __inline__ int ide_default_irq(unsigned long base)
  28. {
  29. switch (base) {
  30. case 0x1f0: return 14;
  31. case 0x170: return 15;
  32. case 0x1e8: return 11;
  33. case 0x168: return 10;
  34. case 0x1e0: return 8;
  35. case 0x160: return 12;
  36. default:
  37. return 0;
  38. }
  39. }
  40. static __inline__ unsigned long ide_default_io_base(int index)
  41. {
  42. /*
  43. * If PCI is present then it is not safe to poke around
  44. * the other legacy IDE ports. Only 0x1f0 and 0x170 are
  45. * defined compatibility mode ports for PCI. A user can
  46. * override this using ide= but we must default safe.
  47. */
  48. if (no_pci_devices()) {
  49. switch (index) {
  50. case 2: return 0x1e8;
  51. case 3: return 0x168;
  52. case 4: return 0x1e0;
  53. case 5: return 0x160;
  54. }
  55. }
  56. switch (index) {
  57. case 0: return 0x1f0;
  58. case 1: return 0x170;
  59. default:
  60. return 0;
  61. }
  62. }
  63. #define IDE_ARCH_OBSOLETE_INIT
  64. #define ide_default_io_ctl(base) ((base) + 0x206) /* obsolete */
  65. #ifdef CONFIG_BLK_DEV_IDEPCI
  66. #define ide_init_default_irq(base) (0)
  67. #else
  68. #define ide_init_default_irq(base) ide_default_irq(base)
  69. #endif
  70. /* MIPS port and memory-mapped I/O string operations. */
  71. static inline void __ide_flush_prologue(void)
  72. {
  73. #ifdef CONFIG_SMP
  74. if (cpu_has_dc_aliases)
  75. preempt_disable();
  76. #endif
  77. }
  78. static inline void __ide_flush_epilogue(void)
  79. {
  80. #ifdef CONFIG_SMP
  81. if (cpu_has_dc_aliases)
  82. preempt_enable();
  83. #endif
  84. }
  85. static inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size)
  86. {
  87. if (cpu_has_dc_aliases) {
  88. unsigned long end = addr + size;
  89. while (addr < end) {
  90. local_flush_data_cache_page((void *)addr);
  91. addr += PAGE_SIZE;
  92. }
  93. }
  94. }
  95. /*
  96. * insw() and gang might be called with interrupts disabled, so we can't
  97. * send IPIs for flushing due to the potencial of deadlocks, see the comment
  98. * above smp_call_function() in arch/mips/kernel/smp.c. We work around the
  99. * problem by disabling preemption so we know we actually perform the flush
  100. * on the processor that actually has the lines to be flushed which hopefully
  101. * is even better for performance anyway.
  102. */
  103. static inline void __ide_insw(unsigned long port, void *addr,
  104. unsigned int count)
  105. {
  106. __ide_flush_prologue();
  107. insw(port, addr, count);
  108. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  109. __ide_flush_epilogue();
  110. }
  111. static inline void __ide_insl(unsigned long port, void *addr, unsigned int count)
  112. {
  113. __ide_flush_prologue();
  114. insl(port, addr, count);
  115. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  116. __ide_flush_epilogue();
  117. }
  118. static inline void __ide_outsw(unsigned long port, const void *addr,
  119. unsigned long count)
  120. {
  121. __ide_flush_prologue();
  122. outsw(port, addr, count);
  123. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  124. __ide_flush_epilogue();
  125. }
  126. static inline void __ide_outsl(unsigned long port, const void *addr,
  127. unsigned long count)
  128. {
  129. __ide_flush_prologue();
  130. outsl(port, addr, count);
  131. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  132. __ide_flush_epilogue();
  133. }
  134. static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count)
  135. {
  136. __ide_flush_prologue();
  137. readsw(port, addr, count);
  138. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  139. __ide_flush_epilogue();
  140. }
  141. static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count)
  142. {
  143. __ide_flush_prologue();
  144. readsl(port, addr, count);
  145. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  146. __ide_flush_epilogue();
  147. }
  148. static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count)
  149. {
  150. __ide_flush_prologue();
  151. writesw(port, addr, count);
  152. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  153. __ide_flush_epilogue();
  154. }
  155. static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
  156. {
  157. __ide_flush_prologue();
  158. writesl(port, addr, count);
  159. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  160. __ide_flush_epilogue();
  161. }
  162. /* ide_insw calls insw, not __ide_insw. Why? */
  163. #undef insw
  164. #undef insl
  165. #undef outsw
  166. #undef outsl
  167. #define insw(port, addr, count) __ide_insw(port, addr, count)
  168. #define insl(port, addr, count) __ide_insl(port, addr, count)
  169. #define outsw(port, addr, count) __ide_outsw(port, addr, count)
  170. #define outsl(port, addr, count) __ide_outsl(port, addr, count)
  171. #endif /* __KERNEL__ */
  172. #endif /* __ASM_MACH_GENERIC_IDE_H */