Module Name:    src
Committed By:   jmcneill
Date:           Thu Jul 22 00:47:56 UTC 2021

Modified Files:
        src/sys/arch/arm/fdt: acpi_fdt.c files.fdt

Log Message:
Expose SMBIOS tables using sysctl machdep.dmi.*, same as x86.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/fdt/acpi_fdt.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/arm/fdt/files.fdt

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/fdt/acpi_fdt.c
diff -u src/sys/arch/arm/fdt/acpi_fdt.c:1.19 src/sys/arch/arm/fdt/acpi_fdt.c:1.20
--- src/sys/arch/arm/fdt/acpi_fdt.c:1.19	Sat Apr 24 23:36:26 2021
+++ src/sys/arch/arm/fdt/acpi_fdt.c	Thu Jul 22 00:47:55 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_fdt.c,v 1.19 2021/04/24 23:36:26 thorpej Exp $ */
+/* $NetBSD: acpi_fdt.c,v 1.20 2021/07/22 00:47:55 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015-2017 Jared McNeill <jmcne...@invisible.ca>
@@ -30,7 +30,7 @@
 #include "opt_efi.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.19 2021/04/24 23:36:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v 1.20 2021/07/22 00:47:55 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -47,6 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_fdt.c,v
 
 #include <dev/acpi/acpivar.h>
 #include <dev/pci/pcivar.h>
+#include <dev/smbiosvar.h>
 
 #include <arm/arm/psci.h>
 
@@ -61,6 +62,7 @@ static void	acpi_fdt_attach(device_t, de
 
 static void	acpi_fdt_poweroff(device_t);
 
+static void	acpi_fdt_smbios_init(device_t);
 static void	acpi_fdt_sysctl_init(void);
 
 extern struct arm32_bus_dma_tag acpi_coherent_dma_tag;
@@ -89,18 +91,24 @@ acpi_fdt_match(device_t parent, cfdata_t
 static void
 acpi_fdt_attach(device_t parent, device_t self, void *aux)
 {
+	extern void platform_init(void); /* XXX */
 	struct fdt_attach_args * const faa = aux;
 	struct acpibus_attach_args aa;
 
 	aprint_naive("\n");
 	aprint_normal("\n");
 
+	acpi_fdt_smbios_init(self);
+	platform_init();
+
 	fdtbus_register_power_controller(self, faa->faa_phandle,
 	    &acpi_fdt_power_funcs);
 
 	if (!acpi_probe())
 		panic("ACPI subsystem failed to initialize");
 
+	platform_init();
+
 	memset(&aa, 0, sizeof(aa));
 #if NPCI > 0
 	aa.aa_pciflags =
@@ -133,26 +141,64 @@ acpi_fdt_poweroff(device_t dev)
 }
 
 static void
+acpi_fdt_smbios_init(device_t dev)
+{
+	struct smb3hdr *sh;
+	uint8_t *ptr;
+
+	const int chosen = OF_finddevice("/chosen");
+	if (chosen >= 0) {
+		of_getprop_uint64(chosen, "netbsd,smbios-table", &smbios_table);
+	}
+	if (smbios_table == 0) {
+		return;
+	}
+
+	sh = AcpiOsMapMemory(smbios_table, sizeof(*sh));
+	if (sh == NULL) {
+		return;
+	}
+	if (!smbios3_check_header((uint8_t *)sh)) {
+		AcpiOsUnmapMemory(sh, sizeof(*sh));
+		return;
+	}
+
+	ptr = AcpiOsMapMemory(sh->addr, sh->size);
+	if (ptr != NULL) {
+		smbios_entry.addr = ptr;
+		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;
+
+		device_printf(dev, "SMBIOS rev. %d.%d.%d @ 0x%lx\n",
+		    sh->majrev, sh->minrev, sh->docrev, (u_long)sh->addr);
+	}
+	AcpiOsUnmapMemory(sh, sizeof(*sh));
+}
+
+static void
 acpi_fdt_sysctl_init(void)
 {
 	const struct sysctlnode *rnode;
 	int error;
 
-	const int chosen = OF_finddevice("/chosen");
-	if (chosen >= 0)
-		of_getprop_uint64(chosen, "netbsd,smbios-table", &smbios_table);
+	if (smbios_table == 0) {
+		return;
+	}
 
 	error = sysctl_createv(NULL, 0, NULL, &rnode,
 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
 	    NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL);
-	if (error)
+	if (error) {
 		return;
-
-	if (smbios_table != 0) {
-		(void)sysctl_createv(NULL, 0, &rnode, NULL,
-		    CTLFLAG_PERMANENT | CTLFLAG_READONLY | CTLFLAG_HEX, CTLTYPE_QUAD,
-		    "smbios", SYSCTL_DESCR("SMBIOS table pointer"),
-		    NULL, 0, &smbios_table, sizeof(smbios_table),
-		    CTL_CREATE, CTL_EOL);
 	}
+
+	(void)sysctl_createv(NULL, 0, &rnode, NULL,
+	    CTLFLAG_PERMANENT | CTLFLAG_READONLY | CTLFLAG_HEX, CTLTYPE_QUAD,
+	    "smbios", SYSCTL_DESCR("SMBIOS table pointer"),
+	    NULL, 0, &smbios_table, sizeof(smbios_table),
+	    CTL_CREATE, CTL_EOL);
 }

Index: src/sys/arch/arm/fdt/files.fdt
diff -u src/sys/arch/arm/fdt/files.fdt:1.33 src/sys/arch/arm/fdt/files.fdt:1.34
--- src/sys/arch/arm/fdt/files.fdt:1.33	Mon Apr 26 14:44:16 2021
+++ src/sys/arch/arm/fdt/files.fdt	Thu Jul 22 00:47:55 2021
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.33 2021/04/26 14:44:16 thorpej Exp $
+# $NetBSD: files.fdt,v 1.34 2021/07/22 00:47:55 jmcneill Exp $
 
 include	"dev/pckbport/files.pckbport"
 
@@ -75,6 +75,7 @@ file	arch/arm/fdt/pmu_fdt.c			pmu_fdt
 attach	genfb at fdt with plfb_fdt: fdt_display_timing
 file	arch/arm/fdt/plfb_fdt.c			plfb_fdt
 
-device	acpifdt: acpibus
+device	acpifdt: acpibus, smbios
 attach	acpifdt at fdt with acpi_fdt
 file	arch/arm/fdt/acpi_fdt.c			acpi_fdt
+file	dev/smbios_platform.c			acpi_fdt

Reply via email to