aslpredef.c revision 1.1.1.16 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: aslpredef - support for ACPI predefined names
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.16 christos * Copyright (C) 2000 - 2021, 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.16 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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 #define ACPI_CREATE_PREDEFINED_TABLE
45 1.1.1.4 christos #define ACPI_CREATE_RESOURCE_TABLE
46 1.1 jruoho
47 1.1 jruoho #include "aslcompiler.h"
48 1.1 jruoho #include "aslcompiler.y.h"
49 1.1 jruoho #include "acpredef.h"
50 1.1.1.4 christos #include "acnamesp.h"
51 1.1 jruoho
52 1.1 jruoho
53 1.1 jruoho #define _COMPONENT ACPI_COMPILER
54 1.1 jruoho ACPI_MODULE_NAME ("aslpredef")
55 1.1 jruoho
56 1.1 jruoho
57 1.1 jruoho /* Local prototypes */
58 1.1 jruoho
59 1.1.1.2 jruoho static void
60 1.1.1.2 jruoho ApCheckForUnexpectedReturnValue (
61 1.1.1.2 jruoho ACPI_PARSE_OBJECT *Op,
62 1.1.1.2 jruoho ASL_METHOD_INFO *MethodInfo);
63 1.1.1.2 jruoho
64 1.1 jruoho static UINT32
65 1.1 jruoho ApCheckForSpecialName (
66 1.1 jruoho ACPI_PARSE_OBJECT *Op,
67 1.1 jruoho char *Name);
68 1.1 jruoho
69 1.1 jruoho
70 1.1 jruoho /*******************************************************************************
71 1.1 jruoho *
72 1.1 jruoho * FUNCTION: ApCheckForPredefinedMethod
73 1.1 jruoho *
74 1.1 jruoho * PARAMETERS: Op - A parse node of type "METHOD".
75 1.1 jruoho * MethodInfo - Saved info about this method
76 1.1 jruoho *
77 1.1 jruoho * RETURN: None
78 1.1 jruoho *
79 1.1 jruoho * DESCRIPTION: If method is a predefined name, check that the number of
80 1.1 jruoho * arguments and the return type (returns a value or not)
81 1.1 jruoho * is correct.
82 1.1 jruoho *
83 1.1 jruoho ******************************************************************************/
84 1.1 jruoho
85 1.1.1.3 jruoho BOOLEAN
86 1.1 jruoho ApCheckForPredefinedMethod (
87 1.1 jruoho ACPI_PARSE_OBJECT *Op,
88 1.1 jruoho ASL_METHOD_INFO *MethodInfo)
89 1.1 jruoho {
90 1.1.1.4 christos UINT32 Index;
91 1.1.1.4 christos UINT32 RequiredArgCount;
92 1.1.1.4 christos const ACPI_PREDEFINED_INFO *ThisName;
93 1.1 jruoho
94 1.1 jruoho
95 1.1 jruoho /* Check for a match against the predefined name list */
96 1.1 jruoho
97 1.1 jruoho Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg);
98 1.1 jruoho
99 1.1 jruoho switch (Index)
100 1.1 jruoho {
101 1.1 jruoho case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
102 1.1 jruoho case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
103 1.1 jruoho case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
104 1.1 jruoho
105 1.1 jruoho /* Just return, nothing to do */
106 1.1.1.3 jruoho return (FALSE);
107 1.1 jruoho
108 1.1 jruoho
109 1.1 jruoho case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
110 1.1 jruoho
111 1.1.1.12 christos AslGbl_ReservedMethods++;
112 1.1 jruoho
113 1.1 jruoho /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */
114 1.1 jruoho
115 1.1 jruoho if (MethodInfo->NumArguments != 0)
116 1.1 jruoho {
117 1.1.1.12 christos sprintf (AslGbl_MsgBuffer, "%s requires %d", Op->Asl.ExternalName, 0);
118 1.1 jruoho
119 1.1 jruoho AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
120 1.1.1.12 christos AslGbl_MsgBuffer);
121 1.1 jruoho }
122 1.1 jruoho break;
123 1.1 jruoho
124 1.1 jruoho
125 1.1 jruoho default:
126 1.1 jruoho /*
127 1.1.1.4 christos * Matched a predefined method name - validate the ASL-defined
128 1.1.1.4 christos * argument count against the ACPI specification.
129 1.1 jruoho *
130 1.1.1.4 christos * Some methods are allowed to have a "minimum" number of args
131 1.1.1.4 christos * (_SCP) because their definition in ACPI has changed over time.
132 1.1 jruoho */
133 1.1.1.12 christos AslGbl_ReservedMethods++;
134 1.1.1.4 christos ThisName = &AcpiGbl_PredefinedMethods[Index];
135 1.1.1.4 christos RequiredArgCount = METHOD_GET_ARG_COUNT (ThisName->Info.ArgumentList);
136 1.1 jruoho
137 1.1.1.4 christos if (MethodInfo->NumArguments != RequiredArgCount)
138 1.1 jruoho {
139 1.1.1.12 christos sprintf (AslGbl_MsgBuffer, "%4.4s requires %u",
140 1.1.1.4 christos ThisName->Info.Name, RequiredArgCount);
141 1.1 jruoho
142 1.1.1.4 christos if (MethodInfo->NumArguments < RequiredArgCount)
143 1.1 jruoho {
144 1.1.1.4 christos AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op,
145 1.1.1.12 christos AslGbl_MsgBuffer);
146 1.1 jruoho }
147 1.1.1.4 christos else if ((MethodInfo->NumArguments > RequiredArgCount) &&
148 1.1.1.4 christos !(ThisName->Info.ArgumentList & ARG_COUNT_IS_MINIMUM))
149 1.1 jruoho {
150 1.1.1.4 christos AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op,
151 1.1.1.12 christos AslGbl_MsgBuffer);
152 1.1 jruoho }
153 1.1 jruoho }
154 1.1 jruoho
155 1.1 jruoho /*
156 1.1 jruoho * Check if method returns no value, but the predefined name is
157 1.1 jruoho * required to return a value
158 1.1 jruoho */
159 1.1 jruoho if (MethodInfo->NumReturnNoValue &&
160 1.1.1.4 christos ThisName->Info.ExpectedBtypes)
161 1.1 jruoho {
162 1.1.1.12 christos AcpiUtGetExpectedReturnTypes (AslGbl_StringBuffer,
163 1.1.1.4 christos ThisName->Info.ExpectedBtypes);
164 1.1 jruoho
165 1.1.1.12 christos sprintf (AslGbl_MsgBuffer, "%s required for %4.4s",
166 1.1.1.12 christos AslGbl_StringBuffer, ThisName->Info.Name);
167 1.1 jruoho
168 1.1 jruoho AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op,
169 1.1.1.12 christos AslGbl_MsgBuffer);
170 1.1 jruoho }
171 1.1 jruoho break;
172 1.1 jruoho }
173 1.1.1.3 jruoho
174 1.1.1.3 jruoho return (TRUE);
175 1.1 jruoho }
176 1.1 jruoho
177 1.1 jruoho
178 1.1 jruoho /*******************************************************************************
179 1.1 jruoho *
180 1.1.1.2 jruoho * FUNCTION: ApCheckForUnexpectedReturnValue
181 1.1.1.2 jruoho *
182 1.1.1.2 jruoho * PARAMETERS: Op - A parse node of type "RETURN".
183 1.1.1.2 jruoho * MethodInfo - Saved info about this method
184 1.1.1.2 jruoho *
185 1.1.1.2 jruoho * RETURN: None
186 1.1.1.2 jruoho *
187 1.1.1.2 jruoho * DESCRIPTION: Check for an unexpected return value from a predefined method.
188 1.1.1.2 jruoho * Invoked for predefined methods that are defined to not return
189 1.1.1.2 jruoho * any value. If there is a return value, issue a remark, since
190 1.1.1.2 jruoho * the ASL writer may be confused as to the method definition
191 1.1.1.2 jruoho * and/or functionality.
192 1.1.1.2 jruoho *
193 1.1.1.2 jruoho * Note: We ignore all return values of "Zero", since this is what a standalone
194 1.1.1.2 jruoho * Return() statement will always generate -- so we ignore it here --
195 1.1.1.2 jruoho * i.e., there is no difference between Return() and Return(Zero).
196 1.1.1.2 jruoho * Also, a null Return() will be disassembled to return(Zero) -- so, we
197 1.1.1.2 jruoho * don't want to generate extraneous remarks/warnings for a disassembled
198 1.1.1.2 jruoho * ASL file.
199 1.1.1.2 jruoho *
200 1.1.1.2 jruoho ******************************************************************************/
201 1.1.1.2 jruoho
202 1.1.1.2 jruoho static void
203 1.1.1.2 jruoho ApCheckForUnexpectedReturnValue (
204 1.1.1.2 jruoho ACPI_PARSE_OBJECT *Op,
205 1.1.1.2 jruoho ASL_METHOD_INFO *MethodInfo)
206 1.1.1.2 jruoho {
207 1.1.1.2 jruoho ACPI_PARSE_OBJECT *ReturnValueOp;
208 1.1.1.2 jruoho
209 1.1.1.2 jruoho
210 1.1.1.2 jruoho /* Ignore Return() and Return(Zero) (they are the same) */
211 1.1.1.2 jruoho
212 1.1.1.2 jruoho ReturnValueOp = Op->Asl.Child;
213 1.1.1.2 jruoho if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO)
214 1.1.1.2 jruoho {
215 1.1.1.2 jruoho return;
216 1.1.1.2 jruoho }
217 1.1.1.2 jruoho
218 1.1.1.2 jruoho /* We have a valid return value, but the reserved name did not expect it */
219 1.1.1.2 jruoho
220 1.1.1.2 jruoho AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL,
221 1.1.1.2 jruoho Op, MethodInfo->Op->Asl.ExternalName);
222 1.1.1.2 jruoho }
223 1.1.1.2 jruoho
224 1.1.1.2 jruoho
225 1.1.1.2 jruoho /*******************************************************************************
226 1.1.1.2 jruoho *
227 1.1 jruoho * FUNCTION: ApCheckPredefinedReturnValue
228 1.1 jruoho *
229 1.1 jruoho * PARAMETERS: Op - A parse node of type "RETURN".
230 1.1 jruoho * MethodInfo - Saved info about this method
231 1.1 jruoho *
232 1.1 jruoho * RETURN: None
233 1.1 jruoho *
234 1.1 jruoho * DESCRIPTION: If method is a predefined name, attempt to validate the return
235 1.1 jruoho * value. Only "static" types can be validated - a simple return
236 1.1 jruoho * of an integer/string/buffer/package or a named reference to
237 1.1 jruoho * a static object. Values such as a Localx or Argx or a control
238 1.1.1.2 jruoho * method invocation are not checked. Issue a warning if there is
239 1.1.1.2 jruoho * a valid return value, but the reserved method defines no
240 1.1.1.2 jruoho * return value.
241 1.1 jruoho *
242 1.1 jruoho ******************************************************************************/
243 1.1 jruoho
244 1.1 jruoho void
245 1.1 jruoho ApCheckPredefinedReturnValue (
246 1.1 jruoho ACPI_PARSE_OBJECT *Op,
247 1.1 jruoho ASL_METHOD_INFO *MethodInfo)
248 1.1 jruoho {
249 1.1.1.4 christos UINT32 Index;
250 1.1.1.4 christos ACPI_PARSE_OBJECT *ReturnValueOp;
251 1.1.1.4 christos const ACPI_PREDEFINED_INFO *ThisName;
252 1.1 jruoho
253 1.1 jruoho
254 1.1.1.5 christos /*
255 1.1.1.5 christos * Check parent method for a match against the predefined name list.
256 1.1.1.5 christos *
257 1.1.1.5 christos * Note: Disable compiler errors/warnings because any errors will be
258 1.1.1.5 christos * caught when analyzing the parent method. Eliminates duplicate errors.
259 1.1.1.5 christos */
260 1.1.1.12 christos AslGbl_AllExceptionsDisabled = TRUE;
261 1.1 jruoho Index = ApCheckForPredefinedName (MethodInfo->Op,
262 1.1.1.7 christos MethodInfo->Op->Asl.NameSeg);
263 1.1.1.12 christos AslGbl_AllExceptionsDisabled = FALSE;
264 1.1 jruoho
265 1.1 jruoho switch (Index)
266 1.1 jruoho {
267 1.1.1.2 jruoho case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
268 1.1.1.2 jruoho
269 1.1.1.2 jruoho /* No return value expected, warn if there is one */
270 1.1.1.2 jruoho
271 1.1.1.2 jruoho ApCheckForUnexpectedReturnValue (Op, MethodInfo);
272 1.1.1.2 jruoho return;
273 1.1.1.2 jruoho
274 1.1 jruoho case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
275 1.1 jruoho case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
276 1.1 jruoho case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
277 1.1 jruoho
278 1.1 jruoho /* Just return, nothing to do */
279 1.1 jruoho return;
280 1.1 jruoho
281 1.1 jruoho default: /* A standard predefined ACPI name */
282 1.1 jruoho
283 1.1.1.4 christos ThisName = &AcpiGbl_PredefinedMethods[Index];
284 1.1.1.4 christos if (!ThisName->Info.ExpectedBtypes)
285 1.1 jruoho {
286 1.1.1.2 jruoho /* No return value expected, warn if there is one */
287 1.1.1.2 jruoho
288 1.1.1.2 jruoho ApCheckForUnexpectedReturnValue (Op, MethodInfo);
289 1.1 jruoho return;
290 1.1 jruoho }
291 1.1 jruoho
292 1.1 jruoho /* Get the object returned, it is the next argument */
293 1.1 jruoho
294 1.1 jruoho ReturnValueOp = Op->Asl.Child;
295 1.1 jruoho switch (ReturnValueOp->Asl.ParseOpcode)
296 1.1 jruoho {
297 1.1 jruoho case PARSEOP_ZERO:
298 1.1 jruoho case PARSEOP_ONE:
299 1.1 jruoho case PARSEOP_ONES:
300 1.1 jruoho case PARSEOP_INTEGER:
301 1.1 jruoho case PARSEOP_STRING_LITERAL:
302 1.1 jruoho case PARSEOP_BUFFER:
303 1.1 jruoho case PARSEOP_PACKAGE:
304 1.1 jruoho
305 1.1 jruoho /* Static data return object - check against expected type */
306 1.1 jruoho
307 1.1.1.4 christos ApCheckObjectType (ThisName->Info.Name, ReturnValueOp,
308 1.1.1.4 christos ThisName->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
309 1.1.1.4 christos
310 1.1.1.4 christos /* For packages, check the individual package elements */
311 1.1.1.4 christos
312 1.1.1.4 christos if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_PACKAGE)
313 1.1.1.4 christos {
314 1.1.1.4 christos ApCheckPackage (ReturnValueOp, ThisName);
315 1.1.1.4 christos }
316 1.1 jruoho break;
317 1.1 jruoho
318 1.1 jruoho default:
319 1.1 jruoho /*
320 1.1 jruoho * All other ops are very difficult or impossible to typecheck at
321 1.1 jruoho * compile time. These include all Localx, Argx, and method
322 1.1 jruoho * invocations. Also, NAMESEG and NAMESTRING because the type of
323 1.1 jruoho * any named object can be changed at runtime (for example,
324 1.1 jruoho * CopyObject will change the type of the target object.)
325 1.1 jruoho */
326 1.1 jruoho break;
327 1.1 jruoho }
328 1.1 jruoho }
329 1.1 jruoho }
330 1.1 jruoho
331 1.1 jruoho
332 1.1 jruoho /*******************************************************************************
333 1.1 jruoho *
334 1.1 jruoho * FUNCTION: ApCheckForPredefinedObject
335 1.1 jruoho *
336 1.1 jruoho * PARAMETERS: Op - A parse node
337 1.1 jruoho * Name - The ACPI name to be checked
338 1.1 jruoho *
339 1.1 jruoho * RETURN: None
340 1.1 jruoho *
341 1.1 jruoho * DESCRIPTION: Check for a predefined name for a static object (created via
342 1.1 jruoho * the ASL Name operator). If it is a predefined ACPI name, ensure
343 1.1 jruoho * that the name does not require any arguments (which would
344 1.1.1.13 christos * require a control method implementation of the name), and that
345 1.1 jruoho * the type of the object is one of the expected types for the
346 1.1 jruoho * predefined name.
347 1.1 jruoho *
348 1.1 jruoho ******************************************************************************/
349 1.1 jruoho
350 1.1 jruoho void
351 1.1 jruoho ApCheckForPredefinedObject (
352 1.1 jruoho ACPI_PARSE_OBJECT *Op,
353 1.1 jruoho char *Name)
354 1.1 jruoho {
355 1.1.1.4 christos UINT32 Index;
356 1.1.1.4 christos ACPI_PARSE_OBJECT *ObjectOp;
357 1.1.1.4 christos const ACPI_PREDEFINED_INFO *ThisName;
358 1.1 jruoho
359 1.1 jruoho
360 1.1 jruoho /*
361 1.1 jruoho * Check for a real predefined name -- not a resource descriptor name
362 1.1 jruoho * or a predefined scope name
363 1.1 jruoho */
364 1.1 jruoho Index = ApCheckForPredefinedName (Op, Name);
365 1.1 jruoho
366 1.1 jruoho switch (Index)
367 1.1 jruoho {
368 1.1 jruoho case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */
369 1.1 jruoho case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */
370 1.1 jruoho case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */
371 1.1 jruoho
372 1.1 jruoho /* Nothing to do */
373 1.1 jruoho return;
374 1.1 jruoho
375 1.1 jruoho case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */
376 1.1 jruoho
377 1.1 jruoho /*
378 1.1 jruoho * These names must be control methods, by definition in ACPI spec.
379 1.1 jruoho * Also because they are defined to return no value. None of them
380 1.1 jruoho * require any arguments.
381 1.1 jruoho */
382 1.1 jruoho AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
383 1.1 jruoho "with zero arguments");
384 1.1 jruoho return;
385 1.1 jruoho
386 1.1.1.4 christos default:
387 1.1 jruoho
388 1.1.1.4 christos break;
389 1.1.1.4 christos }
390 1.1 jruoho
391 1.1.1.4 christos /* A standard predefined ACPI name */
392 1.1 jruoho
393 1.1.1.4 christos /*
394 1.1.1.4 christos * If this predefined name requires input arguments, then
395 1.1.1.4 christos * it must be implemented as a control method
396 1.1.1.4 christos */
397 1.1.1.4 christos ThisName = &AcpiGbl_PredefinedMethods[Index];
398 1.1.1.4 christos if (METHOD_GET_ARG_COUNT (ThisName->Info.ArgumentList) > 0)
399 1.1.1.4 christos {
400 1.1.1.4 christos AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
401 1.1.1.4 christos "with arguments");
402 1.1.1.4 christos return;
403 1.1.1.4 christos }
404 1.1 jruoho
405 1.1.1.4 christos /*
406 1.1.1.4 christos * If no return value is expected from this predefined name, then
407 1.1.1.4 christos * it follows that it must be implemented as a control method
408 1.1.1.4 christos * (with zero args, because the args > 0 case was handled above)
409 1.1.1.4 christos * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx
410 1.1.1.4 christos */
411 1.1.1.4 christos if (!ThisName->Info.ExpectedBtypes)
412 1.1.1.4 christos {
413 1.1.1.4 christos AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op,
414 1.1.1.4 christos "with zero arguments");
415 1.1 jruoho return;
416 1.1 jruoho }
417 1.1.1.4 christos
418 1.1.1.4 christos /* Typecheck the actual object, it is the next argument */
419 1.1.1.4 christos
420 1.1.1.4 christos ObjectOp = Op->Asl.Child->Asl.Next;
421 1.1.1.4 christos ApCheckObjectType (ThisName->Info.Name, Op->Asl.Child->Asl.Next,
422 1.1.1.4 christos ThisName->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
423 1.1.1.4 christos
424 1.1.1.4 christos /* For packages, check the individual package elements */
425 1.1.1.4 christos
426 1.1.1.4 christos if (ObjectOp->Asl.ParseOpcode == PARSEOP_PACKAGE)
427 1.1.1.4 christos {
428 1.1.1.4 christos ApCheckPackage (ObjectOp, ThisName);
429 1.1.1.4 christos }
430 1.1 jruoho }
431 1.1 jruoho
432 1.1 jruoho
433 1.1 jruoho /*******************************************************************************
434 1.1 jruoho *
435 1.1 jruoho * FUNCTION: ApCheckForPredefinedName
436 1.1 jruoho *
437 1.1 jruoho * PARAMETERS: Op - A parse node
438 1.1 jruoho * Name - NameSeg to check
439 1.1 jruoho *
440 1.1 jruoho * RETURN: None
441 1.1 jruoho *
442 1.1 jruoho * DESCRIPTION: Check a NameSeg against the reserved list.
443 1.1 jruoho *
444 1.1 jruoho ******************************************************************************/
445 1.1 jruoho
446 1.1 jruoho UINT32
447 1.1 jruoho ApCheckForPredefinedName (
448 1.1 jruoho ACPI_PARSE_OBJECT *Op,
449 1.1 jruoho char *Name)
450 1.1 jruoho {
451 1.1.1.4 christos UINT32 i;
452 1.1.1.4 christos const ACPI_PREDEFINED_INFO *ThisName;
453 1.1 jruoho
454 1.1 jruoho
455 1.1 jruoho if (Name[0] == 0)
456 1.1 jruoho {
457 1.1.1.8 christos AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op,
458 1.1.1.8 christos "zero length name found");
459 1.1 jruoho }
460 1.1 jruoho
461 1.1 jruoho /* All reserved names are prefixed with a single underscore */
462 1.1 jruoho
463 1.1 jruoho if (Name[0] != '_')
464 1.1 jruoho {
465 1.1 jruoho return (ACPI_NOT_RESERVED_NAME);
466 1.1 jruoho }
467 1.1 jruoho
468 1.1 jruoho /* Check for a standard predefined method name */
469 1.1 jruoho
470 1.1.1.4 christos ThisName = AcpiGbl_PredefinedMethods;
471 1.1.1.4 christos for (i = 0; ThisName->Info.Name[0]; i++)
472 1.1 jruoho {
473 1.1.1.13 christos if (ACPI_COMPARE_NAMESEG (Name, ThisName->Info.Name))
474 1.1 jruoho {
475 1.1 jruoho /* Return index into predefined array */
476 1.1 jruoho return (i);
477 1.1 jruoho }
478 1.1.1.4 christos
479 1.1.1.4 christos ThisName++; /* Does not account for extra package data, but is OK */
480 1.1 jruoho }
481 1.1 jruoho
482 1.1 jruoho /* Check for resource names and predefined scope names */
483 1.1 jruoho
484 1.1.1.4 christos ThisName = AcpiGbl_ResourceNames;
485 1.1.1.4 christos while (ThisName->Info.Name[0])
486 1.1 jruoho {
487 1.1.1.13 christos if (ACPI_COMPARE_NAMESEG (Name, ThisName->Info.Name))
488 1.1 jruoho {
489 1.1 jruoho return (ACPI_PREDEFINED_NAME);
490 1.1 jruoho }
491 1.1.1.4 christos
492 1.1.1.4 christos ThisName++;
493 1.1 jruoho }
494 1.1 jruoho
495 1.1.1.4 christos ThisName = AcpiGbl_ScopeNames;
496 1.1.1.4 christos while (ThisName->Info.Name[0])
497 1.1 jruoho {
498 1.1.1.13 christos if (ACPI_COMPARE_NAMESEG (Name, ThisName->Info.Name))
499 1.1 jruoho {
500 1.1 jruoho return (ACPI_PREDEFINED_NAME);
501 1.1 jruoho }
502 1.1.1.4 christos
503 1.1.1.4 christos ThisName++;
504 1.1 jruoho }
505 1.1 jruoho
506 1.1 jruoho /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */
507 1.1 jruoho
508 1.1 jruoho return (ApCheckForSpecialName (Op, Name));
509 1.1 jruoho }
510 1.1 jruoho
511 1.1 jruoho
512 1.1 jruoho /*******************************************************************************
513 1.1 jruoho *
514 1.1 jruoho * FUNCTION: ApCheckForSpecialName
515 1.1 jruoho *
516 1.1 jruoho * PARAMETERS: Op - A parse node
517 1.1 jruoho * Name - NameSeg to check
518 1.1 jruoho *
519 1.1 jruoho * RETURN: None
520 1.1 jruoho *
521 1.1 jruoho * DESCRIPTION: Check for the "special" predefined names -
522 1.1 jruoho * _Lxx, _Exx, _Qxx, _Wxx, and _T_x
523 1.1 jruoho *
524 1.1 jruoho ******************************************************************************/
525 1.1 jruoho
526 1.1 jruoho static UINT32
527 1.1 jruoho ApCheckForSpecialName (
528 1.1 jruoho ACPI_PARSE_OBJECT *Op,
529 1.1 jruoho char *Name)
530 1.1 jruoho {
531 1.1 jruoho
532 1.1 jruoho /*
533 1.1 jruoho * Check for the "special" predefined names. We already know that the
534 1.1 jruoho * first character is an underscore.
535 1.1 jruoho * GPE: _Lxx
536 1.1 jruoho * GPE: _Exx
537 1.1 jruoho * GPE: _Wxx
538 1.1 jruoho * EC: _Qxx
539 1.1 jruoho */
540 1.1 jruoho if ((Name[1] == 'L') ||
541 1.1 jruoho (Name[1] == 'E') ||
542 1.1 jruoho (Name[1] == 'W') ||
543 1.1 jruoho (Name[1] == 'Q'))
544 1.1 jruoho {
545 1.1 jruoho /* The next two characters must be hex digits */
546 1.1 jruoho
547 1.1 jruoho if ((isxdigit ((int) Name[2])) &&
548 1.1 jruoho (isxdigit ((int) Name[3])))
549 1.1 jruoho {
550 1.1 jruoho return (ACPI_EVENT_RESERVED_NAME);
551 1.1 jruoho }
552 1.1 jruoho }
553 1.1 jruoho
554 1.1 jruoho /* Check for the names reserved for the compiler itself: _T_x */
555 1.1 jruoho
556 1.1 jruoho else if ((Op->Asl.ExternalName[1] == 'T') &&
557 1.1 jruoho (Op->Asl.ExternalName[2] == '_'))
558 1.1 jruoho {
559 1.1 jruoho /* Ignore if actually emitted by the compiler */
560 1.1 jruoho
561 1.1.1.10 christos if (Op->Asl.CompileFlags & OP_COMPILER_EMITTED)
562 1.1 jruoho {
563 1.1 jruoho return (ACPI_NOT_RESERVED_NAME);
564 1.1 jruoho }
565 1.1 jruoho
566 1.1 jruoho /*
567 1.1 jruoho * Was not actually emitted by the compiler. This is a special case,
568 1.1 jruoho * however. If the ASL code being compiled was the result of a
569 1.1.1.15 christos * disassembly, it may possibly contain valid compiler-emitted names
570 1.1 jruoho * of the form "_T_x". We don't want to issue an error or even a
571 1.1 jruoho * warning and force the user to manually change the names. So, we
572 1.1 jruoho * will issue a remark instead.
573 1.1 jruoho */
574 1.1.1.7 christos AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED,
575 1.1.1.7 christos Op, Op->Asl.ExternalName);
576 1.1 jruoho return (ACPI_COMPILER_RESERVED_NAME);
577 1.1 jruoho }
578 1.1 jruoho
579 1.1 jruoho /*
580 1.1 jruoho * The name didn't match any of the known predefined names. Flag it as a
581 1.1 jruoho * warning, since the entire namespace starting with an underscore is
582 1.1 jruoho * reserved by the ACPI spec.
583 1.1 jruoho */
584 1.1.1.7 christos AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME,
585 1.1.1.7 christos Op, Op->Asl.ExternalName);
586 1.1 jruoho
587 1.1 jruoho return (ACPI_NOT_RESERVED_NAME);
588 1.1 jruoho }
589 1.1 jruoho
590 1.1 jruoho
591 1.1 jruoho /*******************************************************************************
592 1.1 jruoho *
593 1.1 jruoho * FUNCTION: ApCheckObjectType
594 1.1 jruoho *
595 1.1.1.4 christos * PARAMETERS: PredefinedName - Name of the predefined object we are checking
596 1.1.1.4 christos * Op - Current parse node
597 1.1 jruoho * ExpectedBtypes - Bitmap of expected return type(s)
598 1.1.1.4 christos * PackageIndex - Index of object within parent package (if
599 1.1.1.4 christos * applicable - ACPI_NOT_PACKAGE_ELEMENT
600 1.1.1.4 christos * otherwise)
601 1.1 jruoho *
602 1.1 jruoho * RETURN: None
603 1.1 jruoho *
604 1.1 jruoho * DESCRIPTION: Check if the object type is one of the types that is expected
605 1.1 jruoho * by the predefined name. Only a limited number of object types
606 1.1 jruoho * can be returned by the predefined names.
607 1.1 jruoho *
608 1.1 jruoho ******************************************************************************/
609 1.1 jruoho
610 1.1.1.4 christos ACPI_STATUS
611 1.1 jruoho ApCheckObjectType (
612 1.1.1.4 christos const char *PredefinedName,
613 1.1 jruoho ACPI_PARSE_OBJECT *Op,
614 1.1.1.4 christos UINT32 ExpectedBtypes,
615 1.1.1.4 christos UINT32 PackageIndex)
616 1.1 jruoho {
617 1.1 jruoho UINT32 ReturnBtype;
618 1.1.1.4 christos char *TypeName;
619 1.1 jruoho
620 1.1 jruoho
621 1.1.1.4 christos if (!Op)
622 1.1.1.4 christos {
623 1.1.1.4 christos return (AE_TYPE);
624 1.1.1.4 christos }
625 1.1.1.4 christos
626 1.1.1.4 christos /* Map the parse opcode to a bitmapped return type (RTYPE) */
627 1.1.1.4 christos
628 1.1 jruoho switch (Op->Asl.ParseOpcode)
629 1.1 jruoho {
630 1.1 jruoho case PARSEOP_ZERO:
631 1.1 jruoho case PARSEOP_ONE:
632 1.1 jruoho case PARSEOP_ONES:
633 1.1 jruoho case PARSEOP_INTEGER:
634 1.1 jruoho
635 1.1.1.4 christos ReturnBtype = ACPI_RTYPE_INTEGER;
636 1.1.1.4 christos TypeName = "Integer";
637 1.1 jruoho break;
638 1.1 jruoho
639 1.1 jruoho case PARSEOP_STRING_LITERAL:
640 1.1.1.4 christos
641 1.1 jruoho ReturnBtype = ACPI_RTYPE_STRING;
642 1.1.1.4 christos TypeName = "String";
643 1.1.1.4 christos break;
644 1.1.1.4 christos
645 1.1.1.4 christos case PARSEOP_BUFFER:
646 1.1.1.4 christos
647 1.1.1.4 christos ReturnBtype = ACPI_RTYPE_BUFFER;
648 1.1.1.4 christos TypeName = "Buffer";
649 1.1 jruoho break;
650 1.1 jruoho
651 1.1 jruoho case PARSEOP_PACKAGE:
652 1.1.1.4 christos case PARSEOP_VAR_PACKAGE:
653 1.1.1.4 christos
654 1.1 jruoho ReturnBtype = ACPI_RTYPE_PACKAGE;
655 1.1.1.4 christos TypeName = "Package";
656 1.1.1.4 christos break;
657 1.1.1.4 christos
658 1.1.1.4 christos case PARSEOP_NAMESEG:
659 1.1.1.4 christos case PARSEOP_NAMESTRING:
660 1.1.1.4 christos /*
661 1.1.1.4 christos * Ignore any named references within a package object.
662 1.1.1.4 christos *
663 1.1.1.4 christos * For Package objects, references are allowed instead of any of the
664 1.1.1.4 christos * standard data types (Integer/String/Buffer/Package). These
665 1.1.1.4 christos * references are resolved at runtime. NAMESEG and NAMESTRING are
666 1.1.1.4 christos * impossible to typecheck at compile time because the type of
667 1.1.1.4 christos * any named object can be changed at runtime (for example,
668 1.1.1.4 christos * CopyObject will change the type of the target object).
669 1.1.1.4 christos */
670 1.1.1.4 christos if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
671 1.1.1.4 christos {
672 1.1.1.4 christos return (AE_OK);
673 1.1.1.4 christos }
674 1.1.1.4 christos
675 1.1.1.4 christos ReturnBtype = ACPI_RTYPE_REFERENCE;
676 1.1.1.4 christos TypeName = "Reference";
677 1.1 jruoho break;
678 1.1 jruoho
679 1.1 jruoho default:
680 1.1.1.4 christos
681 1.1 jruoho /* Not one of the supported object types */
682 1.1 jruoho
683 1.1.1.4 christos TypeName = UtGetOpName (Op->Asl.ParseOpcode);
684 1.1 jruoho goto TypeErrorExit;
685 1.1 jruoho }
686 1.1 jruoho
687 1.1 jruoho /* Exit if the object is one of the expected types */
688 1.1 jruoho
689 1.1 jruoho if (ReturnBtype & ExpectedBtypes)
690 1.1 jruoho {
691 1.1.1.4 christos return (AE_OK);
692 1.1 jruoho }
693 1.1 jruoho
694 1.1 jruoho
695 1.1 jruoho TypeErrorExit:
696 1.1 jruoho
697 1.1 jruoho /* Format the expected types and emit an error message */
698 1.1 jruoho
699 1.1.1.12 christos AcpiUtGetExpectedReturnTypes (AslGbl_StringBuffer, ExpectedBtypes);
700 1.1 jruoho
701 1.1.1.4 christos if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT)
702 1.1.1.4 christos {
703 1.1.1.12 christos sprintf (AslGbl_MsgBuffer, "%4.4s: found %s, %s required",
704 1.1.1.12 christos PredefinedName, TypeName, AslGbl_StringBuffer);
705 1.1.1.4 christos }
706 1.1.1.4 christos else
707 1.1.1.4 christos {
708 1.1.1.12 christos sprintf (AslGbl_MsgBuffer, "%4.4s: found %s at index %u, %s required",
709 1.1.1.12 christos PredefinedName, TypeName, PackageIndex, AslGbl_StringBuffer);
710 1.1.1.4 christos }
711 1.1 jruoho
712 1.1.1.12 christos AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op, AslGbl_MsgBuffer);
713 1.1.1.4 christos return (AE_TYPE);
714 1.1 jruoho }
715 1.1 jruoho
716 1.1 jruoho
717 1.1 jruoho /*******************************************************************************
718 1.1 jruoho *
719 1.1 jruoho * FUNCTION: ApDisplayReservedNames
720 1.1 jruoho *
721 1.1 jruoho * PARAMETERS: None
722 1.1 jruoho *
723 1.1 jruoho * RETURN: None
724 1.1 jruoho *
725 1.1 jruoho * DESCRIPTION: Dump information about the ACPI predefined names and predefined
726 1.1 jruoho * resource descriptor names.
727 1.1 jruoho *
728 1.1 jruoho ******************************************************************************/
729 1.1 jruoho
730 1.1 jruoho void
731 1.1 jruoho ApDisplayReservedNames (
732 1.1 jruoho void)
733 1.1 jruoho {
734 1.1 jruoho const ACPI_PREDEFINED_INFO *ThisName;
735 1.1 jruoho UINT32 Count;
736 1.1.1.4 christos UINT32 NumTypes;
737 1.1 jruoho
738 1.1 jruoho
739 1.1 jruoho /*
740 1.1 jruoho * Predefined names/methods
741 1.1 jruoho */
742 1.1 jruoho printf ("\nPredefined Name Information\n\n");
743 1.1 jruoho
744 1.1 jruoho Count = 0;
745 1.1.1.4 christos ThisName = AcpiGbl_PredefinedMethods;
746 1.1 jruoho while (ThisName->Info.Name[0])
747 1.1 jruoho {
748 1.1.1.12 christos AcpiUtDisplayPredefinedMethod (AslGbl_MsgBuffer, ThisName, FALSE);
749 1.1 jruoho Count++;
750 1.1.1.4 christos ThisName = AcpiUtGetNextPredefinedMethod (ThisName);
751 1.1 jruoho }
752 1.1 jruoho
753 1.1 jruoho printf ("%u Predefined Names are recognized\n", Count);
754 1.1 jruoho
755 1.1 jruoho /*
756 1.1 jruoho * Resource Descriptor names
757 1.1 jruoho */
758 1.1.1.4 christos printf ("\nPredefined Names for Resource Descriptor Fields\n\n");
759 1.1 jruoho
760 1.1 jruoho Count = 0;
761 1.1.1.4 christos ThisName = AcpiGbl_ResourceNames;
762 1.1 jruoho while (ThisName->Info.Name[0])
763 1.1 jruoho {
764 1.1.1.12 christos NumTypes = AcpiUtGetResourceBitWidth (AslGbl_MsgBuffer,
765 1.1.1.4 christos ThisName->Info.ArgumentList);
766 1.1.1.4 christos
767 1.1.1.4 christos printf ("%4.4s Field is %s bits wide%s\n",
768 1.1.1.12 christos ThisName->Info.Name, AslGbl_MsgBuffer,
769 1.1.1.4 christos (NumTypes > 1) ? " (depending on descriptor type)" : "");
770 1.1.1.4 christos
771 1.1 jruoho Count++;
772 1.1 jruoho ThisName++;
773 1.1 jruoho }
774 1.1 jruoho
775 1.1.1.4 christos printf ("%u Resource Descriptor Field Names are recognized\n", Count);
776 1.1 jruoho
777 1.1 jruoho /*
778 1.1 jruoho * Predefined scope names
779 1.1 jruoho */
780 1.1.1.4 christos printf ("\nPredefined Scope/Device Names (automatically created at root)\n\n");
781 1.1 jruoho
782 1.1.1.4 christos ThisName = AcpiGbl_ScopeNames;
783 1.1 jruoho while (ThisName->Info.Name[0])
784 1.1 jruoho {
785 1.1.1.4 christos printf ("%4.4s Scope/Device\n", ThisName->Info.Name);
786 1.1 jruoho ThisName++;
787 1.1 jruoho }
788 1.1 jruoho }
789