ide.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. static __inline__ int ide_probe_legacy(void)
  20. {
  21. #ifdef CONFIG_PCI
  22. struct pci_dev *dev;
  23. /*
  24. * This can be called on the ide_setup() path, super-early in
  25. * boot. But the down_read() will enable local interrupts,
  26. * which can cause some machines to crash. So here we detect
  27. * and flag that situation and bail out early.
  28. */
  29. if (no_pci_devices())
  30. return 0;
  31. dev = pci_get_class(PCI_CLASS_BRIDGE_EISA << 8, NULL);
  32. if (dev)
  33. goto found;
  34. dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
  35. if (dev)
  36. goto found;
  37. return 0;
  38. found:
  39. pci_dev_put(dev);
  40. return 1;
  41. #elif defined(CONFIG_EISA) || defined(CONFIG_ISA)
  42. return 1;
  43. #else
  44. return 0;
  45. #endif
  46. }
  47. /* MIPS port and memory-mapped I/O string operations. */
  48. static inline void __ide_flush_prologue(void)
  49. {
  50. #ifdef CONFIG_SMP
  51. if (cpu_has_dc_aliases)
  52. preempt_disable();
  53. #endif
  54. }
  55. static inline void __ide_flush_epilogue(void)
  56. {
  57. #ifdef CONFIG_SMP
  58. if (cpu_has_dc_aliases)
  59. preempt_enable();
  60. #endif
  61. }
  62. static inline void __ide_flush_dcache_range(unsigned long addr, unsigned long size)
  63. {
  64. if (cpu_has_dc_aliases) {
  65. unsigned long end = addr + size;
  66. while (addr < end) {
  67. local_flush_data_cache_page((void *)addr);
  68. addr += PAGE_SIZE;
  69. }
  70. }
  71. }
  72. /*
  73. * insw() and gang might be called with interrupts disabled, so we can't
  74. * send IPIs for flushing due to the potencial of deadlocks, see the comment
  75. * above smp_call_function() in arch/mips/kernel/smp.c. We work around the
  76. * problem by disabling preemption so we know we actually perform the flush
  77. * on the processor that actually has the lines to be flushed which hopefully
  78. * is even better for performance anyway.
  79. */
  80. static inline void __ide_insw(unsigned long port, void *addr,
  81. unsigned int count)
  82. {
  83. __ide_flush_prologue();
  84. insw(port, addr, count);
  85. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  86. __ide_flush_epilogue();
  87. }
  88. static inline void __ide_insl(unsigned long port, void *addr, unsigned int count)
  89. {
  90. __ide_flush_prologue();
  91. insl(port, addr, count);
  92. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  93. __ide_flush_epilogue();
  94. }
  95. static inline void __ide_outsw(unsigned long port, const void *addr,
  96. unsigned long count)
  97. {
  98. __ide_flush_prologue();
  99. outsw(port, addr, count);
  100. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  101. __ide_flush_epilogue();
  102. }
  103. static inline void __ide_outsl(unsigned long port, const void *addr,
  104. unsigned long count)
  105. {
  106. __ide_flush_prologue();
  107. outsl(port, addr, count);
  108. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  109. __ide_flush_epilogue();
  110. }
  111. static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count)
  112. {
  113. __ide_flush_prologue();
  114. readsw(port, addr, count);
  115. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  116. __ide_flush_epilogue();
  117. }
  118. static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count)
  119. {
  120. __ide_flush_prologue();
  121. readsl(port, addr, count);
  122. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  123. __ide_flush_epilogue();
  124. }
  125. static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 count)
  126. {
  127. __ide_flush_prologue();
  128. writesw(port, addr, count);
  129. __ide_flush_dcache_range((unsigned long)addr, count * 2);
  130. __ide_flush_epilogue();
  131. }
  132. static inline void __ide_mm_outsl(void __iomem * port, void *addr, u32 count)
  133. {
  134. __ide_flush_prologue();
  135. writesl(port, addr, count);
  136. __ide_flush_dcache_range((unsigned long)addr, count * 4);
  137. __ide_flush_epilogue();
  138. }
  139. /* ide_insw calls insw, not __ide_insw. Why? */
  140. #undef insw
  141. #undef insl
  142. #undef outsw
  143. #undef outsl
  144. #define insw(port, addr, count) __ide_insw(port, addr, count)
  145. #define insl(port, addr, count) __ide_insl(port, addr, count)
  146. #define outsw(port, addr, count) __ide_outsw(port, addr, count)
  147. #define outsl(port, addr, count) __ide_outsl(port, addr, count)
  148. #endif /* __KERNEL__ */
  149. #endif /* __ASM_MACH_GENERIC_IDE_H */