From patchwork Thu Oct 5 14:44: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: 13410153 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 4408DE92706 for ; Thu, 5 Oct 2023 14:45:44 +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=1gH5ZMApGK0LDe+sNo3J19eyucKGNZo+h3k9LIjuqhw=; b=zYkEVrChTgx4iH 84KK4Q/vYeo4DG4Qkc86tgE4kWesj18910qg8OsKaPR5hnDwotFrqDcjFSV0IgiWaM73kYA1fNKFl F/ToTgnZ39hmc6g6tC6pe6GKHF0RdO4NKVj6ltV9mw91OevTAbcOyJI7/iJ7KBGj8ptoeOKxmlCPl twcL3sBNJ1C4wfVtZBBekq1DN7+5N8W7tqAa3ce1GXsVNoes+k+htmB7/010m5Yv2jMtLLd9FSmTA m9eMpwMOlgCYQcrPHL9UgiqXTcsc2lNJ30oR1nFYU9vaMMGfUsKoIwJzpZiKoRMvSvCpReJj1NPkj 86s1bDOR8FZ6SI0J7Y4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbH-003lb5-2U; Thu, 05 Oct 2023 14:45:15 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbE-003lZf-0a for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45:13 +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 B3951DA7; Thu, 5 Oct 2023 07:45:48 -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 099FA3F641; Thu, 5 Oct 2023 07:45:08 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:44:54 +0100 Subject: [PATCH v4 01/17] firmware: arm_ffa: Update the FF-A command list with v1.1 additions MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-1-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=3114; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=278KahauozE45XUUmHl11QnvUebKx7Dm6zTUaEvv3Cs=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvwExh2e02foBJMzeMrAazRi+haUyLVwCFry sj7SSL7VMWJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8AAKCRAAQbq8MX7i mMeED/4pLumUe+LTTAquMVWC2OYtNXXQuLnLgaiSrgDLjpPeCYpasHYXpdF6zFoqoExrlcgrGFp gkByGXQSVkqoDUz4nilUhFkxHbVuLqyZ1z604MEe5xJkUDd1OXodi/gP53BfHKU81GzddyzHey0 JaICJRZqPdChQV2sOXbwraD9LffsenQCB6tbu2GvZ6b+b/QENbErv+gIw8dOj0X9yitqJOmTPge 3JVsxo8alTbZl6Z9Mn8JOQxt1JsLw4BsNCnShWXR+tBKX2wIpIEUXyx1ItzApPqbMiqFc8GZZEn ZLcY7qwpDU6FvfrSf41pTpc/Ql+iSosMdup7Z5Qe1FUVMgpWtR7F9dFQ/+XmOYaQibkyygUhJOa cXl5DCthQ6kGxbrtABxpDNfC/B7uE71gLxpQjwAr4bkOxPcVvYg8S5ndxlBvWBrbiqCNQ1nEMSG trn/8ofng02cTJqQyrlLS0vYF0Mwl3HfaivO7n0S/BgGQR1KeKNR38IaDKS/G22sYGUyE0bBLwT Yj515gl2lFlLYCEebRc9VcUhQuI+FSgfXDAG0CwPY/2kglmaHfAO2HeZS+gFz9OFhRrE/R451Hm oym3CG+WkD0iSxY87/WZq3VWdUogn2+F0W2WOfMfHQyXV+I/R4pLrOaret/D2Zh+1sevtSxVQMA hJPBFpxiyt0IUbQ== 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-20231005_074512_265091_30C014A1 X-CRM114-Status: GOOD ( 10.74 ) 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 | 1 + include/linux/arm_ffa.h | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 7cd6b1564e80..a64512388ea5 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) 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 Thu Oct 5 14:44:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13410152 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 450EDE92705 for ; Thu, 5 Oct 2023 14:45:41 +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=02LsSWQeDaS1FMxuYyEryNlwHcPoPd2XJ924xRMFTsM=; b=IO0Qwd4chQP/2P a1UsAswjsMLMKIGkTU/YW2Zc/J1A7QCo6QFmwqHfQYqOUCY0Pczl8CwDRQ0n9olOsVVFNAQSVoorb i1a2i7+rwJQEjIwsKShZUarrEekcFhtTzorRWzhjHlQdgFE+dTMH/UA0dA0x/mL3S7DCUHGIoH5Tk pvBUqhuKv8QhlSOW2XKxPsSVuTmM2oRMe+gmLsSkcCTfDke1K4ehzPPDxIzwKTK+8v7IhAEG60L1u oXbfD4GpUh075lpRf1hOlzjBphO7RuwMQXwun/M677Qqwfzk1FGjd53DdFKZ4R83YIw/QH0lE7xBe nBTmcdsJihbXhuALTJrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbI-003lbW-16; Thu, 05 Oct 2023 14:45:16 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbE-003lZi-0a for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45:13 +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 E58FD139F; Thu, 5 Oct 2023 07:45:49 -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 3B6EE3F641; Thu, 5 Oct 2023 07:45:10 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:44:55 +0100 Subject: [PATCH v4 02/17] firmware: arm_ffa: Implement notification bitmap create and destroy interfaces MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-2-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=3477; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=uUL2ZAphmbDP68h5pYnBIMj7pjeetUE+/DHcD8KcBDo=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvwJYa5tKnQfZaTKhzLY4WPPK31PNv/mf0ul VCCjuqGifWJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8AAKCRAAQbq8MX7i mIqlD/9ZEzkQ5vVuCRL2ahSlui8c006jtP9sHnonqbqj/uQI25nWgyFlpfjkONGVjuCMTyUxRWu xPfCEn94+9Nx50JUjhdjNc9lCj3k8PvmC0kPUGwP96/dA4nNBdeYQmENzZNAnTMdDmj42UsCr7D /uBP0aJtAoA1lT2tLSqmsRx0ACpfaysMnTu/D+G4ZHuqNhzPXHiW+bE3EJm2lWc+yLY7UttbGGI vEUFMRS6Iz3/H5CJeDNSmvB94k6cnvNXEWdQeuL+cVAiiQLnls8iQ2ZLgqVVxjJlwHZ9C1Ol83D /voSUdLmKmDyfFcqxQR/VsZGakRzJKhgHgsqNYETj3VcVLBGvbKimPHA/QXXGejKWaRKtdb1M2d 64QcsZkswWyn0Vfz/Ku/ImS0Bt6teVWNbP6Yt7Edi+whd9/b3AmfUSY6WD3N55nrfD4W6FJwP0b EunSKSrbY9qbWhzejMYfZS+vRZnVxLu7/Su1ZJEtVEjPLH+Fcpg2G7ffClOyyRswQtBvL14hXzJ R2ca4WEMv1PAzoWFn6gik8c77a9suhCesDI9ubXm4+Y4/uU6mGDTMxalUn0DcDeN/qmha7Dmt5j uXreRXJ/pFpNCmG5vwW6+Fn2aGF5i6McW5N6lLQjbzFqbHvq/nKgVAZy+rJdR+cBAMEiZnfN7YO m82V4mWUYhJq3mQ== 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-20231005_074512_330620_879BFD97 X-CRM114-Status: GOOD ( 14.99 ) 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 | 63 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index a64512388ea5..c2ab6f4cf296 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) || @@ -704,6 +736,34 @@ 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) { + pr_err("Notifications not supported, continuing with it ..\n"); + return 0; + } + + 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; @@ -759,7 +819,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); @@ -774,6 +834,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 Thu Oct 5 14:44:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13410156 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 BE6E5E92706 for ; Thu, 5 Oct 2023 14:45:49 +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=CJWM3+wIQ9p6Adya6K98zvHx9PkODHmTgOKhucoPK8k=; b=ZzSRfN28K1Jzm7 6rlFYZVHA1lzXLWysnibTCWpZ4Wgq6kgwyggMSWYsn63Dr7v7e/FeE/Fo/Z3v0phd7pVmqXsR9E26 GSJB6o1eteB0Py7ZLHmTmDPwt5pdbu4u4e8+sEv+QNO2n2nJ2vxmlxZqS2lKDGYVyk+9NBlEWJ+eQ wirRNypz/2ZIZfw2BTR90LCLy8FR4YEC3bOeweu66Y3p6UnI+Zxy/xN9eeC8rFO1HxDDyv483M6hO bIxJloq4OAK3uQXTKMN0QeMY4Hjl2ZcFKNmtj/W+bx901caaoCwREV+a7IdG4xmFpOfhWcAylSeWk IuQdGOtwXuyUnYgHBkGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbM-003lcy-08; Thu, 05 Oct 2023 14:45: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 1qoPbF-003laI-08 for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45:14 +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 23273150C; Thu, 5 Oct 2023 07:45:51 -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 6D3DD3F641; Thu, 5 Oct 2023 07:45:11 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:44:56 +0100 Subject: [PATCH v4 03/17] firmware: arm_ffa: Implement the notification bind and unbind interface MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-3-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=tCh7LbKeNAevFd5uQSx03qEkiVl/aQEeXvD/r/UF4UU=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvwFDa1dLaZiLdaBoo+tK3/uFpNRlVXwQfJU v79YnQB7lKJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8AAKCRAAQbq8MX7i mLWQD/wLXEyJRAXmNV7481V9rRrEOHvJ36UfKSIWMkvKASOA5tN91M1Orlf6679gmfJJDBvv8SP X8CpzgeqIgLndGOcvlgUc6sKgXdT2QHLzGMqSlp1zh6NNBzuH0CCY9YjZ+CGIHBB+vWPPL47OQR VcuIKfuU9VXpea+xynjlRpwkoqgjz/YGTSL19m3GOfUW6GSzopPt0aAVibxZK7PQBGRnqYbKMcO NkgOexysE6f9G4lhGDOJfhErVsR4D3jNpMh5UZfLxCi1Jd7Ehjxo8qT2SmQQ9Kf79rwsRbGakpv j/sU7v5lEMsDfKRyJPc9QT+mGcVv4FpPNySXQDWLWk35gS7Vk1hZxkkocYP1z/6HYsJMkhCSsyJ 4mGhqnGr9KiRwMhuUNBBi4vJjI4tXqCP+QahymeH4WfnlAt4P70SMXy4TTadgIPeoloJYQQa298 TG0iIjeHhIsvuVombabM1TmrG5EGsfhwomwXxhzl6KAojYWradn5YXCbOWOfoTJXeueuxfvASH6 p/YqWegmTZ7RtKxys24QRT1RvxOnCj5phnY8nqFHrkicnZL8uiHewpV4UN6yNvPdSdEwEIP96mC jXGiYEKjH2d9OYaTf779pGMbGf6ha1eNRMyOeoa/Vq6iilHIcNcBSoqvxabFOqVMo9FFGz2/BYJ eN6H/Li3w/s+KLw== 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-20231005_074513_177268_497A73E4 X-CRM114-Status: GOOD ( 13.49 ) 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 c2ab6f4cf296..20f8f4ca8e89 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 Thu Oct 5 14:44:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13410155 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 A0694E92707 for ; Thu, 5 Oct 2023 14:45:48 +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=98M25LN/Mvo9UGlB3g3GhdlmtlaaIRcVLT0Bat/4Pl4=; b=nGprvPkkEjXBG4 qU6TdSWnJ5fGUUvkGFEm4Zc2CRaor5KN/yU8kWaMmzBXRBupQrjyHM2/CgxB02gYwKmqYL2W2o1+5 vYu79vK1lMoWOcQOkyclebKNr939M1H03WSt+qybEmiGFuRdNIake5+glhnffc6b4lao1MbS4xWF5 GmGd8WrBG43mvuqykIHIkpcNJ6QZolV+13GeVW+ACfbrzOPxvNPlIjfUP+k1UjNQ6wN+xZSa2hltv 5ZUWl8Y9ap8cSw9Rqa0vE9OKtNKdvS9yaBAfZagQKoybH59cNny6lMTVI9t+Lu5LhgFP/Ffnwo+S2 fu/5yZ+fv54JBam9DytA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbP-003lf4-1g; Thu, 05 Oct 2023 14:45:23 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbI-003lb4-07 for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45: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 54E351515; Thu, 5 Oct 2023 07:45:52 -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 9EF643F641; Thu, 5 Oct 2023 07:45:12 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:44:57 +0100 Subject: [PATCH v4 04/17] firmware: arm_ffa: Implement the FFA_RUN interface MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-4-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=PdtsxMbWHMsPxE3UREG0cqF5vyZGskCvDY/GrQFa0NE=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvw8PoKVnG2NHbjO9VKHIkzUeI3tmEoRMZG4 CcZ3zhBb9iJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8AAKCRAAQbq8MX7i mJGAD/9T3ada0rAJvvmdm4qPS7qlrINgtkmqLi3Kf2JYBUErUpdZ9bQfUD1yvZquHAA5O5ATiRu GDBcpn+mkMSOAOjQ5bmbwwSKb37jWU8zyryDMzbqUAF4bt72WWsr2nJqBeYO+gBvgNX6/A21j0V txxuE1Eai5zxYoAntxc3ND/8iEZDkHyL4lrz6KzJP6+Uny/NJngaFfCt+dFVAIot5azBIDqOSsm S5+Ae70YY1Fsh9XmTsSdlBCkgNuZZ2luTyhtDyhnZQpMlAbDh1TksFq3MshGvnWl5g6diNEx3EF BaYASOCTcWO/I2Pck5cMDkd2F+kYCUrc1c5gVa5GkMlRmFW1y9sUMXz08M98VAxyso4ADG23epZ s+5WMm+x4p2KfMXSba5EDeucauhkjWSwOZTtmz8h68H/YiveyVJv3b13GyDAUWOuaOvqyFrOeWy ca5z0JUUTmHEP5v8Jw7E6OFhsie/0uSByFsm99bjEdMAKiTBef41nweztaesSB9xvHpF2eLYjdv rUYKP0EVnUFhT7Tcj+R5PaZ1Gyj6HD+SIGGrDjVsw26gnZDLolIqu0b5lFtc2OjrC8LRd3ndkcc Z/lFQk6x8A+rsiOk0Jgp8mYUu+GE6+bAp/cJgi9H5jMtmmkDVc0UKICHlTxtH5azRoGSmRwyzrd AvR/xApIzrT8qFw== 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-20231005_074516_172084_D85BB59E X-CRM114-Status: GOOD ( 13.43 ) 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 20f8f4ca8e89..82e54d231074 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) || @@ -700,10 +717,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 Thu Oct 5 14:44: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: 13410161 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 AD8F6E92705 for ; Thu, 5 Oct 2023 14:45:53 +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=veC2vdQapp2/JEk0ay557Q9y69CECkkpJwOwnWTJdm8=; b=tDsP9QbnGnoHdm qBYdBjqCVZlysCwyrI9Qo2eReRLYorNFtT7eUdCdjlGNSquc7TB+QI6ar1Yv8pvnQOrEahIVLjGgp C4kOjpxsHJDczIa2hRnarP7d+GF+9Co+AEpjSP+RSKpxNT6/aeygQrYWAP5c4MBh0NA7I6zA2qji8 WrkXBvLOCFgAEYOFqac4jA1hsaJ/2Nl3vji4bzloYhaBb5bxFF+kjXTZCObA/xX6aVRrJx3DZ+kfe 5XCP+Ln++/9BvnACcAFuH9P5OTRIjt660MV1HUpeRwN71pLlpQCPR8aQOIqT3IUc1WkRw/a/IZRGc S1IsDU6lEbG+BgnIbqNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbO-003leX-2L; Thu, 05 Oct 2023 14:45:22 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbJ-003lbX-0F for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45: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 86B101516; Thu, 5 Oct 2023 07:45:53 -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 D0B8D3F641; Thu, 5 Oct 2023 07:45:13 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:44:58 +0100 Subject: [PATCH v4 05/17] firmware: arm_ffa: Implement the FFA_NOTIFICATION_SET interface MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-5-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=4q7IiagFj1+jcbEerM+tVmHVjhNoYEy9g+TfTOniWJY=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvxU+OC43JQZl2rh/aQ5hxCbL/2rnY6mISRn pGTv/huwB2JAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8QAKCRAAQbq8MX7i mONFD/91SNwLzgvbqoev7AcemtwFwEIcUq5ymafJb0GYsSNhSIHyE2Fc0QDnD5JgTQvF8Ww7bCa MyrtPbAxmPj+VkfD75JZmgXC7v0nVPjZ69uR+7D2kP2PxNOFiz2q0HCYkpTe6MumZGA4a+xWlrW il9Rc3Ylp2GYlRp/k4nA+JIhTSoqlqo4p+2Mzr52ESdNQrMyqiPIXM+qjcL13Tlb922K0ZfoNJd ElfDaqGRnnn/6yMZGzItAbsp3BnOXpjZtv4s1ogVe9+P+5RCwTGSrx4J1LM2lD71mQKB2ibjp2R OmErG7UrdKtHSNkfII9fiAffYeIJ++KnBX/1KWzpoRS7ssxnSy42bsi1DxKYUrbuTKLHC3brOxw 1hU8XanUC/u+SxI4ciJ+xpVxxBfdGP0aQQ65qwfgyTAKFNka9IYXK2mDCHjVg51VqEV0Mr8IlK1 VoggYkLvIFjuDM4mdGSf3Hi40v2Jvw2vNmCc05bXgg8re0mkLkdb9QgPbnmtE7y1cQeMiz8PxgL iuvKwiuOc0AFBXYA/pJlKmV3mGH47ffFqhOvSxDGcdYqIG/uh41kL6g+S381gOSz7VPfG/S4ZXS W3YPGIu6toky30eaLCxxby8VqYvn2IRsTMMcrh/6BZmuSXm27BykzpyPoIA9iDds6LVrS+okCZK +vJMXWVolUaXsHw== 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-20231005_074517_162635_B7450193 X-CRM114-Status: UNSURE ( 9.61 ) 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 82e54d231074..4edb3cb48014 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 Thu Oct 5 14:44: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: 13410162 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 3CE6AE92707 for ; Thu, 5 Oct 2023 14:45:57 +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=7ETDgLKUkhXWbsYs1UPUTz2ZN9iDqsm9Uzqp2tlFqno=; b=BfodggHJSbQR1K VQOad/cwW5cS2PWpX0NuCmVTNJ+zZp8UOBtJ9AU+0vo3Yc+wenYij3/uYYk0BUutyCTXLAfetFKPJ 3twk8S6TW1zd1Hbg66ifyvMdRc3vke8tvWLYcSK1/qp+KHrwnky4NlEyQtAGj4S0L1P7KTLmf7WxF WngxrqiEx/KTMPo2vb6JuxH/f7IF/FaU7wlmMfp8owXVJhU0NZgDZr2j1rbiu4ucJPPIPJ29j20D/ xzystWED1Ib2znpDsf8FyYEBF0QtUWpEHvwpjr4Qk9fm3WjlfXtYrUYQj+2VWIN+IO/wfRVu9WmQm g9h2vv6oR0p0l4+DOWsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbT-003lhx-1J; Thu, 05 Oct 2023 14:45:27 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbJ-003lbm-0F for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45:25 +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 B8444152B; Thu, 5 Oct 2023 07:45: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 0E3F83F641; Thu, 5 Oct 2023 07:45:14 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:44:59 +0100 Subject: [PATCH v4 06/17] firmware: arm_ffa: Implement the FFA_NOTIFICATION_GET interface MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-6-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=JcT3Ibz8prcH4LEIf0QXidGEqQ8ig8451gBfq+wr8D4=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvxvFGznmnDBqCTWy0NqxVWxtJHCRuDBexLt 2bYjTzDE3OJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8QAKCRAAQbq8MX7i mERnD/4qCvT3/HHxEq/b26JmL747hInAIaYIfi/Td6/7hwAKc2U4VIbtgn31Q0N7BZqt6uPqV1Z MsN/KoXXC80NrC7hIewgMZvSbz6Qyqd6iM1O87L/9YHjWM2tqsFAu2BP7eQqhvkJROEUYtvNeSK JVYdpJo9CwznRP91qloacnqHJlWhIT0ijwEN3zJzsRiQ5f9jPHAml3B4j6SokSNdhmqrnJqNMK5 t9/gwH2aAMbB6bOI6+fdizycB2HOu9/YLMW6JgsjhGitHgNj7q+7mZzeQ24F+vdGcvS/rAHJvTW fNFQlvLo927ZLqLRzBeSFHAv28cDK59Y2l5+2QmsDukXZwDbcf478OAqxWq6SnRTJzLvZwx9Rbx cMkupybn+cuV/Y5eOG4bh0t7txXL4ElvmELHOZrg+HlBuEwNoc6SiEi3/T2baSKSkEWpbMRBb72 hy9VECbyvs+IcizjiQopX19+J0OEMkTpkL+WFOiyJEBrnHDACfdSuGlZf44KePvCTTUyDGWKttd OTIvugwJSoRNpyLayc6QLbQWDDgl0bYO9dTeNNUZOx4HQAJldZ1dBlHF66Apewk91pfo7oQ9EAx AhnfDhPYiczjb22X6q6NU9BNIBLKQomgJuqqZaA4fXfUVSHOPP+oWsZJGPl8q0iJy5pXDrxd0ZY I+vqGuQmy4LPt+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-20231005_074517_244042_C7CCDAD7 X-CRM114-Status: GOOD ( 10.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 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 4edb3cb48014..7a0ac4f496bb 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 Thu Oct 5 14:45:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13410163 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 4F98FE92709 for ; Thu, 5 Oct 2023 14:45:59 +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=8m8ZtT0ysi7nU5vN/OqGvkW26My+Lsa+QBjNXA4BNIs=; b=NnLuMYgSiFnYCJ Riwej0yVIQEE8ykzrvCZM1Lck170gBd3pDFofiVBSWq77YFSG43MqvgiT+dXPC6olHHZrQgf8mwzT YiKd4d/H92uYA+9X9/M2SJmoRWkibxbIPqMA7/kfiRS4hotmxNfEEwuvxy60HyPN49KyuZbyTOmJK 1w6Wpsa0WslROxXV5N0B+9MV/nQFh5PRfuySV/obyl3S+MWPrhy/z84aRfzwUE3l9Xnuja+Q7Qmjc YQhXIJaY8NqfUr5mBsECSpP349oNACcv/rcORnITdd8ZIdG0cg+wvud8vqZdBybnTLrnjGYBcT4Ul yBdlTG/1i4PuGnWJLsHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbU-003ljU-20; Thu, 05 Oct 2023 14:45:28 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbK-003lcC-17 for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45:25 +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 E9B60153B; Thu, 5 Oct 2023 07:45: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 3FEBB3F641; Thu, 5 Oct 2023 07:45:16 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:45:00 +0100 Subject: [PATCH v4 07/17] firmware: arm_ffa: Implement the NOTIFICATION_INFO_GET interface MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-7-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=3589; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=CxdxAVY/MTl/iCsvKjrPq0pC+5xP2GJmZN5U5PgPO4U=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvxEQ3Lxe6D8SGBgmlxd7WIweA9a2k9e1/F8 qW6cSsYxT+JAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8QAKCRAAQbq8MX7i mCVBD/9Xn3XgDDApkwxp7KVKVIg7rGT1Sq9ths7IIjgjpfYaRJ6zeZFgdeS58z8U1QkcvWwU7Vf 3x6ZaO4qOQvFBclszikt9H58PtlFYKbt2PcYJDKCduZizKD/nOsjZvSOQJYzj4LHVJgkaSP9q5h X7dt7grFJgUOYHQYANvQ+/Ime/WfxFqvGOUppRjF43r8ULCJFm7YB+WnGvWhaKFkHDeHuSDK29o rzd1XL3DcZgRwPjyBDqxfTPyzhQkBJL9syVxjaiWDkeFvtO43kugc0S7UzvbhghsQyhvyBCZQKu SwlHDORZbwvv5kguLGz7iVG4hoatsia+GSRo+w5idN6w8BpcOqYV9E8zTs3KY13hNM7dw6dCl2s cYVjNGdJyE/8NVGbBmOaaD7LWm01HgmiA5PjRuIq1UiauwSrjr3HRXCf6oOfemPCp2psr+vH/8d cl/A3fLYh3QX+KneRzUrbahJ4KW5bTaQ99XhbLxkZH22a7zYZl+IV8MrXXTaTZ18TeXr9p3s7kx CIOnftd/qbT9XiQyB+9Tf/+0gwUWPvHNwA/oe0wT0EBzQOWggsmiQp5VoJ1mpzud8O+mIvNbSbM R4P7GNVFn7yD76gDTZk8/RD39Pqyu/qCIjyrla8bogW+DUYW7wkb2wW1tza5b0zbwNzie2vZl89 6IaQKwjmzuV/+SA== 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-20231005_074518_480247_82978B7E X-CRM114-Status: GOOD ( 12.66 ) 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 | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 7a0ac4f496bb..b1dd8539ab0d 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,72 @@ 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(void) +{ + int idx, list, max_ids, lists_cnt, ids_processed, ids_count[MAX_IDS_64]; + bool is_64b_resp; + 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) && ret.a0 != FFA_SUCCESS) { + if (ret.a2 != FFA_RET_NO_DATA) + pr_err("Notification Info fetch failed: 0x%lx (0x%lx)", + ret.a0, ret.a2); + return; + } + + is_64b_resp = (ret.a0 == FFA_FN64_SUCCESS); + + ids_processed = 0; + lists_cnt = FIELD_GET(NOTIFICATION_INFO_GET_ID_COUNT, ret.a2); + if (is_64b_resp) { + 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 Thu Oct 5 14:45:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13410165 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 AD907E92706 for ; Thu, 5 Oct 2023 14:45:57 +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=T+5YVkoOJWyhAMiG8DD4fBNDvp0bswyreik2dZNpHfY=; b=fHb+WL/CiPMJgk Ehd7acKWXo2XxNlCXZj2YQKWFzb4oh6q+l2RFTNtV8K8sCQqzDFgNHFQNZPHum1SsxaTUlhi5d9gK VZD+fxir6rzVDT9gLZD4c0QX9RAKlKUF7Eta8ITOPhKeRdXLrTCjNqAp9jyc7U/0B7GCMH/KCfbF6 38gqxsDm0Koi/5ZXwcKD9FKHlpaLU2KBpYBjfIwPTRvz1PmnmOSKhPbE2Y8uwH/wuVFTq1cccmlDn 4X/71QhDNdhzjZIyYlpaSGBlUpf6ha8a2RD9ISamazEuyVFqifmiQUAA+5xP7CTfI5+atAgiy0obU 62wkPpsAW5RRIBKD8ocQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbS-003lgz-1J; Thu, 05 Oct 2023 14:45:26 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbL-003lcW-1r for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45:24 +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 275C01570; Thu, 5 Oct 2023 07:45: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 719143F641; Thu, 5 Oct 2023 07:45:17 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:45:01 +0100 Subject: [PATCH v4 08/17] firmware: arm_ffa: Initial support for scheduler receiver interrupt MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-8-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=7668; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=yU+hWtBWbLNiVtAMPUpIWeJRLZY4AERdKc+TThgbkq8=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvxPVH0CxF7HA2KS9+I8Bsy1VybqF81R5Ap0 SepshdLeK+JAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8QAKCRAAQbq8MX7i mOFID/4yQcSmODzazuTJAo2qCM/wRZ1K9colo9iGkyq2Bvf+QlxB71uQbOiwTIUzecMhAAnawZm mdrYi2an/rCfTkPO3SUUTEeBofdZzw7HmIQ1MaFnmEAMzPg7xa9B+DRZd3u3cdvbk0ixmz3btL9 v7RB4Uf+6/aulhX6sZ6m4PpIP/sarkjLNPg7kIsJsYW1oMeQ9DcgYXVCubSRcamdb+kDH+wdwbc rzCs2/5qXsiCIvNZ7DrchAl8GZztkphtUs/scloQcVP70N/TwaO04rspoOpoiQCBaVvWlNk79mp 2ZhfoEBcb5ekI3kxnTG6ej5tRiU2yd37IqKm4rVUIraF8+LJqKJh72HSeSethCmFK0xiRz1dD+s px0VefwJn52EgylDgmgRn/DF2Y4tRfFnzRrJ38GBsRtswEyKr6JIpjKZ4ytzkzY5gLLLCkFwtIT s6t2xlculC6/zXk8Ftbce+ie/HDOitgPWjL/wvc1mM7UE/aZv7OffunAAvLDCGmwBPyLB/MeTaI 9IBqMCFQPjEx7dQPaDd+zk9sjElWRKBtNRLh68rs6U7JLZcbk4O9ifRmb3hKxDgCqAD7XfAVZPX pSPW2/ij0UD8pC3IeHiO3CdXVLxu+OlVmOcEsI88juRU21Khq11M4Lg7O52PL0Aedtj7kK1j2KL KQoTgS+6nEN3SRA== 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-20231005_074519_707447_D73DEB2A X-CRM114-Status: GOOD ( 22.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 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 | 186 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 176 insertions(+), 10 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index b1dd8539ab0d..f8d01840f5ec 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,11 @@ 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; }; static struct ffa_drv_info *drv_info; @@ -917,34 +931,182 @@ static void ffa_setup_partitions(void) kfree(pbuf); } -static int ffa_notifications_setup(void) +/* 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) { - int ret; + struct ffa_pcpu_irq *pcpu = irq_data; + struct ffa_drv_info *info = pcpu->info; - ret = ffa_features(FFA_NOTIFICATION_BITMAP_CREATE, 0, NULL, NULL); - if (ret) { - pr_err("Notifications not supported, continuing with it ..\n"); - return 0; + queue_work(info->notif_pcpu_wq, &info->irq_work); + + return IRQ_HANDLED; +} + +static void ffa_sched_recv_irq_work_fn(struct work_struct *work) +{ + ffa_notification_info_get(); +} + +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; } - ret = ffa_notification_bitmap_create(); + 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("notification_bitmap_create error %d\n", ret); + pr_err("Error registering notification IRQ %d: %d\n", irq, ret); return ret; } - drv_info->bitmap_created = true; + 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, irq; + + ret = ffa_features(FFA_NOTIFICATION_BITMAP_CREATE, 0, NULL, NULL); + if (ret) { + pr_err("Notifications not supported, continuing with it ..\n"); + return 0; + } + + ret = ffa_notification_bitmap_create(); + if (ret) { + pr_err("notification_bitmap_create error %d\n", ret); + return ret; + } + drv_info->bitmap_created = true; + + irq = ffa_sched_recv_irq_map(); + if (irq <= 0) { + ret = irq; + goto cleanup; + } + + 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) { int ret; @@ -1000,7 +1162,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 Thu Oct 5 14:45: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: 13410168 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 E5627E92710 for ; Thu, 5 Oct 2023 14:46:04 +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=uSDeld5wuKHJrkogeWwfOox+GZ04ydUKbMC1QCd4spU=; b=LRogpBQ5jUKKXy WrAncZktJcMRRYbsZUVpm+TCHY0zyQRg5KszJBjx/b2grN4KC6TYoXPpcZu723oqBi8uw+VYVpWdT XRkA6rfkmTxLk/Vk464KrvyVaiE8Ps7JYiFKt0QQjI7TSGuTGvxdfGzIPyY9iQhWJNEgF728NBHlP Iu4cB5c9ekkWkDJN6pC8Sl42oF4drnqlTiEqP71V7Bs4FH0upwnXmmCfQ7t4xTNmlzV2A8oQniYBd imtL9d8Fe7YC6nXk8P/mRmU8o0wI0or5tIehrCJvJYJZmdJdiKS813lrorynR/c64lhwYcAoFGOLl ztKigYrKYesPcahKjUrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbb-003lrd-0z; Thu, 05 Oct 2023 14:45:35 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbN-003lbX-1Q for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45: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 592F01576; Thu, 5 Oct 2023 07:45:58 -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 A34533F641; Thu, 5 Oct 2023 07:45:18 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:45:02 +0100 Subject: [PATCH v4 09/17] firmware: arm_ffa: Add schedule receiver callback mechanism MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-9-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=6827; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=gJTWJRo2bKu1EdJbiC84iwBAD0RzFSDy4pUoU0x9hq8=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvxGjQa+0sAlJhSFtCphaKPzxz2FRYB4zWti ArUgI9NfyCJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8QAKCRAAQbq8MX7i mIqHEACkL+R/tDisIKTNBsGivvSys5ySeP71mI8sLeNBNOSl8IXDls5/yWM4iOMamS7mEGF98Wn lkCU+R8ZXSFIg3J8QLHwCeHxM67MbS/eS+va18UvHwdjPpYDgSZzetVPzMD9t6MEaLlSfQtUrmm gtjTd8uFdnUtxCgGk207A0q+8o3P8TSK/r1bRbvC110s5MpxI+2bzlMYQg/QLGkHGI/1BVrd/ne vwX0dZ9pouIYLKlX7A8aHPQAnfseCQU+zKXFDdEhiCTTis5E3nrIbFDTQH9qRQodzwvFe05E2Ae u9g1/vIlCmJw+WPCUxgEII5pRILJSxT8H9U+rN0eiQ4bFq+lC8dQdqxjw9SHvZNdvDMOOsQRSpn H/vdKzn82opVDsNQROy4SkcwxsvseMAqQJkYak15cvcYcE0QsN2QqEijzI1U8DX1SDP3U2mM+Hb LpqUiefyou9gofFy/4b5ZTRtdwHiCfkd1UOfMM4jg47GTgINo0U7ZtAcPUAbdLXGrred0TIYmZ4 3f1LZBDGyvUxCSW0Vmlc1jMqexzGAAxDiJofkFVL3JuG22wrgvJyioh0DkXqqJ+YN39w6ihTI7/ iFHbu615GbRfcsksbVB7FaXFR72+4k8tPDxvs/nxTv/3k9tj8hY8/txYo28nPKPSE+OXfNi4Xzw tTjcK34TWsnJaYA== 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-20231005_074521_587861_B72B40FD X-CRM114-Status: GOOD ( 18.82 ) 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 f8d01840f5ec..04cdb49cc78b 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" @@ -99,6 +100,8 @@ struct ffa_drv_info { struct ffa_pcpu_irq __percpu *irq_pcpu; struct workqueue_struct *notif_pcpu_wq; struct work_struct irq_work; + struct xarray partition_info; + unsigned int partition_count; }; static struct ffa_drv_info *drv_info; @@ -694,9 +697,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(void) @@ -845,6 +865,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, @@ -865,11 +918,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) @@ -900,6 +959,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); @@ -908,6 +968,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); @@ -927,10 +988,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) @@ -1164,9 +1257,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); @@ -1182,9 +1277,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 Thu Oct 5 14:45: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: 13410164 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 34115E92708 for ; Thu, 5 Oct 2023 14:45:58 +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=QY5RLIL30jY+3PVwI6Q5LAJVZBTTOmYczELEBA6p08Q=; b=axt3JZttG5jKSo Dmt1JXbuRd39DY+HLKFvsLlYbAQyeNnoa39iclfKbHtgfh2UE07+VaO3bv9oM4lGhvzicclUQzH3v U7g83Oe5wsNi13a4NqpUBsEviZKTYe3ENWPkv+RnX1ek4Yikk1HU7i8bZ8jHqYwXG61rrzhaZEBUw FFW1qQWPN6Y6kOiwK5wC0zohNmQJpGsvD/0NpaNJxKTK1yquqrQ2PgY1txc4nO1yoYP16nxvHhO4Z hspTSelZPyGjCfojZSA5lozo3Fp89/HcaTj4gNCwB4b4w2tVTISUFjfyjWOWm4ABgbfpJw3VEiJOV IED1Mq0NTYEVLJrik1kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbX-003lp8-2I; Thu, 05 Oct 2023 14:45:32 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbN-003lb4-0N for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45:25 +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 8B57F1596; Thu, 5 Oct 2023 07:45: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 D53253F641; Thu, 5 Oct 2023 07:45:19 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:45:03 +0100 Subject: [PATCH v4 10/17] firmware: arm_ffa: Add interfaces to request notification callbacks MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-10-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=6943; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=jS9ZlPVRWP8/Wp7yswbAzCodeaTe0yPLbi3t5Cfh9Ag=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvxxToFsUAseBZwM6KJxyCdYs3fXrYhfoBev HCeQCsEg1mJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8QAKCRAAQbq8MX7i mNK6EACWTqIstipLTxGSmcoa6S6ckNRC7YGl/dzKaA1U1CN4NJlnY7c3ndXCz5pXlEa4dYM/qS0 jRxaMokUoAM+oTzQ7oHpHcsbwV+U94b7PZUf8LE43zwDehpCDOVZiUw+JG3P8TqWZHHvyJ1uKWi twxvwIdASgc+QLTKMBsFqccxnZaHifF4CefM40n+vllCJCxHNPJNdniQkgNdHQafj5059JAavWj //Rv28k+dZJFGRpOpjhleRQdTJzCKQljD15ayt5RgeLeiusqE3wFRak8Nlht2+DrgDzaLNQHX8o Rnf61LLiBqlGbwpa73pFUY1jbHWkhsX2KXCGUs+PvVw+Kkwun+mkzF0wmC/u4Pq1J9hxKnoR+/q rcu0UJ/bz961gkivXmEmB4rxsxgZRZHcdJvXxftpVOKft4eMWhZjmOcV7vx+//W7Q0yOHl3sMoI pex2Bh/FzNT9tHCikz7PHQEcLbNGpDmTy0O/w4HfcslvVVmORIrWb8oysRawD/Q0IOHeZJS2JQr qAYdTBJjDKZJhQ0uwJYOyF/URnhCcfE97aSQ4UhrSQ80ls54ZTnMYJR0nE3gDe5z9jB/xIJ56Oe eoNYe6U5TjkGeqs3WWmwsh3coiR2lAL3EQCD+TVYeafWSwnQk8y/2tTnnoE0nBXcd//xg/b0yCW cIMJ8icGIGdFEsg== 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-20231005_074521_268949_93026F90 X-CRM114-Status: GOOD ( 18.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 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 04cdb49cc78b..fc8b29648fb2 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[] = { @@ -102,6 +106,8 @@ struct ffa_drv_info { struct work_struct irq_work; 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; @@ -626,6 +632,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) { @@ -865,6 +873,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) { @@ -898,6 +921,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, @@ -921,6 +1061,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 = { @@ -1194,6 +1336,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 Thu Oct 5 14:45: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: 13410169 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 DBDB2E92718 for ; Thu, 5 Oct 2023 14:46:06 +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=OIbFwPvzNg7TX8FD3RqIdPSipvqzyk5oBYieFWPPTAc=; b=CxpZ+ZeBHZ6wOd zshZedDN7U0cEHcDTOLmpoOrjfgqtRQyIIIRE6hgY+h7cBMLWzmnc33zIGWRrHDvxrCVax8XjZfsW IK00lRguFV8LAYlt7Quzjk42wujDC1uxGC1sZkgMOpljJ9689bgPVP9k+zBmNNbu4MpGWKOYifRTi CauPigUuMcdLbI2Jrfe1rf2LXo5klyAN0JidrXw9SF1k2zvQCNZacEvG8YKpN9CFgggDKPlXRlNaT 4ZvnkkwRg76h+MaY0VTsmDBLOAxmYFO1r0q/4wf1xhhDzfAugVDRlAJJATWtMoy68+Vri9TOnajmZ xe2WKhy5e3GH3euhlDKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbd-003ltn-23; Thu, 05 Oct 2023 14:45: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 1qoPbP-003leR-0g for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45: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 BD3F515A1; Thu, 5 Oct 2023 07:46: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 131023F641; Thu, 5 Oct 2023 07:45:20 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:45:04 +0100 Subject: [PATCH v4 11/17] firmware: arm_ffa: Add interface to send a notification to a given partition MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-11-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=iR7xv4zWGKiCOfOTUrWKzr2y6gNM1XQTF7Jjqnppvvw=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvyUa0kf0qaS0e9Fg2dVQkQFVfR5hK3IAhDQ 3s8+Y7UIlyJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8gAKCRAAQbq8MX7i mCgED/91RGR3wwqUHgbGtWvWw4cfovaRPFwuGja8Cj4hR3egB3+yLDr+TPgjf+wHVIK/ZEs5HFw 0R+5bItjUQwwU7Y80SQYiSM9FkybAD3kZB1FBRsTl6beRCGLrJ0CklF1pPVOdF5XsSnbRLWhKx0 jBnxfrKRfPVqjsfN5Yi5f6ULO440sAzg8cg7JtIJWr90zNlP73H+zJ6vXquz6TmeCyi77JF+FST yzN+4c8CE8gJf4IhWYCbkNp/nNnNCPjGngtU1+u5h7KLbgThhnTJ8FILeuE+4wIvQo5ZsJCgG63 bhvLgyIXKeDemXY8cE7Nyjkz2P+sx+1aE5WPUTY+mFTn/3ghi1A1bQj0Ve+k2H/QCzFFNHzxtya SLhDDj8FntmyY0B4LG3jPV2AXUXUduTzRZPXHGrylpLBphhEyfFDfzFZ+zvJNGsQdSOOPGEnZqH FaAjTBLfPr5z430rzOETAznr6tmCsDwG9i+19z9Tar98vh0XO4SwrMAxqy8VffZtydzvMIsVqPK 4gVugFVckzfTH7qK/TMMsOI3slkz/eVg/3pDovmx90tjBpkDd5E5nSHTQlD5oQ3GjGEcnDWYbCV W2Q6S68e32v6eQhNtRb7Ee5LN6Q4hANzyQg8lkVcWi+i0burck21d8HG7I7T+XIFwSDbCqD4QeZ EMS66X/ci5BMM5g== 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-20231005_074523_442529_9377D6F4 X-CRM114-Status: GOOD ( 12.16 ) 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 fc8b29648fb2..2a46052a280a 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -1038,6 +1038,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, @@ -1063,6 +1075,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 Thu Oct 5 14:45: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: 13410171 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 8773CE92706 for ; Thu, 5 Oct 2023 14:46:11 +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=FobYpCYepuffpUn5RSowsTDTDMZAW/1fjYdfPseGsLg=; b=dQ2QGVTU/vKZ3m FW/ip0/YMkKz10chPhdS64FJfa11KoyUF9/FZrC9ZNnm1pkLvT2JE1ufmCdTC9CVmz74qW/VbaDWh vvSZEMntlffR3EDrgYtunxGPogmev02SSbZGDGMd2s5oIVQW6q+TbjdfJSQLlFN1rrggAHvIZz6QW lcyaoN79TESbaaYn79KOUSiHG/VmJejCCF9Ojs4H2EdKc5Y8qaig7KfrEVoCeG91ToN77tbiSVk0j lFaS7CnSeNg//pifpB0VYc/nYSdDWsFLs0Duv/jQAGXx9zm9gxtW0GxrvwsWutKXDa0/gkgKAzZgS YcbSCStH23VqcblDDKCg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbg-003lw1-13; Thu, 05 Oct 2023 14:45: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 1qoPbS-003lcC-29 for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45: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 46ABB15BF; Thu, 5 Oct 2023 07:46: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 44F8C3F641; Thu, 5 Oct 2023 07:45:22 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:45:05 +0100 Subject: [PATCH v4 12/17] firmware: arm_ffa: Add notification handling mechanism MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-12-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=4050; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=GHIh6ClSLWjbfe+dbK9XBffuB6q16AXPdqCkeJlcuXE=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvypoEExryuzL9TlqjKcrV/X62vuDwcXQGTN A+YUdxhg4qJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8gAKCRAAQbq8MX7i mDeFD/901XcmtIPEPA/bjc45RGEcElECvD2xcHIFEzydP8tYoOD68Z5I43vLBDzveQ95360VKDl wUCNdHj3d7NQ9xgrv1G/kSlyMdkt4H4DiNzIq/Z/0K6lxJD1RirhRlOUqdJQ6/MYzF5GCC29FEl XfcURhAXY2q1T6yrH8yz7N5fOfi+18MO11iKs/twtwb+6nCqznoCue4sBefC4ewqrAu/8fdh3aQ NFvgRgh2Ih1GiLUzjDO9nWDycMdMcra78eosR46uOydc3d0oOi6sus0JZUlBkU/w80cOOo1bsNk iEmkw6kMBugHB+npBBNVZgRRJKEfRIxoKjfP3LzRS8voe0KyhJdYutOF28Addnf818VFjtugfuG O+vNfJ1rSZPCXpBDFFXvMn7YK9dW6ZP5pLcgQTaHZI/njc9Sv88KQpCn99vd1GpPQB3h29lDf+j 7q3I2Ow5Dr+6I95FjWndkgBbhAPXcqttaqi7jNauOCEFsX3L8SQi+7tcthh0ZjhcsNa2pt1+PpM bIQqnPe07SMzI0aSRRwTlhvb1cVgJIINcHQy7XYLmOQw9R3sDJIOAgiDc9nkHa4GLQwSTrFNsw2 Ziq0cuX0y74ADM8wE537ofiX7S3BpGkJVAUne4Az9iUU+92cHHRC1UIOYUote06csWz8r5DFVz7 kCWTo3GBnqxNAFg== 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-20231005_074526_854298_2AE4A397 X-CRM114-Status: GOOD ( 15.56 ) 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 | 67 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 2a46052a280a..9dd5335001ee 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; struct xarray partition_info; unsigned int partition_count; @@ -633,6 +634,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) @@ -1050,6 +1055,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, @@ -1154,6 +1207,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) @@ -1294,6 +1354,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; @@ -1352,7 +1413,11 @@ static int ffa_notifications_setup(void) hash_init(drv_info->notifier_hash); mutex_init(&drv_info->notify_lock); - return 0; + /* Register internal scheduling callback */ + ret = ffa_sched_recv_cb_update(drv_info->vm_id, ffa_self_notif_handle, + drv_info, true); + if (!ret) + return ret; cleanup: ffa_notifications_cleanup(); return ret; From patchwork Thu Oct 5 14:45: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: 13410166 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 02383E9270A for ; Thu, 5 Oct 2023 14:46:01 +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=Wjci7rEF9/LoogS4XFu8OB4w62dAqnDKtqhaYvo7NFA=; b=MIblD9riA+7DNG nvQa/uCWp4V+D7ACVvj0GD2duzRf9kR/N6S/FmYyjrF0o53kIrb7E5nhUcTmSgWzbgwtJ2RM7cdk8 Jg6/Nsw1keDxEyfesWImY0IDvCWPGm+VN9g9rSbrJHUqe3/E3KTT5vn0XYeVme0uJAsT4uzSImFbh erXJHcVdbU9p5k+Q+5K/uvALRwF0tprYvdxW8cNCL1heu9MASHCB8o/q1QA/dqVH4FX03Ulbc+Oj6 DBeoH8U4zGGqa8b69pjkkTx6ubLPZsJsnj02YpHSwPXYY8Ww9vSqi9FHkACSaCEaJegjvM6W2ztTI ptKjE1LYvn1DHIJGpOew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbe-003lug-2I; Thu, 05 Oct 2023 14:45: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 1qoPbS-003lcW-0P for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45: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 2CB7015DB; Thu, 5 Oct 2023 07:46: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 76BCC3F8A4; Thu, 5 Oct 2023 07:45:23 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:45:06 +0100 Subject: [PATCH v4 13/17] firmware: arm_ffa: Simplify the computation of transmit and fragment length MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-13-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=Bk/KguDz+Pa9YD44dR4bVtd5OHjZzTqIACMhi/OAstc=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvy54FhXD9M3/xGz2SYo5UUiWjBKhS/CrOYm DIteIRcWumJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8gAKCRAAQbq8MX7i mJxdD/9iwVr+502At7oyF6Lgr+0lSTlhDAKQPpxK5BQ3baVM+bFBNobUFInNlj4NHXerZu82j3u ErROcKLWnk9PtI4ZeGC7Lr6vWIHhPPlsQjXVc2RoZhtJh5pVTyixbZwLDNeshdpAlgs3f0Fd9EK uK4oJAsfkM6R7uqO1BqUVv1B2xPk257JdObrqFBe1mY7lBmw+IqM+0CmFsCFia6P2jdK8NeDxxo ETqyQEn//VvVBATcDvvneF6jQfgaTiwU6U81lmkLOJpB0n1k6aYRqbAnhWNdwOByUWKIY9uNJKU GmSjN3IAPeGmqLaOTvZlXeLP6lgTIss3G6PNJ1lJChuyaHGhGWBE5BGT2mWtKzSPpXajXWrYKEP Um/zAnMG1FByBEGqopm0WfTI0XzJk3+w9KmnKPwsJxERVNcZwBZVifBHo4xuZpY79zHo2IZuIPS 86omoq3ypaNfWSJepmqd5DDWM/jP6/eCRvwVkB2qx4iGjCYz6Do0+ERW/AtwYI3/Lj+nnc98wWy 2incga0kZXWdQad2zcil4HEd5OrT7t2CNfLc6SG+pK4baDf7hwgca3ZMUpKCcRp3MZKaT3DJw7H S8g6D1fojvvMJSQBIuYqs57qtiOrt9P90hVO4p6ARwna608lqxgqOHpB8Ls2foVseWQLDkVaypN A7hJTpnH2aldgpw== 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-20231005_074526_261961_E48E28A2 X-CRM114-Status: GOOD ( 11.71 ) 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 9dd5335001ee..45ad704734a2 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -442,23 +442,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; } @@ -467,13 +469,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 Thu Oct 5 14:45:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13410173 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 10B6DE92709 for ; Thu, 5 Oct 2023 14:46:15 +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=JTvLlpPWXEaV2PjYIIusin8v4Ff12bxr3LHXHIUvpPU=; b=k4mqVIjCctH+76 xQ6IDM83g9aDkC03K8wFo72n6o3CAS4ulHN5uv/S7ckTjKbvRM+bvEmA9VHZk4eu8tJ31d0xau4+J ReTO4sAQypZS6g1XlFW/dpN4/UjkXiZCIZZ8qGMr4Ni3xqg54U7lVNAbl7RkyFmYVaqdyEGUnI6W6 Imsq9J7Ft0VwAkdwuI7mxsiqJGK2bwlHuTxIn0YMthnSFWzxkVxqLO/laxVPKxSc/EueGC0BeGiRg tNvK7xcKpLl8ZJtvWn0CzGTovjQr57gzMkYH2aSx37F5BEob71xfk166Mq+nb1b64OaroJ7LQadGc 9hLeaVWLxVPligAG5A5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbl-003m0R-1x; Thu, 05 Oct 2023 14:45: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 1qoPbS-003lb4-2V for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45:32 +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 C90EC1650; Thu, 5 Oct 2023 07:46: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 A87D53F641; Thu, 5 Oct 2023 07:45:24 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:45:07 +0100 Subject: [PATCH v4 14/17] KVM: arm64: FFA: Remove access of endpoint memory access descriptor array MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-14-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=3232; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=SS6JRBjjCJQqFwvnNz13s81gsvYnAl3iEKszag6Pbtw=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvydd/+94+47JnCF7cTSk3FzmX9PSPrdF9Ly GN4PBA5oLqJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8gAKCRAAQbq8MX7i mLjxEADBX6incMiMnSXjh5fzCkWAWrvI9bfk0iqevZkcvD1/rbY6wqo3eJMbTL8rhsCA9DphjKX wscGHUig6QHtuR6KFqbQVId6lgMAPFL8yCfALoAp1RbZtNe0FKoFN6YoPtGM42ckpNthk+9XA7j ohxfcrgBkmGYRAChnxFguIvAk8FXHWS81BY6XGhacN1OnSfUNhmhZvs/MAqdeDh5TO3mEQ2ckA/ nYWRc1JBvLGg6tpYzyZiAh5tV3gDSqUehDjjTqZMn9bMQrsFaxYg+psry4m3jdNoDf+Wkg+D4Pm qA11X7O6BdsBI8mD+Hg7l3u/vkzJ3026jUUPUVtTaMWxxMX3VlrWtqcWSENBoPIPwopVECspfQ0 yBGGZhhA3fOL5gZQ23newDuhWt+cuJlXtwGzFdRGtC2idSBQd0Cnm2BPbBX9uc7u2kkyOIAkkdt NQuIpW5Ib8xcMhJcStZ8lj73YiQsWf1BoXROHcljTWTFyEJrV5AJBC9e1gPPMReQMLlRPMyQ/gD eJlreACercAiLNVQk8uCf3RfGBNoB6bIBmbh/C5T6iDWi7EU8mpzPJkpHOZildEw450NjWCqzpS I9o4IfUm5LWPwOfuh4H+Na+Xiz2z4v2Jbw8o4K+3carzaVhIRM91dw/oAjgK2o4TScC8WIfi7ot x1XvkKUx7I2W/kw== 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-20231005_074527_018399_61994FC2 X-CRM114-Status: GOOD ( 13.54 ) 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 FF-A version as the argument from which the memory access descriptor format can be determined. v1.0 uses the old format while v1.1 onwards use the new format specified in the v1.1 specification. Cc: Marc Zyngier Cc: Oliver Upton Cc: Will Deacon Cc: Quentin Perret Signed-off-by: Sudeep Holla Acked-by: Marc Zyngier --- arch/arm64/kvm/hyp/nvhe/ffa.c | 10 ++++++++-- include/linux/arm_ffa.h | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 6e4dba9eadef..320f2eaa14a9 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,9 @@ 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, FFA_VERSION_1_0); + 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 +507,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 +532,9 @@ 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, FFA_VERSION_1_0); + 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..2444d596b703 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, u32 ffa_version) +{ + return COMPOSITE_OFFSET(0); +} + struct ffa_mem_ops_args { bool use_txbuf; u32 nattrs; From patchwork Thu Oct 5 14:45:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13410170 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 15626E92708 for ; Thu, 5 Oct 2023 14:46: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=fgn9a7wAv026ucUy0iSUNpNqKUnw3MVKs6/DuvzcQD4=; b=N9tjghCTFVxE7O KCkvw04gBxOyjpJEFzaHEYR8PFlAW1a1m1WH6xxt4SN/4xvebCS1lqnuclc4ZmcE5djtIFqNLrpGz 2c7Kip7aQ7i+VF1NNkiXrqVs57HHsrMGo3JA/5tL2TA0/HbjZoK6PdnltE2KJr7cy4Mz9DGmbfd0d 4Jcp/DR6WvafHpd9IJx3bO/L0A7ifA2w7ZiubWRK2yMtIwMMawO2b/OLZs0dHpeT/CMRoHIldIuyx +B+XxwzG/9Dz1TjiYSsb6CcicxnV3eTdA/jmhtf/92cZfhRwd7+tI1DBq9jjL2Jifnzc6JknN1blo siCznw40/DKMzlFbMYGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbj-003lyT-0Q; Thu, 05 Oct 2023 14:45:43 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbU-003liI-0l for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45:32 +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 08C691655; Thu, 5 Oct 2023 07:46: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 50A843F641; Thu, 5 Oct 2023 07:45:26 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:45:08 +0100 Subject: [PATCH v4 15/17] firmware: arm_ffa: Switch to using ffa_mem_desc_offset() accessor MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-15-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=1380; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=dftsGeY1DJoCwWfBKEb8lal/PjiIATpRlO3OUrofRCc=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvyU+xRMy3zAAPz5EmrKB/zbOi8MBAJRtWAu gSJrAtP0TqJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8gAKCRAAQbq8MX7i mMzlEADC7lH5pUpEzXnZb9aFQtnhTnJ0WRHy3P6aG27izufZJSrmsAlykpGuUcdyhfN6mWSDcTK I/CeMK17mZBbJw2pnGfJp2WHYOfcbY3nPP5xcoi1Arem8t8y7YfgceVxaATJpaiBF7mOfZHuOPL bvonNJg5hali/lX5uyKbGTqmO12QjHHCtmCFtS/+79nTqpILkF9QcnLbEU7tUukbplE7YH4o4KS UxllLl9c3KNRsENtPP3cNt1swBdF2CLRwNmgHVW+fBEJ6mvmoIYJhSJEWx0zQHKULWYIavUqaNT Inh4L3sY/6YmhRaIrY7goieuI1zdz4ZYsDxTI0r076/fWqb6Lj+sB/SVr1ia/+wsYpg/PtHTzXh tOaBu0oyRh6BqHXFM49GlQKozWKV/advFhy25KTuryCQcbSR2skEJe/b/EhuxHx8/LJGCtLOeFX PQ05NvrMMXQLkApitInDB1kKifye9pwk2XkfsyLkZMsKIY45qD8Lkmy/17JWvgx2+VeAwD+eR2V WL6+M8fUOUJe0mXNmR2KibP46sIizy/1a9luMSMC1s1IdPZpWjSTk2e0WBthrco8Uw5JIqZRroC 7fTMxSBJ4YwKDAB5wTK2dv1jJ1MN5Z7hdpHVranN7qMUpaAWVBDUaok7CFxyEfqKv87OsKNttSt l2IZL/v5JzMvXpg== 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-20231005_074528_378387_51DF8FC1 X-CRM114-Status: GOOD ( 10.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 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 45ad704734a2..4de08ffce599 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -454,8 +454,10 @@ ffa_setup_and_transmit(u32 func_id, void *buffer, u32 max_fragsize, 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, drv_info->version); + composite_offset = ffa_mem_desc_offset(buffer, args->nattrs, + drv_info->version); for (idx = 0; idx < args->nattrs; idx++, ep_mem_access++) { ep_mem_access->receiver = args->attrs[idx].receiver; From patchwork Thu Oct 5 14:45:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13410167 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 B8376E92709 for ; Thu, 5 Oct 2023 14:46:03 +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=ZBFS/rJOlA7WbIuaTsfheNTXB0NDFHpg7ZPCZSSWBI8=; b=sJG3oN/+tD3JXz 8r3vDQACExRrR8ErL8Zilgi+aDpsDd77oHDXlK5EVklud+L5MomCjZx2K/n7XgSXpqLbzwlC7Jwv9 vXyDJPOAV+v459YY/KvH8yuOWkW5GppMm1ClcZNVxRTGZwZJbvfShcuV386DswQyMtnAEg6Qa6C3m 5G1PPwotWHOZojOlKq9aE0xdn7ncT602z5vWm2pP6UEEMnOCIace4vv/53Wide8Pi1EcHw0M25uoZ zGL9PABa7HDqdGKhnVTGpieDan4+iqwGY5BZCz3NqsHFozs/EYuHOzIb6dnTKqL1YbUB/+70omOCJ 2jtJOp4K8fqW1fMlyX1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbh-003lxN-2W; Thu, 05 Oct 2023 14:45: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 1qoPbV-003lcW-0H for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45:32 +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 386CA1682; Thu, 5 Oct 2023 07:46: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 826DF3F641; Thu, 5 Oct 2023 07:45:27 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:45:09 +0100 Subject: [PATCH v4 16/17] firmware: arm_ffa: Update memory descriptor to support v1.1 format MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-16-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=4145; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=AsgrCLkaUu1zLbCge8pt4uxFm41JF9MxE5C3AnabUNY=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvyF1KWLkS6mBQdJcATQCVZa74qTBlObPPJb RknDLHuEUqJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8gAKCRAAQbq8MX7i mIGTD/0ZOjx3MsHUpdw/U0qsG9hf76rA/Ja1Eax44lG4iDhpRJUPpBs8fMD+mqupQpKmB4YgHlk XwTP6t08kC0l6+zrg7gxxKUK1X4xEpLRTpjtCoQU7kTrtXNfLXop3zz/XksZQHrcdb1Z3YLsIkX YPlFklYloF/otyQfDlm0/CLyTbM4Td5igLAvLvHqsYob2ucq54i/IBlIe1bHpD6u0gdHuf+1icX NTDMhPmTWo8+kblRzR0bcDHub8St1Op0pKvJGXOdV+ZkiOE9xKc3F8y9n9lHVAbIw565HcSasOx ObaEXkiYXAhyz1+pzczao49bl0bCmTS7RYDB/3rNgH1M7rabqqrnmn0/Vtq0giGykAKFFZtpNb1 WJgur9MivEN2wjIJSkY/ISh6fWMuTJJUoTM++6+0tX1KG/mROO7iXvvVMRF911H0BOWeUhNxuD7 YqKaciz8soevmr7tn1okIpyXdBm+lDWHj+xy1pf0DmWX9vpKRDrX23Rz1PibW5G2Su5WylumCm+ BoGse61vKBGKBvu3tc6EhKqb8wap70gooIAQk8oam0Yp5dAauQHAQinNbPJIQoYuXhOHG8Pvxur t70nVoJCHYCoeNpQjXc0onTV2sC8gqSaXcDshJUS/fe7SA3tE3PwTGIdWD7gkDhHLsS7mhaxTra tlyc6hpKD//gnNw== 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-20231005_074529_373082_283DE5C2 X-CRM114-Status: GOOD ( 17.36 ) 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 updated 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 4de08ffce599..7b3db675454c 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -423,7 +423,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 (drv_info->version <= FFA_VERSION_1_0) { + 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 2444d596b703..510fe78bff71 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, u32 ffa_version) { - 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 in the current structure) + */ + if (ffa_version <= FFA_VERSION_1_0) + 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 Thu Oct 5 14:45:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13410172 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 BA0D5E92705 for ; Thu, 5 Oct 2023 14:46:09 +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=lfHKxMMxJyuTGUiUGch4wlUxnARnLVINuTbd7vf7mH0=; b=goy77qRkoky8oA C8PDIfG9QibEEo5IpAcOCUKC4P3xyV4wiU7XZkkWNyLu5L2zsuEi6Cxk9Zko/yuZf5FsfyEshxdh3 gCGjuiT5p3uBlPYGAscOnzyd8MX83CI2hqD4Y2LTxlpeFhd0kOvJXuvj29gSemvW2PtFNS+I7m94w GLH0AEX9ds+nb3rb4J8IIjSIQysXeqE4Mtn9Lft+SnbWf1h6BXs86Rg3oWmmMeLFHUW7I9YbJDuoz YD/OBsjguGT2xJd2kFxHYed1HiCV5IOPqSL3Y1BJ8FT1Fme7sa6g309kVerfmrCGAZG0h+8yGLrEY Kxczakw+miRse6QKG5iA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qoPbk-003lzi-23; Thu, 05 Oct 2023 14:45: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 1qoPbV-003leR-3A for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2023 14:45:32 +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 69AD6165C; Thu, 5 Oct 2023 07:46: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 B40EF3F641; Thu, 5 Oct 2023 07:45:28 -0700 (PDT) From: Sudeep Holla Date: Thu, 05 Oct 2023 15:45:10 +0100 Subject: [PATCH v4 17/17] firmware: arm_ffa: Upgrade the driver version to v1.1 MIME-Version: 1.0 Message-Id: <20231005-ffa_v1-1_notif-v4-17-cddd3237809c@arm.com> References: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@arm.com> In-Reply-To: <20231005-ffa_v1-1_notif-v4-0-cddd3237809c@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=8SIeTzl6vfeVnSukOY6SLPu6xQWTGCA8RlmB08AfRzE=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBlHsvztoI4de2Cc5nOvWVIziqQtyYMiDZMOD3tc WBouUU3Wx6JAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZR7L8wAKCRAAQbq8MX7i mFhDD/4jQiafvyRrcC2b2LaGjuEUPeCodEI/rRe0nBjODHCAqzlejdqSphbj+vL6tH8E/yNs0yI 0bNJi1s4p9YxYGBoCSecB0t/OIrstLVWiJE3Kx5sMb9Qm0/h5UG9ZXjy+TlT+zwYxb0HmfxBxtA G+wRUxur9rOh0IZECNkx6p0MYNCSHKg0PEOXbBVpxFsfgtqVS/38AqUyoH0eDHZpQAsaTJqBzaJ p1kJbcPknG6P4uRvrvkvTTNS9O3rBIadKkNDQJ6IAgFqNoNCAIPktl9rldt9mXZEKDe+Nw3uhwn vcF/9PcceCIjNhlWas42vsC1HA7HoWiLQSrnRvDV90Q+iDp2mjdTrQBEYxinT8sLrEZ7IAFLOnm aJ0Y/AhrvlbWXPnyVcdewKn+u7+d0+cgLPYX1qKyZmZHTGJweggDqTwwhIkV+BVxZQ8hWQ62dEN j02d9aFkqeFvNk5dQT2BT6+Hsye6c69eP7ZqLGgUzTmiOVPh4zkq/BIP2SThzMf/AHFfIO8Xkes vXirXf1P2uk6XilG4P8hEAljGjdFnxzTf9I2y1Ql/BuBXTpYm+WLKmwEQpB3tOKWT2NKd6UhswJ ulieKWOpF7ll6xkWPR2VNLcDJvygLs8K8AhLWdeWhkkVLMsOQHlv4yAg2L1ARvtN/h5Qh2q+R/P Qj9KybnRjVCtntA== 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-20231005_074530_152172_2619EB16 X-CRM114-Status: UNSURE ( 9.53 ) 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 7b3db675454c..7b6fa6a2781d 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)