Source-Changes-HG archive

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

[src/trunk]: src/sys/dev x86's platform.c no longer has any x86 specific code...



details:   https://anonhg.NetBSD.org/src/rev/c1fcf7560608
branches:  trunk
changeset: 1022491:c1fcf7560608
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Wed Jul 21 23:26:15 2021 +0000

description:
x86's platform.c no longer has any x86 specific code in it, so move it to
dev/smbios_platform.c to let other ports use it

diffstat:

 sys/arch/x86/conf/files.x86 |    4 +-
 sys/arch/x86/x86/platform.c |  346 --------------------------------------------
 sys/dev/smbios_platform.c   |  321 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 323 insertions(+), 348 deletions(-)

diffs (truncated from 693 to 300 lines):

diff -r 54ee91f83528 -r c1fcf7560608 sys/arch/x86/conf/files.x86
--- a/sys/arch/x86/conf/files.x86       Wed Jul 21 23:16:08 2021 +0000
+++ b/sys/arch/x86/conf/files.x86       Wed Jul 21 23:26:15 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.x86,v 1.121 2021/07/21 23:16:08 jmcneill Exp $
+#      $NetBSD: files.x86,v 1.122 2021/07/21 23:26:15 jmcneill Exp $
 
 # options for MP configuration through the MP spec
 defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -103,7 +103,7 @@
 file   arch/x86/x86/ipi.c              machdep & !xenpv
 file   arch/x86/x86/mtrr_i686.c        mtrr & !xenpv
 file   arch/x86/x86/patch.c            machdep & !xenpv
-file   arch/x86/x86/platform.c         machdep
+file   dev/smbios_platform.c           machdep
 file   arch/x86/x86/pmap.c             machdep
 file   arch/x86/x86/x86_tlb.c          machdep
 file   arch/x86/x86/procfs_machdep.c   procfs
diff -r 54ee91f83528 -r c1fcf7560608 sys/arch/x86/x86/platform.c
--- a/sys/arch/x86/x86/platform.c       Wed Jul 21 23:16:08 2021 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,346 +0,0 @@
-/* $NetBSD: platform.c,v 1.17 2021/07/21 23:16:09 jmcneill Exp $ */
-
-/*-
- * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
- * 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 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.
- */
-
-#include "isa.h"
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: platform.c,v 1.17 2021/07/21 23:16:09 jmcneill Exp $");
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/uuid.h>
-#include <sys/pmf.h>
-
-#if NISA > 0
-#include <dev/isa/isavar.h>
-#endif
-
-#include <dev/smbiosvar.h>
-
-static int platform_dminode = CTL_EOL;
-
-void           platform_init(void);    /* XXX */
-static void    platform_add(struct smbtable *, const char *, int);
-static void    platform_add_word(struct smbtable *, const char *, uint16_t,
-                               const char *);
-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[] = {
-       "chassis-serial",
-       "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_chassis *pchassis;
-       struct smbios_processor *pproc;
-       struct smbios_slot *pslot;
-       int nisa, nother;
-
-       smbios.cookie = 0;
-       if (smbios_find_table(SMBIOS_TYPE_SYSTEM, &smbios)) {
-               psys = smbios.tblhdr;
-
-               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", 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, "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;
-       if (smbios_find_table(SMBIOS_TYPE_ENCLOSURE, &smbios)) {
-               pchassis = smbios.tblhdr;
-
-               platform_add(&smbios, "chassis-vendor", pchassis->vendor);
-               platform_add(&smbios, "chassis-type", pchassis->shape);
-               platform_add(&smbios, "chassis-version", pchassis->version);
-               platform_add(&smbios, "chassis-serial", pchassis->serial);
-               platform_add(&smbios, "chassis-asset-tag", pchassis->asset);
-       }
-
-       smbios.cookie = 0;
-       if (smbios_find_table(SMBIOS_TYPE_PROCESSOR, &smbios)) {
-               pproc = smbios.tblhdr;
-
-               platform_add(&smbios, "processor-vendor", pproc->vendor);
-               platform_add(&smbios, "processor-version", pproc->version);
-               platform_add_word(&smbios, "processor-frequency",
-                       pproc->curspeed, " MHz");
-       }
-
-       smbios.cookie = 0;
-       nisa = 0;
-       nother = 0;
-       while (smbios_find_table(SMBIOS_TYPE_SLOTS, &smbios)) {
-               pslot = smbios.tblhdr;
-               switch (pslot->type) {
-               case SMBIOS_SLOT_ISA:
-               case SMBIOS_SLOT_EISA:
-                       nisa++;
-                       break;
-               default:
-                       nother++;
-                       break;
-               }
-       }
-
-#if NISA > 0
-       if ((nother | nisa) != 0) {
-               /* Only if there seems to be good expansion slot info. */
-               isa_set_slotcount(nisa);
-       }
-#endif
-
-       platform_print();
-}
-
-static void
-platform_print(void)
-{
-       const char *vend, *prod, *ver;
-
-       vend = pmf_get_platform("system-vendor");
-       prod = pmf_get_platform("system-product");
-       ver = pmf_get_platform("system-version");
-
-       if (vend == NULL)
-               aprint_verbose("Generic");
-       else
-               aprint_verbose("%s", vend);
-       if (prod == NULL)
-               aprint_verbose(" PC");
-       else
-               aprint_verbose(" %s", prod);
-       if (ver != NULL)
-               aprint_verbose(" (%s)", ver);
-       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) {
-               /* add to platform dictionary */
-               pmf_set_platform(key, tmpbuf);
-
-               /* create sysctl node */
-               platform_create_sysctl(key);
-       }
-}
-
-static void
-platform_add_word(struct smbtable *tbl, const char *key, uint16_t val,
-       const char *suf)
-{
-       char tmpbuf[128]; /* XXX is this long enough? */
-
-       if (snprintf(tmpbuf, sizeof(tmpbuf), "%u%s", val, suf)) {
-               /* add to platform dictionary */
-               pmf_set_platform(key, tmpbuf);
-
-               /* create sysctl node */
-               platform_create_sysctl(key);
-       }
-}
-
-static int
-platform_scan_date(char *buf, unsigned int *month, unsigned int *day,
-    unsigned int *year)
-{
-       char *p, *s;
-
-       s = buf;
-       p = strchr(s, '/');
-       if (p) *p = '\0';
-       *month = strtoul(s, NULL, 10);
-       if (!p) return 1;
-
-       s = p + 1;
-       p = strchr(s, '/');
-       if (p) *p = '\0';
-       *day = strtoul(s, NULL, 10);
-       if (!p) return 2;
-
-       s = p + 1;
-       *year = strtoul(s, NULL, 10);
-       return 3;
-}
-
-static void
-platform_add_date(struct smbtable *tbl, const char *key, int idx)
-{
-       unsigned int month, day, year;
-       char tmpbuf[128], datestr[9];
-
-       if (smbios_get_string(tbl, idx, tmpbuf, 128) == NULL)
-               return;
-       if (platform_scan_date(tmpbuf, &month, &day, &year) != 3)
-               return;
-       if (month == 0 || month > 12 || day == 0 || day > 31)



Home | Main Index | Thread Index | Old Index