1 /******************************************************************************
3 * Module Name: tbinstal - ACPI table installation and removal
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2018, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
48 #define _COMPONENT ACPI_TABLES
49 ACPI_MODULE_NAME ("tbinstal")
52 /*******************************************************************************
54 * FUNCTION: AcpiTbInstallTableWithOverride
56 * PARAMETERS: NewTableDesc - New table descriptor to install
57 * Override - Whether override should be performed
58 * TableIndex - Where the table index is returned
62 * DESCRIPTION: Install an ACPI table into the global data structure. The
63 * table override mechanism is called to allow the host
64 * OS to replace any table before it is installed in the root
67 ******************************************************************************/
70 AcpiTbInstallTableWithOverride (
71 ACPI_TABLE_DESC
*NewTableDesc
,
79 Status
= AcpiTbGetNextTableDescriptor (&i
, NULL
);
80 if (ACPI_FAILURE (Status
))
86 * ACPI Table Override:
88 * Before we install the table, let the host OS override it with a new
89 * one if desired. Any table within the RSDT/XSDT can be replaced,
90 * including the DSDT which is pointed to by the FADT.
94 AcpiTbOverrideTable (NewTableDesc
);
97 AcpiTbInitTableDescriptor (&AcpiGbl_RootTableList
.Tables
[i
],
98 NewTableDesc
->Address
, NewTableDesc
->Flags
, NewTableDesc
->Pointer
);
100 AcpiTbPrintTableHeader (NewTableDesc
->Address
, NewTableDesc
->Pointer
);
102 /* This synchronizes AcpiGbl_DsdtIndex */
106 /* Set the global integer width (based upon revision of the DSDT) */
108 if (i
== AcpiGbl_DsdtIndex
)
110 AcpiUtSetIntegerWidth (NewTableDesc
->Pointer
->Revision
);
115 /*******************************************************************************
117 * FUNCTION: AcpiTbInstallStandardTable
119 * PARAMETERS: Address - Address of the table (might be a virtual
120 * address depending on the TableFlags)
121 * Flags - Flags for the table
122 * Reload - Whether reload should be performed
123 * Override - Whether override should be performed
124 * TableIndex - Where the table index is returned
128 * DESCRIPTION: This function is called to verify and install an ACPI table.
129 * When this function is called by "Load" or "LoadTable" opcodes,
130 * or by AcpiLoadTable() API, the "Reload" parameter is set.
131 * After successfully returning from this function, table is
132 * "INSTALLED" but not "VALIDATED".
134 ******************************************************************************/
137 AcpiTbInstallStandardTable (
138 ACPI_PHYSICAL_ADDRESS Address
,
145 ACPI_STATUS Status
= AE_OK
;
146 ACPI_TABLE_DESC NewTableDesc
;
149 ACPI_FUNCTION_TRACE (TbInstallStandardTable
);
152 /* Acquire a temporary table descriptor for validation */
154 Status
= AcpiTbAcquireTempTable (&NewTableDesc
, Address
, Flags
);
155 if (ACPI_FAILURE (Status
))
157 ACPI_ERROR ((AE_INFO
,
158 "Could not acquire table length at %8.8X%8.8X",
159 ACPI_FORMAT_UINT64 (Address
)));
160 return_ACPI_STATUS (Status
);
164 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
165 * be useful for debugging ACPI problems on some machines.
168 AcpiGbl_DisableSsdtTableInstall
&&
169 ACPI_COMPARE_NAME (&NewTableDesc
.Signature
, ACPI_SIG_SSDT
))
172 "Ignoring installation of %4.4s at %8.8X%8.8X",
173 NewTableDesc
.Signature
.Ascii
, ACPI_FORMAT_UINT64 (Address
)));
177 /* Acquire the table lock */
179 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
181 /* Validate and verify a table before installation */
183 Status
= AcpiTbVerifyTempTable (&NewTableDesc
, NULL
, &i
);
184 if (ACPI_FAILURE (Status
))
186 if (Status
== AE_CTRL_TERMINATE
)
189 * Table was unloaded, allow it to be reloaded.
190 * As we are going to return AE_OK to the caller, we should
191 * take the responsibility of freeing the input descriptor.
192 * Refill the input descriptor to ensure
193 * AcpiTbInstallTableWithOverride() can be called again to
194 * indicate the re-installation.
196 AcpiTbUninstallTable (&NewTableDesc
);
197 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
199 return_ACPI_STATUS (AE_OK
);
204 /* Add the table to the global root table list */
206 AcpiTbInstallTableWithOverride (&NewTableDesc
, Override
, TableIndex
);
208 /* Invoke table handler */
210 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
211 AcpiTbNotifyTable (ACPI_TABLE_EVENT_INSTALL
, NewTableDesc
.Pointer
);
212 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
216 /* Release the table lock */
218 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
222 /* Release the temporary table descriptor */
224 AcpiTbReleaseTempTable (&NewTableDesc
);
225 return_ACPI_STATUS (Status
);
229 /*******************************************************************************
231 * FUNCTION: AcpiTbOverrideTable
233 * PARAMETERS: OldTableDesc - Validated table descriptor to be
238 * DESCRIPTION: Attempt table override by calling the OSL override functions.
239 * Note: If the table is overridden, then the entire new table
240 * is acquired and returned by this function.
241 * Before/after invocation, the table descriptor is in a state
242 * that is "VALIDATED".
244 ******************************************************************************/
247 AcpiTbOverrideTable (
248 ACPI_TABLE_DESC
*OldTableDesc
)
251 ACPI_TABLE_DESC NewTableDesc
;
252 ACPI_TABLE_HEADER
*Table
;
253 ACPI_PHYSICAL_ADDRESS Address
;
255 ACPI_ERROR_ONLY (char *OverrideType
);
258 /* (1) Attempt logical override (returns a logical address) */
260 Status
= AcpiOsTableOverride (OldTableDesc
->Pointer
, &Table
);
261 if (ACPI_SUCCESS (Status
) && Table
)
263 AcpiTbAcquireTempTable (&NewTableDesc
, ACPI_PTR_TO_PHYSADDR (Table
),
264 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
);
265 ACPI_ERROR_ONLY (OverrideType
= "Logical");
269 /* (2) Attempt physical override (returns a physical address) */
271 Status
= AcpiOsPhysicalTableOverride (OldTableDesc
->Pointer
,
273 if (ACPI_SUCCESS (Status
) && Address
&& Length
)
275 AcpiTbAcquireTempTable (&NewTableDesc
, Address
,
276 ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
);
277 ACPI_ERROR_ONLY (OverrideType
= "Physical");
281 return; /* There was no override */
287 * Validate and verify a table before overriding, no nested table
288 * duplication check as it's too complicated and unnecessary.
290 Status
= AcpiTbVerifyTempTable (&NewTableDesc
, NULL
, NULL
);
291 if (ACPI_FAILURE (Status
))
296 ACPI_INFO (("%4.4s 0x%8.8X%8.8X"
297 " %s table override, new table: 0x%8.8X%8.8X",
298 OldTableDesc
->Signature
.Ascii
,
299 ACPI_FORMAT_UINT64 (OldTableDesc
->Address
),
300 OverrideType
, ACPI_FORMAT_UINT64 (NewTableDesc
.Address
)));
302 /* We can now uninstall the original table */
304 AcpiTbUninstallTable (OldTableDesc
);
307 * Replace the original table descriptor and keep its state as
310 AcpiTbInitTableDescriptor (OldTableDesc
, NewTableDesc
.Address
,
311 NewTableDesc
.Flags
, NewTableDesc
.Pointer
);
312 AcpiTbValidateTempTable (OldTableDesc
);
314 /* Release the temporary table descriptor */
316 AcpiTbReleaseTempTable (&NewTableDesc
);
320 /*******************************************************************************
322 * FUNCTION: AcpiTbUninstallTable
324 * PARAMETERS: TableDesc - Table descriptor
328 * DESCRIPTION: Delete one internal ACPI table
330 ******************************************************************************/
333 AcpiTbUninstallTable (
334 ACPI_TABLE_DESC
*TableDesc
)
337 ACPI_FUNCTION_TRACE (TbUninstallTable
);
340 /* Table must be installed */
342 if (!TableDesc
->Address
)
347 AcpiTbInvalidateTable (TableDesc
);
349 if ((TableDesc
->Flags
& ACPI_TABLE_ORIGIN_MASK
) ==
350 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL
)
352 ACPI_FREE (ACPI_PHYSADDR_TO_PTR (TableDesc
->Address
));
355 TableDesc
->Address
= ACPI_PTR_TO_PHYSADDR (NULL
);