xref: /freebsd/sys/dev/acpi_support/acpi_rapidstart.c (revision f6a3b357e9be4c6423c85eff9a847163a0d307c8)
1 /*-
2  * Copyright (c) 2013 Takanori Watanabe
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 #include "opt_acpi.h"
31 #include <sys/param.h>
32 #include <sys/kernel.h>
33 #include <sys/bus.h>
34 
35 #include <contrib/dev/acpica/include/acpi.h>
36 
37 #include "acpi_if.h"
38 #include <sys/module.h>
39 #include <dev/acpica/acpivar.h>
40 #include <sys/sysctl.h>
41 static int sysctl_acpi_rapidstart_gen_handler(SYSCTL_HANDLER_ARGS);
42 
43 
44 static struct acpi_rapidstart_name_list
45 {
46 	char *nodename;
47 	char *getmethod;
48 	char *setmethod;
49 	char *comment;
50 } acpi_rapidstart_oids[] ={
51 	{"ffs","GFFS","SFFS","Flash Fast Store Flag"},
52 	{"ftv","GFTV","SFTV","Time value"},
53 	{NULL, NULL, NULL, NULL}
54 };
55 
56 struct acpi_rapidstart_softc {
57 	struct sysctl_ctx_list	*sysctl_ctx;
58 	struct sysctl_oid	*sysctl_tree;
59 
60 };
61 static char    *rapidstart_ids[] = {"INT3392", NULL};
62 static int
63 acpi_rapidstart_probe(device_t dev)
64 {
65 	int rv;
66 
67 	if (acpi_disabled("rapidstart") ||
68 	    device_get_unit(dev) != 0)
69 		return (ENXIO);
70 	rv = ACPI_ID_PROBE(device_get_parent(dev), dev, rapidstart_ids, NULL);
71 	if (rv <= 0)
72 		device_set_desc(dev, "Intel Rapid Start ACPI device");
73 
74 	return (rv);
75 
76 }
77 
78 static int
79 acpi_rapidstart_attach(device_t dev)
80 {
81 	struct acpi_rapidstart_softc *sc;
82 	int i;
83 
84 	sc = device_get_softc(dev);
85 
86 	sc->sysctl_ctx = device_get_sysctl_ctx(dev);
87 	sc->sysctl_tree = device_get_sysctl_tree(dev);
88 	for (i = 0 ; acpi_rapidstart_oids[i].nodename != NULL; i++){
89 		if (acpi_rapidstart_oids[i].setmethod != NULL) {
90 			SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
91 			    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
92 			    i, acpi_rapidstart_oids[i].nodename,
93 			    CTLTYPE_INT | CTLFLAG_RW,
94 			    dev, i, sysctl_acpi_rapidstart_gen_handler, "I",
95 			    acpi_rapidstart_oids[i].comment);
96 		} else {
97 			SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
98 			    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
99 			    i, acpi_rapidstart_oids[i].nodename,
100 			    CTLTYPE_INT | CTLFLAG_RD,
101 			    dev, i, sysctl_acpi_rapidstart_gen_handler, "I",
102 			    acpi_rapidstart_oids[i].comment);
103 		}
104 	}
105 	return (0);
106 }
107 
108 static int
109 sysctl_acpi_rapidstart_gen_handler(SYSCTL_HANDLER_ARGS)
110 {
111 	device_t	dev = arg1;
112 	int 	function = oidp->oid_arg2;
113 	int		error = 0, val;
114 
115 	acpi_GetInteger(acpi_get_handle(dev),
116 	    acpi_rapidstart_oids[function].getmethod, &val);
117 	error = sysctl_handle_int(oidp, &val, 0, req);
118 	if (error || !req->newptr || !acpi_rapidstart_oids[function].setmethod)
119 		return (error);
120 	acpi_SetInteger(acpi_get_handle(dev),
121 	    acpi_rapidstart_oids[function].setmethod, val);
122 	return (0);
123 }
124 
125 static device_method_t acpi_rapidstart_methods[] = {
126 	/* Device interface */
127 	DEVMETHOD(device_probe, acpi_rapidstart_probe),
128 	DEVMETHOD(device_attach, acpi_rapidstart_attach),
129 
130 	DEVMETHOD_END
131 };
132 
133 static driver_t	acpi_rapidstart_driver = {
134 	"acpi_rapidstart",
135 	acpi_rapidstart_methods,
136 	sizeof(struct acpi_rapidstart_softc),
137 };
138 
139 static devclass_t acpi_rapidstart_devclass;
140 
141 DRIVER_MODULE(acpi_rapidstart, acpi, acpi_rapidstart_driver, acpi_rapidstart_devclass,
142 	      0, 0);
143 MODULE_DEPEND(acpi_rapidstart, acpi, 1, 1, 1);
144 
145