pmem.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright(c) 2015 Intel 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. #ifndef __ASM_X86_PMEM_H__
  14. #define __ASM_X86_PMEM_H__
  15. #include <linux/uaccess.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/cpufeature.h>
  18. #include <asm/special_insns.h>
  19. #ifdef CONFIG_ARCH_HAS_PMEM_API
  20. /**
  21. * arch_memcpy_to_pmem - copy data to persistent memory
  22. * @dst: destination buffer for the copy
  23. * @src: source buffer for the copy
  24. * @n: length of the copy in bytes
  25. *
  26. * Copy data to persistent memory media via non-temporal stores so that
  27. * a subsequent pmem driver flush operation will drain posted write queues.
  28. */
  29. static inline void arch_memcpy_to_pmem(void *dst, const void *src, size_t n)
  30. {
  31. int rem;
  32. /*
  33. * We are copying between two kernel buffers, if
  34. * __copy_from_user_inatomic_nocache() returns an error (page
  35. * fault) we would have already reported a general protection fault
  36. * before the WARN+BUG.
  37. */
  38. rem = __copy_from_user_inatomic_nocache(dst, (void __user *) src, n);
  39. if (WARN(rem, "%s: fault copying %p <- %p unwritten: %d\n",
  40. __func__, dst, src, rem))
  41. BUG();
  42. }
  43. static inline void arch_invalidate_pmem(void *addr, size_t size)
  44. {
  45. clflush_cache_range(addr, size);
  46. }
  47. #endif /* CONFIG_ARCH_HAS_PMEM_API */
  48. #endif /* __ASM_X86_PMEM_H__ */