/******************************************************************************
*
* Module Name: exfldio - Aml Field I/O
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2016, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/
#include "acpi.h"
#include "accommon.h"
#include "acinterp.h"
#include "amlcode.h"
#include "acevents.h"
#include "acdispat.h"
ACPI_MODULE_NAME ("exfldio")
/* Local prototypes */
static ACPI_STATUS
static BOOLEAN
static ACPI_STATUS
/*******************************************************************************
*
* FUNCTION: AcpiExSetupRegion
*
* PARAMETERS: ObjDesc - Field to be read or written
* FieldDatumByteOffset - Byte offset of this datum within the
* parent field
*
* RETURN: Status
*
* DESCRIPTION: Common processing for AcpiExExtractFromField and
* AcpiExInsertIntoField. Initialize the Region if necessary and
* validate the request.
*
******************************************************************************/
static ACPI_STATUS
{
/* We must have a valid region */
{
}
/* Validate the Space ID */
if (!AcpiIsValidSpaceId (SpaceId))
{
}
/*
* If the Region Address and Length have not been previously evaluated,
* evaluate them now and save the results.
*/
{
if (ACPI_FAILURE (Status))
{
}
}
/*
* Exit now for SMBus, GSBus or IPMI address space, it has a non-linear
* address space and the request cannot be directly validated
*/
if (SpaceId == ACPI_ADR_SPACE_SMBUS ||
SpaceId == ACPI_ADR_SPACE_GSBUS ||
{
/* SMBus or IPMI has a non-linear address space */
}
#ifdef ACPI_UNDER_DEVELOPMENT
/*
* If the Field access is AnyAcc, we can now compute the optimal
* access (because we know know the length of the parent region)
*/
{
if (ACPI_FAILURE (Status))
{
}
}
#endif
/*
* Validate the request. The entire request from the byte offset for a
* length of one field datum (access width) must fit within the region.
* (Region length is specified in bytes)
*/
{
{
/*
* Slack mode only: We will go ahead and allow access to this
* field if it is within the region length rounded up to the next
* access width boundary. ACPI_SIZE cast for 64-bit compile.
*/
{
}
}
{
/*
* This is the case where the AccessType (AccWord, etc.) is wider
* than the region itself. For example, a region of length one
* byte, and a field with Dword access specified.
*/
"Field [%4.4s] access width (%u bytes) "
"too large for region [%4.4s] (length %u)",
}
/*
* Offset rounded up to next multiple of field width
* exceeds region length, indicate an error
*/
"Field [%4.4s] Base+Offset+Width %u+%u+%u "
"is beyond end of region [%4.4s] (length %u)",
}
}
/*******************************************************************************
*
* FUNCTION: AcpiExAccessRegion
*
* PARAMETERS: ObjDesc - Field to be read
* FieldDatumByteOffset - Byte offset of this datum within the
* parent field
* Value - Where to store value (must at least
* 64 bits)
* Function - Read or Write flag plus other region-
* dependent flags
*
* RETURN: Status
*
* DESCRIPTION: Read or Write a single field datum to an Operation Region.
*
******************************************************************************/
{
/*
* Ensure that the region operands are fully evaluated and verify
* the validity of the request
*/
if (ACPI_FAILURE (Status))
{
}
/*
* The physical address of this field datum is:
*
* 1) The base of the region, plus
* 2) The base offset of the field, plus
* 3) The current offset into the field
*/
{
}
else
{
}
" Region [%s:%X], Width %X, ByteBase %X, Offset %X at %8.8X%8.8X\n",
/* Invoke the appropriate AddressSpace/OpRegion handler */
if (ACPI_FAILURE (Status))
{
if (Status == AE_NOT_IMPLEMENTED)
{
"Region %s (ID=%u) not implemented",
}
else if (Status == AE_NOT_EXIST)
{
"Region %s (ID=%u) has no handler",
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiExRegisterOverflow
*
* PARAMETERS: ObjDesc - Register(Field) to be written
* Value - Value to be stored
*
* RETURN: TRUE if value overflows the field, FALSE otherwise
*
* DESCRIPTION: Check if a value is out of range of the field being written.
* Used to check if the values written to Index and Bank registers
* are out of range. Normally, the value is simply truncated
* to fit the field, but this case is most likely a serious
* coding error in the ASL.
*
******************************************************************************/
static BOOLEAN
{
{
/*
* The field is large enough to hold the maximum integer, so we can
* never overflow it.
*/
return (FALSE);
}
{
/*
* The Value is larger than the maximum value that can fit into
* the register.
*/
"Index value 0x%8.8X%8.8X overflows field width 0x%X",
return (TRUE);
}
/* The Value will fit into the field with no truncation */
return (FALSE);
}
/*******************************************************************************
*
* FUNCTION: AcpiExFieldDatumIo
*
* PARAMETERS: ObjDesc - Field to be read
* FieldDatumByteOffset - Byte offset of this datum within the
* parent field
* Value - Where to store value (must be 64 bits)
* ReadWrite - Read or Write flag
*
* RETURN: Status
*
* DESCRIPTION: Read or Write a single datum of a field. The FieldType is
* demultiplexed here to handle the different types of fields
* (BufferField, RegionField, IndexField, BankField)
*
******************************************************************************/
static ACPI_STATUS
{
{
if (!Value)
{
LocalValue = 0;
/* To support reads without saving return value */
Value = &LocalValue;
}
/* Clear the entire return buffer first, [Very Important!] */
*Value = 0;
}
/*
* The four types of fields are:
*
* OperationRegion
* Data Register
*/
{
case ACPI_TYPE_BUFFER_FIELD:
/*
* If the BufferField arguments have not been previously evaluated,
* evaluate them now and save the results.
*/
{
if (ACPI_FAILURE (Status))
{
}
}
{
/*
* Copy the data from the source buffer.
* Length is the field width in bytes.
*/
}
else
{
/*
* Copy the data to the target buffer.
* Length is the field width in bytes.
*/
}
break;
/*
* Ensure that the BankValue is not beyond the capacity of
* the register
*/
{
}
/*
* For BankFields, we must write the BankValue to the BankRegister
* (itself a RegionField) before we can access the data.
*/
if (ACPI_FAILURE (Status))
{
}
/*
* Now that the Bank has been selected, fall through to the
* RegionField case and write the datum to the Operation Region
*/
/*lint -fallthrough */
/*
* For simple RegionFields, we just directly access the owning
* Operation Region.
*/
break;
/*
* Ensure that the IndexValue is not beyond the capacity of
* the register
*/
{
}
/* Write the index value to the IndexRegister (itself a RegionField) */
"Write to Index Register: Value %8.8X\n",
&FieldDatumByteOffset, sizeof (FieldDatumByteOffset));
if (ACPI_FAILURE (Status))
{
}
{
/* Read the datum from the DataRegister */
"Read from Data Register\n"));
}
else
{
/* Write the datum to the DataRegister */
"Write to Data Register: Value %8.8X%8.8X\n",
ACPI_FORMAT_UINT64 (*Value)));
}
break;
default:
break;
}
if (ACPI_SUCCESS (Status))
{
{
"Value Read %8.8X%8.8X, Width %u\n",
}
else
{
"Value Written %8.8X%8.8X, Width %u\n",
}
}
}
/*******************************************************************************
*
* FUNCTION: AcpiExWriteWithUpdateRule
*
* PARAMETERS: ObjDesc - Field to be written
* Mask - bitmask within field datum
* FieldValue - Value to write
* FieldDatumByteOffset - Offset of datum within field
*
* RETURN: Status
*
* DESCRIPTION: Apply the field update rule to a field write
*
******************************************************************************/
{
/* Start with the new bits */
/* If the mask is all ones, we don't need to worry about the update rule */
if (Mask != ACPI_UINT64_MAX)
{
/* Decode the update rule */
{
/*
* Check if update rule needs to be applied (not if mask is all
* ones) The left shift drops the bits we want to ignore.
*/
{
/*
* the field, and merge with the new field value.
*/
if (ACPI_FAILURE (Status))
{
}
}
break;
/* Set positions outside the field to all ones */
MergedValue |= ~Mask;
break;
/* Set positions outside the field to all zeros */
MergedValue &= Mask;
break;
default:
"Unknown UpdateRule value: 0x%X",
}
}
"Mask %8.8X%8.8X, DatumOffset %X, Width %X, "
"Value %8.8X%8.8X, MergedValue %8.8X%8.8X\n",
/* Write the merged value */
}
/*******************************************************************************
*
* FUNCTION: AcpiExExtractFromField
*
* PARAMETERS: ObjDesc - Field to be read
* Buffer - Where to store the field data
* BufferLength - Length of Buffer
*
* RETURN: Status
*
* DESCRIPTION: Retrieve the current value of the given field
*
******************************************************************************/
void *Buffer,
{
UINT32 i;
/* Validate target buffer and clear it */
if (BufferLength <
{
"Field size %u (bits) is too large for buffer (%u)",
}
/* Handle the simple case here */
{
if (BufferLength >= sizeof (UINT64))
{
}
else
{
/* Use RawDatum (UINT64) to handle buffers < 64 bits */
}
}
/* TBD: Move to common setup code */
/* Field algorithm is limited to sizeof(UINT64), truncate if needed */
{
}
/* Compute the number of datums (access width data items) */
/* Priming read from the field */
if (ACPI_FAILURE (Status))
{
}
/* Read the rest of the field */
for (i = 1; i < FieldDatumCount; i++)
{
/* Get next input datum from the field */
if (ACPI_FAILURE (Status))
{
}
/*
* Merge with previous datum if necessary.
*
* Note: Before the shift, check if the shift value will be larger than
* the integer size. If so, there is no need to perform the operation.
* This avoids the differences in behavior between different compilers
* concerning shift values larger than the target data width.
*/
{
MergedDatum |= RawDatum <<
}
if (i == DatumCount)
{
break;
}
/* Write merged datum to target buffer */
BufferLength - BufferOffset));
}
/* Mask off any extra bits in the last datum */
if (BufferTailBits)
{
}
/* Write the last datum to the buffer */
BufferLength - BufferOffset));
}
/*******************************************************************************
*
* FUNCTION: AcpiExInsertIntoField
*
* PARAMETERS: ObjDesc - Field to be written
* Buffer - Data to be written
* BufferLength - Length of Buffer
*
* RETURN: Status
*
* DESCRIPTION: Store the Buffer contents into the given field
*
******************************************************************************/
void *Buffer,
{
void *NewBuffer;
UINT32 i;
/* Validate input buffer */
/*
* We must have a buffer that is at least as long as the field
* we are writing to. This is because individual fields are
* indivisible and partial writes are not supported -- as per
* the ACPI specification.
*/
if (BufferLength < RequiredLength)
{
/* We need to create a new buffer */
if (!NewBuffer)
{
}
/*
* Copy the original data to the new buffer, starting
* at Byte zero. All unused (upper) bytes of the
* buffer will be 0.
*/
}
/* TBD: Move to common setup code */
/* Algo is limited to sizeof(UINT64), so cut the AccessByteWidth */
{
}
/*
* Create the bitmasks used for bit insertion.
* shift operator
*/
if (AccessBitWidth == ACPI_INTEGER_BIT_SIZE)
{
}
else
{
}
/* Compute the number of datums (access width data items) */
/* Get initial Datum from the input buffer */
BufferLength - BufferOffset));
/* Write the entire field */
for (i = 1; i < FieldDatumCount; i++)
{
/* Write merged datum to the target field */
MergedDatum &= Mask;
if (ACPI_FAILURE (Status))
{
goto Exit;
}
/*
* Start new output datum by merging with previous input datum
* if necessary.
*
* Note: Before the shift, check if the shift value will be larger than
* the integer size. If so, there is no need to perform the operation.
* This avoids the differences in behavior between different compilers
* concerning shift values larger than the target data width.
*/
{
MergedDatum = RawDatum >>
}
else
{
MergedDatum = 0;
}
if (i == DatumCount)
{
break;
}
/* Get the next input datum from the buffer */
BufferLength - BufferOffset));
}
/* Mask off any extra bits in the last datum */
if (BufferTailBits)
{
}
/* Write the last datum to the field */
MergedDatum &= Mask;
Exit:
/* Free temporary buffer if we used one */
if (NewBuffer)
{
}
}