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