From patchwork Tue Aug 20 14:27:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13770224 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 065B8C3DA4A for ; Tue, 20 Aug 2024 14:32:46 +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=hcCm5p5YH8b7Sms6yK/prYpfg8T+r6zExw2mnBIIZOc=; b=zcvgpmlTbjbRnxLmdpqUn0EOys 9K0JX7lBLQl13C49orzA7ns0PNa2tZcpxZdTUSukML2HDjFvHp5gAjZ2WnLivCPaiGJk1S02YUwc1 KzHeURPgtq35cc6AIjfVuSC19YX4N5YY1FyUCbYSEcQOWqimW20gfwI0cOP4NmA2HAVvECZSvMlez OJ5CW8iq++FKCrtGCZUzrCn4Sdq55ULHl1JpjBa4JaBlXMnJVZ0OqsyFJ8umRbQpag3HPZGdXY1xC pNxxxKk8nkuD0HVN0DMfC4rtQ8wDtTfPprYRXFBQhQtN9Qc0X2yH90LOfv/u64GUtcmixUrSv5N1V BtvjBxHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgPuR-00000005Z2W-3Z5B; Tue, 20 Aug 2024 14:32:31 +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 1sgPqx-00000005Y7D-3kvU for linux-arm-kernel@lists.infradead.org; Tue, 20 Aug 2024 14:28:58 +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 D6FC61480; Tue, 20 Aug 2024 07:29:19 -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 66D443F66E; Tue, 20 Aug 2024 07:28:53 -0700 (PDT) From: Sudeep Holla Date: Tue, 20 Aug 2024 15:27:57 +0100 Subject: [PATCH v2 4/7] firmware: arm_ffa: Add support for FFA_PARTITION_INFO_GET_REGS MIME-Version: 1.0 Message-Id: <20240820-ffa_v1-2-v2-4-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=3998; i=sudeep.holla@arm.com; h=from:subject:message-id; bh=FaVILUQPog5h0RCQzSV1xOE1pS2YhfiWm3kuEfz+kUc=; b=owEBbQKS/ZANAwAIAQBBurwxfuKYAcsmYgBmxKgi9j49RTTtANoX8+PTTJahlBUwVmxlT+aKB ani/XphD8SJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZsSoIgAKCRAAQbq8MX7i mJlIEACANYQ0HdvQ9FXLK/aPt/XrKXyjqGeQ6hHkWWGu25gxSQ4zVDddJ/4RT3q+zz+EnGhKcOn 42ZsgudDiW7opNxuj9tBTohAEruz9AShAXMfjSEXrkKcYHBYVqLzQ6C8mg4f1UqJJ4bnD6Y3BZz lFIsDWxND/XBld8cAWK7FyysxWwpcZobp7OLi7bx+yxl1lIH7psDm/xkm6CTR76aaslW1QvNu03 TrFMSQZODb5m/PGXEwBpIbo2q1YTyLtjghiEyZkfUlMrJUquySBWYenoU7JaxteRIVkipGFELHm GZcFEFVGPewDFXJ6EpwEBQGYRrbJLm0DTwhZs8827mWyLikp6qKX5+8QV9wIdgfO1gw340tpcrR BCrbXH6QhkL0DkLUUZVFm/OTXVD5y55uR/cRd22lgTqhMDehmKcW89vmXRcGvhKEL/gPIEk2syb ecRvsSPTf8CuC/2kTIq0pr3gpbxWnSGkOgyI/oGRz4A+0lY/EdCXjL/H2HNwZB4XI5qH81D/fDD TIZGOfnrWmpRk95bNS+LRtp/Bstkd8cna1429z5KDGMEH0RBLgfKyt0SVKNvbmHdvW2+zrEXKI6 VoYlXI/a+gKA4N40/y84S0E+BiNEKufX+qC10MGWffZMdOWcpR4ZVD8QuDifK4umC8pqKF0ZnSq tZtIFCunAX620Jw== 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_409137_4CE4F7A3 X-CRM114-Status: GOOD ( 15.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org FF-A v1.2 introduced FFA_PARTITION_INFO_GET_REGS which is similar to FFA_PARTITION_INFO_GET except that the former uses the registers to get the required information instead of the Rx buffer which the latter uses. We need to first check if the platform supports this new API using FFA_FEATURES so that we can fallback to the FFA_PARTITION_INFO_GET (which is mandatory) if FFA_PARTITION_INFO_GET_REGS is not implemented. Signed-off-by: Sudeep Holla --- drivers/firmware/arm_ffa/driver.c | 72 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c index 91681933ece9..e28cbfe9a801 100644 --- a/drivers/firmware/arm_ffa/driver.c +++ b/drivers/firmware/arm_ffa/driver.c @@ -287,17 +287,75 @@ __ffa_partition_info_get(u32 uuid0, u32 uuid1, u32 uuid2, u32 uuid3, return count; } +#define LAST_INDEX_MASK GENMASK(15, 0) +#define CURRENT_INDEX_MASK GENMASK(31, 16) +#define UUID_INFO_TAG_MASK GENMASK(47, 32) +#define PARTITION_INFO_SZ_MASK GENMASK(63, 48) +#define PARTITION_COUNT(x) ((u16)(FIELD_GET(LAST_INDEX_MASK, (x))) + 1) +#define CURRENT_INDEX(x) ((u16)(FIELD_GET(CURRENT_INDEX_MASK, (x)))) +#define UUID_INFO_TAG(x) ((u16)(FIELD_GET(UUID_INFO_TAG_MASK, (x)))) +#define PARTITION_INFO_SZ(x) ((u16)(FIELD_GET(PARTITION_INFO_SZ_MASK, (x)))) +static int +__ffa_partition_info_get_regs(u32 uuid0, u32 uuid1, u32 uuid2, u32 uuid3, + struct ffa_partition_info *buffer, int num_parts) +{ + u16 buf_sz, start_idx, cur_idx, count = 0, prev_idx = 0, tag = 0; + ffa_value_t partition_info; + + do { + start_idx = prev_idx ? prev_idx + 1 : 0; + + invoke_ffa_fn((ffa_value_t){ + .a0 = FFA_PARTITION_INFO_GET_REGS, + .a1 = (u64)uuid1 << 32 | uuid0, + .a2 = (u64)uuid3 << 32 | uuid2, + .a3 = start_idx | tag << 16, + }, &partition_info); + + if (partition_info.a0 == FFA_ERROR) + return ffa_to_linux_errno((int)partition_info.a2); + + if (!count) + count = PARTITION_COUNT(partition_info.a2); + if (!buffer || !num_parts) /* count only */ + return count; + + cur_idx = CURRENT_INDEX(partition_info.a2); + tag = UUID_INFO_TAG(partition_info.a2); + buf_sz = PARTITION_INFO_SZ(partition_info.a2); + if (buf_sz > sizeof(*buffer)) + buf_sz = sizeof(*buffer); + + memcpy(buffer + prev_idx * buf_sz, &partition_info.a3, + (cur_idx - start_idx + 1) * buf_sz); + prev_idx = cur_idx; + + } while (cur_idx < (count - 1)); + + return count; +} + /* buffer is allocated and caller must free the same if returned count > 0 */ static int ffa_partition_probe(const uuid_t *uuid, struct ffa_partition_info **buffer) { int count; u32 uuid0_4[4]; + bool reg_mode = false; struct ffa_partition_info *pbuf; + if (!ffa_features(FFA_PARTITION_INFO_GET_REGS, 0, NULL, NULL)) + reg_mode = true; + export_uuid((u8 *)uuid0_4, uuid); - count = __ffa_partition_info_get(uuid0_4[0], uuid0_4[1], uuid0_4[2], - uuid0_4[3], NULL, 0); + if (reg_mode) + count = __ffa_partition_info_get_regs(uuid0_4[0], uuid0_4[1], + uuid0_4[2], uuid0_4[3], + NULL, 0); + else + count = __ffa_partition_info_get(uuid0_4[0], uuid0_4[1], + uuid0_4[2], uuid0_4[3], + NULL, 0); if (count <= 0) return count; @@ -305,8 +363,14 @@ ffa_partition_probe(const uuid_t *uuid, struct ffa_partition_info **buffer) if (!pbuf) return -ENOMEM; - count = __ffa_partition_info_get(uuid0_4[0], uuid0_4[1], uuid0_4[2], - uuid0_4[3], pbuf, count); + if (reg_mode) + count = __ffa_partition_info_get_regs(uuid0_4[0], uuid0_4[1], + uuid0_4[2], uuid0_4[3], + pbuf, count); + else + count = __ffa_partition_info_get(uuid0_4[0], uuid0_4[1], + uuid0_4[2], uuid0_4[3], + pbuf, count); if (count <= 0) kfree(pbuf); else