Deleted Added
full compact
acpi_powerres.c (248415) acpi_powerres.c (267647)
1/*-
2 * Copyright (c) 2001 Michael Smith
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

--- 11 unchanged lines hidden (view full) ---

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>
1/*-
2 * Copyright (c) 2001 Michael Smith
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

--- 11 unchanged lines hidden (view full) ---

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: head/sys/dev/acpica/acpi_powerres.c 248415 2013-03-17 07:28:17Z rpaulo $");
28__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_powerres.c 267647 2014-06-19 18:35:14Z jhb $");
29
30#include "opt_acpi.h"
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/malloc.h>
34#include <sys/bus.h>
35
36#include <contrib/dev/acpica/include/acpi.h>

--- 22 unchanged lines hidden (view full) ---

59
60/* Hooks for the ACPI CA debugging infrastructure */
61#define _COMPONENT ACPI_POWERRES
62ACPI_MODULE_NAME("POWERRES")
63
64/* Return values from _STA on a power resource */
65#define ACPI_PWR_OFF 0
66#define ACPI_PWR_ON 1
29
30#include "opt_acpi.h"
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/malloc.h>
34#include <sys/bus.h>
35
36#include <contrib/dev/acpica/include/acpi.h>

--- 22 unchanged lines hidden (view full) ---

59
60/* Hooks for the ACPI CA debugging infrastructure */
61#define _COMPONENT ACPI_POWERRES
62ACPI_MODULE_NAME("POWERRES")
63
64/* Return values from _STA on a power resource */
65#define ACPI_PWR_OFF 0
66#define ACPI_PWR_ON 1
67#define ACPI_PWR_UNK (-1)
68
69/* A relationship between a power resource and a consumer. */
70struct acpi_powerreference {
71 struct acpi_powerconsumer *ar_consumer;
72 struct acpi_powerresource *ar_resource;
73 TAILQ_ENTRY(acpi_powerreference) ar_rlink; /* link on resource list */
74 TAILQ_ENTRY(acpi_powerreference) ar_clink; /* link on consumer */
75};

--- 9 unchanged lines hidden (view full) ---

85
86/* A power resource. */
87struct acpi_powerresource {
88 TAILQ_ENTRY(acpi_powerresource) ap_link;
89 TAILQ_HEAD(,acpi_powerreference) ap_references;
90 ACPI_HANDLE ap_resource;
91 UINT64 ap_systemlevel;
92 UINT64 ap_order;
67
68/* A relationship between a power resource and a consumer. */
69struct acpi_powerreference {
70 struct acpi_powerconsumer *ar_consumer;
71 struct acpi_powerresource *ar_resource;
72 TAILQ_ENTRY(acpi_powerreference) ar_rlink; /* link on resource list */
73 TAILQ_ENTRY(acpi_powerreference) ar_clink; /* link on consumer */
74};

--- 9 unchanged lines hidden (view full) ---

84
85/* A power resource. */
86struct acpi_powerresource {
87 TAILQ_ENTRY(acpi_powerresource) ap_link;
88 TAILQ_HEAD(,acpi_powerreference) ap_references;
89 ACPI_HANDLE ap_resource;
90 UINT64 ap_systemlevel;
91 UINT64 ap_order;
93 int ap_state;
94};
95
96static TAILQ_HEAD(acpi_powerresource_list, acpi_powerresource)
97 acpi_powerresources;
98static TAILQ_HEAD(acpi_powerconsumer_list, acpi_powerconsumer)
99 acpi_powerconsumers;
100ACPI_SERIAL_DECL(powerres, "ACPI power resources");
101

--- 66 unchanged lines hidden (view full) ---

168 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
169 "questionable power resource object %s\n",
170 acpi_name(res)));
171 status = AE_TYPE;
172 goto out;
173 }
174 rp->ap_systemlevel = obj->PowerResource.SystemLevel;
175 rp->ap_order = obj->PowerResource.ResourceOrder;
92};
93
94static TAILQ_HEAD(acpi_powerresource_list, acpi_powerresource)
95 acpi_powerresources;
96static TAILQ_HEAD(acpi_powerconsumer_list, acpi_powerconsumer)
97 acpi_powerconsumers;
98ACPI_SERIAL_DECL(powerres, "ACPI power resources");
99

--- 66 unchanged lines hidden (view full) ---

166 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
167 "questionable power resource object %s\n",
168 acpi_name(res)));
169 status = AE_TYPE;
170 goto out;
171 }
172 rp->ap_systemlevel = obj->PowerResource.SystemLevel;
173 rp->ap_order = obj->PowerResource.ResourceOrder;
176 rp->ap_state = ACPI_PWR_UNK;
177
178 /* Sort the resource into the list */
179 status = AE_OK;
180 srp = TAILQ_FIRST(&acpi_powerresources);
181 if (srp == NULL || rp->ap_order < srp->ap_order) {
182 TAILQ_INSERT_HEAD(&acpi_powerresources, rp, ap_link);
183 goto done;
184 }

--- 448 unchanged lines hidden (view full) ---

633 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
634 if (TAILQ_FIRST(&rp->ap_references) == NULL) {
635 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
636 "%s has no references, not turning on\n",
637 acpi_name(rp->ap_resource)));
638 continue;
639 }
640
174
175 /* Sort the resource into the list */
176 status = AE_OK;
177 srp = TAILQ_FIRST(&acpi_powerresources);
178 if (srp == NULL || rp->ap_order < srp->ap_order) {
179 TAILQ_INSERT_HEAD(&acpi_powerresources, rp, ap_link);
180 goto done;
181 }

