Author: jhb
Date: Thu Jun 19 18:35:14 2014
New Revision: 267647
URL: http://svnweb.freebsd.org/changeset/base/267647

Log:
  Trust the state of a power resource that get from a working _STA method
  instead of trying to cache it.
  
  Previously, we only trusted the state if we did not have a cached state.
  However, once a state was cached, the _STA method was always ignored.
  Specifically, once a power resource had been turned on once (e.g.
  during resume), the driver assumed it was always on even if _STA said it
  was off and never turned it back on.  This prevented the power resource
  from being turned back on if a laptop was resumed twice, for example.
  
  To fix, just remove the cached state entirely and always use the results
  of _STA.  The loops already skip any resources where _STA fails.
  
  Submitted by: trasz (initial patch to invoke _ON)
  MFC after:    1 week

Modified:
  head/sys/dev/acpica/acpi_powerres.c

Modified: head/sys/dev/acpica/acpi_powerres.c
==============================================================================
--- head/sys/dev/acpica/acpi_powerres.c Thu Jun 19 16:28:42 2014        
(r267646)
+++ head/sys/dev/acpica/acpi_powerres.c Thu Jun 19 18:35:14 2014        
(r267647)
@@ -64,7 +64,6 @@ ACPI_MODULE_NAME("POWERRES")
 /* Return values from _STA on a power resource */
 #define ACPI_PWR_OFF   0
 #define ACPI_PWR_ON    1
-#define ACPI_PWR_UNK   (-1)
 
 /* A relationship between a power resource and a consumer. */
 struct acpi_powerreference {
@@ -90,7 +89,6 @@ struct acpi_powerresource {
     ACPI_HANDLE                                ap_resource;
     UINT64                             ap_systemlevel;
     UINT64                             ap_order;
-    int                                        ap_state;
 };
 
 static TAILQ_HEAD(acpi_powerresource_list, acpi_powerresource)
@@ -173,7 +171,6 @@ acpi_pwr_register_resource(ACPI_HANDLE r
     }
     rp->ap_systemlevel = obj->PowerResource.SystemLevel;
     rp->ap_order = obj->PowerResource.ResourceOrder;
-    rp->ap_state = ACPI_PWR_UNK;
     
     /* Sort the resource into the list */
     status = AE_OK;
@@ -638,22 +635,20 @@ acpi_pwr_switch_power(void)
            continue;
        }
 
-       /* We could cache this if we trusted it not to change under us */
        status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
        if (ACPI_FAILURE(status)) {
            ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
                              acpi_name(rp->ap_resource), status));
            /* XXX is this correct?  Always switch if in doubt? */
            continue;
-       } else if (rp->ap_state == ACPI_PWR_UNK)
-           rp->ap_state = cur;
+       }
 
        /*
         * Switch if required.  Note that we ignore the result of the switch
         * effort; we don't know what to do if it fails, so checking wouldn't
         * help much.
         */
-       if (rp->ap_state != ACPI_PWR_ON) {
+       if (cur != ACPI_PWR_ON) {
            status = AcpiEvaluateObject(rp->ap_resource, "_ON", NULL, NULL);
            if (ACPI_FAILURE(status)) {
                ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
@@ -661,7 +656,6 @@ acpi_pwr_switch_power(void)
                                 acpi_name(rp->ap_resource),
                                 AcpiFormatException(status)));
            } else {
-               rp->ap_state = ACPI_PWR_ON;
                ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s on\n",
                                 acpi_name(rp->ap_resource)));
            }
@@ -682,22 +676,20 @@ acpi_pwr_switch_power(void)
            continue;
        }
 
-       /* We could cache this if we trusted it not to change under us */
        status = acpi_GetInteger(rp->ap_resource, "_STA", &cur);
        if (ACPI_FAILURE(status)) {
            ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "can't get status of %s - %d\n",
                              acpi_name(rp->ap_resource), status));
            /* XXX is this correct?  Always switch if in doubt? */
            continue;
-       } else if (rp->ap_state == ACPI_PWR_UNK)
-           rp->ap_state = cur;
+       }
 
        /*
         * Switch if required.  Note that we ignore the result of the switch
         * effort; we don't know what to do if it fails, so checking wouldn't
         * help much.
         */
-       if (rp->ap_state != ACPI_PWR_OFF) {
+       if (cur != ACPI_PWR_OFF) {
            status = AcpiEvaluateObject(rp->ap_resource, "_OFF", NULL, NULL);
            if (ACPI_FAILURE(status)) {
                ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS,
@@ -705,7 +697,6 @@ acpi_pwr_switch_power(void)
                                 acpi_name(rp->ap_resource),
                                 AcpiFormatException(status)));
            } else {
-               rp->ap_state = ACPI_PWR_OFF;
                ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "switched %s off\n",
                                 acpi_name(rp->ap_resource)));
            }
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to