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 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 |
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; |
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; |
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 |
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; |
644 } |
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 */ |
651 if (cur != ACPI_PWR_ON) { |
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 { |
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 |
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; |
685 } |
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 */ |
692 if (cur != ACPI_PWR_OFF) { |
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 { |
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 --- |