From nobody Tue Feb 10 23:33:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+64783+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+64783+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1598652171; cv=none; d=zohomail.com; s=zohoarc; b=FcnBQhofZus9C2h0+8ju1jmKkeNtIQEIXzblgJZtuupJJ//F4XhEDlE4l3/yaQ2TXW3QkmKQLJuwwSq5PxV204jrSe6qChR0lAMt6pJxwpOCl40KXSMtW8KdR/tkXZeaaSbRFJfeWk0zmy37e8KJxdu4u2Hc6XJQqYQGBesPRPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598652171; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Uuv+B7/KbKaFwTiexsjPrqHiSxiZ6XBZtEfitMpsOIA=; b=As02y+LxU/7vHbxTsjCmXqKXqCWWNFpXyIdN2T/xkUCZkYyrISLLWInhYfmYDJWjXHJ1cfT40bdTG7gtwtRuoI9EcO5HrQoyQeIU7cIM7QNbmwhxjKrQViSN7Wf4AsGgf/CwKYXPTXkDv8dlt4Jy2Ueg30gxPMnPzD5DXDAMasQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+64783+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1598652171791641.8715147485141; Fri, 28 Aug 2020 15:02:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uZcKYY1788612xwCgYvPAk62; Fri, 28 Aug 2020 15:02:51 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.72.1598652170728560562 for ; Fri, 28 Aug 2020 15:02:50 -0700 X-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 500EA31B; Fri, 28 Aug 2020 15:02:50 -0700 (PDT) X-Received: from u200856.usa.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F18FB3F71F; Fri, 28 Aug 2020 15:02:49 -0700 (PDT) From: "Jeremy Linton" To: devel@edk2.groups.io Cc: Jeremy Linton , Leif Lindholm , Pete Batard , Andrei Warkentin , Ard Biesheuvel , Samer El-Haj-Mahmoud Subject: [edk2-devel] [PATCH v3 2/5] Platform/RaspberryPi: Monitor ACPI Table installs Date: Fri, 28 Aug 2020 17:02:12 -0500 Message-Id: <20200828220215.101919-3-jeremy.linton@arm.com> In-Reply-To: <20200828220215.101919-1-jeremy.linton@arm.com> References: <20200828220215.101919-1-jeremy.linton@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,jeremy.linton@arm.com X-Gm-Message-State: RO8TwNnJJTgducUX4RyqNmbzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1598652171; bh=NpepjNxvYDGQaVwdums0L70wWBhwqNTEYvnLUfLDb9g=; h=Cc:Date:From:Reply-To:Subject:To; b=wI2TQzPyj+MEKrq/5LZZUYQc4i9nLVi+sLSHvXxHSWl+vpGSxOOAQsfVY139/B8FvnC 3cy2lNwkYznv3+gO144/74WcngMpg5lnexcXTb+Rjlri2JqX5lA0b38AzdWEOxYR3eYQb qhPIIsEXzktTzt5TaJAJ9PNhrI/Q165oUYs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Hook the ACPI table install sequence and add some basic conditional and AML NameOp update logic. If a table has a non-zero PCD declared that pcd is checked for a non-zero value before allowing the table to be installed. We also add a table of NameOp to PCD's which will be written into a DSDT/SSDT table as part of its install process. With this change we can declare something in ASL like: Name (VARN, 0x1234) and then add a table entry like: {"VARN", PcdToken(PcdVarn)} and the value of PcdVarn will replace the 0x1234 declared in the ASL above. Cc: Leif Lindholm Cc: Pete Batard Cc: Andrei Warkentin Cc: Ard Biesheuvel Cc: Samer El-Haj-Mahmoud Signed-off-by: Jeremy Linton Reviewed-by: Pete Batard --- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 153 +++++++++++++++++= +++- 1 file changed, 152 insertions(+), 1 deletion(-) diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/= RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c index af54136ade..9e5d9734ca 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c @@ -568,6 +568,156 @@ ApplyVariables ( } =20 =20 +typedef struct { + CHAR8 Name[4]; + UINTN PcdToken; +} AML_NAME_OP_REPLACE; + +typedef struct { + UINT64 OemTableId; + UINTN PcdToken; + AML_NAME_OP_REPLACE *SdtNameOpReplace; +} NAMESPACE_TABLES; + +#define SSDT_PATTERN_LEN 5 +#define AML_NAMEOP_8 0x0A +#define AML_NAMEOP_16 0x0B +#define AML_NAMEOP_32 0x0C +#define AML_NAMEOP_STR 0x0D +/* + * Scan the given namespace table (DSDT/SSDT) for AML NameOps + * listed in the NameOpReplace structure. If one is found then + * update the value in the table from the specified Pcd + * + * This allows us to have conditionals in AML controlled + * by options in the BDS or detected during firmware bootstrap. + * We could extend this concept for strings/etc but due to len + * variations its probably easier to encode the strings + * in the ASL and pick the correct one based off a variable. + */ +STATIC VOID +UpdateSdtNameOps( + EFI_ACPI_DESCRIPTION_HEADER *AcpiTable, + AML_NAME_OP_REPLACE *NameOpReplace + ) +{ + UINTN Idx; + UINTN Index; + CHAR8 Pattern[SSDT_PATTERN_LEN]; + UINTN PcdVal; + UINT8 *SdtPtr; + UINT32 SdtSize; + + SdtSize =3D AcpiTable->Length; + + if (SdtSize > 0) { + SdtPtr =3D (UINT8*)AcpiTable; + + for (Idx =3D 0; NameOpReplace && NameOpReplace[Idx].PcdToken; Idx++) { + /* + * Do a single NameOp variable replacement these are of the + * form 08 XXXX SIZE VAL, where SIZE is 0A=3Dbyte, 0B=3Dword, 0C=3Dd= word + * and XXXX is the name and VAL is the value + */ + Pattern[0] =3D 0x08; + Pattern[1] =3D NameOpReplace[Idx].Name[0]; + Pattern[2] =3D NameOpReplace[Idx].Name[1]; + Pattern[3] =3D NameOpReplace[Idx].Name[2]; + Pattern[4] =3D NameOpReplace[Idx].Name[3]; + + for (Index =3D 0; Index < (SdtSize - SSDT_PATTERN_LEN); Index++) { + if (CompareMem (SdtPtr + Index, Pattern, SSDT_PATTERN_LEN) =3D=3D = 0) { + PcdVal =3D LibPcdGet32 (NameOpReplace[Idx].PcdToken); + switch (SdtPtr[Index + SSDT_PATTERN_LEN]) { + case AML_NAMEOP_32: + SdtPtr[Index + SSDT_PATTERN_LEN + 4] =3D (PcdVal >> 24) & 0xFF; + SdtPtr[Index + SSDT_PATTERN_LEN + 3] =3D (PcdVal >> 16) & 0xFF; + // Fallthrough + case AML_NAMEOP_16: + SdtPtr[Index + SSDT_PATTERN_LEN + 2] =3D (PcdVal >> 8) & 0xFF; + // Fallthrough + case AML_NAMEOP_8: + SdtPtr[Index + SSDT_PATTERN_LEN + 1] =3D PcdVal & 0xFF; + break; + case 0: + case 1: + SdtPtr[Index + SSDT_PATTERN_LEN + 1] =3D !!PcdVal; + break; + case AML_NAMEOP_STR: + /* + * If the string val is added to the NameOpReplace, we can + * dynamically update things like _HID too as long as the + * string length matches. + */ + break; + } + break; + } + } + } + } +} + + +STATIC BOOLEAN +VerifyUpdateTable( + IN EFI_ACPI_DESCRIPTION_HEADER *AcpiHeader, + IN NAMESPACE_TABLES *SdtTable + ) +{ + BOOLEAN ret; + + ret =3D TRUE; + if (SdtTable->PcdToken && !LibPcdGet32 (SdtTable->PcdToken)) { + ret =3D FALSE; + } + if (ret && SdtTable->SdtNameOpReplace) { + UpdateSdtNameOps (AcpiHeader, SdtTable->SdtNameOpReplace); + } + + return ret; +} + + +STATIC NAMESPACE_TABLES SdtTables[] =3D { + { + SIGNATURE_64 ('R', 'P', 'I', 0, 0, 0, 0, 0), + 0, + NULL + }, + { } +}; + +/* + * Monitor the ACPI tables being installed and when + * a DSDT/SSDT is detected validate that we want to + * install it, and if so update any "NameOp" defined + * variables contained in the table from PCD values + */ +STATIC BOOLEAN +HandleDynamicNamespace ( + IN EFI_ACPI_DESCRIPTION_HEADER *AcpiHeader + ) +{ + UINTN Tables; + + switch (AcpiHeader->Signature) { + case SIGNATURE_32 ('D', 'S', 'D', 'T'): + case SIGNATURE_32 ('S', 'S', 'D', 'T'): + for (Tables =3D 0; SdtTables[Tables].OemTableId; Tables++) { + if (AcpiHeader->OemTableId =3D=3D SdtTables[Tables].OemTableId) { + return VerifyUpdateTable (AcpiHeader, &SdtTables[Tables]); + } + } + DEBUG ((DEBUG_ERROR, "Found namespace table not in table list.\n")); + + return FALSE; + } + + return TRUE; +} + + EFI_STATUS EFIAPI ConfigInitialize ( @@ -618,7 +768,8 @@ ConfigInitialize ( =20 if (PcdGet32 (PcdSystemTableMode) =3D=3D SYSTEM_TABLE_MODE_ACPI || PcdGet32 (PcdSystemTableMode) =3D=3D SYSTEM_TABLE_MODE_BOTH) { - Status =3D LocateAndInstallAcpiFromFv (&mAcpiTableFile); + Status =3D LocateAndInstallAcpiFromFvConditional (&mAcpiTableFile, + &HandleDynamicNamespa= ce); ASSERT_EFI_ERROR (Status); } =20 --=20 2.13.7 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#64783): https://edk2.groups.io/g/devel/message/64783 Mute This Topic: https://groups.io/mt/76484331/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-