cache.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * linux/arch/m68k/mm/cache.c
  3. *
  4. * Instruction cache handling
  5. *
  6. * Copyright (C) 1995 Hamish Macdonald
  7. */
  8. #include <linux/module.h>
  9. #include <asm/pgalloc.h>
  10. #include <asm/traps.h>
  11. static unsigned long virt_to_phys_slow(unsigned long vaddr)
  12. {
  13. if (CPU_IS_060) {
  14. unsigned long paddr;
  15. /* The PLPAR instruction causes an access error if the translation
  16. * is not possible. To catch this we use the same exception mechanism
  17. * as for user space accesses in <asm/uaccess.h>. */
  18. asm volatile (".chip 68060\n"
  19. "1: plpar (%0)\n"
  20. ".chip 68k\n"
  21. "2:\n"
  22. ".section .fixup,\"ax\"\n"
  23. " .even\n"
  24. "3: sub.l %0,%0\n"
  25. " jra 2b\n"
  26. ".previous\n"
  27. ".section __ex_table,\"a\"\n"
  28. " .align 4\n"
  29. " .long 1b,3b\n"
  30. ".previous"
  31. : "=a" (paddr)
  32. : "0" (vaddr));
  33. return paddr;
  34. } else if (CPU_IS_040) {
  35. unsigned long mmusr;
  36. asm volatile (".chip 68040\n\t"
  37. "ptestr (%1)\n\t"
  38. "movec %%mmusr, %0\n\t"
  39. ".chip 68k"
  40. : "=r" (mmusr)
  41. : "a" (vaddr));
  42. if (mmusr & MMU_R_040)
  43. return (mmusr & PAGE_MASK) | (vaddr & ~PAGE_MASK);
  44. } else {
  45. unsigned short mmusr;
  46. unsigned long *descaddr;
  47. asm volatile ("ptestr %3,%2@,#7,%0\n\t"
  48. "pmove %%psr,%1"
  49. : "=a&" (descaddr), "=m" (mmusr)
  50. : "a" (vaddr), "d" (get_fs().seg));
  51. if (mmusr & (MMU_I|MMU_B|MMU_L))
  52. return 0;
  53. descaddr = phys_to_virt((unsigned long)descaddr);
  54. switch (mmusr & MMU_NUM) {
  55. case 1:
  56. return (*descaddr & 0xfe000000) | (vaddr & 0x01ffffff);
  57. case 2:
  58. return (*descaddr & 0xfffc0000) | (vaddr & 0x0003ffff);
  59. case 3:
  60. return (*descaddr & PAGE_MASK) | (vaddr & ~PAGE_MASK);
  61. }
  62. }
  63. return 0;
  64. }
  65. /* Push n pages at kernel virtual address and clear the icache */
  66. /* RZ: use cpush %bc instead of cpush %dc, cinv %ic */
  67. void flush_icache_range(unsigned long address, unsigned long endaddr)
  68. {
  69. if (CPU_IS_COLDFIRE) {
  70. unsigned long start, end;
  71. start = address & ICACHE_SET_MASK;
  72. end = endaddr & ICACHE_SET_MASK;
  73. if (start > end) {
  74. flush_cf_icache(0, end);
  75. end = ICACHE_MAX_ADDR;
  76. }
  77. flush_cf_icache(start, end);
  78. } else if (CPU_IS_040_OR_060) {
  79. address &= PAGE_MASK;
  80. do {
  81. asm volatile ("nop\n\t"
  82. ".chip 68040\n\t"
  83. "cpushp %%bc,(%0)\n\t"
  84. ".chip 68k"
  85. : : "a" (virt_to_phys_slow(address)));
  86. address += PAGE_SIZE;
  87. } while (address < endaddr);
  88. } else {
  89. unsigned long tmp;
  90. asm volatile ("movec %%cacr,%0\n\t"
  91. "orw %1,%0\n\t"
  92. "movec %0,%%cacr"
  93. : "=&d" (tmp)
  94. : "di" (FLUSH_I));
  95. }
  96. }
  97. EXPORT_SYMBOL(flush_icache_range);
  98. void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
  99. unsigned long addr, int len)
  100. {
  101. if (CPU_IS_COLDFIRE) {
  102. unsigned long start, end;
  103. start = addr & ICACHE_SET_MASK;
  104. end = (addr + len) & ICACHE_SET_MASK;
  105. if (start > end) {
  106. flush_cf_icache(0, end);
  107. end = ICACHE_MAX_ADDR;
  108. }
  109. flush_cf_icache(start, end);
  110. } else if (CPU_IS_040_OR_060) {
  111. asm volatile ("nop\n\t"
  112. ".chip 68040\n\t"
  113. "cpushp %%bc,(%0)\n\t"
  114. ".chip 68k"
  115. : : "a" (page_to_phys(page)));
  116. } else {
  117. unsigned long tmp;
  118. asm volatile ("movec %%cacr,%0\n\t"
  119. "orw %1,%0\n\t"
  120. "movec %0,%%cacr"
  121. : "=&d" (tmp)
  122. : "di" (FLUSH_I));
  123. }
  124. }