diff --git a/sys/arch/x86/x86/platform.c b/sys/arch/x86/x86/platform.c index 76db9fa01541..0c8a1c0b4c4d 100644 --- a/sys/arch/x86/x86/platform.c +++ b/sys/arch/x86/x86/platform.c @@ -1,4 +1,4 @@ -/* $NetBSD: platform.c,v 1.11 2011/01/18 07:47:16 jmmv Exp $ */ +/* $NetBSD: platform.c,v 1.12 2011/11/14 02:44:59 jmcneill Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill @@ -29,28 +29,44 @@ #include "isa.h" #include -__KERNEL_RCSID(0, "$NetBSD: platform.c,v 1.11 2011/01/18 07:47:16 jmmv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: platform.c,v 1.12 2011/11/14 02:44:59 jmcneill Exp $"); #include #include #include +#include +#include #include #include #include +static int platform_dminode = CTL_EOL; + void platform_init(void); /* XXX */ static void platform_add(struct smbtable *, const char *, int); static void platform_add_date(struct smbtable *, const char *, int); +static void platform_add_uuid(struct smbtable *, const char *, + const uint8_t *); +static int platform_dmi_sysctl(SYSCTLFN_PROTO); static void platform_print(void); +/* list of private DMI sysctl nodes */ +static const char *platform_private_nodes[] = { + "board-serial", + "system-serial", + "system-uuid", + NULL +}; + void platform_init(void) { struct smbtable smbios; struct smbios_sys *psys; struct smbios_struct_bios *pbios; + struct smbios_board *pboard; struct smbios_slot *pslot; int nisa, nother; @@ -58,19 +74,31 @@ platform_init(void) if (smbios_find_table(SMBIOS_TYPE_SYSTEM, &smbios)) { psys = smbios.tblhdr; - platform_add(&smbios, "system-manufacturer", psys->vendor); - platform_add(&smbios, "system-product-name", psys->product); + platform_add(&smbios, "system-vendor", psys->vendor); + platform_add(&smbios, "system-product", psys->product); platform_add(&smbios, "system-version", psys->version); - platform_add(&smbios, "system-serial-number", psys->serial); + platform_add(&smbios, "system-serial", psys->serial); + platform_add_uuid(&smbios, "system-uuid", psys->uuid); } smbios.cookie = 0; if (smbios_find_table(SMBIOS_TYPE_BIOS, &smbios)) { pbios = smbios.tblhdr; - platform_add(&smbios, "firmware-vendor", pbios->vendor); - platform_add(&smbios, "firmware-version", pbios->version); - platform_add_date(&smbios, "firmware-date", pbios->release); + platform_add(&smbios, "bios-vendor", pbios->vendor); + platform_add(&smbios, "bios-version", pbios->version); + platform_add_date(&smbios, "bios-date", pbios->release); + } + + smbios.cookie = 0; + if (smbios_find_table(SMBIOS_TYPE_BASEBOARD, &smbios)) { + pboard = smbios.tblhdr; + + platform_add(&smbios, "board-vendor", pboard->vendor); + platform_add(&smbios, "board-product", pboard->product); + platform_add(&smbios, "board-version", pboard->version); + platform_add(&smbios, "board-serial", pboard->serial); + platform_add(&smbios, "board-asset-tag", pboard->asset); } smbios.cookie = 0; @@ -102,16 +130,16 @@ platform_init(void) static void platform_print(void) { - const char *manuf, *prod, *ver; + const char *vend, *prod, *ver; - manuf = pmf_get_platform("system-manufacturer"); - prod = pmf_get_platform("system-product-name"); + vend = pmf_get_platform("system-vendor"); + prod = pmf_get_platform("system-product"); ver = pmf_get_platform("system-version"); - if (manuf == NULL) + if (vend == NULL) aprint_verbose("Generic"); else - aprint_verbose("%s", manuf); + aprint_verbose("%s", vend); if (prod == NULL) aprint_verbose(" PC"); else @@ -121,13 +149,54 @@ platform_print(void) aprint_verbose("\n"); } +static bool +platform_sysctl_is_private(const char *key) +{ + unsigned int n; + + for (n = 0; platform_private_nodes[n] != NULL; n++) { + if (strcmp(key, platform_private_nodes[n]) == 0) { + return true; + } + } + + return false; +} + +static void +platform_create_sysctl(const char *key) +{ + int flags = 0, err; + + if (pmf_get_platform(key) == NULL) + return; + + /* If the key is marked private, set CTLFLAG_PRIVATE flag */ + if (platform_sysctl_is_private(key)) + flags |= CTLFLAG_PRIVATE; + + err = sysctl_createv(NULL, 0, NULL, NULL, + CTLFLAG_READONLY | flags, CTLTYPE_STRING, + key, NULL, platform_dmi_sysctl, 0, NULL, 0, + CTL_MACHDEP, platform_dminode, CTL_CREATE, CTL_EOL); + if (err != 0) + printf("platform: sysctl_createv " + "(machdep.dmi.%s) failed, err = %d\n", + key, err); +} + static void platform_add(struct smbtable *tbl, const char *key, int idx) { char tmpbuf[128]; /* XXX is this long enough? */ - if (smbios_get_string(tbl, idx, tmpbuf, 128) != NULL) + if (smbios_get_string(tbl, idx, tmpbuf, 128) != NULL) { + /* add to platform dictionary */ pmf_set_platform(key, tmpbuf); + + /* create sysctl node */ + platform_create_sysctl(key); + } } static int @@ -174,3 +243,60 @@ platform_add_date(struct smbtable *tbl, const char *key, int idx) sprintf(datestr, "%04u%02u%02u", year, month, day); pmf_set_platform(key, datestr); } + +static void +platform_add_uuid(struct smbtable *tbl, const char *key, const uint8_t *buf) +{ + struct uuid uuid; + char tmpbuf[UUID_STR_LEN]; + + uuid_dec_le(buf, &uuid); + uuid_snprintf(tmpbuf, sizeof(tmpbuf), &uuid); + + pmf_set_platform(key, tmpbuf); + platform_create_sysctl(key); +} + +static int +platform_dmi_sysctl(SYSCTLFN_ARGS) +{ + struct sysctlnode node; + const char *v; + int err = 0; + + node = *rnode; + + v = pmf_get_platform(node.sysctl_name); + if (v == NULL) + return ENOENT; + + node.sysctl_data = __UNCONST(v); + err = sysctl_lookup(SYSCTLFN_CALL(&node)); + if (err || newp == NULL) + return err; + + return 0; +} + +SYSCTL_SETUP(sysctl_dmi_setup, "sysctl machdep.dmi subtree setup") +{ + const struct sysctlnode *rnode; + int err; + + err = sysctl_createv(clog, 0, NULL, &rnode, + CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", + NULL, NULL, 0, NULL, 0, + CTL_MACHDEP, CTL_EOL); + if (err) + return; + + err = sysctl_createv(clog, 0, &rnode, &rnode, + CTLFLAG_PERMANENT, CTLTYPE_NODE, "dmi", + SYSCTL_DESCR("DMI table information"), + NULL, 0, NULL, 0, + CTL_CREATE, CTL_EOL); + if (err) + return; + + platform_dminode = rnode->sysctl_num; +} diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 656cbf47ceee..5a60c33ab8fc 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi.c,v 1.251 2011/10/18 23:47:26 jmcneill Exp $ */ +/* $NetBSD: acpi.c,v 1.252 2011/11/14 02:44:59 jmcneill Exp $ */ /*- * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc. @@ -100,7 +100,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.251 2011/10/18 23:47:26 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.252 2011/11/14 02:44:59 jmcneill Exp $"); #include "opt_acpi.h" #include "opt_pcifixup.h" @@ -306,7 +306,7 @@ acpi_probe(void) aprint_normal("ACPI: BIOS is too old (%s). " "Set acpi_force_load to use.\n", - pmf_get_platform("firmware-date")); + pmf_get_platform("bios-date")); acpi_unmap_rsdt(rsdt); goto fail; diff --git a/sys/dev/acpi/acpi_cpu.c b/sys/dev/acpi/acpi_cpu.c index 3d51ff9e1a89..f99cfc7ead72 100644 --- a/sys/dev/acpi/acpi_cpu.c +++ b/sys/dev/acpi/acpi_cpu.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_cpu.c,v 1.47 2011/10/27 05:25:07 jruoho Exp $ */ +/* $NetBSD: acpi_cpu.c,v 1.48 2011/11/14 02:44:59 jmcneill Exp $ */ /*- * Copyright (c) 2010, 2011 Jukka Ruohonen @@ -27,7 +27,7 @@ * SUCH DAMAGE. */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.47 2011/10/27 05:25:07 jruoho Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.48 2011/11/14 02:44:59 jmcneill Exp $"); #include #include @@ -98,8 +98,8 @@ acpicpu_match(device_t parent, cfdata_t match, void *aux) if (acpi_softc == NULL) return 0; - manu = pmf_get_platform("system-manufacturer"); - prod = pmf_get_platform("system-product-name"); + manu = pmf_get_platform("system-vendor"); + prod = pmf_get_platform("system-product"); vers = pmf_get_platform("system-version"); if (manu != NULL && prod != NULL && vers != NULL) { diff --git a/sys/dev/acpi/acpi_quirks.c b/sys/dev/acpi/acpi_quirks.c index 2530255bfb87..2e5cc35688fb 100644 --- a/sys/dev/acpi/acpi_quirks.c +++ b/sys/dev/acpi/acpi_quirks.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_quirks.c,v 1.19 2011/02/20 06:45:32 jruoho Exp $ */ +/* $NetBSD: acpi_quirks.c,v 1.20 2011/11/14 02:44:59 jmcneill Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_quirks.c,v 1.19 2011/02/20 06:45:32 jruoho Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_quirks.c,v 1.20 2011/11/14 02:44:59 jmcneill Exp $"); #include "opt_acpi.h" @@ -129,7 +129,7 @@ acpi_quirks_revcmp(uint32_t tabval, uint32_t wanted, int op) static int acpi_quirks_bios_year(void) { - const char *datestr = pmf_get_platform("firmware-date"); + const char *datestr = pmf_get_platform("bios-date"); unsigned long date; if (datestr == NULL)