ACPI_STATUS AcpiHwRead ( UINT32 *Value, ACPI_GENERIC_ADDRESS *Reg) { UINT64 Address; UINT64 Value64; ACPI_STATUS Status; ACPI_FUNCTION_NAME (HwRead); /* Validate contents of the GAS register */ Status = AcpiHwValidateRegister (Reg, 32, &Address); if (ACPI_FAILURE (Status)) { return (Status); } /* Initialize entire 32-bit return value to zero */ *Value = 0; /* * 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 = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS) Address, &Value64, Reg->BitWidth); *Value = (UINT32) Value64; } else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ { Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address, Value, Reg->BitWidth); } ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n", *Value, Reg->BitWidth, ACPI_FORMAT_UINT64 (Address), AcpiUtGetRegionName (Reg->SpaceId))); return (Status); }
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 AcpiHwRegisterRead ( UINT32 RegisterId, UINT32 *ReturnValue) { UINT32 Value = 0; ACPI_STATUS Status; ACPI_FUNCTION_TRACE (HwRegisterRead); switch (RegisterId) { case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */ Status = AcpiHwReadMultiple (&Value, &AcpiGbl_XPm1aStatus, &AcpiGbl_XPm1bStatus); break; case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */ Status = AcpiHwReadMultiple (&Value, &AcpiGbl_XPm1aEnable, &AcpiGbl_XPm1bEnable); break; case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */ Status = AcpiHwReadMultiple (&Value, &AcpiGbl_FADT.XPm1aControlBlock, &AcpiGbl_FADT.XPm1bControlBlock); /* * Zero the write-only bits. From the ACPI specification, "Hardware * Write-Only Bits": "Upon reads to registers with write-only bits, * software masks out all write-only bits." */ Value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS; break; case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ Status = AcpiHwRead (&Value, &AcpiGbl_FADT.XPm2ControlBlock); break; case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ Status = AcpiHwRead (&Value, &AcpiGbl_FADT.XPmTimerBlock); break; case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ Status = AcpiHwReadPort (AcpiGbl_FADT.SmiCommand, &Value, 8); break; default: ACPI_ERROR ((AE_INFO, "Unknown Register ID: 0x%X", RegisterId)); Status = AE_BAD_PARAMETER; break; } if (ACPI_SUCCESS (Status)) { *ReturnValue = Value; } 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 AcpiHwRead ( UINT32 *Value, ACPI_GENERIC_ADDRESS *Reg) { UINT64 Address; UINT8 AccessWidth; UINT32 BitWidth; UINT8 BitOffset; UINT64 Value64; UINT32 Value32; UINT8 Index; ACPI_STATUS Status; ACPI_FUNCTION_NAME (HwRead); /* Validate contents of the GAS register */ Status = AcpiHwValidateRegister (Reg, 32, &Address); if (ACPI_FAILURE (Status)) { return (Status); } /* * Initialize entire 32-bit return value to zero, convert AccessWidth * into number of bits based */ *Value = 0; 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) { if (BitOffset > AccessWidth) { Value32 = 0; BitOffset -= AccessWidth; } else { if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY) { Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS) Address + Index * ACPI_DIV_8 (AccessWidth), &Value64, AccessWidth); Value32 = (UINT32) Value64; } else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ { Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address + Index * ACPI_DIV_8 (AccessWidth), &Value32, AccessWidth); } if (BitOffset) { Value32 &= ACPI_MASK_BITS_BELOW (BitOffset); BitOffset = 0; } if (BitWidth < AccessWidth) { Value32 &= ACPI_MASK_BITS_ABOVE (BitWidth); } } ACPI_SET_BITS (Value, Index * AccessWidth, ((1 << AccessWidth) - 1), Value32); BitWidth -= BitWidth > AccessWidth ? AccessWidth : BitWidth; Index++; } ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n", *Value, AccessWidth, ACPI_FORMAT_UINT64 (Address), AcpiUtGetRegionName (Reg->SpaceId))); return (Status); }
ACPI_STATUS AcpiHwRead ( UINT64 *Value, ACPI_GENERIC_ADDRESS *Reg) { UINT64 Address; UINT8 AccessWidth; UINT32 BitWidth; UINT8 BitOffset; UINT64 Value64; UINT32 Value32; UINT8 Index; ACPI_STATUS Status; ACPI_FUNCTION_NAME (HwRead); /* Validate contents of the GAS register */ Status = AcpiHwValidateRegister (Reg, 64, &Address); if (ACPI_FAILURE (Status)) { return (Status); } /* * Initialize entire 64-bit return value to zero, convert AccessWidth * into number of bits based */ *Value = 0; 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) { if (BitOffset >= AccessWidth) { Value64 = 0; BitOffset -= AccessWidth; } else { if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY) { Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS) Address + Index * ACPI_DIV_8 (AccessWidth), &Value64, AccessWidth); } else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ { Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address + Index * ACPI_DIV_8 (AccessWidth), &Value32, AccessWidth); Value64 = (UINT64) Value32; } } /* * Use offset style bit writes because "Index * AccessWidth" is * ensured to be less than 64-bits by AcpiHwValidateRegister(). */ ACPI_SET_BITS (Value, Index * AccessWidth, ACPI_MASK_BITS_ABOVE_64 (AccessWidth), Value64); BitWidth -= BitWidth > AccessWidth ? AccessWidth : BitWidth; Index++; } ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n", ACPI_FORMAT_UINT64 (*Value), AccessWidth, ACPI_FORMAT_UINT64 (Address), AcpiUtGetRegionName (Reg->SpaceId))); return (Status); }