flush.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/tlbflush.h>
  17. void flush_cache_mm(struct mm_struct *mm)
  18. {
  19. }
  20. void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  21. unsigned long end)
  22. {
  23. if (vma->vm_flags & VM_EXEC)
  24. __flush_icache_all();
  25. }
  26. void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr,
  27. unsigned long pfn)
  28. {
  29. }
  30. static void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
  31. unsigned long uaddr, void *kaddr, unsigned long len)
  32. {
  33. /* VIPT non-aliasing D-cache */
  34. if (vma->vm_flags & VM_EXEC) {
  35. unsigned long addr = (unsigned long)kaddr;
  36. __cpuc_coherent_kern_range(addr, addr + len);
  37. }
  38. }
  39. /*
  40. * Copy user data from/to a page which is mapped into a different
  41. * processes address space. Really, we want to allow our "user
  42. * space" model to handle this.
  43. *
  44. * Note that this code needs to run on the current CPU.
  45. */
  46. void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
  47. unsigned long uaddr, void *dst, const void *src,
  48. unsigned long len)
  49. {
  50. memcpy(dst, src, len);
  51. flush_ptrace_access(vma, page, uaddr, dst, len);
  52. }
  53. void __flush_dcache_page(struct address_space *mapping, struct page *page)
  54. {
  55. /*
  56. * Writeback any data associated with the kernel mapping of this
  57. * page. This ensures that data in the physical page is mutually
  58. * coherent with the kernels mapping.
  59. */
  60. __cpuc_flush_kern_dcache_area(page_address(page), PAGE_SIZE);
  61. }
  62. /*
  63. * Ensure cache coherency between kernel mapping and userspace mapping
  64. * of this page.
  65. */
  66. void flush_dcache_page(struct page *page)
  67. {
  68. struct address_space *mapping;
  69. /*
  70. * The zero page is never written to, so never has any dirty
  71. * cache lines, and therefore never needs to be flushed.
  72. */
  73. if (page == ZERO_PAGE(0))
  74. return;
  75. mapping = page_mapping(page);
  76. if (mapping && !mapping_mapped(mapping))
  77. clear_bit(PG_dcache_clean, &page->flags);
  78. else {
  79. __flush_dcache_page(mapping, page);
  80. if (mapping)
  81. __flush_icache_all();
  82. set_bit(PG_dcache_clean, &page->flags);
  83. }
  84. }
  85. EXPORT_SYMBOL(flush_dcache_page);