mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-25 05:34:00 +08:00
88793e5c77
4 drivers / enabling modules: NFIT: Instantiates an "nvdimm bus" with the core and registers memory devices (NVDIMMs) enumerated by the ACPI 6.0 NFIT (NVDIMM Firmware Interface table). After registering NVDIMMs the NFIT driver then registers "region" devices. A libnvdimm-region defines an access mode and the boundaries of persistent memory media. A region may span multiple NVDIMMs that are interleaved by the hardware memory controller. In turn, a libnvdimm-region can be carved into a "namespace" device and bound to the PMEM or BLK driver which will attach a Linux block device (disk) interface to the memory. PMEM: Initially merged in v4.1 this driver for contiguous spans of persistent memory address ranges is re-worked to drive PMEM-namespaces emitted by the libnvdimm-core. In this update the PMEM driver, on x86, gains the ability to assert that writes to persistent memory have been flushed all the way through the caches and buffers in the platform to persistent media. See memcpy_to_pmem() and wmb_pmem(). BLK: This new driver enables access to persistent memory media through "Block Data Windows" as defined by the NFIT. The primary difference of this driver to PMEM is that only a small window of persistent memory is mapped into system address space at any given point in time. Per-NVDIMM windows are reprogrammed at run time, per-I/O, to access different portions of the media. BLK-mode, by definition, does not support DAX. BTT: This is a library, optionally consumed by either PMEM or BLK, that converts a byte-accessible namespace into a disk with atomic sector update semantics (prevents sector tearing on crash or power loss). The sinister aspect of sector tearing is that most applications do not know they have a atomic sector dependency. At least today's disk's rarely ever tear sectors and if they do one almost certainly gets a CRC error on access. NVDIMMs will always tear and always silently. Until an application is audited to be robust in the presence of sector-tearing the usage of BTT is recommended. Thanks to: Ross Zwisler, Jeff Moyer, Vishal Verma, Christoph Hellwig, Ingo Molnar, Neil Brown, Boaz Harrosh, Robert Elliott, Matthew Wilcox, Andy Rudoff, Linda Knippers, Toshi Kani, Nicholas Moulin, Rafael Wysocki, and Bob Moore. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABAgAGBQJVjZGBAAoJEB7SkWpmfYgC4fkP/j+k6HmSRNU/yRYPyo7CAWvj 3P5P1i6R6nMZZbjQrQArAXaIyLlFk4sEQDYsciR6dmslhhFZAkR2eFwVO5rBOyx3 QN0yxEpyjJbroRFUrV/BLaFK4cq2oyJAFFHs0u7/pLHBJ4MDMqfRKAMtlnBxEkTE LFcqXapSlvWitSbjMdIBWKFEvncaiJ2mdsFqT4aZqclBBTj00eWQvEG9WxleJLdv +tj7qR/vGcwOb12X5UrbQXgwtMYos7A6IzhHbqwQL8IrOcJ6YB8NopJUpLDd7ZVq KAzX6ZYMzNueN4uvv6aDfqDRLyVL7qoxM9XIjGF5R8SV9sF2LMspm1FBpfowo1GT h2QMr0ky1nHVT32yspBCpE9zW/mubRIDtXxEmZZ53DIc4N6Dy9jFaNVmhoWtTAqG b9pndFnjUzzieCjX5pCvo2M5U6N0AQwsnq76/CasiWyhSa9DNKOg8MVDRg0rbxb0 UvK0v8JwOCIRcfO3qiKcx+02nKPtjCtHSPqGkFKPySRvAdb+3g6YR26CxTb3VmnF etowLiKU7HHalLvqGFOlDoQG6viWes9Zl+ZeANBOCVa6rL2O7ZnXJtYgXf1wDQee fzgKB78BcDjXH4jHobbp/WBANQGN/GF34lse8yHa7Ym+28uEihDvSD1wyNLnefmo 7PJBbN5M5qP5tD0aO7SZ =VtWG -----END PGP SIGNATURE----- Merge tag 'libnvdimm-for-4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/nvdimm Pull libnvdimm subsystem from Dan Williams: "The libnvdimm sub-system introduces, in addition to the libnvdimm-core, 4 drivers / enabling modules: NFIT: Instantiates an "nvdimm bus" with the core and registers memory devices (NVDIMMs) enumerated by the ACPI 6.0 NFIT (NVDIMM Firmware Interface table). After registering NVDIMMs the NFIT driver then registers "region" devices. A libnvdimm-region defines an access mode and the boundaries of persistent memory media. A region may span multiple NVDIMMs that are interleaved by the hardware memory controller. In turn, a libnvdimm-region can be carved into a "namespace" device and bound to the PMEM or BLK driver which will attach a Linux block device (disk) interface to the memory. PMEM: Initially merged in v4.1 this driver for contiguous spans of persistent memory address ranges is re-worked to drive PMEM-namespaces emitted by the libnvdimm-core. In this update the PMEM driver, on x86, gains the ability to assert that writes to persistent memory have been flushed all the way through the caches and buffers in the platform to persistent media. See memcpy_to_pmem() and wmb_pmem(). BLK: This new driver enables access to persistent memory media through "Block Data Windows" as defined by the NFIT. The primary difference of this driver to PMEM is that only a small window of persistent memory is mapped into system address space at any given point in time. Per-NVDIMM windows are reprogrammed at run time, per-I/O, to access different portions of the media. BLK-mode, by definition, does not support DAX. BTT: This is a library, optionally consumed by either PMEM or BLK, that converts a byte-accessible namespace into a disk with atomic sector update semantics (prevents sector tearing on crash or power loss). The sinister aspect of sector tearing is that most applications do not know they have a atomic sector dependency. At least today's disk's rarely ever tear sectors and if they do one almost certainly gets a CRC error on access. NVDIMMs will always tear and always silently. Until an application is audited to be robust in the presence of sector-tearing the usage of BTT is recommended. Thanks to: Ross Zwisler, Jeff Moyer, Vishal Verma, Christoph Hellwig, Ingo Molnar, Neil Brown, Boaz Harrosh, Robert Elliott, Matthew Wilcox, Andy Rudoff, Linda Knippers, Toshi Kani, Nicholas Moulin, Rafael Wysocki, and Bob Moore" * tag 'libnvdimm-for-4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/nvdimm: (33 commits) arch, x86: pmem api for ensuring durability of persistent memory updates libnvdimm: Add sysfs numa_node to NVDIMM devices libnvdimm: Set numa_node to NVDIMM devices acpi: Add acpi_map_pxm_to_online_node() libnvdimm, nfit: handle unarmed dimms, mark namespaces read-only pmem: flag pmem block devices as non-rotational libnvdimm: enable iostat pmem: make_request cleanups libnvdimm, pmem: fix up max_hw_sectors libnvdimm, blk: add support for blk integrity libnvdimm, btt: add support for blk integrity fs/block_dev.c: skip rw_page if bdev has integrity libnvdimm: Non-Volatile Devices tools/testing/nvdimm: libnvdimm unit test infrastructure libnvdimm, nfit, nd_blk: driver for BLK-mode access persistent memory nd_btt: atomic sector updates libnvdimm: infrastructure for btt devices libnvdimm: write blk label set libnvdimm: write pmem label set libnvdimm: blk labels and namespace instantiation ...
153 lines
4.3 KiB
C
153 lines
4.3 KiB
C
/*
|
|
* 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>
|
|
|
|
#ifdef CONFIG_ARCH_HAS_PMEM_API
|
|
#include <asm/cacheflush.h>
|
|
#else
|
|
static inline void arch_wmb_pmem(void)
|
|
{
|
|
BUG();
|
|
}
|
|
|
|
static inline bool __arch_has_wmb_pmem(void)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline void __pmem *arch_memremap_pmem(resource_size_t offset,
|
|
unsigned long size)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline void arch_memcpy_to_pmem(void __pmem *dst, const void *src,
|
|
size_t n)
|
|
{
|
|
BUG();
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
* Architectures that define ARCH_HAS_PMEM_API must provide
|
|
* implementations for arch_memremap_pmem(), arch_memcpy_to_pmem(),
|
|
* arch_wmb_pmem(), and __arch_has_wmb_pmem().
|
|
*/
|
|
|
|
static inline void memcpy_from_pmem(void *dst, void __pmem const *src, size_t size)
|
|
{
|
|
memcpy(dst, (void __force const *) src, size);
|
|
}
|
|
|
|
static inline void memunmap_pmem(void __pmem *addr)
|
|
{
|
|
iounmap((void __force __iomem *) addr);
|
|
}
|
|
|
|
/**
|
|
* arch_has_wmb_pmem - true if wmb_pmem() ensures durability
|
|
*
|
|
* For a given cpu implementation within an architecture it is possible
|
|
* that wmb_pmem() resolves to a nop. In the case this returns
|
|
* false, pmem api users are unable to ensure durability and may want to
|
|
* fall back to a different data consistency model, or otherwise notify
|
|
* the user.
|
|
*/
|
|
static inline bool arch_has_wmb_pmem(void)
|
|
{
|
|
if (IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API))
|
|
return __arch_has_wmb_pmem();
|
|
return false;
|
|
}
|
|
|
|
static inline bool arch_has_pmem_api(void)
|
|
{
|
|
return IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API) && arch_has_wmb_pmem();
|
|
}
|
|
|
|
/*
|
|
* These defaults seek to offer decent performance and minimize the
|
|
* window between i/o completion and writes being durable on media.
|
|
* However, it is undefined / architecture specific whether
|
|
* default_memremap_pmem + default_memcpy_to_pmem is sufficient for
|
|
* making data durable relative to i/o completion.
|
|
*/
|
|
static void default_memcpy_to_pmem(void __pmem *dst, const void *src,
|
|
size_t size)
|
|
{
|
|
memcpy((void __force *) dst, src, size);
|
|
}
|
|
|
|
static void __pmem *default_memremap_pmem(resource_size_t offset,
|
|
unsigned long size)
|
|
{
|
|
return (void __pmem __force *)ioremap_wt(offset, size);
|
|
}
|
|
|
|
/**
|
|
* memremap_pmem - map physical persistent memory for pmem api
|
|
* @offset: physical address of persistent memory
|
|
* @size: size of the mapping
|
|
*
|
|
* Establish a mapping of the architecture specific memory type expected
|
|
* by memcpy_to_pmem() and wmb_pmem(). For example, it may be
|
|
* the case that an uncacheable or writethrough mapping is sufficient,
|
|
* or a writeback mapping provided memcpy_to_pmem() and
|
|
* wmb_pmem() arrange for the data to be written through the
|
|
* cache to persistent media.
|
|
*/
|
|
static inline void __pmem *memremap_pmem(resource_size_t offset,
|
|
unsigned long size)
|
|
{
|
|
if (arch_has_pmem_api())
|
|
return arch_memremap_pmem(offset, size);
|
|
return default_memremap_pmem(offset, size);
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
* must be followed by a wmb_pmem().
|
|
*/
|
|
static inline void memcpy_to_pmem(void __pmem *dst, const void *src, size_t n)
|
|
{
|
|
if (arch_has_pmem_api())
|
|
arch_memcpy_to_pmem(dst, src, n);
|
|
else
|
|
default_memcpy_to_pmem(dst, src, n);
|
|
}
|
|
|
|
/**
|
|
* wmb_pmem - synchronize writes to persistent memory
|
|
*
|
|
* After a series of memcpy_to_pmem() operations this drains data from
|
|
* cpu write buffers and any platform (memory controller) buffers to
|
|
* ensure that written data is durable on persistent memory media.
|
|
*/
|
|
static inline void wmb_pmem(void)
|
|
{
|
|
if (arch_has_pmem_api())
|
|
arch_wmb_pmem();
|
|
}
|
|
#endif /* __PMEM_H__ */
|