Deleted Added
sdiff udiff text old ( 248415 ) new ( 267647 )
full compact
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 $");
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;
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;
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
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;
648 } else if (rp->ap_state == ACPI_PWR_UNK)
649 rp->ap_state = cur;
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 */
656 if (rp->ap_state != 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 {
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
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;
692 } else if (rp->ap_state == ACPI_PWR_UNK)
693 rp->ap_state = cur;
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 */
700 if (rp->ap_state != 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 {
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 ---