ide.h 5.5 KB

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