Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ofw make OpenFirmware info available via sysctl.ofw



details:   https://anonhg.NetBSD.org/src/rev/8daaba9488c7
branches:  trunk
changeset: 1008779:8daaba9488c7
user:      macallan <macallan%NetBSD.org@localhost>
date:      Fri Apr 03 06:02:51 2020 +0000

description:
make OpenFirmware info available via sysctl.ofw
tested on macppc, shark and sparc64

diffstat:

 sys/dev/ofw/files.ofw    |   3 +-
 sys/dev/ofw/ofw_sysctl.c |  64 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletions(-)

diffs (85 lines):

diff -r 481c9f79fd40 -r 8daaba9488c7 sys/dev/ofw/files.ofw
--- a/sys/dev/ofw/files.ofw     Fri Apr 03 03:35:16 2020 +0000
+++ b/sys/dev/ofw/files.ofw     Fri Apr 03 06:02:51 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.ofw,v 1.14 2015/12/16 12:22:48 jmcneill Exp $
+#      $NetBSD: files.ofw,v 1.15 2020/04/03 06:02:51 macallan Exp $
 #
 # First cut on Openfirmware interface
 #
@@ -9,6 +9,7 @@
 
 defpseudo openfirm
 file   dev/ofw/openfirmio.c            openfirm needs-flag
+file   dev/ofw/ofw_sysctl.c            openfirm | ofw_subr
 
 file   dev/ofw/ofw_subr.c              ofbus | openfirm | ofw_subr
 
diff -r 481c9f79fd40 -r 8daaba9488c7 sys/dev/ofw/ofw_sysctl.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ofw/ofw_sysctl.c  Fri Apr 03 06:02:51 2020 +0000
@@ -0,0 +1,64 @@
+/*     $NetBSD: ofw_sysctl.c,v 1.1 2020/04/03 06:02:51 macallan Exp $ */
+
+/*-
+ * Copyright (c) 2020 Michael Lorenz
+ * 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 <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ofw_sysctl.c,v 1.1 2020/04/03 06:02:51 macallan Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/types.h>
+
+#include <sys/sysctl.h>
+#include <dev/ofw/openfirm.h>
+
+char firmwarestring[64] = "unknown";
+
+SYSCTL_SETUP(sysctl_hw_misc_setup, "sysctl hw.ofw subtree misc setup")
+{
+       const struct sysctlnode *me;
+       int openprom;
+
+       if ((openprom = OF_finddevice("/openprom")) != 0) {
+               memset(firmwarestring, 0, 64);
+               if (OF_getprop(openprom, "model", firmwarestring, 63) != 0) {
+                       printf("firmware: %s\n", firmwarestring);
+               }
+       }
+
+       sysctl_createv(clog, 0, NULL, &me,
+               CTLFLAG_PERMANENT,
+               CTLTYPE_NODE, "ofw",
+               SYSCTL_DESCR("OpenFirmware information"),
+               NULL, 0, NULL, 0,
+               CTL_HW, CTL_CREATE, CTL_EOL);
+       sysctl_createv(clog, 0, NULL, NULL,
+               CTLFLAG_PERMANENT,
+               CTLTYPE_STRING, "version",
+               SYSCTL_DESCR("firmware version string"),
+               NULL, 0, firmwarestring, 0,
+               CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL);
+}



Home | Main Index | Thread Index | Old Index