Module Name:    src
Committed By:   macallan
Date:           Fri Apr  3 06:02:51 UTC 2020

Modified Files:
        src/sys/dev/ofw: files.ofw
Added Files:
        src/sys/dev/ofw: ofw_sysctl.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/ofw/files.ofw
cvs rdiff -u -r0 -r1.1 src/sys/dev/ofw/ofw_sysctl.c

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

Modified files:

Index: src/sys/dev/ofw/files.ofw
diff -u src/sys/dev/ofw/files.ofw:1.14 src/sys/dev/ofw/files.ofw:1.15
--- src/sys/dev/ofw/files.ofw:1.14	Wed Dec 16 12:22:48 2015
+++ src/sys/dev/ofw/files.ofw	Fri Apr  3 06:02:51 2020
@@ -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 @@ define	ofw_subr
 
 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
 

Added files:

Index: src/sys/dev/ofw/ofw_sysctl.c
diff -u /dev/null src/sys/dev/ofw/ofw_sysctl.c:1.1
--- /dev/null	Fri Apr  3 06:02:51 2020
+++ src/sys/dev/ofw/ofw_sysctl.c	Fri Apr  3 06:02:51 2020
@@ -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);
+}

Reply via email to