From patchwork Fri Jul 15 02:46:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kwangwoo Lee X-Patchwork-Id: 9231065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D239860868 for ; Fri, 15 Jul 2016 02:46:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAAD428327 for ; Fri, 15 Jul 2016 02:46:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF7DC2832B; Fri, 15 Jul 2016 02:46:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4957E28327 for ; Fri, 15 Jul 2016 02:46:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id F0EB61A1F2E; Thu, 14 Jul 2016 19:47:28 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from invmail3.skhynix.com (exvmail3.skhynix.com [166.125.252.90]) by ml01.01.org (Postfix) with ESMTP id 0FE0B1A1F2A for ; Thu, 14 Jul 2016 19:47:26 -0700 (PDT) X-AuditID: a67dfc59-f790b6d000004b07-a0-57884e8f7e1c From: Kwangwoo Lee To: linux-arm-kernel@lists.infradead.org, linux-nvdimm@lists.01.org, Catalin Marinas , Will Deacon , Mark Rutland , Ross Zwisler , Dan Williams , Vishal Verma Subject: [PATCH v3 3/3] arm64: pmem: add pmem support codes Date: Fri, 15 Jul 2016 11:46:22 +0900 Message-Id: <1468550782-14454-4-git-send-email-kwangwoo.lee@sk.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1468550782-14454-1-git-send-email-kwangwoo.lee@sk.com> References: <1468550782-14454-1-git-send-email-kwangwoo.lee@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBLMWRmVeSWpSXmKPExsXCNUdUSXeCX0e4wb1zzBbvl/UwWkyfeoHR YtPja6wWl3fNYbNonnib3WLp9YtMFhOf/2axuDXhGJPFy48nWBw4PdbMW8PosXjPSyaPeScD Pbpn/2Px2Lyk3uPzJrkAtigum5TUnMyy1CJ9uwSujK0/XQs26Vd83RDUwLhMrYuRk0NCwETi 4IPVLBC2mMSFe+vZuhg5wOLzlqWAhNkENCRObbgPVMLFISJwmEmi7fl0ZhCHWWAyo8TcL1eZ QKqEBawlljzewAxiswioSnyefA4szivgLNG2/AALxFA5iQUX0kHCnAIuEksX/gULCwGVbJrM CzJSQmAJm8TCKeuYIO6RlDi44gbLBEa+BYwMqxhFMvPKchMzc4z1irMzKvMyK/SS83M3MQLD b1ntn8gdjD2t+ocYBTgYlXh4BY62hwuxJpYVV+YeYpTgYFYS4a3y7QgX4k1JrKxKLcqPLyrN SS0+xCjNwaIkzrtkQU64kEB6YklqdmpqQWoRTJaJg1OqgTHWJebKxcDUyy90g9Ok7C4H94eG ua1b/9p/aqvAsV6DC6Gyh/dd2eJpHiQweU6yfUblylOr7F/9PvbgpGKnS9H0Bu97dR1X6/mW G76M4HLZcXhmwnqPBu+ZWqfE97TsUf7LXvV34t7HDq+uxrVsYtTnVbx2yH6yg8PnLItJ8w0s l66TZmK9U67EUpyRaKjFXFScCACgQlGFOwIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprGLMWRmVeSWpSXmKPExsXCFdOSptvv1xFucPWqucX7ZT2MFtOnXmC0 mLqqhcli3udT7BabHl9jtbi8aw6bRfPE2+wWS69fZLKY+Pw3i8WtCceYLF5+PMFiMW/5WhYH Ho8189Yweize85LJY97JQI/u2f9YPDYvqff4dtvD4/MmuQD2KC6blNSczLLUIn27BK6MrT9d CzbpV3zdENTAuEyti5GDQ0LARGLespQuRk4gU0ziwr31bCA2m4CGxKkN91m6GLk4RAQOM0m0 PZ/ODOIwC0xmlJj75SoTSJWwgLXEkscbmEFsFgFVic+Tz4HFeQWcJdqWH2CBWCAnseBCOkiY U8BFYunCv2BhIaCSTZN5JzByL2BkWMUokplXlpuYmWOmV5ydUZmXWaGXnJ+7iREYWstq/0za wfjtsvshRgEORiUeXoGj7eFCrIllxZW5hxglOJiVRHirfDvChXhTEiurUovy44tKc1KLDzFK c7AoifMe/6gULiSQnliSmp2aWpBaBJNl4uCUamBcsH46f21FUZVbm649e+7NZVtfRL6Pfm3q zX7u9nqX4F93mTOe+t5/MPWWpv/bmdJZrwrPNq75JqIZfPXxrdyZqa/e35uQtorhYIDIliqz 36pzd3Iv3no0SVN+VvzNpkdH9h6d+XyXI2PkyVUS8amzPu5vX/fr2CPZii+JZxbM8f3atTQ7 k3HLUSWW4oxEQy3mouJEAKry/SEpAgAA X-CFilter-Loop: Reflected X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kwangwoo Lee , linux-kernel@vger.kernel.org, Woosuk Chung MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support pmem on arm64 platform. The limitation of current implementation is that the persistency of pmem on NVDIMM is not guaranteed on arm64 yet. pmem driver expects that the persistency need to be guaranteed in arch_wmb_pmem(), but the PoP(Point of Persistency) is going to be supported on ARMv8.2 with DC CVAP instruction. Until then, __arch_has_wmb_pmem() will return false and shows warning message. [ 6.250487] nd_pmem namespace0.0: unable to guarantee persistence of writes [ 6.305000] pmem0: detected capacity change from 0 to 1073741824 ... [ 29.215249] EXT4-fs (pmem0): DAX enabled. Warning: EXPERIMENTAL, use at your own risk [ 29.308960] EXT4-fs (pmem0): mounted filesystem with ordered data mode. Opts: dax Signed-off-by: Kwangwoo Lee --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/pmem.h | 143 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 arch/arm64/include/asm/pmem.h diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 12546ce..e14fd31 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -16,6 +16,7 @@ config ARM64 select ARCH_WANT_FRAME_POINTERS select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_MMIO_FLUSH + select ARCH_HAS_PMEM_API select ARM_AMBA select ARM_ARCH_TIMER select ARM_GIC diff --git a/arch/arm64/include/asm/pmem.h b/arch/arm64/include/asm/pmem.h new file mode 100644 index 0000000..0bcfd87 --- /dev/null +++ b/arch/arm64/include/asm/pmem.h @@ -0,0 +1,143 @@ +/* + * Based on arch/x86/include/asm/pmem.h + * + * Copyright(c) 2016 SK hynix Inc. Kwangwoo Lee + * + * 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 __ASM_PMEM_H__ +#define __ASM_PMEM_H__ + +#ifdef CONFIG_ARCH_HAS_PMEM_API +#include +#include + +/** + * arch_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 + * + * Copy data to persistent memory media. if ARCH_HAS_PMEM_API is defined, + * then MEMREMAP_WB is used to memremap() during probe. A subsequent + * arch_wmb_pmem() need to guarantee durability. + */ +static inline void arch_memcpy_to_pmem(void __pmem *dst, const void *src, + size_t n) +{ + memcpy((void __force *) dst, src, n); + __flush_dcache_area(dst, n); +} + +static inline int arch_memcpy_from_pmem(void *dst, const void __pmem *src, + size_t n) +{ + memcpy(dst, (void __force *) src, n); + return 0; +} + +/** + * arch_wmb_pmem - synchronize writes to persistent memory + * + * After a series of arch_memcpy_to_pmem() operations this need to be called to + * ensure that written data is durable on persistent memory media. + */ +static inline void arch_wmb_pmem(void) +{ + /* pmem writes has been done in arch_memcpy_to_pmem() */ + wmb(); + + /* + * ARMv8.2 will support DC CVAP to ensure Point-of-Persistency and here + * is the point for the API like __clean_dcache_area_pop(). + */ +} + +/** + * arch_wb_cache_pmem - write back a cache range + * @vaddr: virtual start address + * @size: number of bytes to write back + * + * Write back a cache range. Leave data in cache for performance of next access. + * This function requires explicit ordering with an arch_wmb_pmem() call. + */ +static inline void arch_wb_cache_pmem(void __pmem *addr, size_t size) +{ + /* + * Just clean cache to PoC. The data in cache is remained to use the + * next access. arch_wmb_pmem() need to be the point to ensure the + * persistency under the current implementation. + */ + __clean_dcache_area(addr, size); +} + +/** + * arch_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'. + * This function requires explicit ordering with an arch_wmb_pmem() call. + */ +static inline size_t arch_copy_from_iter_pmem(void __pmem *addr, size_t bytes, + struct iov_iter *i) +{ + void *vaddr = (void __force *)addr; + size_t len; + + /* + * ARCH_HAS_NOCACHE_UACCESS is not defined and the default mapping is + * MEMREMAP_WB. Instead of using copy_from_iter_nocache(), use cacheable + * version and call arch_wb_cache_pmem(). + */ + len = copy_from_iter(vaddr, bytes, i); + + arch_wb_cache_pmem(addr, bytes); + + return len; +} + +/** + * arch_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. + * This function requires explicit ordering with an arch_wmb_pmem() call. + */ +static inline void arch_clear_pmem(void __pmem *addr, size_t size) +{ + void *vaddr = (void __force *)addr; + + memset(vaddr, 0, size); + arch_wb_cache_pmem(addr, size); +} + +/** + * arch_invalidate_pmem - invalidate a PMEM memory range + * @addr: virtual start address + * @size: number of bytes to zero + * + * After finishing ARS(Address Range Scrubbing), clean and invalidate the + * address range. + */ +static inline void arch_invalidate_pmem(void __pmem *addr, size_t size) +{ + __flush_dcache_area(addr, size); +} + +static inline bool __arch_has_wmb_pmem(void) +{ + /* return false until arch_wmb_pmem() guarantee PoP on ARMv8.2. */ + return false; +} +#endif /* CONFIG_ARCH_HAS_PMEM_API */ +#endif /* __ASM_PMEM_H__ */