Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/stand/efiboot Use SMBIOS system vendor and product strin...



details:   https://anonhg.NetBSD.org/src/rev/88b125132df0
branches:  trunk
changeset: 461567:88b125132df0
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Nov 30 13:02:18 2019 +0000

description:
Use SMBIOS system vendor and product strings to create a "model" string
for the root node in the fabricated ACPI device tree, when possible.

diffstat:

 sys/stand/efiboot/Makefile.efiboot |    4 +-
 sys/stand/efiboot/efiacpi.c        |   40 ++++-
 sys/stand/efiboot/smbios.c         |  190 ++++++++++++++++++++++++
 sys/stand/efiboot/smbios.h         |  287 +++++++++++++++++++++++++++++++++++++
 sys/stand/efiboot/version          |    3 +-
 5 files changed, 519 insertions(+), 5 deletions(-)

diffs (truncated from 586 to 300 lines):

diff -r b9874390126f -r 88b125132df0 sys/stand/efiboot/Makefile.efiboot
--- a/sys/stand/efiboot/Makefile.efiboot        Sat Nov 30 12:04:13 2019 +0000
+++ b/sys/stand/efiboot/Makefile.efiboot        Sat Nov 30 13:02:18 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.8 2019/07/21 17:01:39 rin Exp $
+# $NetBSD: Makefile.efiboot,v 1.9 2019/11/30 13:02:18 jmcneill Exp $
 
 S=             ${.CURDIR}/../../..
 
@@ -22,7 +22,7 @@
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=       crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
 SOURCES+=      boot.c conf.c console.c dev_net.c devopen.c exec.c panic.c prompt.c
