xref: /titanic_44/usr/src/uts/intel/io/acpica/disassembler/dmresrc.c (revision c5a5e6f47e8f40ef4f4a14b199b09585e3ecf9a0)
1 /*******************************************************************************
2  *
3  * Module Name: dmresrc.c - Resource Descriptor disassembly
4  *
5  ******************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2016, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43 
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "amlcode.h"
47 #include "acdisasm.h"
48 
49 
50 #define _COMPONENT          ACPI_CA_DEBUGGER
51         ACPI_MODULE_NAME    ("dbresrc")
52 
53 
54 /* Dispatch tables for Resource disassembly functions */
55 
56 static ACPI_RESOURCE_HANDLER    AcpiGbl_DmResourceDispatch [] =
57 {
58     /* Small descriptors */
59 
60     NULL,                           /* 0x00, Reserved */
61     NULL,                           /* 0x01, Reserved */
62     NULL,                           /* 0x02, Reserved */
63     NULL,                           /* 0x03, Reserved */
64     AcpiDmIrqDescriptor,            /* 0x04, ACPI_RESOURCE_NAME_IRQ_FORMAT */
65     AcpiDmDmaDescriptor,            /* 0x05, ACPI_RESOURCE_NAME_DMA_FORMAT */
66     AcpiDmStartDependentDescriptor, /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */
67     AcpiDmEndDependentDescriptor,   /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */
68     AcpiDmIoDescriptor,             /* 0x08, ACPI_RESOURCE_NAME_IO_PORT */
69     AcpiDmFixedIoDescriptor,        /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO_PORT */
70     AcpiDmFixedDmaDescriptor,       /* 0x0A, ACPI_RESOURCE_NAME_FIXED_DMA */
71     NULL,                           /* 0x0B, Reserved */
72     NULL,                           /* 0x0C, Reserved */
73     NULL,                           /* 0x0D, Reserved */
74     AcpiDmVendorSmallDescriptor,    /* 0x0E, ACPI_RESOURCE_NAME_SMALL_VENDOR */
75     NULL,                           /* 0x0F, ACPI_RESOURCE_NAME_END_TAG (not used) */
76 
77     /* Large descriptors */
78 
79     NULL,                           /* 0x00, Reserved */
80     AcpiDmMemory24Descriptor,       /* 0x01, ACPI_RESOURCE_NAME_MEMORY_24 */
81     AcpiDmGenericRegisterDescriptor,/* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */
82     NULL,                           /* 0x03, Reserved */
83     AcpiDmVendorLargeDescriptor,    /* 0x04, ACPI_RESOURCE_NAME_LARGE_VENDOR */
84     AcpiDmMemory32Descriptor,       /* 0x05, ACPI_RESOURCE_NAME_MEMORY_32 */
85     AcpiDmFixedMemory32Descriptor,  /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY_32 */
86     AcpiDmDwordDescriptor,          /* 0x07, ACPI_RESOURCE_NAME_DWORD_ADDRESS_SPACE */
87     AcpiDmWordDescriptor,           /* 0x08, ACPI_RESOURCE_NAME_WORD_ADDRESS_SPACE */
88     AcpiDmInterruptDescriptor,      /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_XRUPT */
89     AcpiDmQwordDescriptor,          /* 0x0A, ACPI_RESOURCE_NAME_QWORD_ADDRESS_SPACE */
90     AcpiDmExtendedDescriptor,       /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS_SPACE */
91     AcpiDmGpioDescriptor,           /* 0x0C, ACPI_RESOURCE_NAME_GPIO */
92     NULL,                           /* 0x0D, Reserved */
93     AcpiDmSerialBusDescriptor       /* 0x0E, ACPI_RESOURCE_NAME_SERIAL_BUS */
94 };
95 
96 
97 /* Only used for single-threaded applications */
98 /* TBD: remove when name is passed as parameter to the dump functions */
99 
100 static UINT32               ResourceName;
101 
102 
103 /*******************************************************************************
104  *
105  * FUNCTION:    AcpiDmDescriptorName
106  *
107  * PARAMETERS:  None
108  *
109  * RETURN:      None
110  *
111  * DESCRIPTION: Emit a name for the descriptor if one is present (indicated
112  *              by the name being changed from the default name.) A name is only
113  *              emitted if a reference to the descriptor has been made somewhere
114  *              in the original ASL code.
115  *
116  ******************************************************************************/
117 
118 void
119 AcpiDmDescriptorName (
120     void)
121 {
122 
123     if (ResourceName == ACPI_DEFAULT_RESNAME)
124     {
125         return;
126     }
127 
128     AcpiOsPrintf ("%4.4s", (char *) &ResourceName);
129 }
130 
131 
132 /*******************************************************************************
133  *
134  * FUNCTION:    AcpiDmDumpInteger*
135  *
136  * PARAMETERS:  Value               - Value to emit
137  *              Name                - Associated name (emitted as a comment)
138  *
139  * RETURN:      None
140  *
141  * DESCRIPTION: Integer output helper functions
142  *
143  ******************************************************************************/
144 
145 void
146 AcpiDmDumpInteger8 (
147     UINT8                   Value,
148     const char              *Name)
149 {
150     AcpiOsPrintf ("0x%2.2X,               // %s\n", Value, Name);
151 }
152 
153 void
154 AcpiDmDumpInteger16 (
155     UINT16                  Value,
156     const char              *Name)
157 {
158     AcpiOsPrintf ("0x%4.4X,             // %s\n", Value, Name);
159 }
160 
161 void
162 AcpiDmDumpInteger32 (
163     UINT32                  Value,
164     const char              *Name)
165 {
166     AcpiOsPrintf ("0x%8.8X,         // %s\n", Value, Name);
167 }
168 
169 void
170 AcpiDmDumpInteger64 (
171     UINT64                  Value,
172     const char              *Name)
173 {
174     AcpiOsPrintf ("0x%8.8X%8.8X, // %s\n", ACPI_FORMAT_UINT64 (Value), Name);
175 }
176 
177 
178 /*******************************************************************************
179  *
180  * FUNCTION:    AcpiDmBitList
181  *
182  * PARAMETERS:  Mask            - 16-bit value corresponding to 16 interrupt
183  *                                or DMA values
184  *
185  * RETURN:      None
186  *
187  * DESCRIPTION: Dump a bit mask as a list of individual interrupt/DMA levels.
188  *
189  ******************************************************************************/
190 
191 void
192 AcpiDmBitList (
193     UINT16                  Mask)
194 {
195     UINT32                  i;
196     BOOLEAN                 Previous = FALSE;
197 
198 
199     /* Open the initializer list */
200 
201     AcpiOsPrintf ("{");
202 
203     /* Examine each bit */
204 
205     for (i = 0; i < 16; i++)
206     {
207         /* Only interested in bits that are set to 1 */
208 
209         if (Mask & 1)
210         {
211             if (Previous)
212             {
213                 AcpiOsPrintf (",");
214             }
215 
216             Previous = TRUE;
217             AcpiOsPrintf ("%u", i);
218         }
219 
220         Mask >>= 1;
221     }
222 
223     /* Close list */
224 
225     AcpiOsPrintf ("}\n");
226 }
227 
228 
229 /*******************************************************************************
230  *
231  * FUNCTION:    AcpiDmResourceTemplate
232  *
233  * PARAMETERS:  Info            - Curent parse tree walk info
234  *              ByteData        - Pointer to the byte list data
235  *              ByteCount       - Length of the byte list
236  *
237  * RETURN:      None
238  *
239  * DESCRIPTION: Dump the contents of a Resource Template containing a set of
240  *              Resource Descriptors.
241  *
242  ******************************************************************************/
243 
244 void
245 AcpiDmResourceTemplate (
246     ACPI_OP_WALK_INFO       *Info,
247     ACPI_PARSE_OBJECT       *Op,
248     UINT8                   *ByteData,
249     UINT32                  ByteCount)
250 {
251     ACPI_STATUS             Status;
252     UINT32                  CurrentByteOffset;
253     UINT8                   ResourceType;
254     UINT32                  ResourceLength;
255     void                    *Aml;
256     UINT32                  Level;
257     BOOLEAN                 DependentFns = FALSE;
258     UINT8                   ResourceIndex;
259     ACPI_NAMESPACE_NODE     *Node;
260 
261 
262     if (Op->Asl.AmlOpcode != AML_FIELD_OP)
263     {
264         Info->MappingOp = Op;
265     }
266 
267     Level = Info->Level;
268     ResourceName = ACPI_DEFAULT_RESNAME;
269     Node = Op->Common.Node;
270     if (Node)
271     {
272         Node = Node->Child;
273     }
274 
275     for (CurrentByteOffset = 0; CurrentByteOffset < ByteCount;)
276     {
277         Aml = &ByteData[CurrentByteOffset];
278 
279         /* Get the descriptor type and length */
280 
281         ResourceType = AcpiUtGetResourceType (Aml);
282         ResourceLength = AcpiUtGetResourceLength (Aml);
283 
284         /* Validate the Resource Type and Resource Length */
285 
286         Status = AcpiUtValidateResource (NULL, Aml, &ResourceIndex);
287         if (ACPI_FAILURE (Status))
288         {
289             AcpiOsPrintf (
290                 "/*** Could not validate Resource, type (%X) %s***/\n",
291                 ResourceType, AcpiFormatException (Status));
292             return;
293         }
294 
295         /* Point to next descriptor */
296 
297         CurrentByteOffset += AcpiUtGetDescriptorLength (Aml);
298 
299         /* Descriptor pre-processing */
300 
301         switch (ResourceType)
302         {
303         case ACPI_RESOURCE_NAME_START_DEPENDENT:
304 
305             /* Finish a previous StartDependentFns */
306 
307             if (DependentFns)
308             {
309                 Level--;
310                 AcpiDmIndent (Level);
311                 AcpiOsPrintf ("}\n");
312             }
313             break;
314 
315         case ACPI_RESOURCE_NAME_END_DEPENDENT:
316 
317             Level--;
318             DependentFns = FALSE;
319             break;
320 
321         case ACPI_RESOURCE_NAME_END_TAG:
322 
323             /* Normal exit, the resource list is finished */
324 
325             if (DependentFns)
326             {
327                 /*
328                  * Close an open StartDependentDescriptor. This indicates a
329                  * missing EndDependentDescriptor.
330                  */
331                 Level--;
332                 DependentFns = FALSE;
333 
334                 /* Go ahead and insert EndDependentFn() */
335 
336                 AcpiDmEndDependentDescriptor (Info, Aml, ResourceLength, Level);
337 
338                 AcpiDmIndent (Level);
339                 AcpiOsPrintf (
340                     "/*** Disassembler: inserted "
341                     "missing EndDependentFn () ***/\n");
342             }
343             return;
344 
345         default:
346 
347             break;
348         }
349 
350         /* Disassemble the resource structure */
351 
352         if (Node)
353         {
354             ResourceName = Node->Name.Integer;
355             Node = Node->Peer;
356         }
357 
358         AcpiGbl_DmResourceDispatch [ResourceIndex] (
359             Info, Aml, ResourceLength, Level);
360 
361         /* Descriptor post-processing */
362 
363         if (ResourceType == ACPI_RESOURCE_NAME_START_DEPENDENT)
364         {
365             DependentFns = TRUE;
366             Level++;
367         }
368     }
369 }
370 
371 
372 /*******************************************************************************
373  *
374  * FUNCTION:    AcpiDmIsResourceTemplate
375  *
376  * PARAMETERS:  WalkState           - Current walk info
377  *              Op                  - Buffer Op to be examined
378  *
379  * RETURN:      Status. AE_OK if valid template
380  *
381  * DESCRIPTION: Walk a byte list to determine if it consists of a valid set
382  *              of resource descriptors. Nothing is output.
383  *
384  ******************************************************************************/
385 
386 ACPI_STATUS
387 AcpiDmIsResourceTemplate (
388     ACPI_WALK_STATE         *WalkState,
389     ACPI_PARSE_OBJECT       *Op)
390 {
391     ACPI_STATUS             Status;
392     ACPI_PARSE_OBJECT       *NextOp;
393     UINT8                   *Aml;
394     UINT8                   *EndAml;
395     ACPI_SIZE               Length;
396 
397 
398     /* This op must be a buffer */
399 
400     if (Op->Common.AmlOpcode != AML_BUFFER_OP)
401     {
402         return (AE_TYPE);
403     }
404 
405     /* Get the ByteData list and length */
406 
407     NextOp = Op->Common.Value.Arg;
408     if (!NextOp)
409     {
410         AcpiOsPrintf ("NULL byte list in buffer\n");
411         return (AE_TYPE);
412     }
413 
414     NextOp = NextOp->Common.Next;
415     if (!NextOp)
416     {
417         return (AE_TYPE);
418     }
419 
420     Aml = NextOp->Named.Data;
421     Length = (ACPI_SIZE) NextOp->Common.Value.Integer;
422 
423     /* Walk the byte list, abort on any invalid descriptor type or length */
424 
425     Status = AcpiUtWalkAmlResources (WalkState, Aml, Length,
426         NULL, ACPI_CAST_INDIRECT_PTR (void, &EndAml));
427     if (ACPI_FAILURE (Status))
428     {
429         return (AE_TYPE);
430     }
431 
432     /*
433      * For the resource template to be valid, one EndTag must appear
434      * at the very end of the ByteList, not before. (For proper disassembly
435      * of a ResourceTemplate, the buffer must not have any extra data after
436      * the EndTag.)
437      */
438     if ((Aml + Length - sizeof (AML_RESOURCE_END_TAG)) != EndAml)
439     {
440         return (AE_AML_NO_RESOURCE_END_TAG);
441     }
442 
443     /*
444      * All resource descriptors are valid, therefore this list appears
445      * to be a valid resource template
446      */
447     return (AE_OK);
448 }
449