1 /******************************************************************************
2  *
3  * Module Name: dmrestag - Add tags to resource descriptors (Application-level)
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acparser.h"
155 #include "acdisasm.h"
156 #include "acnamesp.h"
157 #include "amlcode.h"
158 
159 /* This module used for application-level code only */
160 
161 #define _COMPONENT          ACPI_CA_DISASSEMBLER
162         ACPI_MODULE_NAME    ("dmrestag")
163 
164 /* Local prototypes */
165 
166 static void
167 AcpiDmUpdateResourceName (
168     ACPI_NAMESPACE_NODE     *ResourceNode);
169 
170 static char *
171 AcpiDmSearchTagList (
172     UINT32                  BitIndex,
173     const ACPI_RESOURCE_TAG *TagList);
174 
175 static char *
176 AcpiDmGetResourceTag (
177     UINT32                  BitIndex,
178     AML_RESOURCE            *Resource,
179     UINT8                   ResourceIndex);
180 
181 static char *
182 AcpiGetTagPathname (
183     ACPI_PARSE_OBJECT       *Op,
184     ACPI_NAMESPACE_NODE     *BufferNode,
185     ACPI_NAMESPACE_NODE     *ResourceNode,
186     UINT32                  BitIndex);
187 
188 static ACPI_NAMESPACE_NODE *
189 AcpiDmGetResourceNode (
190     ACPI_NAMESPACE_NODE     *BufferNode,
191     UINT32                  BitIndex);
192 
193 static ACPI_STATUS
194 AcpiDmAddResourceToNamespace (
195     UINT8                   *Aml,
196     UINT32                  Length,
197     UINT32                  Offset,
198     UINT8                   ResourceIndex,
199     void                    **Context);
200 
201 static void
202 AcpiDmAddResourcesToNamespace (
203     ACPI_NAMESPACE_NODE     *BufferNode,
204     ACPI_PARSE_OBJECT       *Op);
205 
206 
207 /******************************************************************************
208  *
209  * Resource Tag tables
210  *
211  * These are the predefined tags that refer to elements of a resource
212  * descriptor. Each name and offset is defined in the ACPI specification.
213  *
214  * Each table entry contains the bit offset of the field and the associated
215  * name.
216  *
217  ******************************************************************************/
218 
219 static const ACPI_RESOURCE_TAG      AcpiDmIrqTags[] =
220 {
221     {( 1 * 8),      ACPI_RESTAG_INTERRUPT},
222     {( 3 * 8) + 0,  ACPI_RESTAG_INTERRUPTTYPE},
223     {( 3 * 8) + 3,  ACPI_RESTAG_INTERRUPTLEVEL},
224     {( 3 * 8) + 4,  ACPI_RESTAG_INTERRUPTSHARE},
225     {0,             NULL}
226 };
227 
228 static const ACPI_RESOURCE_TAG      AcpiDmDmaTags[] =
229 {
230     {( 1 * 8),      ACPI_RESTAG_DMA},
231     {( 2 * 8) + 0,  ACPI_RESTAG_XFERTYPE},
232     {( 2 * 8) + 2,  ACPI_RESTAG_BUSMASTER},
233     {( 2 * 8) + 5,  ACPI_RESTAG_DMATYPE},
234     {0,             NULL}
235 };
236 
237 static const ACPI_RESOURCE_TAG      AcpiDmIoTags[] =
238 {
239     {( 1 * 8) + 0,  ACPI_RESTAG_DECODE},
240     {( 2 * 8),      ACPI_RESTAG_MINADDR},
241     {( 4 * 8),      ACPI_RESTAG_MAXADDR},
242     {( 6 * 8),      ACPI_RESTAG_ALIGNMENT},
243     {( 7 * 8),      ACPI_RESTAG_LENGTH},
244     {0,             NULL}
245 };
246 
247 static const ACPI_RESOURCE_TAG      AcpiDmFixedIoTags[] =
248 {
249     {( 1 * 8),      ACPI_RESTAG_BASEADDRESS},
250     {( 3 * 8),      ACPI_RESTAG_LENGTH},
251     {0,             NULL}
252 };
253 
254 static const ACPI_RESOURCE_TAG      AcpiDmFixedDmaTags[] =
255 {
256     {( 1 * 8),      ACPI_RESTAG_DMA},
257     {( 3 * 8),      ACPI_RESTAG_DMATYPE},
258     {( 5 * 8),      ACPI_RESTAG_XFERTYPE},
259     {0,             NULL}
260 };
261 
262 static const ACPI_RESOURCE_TAG      AcpiDmMemory24Tags[] =
263 {
264     {( 3 * 8) + 0,  ACPI_RESTAG_READWRITETYPE},
265     {( 4 * 8),      ACPI_RESTAG_MINADDR},
266     {( 6 * 8),      ACPI_RESTAG_MAXADDR},
267     {( 8 * 8),      ACPI_RESTAG_ALIGNMENT},
268     {(10 * 8),      ACPI_RESTAG_LENGTH},
269     {0,             NULL}
270 };
271 
272 static const ACPI_RESOURCE_TAG      AcpiDmRegisterTags[] =
273 {
274     {( 3 * 8),      ACPI_RESTAG_ADDRESSSPACE},
275     {( 4 * 8),      ACPI_RESTAG_REGISTERBITWIDTH},
276     {( 5 * 8),      ACPI_RESTAG_REGISTERBITOFFSET},
277     {( 6 * 8),      ACPI_RESTAG_ACCESSSIZE},
278     {( 7 * 8),      ACPI_RESTAG_ADDRESS},
279     {0,             NULL}
280 };
281 
282 static const ACPI_RESOURCE_TAG      AcpiDmMemory32Tags[] =
283 {
284     {( 3 * 8) + 0,  ACPI_RESTAG_READWRITETYPE},
285     {( 4 * 8),      ACPI_RESTAG_MINADDR},
286     {( 8 * 8),      ACPI_RESTAG_MAXADDR},
287     {(12 * 8),      ACPI_RESTAG_ALIGNMENT},
288     {(16 * 8),      ACPI_RESTAG_LENGTH},
289     {0,             NULL}
290 };
291 
292 static const ACPI_RESOURCE_TAG      AcpiDmFixedMemory32Tags[] =
293 {
294     {( 3 * 8) + 0,  ACPI_RESTAG_READWRITETYPE},
295     {( 4 * 8),      ACPI_RESTAG_BASEADDRESS},
296     {( 8 * 8),      ACPI_RESTAG_LENGTH},
297     {0,             NULL}
298 };
299 
300 static const ACPI_RESOURCE_TAG      AcpiDmInterruptTags[] =
301 {
302     {( 3 * 8) + 1,  ACPI_RESTAG_INTERRUPTTYPE},
303     {( 3 * 8) + 2,  ACPI_RESTAG_INTERRUPTLEVEL},
304     {( 3 * 8) + 3,  ACPI_RESTAG_INTERRUPTSHARE},
305     {( 5 * 8),      ACPI_RESTAG_INTERRUPT},
306     {0,             NULL}
307 };
308 
309 static const ACPI_RESOURCE_TAG      AcpiDmAddress16Tags[] =
310 {
311     {( 4 * 8) + 1,  ACPI_RESTAG_DECODE},
312     {( 4 * 8) + 2,  ACPI_RESTAG_MINTYPE},
313     {( 4 * 8) + 3,  ACPI_RESTAG_MAXTYPE},
314     {( 6 * 8),      ACPI_RESTAG_GRANULARITY},
315     {( 8 * 8),      ACPI_RESTAG_MINADDR},
316     {(10 * 8),      ACPI_RESTAG_MAXADDR},
317     {(12 * 8),      ACPI_RESTAG_TRANSLATION},
318     {(14 * 8),      ACPI_RESTAG_LENGTH},
319     {0,             NULL}
320 };
321 
322 static const ACPI_RESOURCE_TAG      AcpiDmAddress32Tags[] =
323 {
324     {( 4 * 8) + 1,  ACPI_RESTAG_DECODE},
325     {( 4 * 8) + 2,  ACPI_RESTAG_MINTYPE},
326     {( 4 * 8) + 3,  ACPI_RESTAG_MAXTYPE},
327     {( 6 * 8),      ACPI_RESTAG_GRANULARITY},
328     {(10 * 8),      ACPI_RESTAG_MINADDR},
329     {(14 * 8),      ACPI_RESTAG_MAXADDR},
330     {(18 * 8),      ACPI_RESTAG_TRANSLATION},
331     {(22 * 8),      ACPI_RESTAG_LENGTH},
332     {0,             NULL}
333 };
334 
335 static const ACPI_RESOURCE_TAG      AcpiDmAddress64Tags[] =
336 {
337     {( 4 * 8) + 1,  ACPI_RESTAG_DECODE},
338     {( 4 * 8) + 2,  ACPI_RESTAG_MINTYPE},
339     {( 4 * 8) + 3,  ACPI_RESTAG_MAXTYPE},
340     {( 6 * 8),      ACPI_RESTAG_GRANULARITY},
341     {(14 * 8),      ACPI_RESTAG_MINADDR},
342     {(22 * 8),      ACPI_RESTAG_MAXADDR},
343     {(30 * 8),      ACPI_RESTAG_TRANSLATION},
344     {(38 * 8),      ACPI_RESTAG_LENGTH},
345     {0,             NULL}
346 };
347 
348 static const ACPI_RESOURCE_TAG      AcpiDmExtendedAddressTags[] =
349 {
350     {( 4 * 8) + 1,  ACPI_RESTAG_DECODE},
351     {( 4 * 8) + 2,  ACPI_RESTAG_MINTYPE},
352     {( 4 * 8) + 3,  ACPI_RESTAG_MAXTYPE},
353     {( 8 * 8),      ACPI_RESTAG_GRANULARITY},
354     {(16 * 8),      ACPI_RESTAG_MINADDR},
355     {(24 * 8),      ACPI_RESTAG_MAXADDR},
356     {(32 * 8),      ACPI_RESTAG_TRANSLATION},
357     {(40 * 8),      ACPI_RESTAG_LENGTH},
358     {(48 * 8),      ACPI_RESTAG_TYPESPECIFICATTRIBUTES},
359     {0,             NULL}
360 };
361 
362 /* Subtype tables for GPIO descriptors */
363 
364 static const ACPI_RESOURCE_TAG      AcpiDmGpioIntTags[] =
365 {
366     {( 7 * 8) + 0,  ACPI_RESTAG_MODE},
367     {( 7 * 8) + 1,  ACPI_RESTAG_POLARITY},
368     {( 7 * 8) + 3,  ACPI_RESTAG_INTERRUPTSHARE},
369     {( 9 * 8),      ACPI_RESTAG_PINCONFIG},
370     {(10 * 8),      ACPI_RESTAG_DRIVESTRENGTH},
371     {(12 * 8),      ACPI_RESTAG_DEBOUNCETIME},
372     {0,             NULL}
373 };
374 
375 static const ACPI_RESOURCE_TAG      AcpiDmGpioIoTags[] =
376 {
377     {( 7 * 8) + 0,  ACPI_RESTAG_IORESTRICTION},
378     {( 7 * 8) + 3,  ACPI_RESTAG_INTERRUPTSHARE},
379     {( 9 * 8),      ACPI_RESTAG_PINCONFIG},
380     {(10 * 8),      ACPI_RESTAG_DRIVESTRENGTH},
381     {(12 * 8),      ACPI_RESTAG_DEBOUNCETIME},
382     {0,             NULL}
383 };
384 
385 /* Subtype tables for SerialBus descriptors */
386 
387 static const ACPI_RESOURCE_TAG      AcpiDmCsi2SerialBusTags[] =    /* ACPI 6.4 */
388 {
389     {( 6 * 8) + 0,  ACPI_RESTAG_SLAVEMODE},
390     {( 7 * 8) + 0,  ACPI_RESTAG_PHYTYPE},
391     {( 7 * 8) + 2,  ACPI_RESTAG_LOCALPORT},
392     {0,             NULL}
393 };
394 
395 static const ACPI_RESOURCE_TAG      AcpiDmI2cSerialBusTags[] =
396 {
397     {( 6 * 8) + 0,  ACPI_RESTAG_SLAVEMODE},
398     {( 6 * 8) + 2,  ACPI_RESTAG_INTERRUPTSHARE},    /* V2 - ACPI 6.0 */
399     {( 7 * 8) + 0,  ACPI_RESTAG_MODE},
400     {(12 * 8),      ACPI_RESTAG_SPEED},
401     {(16 * 8),      ACPI_RESTAG_ADDRESS},
402     {0,             NULL}
403 };
404 
405 static const ACPI_RESOURCE_TAG      AcpiDmSpiSerialBusTags[] =
406 {
407     {( 6 * 8) + 0,  ACPI_RESTAG_SLAVEMODE},
408     {( 6 * 8) + 2,  ACPI_RESTAG_INTERRUPTSHARE},    /* V2 - ACPI 6.0 */
409     {( 7 * 8) + 0,  ACPI_RESTAG_MODE},
410     {( 7 * 8) + 1,  ACPI_RESTAG_DEVICEPOLARITY},
411     {(12 * 8),      ACPI_RESTAG_SPEED},
412     {(16 * 8),      ACPI_RESTAG_LENGTH},
413     {(17 * 8),      ACPI_RESTAG_PHASE},
414     {(18 * 8),      ACPI_RESTAG_POLARITY},
415     {(19 * 8),      ACPI_RESTAG_ADDRESS},
416     {0,             NULL}
417 };
418 
419 static const ACPI_RESOURCE_TAG      AcpiDmUartSerialBusTags[] =
420 {
421     {( 6 * 8) + 0,  ACPI_RESTAG_SLAVEMODE},         /* Note: not part of original macro */
422     {( 6 * 8) + 2,  ACPI_RESTAG_INTERRUPTSHARE},    /* V2 - ACPI 6.0 */
423     {( 7 * 8) + 0,  ACPI_RESTAG_FLOWCONTROL},
424     {( 7 * 8) + 2,  ACPI_RESTAG_STOPBITS},
425     {( 7 * 8) + 4,  ACPI_RESTAG_LENGTH},
426     {( 7 * 8) + 7,  ACPI_RESTAG_ENDIANNESS},
427     {(12 * 8),      ACPI_RESTAG_SPEED},
428     {(16 * 8),      ACPI_RESTAG_LENGTH_RX},
429     {(18 * 8),      ACPI_RESTAG_LENGTH_TX},
430     {(20 * 8),      ACPI_RESTAG_PARITY},
431     {(21 * 8),      ACPI_RESTAG_LINE},
432     {0,             NULL}
433 };
434 
435 
436 /* Subtype tables for PinFunction descriptor */
437 
438 static const ACPI_RESOURCE_TAG      AcpiDmPinFunctionTags[] =
439 {
440     {( 4 * 8),      ACPI_RESTAG_INTERRUPTSHARE},
441     {( 6 * 8),      ACPI_RESTAG_PINCONFIG},
442     {( 7 * 8),      ACPI_RESTAG_FUNCTION},
443     {0,             NULL}
444 };
445 
446 /* Subtype tables for PinConfig descriptor */
447 
448 static const ACPI_RESOURCE_TAG      AcpiDmPinConfigTags[] =
449 {
450     {( 4 * 8),      ACPI_RESTAG_INTERRUPTSHARE},
451     {( 6 * 8),      ACPI_RESTAG_PINCONFIG_TYPE},
452     {( 7 * 8),      ACPI_RESTAG_PINCONFIG_VALUE},
453     {0,             NULL}
454 };
455 
456 /* Subtype tables for PinGroupFunction descriptor */
457 
458 static const ACPI_RESOURCE_TAG      AcpiDmPinGroupFunctionTags[] =
459 {
460     {( 6 * 8),      ACPI_RESTAG_FUNCTION},
461     {0,             NULL}
462 };
463 
464 /* Subtype tables for Address descriptor type-specific flags */
465 
466 static const ACPI_RESOURCE_TAG      AcpiDmMemoryFlagTags[] =
467 {
468     {( 5 * 8) + 0,  ACPI_RESTAG_READWRITETYPE},
469     {( 5 * 8) + 1,  ACPI_RESTAG_MEMTYPE},
470     {( 5 * 8) + 3,  ACPI_RESTAG_MEMATTRIBUTES},
471     {( 5 * 8) + 5,  ACPI_RESTAG_TYPE},
472     {0,             NULL}
473 };
474 
475 static const ACPI_RESOURCE_TAG      AcpiDmIoFlagTags[] =
476 {
477     {( 5 * 8) + 0,  ACPI_RESTAG_RANGETYPE},
478     {( 5 * 8) + 4,  ACPI_RESTAG_TYPE},
479     {( 5 * 8) + 5,  ACPI_RESTAG_TRANSTYPE},
480     {0,             NULL}
481 };
482 
483 /* Subtype tables for ClockInput descriptor */
484 
485 static const ACPI_RESOURCE_TAG      AcpiDmClockInputTags[] =
486 {
487     {( 6 * 8),      ACPI_RESTAG_FQD},
488     {( 8 * 8),      ACPI_RESTAG_FQN},
489     {0,             NULL}
490 };
491 
492 /*
493  * Dispatch table used to obtain the correct tag table for a descriptor.
494  *
495  * A NULL in this table means one of three things:
496  * 1) The descriptor ID is reserved and invalid
497  * 2) The descriptor has no tags associated with it
498  * 3) The descriptor has subtypes and a separate table will be used.
499  */
500 static const ACPI_RESOURCE_TAG      *AcpiGbl_ResourceTags[] =
501 {
502     /* Small descriptors */
503 
504     NULL,                           /* 0x00, Reserved */
505     NULL,                           /* 0x01, Reserved */
506     NULL,                           /* 0x02, Reserved */
507     NULL,                           /* 0x03, Reserved */
508     AcpiDmIrqTags,                  /* 0x04, ACPI_RESOURCE_NAME_IRQ_FORMAT */
509     AcpiDmDmaTags,                  /* 0x05, ACPI_RESOURCE_NAME_DMA_FORMAT */
510     NULL,                           /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */
511     NULL,                           /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */
512     AcpiDmIoTags,                   /* 0x08, ACPI_RESOURCE_NAME_IO_PORT */
513     AcpiDmFixedIoTags,              /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO_PORT */
514     AcpiDmFixedDmaTags,             /* 0x0A, ACPI_RESOURCE_NAME_FIXED_DMA */
515     NULL,                           /* 0x0B, Reserved */
516     NULL,                           /* 0x0C, Reserved */
517     NULL,                           /* 0x0D, Reserved */
518     NULL,                           /* 0x0E, ACPI_RESOURCE_NAME_SMALL_VENDOR */
519     NULL,                           /* 0x0F, ACPI_RESOURCE_NAME_END_TAG (not used) */
520 
521     /* Large descriptors */
522 
523     NULL,                           /* 0x00, Reserved */
524     AcpiDmMemory24Tags,             /* 0x01, ACPI_RESOURCE_NAME_MEMORY_24 */
525     AcpiDmRegisterTags,             /* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */
526     NULL,                           /* 0x03, Reserved */
527     NULL,                           /* 0x04, ACPI_RESOURCE_NAME_LARGE_VENDOR */
528     AcpiDmMemory32Tags,             /* 0x05, ACPI_RESOURCE_NAME_MEMORY_32 */
529     AcpiDmFixedMemory32Tags,        /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY_32 */
530     AcpiDmAddress32Tags,            /* 0x07, ACPI_RESOURCE_NAME_DWORD_ADDRESS_SPACE */
531     AcpiDmAddress16Tags,            /* 0x08, ACPI_RESOURCE_NAME_WORD_ADDRESS_SPACE */
532     AcpiDmInterruptTags,            /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_XRUPT */
533     AcpiDmAddress64Tags,            /* 0x0A, ACPI_RESOURCE_NAME_QWORD_ADDRESS_SPACE */
534     AcpiDmExtendedAddressTags,      /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS_SPACE */
535     NULL,                           /* 0x0C, ACPI_RESOURCE_NAME_GPIO - Use Subtype table below */
536     AcpiDmPinFunctionTags,          /* 0x0D, ACPI_RESOURCE_NAME_PIN_FUNCTION */
537     NULL,                           /* 0x0E, ACPI_RESOURCE_NAME_SERIAL_BUS - Use Subtype table below */
538     AcpiDmPinConfigTags,            /* 0x0F, ACPI_RESOURCE_NAME_PIN_CONFIG */
539     NULL,                           /* 0x10, ACPI_RESOURCE_NAME_PIN_GROUP */
540     AcpiDmPinGroupFunctionTags,     /* 0x11, ACPI_RESOURCE_NAME_PIN_GROUP_FUNCTION */
541     AcpiDmPinConfigTags,            /* 0x12, ACPI_RESOURCE_NAME_PIN_GROUP_CONFIG - Same as PinConfig */
542     AcpiDmClockInputTags,           /* 0x13, ACPI_RESOURCE_NAME_CLOCK_INPUT */
543 };
544 
545 /* GPIO Subtypes */
546 
547 static const ACPI_RESOURCE_TAG      *AcpiGbl_GpioResourceTags[] =
548 {
549     AcpiDmGpioIntTags,              /* 0x00 Interrupt Connection */
550     AcpiDmGpioIoTags                /* 0x01 I/O Connection */
551 };
552 
553 /* Serial Bus Subtypes */
554 
555 static const ACPI_RESOURCE_TAG      *AcpiGbl_SerialResourceTags[] =
556 {
557     NULL,                           /* 0x00 Reserved */
558     AcpiDmI2cSerialBusTags,         /* 0x01 I2C SerialBus */
559     AcpiDmSpiSerialBusTags,         /* 0x02 SPI SerialBus */
560     AcpiDmUartSerialBusTags,        /* 0x03 UART SerialBus */
561     AcpiDmCsi2SerialBusTags         /* 0x04 CSI2 SerialBus */
562 };
563 
564 /*
565  * Globals used to generate unique resource descriptor names. We use names that
566  * start with underscore and a prefix letter that is not used by other ACPI
567  * reserved names. To this, we append hex 0x00 through 0xFF. These 5 prefixes
568  * allow for 5*256 = 1280 unique names, probably sufficient for any single ASL
569  * file. If this becomes too small, we can use alpha+numerals for a total
570  * of 5*36*36 = 6480.
571  */
572 #define ACPI_NUM_RES_PREFIX     5
573 
574 static UINT32                   AcpiGbl_NextResourceId = 0;
575 static UINT8                    AcpiGbl_NextPrefix = 0;
576 static char                     AcpiGbl_Prefix[ACPI_NUM_RES_PREFIX] =
577                                     {'Y','Z','J','K','X'};
578 
579 
580 /*******************************************************************************
581  *
582  * FUNCTION:    AcpiDmCheckResourceReference
583  *
584  * PARAMETERS:  Op                  - Parse Op for the AML opcode
585  *              WalkState           - Current walk state (with valid scope)
586  *
587  * RETURN:      None
588  *
589  * DESCRIPTION: Convert a reference to a resource descriptor to a symbolic
590  *              reference if possible
591  *
592  * NOTE:        Bit index is used to transparently handle both resource bit
593  *              fields and byte fields.
594  *
595  ******************************************************************************/
596 
597 void
AcpiDmCheckResourceReference(ACPI_PARSE_OBJECT * Op,ACPI_WALK_STATE * WalkState)598 AcpiDmCheckResourceReference (
599     ACPI_PARSE_OBJECT       *Op,
600     ACPI_WALK_STATE         *WalkState)
601 {
602     ACPI_STATUS             Status;
603     ACPI_PARSE_OBJECT       *BufferNameOp;
604     ACPI_PARSE_OBJECT       *IndexOp;
605     ACPI_NAMESPACE_NODE     *BufferNode;
606     ACPI_NAMESPACE_NODE     *ResourceNode;
607     const ACPI_OPCODE_INFO  *OpInfo;
608     UINT32                  BitIndex;
609 
610 
611     /* We are only interested in the CreateXxxxField opcodes */
612 
613     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
614     if (OpInfo->Type != AML_TYPE_CREATE_FIELD)
615     {
616         return;
617     }
618 
619     /* Get the buffer term operand */
620 
621     BufferNameOp = AcpiPsGetDepthNext (NULL, Op);
622 
623     /* Must be a named buffer, not an arg or local or method call */
624 
625     if (BufferNameOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP)
626     {
627         return;
628     }
629 
630     /* Get the Index term, must be an integer constant to convert */
631 
632     IndexOp = BufferNameOp->Common.Next;
633 
634     /* Major cheat: The Node field is also used for the Tag ptr. Clear it now */
635 
636     IndexOp->Common.Node = NULL;
637 
638     OpInfo = AcpiPsGetOpcodeInfo (IndexOp->Common.AmlOpcode);
639     if (OpInfo->ObjectType != ACPI_TYPE_INTEGER)
640     {
641         return;
642     }
643 
644     /* Get the bit offset of the descriptor within the buffer */
645 
646     if ((Op->Common.AmlOpcode == AML_CREATE_BIT_FIELD_OP) ||
647         (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP))
648     {
649         /* Index operand is a bit offset */
650 
651         BitIndex = (UINT32) IndexOp->Common.Value.Integer;
652     }
653     else
654     {
655         /* Index operand is a byte offset, convert to bits */
656 
657         BitIndex = (UINT32) ACPI_MUL_8 (IndexOp->Common.Value.Integer);
658     }
659 
660     /* Lookup the buffer in the namespace */
661 
662     Status = AcpiNsLookup (WalkState->ScopeInfo,
663         BufferNameOp->Common.Value.String, ACPI_TYPE_BUFFER,
664         ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState,
665         &BufferNode);
666     if (ACPI_FAILURE (Status))
667     {
668         return;
669     }
670 
671     /* Validate object type, we must have a buffer */
672 
673     if (BufferNode->Type != ACPI_TYPE_BUFFER)
674     {
675         return;
676     }
677 
678     /* Find the resource descriptor node corresponding to the index */
679 
680     ResourceNode = AcpiDmGetResourceNode (BufferNode, BitIndex);
681     if (!ResourceNode)
682     {
683         return;
684     }
685 
686     /* Translate the Index to a resource tag pathname */
687 
688     AcpiGetTagPathname (IndexOp, BufferNode, ResourceNode, BitIndex);
689 }
690 
691 
692 /*******************************************************************************
693  *
694  * FUNCTION:    AcpiDmGetResourceNode
695  *
696  * PARAMETERS:  BufferNode          - Node for the parent buffer
697  *              BitIndex            - Index into the resource descriptor
698  *
699  * RETURN:      Namespace node for the resource descriptor. NULL if not found
700  *
701  * DESCRIPTION: Find a resource descriptor that corresponds to the bit index
702  *
703  ******************************************************************************/
704 
705 static ACPI_NAMESPACE_NODE *
AcpiDmGetResourceNode(ACPI_NAMESPACE_NODE * BufferNode,UINT32 BitIndex)706 AcpiDmGetResourceNode (
707     ACPI_NAMESPACE_NODE     *BufferNode,
708     UINT32                  BitIndex)
709 {
710     ACPI_NAMESPACE_NODE     *Node;
711     UINT32                  ByteIndex = ACPI_DIV_8 (BitIndex);
712 
713 
714     /*
715      * Child list contains an entry for each resource descriptor. Find
716      * the descriptor that corresponds to the Index.
717      *
718      * If there are no children, this is not a resource template
719      */
720     Node = BufferNode->Child;
721     while (Node)
722     {
723         /*
724          * Check if the Index falls within this resource.
725          *
726          * Value contains the resource offset, Object contains the resource
727          * length (both in bytes)
728          */
729         if ((ByteIndex >= Node->Value) &&
730             (ByteIndex < (Node->Value + Node->Length)))
731         {
732             return (Node);
733         }
734 
735         Node = Node->Peer;
736     }
737 
738     return (NULL);
739 }
740 
741 
742 /*******************************************************************************
743  *
744  * FUNCTION:    AcpiGetTagPathname
745  *
746  * PARAMETERS:  BufferNode          - Node for the parent buffer
747  *              ResourceNode        - Node for a resource descriptor
748  *              BitIndex            - Index into the resource descriptor
749  *
750  * RETURN:      Full pathname for a resource tag. NULL if no match.
751  *              Path is returned in AML (packed) format.
752  *
753  * DESCRIPTION: Convert a BitIndex into a symbolic resource tag (full pathname)
754  *
755  ******************************************************************************/
756 
757 static char *
AcpiGetTagPathname(ACPI_PARSE_OBJECT * IndexOp,ACPI_NAMESPACE_NODE * BufferNode,ACPI_NAMESPACE_NODE * ResourceNode,UINT32 BitIndex)758 AcpiGetTagPathname (
759     ACPI_PARSE_OBJECT       *IndexOp,
760     ACPI_NAMESPACE_NODE     *BufferNode,
761     ACPI_NAMESPACE_NODE     *ResourceNode,
762     UINT32                  BitIndex)
763 {
764     ACPI_STATUS             Status;
765     UINT32                  ResourceBitIndex;
766     UINT8                   ResourceTableIndex;
767     ACPI_SIZE               RequiredSize;
768     char                    *Pathname;
769     char                    *PathnameEnd;
770     AML_RESOURCE            *Aml;
771     ACPI_PARSE_OBJECT       *Op;
772     char                    *InternalPath;
773     char                    *Tag;
774 
775 
776     /* Get the Op that contains the actual buffer data */
777 
778     Op = BufferNode->Op->Common.Value.Arg;
779     Op = Op->Common.Next;
780     if (!Op)
781     {
782         return (NULL);
783     }
784 
785     /* Get the individual resource descriptor and validate it */
786 
787     Aml = ACPI_CAST_PTR (
788         AML_RESOURCE, &Op->Named.Data[ResourceNode->Value]);
789 
790     Status = AcpiUtValidateResource (NULL, Aml, &ResourceTableIndex);
791     if (ACPI_FAILURE (Status))
792     {
793         return (NULL);
794     }
795 
796     /* Get offset into this descriptor (from offset into entire buffer) */
797 
798     ResourceBitIndex = BitIndex - ACPI_MUL_8 (ResourceNode->Value);
799 
800     /* Get the tag associated with this resource descriptor and offset */
801 
802     Tag = AcpiDmGetResourceTag (ResourceBitIndex, Aml, ResourceTableIndex);
803     if (!Tag)
804     {
805         return (NULL);
806     }
807 
808     /*
809      * Now that we know that we have a reference that can be converted to a
810      * symbol, change the name of the resource to a unique name.
811      */
812     AcpiDmUpdateResourceName (ResourceNode);
813 
814     /* Get the full pathname to the parent buffer */
815 
816     RequiredSize = AcpiNsBuildNormalizedPath (BufferNode, NULL, 0, FALSE);
817     if (!RequiredSize)
818     {
819         return (NULL);
820     }
821 
822     Pathname = ACPI_ALLOCATE_ZEROED (RequiredSize + ACPI_PATH_SEGMENT_LENGTH);
823     if (!Pathname)
824     {
825         return (NULL);
826     }
827 
828     (void) AcpiNsBuildNormalizedPath (BufferNode, Pathname,
829         RequiredSize, FALSE);
830 
831     /*
832      * Create the full path to the resource and tag by:
833      *  1) Remove the buffer nameseg from the end of the pathname
834      *  2) Append the resource descriptor nameseg
835      *  3) Append a dot
836      *  4) Append the field tag nameseg
837      *
838      * Always using the full path is a bit brute force, the path can be
839      * often be optimized with carats (if the original buffer namepath is a
840      * single nameseg). This doesn't really matter, because these paths do not
841      * end up in the final compiled AML, it's just an appearance issue for the
842      * disassembled code.
843      */
844     PathnameEnd = Pathname + (RequiredSize - ACPI_NAMESEG_SIZE - 1);
845     ACPI_COPY_NAMESEG (PathnameEnd, ResourceNode->Name.Ascii);
846 
847     PathnameEnd += ACPI_NAMESEG_SIZE;
848     *PathnameEnd = '.';
849 
850     PathnameEnd++;
851     ACPI_COPY_NAMESEG (PathnameEnd, Tag);
852 
853     /* Internalize the namepath to AML format */
854 
855     Status = AcpiNsInternalizeName (Pathname, &InternalPath);
856     ACPI_FREE (Pathname);
857     if (ACPI_FAILURE (Status))
858     {
859         return (NULL);
860     }
861 
862     /* Update the Op with the symbol */
863 
864     AcpiPsInitOp (IndexOp, AML_INT_NAMEPATH_OP);
865     IndexOp->Common.Value.String = InternalPath;
866 
867     /*
868      * We will need the tag later. Cheat by putting it in the Node field.
869      * Note, Tag is a const that is part of a lookup table.
870      */
871     IndexOp->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Tag);
872     return (InternalPath);
873 }
874 
875 
876 /*******************************************************************************
877  *
878  * FUNCTION:    AcpiDmUpdateResourceName
879  *
880  * PARAMETERS:  ResourceNode        - Node for a resource descriptor
881  *
882  * RETURN:      Stores new name in the ResourceNode
883  *
884  * DESCRIPTION: Create a new, unique name for a resource descriptor. Used by
885  *              both the disassembly of the descriptor itself and any symbolic
886  *              references to the descriptor. Ignored if a unique name has
887  *              already been assigned to the resource.
888  *
889  * NOTE: Single threaded, suitable for applications only!
890  *
891  ******************************************************************************/
892 
893 static void
AcpiDmUpdateResourceName(ACPI_NAMESPACE_NODE * ResourceNode)894 AcpiDmUpdateResourceName (
895     ACPI_NAMESPACE_NODE     *ResourceNode)
896 {
897     char                    Name[ACPI_NAMESEG_SIZE];
898 
899 
900     /* Ignore if a unique name has already been assigned */
901 
902     if (ResourceNode->Name.Integer != ACPI_DEFAULT_RESNAME)
903     {
904         return;
905     }
906 
907     /* Generate a new ACPI name for the descriptor */
908 
909     Name[0] = '_';
910     Name[1] = AcpiGbl_Prefix[AcpiGbl_NextPrefix];
911     Name[2] = AcpiUtHexToAsciiChar ((UINT64) AcpiGbl_NextResourceId, 4);
912     Name[3] = AcpiUtHexToAsciiChar ((UINT64) AcpiGbl_NextResourceId, 0);
913 
914     /* Update globals for next name */
915 
916     AcpiGbl_NextResourceId++;
917     if (AcpiGbl_NextResourceId >= 256)
918     {
919         AcpiGbl_NextResourceId = 0;
920         AcpiGbl_NextPrefix++;
921 
922         if (AcpiGbl_NextPrefix > ACPI_NUM_RES_PREFIX)
923         {
924             AcpiGbl_NextPrefix = 0;
925         }
926     }
927 
928     /* Change the resource descriptor name */
929 
930     ResourceNode->Name.Integer = *ACPI_CAST_PTR (UINT32, &Name[0]);
931 }
932 
933 
934 /*******************************************************************************
935  *
936  * FUNCTION:    AcpiDmGetResourceTag
937  *
938  * PARAMETERS:  BitIndex            - Index into the resource descriptor
939  *              Resource            - Pointer to the raw resource data
940  *              ResourceIndex       - Index corresponding to the resource type
941  *
942  * RETURN:      Pointer to the resource tag (ACPI_NAME). NULL if no match.
943  *
944  * DESCRIPTION: Convert a BitIndex into a symbolic resource tag.
945  *
946  * Note: ResourceIndex should be previously validated and guaranteed to ve
947  *       valid.
948  *
949  ******************************************************************************/
950 
951 static char *
AcpiDmGetResourceTag(UINT32 BitIndex,AML_RESOURCE * Resource,UINT8 ResourceIndex)952 AcpiDmGetResourceTag (
953     UINT32                  BitIndex,
954     AML_RESOURCE            *Resource,
955     UINT8                   ResourceIndex)
956 {
957     const ACPI_RESOURCE_TAG *TagList;
958     char                    *Tag = NULL;
959 
960 
961     /* Get the tag list for this resource descriptor type */
962 
963     TagList = AcpiGbl_ResourceTags[ResourceIndex];
964 
965     /*
966      * Handle descriptors that have multiple subtypes
967      */
968     switch (Resource->DescriptorType)
969     {
970     case ACPI_RESOURCE_NAME_ADDRESS16:
971     case ACPI_RESOURCE_NAME_ADDRESS32:
972     case ACPI_RESOURCE_NAME_ADDRESS64:
973     case ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64:
974         /*
975          * Subtype differentiation is the flags.
976          * Kindof brute force, but just blindly search for an index match
977          */
978         if (Resource->Address.ResourceType == ACPI_ADDRESS_TYPE_MEMORY_RANGE)
979         {
980             Tag = AcpiDmSearchTagList (BitIndex, AcpiDmMemoryFlagTags);
981         }
982         else if (Resource->Address.ResourceType == ACPI_ADDRESS_TYPE_IO_RANGE)
983         {
984             Tag = AcpiDmSearchTagList (BitIndex, AcpiDmIoFlagTags);
985         }
986 
987         /* If we found a match, all done. Else, drop to normal search below */
988 
989         if (Tag)
990         {
991             return (Tag);
992         }
993         break;
994 
995     case ACPI_RESOURCE_NAME_GPIO:
996 
997         /* GPIO connection has 2 subtypes: Interrupt and I/O */
998 
999         if (Resource->Gpio.ConnectionType > AML_RESOURCE_MAX_GPIOTYPE)
1000         {
1001             return (NULL);
1002         }
1003 
1004         TagList = AcpiGbl_GpioResourceTags[Resource->Gpio.ConnectionType];
1005         break;
1006 
1007     case ACPI_RESOURCE_NAME_SERIAL_BUS:
1008 
1009         /* SerialBus has 4 subtypes: I2C, SPI, UART, and CSI2 */
1010 
1011         if ((Resource->CommonSerialBus.Type == 0) ||
1012             (Resource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE))
1013         {
1014             return (NULL);
1015         }
1016 
1017         TagList = AcpiGbl_SerialResourceTags[Resource->CommonSerialBus.Type];
1018         break;
1019 
1020     default:
1021 
1022         break;
1023     }
1024 
1025     /* Search for a match against the BitIndex */
1026 
1027     if (TagList)
1028     {
1029         Tag = AcpiDmSearchTagList (BitIndex, TagList);
1030     }
1031 
1032     return (Tag);
1033 }
1034 
1035 
1036 /*******************************************************************************
1037  *
1038  * FUNCTION:    AcpiDmSearchTagList
1039  *
1040  * PARAMETERS:  BitIndex            - Index into the resource descriptor
1041  *              TagList             - List to search
1042  *
1043  * RETURN:      Pointer to a tag (ACPI_NAME). NULL if no match found.
1044  *
1045  * DESCRIPTION: Search a tag list for a match to the input BitIndex. Matches
1046  *              a fixed offset to a symbolic resource tag name.
1047  *
1048  ******************************************************************************/
1049 
1050 static char *
AcpiDmSearchTagList(UINT32 BitIndex,const ACPI_RESOURCE_TAG * TagList)1051 AcpiDmSearchTagList (
1052     UINT32                  BitIndex,
1053     const ACPI_RESOURCE_TAG *TagList)
1054 {
1055 
1056     /*
1057      * Walk the null-terminated tag list to find a matching bit offset.
1058      * We are looking for an exact match.
1059      */
1060     for ( ; TagList->Tag; TagList++)
1061     {
1062         if (BitIndex == TagList->BitIndex)
1063         {
1064             return (TagList->Tag);
1065         }
1066     }
1067 
1068     /* A matching offset was not found */
1069 
1070     return (NULL);
1071 }
1072 
1073 
1074 /*******************************************************************************
1075  *
1076  * FUNCTION:    AcpiDmFindResources
1077  *
1078  * PARAMETERS:  Root                - Root of the parse tree
1079  *
1080  * RETURN:      None
1081  *
1082  * DESCRIPTION: Add all ResourceTemplate declarations to the namespace. Each
1083  *              resource descriptor in each template is given a node -- used
1084  *              for later conversion of resource references to symbolic refs.
1085  *
1086  ******************************************************************************/
1087 
1088 void
AcpiDmFindResources(ACPI_PARSE_OBJECT * Root)1089 AcpiDmFindResources (
1090     ACPI_PARSE_OBJECT       *Root)
1091 {
1092     ACPI_PARSE_OBJECT       *Op = Root;
1093     ACPI_PARSE_OBJECT       *Parent;
1094 
1095 
1096     /* Walk the entire parse tree */
1097 
1098     while (Op)
1099     {
1100         /* We are interested in Buffer() declarations */
1101 
1102         if (Op->Common.AmlOpcode == AML_BUFFER_OP)
1103         {
1104             /* And only declarations of the form Name (XXXX, Buffer()... ) */
1105 
1106             Parent = Op->Common.Parent;
1107             if (Parent->Common.AmlOpcode == AML_NAME_OP)
1108             {
1109                 /*
1110                  * If the buffer is a resource template, add the individual
1111                  * resource descriptors to the namespace, as children of the
1112                  * buffer node.
1113                  */
1114                 if (ACPI_SUCCESS (AcpiDmIsResourceTemplate (NULL, Op)))
1115                 {
1116                     Op->Common.DisasmOpcode = ACPI_DASM_RESOURCE;
1117                     AcpiDmAddResourcesToNamespace (Parent->Common.Node, Op);
1118                 }
1119             }
1120         }
1121 
1122         Op = AcpiPsGetDepthNext (Root, Op);
1123     }
1124 }
1125 
1126 
1127 /*******************************************************************************
1128  *
1129  * FUNCTION:    AcpiDmAddResourcesToNamespace
1130  *
1131  * PARAMETERS:  BufferNode          - Node for the parent buffer
1132  *              Op                  - Parse op for the buffer
1133  *
1134  * RETURN:      None
1135  *
1136  * DESCRIPTION: Add an entire resource template to the namespace. Each
1137  *              resource descriptor is added as a namespace node.
1138  *
1139  ******************************************************************************/
1140 
1141 static void
AcpiDmAddResourcesToNamespace(ACPI_NAMESPACE_NODE * BufferNode,ACPI_PARSE_OBJECT * Op)1142 AcpiDmAddResourcesToNamespace (
1143     ACPI_NAMESPACE_NODE     *BufferNode,
1144     ACPI_PARSE_OBJECT       *Op)
1145 {
1146     ACPI_PARSE_OBJECT       *NextOp;
1147 
1148 
1149     /* Get to the ByteData list */
1150 
1151     NextOp = Op->Common.Value.Arg;
1152     NextOp = NextOp->Common.Next;
1153     if (!NextOp)
1154     {
1155         return;
1156     }
1157 
1158     /* Set Node and Op to point to each other */
1159 
1160     BufferNode->Op = Op;
1161     Op->Common.Node = BufferNode;
1162 
1163     /*
1164      * Insert each resource into the namespace
1165      * NextOp contains the Aml pointer and the Aml length
1166      */
1167     AcpiUtWalkAmlResources (NULL, (UINT8 *) NextOp->Named.Data,
1168         (ACPI_SIZE) NextOp->Common.Value.Integer,
1169         AcpiDmAddResourceToNamespace, (void **) BufferNode);
1170 }
1171 
1172 
1173 /*******************************************************************************
1174  *
1175  * FUNCTION:    AcpiDmAddResourceToNamespace
1176  *
1177  * PARAMETERS:  ACPI_WALK_AML_CALLBACK
1178  *              BufferNode              - Node for the parent buffer
1179  *
1180  * RETURN:      Status
1181  *
1182  * DESCRIPTION: Add one resource descriptor to the namespace as a child of the
1183  *              parent buffer. The same name is used for each descriptor. This
1184  *              is changed later to a unique name if the resource is actually
1185  *              referenced by an AML operator.
1186  *
1187  ******************************************************************************/
1188 
1189 static ACPI_STATUS
AcpiDmAddResourceToNamespace(UINT8 * Aml,UINT32 Length,UINT32 Offset,UINT8 ResourceIndex,void ** Context)1190 AcpiDmAddResourceToNamespace (
1191     UINT8                   *Aml,
1192     UINT32                  Length,
1193     UINT32                  Offset,
1194     UINT8                   ResourceIndex,
1195     void                    **Context)
1196 {
1197     ACPI_STATUS             Status;
1198     ACPI_GENERIC_STATE      ScopeInfo;
1199     ACPI_NAMESPACE_NODE     *Node;
1200 
1201 
1202     /* TBD: Don't need to add descriptors that have no tags defined? */
1203 
1204     /* Add the resource to the namespace, as child of the buffer */
1205 
1206     ScopeInfo.Scope.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Context);
1207     Status = AcpiNsLookup (&ScopeInfo, "_TMP", ACPI_TYPE_LOCAL_RESOURCE,
1208         ACPI_IMODE_LOAD_PASS2,
1209         ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_PREFIX_IS_SCOPE,
1210         NULL, &Node);
1211     if (ACPI_FAILURE (Status))
1212     {
1213         return (AE_OK);
1214     }
1215 
1216     /* Set the name to the default, changed later if resource is referenced */
1217 
1218     Node->Name.Integer = ACPI_DEFAULT_RESNAME;
1219 
1220     /* Save the offset of the descriptor (within the original buffer) */
1221 
1222     Node->Value = Offset;
1223     Node->Length = Length;
1224     return (AE_OK);
1225 }
1226