Add code for device wake capability during sleeping state.
- Add acpi_gpe_enable_bit() to manipulate GPE enable registers based on _PRW objects. - Add acpi_set_device_wakecap(). This will manipulate related PowerResource objects and execute _PSW method of the device. - Cleanup and some small fixes. This code was implemented based on 7.2.1 _PRW in spec mainly.
This commit is contained in:
parent
4da485b40d
commit
d4c2a7c9ac
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=66399
@ -299,6 +299,34 @@ acpi_pmap_vtp(vm_offset_t va)
|
||||
* ACPI Registers I/O
|
||||
*/
|
||||
|
||||
void
|
||||
acpi_gpe_enable_bit(acpi_softc_t *sc, u_int32_t bit, boolean_t on_off)
|
||||
{
|
||||
int x;
|
||||
u_int32_t pos, value;
|
||||
void (*GPEx_EN[])(acpi_softc_t *, boolean_t, u_int32_t *) = {
|
||||
acpi_io_gpe0_enable, acpi_io_gpe0_enable
|
||||
};
|
||||
|
||||
x = -1;
|
||||
pos = bit;
|
||||
if (bit < sc->facp_body->gpe0_len * 4) {
|
||||
x = 0;
|
||||
} else {
|
||||
/* should we check gpe1_len too? */
|
||||
pos = bit - sc->facp_body->gpe1_base;
|
||||
x = 1;
|
||||
}
|
||||
|
||||
if (x == -1 || (on_off != 0 && on_off != 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GPEx_EN[x](sc, ACPI_REGISTERS_INPUT, &value);
|
||||
value = (value & (~(1 << pos))) | (on_off << pos);
|
||||
GPEx_EN[x](sc, ACPI_REGISTERS_OUTPUT, &value);
|
||||
}
|
||||
|
||||
static __inline void
|
||||
acpi_register_input(u_int32_t ioaddr, u_int32_t *value, u_int32_t size)
|
||||
{
|
||||
@ -1166,11 +1194,12 @@ acpi_intr(void *data)
|
||||
acpi_debug = 0; /* Shut up again */
|
||||
}
|
||||
|
||||
acpi_debug = debug; /* Restore debug level */
|
||||
|
||||
/* do something to handle the events... */
|
||||
acpi_process_event(sc, status_a, status_b, status_0, status_1);
|
||||
|
||||
acpi_debug = debug; /* Restore debug level */
|
||||
}
|
||||
|
||||
static int acpi_set_gpe_bits(struct aml_name *name,va_list ap)
|
||||
{
|
||||
struct acpi_softc *sc=va_arg(ap, struct acpi_softc *);
|
||||
|
@ -34,14 +34,31 @@
|
||||
struct acpi_powerres_device {
|
||||
LIST_ENTRY(acpi_powerres_device) links;
|
||||
struct aml_name *name;
|
||||
|
||||
/* _PR[0-2] */
|
||||
#define ACPI_D_STATE_D0 0
|
||||
#define ACPI_D_STATE_D1 1
|
||||
#define ACPI_D_STATE_D2 2
|
||||
#define ACPI_D_STATE_D3 3
|
||||
#define ACPI_D_STATE_UNKNOWN 255
|
||||
u_int8_t state; /* D0 to D3 */
|
||||
u_int8_t next_state; /* initialized with D0 */
|
||||
/* _PRW */
|
||||
#define ACPI_D_WAKECAP_DISABLE 0
|
||||
#define ACPI_D_WAKECAP_ENABLE 1
|
||||
#define ACPI_D_WAKECAP_UNKNOWN 255
|
||||
#define ACPI_D_WAKECAP_DEFAULT 1 /* XXX default enable for testing */
|
||||
u_int8_t wake_cap; /* wake capability */
|
||||
boolean_t gpe_enabled; /* GEPx_EN enabled/disabled */
|
||||
union aml_object *prw_val[2]; /* elements of _PRW package */
|
||||
};
|
||||
|
||||
/* Device Power Management Chind Object Type */
|
||||
#define ACPI_D_PM_TYPE_IRC 0 /* _IRC */
|
||||
#define ACPI_D_PM_TYPE_PRW 1 /* _PRW */
|
||||
#define ACPI_D_PM_TYPE_PRX 2 /* _PR0 - _PR2 */
|
||||
/* and more... */
|
||||
|
||||
struct acpi_powerres_device_ref {
|
||||
LIST_ENTRY(acpi_powerres_device_ref) links;
|
||||
struct acpi_powerres_device *device;
|
||||
@ -55,6 +72,7 @@ struct acpi_powerres_info {
|
||||
u_int8_t state; /* OFF or ON */
|
||||
#define ACPI_PR_MAX 3 /* _PR[0-2] */
|
||||
LIST_HEAD(, acpi_powerres_device_ref) reflist[ACPI_PR_MAX];
|
||||
LIST_HEAD(, acpi_powerres_device_ref) prwlist;
|
||||
};
|
||||
/*Event Structure */
|
||||
struct acpi_event {
|
||||
@ -91,6 +109,8 @@ typedef struct acpi_softc {
|
||||
u_int8_t acpi_get_current_device_state(struct aml_name *);
|
||||
void acpi_set_device_state(acpi_softc_t *, struct aml_name *,
|
||||
u_int8_t);
|
||||
void acpi_set_device_wakecap(acpi_softc_t *, struct aml_name *,
|
||||
u_int8_t);
|
||||
|
||||
/* PowerResource State */
|
||||
void acpi_powerres_init(acpi_softc_t *);
|
||||
@ -100,6 +120,9 @@ void acpi_set_powerres_state(acpi_softc_t *, struct aml_name *,
|
||||
u_int8_t);
|
||||
void acpi_powerres_set_sleeping_state(acpi_softc_t *, u_int8_t);
|
||||
|
||||
/* GPE enable bit manipulation */
|
||||
void acpi_gpe_enable_bit(acpi_softc_t *, u_int32_t, boolean_t);
|
||||
|
||||
/*Event queue*/
|
||||
void acpi_queue_event(int, int);
|
||||
#endif /* !_DEV_ACPI_ACPI_H_ */
|
||||
|
@ -47,6 +47,11 @@
|
||||
static int acpi_powerres_register(struct aml_name *name, va_list ap);
|
||||
static int acpi_powerres_add_device(struct aml_name *name, va_list ap);
|
||||
|
||||
static void acpi_set_device_next_state(acpi_softc_t *sc,
|
||||
struct acpi_powerres_device *device,
|
||||
u_int8_t sleeping_state,
|
||||
u_int8_t def_dstate);
|
||||
|
||||
static char *powerres_statestr[2] = {"_OFF", "_ON"};
|
||||
|
||||
/*
|
||||
@ -74,6 +79,20 @@ acpi_get_current_device_state(struct aml_name *name)
|
||||
return (dstate);
|
||||
}
|
||||
|
||||
static __inline struct acpi_powerres_device *
|
||||
acpi_powerres_get_powerres_device(acpi_softc_t *sc, struct aml_name *name)
|
||||
{
|
||||
struct acpi_powerres_device *device;
|
||||
|
||||
LIST_FOREACH(device, &sc->acpi_powerres_devlist, links) {
|
||||
if (device->name == name) {
|
||||
return (device);
|
||||
}
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* 7.2.2-4: For the OS to put the device in the Dx device state.
|
||||
*/
|
||||
@ -83,6 +102,7 @@ acpi_set_device_state(acpi_softc_t *sc, struct aml_name *name, u_int8_t dstate)
|
||||
char psx[5]; /* "_PSx" */
|
||||
struct acpi_powerres_info *powerres;
|
||||
struct acpi_powerres_device_ref *device_ref;
|
||||
struct acpi_powerres_device *device;
|
||||
struct aml_name *method;
|
||||
struct aml_environ env;
|
||||
|
||||
@ -90,27 +110,40 @@ acpi_set_device_state(acpi_softc_t *sc, struct aml_name *name, u_int8_t dstate)
|
||||
return;
|
||||
}
|
||||
|
||||
device = acpi_powerres_get_powerres_device(sc, name);
|
||||
if (device == NULL) {
|
||||
return;
|
||||
}
|
||||
device->state = dstate;
|
||||
|
||||
/*
|
||||
* D3 state transition. We don't need to check PowerResource,
|
||||
* just execute _PS3 control method of the device.
|
||||
*/
|
||||
if (dstate == ACPI_D_STATE_D3) {
|
||||
goto method_execution;
|
||||
}
|
||||
|
||||
/*
|
||||
* D0 - D2 state transition.
|
||||
* All Power Resources referenced by elements 1 through N
|
||||
* in _PRx of the device must be in the ON state.
|
||||
*
|
||||
*/
|
||||
if (dstate < ACPI_PR_MAX) {
|
||||
LIST_FOREACH(powerres, &sc->acpi_powerres_inflist, links) {
|
||||
LIST_FOREACH(device_ref, &powerres->reflist[dstate], links) {
|
||||
if (device_ref->device->name != name) {
|
||||
continue;
|
||||
}
|
||||
if (powerres->state == ACPI_POWER_RESOURCE_ON) {
|
||||
continue;
|
||||
}
|
||||
LIST_FOREACH(powerres, &sc->acpi_powerres_inflist, links) {
|
||||
LIST_FOREACH(device_ref, &powerres->reflist[dstate], links) {
|
||||
if (device_ref->device->name != name) {
|
||||
continue;
|
||||
}
|
||||
if (powerres->state != ACPI_POWER_RESOURCE_ON) {
|
||||
acpi_set_powerres_state(sc, powerres->name,
|
||||
ACPI_POWER_RESOURCE_ON);
|
||||
powerres->state = ACPI_POWER_RESOURCE_ON;
|
||||
}
|
||||
break; /* already found, goto next PowerResource */
|
||||
}
|
||||
}
|
||||
|
||||
method_execution:
|
||||
/*
|
||||
* If present, the _PSx control method is executed to set the
|
||||
* device into the Dx device state.
|
||||
@ -127,6 +160,72 @@ acpi_set_device_state(acpi_softc_t *sc, struct aml_name *name, u_int8_t dstate)
|
||||
aml_local_stack_delete(aml_local_stack_pop());
|
||||
}
|
||||
|
||||
/*
|
||||
* 7.2.1: For the OS to have the defined wake capability properly enabled
|
||||
* for the device.
|
||||
*/
|
||||
void
|
||||
acpi_set_device_wakecap(acpi_softc_t *sc, struct aml_name *name, u_int8_t cap)
|
||||
{
|
||||
struct acpi_powerres_info *powerres;
|
||||
struct acpi_powerres_device_ref *device_ref;
|
||||
struct acpi_powerres_device *device;
|
||||
struct aml_name *method;
|
||||
union aml_object argv[1];
|
||||
|
||||
if (cap != ACPI_D_WAKECAP_ENABLE && cap != ACPI_D_WAKECAP_DISABLE ) {
|
||||
return;
|
||||
}
|
||||
|
||||
device = acpi_powerres_get_powerres_device(sc, name);
|
||||
if (device == NULL) {
|
||||
return;
|
||||
}
|
||||
device->wake_cap = cap;
|
||||
|
||||
/*
|
||||
* Disable wake capability. We don't need to check PowerResource,
|
||||
* just execute _PSW control method of the device.
|
||||
*/
|
||||
if (cap == ACPI_D_WAKECAP_DISABLE ) {
|
||||
goto method_execution;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable wake capability.
|
||||
* All Power Resources referenced by elements 2 through N
|
||||
* are put into the ON state.
|
||||
*
|
||||
*/
|
||||
LIST_FOREACH(powerres, &sc->acpi_powerres_inflist, links) {
|
||||
LIST_FOREACH(device_ref, &powerres->prwlist, links) {
|
||||
if (device_ref->device->name != name) {
|
||||
continue;
|
||||
}
|
||||
if (powerres->state != ACPI_POWER_RESOURCE_ON) {
|
||||
acpi_set_powerres_state(sc, powerres->name,
|
||||
ACPI_POWER_RESOURCE_ON);
|
||||
}
|
||||
break; /* already found, goto next PowerResource */
|
||||
}
|
||||
}
|
||||
|
||||
method_execution:
|
||||
/*
|
||||
* If present, the _PSW control method is executed to set the
|
||||
* device-specific registers to enable the wake functionality
|
||||
* of the device.
|
||||
*/
|
||||
method = aml_find_from_namespace(name, "_PSW");
|
||||
if (method == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
argv[0].type = aml_t_num;
|
||||
argv[0].num.number = cap;
|
||||
aml_invoke_method(method, 1, argv); /* no result code */
|
||||
}
|
||||
|
||||
/*
|
||||
* 7.4.1 Returns the current ON or OFF status for the power resource.
|
||||
*/
|
||||
@ -152,6 +251,20 @@ acpi_get_current_powerres_state(struct aml_name *name)
|
||||
return (pstate);
|
||||
}
|
||||
|
||||
static __inline struct acpi_powerres_info *
|
||||
acpi_powerres_get_powerres(acpi_softc_t *sc, struct aml_name *name)
|
||||
{
|
||||
struct acpi_powerres_info *powerres;
|
||||
|
||||
LIST_FOREACH(powerres, &sc->acpi_powerres_inflist, links) {
|
||||
if (powerres->name == name) {
|
||||
return (powerres);
|
||||
}
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* 7.4.2,3 Puts the power resource into the ON/OFF state.
|
||||
*/
|
||||
@ -159,6 +272,7 @@ void
|
||||
acpi_set_powerres_state(acpi_softc_t *sc, struct aml_name *name,
|
||||
u_int8_t pstate)
|
||||
{
|
||||
struct acpi_powerres_info *powerres;
|
||||
struct aml_name *method;
|
||||
struct aml_environ env;
|
||||
|
||||
@ -167,6 +281,12 @@ acpi_set_powerres_state(acpi_softc_t *sc, struct aml_name *name,
|
||||
return;
|
||||
}
|
||||
|
||||
powerres = acpi_powerres_get_powerres(sc, name);
|
||||
if (powerres == NULL) {
|
||||
return;
|
||||
}
|
||||
powerres->state = pstate;
|
||||
|
||||
method = aml_find_from_namespace(name, powerres_statestr[pstate]);
|
||||
if (method == NULL) {
|
||||
return; /* just in case */
|
||||
@ -197,6 +317,7 @@ acpi_powerres_init(acpi_softc_t *sc)
|
||||
}
|
||||
LIST_INIT(&powerres->reflist[i]);
|
||||
}
|
||||
LIST_INIT(&powerres->prwlist);
|
||||
LIST_REMOVE(powerres, links);
|
||||
FREE(powerres, M_TEMP);
|
||||
}
|
||||
@ -214,6 +335,25 @@ acpi_powerres_init(acpi_softc_t *sc)
|
||||
acpi_powerres_add_device, sc);
|
||||
}
|
||||
|
||||
static __inline void
|
||||
acpi_powerres_device_prw_print(struct acpi_powerres_device *device)
|
||||
{
|
||||
|
||||
printf("[PRW:%d:", device->wake_cap);
|
||||
switch (device->prw_val[0]->type) {
|
||||
case aml_t_num:
|
||||
/* bit index in GPEx_EN of the enable bit */
|
||||
printf("0x%x", device->prw_val[0]->num.number);
|
||||
break;
|
||||
default:
|
||||
/* XXX in ACPI 2.0, we can have additional GPE blocks */
|
||||
printf("GPE block");
|
||||
break;
|
||||
}
|
||||
/* the lowest sleeping state */
|
||||
printf(":%d] ", device->prw_val[1]->num.number);
|
||||
}
|
||||
|
||||
void
|
||||
acpi_powerres_debug(acpi_softc_t *sc)
|
||||
{
|
||||
@ -223,11 +363,13 @@ acpi_powerres_debug(acpi_softc_t *sc)
|
||||
int i;
|
||||
|
||||
LIST_FOREACH(powerres, &sc->acpi_powerres_inflist, links) {
|
||||
printf("acpi_powerres_debug:");
|
||||
printf("acpi_powerres_debug[powerres]:");
|
||||
aml_print_curname(powerres->name);
|
||||
printf("[%d:%d:%s]\n", powerres->name->property->pres.level,
|
||||
powerres->name->property->pres.order,
|
||||
powerres_statestr[powerres->state]);
|
||||
|
||||
/* for _PR[0-2] */
|
||||
for (i = 0; i < ACPI_PR_MAX; i++) {
|
||||
if (LIST_EMPTY(&powerres->reflist[i])) {
|
||||
continue;
|
||||
@ -240,6 +382,30 @@ acpi_powerres_debug(acpi_softc_t *sc)
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* for _PRW */
|
||||
if (LIST_EMPTY(&powerres->prwlist)) {
|
||||
continue;
|
||||
}
|
||||
printf("\t_PRW:");
|
||||
LIST_FOREACH(device_ref, &powerres->prwlist, links) {
|
||||
device = device_ref->device;
|
||||
aml_print_curname(device->name);
|
||||
acpi_powerres_device_prw_print(device);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
LIST_FOREACH(device, &sc->acpi_powerres_devlist, links) {
|
||||
printf("acpi_powerres_debug[device]:");
|
||||
aml_print_curname(device->name);
|
||||
if (device->state != ACPI_D_STATE_UNKNOWN) {
|
||||
printf("[D%d] ", device->state);
|
||||
}
|
||||
if (device->wake_cap != ACPI_D_WAKECAP_UNKNOWN) {
|
||||
acpi_powerres_device_prw_print(device);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,6 +456,7 @@ acpi_powerres_register(struct aml_name *name, va_list ap)
|
||||
for (i = 0; i < ACPI_PR_MAX; i++) {
|
||||
LIST_INIT(&powerres->reflist[i]);
|
||||
}
|
||||
LIST_INIT(&powerres->prwlist);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -297,7 +464,7 @@ acpi_powerres_register(struct aml_name *name, va_list ap)
|
||||
static int
|
||||
acpi_powerres_add_device(struct aml_name *name, va_list ap)
|
||||
{
|
||||
int i;
|
||||
int i, offset, objtype;
|
||||
int prnum;
|
||||
int dev_found;
|
||||
acpi_softc_t *sc;
|
||||
@ -306,12 +473,23 @@ acpi_powerres_add_device(struct aml_name *name, va_list ap)
|
||||
struct acpi_powerres_info *powerres;
|
||||
struct aml_name *powerres_name;
|
||||
struct aml_environ env;
|
||||
union aml_object **objects;
|
||||
|
||||
sc = va_arg(ap, acpi_softc_t *);
|
||||
|
||||
/* should be _PR[0-2] */
|
||||
prnum = name->name[3] - '0';
|
||||
if (!(prnum >= 0 && prnum < ACPI_PR_MAX)) {
|
||||
objtype = prnum = 0;
|
||||
/* should be _PR[0-2] or _PRW */
|
||||
switch (name->name[3]) {
|
||||
case '0' ... '2':
|
||||
objtype = ACPI_D_PM_TYPE_PRX;
|
||||
prnum = name->name[3] - '0';
|
||||
offset = 0;
|
||||
break;
|
||||
case 'W':
|
||||
objtype = ACPI_D_PM_TYPE_PRW;
|
||||
/* for _PRW, PowerResource reference starts from elements 2 */
|
||||
offset = 2;
|
||||
break;
|
||||
default:
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -327,7 +505,7 @@ acpi_powerres_add_device(struct aml_name *name, va_list ap)
|
||||
/* make the list of devices */
|
||||
dev_found = 0;
|
||||
LIST_FOREACH(device, &sc->acpi_powerres_devlist, links) {
|
||||
if (device->name == name) {
|
||||
if (device->name == name->parent) {
|
||||
dev_found = 1;
|
||||
break;
|
||||
}
|
||||
@ -339,52 +517,151 @@ acpi_powerres_add_device(struct aml_name *name, va_list ap)
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* this is a _PR[0-2] object, we need get a parent of this. */
|
||||
/* set default values */
|
||||
device->state = ACPI_D_STATE_UNKNOWN;
|
||||
device->wake_cap = ACPI_D_WAKECAP_UNKNOWN;
|
||||
|
||||
/* this is a _PR[0-2|W] object, we need the parent of this. */
|
||||
device->name = name->parent;
|
||||
|
||||
/* get the current device state. */
|
||||
device->state = acpi_get_current_device_state(device->name);
|
||||
|
||||
LIST_INSERT_HEAD(&sc->acpi_powerres_devlist, device, links);
|
||||
}
|
||||
|
||||
objects = name->property->package.objects;
|
||||
|
||||
switch (objtype) {
|
||||
case ACPI_D_PM_TYPE_PRX:
|
||||
/* get the current device state. */
|
||||
if (device->state == ACPI_D_STATE_UNKNOWN) {
|
||||
device->state = acpi_get_current_device_state(device->name);
|
||||
}
|
||||
break;
|
||||
case ACPI_D_PM_TYPE_PRW:
|
||||
device->wake_cap = ACPI_D_WAKECAP_DEFAULT;
|
||||
for (i = 0; i < 2; i++) {
|
||||
device->prw_val[i] = objects[i];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* find PowerResource which the device reference to */
|
||||
MALLOC(device_ref, struct acpi_powerres_device_ref *,
|
||||
sizeof(*device_ref), M_TEMP, M_NOWAIT);
|
||||
if (device_ref == NULL) {
|
||||
return (1);
|
||||
}
|
||||
|
||||
device_ref->device = device;
|
||||
env.curname = device->name;
|
||||
for (i = 0; i < name->property->package.elements; i++) {
|
||||
if (name->property->package.objects[i]->type != aml_t_namestr) {
|
||||
for (i = offset; i < name->property->package.elements; i++) {
|
||||
if (objects[i]->type != aml_t_namestr) {
|
||||
printf("acpi_powerres_add_device: not name string\n");
|
||||
continue;
|
||||
}
|
||||
powerres_name = aml_search_name(&env,
|
||||
name->property->package.objects[i]->nstr.dp);
|
||||
powerres_name = aml_search_name(&env, objects[i]->nstr.dp);
|
||||
if (powerres_name == NULL) {
|
||||
printf("acpi_powerres_add_device: not found\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
LIST_FOREACH(powerres, &sc->acpi_powerres_inflist, links) {
|
||||
if (powerres->name == powerres_name) {
|
||||
if (powerres->name != powerres_name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (objtype) {
|
||||
case ACPI_D_PM_TYPE_PRX:
|
||||
LIST_INSERT_HEAD(&powerres->reflist[prnum],
|
||||
device_ref, links);
|
||||
break;
|
||||
case ACPI_D_PM_TYPE_PRW:
|
||||
LIST_INSERT_HEAD(&powerres->prwlist,
|
||||
device_ref, links);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* already found, go to next element... */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* force to set the current device state to make
|
||||
* PowerResource compatible with the device state.
|
||||
*/
|
||||
acpi_set_device_state(sc, device->name, device->state);
|
||||
switch (objtype) {
|
||||
case ACPI_D_PM_TYPE_PRX:
|
||||
/* XXX
|
||||
* force to set the current device state to make
|
||||
* PowerResource compatible with the device state.
|
||||
*/
|
||||
acpi_set_device_state(sc, device->name, device->state);
|
||||
break;
|
||||
case ACPI_D_PM_TYPE_PRW:
|
||||
acpi_set_device_wakecap(sc, device->name, device->wake_cap);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static __inline void
|
||||
acpi_set_device_prw_gpe(acpi_softc_t *sc, struct acpi_powerres_device *device,
|
||||
boolean_t on_off)
|
||||
{
|
||||
u_long ef;
|
||||
|
||||
device->gpe_enabled = on_off;
|
||||
|
||||
/* The proper general-purpose register bits are enabled. */
|
||||
switch (device->prw_val[0]->type) {
|
||||
case aml_t_num:
|
||||
/* bit index in GPEx_EN of the enable bit */
|
||||
ef = read_eflags(); /* XXX should MI */
|
||||
acpi_gpe_enable_bit(sc, device->prw_val[0]->num.number, on_off);
|
||||
write_eflags(ef);
|
||||
break;
|
||||
default:
|
||||
/* XXX in ACPI 2.0, we can have additional GPE blocks */
|
||||
printf("ACPI 2.0 style _PRW/GPE handling is not supported\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
acpi_set_device_next_state(acpi_softc_t *sc,
|
||||
struct acpi_powerres_device *device, u_int8_t sleeping_state,
|
||||
u_int8_t def_dstate)
|
||||
{
|
||||
|
||||
/* set given default device state */
|
||||
device->next_state = def_dstate;
|
||||
|
||||
if (device->wake_cap != ACPI_D_WAKECAP_ENABLE) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* 7.2.1 _PRW
|
||||
* The sleeping state being enterted must be greater or equal to the
|
||||
* power state declared in element 1 of the _PRW object.
|
||||
*/
|
||||
if (sleeping_state < device->prw_val[1]->num.number) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
device->next_state = ACPI_D_STATE_D0; /* XXX need to refer _SxD ? */
|
||||
|
||||
if (sleeping_state > ACPI_S_STATE_S0 && device->gpe_enabled == 0) {
|
||||
acpi_set_device_prw_gpe(sc, device, 1);
|
||||
}
|
||||
|
||||
out:
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* 7.1-5 PowerResource manipulation on the sleeping state transision.
|
||||
*/
|
||||
@ -405,7 +682,7 @@ acpi_powerres_set_sleeping_state(acpi_softc_t *sc, u_int8_t state)
|
||||
* based on PowerResource state change.
|
||||
*/
|
||||
LIST_FOREACH(device, &sc->acpi_powerres_devlist, links) {
|
||||
device->next_state = ACPI_D_STATE_D0;
|
||||
acpi_set_device_next_state(sc, device, state, ACPI_D_STATE_D0);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -420,7 +697,6 @@ acpi_powerres_set_sleeping_state(acpi_softc_t *sc, u_int8_t state)
|
||||
if (powerres->state == ACPI_POWER_RESOURCE_ON) {
|
||||
acpi_set_powerres_state(sc, powerres->name,
|
||||
ACPI_POWER_RESOURCE_OFF);
|
||||
powerres->state = ACPI_POWER_RESOURCE_OFF;
|
||||
}
|
||||
/*
|
||||
* Device states are compatible with the current
|
||||
@ -429,8 +705,8 @@ acpi_powerres_set_sleeping_state(acpi_softc_t *sc, u_int8_t state)
|
||||
for (i = 0; i < ACPI_PR_MAX; i++) {
|
||||
LIST_FOREACH(device_ref, &powerres->reflist[i], links) {
|
||||
device = device_ref->device;
|
||||
/* D3 state */
|
||||
device->next_state = ACPI_D_STATE_D3;
|
||||
acpi_set_device_next_state(sc, device,
|
||||
state, ACPI_D_STATE_D3);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -438,7 +714,6 @@ acpi_powerres_set_sleeping_state(acpi_softc_t *sc, u_int8_t state)
|
||||
if (powerres->state == ACPI_POWER_RESOURCE_OFF) {
|
||||
acpi_set_powerres_state(sc, powerres->name,
|
||||
ACPI_POWER_RESOURCE_ON);
|
||||
powerres->state = ACPI_POWER_RESOURCE_ON;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -460,12 +735,16 @@ acpi_powerres_set_sleeping_state(acpi_softc_t *sc, u_int8_t state)
|
||||
if (device->next_state == ACPI_D_STATE_D3 &&
|
||||
device->state != ACPI_D_STATE_D3) {
|
||||
acpi_set_device_state(sc, device->name, ACPI_D_STATE_D3);
|
||||
device->state = ACPI_D_STATE_D3;
|
||||
}
|
||||
if (device->next_state == ACPI_D_STATE_D0 &&
|
||||
device->state != ACPI_D_STATE_D0) {
|
||||
acpi_set_device_state(sc, device->name, ACPI_D_STATE_D0);
|
||||
device->state = ACPI_D_STATE_D0;
|
||||
}
|
||||
|
||||
/* XXX reset GEPx_EN enabled bit on S0 state */
|
||||
if (state == ACPI_S_STATE_S0 && device->gpe_enabled &&
|
||||
device->wake_cap == ACPI_D_WAKECAP_ENABLE) {
|
||||
acpi_set_device_prw_gpe(sc, device, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user