2005-04-16 18:20:36 -04:00
/******************************************************************************
*
* Module Name : tbutils - Table manipulation utilities
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Copyright ( C ) 2000 - 2005 , R . Byron Moore
* 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/acpi.h>
# include <acpi/actables.h>
# define _COMPONENT ACPI_TABLES
2005-08-05 00:44:28 -04:00
ACPI_MODULE_NAME ( " tbutils " )
2005-04-16 18:20:36 -04:00
2005-04-18 22:49:35 -04:00
/* Local prototypes */
# ifdef ACPI_OBSOLETE_FUNCTIONS
2005-04-16 18:20:36 -04:00
acpi_status
2005-08-05 00:44:28 -04:00
acpi_tb_handle_to_object ( u16 table_id , struct acpi_table_desc * * table_desc ) ;
2005-04-18 22:49:35 -04:00
# endif
2005-04-16 18:20:36 -04:00
2005-07-29 18:15:00 -04:00
/*******************************************************************************
*
* FUNCTION : acpi_tb_is_table_installed
*
* PARAMETERS : new_table_desc - Descriptor for new table being installed
*
* RETURN : Status - AE_ALREADY_EXISTS if the table is already installed
*
* DESCRIPTION : Determine if an ACPI table is already installed
*
* MUTEX : Table data structures should be locked
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-08-05 00:44:28 -04:00
acpi_status acpi_tb_is_table_installed ( struct acpi_table_desc * new_table_desc )
2005-07-29 18:15:00 -04:00
{
2005-08-05 00:44:28 -04:00
struct acpi_table_desc * table_desc ;
2005-07-29 18:15:00 -04:00
2005-08-05 00:44:28 -04:00
ACPI_FUNCTION_TRACE ( " tb_is_table_installed " ) ;
2005-07-29 18:15:00 -04:00
/* Get the list descriptor and first table descriptor */
table_desc = acpi_gbl_table_lists [ new_table_desc - > type ] . next ;
/* Examine all installed tables of this type */
while ( table_desc ) {
2005-08-15 07:42:00 -04:00
/*
* If the table lengths match , perform a full bytewise compare . This
* means that we will allow tables with duplicate oem_table_id ( s ) , as
* long as the tables are different in some way .
*
* Checking if the table has been loaded into the namespace means that
* we don ' t check for duplicate tables during the initial installation
* of tables within the RSDT / XSDT .
*/
2005-07-29 18:15:00 -04:00
if ( ( table_desc - > loaded_into_namespace ) & &
2005-08-15 07:42:00 -04:00
( table_desc - > pointer - > length = =
new_table_desc - > pointer - > length )
& &
( ! ACPI_MEMCMP
2005-10-21 00:00:00 -04:00
( table_desc - > pointer , new_table_desc - > pointer ,
new_table_desc - > pointer - > length ) ) ) {
2005-08-15 07:42:00 -04:00
/* Match: this table is already installed */
2005-07-29 18:15:00 -04:00
2005-08-05 00:44:28 -04:00
ACPI_DEBUG_PRINT ( ( ACPI_DB_TABLES ,
" Table [%4.4s] already installed: Rev %X oem_table_id [%8.8s] \n " ,
new_table_desc - > pointer - > signature ,
new_table_desc - > pointer - > revision ,
new_table_desc - > pointer - >
oem_table_id ) ) ;
2005-07-29 18:15:00 -04:00
2005-08-05 00:44:28 -04:00
new_table_desc - > owner_id = table_desc - > owner_id ;
2005-07-29 18:15:00 -04:00
new_table_desc - > installed_desc = table_desc ;
2005-08-05 00:44:28 -04:00
return_ACPI_STATUS ( AE_ALREADY_EXISTS ) ;
2005-07-29 18:15:00 -04:00
}
/* Get next table on the list */
table_desc = table_desc - > next ;
}
2005-08-05 00:44:28 -04:00
return_ACPI_STATUS ( AE_OK ) ;
2005-07-29 18:15:00 -04:00
}
2005-04-16 18:20:36 -04:00
/*******************************************************************************
*
* FUNCTION : acpi_tb_validate_table_header
*
* PARAMETERS : table_header - Logical pointer to the table
*
* RETURN : Status
*
* DESCRIPTION : Check an ACPI table header for validity
*
* NOTE : Table pointers are validated as follows :
* 1 ) Table pointer must point to valid physical memory
* 2 ) Signature must be 4 ASCII chars , even if we don ' t recognize the
* name
* 3 ) Table must be readable for length specified in the header
* 4 ) Table checksum must be valid ( with the exception of the FACS
* which has no checksum because it contains variable fields )
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
acpi_status
2005-08-05 00:44:28 -04:00
acpi_tb_validate_table_header ( struct acpi_table_header * table_header )
2005-04-16 18:20:36 -04:00
{
2005-08-05 00:44:28 -04:00
acpi_name signature ;
2005-04-16 18:20:36 -04:00
2005-08-05 00:44:28 -04:00
ACPI_FUNCTION_NAME ( " tb_validate_table_header " ) ;
2005-04-16 18:20:36 -04:00
/* Verify that this is a valid address */
2005-08-05 00:44:28 -04:00
if ( ! acpi_os_readable ( table_header , sizeof ( struct acpi_table_header ) ) ) {
ACPI_DEBUG_PRINT ( ( ACPI_DB_ERROR ,
" Cannot read table header at %p \n " ,
table_header ) ) ;
2005-04-18 22:49:35 -04:00
2005-04-16 18:20:36 -04:00
return ( AE_BAD_ADDRESS ) ;
}
/* Ensure that the signature is 4 ASCII characters */
2005-08-05 00:44:28 -04:00
ACPI_MOVE_32_TO_32 ( & signature , table_header - > signature ) ;
if ( ! acpi_ut_valid_acpi_name ( signature ) ) {
ACPI_DEBUG_PRINT ( ( ACPI_DB_ERROR ,
" Table signature at %p [%p] has invalid characters \n " ,
table_header , & signature ) ) ;
2005-04-16 18:20:36 -04:00
2005-08-05 00:44:28 -04:00
ACPI_REPORT_WARNING ( ( " Invalid table signature found: [%4.4s] \n " ,
( char * ) & signature ) ) ;
2005-04-18 22:49:35 -04:00
2005-08-05 00:44:28 -04:00
ACPI_DUMP_BUFFER ( table_header ,
sizeof ( struct acpi_table_header ) ) ;
2005-04-16 18:20:36 -04:00
return ( AE_BAD_SIGNATURE ) ;
}
/* Validate the table length */
2005-08-05 00:44:28 -04:00
if ( table_header - > length < sizeof ( struct acpi_table_header ) ) {
ACPI_DEBUG_PRINT ( ( ACPI_DB_ERROR ,
" Invalid length in table header %p name %4.4s \n " ,
table_header , ( char * ) & signature ) ) ;
2005-04-16 18:20:36 -04:00
2005-08-05 00:44:28 -04:00
ACPI_REPORT_WARNING ( ( " Invalid table header length (0x%X) found \n " , ( u32 ) table_header - > length ) ) ;
2005-04-18 22:49:35 -04:00
2005-08-05 00:44:28 -04:00
ACPI_DUMP_BUFFER ( table_header ,
sizeof ( struct acpi_table_header ) ) ;
2005-04-16 18:20:36 -04:00
return ( AE_BAD_HEADER ) ;
}
return ( AE_OK ) ;
}
/*******************************************************************************
*
* FUNCTION : acpi_tb_verify_table_checksum
*
* PARAMETERS : * table_header - ACPI table to verify
*
* RETURN : 8 bit checksum of table
*
* DESCRIPTION : Does an 8 bit checksum of table and returns status . A correct
* table should have a checksum of 0.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
acpi_status
2005-08-05 00:44:28 -04:00
acpi_tb_verify_table_checksum ( struct acpi_table_header * table_header )
2005-04-16 18:20:36 -04:00
{
2005-08-05 00:44:28 -04:00
u8 checksum ;
acpi_status status = AE_OK ;
2005-04-16 18:20:36 -04:00
2005-08-05 00:44:28 -04:00
ACPI_FUNCTION_TRACE ( " tb_verify_table_checksum " ) ;
2005-04-16 18:20:36 -04:00
/* Compute the checksum on the table */
2005-08-05 00:44:28 -04:00
checksum =
acpi_tb_generate_checksum ( table_header , table_header - > length ) ;
2005-04-16 18:20:36 -04:00
/* Return the appropriate exception */
if ( checksum ) {
2005-08-05 00:44:28 -04:00
ACPI_REPORT_WARNING ( ( " Invalid checksum in table [%4.4s] (%02X, sum %02X is not zero) \n " , table_header - > signature , ( u32 ) table_header - > checksum , ( u32 ) checksum ) ) ;
2005-04-16 18:20:36 -04:00
status = AE_BAD_CHECKSUM ;
}
2005-08-05 00:44:28 -04:00
return_ACPI_STATUS ( status ) ;
2005-04-16 18:20:36 -04:00
}
/*******************************************************************************
*
2005-07-29 18:15:00 -04:00
* FUNCTION : acpi_tb_generate_checksum
2005-04-16 18:20:36 -04:00
*
* PARAMETERS : Buffer - Buffer to checksum
* Length - Size of the buffer
*
2005-04-18 22:49:35 -04:00
* RETURN : 8 bit checksum of buffer
2005-04-16 18:20:36 -04:00
*
* DESCRIPTION : Computes an 8 bit checksum of the buffer ( length ) and returns it .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-08-05 00:44:28 -04:00
u8 acpi_tb_generate_checksum ( void * buffer , u32 length )
2005-04-16 18:20:36 -04:00
{
2005-11-17 13:07:00 -05:00
u8 * end_buffer ;
u8 * rover ;
2005-08-05 00:44:28 -04:00
u8 sum = 0 ;
2005-04-16 18:20:36 -04:00
if ( buffer & & length ) {
/* Buffer and Length are valid */
2005-11-17 13:07:00 -05:00
end_buffer = ACPI_ADD_PTR ( u8 , buffer , length ) ;
2005-04-16 18:20:36 -04:00
2005-11-17 13:07:00 -05:00
for ( rover = buffer ; rover < end_buffer ; rover + + ) {
2005-04-16 18:20:36 -04:00
sum = ( u8 ) ( sum + * rover ) ;
}
}
return ( sum ) ;
}
2005-04-18 22:49:35 -04:00
# ifdef ACPI_OBSOLETE_FUNCTIONS
/*******************************************************************************
*
* FUNCTION : acpi_tb_handle_to_object
*
* PARAMETERS : table_id - Id for which the function is searching
* table_desc - Pointer to return the matching table
* descriptor .
*
* RETURN : Search the tables to find one with a matching table_id and
* return a pointer to that table descriptor .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
acpi_status
2005-08-05 00:44:28 -04:00
acpi_tb_handle_to_object ( u16 table_id ,
struct acpi_table_desc * * return_table_desc )
2005-04-18 22:49:35 -04:00
{
2005-08-05 00:44:28 -04:00
u32 i ;
struct acpi_table_desc * table_desc ;
2005-04-18 22:49:35 -04:00
2005-08-05 00:44:28 -04:00
ACPI_FUNCTION_NAME ( " tb_handle_to_object " ) ;
2005-04-18 22:49:35 -04:00
for ( i = 0 ; i < ACPI_TABLE_MAX ; i + + ) {
table_desc = acpi_gbl_table_lists [ i ] . next ;
while ( table_desc ) {
if ( table_desc - > table_id = = table_id ) {
* return_table_desc = table_desc ;
return ( AE_OK ) ;
}
table_desc = table_desc - > next ;
}
}
2005-08-05 00:44:28 -04:00
ACPI_DEBUG_PRINT ( ( ACPI_DB_ERROR , " table_id=%X does not exist \n " ,
table_id ) ) ;
2005-04-18 22:49:35 -04:00
return ( AE_BAD_PARAMETER ) ;
}
# endif