dtsubtable.c revision 208625
1208625Sjkim/****************************************************************************** 2208625Sjkim * 3208625Sjkim * Module Name: dtsubtable.c - handling of subtables within ACPI tables 4208625Sjkim * 5208625Sjkim *****************************************************************************/ 6208625Sjkim 7208625Sjkim/****************************************************************************** 8208625Sjkim * 9208625Sjkim * 1. Copyright Notice 10208625Sjkim * 11208625Sjkim * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. 12208625Sjkim * All rights reserved. 13208625Sjkim * 14208625Sjkim * 2. License 15208625Sjkim * 16208625Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 17208625Sjkim * rights. You may have additional license terms from the party that provided 18208625Sjkim * you this software, covering your right to use that party's intellectual 19208625Sjkim * property rights. 20208625Sjkim * 21208625Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22208625Sjkim * copy of the source code appearing in this file ("Covered Code") an 23208625Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24208625Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 25208625Sjkim * make derivatives, distribute, use and display any portion of the Covered 26208625Sjkim * Code in any form, with the right to sublicense such rights; and 27208625Sjkim * 28208625Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29208625Sjkim * license (with the right to sublicense), under only those claims of Intel 30208625Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 31208625Sjkim * offer to sell, and import the Covered Code and derivative works thereof 32208625Sjkim * solely to the minimum extent necessary to exercise the above copyright 33208625Sjkim * license, and in no event shall the patent license extend to any additions 34208625Sjkim * to or modifications of the Original Intel Code. No other license or right 35208625Sjkim * is granted directly or by implication, estoppel or otherwise; 36208625Sjkim * 37208625Sjkim * The above copyright and patent license is granted only if the following 38208625Sjkim * conditions are met: 39208625Sjkim * 40208625Sjkim * 3. Conditions 41208625Sjkim * 42208625Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43208625Sjkim * Redistribution of source code of any substantial portion of the Covered 44208625Sjkim * Code or modification with rights to further distribute source must include 45208625Sjkim * the above Copyright Notice, the above License, this list of Conditions, 46208625Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 47208625Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 48208625Sjkim * contain a file documenting the changes Licensee made to create that Covered 49208625Sjkim * Code and the date of any change. Licensee must include in that file the 50208625Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 51208625Sjkim * must include a prominent statement that the modification is derived, 52208625Sjkim * directly or indirectly, from Original Intel Code. 53208625Sjkim * 54208625Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55208625Sjkim * Redistribution of source code of any substantial portion of the Covered 56208625Sjkim * Code or modification without rights to further distribute source must 57208625Sjkim * include the following Disclaimer and Export Compliance provision in the 58208625Sjkim * documentation and/or other materials provided with distribution. In 59208625Sjkim * addition, Licensee may not authorize further sublicense of source of any 60208625Sjkim * portion of the Covered Code, and must include terms to the effect that the 61208625Sjkim * license from Licensee to its licensee is limited to the intellectual 62208625Sjkim * property embodied in the software Licensee provides to its licensee, and 63208625Sjkim * not to intellectual property embodied in modifications its licensee may 64208625Sjkim * make. 65208625Sjkim * 66208625Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67208625Sjkim * substantial portion of the Covered Code or modification must reproduce the 68208625Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 69208625Sjkim * provision in the documentation and/or other materials provided with the 70208625Sjkim * distribution. 71208625Sjkim * 72208625Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 73208625Sjkim * Intel Code. 74208625Sjkim * 75208625Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76208625Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 77208625Sjkim * other dealings in products derived from or relating to the Covered Code 78208625Sjkim * without prior written authorization from Intel. 79208625Sjkim * 80208625Sjkim * 4. Disclaimer and Export Compliance 81208625Sjkim * 82208625Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83208625Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84208625Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85208625Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86208625Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87208625Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88208625Sjkim * PARTICULAR PURPOSE. 89208625Sjkim * 90208625Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91208625Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92208625Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93208625Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94208625Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95208625Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96208625Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97208625Sjkim * LIMITED REMEDY. 98208625Sjkim * 99208625Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100208625Sjkim * software or system incorporating such software without first obtaining any 101208625Sjkim * required license or other approval from the U. S. Department of Commerce or 102208625Sjkim * any other agency or department of the United States Government. In the 103208625Sjkim * event Licensee exports any such software from the United States or 104208625Sjkim * re-exports any such software from a foreign destination, Licensee shall 105208625Sjkim * ensure that the distribution and export/re-export of the software is in 106208625Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 107208625Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108208625Sjkim * any of its subsidiaries will export/re-export any technical data, process, 109208625Sjkim * software, or service, directly or indirectly, to any country for which the 110208625Sjkim * United States government or any agency thereof requires an export license, 111208625Sjkim * other governmental approval, or letter of assurance, without first obtaining 112208625Sjkim * such license, approval or letter. 113208625Sjkim * 114208625Sjkim *****************************************************************************/ 115208625Sjkim 116208625Sjkim#define __DTSUBTABLE_C__ 117208625Sjkim 118208625Sjkim#include "aslcompiler.h" 119208625Sjkim#include "dtcompiler.h" 120208625Sjkim 121208625Sjkim#define _COMPONENT DT_COMPILER 122208625Sjkim ACPI_MODULE_NAME ("dtsubtable") 123208625Sjkim 124208625Sjkim 125208625Sjkim/****************************************************************************** 126208625Sjkim * 127208625Sjkim * FUNCTION: DtCreateSubtable 128208625Sjkim * 129208625Sjkim * PARAMETERS: Buffer - Input buffer 130208625Sjkim * Length - Buffer length 131208625Sjkim * RetSubtable - Returned newly created subtable 132208625Sjkim * 133208625Sjkim * RETURN: None 134208625Sjkim * 135208625Sjkim * DESCRIPTION: Create a subtable that is not listed with ACPI_DMTABLE_INFO 136208625Sjkim * For example, FACS has 24 bytes reserved at the end 137208625Sjkim * and it's not listed at AcpiDmTableInfoFacs 138208625Sjkim * 139208625Sjkim *****************************************************************************/ 140208625Sjkim 141208625Sjkimvoid 142208625SjkimDtCreateSubtable ( 143208625Sjkim UINT8 *Buffer, 144208625Sjkim UINT32 Length, 145208625Sjkim DT_SUBTABLE **RetSubtable) 146208625Sjkim{ 147208625Sjkim DT_SUBTABLE *Subtable; 148208625Sjkim 149208625Sjkim 150208625Sjkim Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE)); 151208625Sjkim 152208625Sjkim /* Create a new buffer for the subtable data */ 153208625Sjkim 154208625Sjkim Subtable->Buffer = UtLocalCalloc (Length); 155208625Sjkim ACPI_MEMCPY (Subtable->Buffer, Buffer, Length); 156208625Sjkim 157208625Sjkim Subtable->Length = Length; 158208625Sjkim Subtable->TotalLength = Length; 159208625Sjkim 160208625Sjkim *RetSubtable = Subtable; 161208625Sjkim} 162208625Sjkim 163208625Sjkim 164208625Sjkim/****************************************************************************** 165208625Sjkim * 166208625Sjkim * FUNCTION: DtInsertSubtable 167208625Sjkim * 168208625Sjkim * PARAMETERS: ParentTable - The Parent of the new subtable 169208625Sjkim * Subtable - The new subtable to insert 170208625Sjkim * 171208625Sjkim * RETURN: None 172208625Sjkim * 173208625Sjkim * DESCRIPTION: Insert the new subtable to the parent table 174208625Sjkim * 175208625Sjkim *****************************************************************************/ 176208625Sjkim 177208625Sjkimvoid 178208625SjkimDtInsertSubtable ( 179208625Sjkim DT_SUBTABLE *ParentTable, 180208625Sjkim DT_SUBTABLE *Subtable) 181208625Sjkim{ 182208625Sjkim DT_SUBTABLE *ChildTable; 183208625Sjkim 184208625Sjkim 185208625Sjkim Subtable->Peer = NULL; 186208625Sjkim Subtable->Parent = ParentTable; 187208625Sjkim 188208625Sjkim /* Link the new entry into the child list */ 189208625Sjkim 190208625Sjkim if (!ParentTable->Child) 191208625Sjkim { 192208625Sjkim ParentTable->Child = Subtable; 193208625Sjkim } 194208625Sjkim else 195208625Sjkim { 196208625Sjkim /* Walk to the end of the child list */ 197208625Sjkim 198208625Sjkim ChildTable = ParentTable->Child; 199208625Sjkim while (ChildTable->Peer) 200208625Sjkim { 201208625Sjkim ChildTable = ChildTable->Peer; 202208625Sjkim } 203208625Sjkim 204208625Sjkim /* Add new subtable at the end of the child list */ 205208625Sjkim 206208625Sjkim ChildTable->Peer = Subtable; 207208625Sjkim } 208208625Sjkim} 209208625Sjkim 210208625Sjkim 211208625Sjkim/****************************************************************************** 212208625Sjkim * 213208625Sjkim * FUNCTION: DtPushSubtable 214208625Sjkim * 215208625Sjkim * PARAMETERS: Subtable - Subtable to push 216208625Sjkim * 217208625Sjkim * RETURN: None 218208625Sjkim * 219208625Sjkim * DESCRIPTION: Push a subtable onto a subtable stack 220208625Sjkim * 221208625Sjkim *****************************************************************************/ 222208625Sjkim 223208625Sjkimvoid 224208625SjkimDtPushSubtable ( 225208625Sjkim DT_SUBTABLE *Subtable) 226208625Sjkim{ 227208625Sjkim 228208625Sjkim Subtable->StackTop = Gbl_SubtableStack; 229208625Sjkim Gbl_SubtableStack = Subtable; 230208625Sjkim} 231208625Sjkim 232208625Sjkim 233208625Sjkim/****************************************************************************** 234208625Sjkim * 235208625Sjkim * FUNCTION: DtPopSubtable 236208625Sjkim * 237208625Sjkim * PARAMETERS: None 238208625Sjkim * 239208625Sjkim * RETURN: None 240208625Sjkim * 241208625Sjkim * DESCRIPTION: Pop a subtable from a subtable stack. Uses global SubtableStack 242208625Sjkim * 243208625Sjkim *****************************************************************************/ 244208625Sjkim 245208625Sjkimvoid 246208625SjkimDtPopSubtable ( 247208625Sjkim void) 248208625Sjkim{ 249208625Sjkim DT_SUBTABLE *Subtable; 250208625Sjkim 251208625Sjkim 252208625Sjkim Subtable = Gbl_SubtableStack; 253208625Sjkim 254208625Sjkim if (Subtable) 255208625Sjkim { 256208625Sjkim Gbl_SubtableStack = Subtable->StackTop; 257208625Sjkim } 258208625Sjkim} 259208625Sjkim 260208625Sjkim 261208625Sjkim/****************************************************************************** 262208625Sjkim * 263208625Sjkim * FUNCTION: DtPeekSubtable 264208625Sjkim * 265208625Sjkim * PARAMETERS: None 266208625Sjkim * 267208625Sjkim * RETURN: The subtable on top of stack 268208625Sjkim * 269208625Sjkim * DESCRIPTION: Get the subtable on top of stack 270208625Sjkim * 271208625Sjkim *****************************************************************************/ 272208625Sjkim 273208625SjkimDT_SUBTABLE * 274208625SjkimDtPeekSubtable ( 275208625Sjkim void) 276208625Sjkim{ 277208625Sjkim 278208625Sjkim return (Gbl_SubtableStack); 279208625Sjkim} 280208625Sjkim 281208625Sjkim 282208625Sjkim/****************************************************************************** 283208625Sjkim * 284208625Sjkim * FUNCTION: DtGetNextSubtable 285208625Sjkim * 286208625Sjkim * PARAMETERS: ParentTable - Parent table whose children we are 287208625Sjkim * getting 288208625Sjkim * ChildTable - Previous child that was found. 289208625Sjkim * The NEXT child will be returned 290208625Sjkim * 291208625Sjkim * RETURN: Pointer to the NEXT child or NULL if none is found. 292208625Sjkim * 293208625Sjkim * DESCRIPTION: Return the next peer subtable within the tree. 294208625Sjkim * 295208625Sjkim *****************************************************************************/ 296208625Sjkim 297208625SjkimDT_SUBTABLE * 298208625SjkimDtGetNextSubtable ( 299208625Sjkim DT_SUBTABLE *ParentTable, 300208625Sjkim DT_SUBTABLE *ChildTable) 301208625Sjkim{ 302208625Sjkim ACPI_FUNCTION_ENTRY (); 303208625Sjkim 304208625Sjkim 305208625Sjkim if (!ChildTable) 306208625Sjkim { 307208625Sjkim /* It's really the parent's _scope_ that we want */ 308208625Sjkim 309208625Sjkim return (ParentTable->Child); 310208625Sjkim } 311208625Sjkim 312208625Sjkim /* Otherwise just return the next peer (NULL if at end-of-list) */ 313208625Sjkim 314208625Sjkim return (ChildTable->Peer); 315208625Sjkim} 316208625Sjkim 317208625Sjkim 318208625Sjkim/****************************************************************************** 319208625Sjkim * 320208625Sjkim * FUNCTION: DtGetParentSubtable 321208625Sjkim * 322208625Sjkim * PARAMETERS: Subtable - Current subtable 323208625Sjkim * 324208625Sjkim * RETURN: Parent of the given subtable 325208625Sjkim * 326208625Sjkim * DESCRIPTION: Get the parent of the given subtable in the tree 327208625Sjkim * 328208625Sjkim *****************************************************************************/ 329208625Sjkim 330208625SjkimDT_SUBTABLE * 331208625SjkimDtGetParentSubtable ( 332208625Sjkim DT_SUBTABLE *Subtable) 333208625Sjkim{ 334208625Sjkim 335208625Sjkim if (!Subtable) 336208625Sjkim { 337208625Sjkim return (NULL); 338208625Sjkim } 339208625Sjkim 340208625Sjkim return (Subtable->Parent); 341208625Sjkim} 342208625Sjkim 343208625Sjkim 344208625Sjkim/****************************************************************************** 345208625Sjkim * 346208625Sjkim * FUNCTION: DtGetSubtableLength 347208625Sjkim * 348208625Sjkim * PARAMETERS: Field - Current field list pointer 349208625Sjkim * Info - Data table info 350208625Sjkim * 351208625Sjkim * RETURN: Subtable length 352208625Sjkim * 353208625Sjkim * DESCRIPTION: Get length of bytes needed to compile the subtable 354208625Sjkim * 355208625Sjkim *****************************************************************************/ 356208625Sjkim 357208625SjkimUINT32 358208625SjkimDtGetSubtableLength ( 359208625Sjkim DT_FIELD *Field, 360208625Sjkim ACPI_DMTABLE_INFO *Info) 361208625Sjkim{ 362208625Sjkim UINT32 ByteLength = 0; 363208625Sjkim 364208625Sjkim 365208625Sjkim /* Walk entire Info table; Null name terminates */ 366208625Sjkim 367208625Sjkim for (; Info->Name; Info++) 368208625Sjkim { 369208625Sjkim ByteLength += DtGetFieldLength (Field, Info); 370208625Sjkim } 371208625Sjkim 372208625Sjkim return (ByteLength); 373208625Sjkim} 374208625Sjkim 375208625Sjkim 376208625Sjkim/****************************************************************************** 377208625Sjkim * 378208625Sjkim * FUNCTION: DtSetSubtableLength 379208625Sjkim * 380208625Sjkim * PARAMETERS: Subtable - Subtable 381208625Sjkim * 382208625Sjkim * RETURN: None 383208625Sjkim * 384208625Sjkim * DESCRIPTION: Set length of the subtable into its length field 385208625Sjkim * 386208625Sjkim *****************************************************************************/ 387208625Sjkim 388208625Sjkimvoid 389208625SjkimDtSetSubtableLength ( 390208625Sjkim DT_SUBTABLE *Subtable) 391208625Sjkim{ 392208625Sjkim 393208625Sjkim if (!Subtable->LengthField) 394208625Sjkim { 395208625Sjkim return; 396208625Sjkim } 397208625Sjkim 398208625Sjkim ACPI_MEMCPY (Subtable->LengthField, &Subtable->TotalLength, 399208625Sjkim Subtable->SizeOfLengthField); 400208625Sjkim} 401