pmem.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 __PMEM_H__
  14. #define __PMEM_H__
  15. #include <linux/io.h>
  16. #include <linux/uio.h>
  17. #ifdef CONFIG_ARCH_HAS_PMEM_API
  18. #define ARCH_MEMREMAP_PMEM MEMREMAP_WB
  19. #include <asm/pmem.h>
  20. #else
  21. #define ARCH_MEMREMAP_PMEM MEMREMAP_WT
  22. /*
  23. * These are simply here to enable compilation, all call sites gate
  24. * calling these symbols with arch_has_pmem_api() and redirect to the
  25. * implementation in asm/pmem.h.
  26. */
  27. static inline void arch_memcpy_to_pmem(void *dst, const void *src, size_t n)
  28. {
  29. BUG();
  30. }
  31. static inline void arch_invalidate_pmem(void *addr, size_t size)
  32. {
  33. BUG();
  34. }
  35. #endif
  36. static inline bool arch_has_pmem_api(void)
  37. {
  38. return IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API);
  39. }
  40. /**
  41. * memcpy_to_pmem - copy data to persistent memory
  42. * @dst: destination buffer for the copy
  43. * @src: source buffer for the copy
  44. * @n: length of the copy in bytes
  45. *
  46. * Perform a memory copy that results in the destination of the copy
  47. * being effectively evicted from, or never written to, the processor
  48. * cache hierarchy after the copy completes. After memcpy_to_pmem()
  49. * data may still reside in cpu or platform buffers, so this operation
  50. * must be followed by a blkdev_issue_flush() on the pmem block device.
  51. */
  52. static inline void memcpy_to_pmem(void *dst, const void *src, size_t n)
  53. {
  54. if (arch_has_pmem_api())
  55. arch_memcpy_to_pmem(dst, src, n);
  56. else
  57. memcpy(dst, src, n);
  58. }
  59. /**
  60. * invalidate_pmem - flush a pmem range from the cache hierarchy
  61. * @addr: virtual start address
  62. * @size: bytes to invalidate (internally aligned to cache line size)
  63. *
  64. * For platforms that support clearing poison this flushes any poisoned
  65. * ranges out of the cache
  66. */
  67. static inline void invalidate_pmem(void *addr, size_t size)
  68. {
  69. if (arch_has_pmem_api())
  70. arch_invalidate_pmem(addr, size);
  71. }
  72. #endif /* __PMEM_H__ */