Path: blob/main/sys/dev/acpi_support/acpi_rapidstart.c
39534 views
/*-1* Copyright (c) 2013 Takanori Watanabe2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#include <sys/cdefs.h>27#include "opt_acpi.h"28#include <sys/param.h>29#include <sys/kernel.h>30#include <sys/bus.h>3132#include <contrib/dev/acpica/include/acpi.h>3334#include "acpi_if.h"35#include <sys/module.h>36#include <dev/acpica/acpivar.h>37#include <sys/sysctl.h>38static int sysctl_acpi_rapidstart_gen_handler(SYSCTL_HANDLER_ARGS);3940static struct acpi_rapidstart_name_list41{42char *nodename;43char *getmethod;44char *setmethod;45char *comment;46} acpi_rapidstart_oids[] ={47{"ffs","GFFS","SFFS","Flash Fast Store Flag"},48{"ftv","GFTV","SFTV","Time value"},49{NULL, NULL, NULL, NULL}50};5152struct acpi_rapidstart_softc {53struct sysctl_ctx_list *sysctl_ctx;54struct sysctl_oid *sysctl_tree;5556};57static char *rapidstart_ids[] = {"INT3392", NULL};58static int59acpi_rapidstart_probe(device_t dev)60{61int rv;6263if (acpi_disabled("rapidstart") ||64device_get_unit(dev) != 0)65return (ENXIO);66rv = ACPI_ID_PROBE(device_get_parent(dev), dev, rapidstart_ids, NULL);67if (rv <= 0)68device_set_desc(dev, "Intel Rapid Start ACPI device");6970return (rv);7172}7374static int75acpi_rapidstart_attach(device_t dev)76{77struct acpi_rapidstart_softc *sc;78int i;7980sc = device_get_softc(dev);8182sc->sysctl_ctx = device_get_sysctl_ctx(dev);83sc->sysctl_tree = device_get_sysctl_tree(dev);84for (i = 0 ; acpi_rapidstart_oids[i].nodename != NULL; i++){85if (acpi_rapidstart_oids[i].setmethod != NULL) {86SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),87SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),88i, acpi_rapidstart_oids[i].nodename,89CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,90dev, i, sysctl_acpi_rapidstart_gen_handler, "I",91acpi_rapidstart_oids[i].comment);92} else {93SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),94SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),95i, acpi_rapidstart_oids[i].nodename,96CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,97dev, i, sysctl_acpi_rapidstart_gen_handler, "I",98acpi_rapidstart_oids[i].comment);99}100}101return (0);102}103104static int105sysctl_acpi_rapidstart_gen_handler(SYSCTL_HANDLER_ARGS)106{107device_t dev = arg1;108int function = oidp->oid_arg2;109int error = 0, val;110111acpi_GetInteger(acpi_get_handle(dev),112acpi_rapidstart_oids[function].getmethod, &val);113error = sysctl_handle_int(oidp, &val, 0, req);114if (error || !req->newptr || !acpi_rapidstart_oids[function].setmethod)115return (error);116acpi_SetInteger(acpi_get_handle(dev),117acpi_rapidstart_oids[function].setmethod, val);118return (0);119}120121static device_method_t acpi_rapidstart_methods[] = {122/* Device interface */123DEVMETHOD(device_probe, acpi_rapidstart_probe),124DEVMETHOD(device_attach, acpi_rapidstart_attach),125126DEVMETHOD_END127};128129static driver_t acpi_rapidstart_driver = {130"acpi_rapidstart",131acpi_rapidstart_methods,132sizeof(struct acpi_rapidstart_softc),133};134135DRIVER_MODULE(acpi_rapidstart, acpi, acpi_rapidstart_driver, 0, 0);136MODULE_DEPEND(acpi_rapidstart, acpi, 1, 1, 1);137138139