From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC554606A322 for ; Thu, 3 Dec 2026 00:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ZYm3v3G+; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=R0y2sIxp; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=U8nln4SB 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:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=xBvCIkI7TLQpJka7+ku8//HfY43BBVyw8FGyA48i3jA=; b=ZYm3v3G+pijo2x gqSbZveYoD9eNXnbj7VEaalABk0ihn3S0o6+AMkvnNWEVvpTMbLAnKf/dlJkOtmlovwntY88P0r2O G8Iz92Hb6C3QlihXeTU57SQDyIuwUcKGHOrZzEwfTzJh88nEik1nQDbM0sn9+oQ63n3AgTLv69mS1 9DNWIbUw1K0XkeNyxrQytX5jhUidR0pB8/mCPZwSHSNMXCBmhb9Bx9FmILwyU+q5vm0O5P4Ggfman SLpaur9jiJNhWaMEN9axXAQp54HzYdJBGu+g+1MCEzeOyFHPqjff8rG16I9GlI93DsLlBunhk4XWU NLijDkDes3F0DGprrHDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYv1E-0000000D6YR-0voV; Thu, 03 Dec 2026 00:49:52 +0000 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYv1A-0000000D6Xl-12bp for linux-arm-kernel@lists.infradead.org; Thu, 03 Dec 2026 00:49:51 +0000 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B306Etk3161241 for ; Thu, 3 Dec 2026 00:49:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= xBvCIkI7TLQpJka7+ku8//HfY43BBVyw8FGyA48i3jA=; b=R0y2sIxp2kgK71Fe DQsFmo7BqfXYCe8fXknSYeju4f6kmOOXM+3BZFyB8pUskOGAu979nuLa0L5U6Vg6 yqXQ7Y/sdC5ZDS1sRf5ucW/4h4fTC3RNfie8vbYhkkf52MRWmqqeomw+LNQNSQet lw7R9fRf4AJFBlGUYlKKf2mP5ssr3j0mPN5WowLKZjN3vsYk7M6/DcBDTbggOtf1 G+lN5RvVxNISdd5/la3gt7ciVSheRa2X+oc06w1pHaXKk+QreRj51Ukkuh4vo7qf 8jRGrq1cEQ75Sth+U75fOXnsjTjpHjXrBoszjrzPxSp4GBkNcnnn+Bih+mextsAu 3roeSQ== Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4jajuq2xgq-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 03 Dec 2026 00:49:47 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-38355b03cb8so12890395eec.0 for ; Wed, 02 Dec 2026 16:49:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796258987; x=1796863787; darn=lists.infradead.org; h=content-transfer-encoding:content-type:mime-version:organization :references:in-reply-to:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to:content-type; bh=xBvCIkI7TLQpJka7+ku8//HfY43BBVyw8FGyA48i3jA=; b=U8nln4SBqQSHg3m6cDRh81rkeutRbVLT9RSkDRG/KTzpLPVCjk4OJrCPmAvHSJgS0h CxucIrFUlXrOi7xthoz4wLgivFz/Yf6Ccc96KvuXT9BCa5tYNhlqKlzxyg2WcOkXedCW jX4knrpmQcE8F7NNgti7oYLD9LALylzrWi43g2oYKreL8577nEUTBo+P5KZlgWtcsMBX LLINZiePSayorgjx3smZbhEw+q8hmkn84ZCkDYiBcxDzsVtRtYBRYVyhzHl0voubVBl3 CKtYtSlF9kgaoUlruvTsyB39atZqa91r+xKTcMxtYrXNtvkU5lFIDv4Qbk4QQ7ULbFQk wHBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796258987; x=1796863787; h=content-transfer-encoding:content-type:mime-version:organization :references:in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xBvCIkI7TLQpJka7+ku8//HfY43BBVyw8FGyA48i3jA=; b=SPTTDI/nLYtFr/zri45UY+EQbKdEVKf0NOvgtFtAjFFaJ/coWh2gqh793z1Nb/QQpb pHsAz83Ft64odIikT4scfOkZS/n5lPUVo2t7+tV6EaI7xOc2dqIA2CoZXcfH5mPE4Ifx UoMq3D9h8NP19M6iTYvH+1UfWzVoMPBPGR9MDkwkhMLF8Na8FZfhpa/H5+zYkt2dDQwS RwqGyeePbwAzzA0wRCy5JxBEqnIFRE/BY1FCX+P6JSiRci6Tf+901cwECkI/hBCaREBX hlxPIJrTf+kurq3nXoNhq+iP/NYQhkaVAjRnWygWtga6SyH8oV5+tl2o8emf84h4Nts2 r9tg== X-Forwarded-Encrypted: i=1; AL+hErEMtLfJGY3QPyNpeZnDKotZuqvxKKyuEvpP03mxXR5GHkhuu5UrwOmT3NQe929Q6HBoPl7mZzL3Dj3VNi7cFR8S@lists.infradead.org X-Gm-Message-State: APuU4Z9gLCV6PeFJNVVdQYNBqMv4npxlvKQOYEZxr3Br1FPJSDLSXuqz RdY5mswVf6eU3O+FE3eQ1uar5/johP2xCbp9NGIEhuj/2NSsqYqPPPPNpKzTs5WsVwaGDNS6kpv sbToVcYHh3HBEFsd8JAwD/Ega3iz+sTMukHzPyIrd152+G8e68L6lc217XA2bfUEg9BLCoU//Ms WA6g== X-Gm-Gg: AZFdTZcZg0QcpyyWF2vRf8kThTaZysukjmT/Pez+b0q74bOiqnmm7IdJbLJeAqC71Da 4zUNPLh4LlNBRNE4n1D4jU0U2HeFMyNhAgJ1pxtsItLoRaafkyepOAocPV/TPT0KQ6na+g2RFct GsaQzM7rvorENtVpZSkWMpQkxYAD/XxVaTNK6ZvYRopBkngBD9Z0uXiGAAVUs6HBiChuxDsPCcq xX2USIKOa/9kgSv0COrsYjoNy861z527k0uW4oIw46JKtt6gND2faGTkvKQNxH8psv0+PgMcorl SY6KmjIPh/nBur3XzJe6S9F/mtpt+WWPhPEfGdftH17LBhj8P041ZZbOUB/t62BcYPrzZe0pn0o EM4pwWRvCuzbBVKJd5n2y9soYsQi7bM7T7cVd75ou58dF+hUMwzdoz2hTnhQc2daV1qAF5EuT2e yIiJZJpJqMLssfjxALwUiZx2CLJA== X-Received: by 2002:a05:7301:1505:b0:384:df31:6a07 with SMTP id 5a478bee46e88-386a87efea0mr33413981eec.30.1796258986515; Wed, 02 Dec 2026 16:49:46 -0800 (PST) X-Received: by 2002:a05:7301:1505:b0:384:df31:6a07 with SMTP id 5a478bee46e88-386a87efea0mr33413959eec.30.1796258985746; Wed, 02 Dec 2026 16:49:45 -0800 (PST) Received: from localhost (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385f68bc0adsm117806454eec.13.2026.12.02.16.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 16:49:45 -0800 (PST) Date: Wed, 2 Dec 2026 16:49:41 -0800 From: Jonathan Cameron To: Yeoreum Yun Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lorenzo Pieralisi , Catalin Marinas , Suzuki Poulose , Steven Price , Sami Mujawar , "Aneesh Kumar K.V" , Jiri Pirko , GONG Ruiqi , Jason Gunthorpe , Mark Brown Subject: Re: [PATCH RFC v2 2/6] firmware: arm_firme: introduce arm_firme Message-ID: <20261202164941.0000329b@oss.qualcomm.com> In-Reply-To: <20261127-firme_interface-v2-2-ab88b2d0b4e0@arm.com> References: <20261127-firme_interface-v2-0-ab88b2d0b4e0@arm.com> <20261127-firme_interface-v2-2-ab88b2d0b4e0@arm.com> Organization: Qualcomm X-Mailer: Claws Mail 4.4.0 (GTK 3.24.51; x86_64-w64-mingw32) X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Authority-Analysis: v=2.4 cv=B8QsQ+tM c=1 sm=1 tr=0 ts=6b10bcab cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=JYp8KDb2vCoCEuGobkYCKw==:17 a=kj9zAlcOel0A:10 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=7CQSdrXTAAAA:8 a=AWWqdwgEO8KigB99n4IA:9 a=CjuIK1q_8ugA:10 a=scEy_gLbYbu1JhEsrz4S:22 a=a-qgeE7W1pNrGK8U0ZQC:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAzMDAwMiBTYWx0ZWRfXyeD241VrVP0k PfbDBu/wfniDb5f3AOGQwbNkXdu3LgjtiUlrRed9JHVgNw00T6C6xazjcqibi5YV6rK32Ioyhva WwrXI3UTmUX5syJHVVSghE2nDCyswPI= X-Proofpoint-ORIG-GUID: 48AmzdMRR8gz7qskfvsz2aJ26bujdYOF X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAzMDAwMiBTYWx0ZWRfX0XE8hncrNBWd b0tDhXsmUfsqltq+jwCjON0j/cEgIFCxqhkriXwbgEJ/MK987O66GJWW32+6F0r8YB1WpPTa4xk KxyN4zXbWieSz0YHCJyzrAx+usDJ2CHMCPfE7XuZrcOTZ7PUKCM4Q57N2Vzc5ZowljTH4LcKLI8 gevcykJG/iuADh13VbdSI2c2tdfTtNcUEypDYnqoLBWVi90ZY57V6Sw7Vs/flvWZoDCZc3AcheU jubO+ri807rvPdt2ezkw5TFowF6EVqG7eUkz+QeAEK4IcRacW8dbSx2GeQWkH8gpz3onTlm+L3v MM0s9/CNPStxUKGTqIc3AzbIte0Jt2jasBygg88iaK3rAwG+W/P/az9hVBxePsxWhqcKeP/I+1I PX78JhYColwQuBM4T53H5guiAI3a6FKJTqC8zfpa8vXXzYy0TNndhWIZ1bRxGvM76/0W4TJODmQ a8d05+j/0leKVz4raIw== X-Proofpoint-GUID: 48AmzdMRR8gz7qskfvsz2aJ26bujdYOF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-02_07,2026-12-02_07,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 adultscore=0 malwarescore=0 suspectscore=0 spamscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612030002 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_164948_317521_40F2BC0B X-CRM114-Status: GOOD ( 45.56 ) X-Spam-Score: -2.8 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Fri, 27 Nov 2026 15:28:32 +0000 Yeoreum Yun wrote: > The Realm Management Extension (FEAT_RME) is part of Arm Confidential > Compute Architecture (CCA) and enables support for dynamic, attestable > trusted execution environments ("Realms") on Arm systems. Hi Yeoreum, > > Realm management flows depend on EL3 firmware for operations such as > Realm construction, resource allocation and isolation, and attestation > of initial Realm state. > > The FIRME defines standard interfaces provided by EL3 firmware to > satisfy these dependencies. These interfaces include: > > - Granule Protection Table management > - IDE key management for PCIe and CXL Root Ports > - Memory Encryption Context management > - Attestation token management > - Integrated device management > > Each group of interfaces forms a FIRME service. A base FIRME service > is also defined to provide common concepts, service discovery, and > feature discovery across services. Some of this feels like cover letter material. I'd focus on what this patch does and any unusual things you want to call out. > > FIRME interfaces are implemented at the EL3 boundary between the > Non-secure, Realm, and Secure states. They may also be used on systems > without FEAT_RME, for example to provide firmware-based attestation or > security services. > > arm_firme.c provides the common APIs to be used for FIRME device/driver > to support for FIRME services Provide common APIs... No need to state the filename. > > Signed-off-by: Yeoreum Yun Various comments inline. > --- > drivers/firmware/Kconfig | 36 ++++++ > drivers/firmware/Makefile | 1 + > drivers/firmware/arm_firme.c | 275 +++++++++++++++++++++++++++++++++++++++++++ > include/linux/arm-smccc.h | 1 + > include/linux/arm_firme.h | 261 ++++++++++++++++++++++++++++++++++++++++ > 5 files changed, 574 insertions(+) > > diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig > index 43e2e2a645945..d031c36c44dcc 100644 > --- a/drivers/firmware/Kconfig > +++ b/drivers/firmware/Kconfig > @@ -60,6 +60,42 @@ config ARM_SDEI_NMI > > If unsure, say N. > > +config ARM_FIRME > + bool "Arm Firmware Interfaces for Realm Management Extension (FIRME)" > + depends on ARM64 && HAVE_ARM_SMCCC_DISCOVERY > + default n Unless something else is forcing things, everything is default n so don't specify it. > + help > + The Realm Management Extension (FEAT_RME) is part of Arm Confidential > + Compute Architecture (CCA) and enables support for dynamic, attestable > + trusted execution environments ("Realms") on Arm systems. > + > + Realm management flows depend on EL3 firmware for operations such as > + Realm construction, resource allocation and isolation, and attestation > + of initial Realm state. > + > + The FIRME defines standard interfaces provided by EL3 firmware to > + satisfy these dependencies. These interfaces include: > + > + - Granule Protection Table management > + - IDE key management for PCIe and CXL Root Ports > + - Memory Encryption Context management > + - Attestation token management > + - Integrated device management > + > + Each group of interfaces forms a FIRME service. A base FIRME service > + is also defined to provide common concepts, service discovery, and > + feature discovery across services. > + > + FIRME interfaces are implemented at the EL3 boundary between the > + Non-secure, Realm, and Secure states. They may also be used on > + systems without FEAT_RME, for example to provide firmware-based > + attestation or security services. > + > + This opions provides the common APIs used for FIRME service > + implementation driver. > + > + If unsure, say N. Why? I'd think we'd want this on any platform that supports it. > + > diff --git a/drivers/firmware/arm_firme.c b/drivers/firmware/arm_firme.c > new file mode 100644 > index 0000000000000..fafed19121141 > --- /dev/null > +++ b/drivers/firmware/arm_firme.c > +int firme_get_shared_buffer_info(struct firme_shared_buf_info *info) > +{ > + if (static_branch_unlikely(&firme_disabled)) > + return -EOPNOTSUPP; > + > + if (!info) > + return -EINVAL; > + > + memcpy(info, &base_service_info.shbuf_info, > + sizeof(struct firme_shared_buf_info)); sizeof(base_service_info.shbuf_info)); as then no one has to check for anything odd about the type. > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(firme_get_shared_buffer_info); > + > +static int firme_smccc_dev_create(void) > +{ > + int ret; > + unsigned long feature, service_list; > + int i, j; > + > + struct firme_dev_info { > + const char *dev_name; > + struct arm_smccc_device *sdev; > + } sdev_info[] = { > + { .dev_name = NULL, }, > + { .dev_name = NULL, }, > + { .dev_name = "arm-firme-ide-keyset", }, > + { .dev_name = NULL, }, > + { .dev_name = "arm-firme-attest", }, > + { .dev_name = NULL, }, > + /* ID_MAX */ Is the comment helpful? I have no idea what it is referring to here. If you want to ensure the size matches FIRME_SERIVCE_ID_MAX then put an assert in or size the array (which would then zero fill anything missing which might not be good). Use the enum you have so we match them up directly [FIRME_ATTEST_SERVICE_ID] = { .dev_name = "arm-firme-attest" }, and only set ones you don't want to be NULL. Let C fill the others in for you as I'm not really seeing them adding much value. That does require sizing the array with sdev_info[FIRME_SERVICE_ID_MAX] = { ... > + }; > + > + ret = __firme_get_feature(FIRME_BASE_SERVICE_ID, 0x01, &feature); > + if (ret) > + return ret; > + > + service_list = FIELD_GET(FIRME_BASE_FEAT1_SERVICE_LIST_MASK, feature); > + service_list = (service_list << 1) | 0x01; Add a comment on why the shift and setting of the bottom bit. Even if in the spec that's a bit unusual. > + > + for (i = FIRME_BASE_SERVICE_ID; i < FIRME_SERVICE_ID_MAX; i++) { > + if (!sdev_info[i].dev_name || !test_bit(i, &service_list)) > + continue; > + sdev_info[i].sdev = arm_smccc_device_register(sdev_info[i].dev_name, > + FIRME_SERVICE_VERSION, > + (void *)i); > + if (IS_ERR(sdev_info[i].sdev)) { > + ret = PTR_ERR(sdev_info[i].sdev); > + break; > + } > + } > + > + if (!ret) > + return 0; Use standard kernel style of errors out of line - may seem more complex, but it is what the average kernel reviewer expects so be nice to them! if (ret) goto unregister; return 0; unregister: > + > + for (j = i - 1; j >= FIRME_BASE_SERVICE_ID; j--) { > + arm_smccc_device_unregister(sdev_info[j].sdev); > + } > + > + return ret; > +} > diff --git a/include/linux/arm_firme.h b/include/linux/arm_firme.h > new file mode 100644 > index 0000000000000..c070eb6a4bb08 > --- /dev/null > +++ b/include/linux/arm_firme.h > @@ -0,0 +1,261 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Copyright (C) 2026 Arm Ltd. > + */ > + > +#ifndef _LINUX_ARM_FIRME_H > +#define _LINUX_ARM_FIRME_H > + > +#include > +#include > +#include > +#include > +#include > + > +/* > + * This file provides common defines for Fimware Interface for Realm > + * Management Extension (FIRME) as specified in > + * https://developer.arm.com/documentation/den0149/latest I'd pick a version rather than Latest... Tends to set a baseline for what you have implemented. I guess this makes sense during RFCs perhaps? > + */ > +/* > + * FIRME IDE key mangement service function ids. > + * > + * NOTE: > + * Other functions except FIRME_ATTEST_PAT_GET are not supported > + * by normal world instance. In general or a specific FIRME implementation? > + */ > +#define FIRME_ATTEST_PAT_GET FIRME_SMC(0x408) > + > +/* > + * FIRME error codes. > + */ > +#define FIRME_RET_SUCCESS (0) > +#define FIRME_RET_NOT_SUPPORTED (-1) > +#define FIRME_RET_INVALID_PARAMETER (-2) > +#define FIRME_RET_ABORTED (-3) > +#define FIRME_RET_INCOMPLETE (-4) > +#define FIRME_RET_DENIED (-5) > +#define FIRME_RET_BUSY (-6) > +#define FIRME_RET_OP_CONFLICT (-7) > +#define FIRME_RET_ALREADY_EXISTS (-8) > +#define FIRME_RET_NOT_FOUND (-9) > +#define FIRME_RET_NO_MEMORY (-10) > +#define FIRME_RET_BAD_DATA (-11) > + > +/* > + * GPI attributes in GPT for FIRME granule management service. > + */ > +#define GPT_GPI_NO_ACCESS (0x0) No brackets around simple numbers. Given these are ARM arm things rather than firme, (D9.6.5 in M.C) I'd add a reference. > +#define GPT_GPI_SA (0x4) > +#define GPT_GPI_NSP (0x5) > +#define GPT_GPI_SECURE (0x8) > +#define GPT_GPI_NS (0x9) > +#define GPT_GPI_ROOT (0xa) > +#define GPT_GPI_REALM (0xb) > +#define GPT_GPI_NS_BY_NS_OR_ROOT (0xd) > +#define GPT_GPI_ANY (0xf) > +#define GPT_GPI_MASK GENMASK(3, 0) > + > +/* > + * FIRME version encoding > + */ > +#define FIRME_MAJOR_VERSION_MASK GENMASK(30, 16) > +#define FIRME_MINOR_VERSION_MASK GENMASK(15, 0) > +#define FIRME_MAJOR_VERSION(x) ((u16)(FIELD_GET(FIRME_MAJOR_VERSION_MASK, (x)))) > +#define FIRME_MINOR_VERSION(x) ((u16)(FIELD_GET(FIRME_MINOR_VERSION_MASK, (x)))) > +#define FIRME_PACK_VERSION_INFO(major, minor) \ > + (FIELD_PREP(FIRME_MAJOR_VERSION_MASK, (major)) | \ > + FIELD_PREP(FIRME_MINOR_VERSION_MASK, (minor))) I'd just use FIELD_PREP / FIELD_GET inline. These sorts of macros often just obscure things. Only introduce them if they save a lot of code. > + > +#define FIRME_VERSION_1_0 FIRME_PACK_VERSION_INFO(1, 0) > + I'd add some spec references such as R0206 for this one. That spec is somewhat hard to navigate. > +#define FIRME_KEYSET_ID_KEYSET_MASK BIT(0) > +#define FIRME_KEYSET_ID_DIRECTION_MASK BIT(1) > +#define FIRME_KEYSET_ID_SUBSTREAM_MASK GENMASK(5, 2) > +#define FIRME_KEYSET_ID_STREAM_MASK GENMASK(13, 6) > +#define FIRME_KEYSET_ID_ROOT_PORT_MASK GENMASK(29, 14) > +#define FIRME_KEYSET_ID_SEGMENT_MASK GENMASK(37, 30) > +#define FIRME_PACK_KEYSET_ID(ks, d, ss_id, s_id, rp_id, sg_id) \ > + (FIELD_PREP(FIRME_KEYSET_ID_KEYSET_MASK, ks) | \ > + FIELD_PREP(FIRME_KEYSET_ID_DIRECTION_MASK, d) | \ > + FIELD_PREP(FIRME_KEYSET_ID_SUBSTREAM_MASK, ss_id) | \ > + FIELD_PREP(FIRME_KEYSET_ID_STREAM_MASK, s_id) | \ > + FIELD_PREP(FIRME_KEYSET_ID_ROOT_PORT_MASK, rp_id) | \ > + FIELD_PREP(FIRME_KEYSET_ID_SEGMENT_MASK, sg_id)) I haven't read on, but unless that is frequently used I'd not have the macro -better to see what goes where inline. > + > +#define FIRME_PGS_4K (0) > +#define FIRME_PGS_64K (1) > +#define FIRME_PGS_16K (2) > + > +#define FIRME_L0GPTSZ_1GB (0) > +#define FIRME_L0GPTSZ_16GB (4) > +#define FIRME_L0GPTSZ_64GB (6) > +#define FIRME_L0GPTSZ_512GB (9) These are references to encodings in GPCCR_EL3.L0GPTZ. I'd be tempted to name them to make that clearer rather than prefix them with FIRME. > + > +#define FIRME_PPS_4GB (0) > +#define FIRME_PPS_64GB (1) > +#define FIRME_PPS_1TB (2) > +#define FIRME_PPS_4TB (3) > +#define FIRME_PPS_16TB (4) > +#define FIRME_PPS_256TB (5) > +#define FIRME_PPS_4PB (6) > +#define FIRME_PPS_64PB (7) Similar with these. Would be odd to have kernel defs for EL3 registers anywhere central but maybe we can make that association with naming despite keeping them here? > + > +/* > + * FIRME Base service features. > + */ > +#define FIRME_BASE_FEAT0_FUNC_VERSION BIT(0) > +#define FIRME_BASE_FEAT0_FUNC_FEATURE BIT(1) > +#define FIRME_BASE_FEAT0_FUNC_MASK GENMASK(2, 0) This seems random. What is the FUNC_MASK for? It covers one more bit than defined values today yet there is nothing table 2.8 that says bit 2 is any different from the remaining bits. > +/* > + * FIRME Granule management service features. > + */ > +#define FIRME_GM_FEAT0_FUNC_GPI_SET BIT(0) > +#define FIRME_GM_FEAT0_FUNC_GPI_OP_COUTINUME BIT(1) I'd add the reset of the values in the spec as that will make it clearer why you have the mask as below... > +#define FIRME_GM_FEAT0_FUNC_MASK GENMASK(3, 0) particularly as this is one bit shorter than the version I'm looking at which has FIRME_GM_GPT_INFO. > + > +#define FIRME_GM_FEAT1_PGS_MASK GENMASK(1, 0) > +#define FIRME_GM_FEAT1_L0GPTSZ_MASK GENMASK(5, 2) > +#define FIRME_GM_FEAT1_PPS_MASK GENMASK(8, 6) More fields exist in the current spec, so I can now see why this is an RFC. In next cover letter talk a bit more on that and when we can expect some stability. > + > +/* > + * FIRME IDE key management service features. > + */ > +#define FIRME_IDE_KEYSET_FEAT0_FUNC_PROG BIT(0) > +#define FIRME_IDE_KEYSET_FEAT0_FUNC_GO BIT(1) > +#define FIRME_IDE_KEYSET_FEAT0_FUNC_STOP BIT(2) > +#define FIRME_IDE_KEYSET_FEAT0_FUNC_POLL BIT(3) > +#define FIRME_IDE_KEYSET_FEAT0_FUNC_MASK GENMASK(3, 0) No FIRME_IDE_KEYSET_FEAT1_MAX_CONCURRENT_OP_CNT ? > + > +/* > + * FIRME IDE key management service features. Same comment as the one above, but different thing... > + */ > +#define FIRME_ATTEST_FEAT0_FUNC_PAT_GET BIT(0) > +#define FIRME_ATTEST_FEAT0_FUNC_MASK GENMASK(5, 0) As above. If you are going to define the full mask, put defines for all the bits so that makes more sense. > + > +#define FIRME_ATTEST_FEAT1_MAX_PAT_PG_CNT_MASK GENMASK(7, 0) Similar here. Maybe this is a spec version thing but I'd like to see all the fields in that register here. > + > +typedef struct arm_smccc_1_2_regs firme_value_t; > +typedef long firme_status_t; I'm not immediately seeing a lot of value in this type, but maybe it makes more sense in later patches. > + > +/* > + * FIRME Service ID Given name of enum, comment doesn't add anything! > + */ > +enum firme_service_id { > + FIRME_BASE_SERVICE_ID = 0, > + FIRME_GM_SERVICE_ID, > + FIRME_IDE_KEYSET_SERVICE_ID, > + FIRME_MEC_SERVICE_ID, > + FIRME_ATTEST_SERVICE_ID, > + FIRME_IDEV_SERVICE_ID, > + FIRME_SERVICE_ID_MAX, No trailing comma if that's there simply for sizing. We don't want it to be easy to accidentally put anything after it. > +}; > + > +enum firme_ide_type { > + FIRME_IDE_TYPE_SELECTIVE, I guess perhaps out of the spec, but odd to call out PCIE for link but not SELECTIVE as both only apply to PCIE today. > + FIRME_IDE_TYPE_PCIE_LINK, > + FIRME_IDE_TYPE_CXL_CACHEMEM, > +}; > + > +struct firme_shared_buf_info { > + size_t min_size; > + size_t max_size; > +}; > + > +static __always_inline int firme_status_to_errno(firme_status_t status) > +{ > + static int firme_status_errno_map[] = { > + 0, /* FIRME_RET_SUCCESS */ Can we do [-FIRME_RET_SUCESS] = 0, [-FIRME_REG_NOT_SUPPORTED] = -EOPNOTSUPP, etc? Nicer to enforce the relationship rather than rely on comments. > + -EOPNOTSUPP, /* FIRME_RET_NOT_SUPPORTED */ > + -EINVAL, /* FIRME_RET_INVALID_PARAMETER */ > + -ECANCELED, /* FIRME_RET_ABORTED */ > + -EAGAIN, /* FIRME_RET_INCOMPLETE */ > + -EACCES, /* FIRME_RET_DENIED */ > + -EBUSY, /* FIRME_RET_BUSY */ > + -EALREADY, /* FIRME_RET_OP_CONFLICT */ > + -EEXIST, /* FIRME_RET_ALREDAY_EXISTS */ ALREADY > + -ENOENT, /* FIRME_RET_NOT_FOUND */ > + -ENOMEM, /* FIRME_RET_NO_MEMORY */ > + -EBADMSG, /* FIRME_RET_BAD_DATA */ > + }; > + > + status = -status; > + > + if (status >= 0 && status < ARRAY_SIZE(firme_status_errno_map)) > + return firme_status_errno_map[status]; > + > + return -EINVAL; > +}; > + > +static __always_inline void invoke_firme_service(firme_value_t args, > + firme_value_t *res) > +{ > + arm_smccc_1_2_smc(&args, res); > +} > + > +#if IS_ENABLED(CONFIG_ARM_FIRME) > +extern int firme_get_version(enum firme_service_id service_id, u32 *version); > +extern int firme_get_feature(enum firme_service_id service_id, > + uint8_t feat_idx, unsigned long *feature); > +extern int firme_get_shared_buffer_info(struct firme_shared_buf_info *info); > +extern void *firme_alloc_shared_buffer(size_t *size, gfp_t gfp_flags); > +extern void firme_free_shared_buffer(void *buf, size_t size); > +#else > +static __always_inline int firme_get_version(enum firme_service_id service_id, > + u32 *version) > +{ > + return -EOPNOTSUPP; > +} > + > +static __always_inline int firme_get_feature(enum firme_service_id service_id, > + uint8_t feat_idx, unsigned long *feature) > +{ > + return -EOPNOTSUPP; > +} > + > +static __always_inline int firme_get_shared_buffer_info(struct firme_shared_buf_info *info) > +{ > + return -EOPNOTSUPP; > +} > + > +static __always_inline void *firme_alloc_shared_buffer(size_t *size, gfp_t gfp_flags) > +{ > + return NULL; > +} > + > +static __always_inline void firme_free_shared_buffer(void *buf, size_t size) > +{ > +} Common practice to just put the {} at the end of the line when the stub does nothing. Why do we need __always_inline markings? inline normally enough for stubs. For that matter, if you need __always inline for anything in here there should probably be some info on why. > +#endif > + > +#endif /* _LINUX_ARM_FIRME_H */ >