From patchwork Thu Aug 3 19:02: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: 13340787 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 EFFD1C00528 for ; Thu, 3 Aug 2023 19:03:05 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=slJLDOjf12lofurANaaQe14WQsMqKtwBBap92bwq7P8=; b=YXJaf6A0h18hoX cjE4RLIcoc8Sd1i6eulTeZT/8KBI8j/1ABYNhONTq/NTVcWlFPDNXxao/P0F3Fpg5lkeDjegwgBHG xKfF+1TCd26/OEkVdGLVa3258iQ+G2UpFJcJt7eQunrQ3XbLO1r6yBRKo3HOTVA0rjyqQSMdKgp6W 1GVwSxkt0HAmEIJ/PnFOCxPqhdGDAjzFZZtsyz0+jkzh806RHDjlUBOcwGo+r2LWzSokSCUOUm3dX 5GFVcuFIi5jaKavabFdnMKUx8DbFgDSTV/X3ZzuvcSwaVPUJB6TUy3lqooej4pN8kFzbz04DUaorQ +zF4uFuXYHkb6SnX21RA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdal-00Agzj-28; Thu, 03 Aug 2023 19:02: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 1qRdad-00Agtl-1N for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:31 +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 1CA1712FC; Thu, 3 Aug 2023 12:03:06 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 016393F6C4; Thu, 3 Aug 2023 12:02:21 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 01/12] firmware: arm_ffa: Update the FF-A command list with v1.1 additions Date: Thu, 3 Aug 2023 20:02:05 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-1-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3496; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=GTz0RHnY4ME8Vwfxd5lhNhdlXiDZdoMtSl5u+RRQtgo=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iMR9I11NYSDHMyCEPHaAUMvwOSSTOS7je6F o6puaIHPz6JAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jAAKCRAAQbq8MX7i mHxxD/wNe71c1PxA5+6LmfU5hH8EMwEUYcgVa+U1KoYRwj1O8FAJwOe1oBGA+qxoczHsrn96Ers 1MHizvhCClNrakDY2X4BDvCgzefy7XqSaLhDRfR9b5BErtsG0zd4Vse/Df3iOOO5mSofYCmGpZb sWgNk9sSK7aVkoC1yijjrdnj6QGj+i8tjoItmef8Rg0yABf4z+Cf46ZvC/brnJZHjVVlQ3lM5p6 I2AXL2IYo8afQAsKp6qLY5S6nwijlkVq4x0+nFiWaoufKqAsubWhyxrzHRxLL76R3Q7vj2rEXqq 0FkFABffP+yL4cXldJxunTFiB1qj9vThJM/1ctQDpyqFbjGaz9wP/DEfUyUU8GTGDVjzsjpGdAe EMQsEdbQtBKSzHUA5Z7V7On5GV6dl21XK/E4CykL18Gl1n9ld4bW1Sx+9OKKM52ALfuxVAuRBmw 94KBmzG7G2hKrLFkC3w3tT5zOJgC9ZKIMKZGRuhdGqnA1aDtpRmppdEETW5xwroBpmyFwE094le e2mMPYYi8fkcE6bWAZVx+awnIbeZ2W4XAQbjMjzysyx7QnAf5OrDaGBfHqNKZ1NM09gb5U5Bd3I FWTbMY/fkYHlp9LTx+nrexyyeSXH2jdAGg4R4dBmWXlsOBwAwCc4cKqkQ4DyanQnTcquYvXpUYI kZTC358t fmlxKdw== 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-20230803_120227_560877_E52558D1 X-CRM114-Status: GOOD ( 14.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Arm Firmware Framework for A-profile(FFA) v1.1 introduces notifications and indirect messaging based upon notifications support and extends some of the memory interfaces. Let us add all the newly supported FF-A function IDs in the spec. Also update to the error values and associated handling. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 3 ++- include/linux/arm_ffa.h | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 2109cd178ff7..6fc83fa6b81c 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -64,6 +64,7 @@ static const int ffa_linux_errmap[] = { -EACCES, /* FFA_RET_DENIED */ -EAGAIN, /* FFA_RET_RETRY */ -ECANCELED, /* FFA_RET_ABORTED */ + -ENODATA, /* FFA_RET_NO_DATA */ }; static inline int ffa_to_linux_errno(int errno) @@ -336,7 +337,7 @@ static int ffa_mem_first_frag(u32 func_id, phys_addr_t buf, u32 buf_sz, if (ret.a0 == FFA_ERROR) return ffa_to_linux_errno((int)ret.a2); - if (ret.a0 == FFA_SUCCESS) { + if (ret.a0 == FFA_SUCCESS || ret.a0 == FFA_FN64_SUCCESS) { if (handle) *handle = PACK_HANDLE(ret.a2, ret.a3); } else if (ret.a0 == FFA_MEM_FRAG_RX) { diff --git a/include/linux/arm_ffa.h b/include/linux/arm_ffa.h index cc060da51bec..2ea1717a0825 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -20,6 +20,7 @@ #define FFA_ERROR FFA_SMC_32(0x60) #define FFA_SUCCESS FFA_SMC_32(0x61) +#define FFA_FN64_SUCCESS FFA_SMC_64(0x61) #define FFA_INTERRUPT FFA_SMC_32(0x62) #define FFA_VERSION FFA_SMC_32(0x63) #define FFA_FEATURES FFA_SMC_32(0x64) @@ -54,6 +55,23 @@ #define FFA_MEM_FRAG_RX FFA_SMC_32(0x7A) #define FFA_MEM_FRAG_TX FFA_SMC_32(0x7B) #define FFA_NORMAL_WORLD_RESUME FFA_SMC_32(0x7C) +#define FFA_NOTIFICATION_BITMAP_CREATE FFA_SMC_32(0x7D) +#define FFA_NOTIFICATION_BITMAP_DESTROY FFA_SMC_32(0x7E) +#define FFA_NOTIFICATION_BIND FFA_SMC_32(0x7F) +#define FFA_NOTIFICATION_UNBIND FFA_SMC_32(0x80) +#define FFA_NOTIFICATION_SET FFA_SMC_32(0x81) +#define FFA_NOTIFICATION_GET FFA_SMC_32(0x82) +#define FFA_NOTIFICATION_INFO_GET FFA_SMC_32(0x83) +#define FFA_FN64_NOTIFICATION_INFO_GET FFA_SMC_64(0x83) +#define FFA_RX_ACQUIRE FFA_SMC_32(0x84) +#define FFA_SPM_ID_GET FFA_SMC_32(0x85) +#define FFA_MSG_SEND2 FFA_SMC_32(0x86) +#define FFA_SECONDARY_EP_REGISTER FFA_SMC_32(0x87) +#define FFA_FN64_SECONDARY_EP_REGISTER FFA_SMC_64(0x87) +#define FFA_MEM_PERM_GET FFA_SMC_32(0x88) +#define FFA_FN64_MEM_PERM_GET FFA_SMC_64(0x88) +#define FFA_MEM_PERM_SET FFA_SMC_32(0x89) +#define FFA_FN64_MEM_PERM_SET FFA_SMC_64(0x89) /* * For some calls it is necessary to use SMC64 to pass or return 64-bit values. @@ -76,6 +94,7 @@ #define FFA_RET_DENIED (-6) #define FFA_RET_RETRY (-7) #define FFA_RET_ABORTED (-8) +#define FFA_RET_NO_DATA (-9) /* FFA version encoding */ #define FFA_MAJOR_VERSION_MASK GENMASK(30, 16) @@ -86,6 +105,7 @@ (FIELD_PREP(FFA_MAJOR_VERSION_MASK, (major)) | \ FIELD_PREP(FFA_MINOR_VERSION_MASK, (minor))) #define FFA_VERSION_1_0 FFA_PACK_VERSION_INFO(1, 0) +#define FFA_VERSION_1_1 FFA_PACK_VERSION_INFO(1, 1) /** * FF-A specification mentions explicitly about '4K pages'. This should From patchwork Thu Aug 3 19:02:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13340781 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 BFB30C00528 for ; Thu, 3 Aug 2023 19:03: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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aGGddWWkmLPi9SCDWqc2LyoSqzR+BxAnNmph1PyL2I4=; b=rRMCTgmO1d2LS9 c86xGiFr/DJXWkUCthU9h0xcZX8gn8N4MIL7qkRqYBtBLde+XYbTY0mDSUplIYmGlrhxNidT+646a nLUb2WtiZmGXH5BKuVYOK/DGH7mvVQht8ekDYduLdlxylDrvA2IYHi+B42sYzDMk+fY/7oto5T7yc 06+v79TDL28hr/5AoJVj46nDbh2TOsDtCzuZ0P57Jgzjt5REM8IDUEpd3/F527ZmnJipAR4rburf2 gvH7Tc/MA0LqHexutIXJljs3zIVxykNC7FHiXzYPDGSxVUVuWhyqYcnmUPC0jBm1I/padzfW/IOn8 9lrBzZqeX9dyCU0woIpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdaj-00Agxb-1v; Thu, 03 Aug 2023 19:02:33 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdad-00Agtk-1J for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:29 +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 74D131474; Thu, 3 Aug 2023 12:03:07 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 595B03F6C4; Thu, 3 Aug 2023 12:02:23 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 02/12] firmware: arm_ffa: Implement notification bitmap create and destroy interfaces Date: Thu, 3 Aug 2023 20:02:06 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-2-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3353; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=LjH8zfz+NSMR+jD4bGN8jL66879DFQjmAd8Zz162PAI=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iMaxntS0KpaU2/1R5tA+iKx9/x8ods9t7Ok eCvBJYhoVKJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jAAKCRAAQbq8MX7i mMsID/9s4LbC/Bg40/xIJACO2aE3Q05WOdrjwdzAzm/gwkN1ioRVW98hKvwa4GdaaG2yPOBr9Gr 6pcRod3atLXK01PwKJE4k/14c1/RmLCCEMuFdjGMK199FvJdMIH9PrgWDjTvNpmn2j50PPjDONE 37t8Mo68WPo56ylte/svzGUiPrmULdojgMG3xdWZgFGCSBo15w+5qEWEPBnN30oH71OpFOJfWT6 +EXhTmAMmgMstzdwOP5nvU8+iTBInCwuuJM91mJGDvE01wJLw2YeKTxsBQkcp61jtLDqxGH8sB7 vGZH+GLbWHXbk3eHiP3hDxyFfwPspTWv+DrRdsp2RfIx6YjQvhH84T9zgiMyHWlfqg7wUWhO0D9 Wi6h68giUNTPgwjuxK4DqLa7vmD2b5PN671/dP8Zy4/xSD8l7t4tTRbUdNYpEWhuW/FBmrgKcYZ WxK9Z7FAOtrHxP5TYqJS8Zzce4Cw7V8hlhwPYnWenOTfdpWDmdTZlQYJEjaSJncxt5z4+Sn6uAe lGzduJ5jdNDzdyJvolC1+2opkY/u4GgMnlQ3/Itr5BQrW0xTgoKajF671RO7zfKtEmbhuCo4NYV JF2quBrCe45ti8nghRLfvrjl4iaEUqHZWAr0VumoGlFY+JOdJ2pP+kVNNab2WHOjAe89h6CBoFi LBm/CFH+ tIK73Rw== 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-20230803_120227_544307_989B8B1A X-CRM114-Status: GOOD ( 15.93 ) 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 | 58 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 6fc83fa6b81c..022c893c9e06 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; @@ -543,6 +544,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) || @@ -700,6 +732,29 @@ static void ffa_setup_partitions(void) kfree(pbuf); } +static int ffa_notifications_setup(void) +{ + int ret; + + ret = ffa_features(FFA_NOTIFICATION_BITMAP_CREATE, 0, NULL, NULL); + if (!ret) { + ret = ffa_notification_bitmap_create(); + if (ret) { + pr_err("notification_bitmap_create error %d\n", ret); + return ret; + } + } + drv_info->bitmap_created = true; + + return 0; +} + +static void ffa_notifications_cleanup(void) +{ + if (drv_info->bitmap_created) + ffa_notification_bitmap_destroy(); +} + static int __init ffa_init(void) { int ret; @@ -755,7 +810,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); @@ -770,6 +825,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 Aug 3 19:02: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: 13340786 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 46057C04FDF for ; Thu, 3 Aug 2023 19:03:05 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5bYETkqJb4BsfFL2eQLNqd9ZTE+ezWJoWoxqiLvq5qg=; b=Maw5mu3t07nrOv bdbNHCqMkbW67bqdkL3/WSP+HTuz1BHJpJPlBG62XV570ipw5T2f7NXlN27BdEcyOj++9fTYkdIVw v60DseWl9QBdKTqutb4QvfdKSUh9p8aaYkLY29KFTvhqOVXU1Iz5sJx75PrHWS1RpcOV3smI+re6c KknOx1pT9w+7moEoWFp8KR29NeD8jM0Le48dbzVEVP8RzC4yyx48xpfHgD5AursF9eCVe4O72U8wd TQBeKJj/lTf3FJ36lcWKi4yxtMoHQ/E75ulGcCo6lVMQ8o6hro3sd7l4fT8nUp9g9fz7h2KiXJ1Rz 5Edg4rUamZhCB0nhlidg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdak-00AgyV-0P; Thu, 03 Aug 2023 19:02:34 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdad-00Agtw-1n for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:31 +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 CD5111477; Thu, 3 Aug 2023 12:03:08 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B17223F6C4; Thu, 3 Aug 2023 12:02:24 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 03/12] firmware: arm_ffa: Implement the notification bind and unbind interface Date: Thu, 3 Aug 2023 20:02:07 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-3-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 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=3OYEZ9E7vpg3yPFg1J667JzF5mZtHS9nU/hUd6LN5Ks=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iMR7qOL9Zi5z8RhAxhVfjJVsHMbQnTx3Ufe 4oIltWTY5yJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jAAKCRAAQbq8MX7i mM0jD/9XM2IgcxuAMRlGOA0NjXZYJLOQhVTzf5TLKjbmRV5nA06MK3WxFLrNfdT1gjWqNVSRnni Nc5eASG2Wd4vb8GG9tKcrr3R5/KIuIRXe4VTlX8y8vUpteSeGKdJc9uRq0ZTrZ+xY2iG4tQDNg4 cW8ORBHJ59Aw9K6GYa4nUm6rqo2oMUOqLtY2C037F+fdB4bVUve5abIP0Ztadp/PiRDmzE+RiDY 4hChusP2o+dYakJz9uQPBhnd0MqLw48I/hypdQhEz62FYc/bnhI/TRE0RlwVPFynsRgGFv98m9Q HMOxgJEqE9tW+nXAIn8+Ak75ueajWk2lVTLeTdRIZy/TWhmXMONqxY0OPEIRKK5932viifLPumB uIx6VvwugAnD5m2s5fRObNOxXb7H3b1eMhLBUX/FK9qwltkSON0B39dI7n9mCwvtNPq5KmMZiH+ 3iUp4H0RQfL5PL1Y0kYhv10bYoYZhogcjVoMuXNyzZ9rfqxjeJnO5qKSmNw5P+/Ybl0drjYx1lU kGYpHoP2Gu8Cc9evLhfeZlbthzIxRZ3Mm7cW1i9D084bh2vIAX5O9pJN6thnWwuLTQam5sjr4I9 88PgMAjGkpyfu9tXxApQQV8Oct3Xp3OvisM9Gb52J8zk/CNCOzf7k8x67yYS+48qyViu0OQ0v+N Ko1L7Vlc vChz1UA== 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-20230803_120227_692306_F799AF8C X-CRM114-Status: GOOD ( 14.28 ) 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 022c893c9e06..a76e5d3a2422 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -575,6 +575,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 Aug 3 19:02: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: 13340783 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 C67FDC001DB for ; Thu, 3 Aug 2023 19:03:02 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7qj18mpDrMelLDpWTimxZ+28tN+5M4h3rXfWMxOOHNQ=; b=nTIo4M68KC2UVg 9bXjtX8THURMwt9JOw3HGJrSxCtPwgB8dV0Nb4hUbrMrr2b9qRlFad6F6z356SkyhzMlrPZJSxCA3 D4miliIo5rC8c4tlivBZ2Odv/0q5UvJh9KuV5CzHuD7YQ4U3cRpsYzbmgDy4+glbl6/pWe6W93Vgi sHBgPq18S7GWOkfafGC+54j1KLfbU5AaruO1D+tyV3UFs4d1WRGoYiFYBwv+nmHDk0UX90I2yYz/r iIxelMqnyQUWiOB7v9isbj8D1W9vOVAZkQejaN87hvscXaQSpBIfWIcopbFPLnMS6CItsGcGsk3eA 85iSO64uZW+at2iIj8YA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdal-00Agz2-03; Thu, 03 Aug 2023 19:02: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 1qRdad-00AguU-2C for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:30 +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 30F861480; Thu, 3 Aug 2023 12:03:10 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 15A3B3F6C4; Thu, 3 Aug 2023 12:02:25 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 04/12] firmware: arm_ffa: Implement the FFA_RUN interface Date: Thu, 3 Aug 2023 20:02:08 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-4-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 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=8UCCbjCIAGT3DvQq6khWZB7ln9w5pDlIi1zeSYgu1Gs=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iNz8e7tlD4ADSye1xFoilF+9E6QAkr3Wlr+ vNDIyzwNgyJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jQAKCRAAQbq8MX7i mAk6D/98H1br3BLgYDjviipRcx6zJ1BF4rGi7dR1v2O8kSdokik+nyBljy56Bx54mY/neK5YSEL V3OYu770AaQ5mIOjZ/jtYreLtn3FI0oZDILv0kdkicEfbRkg6vMtRpI3UwRP8N+fOMX4JwbRciy f1l7VnBCn4BWlMuQ3NAuUTwWEo8FRYs7lG/k0Yk4Pp/FLt9RzaAPYP6rL2qNWNkbR6yTA4yGjOM YCLFgOK7nl7gGIW59NSCaqGrcsN2tr9hxl3pbTzuE8l8d5s0exBV3xeinKM/624DBJbPdheU3Eq Y/i21/woZzEcTiDl7OsLsfMq4KCXXncZ8lhth/PUv+iSKd8U9qG/FQW7WlCPYE4jXLKzj8cD6ON CgmTkzjOI7P9Vsyd1DBT44s1tKYnt/DrQsU4jDlLcQ8eje7udinc84lun2SPhXgBoZVogVb0vdv I9PcwAiPZrJok2N9sRr0KSKmxlCQnMo4CwEw5nzbx1cl91rJTHPNsEvK8JnBG0wiaVx/99+gvQo XqvJKaGd0V8ZMSIM/qCBfPxzwD1MbG9iBFvmSQqvb3BjKi4aJhwg7ukMq3X7m1yrIW7vHbaqWPb R2ueissxARbclA8P2ks0gzOrPycGMJ4pHhJ1GOWXCZUghYePYfnELmTY5n08Eno+2o6fNxlMF3U DKtZi0Ox b2IMgrA== 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-20230803_120227_815094_F26F480D X-CRM114-Status: GOOD ( 14.51 ) 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 a76e5d3a2422..41171ae7f63a 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -604,6 +604,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) || @@ -696,10 +713,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 Aug 3 19:02: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: 13340784 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 DD857C41513 for ; Thu, 3 Aug 2023 19:03: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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Py8gKXDDBvGGg4TGD6aygc5UlQV2OpQk7OtV42isXhI=; b=nNWKi62yTpdfaX d+KMkAFv67QF8xzXyf2VInfytEATSAdJStPbb37mosaP2ilPwISxjLiGPC3DT+iZ6jEuQdUvhnZkc 9v1PBPMfBrCTKXEj0hJPPR8pxcusurHMhEwOhymReN8qT6KMVr1cMNxOwj29Cz1V/wpvo6m74p0k0 ZUHBf7wHer6Ch4zlSRkzf/oNszuu4719erGZhH1Ys7EphyVs3dXvBDYu3UvtUEa5JWmlRUEVssFTe aBWwmp4TOhQ+ji00Cm377Zs3m/bqMujRt1cFiwpK0FNEFosY8lP+xT5LBu8AMb3XR/tk7VwHVXutc WyDKaN0M95ZPFvcvHqkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdaq-00Ah2q-0D; Thu, 03 Aug 2023 19:02: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 1qRdai-00AgwT-1L for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:34 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 88F7B14BF; Thu, 3 Aug 2023 12:03:11 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6DB2C3F6C4; Thu, 3 Aug 2023 12:02:27 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 05/12] firmware: arm_ffa: Implement the FFA_NOTIFICATION_SET interface Date: Thu, 3 Aug 2023 20:02:09 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-5-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 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=gIcrWaE8JjUgJBbBV1coOUsOSzQnr17FTAXR0ZVKxfU=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iNKfnamF9bQ6t4TFfYJFZV5REuiS1Xy3AD1 vlZ5aBZZsGJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jQAKCRAAQbq8MX7i mH0iEAC6zQT+zR4ZBTgQfPzkLYDo+kli3u41l6gxWq9DroxO21dHwyuoxTNebt9LONyflU9080T 3C8Esz2fATBbZepXXtLymI/w5eqABbzsqEyhNbkO5tvJEFuzlfpWjdI0pH7a87uqhDwNU+SfmGi ds4bySxPNCTe3VCYZtLKwXpHkys63ide10vyGav0i0PHiFVTa662IKduPD++3ilsRcsVauaQaSq 8zx2Eg+MbDxSizAnii878HgO68JWasJ16Oedm2sCdS5nBAZ9ngasItOSBduaDAc+Vl5VkQyiYE+ hMOHtvdsRLSQVc0GTDuus+MKboxaSwqxjvjUOyRNHne/MQshMCdg8nr3I9WmrWyXlhMDxC7HbEo 7EjHYevbXwvbZtb+HjyDreSBl7lCR0p1Vr5xL0NNMQY/UHHgz1mJSknxpTgTJnTemOUOORVWisv 6Zvcpg4zJt1ve7v4NnspCL/jdD7l2hfGQULukUBDAOm6lxOzfyX7gBp7cQFbafhheMTez/qTUqF cVuh0MlSTCisXkaOPA7vMeJlc+MiQWqRyWE5qBN4h2seBZQ26M1POhMtzpgxPKLwi8VWQE7ReN8 EARC93Fc/nWtWxn8fw72W5j2peB82WNDTyOSLgDT9y/7/Qi7KfWOde4AS0PEc8cXutdqfcL3Rim HxtYrY/f gkkqNLQ== 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-20230803_120232_500640_4A02B5BC X-CRM114-Status: GOOD ( 10.50 ) 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 41171ae7f63a..492f5bfa3751 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -604,6 +604,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 Aug 3 19:02: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: 13340782 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 4998BC04A6A for ; Thu, 3 Aug 2023 19:03: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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ztvqh+xtyp/zDU2e+PybHS9Cv53PBpQKFSQQEabm5FE=; b=0TIgaOWLZqA1Ly OnqcBcD2BdERFVDUQg2DtvWNc17IbLbjN8pUlXrraUc904CeKXAlnX5WU98twbQvDtO7kOdWsANA0 ZqrDBs1WMrwQ70cBDRez7lKgA1zQMjF0QdJGpXpq6O9pgCo/oRmNZRhr3kxT1HQ7zG88F3GZSYOBj LrmI+we5dS2piBTRlnxYXJxo00nbZ6/3G3YnLcTIo+tbngfki/2fnW8vJy9ittmZXhQ0+nEJNUt+j PZQzM23z41FGXbMBGwRCSE/xqJ5ECJ3jn7ZcdIlNXqkC8ZiLUNDewzutOE1T6t0TMtOF95QraCZ5K sWnumbJQOMZE1IZGCo0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdaq-00Ah3S-2F; Thu, 03 Aug 2023 19:02: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 1qRdai-00AgwP-1L for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:34 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E0ED3113E; Thu, 3 Aug 2023 12:03:12 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C59D03F6C4; Thu, 3 Aug 2023 12:02:28 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 06/12] firmware: arm_ffa: Implement the FFA_NOTIFICATION_GET interface Date: Thu, 3 Aug 2023 20:02:10 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-6-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 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=QiYypOJbkBWHgSGa313TRfX1qAeCKQxgXXJlIzrlCb4=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iN718+JjDcXSIQ5FtP9ojxFvsvrNBlWnUpj ykv/F2Jav+JAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jQAKCRAAQbq8MX7i mOMhEAC9njZpnCHhAp9dXLNaxwkN9GRPwSNRxSfrqdGGB9ELXYXKVYNdQxjLCs9w+HQBeMhu3PO GdqB1/IzaHrq9C+U/fPTREEVy+QdGVjEOorcp3FgFIm5EL+FKuIYXY4qnK1yblPbngl9iC/WPbn MpJisF4XHUZ0E1fi6XXRtt0oQe5iYr1Z65OKtl/Jeojt9Ig/A/RJm9/M7+wwE4/yYmdjlrQSwNF 1G06QJK98gSfDahUTnyxov3diHEGnAOLtus/cMttRcvMcvBI/UcAAEOyPWsVsba/IsGLPmM+9Kp hArXdwdwG+DGXXuOT7l2U1jZcNl3dXL92Eij/1sGNBUTRIaU3SgldzC7J7+9kFRi4kfWXnAuQzH PHwy/tctFZHYBPMILmo/QNKd3w6xG9UJFPhEE4UVJeJy3IANEgomJXA0nhWR+zvEPSZRyP5yGUx PHUjqNTOWxQFaTKNPJ8eI3ZS53D4jGsIapfFgzK9nRQ/jMjkZC4JExsSviXn/FvMc1mhz6d1P6k 6dI7YNjSji1B5+eKJx5BdiWWGegwt93hZX49FR5S4g6CqG5bGi3tKwL0/df4Fk0j1tTn4PsiW1/ lni5aa845TzS/3Ha//Thaa6gvfvIvMnNlICi5R04J0GtP6THy3GZSIQSSZlaMg8D3mPE4XJSaP7 Bkva6i1a nJmYebA== 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-20230803_120232_546072_C28D7524 X-CRM114-Status: GOOD ( 11.55 ) 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 492f5bfa3751..6cad91ee57eb 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -581,6 +581,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) @@ -624,6 +632,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 Aug 3 19:02:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13340788 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 701EEC001DB for ; Thu, 3 Aug 2023 19:03:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yPJdZyWVCYSMzDNDsSrtg+hAeJopRA7PdaxTFvbg+4w=; b=c67pc8HCV3/KjV XNWWJCi27vXYun3fVWbL4+olsJZmk2swAL4yfGci+S0a9wGtoJbGKzUxQNIHyM5TJ7X6oPKyIUrgX Qn6Blshcl8b5NXjDMNLZlJynlpnHl9GfX6DWBt3RgYyfal2SHDOvgxDOcLAMtBEjjmudI5TsA8Ov9 IPeoo4unGeAyF14wbL/cJ/vhHHdvIEOB7I+w6ti1dj+jibt69Uy0qjdYvyTLZ+YmVDEFtSRniDQC8 82fSPRh0wp6/veZdfSlZtmvrOers999OsxA0x5DxFYwqIzJoHS47G19cwozXlqIn7Ze2+tr/IDNha i87/s1vz1hSbwtRSLjxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdar-00Ah44-0x; Thu, 03 Aug 2023 19:02: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 1qRdai-00AgwO-1L for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 44B2C1474; Thu, 3 Aug 2023 12:03:14 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2965F3F6C4; Thu, 3 Aug 2023 12:02:30 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 07/12] firmware: arm_ffa: Implement the NOTIFICATION_INFO_GET interface Date: Thu, 3 Aug 2023 20:02:11 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-7-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3494; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=vUn1QvDYVuAhz5nSv8RI4UWRh34UK5ah39o6Vq2iky0=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iNZpp/pP0MmrPVLW0ACWS8Vn6AitaczmJGu e5T+SQ/VKiJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jQAKCRAAQbq8MX7i mJW2EAC38Vo5Z1tQ4bEfw6f7VUZSfT0cHcJGkGSwlYQb3U5Gteiznl0Y6uFmwbzXyIIsQqe/o2C zVbod+Az8Id9lXe/reAqYZVMArZpcrpyWvI1CHYDLISP6T2RZVAyF9kfK5oEic5ClHE4z1wADYW 6b0Iklk3kxzZ4oUyGAMZQQ7TKyXeYsetslCQfwtgqbSfmyPB1r1EvmVaI1161M5hGoIp3so8aCj EUQvAZJF9gYU1Oz6geRVpCzz5TO2d4yHrMJGehIi8V+OvgJojtOVlTJOCrexja/lgjobNitIZAH 4hxiDhKH3n3Y4+Zz7M2njj4wVYXF1uLf9li9UkDWkQZCyb1htfUIuvOmGN/HJU+Fmc90IMI8wUI Y1RX9pAIXALtYm7sb5AP6lIr3enUlzhPSSO/iD9YKOot5fEdKMySvIWhrTHrzJCiqrc4C0BnnhR isPXyZCXyKeCsNzOtlLqkly7Ubd1u+Q03oQZMpwylUPJOnYoDcu1jKIOs1WWrcrIy3WqNd1PHjt C8TtyS+MmmOCPdHXIpuINrbVngxpS3X220B8uDbWqQqNtWLstuG/d9fJqOrOhb6bJOJR+4/QzJd HoDljVhBbCGHtgVkgpm/dKzLVEmjLoWMO1J9M/iXhT0UqItOpI+JtLNf9MAJZDpvOwZo1tZssXt agPiLtT+ NEDYTcA== 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-20230803_120232_556632_2FAC0F27 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 The receiver’s scheduler uses the FFA_NOTIFICATION_INFO_GET interface to retrieve the list of endpoints that have pending notifications and must be run. A notification could be signaled by a sender in the secure world to a VM. The Hypervisor needs to determine which VM and vCPU (in case a per-vCPU notification is signaled) has a pending notification in this scenario. It must obtain this information through an invocation of the FFA_NOTIFICATION_INFO_GET. Add the implementation of the NOTIFICATION_INFO_GET interface and prepare to use this to handle the schedule receiver interrupt. Implementation of handling notifications will be added later. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 6cad91ee57eb..77ca9753e3f0 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -590,6 +590,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) { @@ -661,6 +668,69 @@ static int ffa_notification_get(u32 flags, struct ffa_notify_bitmaps *notify) return 0; } +static void __do_sched_recv_cb(u16 partition_id, u16 vcpu, bool is_per_vcpu) +{ + pr_err("Callback for partition 0x%x failed.\n", partition_id); +} + +static void ffa_notification_info_get(bool is_64b) +{ + int idx, list, max_ids, lists_cnt, ids_processed, ids_count[MAX_IDS_64]; + ffa_value_t ret; + u64 id_list; + + do { + invoke_ffa_fn((ffa_value_t){ + .a0 = FFA_FN_NATIVE(NOTIFICATION_INFO_GET), + }, &ret); + + if (ret.a0 != FFA_FN_NATIVE(SUCCESS)) { + if (ret.a2 != FFA_RET_NO_DATA) + pr_err("Notification Info fetch failed: 0x%lx (0x%lx)", + ret.a0, ret.a2); + return; + } + + ids_processed = 0; + lists_cnt = FIELD_GET(NOTIFICATION_INFO_GET_ID_COUNT, ret.a2); + if (is_64b) { + max_ids = MAX_IDS_64; + id_list = FIELD_GET(ID_LIST_MASK_64, ret.a2); + } else { + max_ids = MAX_IDS_32; + id_list = FIELD_GET(ID_LIST_MASK_32, ret.a2); + } + + for (idx = 0; idx < lists_cnt; idx++, id_list >>= 2) + ids_count[idx] = (id_list & 0x3) + 1; + + /* Process IDs */ + for (list = 0; list < lists_cnt; list++) { + u16 vcpu_id, part_id, *packed_id_list = (u16 *)&ret.a3; + + if (ids_processed >= max_ids - 1) + break; + + part_id = packed_id_list[++ids_processed]; + + if (!ids_count[list]) { /* Global Notification */ + __do_sched_recv_cb(part_id, 0, false); + continue; + } + + /* Per vCPU Notification */ + for (idx = 0; idx < ids_count[list]; idx++) { + if (ids_processed >= max_ids - 1) + break; + + vcpu_id = packed_id_list[++ids_processed]; + + __do_sched_recv_cb(part_id, vcpu_id, true); + } + } + } while (ret.a2 & NOTIFICATION_INFO_GET_MORE_PEND_MASK); +} + static int ffa_run(struct ffa_device *dev, u16 vcpu) { ffa_value_t ret; From patchwork Thu Aug 3 19:02:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13340790 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 1D87BC04FDF for ; Thu, 3 Aug 2023 19:03: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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mzL5i2uVbJ2BNK8BhpMikfKm/iK6kiEypRZIO/dThOI=; b=dl0E452+J4aQ7m 7I/sgJZpBD6dABirkKtf6eCDIF2fiEsL3+wRXToYRev6HydoKdyHIKNRiq04hEEUwKzF2LvVY7c3G khPoFNxlpkbhIZxAqYdy00trZMoZ2kJr1jvIMKUP/OLgREiat2m2jnWsd7DpxnbbJjIs0vE1Ck74m xS/0bc0H+Q+mC7bLXL7MYJ1d3UsA/x6Iy0/LHDf7dcjLb20Ju2NDSRMT/eTrGUhIi4uU5X8iy6VAn T/R0XUOwNZk2ZoGHrH8lF6AzFkJyTNFXWNB+kgvRO+sJUeUgoFbEWSre2V639SSNjYselYpiFjDOw htOf614u4wANqsCkBkjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdar-00Ah4a-2p; Thu, 03 Aug 2023 19:02: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 1qRdaj-00AgxS-2F for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9DBA21477; Thu, 3 Aug 2023 12:03:15 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 817323F6C4; Thu, 3 Aug 2023 12:02:31 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 08/12] firmware: arm_ffa: Initial support for scheduler receiver interrupt Date: Thu, 3 Aug 2023 20:02:12 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-8-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7308; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=cR9CtR2RFxlY81K/6ozS49XFT+Nzf9J2+LUO1GGNRM8=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iNo49Ygu4XVqY3+8BL3EjsrgF4PmJ1aetrb lHlAKERRtqJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jQAKCRAAQbq8MX7i mJ8GD/sHbjxENa8NCw2cX/z46yE1yjZob8hLmLa/1RN+15h/nHmMIVoyuXZss2ot3iqH3fr1aoC 1XoNTQiMMQlJUrVXGXF3MY+6iZ4aetC4fOOJFMEsjZ+wBYybMBaY/flkdnR/ng52D2MsW14c3bX gLI05ZzQxTxkb1OcwlufwaC+37SoR9oR1+8FbtSJJMgTf9TCg7QOFlfHQWrvvod+I79ZoxhdjTO 0kIq9CWF7NqLFkegK4Lf2J0oSnmheo75ElhwqmswxyjbyAm2PJtK1aqIkWW0rhrHTpTt0cCK4/s DSHkReVq5Tc0Osh00jzF3rTbHeOm6TVNrHTA5xsSAjMlg6FX30Z0UmFA5T8FupcuA99pKI3G5IX qMPKA8zQc4+Z6ja6K8tXI+LjCcqlzx944syuBPsf/T3t2q8sg2ON7Qr58eLjyqoBjU/s9c8u394 ukAhjpCDAbyQKYSnwT+5FB+/2OHc+Xesenx+plVAYON5GZ8jF3kVLCWA5aMn9ImbxDy7fudec1a 0mvDMwcPYt6Rs1IPevUV2L9DOZ1/nWoqqtvScR1EFp1ZxWuZiTXoO/iYkAP1/i2CzylZvnQo/Nx nLknDGYPgQAONFFV8UeG5Voc3rBBLnBNfUDS+f+nRLBla1i7duOINrPytoBKC7LL9hvw0NF6G+c 4cGpE7SH tSOTYLw== 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-20230803_120233_834056_A9D74D2D X-CRM114-Status: GOOD ( 21.41 ) 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 PPI. 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 | 183 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 175 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 77ca9753e3f0..84c934a0ec14 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -22,15 +22,20 @@ #define DRIVER_NAME "ARM FF-A" #define pr_fmt(fmt) DRIVER_NAME ": " fmt +#include #include #include +#include #include +#include #include #include #include #include +#include #include #include +#include #include #include "common.h" @@ -76,6 +81,10 @@ static inline int ffa_to_linux_errno(int errno) return -EINVAL; } +struct ffa_pcpu_irq { + struct ffa_drv_info *info; +}; + struct ffa_drv_info { u32 version; u16 vm_id; @@ -85,6 +94,12 @@ struct ffa_drv_info { void *tx_buffer; bool mem_ops_native; bool bitmap_created; + unsigned int sched_recv_irq; + unsigned int cpuhp_state; + struct ffa_pcpu_irq __percpu *irq_pcpu; + struct workqueue_struct *notif_pcpu_wq; + struct work_struct irq_work; + bool info_get_64b; }; static struct ffa_drv_info *drv_info; @@ -910,9 +925,147 @@ static void ffa_setup_partitions(void) kfree(pbuf); } +/* FFA FEATURE IDs */ +#define FFA_FEAT_NOTIFICATION_PENDING_INT (1) +#define FFA_FEAT_SCHEDULE_RECEIVER_INT (2) +#define FFA_FEAT_MANAGED_EXIT_INT (3) + +static irqreturn_t irq_handler(int irq, void *irq_data) +{ + struct ffa_pcpu_irq *pcpu = irq_data; + struct ffa_drv_info *info = pcpu->info; + + queue_work(info->notif_pcpu_wq, &info->irq_work); + + return IRQ_HANDLED; +} + +static void ffa_sched_recv_irq_work_fn(struct work_struct *work) +{ + struct ffa_drv_info *info = container_of(work, struct ffa_drv_info, + irq_work); + + ffa_notification_info_get(info->info_get_64b); +} + +static int ffa_sched_recv_irq_map(void) +{ + int ret, irq, sr_intid; + + ret = ffa_features(FFA_FEAT_SCHEDULE_RECEIVER_INT, 0, &sr_intid, NULL); + if (ret < 0) { + if (ret != -EOPNOTSUPP) + pr_err("Failed to retrieve scheduler Rx interrupt\n"); + return ret; + } + + if (acpi_disabled) { + struct of_phandle_args oirq = {}; + struct device_node *gic; + + 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); + } else { + irq = acpi_register_gsi(NULL, sr_intid, ACPI_EDGE_SENSITIVE, + ACPI_ACTIVE_HIGH); + } + + if (irq <= 0) { + pr_err("Failed to create IRQ mapping!\n"); + return -ENODATA; + } + + return irq; +} + +static void ffa_sched_recv_irq_unmap(void) +{ + if (drv_info->sched_recv_irq) + irq_dispose_mapping(drv_info->sched_recv_irq); +} + +static int ffa_cpuhp_pcpu_irq_enable(unsigned int cpu) +{ + enable_percpu_irq(drv_info->sched_recv_irq, IRQ_TYPE_NONE); + return 0; +} + +static int ffa_cpuhp_pcpu_irq_disable(unsigned int cpu) +{ + disable_percpu_irq(drv_info->sched_recv_irq); + return 0; +} + +static void ffa_uninit_pcpu_irq(void) +{ + if (drv_info->cpuhp_state) + cpuhp_remove_state(drv_info->cpuhp_state); + + if (drv_info->notif_pcpu_wq) + destroy_workqueue(drv_info->notif_pcpu_wq); + + if (drv_info->sched_recv_irq) + free_percpu_irq(drv_info->sched_recv_irq, drv_info->irq_pcpu); + + if (drv_info->irq_pcpu) + free_percpu(drv_info->irq_pcpu); +} + +static int ffa_init_pcpu_irq(unsigned int irq) +{ + struct ffa_pcpu_irq __percpu *irq_pcpu; + int ret, cpu; + + irq_pcpu = alloc_percpu(struct ffa_pcpu_irq); + if (!irq_pcpu) + return -ENOMEM; + + for_each_present_cpu(cpu) + per_cpu_ptr(irq_pcpu, cpu)->info = drv_info; + + drv_info->irq_pcpu = irq_pcpu; + + ret = request_percpu_irq(irq, irq_handler, "ARM-FFA", irq_pcpu); + if (ret) { + pr_err("Error registering notification IRQ %d: %d\n", irq, ret); + return ret; + } + + INIT_WORK(&drv_info->irq_work, ffa_sched_recv_irq_work_fn); + drv_info->notif_pcpu_wq = create_workqueue("ffa_pcpu_irq_notification"); + if (!drv_info->notif_pcpu_wq) + return -EINVAL; + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "ffa/pcpu-irq:starting", + ffa_cpuhp_pcpu_irq_enable, + ffa_cpuhp_pcpu_irq_disable); + + if (ret < 0) + return ret; + + drv_info->cpuhp_state = ret; + return 0; +} + +static void ffa_notifications_cleanup(void) +{ + ffa_uninit_pcpu_irq(); + ffa_sched_recv_irq_unmap(); + + if (drv_info->bitmap_created) + ffa_notification_bitmap_destroy(); +} + static int ffa_notifications_setup(void) { - int ret; + int ret, irq; ret = ffa_features(FFA_NOTIFICATION_BITMAP_CREATE, 0, NULL, NULL); if (!ret) { @@ -924,13 +1077,23 @@ static int ffa_notifications_setup(void) } drv_info->bitmap_created = true; - return 0; -} + irq = ffa_sched_recv_irq_map(); + if (irq <= 0) + goto cleanup; -static void ffa_notifications_cleanup(void) -{ - if (drv_info->bitmap_created) - ffa_notification_bitmap_destroy(); + if (FFA_FN_NATIVE(NOTIFICATION_INFO_GET) == + FFA_FN64_NOTIFICATION_INFO_GET) + drv_info->info_get_64b = true; + + ret = ffa_init_pcpu_irq(irq); + if (ret) + goto cleanup; + + drv_info->sched_recv_irq = irq; + return 0; +cleanup: + ffa_notifications_cleanup(); + return ret; } static int __init ffa_init(void) @@ -988,7 +1151,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 Aug 3 19:02:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13340789 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 2D6E3C04A6A for ; Thu, 3 Aug 2023 19:03:08 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RbSS4nSRPGhrPvun1ZW0er6p9+Xyv3PUUe416G1FpCY=; b=yISWqpSowOU5B2 oNWLKeGXbHsofJPhaZtBz6YhPB2kA2GFVbccBymi3ZNPpZntZbixYVoS8g9xDIpx/ZbrdtlWqAQyC jj05ax/HoQ/p3ia6M1Plm0/fMS9YUD4F08SBNdTkA2AEyOR54jKP6dHGV1BbAOdOuOUTftyg6im7V at8/AYb+5CmmBeJYHYXHW7eIfOwVZwikWO9faGPrlAi8TBWsvJLf1BVgbJ3J6KChHqAmWQ9PpR4zp k7JpA0bSq7pQ0zVWywkWb25Iui0oYCbuWDCi07O+yKZyQ8VY6MnZb6JSpwytSJ/lc4Qw9Ttc1lwdi LTMo5JT12vlNeAzXf6WA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdat-00Ah5y-07; Thu, 03 Aug 2023 19:02: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 1qRdal-00AgwT-0m for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:37 +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 0106112FC; Thu, 3 Aug 2023 12:03:17 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D95F03F6C4; Thu, 3 Aug 2023 12:02:32 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 09/12] firmware: arm_ffa: Add schedule receiver callback mechanism Date: Thu, 3 Aug 2023 20:02:13 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-9-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6832; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=is99x5WtN5I+1PV/Gr1xhpxo7rZkJNsfbfoP44fgG94=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iN6rgWBsUFDTXfWWyMA5KWKxw/WwXCIKLyy 0R/LP1t79KJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jQAKCRAAQbq8MX7i mJzlD/4nf825CYD8VReXGA+ZJqTwcQzIdq/o3AJhW+cuSTy1+0S44QJe6K0xHFYv67WXTlfTnux 4bXgHDudrmOtgxAYAqOYJNbL8wO00oFLE1ContSBxROX3k/0svjlnUtyDVZUNyhHU6M152IB0jF CZ7ewBYpsbm2Ln2p8csOS/mPdoG4t1AVc3HMxVWJfj8mk7VYcAIK2OdN5S1yLdHTAM1BVpP1NoN kJH/X8HDex/rCmmF08GmekS0UXkzWZo/dexB3nHicLp83U0gUqKfA6maj6Z6cnzeJ+IRmFzUw0y OBmVKP1CrVjN16drccwa+TQIdt2xR0aeIjN1yltHih8U10BrvFwmf/fMCHZALKNTrXEXoF6wtcw lF0h9od3Vfib0umuI5B11miFaBDucFpOKqouW3/zm1iuCupAAI00zp213PK/84joxIrZM5gd6rW h9AeuCnYocRMwiTdU7kk8teoSV0mcMDNDD2Efq+S4WgtyQXQn/6ZhZjq9nv7uuREADy9kzvl3Vw Ymb+rC1JY+z2tQfmJ3OFuWCPhNl3LQTlbMs1aQozOHS1tXNQ8mdACDjZFA6gR6aicjXUXcsmQf2 jTSeNz3RClSoH2YXTAaOhZnhw79enOXXe2G0I9q6BMxsfg7BIGbGCTBdR6cS+PkTJlOn4a1Acgn qRDpxP5H Gi0qTbw== 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-20230803_120235_387779_D8B16CE9 X-CRM114-Status: GOOD ( 18.89 ) 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 | 102 ++++++++++++++++++++++++++++++++++++-- include/linux/arm_ffa.h | 9 ++++ 2 files changed, 108 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 84c934a0ec14..54fca776e5d8 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "common.h" @@ -100,6 +101,8 @@ struct ffa_drv_info { struct workqueue_struct *notif_pcpu_wq; struct work_struct irq_work; bool info_get_64b; + struct xarray partition_info; + unsigned int partition_count; }; static struct ffa_drv_info *drv_info; @@ -683,9 +686,25 @@ 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); + + callback(part_id, vcpu, is_per_vcpu, cb_data); } static void ffa_notification_info_get(bool is_64b) @@ -839,6 +858,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, @@ -859,11 +911,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) @@ -894,6 +952,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); @@ -902,6 +961,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); @@ -921,10 +981,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) @@ -1153,9 +1245,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); @@ -1171,9 +1265,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..63f2e1f5fdc4 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -391,11 +391,20 @@ struct ffa_cpu_ops { int (*run)(struct ffa_device *dev, u16 vcpu); }; +typedef void(*ffa_sched_recv_cb)(u16 partition_id, 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 Aug 3 19:02:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13340792 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 20D25C41513 for ; Thu, 3 Aug 2023 19:03:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7FZ5TI3J5un5FWzn/7Xj5b89E71G5xbhQj84nNfrmcU=; b=OV/D8QA/Kk+w8K 8di25CMYEk1NqBztZL6Img8p0bXz2g/tdfvwlrrhpKpJuxJ0roSg6sxss+qVCQ3QMaphgBY3NBoZm DCBJ7YkVg1F7iMKK0mV8TEDMQFIVYVAhJdOzqiTfh4Ep6v4zKJko/Tsar+/tebGfJNhSowvkIvJ+X 53LSL0a7HWu2sNlFknOn0RMDQEgKOl49pzTfpXHtN9iuWtNimgTZQl1yNRoNhlYQGcQWLTJnywyA6 GcQ6gRbTsHQljadbfWVOqOIQzMpS1i80oinOOMLXVX6Lo5M1WYoKnbtB+zq1zEOrg8gLv58ZlwlyW bcDcxkl9LW0WTwQVXnRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdas-00Ah5T-1W; Thu, 03 Aug 2023 19:02:42 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdal-00AgwP-1x for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:37 +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 59004113E; Thu, 3 Aug 2023 12:03:18 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3DC7B3F6C4; Thu, 3 Aug 2023 12:02:34 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 10/12] firmware: arm_ffa: Add interfaces to request notification callbacks Date: Thu, 3 Aug 2023 20:02:14 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-10-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6618; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=qRF9OB5UOVl/Be6YUQOHzq1xMEFWDG0OS9Avnbmk21A=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iO9aX61DhQFM6JoVap5dmKBG3eS7G5cKSaq NdhCUr47UeJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jgAKCRAAQbq8MX7i mJehEACbjnTfB37YuPYdsBOXuPhf6FQNyCNBdlRuRWfYG7fL2TClyp9hlhGgkg+8FU7oI1SGPqE Bcl0wKOsd0LKRUpV1QdWHyCA3p9EK/+41J/LtXcDXjB9eNSltAW6+EOFG+m2+Zpe15r/WNXnwhx MnQtDjrE++Z1kcmqhzbyLsi6tfxaBKkLh1LGNzm/CIZ7TLe9blNkltWMehbci2DZvrbtAi21YyM xREdgLLEwZRpmr6V+g+i3X70Spd8e5EyzBo6Z/jJV/59vaMEHw+71gu1wWG5Cbn+es4f31LIIo9 3nBWV2KYB57m08F4GxzKHkwlM/Bm4SuOMw/SGwIJuqbprs9L/SoWVlgNeKykqkmulbeIQs8qVaV l/57wWYuTqBZeFovCvz0fjY6rh1jp8sSOZXI27Z0kVU5rXg85k/65lLRQPktl9snGi2f4NX1064 ORxjrnjCUDzx9uUaiQu6NfyqjnTNWxLfLijQrbzLbnSX5NcLrdJHKnY/L6/UgPPaCVszdfbfn1M JseXJt2/6lea5sZd9UWc/gvlLTWgDlfA7Vzh3r4UD9yGF3PZrcvD74+YK+cU3qj/sO7dQJgOE3U /g5pohHD2Vylk2be6Spzujz0uhDEv+sIQa+CVrdDWQEgGy22Vmn7Ilx8zgmpTDhtP2TF71NsjoN aUFAQX7s xTEUlJQ== 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-20230803_120235_746728_9C8A71DA 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 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 | 130 ++++++++++++++++++++++++++++++++++++++ include/linux/arm_ffa.h | 5 ++ 2 files changed, 135 insertions(+) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 54fca776e5d8..29f69f7010c9 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -27,11 +27,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -57,6 +59,8 @@ */ #define RXTX_BUFFER_SIZE SZ_4K +#define FFA_MAX_NOTIFICATIONS 64 + static ffa_fn *invoke_ffa_fn; static const int ffa_linux_errmap[] = { @@ -103,6 +107,8 @@ struct ffa_drv_info { bool info_get_64b; struct xarray partition_info; unsigned int partition_count; + DECLARE_HASHTABLE(notifier_hash, ilog2(FFA_MAX_NOTIFICATIONS)); + struct mutex notify_lock; /* lock to protect notifier hashtable */ }; static struct ffa_drv_info *drv_info; @@ -615,6 +621,9 @@ static int ffa_notification_bitmap_destroy(void) #define MAX_IDS_64 20 #define MAX_IDS_32 10 +#define PER_VCPU_NOTIFICATION_FLAG BIT(0) +#define ALL_NOTIFICATION_BITMAPS_FLAGS (0xF) + static int ffa_notification_bind_common(u16 dst_id, u64 bitmap, u32 flags, bool is_bind) { @@ -858,6 +867,13 @@ static int ffa_memory_lend(struct ffa_mem_ops_args *args) return ffa_memory_ops(FFA_MEM_LEND, args); } +struct notifier_cb_info { + struct hlist_node hnode; + ffa_notifier_cb cb; + void *cb_data; + u16 vm_id; +}; + static int ffa_sched_recv_cb_update(u16 part_id, ffa_sched_recv_cb callback, void *cb_data, bool is_registration) { @@ -891,6 +907,114 @@ 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 part_id, u16 notify_id) +{ + struct notifier_cb_info *node; + + hash_for_each_possible(drv_info->notifier_hash, node, hnode, notify_id) + if (part_id == node->vm_id) + return node; + + return NULL; +} + +static int +update_notifier_cb(u16 part_id, int notify_id, 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(part_id, notify_id); + 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->vm_id = part_id; + 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 int ffa_notify_relinquish(struct ffa_device *dev, int notify_id) +{ + int rc; + + if (notify_id >= FFA_MAX_NOTIFICATIONS) + return -EINVAL; + + mutex_lock(&drv_info->notify_lock); + + rc = update_notifier_cb(dev->vm_id, notify_id, 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; + + 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(dev->vm_id, notify_id, 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)); + return rc; + } + 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, @@ -914,6 +1038,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 = { @@ -1182,6 +1308,10 @@ static int ffa_notifications_setup(void) goto cleanup; drv_info->sched_recv_irq = irq; + + 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 63f2e1f5fdc4..99440129b733 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -393,10 +393,15 @@ struct ffa_cpu_ops { typedef void(*ffa_sched_recv_cb)(u16 partition_id, u16 vcpu, bool is_per_vcpu, void *cb_data); +typedef void (*ffa_notifier_cb)(u16 part_id, 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 Aug 3 19:02:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13340791 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 0ACF9C001DB for ; Thu, 3 Aug 2023 19:03:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6k5nq904HHL8keFZiJpQl9UrFTpoA6ZVpJgnOhdsLnw=; b=0STId8+gkY1m4k D60qLr2X4Vikpu/TBUOBSFmh9nfi8WOtfyEg42657v41/YBKvBUFEx8dBES8ecYy6V2cjuosFg9xc pc3eyvE2YlPxbmDXbwOeBhZj3eJz6SU/ezuJxcwARxOmZSLAc7Fq+72Az4/y4mO8boAa6mK/aHnM7 BgHvP9y0t2GxDJ9QU0Go4iV33rp3vq0DRFp4JVGn+fYSdRX+Vq8255BouDhQY8vCExH0PaErIfemk kydHBZCNXuvqQHaaLbNNBZtVvBmDaV0eqJpoDMB+FELP0fihj+XMRVrfixmYwOXG0DudCt+FYC3JM xFx+OR7n2yN/rS9fHNNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdat-00Ah6U-1o; Thu, 03 Aug 2023 19:02: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 1qRdan-00AgwO-07 for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:39 +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 B14581474; Thu, 3 Aug 2023 12:03:19 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 95BB03F6C4; Thu, 3 Aug 2023 12:02:35 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 11/12] firmware: arm_ffa: Add interface to send a notification to a given partition Date: Thu, 3 Aug 2023 20:02:15 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-11-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 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=8wR5nAQmif3IV58CHUtYI7AoPHUdSNE2CQ+LZOQjskw=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iOv1HNBdEX3FhKzkZotN+AhpxIqQqaUxIht 4xzQN93ADKJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jgAKCRAAQbq8MX7i mLCpEACLQdZqfIGT2MeCv8uDmtpNpBXhU4pq0R58YJj1iTIeDSW/Sn6pVA5wPRgLDkwUSqZxAoE XbaE4Ewo/KUkXXnLY1kPZfKslpX5hPwgcguJK0fZescHMeK3lBqTCJvHlR7aLk3NboxpxCQyNYI FLOi/NUwsLGmYq3zRyJGzQ8E8Lo6FYVDfI0y7B6yv2GL29PKMcw1NI7dJLpTy/3wBdaEiotCi66 TSFsqrDBFXUwpxzrttsxGRc08EXwLH4Yjg+4cQSFXEdVWGfURKUXlHYHD6ClvTQMdSev5JsIXdZ Pgn4PMT2LLEPX6haBwPFXPIPSpzvAX2mTt6/Qb49aj2Lm3VWVbIosKaehnZg7RAwJhfR+0UdeHy yDtGtlKxNL5CYRg0UeT7G4Fi6h4KVy+IKtgCKeBpYlQvlxfwc2kH6TizN01d+qNwFmEiXKsRBj6 Gy0US0wZmwk8/5IMDUjSTtv3L0JrenLMRjP0dgMPB6jWXK4Kp9TLKD+9/QpRFVdq4fkkJRh9x13 JgiudN1I6fQ4UvPKNJoNmUHNS330p1PAKb4gkUnEBfM9aFL0D2iYw+qwc873m7ReIa5v2QNw9Vz eU8NuzLx7cdXRAooHTejIaQcmXFzuU/GzA/HupcAXQdJCUGFDdm5V3QFVrUIe16m/u/HSVqzPxV +yxpERWJ APVWPEg== 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-20230803_120237_167483_2E667B60 X-CRM114-Status: GOOD ( 13.01 ) 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 29f69f7010c9..d98d0fbe5605 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -1015,6 +1015,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, @@ -1040,6 +1052,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 99440129b733..3bba5f999e4f 100644 --- a/include/linux/arm_ffa.h +++ b/include/linux/arm_ffa.h @@ -402,6 +402,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 Aug 3 19:02:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13340793 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 9689CC001DB for ; Thu, 3 Aug 2023 19:03:16 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=J5xP5aHfRWpKrWFDV+NXY9ptm8vqiAgBZzUMCF8wK08=; b=fzkkCo8qI1mgXT rmNF2iEcwAgLgd9NqX9TUtEGQmDesRsjgoX4P1uw67o2Eo/torX0FPs8TlS4P0WrNnPzc/HtcwQJL neMjckZkxoh4xpLVFX2k6kK2f3Mi8cnEnZvrXR4p++/NhEy34ozWmtAXua6/+a6WJMMfzXDAggrSW WCeUcoFTMS/7fE9Ds4aLoHPHVBoBhUm+Ap6nDhFAoTJxfN/Y0WwmdZdk5G4mFy7Bf8ICKZkWM+kj5 fpZCpLoRfnxOaSv4WbdjL2lmB/aT12hBBWn0ve8+RyqmVRPX3qJcUNV+QvIUt+nRk5/JFMYXLIDPz 8tKpBFGjuYfI9nn/CJuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdb0-00AhAH-0u; Thu, 03 Aug 2023 19:02:50 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRdap-00Ah1t-32 for linux-arm-kernel@lists.infradead.org; Thu, 03 Aug 2023 19:02:41 +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 159F31477; Thu, 3 Aug 2023 12:03:21 -0700 (PDT) Received: from usa.arm.com (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EE5F43F6C4; Thu, 3 Aug 2023 12:02:36 -0700 (PDT) From: Sudeep Holla To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Sudeep Holla , Jens Wiklander , Lucian Paul-Trifu , Marc Bonnici , Coboy Chen Subject: [PATCH RFT 12/12] firmware: arm_ffa: Add notification handling mechanism Date: Thu, 3 Aug 2023 20:02:16 +0100 Message-ID: <20230803-ffa_v1-1_notif-v1-12-6613ff2b1f81@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> References: <20230803-ffa_v1-1_notif-v1-0-6613ff2b1f81@arm.com> MIME-Version: 1.0 X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3617; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=alNQ8WKZzdLc226LuzWNQjd8s+t3f1uUa9m/aytNi74=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBky/iOoWGRp8MIkYKLKd/x+ellGoFwhm3RhX3kz sKucyPu4VCJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZMv4jgAKCRAAQbq8MX7i mPDcEADPet/4EO7Br+XNllMSOUk+R0E485k23G+eMp9JL6aTv25MKnHpCBeB1peYYV7olLJ7t0n uEGziIcBnphjXKyQPp3Y7VjrPbXa4dqRUJvfVxvGzMFcX62lAP3ZXtgeqY2PS0p1Get13IgBBCr CPB368Q8teY84JnzlCWVvNJik+FfWneVKQiyn7+KMVagA/rXueVthuBBQ9HI6RYGKzk/aT2YV/C I0S3gyinCVWCXUAdeXADVaDyIrRs20AtVqs6e2UhPApN9Y8Az5dIDV+1LVEI8bXuKOtGpuqktjQ 3tlEaHe7rlVYYJEBrpivp2VTtZLKZVYB+aRtyyFUNVa6wJNLySLr////uUd9twpMoStIa6sdaI8 aDRZLQ7u02Qs7ytjtYnNqKYoY5FGAmwdH6AN5YuIERO3hCJe6bzs3Q/vn0Rek9YcxNJkLtQM49X Q6/EhcX6RGvqvs9CYGwZjKLEN4qwIuLMFqQXGJek2YZ1zN61C96rjlYV0iLjzFlbFn2nNY29xfD bR8tIekEK8fuF7tLJyy7uIsN6K9jCpsx3Um42ZV+9aTYop7zuP9WMHlgpOvg0haxXaSlMKo52Kd 39VfO9lywpdqe17XkyHDZ/lBbL4Of1d6v/rYtrPAW4TOI+WJp2kmwKZwYEIDT1ctelZtcQq62lh rS9GM59D ta7ofVg== 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-20230803_120240_083944_22BA26EB X-CRM114-Status: GOOD ( 16.50 ) 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 | 61 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index d98d0fbe5605..63daef95b048 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -103,6 +103,7 @@ struct ffa_drv_info { unsigned int cpuhp_state; struct ffa_pcpu_irq __percpu *irq_pcpu; struct workqueue_struct *notif_pcpu_wq; + struct work_struct notif_pcpu_work; struct work_struct irq_work; bool info_get_64b; struct xarray partition_info; @@ -1027,6 +1028,54 @@ static int ffa_notify_send(struct ffa_device *dev, int notify_id, BIT(notify_id)); } +static void handle_notif_callbacks(u64 bitmap, u16 part_id) +{ + int i = 0; + struct notifier_cb_info *cb_info = NULL; + + while (bitmap) { + if (bitmap & 1) { + mutex_lock(&drv_info->notify_lock); + cb_info = notifier_hash_node_get(part_id, i); + mutex_unlock(&drv_info->notify_lock); + if (cb_info->cb) + cb_info->cb(part_id, i, cb_info->cb_data); + } + i++; + bitmap >>= 1; + } +} + +static void notif_pcpu_irq_work_fn(struct work_struct *work) +{ + int rc; + struct ffa_notify_bitmaps bitmaps; + struct ffa_drv_info *info = container_of(work, struct ffa_drv_info, + notif_pcpu_work); + + rc = ffa_notification_get(ALL_NOTIFICATION_BITMAPS_FLAGS, &bitmaps); + if (rc) { + pr_err("Failed to retrieve notifications with %d!\n", rc); + return; + } + + handle_notif_callbacks(bitmaps.vm_map, info->vm_id); + handle_notif_callbacks(bitmaps.sp_map, info->vm_id); + handle_notif_callbacks(bitmaps.arch_map, info->vm_id); +} + +static void +ffa_self_notif_handle(u16 part_id, 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, @@ -1128,7 +1177,12 @@ static void ffa_setup_partitions(void) } xa_store(&drv_info->partition_info, tpbuf->id, info, GFP_KERNEL); } - drv_info->partition_count = count; + /* 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 = count + 1; kfree(pbuf); } @@ -1270,6 +1324,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; @@ -1325,7 +1380,9 @@ static int ffa_notifications_setup(void) hash_init(drv_info->notifier_hash); mutex_init(&drv_info->notify_lock); - return 0; + /* Register internal scheduling callback */ + return ffa_sched_recv_cb_update(drv_info->vm_id, + ffa_self_notif_handle, drv_info, true); cleanup: ffa_notifications_cleanup(); return ret;