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