blockops.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #include <linux/kernel.h>
  2. #include <linux/init.h>
  3. #include <linux/errno.h>
  4. #include <linux/mm.h>
  5. #include <asm/memory.h>
  6. #include <asm/ptrace.h>
  7. #include <asm/cacheflush.h>
  8. #include <asm/traps.h>
  9. extern struct cpu_cache_fns blk_cache_fns;
  10. #define HARVARD_CACHE
  11. /*
  12. * blk_flush_kern_dcache_page(kaddr)
  13. *
  14. * Ensure that the data held in the page kaddr is written back
  15. * to the page in question.
  16. *
  17. * - kaddr - kernel address (guaranteed to be page aligned)
  18. */
  19. static void __attribute__((naked))
  20. blk_flush_kern_dcache_page(void *kaddr)
  21. {
  22. asm(
  23. "add r1, r0, %0 \n\
  24. 1: .word 0xec401f0e @ mcrr p15, 0, r0, r1, c14, 0 @ blocking \n\
  25. mov r0, #0 \n\
  26. mcr p15, 0, r0, c7, c5, 0 \n\
  27. mcr p15, 0, r0, c7, c10, 4 \n\
  28. mov pc, lr"
  29. :
  30. : "I" (PAGE_SIZE));
  31. }
  32. /*
  33. * blk_dma_inv_range(start,end)
  34. *
  35. * Invalidate the data cache within the specified region; we will
  36. * be performing a DMA operation in this region and we want to
  37. * purge old data in the cache.
  38. *
  39. * - start - virtual start address of region
  40. * - end - virtual end address of region
  41. */
  42. static void __attribute__((naked))
  43. blk_dma_inv_range_unified(unsigned long start, unsigned long end)
  44. {
  45. asm(
  46. "tst r0, %0 \n\
  47. mcrne p15, 0, r0, c7, c11, 1 @ clean unified line \n\
  48. tst r1, %0 \n\
  49. mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line\n\
  50. .word 0xec401f06 @ mcrr p15, 0, r1, r0, c6, 0 @ blocking \n\
  51. mov r0, #0 \n\
  52. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer \n\
  53. mov pc, lr"
  54. :
  55. : "I" (L1_CACHE_BYTES - 1));
  56. }
  57. static void __attribute__((naked))
  58. blk_dma_inv_range_harvard(unsigned long start, unsigned long end)
  59. {
  60. asm(
  61. "tst r0, %0 \n\
  62. mcrne p15, 0, r0, c7, c10, 1 @ clean D line \n\
  63. tst r1, %0 \n\
  64. mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D line \n\
  65. .word 0xec401f06 @ mcrr p15, 0, r1, r0, c6, 0 @ blocking \n\
  66. mov r0, #0 \n\
  67. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer \n\
  68. mov pc, lr"
  69. :
  70. : "I" (L1_CACHE_BYTES - 1));
  71. }
  72. /*
  73. * blk_dma_clean_range(start,end)
  74. * - start - virtual start address of region
  75. * - end - virtual end address of region
  76. */
  77. static void __attribute__((naked))
  78. blk_dma_clean_range(unsigned long start, unsigned long end)
  79. {
  80. asm(
  81. ".word 0xec401f0c @ mcrr p15, 0, r1, r0, c12, 0 @ blocking \n\
  82. mov r0, #0 \n\
  83. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer \n\
  84. mov pc, lr");
  85. }
  86. /*
  87. * blk_dma_flush_range(start,end)
  88. * - start - virtual start address of region
  89. * - end - virtual end address of region
  90. */
  91. static void __attribute__((naked))
  92. blk_dma_flush_range(unsigned long start, unsigned long end)
  93. {
  94. asm(
  95. ".word 0xec401f0e @ mcrr p15, 0, r1, r0, c14, 0 @ blocking \n\
  96. mov pc, lr");
  97. }
  98. static int blockops_trap(struct pt_regs *regs, unsigned int instr)
  99. {
  100. regs->ARM_r4 |= regs->ARM_r2;
  101. regs->ARM_pc += 4;
  102. return 0;
  103. }
  104. static char *func[] = {
  105. "Prefetch data range",
  106. "Clean+Invalidate data range",
  107. "Clean data range",
  108. "Invalidate data range",
  109. "Invalidate instr range"
  110. };
  111. static struct undef_hook blockops_hook __initdata = {
  112. .instr_mask = 0x0fffffd0,
  113. .instr_val = 0x0c401f00,
  114. .cpsr_mask = PSR_T_BIT,
  115. .cpsr_val = 0,
  116. .fn = blockops_trap,
  117. };
  118. static int __init blockops_check(void)
  119. {
  120. register unsigned int err asm("r4") = 0;
  121. unsigned int err_pos = 1;
  122. unsigned int cache_type;
  123. int i;
  124. asm("mrc p15, 0, %0, c0, c0, 1" : "=r" (cache_type));
  125. printk("Checking V6 block cache operations:\n");
  126. register_undef_hook(&blockops_hook);
  127. __asm__ ("mov r0, %0\n\t"
  128. "mov r1, %1\n\t"
  129. "mov r2, #1\n\t"
  130. ".word 0xec401f2c @ mcrr p15, 0, r1, r0, c12, 2\n\t"
  131. "mov r2, #2\n\t"
  132. ".word 0xec401f0e @ mcrr p15, 0, r1, r0, c14, 0\n\t"
  133. "mov r2, #4\n\t"
  134. ".word 0xec401f0c @ mcrr p15, 0, r1, r0, c12, 0\n\t"
  135. "mov r2, #8\n\t"
  136. ".word 0xec401f06 @ mcrr p15, 0, r1, r0, c6, 0\n\t"
  137. "mov r2, #16\n\t"
  138. ".word 0xec401f05 @ mcrr p15, 0, r1, r0, c5, 0\n\t"
  139. :
  140. : "r" (PAGE_OFFSET), "r" (PAGE_OFFSET + 128)
  141. : "r0", "r1", "r2");
  142. unregister_undef_hook(&blockops_hook);
  143. for (i = 0; i < ARRAY_SIZE(func); i++, err_pos <<= 1)
  144. printk("%30s: %ssupported\n", func[i], err & err_pos ? "not " : "");
  145. if ((err & 8) == 0) {
  146. printk(" --> Using %s block cache invalidate\n",
  147. cache_type & (1 << 24) ? "harvard" : "unified");
  148. if (cache_type & (1 << 24))
  149. cpu_cache.dma_inv_range = blk_dma_inv_range_harvard;
  150. else
  151. cpu_cache.dma_inv_range = blk_dma_inv_range_unified;
  152. }
  153. if ((err & 4) == 0) {
  154. printk(" --> Using block cache clean\n");
  155. cpu_cache.dma_clean_range = blk_dma_clean_range;
  156. }
  157. if ((err & 2) == 0) {
  158. printk(" --> Using block cache clean+invalidate\n");
  159. cpu_cache.dma_flush_range = blk_dma_flush_range;
  160. cpu_cache.flush_kern_dcache_page = blk_flush_kern_dcache_page;
  161. }
  162. return 0;
  163. }
  164. __initcall(blockops_check);