From patchwork Thu Mar 20 17:41:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14024214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4E40C28B30 for ; Thu, 20 Mar 2025 17:42:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DFC928000B; Thu, 20 Mar 2025 13:41:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 48E76280006; Thu, 20 Mar 2025 13:41:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3628A28000B; Thu, 20 Mar 2025 13:41:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 18A47280006 for ; Thu, 20 Mar 2025 13:41:59 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BE0C6141777 for ; Thu, 20 Mar 2025 17:41:59 +0000 (UTC) X-FDA: 83242647558.18.31E46B0 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf15.hostedemail.com (Postfix) with ESMTP id ABC00A000D for ; Thu, 20 Mar 2025 17:41:54 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742492514; a=rsa-sha256; cv=none; b=GJdnBnracppKNpw05YfV+QaCxqogosedE3XyNqbXa9Iv9iLuAisPBW8Qv8yYrTsx0gt6kO g6IcmsoF1BmcBg3yAJho0MuYivczsWRD1rY/cFEqBtljvURKvcdDkViIC1osZchJthDiDs TQYEIlLML4r97fZHnclyebgCHg98Zao= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742492514; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HNmXxUwPUUbE0uhZLdV/DpoiIzAnJIP9flb3a3foWIU=; b=Sv/L4E1tTSrb+1Ix4enDD/KZlfvDasUtTRsizKoZvWbb6qoKSzjC16fUulZqjzKEcpqNK4 gEEpeHH+eVdX37x6NSjMhlDvA4+lnCar6IUJJbeLdaarFQFc1CNTleQ9dnpGrMMuT0gWkI OATM2NSs+pK/GTC3SHsd8Gn+Uo5lU9Y= Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZJXqW3MDtz6M4LB; Fri, 21 Mar 2025 01:38:31 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id BA7F21405A0; Fri, 21 Mar 2025 01:41:51 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.19.247) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 20 Mar 2025 18:41:51 +0100 From: Jonathan Cameron To: , , , , Yicong Yang , CC: , , Yushan Wang , , , Lorenzo Pieralisi , Mark Rutland , Catalin Marinas , Will Deacon , Dan Williams Subject: [RFC PATCH 1/6] memregion: Support fine grained invalidate by cpu_cache_invalidate_memregion() Date: Thu, 20 Mar 2025 17:41:13 +0000 Message-ID: <20250320174118.39173-2-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> References: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.19.247] X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To frapeml500008.china.huawei.com (7.182.85.71) X-Stat-Signature: u3b7eskp7xf6ubc818hedgdjh9f8oske X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: ABC00A000D X-Rspam-User: X-HE-Tag: 1742492514-674134 X-HE-Meta: U2FsdGVkX1+wYU+QIKGRXYEnkgQKXUPFa/RdfR+zEpishzYYxL7szyvEGr540ysI+9u61Pg/zjvgPT04KFx23hofDxL/G+qfDwniClfcJD7oQx7F4Cs0XYFtF9oAE5OJSNExqt4Lbz6e7Rs059MmfB0xbnCTzdffwdG6pAY3tH3qP7K4NBmcczFAm8ks1WMDn5p1hSGdhv63HkJIlZfOaypOprGbRTgoYcGB19PRvzzgXbIqHX4l0hnkcZh5JOktFwuOIaPgaBBl/S+S3oo9hAHwjkrky+FZTBtsXOQTqmad080UlyQJckDY6TqNJyQsQ/vmXWQIqmdumUK2ZKN/tq177wKoB5Dh3nYJ3JSEgEgdxhho2tW8rZqlQZKYElQAVEQ6zQpQBeNneF2xtlY+2vuf4ISvjyyPXhhfx9ZdUwI77nNnqrUhJRqbMTLK+fGJRIO/WiFPNrKAFjvd12MDRZDqG50i8M5oqKMz6yLNi/DMZ6plJnxw8xs4SHwuOoxIcu4W3slReS2E3ke9UiYYGZBRKfX1ActIqYXTFq5oI1wKEfGyaC2Ep121sdZjVA/7wzEQQvLl1MaKtmP7NOSeTHkDKP+vVMX6oNYhI+ake7XXLFTDdySUEqXoRCA0dmOH44csa/Xo1cCLP7yEifcf4ZlWz0GdaPDDjUbccc+xV/uw0KxRu4JdIEJVy0pRTqQdTfYDZXaRc7j6W8+X59br+hh/AurFd9Dw50uO5TRXLG50lZ83/xsx2KeVHrKBpIvsRUBH0LIuwBjAEQtTyDhYKmV7oHmZTwQNMYqA9WqhgAmhoj+4ZT/f+JHEUE2H3QaTG6ozhppN5bDvAR8nmO/Hq8C39UEa7eROQmS0WLM1qjTd4PQS/8VwrOEq9FH9QmmnMK4sOqVft9TPc1Vc/FSZ2nvJvTF3/QS++pURMBUc5nUv4J137fpv1TFJ6ik/87ikQRpLK35obEGKc5rmnuy 8hfN59Jz 3QtDtpM5ctlFlefuEIzBRAGY77bBYKi1ptYdCLX3G8zORTsd3vDn/J+wx0Yorb1uN4ynKgKzODSB8OBC3y2Ly6fKTv1+tEax1u0279OlYNK4cvKgDQZpXKqTQQ8AX9H9Fo3Ip53i8vTrlFHOH06QhLQV4hev/9m4QxuKyc7ca1y/Y+Uug4VZ5dVfTiC/kN0uAQXlrMNQLX8deXvtQeJpxcYrPu0fLj97YjOUL X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Yicong Yang Extend cpu_cache_invalidate_memregion() to support invalidate certain range of memory. Control of types of invalidation is left for when usecases turn up. For now everything is Clean and Invalidate. Signed-off-by: Yicong Yang --- arch/x86/mm/pat/set_memory.c | 2 +- drivers/cxl/core/region.c | 6 +++++- drivers/nvdimm/region.c | 3 ++- drivers/nvdimm/region_devs.c | 3 ++- include/linux/memregion.h | 8 ++++++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index ef4514d64c05..5d2adec1b0d4 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -354,7 +354,7 @@ bool cpu_cache_has_invalidate_memregion(void) } EXPORT_SYMBOL_NS_GPL(cpu_cache_has_invalidate_memregion, "DEVMEM"); -int cpu_cache_invalidate_memregion(int res_desc) +int cpu_cache_invalidate_memregion(int res_desc, phys_addr_t start, size_t len) { if (WARN_ON_ONCE(!cpu_cache_has_invalidate_memregion())) return -ENXIO; diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index e8d11a988fd9..6d1c9eee4cd9 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -238,7 +238,11 @@ static int cxl_region_invalidate_memregion(struct cxl_region *cxlr) } } - cpu_cache_invalidate_memregion(IORES_DESC_CXL); + if (!cxlr->params.res) + return -ENXIO; + cpu_cache_invalidate_memregion(IORES_DESC_CXL, + cxlr->params.res->start, + resource_size(cxlr->params.res)); return 0; } diff --git a/drivers/nvdimm/region.c b/drivers/nvdimm/region.c index 88dc062af5f8..033e40f4dc52 100644 --- a/drivers/nvdimm/region.c +++ b/drivers/nvdimm/region.c @@ -110,7 +110,8 @@ static void nd_region_remove(struct device *dev) * here is ok. */ if (cpu_cache_has_invalidate_memregion()) - cpu_cache_invalidate_memregion(IORES_DESC_PERSISTENT_MEMORY); + cpu_cache_invalidate_memregion(IORES_DESC_PERSISTENT_MEMORY, + 0, -1); } static int child_notify(struct device *dev, void *data) diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index 37417ce5ec7b..eefd294a0f13 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -90,7 +90,8 @@ static int nd_region_invalidate_memregion(struct nd_region *nd_region) } } - cpu_cache_invalidate_memregion(IORES_DESC_PERSISTENT_MEMORY); + cpu_cache_invalidate_memregion(IORES_DESC_PERSISTENT_MEMORY, + 0, -1); out: for (i = 0; i < nd_region->ndr_mappings; i++) { struct nd_mapping *nd_mapping = &nd_region->mapping[i]; diff --git a/include/linux/memregion.h b/include/linux/memregion.h index c01321467789..91d088ee3695 100644 --- a/include/linux/memregion.h +++ b/include/linux/memregion.h @@ -28,6 +28,9 @@ static inline void memregion_free(int id) * cpu_cache_invalidate_memregion - drop any CPU cached data for * memregions described by @res_desc * @res_desc: one of the IORES_DESC_* types + * @start: start physical address of the target memory region. + * @len: length of the target memory region. -1 for all the regions of + * the target type. * * Perform cache maintenance after a memory event / operation that * changes the contents of physical memory in a cache-incoherent manner. @@ -46,7 +49,7 @@ static inline void memregion_free(int id) * the cache maintenance. */ #ifdef CONFIG_ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION -int cpu_cache_invalidate_memregion(int res_desc); +int cpu_cache_invalidate_memregion(int res_desc, phys_addr_t start, size_t len); bool cpu_cache_has_invalidate_memregion(void); #else static inline bool cpu_cache_has_invalidate_memregion(void) @@ -54,7 +57,8 @@ static inline bool cpu_cache_has_invalidate_memregion(void) return false; } -static inline int cpu_cache_invalidate_memregion(int res_desc) +static inline int cpu_cache_invalidate_memregion(int res_desc, + phys_addr_t start, size_t len) { WARN_ON_ONCE("CPU cache invalidation required"); return -ENXIO; From patchwork Thu Mar 20 17:41:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14024223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5982EC28B30 for ; Thu, 20 Mar 2025 17:42:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 999F228000D; Thu, 20 Mar 2025 13:42:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 949E728000C; Thu, 20 Mar 2025 13:42:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8122328000D; Thu, 20 Mar 2025 13:42:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 66CD928000C for ; Thu, 20 Mar 2025 13:42:27 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 535A9BAB23 for ; Thu, 20 Mar 2025 17:42:28 +0000 (UTC) X-FDA: 83242648776.01.9F6C5F8 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf23.hostedemail.com (Postfix) with ESMTP id 44B90140010 for ; Thu, 20 Mar 2025 17:42:26 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742492546; a=rsa-sha256; cv=none; b=rHPEtnthbqjQAn9UECUE5ol4hnWrksjx6qvoEAFMjEaSK3ylX1A1nNJCVO/zsQ2SPqNukk yAz6Xz/9OKYjua++qaXvyk77YlQG0MTzH2AOwHB/gFZhni2RiZjmzyqY7UfM+Pmk2kBd0Y 1w0M4NkOcNMe1bLsXL2KJlrmSrvS25E= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742492546; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8NtAANCe4QtIKO9m3X/Y53rt7yHSwtrSDMfLnQ8LDCg=; b=0FAKQu+sMphffMa1ivOAg74Wkxe+Xpf9+bUxu2vJJHb4kTCi1CuRoBqAcB5eiB8XyIHASc vpIvnxy3Sza4//U6+V0vwkCwq+c3Erio4u7f2OYxJbEJ08Z/H6AwszUCM/jQpIzPtd6BlW vteIeyqNpBfhLZ9Qjj/2yfh+heS3hIA= Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZJXr66Rdqz6M4js; Fri, 21 Mar 2025 01:39:02 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 2F93614050D; Fri, 21 Mar 2025 01:42:23 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.19.247) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 20 Mar 2025 18:42:22 +0100 From: Jonathan Cameron To: , , , , Yicong Yang , CC: , , Yushan Wang , , , Lorenzo Pieralisi , Mark Rutland , Catalin Marinas , Will Deacon , Dan Williams Subject: [RFC PATCH 2/6] arm64: Support ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION Date: Thu, 20 Mar 2025 17:41:14 +0000 Message-ID: <20250320174118.39173-3-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> References: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.19.247] X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To frapeml500008.china.huawei.com (7.182.85.71) X-Rspam-User: X-Rspamd-Queue-Id: 44B90140010 X-Rspamd-Server: rspam05 X-Stat-Signature: 6z3195esy1fmftb8sp6uzauuqkgwf6gt X-HE-Tag: 1742492546-459555 X-HE-Meta: U2FsdGVkX1/gkyTK+5Q2zkkYCg1WHGRYecvCPvApFChPVTXM082Nap2TPUUth+8VKdWIMW0nSvnbYpXuTGLI9bj7KFQWLdxOWm+kLr+NuEornI4Cj+wI/poBnPRWLH4+tR0D1pbH6AwgF9X28vL5sI1kpJlB9SEpekdkhaLRJ95f/rFL6y0DdByfRFUDsRERZ0hk4tGlrotsP9wiCYPkszri8wN/C/aoemjGHrDoTqmt5Jn3JLn6AS7Y/Z3dHXyg4MK7Xxb5AmvMyGlaHoCmVj3EuWhLolRSMQ9oxXPLx9pbRZtP9gAZDqjfJMXx9Dn/RxHOB9bEqtKh1Q4wVfQbm6z3+CB7UQofEopJ7hJvnQSequtDX1KDumOCgpSCTdMMCNZ73FSS1s8jw2SZLZl7TZsFWCENho9QSTS4iH4IdxBbsk0gcBOLyo57cX5nKo/R73oFmXZO01Op44hrloZV+dqyYGbpe3e80MtcyAeHiMxQaqXMJpofvLG2q1IdoteyBmTlTn7DnK6xgnOmkfGxVXPsMfTDZgwK1Xh08ozk9gybI0gCacvIDWwpsRJeR/+C/3H6mPCF+Q6bCEqgIxFoepA5syJCCx34x42NH4h2hLEmjNgsOV7WVtvIucLnYLxbU2eTtXHHsNSxewDq09GhkNr98Gd9tbad2O9XOR3F7QDm9itTDpwlkpXFdBixLvPcZW1BR8JPa/YsftvM0A5BIDaySWr/1sgLZHd3bCgRQGQ3ucGgbu9YmgA/tFVXmkACW3dW9GTzy6BUePAtN+uZXwmsmADnbX60nO/Wjk+Zz9tUp3Xo8XnarcfNlyO4Fkh1iwgOydj80h1aHnE0AhLUysVQhOe7sIDPoZrYAZtJMqxIT4S2hm4jurFb3ATPLfVMujVGDmmOM1aLAOTA9HeAIXpp+yit5ER93/Y4hW0kL3c/fGsu0coEaKuelCmtwDD5djQSUA5FUynNbu5cpvX 2XXqPsvN VqZqR3mJaIGqmq5Cl22FDT8XmP4OfAFkE2lX/4njOb7X98I/noMJvI52dLQ3eh/bongnVsoMATL3Uqz6jW2Itv7UmFkp3B6eYoJqZV1A9IYWjOavENwGw/AM5Gw423YwgMSuWkN2noyQjOaBY1beTMUNIsdbmeuMHIEJ75P/9iOSGo5gDgW33X+cw592xAHheolX8wYwLZTYLXWytzXzAAJxvNq2dUnY4fv7gZAbxzbUlPQQvYPeYDO7xcA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Yicong Yang ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION provides the mechanism for invalidate certain memory regions in a cache-incoherent manner. Currently is used by NVIDMM and CXL memory. This is mainly done by the system component and is implementation define per spec. Provides a method for the platforms register their own invalidate method and implement ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION. Signed-off-by: Yicong Yang Signed-off-by: Jonathan Cameron --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/cacheflush.h | 14 ++++++++++ arch/arm64/mm/flush.c | 42 +++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 940343beb3d4..11ecd20ec3b8 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -21,6 +21,7 @@ config ARM64 select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE select ARCH_HAS_CACHE_LINE_SIZE select ARCH_HAS_CC_PLATFORM + select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION select ARCH_HAS_CRC32 select ARCH_HAS_CRC_T10DIF if KERNEL_MODE_NEON select ARCH_HAS_CURRENT_STACK_POINTER diff --git a/arch/arm64/include/asm/cacheflush.h b/arch/arm64/include/asm/cacheflush.h index 28ab96e808ef..b8eb8738c965 100644 --- a/arch/arm64/include/asm/cacheflush.h +++ b/arch/arm64/include/asm/cacheflush.h @@ -139,6 +139,20 @@ static __always_inline void icache_inval_all_pou(void) dsb(ish); } +#ifdef CONFIG_ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION + +#include + +struct system_cache_flush_method { + int (*invalidate_memregion)(int res_desc, + phys_addr_t start, size_t len); +}; + +void arm64_set_sys_cache_flush_method(const struct system_cache_flush_method *method); +void arm64_clr_sys_cache_flush_method(const struct system_cache_flush_method *method); + +#endif /* CONFIG_ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION */ + #include #endif /* __ASM_CACHEFLUSH_H */ diff --git a/arch/arm64/mm/flush.c b/arch/arm64/mm/flush.c index 013eead9b695..d822406d925d 100644 --- a/arch/arm64/mm/flush.c +++ b/arch/arm64/mm/flush.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -100,3 +101,44 @@ void arch_invalidate_pmem(void *addr, size_t size) } EXPORT_SYMBOL_GPL(arch_invalidate_pmem); #endif + +#ifdef CONFIG_ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION + +static const struct system_cache_flush_method *scfm_data; +DEFINE_SPINLOCK(scfm_lock); + +void arm64_set_sys_cache_flush_method(const struct system_cache_flush_method *method) +{ + guard(spinlock_irqsave)(&scfm_lock); + if (scfm_data || !method || !method->invalidate_memregion) + return; + + scfm_data = method; +} +EXPORT_SYMBOL_GPL(arm64_set_sys_cache_flush_method); + +void arm64_clr_sys_cache_flush_method(const struct system_cache_flush_method *method) +{ + guard(spinlock_irqsave)(&scfm_lock); + if (scfm_data && scfm_data == method) + scfm_data = NULL; +} + +int cpu_cache_invalidate_memregion(int res_desc, phys_addr_t start, size_t len) +{ + guard(spinlock_irqsave)(&scfm_lock); + if (!scfm_data) + return -EOPNOTSUPP; + + return scfm_data->invalidate_memregion(res_desc, start, len); +} +EXPORT_SYMBOL_NS_GPL(cpu_cache_invalidate_memregion, "DEVMEM"); + +bool cpu_cache_has_invalidate_memregion(void) +{ + guard(spinlock_irqsave)(&scfm_lock); + return !!scfm_data; +} +EXPORT_SYMBOL_NS_GPL(cpu_cache_has_invalidate_memregion, "DEVMEM"); + +#endif /* CONFIG_ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION */ From patchwork Thu Mar 20 17:41:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14024224 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7EB3C35FFF for ; Thu, 20 Mar 2025 17:42:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32B1428000E; Thu, 20 Mar 2025 13:42:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D7AC28000C; Thu, 20 Mar 2025 13:42:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A0A128000E; Thu, 20 Mar 2025 13:42:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F11C828000C for ; Thu, 20 Mar 2025 13:42:56 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EA745C17A4 for ; Thu, 20 Mar 2025 17:42:57 +0000 (UTC) X-FDA: 83242649994.11.B48BD0B Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf15.hostedemail.com (Postfix) with ESMTP id EE349A0005 for ; Thu, 20 Mar 2025 17:42:55 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742492576; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wMaU0GN+gDqTWXTX9tqQkIaJ9JtMR6HZhp3FEg0Ugxc=; b=gSgIE3IJDgwahY75QfXFYY1Qt8Rile166JH+LH0fmTiatNs4Qs6BJCGVof932PjxGfytpM W/aT4be5FXDoM8l/0oF0xzD7y4Z8jLNybVaF0+9nbq4poPv3WS6FUJD57QWxT0FKhmTn0d 5Bi0LI0AWsloOH+urAdx4QxyyL2NYco= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742492576; a=rsa-sha256; cv=none; b=1tJwr93pYhwcAWTvKlVNk5hNRcFN6akjKmW3w95qoHoQeIJyOsr6/4GSxz/7tfm5N3VUG5 y5PP9ayR+DLzweN3HEZjMLT/BaFVophfQ73OJ7kL8ibsjKSbNHG/HcBIe2WJvV9O3Xo6p1 lJygiPNe78UMZ2pYccIUKEkP1xNXO64= Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZJXpv5y5jz6L4v9; Fri, 21 Mar 2025 01:37:59 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 4F7A714050A; Fri, 21 Mar 2025 01:42:54 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.19.247) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 20 Mar 2025 18:42:53 +0100 From: Jonathan Cameron To: , , , , Yicong Yang , CC: , , Yushan Wang , , , Lorenzo Pieralisi , Mark Rutland , Catalin Marinas , Will Deacon , Dan Williams Subject: [RFC PATCH 3/6] cache: coherency device class Date: Thu, 20 Mar 2025 17:41:15 +0000 Message-ID: <20250320174118.39173-4-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> References: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.19.247] X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To frapeml500008.china.huawei.com (7.182.85.71) X-Rspam-User: X-Rspamd-Queue-Id: EE349A0005 X-Rspamd-Server: rspam03 X-Stat-Signature: icpbwji7ui7m9ny5598x7qgdix1o9k89 X-HE-Tag: 1742492575-121819 X-HE-Meta: U2FsdGVkX19fi9XUiEPrgpi0dJSAPAUhzo7gORvEpcLkjGQek0TuSJWzkee6xFBb8e5HYsdpsRD8xgwF0clhxVkDsSl2N3JLUBj1hWUpwu2fy0or7wolo/3GXV57sZWDpjbstDXG4N5Qzx2yOVD2wx92VBQxMl7RQKgLseKbBzOZluttgQJF6baQbK8dkzq44WHNRQd4Zbo2Y2bNacoD5gFwkD2p3Zi6UmQenoytXROFfT6aBMmCC988I1FoWzMZ9bbjBUA3qgk23RDKVYODACqUSxNCkwhz+P5WGbpFLDC3Oyn3V5WdCt/666SVuQupWZL1BUA/601+JgMzCFb0C0MYqFDVPcTnkoczz6DFlcXqepks3/dXO6Oy9KMGuVWrxCSktWudT5iqpltNBCm7kvbvjeLRLJ7qJYUXDXxSfkZxc57VoPheZZTHEwUNvVYIcEfYyrsSdeMA1Ey+O9dRV4XdUx/FW1rAT1P6aazcQCWMsnNl73lxJSWNeW18g/ncoGiyfiHGsZ9vtc/Iph/TNA5DCrenK4HBJzK/20Ss5k0hzqjZEywDbNhEMRNK+fKW6vdyMRukqeEweEYoBOqa/bg9zbWjaVVAW62Y63GCNyGKaLGGJ+1oMfhk99+QCNf5EJykb+QIPMJhBFjsOcTZRoV95VfKa7Q1jIYJ8+lL7DVI/Vcleb84LJM61yoqq6IcDwW9Agy6dJh8M0MFpe1Pj4awtIUZXrjJmxvOobIV9FHpFrJIofhbqxNTZ0HBSOjwiS7Le9HuO3yoyg1eiFGwlhujCuYa/5JT6WnQo2cLxrIXv/EV86tD0Xh30LMlqyzkiNb1WxvWUDlBZJFDvCp120d6gdoQCWjHuCCyRzLufaza5bQyYxfEViM5+/pUZLV/I2tGBAxfYzzVh+M+S/lXf6oKfnkUqIVPPNK37OZH5aXI63mcLBW77HJfMd7zENRvG2mTvHUorIApM7qQzdi 0K6+DnUk 8qJQ5tRjhDfNn0WXrW/cmQJ5tC08F73rUSlrzfFASXCGh0emAxOmCxnfsm2QWx/vGpyyExAPMj2VY62zbMAjDpyfhSKnVRGOhFyucoZjilaG4YanlOc3cn6BsqTIjdsd+7jX+T04pXfebrdQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Some systems contain devices that are capable of issuing certain cache invalidation messages to all components in the system. A typical use is when the memory backing a physical address is being changed, such as when a region is configured for CXL or a dynamic capacity event occurs. These perform a similar action to the WBINVD instruction on x86 but may provide finer granularity and/or a richer set of actions. Add a tiny device class to which drivers may register. Each driver provides an ops structure and the first op is Write Back and Invalidate by PA Range. The driver may over invalidate. An optional completion check is also provided. If present that should be called to ensure that the action has finished. If multiple agents are present in the system each should register with this class and the core code will issue the invalidate to all of them before checking for completion on each. This is done to avoid need for filtering in the core code which can become complex when interleave, potentially across different cache coherency hardware, is going on, so it is easier to tell everyone and let those who don't care do nothing. RFC question: 1. Location. Conor, do you mind us putting this in drivers/cache? I'm more than happy to add a maintainers entry and not make this your problem! 2. Need to figure out if all agents have turned up yet? No idea how to ensure this. 3. Is just iterating over devices registered with the class the simplest solution? 4. Given we have a nice device class, to which we can add sysfs attributes, what info might be useful to userspace? It might be useful to indicate how expensive a flush might be for example or where in the topology of the system it is being triggered? Signed-off-by: Jonathan Cameron --- drivers/cache/Kconfig | 6 ++ drivers/cache/Makefile | 2 + drivers/cache/coherency_core.c | 130 ++++++++++++++++++++++++++++++++ include/linux/cache_coherency.h | 60 +++++++++++++++ 4 files changed, 198 insertions(+) diff --git a/drivers/cache/Kconfig b/drivers/cache/Kconfig index db51386c663a..45dc4b2935e7 100644 --- a/drivers/cache/Kconfig +++ b/drivers/cache/Kconfig @@ -1,6 +1,12 @@ # SPDX-License-Identifier: GPL-2.0 menu "Cache Drivers" +config CACHE_COHERENCY_CLASS + bool "Cache coherency control class" + help + Class to which coherency control drivers register allowing core kernel + subsystems to issue invalidations and similar coherency operations. + config AX45MP_L2_CACHE bool "Andes Technology AX45MP L2 Cache controller" depends on RISCV diff --git a/drivers/cache/Makefile b/drivers/cache/Makefile index 55c5e851034d..b72b20f4248f 100644 --- a/drivers/cache/Makefile +++ b/drivers/cache/Makefile @@ -3,3 +3,5 @@ obj-$(CONFIG_AX45MP_L2_CACHE) += ax45mp_cache.o obj-$(CONFIG_SIFIVE_CCACHE) += sifive_ccache.o obj-$(CONFIG_STARFIVE_STARLINK_CACHE) += starfive_starlink_cache.o + +obj-$(CONFIG_CACHE_COHERENCY_CLASS) += coherency_core.o diff --git a/drivers/cache/coherency_core.c b/drivers/cache/coherency_core.c new file mode 100644 index 000000000000..52cb4ceae00c --- /dev/null +++ b/drivers/cache/coherency_core.c @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Class to manage OS controlled coherency agents within the system. + * Specifically to enable operations such as write back and invalidate. + * + * Copyright: Huawei 2025 + * Some elements based on fwctl class as an example of a modern + * lightweight class. + */ + +#include +#include +#include +#include +#include +#include + +#include + +static DEFINE_IDA(cache_coherency_ida); + +static void cache_coherency_device_release(struct device *device) +{ + struct cache_coherency_device *ccd = + container_of(device, struct cache_coherency_device, dev); + + ida_free(&cache_coherency_ida, ccd->id); +} + +static struct class cache_coherency_class = { + .name = "cache_coherency", + .dev_release = cache_coherency_device_release, +}; + +static int cache_inval_one(struct device *dev, void *data) +{ + struct cache_coherency_device *ccd = + container_of(dev, struct cache_coherency_device, dev); + + if (!ccd->ops) + return -EINVAL; + + return ccd->ops->wbinv(ccd, data); +} + +static int cache_inval_done_one(struct device *dev, void *data) +{ + struct cache_coherency_device *ccd = + container_of(dev, struct cache_coherency_device, dev); + if (!ccd->ops) + return -EINVAL; + + return ccd->ops->done(ccd); +} + +static int cache_invalidate_memregion(int res_desc, + phys_addr_t addr, size_t size) +{ + int ret; + struct cc_inval_params params = { + .addr = addr, + .size = size, + }; + + ret = class_for_each_device(&cache_coherency_class, NULL, ¶ms, + cache_inval_one); + if (ret) + return ret; + + return class_for_each_device(&cache_coherency_class, NULL, NULL, + cache_inval_done_one); +} + +static const struct system_cache_flush_method cache_flush_method = { + .invalidate_memregion = cache_invalidate_memregion, +}; + +struct cache_coherency_device * +_cache_coherency_alloc_device(struct device *parent, + const struct coherency_ops *ops, size_t size) +{ + + if (!ops || !ops->wbinv) + return NULL; + + struct cache_coherency_device *ccd __free(kfree) = kzalloc(size, GFP_KERNEL); + + if (!ccd) + return NULL; + + ccd->dev.class = &cache_coherency_class; + ccd->dev.parent = parent; + ccd->ops = ops; + ccd->id = ida_alloc(&cache_coherency_ida, GFP_KERNEL); + + if (dev_set_name(&ccd->dev, "cache_coherency%d", ccd->id)) + return NULL; + + device_initialize(&ccd->dev); + + return_ptr(ccd); +} +EXPORT_SYMBOL_NS_GPL(_cache_coherency_alloc_device, "CACHE_COHERENCY"); + +int cache_coherency_device_register(struct cache_coherency_device *ccd) +{ + return device_add(&ccd->dev); +} +EXPORT_SYMBOL_NS_GPL(cache_coherency_device_register, "CACHE_COHERENCY"); + +void cache_coherency_device_unregister(struct cache_coherency_device *ccd) +{ + device_del(&ccd->dev); +} +EXPORT_SYMBOL_NS_GPL(cache_coherency_device_unregister, "CACHE_COHERENCY"); + +static int __init cache_coherency_init(void) +{ + int ret; + + ret = class_register(&cache_coherency_class); + if (ret) + return ret; + + //TODO: generalize + arm64_set_sys_cache_flush_method(&cache_flush_method); + + return 0; +} +subsys_initcall(cache_coherency_init); diff --git a/include/linux/cache_coherency.h b/include/linux/cache_coherency.h new file mode 100644 index 000000000000..d49be27ad4f1 --- /dev/null +++ b/include/linux/cache_coherency.h @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Cache coherency device drivers + * + * Copyright Huawei 2025 + */ +#ifndef _LINUX_CACHE_COHERENCY_H_ +#define _LINUX_CACHE_COHERENCY_H_ + +#include +#include + +struct cache_coherency_device; +struct cc_inval_params { + phys_addr_t addr; + size_t size; +}; +struct coherency_ops { + int (*wbinv)(struct cache_coherency_device *ccd, struct cc_inval_params *invp); + int (*done)(struct cache_coherency_device *ccd); +}; + +struct cache_coherency_device { + struct device dev; + const struct coherency_ops *ops; + int id; +}; + +int cache_coherency_device_register(struct cache_coherency_device *ccd); +void cache_coherency_device_unregister(struct cache_coherency_device *ccd); + +struct cache_coherency_device * +_cache_coherency_alloc_device(struct device *parent, + const struct coherency_ops *ops, size_t size); + +#define cache_coherency_alloc_device(parent, ops, drv_struct, member) \ + ({ \ + static_assert(__same_type(struct cache_coherency_device, \ + ((drv_struct *)NULL)->member)); \ + static_assert(offsetof(drv_struct, member) == 0); \ + (drv_struct *)_cache_coherency_alloc_device(parent, ops, \ + sizeof(drv_struct)); \ + }) + +static inline struct cache_coherency_device * + cache_coherency_device_get(struct cache_coherency_device *ccd) +{ + get_device(&ccd->dev); + return ccd; +} + +static inline void cache_coherency_device_put(struct cache_coherency_device *ccd) +{ + put_device(&ccd->dev); +} + +DEFINE_FREE(cache_coherency_device, struct cache_coherency_device *, + if (_T) cache_coherency_device_put(_T)); + +#endif From patchwork Thu Mar 20 17:41:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14024225 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47778C36001 for ; Thu, 20 Mar 2025 17:43:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92E4228000F; Thu, 20 Mar 2025 13:43:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DC9C28000C; Thu, 20 Mar 2025 13:43:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A64A28000F; Thu, 20 Mar 2025 13:43:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5C80B28000C for ; Thu, 20 Mar 2025 13:43:28 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2A1D9BAC4F for ; Thu, 20 Mar 2025 17:43:29 +0000 (UTC) X-FDA: 83242651338.19.C692239 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf01.hostedemail.com (Postfix) with ESMTP id 3677E4000B for ; Thu, 20 Mar 2025 17:43:26 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742492607; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Sx0uJyZFYDkNkfu2SZxOotLIfyA6oHFV/FxsVb5FHgw=; b=mkjRsKpuC6JRBAIj0+g32PZjvLXiFGoRfF7brOsS/l3233M+3XP2wgSuW/vHWlRi0r3nZ6 0XdA/ujMMsuT3IDst3QfvmnpZ+g8z1ozuVQn2hGatRkQ+aOlmI+gaNRGngaKwajOGIuLvx xMMT2HGB3idV9Zti3BvH55O85gbYK4Y= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742492607; a=rsa-sha256; cv=none; b=t2w66Y63AZ8BUPJYFnmo5AQaEOFG0k7QF8eJFrZGP27X6DX6kzLgXSJgJMBgV9iDg8QcxR bHibs4ocTp3Q072iWdUR7pGtPfFXIYo51nue7ch7Xg+iGpXRzvmnlDST0Xq9q4zifVUOaB MScNT7AOZJqB8MGgSUkzy7vc3AYvVCU= Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZJXsl1VN3z6K9M7; Fri, 21 Mar 2025 01:40:27 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id ABEA714050D; Fri, 21 Mar 2025 01:43:25 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.19.247) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 20 Mar 2025 18:43:24 +0100 From: Jonathan Cameron To: , , , , Yicong Yang , CC: , , Yushan Wang , , , Lorenzo Pieralisi , Mark Rutland , Catalin Marinas , Will Deacon , Dan Williams Subject: [RFC PATCH 4/6] cache: Support cache maintenance for HiSilicon SoC Hydra Home Agent Date: Thu, 20 Mar 2025 17:41:16 +0000 Message-ID: <20250320174118.39173-5-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> References: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.19.247] X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To frapeml500008.china.huawei.com (7.182.85.71) X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3677E4000B X-Stat-Signature: mh7iue1pmscpdpou1ewzads6u4wui8xz X-HE-Tag: 1742492606-867728 X-HE-Meta: U2FsdGVkX19ZuDm5B40H5YIUWL62iUXM8tM3CsVjnSPQdo/SLurXZKHltgwzuRnN/XbT21vkAXwd+odvcveD08H8jbpYakJ+idYLEwktKSinPRyjdmzx6mfHttIW9zGSaEykSRRUYQOBmH/O27VmP23z9UmKWHR4eS2u0LZjvxOOQ2RuGGX8onyQVsbQIr3BoEGiqUIUmnKjuIY/1cvvXTQ3/RycQdde0yvwBIv7rsXlPreXOPvAfZdg9bMEucOElVlSI/u91Pz7s+JCpB3KBMU4zePA4KrsF0xk5ctbPVILCSfdsGlrjY4R+Eue0QOT4w8xjfLBYi9xTbyx6OajD0G4kgK6Ii8rz78BYhO8gAMIhgppzwwQsJJOiFE+sLi2Q43oZjzHjg5cPQKlubUFjCxGrNbAf1e3X/mDoG5IPFGGGjywFjT7bsfqAi9fYdFenx64eOi1i70DneX/nYptU7HNigyf4BS/7qAhFeYEUrdNq86EYILLj08akuUGYxnTF+r+Nu1F0FRdEt39t0/DD59oyFY5e7vt06IGlx05G9X+0rnFb44Fb2KZypI+TZmMKINK1KVZmiXZHhUW/ieqZTXmCQ5KsC8HzNWC0KN0s1lAITka+XVA3ciWtv8AOnLwUFKKkFielf0/2fble8mcd50QFLz3We60rgy6K/MA9axwX4zU6MY1XqbDwvdPboHNC1Y7yZrMwXU2CJfXm9H1uOEBO7CAFJMwyc4BUQnE/uJziNGaDWM1ggv76yW+6UmQ/Go+x0R2gPIOh+zUB7YNK4xr6EvwSBdjtBV4PIEpYoWd/Q8686SHe2A85SYcQW1iaYl5Pfa5nmatc2XVau2onvkb0aY8I3BYb2n23Gb3798DXn5Y0WVraWkFXTk0/ZFaG979UFdlX2a0wLmjZynmlIrIqjGkrx9MFYfsAhbchtq5DStBHayt5s7/1uykEV0+zsYTQEN6wr9Dk6IJztw SHBAoLFB b/5A/CvBO91DjDNJrgKAzXMegxRmTsjnV6liNNR8fz4VabILjURKsUXlfb0BdfQ1yA5/ES+ZuZoMdq62HHitvNlxoDY4WK19xyQbmDrMH/2GaMme7Amomnx4JpXaFYuWC/zGYu1go7rHX2hPz70bHNNKtnR4gTpTPOciUq6XGHhLQaPwdIRnjDjx9I9YYcxDIGym98pBJANfsA10= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Yicong Yang Hydra Home Agent is a device used for maintain cache coherency, add support of cache maintenance operations for it. Same as HiSilicon L3 cache and L3 cache PMU, memory resource of HHA conflicts with that of HHA PMU. Same workaround is implemented here to workaround resource conflict check. Signed-off-by: Yicong Yang Co-developed-by: Yushan Wang Signed-off-by: Yushan Wang Signed-off-by: Jonathan Cameron --- drivers/cache/Kconfig | 12 +++ drivers/cache/Makefile | 1 + drivers/cache/hisi_soc_hha.c | 193 +++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+) diff --git a/drivers/cache/Kconfig b/drivers/cache/Kconfig index 45dc4b2935e7..6dab014bc581 100644 --- a/drivers/cache/Kconfig +++ b/drivers/cache/Kconfig @@ -6,6 +6,18 @@ config CACHE_COHERENCY_CLASS help Class to which coherency control drivers register allowing core kernel subsystems to issue invalidations and similar coherency operations. +if CACHE_COHERENCY_CLASS + +config HISI_SOC_HHA + tristate "HiSilicon Hydra Home Agent (HHA) device driver" + depends on ARM64 && ACPI || COMPILE_TEST + help + The Hydra Home Agent (HHA) is responsible of cache coherency + on SoC. This drivers provides cache maintenance functions of HHA. + + This driver can be built as a module. If so, the module will be + called hisi_soc_hha. +endif config AX45MP_L2_CACHE bool "Andes Technology AX45MP L2 Cache controller" diff --git a/drivers/cache/Makefile b/drivers/cache/Makefile index b72b20f4248f..48b319984b45 100644 --- a/drivers/cache/Makefile +++ b/drivers/cache/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_SIFIVE_CCACHE) += sifive_ccache.o obj-$(CONFIG_STARFIVE_STARLINK_CACHE) += starfive_starlink_cache.o obj-$(CONFIG_CACHE_COHERENCY_CLASS) += coherency_core.o +obj-$(CONFIG_HISI_SOC_HHA) += hisi_soc_hha.o diff --git a/drivers/cache/hisi_soc_hha.c b/drivers/cache/hisi_soc_hha.c new file mode 100644 index 000000000000..c2af06e5839e --- /dev/null +++ b/drivers/cache/hisi_soc_hha.c @@ -0,0 +1,193 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for HiSilicon Hydra Home Agent (HHA). + * + * Copyright (c) 2024 HiSilicon Technologies Co., Ltd. + * Author: Yicong Yang + * Yushan Wang + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define HISI_HHA_CTRL 0x5004 +#define HISI_HHA_CTRL_EN BIT(0) +#define HISI_HHA_CTRL_RANGE BIT(1) +#define HISI_HHA_CTRL_TYPE GENMASK(3, 2) +#define HISI_HHA_START_L 0x5008 +#define HISI_HHA_START_H 0x500c +#define HISI_HHA_LEN_L 0x5010 +#define HISI_HHA_LEN_H 0x5014 + +/* The maintain operation performs in a 128 Byte granularity */ +#define HISI_HHA_MAINT_ALIGN 128 + +#define HISI_HHA_POLL_GAP_US 10 +#define HISI_HHA_POLL_TIMEOUT_US 50000 + +struct hisi_soc_hha { + struct cache_coherency_device ccd; + /* Locks HHA instance to forbid overlapping access. */ + spinlock_t lock; + void __iomem *base; +}; + +static bool hisi_hha_cache_maintain_wait_finished(struct hisi_soc_hha *soc_hha) +{ + u32 val; + + return !readl_poll_timeout_atomic(soc_hha->base + HISI_HHA_CTRL, val, + !(val & HISI_HHA_CTRL_EN), + HISI_HHA_POLL_GAP_US, + HISI_HHA_POLL_TIMEOUT_US); +} + +static int hisi_hha_cache_do_maintain(struct hisi_soc_hha *soc_hha, + phys_addr_t addr, size_t size) +{ + int ret = 0; + u32 reg; + + if (!size || !IS_ALIGNED(size, HISI_HHA_MAINT_ALIGN)) + return -EINVAL; + + /* + * Hardware will maintain in a range of + * [addr, addr + size + HISI_HHA_MAINT_ALIGN] + */ + size -= HISI_HHA_MAINT_ALIGN; + + guard(spinlock)(&soc_hha->lock); + + if (!hisi_hha_cache_maintain_wait_finished(soc_hha)) + return -EBUSY; + + writel(lower_32_bits(addr), soc_hha->base + HISI_HHA_START_L); + writel(upper_32_bits(addr), soc_hha->base + HISI_HHA_START_H); + writel(lower_32_bits(size), soc_hha->base + HISI_HHA_LEN_L); + writel(upper_32_bits(size), soc_hha->base + HISI_HHA_LEN_H); + + reg = FIELD_PREP(HISI_HHA_CTRL_TYPE, 1); /* Clean Invalid */ + reg |= HISI_HHA_CTRL_RANGE | HISI_HHA_CTRL_EN; + writel(reg, soc_hha->base + HISI_HHA_CTRL); + + return ret; +} + +static int hisi_hha_cache_poll_maintain_done(struct hisi_soc_hha *soc_hha, + phys_addr_t addr, size_t size) +{ + guard(spinlock)(&soc_hha->lock); + + if (!hisi_hha_cache_maintain_wait_finished(soc_hha)) + return -ETIMEDOUT; + + return 0; +} + +static int hisi_soc_hha_wbinv(struct cache_coherency_device *ccd, struct cc_inval_params *invp) +{ + struct hisi_soc_hha *hha = container_of(ccd, struct hisi_soc_hha, ccd); + + return hisi_hha_cache_do_maintain(hha, invp->addr, invp->size); +} + +static int hisi_soc_hha_done(struct cache_coherency_device *ccd) +{ + struct hisi_soc_hha *hha = container_of(ccd, struct hisi_soc_hha, ccd); + + return hisi_hha_cache_poll_maintain_done(hha, 0, 0); +} + +static const struct coherency_ops hha_ops = { + .wbinv = hisi_soc_hha_wbinv, + .done = hisi_soc_hha_done, +}; + +DEFINE_FREE(hisi_soc_hha, struct hisi_soc_hha *, if (_T) cache_coherency_device_put(&_T->ccd)) +static int hisi_soc_hha_probe(struct platform_device *pdev) +{ + struct resource *mem; + int ret; + + struct hisi_soc_hha *soc_hha __free(hisi_soc_hha) = + cache_coherency_alloc_device(&pdev->dev, &hha_ops, + struct hisi_soc_hha, ccd); + if (!soc_hha) + return -ENOMEM; + + platform_set_drvdata(pdev, soc_hha); + + spin_lock_init(&soc_hha->lock); + + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!mem) + return -ENODEV; + + /* + * HHA cache driver share the same register region with HHA uncore PMU + * driver in hardware's perspective, none of them should reserve the + * resource to itself only. Here exclusive access verification is + * avoided by calling devm_ioremap instead of devm_ioremap_resource to + * allow both drivers to exist at the same time. + */ + soc_hha->base = ioremap(mem->start, resource_size(mem)); + if (IS_ERR_OR_NULL(soc_hha->base)) { + return dev_err_probe(&pdev->dev, PTR_ERR(soc_hha->base), + "failed to remap io memory"); + } + + ret = cache_coherency_device_register(&soc_hha->ccd); + if (ret) { + iounmap(soc_hha->base); + return ret; + } + + platform_set_drvdata(pdev, no_free_ptr(soc_hha)); + return 0; +} + +static void hisi_soc_hha_remove(struct platform_device *pdev) +{ + struct hisi_soc_hha *soc_hha = platform_get_drvdata(pdev); + + cache_coherency_device_unregister(&soc_hha->ccd); + iounmap(soc_hha->base); + cache_coherency_device_put(&soc_hha->ccd); +} + +static const struct acpi_device_id hisi_soc_hha_ids[] = { + { "HISI0511", }, + { } +}; +MODULE_DEVICE_TABLE(acpi, hisi_soc_hha_ids); + +static struct platform_driver hisi_soc_hha_driver = { + .driver = { + .name = "hisi_soc_hha", + .acpi_match_table = hisi_soc_hha_ids, + }, + .probe = hisi_soc_hha_probe, + .remove = hisi_soc_hha_remove, +}; + +module_platform_driver(hisi_soc_hha_driver); + +MODULE_IMPORT_NS("CACHE_COHERENCY"); +MODULE_DESCRIPTION("Hisilicon Hydra Home Agent driver supporting cache maintenance"); +MODULE_AUTHOR("Yicong Yang "); +MODULE_AUTHOR("Yushan Wang "); +MODULE_LICENSE("GPL"); From patchwork Thu Mar 20 17:41:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14024226 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51057C28B30 for ; Thu, 20 Mar 2025 17:44:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F470280009; Thu, 20 Mar 2025 13:43:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A3B9280008; Thu, 20 Mar 2025 13:43:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76CEE280009; Thu, 20 Mar 2025 13:43:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 59600280008 for ; Thu, 20 Mar 2025 13:43:59 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6295C1C7F1A for ; Thu, 20 Mar 2025 17:44:00 +0000 (UTC) X-FDA: 83242652640.16.BED6150 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf07.hostedemail.com (Postfix) with ESMTP id 5BC1240007 for ; Thu, 20 Mar 2025 17:43:58 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742492638; a=rsa-sha256; cv=none; b=e8xy0hlYh+HgLT8zb+2cBrVLLixO/m+ODpoG7s4Gfj8rxTRD+DXVFSA5gIlYCNWVzBV5PW Vg6iUNe0SX8VT9DGF98bjgB/xWsL1VafZsso2HhRwQTMNgSEb/xv5DcSCgNJauCleQXD0w UQT590gmhhlCIMQG5B+hA0fDaAOAldg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742492638; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iwJWfv7sSsu8zcuBk05hMx3hXI76rKRudocCrAtv49o=; b=G/uv1ICm40Yq0/vRRZUhnp+qDEjraEI9S1fHTg51oRm9OP+yiWhnHAim+sr5B+Um+l3/Zo pVOnZKIcY4bQPTYvHIFTBR5R0ScTKewB/mlVb4YppjCwllMCWBWPGUjJXiBvsGOqatw6IP qnqaAWu0T1MoqF7xj+MQ+2+jQPaCkOU= Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZJXsw4H2fz6M4kK; Fri, 21 Mar 2025 01:40:36 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id DB01114050C; Fri, 21 Mar 2025 01:43:56 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.19.247) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 20 Mar 2025 18:43:56 +0100 From: Jonathan Cameron To: , , , , Yicong Yang , CC: , , Yushan Wang , , , Lorenzo Pieralisi , Mark Rutland , Catalin Marinas , Will Deacon , Dan Williams Subject: [RFC PATCH 5/6] acpi: PoC of Cache control via ACPI0019 and _DSM Date: Thu, 20 Mar 2025 17:41:17 +0000 Message-ID: <20250320174118.39173-6-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> References: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.19.247] X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To frapeml500008.china.huawei.com (7.182.85.71) X-Rspamd-Server: rspam07 X-Rspam-User: X-Stat-Signature: w6ii6rqxrj7uce4izgexpw69f89qmo41 X-Rspamd-Queue-Id: 5BC1240007 X-HE-Tag: 1742492638-745042 X-HE-Meta: U2FsdGVkX19yLY4XJf5hIHY4I5IBRdbORbrv1mXcezdcuLuBlhEa3DCCaTgJ7eOUEaA9Oqc0+Y25vSwRvj2GW0BKhc6w37yN8BQfbqBP/NQQHxGcruwR4fluA93QkeVuEk5CssW7vzWXhK06emc4EDhqx/zMCtrAlN+3urQHxGHgbr8ErZ+zjBBoKe+ItqejtOOJYS7tcAiQFzsPXLJNkJ8gtGdsagaz88kg+t2cMJXJOuPSJ0KEDvTMZ09pxmLJ4srevix+oZpIe5596+qCINNg1ooJ7MDS2ytVGam0wdIM8rhS4xu7CY57gyzD8JJhRyQUQ1Y8Rz2S202cQ2WkJqJpUH4wUnnDl1V9PU57e/pQ+BzA2VzytVc0ipzu09EjcpCjqlzSL/ySXcyzFQn7ZCaw0uQhPBc2KSEbbVWNx2n2RfDjFc1TvVAlOe0FYCenJolNMPqpX26R/nwmuflDEMgpa7EARTio5iQlFZfDvGgklvo79qk+pKEGFB9zPIGE9i1hY7Zm/rGTgprESsw/FJsUIPBN8v6fpjwUSGvqMROPAx38ZGRPYel8b93L0Dx9injjBVCt0gH4ZysMQTR4sAn3DzBBfL7tQX/iEc3tJFhgwX5D4iiB8KGobTxi5FOhd0FatiFXAuCBXOc2ZcaXscXCbkdlRuzYmUDCC38k+7WuZuuBSHXs92nCTaVBV2eNurephRZAGW1nHlObgMCXYHX5ismCAq6RokbMJ9bpllCiUx4OIlISVgvMoZ8K/+QC2By24PBN+Ivw1dCK7mrntP1EI6+m/PMBNZLVdNMlRHGlZdPwE7SDGLarZLel3woiGjPqR8BGC8YDghAKJZSlPD6rATaax4cANYyAGpsSLMZixHjek9k6OX8V/66zeRHXhAvJ+2xvCdRgR4C/uLRJmhiXxl/kWs5P2jV+PNTTxueKUmRiVqxFQpPm0cU+8UuCO/Jdk9XN1TuXunCT/9h JK9VpAfy GJwK5uzyzO+3MkWWqyCl3Tc3fPAMsHHEjeAL3WItnSD16eCe9vP2irnCJTh2IdRZ/Dv4j2kUhyShQMcf3EPumNCVeZQykmLMex50B6GSmw9Uk3gQ2i4vU6qrT4hg6dY/TFRqiUysgbi6ahxl/whX3M85dO/ZSg6b1dIRpRWToCWdwKYk5r1+H7GiAHKb6Q4cBNjBt2mLJ96n22oDSalgeS1WalIjMhxzAdK1tvdMqnHM7tf3Q29bHqV6JiQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Do not merge. This is the bare outline of what may become an ACPI code first specification proposal. From various discussions, it has become clear that there is some desire not to end up needing a cache flushing driver for every host that supports the flush by PA range functionality that is needed for CXL and similar disagregated memory pools where the host PA mapping to actual memory may change over time and where various races can occur with prefetchers making it hard to use CPU instructions to flush all stale data out. There was once an ARM PSCI specification [1] that defined a firmware interface to solve this problem. However that meant dropping into a more privileged mode, or chatting to an external firmware. That was overkill for those systems that provide a simple MMIO register interface for these operations. That specification never made it beyond alpha level. For the typical class of machine that actually uses these disaggregated pools, ACPI can potentially provide the same benefits with a great deal more flexibility. A _DSM in DSDT via operation regions, may be used to do any of: 1) Make firmware calls 2) Operate a register based state machine. 3) Most other things you might dream of. This was prototyped against an implementation of the ARM specification in [1] wrapped up in _DSM magic. That was chosen to give a second (be it abandoned) example of how this cache control class can be used. DSDT blob example that uses PSCI underneath. Device (CCT0) { Name (_HID, "ACPI0019") // _HID: Hardware ID Name (_UID, Zero) // _UID: Unique ID OperationRegion (AFFH, FFixedHW, One, 0x90) Field (AFFH, BufferAcc, NoLock, Preserve) { AFFX, 1152 } Method (_DSM, 4, Serialized) // _DSM: Device-Specific Method { If ((Arg0 == ToUUID ("61fdc7d5-1468-4807-b565-515bf6b75319") /* Unknown UUID */)) { If ((Arg2 == Zero)) { Return (Buffer (One) { 0x0F // . }) } If ((Arg2 == One)) { Name (CCR1, Buffer (0x08) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // ........ }) CreateDWordField (CCR1, Zero, RRR1) CCR1 = AFFX = Buffer (0x10) { /* 0000 */ 0x17, 0x00, 0x00, 0xC4, 0x00, 0x00, 0x00, 0x00, // ........ /* 0008 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // ........ } Name (CCOP, Zero) CCOP = RRR1 /* \_SB_.CCT0._DSM.RRR1 */ CCR1 = AFFX = Buffer (0x10) { /* 0000 */ 0x17, 0x00, 0x00, 0xC4, 0x00, 0x00, 0x00, 0x00, // ........ /* 0008 */ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // ........ } Name (CCLA, Zero) CCLA = RRR1 /* \_SB_.CCT0._DSM.RRR1 */ CCR1 = AFFX = Buffer (0x10) { /* 0000 */ 0x17, 0x00, 0x00, 0xC4, 0x00, 0x00, 0x00, 0x00, // ........ /* 0008 */ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // ........ } Name (CCRL, Zero) CCRL = RRR1 /* \_SB_.CCT0._DSM.RRR1 */ Return (Package (0x04) { CCOP, CCLA, CCRL, One }) } If ((Arg2 == 0x02)) { If (!((ObjectType (Arg3) == 0x04) && (SizeOf (Arg3) == 0x03))) { Return (One) } Name (BUFF, Buffer (0x28) { /* 0000 */ 0x16, 0x00, 0x00, 0xC4, 0x00, 0x00, 0x00, 0x00, // ........ /* 0008 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........ /* 0010 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........ /* 0018 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........ /* 0020 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // ........ }) CreateQWordField (BUFF, 0x08, BFBA) CreateQWordField (BUFF, 0x10, BFSZ) CreateQWordField (BUFF, 0x20, BFFL) Local0 = Arg3 [Zero] BFBA = DerefOf (Local0) Local0 = Arg3 [One] BFSZ = DerefOf (Local0) Local0 = Arg3 [0x02] Local1 = DerefOf (Local0) If ((Local1 != Zero)) { Return (One) } AFFX = BUFF /* \_SB_.CCT0._DSM.BUFF */ Return (Zero) } If ((Arg2 == 0x03)) { Return (Zero) } } } } Link: https://developer.arm.com/documentation/den0022/falp1/?lang=en [1] Signed-off-by: Jonathan Cameron --- drivers/acpi/Makefile | 1 + drivers/cache/Kconfig | 8 ++ drivers/cache/Makefile | 1 + drivers/cache/acpi_cache_control.c | 157 +++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 40208a0f5dfb..fcb6635d27d8 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -129,3 +129,4 @@ obj-$(CONFIG_ACPI_VIOT) += viot.o obj-$(CONFIG_RISCV) += riscv/ obj-$(CONFIG_X86) += x86/ + diff --git a/drivers/cache/Kconfig b/drivers/cache/Kconfig index 6dab014bc581..5569af0903c4 100644 --- a/drivers/cache/Kconfig +++ b/drivers/cache/Kconfig @@ -17,6 +17,14 @@ config HISI_SOC_HHA This driver can be built as a module. If so, the module will be called hisi_soc_hha. + +config ACPI_CACHE_CONTROL + tristate "ACPI cache maintenance" + depends on ARM64 + help + ACPI0019 device ID in DSDT identifies an interface that may be used + to carry out certain forms of cache flush operation. + endif config AX45MP_L2_CACHE diff --git a/drivers/cache/Makefile b/drivers/cache/Makefile index 48b319984b45..9f0679a6dab1 100644 --- a/drivers/cache/Makefile +++ b/drivers/cache/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_STARFIVE_STARLINK_CACHE) += starfive_starlink_cache.o obj-$(CONFIG_CACHE_COHERENCY_CLASS) += coherency_core.o obj-$(CONFIG_HISI_SOC_HHA) += hisi_soc_hha.o +obj-$(CONFIG_ACPI_CACHE_CONTROL) += acpi_cache_control.o diff --git a/drivers/cache/acpi_cache_control.c b/drivers/cache/acpi_cache_control.c new file mode 100644 index 000000000000..d5b91f505a26 --- /dev/null +++ b/drivers/cache/acpi_cache_control.c @@ -0,0 +1,157 @@ + +#include +#include +#include +#include + +struct acpi_cache_control { + struct cache_coherency_device ccd; + /* Stuff */ +}; + +static const guid_t testguid = + GUID_INIT(0x61FDC7D5, 0x1468, 0x4807, + 0xB5, 0x65, 0x51, 0x5B, 0xF6, 0xB7, 0x53, 0x19); + +static int acpi_cache_control_query(struct acpi_device *device) +{ + union acpi_object *out_obj; + + out_obj = acpi_evaluate_dsm(device->handle, &testguid, 1, 1, NULL);//&in_obj); + if (out_obj->package.count < 4) { + printk("Only partial capabilities received\n"); + return -EINVAL; + } + for (int i = 0; i < out_obj->package.count; i++) + if (out_obj->package.elements[i].type != 1) { + printk("Element %d not integer\n", i); + return -EINVAL; + } + switch (out_obj->package.elements[0].integer.value) { + case 0: + printk("Supports range\n"); + break; + case 1: + printk("Full flush only\n"); + break; + default: + printk("unknown op type %llx\n", + out_obj->package.elements[0].integer.value); + break; + } + + printk("Latency is %lld msecs\n", + out_obj->package.elements[1].integer.value); + printk("Min delay between calls is %lld msecs\n", + out_obj->package.elements[2].integer.value); + + if (out_obj->package.elements[3].integer.value & BIT(0)) + printk("CLEAN_INVALIDATE\n"); + if (out_obj->package.elements[3].integer.value & BIT(1)) + printk("CLEAN\n"); + if (out_obj->package.elements[3].integer.value & BIT(2)) + printk("INVALIDATE\n"); + ACPI_FREE(out_obj); + return 0; +} + +static int acpi_cache_control_inval(struct acpi_device *device, u64 base, u64 size) +{ + union acpi_object *out_obj; + union acpi_object in_array[] = { + [0].integer = { ACPI_TYPE_INTEGER, base }, + [1].integer = { ACPI_TYPE_INTEGER, size }, + [2].integer = { ACPI_TYPE_INTEGER, 0 }, // Clean invalidate + }; + union acpi_object in_obj = { + .package = { + .type = ACPI_TYPE_PACKAGE, + .count = ARRAY_SIZE(in_array), + .elements = in_array, + }, + }; + + out_obj = acpi_evaluate_dsm(device->handle, &testguid, 1, 2, &in_obj); + printk("out type %d\n", out_obj->type); + printk("out val %lld\n", out_obj->integer.value); + ACPI_FREE(out_obj); + return 0; +} + +static int acpi_cc_wbinv(struct cache_coherency_device *ccd, + struct cc_inval_params *invp) +{ + struct acpi_device *acpi_dev = + container_of(ccd->dev.parent, struct acpi_device, dev); + + return acpi_cache_control_inval(acpi_dev, invp->addr, invp->size); +} + +static int acpi_cc_done(struct cache_coherency_device *ccd) +{ + /* Todo */ + return 0; +} + +static const struct coherency_ops acpi_cc_ops = { + .wbinv = acpi_cc_wbinv, + .done = acpi_cc_done, +}; + +DEFINE_FREE(acpi_cache_control, struct acpi_cache_control *, + if (_T) cache_coherency_device_put(&_T->ccd)); + +static int acpi_cache_control_add(struct acpi_device *device) +{ + int ret; + + printk("ACPI device bound\n"); + + ret = acpi_cache_control_query(device); + if (ret) + return ret; + + struct acpi_cache_control *acpi_cc __free(acpi_cache_control) = + cache_coherency_alloc_device(&device->dev, &acpi_cc_ops, + struct acpi_cache_control, ccd); + if (!acpi_cc) + return -ENOMEM; + + ret = cache_coherency_device_register(&acpi_cc->ccd); + if (ret) + return ret; + + dev_set_drvdata(&device->dev, acpi_cc); + return 0; +} + +static void acpi_cache_control_del(struct acpi_device *device) +{ + struct acpi_cache_control *acpi_cc = dev_get_drvdata(&device->dev); + + cache_coherency_device_unregister(&acpi_cc->ccd); + cache_coherency_device_put(&acpi_cc->ccd); +} + +static const struct acpi_device_id acpi_cache_control_ids[] = { + { "ACPI0019" }, + { } +}; + +MODULE_DEVICE_TABLE(acpi, acpi_cache_control_ids); + +static struct acpi_driver acpi_cache_control_driver = { + .name = "acpi_cache_control", + .ids = acpi_cache_control_ids, + .ops = { + .add = acpi_cache_control_add, + .remove = acpi_cache_control_del, + }, +}; + +module_acpi_driver(acpi_cache_control_driver); + +MODULE_IMPORT_NS("CACHE_COHERENCY"); +MODULE_AUTHOR("Jonathan Cameron "); +MODULE_DESCRIPTION("HACKS HACKS HACKS"); +MODULE_LICENSE("GPL"); From patchwork Thu Mar 20 17:41:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 14024227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36F63C28B30 for ; Thu, 20 Mar 2025 17:44:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 641A128000C; Thu, 20 Mar 2025 13:44:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F401280008; Thu, 20 Mar 2025 13:44:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E1D028000C; Thu, 20 Mar 2025 13:44:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 32250280008 for ; Thu, 20 Mar 2025 13:44:37 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0E097B90B6 for ; Thu, 20 Mar 2025 17:44:38 +0000 (UTC) X-FDA: 83242654236.07.7E192AD Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf13.hostedemail.com (Postfix) with ESMTP id 2E74D20009 for ; Thu, 20 Mar 2025 17:44:35 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742492676; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NvpcgGVmmfdX80gEFHqTe4ssrSgKgn6kF5ZLPPIiVCg=; b=G6uNUneHqIiz3u2WVi6XopJijmzb/3ZYncRsEqQIMxHODXTe7k9uu4ANGebddKy1y57ZI8 in4FcDrf4ruFuKfrCgpefMDHnoVYNGxVrFGQdSknUobPsQkLUPHnMxvX+LeIa9yQczg/3r SGTFfTKWmR2N5XJxuh0ZGJfKStwOw3Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742492676; a=rsa-sha256; cv=none; b=bPo55TLmEKfXotRfgMxAkOCd6GSqOdO3CrOvOZfhl2+lUa6880B5jTyAIwlsJOPlWFe7lV EycxG0hep+r4NeJQrkBSpfk6puzdp72cq85572d8QXsljG0hc4rIB7wWQ3nsRiVq199haa c6+tgaXQZgUCa/X+zFem3RiXP9biBhM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZJXtx4jStz6K9Fg; Fri, 21 Mar 2025 01:41:29 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 1893114050A; Fri, 21 Mar 2025 01:44:28 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.19.247) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 20 Mar 2025 18:44:27 +0100 From: Jonathan Cameron To: , , , , Yicong Yang , CC: , , Yushan Wang , , , Lorenzo Pieralisi , Mark Rutland , Catalin Marinas , Will Deacon , Dan Williams Subject: [RFC PATCH 6/6] Hack: Pretend we have PSCI 1.2 Date: Thu, 20 Mar 2025 17:41:18 +0000 Message-ID: <20250320174118.39173-7-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> References: <20250320174118.39173-1-Jonathan.Cameron@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.19.247] X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To frapeml500008.china.huawei.com (7.182.85.71) X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2E74D20009 X-Stat-Signature: 3x8swgwqpo53wtfsxjknryj9h3gskkhp X-HE-Tag: 1742492675-158784 X-HE-Meta: U2FsdGVkX1+urSwDq5qmweeHPHoubJiOrSib4EldoVrWc/vOkXhDPxoEv+4wkTPqYE6tJp1j1Ydp2H4lOOqu9WOjX8HeMo835D6xrHSG7KQnTnV0typhgbvwfqpSofuKxmloRbPiZP15tFd8pCX5Ik2TbZSaDTyUApmshXrblD0GxMB+GFCvpwIS2zGiSFvGSIjtkx68M0mGqoOF6vCRK00wFNJEHaEYGGtRztlgYnXHtqbRhdDRAhYRFul9F39N/d9lzzySmNSlYOuLlBZmW6o9O4WxJQ3LGpHn4bRUKXhRUrAHaVzTENlo5UWKdiUbkMYuaLweZjn3EwaUn0lXsZ2t2BZF0krlEZSeLTHqHv5hFJiWdjNe16GS/95aBv6ZBW7XHM+MMR7S0CTUqs9mRcm3JZ21LZ0GX8ZDTFuDq8Kv/0BNBZC5RMwr8uemAyvyExB7vjmJEjG0rMbI0oam7e0rCdovXVvDVDfp5F+CzIW6OD2/0N9CQzPgChmE/5WS3C+nVEkb4FRPPspI2S852SdOJ/Bx8kHgpX7YcYrCJaVdQhus6JOHv1gLCRuKd+N14S/Iuu1NuXiaP50EE3YPjNrEWrkYNDHwKnfEBUcEyQ8M5mXoMWbeS2y8s5gRTcsH9cH2bP9cZsVcwMLTlxzPG1QT3RKQ7H/B/Pc2TuXTA32Dukz7RV7PExEyC2yemjVsvnJu7DuixJFTSmkWW1olY/Xb131kHBdxd7IGixwTndhpocZ1Ulq7Je6CVZWWCc0FBkpW7WmLRn+ZlBWdv2cA0KrPBq/Skjx8YIh4SxYde0LuU2sBRXqstNwZlxt6yRLiIY5PMUe7JuteHDeE67RZfhHI++8CPq+u5NhiSh2g1JPh+ebe737EwnZOR2eiC8LZjOvZ30lDQLHUeaSsQbO1uqYySzg0WIyBvlL2P2VsrwPEkwqSsYM4ifB6GMqy7AU6DVWrI9qatGojC1ANiad RQnWfupo +AE+t5+uXxBOXPc8/LNjIH9B2wCZF9gzDUXq8QAo1aHQBJ5Qf8FcsCcfolYZVWZcZY67j8zRklY56p8T6oKnsFOWyCyHy7OT56eo9Hs9N6Rci87zaBWRk08+jB9/ifim+5YRGomE6makF3VU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Need to update QEMU to PSCI 1.2. In meantime lie. This is just here to aid testing, not for review! Signed-off-by: Jonathan Cameron --- drivers/firmware/psci/psci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index a1ebbe9b73b1..6a7a6e91fcc4 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -646,6 +646,8 @@ static void __init psci_init_smccc(void) } } + /* Hack until qemu version stuff updated */ + arm_smccc_version_init(ARM_SMCCC_VERSION_1_2, psci_conduit); /* * Conveniently, the SMCCC and PSCI versions are encoded the * same way. No, this isn't accidental.