Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: tbinstal - ACPI table installation and removal
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("tbinstal")
0016 
0017 /*******************************************************************************
0018  *
0019  * FUNCTION:    acpi_tb_install_table_with_override
0020  *
0021  * PARAMETERS:  new_table_desc          - New table descriptor to install
0022  *              override                - Whether override should be performed
0023  *              table_index             - Where the table index is returned
0024  *
0025  * RETURN:      None
0026  *
0027  * DESCRIPTION: Install an ACPI table into the global data structure. The
0028  *              table override mechanism is called to allow the host
0029  *              OS to replace any table before it is installed in the root
0030  *              table array.
0031  *
0032  ******************************************************************************/
0033 void
0034 acpi_tb_install_table_with_override(struct acpi_table_desc *new_table_desc,
0035                     u8 override, u32 *table_index)
0036 {
0037     u32 i;
0038     acpi_status status;
0039 
0040     status = acpi_tb_get_next_table_descriptor(&i, NULL);
0041     if (ACPI_FAILURE(status)) {
0042         return;
0043     }
0044 
0045     /*
0046      * ACPI Table Override:
0047      *
0048      * Before we install the table, let the host OS override it with a new
0049      * one if desired. Any table within the RSDT/XSDT can be replaced,
0050      * including the DSDT which is pointed to by the FADT.
0051      */
0052     if (override) {
0053         acpi_tb_override_table(new_table_desc);
0054     }
0055 
0056     acpi_tb_init_table_descriptor(&acpi_gbl_root_table_list.tables[i],
0057                       new_table_desc->address,
0058                       new_table_desc->flags,
0059                       new_table_desc->pointer);
0060 
0061     acpi_tb_print_table_header(new_table_desc->address,
0062                    new_table_desc->pointer);
0063 
0064     /* This synchronizes acpi_gbl_dsdt_index */
0065 
0066     *table_index = i;
0067 
0068     /* Set the global integer width (based upon revision of the DSDT) */
0069 
0070     if (i == acpi_gbl_dsdt_index) {
0071         acpi_ut_set_integer_width(new_table_desc->pointer->revision);
0072     }
0073 }
0074 
0075 /*******************************************************************************
0076  *
0077  * FUNCTION:    acpi_tb_install_standard_table
0078  *
0079  * PARAMETERS:  address             - Address of the table (might be a virtual
0080  *                                    address depending on the table_flags)
0081  *              flags               - Flags for the table
0082  *              table               - Pointer to the table (required for virtual
0083  *                                    origins, optional for physical)
0084  *              reload              - Whether reload should be performed
0085  *              override            - Whether override should be performed
0086  *              table_index         - Where the table index is returned
0087  *
0088  * RETURN:      Status
0089  *
0090  * DESCRIPTION: This function is called to verify and install an ACPI table.
0091  *              When this function is called by "Load" or "LoadTable" opcodes,
0092  *              or by acpi_load_table() API, the "Reload" parameter is set.
0093  *              After successfully returning from this function, table is
0094  *              "INSTALLED" but not "VALIDATED".
0095  *
0096  ******************************************************************************/
0097 
0098 acpi_status
0099 acpi_tb_install_standard_table(acpi_physical_address address,
0100                    u8 flags,
0101                    struct acpi_table_header *table,
0102                    u8 reload, u8 override, u32 *table_index)
0103 {
0104     u32 i;
0105     acpi_status status = AE_OK;
0106     struct acpi_table_desc new_table_desc;
0107 
0108     ACPI_FUNCTION_TRACE(tb_install_standard_table);
0109 
0110     /* Acquire a temporary table descriptor for validation */
0111 
0112     status =
0113         acpi_tb_acquire_temp_table(&new_table_desc, address, flags, table);
0114     if (ACPI_FAILURE(status)) {
0115         ACPI_ERROR((AE_INFO,
0116                 "Could not acquire table length at %8.8X%8.8X",
0117                 ACPI_FORMAT_UINT64(address)));
0118         return_ACPI_STATUS(status);
0119     }
0120 
0121     /*
0122      * Optionally do not load any SSDTs from the RSDT/XSDT. This can
0123      * be useful for debugging ACPI problems on some machines.
0124      */
0125     if (!reload &&
0126         acpi_gbl_disable_ssdt_table_install &&
0127         ACPI_COMPARE_NAMESEG(&new_table_desc.signature, ACPI_SIG_SSDT)) {
0128         ACPI_INFO(("Ignoring installation of %4.4s at %8.8X%8.8X",
0129                new_table_desc.signature.ascii,
0130                ACPI_FORMAT_UINT64(address)));
0131         goto release_and_exit;
0132     }
0133 
0134     /* Acquire the table lock */
0135 
0136     (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
0137 
0138     /* Validate and verify a table before installation */
0139 
0140     status = acpi_tb_verify_temp_table(&new_table_desc, NULL, &i);
0141     if (ACPI_FAILURE(status)) {
0142         if (status == AE_CTRL_TERMINATE) {
0143             /*
0144              * Table was unloaded, allow it to be reloaded.
0145              * As we are going to return AE_OK to the caller, we should
0146              * take the responsibility of freeing the input descriptor.
0147              * Refill the input descriptor to ensure
0148              * acpi_tb_install_table_with_override() can be called again to
0149              * indicate the re-installation.
0150              */
0151             acpi_tb_uninstall_table(&new_table_desc);
0152             (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
0153             *table_index = i;
0154             return_ACPI_STATUS(AE_OK);
0155         }
0156         goto unlock_and_exit;
0157     }
0158 
0159     /* Add the table to the global root table list */
0160 
0161     acpi_tb_install_table_with_override(&new_table_desc, override,
0162                         table_index);
0163 
0164     /* Invoke table handler */
0165 
0166     (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
0167     acpi_tb_notify_table(ACPI_TABLE_EVENT_INSTALL, new_table_desc.pointer);
0168     (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
0169 
0170 unlock_and_exit:
0171 
0172     /* Release the table lock */
0173 
0174     (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
0175 
0176 release_and_exit:
0177 
0178     /* Release the temporary table descriptor */
0179 
0180     acpi_tb_release_temp_table(&new_table_desc);
0181     return_ACPI_STATUS(status);
0182 }
0183 
0184 /*******************************************************************************
0185  *
0186  * FUNCTION:    acpi_tb_override_table
0187  *
0188  * PARAMETERS:  old_table_desc      - Validated table descriptor to be
0189  *                                    overridden
0190  *
0191  * RETURN:      None
0192  *
0193  * DESCRIPTION: Attempt table override by calling the OSL override functions.
0194  *              Note: If the table is overridden, then the entire new table
0195  *              is acquired and returned by this function.
0196  *              Before/after invocation, the table descriptor is in a state
0197  *              that is "VALIDATED".
0198  *
0199  ******************************************************************************/
0200 
0201 void acpi_tb_override_table(struct acpi_table_desc *old_table_desc)
0202 {
0203     acpi_status status;
0204     struct acpi_table_desc new_table_desc;
0205     struct acpi_table_header *table;
0206     acpi_physical_address address;
0207     u32 length;
0208     ACPI_ERROR_ONLY(char *override_type);
0209 
0210     /* (1) Attempt logical override (returns a logical address) */
0211 
0212     status = acpi_os_table_override(old_table_desc->pointer, &table);
0213     if (ACPI_SUCCESS(status) && table) {
0214         acpi_tb_acquire_temp_table(&new_table_desc,
0215                        ACPI_PTR_TO_PHYSADDR(table),
0216                        ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL,
0217                        table);
0218         ACPI_ERROR_ONLY(override_type = "Logical");
0219         goto finish_override;
0220     }
0221 
0222     /* (2) Attempt physical override (returns a physical address) */
0223 
0224     status = acpi_os_physical_table_override(old_table_desc->pointer,
0225                          &address, &length);
0226     if (ACPI_SUCCESS(status) && address && length) {
0227         acpi_tb_acquire_temp_table(&new_table_desc, address,
0228                        ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
0229                        NULL);
0230         ACPI_ERROR_ONLY(override_type = "Physical");
0231         goto finish_override;
0232     }
0233 
0234     return;         /* There was no override */
0235 
0236 finish_override:
0237 
0238     /*
0239      * Validate and verify a table before overriding, no nested table
0240      * duplication check as it's too complicated and unnecessary.
0241      */
0242     status = acpi_tb_verify_temp_table(&new_table_desc, NULL, NULL);
0243     if (ACPI_FAILURE(status)) {
0244         return;
0245     }
0246 
0247     ACPI_INFO(("%4.4s 0x%8.8X%8.8X"
0248            " %s table override, new table: 0x%8.8X%8.8X",
0249            old_table_desc->signature.ascii,
0250            ACPI_FORMAT_UINT64(old_table_desc->address),
0251            override_type, ACPI_FORMAT_UINT64(new_table_desc.address)));
0252 
0253     /* We can now uninstall the original table */
0254 
0255     acpi_tb_uninstall_table(old_table_desc);
0256 
0257     /*
0258      * Replace the original table descriptor and keep its state as
0259      * "VALIDATED".
0260      */
0261     acpi_tb_init_table_descriptor(old_table_desc, new_table_desc.address,
0262                       new_table_desc.flags,
0263                       new_table_desc.pointer);
0264     acpi_tb_validate_temp_table(old_table_desc);
0265 
0266     /* Release the temporary table descriptor */
0267 
0268     acpi_tb_release_temp_table(&new_table_desc);
0269 }
0270 
0271 /*******************************************************************************
0272  *
0273  * FUNCTION:    acpi_tb_uninstall_table
0274  *
0275  * PARAMETERS:  table_desc          - Table descriptor
0276  *
0277  * RETURN:      None
0278  *
0279  * DESCRIPTION: Delete one internal ACPI table
0280  *
0281  ******************************************************************************/
0282 
0283 void acpi_tb_uninstall_table(struct acpi_table_desc *table_desc)
0284 {
0285 
0286     ACPI_FUNCTION_TRACE(tb_uninstall_table);
0287 
0288     /* Table must be installed */
0289 
0290     if (!table_desc->address) {
0291         return_VOID;
0292     }
0293 
0294     acpi_tb_invalidate_table(table_desc);
0295 
0296     if ((table_desc->flags & ACPI_TABLE_ORIGIN_MASK) ==
0297         ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL) {
0298         ACPI_FREE(table_desc->pointer);
0299         table_desc->pointer = NULL;
0300     }
0301 
0302     table_desc->address = ACPI_PTR_TO_PHYSADDR(NULL);
0303     return_VOID;
0304 }