1*155c79f1Smacallan /* $NetBSD: ofw_sysctl.c,v 1.2 2020/04/03 21:55:07 macallan Exp $ */ 253be9e9cSmacallan 353be9e9cSmacallan /*- 453be9e9cSmacallan * Copyright (c) 2020 Michael Lorenz 553be9e9cSmacallan * All rights reserved. 653be9e9cSmacallan * 753be9e9cSmacallan * Redistribution and use in source and binary forms, with or without 853be9e9cSmacallan * modification, are permitted provided that the following conditions 953be9e9cSmacallan * are met: 1053be9e9cSmacallan * 1. Redistributions of source code must retain the above copyright 1153be9e9cSmacallan * notice, this list of conditions and the following disclaimer. 1253be9e9cSmacallan * 2. Redistributions in binary form must reproduce the above copyright 1353be9e9cSmacallan * notice, this list of conditions and the following disclaimer in the 1453be9e9cSmacallan * documentation and/or other materials provided with the distribution. 1553be9e9cSmacallan * 1653be9e9cSmacallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1753be9e9cSmacallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1853be9e9cSmacallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1953be9e9cSmacallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2053be9e9cSmacallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2153be9e9cSmacallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2253be9e9cSmacallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2353be9e9cSmacallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2453be9e9cSmacallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2553be9e9cSmacallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2653be9e9cSmacallan * POSSIBILITY OF SUCH DAMAGE. 2753be9e9cSmacallan */ 2853be9e9cSmacallan #include <sys/cdefs.h> 29*155c79f1Smacallan __KERNEL_RCSID(0, "$NetBSD: ofw_sysctl.c,v 1.2 2020/04/03 21:55:07 macallan Exp $"); 3053be9e9cSmacallan 3153be9e9cSmacallan #include <sys/param.h> 3253be9e9cSmacallan #include <sys/systm.h> 3353be9e9cSmacallan #include <sys/types.h> 3453be9e9cSmacallan 3553be9e9cSmacallan #include <sys/sysctl.h> 3653be9e9cSmacallan #include <dev/ofw/openfirm.h> 3753be9e9cSmacallan 3853be9e9cSmacallan char firmwarestring[64] = "unknown"; 39*155c79f1Smacallan char firmwareversion[64] = "unknown"; 4053be9e9cSmacallan 4153be9e9cSmacallan SYSCTL_SETUP(sysctl_hw_misc_setup, "sysctl hw.ofw subtree misc setup") 4253be9e9cSmacallan { 4353be9e9cSmacallan const struct sysctlnode *me; 4453be9e9cSmacallan int openprom; 4553be9e9cSmacallan 46*155c79f1Smacallan openprom = OF_finddevice("/openprom"); 47*155c79f1Smacallan if (openprom == 0 || openprom == -1) return; 4853be9e9cSmacallan 4953be9e9cSmacallan sysctl_createv(clog, 0, NULL, &me, 5053be9e9cSmacallan CTLFLAG_PERMANENT, 5153be9e9cSmacallan CTLTYPE_NODE, "ofw", 5253be9e9cSmacallan SYSCTL_DESCR("OpenFirmware information"), 5353be9e9cSmacallan NULL, 0, NULL, 0, 5453be9e9cSmacallan CTL_HW, CTL_CREATE, CTL_EOL); 55*155c79f1Smacallan 56*155c79f1Smacallan memset(firmwarestring, 0, 64); 57*155c79f1Smacallan if (OF_getprop(openprom, "model", firmwarestring, 63) > 0) { 58*155c79f1Smacallan 59*155c79f1Smacallan aprint_debug("firmware: %s\n", firmwarestring); 60*155c79f1Smacallan sysctl_createv(clog, 0, NULL, NULL, 61*155c79f1Smacallan CTLFLAG_PERMANENT, 62*155c79f1Smacallan CTLTYPE_STRING, "model", 63*155c79f1Smacallan SYSCTL_DESCR("firmware type"), 64*155c79f1Smacallan NULL, 0, firmwarestring, 0, 65*155c79f1Smacallan CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL); 66*155c79f1Smacallan } 67*155c79f1Smacallan 68*155c79f1Smacallan memset(firmwareversion, 0, 64); 69*155c79f1Smacallan if (OF_getprop(openprom, "version", firmwareversion, 63) > 0) { 70*155c79f1Smacallan 71*155c79f1Smacallan aprint_debug("version: %s\n", firmwareversion); 7253be9e9cSmacallan sysctl_createv(clog, 0, NULL, NULL, 7353be9e9cSmacallan CTLFLAG_PERMANENT, 7453be9e9cSmacallan CTLTYPE_STRING, "version", 75*155c79f1Smacallan SYSCTL_DESCR("firmware version"), 76*155c79f1Smacallan NULL, 0, firmwareversion, 0, 7753be9e9cSmacallan CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL); 7853be9e9cSmacallan } 79*155c79f1Smacallan } 80