-SOURCES+=      efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c efiacpi.c
+SOURCES+=      efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c efiacpi.c smbios.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=     -I${S}/external/bsd/libfdt/dist
diff -r b9874390126f -r 88b125132df0 sys/stand/efiboot/efiacpi.c
--- a/sys/stand/efiboot/efiacpi.c       Sat Nov 30 12:04:13 2019 +0000
+++ b/sys/stand/efiboot/efiacpi.c       Sat Nov 30 13:02:18 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.4 2019/08/01 13:11:16 jmcneill Exp $ */
+/* $NetBSD: efiacpi.c,v 1.5 2019/11/30 13:02:18 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,6 +32,7 @@
 #include "efiboot.h"
 #include "efiacpi.h"
 #include "efifdt.h"
+#include "smbios.h"
 
 #include <libfdt.h>
 
@@ -77,6 +78,39 @@
        printf("\n");
 }
 
+static char model_buf[128];
+
+static const char *
+efi_acpi_get_model(void)
+{
+       struct smbtable smbios;
+       struct smbios_sys *psys;
+       const char *s;
+       char *buf;
+
+       memset(model_buf, 0, sizeof(model_buf));
+
+       if (smbios3_table != NULL) {
+               smbios_init(smbios3_table);
+
+               buf = model_buf;
+               smbios.cookie = 0;
+               if (smbios_find_table(SMBIOS_TYPE_SYSTEM, &smbios)) {
+                       psys = smbios.tblhdr;
+                       if ((s = smbios_get_string(&smbios, psys->vendor, buf, 64)) != NULL) {
+                               buf += strlen(s);
+                               *buf++ = ' ';
+                       }
+                       smbios_get_string(&smbios, psys->product, buf, 64);
+               }
+       }
+
+       if (model_buf[0] == '\0')
+               strcpy(model_buf, "ACPI");
+
+       return model_buf;
+}
+
 int
 efi_acpi_create_fdt(void)
 {
@@ -94,8 +128,10 @@
        if (error)
                return EIO;
 
+       const char *model = efi_acpi_get_model();
+
        fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "compatible", "netbsd,generic-acpi");
-       fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", "ACPI");
+       fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", model);
        fdt_setprop_cell(fdt, fdt_path_offset(fdt, "/"), "#address-cells", 2);
        fdt_setprop_cell(fdt, fdt_path_offset(fdt, "/"), "#size-cells", 2);
 
diff -r b9874390126f -r 88b125132df0 sys/stand/efiboot/smbios.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/stand/efiboot/smbios.c        Sat Nov 30 13:02:18 2019 +0000
@@ -0,0 +1,190 @@
+/*     $NetBSD: smbios.c,v 1.1 2019/11/30 13:02:18 jmcneill Exp $      */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1999, by UCHIYAMA Yasushi
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. The name of the developer may NOT be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1997-2001 Michael Shalayeff
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: smbios.c,v 1.1 2019/11/30 13:02:18 jmcneill Exp $");
+
+#include <sys/param.h>
+
+#include "efiboot.h"
+#include "smbios.h"
+
+struct smbios_entry smbios_entry;
+
+void
+smbios_init(uint8_t *p)
+{
+       const struct smb3hdr *sh = (const struct smb3hdr *)p;
+
+       smbios_entry.addr = (void *)(uintptr_t)sh->addr;
+       smbios_entry.len = sh->size;
+       smbios_entry.rev = sh->eprev;
+       smbios_entry.mjr = sh->majrev;
+       smbios_entry.min = sh->minrev;
+       smbios_entry.doc = sh->docrev;
+       smbios_entry.count = UINT16_MAX;
+}
+
+/*
+ * smbios_find_table() takes a caller supplied smbios struct type and
+ * a pointer to a handle (struct smbtable) returning one if the structure
+ * is sucessfully located and zero otherwise. Callers should take care
+ * to initilize the cookie field of the smbtable structure to zero before
+ * the first invocation of this function.
+ * Multiple tables of the same type can be located by repeadtly calling
+ * smbios_find_table with the same arguments.
+ */
+int
+smbios_find_table(uint8_t type, struct smbtable *st)
+{
+       uint8_t *va, *end;
+       struct smbtblhdr *hdr;
+       int ret = 0, tcount = 1;
+
+       va = smbios_entry.addr;
+       end = va + smbios_entry.len;
+
+       /*
+        * The cookie field of the smtable structure is used to locate
+        * multiple instances of a table of an arbitrary type. Following the
+        * sucessful location of a table, the type is encoded as bits 0:7 of
+        * the cookie value, the offset in terms of the number of structures
+        * preceding that referenced by the handle is encoded in bits 15:31.
+        */
+       if ((st->cookie & 0xfff) == type && st->cookie >> 16) {
+               if ((uint8_t *)st->hdr >= va && (uint8_t *)st->hdr < end) {
+                       hdr = st->hdr;
+                       if (hdr->type == type) {
+                               va = (uint8_t *)hdr + hdr->size;
+                               for (; va + 1 < end; va++)
+                                       if (*va == 0 && *(va + 1) == 0)
+                                               break;
+                               va+= 2;
+                               tcount = st->cookie >> 16;
+                       }
+               }
+       }
+       for (; va + sizeof(struct smbtblhdr) < end && tcount <=
+           smbios_entry.count; tcount++) {
+               hdr = (struct smbtblhdr *)va;
+               if (hdr->type == type) {
+                       ret = 1;
+                       st->hdr = hdr;
+                       st->tblhdr = va + sizeof(struct smbtblhdr);
+                       st->cookie = (tcount + 1) << 16 | type;
+                       break;
+               }
+               if (hdr->type == SMBIOS_TYPE_EOT)
+                       break;
+               va+= hdr->size;
+               for (; va + 1 < end; va++)
+                       if (*va == 0 && *(va + 1) == 0)
+                               break;
+               va+=2;
+       }
+
+       return ret;
+}
+
+char *
+smbios_get_string(struct smbtable *st, uint8_t indx, char *dest, size_t len)
+{
+       uint8_t *va, *end;
+       char *ret = NULL;
+       int i;
+
+       va = (uint8_t *)st->hdr + st->hdr->size;
+       end = smbios_entry.addr + smbios_entry.len;
+       for (i = 1; va < end && i < indx && *va; i++)
+               while (*va++)
+                       ;
+       if (i == indx) {
+               if (va + len < end) {
+                       ret = dest;
+                       memcpy(ret, va, len);
+                       ret[len - 1] = '\0';
+               }
+       }
+
+       return ret;
+}
diff -r b9874390126f -r 88b125132df0 sys/stand/efiboot/smbios.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/stand/efiboot/smbios.h        Sat Nov 30 13:02:18 2019 +0000
@@ -0,0 +1,287 @@
+/*     $NetBSD: smbios.h,v 1.1 2019/11/30 13:02:18 jmcneill Exp $ */
+/*
+ * Copyright (c) 2006 Gordon Willem Klok <gklok%cogeco.ca@localhost>
+ * Copyright (c) 2005 Jordan Hargrave
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *



Home | Main Index | Thread Index | Old Index