ide.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. /*
  70. * If PCI is present then it is not safe to poke around
  71. * the other legacy IDE ports. Only 0x1f0 and 0x170 are
  72. * defined compatibility mode ports for PCI. A user can
  73. * override this using ide= but we must default safe.
  74. */
  75. if (no_pci_devices()) {
  76. switch (index) {
  77. case 2: return 0x1e8;
  78. case 3: return 0x168;
  79. case 4: return 0x1e0;
  80. case 5: return 0x160;
  81. }
  82. }
  83. switch (index) {
  84. case 0: return 0x1f0;
  85. case 1: return 0x170;
  86. default:
  87. return 0;
  88. }
  89. }
  90. /* MIPS port and memory-mapped I/O string operations. */
  91. static inline void __ide_flush_prologue(void)
  92. {
  93. #ifdef CONFIG_SMP
  94. if (cpu_has_dc_aliases)
  95. preempt_disable();
  96. #endif
  97. }
  98. static inline void __ide_flush_epilogue(void)
  99. {
  100. #ifdef CONFIG_SMP
  101. if (cpu_has_dc_aliases)
  102. preempt_enable();
  103. #endif
  104. }
  105. static inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size)
  106. {
  107. if (cpu_has_dc_aliases) {
  108. unsigned long end = addr + size;
  109. while (addr < end) {
  110. local_flush_data_cache_page((void *)addr);
  111. addr += PAGE_SIZE;
  112. }
  113. }
  114. }
  115. /*
  116. * insw() and gang might be called with interrupts disabled, so we can't
  117. * send IPIs for flushing due to the potencial of deadlocks, see the comment
  118. * above smp_call_function() in arch/mips/kernel/smp.c. We work around the
  119. * problem by disabling preemption so we know we actually perform the flush
  120. * on the processor that actually has the lines to be flushed which hopefully
  121. * is even better for performance anyway.
  122. */
  123. static inline void __ide_insw(unsigned long port, void *addr,
  124. unsigned int count)
  125. {
  126. __ide_flush_prologue();
  127. insw(port, addr, count);
  128. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  129. __ide_flush_epilogue();
  130. }
  131. static inline void __ide_insl(unsigned long port, void *addr, unsigned int count)
  132. {
  133. __ide_flush_prologue();
  134. insl(port, addr, count);
  135. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  136. __ide_flush_epilogue();
  137. }
  138. static inline void __ide_outsw(unsigned long port, const void *addr,
  139. unsigned long count)
  140. {
  141. __ide_flush_prologue();
  142. outsw(port, addr, count);
  143. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  144. __ide_flush_epilogue();
  145. }
  146. static inline void __ide_outsl(unsigned long port, const void *addr,
  147. unsigned long count)
  148. {
  149. __ide_flush_prologue();
  150. outsl(port, addr, count);
  151. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  152. __ide_flush_epilogue();
  153. }
  154. static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count)
  155. {
  156. __ide_flush_prologue();
  157. readsw(port, addr, count);
  158. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  159. __ide_flush_epilogue();
  160. }
  161. static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count)
  162. {
  163. __ide_flush_prologue();
  164. readsl(port, addr, count);
  165. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  166. __ide_flush_epilogue();
  167. }
  168. static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count)
  169. {
  170. __ide_flush_prologue();
  171. writesw(port, addr, count);
  172. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  173. __ide_flush_epilogue();
  174. }
  175. static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
  176. {
  177. __ide_flush_prologue();
  178. writesl(port, addr, count);
  179. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  180. __ide_flush_epilogue();
  181. }
  182. /* ide_insw calls insw, not __ide_insw. Why? */
  183. #undef insw
  184. #undef insl
  185. #undef outsw
  186. #undef outsl
  187. #define insw(port, addr, count) __ide_insw(port, addr, count)
  188. #define insl(port, addr, count) __ide_insl(port, addr, count)
  189. #define outsw(port, addr, count) __ide_outsw(port, addr, count)
  190. #define outsl(port, addr, count) __ide_outsl(port, addr, count)
  191. #endif /* __KERNEL__ */
  192. #endif /* __ASM_MACH_GENERIC_IDE_H */