ACPI_STATUS AcpiExSystemDoSleep ( UINT64 HowLong) { ACPI_FUNCTION_ENTRY (); /* Since this thread will sleep, we must release the interpreter */ AcpiExExitInterpreter (); /* * For compatibility with other ACPI implementations and to prevent * accidental deep sleeps, limit the sleep time to something reasonable. */ if (HowLong > ACPI_MAX_SLEEP) { HowLong = ACPI_MAX_SLEEP; } AcpiOsSleep (HowLong); /* And now we must get the interpreter again */ AcpiExEnterInterpreter (); return (AE_OK); }
void AcpiTerminateDebugger ( void) { /* Terminate the AML Debugger */ AcpiGbl_DbTerminateLoop = TRUE; if (AcpiGbl_DebuggerConfiguration & DEBUGGER_MULTI_THREADED) { AcpiOsReleaseMutex (AcpiGbl_DbCommandReady); /* Wait the AML Debugger threads */ while (!AcpiGbl_DbThreadsTerminated) { AcpiOsSleep (100); } } if (AcpiGbl_DbBuffer) { AcpiOsFree (AcpiGbl_DbBuffer); AcpiGbl_DbBuffer = NULL; } /* Ensure that debug output is now disabled */ AcpiGbl_DbOutputFlags = ACPI_DB_DISABLE_OUTPUT; }
static void acpi_cmbat_init_battery(void *arg) { struct acpi_cmbat_softc *sc; int retry, valid; device_t dev; dev = (device_t)arg; sc = device_get_softc(dev); ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery initialization start\n"); /* * Try repeatedly to get valid data from the battery. Since the * embedded controller isn't always ready just after boot, we may have * to wait a while. */ for (retry = 0; retry < ACPI_CMBAT_RETRY_MAX; retry++, AcpiOsSleep(10000)) { /* batteries on DOCK can be ejected w/ DOCK during retrying */ if (!device_is_attached(dev)) return; if (!acpi_BatteryIsPresent(dev)) continue; /* * Only query the battery if this is the first try or the specific * type of info is still invalid. */ ACPI_SERIAL_BEGIN(cmbat); if (retry == 0 || !acpi_battery_bst_valid(&sc->bst)) { timespecclear(&sc->bst_lastupdated); acpi_cmbat_get_bst(dev); } if (retry == 0 || !acpi_battery_bif_valid(&sc->bif)) acpi_cmbat_get_bif(dev); valid = acpi_battery_bst_valid(&sc->bst) && acpi_battery_bif_valid(&sc->bif); ACPI_SERIAL_END(cmbat); if (valid) break; } if (retry == ACPI_CMBAT_RETRY_MAX) { ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery initialization failed, giving up\n"); } else { ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery initialization done, tried %d times\n", retry + 1); } }
static void acpi_cmbat_init_battery(void *arg) { int retry; device_t dev = (device_t)arg; struct acpi_cmbat_softc *sc = device_get_softc(dev); #define ACPI_CMBAT_RETRY_MAX 6 if (sc->initializing) { return; } sc->initializing = 1; ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery initialization start\n"); for (retry = 0; retry < ACPI_CMBAT_RETRY_MAX; retry++, AcpiOsSleep(10, 0)) { sc->present = acpi_BatteryIsPresent(dev); if (!sc->present) { continue; } timespecclear(&sc->bst_lastupdated); timespecclear(&sc->bif_lastupdated); acpi_cmbat_get_bst(dev); if (!acpi_cmbat_is_bst_valid(&sc->bst)) { continue; } acpi_cmbat_get_bif(dev); if (!acpi_cmbat_is_bif_valid(&sc->bif)) { continue; } break; } if (retry == ACPI_CMBAT_RETRY_MAX) ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery initialization failed, giving up\n"); else ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery initialization done, tried %d times\n", retry+1); sc->initializing = 0; }
ACPI_STATUS AcpiExSystemDoSuspend ( ACPI_INTEGER HowLong) { ACPI_FUNCTION_ENTRY (); /* Since this thread will sleep, we must release the interpreter */ AcpiExRelinquishInterpreter (); AcpiOsSleep (HowLong); /* And now we must get the interpreter again */ AcpiExReacquireInterpreter (); return (AE_OK); }
static void acpi_acad_init_acline(void *arg) { struct acpi_acad_softc *sc; device_t dev; int retry; dev = (device_t)arg; sc = device_get_softc(dev); ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "acline initialization start\n"); for (retry = 0; retry < ACPI_ACAD_RETRY_MAX; retry++) { acpi_acad_get_status(dev); if (sc->status != -1) break; AcpiOsSleep(10000); } ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "acline initialization done, tried %d times\n", retry + 1); }
void AcpiDbExecute ( char *Name, char **Args, ACPI_OBJECT_TYPE *Types, UINT32 Flags) { ACPI_STATUS Status; ACPI_BUFFER ReturnObj; char *NameString; #ifdef ACPI_DEBUG_OUTPUT UINT32 PreviousAllocations; UINT32 Allocations; /* Memory allocation tracking */ PreviousAllocations = AcpiDbGetOutstandingAllocations (); #endif if (*Name == '*') { (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL, NULL); return; } else { NameString = ACPI_ALLOCATE (ACPI_STRLEN (Name) + 1); if (!NameString) { return; } ACPI_MEMSET (&AcpiGbl_DbMethodInfo, 0, sizeof (ACPI_DB_METHOD_INFO)); ACPI_STRCPY (NameString, Name); AcpiUtStrupr (NameString); AcpiGbl_DbMethodInfo.Name = NameString; AcpiGbl_DbMethodInfo.Args = Args; AcpiGbl_DbMethodInfo.Types = Types; AcpiGbl_DbMethodInfo.Flags = Flags; ReturnObj.Pointer = NULL; ReturnObj.Length = ACPI_ALLOCATE_BUFFER; Status = AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo); if (ACPI_FAILURE (Status)) { ACPI_FREE (NameString); return; } /* Get the NS node, determines existence also */ Status = AcpiGetHandle (NULL, AcpiGbl_DbMethodInfo.Pathname, &AcpiGbl_DbMethodInfo.Method); if (ACPI_SUCCESS (Status)) { Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo, &ReturnObj); } ACPI_FREE (NameString); } /* * Allow any handlers in separate threads to complete. * (Such as Notify handlers invoked from AML executed above). */ AcpiOsSleep ((UINT64) 10); #ifdef ACPI_DEBUG_OUTPUT /* Memory allocation tracking */ Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations; AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); if (Allocations > 0) { AcpiOsPrintf ("0x%X Outstanding allocations after evaluation of %s\n", Allocations, AcpiGbl_DbMethodInfo.Pathname); } #endif if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Evaluation of %s failed with status %s\n", AcpiGbl_DbMethodInfo.Pathname, AcpiFormatException (Status)); } else { /* Display a return object, if any */ if (ReturnObj.Length) { AcpiOsPrintf ( "Evaluation of %s returned object %p, external buffer length %X\n", AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer, (UINT32) ReturnObj.Length); AcpiDbDumpExternalObject (ReturnObj.Pointer, 1); /* Dump a _PLD buffer if present */ if (ACPI_COMPARE_NAME ((ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, AcpiGbl_DbMethodInfo.Method)->Name.Ascii), METHOD_NAME__PLD)) { AcpiDbDumpPldBuffer (ReturnObj.Pointer); } } else { AcpiOsPrintf ("No object was returned from evaluation of %s\n", AcpiGbl_DbMethodInfo.Pathname); } } AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); }
void AcpiDbExecute ( NATIVE_CHAR *Name, NATIVE_CHAR **Args, UINT32 Flags) { ACPI_STATUS Status; ACPI_BUFFER ReturnObj; #ifdef ACPI_DEBUG UINT32 PreviousAllocations; UINT32 Allocations; /* Memory allocation tracking */ PreviousAllocations = AcpiDbGetOutstandingAllocations (); #endif AcpiGbl_DbMethodInfo.Name = Name; AcpiGbl_DbMethodInfo.Args = Args; AcpiGbl_DbMethodInfo.Flags = Flags; AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo); Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo, &ReturnObj); /* * Allow any handlers in separate threads to complete. * (Such as Notify handlers invoked from AML executed above). */ AcpiOsSleep (0, 10); #ifdef ACPI_DEBUG /* Memory allocation tracking */ Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations; AcpiDbSetOutputDestination (DB_DUPLICATE_OUTPUT); if (Allocations > 0) { AcpiOsPrintf ("Outstanding: %ld allocations after execution\n", Allocations); } #endif if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Execution of %s failed with status %s\n", AcpiGbl_DbMethodInfo.Pathname, AcpiFormatException (Status)); } else { /* Display a return object, if any */ if (ReturnObj.Length) { AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n", AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer, ReturnObj.Length); AcpiDbDumpObject (ReturnObj.Pointer, 1); } } AcpiDbSetOutputDestination (DB_CONSOLE_OUTPUT); }
void AcpiDbExecute ( char *Name, char **Args, UINT32 Flags) { ACPI_STATUS Status; ACPI_BUFFER ReturnObj; #ifdef ACPI_DEBUG_OUTPUT UINT32 PreviousAllocations; UINT32 Allocations; /* Memory allocation tracking */ PreviousAllocations = AcpiDbGetOutstandingAllocations (); #endif if (*Name == '*') { (void) AcpiWalkNamespace (ACPI_TYPE_METHOD, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, AcpiDbExecutionWalk, NULL, NULL); return; } else { AcpiGbl_DbMethodInfo.Name = Name; AcpiGbl_DbMethodInfo.Args = Args; AcpiGbl_DbMethodInfo.Flags = Flags; ReturnObj.Pointer = NULL; ReturnObj.Length = ACPI_ALLOCATE_BUFFER; AcpiDbExecuteSetup (&AcpiGbl_DbMethodInfo); Status = AcpiDbExecuteMethod (&AcpiGbl_DbMethodInfo, &ReturnObj); } /* * Allow any handlers in separate threads to complete. * (Such as Notify handlers invoked from AML executed above). */ AcpiOsSleep (0, 10); #ifdef ACPI_DEBUG_OUTPUT /* Memory allocation tracking */ Allocations = AcpiDbGetOutstandingAllocations () - PreviousAllocations; AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT); if (Allocations > 0) { AcpiOsPrintf ("Outstanding: %ld allocations after execution\n", Allocations); } #endif if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Execution of %s failed with status %s\n", AcpiGbl_DbMethodInfo.Pathname, AcpiFormatException (Status)); } else { /* Display a return object, if any */ if (ReturnObj.Length) { AcpiOsPrintf ("Execution of %s returned object %p Buflen %X\n", AcpiGbl_DbMethodInfo.Pathname, ReturnObj.Pointer, (UINT32) ReturnObj.Length); AcpiDbDumpObject (ReturnObj.Pointer, 1); } else { AcpiOsPrintf ("No return object from execution of %s\n", AcpiGbl_DbMethodInfo.Pathname); } } AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT); }
static int acpi_smbus_read_multi_1(struct acpi_smbat_softc *sc, uint8_t addr, uint8_t cmd, uint8_t *ptr, uint16_t len) { UINT64 val; uint8_t to; int error; ACPI_SERIAL_ASSERT(smbat); if (batt_sleep_ms) AcpiOsSleep(batt_sleep_ms); val = addr; error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_ADDR, val, 1); if (error) goto out; val = cmd; error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_CMD, val, 1); if (error) goto out; val = 0x0B /* | 0x80 if PEC */ ; error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL, val, 1); if (error) goto out; if (batt_sleep_ms) AcpiOsSleep(batt_sleep_ms); for (to = SMBUS_TIMEOUT; to != 0; to--) { error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL, &val, 1); if (error) goto out; if (val == 0) break; AcpiOsSleep(10); } if (to == 0) { error = ETIMEDOUT; goto out; } error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_STS, &val, 1); if (error) goto out; if (val & SMBUS_STS_MASK) { printf("%s: AE_ERROR 0x%x\n", __FUNCTION__, (int)(val & SMBUS_STS_MASK)); error = EIO; goto out; } /* get length */ error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_BCNT, &val, 1); if (error) goto out; val = (val & 0x1f) + 1; bzero(ptr, len); if (len > val) len = val; if (batt_sleep_ms) AcpiOsSleep(batt_sleep_ms); while (len--) { error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_DATA + len, &val, 1); if (error) goto out; ptr[len] = val; if (batt_sleep_ms) AcpiOsSleep(batt_sleep_ms); } out: return (error); }
static int acpi_smbus_read_2(struct acpi_smbat_softc *sc, uint8_t addr, uint8_t cmd, uint16_t *ptr) { int error, to; UINT64 val; ACPI_SERIAL_ASSERT(smbat); if (batt_sleep_ms) AcpiOsSleep(batt_sleep_ms); val = addr; error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_ADDR, val, 1); if (error) goto out; val = cmd; error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_CMD, val, 1); if (error) goto out; val = 0x09; /* | 0x80 if PEC */ error = ACPI_EC_WRITE(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL, val, 1); if (error) goto out; if (batt_sleep_ms) AcpiOsSleep(batt_sleep_ms); for (to = SMBUS_TIMEOUT; to != 0; to--) { error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_PRTCL, &val, 1); if (error) goto out; if (val == 0) break; AcpiOsSleep(10); } if (to == 0) { error = ETIMEDOUT; goto out; } error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_STS, &val, 1); if (error) goto out; if (val & SMBUS_STS_MASK) { printf("%s: AE_ERROR 0x%x\n", __FUNCTION__, (int)(val & SMBUS_STS_MASK)); error = EIO; goto out; } error = ACPI_EC_READ(sc->ec_dev, sc->sb_base_addr + SMBUS_DATA, &val, 2); if (error) goto out; *ptr = val; out: return (error); }