2015-06-25 14:08:39 +07:00
|
|
|
/*
|
|
|
|
* Copyright(c) 2015 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*/
|
|
|
|
#ifndef __PMEM_H__
|
|
|
|
#define __PMEM_H__
|
|
|
|
|
|
|
|
#include <linux/io.h>
|
2015-08-19 02:55:39 +07:00
|
|
|
#include <linux/uio.h>
|
2015-06-25 14:08:39 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_HAS_PMEM_API
|
2015-08-25 05:29:38 +07:00
|
|
|
#define ARCH_MEMREMAP_PMEM MEMREMAP_WB
|
2015-08-19 02:55:36 +07:00
|
|
|
#include <asm/pmem.h>
|
2015-06-25 14:08:39 +07:00
|
|
|
#else
|
2015-08-25 05:29:38 +07:00
|
|
|
#define ARCH_MEMREMAP_PMEM MEMREMAP_WT
|
|
|
|
/*
|
|
|
|
* These are simply here to enable compilation, all call sites gate
|
|
|
|
* calling these symbols with arch_has_pmem_api() and redirect to the
|
|
|
|
* implementation in asm/pmem.h.
|
|
|
|
*/
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline void arch_memcpy_to_pmem(void *dst, const void *src, size_t n)
|
2015-06-25 14:08:39 +07:00
|
|
|
{
|
|
|
|
BUG();
|
|
|
|
}
|
2015-08-19 02:55:39 +07:00
|
|
|
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline int arch_memcpy_from_pmem(void *dst, const void *src, size_t n)
|
2016-03-09 01:30:19 +07:00
|
|
|
{
|
|
|
|
BUG();
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline size_t arch_copy_from_iter_pmem(void *addr, size_t bytes,
|
2015-08-19 02:55:39 +07:00
|
|
|
struct iov_iter *i)
|
|
|
|
{
|
|
|
|
BUG();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline void arch_clear_pmem(void *addr, size_t size)
|
2015-08-19 02:55:39 +07:00
|
|
|
{
|
|
|
|
BUG();
|
|
|
|
}
|
2016-01-23 06:10:37 +07:00
|
|
|
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline void arch_wb_cache_pmem(void *addr, size_t size)
|
2016-01-23 06:10:37 +07:00
|
|
|
{
|
|
|
|
BUG();
|
|
|
|
}
|
2016-03-08 22:16:07 +07:00
|
|
|
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline void arch_invalidate_pmem(void *addr, size_t size)
|
2016-03-08 22:16:07 +07:00
|
|
|
{
|
|
|
|
BUG();
|
|
|
|
}
|
2015-06-25 14:08:39 +07:00
|
|
|
#endif
|
|
|
|
|
2016-04-13 07:10:52 +07:00
|
|
|
static inline bool arch_has_pmem_api(void)
|
|
|
|
{
|
|
|
|
return IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API);
|
|
|
|
}
|
|
|
|
|
2015-06-25 14:08:39 +07:00
|
|
|
/*
|
2016-03-09 01:30:19 +07:00
|
|
|
* memcpy_from_pmem - read from persistent memory with error handling
|
|
|
|
* @dst: destination buffer
|
|
|
|
* @src: source buffer
|
|
|
|
* @size: transfer length
|
|
|
|
*
|
|
|
|
* Returns 0 on success negative error code on failure.
|
2015-06-25 14:08:39 +07:00
|
|
|
*/
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline int memcpy_from_pmem(void *dst, void const *src, size_t size)
|
2015-06-25 14:08:39 +07:00
|
|
|
{
|
2016-04-13 07:10:52 +07:00
|
|
|
if (arch_has_pmem_api())
|
|
|
|
return arch_memcpy_from_pmem(dst, src, size);
|
|
|
|
else
|
2016-06-04 08:06:47 +07:00
|
|
|
memcpy(dst, src, size);
|
|
|
|
return 0;
|
2015-08-19 02:55:39 +07:00
|
|
|
}
|
|
|
|
|
2015-06-25 14:08:39 +07:00
|
|
|
/**
|
|
|
|
* memcpy_to_pmem - copy data to persistent memory
|
|
|
|
* @dst: destination buffer for the copy
|
|
|
|
* @src: source buffer for the copy
|
|
|
|
* @n: length of the copy in bytes
|
|
|
|
*
|
|
|
|
* Perform a memory copy that results in the destination of the copy
|
|
|
|
* being effectively evicted from, or never written to, the processor
|
|
|
|
* cache hierarchy after the copy completes. After memcpy_to_pmem()
|
|
|
|
* data may still reside in cpu or platform buffers, so this operation
|
2016-06-02 13:07:43 +07:00
|
|
|
* must be followed by a blkdev_issue_flush() on the pmem block device.
|
2015-06-25 14:08:39 +07:00
|
|
|
*/
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline void memcpy_to_pmem(void *dst, const void *src, size_t n)
|
2015-06-25 14:08:39 +07:00
|
|
|
{
|
|
|
|
if (arch_has_pmem_api())
|
|
|
|
arch_memcpy_to_pmem(dst, src, n);
|
|
|
|
else
|
2016-06-04 08:06:47 +07:00
|
|
|
memcpy(dst, src, n);
|
2015-06-25 14:08:39 +07:00
|
|
|
}
|
|
|
|
|
2015-08-19 02:55:39 +07:00
|
|
|
/**
|
|
|
|
* copy_from_iter_pmem - copy data from an iterator to PMEM
|
|
|
|
* @addr: PMEM destination address
|
|
|
|
* @bytes: number of bytes to copy
|
|
|
|
* @i: iterator with source data
|
|
|
|
*
|
|
|
|
* Copy data from the iterator 'i' to the PMEM buffer starting at 'addr'.
|
2016-06-02 13:07:43 +07:00
|
|
|
* See blkdev_issue_flush() note for memcpy_to_pmem().
|
2015-08-19 02:55:39 +07:00
|
|
|
*/
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline size_t copy_from_iter_pmem(void *addr, size_t bytes,
|
2015-08-19 02:55:39 +07:00
|
|
|
struct iov_iter *i)
|
|
|
|
{
|
|
|
|
if (arch_has_pmem_api())
|
|
|
|
return arch_copy_from_iter_pmem(addr, bytes, i);
|
2016-06-04 08:06:47 +07:00
|
|
|
return copy_from_iter_nocache(addr, bytes, i);
|
2015-08-19 02:55:39 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clear_pmem - zero a PMEM memory range
|
|
|
|
* @addr: virtual start address
|
|
|
|
* @size: number of bytes to zero
|
|
|
|
*
|
|
|
|
* Write zeros into the memory range starting at 'addr' for 'size' bytes.
|
2016-06-02 13:07:43 +07:00
|
|
|
* See blkdev_issue_flush() note for memcpy_to_pmem().
|
2015-08-19 02:55:39 +07:00
|
|
|
*/
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline void clear_pmem(void *addr, size_t size)
|
2015-08-19 02:55:39 +07:00
|
|
|
{
|
|
|
|
if (arch_has_pmem_api())
|
|
|
|
arch_clear_pmem(addr, size);
|
|
|
|
else
|
2016-06-04 08:06:47 +07:00
|
|
|
memset(addr, 0, size);
|
2015-08-19 02:55:39 +07:00
|
|
|
}
|
2016-01-23 06:10:37 +07:00
|
|
|
|
2016-03-08 22:16:07 +07:00
|
|
|
/**
|
|
|
|
* invalidate_pmem - flush a pmem range from the cache hierarchy
|
|
|
|
* @addr: virtual start address
|
|
|
|
* @size: bytes to invalidate (internally aligned to cache line size)
|
|
|
|
*
|
|
|
|
* For platforms that support clearing poison this flushes any poisoned
|
|
|
|
* ranges out of the cache
|
|
|
|
*/
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline void invalidate_pmem(void *addr, size_t size)
|
2016-03-08 22:16:07 +07:00
|
|
|
{
|
|
|
|
if (arch_has_pmem_api())
|
|
|
|
arch_invalidate_pmem(addr, size);
|
|
|
|
}
|
|
|
|
|
2016-01-23 06:10:37 +07:00
|
|
|
/**
|
|
|
|
* wb_cache_pmem - write back processor cache for PMEM memory range
|
|
|
|
* @addr: virtual start address
|
|
|
|
* @size: number of bytes to write back
|
|
|
|
*
|
|
|
|
* Write back the processor cache range starting at 'addr' for 'size' bytes.
|
2016-06-02 13:07:43 +07:00
|
|
|
* See blkdev_issue_flush() note for memcpy_to_pmem().
|
2016-01-23 06:10:37 +07:00
|
|
|
*/
|
2016-06-04 08:06:47 +07:00
|
|
|
static inline void wb_cache_pmem(void *addr, size_t size)
|
2016-01-23 06:10:37 +07:00
|
|
|
{
|
|
|
|
if (arch_has_pmem_api())
|
|
|
|
arch_wb_cache_pmem(addr, size);
|
|
|
|
}
|
2015-06-25 14:08:39 +07:00
|
|
|
#endif /* __PMEM_H__ */
|