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