pmem.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright(c) 2017 IBM Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. #include <linux/string.h>
  14. #include <linux/export.h>
  15. #include <linux/uaccess.h>
  16. #include <asm/cacheflush.h>
  17. /*
  18. * CONFIG_ARCH_HAS_PMEM_API symbols
  19. */
  20. void arch_wb_cache_pmem(void *addr, size_t size)
  21. {
  22. unsigned long start = (unsigned long) addr;
  23. flush_inval_dcache_range(start, start + size);
  24. }
  25. EXPORT_SYMBOL(arch_wb_cache_pmem);
  26. void arch_invalidate_pmem(void *addr, size_t size)
  27. {
  28. unsigned long start = (unsigned long) addr;
  29. flush_inval_dcache_range(start, start + size);
  30. }
  31. EXPORT_SYMBOL(arch_invalidate_pmem);
  32. /*
  33. * CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE symbols
  34. */
  35. long __copy_from_user_flushcache(void *dest, const void __user *src,
  36. unsigned size)
  37. {
  38. unsigned long copied, start = (unsigned long) dest;
  39. copied = __copy_from_user(dest, src, size);
  40. flush_inval_dcache_range(start, start + size);
  41. return copied;
  42. }
  43. void *memcpy_flushcache(void *dest, const void *src, size_t size)
  44. {
  45. unsigned long start = (unsigned long) dest;
  46. memcpy(dest, src, size);
  47. flush_inval_dcache_range(start, start + size);
  48. return dest;
  49. }
  50. EXPORT_SYMBOL(memcpy_flushcache);
  51. void memcpy_page_flushcache(char *to, struct page *page, size_t offset,
  52. size_t len)
  53. {
  54. memcpy_flushcache(to, page_to_virt(page) + offset, len);
  55. }
  56. EXPORT_SYMBOL(memcpy_page_flushcache);