dmresrc.c revision 193267
1100966Siwasaki/*******************************************************************************
2100966Siwasaki *
3100966Siwasaki * Module Name: dmresrc.c - Resource Descriptor disassembly
4100966Siwasaki *
5100966Siwasaki ******************************************************************************/
6100966Siwasaki
7100966Siwasaki/******************************************************************************
8100966Siwasaki *
9100966Siwasaki * 1. Copyright Notice
10100966Siwasaki *
11193267Sjkim * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12100966Siwasaki * All rights reserved.
13100966Siwasaki *
14100966Siwasaki * 2. License
15100966Siwasaki *
16100966Siwasaki * 2.1. This is your license from Intel Corp. under its intellectual property
17100966Siwasaki * rights.  You may have additional license terms from the party that provided
18100966Siwasaki * you this software, covering your right to use that party's intellectual
19100966Siwasaki * property rights.
20100966Siwasaki *
21100966Siwasaki * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22100966Siwasaki * copy of the source code appearing in this file ("Covered Code") an
23100966Siwasaki * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24100966Siwasaki * base code distributed originally by Intel ("Original Intel Code") to copy,
25100966Siwasaki * make derivatives, distribute, use and display any portion of the Covered
26100966Siwasaki * Code in any form, with the right to sublicense such rights; and
27100966Siwasaki *
28100966Siwasaki * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29100966Siwasaki * license (with the right to sublicense), under only those claims of Intel
30100966Siwasaki * patents that are infringed by the Original Intel Code, to make, use, sell,
31100966Siwasaki * offer to sell, and import the Covered Code and derivative works thereof
32100966Siwasaki * solely to the minimum extent necessary to exercise the above copyright
33100966Siwasaki * license, and in no event shall the patent license extend to any additions
34100966Siwasaki * to or modifications of the Original Intel Code.  No other license or right
35100966Siwasaki * is granted directly or by implication, estoppel or otherwise;
36100966Siwasaki *
37100966Siwasaki * The above copyright and patent license is granted only if the following
38100966Siwasaki * conditions are met:
39100966Siwasaki *
40100966Siwasaki * 3. Conditions
41100966Siwasaki *
42100966Siwasaki * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43100966Siwasaki * Redistribution of source code of any substantial portion of the Covered
44100966Siwasaki * Code or modification with rights to further distribute source must include
45100966Siwasaki * the above Copyright Notice, the above License, this list of Conditions,
46100966Siwasaki * and the following Disclaimer and Export Compliance provision.  In addition,
47100966Siwasaki * Licensee must cause all Covered Code to which Licensee contributes to
48100966Siwasaki * contain a file documenting the changes Licensee made to create that Covered
49100966Siwasaki * Code and the date of any change.  Licensee must include in that file the
50100966Siwasaki * documentation of any changes made by any predecessor Licensee.  Licensee
51100966Siwasaki * must include a prominent statement that the modification is derived,
52100966Siwasaki * directly or indirectly, from Original Intel Code.
53100966Siwasaki *
54100966Siwasaki * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55100966Siwasaki * Redistribution of source code of any substantial portion of the Covered
56100966Siwasaki * Code or modification without rights to further distribute source must
57100966Siwasaki * include the following Disclaimer and Export Compliance provision in the
58100966Siwasaki * documentation and/or other materials provided with distribution.  In
59100966Siwasaki * addition, Licensee may not authorize further sublicense of source of any
60100966Siwasaki * portion of the Covered Code, and must include terms to the effect that the
61100966Siwasaki * license from Licensee to its licensee is limited to the intellectual
62100966Siwasaki * property embodied in the software Licensee provides to its licensee, and
63100966Siwasaki * not to intellectual property embodied in modifications its licensee may
64100966Siwasaki * make.
65100966Siwasaki *
66100966Siwasaki * 3.3. Redistribution of Executable. Redistribution in executable form of any
67100966Siwasaki * substantial portion of the Covered Code or modification must reproduce the
68100966Siwasaki * above Copyright Notice, and the following Disclaimer and Export Compliance
69100966Siwasaki * provision in the documentation and/or other materials provided with the
70100966Siwasaki * distribution.
71100966Siwasaki *
72100966Siwasaki * 3.4. Intel retains all right, title, and interest in and to the Original
73100966Siwasaki * Intel Code.
74100966Siwasaki *
75100966Siwasaki * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76100966Siwasaki * Intel shall be used in advertising or otherwise to promote the sale, use or
77100966Siwasaki * other dealings in products derived from or relating to the Covered Code
78100966Siwasaki * without prior written authorization from Intel.
79100966Siwasaki *
80100966Siwasaki * 4. Disclaimer and Export Compliance
81100966Siwasaki *
82100966Siwasaki * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83100966Siwasaki * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84100966Siwasaki * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85100966Siwasaki * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86100966Siwasaki * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87100966Siwasaki * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88100966Siwasaki * PARTICULAR PURPOSE.
89100966Siwasaki *
90100966Siwasaki * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91100966Siwasaki * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92100966Siwasaki * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93100966Siwasaki * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94100966Siwasaki * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95100966Siwasaki * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96100966Siwasaki * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97100966Siwasaki * LIMITED REMEDY.
98100966Siwasaki *
99100966Siwasaki * 4.3. Licensee shall not export, either directly or indirectly, any of this
100100966Siwasaki * software or system incorporating such software without first obtaining any
101100966Siwasaki * required license or other approval from the U. S. Department of Commerce or
102100966Siwasaki * any other agency or department of the United States Government.  In the
103100966Siwasaki * event Licensee exports any such software from the United States or
104100966Siwasaki * re-exports any such software from a foreign destination, Licensee shall
105100966Siwasaki * ensure that the distribution and export/re-export of the software is in
106100966Siwasaki * compliance with all laws, regulations, orders, or other restrictions of the
107100966Siwasaki * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108100966Siwasaki * any of its subsidiaries will export/re-export any technical data, process,
109100966Siwasaki * software, or service, directly or indirectly, to any country for which the
110100966Siwasaki * United States government or any agency thereof requires an export license,
111100966Siwasaki * other governmental approval, or letter of assurance, without first obtaining
112100966Siwasaki * such license, approval or letter.
113100966Siwasaki *
114100966Siwasaki *****************************************************************************/
115100966Siwasaki
116100966Siwasaki
117193251Sjkim#include "acpi.h"
118193267Sjkim#include "accommon.h"
119193251Sjkim#include "amlcode.h"
120193251Sjkim#include "acdisasm.h"
121100966Siwasaki
122100966Siwasaki#ifdef ACPI_DISASSEMBLER
123100966Siwasaki
124102550Siwasaki#define _COMPONENT          ACPI_CA_DEBUGGER
125100966Siwasaki        ACPI_MODULE_NAME    ("dbresrc")
126100966Siwasaki
127100966Siwasaki
128151937Sjkim/* Dispatch tables for Resource disassembly functions */
129151937Sjkim
130151937Sjkimtypedef
131151937Sjkimvoid (*ACPI_RESOURCE_HANDLER) (
132151937Sjkim    AML_RESOURCE            *Resource,
133151937Sjkim    UINT32                  Length,
134151937Sjkim    UINT32                  Level);
135151937Sjkim
136193267Sjkimstatic ACPI_RESOURCE_HANDLER    AcpiGbl_DmResourceDispatch [] =
137151937Sjkim{
138167802Sjkim    /* Small descriptors */
139167802Sjkim
140151937Sjkim    NULL,                           /* 0x00, Reserved */
141151937Sjkim    NULL,                           /* 0x01, Reserved */
142151937Sjkim    NULL,                           /* 0x02, Reserved */
143151937Sjkim    NULL,                           /* 0x03, Reserved */
144151937Sjkim    AcpiDmIrqDescriptor,            /* 0x04, ACPI_RESOURCE_NAME_IRQ_FORMAT */
145151937Sjkim    AcpiDmDmaDescriptor,            /* 0x05, ACPI_RESOURCE_NAME_DMA_FORMAT */
146151937Sjkim    AcpiDmStartDependentDescriptor, /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */
147151937Sjkim    AcpiDmEndDependentDescriptor,   /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */
148151937Sjkim    AcpiDmIoDescriptor,             /* 0x08, ACPI_RESOURCE_NAME_IO_PORT */
149151937Sjkim    AcpiDmFixedIoDescriptor,        /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO_PORT */
150151937Sjkim    NULL,                           /* 0x0A, Reserved */
151151937Sjkim    NULL,                           /* 0x0B, Reserved */
152151937Sjkim    NULL,                           /* 0x0C, Reserved */
153151937Sjkim    NULL,                           /* 0x0D, Reserved */
154151937Sjkim    AcpiDmVendorSmallDescriptor,    /* 0x0E, ACPI_RESOURCE_NAME_SMALL_VENDOR */
155167802Sjkim    NULL,                           /* 0x0F, ACPI_RESOURCE_NAME_END_TAG (not used) */
156151937Sjkim
157167802Sjkim    /* Large descriptors */
158167802Sjkim
159151937Sjkim    NULL,                           /* 0x00, Reserved */
160151937Sjkim    AcpiDmMemory24Descriptor,       /* 0x01, ACPI_RESOURCE_NAME_MEMORY_24 */
161151937Sjkim    AcpiDmGenericRegisterDescriptor,/* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */
162151937Sjkim    NULL,                           /* 0x03, Reserved */
163151937Sjkim    AcpiDmVendorLargeDescriptor,    /* 0x04, ACPI_RESOURCE_NAME_LARGE_VENDOR */
164151937Sjkim    AcpiDmMemory32Descriptor,       /* 0x05, ACPI_RESOURCE_NAME_MEMORY_32 */
165151937Sjkim    AcpiDmFixedMemory32Descriptor,  /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY_32 */
166151937Sjkim    AcpiDmDwordDescriptor,          /* 0x07, ACPI_RESOURCE_NAME_DWORD_ADDRESS_SPACE */
167151937Sjkim    AcpiDmWordDescriptor,           /* 0x08, ACPI_RESOURCE_NAME_WORD_ADDRESS_SPACE */
168151937Sjkim    AcpiDmInterruptDescriptor,      /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_XRUPT */
169151937Sjkim    AcpiDmQwordDescriptor,          /* 0x0A, ACPI_RESOURCE_NAME_QWORD_ADDRESS_SPACE */
170151937Sjkim    AcpiDmExtendedDescriptor        /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS_SPACE */
171151937Sjkim};
172151937Sjkim
173151937Sjkim
174167802Sjkim/* Only used for single-threaded applications */
175167802Sjkim/* TBD: remove when name is passed as parameter to the dump functions */
176151937Sjkim
177167802Sjkimstatic UINT32               ResourceName;
178151937Sjkim
179151937Sjkim
180100966Siwasaki/*******************************************************************************
181100966Siwasaki *
182167802Sjkim * FUNCTION:    AcpiDmDescriptorName
183167802Sjkim *
184167802Sjkim * PARAMETERS:  None
185167802Sjkim *
186167802Sjkim * RETURN:      None
187167802Sjkim *
188167802Sjkim * DESCRIPTION: Emit a name for the descriptor if one is present (indicated
189167802Sjkim *              by the name being changed from the default name.) A name is only
190167802Sjkim *              emitted if a reference to the descriptor has been made somewhere
191167802Sjkim *              in the original ASL code.
192167802Sjkim *
193167802Sjkim ******************************************************************************/
194167802Sjkim
195167802Sjkimvoid
196167802SjkimAcpiDmDescriptorName (
197167802Sjkim    void)
198167802Sjkim{
199167802Sjkim
200167802Sjkim    if (ResourceName == ACPI_DEFAULT_RESNAME)
201167802Sjkim    {
202167802Sjkim        return;
203167802Sjkim    }
204167802Sjkim
205167802Sjkim    AcpiOsPrintf ("%4.4s", (char *) &ResourceName);
206167802Sjkim}
207167802Sjkim
208167802Sjkim
209167802Sjkim/*******************************************************************************
210167802Sjkim *
211151937Sjkim * FUNCTION:    AcpiDmDumpInteger*
212151937Sjkim *
213151937Sjkim * PARAMETERS:  Value               - Value to emit
214151937Sjkim *              Name                - Associated name (emitted as a comment)
215151937Sjkim *
216151937Sjkim * RETURN:      None
217151937Sjkim *
218151937Sjkim * DESCRIPTION: Integer output helper functions
219151937Sjkim *
220151937Sjkim ******************************************************************************/
221151937Sjkim
222151937Sjkimvoid
223151937SjkimAcpiDmDumpInteger8 (
224151937Sjkim    UINT8                   Value,
225151937Sjkim    char                    *Name)
226151937Sjkim{
227151937Sjkim    AcpiOsPrintf ("0x%2.2X,               // %s\n", Value, Name);
228151937Sjkim}
229151937Sjkim
230151937Sjkimvoid
231151937SjkimAcpiDmDumpInteger16 (
232151937Sjkim    UINT16                  Value,
233151937Sjkim    char                    *Name)
234151937Sjkim{
235151937Sjkim    AcpiOsPrintf ("0x%4.4X,             // %s\n", Value, Name);
236151937Sjkim}
237151937Sjkim
238151937Sjkimvoid
239151937SjkimAcpiDmDumpInteger32 (
240151937Sjkim    UINT32                  Value,
241151937Sjkim    char                    *Name)
242151937Sjkim{
243151937Sjkim    AcpiOsPrintf ("0x%8.8X,         // %s\n", Value, Name);
244151937Sjkim}
245151937Sjkim
246151937Sjkimvoid
247151937SjkimAcpiDmDumpInteger64 (
248151937Sjkim    UINT64                  Value,
249151937Sjkim    char                    *Name)
250151937Sjkim{
251167802Sjkim    AcpiOsPrintf ("0x%8.8X%8.8X, // %s\n", ACPI_FORMAT_UINT64 (Value), Name);
252151937Sjkim}
253151937Sjkim
254151937Sjkim
255151937Sjkim/*******************************************************************************
256151937Sjkim *
257100966Siwasaki * FUNCTION:    AcpiDmBitList
258100966Siwasaki *
259100966Siwasaki * PARAMETERS:  Mask            - 16-bit value corresponding to 16 interrupt
260100966Siwasaki *                                or DMA values
261100966Siwasaki *
262100966Siwasaki * RETURN:      None
263100966Siwasaki *
264123315Snjl * DESCRIPTION: Dump a bit mask as a list of individual interrupt/DMA levels.
265100966Siwasaki *
266100966Siwasaki ******************************************************************************/
267100966Siwasaki
268100966Siwasakivoid
269100966SiwasakiAcpiDmBitList (
270100966Siwasaki    UINT16                  Mask)
271100966Siwasaki{
272100966Siwasaki    UINT32                  i;
273100966Siwasaki    BOOLEAN                 Previous = FALSE;
274100966Siwasaki
275100966Siwasaki
276100966Siwasaki    /* Open the initializer list */
277100966Siwasaki
278151937Sjkim    AcpiOsPrintf ("{");
279100966Siwasaki
280100966Siwasaki    /* Examine each bit */
281100966Siwasaki
282100966Siwasaki    for (i = 0; i < 16; i++)
283100966Siwasaki    {
284100966Siwasaki        /* Only interested in bits that are set to 1 */
285100966Siwasaki
286100966Siwasaki        if (Mask & 1)
287100966Siwasaki        {
288100966Siwasaki            if (Previous)
289100966Siwasaki            {
290100966Siwasaki                AcpiOsPrintf (",");
291100966Siwasaki            }
292100966Siwasaki            Previous = TRUE;
293100966Siwasaki            AcpiOsPrintf ("%d", i);
294100966Siwasaki        }
295100966Siwasaki
296100966Siwasaki        Mask >>= 1;
297100966Siwasaki    }
298100966Siwasaki
299100966Siwasaki    /* Close list */
300100966Siwasaki
301100966Siwasaki    AcpiOsPrintf ("}\n");
302100966Siwasaki}
303100966Siwasaki
304100966Siwasaki
305100966Siwasaki/*******************************************************************************
306100966Siwasaki *
307151937Sjkim * FUNCTION:    AcpiDmResourceTemplate
308100966Siwasaki *
309100966Siwasaki * PARAMETERS:  Info            - Curent parse tree walk info
310100966Siwasaki *              ByteData        - Pointer to the byte list data
311100966Siwasaki *              ByteCount       - Length of the byte list
312100966Siwasaki *
313100966Siwasaki * RETURN:      None
314100966Siwasaki *
315151937Sjkim * DESCRIPTION: Dump the contents of a Resource Template containing a set of
316151937Sjkim *              Resource Descriptors.
317100966Siwasaki *
318100966Siwasaki ******************************************************************************/
319100966Siwasaki
320100966Siwasakivoid
321151937SjkimAcpiDmResourceTemplate (
322100966Siwasaki    ACPI_OP_WALK_INFO       *Info,
323167802Sjkim    ACPI_PARSE_OBJECT       *Op,
324100966Siwasaki    UINT8                   *ByteData,
325100966Siwasaki    UINT32                  ByteCount)
326100966Siwasaki{
327167802Sjkim    ACPI_STATUS             Status;
328193267Sjkim    UINT32                  CurrentByteOffset;
329151937Sjkim    UINT8                   ResourceType;
330151937Sjkim    UINT32                  ResourceLength;
331167802Sjkim    void                    *Aml;
332100966Siwasaki    UINT32                  Level;
333100966Siwasaki    BOOLEAN                 DependentFns = FALSE;
334167802Sjkim    UINT8                   ResourceIndex;
335167802Sjkim    ACPI_NAMESPACE_NODE     *Node;
336100966Siwasaki
337100966Siwasaki
338100966Siwasaki    Level = Info->Level;
339167802Sjkim    ResourceName = ACPI_DEFAULT_RESNAME;
340167802Sjkim    Node = Op->Common.Node;
341167802Sjkim    if (Node)
342167802Sjkim    {
343167802Sjkim        Node = Node->Child;
344167802Sjkim    }
345100966Siwasaki
346193267Sjkim    for (CurrentByteOffset = 0; CurrentByteOffset < ByteCount;)
347100966Siwasaki    {
348167802Sjkim        Aml = &ByteData[CurrentByteOffset];
349167802Sjkim
350151937Sjkim        /* Get the descriptor type and length */
351151937Sjkim
352167802Sjkim        ResourceType = AcpiUtGetResourceType (Aml);
353167802Sjkim        ResourceLength = AcpiUtGetResourceLength (Aml);
354100966Siwasaki
355167802Sjkim        /* Validate the Resource Type and Resource Length */
356100966Siwasaki
357167802Sjkim        Status = AcpiUtValidateResource (Aml, &ResourceIndex);
358167802Sjkim        if (ACPI_FAILURE (Status))
359167802Sjkim        {
360167802Sjkim            AcpiOsPrintf ("/*** Could not validate Resource, type (%X) %s***/\n",
361167802Sjkim                ResourceType, AcpiFormatException (Status));
362167802Sjkim            return;
363167802Sjkim        }
364167802Sjkim
365151937Sjkim        /* Point to next descriptor */
366100966Siwasaki
367167802Sjkim        CurrentByteOffset += AcpiUtGetDescriptorLength (Aml);
368100966Siwasaki
369151937Sjkim        /* Descriptor pre-processing */
370151937Sjkim
371151937Sjkim        switch (ResourceType)
372100966Siwasaki        {
373151937Sjkim        case ACPI_RESOURCE_NAME_START_DEPENDENT:
374100966Siwasaki
375100966Siwasaki            /* Finish a previous StartDependentFns */
376100966Siwasaki
377100966Siwasaki            if (DependentFns)
378100966Siwasaki            {
379100966Siwasaki                Level--;
380100966Siwasaki                AcpiDmIndent (Level);
381100966Siwasaki                AcpiOsPrintf ("}\n");
382100966Siwasaki            }
383100966Siwasaki            break;
384100966Siwasaki
385151937Sjkim        case ACPI_RESOURCE_NAME_END_DEPENDENT:
386100966Siwasaki
387100966Siwasaki            Level--;
388100966Siwasaki            DependentFns = FALSE;
389100966Siwasaki            break;
390100966Siwasaki
391151937Sjkim        case ACPI_RESOURCE_NAME_END_TAG:
392100966Siwasaki
393151937Sjkim            /* Normal exit, the resource list is finished */
394100966Siwasaki
395100966Siwasaki            if (DependentFns)
396100966Siwasaki            {
397100966Siwasaki                /*
398151937Sjkim                 * Close an open StartDependentDescriptor. This indicates a
399151937Sjkim                 * missing EndDependentDescriptor.
400100966Siwasaki                 */
401100966Siwasaki                Level--;
402100966Siwasaki                DependentFns = FALSE;
403100966Siwasaki
404151937Sjkim                /* Go ahead and insert EndDependentFn() */
405100966Siwasaki
406167802Sjkim                AcpiDmEndDependentDescriptor (Aml, ResourceLength, Level);
407151937Sjkim
408151937Sjkim                AcpiDmIndent (Level);
409151937Sjkim                AcpiOsPrintf (
410151937Sjkim                    "/*** Disassembler: inserted missing EndDependentFn () ***/\n");
411100966Siwasaki            }
412100966Siwasaki            return;
413100966Siwasaki
414151937Sjkim        default:
415100966Siwasaki            break;
416151937Sjkim        }
417100966Siwasaki
418167802Sjkim        /* Disassemble the resource structure */
419100966Siwasaki
420167802Sjkim        if (Node)
421151937Sjkim        {
422167802Sjkim            ResourceName = Node->Name.Integer;
423167802Sjkim            Node = Node->Peer;
424100966Siwasaki        }
425151937Sjkim
426193267Sjkim        AcpiGbl_DmResourceDispatch [ResourceIndex] (
427167802Sjkim            Aml, ResourceLength, Level);
428151937Sjkim
429151937Sjkim        /* Descriptor post-processing */
430151937Sjkim
431151937Sjkim        if (ResourceType == ACPI_RESOURCE_NAME_START_DEPENDENT)
432151937Sjkim        {
433151937Sjkim            DependentFns = TRUE;
434151937Sjkim            Level++;
435151937Sjkim        }
436100966Siwasaki    }
437100966Siwasaki}
438100966Siwasaki
439100966Siwasaki
440100966Siwasaki/*******************************************************************************
441100966Siwasaki *
442151937Sjkim * FUNCTION:    AcpiDmIsResourceTemplate
443100966Siwasaki *
444100966Siwasaki * PARAMETERS:  Op          - Buffer Op to be examined
445100966Siwasaki *
446167802Sjkim * RETURN:      Status. AE_OK if valid template
447100966Siwasaki *
448100966Siwasaki * DESCRIPTION: Walk a byte list to determine if it consists of a valid set
449100966Siwasaki *              of resource descriptors.  Nothing is output.
450100966Siwasaki *
451100966Siwasaki ******************************************************************************/
452100966Siwasaki
453167802SjkimACPI_STATUS
454151937SjkimAcpiDmIsResourceTemplate (
455100966Siwasaki    ACPI_PARSE_OBJECT       *Op)
456100966Siwasaki{
457167802Sjkim    ACPI_STATUS             Status;
458100966Siwasaki    ACPI_PARSE_OBJECT       *NextOp;
459167802Sjkim    UINT8                   *Aml;
460167802Sjkim    UINT8                   *EndAml;
461167802Sjkim    ACPI_SIZE               Length;
462100966Siwasaki
463100966Siwasaki
464100966Siwasaki    /* This op must be a buffer */
465100966Siwasaki
466100966Siwasaki    if (Op->Common.AmlOpcode != AML_BUFFER_OP)
467100966Siwasaki    {
468167802Sjkim        return (AE_TYPE);
469100966Siwasaki    }
470100966Siwasaki
471167802Sjkim    /* Get the ByteData list and length */
472100966Siwasaki
473100966Siwasaki    NextOp = Op->Common.Value.Arg;
474100966Siwasaki    NextOp = NextOp->Common.Next;
475100966Siwasaki    if (!NextOp)
476100966Siwasaki    {
477167802Sjkim        return (AE_TYPE);
478100966Siwasaki    }
479100966Siwasaki
480167802Sjkim    Aml = NextOp->Named.Data;
481167802Sjkim    Length = (ACPI_SIZE) NextOp->Common.Value.Integer;
482100966Siwasaki
483167802Sjkim    /* Walk the byte list, abort on any invalid descriptor type or length */
484100966Siwasaki
485167802Sjkim    Status = AcpiUtWalkAmlResources (Aml, Length, NULL, &EndAml);
486167802Sjkim    if (ACPI_FAILURE (Status))
487100966Siwasaki    {
488167802Sjkim        return (AE_TYPE);
489126372Snjl    }
490126372Snjl
491167802Sjkim    /*
492167802Sjkim     * For the resource template to be valid, one EndTag must appear
493167802Sjkim     * at the very end of the ByteList, not before. (For proper disassembly
494167802Sjkim     * of a ResourceTemplate, the buffer must not have any extra data after
495167802Sjkim     * the EndTag.)
496167802Sjkim     */
497167802Sjkim    if ((Aml + Length - sizeof (AML_RESOURCE_END_TAG)) != EndAml)
498100966Siwasaki    {
499167802Sjkim        return (AE_AML_NO_RESOURCE_END_TAG);
500100966Siwasaki    }
501100966Siwasaki
502167802Sjkim    /*
503167802Sjkim     * All resource descriptors are valid, therefore this list appears
504167802Sjkim     * to be a valid resource template
505167802Sjkim     */
506167802Sjkim    return (AE_OK);
507100966Siwasaki}
508100966Siwasaki
509100966Siwasaki#endif
510