1 1.1 christos /****************************************************************************** 2 1.1 christos * 3 1.1 christos * Module Name: tbdata - Table manager data structure functions 4 1.1 christos * 5 1.1 christos *****************************************************************************/ 6 1.1 christos 7 1.21 christos /****************************************************************************** 8 1.21 christos * 9 1.21 christos * 1. Copyright Notice 10 1.21 christos * 11 1.22 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp. 12 1.1 christos * All rights reserved. 13 1.1 christos * 14 1.21 christos * 2. License 15 1.21 christos * 16 1.21 christos * 2.1. This is your license from Intel Corp. under its intellectual property 17 1.21 christos * rights. You may have additional license terms from the party that provided 18 1.21 christos * you this software, covering your right to use that party's intellectual 19 1.21 christos * property rights. 20 1.21 christos * 21 1.21 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 1.21 christos * copy of the source code appearing in this file ("Covered Code") an 23 1.21 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 1.21 christos * base code distributed originally by Intel ("Original Intel Code") to copy, 25 1.21 christos * make derivatives, distribute, use and display any portion of the Covered 26 1.21 christos * Code in any form, with the right to sublicense such rights; and 27 1.21 christos * 28 1.21 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 1.21 christos * license (with the right to sublicense), under only those claims of Intel 30 1.21 christos * patents that are infringed by the Original Intel Code, to make, use, sell, 31 1.21 christos * offer to sell, and import the Covered Code and derivative works thereof 32 1.21 christos * solely to the minimum extent necessary to exercise the above copyright 33 1.21 christos * license, and in no event shall the patent license extend to any additions 34 1.21 christos * to or modifications of the Original Intel Code. No other license or right 35 1.21 christos * is granted directly or by implication, estoppel or otherwise; 36 1.21 christos * 37 1.21 christos * The above copyright and patent license is granted only if the following 38 1.21 christos * conditions are met: 39 1.21 christos * 40 1.21 christos * 3. Conditions 41 1.21 christos * 42 1.21 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 1.21 christos * Redistribution of source code of any substantial portion of the Covered 44 1.21 christos * Code or modification with rights to further distribute source must include 45 1.21 christos * the above Copyright Notice, the above License, this list of Conditions, 46 1.21 christos * and the following Disclaimer and Export Compliance provision. In addition, 47 1.21 christos * Licensee must cause all Covered Code to which Licensee contributes to 48 1.21 christos * contain a file documenting the changes Licensee made to create that Covered 49 1.21 christos * Code and the date of any change. Licensee must include in that file the 50 1.21 christos * documentation of any changes made by any predecessor Licensee. Licensee 51 1.21 christos * must include a prominent statement that the modification is derived, 52 1.21 christos * directly or indirectly, from Original Intel Code. 53 1.21 christos * 54 1.21 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 1.21 christos * Redistribution of source code of any substantial portion of the Covered 56 1.21 christos * Code or modification without rights to further distribute source must 57 1.21 christos * include the following Disclaimer and Export Compliance provision in the 58 1.21 christos * documentation and/or other materials provided with distribution. In 59 1.21 christos * addition, Licensee may not authorize further sublicense of source of any 60 1.21 christos * portion of the Covered Code, and must include terms to the effect that the 61 1.21 christos * license from Licensee to its licensee is limited to the intellectual 62 1.21 christos * property embodied in the software Licensee provides to its licensee, and 63 1.21 christos * not to intellectual property embodied in modifications its licensee may 64 1.21 christos * make. 65 1.21 christos * 66 1.21 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 1.21 christos * substantial portion of the Covered Code or modification must reproduce the 68 1.21 christos * above Copyright Notice, and the following Disclaimer and Export Compliance 69 1.21 christos * provision in the documentation and/or other materials provided with the 70 1.21 christos * distribution. 71 1.21 christos * 72 1.21 christos * 3.4. Intel retains all right, title, and interest in and to the Original 73 1.21 christos * Intel Code. 74 1.21 christos * 75 1.21 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 1.21 christos * Intel shall be used in advertising or otherwise to promote the sale, use or 77 1.21 christos * other dealings in products derived from or relating to the Covered Code 78 1.21 christos * without prior written authorization from Intel. 79 1.21 christos * 80 1.21 christos * 4. Disclaimer and Export Compliance 81 1.21 christos * 82 1.21 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 1.21 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 1.21 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 1.21 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 1.21 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 1.21 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 1.21 christos * PARTICULAR PURPOSE. 89 1.21 christos * 90 1.21 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 1.21 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 1.21 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 1.21 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 1.21 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 1.21 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 1.21 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 1.21 christos * LIMITED REMEDY. 98 1.21 christos * 99 1.21 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 1.21 christos * software or system incorporating such software without first obtaining any 101 1.21 christos * required license or other approval from the U. S. Department of Commerce or 102 1.21 christos * any other agency or department of the United States Government. In the 103 1.21 christos * event Licensee exports any such software from the United States or 104 1.21 christos * re-exports any such software from a foreign destination, Licensee shall 105 1.21 christos * ensure that the distribution and export/re-export of the software is in 106 1.21 christos * compliance with all laws, regulations, orders, or other restrictions of the 107 1.21 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 1.21 christos * any of its subsidiaries will export/re-export any technical data, process, 109 1.21 christos * software, or service, directly or indirectly, to any country for which the 110 1.21 christos * United States government or any agency thereof requires an export license, 111 1.21 christos * other governmental approval, or letter of assurance, without first obtaining 112 1.21 christos * such license, approval or letter. 113 1.21 christos * 114 1.21 christos ***************************************************************************** 115 1.21 christos * 116 1.21 christos * Alternatively, you may choose to be licensed under the terms of the 117 1.21 christos * following license: 118 1.21 christos * 119 1.1 christos * Redistribution and use in source and binary forms, with or without 120 1.1 christos * modification, are permitted provided that the following conditions 121 1.1 christos * are met: 122 1.1 christos * 1. Redistributions of source code must retain the above copyright 123 1.1 christos * notice, this list of conditions, and the following disclaimer, 124 1.1 christos * without modification. 125 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below 127 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon 128 1.1 christos * including a substantially similar Disclaimer requirement for further 129 1.1 christos * binary redistribution. 130 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names 131 1.1 christos * of any contributors may be used to endorse or promote products derived 132 1.1 christos * from this software without specific prior written permission. 133 1.1 christos * 134 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 1.16 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 1.21 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 1.21 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 1.21 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 1.21 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 1.21 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 1.21 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 1.21 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 1.21 christos * 146 1.21 christos * Alternatively, you may choose to be licensed under the terms of the 147 1.21 christos * GNU General Public License ("GPL") version 2 as published by the Free 148 1.21 christos * Software Foundation. 149 1.21 christos * 150 1.21 christos *****************************************************************************/ 151 1.1 christos 152 1.1 christos #include "acpi.h" 153 1.1 christos #include "accommon.h" 154 1.1 christos #include "acnamesp.h" 155 1.1 christos #include "actables.h" 156 1.7 christos #include "acevents.h" 157 1.1 christos 158 1.1 christos #define _COMPONENT ACPI_TABLES 159 1.1 christos ACPI_MODULE_NAME ("tbdata") 160 1.1 christos 161 1.9 christos /* Local prototypes */ 162 1.9 christos 163 1.9 christos static ACPI_STATUS 164 1.9 christos AcpiTbCheckDuplication ( 165 1.9 christos ACPI_TABLE_DESC *TableDesc, 166 1.9 christos UINT32 *TableIndex); 167 1.9 christos 168 1.9 christos static BOOLEAN 169 1.9 christos AcpiTbCompareTables ( 170 1.9 christos ACPI_TABLE_DESC *TableDesc, 171 1.9 christos UINT32 TableIndex); 172 1.9 christos 173 1.9 christos 174 1.9 christos /******************************************************************************* 175 1.9 christos * 176 1.9 christos * FUNCTION: AcpiTbCompareTables 177 1.9 christos * 178 1.9 christos * PARAMETERS: TableDesc - Table 1 descriptor to be compared 179 1.9 christos * TableIndex - Index of table 2 to be compared 180 1.9 christos * 181 1.9 christos * RETURN: TRUE if both tables are identical. 182 1.9 christos * 183 1.9 christos * DESCRIPTION: This function compares a table with another table that has 184 1.9 christos * already been installed in the root table list. 185 1.9 christos * 186 1.9 christos ******************************************************************************/ 187 1.9 christos 188 1.9 christos static BOOLEAN 189 1.9 christos AcpiTbCompareTables ( 190 1.9 christos ACPI_TABLE_DESC *TableDesc, 191 1.9 christos UINT32 TableIndex) 192 1.9 christos { 193 1.9 christos ACPI_STATUS Status = AE_OK; 194 1.9 christos BOOLEAN IsIdentical; 195 1.9 christos ACPI_TABLE_HEADER *Table; 196 1.9 christos UINT32 TableLength; 197 1.9 christos UINT8 TableFlags; 198 1.9 christos 199 1.9 christos 200 1.9 christos Status = AcpiTbAcquireTable (&AcpiGbl_RootTableList.Tables[TableIndex], 201 1.9 christos &Table, &TableLength, &TableFlags); 202 1.9 christos if (ACPI_FAILURE (Status)) 203 1.9 christos { 204 1.9 christos return (FALSE); 205 1.9 christos } 206 1.9 christos 207 1.9 christos /* 208 1.9 christos * Check for a table match on the entire table length, 209 1.9 christos * not just the header. 210 1.9 christos */ 211 1.9 christos IsIdentical = (BOOLEAN)((TableDesc->Length != TableLength || 212 1.9 christos memcmp (TableDesc->Pointer, Table, TableLength)) ? 213 1.9 christos FALSE : TRUE); 214 1.9 christos 215 1.9 christos /* Release the acquired table */ 216 1.9 christos 217 1.9 christos AcpiTbReleaseTable (Table, TableLength, TableFlags); 218 1.9 christos return (IsIdentical); 219 1.9 christos } 220 1.9 christos 221 1.1 christos 222 1.1 christos /******************************************************************************* 223 1.1 christos * 224 1.1 christos * FUNCTION: AcpiTbInitTableDescriptor 225 1.1 christos * 226 1.1 christos * PARAMETERS: TableDesc - Table descriptor 227 1.1 christos * Address - Physical address of the table 228 1.1 christos * Flags - Allocation flags of the table 229 1.1 christos * Table - Pointer to the table 230 1.1 christos * 231 1.1 christos * RETURN: None 232 1.1 christos * 233 1.1 christos * DESCRIPTION: Initialize a new table descriptor 234 1.1 christos * 235 1.1 christos ******************************************************************************/ 236 1.1 christos 237 1.1 christos void 238 1.1 christos AcpiTbInitTableDescriptor ( 239 1.1 christos ACPI_TABLE_DESC *TableDesc, 240 1.1 christos ACPI_PHYSICAL_ADDRESS Address, 241 1.1 christos UINT8 Flags, 242 1.1 christos ACPI_TABLE_HEADER *Table) 243 1.1 christos { 244 1.1 christos 245 1.1 christos /* 246 1.17 christos * Initialize the table descriptor. Set the pointer to NULL for external 247 1.17 christos * tables, since the table is not fully mapped at this time. 248 1.1 christos */ 249 1.4 christos memset (TableDesc, 0, sizeof (ACPI_TABLE_DESC)); 250 1.1 christos TableDesc->Address = Address; 251 1.1 christos TableDesc->Length = Table->Length; 252 1.1 christos TableDesc->Flags = Flags; 253 1.1 christos ACPI_MOVE_32_TO_32 (TableDesc->Signature.Ascii, Table->Signature); 254 1.17 christos 255 1.17 christos switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK) 256 1.17 christos { 257 1.17 christos case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: 258 1.17 christos case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: 259 1.17 christos 260 1.17 christos TableDesc->Pointer = Table; 261 1.17 christos break; 262 1.17 christos 263 1.17 christos case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: 264 1.17 christos default: 265 1.17 christos 266 1.17 christos break; 267 1.17 christos } 268 1.1 christos } 269 1.1 christos 270 1.1 christos 271 1.1 christos /******************************************************************************* 272 1.1 christos * 273 1.1 christos * FUNCTION: AcpiTbAcquireTable 274 1.1 christos * 275 1.1 christos * PARAMETERS: TableDesc - Table descriptor 276 1.1 christos * TablePtr - Where table is returned 277 1.1 christos * TableLength - Where table length is returned 278 1.1 christos * TableFlags - Where table allocation flags are returned 279 1.1 christos * 280 1.1 christos * RETURN: Status 281 1.1 christos * 282 1.1 christos * DESCRIPTION: Acquire an ACPI table. It can be used for tables not 283 1.1 christos * maintained in the AcpiGbl_RootTableList. 284 1.1 christos * 285 1.1 christos ******************************************************************************/ 286 1.1 christos 287 1.1 christos ACPI_STATUS 288 1.1 christos AcpiTbAcquireTable ( 289 1.1 christos ACPI_TABLE_DESC *TableDesc, 290 1.1 christos ACPI_TABLE_HEADER **TablePtr, 291 1.1 christos UINT32 *TableLength, 292 1.1 christos UINT8 *TableFlags) 293 1.1 christos { 294 1.1 christos ACPI_TABLE_HEADER *Table = NULL; 295 1.1 christos 296 1.1 christos 297 1.1 christos switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK) 298 1.1 christos { 299 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: 300 1.1 christos 301 1.1 christos Table = AcpiOsMapMemory (TableDesc->Address, TableDesc->Length); 302 1.1 christos break; 303 1.1 christos 304 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: 305 1.1 christos case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: 306 1.1 christos 307 1.17 christos Table = TableDesc->Pointer; 308 1.1 christos break; 309 1.1 christos 310 1.1 christos default: 311 1.1 christos 312 1.1 christos break; 313 1.1 christos } 314 1.1 christos 315 1.1 christos /* Table is not valid yet */ 316 1.1 christos 317 1.1 christos if (!Table) 318 1.1 christos { 319 1.1 christos return (AE_NO_MEMORY); 320 1.1 christos } 321 1.1 christos 322 1.1 christos /* Fill the return values */ 323 1.1 christos 324 1.1 christos *TablePtr = Table; 325 1.1 christos *TableLength = TableDesc->Length; 326 1.1 christos *TableFlags = TableDesc->Flags; 327 1.1 christos return (AE_OK); 328 1.1 christos } 329 1.1 christos 330 1.1 christos 331 1.1 christos /******************************************************************************* 332 1.1 christos * 333 1.1 christos * FUNCTION: AcpiTbReleaseTable 334 1.1 christos * 335 1.1 christos * PARAMETERS: Table - Pointer for the table 336 1.1 christos * TableLength - Length for the table 337 1.1 christos * TableFlags - Allocation flags for the table 338 1.1 christos * 339 1.1 christos * RETURN: None 340 1.1 christos * 341 1.1 christos * DESCRIPTION: Release a table. The inverse of AcpiTbAcquireTable(). 342 1.1 christos * 343 1.1 christos ******************************************************************************/ 344 1.1 christos 345 1.1 christos void 346 1.1 christos AcpiTbReleaseTable ( 347 1.1 christos ACPI_TABLE_HEADER *Table, 348 1.1 christos UINT32 TableLength, 349 1.1 christos UINT8 TableFlags) 350 1.1 christos { 351 1.1 christos 352 1.1 christos switch (TableFlags & ACPI_TABLE_ORIGIN_MASK) 353 1.1 christos { 354 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: 355 1.1 christos 356 1.1 christos AcpiOsUnmapMemory (Table, TableLength); 357 1.1 christos break; 358 1.1 christos 359 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: 360 1.1 christos case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: 361 1.1 christos default: 362 1.1 christos 363 1.1 christos break; 364 1.1 christos } 365 1.1 christos } 366 1.1 christos 367 1.1 christos 368 1.1 christos /******************************************************************************* 369 1.1 christos * 370 1.1 christos * FUNCTION: AcpiTbAcquireTempTable 371 1.1 christos * 372 1.1 christos * PARAMETERS: TableDesc - Table descriptor to be acquired 373 1.1 christos * Address - Address of the table 374 1.1 christos * Flags - Allocation flags of the table 375 1.17 christos * Table - Pointer to the table (required for virtual 376 1.17 christos * origins, optional for physical) 377 1.1 christos * 378 1.1 christos * RETURN: Status 379 1.1 christos * 380 1.1 christos * DESCRIPTION: This function validates the table header to obtain the length 381 1.1 christos * of a table and fills the table descriptor to make its state as 382 1.1 christos * "INSTALLED". Such a table descriptor is only used for verified 383 1.1 christos * installation. 384 1.1 christos * 385 1.1 christos ******************************************************************************/ 386 1.1 christos 387 1.1 christos ACPI_STATUS 388 1.1 christos AcpiTbAcquireTempTable ( 389 1.1 christos ACPI_TABLE_DESC *TableDesc, 390 1.1 christos ACPI_PHYSICAL_ADDRESS Address, 391 1.17 christos UINT8 Flags, 392 1.17 christos ACPI_TABLE_HEADER *Table) 393 1.1 christos { 394 1.17 christos BOOLEAN MappedTable = FALSE; 395 1.1 christos 396 1.1 christos 397 1.1 christos switch (Flags & ACPI_TABLE_ORIGIN_MASK) 398 1.1 christos { 399 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: 400 1.1 christos 401 1.1 christos /* Get the length of the full table from the header */ 402 1.1 christos 403 1.17 christos if (!Table) 404 1.1 christos { 405 1.17 christos Table = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER)); 406 1.17 christos if (!Table) 407 1.17 christos { 408 1.17 christos return (AE_NO_MEMORY); 409 1.17 christos } 410 1.17 christos 411 1.17 christos MappedTable = TRUE; 412 1.1 christos } 413 1.1 christos 414 1.17 christos break; 415 1.1 christos 416 1.1 christos case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: 417 1.1 christos case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: 418 1.1 christos 419 1.17 christos if (!Table) 420 1.1 christos { 421 1.17 christos return (AE_BAD_PARAMETER); 422 1.1 christos } 423 1.1 christos 424 1.17 christos break; 425 1.1 christos 426 1.1 christos default: 427 1.1 christos 428 1.17 christos /* Table is not valid yet */ 429 1.17 christos 430 1.17 christos return (AE_NO_MEMORY); 431 1.1 christos } 432 1.1 christos 433 1.17 christos AcpiTbInitTableDescriptor (TableDesc, Address, Flags, Table); 434 1.17 christos if (MappedTable) 435 1.17 christos { 436 1.17 christos AcpiOsUnmapMemory (Table, sizeof (ACPI_TABLE_HEADER)); 437 1.17 christos } 438 1.1 christos 439 1.17 christos return (AE_OK); 440 1.1 christos } 441 1.1 christos 442 1.1 christos 443 1.1 christos /******************************************************************************* 444 1.1 christos * 445 1.1 christos * FUNCTION: AcpiTbReleaseTempTable 446 1.1 christos * 447 1.1 christos * PARAMETERS: TableDesc - Table descriptor to be released 448 1.1 christos * 449 1.1 christos * RETURN: Status 450 1.1 christos * 451 1.1 christos * DESCRIPTION: The inverse of AcpiTbAcquireTempTable(). 452 1.1 christos * 453 1.1 christos *****************************************************************************/ 454 1.1 christos 455 1.1 christos void 456 1.1 christos AcpiTbReleaseTempTable ( 457 1.1 christos ACPI_TABLE_DESC *TableDesc) 458 1.1 christos { 459 1.1 christos 460 1.1 christos /* 461 1.1 christos * Note that the .Address is maintained by the callers of 462 1.1 christos * AcpiTbAcquireTempTable(), thus do not invoke AcpiTbUninstallTable() 463 1.1 christos * where .Address will be freed. 464 1.1 christos */ 465 1.1 christos AcpiTbInvalidateTable (TableDesc); 466 1.1 christos } 467 1.1 christos 468 1.1 christos 469 1.1 christos /****************************************************************************** 470 1.1 christos * 471 1.1 christos * FUNCTION: AcpiTbValidateTable 472 1.1 christos * 473 1.1 christos * PARAMETERS: TableDesc - Table descriptor 474 1.1 christos * 475 1.1 christos * RETURN: Status 476 1.1 christos * 477 1.1 christos * DESCRIPTION: This function is called to validate the table, the returned 478 1.1 christos * table descriptor is in "VALIDATED" state. 479 1.1 christos * 480 1.1 christos *****************************************************************************/ 481 1.1 christos 482 1.1 christos ACPI_STATUS 483 1.1 christos AcpiTbValidateTable ( 484 1.1 christos ACPI_TABLE_DESC *TableDesc) 485 1.1 christos { 486 1.1 christos ACPI_STATUS Status = AE_OK; 487 1.1 christos 488 1.1 christos 489 1.1 christos ACPI_FUNCTION_TRACE (TbValidateTable); 490 1.1 christos 491 1.1 christos 492 1.1 christos /* Validate the table if necessary */ 493 1.1 christos 494 1.1 christos if (!TableDesc->Pointer) 495 1.1 christos { 496 1.1 christos Status = AcpiTbAcquireTable (TableDesc, &TableDesc->Pointer, 497 1.5 christos &TableDesc->Length, &TableDesc->Flags); 498 1.1 christos if (!TableDesc->Pointer) 499 1.1 christos { 500 1.1 christos Status = AE_NO_MEMORY; 501 1.1 christos } 502 1.1 christos } 503 1.1 christos 504 1.1 christos return_ACPI_STATUS (Status); 505 1.1 christos } 506 1.1 christos 507 1.1 christos 508 1.1 christos /******************************************************************************* 509 1.1 christos * 510 1.1 christos * FUNCTION: AcpiTbInvalidateTable 511 1.1 christos * 512 1.1 christos * PARAMETERS: TableDesc - Table descriptor 513 1.1 christos * 514 1.1 christos * RETURN: None 515 1.1 christos * 516 1.1 christos * DESCRIPTION: Invalidate one internal ACPI table, this is the inverse of 517 1.1 christos * AcpiTbValidateTable(). 518 1.1 christos * 519 1.1 christos ******************************************************************************/ 520 1.1 christos 521 1.1 christos void 522 1.1 christos AcpiTbInvalidateTable ( 523 1.1 christos ACPI_TABLE_DESC *TableDesc) 524 1.1 christos { 525 1.1 christos 526 1.1 christos ACPI_FUNCTION_TRACE (TbInvalidateTable); 527 1.1 christos 528 1.1 christos 529 1.1 christos /* Table must be validated */ 530 1.1 christos 531 1.1 christos if (!TableDesc->Pointer) 532 1.1 christos { 533 1.1 christos return_VOID; 534 1.1 christos } 535 1.1 christos 536 1.1 christos AcpiTbReleaseTable (TableDesc->Pointer, TableDesc->Length, 537 1.1 christos TableDesc->Flags); 538 1.17 christos 539 1.17 christos switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK) 540 1.17 christos { 541 1.17 christos case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL: 542 1.17 christos 543 1.17 christos TableDesc->Pointer = NULL; 544 1.17 christos break; 545 1.17 christos 546 1.17 christos case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL: 547 1.17 christos case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL: 548 1.17 christos default: 549 1.17 christos 550 1.17 christos break; 551 1.17 christos } 552 1.1 christos 553 1.1 christos return_VOID; 554 1.1 christos } 555 1.1 christos 556 1.1 christos 557 1.1 christos /****************************************************************************** 558 1.1 christos * 559 1.1 christos * FUNCTION: AcpiTbValidateTempTable 560 1.1 christos * 561 1.1 christos * PARAMETERS: TableDesc - Table descriptor 562 1.1 christos * 563 1.1 christos * RETURN: Status 564 1.1 christos * 565 1.1 christos * DESCRIPTION: This function is called to validate the table, the returned 566 1.1 christos * table descriptor is in "VALIDATED" state. 567 1.1 christos * 568 1.1 christos *****************************************************************************/ 569 1.1 christos 570 1.1 christos ACPI_STATUS 571 1.1 christos AcpiTbValidateTempTable ( 572 1.1 christos ACPI_TABLE_DESC *TableDesc) 573 1.1 christos { 574 1.1 christos 575 1.9 christos if (!TableDesc->Pointer && !AcpiGbl_EnableTableValidation) 576 1.1 christos { 577 1.1 christos /* 578 1.1 christos * Only validates the header of the table. 579 1.1 christos * Note that Length contains the size of the mapping after invoking 580 1.1 christos * this work around, this value is required by 581 1.1 christos * AcpiTbReleaseTempTable(). 582 1.1 christos * We can do this because in AcpiInitTableDescriptor(), the Length 583 1.1 christos * field of the installed descriptor is filled with the actual 584 1.1 christos * table length obtaining from the table header. 585 1.1 christos */ 586 1.1 christos TableDesc->Length = sizeof (ACPI_TABLE_HEADER); 587 1.1 christos } 588 1.1 christos 589 1.1 christos return (AcpiTbValidateTable (TableDesc)); 590 1.1 christos } 591 1.1 christos 592 1.1 christos 593 1.9 christos /******************************************************************************* 594 1.9 christos * 595 1.9 christos * FUNCTION: AcpiTbCheckDuplication 596 1.9 christos * 597 1.9 christos * PARAMETERS: TableDesc - Table descriptor 598 1.9 christos * TableIndex - Where the table index is returned 599 1.9 christos * 600 1.9 christos * RETURN: Status 601 1.9 christos * 602 1.9 christos * DESCRIPTION: Avoid installing duplicated tables. However table override and 603 1.9 christos * user aided dynamic table load is allowed, thus comparing the 604 1.9 christos * address of the table is not sufficient, and checking the entire 605 1.9 christos * table content is required. 606 1.9 christos * 607 1.9 christos ******************************************************************************/ 608 1.9 christos 609 1.9 christos static ACPI_STATUS 610 1.9 christos AcpiTbCheckDuplication ( 611 1.9 christos ACPI_TABLE_DESC *TableDesc, 612 1.9 christos UINT32 *TableIndex) 613 1.9 christos { 614 1.9 christos UINT32 i; 615 1.9 christos 616 1.9 christos 617 1.9 christos ACPI_FUNCTION_TRACE (TbCheckDuplication); 618 1.9 christos 619 1.9 christos 620 1.9 christos /* Check if table is already registered */ 621 1.9 christos 622 1.9 christos for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i) 623 1.9 christos { 624 1.9 christos /* Do not compare with unverified tables */ 625 1.9 christos 626 1.9 christos if (!(AcpiGbl_RootTableList.Tables[i].Flags & ACPI_TABLE_IS_VERIFIED)) 627 1.9 christos { 628 1.9 christos continue; 629 1.9 christos } 630 1.9 christos 631 1.9 christos /* 632 1.9 christos * Check for a table match on the entire table length, 633 1.9 christos * not just the header. 634 1.9 christos */ 635 1.9 christos if (!AcpiTbCompareTables (TableDesc, i)) 636 1.9 christos { 637 1.9 christos continue; 638 1.9 christos } 639 1.9 christos 640 1.9 christos /* 641 1.9 christos * Note: the current mechanism does not unregister a table if it is 642 1.9 christos * dynamically unloaded. The related namespace entries are deleted, 643 1.9 christos * but the table remains in the root table list. 644 1.9 christos * 645 1.9 christos * The assumption here is that the number of different tables that 646 1.9 christos * will be loaded is actually small, and there is minimal overhead 647 1.9 christos * in just keeping the table in case it is needed again. 648 1.9 christos * 649 1.9 christos * If this assumption changes in the future (perhaps on large 650 1.9 christos * machines with many table load/unload operations), tables will 651 1.9 christos * need to be unregistered when they are unloaded, and slots in the 652 1.9 christos * root table list should be reused when empty. 653 1.9 christos */ 654 1.9 christos if (AcpiGbl_RootTableList.Tables[i].Flags & 655 1.9 christos ACPI_TABLE_IS_LOADED) 656 1.9 christos { 657 1.9 christos /* Table is still loaded, this is an error */ 658 1.9 christos 659 1.9 christos return_ACPI_STATUS (AE_ALREADY_EXISTS); 660 1.9 christos } 661 1.9 christos else 662 1.9 christos { 663 1.9 christos *TableIndex = i; 664 1.9 christos return_ACPI_STATUS (AE_CTRL_TERMINATE); 665 1.9 christos } 666 1.9 christos } 667 1.9 christos 668 1.9 christos /* Indicate no duplication to the caller */ 669 1.9 christos 670 1.9 christos return_ACPI_STATUS (AE_OK); 671 1.9 christos } 672 1.9 christos 673 1.9 christos 674 1.1 christos /****************************************************************************** 675 1.1 christos * 676 1.1 christos * FUNCTION: AcpiTbVerifyTempTable 677 1.1 christos * 678 1.1 christos * PARAMETERS: TableDesc - Table descriptor 679 1.1 christos * Signature - Table signature to verify 680 1.9 christos * TableIndex - Where the table index is returned 681 1.1 christos * 682 1.1 christos * RETURN: Status 683 1.1 christos * 684 1.1 christos * DESCRIPTION: This function is called to validate and verify the table, the 685 1.1 christos * returned table descriptor is in "VALIDATED" state. 686 1.9 christos * Note that 'TableIndex' is required to be set to !NULL to 687 1.9 christos * enable duplication check. 688 1.1 christos * 689 1.1 christos *****************************************************************************/ 690 1.1 christos 691 1.1 christos ACPI_STATUS 692 1.1 christos AcpiTbVerifyTempTable ( 693 1.1 christos ACPI_TABLE_DESC *TableDesc, 694 1.9 christos const char *Signature, 695 1.9 christos UINT32 *TableIndex) 696 1.1 christos { 697 1.1 christos ACPI_STATUS Status = AE_OK; 698 1.1 christos 699 1.1 christos 700 1.1 christos ACPI_FUNCTION_TRACE (TbVerifyTempTable); 701 1.1 christos 702 1.1 christos 703 1.1 christos /* Validate the table */ 704 1.1 christos 705 1.1 christos Status = AcpiTbValidateTempTable (TableDesc); 706 1.1 christos if (ACPI_FAILURE (Status)) 707 1.1 christos { 708 1.1 christos return_ACPI_STATUS (AE_NO_MEMORY); 709 1.1 christos } 710 1.1 christos 711 1.1 christos /* If a particular signature is expected (DSDT/FACS), it must match */ 712 1.1 christos 713 1.1 christos if (Signature && 714 1.12 christos !ACPI_COMPARE_NAMESEG (&TableDesc->Signature, Signature)) 715 1.1 christos { 716 1.1 christos ACPI_BIOS_ERROR ((AE_INFO, 717 1.1 christos "Invalid signature 0x%X for ACPI table, expected [%s]", 718 1.1 christos TableDesc->Signature.Integer, Signature)); 719 1.1 christos Status = AE_BAD_SIGNATURE; 720 1.1 christos goto InvalidateAndExit; 721 1.1 christos } 722 1.1 christos 723 1.9 christos if (AcpiGbl_EnableTableValidation) 724 1.9 christos { 725 1.9 christos /* Verify the checksum */ 726 1.1 christos 727 1.19 christos Status = AcpiUtVerifyChecksum (TableDesc->Pointer, TableDesc->Length); 728 1.1 christos if (ACPI_FAILURE (Status)) 729 1.1 christos { 730 1.1 christos ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY, 731 1.3 christos "%4.4s 0x%8.8X%8.8X" 732 1.1 christos " Attempted table install failed", 733 1.6 christos AcpiUtValidNameseg (TableDesc->Signature.Ascii) ? 734 1.1 christos TableDesc->Signature.Ascii : "????", 735 1.3 christos ACPI_FORMAT_UINT64 (TableDesc->Address))); 736 1.5 christos 737 1.1 christos goto InvalidateAndExit; 738 1.1 christos } 739 1.9 christos 740 1.9 christos /* Avoid duplications */ 741 1.9 christos 742 1.9 christos if (TableIndex) 743 1.9 christos { 744 1.9 christos Status = AcpiTbCheckDuplication (TableDesc, TableIndex); 745 1.9 christos if (ACPI_FAILURE (Status)) 746 1.9 christos { 747 1.9 christos if (Status != AE_CTRL_TERMINATE) 748 1.9 christos { 749 1.11 christos ACPI_EXCEPTION ((AE_INFO, Status, 750 1.9 christos "%4.4s 0x%8.8X%8.8X" 751 1.11 christos " Table is already loaded", 752 1.9 christos AcpiUtValidNameseg (TableDesc->Signature.Ascii) ? 753 1.9 christos TableDesc->Signature.Ascii : "????", 754 1.9 christos ACPI_FORMAT_UINT64 (TableDesc->Address))); 755 1.9 christos } 756 1.9 christos 757 1.9 christos goto InvalidateAndExit; 758 1.9 christos } 759 1.9 christos } 760 1.9 christos 761 1.9 christos TableDesc->Flags |= ACPI_TABLE_IS_VERIFIED; 762 1.1 christos } 763 1.1 christos 764 1.9 christos return_ACPI_STATUS (Status); 765 1.1 christos 766 1.1 christos InvalidateAndExit: 767 1.1 christos AcpiTbInvalidateTable (TableDesc); 768 1.1 christos return_ACPI_STATUS (Status); 769 1.1 christos } 770 1.1 christos 771 1.1 christos 772 1.1 christos /******************************************************************************* 773 1.1 christos * 774 1.1 christos * FUNCTION: AcpiTbResizeRootTableList 775 1.1 christos * 776 1.1 christos * PARAMETERS: None 777 1.1 christos * 778 1.1 christos * RETURN: Status 779 1.1 christos * 780 1.1 christos * DESCRIPTION: Expand the size of global table array 781 1.1 christos * 782 1.1 christos ******************************************************************************/ 783 1.1 christos 784 1.1 christos ACPI_STATUS 785 1.1 christos AcpiTbResizeRootTableList ( 786 1.1 christos void) 787 1.1 christos { 788 1.1 christos ACPI_TABLE_DESC *Tables; 789 1.1 christos UINT32 TableCount; 790 1.9 christos UINT32 CurrentTableCount, MaxTableCount; 791 1.9 christos UINT32 i; 792 1.1 christos 793 1.1 christos 794 1.1 christos ACPI_FUNCTION_TRACE (TbResizeRootTableList); 795 1.1 christos 796 1.1 christos 797 1.1 christos /* AllowResize flag is a parameter to AcpiInitializeTables */ 798 1.1 christos 799 1.1 christos if (!(AcpiGbl_RootTableList.Flags & ACPI_ROOT_ALLOW_RESIZE)) 800 1.1 christos { 801 1.1 christos ACPI_ERROR ((AE_INFO, "Resize of Root Table Array is not allowed")); 802 1.1 christos return_ACPI_STATUS (AE_SUPPORT); 803 1.1 christos } 804 1.1 christos 805 1.1 christos /* Increase the Table Array size */ 806 1.1 christos 807 1.1 christos if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) 808 1.1 christos { 809 1.1 christos TableCount = AcpiGbl_RootTableList.MaxTableCount; 810 1.1 christos } 811 1.1 christos else 812 1.1 christos { 813 1.1 christos TableCount = AcpiGbl_RootTableList.CurrentTableCount; 814 1.1 christos } 815 1.1 christos 816 1.9 christos MaxTableCount = TableCount + ACPI_ROOT_TABLE_SIZE_INCREMENT; 817 1.1 christos Tables = ACPI_ALLOCATE_ZEROED ( 818 1.9 christos ((ACPI_SIZE) MaxTableCount) * sizeof (ACPI_TABLE_DESC)); 819 1.1 christos if (!Tables) 820 1.1 christos { 821 1.1 christos ACPI_ERROR ((AE_INFO, "Could not allocate new root table array")); 822 1.1 christos return_ACPI_STATUS (AE_NO_MEMORY); 823 1.1 christos } 824 1.1 christos 825 1.1 christos /* Copy and free the previous table array */ 826 1.1 christos 827 1.9 christos CurrentTableCount = 0; 828 1.1 christos if (AcpiGbl_RootTableList.Tables) 829 1.1 christos { 830 1.9 christos for (i = 0; i < TableCount; i++) 831 1.9 christos { 832 1.9 christos if (AcpiGbl_RootTableList.Tables[i].Address) 833 1.9 christos { 834 1.9 christos memcpy (Tables + CurrentTableCount, 835 1.9 christos AcpiGbl_RootTableList.Tables + i, 836 1.9 christos sizeof (ACPI_TABLE_DESC)); 837 1.9 christos CurrentTableCount++; 838 1.9 christos } 839 1.9 christos } 840 1.1 christos 841 1.1 christos if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) 842 1.1 christos { 843 1.1 christos ACPI_FREE (AcpiGbl_RootTableList.Tables); 844 1.1 christos } 845 1.1 christos } 846 1.1 christos 847 1.1 christos AcpiGbl_RootTableList.Tables = Tables; 848 1.9 christos AcpiGbl_RootTableList.MaxTableCount = MaxTableCount; 849 1.9 christos AcpiGbl_RootTableList.CurrentTableCount = CurrentTableCount; 850 1.1 christos AcpiGbl_RootTableList.Flags |= ACPI_ROOT_ORIGIN_ALLOCATED; 851 1.1 christos 852 1.1 christos return_ACPI_STATUS (AE_OK); 853 1.1 christos } 854 1.1 christos 855 1.1 christos 856 1.1 christos /******************************************************************************* 857 1.1 christos * 858 1.3 christos * FUNCTION: AcpiTbGetNextTableDescriptor 859 1.1 christos * 860 1.1 christos * PARAMETERS: TableIndex - Where table index is returned 861 1.3 christos * TableDesc - Where table descriptor is returned 862 1.1 christos * 863 1.3 christos * RETURN: Status and table index/descriptor. 864 1.1 christos * 865 1.1 christos * DESCRIPTION: Allocate a new ACPI table entry to the global table list 866 1.1 christos * 867 1.1 christos ******************************************************************************/ 868 1.1 christos 869 1.1 christos ACPI_STATUS 870 1.3 christos AcpiTbGetNextTableDescriptor ( 871 1.3 christos UINT32 *TableIndex, 872 1.3 christos ACPI_TABLE_DESC **TableDesc) 873 1.1 christos { 874 1.1 christos ACPI_STATUS Status; 875 1.3 christos UINT32 i; 876 1.1 christos 877 1.1 christos 878 1.1 christos /* Ensure that there is room for the table in the Root Table List */ 879 1.1 christos 880 1.1 christos if (AcpiGbl_RootTableList.CurrentTableCount >= 881 1.1 christos AcpiGbl_RootTableList.MaxTableCount) 882 1.1 christos { 883 1.1 christos Status = AcpiTbResizeRootTableList(); 884 1.1 christos if (ACPI_FAILURE (Status)) 885 1.1 christos { 886 1.1 christos return (Status); 887 1.1 christos } 888 1.1 christos } 889 1.1 christos 890 1.3 christos i = AcpiGbl_RootTableList.CurrentTableCount; 891 1.1 christos AcpiGbl_RootTableList.CurrentTableCount++; 892 1.3 christos 893 1.3 christos if (TableIndex) 894 1.3 christos { 895 1.3 christos *TableIndex = i; 896 1.3 christos } 897 1.3 christos if (TableDesc) 898 1.3 christos { 899 1.3 christos *TableDesc = &AcpiGbl_RootTableList.Tables[i]; 900 1.3 christos } 901 1.3 christos 902 1.1 christos return (AE_OK); 903 1.1 christos } 904 1.1 christos 905 1.1 christos 906 1.1 christos /******************************************************************************* 907 1.1 christos * 908 1.1 christos * FUNCTION: AcpiTbTerminate 909 1.1 christos * 910 1.1 christos * PARAMETERS: None 911 1.1 christos * 912 1.1 christos * RETURN: None 913 1.1 christos * 914 1.1 christos * DESCRIPTION: Delete all internal ACPI tables 915 1.1 christos * 916 1.1 christos ******************************************************************************/ 917 1.1 christos 918 1.1 christos void 919 1.1 christos AcpiTbTerminate ( 920 1.1 christos void) 921 1.1 christos { 922 1.1 christos UINT32 i; 923 1.1 christos 924 1.1 christos 925 1.1 christos ACPI_FUNCTION_TRACE (TbTerminate); 926 1.1 christos 927 1.1 christos 928 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 929 1.1 christos 930 1.1 christos /* Delete the individual tables */ 931 1.1 christos 932 1.1 christos for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++) 933 1.1 christos { 934 1.1 christos AcpiTbUninstallTable (&AcpiGbl_RootTableList.Tables[i]); 935 1.1 christos } 936 1.1 christos 937 1.1 christos /* 938 1.1 christos * Delete the root table array if allocated locally. Array cannot be 939 1.1 christos * mapped, so we don't need to check for that flag. 940 1.1 christos */ 941 1.1 christos if (AcpiGbl_RootTableList.Flags & ACPI_ROOT_ORIGIN_ALLOCATED) 942 1.1 christos { 943 1.1 christos ACPI_FREE (AcpiGbl_RootTableList.Tables); 944 1.1 christos } 945 1.1 christos 946 1.1 christos AcpiGbl_RootTableList.Tables = NULL; 947 1.1 christos AcpiGbl_RootTableList.Flags = 0; 948 1.1 christos AcpiGbl_RootTableList.CurrentTableCount = 0; 949 1.1 christos 950 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n")); 951 1.1 christos 952 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 953 1.1 christos return_VOID; 954 1.1 christos } 955 1.1 christos 956 1.1 christos 957 1.1 christos /******************************************************************************* 958 1.1 christos * 959 1.1 christos * FUNCTION: AcpiTbDeleteNamespaceByOwner 960 1.1 christos * 961 1.1 christos * PARAMETERS: TableIndex - Table index 962 1.1 christos * 963 1.1 christos * RETURN: Status 964 1.1 christos * 965 1.1 christos * DESCRIPTION: Delete all namespace objects created when this table was loaded. 966 1.1 christos * 967 1.1 christos ******************************************************************************/ 968 1.1 christos 969 1.1 christos ACPI_STATUS 970 1.1 christos AcpiTbDeleteNamespaceByOwner ( 971 1.1 christos UINT32 TableIndex) 972 1.1 christos { 973 1.1 christos ACPI_OWNER_ID OwnerId; 974 1.1 christos ACPI_STATUS Status; 975 1.1 christos 976 1.1 christos 977 1.1 christos ACPI_FUNCTION_TRACE (TbDeleteNamespaceByOwner); 978 1.1 christos 979 1.1 christos 980 1.1 christos Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES); 981 1.1 christos if (ACPI_FAILURE (Status)) 982 1.1 christos { 983 1.1 christos return_ACPI_STATUS (Status); 984 1.1 christos } 985 1.1 christos 986 1.1 christos if (TableIndex >= AcpiGbl_RootTableList.CurrentTableCount) 987 1.1 christos { 988 1.1 christos /* The table index does not exist */ 989 1.1 christos 990 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 991 1.1 christos return_ACPI_STATUS (AE_NOT_EXIST); 992 1.1 christos } 993 1.1 christos 994 1.1 christos /* Get the owner ID for this table, used to delete namespace nodes */ 995 1.1 christos 996 1.1 christos OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId; 997 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 998 1.1 christos 999 1.1 christos /* 1000 1.1 christos * Need to acquire the namespace writer lock to prevent interference 1001 1.1 christos * with any concurrent namespace walks. The interpreter must be 1002 1.1 christos * released during the deletion since the acquisition of the deletion 1003 1.1 christos * lock may block, and also since the execution of a namespace walk 1004 1.1 christos * must be allowed to use the interpreter. 1005 1.1 christos */ 1006 1.1 christos Status = AcpiUtAcquireWriteLock (&AcpiGbl_NamespaceRwLock); 1007 1.1 christos if (ACPI_FAILURE (Status)) 1008 1.1 christos { 1009 1.1 christos return_ACPI_STATUS (Status); 1010 1.1 christos } 1011 1.13 christos 1012 1.7 christos AcpiNsDeleteNamespaceByOwner (OwnerId); 1013 1.1 christos AcpiUtReleaseWriteLock (&AcpiGbl_NamespaceRwLock); 1014 1.1 christos return_ACPI_STATUS (Status); 1015 1.1 christos } 1016 1.1 christos 1017 1.1 christos 1018 1.1 christos /******************************************************************************* 1019 1.1 christos * 1020 1.1 christos * FUNCTION: AcpiTbAllocateOwnerId 1021 1.1 christos * 1022 1.1 christos * PARAMETERS: TableIndex - Table index 1023 1.1 christos * 1024 1.1 christos * RETURN: Status 1025 1.1 christos * 1026 1.1 christos * DESCRIPTION: Allocates OwnerId in TableDesc 1027 1.1 christos * 1028 1.1 christos ******************************************************************************/ 1029 1.1 christos 1030 1.1 christos ACPI_STATUS 1031 1.1 christos AcpiTbAllocateOwnerId ( 1032 1.1 christos UINT32 TableIndex) 1033 1.1 christos { 1034 1.1 christos ACPI_STATUS Status = AE_BAD_PARAMETER; 1035 1.1 christos 1036 1.1 christos 1037 1.1 christos ACPI_FUNCTION_TRACE (TbAllocateOwnerId); 1038 1.1 christos 1039 1.1 christos 1040 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 1041 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount) 1042 1.1 christos { 1043 1.1 christos Status = AcpiUtAllocateOwnerId ( 1044 1.5 christos &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId)); 1045 1.1 christos } 1046 1.1 christos 1047 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 1048 1.1 christos return_ACPI_STATUS (Status); 1049 1.1 christos } 1050 1.1 christos 1051 1.1 christos 1052 1.1 christos /******************************************************************************* 1053 1.1 christos * 1054 1.1 christos * FUNCTION: AcpiTbReleaseOwnerId 1055 1.1 christos * 1056 1.1 christos * PARAMETERS: TableIndex - Table index 1057 1.1 christos * 1058 1.1 christos * RETURN: Status 1059 1.1 christos * 1060 1.1 christos * DESCRIPTION: Releases OwnerId in TableDesc 1061 1.1 christos * 1062 1.1 christos ******************************************************************************/ 1063 1.1 christos 1064 1.1 christos ACPI_STATUS 1065 1.1 christos AcpiTbReleaseOwnerId ( 1066 1.1 christos UINT32 TableIndex) 1067 1.1 christos { 1068 1.1 christos ACPI_STATUS Status = AE_BAD_PARAMETER; 1069 1.1 christos 1070 1.1 christos 1071 1.1 christos ACPI_FUNCTION_TRACE (TbReleaseOwnerId); 1072 1.1 christos 1073 1.1 christos 1074 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 1075 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount) 1076 1.1 christos { 1077 1.1 christos AcpiUtReleaseOwnerId ( 1078 1.1 christos &(AcpiGbl_RootTableList.Tables[TableIndex].OwnerId)); 1079 1.1 christos Status = AE_OK; 1080 1.1 christos } 1081 1.1 christos 1082 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 1083 1.1 christos return_ACPI_STATUS (Status); 1084 1.1 christos } 1085 1.1 christos 1086 1.1 christos 1087 1.1 christos /******************************************************************************* 1088 1.1 christos * 1089 1.1 christos * FUNCTION: AcpiTbGetOwnerId 1090 1.1 christos * 1091 1.1 christos * PARAMETERS: TableIndex - Table index 1092 1.1 christos * OwnerId - Where the table OwnerId is returned 1093 1.1 christos * 1094 1.1 christos * RETURN: Status 1095 1.1 christos * 1096 1.1 christos * DESCRIPTION: returns OwnerId for the ACPI table 1097 1.1 christos * 1098 1.1 christos ******************************************************************************/ 1099 1.1 christos 1100 1.1 christos ACPI_STATUS 1101 1.1 christos AcpiTbGetOwnerId ( 1102 1.1 christos UINT32 TableIndex, 1103 1.1 christos ACPI_OWNER_ID *OwnerId) 1104 1.1 christos { 1105 1.1 christos ACPI_STATUS Status = AE_BAD_PARAMETER; 1106 1.1 christos 1107 1.1 christos 1108 1.1 christos ACPI_FUNCTION_TRACE (TbGetOwnerId); 1109 1.1 christos 1110 1.1 christos 1111 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 1112 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount) 1113 1.1 christos { 1114 1.1 christos *OwnerId = AcpiGbl_RootTableList.Tables[TableIndex].OwnerId; 1115 1.1 christos Status = AE_OK; 1116 1.1 christos } 1117 1.1 christos 1118 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 1119 1.1 christos return_ACPI_STATUS (Status); 1120 1.1 christos } 1121 1.1 christos 1122 1.1 christos 1123 1.1 christos /******************************************************************************* 1124 1.1 christos * 1125 1.1 christos * FUNCTION: AcpiTbIsTableLoaded 1126 1.1 christos * 1127 1.1 christos * PARAMETERS: TableIndex - Index into the root table 1128 1.1 christos * 1129 1.1 christos * RETURN: Table Loaded Flag 1130 1.1 christos * 1131 1.1 christos ******************************************************************************/ 1132 1.1 christos 1133 1.1 christos BOOLEAN 1134 1.1 christos AcpiTbIsTableLoaded ( 1135 1.1 christos UINT32 TableIndex) 1136 1.1 christos { 1137 1.1 christos BOOLEAN IsLoaded = FALSE; 1138 1.1 christos 1139 1.1 christos 1140 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 1141 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount) 1142 1.1 christos { 1143 1.1 christos IsLoaded = (BOOLEAN) 1144 1.1 christos (AcpiGbl_RootTableList.Tables[TableIndex].Flags & 1145 1.1 christos ACPI_TABLE_IS_LOADED); 1146 1.1 christos } 1147 1.1 christos 1148 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 1149 1.1 christos return (IsLoaded); 1150 1.1 christos } 1151 1.1 christos 1152 1.1 christos 1153 1.1 christos /******************************************************************************* 1154 1.1 christos * 1155 1.1 christos * FUNCTION: AcpiTbSetTableLoadedFlag 1156 1.1 christos * 1157 1.1 christos * PARAMETERS: TableIndex - Table index 1158 1.1 christos * IsLoaded - TRUE if table is loaded, FALSE otherwise 1159 1.1 christos * 1160 1.1 christos * RETURN: None 1161 1.1 christos * 1162 1.1 christos * DESCRIPTION: Sets the table loaded flag to either TRUE or FALSE. 1163 1.1 christos * 1164 1.1 christos ******************************************************************************/ 1165 1.1 christos 1166 1.1 christos void 1167 1.1 christos AcpiTbSetTableLoadedFlag ( 1168 1.1 christos UINT32 TableIndex, 1169 1.1 christos BOOLEAN IsLoaded) 1170 1.1 christos { 1171 1.1 christos 1172 1.1 christos (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES); 1173 1.1 christos if (TableIndex < AcpiGbl_RootTableList.CurrentTableCount) 1174 1.1 christos { 1175 1.1 christos if (IsLoaded) 1176 1.1 christos { 1177 1.1 christos AcpiGbl_RootTableList.Tables[TableIndex].Flags |= 1178 1.1 christos ACPI_TABLE_IS_LOADED; 1179 1.1 christos } 1180 1.1 christos else 1181 1.1 christos { 1182 1.1 christos AcpiGbl_RootTableList.Tables[TableIndex].Flags &= 1183 1.1 christos ~ACPI_TABLE_IS_LOADED; 1184 1.1 christos } 1185 1.1 christos } 1186 1.1 christos 1187 1.1 christos (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES); 1188 1.1 christos } 1189 1.7 christos 1190 1.7 christos 1191 1.7 christos /******************************************************************************* 1192 1.7 christos * 1193 1.7 christos * FUNCTION: AcpiTbLoadTable 1194 1.7 christos * 1195 1.7 christos * PARAMETERS: TableIndex - Table index 1196 1.7 christos * ParentNode - Where table index is returned 1197 1.7 christos * 1198 1.7 christos * RETURN: Status 1199 1.7 christos * 1200 1.7 christos * DESCRIPTION: Load an ACPI table 1201 1.7 christos * 1202 1.7 christos ******************************************************************************/ 1203 1.7 christos 1204 1.7 christos ACPI_STATUS 1205 1.7 christos AcpiTbLoadTable ( 1206 1.7 christos UINT32 TableIndex, 1207 1.7 christos ACPI_NAMESPACE_NODE *ParentNode) 1208 1.7 christos { 1209 1.7 christos ACPI_TABLE_HEADER *Table; 1210 1.7 christos ACPI_STATUS Status; 1211 1.7 christos ACPI_OWNER_ID OwnerId; 1212 1.7 christos 1213 1.7 christos 1214 1.7 christos ACPI_FUNCTION_TRACE (TbLoadTable); 1215 1.7 christos 1216 1.7 christos 1217 1.7 christos /* 1218 1.7 christos * Note: Now table is "INSTALLED", it must be validated before 1219 1.7 christos * using. 1220 1.7 christos */ 1221 1.7 christos Status = AcpiGetTableByIndex (TableIndex, &Table); 1222 1.7 christos if (ACPI_FAILURE (Status)) 1223 1.7 christos { 1224 1.7 christos return_ACPI_STATUS (Status); 1225 1.7 christos } 1226 1.7 christos 1227 1.7 christos Status = AcpiNsLoadTable (TableIndex, ParentNode); 1228 1.14 christos if (ACPI_FAILURE (Status)) 1229 1.14 christos { 1230 1.14 christos return_ACPI_STATUS (Status); 1231 1.14 christos } 1232 1.7 christos 1233 1.10 christos /* 1234 1.7 christos * Update GPEs for any new _Lxx/_Exx methods. Ignore errors. The host is 1235 1.7 christos * responsible for discovering any new wake GPEs by running _PRW methods 1236 1.7 christos * that may have been loaded by this table. 1237 1.7 christos */ 1238 1.7 christos Status = AcpiTbGetOwnerId (TableIndex, &OwnerId); 1239 1.7 christos if (ACPI_SUCCESS (Status)) 1240 1.7 christos { 1241 1.7 christos AcpiEvUpdateGpes (OwnerId); 1242 1.7 christos } 1243 1.7 christos 1244 1.9 christos /* Invoke table handler */ 1245 1.7 christos 1246 1.9 christos AcpiTbNotifyTable (ACPI_TABLE_EVENT_LOAD, Table); 1247 1.7 christos return_ACPI_STATUS (Status); 1248 1.7 christos } 1249 1.7 christos 1250 1.7 christos 1251 1.7 christos /******************************************************************************* 1252 1.7 christos * 1253 1.7 christos * FUNCTION: AcpiTbInstallAndLoadTable 1254 1.7 christos * 1255 1.8 christos * PARAMETERS: Address - Physical address of the table 1256 1.7 christos * Flags - Allocation flags of the table 1257 1.17 christos * Table - Pointer to the table (required for 1258 1.17 christos * virtual origins, optional for 1259 1.17 christos * physical) 1260 1.8 christos * Override - Whether override should be performed 1261 1.7 christos * TableIndex - Where table index is returned 1262 1.7 christos * 1263 1.7 christos * RETURN: Status 1264 1.7 christos * 1265 1.7 christos * DESCRIPTION: Install and load an ACPI table 1266 1.7 christos * 1267 1.7 christos ******************************************************************************/ 1268 1.7 christos 1269 1.7 christos ACPI_STATUS 1270 1.7 christos AcpiTbInstallAndLoadTable ( 1271 1.7 christos ACPI_PHYSICAL_ADDRESS Address, 1272 1.7 christos UINT8 Flags, 1273 1.17 christos ACPI_TABLE_HEADER *Table, 1274 1.7 christos BOOLEAN Override, 1275 1.7 christos UINT32 *TableIndex) 1276 1.7 christos { 1277 1.7 christos ACPI_STATUS Status; 1278 1.7 christos UINT32 i; 1279 1.7 christos 1280 1.7 christos 1281 1.8 christos ACPI_FUNCTION_TRACE (TbInstallAndLoadTable); 1282 1.7 christos 1283 1.7 christos 1284 1.7 christos /* Install the table and load it into the namespace */ 1285 1.7 christos 1286 1.17 christos Status = AcpiTbInstallStandardTable (Address, Flags, Table, TRUE, 1287 1.7 christos Override, &i); 1288 1.7 christos if (ACPI_FAILURE (Status)) 1289 1.7 christos { 1290 1.9 christos goto Exit; 1291 1.7 christos } 1292 1.7 christos 1293 1.8 christos Status = AcpiTbLoadTable (i, AcpiGbl_RootNode); 1294 1.7 christos 1295 1.9 christos Exit: 1296 1.8 christos *TableIndex = i; 1297 1.8 christos return_ACPI_STATUS (Status); 1298 1.8 christos } 1299 1.8 christos 1300 1.8 christos 1301 1.8 christos /******************************************************************************* 1302 1.8 christos * 1303 1.8 christos * FUNCTION: AcpiTbUnloadTable 1304 1.8 christos * 1305 1.8 christos * PARAMETERS: TableIndex - Table index 1306 1.8 christos * 1307 1.8 christos * RETURN: Status 1308 1.8 christos * 1309 1.8 christos * DESCRIPTION: Unload an ACPI table 1310 1.8 christos * 1311 1.8 christos ******************************************************************************/ 1312 1.7 christos 1313 1.8 christos ACPI_STATUS 1314 1.8 christos AcpiTbUnloadTable ( 1315 1.8 christos UINT32 TableIndex) 1316 1.8 christos { 1317 1.8 christos ACPI_STATUS Status = AE_OK; 1318 1.8 christos ACPI_TABLE_HEADER *Table; 1319 1.8 christos 1320 1.8 christos 1321 1.8 christos ACPI_FUNCTION_TRACE (TbUnloadTable); 1322 1.8 christos 1323 1.8 christos 1324 1.8 christos /* Ensure the table is still loaded */ 1325 1.7 christos 1326 1.8 christos if (!AcpiTbIsTableLoaded (TableIndex)) 1327 1.7 christos { 1328 1.8 christos return_ACPI_STATUS (AE_NOT_EXIST); 1329 1.7 christos } 1330 1.7 christos 1331 1.9 christos /* Invoke table handler */ 1332 1.8 christos 1333 1.9 christos Status = AcpiGetTableByIndex (TableIndex, &Table); 1334 1.9 christos if (ACPI_SUCCESS (Status)) 1335 1.7 christos { 1336 1.9 christos AcpiTbNotifyTable (ACPI_TABLE_EVENT_UNLOAD, Table); 1337 1.7 christos } 1338 1.7 christos 1339 1.8 christos /* Delete the portion of the namespace owned by this table */ 1340 1.7 christos 1341 1.8 christos Status = AcpiTbDeleteNamespaceByOwner (TableIndex); 1342 1.8 christos if (ACPI_FAILURE (Status)) 1343 1.7 christos { 1344 1.8 christos return_ACPI_STATUS (Status); 1345 1.7 christos } 1346 1.7 christos 1347 1.8 christos (void) AcpiTbReleaseOwnerId (TableIndex); 1348 1.8 christos AcpiTbSetTableLoadedFlag (TableIndex, FALSE); 1349 1.7 christos return_ACPI_STATUS (Status); 1350 1.7 christos } 1351 1.9 christos 1352 1.9 christos 1353 1.9 christos /******************************************************************************* 1354 1.9 christos * 1355 1.9 christos * FUNCTION: AcpiTbNotifyTable 1356 1.9 christos * 1357 1.9 christos * PARAMETERS: Event - Table event 1358 1.9 christos * Table - Validated table pointer 1359 1.9 christos * 1360 1.9 christos * RETURN: None 1361 1.9 christos * 1362 1.9 christos * DESCRIPTION: Notify a table event to the users. 1363 1.9 christos * 1364 1.9 christos ******************************************************************************/ 1365 1.9 christos 1366 1.9 christos void 1367 1.9 christos AcpiTbNotifyTable ( 1368 1.9 christos UINT32 Event, 1369 1.9 christos void *Table) 1370 1.9 christos { 1371 1.9 christos /* Invoke table handler if present */ 1372 1.9 christos 1373 1.9 christos if (AcpiGbl_TableHandler) 1374 1.9 christos { 1375 1.9 christos (void) AcpiGbl_TableHandler (Event, Table, 1376 1.9 christos AcpiGbl_TableHandlerContext); 1377 1.9 christos } 1378 1.9 christos } 1379