pg-sh7705.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * arch/sh/mm/pg-sh7705.c
  3. *
  4. * Copyright (C) 1999, 2000 Niibe Yutaka
  5. * Copyright (C) 2004 Alex Song
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/mman.h>
  13. #include <linux/mm.h>
  14. #include <linux/threads.h>
  15. #include <asm/addrspace.h>
  16. #include <asm/page.h>
  17. #include <asm/pgtable.h>
  18. #include <asm/processor.h>
  19. #include <asm/cache.h>
  20. #include <asm/io.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/pgalloc.h>
  23. #include <asm/mmu_context.h>
  24. #include <asm/cacheflush.h>
  25. static inline void __flush_purge_virtual_region(void *p1, void *virt, int size)
  26. {
  27. unsigned long v;
  28. unsigned long begin, end;
  29. unsigned long p1_begin;
  30. begin = L1_CACHE_ALIGN((unsigned long)virt);
  31. end = L1_CACHE_ALIGN((unsigned long)virt + size);
  32. p1_begin = (unsigned long)p1 & ~(L1_CACHE_BYTES - 1);
  33. /* do this the slow way as we may not have TLB entries
  34. * for virt yet. */
  35. for (v = begin; v < end; v += L1_CACHE_BYTES) {
  36. unsigned long p;
  37. unsigned long ways, addr;
  38. p = __pa(p1_begin);
  39. ways = current_cpu_data.dcache.ways;
  40. addr = CACHE_OC_ADDRESS_ARRAY;
  41. do {
  42. unsigned long data;
  43. addr |= (v & current_cpu_data.dcache.entry_mask);
  44. data = ctrl_inl(addr);
  45. if ((data & CACHE_PHYSADDR_MASK) ==
  46. (p & CACHE_PHYSADDR_MASK)) {
  47. data &= ~(SH_CACHE_UPDATED|SH_CACHE_VALID);
  48. ctrl_outl(data, addr);
  49. }
  50. addr += current_cpu_data.dcache.way_incr;
  51. } while (--ways);
  52. p1_begin += L1_CACHE_BYTES;
  53. }
  54. }
  55. /*
  56. * clear_user_page
  57. * @to: P1 address
  58. * @address: U0 address to be mapped
  59. */
  60. void clear_user_page(void *to, unsigned long address, struct page *pg)
  61. {
  62. struct page *page = virt_to_page(to);
  63. if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0) {
  64. clear_page(to);
  65. __flush_wback_region(to, PAGE_SIZE);
  66. } else {
  67. __flush_purge_virtual_region(to,
  68. (void *)(address & 0xfffff000),
  69. PAGE_SIZE);
  70. clear_page(to);
  71. __flush_wback_region(to, PAGE_SIZE);
  72. }
  73. }
  74. /*
  75. * copy_user_page
  76. * @to: P1 address
  77. * @from: P1 address
  78. * @address: U0 address to be mapped
  79. */
  80. void copy_user_page(void *to, void *from, unsigned long address,
  81. struct page *pg)
  82. {
  83. struct page *page = virt_to_page(to);
  84. if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0) {
  85. copy_page(to, from);
  86. __flush_wback_region(to, PAGE_SIZE);
  87. } else {
  88. __flush_purge_virtual_region(to,
  89. (void *)(address & 0xfffff000),
  90. PAGE_SIZE);
  91. copy_page(to, from);
  92. __flush_wback_region(to, PAGE_SIZE);
  93. }
  94. }