Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/dev/acpi_support/acpi_rapidstart.c
39534 views
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
#include "opt_acpi.h"
29
#include <sys/param.h>
30
#include <sys/kernel.h>
31
#include <sys/bus.h>
32
33
#include <contrib/dev/acpica/include/acpi.h>
34
35
#include "acpi_if.h"
36
#include <sys/module.h>
37
#include <dev/acpica/acpivar.h>
38
#include <sys/sysctl.h>
39
static int sysctl_acpi_rapidstart_gen_handler(SYSCTL_HANDLER_ARGS);
40
41
static struct acpi_rapidstart_name_list
42
{
43
char *nodename;
44
char *getmethod;
45
char *setmethod;
46
char *comment;
47
} acpi_rapidstart_oids[] ={
48
{"ffs","GFFS","SFFS","Flash Fast Store Flag"},
49
{"ftv","GFTV","SFTV","Time value"},
50
{NULL, NULL, NULL, NULL}
51
};
52
53
struct acpi_rapidstart_softc {
54
struct sysctl_ctx_list *sysctl_ctx;
55
struct sysctl_oid *sysctl_tree;
56
57
};
58
static char *rapidstart_ids[] = {"INT3392", NULL};
59
static int
60
acpi_rapidstart_probe(device_t dev)
61
{
62
int rv;
63
64
if (acpi_disabled("rapidstart") ||
65
device_get_unit(dev) != 0)
66
return (ENXIO);
67
rv = ACPI_ID_PROBE(device_get_parent(dev), dev, rapidstart_ids, NULL);
68
if (rv <= 0)
69
device_set_desc(dev, "Intel Rapid Start ACPI device");
70
71
return (rv);
72
73
}
74
75
static int
76
acpi_rapidstart_attach(device_t dev)
77
{
78
struct acpi_rapidstart_softc *sc;
79
int i;
80
81
sc = device_get_softc(dev);
82
83
sc->sysctl_ctx = device_get_sysctl_ctx(dev);
84
sc->sysctl_tree = device_get_sysctl_tree(dev);
85
for (i = 0 ; acpi_rapidstart_oids[i].nodename != NULL; i++){
86
if (acpi_rapidstart_oids[i].setmethod != NULL) {
87
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
88
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
89
i, acpi_rapidstart_oids[i].nodename,
90
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE,
91
dev, i, sysctl_acpi_rapidstart_gen_handler, "I",
92
acpi_rapidstart_oids[i].comment);
93
} else {
94
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
95
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
96
i, acpi_rapidstart_oids[i].nodename,
97
CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
98
dev, i, sysctl_acpi_rapidstart_gen_handler, "I",
99
acpi_rapidstart_oids[i].comment);
100
}
101
}
102
return (0);
103
}
104
105
static int
106
sysctl_acpi_rapidstart_gen_handler(SYSCTL_HANDLER_ARGS)
107
{
108
device_t dev = arg1;
109
int function = oidp->oid_arg2;
110
int error = 0, val;
111
112
acpi_GetInteger(acpi_get_handle(dev),
113
acpi_rapidstart_oids[function].getmethod, &val);
114
error = sysctl_handle_int(oidp, &val, 0, req);
115
if (error || !req->newptr || !acpi_rapidstart_oids[function].setmethod)
116
return (error);
117
acpi_SetInteger(acpi_get_handle(dev),
118
acpi_rapidstart_oids[function].setmethod, val);
119
return (0);
120
}
121
122
static device_method_t acpi_rapidstart_methods[] = {
123
/* Device interface */
124
DEVMETHOD(device_probe, acpi_rapidstart_probe),
125
DEVMETHOD(device_attach, acpi_rapidstart_attach),
126
127
DEVMETHOD_END
128
};
129
130
static driver_t acpi_rapidstart_driver = {
131
"acpi_rapidstart",
132
acpi_rapidstart_methods,
133
sizeof(struct acpi_rapidstart_softc),
134
};
135
136
DRIVER_MODULE(acpi_rapidstart, acpi, acpi_rapidstart_driver, 0, 0);
137
MODULE_DEPEND(acpi_rapidstart, acpi, 1, 1, 1);
138
139