cache.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 - 2003 by Ralf Baechle
  7. */
  8. #include <linux/config.h>
  9. #include <linux/init.h>
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/sched.h>
  13. #include <linux/mm.h>
  14. #include <asm/cacheflush.h>
  15. #include <asm/processor.h>
  16. #include <asm/cpu.h>
  17. #include <asm/cpu-features.h>
  18. /* Cache operations. */
  19. void (*flush_cache_all)(void);
  20. void (*__flush_cache_all)(void);
  21. void (*flush_cache_mm)(struct mm_struct *mm);
  22. void (*flush_cache_range)(struct vm_area_struct *vma, unsigned long start,
  23. unsigned long end);
  24. void (*flush_cache_page)(struct vm_area_struct *vma, unsigned long page, unsigned long pfn);
  25. void (*flush_icache_range)(unsigned long __user start,
  26. unsigned long __user end);
  27. void (*flush_icache_page)(struct vm_area_struct *vma, struct page *page);
  28. /* MIPS specific cache operations */
  29. void (*flush_cache_sigtramp)(unsigned long addr);
  30. void (*flush_data_cache_page)(unsigned long addr);
  31. void (*flush_icache_all)(void);
  32. #ifdef CONFIG_DMA_NONCOHERENT
  33. /* DMA cache operations. */
  34. void (*_dma_cache_wback_inv)(unsigned long start, unsigned long size);
  35. void (*_dma_cache_wback)(unsigned long start, unsigned long size);
  36. void (*_dma_cache_inv)(unsigned long start, unsigned long size);
  37. EXPORT_SYMBOL(_dma_cache_wback_inv);
  38. EXPORT_SYMBOL(_dma_cache_wback);
  39. EXPORT_SYMBOL(_dma_cache_inv);
  40. #endif /* CONFIG_DMA_NONCOHERENT */
  41. /*
  42. * We could optimize the case where the cache argument is not BCACHE but
  43. * that seems very atypical use ...
  44. */
  45. asmlinkage int sys_cacheflush(unsigned long __user addr,
  46. unsigned long bytes, unsigned int cache)
  47. {
  48. if (!access_ok(VERIFY_WRITE, (void __user *) addr, bytes))
  49. return -EFAULT;
  50. flush_icache_range(addr, addr + bytes);
  51. return 0;
  52. }
  53. void __flush_dcache_page(struct page *page)
  54. {
  55. struct address_space *mapping = page_mapping(page);
  56. unsigned long addr;
  57. if (mapping && !mapping_mapped(mapping)) {
  58. SetPageDcacheDirty(page);
  59. return;
  60. }
  61. /*
  62. * We could delay the flush for the !page_mapping case too. But that
  63. * case is for exec env/arg pages and those are %99 certainly going to
  64. * get faulted into the tlb (and thus flushed) anyways.
  65. */
  66. addr = (unsigned long) page_address(page);
  67. flush_data_cache_page(addr);
  68. }
  69. EXPORT_SYMBOL(__flush_dcache_page);
  70. void __update_cache(struct vm_area_struct *vma, unsigned long address,
  71. pte_t pte)
  72. {
  73. struct page *page;
  74. unsigned long pfn, addr;
  75. pfn = pte_pfn(pte);
  76. if (pfn_valid(pfn) && (page = pfn_to_page(pfn), page_mapping(page)) &&
  77. Page_dcache_dirty(page)) {
  78. if (pages_do_alias((unsigned long)page_address(page),
  79. address & PAGE_MASK)) {
  80. addr = (unsigned long) page_address(page);
  81. flush_data_cache_page(addr);
  82. }
  83. ClearPageDcacheDirty(page);
  84. }
  85. }
  86. extern void ld_mmu_r23000(void);
  87. extern void ld_mmu_r4xx0(void);
  88. extern void ld_mmu_tx39(void);
  89. extern void ld_mmu_r6000(void);
  90. extern void ld_mmu_tfp(void);
  91. extern void ld_mmu_andes(void);
  92. extern void ld_mmu_sb1(void);
  93. void __init cpu_cache_init(void)
  94. {
  95. if (cpu_has_4ktlb) {
  96. #if defined(CONFIG_CPU_R4X00) || defined(CONFIG_CPU_VR41XX) || \
  97. defined(CONFIG_CPU_R4300) || defined(CONFIG_CPU_R5000) || \
  98. defined(CONFIG_CPU_NEVADA) || defined(CONFIG_CPU_R5432) || \
  99. defined(CONFIG_CPU_R5500) || defined(CONFIG_CPU_MIPS32) || \
  100. defined(CONFIG_CPU_MIPS64) || defined(CONFIG_CPU_TX49XX) || \
  101. defined(CONFIG_CPU_RM7000) || defined(CONFIG_CPU_RM9000)
  102. ld_mmu_r4xx0();
  103. #endif
  104. } else switch (current_cpu_data.cputype) {
  105. #ifdef CONFIG_CPU_R3000
  106. case CPU_R2000:
  107. case CPU_R3000:
  108. case CPU_R3000A:
  109. case CPU_R3081E:
  110. ld_mmu_r23000();
  111. break;
  112. #endif
  113. #ifdef CONFIG_CPU_TX39XX
  114. case CPU_TX3912:
  115. case CPU_TX3922:
  116. case CPU_TX3927:
  117. ld_mmu_tx39();
  118. break;
  119. #endif
  120. #ifdef CONFIG_CPU_R10000
  121. case CPU_R10000:
  122. case CPU_R12000:
  123. ld_mmu_r4xx0();
  124. break;
  125. #endif
  126. #ifdef CONFIG_CPU_SB1
  127. case CPU_SB1:
  128. ld_mmu_sb1();
  129. break;
  130. #endif
  131. case CPU_R8000:
  132. panic("R8000 is unsupported");
  133. break;
  134. default:
  135. panic("Yeee, unsupported cache architecture.");
  136. }
  137. }