--- 448 unchanged lines hidden (view full) ---

630 TAILQ_FOREACH(rp, &acpi_powerresources, ap_link) {
631 if (TAILQ_FIRST(&rp->ap_references) == NULL) {
632 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
633 "%s has no references, not turning on\n",
634 acpi_name(rp->ap_resource)));
635 continue;
636 }
637
641 /* We could cache this if we trusted it not to change under us */
642 status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
643 if (ACPI_FAILURE(status)) {
644 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
645 acpi_name(rp->ap_resource), status));
646 /* XXX is this correct? Always switch if in doubt? */
647 continue;
638 status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
639 if (ACPI_FAILURE(status)) {
640 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
641 acpi_name(rp->ap_resource), status));
642 /* XXX is this correct? Always switch if in doubt? */
643 continue;
648 } else if (rp->ap_state == ACPI_PWR_UNK)
649 rp->ap_state = cur;
644 }
650
651 /*
652 * Switch if required. Note that we ignore the result of the switch
653 * effort; we don't know what to do if it fails, so checking wouldn't
654 * help much.
655 */
645
646 /*
647 * Switch if required. Note that we ignore the result of the switch
648 * effort; we don't know what to do if it fails, so checking wouldn't
649 * help much.
650 */
656 if (rp->ap_state != ACPI_PWR_ON) {
651 if (cur != ACPI_PWR_ON) {
657 status = AcpiEvaluateObject(rp->ap_resource, "_ON", NULL, NULL);
658 if (ACPI_FAILURE(status)) {
659 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
660 "failed to switch %s on - %s\n",
661 acpi_name(rp->ap_resource),
662 AcpiFormatException(status)));
663 } else {
652 status = AcpiEvaluateObject(rp->ap_resource, "_ON", NULL, NULL);
653 if (ACPI_FAILURE(status)) {
654 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
655 "failed to switch %s on - %s\n",
656 acpi_name(rp->ap_resource),
657 AcpiFormatException(status)));
658 } else {
664 rp->ap_state = ACPI_PWR_ON;
665 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s on\n",
666 acpi_name(rp->ap_resource)));
667 }
668 } else {
669 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already on\n",
670 acpi_name(rp->ap_resource)));
671 }
672 }

--- 4 unchanged lines hidden (view full) ---

677
678 if (TAILQ_FIRST(&rp->ap_references) != NULL) {
679 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
680 "%s has references, not turning off\n",
681 acpi_name(rp->ap_resource)));
682 continue;
683 }
684
659 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s on\n",
660 acpi_name(rp->ap_resource)));
661 }
662 } else {
663 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already on\n",
664 acpi_name(rp->ap_resource)));
665 }
666 }

--- 4 unchanged lines hidden (view full) ---

671
672 if (TAILQ_FIRST(&rp->ap_references) != NULL) {
673 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
674 "%s has references, not turning off\n",
675 acpi_name(rp->ap_resource)));
676 continue;
677 }
678
685 /* We could cache this if we trusted it not to change under us */
686 status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
687 if (ACPI_FAILURE(status)) {
688 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
689 acpi_name(rp->ap_resource), status));
690 /* XXX is this correct? Always switch if in doubt? */
691 continue;
679 status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
680 if (ACPI_FAILURE(status)) {
681 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
682 acpi_name(rp->ap_resource), status));
683 /* XXX is this correct? Always switch if in doubt? */
684 continue;
692 } else if (rp->ap_state == ACPI_PWR_UNK)
693 rp->ap_state = cur;
685 }
694
695 /*
696 * Switch if required. Note that we ignore the result of the switch
697 * effort; we don't know what to do if it fails, so checking wouldn't
698 * help much.
699 */
686
687 /*
688 * Switch if required. Note that we ignore the result of the switch
689 * effort; we don't know what to do if it fails, so checking wouldn't
690 * help much.
691 */
700 if (rp->ap_state != ACPI_PWR_OFF) {
692 if (cur != ACPI_PWR_OFF) {
701 status = AcpiEvaluateObject(rp->ap_resource, "_OFF", NULL, NULL);
702 if (ACPI_FAILURE(status)) {
703 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
704 "failed to switch %s off - %s\n",
705 acpi_name(rp->ap_resource),
706 AcpiFormatException(status)));
707 } else {
693 status = AcpiEvaluateObject(rp->ap_resource, "_OFF", NULL, NULL);
694 if (ACPI_FAILURE(status)) {
695 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
696 "failed to switch %s off - %s\n",
697 acpi_name(rp->ap_resource),
698 AcpiFormatException(status)));
699 } else {
708 rp->ap_state = ACPI_PWR_OFF;
709 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s off\n",
710 acpi_name(rp->ap_resource)));
711 }
712 } else {
713 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already off\n",
714 acpi_name(rp->ap_resource)));
715 }
716 }

--- 41 unchanged lines hidden ---
700 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s off\n",
701 acpi_name(rp->ap_resource)));
702 }
703 } else {
704 ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "%s is already off\n",
705 acpi_name(rp->ap_resource)));
706 }
707 }

--- 41 unchanged lines hidden ---