ACPI_STATUS AcpiEnterSleepStateS4bios ( void) { UINT32 InValue; ACPI_STATUS Status; ACPI_FUNCTION_TRACE (AcpiEnterSleepStateS4bios); /* Clear the wake status bit (PM1) */ Status = AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } Status = AcpiHwClearAcpiStatus (); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* * 1) Disable/Clear all GPEs * 2) Enable all wakeup GPEs */ Status = AcpiHwDisableAllGpes (); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } AcpiGbl_SystemAwakeAndRunning = FALSE; Status = AcpiHwEnableAllWakeupGpes (); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } ACPI_FLUSH_CPU_CACHE (); Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand, (UINT32) AcpiGbl_FADT.S4BiosRequest, 8); do { AcpiOsStall (ACPI_USEC_PER_MSEC); Status = AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS, &InValue); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } while (!InValue); return_ACPI_STATUS (AE_OK); }
ACPI_STATUS AcpiExSystemIoSpaceHandler ( UINT32 Function, ACPI_PHYSICAL_ADDRESS Address, UINT32 BitWidth, UINT64 *Value, void *HandlerContext, void *RegionContext) { ACPI_STATUS Status = AE_OK; UINT32 Value32; ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n", BitWidth, Function, ACPI_FORMAT_UINT64 (Address))); /* Decode the function parameter */ switch (Function) { case ACPI_READ: Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address, &Value32, BitWidth); *Value = Value32; break; case ACPI_WRITE: Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address, (UINT32) *Value, BitWidth); break; default: Status = AE_BAD_PARAMETER; break; } return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiHwWrite ( UINT32 Value, ACPI_GENERIC_ADDRESS *Reg) { UINT64 Address; ACPI_STATUS Status; ACPI_FUNCTION_NAME (HwWrite); /* Validate contents of the GAS register */ Status = AcpiHwValidateRegister (Reg, 32, &Address); if (ACPI_FAILURE (Status)) { return (Status); } /* * Two address spaces supported: Memory or IO. PCI_Config is * not supported here because the GAS structure is insufficient */ if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY) { Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS) Address, (UINT64) Value, Reg->BitWidth); } else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ { Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address, Value, Reg->BitWidth); } ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n", Value, Reg->BitWidth, ACPI_FORMAT_UINT64 (Address), AcpiUtGetRegionName (Reg->SpaceId))); return (Status); }
ACPI_STATUS AcpiHwSetMode ( UINT32 Mode) { ACPI_STATUS Status; UINT32 Retry; ACPI_FUNCTION_TRACE (HwSetMode); /* If the Hardware Reduced flag is set, machine is always in acpi mode */ if (AcpiGbl_ReducedHardware) { return_ACPI_STATUS (AE_OK); } /* * ACPI 2.0 clarified that if SMI_CMD in FADT is zero, * system does not support mode transition. */ if (!AcpiGbl_FADT.SmiCommand) { ACPI_ERROR ((AE_INFO, "No SMI_CMD in FADT, mode transition failed")); return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); } /* * ACPI 2.0 clarified the meaning of ACPI_ENABLE and ACPI_DISABLE * in FADT: If it is zero, enabling or disabling is not supported. * As old systems may have used zero for mode transition, * we make sure both the numbers are zero to determine these * transitions are not supported. */ if (!AcpiGbl_FADT.AcpiEnable && !AcpiGbl_FADT.AcpiDisable) { ACPI_ERROR ((AE_INFO, "No ACPI mode transition supported in this system " "(enable/disable both zero)")); return_ACPI_STATUS (AE_OK); } switch (Mode) { case ACPI_SYS_MODE_ACPI: /* BIOS should have disabled ALL fixed and GP events */ Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand, (UINT32) AcpiGbl_FADT.AcpiEnable, 8); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Attempting to enable ACPI mode\n")); break; case ACPI_SYS_MODE_LEGACY: /* * BIOS should clear all fixed status bits and restore fixed event * enable bits to default */ Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand, (UINT32) AcpiGbl_FADT.AcpiDisable, 8); ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Attempting to enable Legacy (non-ACPI) mode\n")); break; default: return_ACPI_STATUS (AE_BAD_PARAMETER); } if (ACPI_FAILURE (Status)) { ACPI_EXCEPTION ((AE_INFO, Status, "Could not write ACPI mode change")); return_ACPI_STATUS (Status); } /* * Some hardware takes a LONG time to switch modes. Give them 3 sec to * do so, but allow faster systems to proceed more quickly. */ Retry = 3000; while (Retry) { if (AcpiHwGetMode () == Mode) { ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Mode %X successfully enabled\n", Mode)); return_ACPI_STATUS (AE_OK); } AcpiOsStall (ACPI_USEC_PER_MSEC); Retry--; } ACPI_ERROR ((AE_INFO, "Hardware did not change modes")); return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); }
ACPI_STATUS AcpiHwRegisterWrite ( UINT32 RegisterId, UINT32 Value) { ACPI_STATUS Status; UINT32 ReadValue; ACPI_FUNCTION_TRACE (HwRegisterWrite); switch (RegisterId) { case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */ /* * Handle the "ignored" bit in PM1 Status. According to the ACPI * specification, ignored bits are to be preserved when writing. * Normally, this would mean a read/modify/write sequence. However, * preserving a bit in the status register is different. Writing a * one clears the status, and writing a zero preserves the status. * Therefore, we must always write zero to the ignored bit. * * This behavior is clarified in the ACPI 4.0 specification. */ Value &= ~ACPI_PM1_STATUS_PRESERVED_BITS; Status = AcpiHwWriteMultiple (Value, &AcpiGbl_XPm1aStatus, &AcpiGbl_XPm1bStatus); break; case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */ Status = AcpiHwWriteMultiple (Value, &AcpiGbl_XPm1aEnable, &AcpiGbl_XPm1bEnable); break; case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */ /* * Perform a read first to preserve certain bits (per ACPI spec) * Note: This includes SCI_EN, we never want to change this bit */ Status = AcpiHwReadMultiple (&ReadValue, &AcpiGbl_FADT.XPm1aControlBlock, &AcpiGbl_FADT.XPm1bControlBlock); if (ACPI_FAILURE (Status)) { goto Exit; } /* Insert the bits to be preserved */ ACPI_INSERT_BITS (Value, ACPI_PM1_CONTROL_PRESERVED_BITS, ReadValue); /* Now we can write the data */ Status = AcpiHwWriteMultiple (Value, &AcpiGbl_FADT.XPm1aControlBlock, &AcpiGbl_FADT.XPm1bControlBlock); break; case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ /* * For control registers, all reserved bits must be preserved, * as per the ACPI spec. */ Status = AcpiHwRead (&ReadValue, &AcpiGbl_FADT.XPm2ControlBlock); if (ACPI_FAILURE (Status)) { goto Exit; } /* Insert the bits to be preserved */ ACPI_INSERT_BITS (Value, ACPI_PM2_CONTROL_PRESERVED_BITS, ReadValue); Status = AcpiHwWrite (Value, &AcpiGbl_FADT.XPm2ControlBlock); break; case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ Status = AcpiHwWrite (Value, &AcpiGbl_FADT.XPmTimerBlock); break; case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ /* SMI_CMD is currently always in IO space */ Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand, Value, 8); break; default: ACPI_ERROR ((AE_INFO, "Unknown Register ID: 0x%X", RegisterId)); Status = AE_BAD_PARAMETER; break; } Exit: return_ACPI_STATUS (Status); }
ACPI_STATUS AeRegionHandler ( UINT32 Function, ACPI_PHYSICAL_ADDRESS Address, UINT32 BitWidth, UINT64 *Value, void *HandlerContext, void *RegionContext) { ACPI_OPERAND_OBJECT *RegionObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, RegionContext); UINT8 *Buffer = ACPI_CAST_PTR (UINT8, Value); ACPI_PHYSICAL_ADDRESS BaseAddress; ACPI_SIZE Length; BOOLEAN BufferExists; AE_REGION *RegionElement; void *BufferValue; ACPI_STATUS Status; UINT32 ByteWidth; UINT32 i; UINT8 SpaceId; ACPI_FUNCTION_NAME (AeRegionHandler); /* * If the object is not a region, simply return */ if (RegionObject->Region.Type != ACPI_TYPE_REGION) { return AE_OK; } /* * Region support can be disabled with the -r option. * We use this to support dynamically loaded tables where we pass a valid * address to the AML. */ if (AcpiGbl_DbOpt_NoRegionSupport) { BufferValue = ACPI_TO_POINTER (Address); ByteWidth = (BitWidth / 8); if (BitWidth % 8) { ByteWidth += 1; } goto DoFunction; } /* * Find the region's address space and length before searching * the linked list. */ BaseAddress = RegionObject->Region.Address; Length = (ACPI_SIZE) RegionObject->Region.Length; SpaceId = RegionObject->Region.SpaceId; ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, "Operation Region request on %s at 0x%X\n", AcpiUtGetRegionName (RegionObject->Region.SpaceId), (UINT32) Address)); switch (SpaceId) { case ACPI_ADR_SPACE_SYSTEM_IO: /* * For I/O space, exercise the port validation */ switch (Function & ACPI_IO_MASK) { case ACPI_READ: Status = AcpiHwReadPort (Address, (UINT32 *) Value, BitWidth); break; case ACPI_WRITE: Status = AcpiHwWritePort (Address, (UINT32) *Value, BitWidth); break; default: Status = AE_BAD_PARAMETER; break; } if (ACPI_FAILURE (Status)) { return (Status); } /* Now go ahead and simulate the hardware */ break; case ACPI_ADR_SPACE_SMBUS: Length = 0; switch (Function & ACPI_IO_MASK) { case ACPI_READ: switch (Function >> 16) { case AML_FIELD_ATTRIB_SMB_QUICK: case AML_FIELD_ATTRIB_SMB_SEND_RCV: case AML_FIELD_ATTRIB_SMB_BYTE: Length = 1; break; case AML_FIELD_ATTRIB_SMB_WORD: case AML_FIELD_ATTRIB_SMB_WORD_CALL: Length = 2; break; case AML_FIELD_ATTRIB_SMB_BLOCK: case AML_FIELD_ATTRIB_SMB_BLOCK_CALL: Length = 32; break; default: break; } break; case ACPI_WRITE: switch (Function >> 16) { case AML_FIELD_ATTRIB_SMB_QUICK: case AML_FIELD_ATTRIB_SMB_SEND_RCV: case AML_FIELD_ATTRIB_SMB_BYTE: case AML_FIELD_ATTRIB_SMB_WORD: case AML_FIELD_ATTRIB_SMB_BLOCK: Length = 0; break; case AML_FIELD_ATTRIB_SMB_WORD_CALL: Length = 2; break; case AML_FIELD_ATTRIB_SMB_BLOCK_CALL: Length = 32; break; default: break; } break; default: break; } for (i = 0; i < Length; i++) { Buffer[i+2] = (UINT8) (0xA0 + i); } Buffer[0] = 0x7A; Buffer[1] = (UINT8) Length; return (AE_OK); case ACPI_ADR_SPACE_IPMI: /* ACPI 4.0 */ AcpiOsPrintf ("AcpiExec: Received IPMI request: " "Address %X BaseAddress %X Length %X Width %X BufferLength %u\n", (UINT32) Address, (UINT32) BaseAddress, Length, BitWidth, Buffer[1]); /* * Regardless of a READ or WRITE, this handler is passed a 66-byte * buffer in which to return the IPMI status/length/data. * * Return some example data to show use of the bidirectional buffer */ Buffer[0] = 0; /* Status byte */ Buffer[1] = 64; /* Return buffer data length */ Buffer[2] = 0; /* Completion code */ Buffer[3] = 0x34; /* Power measurement */ Buffer[4] = 0x12; /* Power measurement */ Buffer[65] = 0xEE; /* last buffer byte */ return (AE_OK); default: break; } /* * Search through the linked list for this region's buffer */ BufferExists = FALSE; RegionElement = AeRegions.RegionList; if (AeRegions.NumberOfRegions) { while (!BufferExists && RegionElement) { if (RegionElement->Address == BaseAddress && RegionElement->Length == Length && RegionElement->SpaceId == SpaceId) { BufferExists = TRUE; } else { RegionElement = RegionElement->NextRegion; } } } /* * If the Region buffer does not exist, create it now */ if (!BufferExists) { /* * Do the memory allocations first */ RegionElement = AcpiOsAllocate (sizeof (AE_REGION)); if (!RegionElement) { return AE_NO_MEMORY; } RegionElement->Buffer = AcpiOsAllocate (Length); if (!RegionElement->Buffer) { AcpiOsFree (RegionElement); return AE_NO_MEMORY; } /* Initialize the region with the default fill value */ ACPI_MEMSET (RegionElement->Buffer, AcpiGbl_RegionFillValue, Length); RegionElement->Address = BaseAddress; RegionElement->Length = Length; RegionElement->SpaceId = SpaceId; RegionElement->NextRegion = NULL; /* * Increment the number of regions and put this one * at the head of the list as it will probably get accessed * more often anyway. */ AeRegions.NumberOfRegions += 1; if (AeRegions.RegionList) { RegionElement->NextRegion = AeRegions.RegionList; } AeRegions.RegionList = RegionElement; } /* * Calculate the size of the memory copy */ ByteWidth = (BitWidth / 8); if (BitWidth % 8) { ByteWidth += 1; } /* * The buffer exists and is pointed to by RegionElement. * We now need to verify the request is valid and perform the operation. * * NOTE: RegionElement->Length is in bytes, therefore it we compare against * ByteWidth (see above) */ if (((UINT64) Address + ByteWidth) > ((UINT64)(RegionElement->Address) + RegionElement->Length)) { ACPI_WARNING ((AE_INFO, "Request on [%4.4s] is beyond region limit Req-0x%X+0x%X, Base=0x%X, Len-0x%X", (RegionObject->Region.Node)->Name.Ascii, (UINT32) Address, ByteWidth, (UINT32)(RegionElement->Address), RegionElement->Length)); return AE_AML_REGION_LIMIT; } /* * Get BufferValue to point to the "address" in the buffer */ BufferValue = ((UINT8 *) RegionElement->Buffer + ((UINT64) Address - (UINT64) RegionElement->Address)); DoFunction: /* * Perform a read or write to the buffer space */ switch (Function) { case ACPI_READ: /* * Set the pointer Value to whatever is in the buffer */ ACPI_MEMCPY (Value, BufferValue, ByteWidth); break; case ACPI_WRITE: /* * Write the contents of Value to the buffer */ ACPI_MEMCPY (BufferValue, Value, ByteWidth); break; default: return AE_BAD_PARAMETER; } return AE_OK; }
ACPI_STATUS AcpiHwWrite ( UINT32 Value, ACPI_GENERIC_ADDRESS *Reg) { UINT64 Address; UINT8 AccessWidth; UINT32 BitWidth; UINT8 BitOffset; UINT64 Value64; UINT32 NewValue32, OldValue32; UINT8 Index; ACPI_STATUS Status; ACPI_FUNCTION_NAME (HwWrite); /* Validate contents of the GAS register */ Status = AcpiHwValidateRegister (Reg, 32, &Address); if (ACPI_FAILURE (Status)) { return (Status); } /* Convert AccessWidth into number of bits based */ AccessWidth = Reg->AccessWidth ? Reg->AccessWidth : 1; AccessWidth = 1 << (AccessWidth + 2); BitWidth = ACPI_ROUND_UP (Reg->BitOffset + Reg->BitWidth, AccessWidth); BitOffset = Reg->BitOffset; /* * Two address spaces supported: Memory or IO. PCI_Config is * not supported here because the GAS structure is insufficient */ Index = 0; while (BitWidth) { NewValue32 = ACPI_GET_BITS (&Value, (Index * AccessWidth), ((1 << AccessWidth) - 1)); if (BitOffset > AccessWidth) { BitOffset -= AccessWidth; } else { if (BitOffset) { NewValue32 &= ACPI_MASK_BITS_BELOW (BitOffset); } if (BitWidth < AccessWidth) { NewValue32 &= ACPI_MASK_BITS_ABOVE (BitWidth); } if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY) { if (BitOffset || BitWidth < AccessWidth) { /* * Read old values in order not to modify the bits that * are beyond the register BitWidth/BitOffset setting. */ Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS) Address + Index * ACPI_DIV_8 (AccessWidth), &Value64, AccessWidth); OldValue32 = (UINT32) Value64; if (BitOffset) { OldValue32 &= ACPI_MASK_BITS_ABOVE (BitOffset + 1); BitOffset = 0; } if (BitWidth < AccessWidth) { OldValue32 &= ACPI_MASK_BITS_BELOW (BitWidth - 1); } NewValue32 |= OldValue32; } Value64 = (UINT64) NewValue32; Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS) Address + Index * ACPI_DIV_8 (AccessWidth), Value64, AccessWidth); } else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ { if (BitOffset || BitWidth < AccessWidth) { /* * Read old values in order not to modify the bits that * are beyond the register BitWidth/BitOffset setting. */ Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address + Index * ACPI_DIV_8 (AccessWidth), &OldValue32, AccessWidth); if (BitOffset) { OldValue32 &= ACPI_MASK_BITS_ABOVE (BitOffset + 1); BitOffset = 0; } if (BitWidth < AccessWidth) { OldValue32 &= ACPI_MASK_BITS_BELOW (BitWidth - 1); } NewValue32 |= OldValue32; } Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address + Index * ACPI_DIV_8 (AccessWidth), NewValue32, AccessWidth); } } BitWidth -= BitWidth > AccessWidth ? AccessWidth : BitWidth; Index++; } ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n", Value, AccessWidth, ACPI_FORMAT_UINT64 (Address), AcpiUtGetRegionName (Reg->SpaceId))); return (Status); }
ACPI_STATUS AcpiHwWrite ( UINT64 Value, ACPI_GENERIC_ADDRESS *Reg) { UINT64 Address; UINT8 AccessWidth; UINT32 BitWidth; UINT8 BitOffset; UINT64 Value64; UINT8 Index; ACPI_STATUS Status; ACPI_FUNCTION_NAME (HwWrite); /* Validate contents of the GAS register */ Status = AcpiHwValidateRegister (Reg, 64, &Address); if (ACPI_FAILURE (Status)) { return (Status); } /* Convert AccessWidth into number of bits based */ AccessWidth = AcpiHwGetAccessBitWidth (Address, Reg, 64); BitWidth = Reg->BitOffset + Reg->BitWidth; BitOffset = Reg->BitOffset; /* * Two address spaces supported: Memory or IO. PCI_Config is * not supported here because the GAS structure is insufficient */ Index = 0; while (BitWidth) { /* * Use offset style bit reads because "Index * AccessWidth" is * ensured to be less than 64-bits by AcpiHwValidateRegister(). */ Value64 = ACPI_GET_BITS (&Value, Index * AccessWidth, ACPI_MASK_BITS_ABOVE_64 (AccessWidth)); if (BitOffset >= AccessWidth) { BitOffset -= AccessWidth; } else { if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY) { Status = AcpiOsWriteMemory ((ACPI_PHYSICAL_ADDRESS) Address + Index * ACPI_DIV_8 (AccessWidth), Value64, AccessWidth); } else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ { Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address + Index * ACPI_DIV_8 (AccessWidth), (UINT32) Value64, AccessWidth); } } /* * Index * AccessWidth is ensured to be less than 32-bits by * AcpiHwValidateRegister(). */ BitWidth -= BitWidth > AccessWidth ? AccessWidth : BitWidth; Index++; } ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n", ACPI_FORMAT_UINT64 (Value), AccessWidth, ACPI_FORMAT_UINT64 (Address), AcpiUtGetRegionName (Reg->SpaceId))); return (Status); }