From patchwork Fri Sep 29 15:02:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404500 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C639E71D40 for ; Fri, 29 Sep 2023 15:03:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=e+6U2rcuoaD9NCYVcauQUH/Nc3xIAXN/vt3bIGtGn/w=; b=Ve2qD90nWu0CWp h9MUBPMIHc6+ALagJGVQDJFttD/m+zniI4AgjHVE7LbT/OU2s9b0uoL9vJSq8vsYj/7G8ggLcII/T TbDZhfiM0DZdpp6FpS6Q43hGcHOYbPcaDl3JljBkgFA9zTYP+MVY16Zin8kOiW3QhEcgVBUIe+5O0 Fd1cGiGGUwwyu6cTpDgHJtKTiAZJu0zHM4boSbOptIsO6Vx1TFUDWkoO0JQVyju50JGggwiMO1LKL cQhRKzYY/Vv3DIsjWmKaLxj1sHmib+eeUVev3MIAW3z4sfrZ0EOeWcCUXACdq2nZxC92PxIR9ZeuA pCwchE65p6z5SCtP2JjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1U-0088DX-0J; Fri, 29 Sep 2023 15:03:20 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1R-0088CD-2y for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:19 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4C5CCDA7; Fri, 29 Sep 2023 08:03:54 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E98F73F5A1; Fri, 29 Sep 2023 08:03:14 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:02:50 +0100 Subject: [PATCH v3 01/17] firmware: arm_ffa: Update the FF-A command list with v1.1 additions MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-1-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3496; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=iM0M4h4uY9LcS7jhU1Ni5Kw/SdOd9wlQU64B4wmmDx0=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucupa6nu79ubQS1rGE5x6xDF2tzzi8ymkczB +9PQ0u0UjSJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnLgAKCRAAQbq8MX7i mLjEEACOITJFey81YFZaZ4P1XZfaKQl3vuVT1PteZN8+r24U0QvVP6mibtqsrCl4IdmaN7ZeoOr xxRNx4r5EnDIuJuLiHKXEl4jOmQ/Nal4jRKeXZpWy+dDikzbxmi+heZT+Mkp9PPhVpIj5XRYUf3 ToQCVjUw8W65uU8pfa+btq9MRmhiNj5Umv8tq4QqoTXmm6YSrdws7xDcWpm2V7Q0VjgWYouKGin GgAnZWoqx6Xw3rNqqtEjiPbgT1mwJykkw7aqvrJ00Bn4zMdH8iCVlIQj6jVppgcL3a5brKuMCyQ Bs5xmJE3dirLFz9V/YDPKMgQHKCdEJ6zEbO8xc+R7g6MIDAYGpUZIRz0xCQFqWpGeKLP3oZO0g7 +V3CuTyV8w9CbkylNAA4U9JRUejXay1ozQaXFx3+sAlWNKLXWaKKx1YChwuyMAFmP3yXd+J9kxH Bj75RFUQpOObva2z1SqAebRDPchCO5G+O1SK/llnjNYBTxlEsoQZGQJSiZpJWxLz0a2ALsiYyQV XhTyOCHWoOC1oMLCmCU+y3GQBbEsQn5z46OkEj4pkuZlpz1KccE+hCxvNc4mFIzqX/Q4p3kgwKA he1B8mEgOID8KJ5607k6eyvN3pV2ZWPiRSwiaNzG1G9VhZ1/XvSto3MF7DqcdeXUOt8alvTZh+r pLzgvyV8EwSxujw== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080318_049340_6C0D799B X-CRM114-Status: GOOD ( 13.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Arm Firmware Framework for A-profile(FFA) v1.1 introduces notifications and indirect messaging based upon notifications support and extends some of the memory interfaces. Let us add all the newly supported FF-A function IDs in the spec. Also update to the error values and associated handling. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 3 ++- include/linux/arm_ffa.h | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 121f4fc903cd..2b24cda2a185 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -64,6 +64,7 @@ static const int ffa_linux_errmap[] = { -EACCES, /* FFA_RET_DENIED */ -EAGAIN, /* FFA_RET_RETRY */ -ECANCELED, /* FFA_RET_ABORTED */ + -ENODATA, /* FFA_RET_NO_DATA */ }; static inline int ffa_to_linux_errno(int errno) @@ -336,7 +337,7 @@ static int ffa_mem_first_frag(u32 func_id, phys_addr_t buf, u32 buf_sz, if (ret.a0 == FFA_ERROR) return ffa_to_linux_errno((int)ret.a2); - if (ret.a0 == FFA_SUCCESS) { + if (ret.a0 == FFA_SUCCESS || ret.a0 == FFA_FN64_SUCCESS) { if (handle) *handle = PACK_HANDLE(ret.a2, ret.a3); } else if (ret.a0 == FFA_MEM_FRAG_RX) { diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index cc060da51bec..2ea1717a0825 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -20,6 +20,7 @@ #define FFA_ERROR FFA_SMC_32(0x60) #define FFA_SUCCESS FFA_SMC_32(0x61) +#define FFA_FN64_SUCCESS FFA_SMC_64(0x61) #define FFA_INTERRUPT FFA_SMC_32(0x62) #define FFA_VERSION FFA_SMC_32(0x63) #define FFA_FEATURES FFA_SMC_32(0x64) @@ -54,6 +55,23 @@ #define FFA_MEM_FRAG_RX FFA_SMC_32(0x7A) #define FFA_MEM_FRAG_TX FFA_SMC_32(0x7B) #define FFA_NORMAL_WORLD_RESUME FFA_SMC_32(0x7C) +#define FFA_NOTIFICATION_BITMAP_CREATE FFA_SMC_32(0x7D) +#define FFA_NOTIFICATION_BITMAP_DESTROY FFA_SMC_32(0x7E) +#define FFA_NOTIFICATION_BIND FFA_SMC_32(0x7F) +#define FFA_NOTIFICATION_UNBIND FFA_SMC_32(0x80) +#define FFA_NOTIFICATION_SET FFA_SMC_32(0x81) +#define FFA_NOTIFICATION_GET FFA_SMC_32(0x82) +#define FFA_NOTIFICATION_INFO_GET FFA_SMC_32(0x83) +#define FFA_FN64_NOTIFICATION_INFO_GET FFA_SMC_64(0x83) +#define FFA_RX_ACQUIRE FFA_SMC_32(0x84) +#define FFA_SPM_ID_GET FFA_SMC_32(0x85) +#define FFA_MSG_SEND2 FFA_SMC_32(0x86) +#define FFA_SECONDARY_EP_REGISTER FFA_SMC_32(0x87) +#define FFA_FN64_SECONDARY_EP_REGISTER FFA_SMC_64(0x87) +#define FFA_MEM_PERM_GET FFA_SMC_32(0x88) +#define FFA_FN64_MEM_PERM_GET FFA_SMC_64(0x88) +#define FFA_MEM_PERM_SET FFA_SMC_32(0x89) +#define FFA_FN64_MEM_PERM_SET FFA_SMC_64(0x89) /* * For some calls it is necessary to use SMC64 to pass or return 64-bit values. @@ -76,6 +94,7 @@ #define FFA_RET_DENIED (-6) #define FFA_RET_RETRY (-7) #define FFA_RET_ABORTED (-8) +#define FFA_RET_NO_DATA (-9) /* FFA version encoding */ #define FFA_MAJOR_VERSION_MASK GENMASK(30, 16) @@ -86,6 +105,7 @@ (FIELD_PREP(FFA_MAJOR_VERSION_MASK, (major)) | \ FIELD_PREP(FFA_MINOR_VERSION_MASK, (minor))) #define FFA_VERSION_1_0 FFA_PACK_VERSION_INFO(1, 0) +#define FFA_VERSION_1_1 FFA_PACK_VERSION_INFO(1, 1) /** * FF-A specification mentions explicitly about '4K pages'. This should From patchwork Fri Sep 29 15:02:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404503 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 39102E71D40 for ; Fri, 29 Sep 2023 15:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VumgiMSP/cHaOEydya2XgmFGtsmVZkcyHu3EA4Igzpk=; b=x/Y85VpMAkvBti NBXQVoPGAvj2ik2c47EEImWaE9TAQL0lpDqk5BmFNSWV/MNyGACWyHJ9sMAzrVGjG6+z24Rzy/Ag/ 43YE65kSKUoTilY1vPKvhky31VSjxVvw6IyxjM5jVtmTomxUjKOcZngHhNlRhARG6yyNyHO+75T6X 9HkzxTUHHtJHs5vaBebww1EGI/2niDGYPHvznLywNpw1K9gz5ahyybDNci5M2L+bOwWUIsw00UdJj k25IMStggRTjIux71gNhWDha4vL5ZuUc+x4gA+pGmoEL4SJgCGkHaOOaT5afnrI+RCCy8TKxEZdYX yR1N8kTr+cRqYj9Hm84w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1l-0088Mz-0H; Fri, 29 Sep 2023 15:03:37 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1U-0088Df-2J for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:22 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 794261007; Fri, 29 Sep 2023 08:03:55 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 226643F5A1; Fri, 29 Sep 2023 08:03:16 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:02:51 +0100 Subject: [PATCH v3 02/17] firmware: arm_ffa: Implement notification bitmap create and destroy interfaces MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-2-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3398; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=E8dkL+QG2QXGEwg80l0faZM6cA032hi2OPI14UW5ukU=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucuvBBiLwRwI+A6SBHoF7BhodlY60hl2wjwZ SYQKjnfHqqJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnLgAKCRAAQbq8MX7i mFOQEAC1qH09c9WVdsH6CsUdBdw3pCM0Gbn2kvv/5BJyJEKhaSlahsvCohQGLVkTiinsRzlQN/G AcbwPbb9tZ6+AvWDnxeUa+YLz+hjT8PgQuLziXUmrqyngPU8IivU3ENKLnHIjjyI68E+q1hEddD Svfmo57KwmzLDn6fbf4BlyL2rF2KDR+VamNUuLOUp2dCgn9nMoQ/1bchDcxwLK2OiYyAiTqI+Fs tSCdY/pzUJXye/nnv5FK+H++Y9Xv2Ji4lmCTPDKTunmMpVRu2xlG5JClEVE5XfLjLwCsvkGiEF5 me4K9Kg3IIoENEpbOV18LLSJN7BcY/LU6DKfhqvH5jhRHx0rbm7lkhikTDwFCR1Gwdy8IJ6VgHn o40WyqaKv6EorKh4e+DFuAGDp6d/XpyS5OTVGE7HDWlucYNIAl61NZrm3KEmrjFekJhyhgRIeo8 q9cX4JCiLvfKxuMCzChS7AuDsBBqxqKxl01wFXBzKAV+xFIySKgSlLRmnLbelzFtlE6b//SigsB jaXxpvQwwDP9iNWBomOpWr6CDOJfb3VfumDdG7+ZWp25wXMhkgNy/gTVs4KlvT6o/EWJIexGdNy 5CeJ3/a3wfsW/0u+goWAFd7k+lebdnG7HsvrJLbCXR3eyzJLSTHfT3QwXPqQRyKuLB4pns2+euD 4XFwj2kKBd17Y+w== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080320_859173_2F906634 X-CRM114-Status: GOOD ( 15.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On systems without a hypervisor the responsibility of requesting the creation of the notification bitmaps in the SPM falls to the FF-A driver. We use FFA features to determine if the ABI is supported, if it is not we can assume there is a hypervisor present and will take care of ensure the relevant notifications bitmaps are created on this partitions behalf. An endpoint’s notification bitmaps needs to be setup before it configures its notifications and before other endpoints and partition managers can start signaling these notifications. Add interface to create and destroy the notification bitmaps and use the same to do the necessary setup during the initialisation and cleanup during the module exit. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 60 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 2b24cda2a185..efa4e7fb15e3 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -84,6 +84,7 @@ struct ffa_drv_info { void *rx_buffer; void *tx_buffer; bool mem_ops_native; + bool bitmap_created; }; static struct ffa_drv_info *drv_info; @@ -555,6 +556,37 @@ static int ffa_features(u32 func_feat_id, u32 input_props, return 0; } +static int ffa_notification_bitmap_create(void) +{ + ffa_value_t ret; + u16 vcpu_count = nr_cpu_ids; + + invoke_ffa_fn((ffa_value_t){ + .a0 = FFA_NOTIFICATION_BITMAP_CREATE, + .a1 = drv_info->vm_id, .a2 = vcpu_count, + }, &ret); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + return 0; +} + +static int ffa_notification_bitmap_destroy(void) +{ + ffa_value_t ret; + + invoke_ffa_fn((ffa_value_t){ + .a0 = FFA_NOTIFICATION_BITMAP_DESTROY, + .a1 = drv_info->vm_id, + }, &ret); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + return 0; +} + static void ffa_set_up_mem_ops_native_flag(void) { if (!ffa_features(FFA_FN_NATIVE(MEM_LEND), 0, NULL, NULL) || @@ -712,6 +744,31 @@ static void ffa_setup_partitions(void) kfree(pbuf); } +static int ffa_notifications_setup(void) +{ + int ret; + + ret = ffa_features(FFA_NOTIFICATION_BITMAP_CREATE, 0, NULL, NULL); + if (!ret) { + ret = ffa_notification_bitmap_create(); + if (ret) { + pr_err("notification_bitmap_create error %d\n", ret); + return ret; + } + } + drv_info->bitmap_created = true; + + return 0; +} + +static void ffa_notifications_cleanup(void) +{ + if (drv_info->bitmap_created) { + ffa_notification_bitmap_destroy(); + drv_info->bitmap_created = false; + } +} + static int __init ffa_init(void) { int ret; @@ -767,7 +824,7 @@ static int __init ffa_init(void) ffa_set_up_mem_ops_native_flag(); - return 0; + return ffa_notifications_setup(); free_pages: if (drv_info->tx_buffer) free_pages_exact(drv_info->tx_buffer, RXTX_BUFFER_SIZE); @@ -782,6 +839,7 @@ subsys_initcall(ffa_init); static void __exit ffa_exit(void) { + ffa_notifications_cleanup(); ffa_rxtx_unmap(drv_info->vm_id); free_pages_exact(drv_info->tx_buffer, RXTX_BUFFER_SIZE); free_pages_exact(drv_info->rx_buffer, RXTX_BUFFER_SIZE); From patchwork Fri Sep 29 15:02:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404516 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D79ABE71D46 for ; Fri, 29 Sep 2023 15:04:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Z/Y7LVHWSRYfbRSmKZ6VWmljzYTXKIoq0EYrpkwWjOk=; b=mKah8DdKRaG4yY 3CPPVSVPQju2sj8ovJky7SXXz4DMOk0dlBW/wjMoAvpIVTwiYtPQbhoLqfmkdqeGyQS42gA/qE7rI iu0alifT8TbH6EXxbhGjwfDv93DtdOavBGYIjFD6sCL4aedcdIXcjCj2vMKhyS+0sKf1v67oov3XN reQJe1m/+9X4+qTPEjk5+WGyrkNF48MKiXSNHSz7JBgQe7Pp4GZqVWqQR/yth6oI7tO/e9rYYrQsR CUN3RwV4K9OnxX1HP+dlcnjtJBnzOmWziWGI95/Dlf1THbhBZUsdyuKrLd2R6T82WEtPux4WZ74DI Wth2GQuQt/GjRvh95xlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1k-0088Ma-1j; Fri, 29 Sep 2023 15:03:36 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1T-0088Cp-0Y for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:20 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A80311063; Fri, 29 Sep 2023 08:03:56 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4F9973F5A1; Fri, 29 Sep 2023 08:03:17 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:02:52 +0100 Subject: [PATCH v3 03/17] firmware: arm_ffa: Implement the notification bind and unbind interface MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-3-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2207; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=6dM7t7UcezChOGHUwYllL2LxWCmWJi8qtz0lRrVzNQ8=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucuri2NvMBd2IjxYNO/D03XgYBmvOLA9YjLc idNzqIiTE+JAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnLgAKCRAAQbq8MX7i mNOuD/4+jcPMdjdx5iTpJDFKJIU+T08pss3uCcdy0GEF9cddo335kSH2rAbXlNk4XHH150kw9K6 NInTCOWpnCVvD+Wk6I7pKYDd/tzKh1KVjCDpRtRLx7g1B8ihjnxthRTCrPfW59G3VnS/QSV9KJG GlGLfx9VBDIazIYaHrHEkvvKEla+rLU/MkLR8tsFSFssXmpA/GflTEHkhO0oqLgst4InUYFW7Rw aTBrbwjOWCFmuqr7xV8IaoLNaNAzZV6bh1pFziLwX+yLxZCUBQV/zo/ptQGaVLTj110JE6GCv/h +QUPZrnjOClVOffWhXtHa1mwQ7a0Pt+sMymCaSszK4xddfnOuHwm0/DavXf2qMHMiovdQYf5yro K7NqxivFAX+2WLsp4vLXyqXhIlq71OuQrVlxv5NVzrw3tgAGJQPxmKV4i1pqrq3QII8mDYYHLj3 a/nDOfABp7AhYVGZBAUQq5njecxdmJl+k3V2W1jAS5+TahyPrgEQG+U/aJVQf2h6YXnFaEig7Ar zFLcB4iIldYmZT6ZY4bLawjD5CKPEsbKa7ya9kYh8EM/4oU9WsCMawjgAgO9EL4i6j7pRRj5aAR NXnyPYf3dTdYpQTGzZxstOj6dAf/08kehdTyFTkQM80QG4peBrh9Azl8ldq6hTjmO4joZS7G0Ig qiCKLrfOcFW9VFQ== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080319_302275_391FBF19 X-CRM114-Status: GOOD ( 13.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A receiver endpoint must bind a notification to any sender endpoint before the latter can signal the notification to the former. The receiver assigns one or more doorbells to a specific sender. Only the sender can ring these doorbells. A receiver uses the FFA_NOTIFICATION_BIND interface to bind one or more notifications to the sender. A receiver un-binds a notification from a sender endpoint to stop the notification from being signaled. It uses the FFA_NOTIFICATION_UNBIND interface to do this. Allow the FF-A driver to be able to bind and unbind a given notification ID to a specific partition ID. This will be used to register and unregister notification callbacks from the FF-A client drivers. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index efa4e7fb15e3..26bf9c4e3b5f 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -587,6 +587,35 @@ static int ffa_notification_bitmap_destroy(void) return 0; } +#define NOTIFICATION_LOW_MASK GENMASK(31, 0) +#define NOTIFICATION_HIGH_MASK GENMASK(63, 32) +#define NOTIFICATION_BITMAP_HIGH(x) \ + ((u32)(FIELD_GET(NOTIFICATION_HIGH_MASK, (x)))) +#define NOTIFICATION_BITMAP_LOW(x) \ + ((u32)(FIELD_GET(NOTIFICATION_LOW_MASK, (x)))) + +static int ffa_notification_bind_common(u16 dst_id, u64 bitmap, + u32 flags, bool is_bind) +{ + ffa_value_t ret; + u32 func, src_dst_ids = PACK_TARGET_INFO(dst_id, drv_info->vm_id); + + func = is_bind ? FFA_NOTIFICATION_BIND : FFA_NOTIFICATION_UNBIND; + + invoke_ffa_fn((ffa_value_t){ + .a0 = func, .a1 = src_dst_ids, .a2 = flags, + .a3 = NOTIFICATION_BITMAP_LOW(bitmap), + .a4 = NOTIFICATION_BITMAP_HIGH(bitmap), + }, &ret); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + else if (ret.a0 != FFA_SUCCESS) + return -EINVAL; + + return 0; +} + static void ffa_set_up_mem_ops_native_flag(void) { if (!ffa_features(FFA_FN_NATIVE(MEM_LEND), 0, NULL, NULL) || From patchwork Fri Sep 29 15:02:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404501 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 304F3E71D46 for ; Fri, 29 Sep 2023 15:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2KXyJMKgDnNy0khLtDKzqFuXmRMm8PXIzSxQe4JM9+E=; b=MpqwZAjtnbw9FD gfKPpEn3gKRMxrELzzotfgvQmZsCGsD4phm0hmELIQ7qaZBweZJj0K+H5Ce2M4DIThgDZ6/7hJNh7 US8H/k9niAf64nEtllW5z86pGFLyPXKk0hftCmksbzLcDYp6BrhWqIawhcU7fVtC6s2UCEUfSUlZR b65OXEGJXpbOCJZyhkls5SyJ67WTonHB4gN1xoXtJF7mU2fll/Yx1AunodQrDf+LybU9qJTS/Uxox DZiffQvb0UvlGJyhqVPif5ES7dfMfxnd4lYdHL6ngrdDT54jojYuXSjpXB6T31yup/Q7udj0mGf4U MFR1JIaZr9R14bR2qaQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1m-0088OB-1m; Fri, 29 Sep 2023 15:03:38 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1V-0088Ec-2J for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:26 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D3831106F; Fri, 29 Sep 2023 08:03:57 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7CBCE3F5A1; Fri, 29 Sep 2023 08:03:18 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:02:53 +0100 Subject: [PATCH v3 04/17] firmware: arm_ffa: Implement the FFA_RUN interface MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-4-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2472; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=3/hdIfSwI04CJ8YoVOAM5D8uyI/IOxahGfihf3h43bU=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucuyb+IhwHkIr8NkHq2LIo7vVzNfZRZsmBWR 4z6tmAq9BKJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnLgAKCRAAQbq8MX7i mG9sD/908ogrCGeAYlAX2T65/u61ZJ7us0nLl5Uheh/+02XbBaRhe5MTBlWCuxDsgwR+evhSYU3 NwZ+qXzILP+4auBk2iAlAxfSh9tGliHl2UOOCsb8ovJaLgagrw0zXJyYJkwz5OPshhY5EkfMnt3 ffwMTulCVOv6iLyGnghUQsyxGZOff5IMuGouns2vqnmEW4CmLqDkBo1X/vnXefbZlt2Lz9eSAjO RuVdrdEZoB90GM2q/FCns3FFtmg/pb59uh4paZ8+kaoyQ+sB5GoZXg+Q17bbTlar9Ypm9Sp5Rui R8wcjmq7I58eIXNWwCbz6jVY1nw3X46H5JOEPXZElh57O7PajQLrJLV4pQwgXQH6PMaNwmd4d3l iJf+UbzPbDEo7JkBz+43MWhMEXGZwsQDAmOUXF0n/TQUBsqpLHHGZqbr42FJqoXo6qrjXO5fnNV m5rk4WRCOgmCzRZnE1ewRI1Oxdg+3QoUplO43iTFP3tZjUADnTQl8mQ8mpP0byodrXWaRIRSI0A P0Zl2+qvKUG9qZjgnrBGdRVJ7HoFU821Z2ZQ+KqxQNbHF3Xe5Y4yHN9gYn3sNukQx0PWQ8tSQuI BukTyIlcNQBrrUg3Loqo+XFukGt5Nlcco2QOziTsxJfSh8kWllWq4qle1u1bIHS2p6Gxbeg38LN W/D92epURHxVZ2g== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080321_883654_1BF8AD9A X-CRM114-Status: GOOD ( 13.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org FFA_RUN is used by a scheduler to allocate CPU cycles to a target endpoint execution context specified in the target information parameter. If the endpoint execution context is in the waiting/blocked state, it transitions to the running state. Expose the ability to call FFA_RUN in order to give any partition in the system cpu cycles to perform IMPDEF functionality. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 22 ++++++++++++++++++++++ include/linux/arm_ffa.h | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 26bf9c4e3b5f..b265063e76ea 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -616,6 +616,23 @@ static int ffa_notification_bind_common(u16 dst_id, u64 bitmap, return 0; } +static int ffa_run(struct ffa_device *dev, u16 vcpu) +{ + ffa_value_t ret; + u32 target = dev->vm_id << 16 | vcpu; + + invoke_ffa_fn((ffa_value_t){ .a0 = FFA_RUN, .a1 = target, }, &ret); + + while (ret.a0 == FFA_INTERRUPT) + invoke_ffa_fn((ffa_value_t){ .a0 = FFA_RUN, .a1 = ret.a1, }, + &ret); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + + return 0; +} + static void ffa_set_up_mem_ops_native_flag(void) { if (!ffa_features(FFA_FN_NATIVE(MEM_LEND), 0, NULL, NULL) || @@ -708,10 +725,15 @@ static const struct ffa_mem_ops ffa_drv_mem_ops = { .memory_lend = ffa_memory_lend, }; +static const struct ffa_cpu_ops ffa_drv_cpu_ops = { + .run = ffa_run, +}; + static const struct ffa_ops ffa_drv_ops = { .info_ops = &ffa_drv_info_ops, .msg_ops = &ffa_drv_msg_ops, .mem_ops = &ffa_drv_mem_ops, + .cpu_ops = &ffa_drv_cpu_ops, }; void ffa_device_match_uuid(struct ffa_device *ffa_dev, const uuid_t *uuid) diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index 2ea1717a0825..12fd134bf670 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -387,10 +387,15 @@ struct ffa_mem_ops { int (*memory_lend)(struct ffa_mem_ops_args *args); }; +struct ffa_cpu_ops { + int (*run)(struct ffa_device *dev, u16 vcpu); +}; + struct ffa_ops { const struct ffa_info_ops *info_ops; const struct ffa_msg_ops *msg_ops; const struct ffa_mem_ops *mem_ops; + const struct ffa_cpu_ops *cpu_ops; }; #endif /* _LINUX_ARM_FFA_H */ From patchwork Fri Sep 29 15:02:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404517 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 39533E71D40 for ; Fri, 29 Sep 2023 15:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=t6XsNXT3xSbYpcfxl3hbEjyg5qA+7dDeNEk1bQ2SlCk=; b=GJe/Cv5DlBIMqZ OzmPEWvIyBaoZ4cLC4MnTeHqParu2T4Kf8a2uRKSePEQSq2GbKR+c7xJVCn4YvLsQZMZ8XXBLHBeH rrpkqo+Z0eVxsIC5yRxbHojqv8SQ1QbYfgCG2Cn2NUmHFAwgObNGSnQHn8cv/4I9HqLW4G9tec/aY Rs6M1UVF/GppVMOZt1JajrxQZIWto//QoZi1VV9hWYQfqhpTSIqc3MW3wd5UbDQk1O1MfcseYKLvG Ajb6NDK4YhdAtTP5/1lUZ29ej9dhsd3Y/AmAkGv/C47y1nvTBj2xfLJOmuqp3jchP3Yfatx/AKZOW DDjpnQSA1YczZjisrcyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1l-0088Np-36; Fri, 29 Sep 2023 15:03:37 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1V-0088E3-11 for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:22 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0CAAD1FB; Fri, 29 Sep 2023 08:03:59 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A9E713F5A1; Fri, 29 Sep 2023 08:03:19 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:02:54 +0100 Subject: [PATCH v3 05/17] firmware: arm_ffa: Implement the FFA_NOTIFICATION_SET interface MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-5-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1504; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=NVitlqlRV6z20CY5oo4iFS9EKuyldYrTV9XNc0cCWyc=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucvy4pQu2saUIRdI36LiwoHG6ULgL6RfFRQi fMkLTenBjiJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnLwAKCRAAQbq8MX7i mITrEACmc38jc6FrQ9DZH7qAj0dD8/GukHrMcd5qq5SLIcbmUX61YipNeM7Kd2ppRcbWZ/xGm2Q AulqjS6eYgOY2h27Rp5bcyYpVlxp23XO9No+SELhluA0oG9uwlJXihjfG2/RbtQxbV5d0gQ59d8 Ttd797Cq5/SSIQzAl98HZfRFnTBPv/gGN7yyIA92eJis8mpuW1jJcj4vPlooG9cqkE4Eb2aoraM agoNF6JPVw+qDCNyJKNq6igaw0zHlQzrT2Hv0OFuX88eHjZb9dtGaTRJ0saCtj/GC3G4LcD89qG ekKeFQL8jxcZQHCbSbcZ4CSUsFBe+NRTiNi7bvObHMlQgjPiF7Ucy9rX36ReR7iLh5suRXBd59g iMzZK2zKs3EKXnM5W31d2iT4pKgVgvSBhkF/diAH01uAXX9x4/cVVQ8n2Ji4tPajh/R9eNOSPIy c3NAvTm09R7x6E6YYE8b1gthZ9fiCiueKuyk7Dk8NhPHzyGVJn3ECcGVgO94aiH4rQmkZhrSORs vEsxUZiHHw+rYa1UOp0hmp12I2QBFv6nfY6nDdyWKnOmR0dAPVffO2OjvAPk0Z+xTRkZtK931JS gfZwD0xyCQPB6XHe9G52fWY6Dqr5puzKz5qDATddMmVtAx1Q6kM3/10UMRYla3G6kO623MzgD3r I/j4tJUpRtZIDAg== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080321_403341_71A85E6A X-CRM114-Status: UNSURE ( 9.93 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The framework provides an interface to the sender to specify the notification to signal to the receiver. A sender signals a notification by requesting its partition manager to set the corresponding bit in the notifications bitmap of the receiver invoking FFA_NOTIFICATION_SET. Implement the FFA_NOTIFICATION_SET to enable the caller(sender) to send the notifications for any other partitions in the system. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index b265063e76ea..b0d1ddfe0230 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -616,6 +616,26 @@ static int ffa_notification_bind_common(u16 dst_id, u64 bitmap, return 0; } +static +int ffa_notification_set(u16 src_id, u16 dst_id, u32 flags, u64 bitmap) +{ + ffa_value_t ret; + u32 src_dst_ids = PACK_TARGET_INFO(dst_id, src_id); + + invoke_ffa_fn((ffa_value_t) { + .a0 = FFA_NOTIFICATION_SET, .a1 = src_dst_ids, .a2 = flags, + .a3 = NOTIFICATION_BITMAP_LOW(bitmap), + .a4 = NOTIFICATION_BITMAP_HIGH(bitmap), + }, &ret); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + else if (ret.a0 != FFA_SUCCESS) + return -EINVAL; + + return 0; +} + static int ffa_run(struct ffa_device *dev, u16 vcpu) { ffa_value_t ret; From patchwork Fri Sep 29 15:02:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404504 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83E6DE71D47 for ; Fri, 29 Sep 2023 15:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UxMzbA7TwfXIx8sqrMbR2IrJwBNGHdZx2c3eIkU2PHs=; b=mVGnY6mmEFupwe z23qAyftyDDiWj9JFuBdRuUx/kwM/BUMNNERUcGKAB1DKbaDd0/uhEPSbGC/m2LnRQkQ9Q0OmukvA KLvSmcdLG59He1JyOLxlUqwycM9kXat/pmvmYjxRcmx2qLyt2occ0/LMwxXvQnBA+FP3VXF8aJoYw BOIMai80d22PwPj1ukrQP8b8OlLD61BDwtFgqlora41ztPvqle7NMzrG8qbEbYM/9i1arnCofvi5O NKhtKu7RWF5zznQ2In1fWmuRi6yiPWsmLCZd398GE9jYpJEGHUnE6Z/dt3FfHHNdmPopcJX9E1NAC xLgFF77TL4e2fT61tJng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1n-0088PV-2c; Fri, 29 Sep 2023 15:03:39 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1Y-0088Gh-2c for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:26 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3996CDA7; Fri, 29 Sep 2023 08:04:00 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D75F33F5A1; Fri, 29 Sep 2023 08:03:20 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:02:55 +0100 Subject: [PATCH v3 06/17] firmware: arm_ffa: Implement the FFA_NOTIFICATION_GET interface MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-6-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2442; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=WcMcF7+EWspNtIEKv7vhK+PdYzYtK3Hl6T1/APp/RSo=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucv9DdfP5qDeC0S7ZKdLh/2EacPtt+fAel+o gzGvF/3OYaJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnLwAKCRAAQbq8MX7i mGymD/9pOqUOteL/bKSdzoY3NQCakLGj4XiCROjEievu5tUdHy0Zb3ttZk2FNhwO0U4GTs+zN7q JMY1pBn0Whe/TMy9uoR6QMHY6DydUrmxF8i/Xbg7acJwrYzP/EKGbHrD6nHsIzaw0fbVrZTqC5W LrCV8D0042hPxLhPqFuOrSa8Wi2xtDsE9HI0rV41qzg28H6SKgJnGLwavnGvlpsiAb9hjeNrrBC eO2ZS/vJ+VoZ10DcHBJrmOCXPVkzVM1KSd9nkazpTsP4Gg4NxFIQLNiCA24RT29pJm1F6Mz+1cZ qxPRFroeIabsRziknlj+JG2p/ezP4ZysriTfCWnUeZUIQAqxn5d1Xop+gz2dWqS5sg8ZkdHy9wa Waq9Ys3Mn/bEwq+JCFTqrN0bDJsdtsddVA/rahCLcpDrl0WoLDP1zmJlhf0JfD+JVEia/yhQ8Rn 9mWF/AJvGd8/xdy+e/iL76A+H34ZXxNZ5rP2/QmxJC3Ph2encmrjrISyXwXhuAzNwk9084Fa9ES 2rgkFA6HujhRSgn1MhgUDkGDnUJmLF57TS0LBZvuWspwiK7WEqM2G/sl2VN6ihtJIvaKqDfVSf5 dZm5IZsQJyr2LqWGDrPh+MiyyQMfHZ5qsHsD1tF2uccVe9AukepEBy0x29Bi6VSTfwjyt1PkpTd 9T/z+j/ZK2XvPBQ== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080324_939648_1835786D X-CRM114-Status: GOOD ( 11.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The framework provides an interface to the receiver to determine the identity of the notification. A receiver endpoint must use the FFA_NOTIFICATION_GET interface to retrieve its pending notifications and handle them. Add the support for FFA_NOTIFICATION_GET to allow the caller(receiver) to fetch its pending notifications from other partitions in the system. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index b0d1ddfe0230..02eedb7bc171 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -593,6 +593,14 @@ static int ffa_notification_bitmap_destroy(void) ((u32)(FIELD_GET(NOTIFICATION_HIGH_MASK, (x)))) #define NOTIFICATION_BITMAP_LOW(x) \ ((u32)(FIELD_GET(NOTIFICATION_LOW_MASK, (x)))) +#define PACK_NOTIFICATION_BITMAP(low, high) \ + (FIELD_PREP(NOTIFICATION_LOW_MASK, (low)) | \ + FIELD_PREP(NOTIFICATION_HIGH_MASK, (high))) + +#define RECEIVER_VCPU_MASK GENMASK(31, 16) +#define PACK_NOTIFICATION_GET_RECEIVER_INFO(vcpu_r, r) \ + (FIELD_PREP(RECEIVER_VCPU_MASK, (vcpu_r)) | \ + FIELD_PREP(RECEIVER_ID_MASK, (r))) static int ffa_notification_bind_common(u16 dst_id, u64 bitmap, u32 flags, bool is_bind) @@ -636,6 +644,35 @@ int ffa_notification_set(u16 src_id, u16 dst_id, u32 flags, u64 bitmap) return 0; } +struct ffa_notify_bitmaps { + u64 sp_map; + u64 vm_map; + u64 arch_map; +}; + +static int ffa_notification_get(u32 flags, struct ffa_notify_bitmaps *notify) +{ + ffa_value_t ret; + u16 src_id = drv_info->vm_id; + u16 cpu_id = smp_processor_id(); + u32 rec_vcpu_ids = PACK_NOTIFICATION_GET_RECEIVER_INFO(cpu_id, src_id); + + invoke_ffa_fn((ffa_value_t){ + .a0 = FFA_NOTIFICATION_GET, .a1 = rec_vcpu_ids, .a2 = flags, + }, &ret); + + if (ret.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)ret.a2); + else if (ret.a0 != FFA_SUCCESS) + return -EINVAL; /* Something else went wrong. */ + + notify->sp_map = PACK_NOTIFICATION_BITMAP(ret.a2, ret.a3); + notify->vm_map = PACK_NOTIFICATION_BITMAP(ret.a4, ret.a5); + notify->arch_map = PACK_NOTIFICATION_BITMAP(ret.a6, ret.a7); + + return 0; +} + static int ffa_run(struct ffa_device *dev, u16 vcpu) { ffa_value_t ret; From patchwork Fri Sep 29 15:02:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404515 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 791BFE71D47 for ; Fri, 29 Sep 2023 15:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eJYAxLXWDvjAg+/exX8StGzIXWGhVwb28ZYkvVD4qKc=; b=PFXEbJCSNK85dv xYTiFbGWBGVYzzKFIICWBCADNIbnjXnVGYEIhYAqKiehL9XwAoJwFj7k5hgQxiRt1XslDlzssgpDU 0MzLOa124+RROteq/Knjj601HiddPeTAh0MoiSAAC1unxRO8N6y1JyKtkEDsVK1x/txiTB4LGqUkr SlXOpOLOKSZwdo1njPqxYjibY79x3bjn5YkAiAS6BvMQbilaN7/Tp6gwKKtGxcuWq7vmn4Zc68LfF nsktQgtfal8A2MS/rtZZKVvSeHp+wKRYwYNjThPb3/clIYwWR6gYKtk7tAhmZAVenXBSdxpnfpiR7 N92X1j1bUUeutbX5qtgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1n-0088PA-0g; Fri, 29 Sep 2023 15:03:39 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1X-0088E3-1E for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:26 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 66FB11FB; Fri, 29 Sep 2023 08:04:01 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 103C33F5A1; Fri, 29 Sep 2023 08:03:21 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:02:56 +0100 Subject: [PATCH v3 07/17] firmware: arm_ffa: Implement the NOTIFICATION_INFO_GET interface MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-7-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3494; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=dQUQF6aKVXxeLM41f9K20i0Yq+P0jCynjIfIlm9Bp8g=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucve2qtLbbccIMHbNg0cUf8hiyVYCCGIRU/s AUdAu0DaQyJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnLwAKCRAAQbq8MX7i mL5mEACznJSiwoQJn1cxlk6mI1vNela97vgqL1j821bBPau8I9q9uEkahsMEkK8ZMejEntkD1c2 JgdvOhL3f13iNoysjiebYplIRPJF36hgRQ9fdwsv+bVL95NtRcoliH8dNvPY1ftgpuk7m/cfZbT /Yb1wzb4hklyhzCb4XW144DqTaElVUsaeTRoIIKZCWPnwXNuWgVmB2/xHfBm91m0SDz9o6w3ZD6 8IHsknrXCp5Y1ETDm9EvfTVzHgx3N8MWbBx4ijgUrIHhpLpMtpw+ooJa4Jnl2/Dnq01WUODNcVS ZjTLOkkE1gEBGjZAlrgXm8woWgAMdyjlXMlYaOl2LUmHmSGx6xKigCLvtdQoJ8cVobgY5PzlyTo VXaoLW5r6mIzMe1mOcbcJIddUTm0+a+GFyASb1ob+fCnjemXUlmMx+re2lIzi0La+Z1WLSQlgTj fpXAdk74k0xCEjY7oVPlB4Kbn4hgRatx7Fr6QGuif6dNdZq9B91nK4dJxjwQUXP6ylWlPJ35/6Y W+FopXFpC9zYyOPxlCPPTWu3bTrAad4gbFUFWjg5i7LZqcQeRUmMZYDY/CAATfRwHwfy9ncUvPP wjAcBOYAbLC4+vNjcV08PNxX9UH8ExHo6oYxxvsppBx5xWaVUfiCl8FZ1cHfiZ94R8/zX9pnI9b oqr4LayRyO3Zs6g== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080323_511291_E5A0A86C X-CRM114-Status: GOOD ( 12.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The receiver’s scheduler uses the FFA_NOTIFICATION_INFO_GET interface to retrieve the list of endpoints that have pending notifications and must be run. A notification could be signaled by a sender in the secure world to a VM. The Hypervisor needs to determine which VM and vCPU (in case a per-vCPU notification is signaled) has a pending notification in this scenario. It must obtain this information through an invocation of the FFA_NOTIFICATION_INFO_GET. Add the implementation of the NOTIFICATION_INFO_GET interface and prepare to use this to handle the schedule receiver interrupt. Implementation of handling notifications will be added later. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 02eedb7bc171..dfeeb751bebe 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -602,6 +602,13 @@ static int ffa_notification_bitmap_destroy(void) (FIELD_PREP(RECEIVER_VCPU_MASK, (vcpu_r)) | \ FIELD_PREP(RECEIVER_ID_MASK, (r))) +#define NOTIFICATION_INFO_GET_MORE_PEND_MASK BIT(0) +#define NOTIFICATION_INFO_GET_ID_COUNT GENMASK(11, 7) +#define ID_LIST_MASK_64 GENMASK(51, 12) +#define ID_LIST_MASK_32 GENMASK(31, 12) +#define MAX_IDS_64 20 +#define MAX_IDS_32 10 + static int ffa_notification_bind_common(u16 dst_id, u64 bitmap, u32 flags, bool is_bind) { @@ -673,6 +680,69 @@ static int ffa_notification_get(u32 flags, struct ffa_notify_bitmaps *notify) return 0; } +static void __do_sched_recv_cb(u16 partition_id, u16 vcpu, bool is_per_vcpu) +{ + pr_err("Callback for partition 0x%x failed.\n", partition_id); +} + +static void ffa_notification_info_get(bool is_64b) +{ + int idx, list, max_ids, lists_cnt, ids_processed, ids_count[MAX_IDS_64]; + ffa_value_t ret; + u64 id_list; + + do { + invoke_ffa_fn((ffa_value_t){ + .a0 = FFA_FN_NATIVE(NOTIFICATION_INFO_GET), + }, &ret); + + if (ret.a0 != FFA_FN_NATIVE(SUCCESS)) { + if (ret.a2 != FFA_RET_NO_DATA) + pr_err("Notification Info fetch failed: 0x%lx (0x%lx)", + ret.a0, ret.a2); + return; + } + + ids_processed = 0; + lists_cnt = FIELD_GET(NOTIFICATION_INFO_GET_ID_COUNT, ret.a2); + if (is_64b) { + max_ids = MAX_IDS_64; + id_list = FIELD_GET(ID_LIST_MASK_64, ret.a2); + } else { + max_ids = MAX_IDS_32; + id_list = FIELD_GET(ID_LIST_MASK_32, ret.a2); + } + + for (idx = 0; idx < lists_cnt; idx++, id_list >>= 2) + ids_count[idx] = (id_list & 0x3) + 1; + + /* Process IDs */ + for (list = 0; list < lists_cnt; list++) { + u16 vcpu_id, part_id, *packed_id_list = (u16 *)&ret.a3; + + if (ids_processed >= max_ids - 1) + break; + + part_id = packed_id_list[++ids_processed]; + + if (!ids_count[list]) { /* Global Notification */ + __do_sched_recv_cb(part_id, 0, false); + continue; + } + + /* Per vCPU Notification */ + for (idx = 0; idx < ids_count[list]; idx++) { + if (ids_processed >= max_ids - 1) + break; + + vcpu_id = packed_id_list[++ids_processed]; + + __do_sched_recv_cb(part_id, vcpu_id, true); + } + } + } while (ret.a2 & NOTIFICATION_INFO_GET_MORE_PEND_MASK); +} + static int ffa_run(struct ffa_device *dev, u16 vcpu) { ffa_value_t ret; From patchwork Fri Sep 29 15:02:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404507 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E570FE71D40 for ; Fri, 29 Sep 2023 15:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QemGLNy2UKFLXQgepDymkIOQTcxO6Zzh+/6N2A50N1w=; b=vryWAAASaCvSku sjKUxfSYbBLQq61ROjb6s5LoXcq87M30uvNwCtqZSw/3IpSe91jJ7ZqQ+ZjdCkGs4hQKG8FZxSa2o Y+3jDpsykuTqgfmmlkWhNOaxNPLNg198KKcETOSPFN2aHkkWMXGLoESTfTb3An2MqkuDQWEbrY7Jl Uz0MeA9quxRd9JXPCmiXEjVTT5Ot2byX0xmHlcu7r0cdMvGPxcQdPi4ITQnVMnnnrOMBAZm6u0r1s /aSBZXdvSVvQH4jYSAUqcCDMbEH5othyJlDZqS5u7Wqfqo37fMaJvBDxluFwGb/6Xs41duWoUOPXK 14dxbb1e/p45xVlNQSAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1p-0088Qo-02; Fri, 29 Sep 2023 15:03:41 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1a-0088HZ-2o for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 948B91007; Fri, 29 Sep 2023 08:04:02 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3DA393F5A1; Fri, 29 Sep 2023 08:03:23 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:02:57 +0100 Subject: [PATCH v3 08/17] firmware: arm_ffa: Initial support for scheduler receiver interrupt MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-8-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7567; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=cEqV4YVf1LWm1xYaB7cZIwUpKEDLEWd8Uc3+Kj3BYQI=; b=owEBbAKT/ZANAwAIAQBBurwxfuKYAcsmYgBlFucvCcxjPXx8TBj4nbCzrmy1KuOnDdP4lGixl 6UZ6ZzDsruJAjIEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnLwAKCRAAQbq8MX7i mJWaD/ifHyJbruDUC9theNrtvo0jGb1ru5UA3xiOU0FdjmfkTlfhzrKsEIf3vD/VNiWrVIrLpeh iQD7oj49Afj2+HakhGwbMo1ML25XWx8ZA2TFScS1VISOorUwxXS0+s8Ve8krpWjQRaztztHRiQP JDjtuBIa5u9fw04zDIsPPyJE4WpAPaAv+8vjG5dzjO6caEmnJ+HJNsn2aKFeuJ4csOXa5yATwGk 8gvOk7wbJ9/PIKlU1/+UcXPWpyA3ZpBpVbaMho7X7D/142ZKGvp2L8F3YWo2Z1okmafVUbrwyNq a6hgu8//Ux/MjxiQZVHww2tpc44zqr+TeWZwCa8NVGO7bA8U6XLx9eyaZ16PigxKMXnFnCeyBzc EK451CBMexA+OmxNNLSgDsHgSzxROs0SuSo75sPoEIjg2KZ1yS9eGNVOkLBbdGUhQQHvR8FeOhf sw6NaJdPLAPqjv6dcfuM/bm155YP9GbJsl97CkXjHZuHcVGTTCkTL2pYVMsxIimUd5gWKnXOEhe BP4gcnAlQSLEe6aKPsAGEtiphMBcfQo0EO8wquHZqE45eOF7QZjVYTsZmQp4XhSYsvYfQ2zwktP syZVXcfXmPIeVpY7tsvAj62CY+Nho0TP0PJCEK0S+atI+XGQWbUTBeoBJPFJxvAqTLNOACitipc DA8CCM3Y9PMV4 X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080327_021707_2FC6890F X-CRM114-Status: GOOD ( 21.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The Framework uses the schedule receiver interrupt to inform the receiver’s scheduler that the receiver must be run to handle a pending notification. A receiver’s scheduler can obtain the description of the schedule receiver interrupt by invoking the FFA_FEATURES interface. The delivery of the physical schedule receiver interrupt from the secure state to the non-secure state depends upon the state of the interrupt controller as configured by the hypervisor. The schedule seceiver interrupt is assumed to be a SGI. The Arm GIC specification defines 16 SGIs. It recommends that they are equally divided between the non-secure and secure states. OS like Linux kernel in the non-secure state typically do not have SGIs to spare. The usage of SGIs in the secure state is however limited. It is more likely that software in the Secure world does not use all the SGIs allocated to it. It is recommended that the secure world software donates an unused SGI to the normal world for use as the schedule receiver interrupt. This implies that secure world software must configure the SGI in the GIC as a non-secure interrupt before presenting it to the normal world. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 192 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 182 insertions(+), 10 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index dfeeb751bebe..a0c80eff04c4 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -22,15 +22,20 @@ #define DRIVER_NAME "ARM FF-A" #define pr_fmt(fmt) DRIVER_NAME ": " fmt +#include #include #include +#include #include +#include #include #include #include #include +#include #include #include +#include #include #include "common.h" @@ -76,6 +81,10 @@ static inline int ffa_to_linux_errno(int errno) return -EINVAL; } +struct ffa_pcpu_irq { + struct ffa_drv_info *info; +}; + struct ffa_drv_info { u32 version; u16 vm_id; @@ -85,6 +94,12 @@ struct ffa_drv_info { void *tx_buffer; bool mem_ops_native; bool bitmap_created; + unsigned int sched_recv_irq; + unsigned int cpuhp_state; + struct ffa_pcpu_irq __percpu *irq_pcpu; + struct workqueue_struct *notif_pcpu_wq; + struct work_struct irq_work; + bool info_get_64b; }; static struct ffa_drv_info *drv_info; @@ -922,9 +937,153 @@ static void ffa_setup_partitions(void) kfree(pbuf); } +/* FFA FEATURE IDs */ +#define FFA_FEAT_NOTIFICATION_PENDING_INT (1) +#define FFA_FEAT_SCHEDULE_RECEIVER_INT (2) +#define FFA_FEAT_MANAGED_EXIT_INT (3) + +static irqreturn_t irq_handler(int irq, void *irq_data) +{ + struct ffa_pcpu_irq *pcpu = irq_data; + struct ffa_drv_info *info = pcpu->info; + + queue_work(info->notif_pcpu_wq, &info->irq_work); + + return IRQ_HANDLED; +} + +static void ffa_sched_recv_irq_work_fn(struct work_struct *work) +{ + struct ffa_drv_info *info = container_of(work, struct ffa_drv_info, + irq_work); + + ffa_notification_info_get(info->info_get_64b); +} + +static int ffa_sched_recv_irq_map(void) +{ + int ret, irq, sr_intid; + + /* The returned sr_intid is assumed to be SGI donated to NS world */ + ret = ffa_features(FFA_FEAT_SCHEDULE_RECEIVER_INT, 0, &sr_intid, NULL); + if (ret < 0) { + if (ret != -EOPNOTSUPP) + pr_err("Failed to retrieve scheduler Rx interrupt\n"); + return ret; + } + + if (acpi_disabled) { + struct of_phandle_args oirq = {}; + struct device_node *gic; + + /* Only GICv3 supported currently with the device tree */ + gic = of_find_compatible_node(NULL, NULL, "arm,gic-v3"); + if (!gic) + return -ENXIO; + + oirq.np = gic; + oirq.args_count = 1; + oirq.args[0] = sr_intid; + irq = irq_create_of_mapping(&oirq); + of_node_put(gic); +#ifdef CONFIG_ACPI + } else { + irq = acpi_register_gsi(NULL, sr_intid, ACPI_EDGE_SENSITIVE, + ACPI_ACTIVE_HIGH); +#endif + } + + if (irq <= 0) { + pr_err("Failed to create IRQ mapping!\n"); + return -ENODATA; + } + + return irq; +} + +static void ffa_sched_recv_irq_unmap(void) +{ + if (drv_info->sched_recv_irq) + irq_dispose_mapping(drv_info->sched_recv_irq); +} + +static int ffa_cpuhp_pcpu_irq_enable(unsigned int cpu) +{ + enable_percpu_irq(drv_info->sched_recv_irq, IRQ_TYPE_NONE); + return 0; +} + +static int ffa_cpuhp_pcpu_irq_disable(unsigned int cpu) +{ + disable_percpu_irq(drv_info->sched_recv_irq); + return 0; +} + +static void ffa_uninit_pcpu_irq(void) +{ + if (drv_info->cpuhp_state) + cpuhp_remove_state(drv_info->cpuhp_state); + + if (drv_info->notif_pcpu_wq) + destroy_workqueue(drv_info->notif_pcpu_wq); + + if (drv_info->sched_recv_irq) + free_percpu_irq(drv_info->sched_recv_irq, drv_info->irq_pcpu); + + if (drv_info->irq_pcpu) + free_percpu(drv_info->irq_pcpu); +} + +static int ffa_init_pcpu_irq(unsigned int irq) +{ + struct ffa_pcpu_irq __percpu *irq_pcpu; + int ret, cpu; + + irq_pcpu = alloc_percpu(struct ffa_pcpu_irq); + if (!irq_pcpu) + return -ENOMEM; + + for_each_present_cpu(cpu) + per_cpu_ptr(irq_pcpu, cpu)->info = drv_info; + + drv_info->irq_pcpu = irq_pcpu; + + ret = request_percpu_irq(irq, irq_handler, "ARM-FFA", irq_pcpu); + if (ret) { + pr_err("Error registering notification IRQ %d: %d\n", irq, ret); + return ret; + } + + INIT_WORK(&drv_info->irq_work, ffa_sched_recv_irq_work_fn); + drv_info->notif_pcpu_wq = create_workqueue("ffa_pcpu_irq_notification"); + if (!drv_info->notif_pcpu_wq) + return -EINVAL; + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "ffa/pcpu-irq:starting", + ffa_cpuhp_pcpu_irq_enable, + ffa_cpuhp_pcpu_irq_disable); + + if (ret < 0) + return ret; + + drv_info->cpuhp_state = ret; + return 0; +} + +static void ffa_notifications_cleanup(void) +{ + ffa_uninit_pcpu_irq(); + ffa_sched_recv_irq_unmap(); + + if (drv_info->bitmap_created) { + ffa_notification_bitmap_destroy(); + drv_info->bitmap_created = false; + } +} + static int ffa_notifications_setup(void) { - int ret; + int ret, irq; ret = ffa_features(FFA_NOTIFICATION_BITMAP_CREATE, 0, NULL, NULL); if (!ret) { @@ -936,15 +1095,24 @@ static int ffa_notifications_setup(void) } drv_info->bitmap_created = true; - return 0; -} + irq = ffa_sched_recv_irq_map(); + if (irq <= 0) + goto cleanup; -static void ffa_notifications_cleanup(void) -{ - if (drv_info->bitmap_created) { - ffa_notification_bitmap_destroy(); - drv_info->bitmap_created = false; - } + if (FFA_FN_NATIVE(NOTIFICATION_INFO_GET) == + FFA_FN64_NOTIFICATION_INFO_GET) + drv_info->info_get_64b = true; + + drv_info->sched_recv_irq = irq; + + ret = ffa_init_pcpu_irq(irq); + if (ret) + goto cleanup; + + return 0; +cleanup: + ffa_notifications_cleanup(); + return ret; } static int __init ffa_init(void) @@ -1002,7 +1170,11 @@ static int __init ffa_init(void) ffa_set_up_mem_ops_native_flag(); - return ffa_notifications_setup(); + ret = ffa_notifications_setup(); + if (ret) + goto free_pages; + + return 0; free_pages: if (drv_info->tx_buffer) free_pages_exact(drv_info->tx_buffer, RXTX_BUFFER_SIZE); From patchwork Fri Sep 29 15:02:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404518 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2255E71D48 for ; Fri, 29 Sep 2023 15:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=U4GRC0nX2qcT8VSNNiZmfIUD2rVTeuFaKqY63oESH4M=; b=qQJc77QNkkKYeS wdjzj/K8OrOQCComIZuD2TfQ2WoxcblH95o1Z8JL5opMQbyLnGXQKLxOROYd++smmgRAbuB6pxVoU VVvH5bbefF1y3DG0fXhBcSGcDWtkD5bP1nFZwlxXXBAHhkDlxw0IIN+mOeSu0D+jhi1QqZhv56BXO RJEZTsqc2PWmCnIaCJR7Sw0ltzx2LhtpA/98g64wfk4fOwUtX6m/OaWstyWZu5Zrr16e87a2CG9rA bhujxX64+rFqmtl/LrlSkZ/CDFIynDTScI0X1N3VJmlPLqJxPkar3t+Qbu3ofbWJ4BctjGQ/r0w4k zu3Mu/8YdRqkI+ZgOs9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1o-0088Pz-1F; Fri, 29 Sep 2023 15:03:40 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1a-0088HE-0c for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C1D761063; Fri, 29 Sep 2023 08:04:03 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6B2203F5A1; Fri, 29 Sep 2023 08:03:24 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:02:58 +0100 Subject: [PATCH v3 09/17] firmware: arm_ffa: Add schedule receiver callback mechanism MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-9-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6815; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=QTjl2nGOgYZchW93FMLg30GznbSP+X31xJeCsksgTOY=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucvtP8Igd7LIpZ/OnLROdVloX0hZBMHnKWgp +rQrd+fzceJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnLwAKCRAAQbq8MX7i mLzaD/47I2TU57DiWYGfG4LsOVQum65Qk6vaX+/RJ2Mqjwe8fHP5nynmS/L+E6ijv+ks4Y1ZwtZ jICzHYSINpp7L2ANkE8p84gMopNfwKVR23euvEGUBBHlCQDwRAHA4BGmasVm2n+AvsGWMEFKnrT TaeqNmMNa676IMmu1IltZSHw5h6C7GTiX/9UJx2zIgWNkRP+6a29P8P8NCgeyOEmAYXlLfO1AmI +PQDUvQ0cZWWTdvbtxTeGmQrbgqFy+7QuZ0RtxqOKrAWRyK4at3qofTsd970nWgHAtbxGDQgepR RBH2ACcCX/NCApIVZWI8ujAj2D1Z8K9BEfCbPf4g3PtrM1gL7ovpdIFL9mKRFQ6R2H95HJbcfx8 ip9SA+DSyolWGdZoaPzuUMW22D4pob06jjcl/YNWIzKlMIn4jI88j4XE5wZTDzv0h7V+NKPERNm l9wpP/PoLi6AAa+ry4Zie7zlDhoobTpd97pECTuHBJ6AOhh8ECR/MIRF0K24UwKtlCWT7bBIVXo wGjOSmBt8EIEkqNCjvrwIlKp+v6UvqfFg/57hI7fVonOo7Z3+0rBKOmfZRK7SxEZXfyoRoEmdLB chdcC8bIbl4uvGvu9bkd++M+xFHrC7IF56+vVb98+hGA//Qudznlksq8VkxmhNIan8OQFRLjDCS gYbDXIUu1891Xnw== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080326_322011_7F0CBD10 X-CRM114-Status: GOOD ( 19.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Enable client drivers to register a callback function that will be called when one or more notifications are pending for a target partition as part of schedule receiver interrupt handling. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 103 ++++++++++++++++++++++++++++++++++++-- include/linux/arm_ffa.h | 8 +++ 2 files changed, 108 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index a0c80eff04c4..64f9c9e713d1 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "common.h" @@ -100,6 +101,8 @@ struct ffa_drv_info { struct workqueue_struct *notif_pcpu_wq; struct work_struct irq_work; bool info_get_64b; + struct xarray partition_info; + unsigned int partition_count; }; static struct ffa_drv_info *drv_info; @@ -695,9 +698,26 @@ static int ffa_notification_get(u32 flags, struct ffa_notify_bitmaps *notify) return 0; } -static void __do_sched_recv_cb(u16 partition_id, u16 vcpu, bool is_per_vcpu) +struct ffa_dev_part_info { + ffa_sched_recv_cb callback; + void *cb_data; + rwlock_t rw_lock; +}; + +static void __do_sched_recv_cb(u16 part_id, u16 vcpu, bool is_per_vcpu) { - pr_err("Callback for partition 0x%x failed.\n", partition_id); + struct ffa_dev_part_info *partition; + ffa_sched_recv_cb callback; + void *cb_data; + + partition = xa_load(&drv_info->partition_info, part_id); + read_lock(&partition->rw_lock); + callback = partition->callback; + cb_data = partition->cb_data; + read_unlock(&partition->rw_lock); + + if (callback) + callback(vcpu, is_per_vcpu, cb_data); } static void ffa_notification_info_get(bool is_64b) @@ -851,6 +871,39 @@ static int ffa_memory_lend(struct ffa_mem_ops_args *args) return ffa_memory_ops(FFA_MEM_LEND, args); } +static int ffa_sched_recv_cb_update(u16 part_id, ffa_sched_recv_cb callback, + void *cb_data, bool is_registration) +{ + struct ffa_dev_part_info *partition; + bool cb_valid; + + partition = xa_load(&drv_info->partition_info, part_id); + write_lock(&partition->rw_lock); + + cb_valid = !!partition->callback; + if (!(is_registration ^ cb_valid)) { + write_unlock(&partition->rw_lock); + return -EINVAL; + } + + partition->callback = callback; + partition->cb_data = cb_data; + + write_unlock(&partition->rw_lock); + return 0; +} + +static int ffa_sched_recv_cb_register(struct ffa_device *dev, + ffa_sched_recv_cb cb, void *cb_data) +{ + return ffa_sched_recv_cb_update(dev->vm_id, cb, cb_data, true); +} + +static int ffa_sched_recv_cb_unregister(struct ffa_device *dev) +{ + return ffa_sched_recv_cb_update(dev->vm_id, NULL, NULL, false); +} + static const struct ffa_info_ops ffa_drv_info_ops = { .api_version_get = ffa_api_version_get, .partition_info_get = ffa_partition_info_get, @@ -871,11 +924,17 @@ static const struct ffa_cpu_ops ffa_drv_cpu_ops = { .run = ffa_run, }; +static const struct ffa_notifier_ops ffa_drv_notifier_ops = { + .sched_recv_cb_register = ffa_sched_recv_cb_register, + .sched_recv_cb_unregister = ffa_sched_recv_cb_unregister, +}; + static const struct ffa_ops ffa_drv_ops = { .info_ops = &ffa_drv_info_ops, .msg_ops = &ffa_drv_msg_ops, .mem_ops = &ffa_drv_mem_ops, .cpu_ops = &ffa_drv_cpu_ops, + .notifier_ops = &ffa_drv_notifier_ops, }; void ffa_device_match_uuid(struct ffa_device *ffa_dev, const uuid_t *uuid) @@ -906,6 +965,7 @@ static void ffa_setup_partitions(void) int count, idx; uuid_t uuid; struct ffa_device *ffa_dev; + struct ffa_dev_part_info *info; struct ffa_partition_info *pbuf, *tpbuf; count = ffa_partition_probe(&uuid_null, &pbuf); @@ -914,6 +974,7 @@ static void ffa_setup_partitions(void) return; } + xa_init(&drv_info->partition_info); for (idx = 0, tpbuf = pbuf; idx < count; idx++, tpbuf++) { import_uuid(&uuid, (u8 *)tpbuf->uuid); @@ -933,10 +994,42 @@ static void ffa_setup_partitions(void) if (drv_info->version > FFA_VERSION_1_0 && !(tpbuf->properties & FFA_PARTITION_AARCH64_EXEC)) _ffa_mode_32bit_set(ffa_dev); + + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) { + ffa_device_unregister(ffa_dev); + continue; + } + xa_store(&drv_info->partition_info, tpbuf->id, info, GFP_KERNEL); } + drv_info->partition_count = count; + kfree(pbuf); } +static void ffa_partitions_cleanup(void) +{ + struct ffa_dev_part_info **info; + int idx, count = drv_info->partition_count; + + if (!count) + return; + + info = kcalloc(count, sizeof(**info), GFP_KERNEL); + if (!info) + return; + + xa_extract(&drv_info->partition_info, (void **)info, 0, VM_ID_MASK, + count, XA_PRESENT); + + for (idx = 0; idx < count; idx++) + kfree(info[idx]); + kfree(info); + + drv_info->partition_count = 0; + xa_destroy(&drv_info->partition_info); +} + /* FFA FEATURE IDs */ #define FFA_FEAT_NOTIFICATION_PENDING_INT (1) #define FFA_FEAT_SCHEDULE_RECEIVER_INT (2) @@ -1172,9 +1265,11 @@ static int __init ffa_init(void) ret = ffa_notifications_setup(); if (ret) - goto free_pages; + goto partitions_cleanup; return 0; +partitions_cleanup: + ffa_partitions_cleanup(); free_pages: if (drv_info->tx_buffer) free_pages_exact(drv_info->tx_buffer, RXTX_BUFFER_SIZE); @@ -1190,9 +1285,11 @@ subsys_initcall(ffa_init); static void __exit ffa_exit(void) { ffa_notifications_cleanup(); + ffa_partitions_cleanup(); ffa_rxtx_unmap(drv_info->vm_id); free_pages_exact(drv_info->tx_buffer, RXTX_BUFFER_SIZE); free_pages_exact(drv_info->rx_buffer, RXTX_BUFFER_SIZE); + xa_destroy(&drv_info->partition_info); kfree(drv_info); arm_ffa_bus_exit(); } diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index 12fd134bf670..f9cf6114ef82 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -391,11 +391,19 @@ struct ffa_cpu_ops { int (*run)(struct ffa_device *dev, u16 vcpu); }; +typedef void (*ffa_sched_recv_cb)(u16 vcpu, bool is_per_vcpu, void *cb_data); +struct ffa_notifier_ops { + int (*sched_recv_cb_register)(struct ffa_device *dev, + ffa_sched_recv_cb cb, void *cb_data); + int (*sched_recv_cb_unregister)(struct ffa_device *dev); +}; + struct ffa_ops { const struct ffa_info_ops *info_ops; const struct ffa_msg_ops *msg_ops; const struct ffa_mem_ops *mem_ops; const struct ffa_cpu_ops *cpu_ops; + const struct ffa_notifier_ops *notifier_ops; }; #endif /* _LINUX_ARM_FFA_H */ From patchwork Fri Sep 29 15:02:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404505 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B0B01E71D45 for ; Fri, 29 Sep 2023 15:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GNrDDfQnBkKpfMaEfgzosKVdlJJ/YhFbURmnXZCg58I=; b=GDdjuh/gUWQz7d VhhnQV9CiLREJaJruCtRSWHKRqPqkK8/Gy4b/F2REB7l1XvAAdnkxt5ojoWyiU3AYI27cj4yLON9L tmMcpvdQne0ynSl0dnAvEfQNX/N59hu1tjTF5bS/ed2dI1TncL+4oYzvENGvBzmimCG1xM5OMy0mD jHQsj2uXB6r8j0Q+XVPygN6IkmRut774yrhMuoSpCwKxlU7CS/82F13oPqV81rr7jbhaOPcRN+QGT 7N+bQm7siKgkKDGd83x457rjWeAp6Go/MpkGbI5nDItSw7nfw8sRihTKcLXwXk+0boZyjFi9Rn6W2 gXZcoOTo6wO8HAwE83dw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1p-0088RM-1x; Fri, 29 Sep 2023 15:03:41 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1b-0088E3-0B for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EF1DE139F; Fri, 29 Sep 2023 08:04:04 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 985543F5A1; Fri, 29 Sep 2023 08:03:25 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:02:59 +0100 Subject: [PATCH v3 10/17] firmware: arm_ffa: Add interfaces to request notification callbacks MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-10-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6933; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=OABTEeQ3MAALLW9HhMJwEV1Db8srfXnLIyC117qcUAI=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucv3MQlmS7vh34so5Kxq1Y87woU7Ne8OlI2E z3hoj7GugeJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnLwAKCRAAQbq8MX7i mL76D/sFwlsLqNbOXji9IdAZdx4tXI1SvlkNcbBghOJYaA7HUI7wJ5Fpn8C+QZh7vt/L7sljIEp OV6ib4vIO0kZGBlDKzbiyz4vKux+gwE4rwetIg7w4V+ToBwdPID2ztbSPhzKu35lVlU7HUstRXK QifmXswQvY+3JygYPm81dzH0zeGKCP4YRORQpB+bnwZmwJjPhMt85g4yFAPNtLJraKfOOpAvdDj Gd/mlToVfodxMgWXPXh3wvvMDFBcaDNugTSDmzsUoJF2DAqTbjJRk8fHRctT9c/EGUBrNo+MI4+ mZxWhMcUJrcuShuDW58os/wk8++8AwNkdeXOVZRSvwBlPzhI5kkDPWY7ZEAW0+DszRQ5ZPS6Cdh tybWZUB2uZtaDMBggNhFxVdVTjsmSj9CaDy2y/Q6pR0ijO8nunCDWJg1n8dbLcw1YtB3waKu9x5 aDNH1w0/gRxlW3IcYxA5UEIbSYA9UEI1vQro/dZW+mealB3VRQgpk1l2wMq8gTcXO4zmEFas1vE 2gDRX5eZOXTB8zKt8K3fH5fzUr2wV1nA2GQ2rELBEoV2SO5RYKaxBPaVoIy9/PFt2Uq/mY5ybss 6+el2Kfa1htu6Mlpw2H5XM8ooQvIZozPjx+3va0E6gwO5bNnGUSom+cDc28x74kj0+C5O6G+j2c gHYazd5wKTyt1RQ== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080327_206589_C836B34E X-CRM114-Status: GOOD ( 18.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add interface to the FFA driver to allow for client drivers to request and relinquish a notification as well as provide a callback for the notification. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 145 ++++++++++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 5 ++ 2 files changed, 150 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 64f9c9e713d1..55707a5d333d 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -27,11 +27,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -57,6 +59,8 @@ */ #define RXTX_BUFFER_SIZE SZ_4K +#define FFA_MAX_NOTIFICATIONS 64 + static ffa_fn *invoke_ffa_fn; static const int ffa_linux_errmap[] = { @@ -103,6 +107,8 @@ struct ffa_drv_info { bool info_get_64b; struct xarray partition_info; unsigned int partition_count; + DECLARE_HASHTABLE(notifier_hash, ilog2(FFA_MAX_NOTIFICATIONS)); + struct mutex notify_lock; /* lock to protect notifier hashtable */ }; static struct ffa_drv_info *drv_info; @@ -627,6 +633,8 @@ static int ffa_notification_bitmap_destroy(void) #define MAX_IDS_64 20 #define MAX_IDS_32 10 +#define PER_VCPU_NOTIFICATION_FLAG BIT(0) + static int ffa_notification_bind_common(u16 dst_id, u64 bitmap, u32 flags, bool is_bind) { @@ -871,6 +879,21 @@ static int ffa_memory_lend(struct ffa_mem_ops_args *args) return ffa_memory_ops(FFA_MEM_LEND, args); } +#define FFA_SECURE_PARTITION_ID_FLAG BIT(15) + +enum notify_type { + NON_SECURE_VM, + SECURE_PARTITION, + FRAMEWORK, +}; + +struct notifier_cb_info { + struct hlist_node hnode; + ffa_notifier_cb cb; + void *cb_data; + enum notify_type type; +}; + static int ffa_sched_recv_cb_update(u16 part_id, ffa_sched_recv_cb callback, void *cb_data, bool is_registration) { @@ -904,6 +927,123 @@ static int ffa_sched_recv_cb_unregister(struct ffa_device *dev) return ffa_sched_recv_cb_update(dev->vm_id, NULL, NULL, false); } +static int ffa_notification_bind(u16 dst_id, u64 bitmap, u32 flags) +{ + return ffa_notification_bind_common(dst_id, bitmap, flags, true); +} + +static int ffa_notification_unbind(u16 dst_id, u64 bitmap) +{ + return ffa_notification_bind_common(dst_id, bitmap, 0, false); +} + +/* Should be called while the notify_lock is taken */ +static struct notifier_cb_info * +notifier_hash_node_get(u16 notify_id, enum notify_type type) +{ + struct notifier_cb_info *node; + + hash_for_each_possible(drv_info->notifier_hash, node, hnode, notify_id) + if (type == node->type) + return node; + + return NULL; +} + +static int +update_notifier_cb(int notify_id, enum notify_type type, ffa_notifier_cb cb, + void *cb_data, bool is_registration) +{ + struct notifier_cb_info *cb_info = NULL; + bool cb_found; + + cb_info = notifier_hash_node_get(notify_id, type); + cb_found = !!cb_info; + + if (!(is_registration ^ cb_found)) + return -EINVAL; + + if (is_registration) { + cb_info = kzalloc(sizeof(*cb_info), GFP_KERNEL); + if (!cb_info) + return -ENOMEM; + + cb_info->type = type; + cb_info->cb = cb; + cb_info->cb_data = cb_data; + + hash_add(drv_info->notifier_hash, &cb_info->hnode, notify_id); + } else { + hash_del(&cb_info->hnode); + } + + return 0; +} + +static enum notify_type ffa_notify_type_get(u16 vm_id) +{ + if (vm_id & FFA_SECURE_PARTITION_ID_FLAG) + return SECURE_PARTITION; + else + return NON_SECURE_VM; +} + +static int ffa_notify_relinquish(struct ffa_device *dev, int notify_id) +{ + int rc; + enum notify_type type = ffa_notify_type_get(dev->vm_id); + + if (notify_id >= FFA_MAX_NOTIFICATIONS) + return -EINVAL; + + mutex_lock(&drv_info->notify_lock); + + rc = update_notifier_cb(notify_id, type, NULL, NULL, false); + if (rc) { + pr_err("Could not unregister notifcation callback\n"); + mutex_unlock(&drv_info->notify_lock); + return rc; + } + + rc = ffa_notification_unbind(dev->vm_id, BIT(notify_id)); + + mutex_unlock(&drv_info->notify_lock); + + return rc; +} + +static int ffa_notify_request(struct ffa_device *dev, bool is_per_vcpu, + ffa_notifier_cb cb, void *cb_data, int notify_id) +{ + int rc; + u32 flags = 0; + enum notify_type type = ffa_notify_type_get(dev->vm_id); + + if (notify_id >= FFA_MAX_NOTIFICATIONS) + return -EINVAL; + + mutex_lock(&drv_info->notify_lock); + + if (is_per_vcpu) + flags = PER_VCPU_NOTIFICATION_FLAG; + + rc = ffa_notification_bind(dev->vm_id, BIT(notify_id), flags); + if (rc) { + mutex_unlock(&drv_info->notify_lock); + return rc; + } + + rc = update_notifier_cb(notify_id, type, cb, cb_data, true); + if (rc) { + pr_err("Failed to register callback for %d - %d\n", + notify_id, rc); + ffa_notification_unbind(dev->vm_id, BIT(notify_id)); + } + mutex_unlock(&drv_info->notify_lock); + + return rc; +} + static const struct ffa_info_ops ffa_drv_info_ops = { .api_version_get = ffa_api_version_get, .partition_info_get = ffa_partition_info_get, @@ -927,6 +1067,8 @@ static const struct ffa_cpu_ops ffa_drv_cpu_ops = { static const struct ffa_notifier_ops ffa_drv_notifier_ops = { .sched_recv_cb_register = ffa_sched_recv_cb_register, .sched_recv_cb_unregister = ffa_sched_recv_cb_unregister, + .notify_request = ffa_notify_request, + .notify_relinquish = ffa_notify_relinquish, }; static const struct ffa_ops ffa_drv_ops = { @@ -1202,6 +1344,9 @@ static int ffa_notifications_setup(void) if (ret) goto cleanup; + hash_init(drv_info->notifier_hash); + mutex_init(&drv_info->notify_lock); + return 0; cleanup: ffa_notifications_cleanup(); diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index f9cf6114ef82..fb6f388a3737 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -392,10 +392,15 @@ struct ffa_cpu_ops { }; typedef void (*ffa_sched_recv_cb)(u16 vcpu, bool is_per_vcpu, void *cb_data); +typedef void (*ffa_notifier_cb)(int notify_id, void *cb_data); + struct ffa_notifier_ops { int (*sched_recv_cb_register)(struct ffa_device *dev, ffa_sched_recv_cb cb, void *cb_data); int (*sched_recv_cb_unregister)(struct ffa_device *dev); + int (*notify_request)(struct ffa_device *dev, bool per_vcpu, + ffa_notifier_cb cb, void *cb_data, int notify_id); + int (*notify_relinquish)(struct ffa_device *dev, int notify_id); }; struct ffa_ops { From patchwork Fri Sep 29 15:03:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404502 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DD107E71D45 for ; Fri, 29 Sep 2023 15:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ntKcQPTJYsG3ektXcv4NjjM0hXzaZ1SR0JIxi0+w9kU=; b=aFTykaSkXPLY0e WXRuVM3j9Sgod6GzsBLO5sWAZMEgn2EpU2ZYlOumn+5UxIIxctoGz8OM814HurFpvKvvwGyS9ESSF AX9RZHkA0vVzpstVgU/wsjc68XvYpOgD1gns/wJQr16bt11VBmN8hKt29r6SaQ1o3ARyxmpJEyZlI giwE0w5ZblKxKBQZ5vnS+lBrNxstaNETtl38WlnYU3A8ak2DG5mu3dl+C5AgNRcyiNndf/UiNwt0I qqqstIjb65C3XpA9bpI0qcapsocx33pzXqq1LHtK+vEx6deC/4eJ24SD8xneDvaZ6q6klElxCOkyB NkJl6NVutsrwnHb86OoA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1q-0088Rx-0f; Fri, 29 Sep 2023 15:03:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1c-0088Gh-0C for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:33 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2845E1FB; Fri, 29 Sep 2023 08:04:06 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C59123F5A1; Fri, 29 Sep 2023 08:03:26 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:03:00 +0100 Subject: [PATCH v3 11/17] firmware: arm_ffa: Add interface to send a notification to a given partition MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-11-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2181; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=f4Gw9qi5dW5Ef+rKySqOZWY9UgWqEziJ+T29fyYYAJQ=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucw0qDNmU79mdBC/Sm4VFjwdP3A5KYk8XFDF lr0YD4RIgaJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnMAAKCRAAQbq8MX7i mEk5EADEAWUv/82JqDbfhVrIMI84gpGtF67+Q77nDFptg0Czw+joaWzzI78ZRTQFg3lkwfn6d82 N49R/38j+mg8mpP96clRyYmcnDs+jkCmMXEZPyrfs31rlMBMdFzILvcUZFOsHhke69LQJJHLFEb w/eqzS4FYuXiHmxsfopzHI8o9HSd7dUCrREGSegHBSd+Qub4UbjN29sQfUyUHUJOrcKkqvzCxnp 7O+D21eP//W2KUVkN7nvTf34yAl7VBVMRAf7S4W2TYn6XmFAeMnzV0T6xZcyy8p29zYqqtCUTef iLGunKeDB2sYEyUQTAuzg5TbH9faXqUd+o60UrjQPqjNE9yEfutyMlbY3IbIwVwbBgCgAtkFEDx ZGw4XTLAWKtoh3MisocU+yEFeGLAS9Luv1ANBivu5CjOzpCbbsIlIh0rG/kL0jWSwATPJ/OzIRD 7wQWzblYr6tT9f+EiswyTjVI5LbxDcuVOCWlKfo6jyMJ6pXDH89GkbPDXwfceI6sp8TJmXCV1DL dx7Hs9cLKXYKoOqNUr8nnklk/Le/GCfs+rv6QDGcHVGpSjBKosswxyMSb67+iAbGhEj0y0Ezzq+ a00K1Bvn1zDjWzRm/jrBLCki+vESjEOGUPlGsNZLJhoHAsG6oJqtK+JAkVZiSDYqmk/nJivdBTj VULpEsARIEChWwA== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080328_190284_8995904F X-CRM114-Status: GOOD ( 12.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The framework provides an interface to the sender endpoint to specify the notification to signal to the receiver endpoint. A sender signals a notification by requesting its partition manager to set the corresponding bit in the notifications bitmap of the receiver. Expose the ability to send a notification to another partition. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 13 +++++++++++++ include/linux/arm_ffa.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 55707a5d333d..94e39ee83278 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -1044,6 +1044,18 @@ static int ffa_notify_request(struct ffa_device *dev, bool is_per_vcpu, return rc; } +static int ffa_notify_send(struct ffa_device *dev, int notify_id, + bool is_per_vcpu, u16 vcpu) +{ + u32 flags = 0; + + if (is_per_vcpu) + flags |= (PER_VCPU_NOTIFICATION_FLAG | vcpu << 16); + + return ffa_notification_set(dev->vm_id, drv_info->vm_id, flags, + BIT(notify_id)); +} + static const struct ffa_info_ops ffa_drv_info_ops = { .api_version_get = ffa_api_version_get, .partition_info_get = ffa_partition_info_get, @@ -1069,6 +1081,7 @@ static const struct ffa_notifier_ops ffa_drv_notifier_ops = { .sched_recv_cb_unregister = ffa_sched_recv_cb_unregister, .notify_request = ffa_notify_request, .notify_relinquish = ffa_notify_relinquish, + .notify_send = ffa_notify_send, }; static const struct ffa_ops ffa_drv_ops = { diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index fb6f388a3737..f6df81f14b6d 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -401,6 +401,8 @@ struct ffa_notifier_ops { int (*notify_request)(struct ffa_device *dev, bool per_vcpu, ffa_notifier_cb cb, void *cb_data, int notify_id); int (*notify_relinquish)(struct ffa_device *dev, int notify_id); + int (*notify_send)(struct ffa_device *dev, int notify_id, bool per_vcpu, + u16 vcpu); }; struct ffa_ops { From patchwork Fri Sep 29 15:03:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404510 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3252E71D40 for ; Fri, 29 Sep 2023 15:04:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bHdu/KAZvWqSfh0UMAAGZFGDTNHBu46LLFPnZp51I80=; b=XRivp2pmxwEGfv +vGySnLGssz8xUPQ5RsgA2JqzCiXwSjDk4NRHdyYnYKzEnt0DY74F4RepMdOLucnZzTFOG0VyqepX /Wzhi8POBmNz7QLgNOFhPPa/1u33yQgaxdE6Pr7xqBQCxcIi18tfSLoKv/RKawTsvW5zSAhtnaKdC Ci+FvPBePO/p6SMZL1Xt4ICucYb3JsxKa6XGS/T4YM2U0oQcKi2t5LKfD0yuV6Cm9yTLhwMSosEUB JO3bTLZ8Zj/r+uwTmw+nR1VPUv/a5DejIndfjNN73kOdvJBVgfjo/IsTCEUdCzfKuJ4pnrHSKb8Fy PxNwD5ejGafw9ZooE79g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1q-0088ST-2V; Fri, 29 Sep 2023 15:03:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1e-0088HZ-0N for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:34 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 55718DA7; Fri, 29 Sep 2023 08:04:07 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F2DDE3F5A1; Fri, 29 Sep 2023 08:03:27 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:03:01 +0100 Subject: [PATCH v3 12/17] firmware: arm_ffa: Add notification handling mechanism MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-12-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4004; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=P0A5RMcFNkidNv2DNz6gtpSgVPPefciFbLXlHTbsR/M=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucwYmIkcIk2FrlNkANdeNEyh1b6LuU9cIg6j jetsf0+Ho6JAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnMAAKCRAAQbq8MX7i mJwoEACek+U4yIiIyf+5+1Vh7WX8nlg+7YdLyiDPGJYHdqU881l2wYDmoBWzUK19uCCgbFPgGXv ZUVO/jtWZHzOEC1wjgPqt5GTcWcnOt0m5H4NMoSR4AfzZ1eKTFxGRiW9tJVxFVl0NkRgxGGaP9j Q2Emlt3TD140Qd+A3VSJCzq9fj73LIaN3iDy0kk9QFxHPiU1TK8Mp1deUeJFC8l7iAFn+xWo7m5 d1yqm5NcMcxCQVF6J4gS3wiGTPHrhDPnPNHTefpTFHGK5YrNlGaq8A6S33T3PlYN5BKR+JqW7SF CADpA27cPbfNbUznDeM6Fq19FwLCrNmYIC8ZaCUMoHfDCTp4t6gL6Z55kRx+TCikMvyxgk4P6sO 1lK4Q0K8nlx42ck/2b+Y8ZFsotH7zRlRZanCTU4uIvEtyuZQcfhtXhEK3jG7Eub63YfqntyOLCv 1jgzman0nENiAQ+jfiOSIYmOM1YYzFclo9DgEOYMYSWwBCPvV9u4G/AFHmg0wk67EfGlS4+jdYU JDdM95MHp9GRpO9C9vPfq9Mn8zCPG43/ew1PrFb+8+XoRYNBgxzsOftfJ+I9UDRMdjh0d+LQxUF NdngDiMl16m67dHvft3/T6GRck9IDJPmsnk0wKMosXReNgB+CgQ6BxmfT+k6Tf+OOo7DSaX6FO1 aox1d4DkRrF8gSg== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080330_267752_C0A44058 X-CRM114-Status: GOOD ( 15.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With all the necessary plumbing in place, let us add handling the notifications as part of schedule receiver interrupt handler. In order to do so, we need to just register scheduling callback on behalf of the driver partition. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 65 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 94e39ee83278..28bf345862d9 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -103,6 +103,7 @@ struct ffa_drv_info { unsigned int cpuhp_state; struct ffa_pcpu_irq __percpu *irq_pcpu; struct workqueue_struct *notif_pcpu_wq; + struct work_struct notif_pcpu_work; struct work_struct irq_work; bool info_get_64b; struct xarray partition_info; @@ -634,6 +635,10 @@ static int ffa_notification_bitmap_destroy(void) #define MAX_IDS_32 10 #define PER_VCPU_NOTIFICATION_FLAG BIT(0) +#define SECURE_PARTITION_BITMAP BIT(0) +#define NON_SECURE_VM_BITMAP BIT(1) +#define SPM_FRAMEWORK_BITMAP BIT(2) +#define NS_HYP_FRAMEWORK_BITMAP BIT(3) static int ffa_notification_bind_common(u16 dst_id, u64 bitmap, u32 flags, bool is_bind) @@ -1056,6 +1061,54 @@ static int ffa_notify_send(struct ffa_device *dev, int notify_id, BIT(notify_id)); } +static void handle_notif_callbacks(u64 bitmap, enum notify_type type) +{ + int notify_id; + struct notifier_cb_info *cb_info = NULL; + + for (notify_id = 0; notify_id <= FFA_MAX_NOTIFICATIONS && bitmap; + notify_id++, bitmap >>= 1) { + if (!(bitmap & 1)) + continue; + + mutex_lock(&drv_info->notify_lock); + cb_info = notifier_hash_node_get(notify_id, type); + mutex_unlock(&drv_info->notify_lock); + + if (cb_info && cb_info->cb) + cb_info->cb(notify_id, cb_info->cb_data); + } +} + +static void notif_pcpu_irq_work_fn(struct work_struct *work) +{ + int rc; + struct ffa_notify_bitmaps bitmaps; + + rc = ffa_notification_get(SECURE_PARTITION_BITMAP | + SPM_FRAMEWORK_BITMAP, &bitmaps); + if (rc) { + pr_err("Failed to retrieve notifications with %d!\n", rc); + return; + } + + handle_notif_callbacks(bitmaps.vm_map, NON_SECURE_VM); + handle_notif_callbacks(bitmaps.sp_map, SECURE_PARTITION); + handle_notif_callbacks(bitmaps.arch_map, FRAMEWORK); +} + +static void +ffa_self_notif_handle(u16 vcpu, bool is_per_vcpu, void *cb_data) +{ + struct ffa_drv_info *info = cb_data; + + if (!is_per_vcpu) + notif_pcpu_irq_work_fn(&info->notif_pcpu_work); + else + queue_work_on(vcpu, info->notif_pcpu_wq, + &info->notif_pcpu_work); +} + static const struct ffa_info_ops ffa_drv_info_ops = { .api_version_get = ffa_api_version_get, .partition_info_get = ffa_partition_info_get, @@ -1160,6 +1213,13 @@ static void ffa_setup_partitions(void) drv_info->partition_count = count; kfree(pbuf); + + /* Allocate for the host */ + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return; + xa_store(&drv_info->partition_info, drv_info->vm_id, info, GFP_KERNEL); + drv_info->partition_count++; } static void ffa_partitions_cleanup(void) @@ -1303,6 +1363,7 @@ static int ffa_init_pcpu_irq(unsigned int irq) } INIT_WORK(&drv_info->irq_work, ffa_sched_recv_irq_work_fn); + INIT_WORK(&drv_info->notif_pcpu_work, notif_pcpu_irq_work_fn); drv_info->notif_pcpu_wq = create_workqueue("ffa_pcpu_irq_notification"); if (!drv_info->notif_pcpu_wq) return -EINVAL; @@ -1360,7 +1421,9 @@ static int ffa_notifications_setup(void) hash_init(drv_info->notifier_hash); mutex_init(&drv_info->notify_lock); - return 0; + /* Register internal scheduling callback */ + return ffa_sched_recv_cb_update(drv_info->vm_id, + ffa_self_notif_handle, drv_info, true); cleanup: ffa_notifications_cleanup(); return ret; From patchwork Fri Sep 29 15:03:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404514 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DA7DE71D45 for ; Fri, 29 Sep 2023 15:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dwBAy/ndwy2nBBLO8lSNuA6x/ZWdwmT0457zcYcP5HI=; b=xmOaEpxqP/b2/2 S6SpSOehU5zQ2oQdiH66fkEHzAp+DO47H872spr2CS6hohNfXSIE9UUft05BR21oTZ7FxsPobFWs0 bPZQ08rJ1XJRKow9OnmVdZM9Wy/fuCI2fCfraaDux64TX2gvqFYUgLpZDsMbVR+JCAuPnO01aayg0 G9NFmD/DIILh/zZJnOpDEfPMhw6Mg64Fat7NciXBEB+bM8lUTbVTvwK8muvq0Nllj0TzdwWMxXh+Q vqNwYUQsn0qMoefxNFVb5soup9hoK5J5M23uWgbJuTSnX9uCa2j50yIWbAxVfPtGxJDst5/O+NYvh 464LRjEGGZQcbt3z3O5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1t-0088V5-0x; Fri, 29 Sep 2023 15:03:45 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1g-0088Jv-1y for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 830451063; Fri, 29 Sep 2023 08:04:08 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2C19E3F5A1; Fri, 29 Sep 2023 08:03:29 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:03:02 +0100 Subject: [PATCH v3 13/17] firmware: arm_ffa: Simplify the computation of transmit and fragment length MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-13-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3428; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=Rg2XKzRPf8SFjG3ZX7rctW9KFXN9uruVnGqowukr10g=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucwynFFqxvHjHWr3fQpCjnPEZhI6MOOZvWa3 Vu9DXT+PxuJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnMAAKCRAAQbq8MX7i mH0vD/9TOnvx/MRuf4JrzUDS0qYwarst+XtR3YA98cDVMU8SMMO++DDxeULkEmoW+QL2OvtpWCZ 8d3lTmNKbLFKIYuhEzURoXfKBUF35MeyPXSz76xnHUEQeFVMkZIAESgR36OsOMQLTzrzc7nN9d7 tcgtQD9modOPd0+6UzVfiVtrSykcD40pt5WHe2T6VHzFTK55owf95LIU7KvC/RC2X5cEW2rmzJn oY6Ja/kPJwEG95nzOKNGthIvx1TVkUeAE8Ddmvg8OQhCxVia1W155fGXV5awZjMQsI57RhafAWt 9ddvScF4rANyVsDwrNNgs5riRWtRr0puMtoSie1jLyYKrFkCdGDnLgITtlqseAFogwpb0qgy1uD 6CmbM8mZwNS9WRr++ufKCa6Ynmvott+IWrhJ3T9HCzV//d9dTlrngYy1lyM22EBDtc84xGEVtAi Cmao8jTeECdfRKgwaQjU2Bi7+iWI46p0qKrgfJahOtmn28QGaaFq2reFTUuHqpZL6e3hrZfzuSq mB+5RROSIdq8xfLzNtuBb2VuSIIseDUEPPgsI/Vba+/SaRcmjv0VNrnzwIcXQ60nRyMDTfHF9Mh g24xJTfJaxOVji9fNnczaH9U54X4vGsenurTg3yzOhRgawrk0kpbxeTbgUGv3uRwi3J+3YMU3Pu g0MMyU22hszKPMw== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080332_742647_1555A4DF X-CRM114-Status: GOOD ( 12.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The computation of endpoint memory access descriptor's composite memory region descriptor offset is using COMPOSITE_CONSTITUENTS_OFFSET which is unnecessary complicated. Composite memory region descriptor always follow the endpoint memory access descriptor array and hence it is computed accordingly. COMPOSITE_CONSTITUENTS_OFFSET is useless and wrong for any input other than endpoint memory access descriptor count. Let us drop the usage of COMPOSITE_CONSTITUENTS_OFFSET to simplify the computation of total transmit and fragment length in the memory transactions. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 14 ++++++++------ include/linux/arm_ffa.h | 2 -- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 28bf345862d9..d9ff3ec4f1eb 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -443,23 +443,25 @@ ffa_setup_and_transmit(u32 func_id, void *buffer, u32 max_fragsize, { int rc = 0; bool first = true; + u32 composite_offset; phys_addr_t addr = 0; + struct ffa_mem_region *mem_region = buffer; struct ffa_composite_mem_region *composite; struct ffa_mem_region_addr_range *constituents; struct ffa_mem_region_attributes *ep_mem_access; - struct ffa_mem_region *mem_region = buffer; u32 idx, frag_len, length, buf_sz = 0, num_entries = sg_nents(args->sg); mem_region->tag = args->tag; mem_region->flags = args->flags; mem_region->sender_id = drv_info->vm_id; mem_region->attributes = ffa_memory_attributes_get(func_id); - ep_mem_access = &mem_region->ep_mem_access[0]; + ep_mem_access = buffer + COMPOSITE_OFFSET(0); + composite_offset = COMPOSITE_OFFSET(args->nattrs); for (idx = 0; idx < args->nattrs; idx++, ep_mem_access++) { ep_mem_access->receiver = args->attrs[idx].receiver; ep_mem_access->attrs = args->attrs[idx].attrs; - ep_mem_access->composite_off = COMPOSITE_OFFSET(args->nattrs); + ep_mem_access->composite_off = composite_offset; ep_mem_access->flag = 0; ep_mem_access->reserved = 0; } @@ -468,13 +470,13 @@ ffa_setup_and_transmit(u32 func_id, void *buffer, u32 max_fragsize, mem_region->reserved_1 = 0; mem_region->ep_count = args->nattrs; - composite = buffer + COMPOSITE_OFFSET(args->nattrs); + composite = buffer + composite_offset; composite->total_pg_cnt = ffa_get_num_pages_sg(args->sg); composite->addr_range_cnt = num_entries; composite->reserved = 0; - length = COMPOSITE_CONSTITUENTS_OFFSET(args->nattrs, num_entries); - frag_len = COMPOSITE_CONSTITUENTS_OFFSET(args->nattrs, 0); + length = composite_offset + CONSTITUENTS_OFFSET(num_entries); + frag_len = composite_offset + CONSTITUENTS_OFFSET(0); if (frag_len > max_fragsize) return -ENXIO; diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index f6df81f14b6d..748d0a83a4bc 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -356,8 +356,6 @@ struct ffa_mem_region { (offsetof(struct ffa_mem_region, ep_mem_access[x])) #define CONSTITUENTS_OFFSET(x) \ (offsetof(struct ffa_composite_mem_region, constituents[x])) -#define COMPOSITE_CONSTITUENTS_OFFSET(x, y) \ - (COMPOSITE_OFFSET(x) + CONSTITUENTS_OFFSET(y)) struct ffa_mem_ops_args { bool use_txbuf; From patchwork Fri Sep 29 15:03:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404509 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 977F9E71D48 for ; Fri, 29 Sep 2023 15:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NxCtHc2l0Y5BT7VOx7PB/+QpJRcUjZiv9AIxQ2b2xm0=; b=EgMtS4JHhFl60F qtrMFG54LxkmgCHB3ejgAsUaZMafslvcJWM3FcH54D+sYtJzrQ51fSvMxJPQnYfn8wH9tpAGzleRN FQ+OhDsDiSz6zOgPjNqTXRL2+VKeRc+sV8IPXsIN9qeadYyKDJY4fmAaPlcOucAlT7CWOUx/wdJSW KTp+ATdTrlX/g0Hu+96ZaIaaj8GWmo7u4+4A5Ebfp/BfK5B8LUO7BTNhxOif+pA2TikDdcR/oUyS9 ZkVQFuuBk4XxMLQUXEvVaE5lAMdQGz9bRtfk4uGSmVh71jXdHXijYK0OPe81Iuhp5UdZVykjwd8Gd QXlpVR/eXSR6qlH+EZAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1t-0088Vm-36; Fri, 29 Sep 2023 15:03:45 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1g-0088Jr-1Z for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 24D60106F; Fri, 29 Sep 2023 08:04:10 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5953C3F5A1; Fri, 29 Sep 2023 08:03:30 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:03:03 +0100 Subject: [PATCH v3 14/17] KVM: arm64: FFA: Remove access of endpoint memory access descriptor array MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-14-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez Cc: Marc Zyngier , Oliver Upton , Will Deacon , Quentin Perret X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3159; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=64pcj+hQs1mQBRXTHk+OD4ILrYtlsf+Zd4SaIeIRqXs=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucwKh/Fe3GJay3phEMH0ENESU2rWfHbdYJMI ySGRC8yREeJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnMAAKCRAAQbq8MX7i mJJyD/9Q2noyk3D968ikUkQGfX8OZNm4vkic6pbl9zlMTAVy6rlNgkCcBRp20EGRHv7e8QJqHI7 mQCnJ/Jmj4EKCWzzKsb00YYxkLuPnJh6LlfuAdOpli7YBaL6yaUWT4hVXK+dbJsBzFvFu0mCPl4 pLT6oSO+0DRQbA28btZF7bH8xaUCajsqQ2wr3tiK4yQyY5kDxIWGVqDoN52w+nvki+F4JLLgR4w KA0d8ojDpffbyZD5eES1TxyLuBZL8H7GijFgco+G5C2URDJ5BRS9LtI/8tfEz6LF3TZ34hN1D0z UwzbVp+ZH3EUF/4cpcf2dniVBq2p1mdQPYmV8X18K8GCNNIFd3W2aIMNsOXAGChWnMbl6X2UTKr vCFnvY1Y3wlc3x2+c/SjEUvQqXwWBT+pVJv47/6pwg4DFSyMQ4ZOWqM+6pohVKsSxGJdJD2zVPG fs1eNYIqENGi4hLyYuZ8hzEJbetFPVrr4La9LaRtjQgGJKMDAqgYTMpob95l7sX1yTeXiwNZyV6 ihXZDcLQo3nZ5OAP22EuM5ljfJGwIDkEGvHGBtt5VMZwQpMLfD0pLJeOV7jhpUKgyCqltf6wuLV zP+TB4ndSP/J7MyWfvnp1232pQRvR9pQiDts8CnilJtB3luJrNxf800Jq6gMESJYGCgrnYqNewD GK1rKGoRX/DWBhg== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080332_622322_6345B9E7 X-CRM114-Status: GOOD ( 13.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org FF-A v1.1 removes the fixed location of endpoint memory access descriptor array within the memory transaction descriptor structure. In preparation to remove the ep_mem_access member from the ffa_mem_region structure, provide the accessor to fetch the offset and use the same in FF-A proxy implementation. The accessor take the boolean argument that indicates if the memory access descriptor versions is v1(old format) or not. Currently it is set true as FF-A proxy supports only v1.0 Cc: Marc Zyngier Cc: Oliver Upton Cc: Will Deacon Cc: Quentin Perret Signed-off-by: Sudeep Holla --- arch/arm64/kvm/hyp/nvhe/ffa.c | 8 ++++++-- include/linux/arm_ffa.h | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 6e4dba9eadef..5f956f53e6bf 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -423,6 +423,7 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id, DECLARE_REG(u32, fraglen, ctxt, 2); DECLARE_REG(u64, addr_mbz, ctxt, 3); DECLARE_REG(u32, npages_mbz, ctxt, 4); + struct ffa_mem_region_attributes *ep_mem_access; struct ffa_composite_mem_region *reg; struct ffa_mem_region *buf; u32 offset, nr_ranges; @@ -452,7 +453,8 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id, buf = hyp_buffers.tx; memcpy(buf, host_buffers.tx, fraglen); - offset = buf->ep_mem_access[0].composite_off; + ep_mem_access = (void *)buf + ffa_mem_desc_offset(buf, 0, true); + offset = ep_mem_access->composite_off; if (!offset || buf->ep_count != 1 || buf->sender_id != HOST_FFA_ID) { ret = FFA_RET_INVALID_PARAMETERS; goto out_unlock; @@ -504,6 +506,7 @@ static void do_ffa_mem_reclaim(struct arm_smccc_res *res, DECLARE_REG(u32, handle_lo, ctxt, 1); DECLARE_REG(u32, handle_hi, ctxt, 2); DECLARE_REG(u32, flags, ctxt, 3); + struct ffa_mem_region_attributes *ep_mem_access; struct ffa_composite_mem_region *reg; u32 offset, len, fraglen, fragoff; struct ffa_mem_region *buf; @@ -528,7 +531,8 @@ static void do_ffa_mem_reclaim(struct arm_smccc_res *res, len = res->a1; fraglen = res->a2; - offset = buf->ep_mem_access[0].composite_off; + ep_mem_access = (void *)buf + ffa_mem_desc_offset(buf, 0, true); + offset = ep_mem_access->composite_off; /* * We can trust the SPMD to get this right, but let's at least * check that we end up with something that doesn't look _completely_ diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index 748d0a83a4bc..7be240e37f36 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -357,6 +357,12 @@ struct ffa_mem_region { #define CONSTITUENTS_OFFSET(x) \ (offsetof(struct ffa_composite_mem_region, constituents[x])) +static inline u32 +ffa_mem_desc_offset(struct ffa_mem_region *buf, int count, bool mem_desc_v1) +{ + return COMPOSITE_OFFSET(0); +} + struct ffa_mem_ops_args { bool use_txbuf; u32 nattrs; From patchwork Fri Sep 29 15:03:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404508 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13B51E71D45 for ; Fri, 29 Sep 2023 15:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=s5qOxtx/syVkGqU0Bfj9ijfJyhHbHwELb/qQQ2pECCQ=; b=udlp5ocaBda7Vx pqRWvNEh3dP+xIjNkaKQ3IZzqVeI6sbDYtDmW5epZ1fKd8Znk4hYios1iJyuNEuV6e2UstzCGyV6u hKoiIvZ50bTwmFFHE/2VjZxJvJjnU8wkV7Zwjldv6h6pfSciCDRueTybHdUCNqVoL0TEKnQlENzUK JnJbVf2TZ6ZrZylb6lBYkP7qFISmmT3uqFqo49sZm5OseLkDjjZlb29ZsWEDXTbnvJCFde0n+wQDB qMIeKjFQyCp4b6rp0ZTrR21+Ujd3GkYK2ktkbYNGNesMj3WCBLP4l1htd7TCV/FbkKs8mGjdqxRb3 7wXTwrx20nq6dildZZkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1v-0088XF-1C; Fri, 29 Sep 2023 15:03:47 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1h-0088Gh-0z for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 521B612FC; Fri, 29 Sep 2023 08:04:11 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EF78B3F5A1; Fri, 29 Sep 2023 08:03:31 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:03:04 +0100 Subject: [PATCH v3 15/17] firmware: arm_ffa: Switch to using ffa_mem_desc_offset() accessor MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-15-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1661; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=WKIYZxRqRXASwTfRhZK26/hbt/X8NbiSbXFTeLJ2R0A=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucwmwQnsz2nnr94GhK0TUe/Jk8JcvkQITM0z Ety5uzdjVuJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnMAAKCRAAQbq8MX7i mPPID/9yCTj2U/sG/SGPGXZX1PRqK0TYhMUirlq7o4A+AUsh/+lnTThpYGVyeFIPhEbfEuwJ3r4 xJZKlx/dAhwN/F5D9Yx9D11CaqffpLne3jbRUm/swWw9ZiwTxZy4vYdp3gavKxqmWZchb/+IZY5 GvLHTwwmZs3tTmS8AO4vs6s9wAsr53vz044AqXOxcGBArDFSRVoDMq8GevIwwosL+KwolPqBD34 NQ6PzM0VNF3JEsLAIB6aP14BTMuyg0b3SLIZuFof8jNXGV8t7v9joYR2KU4bIVpI6ovEe+3ZY9b x2jbLM3K99PaCKNOTWc/LzSIs8tjrRpGAtes85HZpZ9iRJb5q+kBVI68xH1UuM7C3ULi9bYKPQU XFfp2FqKzMU9mKNI2JyYDE1rX6OVQKn7bnQ1+ha8ZL0eOQB+Bj/XJ8plh+DsfgownGTs7oNyjIF knjtTxRZq0msn/kVdG5ohwumM3OAMhRRJsi48kLZLHLMEyv/HGHY8v8MeGn337swMn2MRUv4Epk s+cmPCIEkscIGZdteeJoEns6miKAcJjytJRUMJoTb9h3d7664+OwYhG4WBw1EnnuTyK757xV3DY 7BBZnkc+2xVdd0QNPQy3Wk5+1a4qeQPDwsd9G6zVKUb04gYVHGDWeBvd97wmvklKWSIdBD6Ud4/ QSorGiA03tjiZWA== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080333_390656_C4885781 X-CRM114-Status: GOOD ( 11.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In preparation to add support to the new memory transaction descriptor, the ep_mem_access member needs to be removed and hence even the macro COMPOSITE_OFFSET(). Let us switch to using the new ffa_mem_desc_offset() accessor in ffa_setup_and_transmit(). This will enable adding the support for new format transparently without any changes here again. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index d9ff3ec4f1eb..ef7011c86d60 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -449,14 +449,15 @@ ffa_setup_and_transmit(u32 func_id, void *buffer, u32 max_fragsize, struct ffa_composite_mem_region *composite; struct ffa_mem_region_addr_range *constituents; struct ffa_mem_region_attributes *ep_mem_access; + bool mdesc_v1 = drv_info->version <= FFA_VERSION_1_0; u32 idx, frag_len, length, buf_sz = 0, num_entries = sg_nents(args->sg); mem_region->tag = args->tag; mem_region->flags = args->flags; mem_region->sender_id = drv_info->vm_id; mem_region->attributes = ffa_memory_attributes_get(func_id); - ep_mem_access = buffer + COMPOSITE_OFFSET(0); - composite_offset = COMPOSITE_OFFSET(args->nattrs); + ep_mem_access = buffer + ffa_mem_desc_offset(buffer, 0, mdesc_v1); + composite_offset = ffa_mem_desc_offset(buffer, args->nattrs, mdesc_v1); for (idx = 0; idx < args->nattrs; idx++, ep_mem_access++) { ep_mem_access->receiver = args->attrs[idx].receiver; From patchwork Fri Sep 29 15:03:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404519 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 89D4CE71D46 for ; Fri, 29 Sep 2023 15:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eqlLHAVStixEwzmblEt/1CSC0kpAu/mJy1VwSJlzv1E=; b=yqpDbClFMhsRGI Sk+/tVnC4cm76SvhtKf/4O5E41LG+7/oZUNDzcS2/oxWIs42NfsMc0MCAT0RCL1ziiXZHa94xCKpG i9AOdvGP8QI0yISudF93yp7nj5mldbZ/vF2K2JtvPOI3XexhX2xjKIpXu+oL4Qd9SpmUedjviSG5P pWgnhbbuVrW+lohOL00efrNnfVuQDO/Xf+MkqY8wRODj8rJoO/K0TACT5jEuaWfBve7t90gBxHPSO lwHFfkN0DcABYf3LgcDuYJE8wDTnsZzOzI3klfsJH6UwtEYFqp8YvnNkn8QuF06NjmQOHq9Jpdb2I txjVzYpi8FnjYpeB7t+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1u-0088WT-2R; Fri, 29 Sep 2023 15:03:46 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1i-0088Kv-1v for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7F4AA1FB; Fri, 29 Sep 2023 08:04:12 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2884C3F5A1; Fri, 29 Sep 2023 08:03:33 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:03:05 +0100 Subject: [PATCH v3 16/17] firmware: arm_ffa: Update memory descriptor to support v1.1 format MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-16-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4081; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=WhdrDVZNbm/z1aM3IcsKqTU6ZT3SC2M0eEn3tH9qkZc=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucwbXjAQ8dzp00ZxFqLBv0AqMokTo704J+fB rmuIA6oMUWJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnMAAKCRAAQbq8MX7i mBMUEACmH/uqQzGyBRet5JKTbwTcgVI1Vo2373bNgX4uPpmlDE4Oyfy+ai6exmpC4duHMn5NjWy i42VWuu5z2HlnqrcSUiVglmYkyKzLygQeslDAAZOn6vXpnu07OCRUm/F/JS9H44XQPLEegaYMKw Y7aFIyEIKe9Uqx+9VOAJ0P7HElKSxc5rq3sd8TI9OMfhgW7hNf5o4/0E9qaL0AUhtlM+TOAAKvk VgERES5cvrmMCvrB0wzrwDwe/+V9gIBPkVziTJtWHAwn9sGGS66DWfSOFTxcfjVaJIJ+jkpWbfd KYCNr3KA4RkzhW3ZigXoqoz1oi/iT0uvkayAfCa9VSmr00sXXmV5YUNuOctmTQQ87jqF5iekLvW 0ELWwJIj4Hl+f5ExhN6YTOYFpDBFgreJvHjCWbd41gBOg578VNODsKR2teY+VaJoXgUDhqQEr0T yqz5NcyQ+CorJBGlHdAnv0RVkXvXf5EorbzZM8RHAiHDPUg7D6ggpa/2Bb2WqMYy5xfWWgzLLM1 KF9tdwtKVjXA4HtBsSsqBIx3YbDroWv+dng6o8gUxjTpebBI8aONSt7j9WXBaJWmttINxcjhFi5 gSn3EwpPWAy6JevYs5nPGl+XxuILkJHTVw1aPev7xiH5WHhpFpOl1YXrAiHc7Dyigcf5EnmculJ p3Pf60Ckmccnwqg== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080334_746120_1E4780F7 X-CRM114-Status: GOOD ( 17.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Update memory transaction descriptor structure to accommodate couple of new entries in v1.1 which were previously marked reserved and MBZ(must be zero). It also removes the flexible array member ep_mem_access in the memory transaction descriptor structure as it need not be at fixed offset. Also update ffa_mem_desc_offset() accessor to handle both old and new formats of memory transaction descriptors. The updates ffa_mem_region structure aligns with new format in v1.1 and hence the driver/user must take care not to use members beyond and including ep_mem_offset when using the old format. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 11 ++++++++--- include/linux/arm_ffa.h | 32 +++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index ef7011c86d60..0168e69c495d 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -424,7 +424,7 @@ static u32 ffa_get_num_pages_sg(struct scatterlist *sg) return num_pages; } -static u8 ffa_memory_attributes_get(u32 func_id) +static u16 ffa_memory_attributes_get(u32 func_id) { /* * For the memory lend or donate operation, if the receiver is a PE or @@ -467,9 +467,14 @@ ffa_setup_and_transmit(u32 func_id, void *buffer, u32 max_fragsize, ep_mem_access->reserved = 0; } mem_region->handle = 0; - mem_region->reserved_0 = 0; - mem_region->reserved_1 = 0; mem_region->ep_count = args->nattrs; + if (mdesc_v1) { + mem_region->ep_mem_size = 0; + } else { + mem_region->ep_mem_size = sizeof(*ep_mem_access); + mem_region->ep_mem_offset = sizeof(*mem_region); + memset(mem_region->reserved, 0, 12); + } composite = buffer + composite_offset; composite->total_pg_cnt = ffa_get_num_pages_sg(args->sg); diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index 7be240e37f36..f3adba0ef6c6 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -298,8 +298,8 @@ struct ffa_mem_region { #define FFA_MEM_NON_SHAREABLE (0) #define FFA_MEM_OUTER_SHAREABLE (2) #define FFA_MEM_INNER_SHAREABLE (3) - u8 attributes; - u8 reserved_0; + /* Memory region attributes, upper byte MBZ pre v1.1 */ + u16 attributes; /* * Clear memory region contents after unmapping it from the sender and * before mapping it for any receiver. @@ -337,30 +337,40 @@ struct ffa_mem_region { * memory region. */ u64 tag; - u32 reserved_1; + /* Size of each endpoint memory access descriptor, MBZ pre v1.1 */ + u32 ep_mem_size; /* * The number of `ffa_mem_region_attributes` entries included in this * transaction. */ u32 ep_count; /* - * An array of endpoint memory access descriptors. - * Each one specifies a memory region offset, an endpoint and the - * attributes with which this memory region should be mapped in that - * endpoint's page table. + * 16-byte aligned offset from the base address of this descriptor + * to the first element of the endpoint memory access descriptor array + * Valid only from v1.1 */ - struct ffa_mem_region_attributes ep_mem_access[]; + u32 ep_mem_offset; + /* MBZ, valid only from v1.1 */ + u32 reserved[3]; }; -#define COMPOSITE_OFFSET(x) \ - (offsetof(struct ffa_mem_region, ep_mem_access[x])) #define CONSTITUENTS_OFFSET(x) \ (offsetof(struct ffa_composite_mem_region, constituents[x])) static inline u32 ffa_mem_desc_offset(struct ffa_mem_region *buf, int count, bool mem_desc_v1) { - return COMPOSITE_OFFSET(0); + u32 offset = count * sizeof(struct ffa_mem_region_attributes); + /* + * Earlier to v1.1, the endpoint memory descriptor array started at + * offset 32(i.e. offset of ep_mem_offset itself) + */ + if (mem_desc_v1) + offset += offsetof(struct ffa_mem_region, ep_mem_offset); + else + offset += sizeof(struct ffa_mem_region); + + return offset; } struct ffa_mem_ops_args { From patchwork Fri Sep 29 15:03:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13404506 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45A2AE71D46 for ; Fri, 29 Sep 2023 15:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aN7SujWJ6i+x5d4Wi52H54N0NfVEOPbfnACsAJVi4Cg=; b=wECPnWLpNRu8HR cZQ5vX2Bd1PDuCLRP45M3nXPsbUKMZ7bnBnPi+XakUNXBKGk79zWTwat5N7W0SMbIq6Q5c+9aX+i0 dTE5w0wZRx97i6SrEt/LqzysDmaqhIRWQEL+GP9yLrUsQdtW+0qTxmuO7WaHhqv/JeG9S47Do6vUe wJNr1EKwEuAGmR0xb8XGAn3q+jKJF+wbOcFtJm/lnqAHok8DnYaLsKyDKw0Y6ess5bLNnCwly2BAj D1SiIZKzskhb4wfVQVf3i5RJ9ZkX4caOHHMOnfR38A/X8LSNQEGQwwjoM7wV8pIpD5jALg2gqRio2 mxmGT4oeR+qP7HmXuwMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1s-0088UK-28; Fri, 29 Sep 2023 15:03:44 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qmF1j-0088HZ-1n for linux-arm-kernel@lists.infradead.org; Fri, 29 Sep 2023 15:03:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AC47EDA7; Fri, 29 Sep 2023 08:04:13 -0700 (PDT) Received: from e103737-lin.cambridge.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 55A5E3F5A1; Fri, 29 Sep 2023 08:03:34 -0700 (PDT) From: Sudeep Holla Date: Fri, 29 Sep 2023 16:03:06 +0100 Subject: [PATCH v3 17/17] firmware: arm_ffa: Upgrade the driver version to v1.1 MIME-Version: 1.0 Message-Id: <20230929-ffa_v1-1_notif-v3-17-c8e4f15190c8@arm.com> References: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> In-Reply-To: <20230929-ffa_v1-1_notif-v3-0-c8e4f15190c8@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sudeep Holla , Marc Bonnici , Jens Wiklander , Coboy Chen , Lorenzo Pieralisi , Olivier Deprez X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=687; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=Xm+5FQuOK8ltFjmVMKkQ+PdVAQzeFkX0aF6wk6FDOU0=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlFucxGzAT4dtPyO2lxZI7phiqRwrHuueWtGUs8 eFRbadMVFWJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZRbnMQAKCRAAQbq8MX7i mO0MD/0QyHmOb8sV3V0Lb9aSY63l2HnDx4ye1U5oX7byMSasGabyYpk3cw50aYeKQvtEZhS7xfm Q43V8PYqoUOlaO36fMHcKOLd9F099mOjConyL3D3iMx80HQ3ZObWJtIQZW2i5bfeA/1rHpYgT3Q wfYD5O57fXo2h3Sowfez4r+hgQU44qIySiwBKqf9RX/+YScjbl7uOr1l6kWkaoOn7EO3mAl5szF 0Ejm09ReyqcCq4IoQToT1jd/drs+PBZjID8AQk9I1sGOjwTqnpxqtedU2Yu0J7vvkvJ0YPH951M NCwiajsv43RKWDXk8hTw+s4vdnBKpZFhylt+eNszjkVqRiKwZdUhMNDaCvjjrwU1E6QGKJCCPS1 +5HkuL+91d2hdJ6XJ/kxwzH01cnxIJlUch2uq4fDnU7/T8q1aaockAuqv6A+2qmQD8nqQhgeKYx byBdoChwkIfQjilwuY9zN3cqnH8opvSfqValQlYQVGvy2JHymglxD4NABkqirdLwvB1jwl7Gmfq tH7SDYUMjeuvz8mp4B/3C+tTYpnR5SluVnU4IFDs+DhRPMBNADFscKgRdmtaxbmZsJbNi08gFuL hdWO1rQn6Hn312S3CAM7tMFulJHzM++KmLTF30lUFuhsMSgftNvuRIuEa8miv5UW6lQV1AVr02o 5/CLChj1D65pywA== X-Developer-Key: i=sudeep.holla@arm.com; a=openpgp; fpr=7360A21742ADF5A11767C1C139CFD4755FE2D5B4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230929_080335_644752_1C2E9812 X-CRM114-Status: UNSURE ( 9.84 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With quite a few v1.1 features supported, we can bump the driver version to v1.1 now. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 0168e69c495d..e9c6282d750c 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -43,7 +43,7 @@ #include "common.h" -#define FFA_DRIVER_VERSION FFA_VERSION_1_0 +#define FFA_DRIVER_VERSION FFA_VERSION_1_1 #define FFA_MIN_VERSION FFA_VERSION_1_0 #define SENDER_ID_MASK GENMASK(31, 16)