summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Moore <Robert.Moore@intel.com>2016-12-02 08:14:38 -0800
committerGitHub <noreply@github.com>2016-12-02 08:14:38 -0800
commit47614972f78c7b9cef9d5c04a0b6921dc0b1d00d (patch)
treec1e2b6b91b4f5a7d52d14155b5a8d2ae17b8568d
parent2f4aaeb703e4671b700faad85e6fcaf56c8ce664 (diff)
parent365b321a31cb701957c055cae2d2161577147252 (diff)
downloadacpica-47614972f78c7b9cef9d5c04a0b6921dc0b1d00d.tar.gz
Merge pull request #161 from zetalog/acpica-gas
Acpica gas
-rw-r--r--source/components/executer/exfldio.c15
-rw-r--r--source/components/hardware/hwregs.c230
-rw-r--r--source/include/acmacros.h77
3 files changed, 276 insertions, 46 deletions
diff --git a/source/components/executer/exfldio.c b/source/components/executer/exfldio.c
index b7e86fdb0..578ba48e0 100644
--- a/source/components/executer/exfldio.c
+++ b/source/components/executer/exfldio.c
@@ -1018,20 +1018,9 @@ AcpiExInsertIntoField (
AccessBitWidth = ACPI_MUL_8 (ObjDesc->CommonField.AccessByteWidth);
- /*
- * Create the bitmasks used for bit insertion.
- * Note: This if/else is used to bypass compiler differences with the
- * shift operator
- */
- if (AccessBitWidth == ACPI_INTEGER_BIT_SIZE)
- {
- WidthMask = ACPI_UINT64_MAX;
- }
- else
- {
- WidthMask = ACPI_MASK_BITS_ABOVE (AccessBitWidth);
- }
+ /* Create the bitmasks used for bit insertion */
+ WidthMask = ACPI_MASK_BITS_ABOVE_64 (AccessBitWidth);
Mask = WidthMask &
ACPI_MASK_BITS_BELOW (ObjDesc->CommonField.StartFieldBitOffset);
diff --git a/source/components/hardware/hwregs.c b/source/components/hardware/hwregs.c
index ffad33fcf..1f9e4c245 100644
--- a/source/components/hardware/hwregs.c
+++ b/source/components/hardware/hwregs.c
@@ -126,6 +126,12 @@
/* Local Prototypes */
+static UINT8
+AcpiHwGetAccessBitWidth (
+ UINT64 Address,
+ ACPI_GENERIC_ADDRESS *Reg,
+ UINT8 MaxBitWidth);
+
static ACPI_STATUS
AcpiHwReadMultiple (
UINT32 *Value,
@@ -143,6 +149,90 @@ AcpiHwWriteMultiple (
/******************************************************************************
*
+ * FUNCTION: AcpiHwGetAccessBitWidth
+ *
+ * PARAMETERS: Address - GAS register address
+ * Reg - GAS register structure
+ * MaxBitWidth - Max BitWidth supported (32 or 64)
+ *
+ * RETURN: Status
+ *
+ * DESCRIPTION: Obtain optimal access bit width
+ *
+ ******************************************************************************/
+
+static UINT8
+AcpiHwGetAccessBitWidth (
+ UINT64 Address,
+ ACPI_GENERIC_ADDRESS *Reg,
+ UINT8 MaxBitWidth)
+{
+ UINT8 AccessBitWidth;
+
+
+ /*
+ * GAS format "register", used by FADT:
+ * 1. Detected if BitOffset is 0 and BitWidth is 8/16/32/64;
+ * 2. AccessSize field is ignored and BitWidth field is used for
+ * determining the boundary of the IO accesses.
+ * GAS format "region", used by APEI registers:
+ * 1. Detected if BitOffset is not 0 or BitWidth is not 8/16/32/64;
+ * 2. AccessSize field is used for determining the boundary of the
+ * IO accesses;
+ * 3. BitOffset/BitWidth fields are used to describe the "region".
+ *
+ * Note: This algorithm assumes that the "Address" fields should always
+ * contain aligned values.
+ */
+ if (!Reg->BitOffset && Reg->BitWidth &&
+ ACPI_IS_POWER_OF_TWO (Reg->BitWidth) &&
+ ACPI_IS_ALIGNED (Reg->BitWidth, 8))
+ {
+ AccessBitWidth = Reg->BitWidth;
+ }
+ else if (Reg->AccessWidth)
+ {
+ AccessBitWidth = (1 << (Reg->AccessWidth + 2));
+ }
+ else
+ {
+ AccessBitWidth = ACPI_ROUND_UP_POWER_OF_TWO_8 (
+ Reg->BitOffset + Reg->BitWidth);
+ if (AccessBitWidth <= 8)
+ {
+ AccessBitWidth = 8;
+ }
+ else
+ {
+ while (!ACPI_IS_ALIGNED (Address, AccessBitWidth >> 3))
+ {
+ AccessBitWidth >>= 1;
+ }
+ }
+ }
+
+ /* Maximum IO port access bit width is 32 */
+
+ if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_IO)
+ {
+ MaxBitWidth = 32;
+ }
+
+ /*
+ * Return access width according to the requested maximum access bit width,
+ * as the caller should know the format of the register and may enforce
+ * a 32-bit accesses.
+ */
+ if (AccessBitWidth < MaxBitWidth)
+ {
+ return (AccessBitWidth);
+ }
+ return (MaxBitWidth);
+}
+
+
+/******************************************************************************
+ *
* FUNCTION: AcpiHwValidateRegister
*
* PARAMETERS: Reg - GAS register structure
@@ -163,6 +253,9 @@ AcpiHwValidateRegister (
UINT8 MaxBitWidth,
UINT64 *Address)
{
+ UINT8 BitWidth;
+ UINT8 AccessWidth;
+
/* Must have a valid pointer to a GAS structure */
@@ -192,24 +285,25 @@ AcpiHwValidateRegister (
return (AE_SUPPORT);
}
- /* Validate the BitWidth */
+ /* Validate the AccessWidth */
- if ((Reg->BitWidth != 8) &&
- (Reg->BitWidth != 16) &&
- (Reg->BitWidth != 32) &&
- (Reg->BitWidth != MaxBitWidth))
+ if (Reg->AccessWidth > 4)
{
ACPI_ERROR ((AE_INFO,
- "Unsupported register bit width: 0x%X", Reg->BitWidth));
+ "Unsupported register access width: 0x%X", Reg->AccessWidth));
return (AE_SUPPORT);
}
- /* Validate the BitOffset. Just a warning for now. */
+ /* Validate the BitWidth, convert AccessWidth into number of bits */
- if (Reg->BitOffset != 0)
+ AccessWidth = AcpiHwGetAccessBitWidth (*Address, Reg, MaxBitWidth);
+ BitWidth = ACPI_ROUND_UP (Reg->BitOffset + Reg->BitWidth, AccessWidth);
+ if (MaxBitWidth < BitWidth)
{
ACPI_WARNING ((AE_INFO,
- "Unsupported register bit offset: 0x%X", Reg->BitOffset));
+ "Requested bit width 0x%X is smaller than register bit width 0x%X",
+ MaxBitWidth, BitWidth));
+ return (AE_SUPPORT);
}
return (AE_OK);
@@ -230,10 +324,7 @@ AcpiHwValidateRegister (
* 64-bit values is not needed.
*
* LIMITATIONS: <These limitations also apply to AcpiHwWrite>
- * BitWidth must be exactly 8, 16, or 32.
* SpaceID must be SystemMemory or SystemIO.
- * BitOffset and AccessWidth are currently ignored, as there has
- * not been a need to implement these.
*
******************************************************************************/
@@ -243,7 +334,12 @@ AcpiHwRead (
ACPI_GENERIC_ADDRESS *Reg)
{
UINT64 Address;
+ UINT8 AccessWidth;
+ UINT32 BitWidth;
+ UINT8 BitOffset;
UINT64 Value64;
+ UINT32 Value32;
+ UINT8 Index;
ACPI_STATUS Status;
@@ -258,30 +354,58 @@ AcpiHwRead (
return (Status);
}
- /* Initialize entire 32-bit return value to zero */
-
+ /*
+ * Initialize entire 32-bit return value to zero, convert AccessWidth
+ * into number of bits based
+ */
*Value = 0;
+ AccessWidth = AcpiHwGetAccessBitWidth (Address, Reg, 32);
+ 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
*/
- if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
+ Index = 0;
+ while (BitWidth)
{
- Status = AcpiOsReadMemory ((ACPI_PHYSICAL_ADDRESS)
- Address, &Value64, Reg->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);
+ }
+ }
- *Value = (UINT32) Value64;
- }
- else /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
- {
- Status = AcpiHwReadPort ((ACPI_IO_ADDRESS)
- Address, Value, Reg->BitWidth);
+ /*
+ * Use offset style bit writes because "Index * AccessWidth" is
+ * ensured to be less than 32-bits by AcpiHwValidateRegister().
+ */
+ ACPI_SET_BITS (Value, Index * AccessWidth,
+ ACPI_MASK_BITS_ABOVE_32 (AccessWidth), 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, Reg->BitWidth, ACPI_FORMAT_UINT64 (Address),
+ *Value, AccessWidth, ACPI_FORMAT_UINT64 (Address),
AcpiUtGetRegionName (Reg->SpaceId)));
return (Status);
@@ -309,6 +433,12 @@ AcpiHwWrite (
ACPI_GENERIC_ADDRESS *Reg)
{
UINT64 Address;
+ UINT8 AccessWidth;
+ UINT32 BitWidth;
+ UINT8 BitOffset;
+ UINT64 Value64;
+ UINT32 Value32;
+ UINT8 Index;
ACPI_STATUS Status;
@@ -323,24 +453,58 @@ AcpiHwWrite (
return (Status);
}
+ /* Convert AccessWidth into number of bits based */
+
+ AccessWidth = AcpiHwGetAccessBitWidth (Address, Reg, 32);
+ 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
*/
- if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
+ Index = 0;
+ while (BitWidth)
{
- 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);
+ /*
+ * Use offset style bit reads because "Index * AccessWidth" is
+ * ensured to be less than 32-bits by AcpiHwValidateRegister().
+ */
+ Value32 = ACPI_GET_BITS (&Value, Index * AccessWidth,
+ ACPI_MASK_BITS_ABOVE_32 (AccessWidth));
+
+ if (BitOffset >= AccessWidth)
+ {
+ BitOffset -= AccessWidth;
+ }
+ else
+ {
+ if (Reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY)
+ {
+ Value64 = (UINT64) Value32;
+ 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),
+ Value32, 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 width %2d to %8.8X%8.8X (%s)\n",
- Value, Reg->BitWidth, ACPI_FORMAT_UINT64 (Address),
+ Value, AccessWidth, ACPI_FORMAT_UINT64 (Address),
AcpiUtGetRegionName (Reg->SpaceId)));
return (Status);
diff --git a/source/include/acmacros.h b/source/include/acmacros.h
index a805a32ce..0cecfa022 100644
--- a/source/include/acmacros.h
+++ b/source/include/acmacros.h
@@ -336,14 +336,91 @@
#define ACPI_IS_MISALIGNED(value) (((ACPI_SIZE) value) & (sizeof(ACPI_SIZE)-1))
+/* Generic (power-of-two) rounding */
+
+#ifndef ACPI_USE_NATIVE_BIT_FINDER
+
+#define __ACPI_FIND_LAST_BIT_2(a, r) ((((UINT8) (a)) & 0x02) ? (r)+1 : (r))
+#define __ACPI_FIND_LAST_BIT_4(a, r) ((((UINT8) (a)) & 0x0C) ? \
+ __ACPI_FIND_LAST_BIT_2 ((a)>>2, (r)+2) : \
+ __ACPI_FIND_LAST_BIT_2 ((a), (r)))
+#define __ACPI_FIND_LAST_BIT_8(a, r) ((((UINT8) (a)) & 0xF0) ? \
+ __ACPI_FIND_LAST_BIT_4 ((a)>>4, (r)+4) : \
+ __ACPI_FIND_LAST_BIT_4 ((a), (r)))
+#define __ACPI_FIND_LAST_BIT_16(a, r) ((((UINT16) (a)) & 0xFF00) ? \
+ __ACPI_FIND_LAST_BIT_8 ((a)>>8, (r)+8) : \
+ __ACPI_FIND_LAST_BIT_8 ((a), (r)))
+#define __ACPI_FIND_LAST_BIT_32(a, r) ((((UINT32) (a)) & 0xFFFF0000) ? \
+ __ACPI_FIND_LAST_BIT_16 ((a)>>16, (r)+16) : \
+ __ACPI_FIND_LAST_BIT_16 ((a), (r)))
+#define __ACPI_FIND_LAST_BIT_64(a, r) ((((UINT64) (a)) & 0xFFFFFFFF00000000) ? \
+ __ACPI_FIND_LAST_BIT_32 ((a)>>32, (r)+32) : \
+ __ACPI_FIND_LAST_BIT_32 ((a), (r)))
+
+#define ACPI_FIND_LAST_BIT_8(a) ((a) ? __ACPI_FIND_LAST_BIT_8 (a, 1) : 0)
+#define ACPI_FIND_LAST_BIT_16(a) ((a) ? __ACPI_FIND_LAST_BIT_16 (a, 1) : 0)
+#define ACPI_FIND_LAST_BIT_32(a) ((a) ? __ACPI_FIND_LAST_BIT_32 (a, 1) : 0)
+#define ACPI_FIND_LAST_BIT_64(a) ((a) ? __ACPI_FIND_LAST_BIT_64 (a, 1) : 0)
+
+#define __ACPI_FIND_FIRST_BIT_2(a, r) ((((UINT8) (a)) & 0x01) ? (r) : (r)+1)
+#define __ACPI_FIND_FIRST_BIT_4(a, r) ((((UINT8) (a)) & 0x03) ? \
+ __ACPI_FIND_FIRST_BIT_2 ((a), (r)) : \
+ __ACPI_FIND_FIRST_BIT_2 ((a)>>2, (r)+2))
+#define __ACPI_FIND_FIRST_BIT_8(a, r) ((((UINT8) (a)) & 0x0F) ? \
+ __ACPI_FIND_FIRST_BIT_4 ((a), (r)) : \
+ __ACPI_FIND_FIRST_BIT_4 ((a)>>4, (r)+4))
+#define __ACPI_FIND_FIRST_BIT_16(a, r) ((((UINT16) (a)) & 0x00FF) ? \
+ __ACPI_FIND_FIRST_BIT_8 ((a), (r)) : \
+ __ACPI_FIND_FIRST_BIT_8 ((a)>>8, (r)+8))
+#define __ACPI_FIND_FIRST_BIT_32(a, r) ((((UINT32) (a)) & 0x0000FFFF) ? \
+ __ACPI_FIND_FIRST_BIT_16 ((a), (r)) : \
+ __ACPI_FIND_FIRST_BIT_16 ((a)>>16, (r)+16))
+#define __ACPI_FIND_FIRST_BIT_64(a, r) ((((UINT64) (a)) & 0x00000000FFFFFFFF) ? \
+ __ACPI_FIND_FIRST_BIT_32 ((a), (r)) : \
+ __ACPI_FIND_FIRST_BIT_32 ((a)>>32, (r)+32))
+
+#define ACPI_FIND_FIRST_BIT_8(a) ((a) ? __ACPI_FIND_FIRST_BIT_8 (a, 1) : 0)
+#define ACPI_FIND_FIRST_BIT_16(a) ((a) ? __ACPI_FIND_FIRST_BIT_16 (a, 1) : 0)
+#define ACPI_FIND_FIRST_BIT_32(a) ((a) ? __ACPI_FIND_FIRST_BIT_32 (a, 1) : 0)
+#define ACPI_FIND_FIRST_BIT_64(a) ((a) ? __ACPI_FIND_FIRST_BIT_64 (a, 1) : 0)
+
+#endif /* ACPI_USE_NATIVE_BIT_FINDER */
+
+#define ACPI_ROUND_UP_POWER_OF_TWO_8(a) ((UINT8) \
+ (((UINT16) 1) << ACPI_FIND_LAST_BIT_8 ((a) - 1)))
+#define ACPI_ROUND_DOWN_POWER_OF_TWO_8(a) ((UINT8) \
+ (((UINT16) 1) << (ACPI_FIND_LAST_BIT_8 ((a)) - 1)))
+#define ACPI_ROUND_UP_POWER_OF_TWO_16(a) ((UINT16) \
+ (((UINT32) 1) << ACPI_FIND_LAST_BIT_16 ((a) - 1)))
+#define ACPI_ROUND_DOWN_POWER_OF_TWO_16(a) ((UINT16) \
+ (((UINT32) 1) << (ACPI_FIND_LAST_BIT_16 ((a)) - 1)))
+#define ACPI_ROUND_UP_POWER_OF_TWO_32(a) ((UINT32) \
+ (((UINT64) 1) << ACPI_FIND_LAST_BIT_32 ((a) - 1)))
+#define ACPI_ROUND_DOWN_POWER_OF_TWO_32(a) ((UINT32) \
+ (((UINT64) 1) << (ACPI_FIND_LAST_BIT_32 ((a)) - 1)))
+#define ACPI_IS_ALIGNED(a, s) (((a) & ((s) - 1)) == 0)
+#define ACPI_IS_POWER_OF_TWO(a) ACPI_IS_ALIGNED(a, a)
+
/*
* Bitmask creation
* Bit positions start at zero.
* MASK_BITS_ABOVE creates a mask starting AT the position and above
* MASK_BITS_BELOW creates a mask starting one bit BELOW the position
+ * MASK_BITS_ABOVE/BELOW accpets a bit offset to create a mask
+ * MASK_BITS_ABOVE/BELOW_32/64 accpets a bit width to create a mask
+ * Note: The ACPI_INTEGER_BIT_SIZE check is used to bypass compiler
+ * differences with the shift operator
*/
#define ACPI_MASK_BITS_ABOVE(position) (~((ACPI_UINT64_MAX) << ((UINT32) (position))))
#define ACPI_MASK_BITS_BELOW(position) ((ACPI_UINT64_MAX) << ((UINT32) (position)))
+#define ACPI_MASK_BITS_ABOVE_32(width) ((UINT32) ACPI_MASK_BITS_ABOVE(width))
+#define ACPI_MASK_BITS_BELOW_32(width) ((UINT32) ACPI_MASK_BITS_BELOW(width))
+#define ACPI_MASK_BITS_ABOVE_64(width) ((width) == ACPI_INTEGER_BIT_SIZE ? \
+ ACPI_UINT64_MAX : \
+ ACPI_MASK_BITS_ABOVE(width))
+#define ACPI_MASK_BITS_BELOW_64(width) ((width) == ACPI_INTEGER_BIT_SIZE ? \
+ (UINT64) 0 : \
+ ACPI_MASK_BITS_BELOW(width))
/* Bitfields within ACPI registers */