From patchwork Tue Aug 20 14:27:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13770225 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 3EB37C3DA4A for ; Tue, 20 Aug 2024 14:33:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+oD/hV5S024XBNJB+roKxBTw+HcmfynLqt2BZxGCG3M=; b=3En3vZaDaH13mekgd9tR95BHnz 4k9x8ka9PQ5SmQjYU2bSZUAV4XbVwRgc/zV0TnZGueMUsKjPLqOoPG1SD5CBqHAToiHTdoo8tyvGw KHwoQIHOL6M9ZfoZxY9CrAhlxv3ndnvKKVm8Kmm1Y4OpfnMYqa2/fyiXkqf5aj+P1KtYXL7gDgrXw XodritUnEq0qzKimu59KYopZIa6JdEbT8b26r17q4f37yt2L4wjywUWOTsA1QlSsCaynJtD0ULATx nFT0V8BcLj5ovy/Fw7PA8F0in7SQSb05/m56pl8owmB3SXCS/UTenI2M0an4yNZaZGeeUJmWh5KuW wd8pw2lg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgPv6-00000005Z9d-2ykW; Tue, 20 Aug 2024 14:33:12 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgPqy-00000005Y9o-0FJO for linux-arm-kernel@lists.infradead.org; Tue, 20 Aug 2024 14:28:59 +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 249A61515; Tue, 20 Aug 2024 07:29:21 -0700 (PDT) Received: from [127.0.1.1] (e107155-lin.cambridge.arm.com [10.1.198.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A8BC33F66E; Tue, 20 Aug 2024 07:28:54 -0700 (PDT) From: Sudeep Holla Date: Tue, 20 Aug 2024 15:27:59 +0100 Subject: [PATCH v2 6/7] firmware: arm_ffa: Add support for FFA_YIELD in direct messaging MIME-Version: 1.0 Message-Id: <20240820-ffa_v1-2-v2-6-18c0c5f3c65e@arm.com> References: <20240820-ffa_v1-2-v2-0-18c0c5f3c65e@arm.com> In-Reply-To: <20240820-ffa_v1-2-v2-0-18c0c5f3c65e@arm.com> To: linux-arm-kernel@lists.infradead.org, Sudeep Holla , op-tee@lists.trustedfirmware.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2597; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=UPzZl1vZFx+imzj6babsbM3+MYlge8k3jow5sCrZRaI=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBmxKgiz4HZYMztfxBqlSIPr2ZTREJKYnNjPx39F BhlnrU1T9+JAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZsSoIgAKCRAAQbq8MX7i mHGQD/9bh6tkVePADuGMWm9yYai7OBCM7cs+lbqXBcEtshAKZyroHyc9LUTAjr12cfp6swTtG1r Zfxnaf1LZYIVF+dfxOZm3AJQUPX6q7mhDWfpUhNvE4a4AGu5SP39uln9ZlHdFtN3mFYMHhtDZNd 1H9mj4pehqZYuXolTedxNRXQT6Pk9bIe7iOiVVPETbDAxQhbAyl9602DvB2JAlR+8aVKh0oxXXJ LYjxsGcITYeyMTQrst32snsQYNLV0YdJRw3ld8ruVdItucVi1tMgcCVZprMRFHRWos57FhYRFYu tyUczrpKoYC1+u7/+b11mjIm7kF9jWA8m3q8wZ6hy7GDMvwIgoy/Oh0xbXw6SmH2W6MK4N8I1yG FlG8SDPspc96IMGAZB0KYTZ7Ne7T49upq09Bwj7GSxYT6lIOsHzWGrXQv0+NHqObXTLJDzv6ILr htGqfTGyOk9Z2foIA5IdfagSN+2KEjlM04Pz4SogdJW5AZhXnll6zUipK/A4HiqT4PpXaMsJSs9 ferHO44lYd+//UAdC16yVfrcLOtaLR+5fWVzXdPUX+F8P50nWAjWJVIiPsszWo5PZhEf+zZFzN5 UGDDq5O8ytElBk0KVQHpXHG3ybKB+w7NJvVJAH0449FNuP/X2nHe2VsDQDJWsAx9CSDlUhLgy+s 0FfjZPeEdsyF1lQ== 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-20240820_072856_533261_E22F001C X-CRM114-Status: GOOD ( 13.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Successful completion of both direct messaging function can be indicated through an invocation of FFA_YIELD or GGA_INTERRUPT by the callee. FFA_INTERRUPT indicates that the direct request was interrupted and must be resumed through the FFA_RUN interface which is already done in the driver. FFA_YIELD indicates that the receiver endpoint has transitioned to the blocked runtime state and must be resumed through the FFA_RUN interface. However, the way receiver endpoint gets unblocked is implementation defined. So, the driver just sleeps for 1 - 2ms and issues FFA_RUN. It can return to the caller with FFA_YIELD is the receiver endpoint is still blocked. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index ec99fed5715d..d47272859190 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -397,6 +398,18 @@ static int ffa_id_get(u16 *vm_id) return 0; } +static inline void ffa_msg_send_wait_for_completion(ffa_value_t *ret) +{ + while (ret->a0 == FFA_INTERRUPT || ret->a0 == FFA_YIELD) { + if (ret->a0 == FFA_YIELD) + fsleep(1000); + + invoke_ffa_fn((ffa_value_t){ + .a0 = FFA_RUN, .a1 = ret->a1, + }, ret); + } +} + static int ffa_msg_send_direct_req(u16 src_id, u16 dst_id, bool mode_32bit, struct ffa_send_direct_data *data) { @@ -417,10 +430,7 @@ static int ffa_msg_send_direct_req(u16 src_id, u16 dst_id, bool mode_32bit, .a6 = data->data3, .a7 = data->data4, }, &ret); - while (ret.a0 == FFA_INTERRUPT) - invoke_ffa_fn((ffa_value_t){ - .a0 = FFA_RUN, .a1 = ret.a1, - }, &ret); + ffa_msg_send_wait_for_completion(&ret); if (ret.a0 == FFA_ERROR) return ffa_to_linux_errno((int)ret.a2); @@ -482,10 +492,7 @@ static int ffa_msg_send_direct_req2(u16 src_id, u16 dst_id, const uuid_t *uuid, invoke_ffa_fn(args, &ret); - while (ret.a0 == FFA_INTERRUPT) - invoke_ffa_fn((ffa_value_t){ - .a0 = FFA_RUN, .a1 = ret.a1, - }, &ret); + ffa_msg_send_wait_for_completion(&ret); if (ret.a0 == FFA_ERROR) return ffa_to_linux_errno((int)ret.a2);