cache.c 4.1 KB

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