Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: tbfind   - find table
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "actables.h"
0013 
0014 #define _COMPONENT          ACPI_TABLES
0015 ACPI_MODULE_NAME("tbfind")
0016 
0017 /*******************************************************************************
0018  *
0019  * FUNCTION:    acpi_tb_find_table
0020  *
0021  * PARAMETERS:  signature           - String with ACPI table signature
0022  *              oem_id              - String with the table OEM ID
0023  *              oem_table_id        - String with the OEM Table ID
0024  *              table_index         - Where the table index is returned
0025  *
0026  * RETURN:      Status and table index
0027  *
0028  * DESCRIPTION: Find an ACPI table (in the RSDT/XSDT) that matches the
0029  *              Signature, OEM ID and OEM Table ID. Returns an index that can
0030  *              be used to get the table header or entire table.
0031  *
0032  ******************************************************************************/
0033 acpi_status
0034 acpi_tb_find_table(char *signature,
0035            char *oem_id, char *oem_table_id, u32 *table_index)
0036 {
0037     acpi_status status = AE_OK;
0038     struct acpi_table_header header;
0039     u32 i;
0040 
0041     ACPI_FUNCTION_TRACE(tb_find_table);
0042 
0043     /* Validate the input table signature */
0044 
0045     if (!acpi_ut_valid_nameseg(signature)) {
0046         return_ACPI_STATUS(AE_BAD_SIGNATURE);
0047     }
0048 
0049     /* Don't allow the OEM strings to be too long */
0050 
0051     if ((strlen(oem_id) > ACPI_OEM_ID_SIZE) ||
0052         (strlen(oem_table_id) > ACPI_OEM_TABLE_ID_SIZE)) {
0053         return_ACPI_STATUS(AE_AML_STRING_LIMIT);
0054     }
0055 
0056     /* Normalize the input strings */
0057 
0058     memset(&header, 0, sizeof(struct acpi_table_header));
0059     ACPI_COPY_NAMESEG(header.signature, signature);
0060     strncpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
0061     strncpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
0062 
0063     /* Search for the table */
0064 
0065     (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
0066     for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
0067         if (memcmp(&(acpi_gbl_root_table_list.tables[i].signature),
0068                header.signature, ACPI_NAMESEG_SIZE)) {
0069 
0070             /* Not the requested table */
0071 
0072             continue;
0073         }
0074 
0075         /* Table with matching signature has been found */
0076 
0077         if (!acpi_gbl_root_table_list.tables[i].pointer) {
0078 
0079             /* Table is not currently mapped, map it */
0080 
0081             status =
0082                 acpi_tb_validate_table(&acpi_gbl_root_table_list.
0083                            tables[i]);
0084             if (ACPI_FAILURE(status)) {
0085                 goto unlock_and_exit;
0086             }
0087 
0088             if (!acpi_gbl_root_table_list.tables[i].pointer) {
0089                 continue;
0090             }
0091         }
0092 
0093         /* Check for table match on all IDs */
0094 
0095         if (!memcmp
0096             (acpi_gbl_root_table_list.tables[i].pointer->signature,
0097              header.signature, ACPI_NAMESEG_SIZE) && (!oem_id[0]
0098                                   ||
0099                                   !memcmp
0100                                   (acpi_gbl_root_table_list.
0101                                    tables[i].
0102                                    pointer->oem_id,
0103                                    header.oem_id,
0104                                    ACPI_OEM_ID_SIZE))
0105             && (!oem_table_id[0]
0106             || !memcmp(acpi_gbl_root_table_list.tables[i].pointer->
0107                    oem_table_id, header.oem_table_id,
0108                    ACPI_OEM_TABLE_ID_SIZE))) {
0109             *table_index = i;
0110 
0111             ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
0112                       "Found table [%4.4s]\n",
0113                       header.signature));
0114             goto unlock_and_exit;
0115         }
0116     }
0117     status = AE_NOT_FOUND;
0118 
0119 unlock_and_exit:
0120     (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
0121     return_ACPI_STATUS(status);
0122 }