dmextern.c revision 1.1.1.3 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: dmextern - Support for External() ASL statements
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.3 christos * Copyright (C) 2000 - 2013, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 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 "acnamesp.h"
48 1.1 jruoho #include "acdisasm.h"
49 1.1.1.3 christos #include "aslcompiler.h"
50 1.1.1.3 christos #include <stdio.h>
51 1.1.1.3 christos #include <errno.h>
52 1.1 jruoho
53 1.1 jruoho
54 1.1 jruoho /*
55 1.1 jruoho * This module is used for application-level code (iASL disassembler) only.
56 1.1 jruoho *
57 1.1 jruoho * It contains the code to create and emit any necessary External() ASL
58 1.1 jruoho * statements for the module being disassembled.
59 1.1 jruoho */
60 1.1 jruoho #define _COMPONENT ACPI_CA_DISASSEMBLER
61 1.1 jruoho ACPI_MODULE_NAME ("dmextern")
62 1.1 jruoho
63 1.1 jruoho
64 1.1 jruoho /*
65 1.1 jruoho * This table maps ACPI_OBJECT_TYPEs to the corresponding ASL
66 1.1 jruoho * ObjectTypeKeyword. Used to generate typed external declarations
67 1.1 jruoho */
68 1.1 jruoho static const char *AcpiGbl_DmTypeNames[] =
69 1.1 jruoho {
70 1.1 jruoho /* 00 */ "", /* Type ANY */
71 1.1 jruoho /* 01 */ ", IntObj",
72 1.1 jruoho /* 02 */ ", StrObj",
73 1.1 jruoho /* 03 */ ", BuffObj",
74 1.1 jruoho /* 04 */ ", PkgObj",
75 1.1 jruoho /* 05 */ ", FieldUnitObj",
76 1.1 jruoho /* 06 */ ", DeviceObj",
77 1.1 jruoho /* 07 */ ", EventObj",
78 1.1 jruoho /* 08 */ ", MethodObj",
79 1.1 jruoho /* 09 */ ", MutexObj",
80 1.1 jruoho /* 10 */ ", OpRegionObj",
81 1.1 jruoho /* 11 */ ", PowerResObj",
82 1.1 jruoho /* 12 */ ", ProcessorObj",
83 1.1 jruoho /* 13 */ ", ThermalZoneObj",
84 1.1 jruoho /* 14 */ ", BuffFieldObj",
85 1.1 jruoho /* 15 */ ", DDBHandleObj",
86 1.1 jruoho /* 16 */ "", /* Debug object */
87 1.1 jruoho /* 17 */ ", FieldUnitObj",
88 1.1 jruoho /* 18 */ ", FieldUnitObj",
89 1.1 jruoho /* 19 */ ", FieldUnitObj"
90 1.1 jruoho };
91 1.1 jruoho
92 1.1.1.3 christos #define METHOD_SEPARATORS " \t,()\n"
93 1.1.1.3 christos
94 1.1 jruoho
95 1.1 jruoho /* Local prototypes */
96 1.1 jruoho
97 1.1 jruoho static const char *
98 1.1 jruoho AcpiDmGetObjectTypeName (
99 1.1 jruoho ACPI_OBJECT_TYPE Type);
100 1.1 jruoho
101 1.1 jruoho static char *
102 1.1 jruoho AcpiDmNormalizeParentPrefix (
103 1.1 jruoho ACPI_PARSE_OBJECT *Op,
104 1.1 jruoho char *Path);
105 1.1 jruoho
106 1.1.1.3 christos static void
107 1.1.1.3 christos AcpiDmAddPathToExternalList (
108 1.1.1.3 christos char *Path,
109 1.1.1.3 christos UINT8 Type,
110 1.1.1.3 christos UINT32 Value,
111 1.1.1.3 christos UINT16 Flags);
112 1.1.1.3 christos
113 1.1.1.3 christos static ACPI_STATUS
114 1.1.1.3 christos AcpiDmCreateNewExternal (
115 1.1.1.3 christos char *ExternalPath,
116 1.1.1.3 christos char *InternalPath,
117 1.1.1.3 christos UINT8 Type,
118 1.1.1.3 christos UINT32 Value,
119 1.1.1.3 christos UINT16 Flags);
120 1.1.1.3 christos
121 1.1 jruoho
122 1.1 jruoho /*******************************************************************************
123 1.1 jruoho *
124 1.1 jruoho * FUNCTION: AcpiDmGetObjectTypeName
125 1.1 jruoho *
126 1.1 jruoho * PARAMETERS: Type - An ACPI_OBJECT_TYPE
127 1.1 jruoho *
128 1.1 jruoho * RETURN: Pointer to a string
129 1.1 jruoho *
130 1.1 jruoho * DESCRIPTION: Map an object type to the ASL object type string.
131 1.1 jruoho *
132 1.1 jruoho ******************************************************************************/
133 1.1 jruoho
134 1.1 jruoho static const char *
135 1.1 jruoho AcpiDmGetObjectTypeName (
136 1.1 jruoho ACPI_OBJECT_TYPE Type)
137 1.1 jruoho {
138 1.1 jruoho
139 1.1 jruoho if (Type == ACPI_TYPE_LOCAL_SCOPE)
140 1.1 jruoho {
141 1.1 jruoho Type = ACPI_TYPE_DEVICE;
142 1.1 jruoho }
143 1.1 jruoho
144 1.1 jruoho else if (Type > ACPI_TYPE_LOCAL_INDEX_FIELD)
145 1.1 jruoho {
146 1.1 jruoho return ("");
147 1.1 jruoho }
148 1.1 jruoho
149 1.1 jruoho return (AcpiGbl_DmTypeNames[Type]);
150 1.1 jruoho }
151 1.1 jruoho
152 1.1 jruoho
153 1.1 jruoho /*******************************************************************************
154 1.1 jruoho *
155 1.1 jruoho * FUNCTION: AcpiDmNormalizeParentPrefix
156 1.1 jruoho *
157 1.1 jruoho * PARAMETERS: Op - Parse op
158 1.1 jruoho * Path - Path with parent prefix
159 1.1 jruoho *
160 1.1 jruoho * RETURN: The full pathname to the object (from the namespace root)
161 1.1 jruoho *
162 1.1 jruoho * DESCRIPTION: Returns the full pathname of a path with parent prefix
163 1.1 jruoho * The caller must free the fullpath returned.
164 1.1 jruoho *
165 1.1 jruoho ******************************************************************************/
166 1.1 jruoho
167 1.1 jruoho static char *
168 1.1 jruoho AcpiDmNormalizeParentPrefix (
169 1.1 jruoho ACPI_PARSE_OBJECT *Op,
170 1.1 jruoho char *Path)
171 1.1 jruoho {
172 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
173 1.1 jruoho char *Fullpath;
174 1.1 jruoho char *ParentPath;
175 1.1 jruoho ACPI_SIZE Length;
176 1.1.1.3 christos UINT32 Index = 0;
177 1.1 jruoho
178 1.1 jruoho
179 1.1.1.3 christos if (!Op)
180 1.1.1.3 christos {
181 1.1.1.3 christos return (NULL);
182 1.1.1.3 christos }
183 1.1.1.3 christos
184 1.1.1.3 christos /* Search upwards in the parse tree until we reach the next namespace node */
185 1.1 jruoho
186 1.1.1.3 christos Op = Op->Common.Parent;
187 1.1 jruoho while (Op)
188 1.1 jruoho {
189 1.1 jruoho if (Op->Common.Node)
190 1.1 jruoho {
191 1.1 jruoho break;
192 1.1 jruoho }
193 1.1 jruoho
194 1.1 jruoho Op = Op->Common.Parent;
195 1.1 jruoho }
196 1.1 jruoho
197 1.1 jruoho if (!Op)
198 1.1 jruoho {
199 1.1 jruoho return (NULL);
200 1.1 jruoho }
201 1.1 jruoho
202 1.1 jruoho /*
203 1.1 jruoho * Find the actual parent node for the reference:
204 1.1 jruoho * Remove all carat prefixes from the input path.
205 1.1 jruoho * There may be multiple parent prefixes (For example, ^^^M000)
206 1.1 jruoho */
207 1.1 jruoho Node = Op->Common.Node;
208 1.1 jruoho while (Node && (*Path == (UINT8) AML_PARENT_PREFIX))
209 1.1 jruoho {
210 1.1 jruoho Node = Node->Parent;
211 1.1 jruoho Path++;
212 1.1 jruoho }
213 1.1 jruoho
214 1.1 jruoho if (!Node)
215 1.1 jruoho {
216 1.1 jruoho return (NULL);
217 1.1 jruoho }
218 1.1 jruoho
219 1.1 jruoho /* Get the full pathname for the parent node */
220 1.1 jruoho
221 1.1 jruoho ParentPath = AcpiNsGetExternalPathname (Node);
222 1.1 jruoho if (!ParentPath)
223 1.1 jruoho {
224 1.1 jruoho return (NULL);
225 1.1 jruoho }
226 1.1 jruoho
227 1.1 jruoho Length = (ACPI_STRLEN (ParentPath) + ACPI_STRLEN (Path) + 1);
228 1.1 jruoho if (ParentPath[1])
229 1.1 jruoho {
230 1.1 jruoho /*
231 1.1 jruoho * If ParentPath is not just a simple '\', increment the length
232 1.1 jruoho * for the required dot separator (ParentPath.Path)
233 1.1 jruoho */
234 1.1 jruoho Length++;
235 1.1.1.3 christos
236 1.1.1.3 christos /* For External() statements, we do not want a leading '\' */
237 1.1.1.3 christos
238 1.1.1.3 christos if (*ParentPath == AML_ROOT_PREFIX)
239 1.1.1.3 christos {
240 1.1.1.3 christos Index = 1;
241 1.1.1.3 christos }
242 1.1 jruoho }
243 1.1 jruoho
244 1.1 jruoho Fullpath = ACPI_ALLOCATE_ZEROED (Length);
245 1.1 jruoho if (!Fullpath)
246 1.1 jruoho {
247 1.1 jruoho goto Cleanup;
248 1.1 jruoho }
249 1.1 jruoho
250 1.1 jruoho /*
251 1.1 jruoho * Concatenate parent fullpath and path. For example,
252 1.1 jruoho * parent fullpath "\_SB_", Path "^INIT", Fullpath "\_SB_.INIT"
253 1.1 jruoho *
254 1.1 jruoho * Copy the parent path
255 1.1 jruoho */
256 1.1.1.3 christos ACPI_STRCPY (Fullpath, &ParentPath[Index]);
257 1.1 jruoho
258 1.1.1.3 christos /*
259 1.1.1.3 christos * Add dot separator
260 1.1.1.3 christos * (don't need dot if parent fullpath is a single backslash)
261 1.1.1.3 christos */
262 1.1 jruoho if (ParentPath[1])
263 1.1 jruoho {
264 1.1 jruoho ACPI_STRCAT (Fullpath, ".");
265 1.1 jruoho }
266 1.1 jruoho
267 1.1 jruoho /* Copy child path (carat parent prefix(es) were skipped above) */
268 1.1 jruoho
269 1.1 jruoho ACPI_STRCAT (Fullpath, Path);
270 1.1 jruoho
271 1.1 jruoho Cleanup:
272 1.1 jruoho ACPI_FREE (ParentPath);
273 1.1 jruoho return (Fullpath);
274 1.1 jruoho }
275 1.1 jruoho
276 1.1 jruoho
277 1.1 jruoho /*******************************************************************************
278 1.1 jruoho *
279 1.1.1.2 jruoho * FUNCTION: AcpiDmAddToExternalFileList
280 1.1.1.2 jruoho *
281 1.1.1.2 jruoho * PARAMETERS: PathList - Single path or list separated by comma
282 1.1.1.2 jruoho *
283 1.1.1.2 jruoho * RETURN: None
284 1.1.1.2 jruoho *
285 1.1.1.2 jruoho * DESCRIPTION: Add external files to global list
286 1.1.1.2 jruoho *
287 1.1.1.2 jruoho ******************************************************************************/
288 1.1.1.2 jruoho
289 1.1.1.2 jruoho ACPI_STATUS
290 1.1.1.2 jruoho AcpiDmAddToExternalFileList (
291 1.1.1.3 christos char *Pathname)
292 1.1.1.2 jruoho {
293 1.1.1.2 jruoho ACPI_EXTERNAL_FILE *ExternalFile;
294 1.1.1.3 christos char *LocalPathname;
295 1.1.1.2 jruoho
296 1.1.1.2 jruoho
297 1.1.1.3 christos if (!Pathname)
298 1.1.1.2 jruoho {
299 1.1.1.2 jruoho return (AE_OK);
300 1.1.1.2 jruoho }
301 1.1.1.2 jruoho
302 1.1.1.3 christos LocalPathname = ACPI_ALLOCATE (strlen (Pathname) + 1);
303 1.1.1.3 christos if (!LocalPathname)
304 1.1.1.2 jruoho {
305 1.1.1.3 christos return (AE_NO_MEMORY);
306 1.1.1.3 christos }
307 1.1.1.2 jruoho
308 1.1.1.3 christos ExternalFile = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EXTERNAL_FILE));
309 1.1.1.3 christos if (!ExternalFile)
310 1.1.1.3 christos {
311 1.1.1.3 christos ACPI_FREE (LocalPathname);
312 1.1.1.3 christos return (AE_NO_MEMORY);
313 1.1.1.3 christos }
314 1.1.1.2 jruoho
315 1.1.1.3 christos /* Take a copy of the file pathname */
316 1.1.1.2 jruoho
317 1.1.1.3 christos strcpy (LocalPathname, Pathname);
318 1.1.1.3 christos ExternalFile->Path = LocalPathname;
319 1.1.1.2 jruoho
320 1.1.1.3 christos if (AcpiGbl_ExternalFileList)
321 1.1.1.3 christos {
322 1.1.1.3 christos ExternalFile->Next = AcpiGbl_ExternalFileList;
323 1.1.1.2 jruoho }
324 1.1.1.2 jruoho
325 1.1.1.3 christos AcpiGbl_ExternalFileList = ExternalFile;
326 1.1.1.2 jruoho return (AE_OK);
327 1.1.1.2 jruoho }
328 1.1.1.2 jruoho
329 1.1.1.2 jruoho
330 1.1.1.2 jruoho /*******************************************************************************
331 1.1.1.2 jruoho *
332 1.1.1.2 jruoho * FUNCTION: AcpiDmClearExternalFileList
333 1.1.1.2 jruoho *
334 1.1.1.2 jruoho * PARAMETERS: None
335 1.1.1.2 jruoho *
336 1.1.1.2 jruoho * RETURN: None
337 1.1.1.2 jruoho *
338 1.1.1.2 jruoho * DESCRIPTION: Clear the external file list
339 1.1.1.2 jruoho *
340 1.1.1.2 jruoho ******************************************************************************/
341 1.1.1.2 jruoho
342 1.1.1.2 jruoho void
343 1.1.1.2 jruoho AcpiDmClearExternalFileList (
344 1.1.1.2 jruoho void)
345 1.1.1.2 jruoho {
346 1.1.1.2 jruoho ACPI_EXTERNAL_FILE *NextExternal;
347 1.1.1.2 jruoho
348 1.1.1.2 jruoho
349 1.1.1.2 jruoho while (AcpiGbl_ExternalFileList)
350 1.1.1.2 jruoho {
351 1.1.1.2 jruoho NextExternal = AcpiGbl_ExternalFileList->Next;
352 1.1.1.2 jruoho ACPI_FREE (AcpiGbl_ExternalFileList->Path);
353 1.1.1.2 jruoho ACPI_FREE (AcpiGbl_ExternalFileList);
354 1.1.1.2 jruoho AcpiGbl_ExternalFileList = NextExternal;
355 1.1.1.2 jruoho }
356 1.1.1.2 jruoho }
357 1.1.1.2 jruoho
358 1.1.1.2 jruoho
359 1.1.1.2 jruoho /*******************************************************************************
360 1.1.1.2 jruoho *
361 1.1.1.3 christos * FUNCTION: AcpiDmGetExternalsFromFile
362 1.1.1.3 christos *
363 1.1.1.3 christos * PARAMETERS: None
364 1.1.1.3 christos *
365 1.1.1.3 christos * RETURN: None
366 1.1.1.3 christos *
367 1.1.1.3 christos * DESCRIPTION: Process the optional external reference file.
368 1.1.1.3 christos *
369 1.1.1.3 christos * Each line in the file should be of the form:
370 1.1.1.3 christos * External (<Method namepath>, MethodObj, <ArgCount>)
371 1.1.1.3 christos *
372 1.1.1.3 christos * Example:
373 1.1.1.3 christos * External (_SB_.PCI0.XHC_.PS0X, MethodObj, 4)
374 1.1.1.3 christos *
375 1.1.1.3 christos ******************************************************************************/
376 1.1.1.3 christos
377 1.1.1.3 christos void
378 1.1.1.3 christos AcpiDmGetExternalsFromFile (
379 1.1.1.3 christos void)
380 1.1.1.3 christos {
381 1.1.1.3 christos FILE *ExternalRefFile;
382 1.1.1.3 christos char *Token;
383 1.1.1.3 christos char *MethodName;
384 1.1.1.3 christos UINT32 ArgCount;
385 1.1.1.3 christos UINT32 ImportCount = 0;
386 1.1.1.3 christos
387 1.1.1.3 christos
388 1.1.1.3 christos if (!Gbl_ExternalRefFilename)
389 1.1.1.3 christos {
390 1.1.1.3 christos return;
391 1.1.1.3 christos }
392 1.1.1.3 christos
393 1.1.1.3 christos /* Open the file */
394 1.1.1.3 christos
395 1.1.1.3 christos ExternalRefFile = fopen (Gbl_ExternalRefFilename, "r");
396 1.1.1.3 christos if (!ExternalRefFile)
397 1.1.1.3 christos {
398 1.1.1.3 christos fprintf (stderr, "Could not open external reference file \"%s\"\n",
399 1.1.1.3 christos Gbl_ExternalRefFilename);
400 1.1.1.3 christos return;
401 1.1.1.3 christos }
402 1.1.1.3 christos
403 1.1.1.3 christos /* Each line defines a method */
404 1.1.1.3 christos
405 1.1.1.3 christos while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ExternalRefFile))
406 1.1.1.3 christos {
407 1.1.1.3 christos Token = strtok (StringBuffer, METHOD_SEPARATORS); /* "External" */
408 1.1.1.3 christos if (!Token) continue;
409 1.1.1.3 christos if (strcmp (Token, "External")) continue;
410 1.1.1.3 christos
411 1.1.1.3 christos MethodName = strtok (NULL, METHOD_SEPARATORS); /* Method namepath */
412 1.1.1.3 christos if (!MethodName) continue;
413 1.1.1.3 christos
414 1.1.1.3 christos Token = strtok (NULL, METHOD_SEPARATORS); /* "MethodObj" */
415 1.1.1.3 christos if (!Token) continue;
416 1.1.1.3 christos if (strcmp (Token, "MethodObj")) continue;
417 1.1.1.3 christos
418 1.1.1.3 christos Token = strtok (NULL, METHOD_SEPARATORS); /* Arg count */
419 1.1.1.3 christos if (!Token) continue;
420 1.1.1.3 christos
421 1.1.1.3 christos /* Convert arg count string to an integer */
422 1.1.1.3 christos
423 1.1.1.3 christos errno = 0;
424 1.1.1.3 christos ArgCount = strtoul (Token, NULL, 0);
425 1.1.1.3 christos if (errno)
426 1.1.1.3 christos {
427 1.1.1.3 christos fprintf (stderr, "Invalid argument count (%s)\n", Token);
428 1.1.1.3 christos continue;
429 1.1.1.3 christos }
430 1.1.1.3 christos if (ArgCount > 7)
431 1.1.1.3 christos {
432 1.1.1.3 christos fprintf (stderr, "Invalid argument count (%u)\n", ArgCount);
433 1.1.1.3 christos continue;
434 1.1.1.3 christos }
435 1.1.1.3 christos
436 1.1.1.3 christos /* Add this external to the global list */
437 1.1.1.3 christos
438 1.1.1.3 christos AcpiOsPrintf ("%s: Importing method external (%u arguments) %s\n",
439 1.1.1.3 christos Gbl_ExternalRefFilename, ArgCount, MethodName);
440 1.1.1.3 christos
441 1.1.1.3 christos AcpiDmAddPathToExternalList (MethodName, ACPI_TYPE_METHOD,
442 1.1.1.3 christos ArgCount, (ACPI_EXT_RESOLVED_REFERENCE | ACPI_EXT_ORIGIN_FROM_FILE));
443 1.1.1.3 christos ImportCount++;
444 1.1.1.3 christos }
445 1.1.1.3 christos
446 1.1.1.3 christos if (!ImportCount)
447 1.1.1.3 christos {
448 1.1.1.3 christos fprintf (stderr, "Did not find any external methods in reference file \"%s\"\n",
449 1.1.1.3 christos Gbl_ExternalRefFilename);
450 1.1.1.3 christos }
451 1.1.1.3 christos else
452 1.1.1.3 christos {
453 1.1.1.3 christos /* Add the external(s) to the namespace */
454 1.1.1.3 christos
455 1.1.1.3 christos AcpiDmAddExternalsToNamespace ();
456 1.1.1.3 christos
457 1.1.1.3 christos AcpiOsPrintf ("%s: Imported %u external method definitions\n",
458 1.1.1.3 christos Gbl_ExternalRefFilename, ImportCount);
459 1.1.1.3 christos }
460 1.1.1.3 christos
461 1.1.1.3 christos fclose (ExternalRefFile);
462 1.1.1.3 christos }
463 1.1.1.3 christos
464 1.1.1.3 christos
465 1.1.1.3 christos /*******************************************************************************
466 1.1.1.3 christos *
467 1.1.1.3 christos * FUNCTION: AcpiDmAddOpToExternalList
468 1.1 jruoho *
469 1.1 jruoho * PARAMETERS: Op - Current parser Op
470 1.1 jruoho * Path - Internal (AML) path to the object
471 1.1 jruoho * Type - ACPI object type to be added
472 1.1 jruoho * Value - Arg count if adding a Method object
473 1.1.1.3 christos * Flags - To be passed to the external object
474 1.1 jruoho *
475 1.1 jruoho * RETURN: None
476 1.1 jruoho *
477 1.1 jruoho * DESCRIPTION: Insert a new name into the global list of Externals which
478 1.1 jruoho * will in turn be later emitted as an External() declaration
479 1.1 jruoho * in the disassembled output.
480 1.1 jruoho *
481 1.1.1.3 christos * This function handles the most common case where the referenced
482 1.1.1.3 christos * name is simply not found in the constructed namespace.
483 1.1.1.3 christos *
484 1.1 jruoho ******************************************************************************/
485 1.1 jruoho
486 1.1 jruoho void
487 1.1.1.3 christos AcpiDmAddOpToExternalList (
488 1.1 jruoho ACPI_PARSE_OBJECT *Op,
489 1.1 jruoho char *Path,
490 1.1 jruoho UINT8 Type,
491 1.1.1.3 christos UINT32 Value,
492 1.1.1.3 christos UINT16 Flags)
493 1.1 jruoho {
494 1.1 jruoho char *ExternalPath;
495 1.1.1.3 christos char *InternalPath = Path;
496 1.1.1.3 christos char *Temp;
497 1.1 jruoho ACPI_STATUS Status;
498 1.1 jruoho
499 1.1 jruoho
500 1.1.1.3 christos ACPI_FUNCTION_TRACE (DmAddOpToExternalList);
501 1.1.1.3 christos
502 1.1.1.3 christos
503 1.1 jruoho if (!Path)
504 1.1 jruoho {
505 1.1.1.3 christos return_VOID;
506 1.1.1.3 christos }
507 1.1.1.3 christos
508 1.1.1.3 christos /* Remove a root backslash if present */
509 1.1.1.3 christos
510 1.1.1.3 christos if ((*Path == AML_ROOT_PREFIX) && (Path[1]))
511 1.1.1.3 christos {
512 1.1.1.3 christos Path++;
513 1.1 jruoho }
514 1.1 jruoho
515 1.1.1.3 christos /* Externalize the pathname */
516 1.1 jruoho
517 1.1 jruoho Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, Path,
518 1.1.1.3 christos NULL, &ExternalPath);
519 1.1 jruoho if (ACPI_FAILURE (Status))
520 1.1 jruoho {
521 1.1.1.3 christos return_VOID;
522 1.1 jruoho }
523 1.1 jruoho
524 1.1.1.3 christos /*
525 1.1.1.3 christos * Get the full pathname from the root if "Path" has one or more
526 1.1.1.3 christos * parent prefixes (^). Note: path will not contain a leading '\'.
527 1.1.1.3 christos */
528 1.1 jruoho if (*Path == (UINT8) AML_PARENT_PREFIX)
529 1.1 jruoho {
530 1.1.1.3 christos Temp = AcpiDmNormalizeParentPrefix (Op, ExternalPath);
531 1.1.1.3 christos
532 1.1.1.3 christos /* Set new external path */
533 1.1.1.3 christos
534 1.1.1.3 christos ACPI_FREE (ExternalPath);
535 1.1.1.3 christos ExternalPath = Temp;
536 1.1.1.3 christos if (!Temp)
537 1.1 jruoho {
538 1.1.1.3 christos return_VOID;
539 1.1.1.3 christos }
540 1.1.1.3 christos
541 1.1.1.3 christos /* Create the new internal pathname */
542 1.1 jruoho
543 1.1.1.3 christos Flags |= ACPI_EXT_INTERNAL_PATH_ALLOCATED;
544 1.1.1.3 christos Status = AcpiNsInternalizeName (ExternalPath, &InternalPath);
545 1.1.1.3 christos if (ACPI_FAILURE (Status))
546 1.1.1.3 christos {
547 1.1 jruoho ACPI_FREE (ExternalPath);
548 1.1.1.3 christos return_VOID;
549 1.1.1.3 christos }
550 1.1.1.3 christos }
551 1.1.1.3 christos
552 1.1.1.3 christos /* Create the new External() declaration node */
553 1.1.1.3 christos
554 1.1.1.3 christos Status = AcpiDmCreateNewExternal (ExternalPath, InternalPath,
555 1.1.1.3 christos Type, Value, Flags);
556 1.1.1.3 christos if (ACPI_FAILURE (Status))
557 1.1.1.3 christos {
558 1.1.1.3 christos ACPI_FREE (ExternalPath);
559 1.1.1.3 christos if (Flags & ACPI_EXT_INTERNAL_PATH_ALLOCATED)
560 1.1.1.3 christos {
561 1.1.1.3 christos ACPI_FREE (InternalPath);
562 1.1 jruoho }
563 1.1 jruoho }
564 1.1 jruoho
565 1.1.1.3 christos return_VOID;
566 1.1.1.3 christos }
567 1.1.1.3 christos
568 1.1.1.3 christos
569 1.1.1.3 christos /*******************************************************************************
570 1.1.1.3 christos *
571 1.1.1.3 christos * FUNCTION: AcpiDmAddNodeToExternalList
572 1.1.1.3 christos *
573 1.1.1.3 christos * PARAMETERS: Node - Namespace node for object to be added
574 1.1.1.3 christos * Type - ACPI object type to be added
575 1.1.1.3 christos * Value - Arg count if adding a Method object
576 1.1.1.3 christos * Flags - To be passed to the external object
577 1.1.1.3 christos *
578 1.1.1.3 christos * RETURN: None
579 1.1.1.3 christos *
580 1.1.1.3 christos * DESCRIPTION: Insert a new name into the global list of Externals which
581 1.1.1.3 christos * will in turn be later emitted as an External() declaration
582 1.1.1.3 christos * in the disassembled output.
583 1.1.1.3 christos *
584 1.1.1.3 christos * This function handles the case where the referenced name has
585 1.1.1.3 christos * been found in the namespace, but the name originated in a
586 1.1.1.3 christos * table other than the one that is being disassembled (such
587 1.1.1.3 christos * as a table that is added via the iASL -e option).
588 1.1.1.3 christos *
589 1.1.1.3 christos ******************************************************************************/
590 1.1.1.3 christos
591 1.1.1.3 christos void
592 1.1.1.3 christos AcpiDmAddNodeToExternalList (
593 1.1.1.3 christos ACPI_NAMESPACE_NODE *Node,
594 1.1.1.3 christos UINT8 Type,
595 1.1.1.3 christos UINT32 Value,
596 1.1.1.3 christos UINT16 Flags)
597 1.1.1.3 christos {
598 1.1.1.3 christos char *ExternalPath;
599 1.1.1.3 christos char *InternalPath;
600 1.1.1.3 christos char *Temp;
601 1.1.1.3 christos ACPI_STATUS Status;
602 1.1.1.3 christos
603 1.1.1.3 christos
604 1.1.1.3 christos ACPI_FUNCTION_TRACE (DmAddNodeToExternalList);
605 1.1.1.3 christos
606 1.1.1.3 christos
607 1.1.1.3 christos if (!Node)
608 1.1.1.3 christos {
609 1.1.1.3 christos return_VOID;
610 1.1.1.3 christos }
611 1.1.1.3 christos
612 1.1.1.3 christos /* Get the full external and internal pathnames to the node */
613 1.1.1.3 christos
614 1.1.1.3 christos ExternalPath = AcpiNsGetExternalPathname (Node);
615 1.1.1.3 christos if (!ExternalPath)
616 1.1.1.3 christos {
617 1.1.1.3 christos return_VOID;
618 1.1.1.3 christos }
619 1.1.1.3 christos
620 1.1.1.3 christos Status = AcpiNsInternalizeName (ExternalPath, &InternalPath);
621 1.1.1.3 christos if (ACPI_FAILURE (Status))
622 1.1.1.3 christos {
623 1.1.1.3 christos ACPI_FREE (ExternalPath);
624 1.1.1.3 christos return_VOID;
625 1.1.1.3 christos }
626 1.1.1.3 christos
627 1.1.1.3 christos /* Remove the root backslash */
628 1.1.1.3 christos
629 1.1.1.3 christos if ((*ExternalPath == AML_ROOT_PREFIX) && (ExternalPath[1]))
630 1.1.1.3 christos {
631 1.1.1.3 christos Temp = ACPI_ALLOCATE_ZEROED (ACPI_STRLEN (ExternalPath) + 1);
632 1.1.1.3 christos if (!Temp)
633 1.1.1.3 christos {
634 1.1.1.3 christos return_VOID;
635 1.1.1.3 christos }
636 1.1.1.3 christos
637 1.1.1.3 christos ACPI_STRCPY (Temp, &ExternalPath[1]);
638 1.1.1.3 christos ACPI_FREE (ExternalPath);
639 1.1.1.3 christos ExternalPath = Temp;
640 1.1.1.3 christos }
641 1.1.1.3 christos
642 1.1.1.3 christos /* Create the new External() declaration node */
643 1.1.1.3 christos
644 1.1.1.3 christos Status = AcpiDmCreateNewExternal (ExternalPath, InternalPath, Type,
645 1.1.1.3 christos Value, (Flags | ACPI_EXT_INTERNAL_PATH_ALLOCATED));
646 1.1.1.3 christos if (ACPI_FAILURE (Status))
647 1.1.1.3 christos {
648 1.1.1.3 christos ACPI_FREE (ExternalPath);
649 1.1.1.3 christos ACPI_FREE (InternalPath);
650 1.1.1.3 christos }
651 1.1.1.3 christos
652 1.1.1.3 christos return_VOID;
653 1.1.1.3 christos }
654 1.1.1.3 christos
655 1.1.1.3 christos
656 1.1.1.3 christos /*******************************************************************************
657 1.1.1.3 christos *
658 1.1.1.3 christos * FUNCTION: AcpiDmAddPathToExternalList
659 1.1.1.3 christos *
660 1.1.1.3 christos * PARAMETERS: Path - External name of the object to be added
661 1.1.1.3 christos * Type - ACPI object type to be added
662 1.1.1.3 christos * Value - Arg count if adding a Method object
663 1.1.1.3 christos * Flags - To be passed to the external object
664 1.1.1.3 christos *
665 1.1.1.3 christos * RETURN: None
666 1.1.1.3 christos *
667 1.1.1.3 christos * DESCRIPTION: Insert a new name into the global list of Externals which
668 1.1.1.3 christos * will in turn be later emitted as an External() declaration
669 1.1.1.3 christos * in the disassembled output.
670 1.1.1.3 christos *
671 1.1.1.3 christos * This function currently is used to add externals via a
672 1.1.1.3 christos * reference file (via the -fe iASL option).
673 1.1.1.3 christos *
674 1.1.1.3 christos ******************************************************************************/
675 1.1.1.3 christos
676 1.1.1.3 christos static void
677 1.1.1.3 christos AcpiDmAddPathToExternalList (
678 1.1.1.3 christos char *Path,
679 1.1.1.3 christos UINT8 Type,
680 1.1.1.3 christos UINT32 Value,
681 1.1.1.3 christos UINT16 Flags)
682 1.1.1.3 christos {
683 1.1.1.3 christos char *InternalPath;
684 1.1.1.3 christos char *ExternalPath;
685 1.1.1.3 christos ACPI_STATUS Status;
686 1.1.1.3 christos
687 1.1.1.3 christos
688 1.1.1.3 christos ACPI_FUNCTION_TRACE (DmAddPathToExternalList);
689 1.1.1.3 christos
690 1.1.1.3 christos
691 1.1.1.3 christos if (!Path)
692 1.1.1.3 christos {
693 1.1.1.3 christos return_VOID;
694 1.1.1.3 christos }
695 1.1.1.3 christos
696 1.1.1.3 christos /* Remove a root backslash if present */
697 1.1.1.3 christos
698 1.1.1.3 christos if ((*Path == AML_ROOT_PREFIX) && (Path[1]))
699 1.1.1.3 christos {
700 1.1.1.3 christos Path++;
701 1.1.1.3 christos }
702 1.1.1.3 christos
703 1.1.1.3 christos /* Create the internal and external pathnames */
704 1.1.1.3 christos
705 1.1.1.3 christos Status = AcpiNsInternalizeName (Path, &InternalPath);
706 1.1.1.3 christos if (ACPI_FAILURE (Status))
707 1.1.1.3 christos {
708 1.1.1.3 christos return_VOID;
709 1.1.1.3 christos }
710 1.1.1.3 christos
711 1.1.1.3 christos Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, InternalPath,
712 1.1.1.3 christos NULL, &ExternalPath);
713 1.1.1.3 christos if (ACPI_FAILURE (Status))
714 1.1.1.3 christos {
715 1.1.1.3 christos ACPI_FREE (InternalPath);
716 1.1.1.3 christos return_VOID;
717 1.1.1.3 christos }
718 1.1.1.3 christos
719 1.1.1.3 christos /* Create the new External() declaration node */
720 1.1.1.3 christos
721 1.1.1.3 christos Status = AcpiDmCreateNewExternal (ExternalPath, InternalPath,
722 1.1.1.3 christos Type, Value, (Flags | ACPI_EXT_INTERNAL_PATH_ALLOCATED));
723 1.1.1.3 christos if (ACPI_FAILURE (Status))
724 1.1.1.3 christos {
725 1.1.1.3 christos ACPI_FREE (ExternalPath);
726 1.1.1.3 christos ACPI_FREE (InternalPath);
727 1.1.1.3 christos }
728 1.1.1.3 christos
729 1.1.1.3 christos return_VOID;
730 1.1.1.3 christos }
731 1.1.1.3 christos
732 1.1.1.3 christos
733 1.1.1.3 christos /*******************************************************************************
734 1.1.1.3 christos *
735 1.1.1.3 christos * FUNCTION: AcpiDmCreateNewExternal
736 1.1.1.3 christos *
737 1.1.1.3 christos * PARAMETERS: ExternalPath - External path to the object
738 1.1.1.3 christos * InternalPath - Internal (AML) path to the object
739 1.1.1.3 christos * Type - ACPI object type to be added
740 1.1.1.3 christos * Value - Arg count if adding a Method object
741 1.1.1.3 christos * Flags - To be passed to the external object
742 1.1.1.3 christos *
743 1.1.1.3 christos * RETURN: Status
744 1.1.1.3 christos *
745 1.1.1.3 christos * DESCRIPTION: Common low-level function to insert a new name into the global
746 1.1.1.3 christos * list of Externals which will in turn be later emitted as
747 1.1.1.3 christos * External() declarations in the disassembled output.
748 1.1.1.3 christos *
749 1.1.1.3 christos * Note: The external name should not include a root prefix
750 1.1.1.3 christos * (backslash). We do not want External() statements to contain
751 1.1.1.3 christos * a leading '\', as this prevents duplicate external statements
752 1.1.1.3 christos * of the form:
753 1.1.1.3 christos *
754 1.1.1.3 christos * External (\ABCD)
755 1.1.1.3 christos * External (ABCD)
756 1.1.1.3 christos *
757 1.1.1.3 christos * This would cause a compile time error when the disassembled
758 1.1.1.3 christos * output file is recompiled.
759 1.1.1.3 christos *
760 1.1.1.3 christos * There are two cases that are handled here. For both, we emit
761 1.1.1.3 christos * an External() statement:
762 1.1.1.3 christos * 1) The name was simply not found in the namespace.
763 1.1.1.3 christos * 2) The name was found, but it originated in a table other than
764 1.1.1.3 christos * the table that is being disassembled.
765 1.1.1.3 christos *
766 1.1.1.3 christos ******************************************************************************/
767 1.1.1.3 christos
768 1.1.1.3 christos static ACPI_STATUS
769 1.1.1.3 christos AcpiDmCreateNewExternal (
770 1.1.1.3 christos char *ExternalPath,
771 1.1.1.3 christos char *InternalPath,
772 1.1.1.3 christos UINT8 Type,
773 1.1.1.3 christos UINT32 Value,
774 1.1.1.3 christos UINT16 Flags)
775 1.1.1.3 christos {
776 1.1.1.3 christos ACPI_EXTERNAL_LIST *NewExternal;
777 1.1.1.3 christos ACPI_EXTERNAL_LIST *NextExternal;
778 1.1.1.3 christos ACPI_EXTERNAL_LIST *PrevExternal = NULL;
779 1.1.1.3 christos
780 1.1.1.3 christos
781 1.1.1.3 christos ACPI_FUNCTION_TRACE (DmCreateNewExternal);
782 1.1.1.3 christos
783 1.1.1.3 christos
784 1.1 jruoho /* Check all existing externals to ensure no duplicates */
785 1.1 jruoho
786 1.1 jruoho NextExternal = AcpiGbl_ExternalList;
787 1.1 jruoho while (NextExternal)
788 1.1 jruoho {
789 1.1 jruoho if (!ACPI_STRCMP (ExternalPath, NextExternal->Path))
790 1.1 jruoho {
791 1.1 jruoho /* Duplicate method, check that the Value (ArgCount) is the same */
792 1.1 jruoho
793 1.1 jruoho if ((NextExternal->Type == ACPI_TYPE_METHOD) &&
794 1.1 jruoho (NextExternal->Value != Value))
795 1.1 jruoho {
796 1.1 jruoho ACPI_ERROR ((AE_INFO,
797 1.1.1.3 christos "External method arg count mismatch %s: Current %u, attempted %u",
798 1.1 jruoho NextExternal->Path, NextExternal->Value, Value));
799 1.1 jruoho }
800 1.1 jruoho
801 1.1 jruoho /* Allow upgrade of type from ANY */
802 1.1 jruoho
803 1.1 jruoho else if (NextExternal->Type == ACPI_TYPE_ANY)
804 1.1 jruoho {
805 1.1 jruoho NextExternal->Type = Type;
806 1.1 jruoho NextExternal->Value = Value;
807 1.1 jruoho }
808 1.1 jruoho
809 1.1.1.3 christos return_ACPI_STATUS (AE_ALREADY_EXISTS);
810 1.1 jruoho }
811 1.1 jruoho
812 1.1 jruoho NextExternal = NextExternal->Next;
813 1.1 jruoho }
814 1.1 jruoho
815 1.1 jruoho /* Allocate and init a new External() descriptor */
816 1.1 jruoho
817 1.1 jruoho NewExternal = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EXTERNAL_LIST));
818 1.1 jruoho if (!NewExternal)
819 1.1 jruoho {
820 1.1.1.3 christos return_ACPI_STATUS (AE_NO_MEMORY);
821 1.1 jruoho }
822 1.1 jruoho
823 1.1.1.3 christos ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
824 1.1.1.3 christos "Adding external reference node (%s) type [%s]\n",
825 1.1.1.3 christos ExternalPath, AcpiUtGetTypeName (Type)));
826 1.1.1.3 christos
827 1.1.1.3 christos NewExternal->Flags = Flags;
828 1.1.1.3 christos NewExternal->Value = Value;
829 1.1 jruoho NewExternal->Path = ExternalPath;
830 1.1 jruoho NewExternal->Type = Type;
831 1.1 jruoho NewExternal->Length = (UINT16) ACPI_STRLEN (ExternalPath);
832 1.1.1.3 christos NewExternal->InternalPath = InternalPath;
833 1.1 jruoho
834 1.1.1.3 christos /* Link the new descriptor into the global list, alphabetically ordered */
835 1.1 jruoho
836 1.1 jruoho NextExternal = AcpiGbl_ExternalList;
837 1.1 jruoho while (NextExternal)
838 1.1 jruoho {
839 1.1.1.3 christos if (AcpiUtStricmp (NewExternal->Path, NextExternal->Path) < 0)
840 1.1 jruoho {
841 1.1 jruoho if (PrevExternal)
842 1.1 jruoho {
843 1.1 jruoho PrevExternal->Next = NewExternal;
844 1.1 jruoho }
845 1.1 jruoho else
846 1.1 jruoho {
847 1.1 jruoho AcpiGbl_ExternalList = NewExternal;
848 1.1 jruoho }
849 1.1 jruoho
850 1.1 jruoho NewExternal->Next = NextExternal;
851 1.1.1.3 christos return_ACPI_STATUS (AE_OK);
852 1.1 jruoho }
853 1.1 jruoho
854 1.1 jruoho PrevExternal = NextExternal;
855 1.1 jruoho NextExternal = NextExternal->Next;
856 1.1 jruoho }
857 1.1 jruoho
858 1.1 jruoho if (PrevExternal)
859 1.1 jruoho {
860 1.1 jruoho PrevExternal->Next = NewExternal;
861 1.1 jruoho }
862 1.1 jruoho else
863 1.1 jruoho {
864 1.1 jruoho AcpiGbl_ExternalList = NewExternal;
865 1.1 jruoho }
866 1.1.1.3 christos
867 1.1.1.3 christos return_ACPI_STATUS (AE_OK);
868 1.1 jruoho }
869 1.1 jruoho
870 1.1 jruoho
871 1.1 jruoho /*******************************************************************************
872 1.1 jruoho *
873 1.1 jruoho * FUNCTION: AcpiDmAddExternalsToNamespace
874 1.1 jruoho *
875 1.1 jruoho * PARAMETERS: None
876 1.1 jruoho *
877 1.1 jruoho * RETURN: None
878 1.1 jruoho *
879 1.1 jruoho * DESCRIPTION: Add all externals to the namespace. Allows externals to be
880 1.1 jruoho * "resolved".
881 1.1 jruoho *
882 1.1 jruoho ******************************************************************************/
883 1.1 jruoho
884 1.1 jruoho void
885 1.1 jruoho AcpiDmAddExternalsToNamespace (
886 1.1 jruoho void)
887 1.1 jruoho {
888 1.1 jruoho ACPI_STATUS Status;
889 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
890 1.1.1.3 christos ACPI_OPERAND_OBJECT *ObjDesc;
891 1.1 jruoho ACPI_EXTERNAL_LIST *External = AcpiGbl_ExternalList;
892 1.1 jruoho
893 1.1 jruoho
894 1.1 jruoho while (External)
895 1.1 jruoho {
896 1.1 jruoho /* Add the external name (object) into the namespace */
897 1.1 jruoho
898 1.1 jruoho Status = AcpiNsLookup (NULL, External->InternalPath, External->Type,
899 1.1 jruoho ACPI_IMODE_LOAD_PASS1,
900 1.1.1.3 christos ACPI_NS_ERROR_IF_FOUND | ACPI_NS_EXTERNAL | ACPI_NS_DONT_OPEN_SCOPE,
901 1.1 jruoho NULL, &Node);
902 1.1 jruoho
903 1.1 jruoho if (ACPI_FAILURE (Status))
904 1.1 jruoho {
905 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
906 1.1 jruoho "while adding external to namespace [%s]",
907 1.1 jruoho External->Path));
908 1.1 jruoho }
909 1.1.1.3 christos
910 1.1.1.3 christos else switch (External->Type)
911 1.1 jruoho {
912 1.1.1.3 christos case ACPI_TYPE_METHOD:
913 1.1.1.3 christos
914 1.1 jruoho /* For methods, we need to save the argument count */
915 1.1 jruoho
916 1.1.1.3 christos ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
917 1.1.1.3 christos ObjDesc->Method.ParamCount = (UINT8) External->Value;
918 1.1.1.3 christos Node->Object = ObjDesc;
919 1.1.1.3 christos break;
920 1.1.1.3 christos
921 1.1.1.3 christos case ACPI_TYPE_REGION:
922 1.1.1.3 christos
923 1.1.1.3 christos /* Regions require a region sub-object */
924 1.1.1.3 christos
925 1.1.1.3 christos ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
926 1.1.1.3 christos ObjDesc->Region.Node = Node;
927 1.1.1.3 christos Node->Object = ObjDesc;
928 1.1.1.3 christos break;
929 1.1.1.3 christos
930 1.1.1.3 christos default:
931 1.1.1.3 christos
932 1.1.1.3 christos break;
933 1.1 jruoho }
934 1.1 jruoho
935 1.1 jruoho External = External->Next;
936 1.1 jruoho }
937 1.1 jruoho }
938 1.1 jruoho
939 1.1 jruoho
940 1.1 jruoho /*******************************************************************************
941 1.1 jruoho *
942 1.1 jruoho * FUNCTION: AcpiDmGetExternalMethodCount
943 1.1 jruoho *
944 1.1 jruoho * PARAMETERS: None
945 1.1 jruoho *
946 1.1 jruoho * RETURN: The number of control method externals in the external list
947 1.1 jruoho *
948 1.1 jruoho * DESCRIPTION: Return the number of method externals that have been generated.
949 1.1 jruoho * If any control method externals have been found, we must
950 1.1 jruoho * re-parse the entire definition block with the new information
951 1.1 jruoho * (number of arguments for the methods.) This is limitation of
952 1.1 jruoho * AML, we don't know the number of arguments from the control
953 1.1 jruoho * method invocation itself.
954 1.1 jruoho *
955 1.1 jruoho ******************************************************************************/
956 1.1 jruoho
957 1.1 jruoho UINT32
958 1.1 jruoho AcpiDmGetExternalMethodCount (
959 1.1 jruoho void)
960 1.1 jruoho {
961 1.1 jruoho ACPI_EXTERNAL_LIST *External = AcpiGbl_ExternalList;
962 1.1 jruoho UINT32 Count = 0;
963 1.1 jruoho
964 1.1 jruoho
965 1.1 jruoho while (External)
966 1.1 jruoho {
967 1.1 jruoho if (External->Type == ACPI_TYPE_METHOD)
968 1.1 jruoho {
969 1.1 jruoho Count++;
970 1.1 jruoho }
971 1.1 jruoho
972 1.1 jruoho External = External->Next;
973 1.1 jruoho }
974 1.1 jruoho
975 1.1 jruoho return (Count);
976 1.1 jruoho }
977 1.1 jruoho
978 1.1 jruoho
979 1.1 jruoho /*******************************************************************************
980 1.1 jruoho *
981 1.1 jruoho * FUNCTION: AcpiDmClearExternalList
982 1.1 jruoho *
983 1.1 jruoho * PARAMETERS: None
984 1.1 jruoho *
985 1.1 jruoho * RETURN: None
986 1.1 jruoho *
987 1.1 jruoho * DESCRIPTION: Free the entire External info list
988 1.1 jruoho *
989 1.1 jruoho ******************************************************************************/
990 1.1 jruoho
991 1.1 jruoho void
992 1.1 jruoho AcpiDmClearExternalList (
993 1.1 jruoho void)
994 1.1 jruoho {
995 1.1 jruoho ACPI_EXTERNAL_LIST *NextExternal;
996 1.1 jruoho
997 1.1 jruoho
998 1.1 jruoho while (AcpiGbl_ExternalList)
999 1.1 jruoho {
1000 1.1 jruoho NextExternal = AcpiGbl_ExternalList->Next;
1001 1.1 jruoho ACPI_FREE (AcpiGbl_ExternalList->Path);
1002 1.1 jruoho ACPI_FREE (AcpiGbl_ExternalList);
1003 1.1 jruoho AcpiGbl_ExternalList = NextExternal;
1004 1.1 jruoho }
1005 1.1 jruoho }
1006 1.1 jruoho
1007 1.1 jruoho
1008 1.1 jruoho /*******************************************************************************
1009 1.1 jruoho *
1010 1.1 jruoho * FUNCTION: AcpiDmEmitExternals
1011 1.1 jruoho *
1012 1.1 jruoho * PARAMETERS: None
1013 1.1 jruoho *
1014 1.1 jruoho * RETURN: None
1015 1.1 jruoho *
1016 1.1 jruoho * DESCRIPTION: Emit an External() ASL statement for each of the externals in
1017 1.1 jruoho * the global external info list.
1018 1.1 jruoho *
1019 1.1 jruoho ******************************************************************************/
1020 1.1 jruoho
1021 1.1 jruoho void
1022 1.1 jruoho AcpiDmEmitExternals (
1023 1.1 jruoho void)
1024 1.1 jruoho {
1025 1.1 jruoho ACPI_EXTERNAL_LIST *NextExternal;
1026 1.1 jruoho
1027 1.1 jruoho
1028 1.1 jruoho if (!AcpiGbl_ExternalList)
1029 1.1 jruoho {
1030 1.1 jruoho return;
1031 1.1 jruoho }
1032 1.1 jruoho
1033 1.1 jruoho /*
1034 1.1.1.3 christos * Determine the number of control methods in the external list, and
1035 1.1.1.3 christos * also how many of those externals were resolved via the namespace.
1036 1.1 jruoho */
1037 1.1.1.3 christos NextExternal = AcpiGbl_ExternalList;
1038 1.1.1.3 christos while (NextExternal)
1039 1.1 jruoho {
1040 1.1.1.3 christos if (NextExternal->Type == ACPI_TYPE_METHOD)
1041 1.1.1.3 christos {
1042 1.1.1.3 christos AcpiGbl_NumExternalMethods++;
1043 1.1.1.3 christos if (NextExternal->Flags & ACPI_EXT_RESOLVED_REFERENCE)
1044 1.1.1.3 christos {
1045 1.1.1.3 christos AcpiGbl_ResolvedExternalMethods++;
1046 1.1.1.3 christos }
1047 1.1.1.3 christos }
1048 1.1.1.3 christos
1049 1.1.1.3 christos NextExternal = NextExternal->Next;
1050 1.1.1.3 christos }
1051 1.1 jruoho
1052 1.1.1.3 christos /* Check if any control methods were unresolved */
1053 1.1.1.3 christos
1054 1.1.1.3 christos AcpiDmUnresolvedWarning (1);
1055 1.1.1.3 christos
1056 1.1.1.3 christos /* Emit any unresolved method externals in a single text block */
1057 1.1.1.3 christos
1058 1.1.1.3 christos NextExternal = AcpiGbl_ExternalList;
1059 1.1.1.3 christos while (NextExternal)
1060 1.1.1.3 christos {
1061 1.1.1.3 christos if ((NextExternal->Type == ACPI_TYPE_METHOD) &&
1062 1.1.1.3 christos (!(NextExternal->Flags & ACPI_EXT_RESOLVED_REFERENCE)))
1063 1.1 jruoho {
1064 1.1.1.3 christos AcpiOsPrintf (" External (%s%s",
1065 1.1.1.3 christos NextExternal->Path,
1066 1.1.1.3 christos AcpiDmGetObjectTypeName (NextExternal->Type));
1067 1.1.1.3 christos
1068 1.1.1.3 christos AcpiOsPrintf (
1069 1.1.1.3 christos ") // Warning: Unresolved Method, "
1070 1.1.1.3 christos "guessing %u arguments (may be incorrect, see warning above)\n",
1071 1.1.1.3 christos NextExternal->Value);
1072 1.1.1.3 christos
1073 1.1.1.3 christos NextExternal->Flags |= ACPI_EXT_EXTERNAL_EMITTED;
1074 1.1 jruoho }
1075 1.1.1.3 christos
1076 1.1.1.3 christos NextExternal = NextExternal->Next;
1077 1.1.1.3 christos }
1078 1.1.1.3 christos
1079 1.1.1.3 christos AcpiOsPrintf ("\n");
1080 1.1.1.3 christos
1081 1.1.1.3 christos
1082 1.1.1.3 christos /* Emit externals that were imported from a file */
1083 1.1.1.3 christos
1084 1.1.1.3 christos if (Gbl_ExternalRefFilename)
1085 1.1.1.3 christos {
1086 1.1.1.3 christos AcpiOsPrintf (
1087 1.1.1.3 christos " /*\n * External declarations that were imported from\n"
1088 1.1.1.3 christos " * the reference file [%s]\n */\n",
1089 1.1.1.3 christos Gbl_ExternalRefFilename);
1090 1.1.1.3 christos
1091 1.1.1.3 christos NextExternal = AcpiGbl_ExternalList;
1092 1.1.1.3 christos while (NextExternal)
1093 1.1 jruoho {
1094 1.1.1.3 christos if (!(NextExternal->Flags & ACPI_EXT_EXTERNAL_EMITTED) &&
1095 1.1.1.3 christos (NextExternal->Flags & ACPI_EXT_ORIGIN_FROM_FILE))
1096 1.1.1.3 christos {
1097 1.1.1.3 christos AcpiOsPrintf (" External (%s%s",
1098 1.1.1.3 christos NextExternal->Path,
1099 1.1.1.3 christos AcpiDmGetObjectTypeName (NextExternal->Type));
1100 1.1.1.3 christos
1101 1.1.1.3 christos if (NextExternal->Type == ACPI_TYPE_METHOD)
1102 1.1.1.3 christos {
1103 1.1.1.3 christos AcpiOsPrintf (") // %u Arguments\n",
1104 1.1.1.3 christos NextExternal->Value);
1105 1.1.1.3 christos }
1106 1.1.1.3 christos else
1107 1.1.1.3 christos {
1108 1.1.1.3 christos AcpiOsPrintf (")\n");
1109 1.1.1.3 christos }
1110 1.1.1.3 christos NextExternal->Flags |= ACPI_EXT_EXTERNAL_EMITTED;
1111 1.1.1.3 christos }
1112 1.1.1.3 christos
1113 1.1.1.3 christos NextExternal = NextExternal->Next;
1114 1.1.1.3 christos }
1115 1.1.1.3 christos
1116 1.1.1.3 christos AcpiOsPrintf ("\n");
1117 1.1.1.3 christos }
1118 1.1.1.3 christos
1119 1.1.1.3 christos /*
1120 1.1.1.3 christos * Walk the list of externals found during the AML parsing
1121 1.1.1.3 christos */
1122 1.1.1.3 christos while (AcpiGbl_ExternalList)
1123 1.1.1.3 christos {
1124 1.1.1.3 christos if (!(AcpiGbl_ExternalList->Flags & ACPI_EXT_EXTERNAL_EMITTED))
1125 1.1.1.3 christos {
1126 1.1.1.3 christos AcpiOsPrintf (" External (%s%s",
1127 1.1.1.3 christos AcpiGbl_ExternalList->Path,
1128 1.1.1.3 christos AcpiDmGetObjectTypeName (AcpiGbl_ExternalList->Type));
1129 1.1.1.3 christos
1130 1.1.1.3 christos /* For methods, add a comment with the number of arguments */
1131 1.1.1.3 christos
1132 1.1.1.3 christos if (AcpiGbl_ExternalList->Type == ACPI_TYPE_METHOD)
1133 1.1.1.3 christos {
1134 1.1.1.3 christos AcpiOsPrintf (") // %u Arguments\n",
1135 1.1.1.3 christos AcpiGbl_ExternalList->Value);
1136 1.1.1.3 christos }
1137 1.1.1.3 christos else
1138 1.1.1.3 christos {
1139 1.1.1.3 christos AcpiOsPrintf (")\n");
1140 1.1.1.3 christos }
1141 1.1 jruoho }
1142 1.1 jruoho
1143 1.1 jruoho /* Free this external info block and move on to next external */
1144 1.1 jruoho
1145 1.1 jruoho NextExternal = AcpiGbl_ExternalList->Next;
1146 1.1.1.3 christos if (AcpiGbl_ExternalList->Flags & ACPI_EXT_INTERNAL_PATH_ALLOCATED)
1147 1.1 jruoho {
1148 1.1 jruoho ACPI_FREE (AcpiGbl_ExternalList->InternalPath);
1149 1.1 jruoho }
1150 1.1 jruoho
1151 1.1 jruoho ACPI_FREE (AcpiGbl_ExternalList->Path);
1152 1.1 jruoho ACPI_FREE (AcpiGbl_ExternalList);
1153 1.1 jruoho AcpiGbl_ExternalList = NextExternal;
1154 1.1 jruoho }
1155 1.1 jruoho
1156 1.1 jruoho AcpiOsPrintf ("\n");
1157 1.1 jruoho }
1158 1.1 jruoho
1159 1.1.1.3 christos
1160 1.1.1.3 christos /*******************************************************************************
1161 1.1.1.3 christos *
1162 1.1.1.3 christos * FUNCTION: AcpiDmUnresolvedWarning
1163 1.1.1.3 christos *
1164 1.1.1.3 christos * PARAMETERS: Type - Where to output the warning.
1165 1.1.1.3 christos * 0 means write to stderr
1166 1.1.1.3 christos * 1 means write to AcpiOsPrintf
1167 1.1.1.3 christos *
1168 1.1.1.3 christos * RETURN: None
1169 1.1.1.3 christos *
1170 1.1.1.3 christos * DESCRIPTION: Issue warning message if there are unresolved external control
1171 1.1.1.3 christos * methods within the disassembly.
1172 1.1.1.3 christos *
1173 1.1.1.3 christos ******************************************************************************/
1174 1.1.1.3 christos
1175 1.1.1.3 christos #if 0
1176 1.1.1.3 christos Summary of the external control method problem:
1177 1.1.1.3 christos
1178 1.1.1.3 christos When the -e option is used with disassembly, the various SSDTs are simply
1179 1.1.1.3 christos loaded into a global namespace for the disassembler to use in order to
1180 1.1.1.3 christos resolve control method references (invocations).
1181 1.1.1.3 christos
1182 1.1.1.3 christos The disassembler tracks any such references, and will emit an External()
1183 1.1.1.3 christos statement for these types of methods, with the proper number of arguments .
1184 1.1.1.3 christos
1185 1.1.1.3 christos Without the SSDTs, the AML does not contain enough information to properly
1186 1.1.1.3 christos disassemble the control method invocation -- because the disassembler does
1187 1.1.1.3 christos not know how many arguments to parse.
1188 1.1.1.3 christos
1189 1.1.1.3 christos An example: Assume we have two control methods. ABCD has one argument, and
1190 1.1.1.3 christos EFGH has zero arguments. Further, we have two additional control methods
1191 1.1.1.3 christos that invoke ABCD and EFGH, named T1 and T2:
1192 1.1.1.3 christos
1193 1.1.1.3 christos Method (ABCD, 1)
1194 1.1.1.3 christos {
1195 1.1.1.3 christos }
1196 1.1.1.3 christos Method (EFGH, 0)
1197 1.1.1.3 christos {
1198 1.1.1.3 christos }
1199 1.1.1.3 christos Method (T1)
1200 1.1.1.3 christos {
1201 1.1.1.3 christos ABCD (Add (2, 7, Local0))
1202 1.1.1.3 christos }
1203 1.1.1.3 christos Method (T2)
1204 1.1.1.3 christos {
1205 1.1.1.3 christos EFGH ()
1206 1.1.1.3 christos Add (2, 7, Local0)
1207 1.1.1.3 christos }
1208 1.1.1.3 christos
1209 1.1.1.3 christos Here is the AML code that is generated for T1 and T2:
1210 1.1.1.3 christos
1211 1.1.1.3 christos 185: Method (T1)
1212 1.1.1.3 christos
1213 1.1.1.3 christos 0000034C: 14 10 54 31 5F 5F 00 ... "..T1__."
1214 1.1.1.3 christos
1215 1.1.1.3 christos 186: {
1216 1.1.1.3 christos 187: ABCD (Add (2, 7, Local0))
1217 1.1.1.3 christos
1218 1.1.1.3 christos 00000353: 41 42 43 44 ............ "ABCD"
1219 1.1.1.3 christos 00000357: 72 0A 02 0A 07 60 ...... "r....`"
1220 1.1.1.3 christos
1221 1.1.1.3 christos 188: }
1222 1.1.1.3 christos
1223 1.1.1.3 christos 190: Method (T2)
1224 1.1.1.3 christos
1225 1.1.1.3 christos 0000035D: 14 10 54 32 5F 5F 00 ... "..T2__."
1226 1.1.1.3 christos
1227 1.1.1.3 christos 191: {
1228 1.1.1.3 christos 192: EFGH ()
1229 1.1.1.3 christos
1230 1.1.1.3 christos 00000364: 45 46 47 48 ............ "EFGH"
1231 1.1.1.3 christos
1232 1.1.1.3 christos 193: Add (2, 7, Local0)
1233 1.1.1.3 christos
1234 1.1.1.3 christos 00000368: 72 0A 02 0A 07 60 ...... "r....`"
1235 1.1.1.3 christos 194: }
1236 1.1.1.3 christos
1237 1.1.1.3 christos Note that the AML code for T1 and T2 is essentially identical. When
1238 1.1.1.3 christos disassembling this code, the methods ABCD and EFGH must be known to the
1239 1.1.1.3 christos disassembler, otherwise it does not know how to handle the method invocations.
1240 1.1.1.3 christos
1241 1.1.1.3 christos In other words, if ABCD and EFGH are actually external control methods
1242 1.1.1.3 christos appearing in an SSDT, the disassembler does not know what to do unless
1243 1.1.1.3 christos the owning SSDT has been loaded via the -e option.
1244 1.1.1.3 christos #endif
1245 1.1.1.3 christos
1246 1.1.1.3 christos void
1247 1.1.1.3 christos AcpiDmUnresolvedWarning (
1248 1.1.1.3 christos UINT8 Type)
1249 1.1.1.3 christos {
1250 1.1.1.3 christos
1251 1.1.1.3 christos if (!AcpiGbl_NumExternalMethods)
1252 1.1.1.3 christos {
1253 1.1.1.3 christos return;
1254 1.1.1.3 christos }
1255 1.1.1.3 christos
1256 1.1.1.3 christos if (Type)
1257 1.1.1.3 christos {
1258 1.1.1.3 christos if (!AcpiGbl_ExternalFileList)
1259 1.1.1.3 christos {
1260 1.1.1.3 christos /* The -e option was not specified */
1261 1.1.1.3 christos
1262 1.1.1.3 christos AcpiOsPrintf (" /*\n"
1263 1.1.1.3 christos " * iASL Warning: There were %u external control methods found during\n"
1264 1.1.1.3 christos " * disassembly, but additional ACPI tables to resolve these externals\n"
1265 1.1.1.3 christos " * were not specified. This resulting disassembler output file may not\n"
1266 1.1.1.3 christos " * compile because the disassembler did not know how many arguments\n"
1267 1.1.1.3 christos " * to assign to these methods. To specify the tables needed to resolve\n"
1268 1.1.1.3 christos " * external control method references, use the one of the following\n"
1269 1.1.1.3 christos " * example iASL invocations:\n"
1270 1.1.1.3 christos " * iasl -e <ssdt1.aml,ssdt2.aml...> -d <dsdt.aml>\n"
1271 1.1.1.3 christos " * iasl -e <dsdt.aml,ssdt2.aml...> -d <ssdt1.aml>\n"
1272 1.1.1.3 christos " */\n",
1273 1.1.1.3 christos AcpiGbl_NumExternalMethods);
1274 1.1.1.3 christos }
1275 1.1.1.3 christos else if (AcpiGbl_NumExternalMethods != AcpiGbl_ResolvedExternalMethods)
1276 1.1.1.3 christos {
1277 1.1.1.3 christos /* The -e option was specified, but there are still some unresolved externals */
1278 1.1.1.3 christos
1279 1.1.1.3 christos AcpiOsPrintf (" /*\n"
1280 1.1.1.3 christos " * iASL Warning: There were %u external control methods found during\n"
1281 1.1.1.3 christos " * disassembly, but only %u %s resolved (%u unresolved). Additional\n"
1282 1.1.1.3 christos " * ACPI tables are required to properly disassemble the code. This\n"
1283 1.1.1.3 christos " * resulting disassembler output file may not compile because the\n"
1284 1.1.1.3 christos " * disassembler did not know how many arguments to assign to the\n"
1285 1.1.1.3 christos " * unresolved methods.\n"
1286 1.1.1.3 christos " */\n",
1287 1.1.1.3 christos AcpiGbl_NumExternalMethods, AcpiGbl_ResolvedExternalMethods,
1288 1.1.1.3 christos (AcpiGbl_ResolvedExternalMethods > 1 ? "were" : "was"),
1289 1.1.1.3 christos (AcpiGbl_NumExternalMethods - AcpiGbl_ResolvedExternalMethods));
1290 1.1.1.3 christos }
1291 1.1.1.3 christos }
1292 1.1.1.3 christos else
1293 1.1.1.3 christos {
1294 1.1.1.3 christos if (!AcpiGbl_ExternalFileList)
1295 1.1.1.3 christos {
1296 1.1.1.3 christos /* The -e option was not specified */
1297 1.1.1.3 christos
1298 1.1.1.3 christos fprintf (stderr, "\n"
1299 1.1.1.3 christos "iASL Warning: There were %u external control methods found during\n"
1300 1.1.1.3 christos "disassembly, but additional ACPI tables to resolve these externals\n"
1301 1.1.1.3 christos "were not specified. The resulting disassembler output file may not\n"
1302 1.1.1.3 christos "compile because the disassembler did not know how many arguments\n"
1303 1.1.1.3 christos "to assign to these methods. To specify the tables needed to resolve\n"
1304 1.1.1.3 christos "external control method references, use the one of the following\n"
1305 1.1.1.3 christos "example iASL invocations:\n"
1306 1.1.1.3 christos " iasl -e <ssdt1.aml,ssdt2.aml...> -d <dsdt.aml>\n"
1307 1.1.1.3 christos " iasl -e <dsdt.aml,ssdt2.aml...> -d <ssdt1.aml>\n",
1308 1.1.1.3 christos AcpiGbl_NumExternalMethods);
1309 1.1.1.3 christos }
1310 1.1.1.3 christos else if (AcpiGbl_NumExternalMethods != AcpiGbl_ResolvedExternalMethods)
1311 1.1.1.3 christos {
1312 1.1.1.3 christos /* The -e option was specified, but there are still some unresolved externals */
1313 1.1.1.3 christos
1314 1.1.1.3 christos fprintf (stderr, "\n"
1315 1.1.1.3 christos "iASL Warning: There were %u external control methods found during\n"
1316 1.1.1.3 christos "disassembly, but only %u %s resolved (%u unresolved). Additional\n"
1317 1.1.1.3 christos "ACPI tables are required to properly disassemble the code. The\n"
1318 1.1.1.3 christos "resulting disassembler output file may not compile because the\n"
1319 1.1.1.3 christos "disassembler did not know how many arguments to assign to the\n"
1320 1.1.1.3 christos "unresolved methods.\n",
1321 1.1.1.3 christos AcpiGbl_NumExternalMethods, AcpiGbl_ResolvedExternalMethods,
1322 1.1.1.3 christos (AcpiGbl_ResolvedExternalMethods > 1 ? "were" : "was"),
1323 1.1.1.3 christos (AcpiGbl_NumExternalMethods - AcpiGbl_ResolvedExternalMethods));
1324 1.1.1.3 christos }
1325 1.1.1.3 christos }
1326 1.1.1.3 christos }
1327