cache.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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, 07 by Ralf Baechle (ralf@linux-mips.org)
  7. * Copyright (C) 2007 MIPS Technologies, Inc.
  8. */
  9. #include <linux/fs.h>
  10. #include <linux/fcntl.h>
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/sched.h>
  15. #include <linux/mm.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/processor.h>
  18. #include <asm/cpu.h>
  19. #include <asm/cpu-features.h>
  20. /* Cache operations. */
  21. void (*flush_cache_all)(void);
  22. void (*__flush_cache_all)(void);
  23. void (*flush_cache_mm)(struct mm_struct *mm);
  24. void (*flush_cache_range)(struct vm_area_struct *vma, unsigned long start,
  25. unsigned long end);
  26. void (*flush_cache_page)(struct vm_area_struct *vma, unsigned long page,
  27. unsigned long pfn);
  28. void (*flush_icache_range)(unsigned long start, unsigned long end);
  29. /* MIPS specific cache operations */
  30. void (*flush_cache_sigtramp)(unsigned long addr);
  31. void (*local_flush_data_cache_page)(void * addr);
  32. void (*flush_data_cache_page)(unsigned long addr);
  33. void (*flush_icache_all)(void);
  34. EXPORT_SYMBOL_GPL(local_flush_data_cache_page);
  35. EXPORT_SYMBOL(flush_data_cache_page);
  36. #ifdef CONFIG_DMA_NONCOHERENT
  37. /* DMA cache operations. */
  38. void (*_dma_cache_wback_inv)(unsigned long start, unsigned long size);
  39. void (*_dma_cache_wback)(unsigned long start, unsigned long size);
  40. void (*_dma_cache_inv)(unsigned long start, unsigned long size);
  41. EXPORT_SYMBOL(_dma_cache_wback_inv);
  42. EXPORT_SYMBOL(_dma_cache_wback);
  43. EXPORT_SYMBOL(_dma_cache_inv);
  44. #endif /* CONFIG_DMA_NONCOHERENT */
  45. /*
  46. * We could optimize the case where the cache argument is not BCACHE but
  47. * that seems very atypical use ...
  48. */
  49. asmlinkage int sys_cacheflush(unsigned long addr,
  50. unsigned long bytes, unsigned int cache)
  51. {
  52. if (bytes == 0)
  53. return 0;
  54. if (!access_ok(VERIFY_WRITE, (void __user *) addr, bytes))
  55. return -EFAULT;
  56. flush_icache_range(addr, addr + bytes);
  57. return 0;
  58. }
  59. void __flush_dcache_page(struct page *page)
  60. {
  61. struct address_space *mapping = page_mapping(page);
  62. unsigned long addr;
  63. if (PageHighMem(page))
  64. return;
  65. if (mapping && !mapping_mapped(mapping)) {
  66. SetPageDcacheDirty(page);
  67. return;
  68. }
  69. /*
  70. * We could delay the flush for the !page_mapping case too. But that
  71. * case is for exec env/arg pages and those are %99 certainly going to
  72. * get faulted into the tlb (and thus flushed) anyways.
  73. */
  74. addr = (unsigned long) page_address(page);
  75. flush_data_cache_page(addr);
  76. }
  77. EXPORT_SYMBOL(__flush_dcache_page);
  78. void __flush_anon_page(struct page *page, unsigned long vmaddr)
  79. {
  80. if (pages_do_alias((unsigned long)page_address(page), vmaddr)) {
  81. void *kaddr;
  82. kaddr = kmap_coherent(page, vmaddr);
  83. flush_data_cache_page((unsigned long)kaddr);
  84. kunmap_coherent();
  85. }
  86. }
  87. EXPORT_SYMBOL(__flush_anon_page);
  88. void __update_cache(struct vm_area_struct *vma, unsigned long address,
  89. pte_t pte)
  90. {
  91. struct page *page;
  92. unsigned long pfn, addr;
  93. int exec = (vma->vm_flags & VM_EXEC) && !cpu_has_ic_fills_f_dc;
  94. pfn = pte_pfn(pte);
  95. if (unlikely(!pfn_valid(pfn)))
  96. return;
  97. page = pfn_to_page(pfn);
  98. if (page_mapping(page) && Page_dcache_dirty(page)) {
  99. addr = (unsigned long) page_address(page);
  100. if (exec || pages_do_alias(addr, address & PAGE_MASK))
  101. flush_data_cache_page(addr);
  102. ClearPageDcacheDirty(page);
  103. }
  104. }
  105. static char cache_panic[] __initdata = "Yeee, unsupported cache architecture.";
  106. void __init cpu_cache_init(void)
  107. {
  108. if (cpu_has_3k_cache) {
  109. extern void __weak r3k_cache_init(void);
  110. r3k_cache_init();
  111. return;
  112. }
  113. if (cpu_has_6k_cache) {
  114. extern void __weak r6k_cache_init(void);
  115. r6k_cache_init();
  116. return;
  117. }
  118. if (cpu_has_4k_cache) {
  119. extern void __weak r4k_cache_init(void);
  120. r4k_cache_init();
  121. return;
  122. }
  123. if (cpu_has_8k_cache) {
  124. extern void __weak r8k_cache_init(void);
  125. r8k_cache_init();
  126. return;
  127. }
  128. if (cpu_has_tx39_cache) {
  129. extern void __weak tx39_cache_init(void);
  130. tx39_cache_init();
  131. return;
  132. }
  133. if (cpu_has_sb1_cache) {
  134. extern void __weak sb1_cache_init(void);
  135. sb1_cache_init();
  136. return;
  137. }
  138. panic(cache_panic);
  139. }
  140. int __weak __uncached_access(struct file *file, unsigned long addr)
  141. {
  142. if (file->f_flags & O_SYNC)
  143. return 1;
  144. return addr >= __pa(high_memory);
  145. }