From d3b27d312268bcc931b81c7a0ad18adabff2cfc4 Mon Sep 17 00:00:00 2001 From: kettenis Date: Wed, 3 Jul 2024 20:12:30 +0000 Subject: [PATCH] Switch to a table for mapping smbios vendor/product to device tree file name. Check for a partial match of the vendor like we already do for the product. This will help adding more machines to the list. ok patrick@, deraadt@ --- sys/arch/arm64/stand/efiboot/efiboot.c | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/sys/arch/arm64/stand/efiboot/efiboot.c b/sys/arch/arm64/stand/efiboot/efiboot.c index 564921d0cf2..f912edb4996 100644 --- a/sys/arch/arm64/stand/efiboot/efiboot.c +++ b/sys/arch/arm64/stand/efiboot/efiboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efiboot.c,v 1.53 2024/06/20 21:52:08 kettenis Exp $ */ +/* $OpenBSD: efiboot.c,v 1.54 2024/07/03 20:12:30 kettenis Exp $ */ /* * Copyright (c) 2015 YASUOKA Masahiko @@ -1109,10 +1109,24 @@ mdrandom(char *buf, size_t buflen) #define FW_PATH "/etc/firmware/dtb/" +struct smbios_dtb { + const char *vendor; + const char *prod; + const char *dtb; +} smbios_dtb[] = { + { "LENOVO", "21BX", + "qcom/sc8280xp-lenovo-thinkpad-x13s.dtb" }, + { "LENOVO", "21BY", + "qcom/sc8280xp-lenovo-thinkpad-x13s.dtb" }, +}; + void * efi_fdt(void) { extern char *hw_vendor, *hw_prod; + size_t vendorlen, prodlen; + char dtb[256]; + int i; /* 'mach dtb' has precedence */ if (fdt_override != NULL) @@ -1122,11 +1136,14 @@ efi_fdt(void) if (hw_vendor == NULL || hw_prod == NULL) return fdt_sys; - if (strcmp(hw_vendor, "LENOVO") == 0) { - if (strncmp(hw_prod, "21BX", 4) == 0 || - strncmp(hw_prod, "21BY", 4) == 0) { - fdt_load_override(FW_PATH - "qcom/sc8280xp-lenovo-thinkpad-x13s.dtb"); + for (i = 0; i < nitems(smbios_dtb); i++) { + vendorlen = strlen(smbios_dtb[i].vendor); + prodlen = strlen(smbios_dtb[i].prod); + if (strncmp(hw_vendor, smbios_dtb[i].vendor, vendorlen) == 0 && + strncmp(hw_prod, smbios_dtb[i].prod, prodlen) == 0) { + snprintf(dtb, sizeof(dtb), "%s%s", FW_PATH, + smbios_dtb[i].dtb); + fdt_load_override(dtb); /* TODO: find a better mechanism */ cnset(ttydev("fb0")); } -- 2.20.1