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