tbutils.c revision 26f3cdf03f1adcc98f6d3d99843ee71e9229a8c0
/******************************************************************************
*
* Module Name: tbutils - table utilities
*
*****************************************************************************/
/*
* Copyright (C) 2000 - 2011, 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.
*/
#define __TBUTILS_C__
#include "acpi.h"
#include "accommon.h"
#include "actables.h"
#define _COMPONENT ACPI_TABLES
ACPI_MODULE_NAME ("tbutils")
/* Local prototypes */
static void
char *String,
static void
static ACPI_PHYSICAL_ADDRESS
/*******************************************************************************
*
* FUNCTION: AcpiTbInitializeFacs
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Create a permanent mapping for the FADT and save it in a global
* for accessing the Global Lock and Firmware Waking Vector
*
******************************************************************************/
void)
{
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiTbTablesLoaded
*
* PARAMETERS: None
*
* RETURN: TRUE if required ACPI tables are loaded
*
* DESCRIPTION: Determine if the minimum required ACPI tables are present
* (FADT, FACS, DSDT)
*
******************************************************************************/
void)
{
{
return (TRUE);
}
return (FALSE);
}
/*******************************************************************************
*
* FUNCTION: AcpiTbFixString
*
* PARAMETERS: String - String to be repaired
* Length - Maximum length
*
* RETURN: None
*
* DESCRIPTION: Replace every non-printable or non-ascii byte in the string
* with a question mark '?'.
*
******************************************************************************/
static void
char *String,
{
{
if (!ACPI_IS_PRINT (*String))
{
*String = '?';
}
String++;
Length--;
}
}
/*******************************************************************************
*
* FUNCTION: AcpiTbCleanupTableHeader
*
* PARAMETERS: OutHeader - Where the cleaned header is returned
* Header - Input ACPI table header
*
* RETURN: Returns the cleaned header in OutHeader
*
* DESCRIPTION: Copy the table header and ensure that all "string" fields in
* the header consist of printable characters.
*
******************************************************************************/
static void
{
}
/*******************************************************************************
*
* FUNCTION: AcpiTbPrintTableHeader
*
* PARAMETERS: Address - Table physical address
* Header - Table header
*
* RETURN: None
*
* DESCRIPTION: Print an ACPI table header. Special cases for FACS and RSDP.
*
******************************************************************************/
void
{
/*
* The reason that the Address is cast to a void pointer is so that we
* can use %p which will work properly on both 32-bit and 64-bit hosts.
*/
{
/* FACS only has signature and length fields */
}
{
/* RSDP has no common fields */
ACPI_CAST_PTR (void, Address),
LocalHeader.OemId));
}
else
{
/* Standard ACPI table with full common header */
"%4.4s %p %05X (v%.2d %6.6s %8.8s %08X %4.4s %08X)",
}
}
/*******************************************************************************
*
* FUNCTION: AcpiTbValidateChecksum
*
* PARAMETERS: Table - ACPI table to verify
* Length - Length of entire table
*
* RETURN: Status
*
* DESCRIPTION: Verifies that the table checksums to zero. Optionally returns
* exception on bad checksum.
*
******************************************************************************/
{
/* Compute the checksum on the table */
/* Checksum ok? (should be zero) */
if (Checksum)
{
"Incorrect checksum in table [%4.4s] - 0x%2.2X, should be 0x%2.2X",
#if (ACPI_CHECKSUM_ABORT)
return (AE_BAD_CHECKSUM);
#endif
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiTbChecksum
*
* PARAMETERS: Buffer - Pointer to memory region to be checked
* Length - Length of this memory region
*
* RETURN: Checksum (UINT8)
*
* DESCRIPTION: Calculates circular checksum of memory region.
*
******************************************************************************/
{
{
}
return Sum;
}
/*******************************************************************************
*
* FUNCTION: AcpiTbCheckDsdtHeader
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
* the DSDT header has been corrupted.
*
******************************************************************************/
void
void)
{
/* Compare original length and checksum to current values */
{
"The DSDT has been corrupted or replaced - old, new headers below"));
/* Disable further error messages */
}
}
/*******************************************************************************
*
* FUNCTION: AcpiTbCopyDsdt
*
* PARAMETERS: TableDesc - Installed table to copy
*
* RETURN: None
*
* DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
* Some very bad BIOSs are known to either corrupt the DSDT or
* install a new, bad DSDT. This copy works around the problem.
*
******************************************************************************/
{
if (!NewTable)
{
return (NULL);
}
"Forced DSDT copy: length 0x%05X copied locally, original unmapped",
return (NewTable);
}
/*******************************************************************************
*
* FUNCTION: AcpiTbInstallTable
*
* PARAMETERS: Address - Physical address of DSDT or FACS
* Signature - Table signature, NULL if no need to
* match
* TableIndex - Index into root table array
*
* RETURN: None
*
* DESCRIPTION: Install an ACPI table into the global data structure. The
* table override mechanism is implemented here to allow the host
* OS to replace any table before it is installed in the root
* table array.
*
******************************************************************************/
void
char *Signature,
{
if (!Address)
{
Signature));
return;
}
/* Map just the table header */
if (!MappedTable)
{
return;
}
if (Signature &&
{
"Invalid signature 0x%X for ACPI table, expected [%s]",
goto UnmapAndExit;
}
/*
* ACPI Table Override:
*
* Before we install the table, let the host OS override it with a new
* including the DSDT which is pointed to by the FADT.
*/
{
"%4.4s @ 0x%p Table override, replaced with:",
}
else
{
}
/* Initialize the table entry */
if (TableIndex == ACPI_TABLE_INDEX_DSDT)
{
/* Global integer width is based upon revision of the DSDT */
}
}
/*******************************************************************************
*
* FUNCTION: AcpiTbGetRootTableEntry
*
* TableEntrySize - sizeof 32 or 64 (RSDT or XSDT)
*
* RETURN: Physical address extracted from the root table
*
* DESCRIPTION: Get one root table entry. Handles 32-bit and 64-bit cases on
* both 32-bit and 64-bit platforms
*
* NOTE: ACPI_PHYSICAL_ADDRESS is 32-bit on 32-bit platforms, 64-bit on
* 64-bit platforms.
*
******************************************************************************/
static ACPI_PHYSICAL_ADDRESS
{
/*
* Get the table physical address (32-bit for RSDT, 64-bit for XSDT):
* Note: Addresses are 32-bit aligned (not 64) in both RSDT and XSDT
*/
if (TableEntrySize == sizeof (UINT32))
{
/*
* 32-bit platform, RSDT: Return 32-bit table entry
* 64-bit platform, RSDT: Expand 32-bit to 64-bit and return
*/
}
else
{
/*
* 32-bit platform, XSDT: Truncate 64-bit to 32-bit and return
* 64-bit platform, XSDT: Move (unaligned) 64-bit to local,
* return 64-bit
*/
#if ACPI_MACHINE_WIDTH == 32
if (Address64 > ACPI_UINT32_MAX)
{
/* Will truncate 64-bit address to 32 bits, issue warning */
"64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
" truncating",
}
#endif
return ((ACPI_PHYSICAL_ADDRESS) (Address64));
}
}
/*******************************************************************************
*
* FUNCTION: AcpiTbParseRootTable
*
* PARAMETERS: Rsdp - Pointer to the RSDP
*
* RETURN: Status
*
* DESCRIPTION: This function is called to parse the Root System Description
* Table (RSDT or XSDT)
*
* NOTE: Tables are mapped (not copied) for efficiency. The FACS must
* be mapped and cannot be copied because it contains the actual
* memory location of the ACPI Global Lock.
*
******************************************************************************/
{
UINT32 i;
/*
* Map the entire RSDP and extract the address of the RSDT or XSDT
*/
if (!Rsdp)
{
}
/* Differentiate between RSDT and XSDT root tables */
{
/*
* Root table is an XSDT (64-bit physical addresses). We must use the
* XSDT if the revision is > 1 and the XSDT pointer is present, as per
* the ACPI specification.
*/
TableEntrySize = sizeof (UINT64);
}
else
{
/* Root table is an RSDT (32-bit physical addresses) */
TableEntrySize = sizeof (UINT32);
}
/*
* It is not possible to map more than one entry in some environments,
* so unmap the RSDP here before mapping other tables
*/
if (!Table)
{
}
/* Get the length of the full table, verify length and map entire table */
if (Length < sizeof (ACPI_TABLE_HEADER))
{
}
if (!Table)
{
}
/* Validate the root table checksum */
if (ACPI_FAILURE (Status))
{
}
/* Calculate the number of tables described in the root table */
/*
* First two entries in the table array are reserved for the DSDT
* come from the FADT
*/
/*
*/
for (i = 0; i < TableCount; i++)
{
{
/* There is no more room in the root table array, attempt resize */
if (ACPI_FAILURE (Status))
{
(unsigned) (TableCount -
break;
}
}
/* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
}
/*
* It is not possible to map more than one entry in some environments,
* so unmap the root table here before mapping other tables
*/
/*
* Complete the initialization of the root table array by examining
* the header of each table
*/
{
NULL, i);
/* Special case for FADT - get the DSDT and FACS */
if (ACPI_COMPARE_NAME (
{
AcpiTbParseFadt (i);
}
}
}