From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796258989; b=tJ8stWvPb5myhVSytz4daTjnz3EQoiHZNOC/epX/AVYSNOEGisOLC5n9cySZnCqMEu4r jOkkBF8x4VVUoBE+/HcZC+W/lRqea1AAdTi727A2zFUMz75aTQMP0NPWx66M4Elsg5CeM /1ptSLdLSQvu3HJtbVkzHWbw70g4no5cX1bXLJ06vxa4WwDZQzsmmFqbYK+ni5+R293KL HCqc/BCZC76V4VN5UMnXneYgMsRaerFzbc6Z6hOsBNRuIlN4BZ9i4qG4dhS7ZeT+kiotb zGxuIATyyP91fEsX2i3KHkcnJMTFhbeZpnaopiowBthdqte54uif9vimp0t3jQi589g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796258989; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg: X-Received:X-Received:Received:Date:From:To:Cc:Subject:Message-ID: In-Reply-To:References:Organization:X-Mailer:MIME-Version: Content-Type:Content-Transfer-Encoding:X-Authority-Analysis: X-Proofpoint-Spam-Info:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=xBvCIkI7TLQpJka7+ku8//HfY43BBVyw8FGyA48i3jA=; b=QaKZH86Pv54RoVEHXjKxS2rqENbPOg1864TmU1TQIUwB2KBRsi15X9JqQx27fxffFFhw 9NpLy/43OaXkDnQbL1Y0Wbx4rQ95zfyIFB6kERgdz8vroJfpz5b90Da1ME/7evaqO2rTb hk/VEPoixlB4uw9VnZhf7BSX2O2PBM+64f0AJPifciHGlI39xMu6L8KKqVivEuOIqkBRs kWBfx8L+RUsuB5luC2PVQFdbEgpWtycwTaatMmVVUr338oigC0qxwYJyZkgALOOR3paO/ v2lZuF8Mx1+2Z2FGipM29rtWl/c+6JyMjF8p06DJDHjURbnRsvSHCKTLg7uHS32t4jw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=R0y2sIxp; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=AHltgUTT; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 E57AE606A322 for ; Thu, 3 Dec 2026 00:49:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E57AE606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; 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=AHltgUTT 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 6B3067XP3161109 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 4jajuq2xgp-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-341eff9e381so20523962eec.1 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=vger.kernel.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=AHltgUTTnCHy9WwZ40yUTQeSIktO5z6jhVvzDaK88oTaXXLCFBfNG9ewWNgVm3sSSr zgzIFKe7eineqsCkdwSatwdhHNrcWDjAtHGcvHrcul1+liM+Fb+syc/6GrlAq91s/JHp olCt1a+rcubKkP/HaDXomuIl7OGM/LklZRQ3Pz5CsL7HL3n9j1AHz5cpfGEWnPzzvwmq +wN8hazJhgdsS1WpSjsrRWA/8V3UW4Gl4X19Hlc0dYNidM4uAi+LEvuJXUIcpBnXoeMA n4UOS434V7y/JCtuD2euZ10b2y87LO7l2ynqsbx4fmZvpoTS+mD7ggxQrA0TYQ/P1xOD WiWg== 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=nejjqQRWhKS/FKo1ApLSPfKKiO2/nauPjOoMXtjAhE0YOoxPGMN8b3/qBgLvSQiG1G 1WBc373NH6wcFwEdUrBPTBafObEnErLlvVyp2I7Sc53F44IhKyDKg5I/y4wBd/0Ajcne ZoH7Ns7vpjOuTURdpVSXlsSANEbDFXjCmhGYOcULwIMcZEF3QiPIhgu9xdYYpCDw1gty +H4DgA3lIJmflsRZjr2yPaHvXOvjxbNEUh8dK+TqPLfdD47TszzaD7WJnTOpZ3ZJfjUk bfheV+yzOijp1QZIjqsC0yHgXiyn/m45QVu5Yj2UyPHfhiXkRj9Q4jY1CFvZadzgnMUC 0f0g== X-Gm-Message-State: APuU4Z+zhNNJeIGWoHFsw+q7nwOFRQfygYXNfi+6mwD8N6kfvxDtzqKr 3zPvfAJyytxLAVCs+YQSmc9+7MacWa6dSxD/hHZcKlIRZ3ShrNXNWRwVUcSekpJbKLHYCWG4mOV na4Pohsi3cbfknUGRps3lv9IGtM3wU/NtYNfGstRv3J9pg6N/8R6x8lSMJzwEYGh3jKA= X-Gm-Gg: AZFdTZfOPhjZ/Yo3RaptrkMciunwf+p55EFIfU8UIiq0QSwZ2U+ZaOvpj1Fc/i3C3Pv xJPrB4vyPeRIC7y572NHMyWKWp6vhJ8y/s5RdYgOk6oJLyyYOYiUGldx97lNWLU7BdNYNxQKztm yVniHnRfJgaNGOkqugA/MsEx1XvDHrjrm2uI1THOdytkmsyIGQtpGBTIuKjBwcFqIEhdNn6BZuy zGozreQutE4vOHD0WMoEYfgEjFKVNn/ZTw4dl7hwEu1J7WSs9hVEIl7tLEO1C5ixkrYlpYmb37o 0uQglq9/zOpWQ/qFl9Z3wJZgl8ho9j4b72T4fQ3eeTMXevheGM+PCWaan6PsQx4EFjP49Afw3ug nh8hv1icK8s2xdFToBlCxr2NxpJXgPNFcuNNb6tS4Gm1aKYttvKB/JHb0asb4sXGih1jXpsYuuG lX8VsZA0RqpqqTQSY0dKw4bxly0Q== X-Received: by 2002:a05:7301:1505:b0:384:df31:6a07 with SMTP id 5a478bee46e88-386a87efea0mr33413985eec.30.1796258986526; 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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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: AW1haW4tMjYxMjAzMDAwMiBTYWx0ZWRfX1bGQCkR6nXiV ax/IVQ17qbZeEY5R6PSC9Izvye1f0rVBuXyM+bHoERs+nvQodrwZijSi8NcH7M8xtWruIxtibUN Q3hCqM/JasJQOOc39nxbZxDSW7PaTF4= X-Proofpoint-ORIG-GUID: f-hZZQCq6K9uYkGpV8OoxDuiS1QVTKLG X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAzMDAwMiBTYWx0ZWRfX1P0ZeDTqOmu4 CyU0GbNyN9YST5rCxRokjmDY9dbq59eBwvxK0g3MKB7TIdMXGXe5WrhTVsfCOjoCVZRsn35yzC/ oVF+jgpwo8xNlm6O0WBWaAFnbBnDSJ2vQPN9Nmt60JSjAXmgNoodGDb1jQLk4RPxUkwEraAJB/x Hg2StOAHfSuUG9NqzDqcTIQEITdfS8nV2UQ2U9SkCWDsjUto+ZHKO51kkyteNuE/yPFgn7pU/oP Me/xt/8apwFCg3DP1Rpmerfgo81VIkjHYEzjG6G7xPal8ZTTkNySu94b7tjHCH5r4VCRGTQsERw 2Me2yudgOztEzZWj8H7Pmcw9asHGEPHu5Cqawo5+GvNxF0LwHEWuolsydVAG513gmYZ0KgjjgU1 zonhdvKB3KlY5VGCAj+jFyZPaCoTcLMh56r9sIgC90NoqEsXApy+3ZMJFyBBbPweCg6PhVrHcar pFvsc671loZ+8JeL5dQ== X-Proofpoint-GUID: f-hZZQCq6K9uYkGpV8OoxDuiS1QVTKLG 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 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 */ >