flush.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * linux/arch/unicore32/mm/flush.c
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Copyright (C) 2001-2010 GUAN Xue-tao
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/mm.h>
  14. #include <linux/pagemap.h>
  15. #include <asm/cacheflush.h>
  16. #include <asm/system.h>
  17. #include <asm/tlbflush.h>
  18. void flush_cache_mm(struct mm_struct *mm)
  19. {
  20. }
  21. void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  22. unsigned long end)
  23. {
  24. if (vma->vm_flags & VM_EXEC)
  25. __flush_icache_all();
  26. }
  27. void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr,
  28. unsigned long pfn)
  29. {
  30. }
  31. static void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
  32. unsigned long uaddr, void *kaddr, unsigned long len)
  33. {
  34. /* VIPT non-aliasing D-cache */
  35. if (vma->vm_flags & VM_EXEC) {
  36. unsigned long addr = (unsigned long)kaddr;
  37. __cpuc_coherent_kern_range(addr, addr + len);
  38. }
  39. }
  40. /*
  41. * Copy user data from/to a page which is mapped into a different
  42. * processes address space. Really, we want to allow our "user
  43. * space" model to handle this.
  44. *
  45. * Note that this code needs to run on the current CPU.
  46. */
  47. void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
  48. unsigned long uaddr, void *dst, const void *src,
  49. unsigned long len)
  50. {
  51. memcpy(dst, src, len);
  52. flush_ptrace_access(vma, page, uaddr, dst, len);
  53. }
  54. void __flush_dcache_page(struct address_space *mapping, struct page *page)
  55. {
  56. /*
  57. * Writeback any data associated with the kernel mapping of this
  58. * page. This ensures that data in the physical page is mutually
  59. * coherent with the kernels mapping.
  60. */
  61. __cpuc_flush_kern_dcache_area(page_address(page), PAGE_SIZE);
  62. }
  63. /*
  64. * Ensure cache coherency between kernel mapping and userspace mapping
  65. * of this page.
  66. */
  67. void flush_dcache_page(struct page *page)
  68. {
  69. struct address_space *mapping;
  70. /*
  71. * The zero page is never written to, so never has any dirty
  72. * cache lines, and therefore never needs to be flushed.
  73. */
  74. if (page == ZERO_PAGE(0))
  75. return;
  76. mapping = page_mapping(page);
  77. if (mapping && !mapping_mapped(mapping))
  78. clear_bit(PG_dcache_clean, &page->flags);
  79. else {
  80. __flush_dcache_page(mapping, page);
  81. if (mapping)
  82. __flush_icache_all();
  83. set_bit(PG_dcache_clean, &page->flags);
  84. }
  85. }
  86. EXPORT_SYMBOL(flush_dcache_page);