cache.c 4.0 KB

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