From patchwork Wed Aug 14 13:48:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 13763530 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 0880CC3DA4A for ; Wed, 14 Aug 2024 13:52:31 +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=GEw0XpgIfXkmuNzjc4DCl0I9T/ ss5Hcd4UN2ktb4RjlvgN4SDimeJrVUQHIxSvDdhwXPj+N7zdstqwy7G5YJ/BeTGmc2jFW3jJEBUCA ru546MMPci9KigOYhuKLLsBrUJu1UVL9R5Ba/2WPqwe4gdRukn933nX/tCRfrI3VcVnstTt1L/gJh A7uheIUPR5B+A9bfiWh/1geMIuIKTXCWEPyGPFN0ig51rcTTYF2orx+ZZN9Eph0NTNt8kr5pwnWTF IMRUIj+iOzk/k6NOPscIBoUEbZQRDEEiCMPLFPE7+PDbCIP9752go7YtpO1IdV0H6wQngxWc9gKny Iow9wKBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1seEQD-000000079rv-3kHP; Wed, 14 Aug 2024 13:52:17 +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 1seEND-0000000795Q-4C4R for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2024 13:49:13 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8903F165C; Wed, 14 Aug 2024 06:49:37 -0700 (PDT) Received: from [127.0.1.1] (e107155-lin.cambridge.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 226BF3F6A8; Wed, 14 Aug 2024 06:49:11 -0700 (PDT) From: Sudeep Holla Date: Wed, 14 Aug 2024 14:48:53 +0100 Subject: [PATCH 4/7] firmware: arm_ffa: Add support for FFA_PARTITION_INFO_GET_REGS MIME-Version: 1.0 Message-Id: <20240814-ffa_v1-2-v1-4-9e9abef69b21@arm.com> References: <20240814-ffa_v1-2-v1-0-9e9abef69b21@arm.com> In-Reply-To: <20240814-ffa_v1-2-v1-0-9e9abef69b21@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/ZANAwAIAQBBurwxfuKYAcsmYgBmvLXTJSW9ZRpxTJBJvY6AKuGV10PgWsRD02QD0 snFNHoonryJAjMEAAEIAB0WIQS6ceUSBvMeskPdk+EAQbq8MX7imAUCZry10wAKCRAAQbq8MX7i mM13EADORvgERTejKyT5V1/JoTS5TefrWAvyexFUTZicSnOwClH4CNkfmTIyeesKoyHO24tBpFQ W4drEfiZP/5NtG/OyiAOgomVmB9UL0gDGnLxj2eQs4092WJ6GylRnNY063jMv8gjjpjyYXRf05U uCwf10OGc+Q81tVc5ndM9lqkcFV/Uwq/yVxuBp5eQ0Omvc9Ya4cRNbyQ1bhmR6Bn6XQ7NBYwW4L +8oNrWo5Cer2QHWcb44DwEI3t5HjqtLr31e6kzEDHD7COdb92SGB22M1idgiEZLfilsvKEQtGzB XAJbt1i/HsdjXd9pEOb+bQi1MEIxvaeLdHSad5fJcJpv+Z3CAynyd2cremlTykRKV1Mk/CV1fef 26PpEC/63qOC+SilY7uv4w90nOa+XF+z9gy4U9HWPaDxfQl5/eYid7xxuYs/rbtHBi7x2WFuatr oWkk/167T0DTKvKwL6ByGuR6g7lrKnyQw5lQQJGPBVHrphtt2qbJbOeKr0U0h892TbckgLSw1KH RkRSDIItP9t2kZkZ6zG/jHSvYbziZGy4ivKVUNZ9MGP2sn299jYLtprXeTUmAxL3iOQ246daodO j58DAynPlsCF7Dli+wLLBjvQ6CiiM1H4XD13l2AEnyEBO14luCapg4JgR62miQuJPHIgjLaHJe4 CUyeTMvtb8nTypw== 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-20240814_064912_167962_D46E825F X-CRM114-Status: GOOD ( 14.45 ) 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