Path: blob/main/sys/dev/acpi_support/acpi_sbl_wmi.c
39507 views
/*-1* Copyright (c) 2024 Rubicon Communications, LLC (Netgate)2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8* 2. Redistributions in binary form must reproduce the above copyright9* notice, this list of conditions and the following disclaimer in the10* documentation and/or other materials provided with the distribution.11*12* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND13* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE14* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE15* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE16* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL17* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS18* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)19* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT20* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY21* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF22* SUCH DAMAGE.23*/2425#include <sys/cdefs.h>26#include "opt_acpi.h"27#include <sys/param.h>28#include <sys/conf.h>29#include <sys/uio.h>30#include <sys/proc.h>31#include <sys/kernel.h>32#include <sys/bus.h>33#include <sys/sbuf.h>34#include <sys/module.h>35#include <sys/sysctl.h>3637#include <contrib/dev/acpica/include/acpi.h>38#include <contrib/dev/acpica/include/accommon.h>39#include <dev/acpica/acpivar.h>40#include "acpi_wmi_if.h"4142#define _COMPONENT ACPI_OEM43ACPI_MODULE_NAME("SBL-FW-UPDATE-WMI")44ACPI_SERIAL_DECL(sbl_wmi, "SBL WMI device");4546#define ACPI_SBL_FW_UPDATE_WMI_GUID "44FADEB1-B204-40F2-8581-394BBDC1B651"4748struct acpi_sbl_wmi_softc {49device_t dev;50device_t wmi_dev;51};5253static void54acpi_sbl_wmi_identify(driver_t *driver, device_t parent)55{56/* Don't do anything if driver is disabled. */57if (acpi_disabled("sbl_wmi"))58return;5960/* Add only a single device instance. */61if (device_find_child(parent, "acpi_sbl_wmi", DEVICE_UNIT_ANY) != NULL)62return;6364/* Check management GUID to see whether system is compatible. */65if (!ACPI_WMI_PROVIDES_GUID_STRING(parent,66ACPI_SBL_FW_UPDATE_WMI_GUID))67return;6869if (BUS_ADD_CHILD(parent, 0, "acpi_sbl_wmi", DEVICE_UNIT_ANY) == NULL)70device_printf(parent, "add acpi_sbl_wmi child failed\n");71}7273static int74acpi_sbl_wmi_probe(device_t dev)75{76if (!ACPI_WMI_PROVIDES_GUID_STRING(device_get_parent(dev),77ACPI_SBL_FW_UPDATE_WMI_GUID))78return (EINVAL);79device_set_desc(dev, "SBL Firmware Update WMI device");80return (0);81}8283static int84acpi_sbl_wmi_sysctl_get(struct acpi_sbl_wmi_softc *sc, int *val)85{86ACPI_OBJECT *obj;87ACPI_BUFFER out = { ACPI_ALLOCATE_BUFFER, NULL };88int error = 0;8990if (ACPI_FAILURE(ACPI_WMI_GET_BLOCK(sc->wmi_dev,91ACPI_SBL_FW_UPDATE_WMI_GUID, 0, &out))) {92error = EINVAL;93goto out;94}9596obj = out.Pointer;97if (obj->Type != ACPI_TYPE_INTEGER) {98error = EINVAL;99goto out;100}101102*val = obj->Integer.Value;103104out:105if (out.Pointer)106AcpiOsFree(out.Pointer);107108return (error);109}110111static int112acpi_sbl_wmi_sysctl_set(struct acpi_sbl_wmi_softc *sc, int in)113{114ACPI_BUFFER input = { ACPI_ALLOCATE_BUFFER, NULL };115uint32_t val;116117val = in;118input.Length = sizeof(val);119input.Pointer = &val;120121if (ACPI_FAILURE(ACPI_WMI_SET_BLOCK(sc->wmi_dev,122ACPI_SBL_FW_UPDATE_WMI_GUID, 0, &input)))123return (ENODEV);124125return (0);126}127128static int129acpi_sbl_wmi_fw_upgrade_sysctl(SYSCTL_HANDLER_ARGS)130{131struct acpi_sbl_wmi_softc *sc;132int arg;133int error = 0;134135ACPI_SERIAL_BEGIN(sbl_wmi);136137sc = (struct acpi_sbl_wmi_softc *)oidp->oid_arg1;138error = acpi_sbl_wmi_sysctl_get(sc, &arg);139if (error != 0)140goto out;141142error = sysctl_handle_int(oidp, &arg, 0, req);143if (! error && req->newptr != NULL)144error = acpi_sbl_wmi_sysctl_set(sc, arg);145146out:147ACPI_SERIAL_END(sbl_wmi);148149return (error);150}151152static int153acpi_sbl_wmi_attach(device_t dev)154{155struct acpi_sbl_wmi_softc *sc;156struct sysctl_ctx_list *sysctl_ctx;157struct sysctl_oid *sysctl_tree;158159sc = device_get_softc(dev);160sc->dev = dev;161sc->wmi_dev = device_get_parent(dev);162163sysctl_ctx = device_get_sysctl_ctx(dev);164sysctl_tree = device_get_sysctl_tree(dev);165166SYSCTL_ADD_PROC(sysctl_ctx,167SYSCTL_CHILDREN(sysctl_tree), OID_AUTO,168"firmware_update_request",169CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,170sc, 0, acpi_sbl_wmi_fw_upgrade_sysctl, "I",171"Signal SBL that a firmware update is available");172173return (0);174}175176static device_method_t acpi_sbl_wmi_methods[] = {177DEVMETHOD(device_identify, acpi_sbl_wmi_identify),178DEVMETHOD(device_probe, acpi_sbl_wmi_probe),179DEVMETHOD(device_attach, acpi_sbl_wmi_attach),180181DEVMETHOD_END182};183184static driver_t acpi_sbl_wmi_driver = {185"acpi_sbl_wmi",186acpi_sbl_wmi_methods,187sizeof(struct acpi_sbl_wmi_softc),188};189190DRIVER_MODULE(acpi_sbl_wmi, acpi_wmi, acpi_sbl_wmi_driver, 0, 0);191MODULE_DEPEND(acpi_sbl_wmi, acpi_wmi, 1, 1, 1);192MODULE_DEPEND(acpi_sbl_wmi, acpi, 1, 1, 1);193194195