ide.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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_probe_legacy(void)
  28. {
  29. #ifdef CONFIG_PCI
  30. struct pci_dev *dev;
  31. /*
  32. * This can be called on the ide_setup() path, super-early in
  33. * boot. But the down_read() will enable local interrupts,
  34. * which can cause some machines to crash. So here we detect
  35. * and flag that situation and bail out early.
  36. */
  37. if (no_pci_devices())
  38. return 0;
  39. dev = pci_get_class(PCI_CLASS_BRIDGE_EISA << 8, NULL);
  40. if (dev)
  41. goto found;
  42. dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
  43. if (dev)
  44. goto found;
  45. return 0;
  46. found:
  47. pci_dev_put(dev);
  48. return 1;
  49. #elif defined(CONFIG_EISA) || defined(CONFIG_ISA)
  50. return 1;
  51. #else
  52. return 0;
  53. #endif
  54. }
  55. static __inline__ int ide_default_irq(unsigned long base)
  56. {
  57. switch (base) {
  58. case 0x1f0: return 14;
  59. case 0x170: return 15;
  60. case 0x1e8: return 11;
  61. case 0x168: return 10;
  62. case 0x1e0: return 8;
  63. case 0x160: return 12;
  64. default:
  65. return 0;
  66. }
  67. }
  68. static __inline__ unsigned long ide_default_io_base(int index)
  69. {
  70. if (!ide_probe_legacy())
  71. return 0;
  72. /*
  73. * If PCI is present then it is not safe to poke around
  74. * the other legacy IDE ports. Only 0x1f0 and 0x170 are
  75. * defined compatibility mode ports for PCI. A user can
  76. * override this using ide= but we must default safe.
  77. */
  78. if (no_pci_devices()) {
  79. switch (index) {
  80. case 2: return 0x1e8;
  81. case 3: return 0x168;
  82. case 4: return 0x1e0;
  83. case 5: return 0x160;
  84. }
  85. }
  86. switch (index) {
  87. case 0: return 0x1f0;
  88. case 1: return 0x170;
  89. default:
  90. return 0;
  91. }
  92. }
  93. #define IDE_ARCH_OBSOLETE_INIT
  94. #define ide_default_io_ctl(base) ((base) + 0x206) /* obsolete */
  95. #ifdef CONFIG_BLK_DEV_IDEPCI
  96. #define ide_init_default_irq(base) (0)
  97. #else
  98. #define ide_init_default_irq(base) ide_default_irq(base)
  99. #endif
  100. /* MIPS port and memory-mapped I/O string operations. */
  101. static inline void __ide_flush_prologue(void)
  102. {
  103. #ifdef CONFIG_SMP
  104. if (cpu_has_dc_aliases)
  105. preempt_disable();
  106. #endif
  107. }
  108. static inline void __ide_flush_epilogue(void)
  109. {
  110. #ifdef CONFIG_SMP
  111. if (cpu_has_dc_aliases)
  112. preempt_enable();
  113. #endif
  114. }
  115. static inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size)
  116. {
  117. if (cpu_has_dc_aliases) {
  118. unsigned long end = addr + size;
  119. while (addr < end) {
  120. local_flush_data_cache_page((void *)addr);
  121. addr += PAGE_SIZE;
  122. }
  123. }
  124. }
  125. /*
  126. * insw() and gang might be called with interrupts disabled, so we can't
  127. * send IPIs for flushing due to the potencial of deadlocks, see the comment
  128. * above smp_call_function() in arch/mips/kernel/smp.c. We work around the
  129. * problem by disabling preemption so we know we actually perform the flush
  130. * on the processor that actually has the lines to be flushed which hopefully
  131. * is even better for performance anyway.
  132. */
  133. static inline void __ide_insw(unsigned long port, void *addr,
  134. unsigned int count)
  135. {
  136. __ide_flush_prologue();
  137. insw(port, addr, count);
  138. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  139. __ide_flush_epilogue();
  140. }
  141. static inline void __ide_insl(unsigned long port, void *addr, unsigned int count)
  142. {
  143. __ide_flush_prologue();
  144. insl(port, addr, count);
  145. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  146. __ide_flush_epilogue();
  147. }
  148. static inline void __ide_outsw(unsigned long port, const void *addr,
  149. unsigned long count)
  150. {
  151. __ide_flush_prologue();
  152. outsw(port, addr, count);
  153. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  154. __ide_flush_epilogue();
  155. }
  156. static inline void __ide_outsl(unsigned long port, const void *addr,
  157. unsigned long count)
  158. {
  159. __ide_flush_prologue();
  160. outsl(port, addr, count);
  161. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  162. __ide_flush_epilogue();
  163. }
  164. static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count)
  165. {
  166. __ide_flush_prologue();
  167. readsw(port, addr, count);
  168. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  169. __ide_flush_epilogue();
  170. }
  171. static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count)
  172. {
  173. __ide_flush_prologue();
  174. readsl(port, addr, count);
  175. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  176. __ide_flush_epilogue();
  177. }
  178. static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count)
  179. {
  180. __ide_flush_prologue();
  181. writesw(port, addr, count);
  182. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  183. __ide_flush_epilogue();
  184. }
  185. static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
  186. {
  187. __ide_flush_prologue();
  188. writesl(port, addr, count);
  189. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  190. __ide_flush_epilogue();
  191. }
  192. /* ide_insw calls insw, not __ide_insw. Why? */
  193. #undef insw
  194. #undef insl
  195. #undef outsw
  196. #undef outsl
  197. #define insw(port, addr, count) __ide_insw(port, addr, count)
  198. #define insl(port, addr, count) __ide_insl(port, addr, count)
  199. #define outsw(port, addr, count) __ide_outsw(port, addr, count)
  200. #define outsl(port, addr, count) __ide_outsl(port, addr, count)
  201. #endif /* __KERNEL__ */
  202. #endif /* __ASM_MACH_GENERIC_IDE_H */