On Fri, 20 Nov 2026 13:52:03 -0400
Jason Gunthorpe <[email protected]> wrote:

> DRTM is defined over SMCs, but if the stub blindly issues an SMC the
> machine might crash. To do this safely and automatically, the stub has to
> extract the ACPI_FADT_PSCI_COMPLIANT (without HVC) from the ACPI table,
> then check with PSCI if SMCC 1.1 is supported
> 
> Implement a really basic ACPI walk down to the FACP and pull it out.  Be
> strict about parsing the ACPI. Put it in the drtm file for now as it is
> the only expected user.
> 
> Follow the overall design in the kernel and finish up with trying to call
> ARM_SMCCC_VERSION_FUNC_ID like the kernel does.
> 
> Signed-off-by: Jason Gunthorpe <[email protected]>
> ---
Few trivial things.

Reviewed-by: Jonathan Cameron <[email protected]>


> diff --git a/drivers/firmware/efi/libstub/arm64-smcc.c 
> b/drivers/firmware/efi/libstub/arm64-smcc.c
> new file mode 100644
> index 00000000000000..a722522e1af85e
> --- /dev/null
> +++ b/drivers/firmware/efi/libstub/arm64-smcc.c
> @@ -0,0 +1,212 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES
> + *
> + * Determine if ARM64 can use SMCC 1.1 calls.
> + */
> +#include <linux/acpi.h>
> +
> +#include <uapi/linux/psci.h>
> +
> +#include "efistub.h"
> +#include "arm64-stub.h"
> +
> +static bool efi_acpi_checksum_valid(const void *table, u32 length)
> +{
> +     const u8 *p = table;
> +     u8 checksum = 0;
> +
> +     /*
> +      * Nothing this code walks is remotely close to this large.  The length
> +      * fields are firmware supplied and are used to bound checksum loops, so
> +      * cap them to avoid checksumming forever if one is corrupt.
> +      */
> +     if (length > SZ_1M)
> +             return false;
> +
> +     while (length--)
> +             checksum += *p++;
> +
> +     return checksum == 0;
> +}
> +
> +static const struct acpi_table_fadt *
> +efi_acpi_find_fadt(const struct acpi_table_xsdt *xsdt)
> +{
> +     u32 nr_entries;
> +     u32 i;
> +
> +     nr_entries = (xsdt->header.length -
> +                   offsetof(struct acpi_table_xsdt, table_offset_entry)) /
> +                  sizeof(xsdt->table_offset_entry[0]);
> +     for (i = 0; i < nr_entries; i++) {

Might as well do

        for (u32 i = 0; 


> +             u64 address = xsdt->table_offset_entry[i];
> +             const struct acpi_table_header *table;
> +
> +             if (!address)
> +                     continue;
> +
> +             table = (const void *)address;
> +             if (!memcmp(table->signature, ACPI_SIG_FADT,
> +                         sizeof(table->signature)))
> +                     return (const void *)table;
> +     }
> +
> +     return NULL;
> +}

> +static bool efi_arm64_smc_conduit_available(void)
> +{
> +     const struct acpi_table_fadt *fadt;
> +     const struct acpi_table_xsdt *xsdt;
> +     const struct acpi_table_rsdp *rsdp;
> +     u32 length;
> +     u16 flags;
> +
> +     rsdp = get_efi_config_table(ACPI_20_TABLE_GUID);
> +     if (!rsdp) {
> +             efi_debug(
> +                     "DRTM: ACPI 2.0 RSDP is unavailable; SMC conduit is 
> unknown\n");

It is long anyway, so definitely go longer and avoid that ugliness!

> +             return false;
> +     }
> +
> +     if (memcmp(rsdp->signature, ACPI_SIG_RSDP, sizeof(rsdp->signature))) {
> +             efi_err("DRTM: ACPI RSDP signature is invalid\n");
> +             return false;
> +     }
> +
> +     if (rsdp->revision < 2) {
> +             efi_err("DRTM: ACPI RSDP revision does not provide an XSDT\n");
> +             return false;
> +     }
> +
> +     length = rsdp->length;
> +     if (length < sizeof(*rsdp)) {
> +             efi_err("DRTM: ACPI RSDP length is invalid\n");
> +             return false;
> +     }
> +     if (!efi_acpi_checksum_valid(rsdp, offsetof(struct acpi_table_rsdp,
> +                                                 length))) {

Could use acpi_rsdp_common instead of offset in the combined structure.
Not sure it is much clearer though.

> +             efi_err("DRTM: ACPI RSDP legacy checksum is invalid\n");
> +             return false;
> +     }




Reply via email to