nsarguments.c revision 1.1.1.1.10.3 1 1.1.1.1.10.2 tls /******************************************************************************
2 1.1.1.1.10.2 tls *
3 1.1.1.1.10.2 tls * Module Name: nsarguments - Validation of args for ACPI predefined methods
4 1.1.1.1.10.2 tls *
5 1.1.1.1.10.2 tls *****************************************************************************/
6 1.1.1.1.10.2 tls
7 1.1.1.1.10.2 tls /*
8 1.1.1.1.10.3 jdolecek * Copyright (C) 2000 - 2017, Intel Corp.
9 1.1.1.1.10.2 tls * All rights reserved.
10 1.1.1.1.10.2 tls *
11 1.1.1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
12 1.1.1.1.10.2 tls * modification, are permitted provided that the following conditions
13 1.1.1.1.10.2 tls * are met:
14 1.1.1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
15 1.1.1.1.10.2 tls * notice, this list of conditions, and the following disclaimer,
16 1.1.1.1.10.2 tls * without modification.
17 1.1.1.1.10.2 tls * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.1.10.2 tls * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.1.10.2 tls * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.1.10.2 tls * including a substantially similar Disclaimer requirement for further
21 1.1.1.1.10.2 tls * binary redistribution.
22 1.1.1.1.10.2 tls * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.1.10.2 tls * of any contributors may be used to endorse or promote products derived
24 1.1.1.1.10.2 tls * from this software without specific prior written permission.
25 1.1.1.1.10.2 tls *
26 1.1.1.1.10.2 tls * Alternatively, this software may be distributed under the terms of the
27 1.1.1.1.10.2 tls * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.1.10.2 tls * Software Foundation.
29 1.1.1.1.10.2 tls *
30 1.1.1.1.10.2 tls * NO WARRANTY
31 1.1.1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.1.10.2 tls * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.1.10.2 tls * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.1.10.2 tls * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.1.10.2 tls * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.1.10.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.1.10.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.1.10.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.1.10.2 tls * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.1.10.2 tls * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.1.10.2 tls * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.1.10.2 tls */
43 1.1.1.1.10.2 tls
44 1.1.1.1.10.2 tls #include "acpi.h"
45 1.1.1.1.10.2 tls #include "accommon.h"
46 1.1.1.1.10.2 tls #include "acnamesp.h"
47 1.1.1.1.10.2 tls #include "acpredef.h"
48 1.1.1.1.10.2 tls
49 1.1.1.1.10.2 tls
50 1.1.1.1.10.2 tls #define _COMPONENT ACPI_NAMESPACE
51 1.1.1.1.10.2 tls ACPI_MODULE_NAME ("nsarguments")
52 1.1.1.1.10.2 tls
53 1.1.1.1.10.2 tls
54 1.1.1.1.10.2 tls /*******************************************************************************
55 1.1.1.1.10.2 tls *
56 1.1.1.1.10.2 tls * FUNCTION: AcpiNsCheckArgumentTypes
57 1.1.1.1.10.2 tls *
58 1.1.1.1.10.2 tls * PARAMETERS: Info - Method execution information block
59 1.1.1.1.10.2 tls *
60 1.1.1.1.10.2 tls * RETURN: None
61 1.1.1.1.10.2 tls *
62 1.1.1.1.10.2 tls * DESCRIPTION: Check the incoming argument count and all argument types
63 1.1.1.1.10.2 tls * against the argument type list for a predefined name.
64 1.1.1.1.10.2 tls *
65 1.1.1.1.10.2 tls ******************************************************************************/
66 1.1.1.1.10.2 tls
67 1.1.1.1.10.2 tls void
68 1.1.1.1.10.2 tls AcpiNsCheckArgumentTypes (
69 1.1.1.1.10.2 tls ACPI_EVALUATE_INFO *Info)
70 1.1.1.1.10.2 tls {
71 1.1.1.1.10.2 tls UINT16 ArgTypeList;
72 1.1.1.1.10.2 tls UINT8 ArgCount;
73 1.1.1.1.10.2 tls UINT8 ArgType;
74 1.1.1.1.10.2 tls UINT8 UserArgType;
75 1.1.1.1.10.2 tls UINT32 i;
76 1.1.1.1.10.2 tls
77 1.1.1.1.10.2 tls
78 1.1.1.1.10.3 jdolecek /*
79 1.1.1.1.10.3 jdolecek * If not a predefined name, cannot typecheck args, because
80 1.1.1.1.10.3 jdolecek * we have no idea what argument types are expected.
81 1.1.1.1.10.3 jdolecek * Also, ignore typecheck if warnings/errors if this method
82 1.1.1.1.10.3 jdolecek * has already been evaluated at least once -- in order
83 1.1.1.1.10.3 jdolecek * to suppress repetitive messages.
84 1.1.1.1.10.3 jdolecek */
85 1.1.1.1.10.3 jdolecek if (!Info->Predefined || (Info->Node->Flags & ANOBJ_EVALUATED))
86 1.1.1.1.10.2 tls {
87 1.1.1.1.10.2 tls return;
88 1.1.1.1.10.2 tls }
89 1.1.1.1.10.2 tls
90 1.1.1.1.10.2 tls ArgTypeList = Info->Predefined->Info.ArgumentList;
91 1.1.1.1.10.2 tls ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList);
92 1.1.1.1.10.2 tls
93 1.1.1.1.10.2 tls /* Typecheck all arguments */
94 1.1.1.1.10.2 tls
95 1.1.1.1.10.2 tls for (i = 0; ((i < ArgCount) && (i < Info->ParamCount)); i++)
96 1.1.1.1.10.2 tls {
97 1.1.1.1.10.2 tls ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList);
98 1.1.1.1.10.2 tls UserArgType = Info->Parameters[i]->Common.Type;
99 1.1.1.1.10.2 tls
100 1.1.1.1.10.2 tls if (UserArgType != ArgType)
101 1.1.1.1.10.2 tls {
102 1.1.1.1.10.2 tls ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS,
103 1.1.1.1.10.2 tls "Argument #%u type mismatch - "
104 1.1.1.1.10.2 tls "Found [%s], ACPI requires [%s]", (i + 1),
105 1.1.1.1.10.2 tls AcpiUtGetTypeName (UserArgType),
106 1.1.1.1.10.2 tls AcpiUtGetTypeName (ArgType)));
107 1.1.1.1.10.3 jdolecek
108 1.1.1.1.10.3 jdolecek /* Prevent any additional typechecking for this method */
109 1.1.1.1.10.3 jdolecek
110 1.1.1.1.10.3 jdolecek Info->Node->Flags |= ANOBJ_EVALUATED;
111 1.1.1.1.10.2 tls }
112 1.1.1.1.10.2 tls }
113 1.1.1.1.10.2 tls }
114 1.1.1.1.10.2 tls
115 1.1.1.1.10.2 tls
116 1.1.1.1.10.2 tls /*******************************************************************************
117 1.1.1.1.10.2 tls *
118 1.1.1.1.10.2 tls * FUNCTION: AcpiNsCheckAcpiCompliance
119 1.1.1.1.10.2 tls *
120 1.1.1.1.10.2 tls * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
121 1.1.1.1.10.2 tls * Node - Namespace node for the method/object
122 1.1.1.1.10.2 tls * Predefined - Pointer to entry in predefined name table
123 1.1.1.1.10.2 tls *
124 1.1.1.1.10.2 tls * RETURN: None
125 1.1.1.1.10.2 tls *
126 1.1.1.1.10.2 tls * DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a
127 1.1.1.1.10.2 tls * predefined name is what is expected (matches what is defined in
128 1.1.1.1.10.2 tls * the ACPI specification for this predefined name.)
129 1.1.1.1.10.2 tls *
130 1.1.1.1.10.2 tls ******************************************************************************/
131 1.1.1.1.10.2 tls
132 1.1.1.1.10.2 tls void
133 1.1.1.1.10.2 tls AcpiNsCheckAcpiCompliance (
134 1.1.1.1.10.2 tls char *Pathname,
135 1.1.1.1.10.2 tls ACPI_NAMESPACE_NODE *Node,
136 1.1.1.1.10.2 tls const ACPI_PREDEFINED_INFO *Predefined)
137 1.1.1.1.10.2 tls {
138 1.1.1.1.10.2 tls UINT32 AmlParamCount;
139 1.1.1.1.10.2 tls UINT32 RequiredParamCount;
140 1.1.1.1.10.2 tls
141 1.1.1.1.10.2 tls
142 1.1.1.1.10.3 jdolecek if (!Predefined || (Node->Flags & ANOBJ_EVALUATED))
143 1.1.1.1.10.2 tls {
144 1.1.1.1.10.2 tls return;
145 1.1.1.1.10.2 tls }
146 1.1.1.1.10.2 tls
147 1.1.1.1.10.2 tls /* Get the ACPI-required arg count from the predefined info table */
148 1.1.1.1.10.2 tls
149 1.1.1.1.10.3 jdolecek RequiredParamCount =
150 1.1.1.1.10.3 jdolecek METHOD_GET_ARG_COUNT (Predefined->Info.ArgumentList);
151 1.1.1.1.10.2 tls
152 1.1.1.1.10.2 tls /*
153 1.1.1.1.10.2 tls * If this object is not a control method, we can check if the ACPI
154 1.1.1.1.10.2 tls * spec requires that it be a method.
155 1.1.1.1.10.2 tls */
156 1.1.1.1.10.2 tls if (Node->Type != ACPI_TYPE_METHOD)
157 1.1.1.1.10.2 tls {
158 1.1.1.1.10.2 tls if (RequiredParamCount > 0)
159 1.1.1.1.10.2 tls {
160 1.1.1.1.10.2 tls /* Object requires args, must be implemented as a method */
161 1.1.1.1.10.2 tls
162 1.1.1.1.10.2 tls ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
163 1.1.1.1.10.2 tls "Object (%s) must be a control method with %u arguments",
164 1.1.1.1.10.2 tls AcpiUtGetTypeName (Node->Type), RequiredParamCount));
165 1.1.1.1.10.2 tls }
166 1.1.1.1.10.2 tls else if (!RequiredParamCount && !Predefined->Info.ExpectedBtypes)
167 1.1.1.1.10.2 tls {
168 1.1.1.1.10.2 tls /* Object requires no args and no return value, must be a method */
169 1.1.1.1.10.2 tls
170 1.1.1.1.10.2 tls ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
171 1.1.1.1.10.2 tls "Object (%s) must be a control method "
172 1.1.1.1.10.2 tls "with no arguments and no return value",
173 1.1.1.1.10.2 tls AcpiUtGetTypeName (Node->Type)));
174 1.1.1.1.10.2 tls }
175 1.1.1.1.10.2 tls
176 1.1.1.1.10.2 tls return;
177 1.1.1.1.10.2 tls }
178 1.1.1.1.10.2 tls
179 1.1.1.1.10.2 tls /*
180 1.1.1.1.10.2 tls * This is a control method.
181 1.1.1.1.10.2 tls * Check that the ASL/AML-defined parameter count for this method
182 1.1.1.1.10.2 tls * matches the ACPI-required parameter count
183 1.1.1.1.10.2 tls *
184 1.1.1.1.10.2 tls * Some methods are allowed to have a "minimum" number of args (_SCP)
185 1.1.1.1.10.2 tls * because their definition in ACPI has changed over time.
186 1.1.1.1.10.2 tls *
187 1.1.1.1.10.2 tls * Note: These are BIOS errors in the declaration of the object
188 1.1.1.1.10.2 tls */
189 1.1.1.1.10.2 tls AmlParamCount = Node->Object->Method.ParamCount;
190 1.1.1.1.10.2 tls
191 1.1.1.1.10.2 tls if (AmlParamCount < RequiredParamCount)
192 1.1.1.1.10.2 tls {
193 1.1.1.1.10.2 tls ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
194 1.1.1.1.10.2 tls "Insufficient arguments - "
195 1.1.1.1.10.2 tls "ASL declared %u, ACPI requires %u",
196 1.1.1.1.10.2 tls AmlParamCount, RequiredParamCount));
197 1.1.1.1.10.2 tls }
198 1.1.1.1.10.2 tls else if ((AmlParamCount > RequiredParamCount) &&
199 1.1.1.1.10.2 tls !(Predefined->Info.ArgumentList & ARG_COUNT_IS_MINIMUM))
200 1.1.1.1.10.2 tls {
201 1.1.1.1.10.2 tls ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
202 1.1.1.1.10.2 tls "Excess arguments - "
203 1.1.1.1.10.2 tls "ASL declared %u, ACPI requires %u",
204 1.1.1.1.10.2 tls AmlParamCount, RequiredParamCount));
205 1.1.1.1.10.2 tls }
206 1.1.1.1.10.2 tls }
207 1.1.1.1.10.2 tls
208 1.1.1.1.10.2 tls
209 1.1.1.1.10.2 tls /*******************************************************************************
210 1.1.1.1.10.2 tls *
211 1.1.1.1.10.2 tls * FUNCTION: AcpiNsCheckArgumentCount
212 1.1.1.1.10.2 tls *
213 1.1.1.1.10.2 tls * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
214 1.1.1.1.10.2 tls * Node - Namespace node for the method/object
215 1.1.1.1.10.2 tls * UserParamCount - Number of args passed in by the caller
216 1.1.1.1.10.2 tls * Predefined - Pointer to entry in predefined name table
217 1.1.1.1.10.2 tls *
218 1.1.1.1.10.2 tls * RETURN: None
219 1.1.1.1.10.2 tls *
220 1.1.1.1.10.2 tls * DESCRIPTION: Check that incoming argument count matches the declared
221 1.1.1.1.10.2 tls * parameter count (in the ASL/AML) for an object.
222 1.1.1.1.10.2 tls *
223 1.1.1.1.10.2 tls ******************************************************************************/
224 1.1.1.1.10.2 tls
225 1.1.1.1.10.2 tls void
226 1.1.1.1.10.2 tls AcpiNsCheckArgumentCount (
227 1.1.1.1.10.2 tls char *Pathname,
228 1.1.1.1.10.2 tls ACPI_NAMESPACE_NODE *Node,
229 1.1.1.1.10.2 tls UINT32 UserParamCount,
230 1.1.1.1.10.2 tls const ACPI_PREDEFINED_INFO *Predefined)
231 1.1.1.1.10.2 tls {
232 1.1.1.1.10.2 tls UINT32 AmlParamCount;
233 1.1.1.1.10.2 tls UINT32 RequiredParamCount;
234 1.1.1.1.10.2 tls
235 1.1.1.1.10.2 tls
236 1.1.1.1.10.3 jdolecek if (Node->Flags & ANOBJ_EVALUATED)
237 1.1.1.1.10.3 jdolecek {
238 1.1.1.1.10.3 jdolecek return;
239 1.1.1.1.10.3 jdolecek }
240 1.1.1.1.10.3 jdolecek
241 1.1.1.1.10.2 tls if (!Predefined)
242 1.1.1.1.10.2 tls {
243 1.1.1.1.10.2 tls /*
244 1.1.1.1.10.2 tls * Not a predefined name. Check the incoming user argument count
245 1.1.1.1.10.2 tls * against the count that is specified in the method/object.
246 1.1.1.1.10.2 tls */
247 1.1.1.1.10.2 tls if (Node->Type != ACPI_TYPE_METHOD)
248 1.1.1.1.10.2 tls {
249 1.1.1.1.10.2 tls if (UserParamCount)
250 1.1.1.1.10.2 tls {
251 1.1.1.1.10.2 tls ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
252 1.1.1.1.10.2 tls "%u arguments were passed to a non-method ACPI object (%s)",
253 1.1.1.1.10.2 tls UserParamCount, AcpiUtGetTypeName (Node->Type)));
254 1.1.1.1.10.2 tls }
255 1.1.1.1.10.2 tls
256 1.1.1.1.10.2 tls return;
257 1.1.1.1.10.2 tls }
258 1.1.1.1.10.2 tls
259 1.1.1.1.10.2 tls /*
260 1.1.1.1.10.2 tls * This is a control method. Check the parameter count.
261 1.1.1.1.10.2 tls * We can only check the incoming argument count against the
262 1.1.1.1.10.2 tls * argument count declared for the method in the ASL/AML.
263 1.1.1.1.10.2 tls *
264 1.1.1.1.10.2 tls * Emit a message if too few or too many arguments have been passed
265 1.1.1.1.10.2 tls * by the caller.
266 1.1.1.1.10.2 tls *
267 1.1.1.1.10.2 tls * Note: Too many arguments will not cause the method to
268 1.1.1.1.10.2 tls * fail. However, the method will fail if there are too few
269 1.1.1.1.10.2 tls * arguments and the method attempts to use one of the missing ones.
270 1.1.1.1.10.2 tls */
271 1.1.1.1.10.2 tls AmlParamCount = Node->Object->Method.ParamCount;
272 1.1.1.1.10.2 tls
273 1.1.1.1.10.2 tls if (UserParamCount < AmlParamCount)
274 1.1.1.1.10.2 tls {
275 1.1.1.1.10.2 tls ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
276 1.1.1.1.10.2 tls "Insufficient arguments - "
277 1.1.1.1.10.2 tls "Caller passed %u, method requires %u",
278 1.1.1.1.10.2 tls UserParamCount, AmlParamCount));
279 1.1.1.1.10.2 tls }
280 1.1.1.1.10.2 tls else if (UserParamCount > AmlParamCount)
281 1.1.1.1.10.2 tls {
282 1.1.1.1.10.2 tls ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
283 1.1.1.1.10.2 tls "Excess arguments - "
284 1.1.1.1.10.2 tls "Caller passed %u, method requires %u",
285 1.1.1.1.10.2 tls UserParamCount, AmlParamCount));
286 1.1.1.1.10.2 tls }
287 1.1.1.1.10.2 tls
288 1.1.1.1.10.2 tls return;
289 1.1.1.1.10.2 tls }
290 1.1.1.1.10.2 tls
291 1.1.1.1.10.2 tls /*
292 1.1.1.1.10.2 tls * This is a predefined name. Validate the user-supplied parameter
293 1.1.1.1.10.2 tls * count against the ACPI specification. We don't validate against
294 1.1.1.1.10.2 tls * the method itself because what is important here is that the
295 1.1.1.1.10.2 tls * caller is in conformance with the spec. (The arg count for the
296 1.1.1.1.10.2 tls * method was checked against the ACPI spec earlier.)
297 1.1.1.1.10.2 tls *
298 1.1.1.1.10.2 tls * Some methods are allowed to have a "minimum" number of args (_SCP)
299 1.1.1.1.10.2 tls * because their definition in ACPI has changed over time.
300 1.1.1.1.10.2 tls */
301 1.1.1.1.10.3 jdolecek RequiredParamCount =
302 1.1.1.1.10.3 jdolecek METHOD_GET_ARG_COUNT (Predefined->Info.ArgumentList);
303 1.1.1.1.10.2 tls
304 1.1.1.1.10.2 tls if (UserParamCount < RequiredParamCount)
305 1.1.1.1.10.2 tls {
306 1.1.1.1.10.2 tls ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
307 1.1.1.1.10.2 tls "Insufficient arguments - "
308 1.1.1.1.10.2 tls "Caller passed %u, ACPI requires %u",
309 1.1.1.1.10.2 tls UserParamCount, RequiredParamCount));
310 1.1.1.1.10.2 tls }
311 1.1.1.1.10.2 tls else if ((UserParamCount > RequiredParamCount) &&
312 1.1.1.1.10.2 tls !(Predefined->Info.ArgumentList & ARG_COUNT_IS_MINIMUM))
313 1.1.1.1.10.2 tls {
314 1.1.1.1.10.2 tls ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
315 1.1.1.1.10.2 tls "Excess arguments - "
316 1.1.1.1.10.2 tls "Caller passed %u, ACPI requires %u",
317 1.1.1.1.10.2 tls UserParamCount, RequiredParamCount));
318 1.1.1.1.10.2 tls }
319 1.1.1.1.10.2 tls }
320