dtsubtable.c revision 209746
1210284Sjmallett/****************************************************************************** 2210284Sjmallett * 3210284Sjmallett * Module Name: dtsubtable.c - handling of subtables within ACPI tables 4210284Sjmallett * 5210284Sjmallett *****************************************************************************/ 6210284Sjmallett 7210284Sjmallett/****************************************************************************** 8210284Sjmallett * 9210284Sjmallett * 1. Copyright Notice 10210284Sjmallett * 11210284Sjmallett * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. 12210284Sjmallett * All rights reserved. 13210284Sjmallett * 14210284Sjmallett * 2. License 15210284Sjmallett * 16210284Sjmallett * 2.1. This is your license from Intel Corp. under its intellectual property 17210284Sjmallett * rights. You may have additional license terms from the party that provided 18210284Sjmallett * you this software, covering your right to use that party's intellectual 19210284Sjmallett * property rights. 20210284Sjmallett * 21210284Sjmallett * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22210284Sjmallett * copy of the source code appearing in this file ("Covered Code") an 23210284Sjmallett * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24210284Sjmallett * base code distributed originally by Intel ("Original Intel Code") to copy, 25210284Sjmallett * make derivatives, distribute, use and display any portion of the Covered 26210284Sjmallett * Code in any form, with the right to sublicense such rights; and 27210284Sjmallett * 28210284Sjmallett * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29210284Sjmallett * license (with the right to sublicense), under only those claims of Intel 30210284Sjmallett * patents that are infringed by the Original Intel Code, to make, use, sell, 31210284Sjmallett * offer to sell, and import the Covered Code and derivative works thereof 32210284Sjmallett * solely to the minimum extent necessary to exercise the above copyright 33210284Sjmallett * license, and in no event shall the patent license extend to any additions 34210284Sjmallett * to or modifications of the Original Intel Code. No other license or right 35210284Sjmallett * is granted directly or by implication, estoppel or otherwise; 36210284Sjmallett * 37210284Sjmallett * The above copyright and patent license is granted only if the following 38210284Sjmallett * conditions are met: 39210284Sjmallett * 40210284Sjmallett * 3. Conditions 41210284Sjmallett * 42210284Sjmallett * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43210284Sjmallett * Redistribution of source code of any substantial portion of the Covered 44210284Sjmallett * Code or modification with rights to further distribute source must include 45210284Sjmallett * the above Copyright Notice, the above License, this list of Conditions, 46210284Sjmallett * and the following Disclaimer and Export Compliance provision. In addition, 47210284Sjmallett * Licensee must cause all Covered Code to which Licensee contributes to 48210284Sjmallett * contain a file documenting the changes Licensee made to create that Covered 49210284Sjmallett * Code and the date of any change. Licensee must include in that file the 50210284Sjmallett * documentation of any changes made by any predecessor Licensee. Licensee 51210284Sjmallett * must include a prominent statement that the modification is derived, 52210284Sjmallett * directly or indirectly, from Original Intel Code. 53210284Sjmallett * 54210284Sjmallett * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55210284Sjmallett * Redistribution of source code of any substantial portion of the Covered 56210284Sjmallett * Code or modification without rights to further distribute source must 57210284Sjmallett * include the following Disclaimer and Export Compliance provision in the 58210284Sjmallett * documentation and/or other materials provided with distribution. In 59210284Sjmallett * addition, Licensee may not authorize further sublicense of source of any 60210284Sjmallett * portion of the Covered Code, and must include terms to the effect that the 61210284Sjmallett * license from Licensee to its licensee is limited to the intellectual 62210284Sjmallett * property embodied in the software Licensee provides to its licensee, and 63210284Sjmallett * not to intellectual property embodied in modifications its licensee may 64210284Sjmallett * make. 65210284Sjmallett * 66210284Sjmallett * 3.3. Redistribution of Executable. Redistribution in executable form of any 67210284Sjmallett * substantial portion of the Covered Code or modification must reproduce the 68210284Sjmallett * above Copyright Notice, and the following Disclaimer and Export Compliance 69210284Sjmallett * provision in the documentation and/or other materials provided with the 70210284Sjmallett * distribution. 71210284Sjmallett * 72210284Sjmallett * 3.4. Intel retains all right, title, and interest in and to the Original 73210284Sjmallett * Intel Code. 74210284Sjmallett * 75210284Sjmallett * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76210284Sjmallett * Intel shall be used in advertising or otherwise to promote the sale, use or 77210284Sjmallett * other dealings in products derived from or relating to the Covered Code 78210284Sjmallett * without prior written authorization from Intel. 79210284Sjmallett * 80210284Sjmallett * 4. Disclaimer and Export Compliance 81210284Sjmallett * 82210284Sjmallett * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83210284Sjmallett * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84210284Sjmallett * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85210284Sjmallett * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86210284Sjmallett * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87210284Sjmallett * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88210284Sjmallett * PARTICULAR PURPOSE. 89210284Sjmallett * 90210284Sjmallett * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91210284Sjmallett * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92210284Sjmallett * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93210284Sjmallett * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94210284Sjmallett * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95210284Sjmallett * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96210284Sjmallett * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97210284Sjmallett * LIMITED REMEDY. 98210284Sjmallett * 99210284Sjmallett * 4.3. Licensee shall not export, either directly or indirectly, any of this 100210284Sjmallett * software or system incorporating such software without first obtaining any 101210284Sjmallett * required license or other approval from the U. S. Department of Commerce or 102210284Sjmallett * any other agency or department of the United States Government. In the 103210284Sjmallett * event Licensee exports any such software from the United States or 104210284Sjmallett * re-exports any such software from a foreign destination, Licensee shall 105210284Sjmallett * ensure that the distribution and export/re-export of the software is in 106210284Sjmallett * compliance with all laws, regulations, orders, or other restrictions of the 107210284Sjmallett * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108210284Sjmallett * any of its subsidiaries will export/re-export any technical data, process, 109210284Sjmallett * software, or service, directly or indirectly, to any country for which the 110210284Sjmallett * United States government or any agency thereof requires an export license, 111210284Sjmallett * other governmental approval, or letter of assurance, without first obtaining 112210284Sjmallett * such license, approval or letter. 113210284Sjmallett * 114210284Sjmallett *****************************************************************************/ 115210284Sjmallett 116210284Sjmallett#define __DTSUBTABLE_C__ 117210284Sjmallett 118210284Sjmallett#include <contrib/dev/acpica/compiler/aslcompiler.h> 119210284Sjmallett#include <contrib/dev/acpica/compiler/dtcompiler.h> 120210284Sjmallett 121210284Sjmallett#define _COMPONENT DT_COMPILER 122210284Sjmallett ACPI_MODULE_NAME ("dtsubtable") 123210284Sjmallett 124210284Sjmallett 125210284Sjmallett/****************************************************************************** 126210284Sjmallett * 127210284Sjmallett * FUNCTION: DtCreateSubtable 128210284Sjmallett * 129210284Sjmallett * PARAMETERS: Buffer - Input buffer 130210284Sjmallett * Length - Buffer length 131210284Sjmallett * RetSubtable - Returned newly created subtable 132210284Sjmallett * 133210284Sjmallett * RETURN: None 134210284Sjmallett * 135210284Sjmallett * DESCRIPTION: Create a subtable that is not listed with ACPI_DMTABLE_INFO 136210284Sjmallett * For example, FACS has 24 bytes reserved at the end 137210284Sjmallett * and it's not listed at AcpiDmTableInfoFacs 138210284Sjmallett * 139210284Sjmallett *****************************************************************************/ 140210284Sjmallett 141210284Sjmallettvoid 142210284SjmallettDtCreateSubtable ( 143210284Sjmallett UINT8 *Buffer, 144210284Sjmallett UINT32 Length, 145210284Sjmallett DT_SUBTABLE **RetSubtable) 146210284Sjmallett{ 147210284Sjmallett DT_SUBTABLE *Subtable; 148210284Sjmallett 149210284Sjmallett 150210284Sjmallett Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE)); 151210284Sjmallett 152210284Sjmallett /* Create a new buffer for the subtable data */ 153210284Sjmallett 154210284Sjmallett Subtable->Buffer = UtLocalCalloc (Length); 155210284Sjmallett ACPI_MEMCPY (Subtable->Buffer, Buffer, Length); 156210284Sjmallett 157210284Sjmallett Subtable->Length = Length; 158210284Sjmallett Subtable->TotalLength = Length; 159210284Sjmallett 160210284Sjmallett *RetSubtable = Subtable; 161210284Sjmallett} 162210284Sjmallett 163210284Sjmallett 164210284Sjmallett/****************************************************************************** 165210284Sjmallett * 166210284Sjmallett * FUNCTION: DtInsertSubtable 167210284Sjmallett * 168210284Sjmallett * PARAMETERS: ParentTable - The Parent of the new subtable 169210284Sjmallett * Subtable - The new subtable to insert 170210284Sjmallett * 171210284Sjmallett * RETURN: None 172210284Sjmallett * 173210284Sjmallett * DESCRIPTION: Insert the new subtable to the parent table 174210284Sjmallett * 175210284Sjmallett *****************************************************************************/ 176210284Sjmallett 177210284Sjmallettvoid 178210284SjmallettDtInsertSubtable ( 179210284Sjmallett DT_SUBTABLE *ParentTable, 180210284Sjmallett DT_SUBTABLE *Subtable) 181210284Sjmallett{ 182210284Sjmallett DT_SUBTABLE *ChildTable; 183210284Sjmallett 184210284Sjmallett 185210284Sjmallett Subtable->Peer = NULL; 186210284Sjmallett Subtable->Parent = ParentTable; 187210284Sjmallett 188210284Sjmallett /* Link the new entry into the child list */ 189210284Sjmallett 190210284Sjmallett if (!ParentTable->Child) 191210284Sjmallett { 192210284Sjmallett ParentTable->Child = Subtable; 193210284Sjmallett } 194210284Sjmallett else 195210284Sjmallett { 196210284Sjmallett /* Walk to the end of the child list */ 197210284Sjmallett 198210284Sjmallett ChildTable = ParentTable->Child; 199210284Sjmallett while (ChildTable->Peer) 200210284Sjmallett { 201210284Sjmallett ChildTable = ChildTable->Peer; 202210284Sjmallett } 203210284Sjmallett 204210284Sjmallett /* Add new subtable at the end of the child list */ 205210284Sjmallett 206210284Sjmallett ChildTable->Peer = Subtable; 207210284Sjmallett } 208210284Sjmallett} 209210284Sjmallett 210210284Sjmallett 211210284Sjmallett/****************************************************************************** 212210284Sjmallett * 213210284Sjmallett * FUNCTION: DtPushSubtable 214210284Sjmallett * 215210284Sjmallett * PARAMETERS: Subtable - Subtable to push 216210284Sjmallett * 217210284Sjmallett * RETURN: None 218210284Sjmallett * 219210284Sjmallett * DESCRIPTION: Push a subtable onto a subtable stack 220210284Sjmallett * 221210284Sjmallett *****************************************************************************/ 222210284Sjmallett 223210284Sjmallettvoid 224210284SjmallettDtPushSubtable ( 225210284Sjmallett DT_SUBTABLE *Subtable) 226210284Sjmallett{ 227210284Sjmallett 228210284Sjmallett Subtable->StackTop = Gbl_SubtableStack; 229210284Sjmallett Gbl_SubtableStack = Subtable; 230210284Sjmallett} 231210284Sjmallett 232210284Sjmallett 233210284Sjmallett/****************************************************************************** 234210284Sjmallett * 235210284Sjmallett * FUNCTION: DtPopSubtable 236210284Sjmallett * 237210284Sjmallett * PARAMETERS: None 238210284Sjmallett * 239210284Sjmallett * RETURN: None 240210284Sjmallett * 241210284Sjmallett * DESCRIPTION: Pop a subtable from a subtable stack. Uses global SubtableStack 242210284Sjmallett * 243210284Sjmallett *****************************************************************************/ 244210284Sjmallett 245210284Sjmallettvoid 246210284SjmallettDtPopSubtable ( 247210284Sjmallett void) 248210284Sjmallett{ 249210284Sjmallett DT_SUBTABLE *Subtable; 250210284Sjmallett 251210284Sjmallett 252210284Sjmallett Subtable = Gbl_SubtableStack; 253210284Sjmallett 254210284Sjmallett if (Subtable) 255210284Sjmallett { 256210284Sjmallett Gbl_SubtableStack = Subtable->StackTop; 257210284Sjmallett } 258210284Sjmallett} 259210284Sjmallett 260210284Sjmallett 261210284Sjmallett/****************************************************************************** 262210284Sjmallett * 263210284Sjmallett * FUNCTION: DtPeekSubtable 264210284Sjmallett * 265210284Sjmallett * PARAMETERS: None 266210284Sjmallett * 267210284Sjmallett * RETURN: The subtable on top of stack 268210284Sjmallett * 269210284Sjmallett * DESCRIPTION: Get the subtable on top of stack 270210284Sjmallett * 271210284Sjmallett *****************************************************************************/ 272210284Sjmallett 273210284SjmallettDT_SUBTABLE * 274210284SjmallettDtPeekSubtable ( 275210284Sjmallett void) 276210284Sjmallett{ 277210284Sjmallett 278210284Sjmallett return (Gbl_SubtableStack); 279210284Sjmallett} 280210284Sjmallett 281210284Sjmallett 282210284Sjmallett/****************************************************************************** 283210284Sjmallett * 284210284Sjmallett * FUNCTION: DtGetNextSubtable 285210284Sjmallett * 286210284Sjmallett * PARAMETERS: ParentTable - Parent table whose children we are 287210284Sjmallett * getting 288210284Sjmallett * ChildTable - Previous child that was found. 289210284Sjmallett * The NEXT child will be returned 290210284Sjmallett * 291210284Sjmallett * RETURN: Pointer to the NEXT child or NULL if none is found. 292210284Sjmallett * 293210284Sjmallett * DESCRIPTION: Return the next peer subtable within the tree. 294210284Sjmallett * 295210284Sjmallett *****************************************************************************/ 296210284Sjmallett 297210284SjmallettDT_SUBTABLE * 298210284SjmallettDtGetNextSubtable ( 299210284Sjmallett DT_SUBTABLE *ParentTable, 300210284Sjmallett DT_SUBTABLE *ChildTable) 301210284Sjmallett{ 302210284Sjmallett ACPI_FUNCTION_ENTRY (); 303210284Sjmallett 304210284Sjmallett 305210284Sjmallett if (!ChildTable) 306210284Sjmallett { 307210284Sjmallett /* It's really the parent's _scope_ that we want */ 308210284Sjmallett 309210284Sjmallett return (ParentTable->Child); 310210284Sjmallett } 311210284Sjmallett 312210284Sjmallett /* Otherwise just return the next peer (NULL if at end-of-list) */ 313210284Sjmallett 314210284Sjmallett return (ChildTable->Peer); 315210284Sjmallett} 316210284Sjmallett 317210284Sjmallett 318210284Sjmallett/****************************************************************************** 319210284Sjmallett * 320210284Sjmallett * FUNCTION: DtGetParentSubtable 321210284Sjmallett * 322210284Sjmallett * PARAMETERS: Subtable - Current subtable 323210284Sjmallett * 324210284Sjmallett * RETURN: Parent of the given subtable 325210284Sjmallett * 326210284Sjmallett * DESCRIPTION: Get the parent of the given subtable in the tree 327210284Sjmallett * 328210284Sjmallett *****************************************************************************/ 329210284Sjmallett 330210284SjmallettDT_SUBTABLE * 331210284SjmallettDtGetParentSubtable ( 332210284Sjmallett DT_SUBTABLE *Subtable) 333210284Sjmallett{ 334210284Sjmallett 335210284Sjmallett if (!Subtable) 336210284Sjmallett { 337210284Sjmallett return (NULL); 338210284Sjmallett } 339210284Sjmallett 340210284Sjmallett return (Subtable->Parent); 341} 342 343 344/****************************************************************************** 345 * 346 * FUNCTION: DtGetSubtableLength 347 * 348 * PARAMETERS: Field - Current field list pointer 349 * Info - Data table info 350 * 351 * RETURN: Subtable length 352 * 353 * DESCRIPTION: Get length of bytes needed to compile the subtable 354 * 355 *****************************************************************************/ 356 357UINT32 358DtGetSubtableLength ( 359 DT_FIELD *Field, 360 ACPI_DMTABLE_INFO *Info) 361{ 362 UINT32 ByteLength = 0; 363 364 365 /* Walk entire Info table; Null name terminates */ 366 367 for (; Info->Name; Info++) 368 { 369 ByteLength += DtGetFieldLength (Field, Info); 370 } 371 372 return (ByteLength); 373} 374 375 376/****************************************************************************** 377 * 378 * FUNCTION: DtSetSubtableLength 379 * 380 * PARAMETERS: Subtable - Subtable 381 * 382 * RETURN: None 383 * 384 * DESCRIPTION: Set length of the subtable into its length field 385 * 386 *****************************************************************************/ 387 388void 389DtSetSubtableLength ( 390 DT_SUBTABLE *Subtable) 391{ 392 393 if (!Subtable->LengthField) 394 { 395 return; 396 } 397 398 ACPI_MEMCPY (Subtable->LengthField, &Subtable->TotalLength, 399 Subtable->SizeOfLengthField); 400} 401