nsprepkg.c revision 1.1.1.17 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: nsprepkg - Validation of package objects for predefined names
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1.1.16 christos /******************************************************************************
8 1.1.1.16 christos *
9 1.1.1.16 christos * 1. Copyright Notice
10 1.1.1.16 christos *
11 1.1.1.17 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
12 1.1 christos * All rights reserved.
13 1.1 christos *
14 1.1.1.16 christos * 2. License
15 1.1.1.16 christos *
16 1.1.1.16 christos * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.1.1.16 christos * rights. You may have additional license terms from the party that provided
18 1.1.1.16 christos * you this software, covering your right to use that party's intellectual
19 1.1.1.16 christos * property rights.
20 1.1.1.16 christos *
21 1.1.1.16 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.1.1.16 christos * copy of the source code appearing in this file ("Covered Code") an
23 1.1.1.16 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.1.1.16 christos * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.1.1.16 christos * make derivatives, distribute, use and display any portion of the Covered
26 1.1.1.16 christos * Code in any form, with the right to sublicense such rights; and
27 1.1.1.16 christos *
28 1.1.1.16 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.1.1.16 christos * license (with the right to sublicense), under only those claims of Intel
30 1.1.1.16 christos * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.1.1.16 christos * offer to sell, and import the Covered Code and derivative works thereof
32 1.1.1.16 christos * solely to the minimum extent necessary to exercise the above copyright
33 1.1.1.16 christos * license, and in no event shall the patent license extend to any additions
34 1.1.1.16 christos * to or modifications of the Original Intel Code. No other license or right
35 1.1.1.16 christos * is granted directly or by implication, estoppel or otherwise;
36 1.1.1.16 christos *
37 1.1.1.16 christos * The above copyright and patent license is granted only if the following
38 1.1.1.16 christos * conditions are met:
39 1.1.1.16 christos *
40 1.1.1.16 christos * 3. Conditions
41 1.1.1.16 christos *
42 1.1.1.16 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.1.1.16 christos * Redistribution of source code of any substantial portion of the Covered
44 1.1.1.16 christos * Code or modification with rights to further distribute source must include
45 1.1.1.16 christos * the above Copyright Notice, the above License, this list of Conditions,
46 1.1.1.16 christos * and the following Disclaimer and Export Compliance provision. In addition,
47 1.1.1.16 christos * Licensee must cause all Covered Code to which Licensee contributes to
48 1.1.1.16 christos * contain a file documenting the changes Licensee made to create that Covered
49 1.1.1.16 christos * Code and the date of any change. Licensee must include in that file the
50 1.1.1.16 christos * documentation of any changes made by any predecessor Licensee. Licensee
51 1.1.1.16 christos * must include a prominent statement that the modification is derived,
52 1.1.1.16 christos * directly or indirectly, from Original Intel Code.
53 1.1.1.16 christos *
54 1.1.1.16 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.1.1.16 christos * Redistribution of source code of any substantial portion of the Covered
56 1.1.1.16 christos * Code or modification without rights to further distribute source must
57 1.1.1.16 christos * include the following Disclaimer and Export Compliance provision in the
58 1.1.1.16 christos * documentation and/or other materials provided with distribution. In
59 1.1.1.16 christos * addition, Licensee may not authorize further sublicense of source of any
60 1.1.1.16 christos * portion of the Covered Code, and must include terms to the effect that the
61 1.1.1.16 christos * license from Licensee to its licensee is limited to the intellectual
62 1.1.1.16 christos * property embodied in the software Licensee provides to its licensee, and
63 1.1.1.16 christos * not to intellectual property embodied in modifications its licensee may
64 1.1.1.16 christos * make.
65 1.1.1.16 christos *
66 1.1.1.16 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.1.1.16 christos * substantial portion of the Covered Code or modification must reproduce the
68 1.1.1.16 christos * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.1.1.16 christos * provision in the documentation and/or other materials provided with the
70 1.1.1.16 christos * distribution.
71 1.1.1.16 christos *
72 1.1.1.16 christos * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.1.1.16 christos * Intel Code.
74 1.1.1.16 christos *
75 1.1.1.16 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.1.1.16 christos * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.1.1.16 christos * other dealings in products derived from or relating to the Covered Code
78 1.1.1.16 christos * without prior written authorization from Intel.
79 1.1.1.16 christos *
80 1.1.1.16 christos * 4. Disclaimer and Export Compliance
81 1.1.1.16 christos *
82 1.1.1.16 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.1.1.16 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.1.1.16 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.1.1.16 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.1.1.16 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.1.1.16 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.1.1.16 christos * PARTICULAR PURPOSE.
89 1.1.1.16 christos *
90 1.1.1.16 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.1.1.16 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.1.1.16 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.1.1.16 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.1.1.16 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.1.1.16 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.1.1.16 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.1.1.16 christos * LIMITED REMEDY.
98 1.1.1.16 christos *
99 1.1.1.16 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.1.1.16 christos * software or system incorporating such software without first obtaining any
101 1.1.1.16 christos * required license or other approval from the U. S. Department of Commerce or
102 1.1.1.16 christos * any other agency or department of the United States Government. In the
103 1.1.1.16 christos * event Licensee exports any such software from the United States or
104 1.1.1.16 christos * re-exports any such software from a foreign destination, Licensee shall
105 1.1.1.16 christos * ensure that the distribution and export/re-export of the software is in
106 1.1.1.16 christos * compliance with all laws, regulations, orders, or other restrictions of the
107 1.1.1.16 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.1.1.16 christos * any of its subsidiaries will export/re-export any technical data, process,
109 1.1.1.16 christos * software, or service, directly or indirectly, to any country for which the
110 1.1.1.16 christos * United States government or any agency thereof requires an export license,
111 1.1.1.16 christos * other governmental approval, or letter of assurance, without first obtaining
112 1.1.1.16 christos * such license, approval or letter.
113 1.1.1.16 christos *
114 1.1.1.16 christos *****************************************************************************
115 1.1.1.16 christos *
116 1.1.1.16 christos * Alternatively, you may choose to be licensed under the terms of the
117 1.1.1.16 christos * following license:
118 1.1.1.16 christos *
119 1.1 christos * Redistribution and use in source and binary forms, with or without
120 1.1 christos * modification, are permitted provided that the following conditions
121 1.1 christos * are met:
122 1.1 christos * 1. Redistributions of source code must retain the above copyright
123 1.1 christos * notice, this list of conditions, and the following disclaimer,
124 1.1 christos * without modification.
125 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
127 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
128 1.1 christos * including a substantially similar Disclaimer requirement for further
129 1.1 christos * binary redistribution.
130 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
131 1.1 christos * of any contributors may be used to endorse or promote products derived
132 1.1 christos * from this software without specific prior written permission.
133 1.1 christos *
134 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 1.1.1.13 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 1.1.1.16 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 1.1.1.16 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 1.1.1.16 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 1.1.1.16 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 1.1.1.16 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 1.1.1.16 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 1.1.1.16 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 1.1.1.16 christos *
146 1.1.1.16 christos * Alternatively, you may choose to be licensed under the terms of the
147 1.1.1.16 christos * GNU General Public License ("GPL") version 2 as published by the Free
148 1.1.1.16 christos * Software Foundation.
149 1.1.1.16 christos *
150 1.1.1.16 christos *****************************************************************************/
151 1.1 christos
152 1.1 christos #include "acpi.h"
153 1.1 christos #include "accommon.h"
154 1.1 christos #include "acnamesp.h"
155 1.1 christos #include "acpredef.h"
156 1.1 christos
157 1.1 christos
158 1.1 christos #define _COMPONENT ACPI_NAMESPACE
159 1.1 christos ACPI_MODULE_NAME ("nsprepkg")
160 1.1 christos
161 1.1 christos
162 1.1 christos /* Local prototypes */
163 1.1 christos
164 1.1 christos static ACPI_STATUS
165 1.1 christos AcpiNsCheckPackageList (
166 1.1 christos ACPI_EVALUATE_INFO *Info,
167 1.1 christos const ACPI_PREDEFINED_INFO *Package,
168 1.1 christos ACPI_OPERAND_OBJECT **Elements,
169 1.1 christos UINT32 Count);
170 1.1 christos
171 1.1 christos static ACPI_STATUS
172 1.1 christos AcpiNsCheckPackageElements (
173 1.1 christos ACPI_EVALUATE_INFO *Info,
174 1.1 christos ACPI_OPERAND_OBJECT **Elements,
175 1.1 christos UINT8 Type1,
176 1.1 christos UINT32 Count1,
177 1.1 christos UINT8 Type2,
178 1.1 christos UINT32 Count2,
179 1.1 christos UINT32 StartIndex);
180 1.1 christos
181 1.1.1.6 christos static ACPI_STATUS
182 1.1.1.6 christos AcpiNsCustomPackage (
183 1.1.1.6 christos ACPI_EVALUATE_INFO *Info,
184 1.1.1.6 christos ACPI_OPERAND_OBJECT **Elements,
185 1.1.1.6 christos UINT32 Count);
186 1.1.1.6 christos
187 1.1 christos
188 1.1 christos /*******************************************************************************
189 1.1 christos *
190 1.1 christos * FUNCTION: AcpiNsCheckPackage
191 1.1 christos *
192 1.1 christos * PARAMETERS: Info - Method execution information block
193 1.1 christos * ReturnObjectPtr - Pointer to the object returned from the
194 1.1 christos * evaluation of a method or object
195 1.1 christos *
196 1.1 christos * RETURN: Status
197 1.1 christos *
198 1.1 christos * DESCRIPTION: Check a returned package object for the correct count and
199 1.1 christos * correct type of all sub-objects.
200 1.1 christos *
201 1.1 christos ******************************************************************************/
202 1.1 christos
203 1.1 christos ACPI_STATUS
204 1.1 christos AcpiNsCheckPackage (
205 1.1 christos ACPI_EVALUATE_INFO *Info,
206 1.1 christos ACPI_OPERAND_OBJECT **ReturnObjectPtr)
207 1.1 christos {
208 1.1 christos ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
209 1.1 christos const ACPI_PREDEFINED_INFO *Package;
210 1.1 christos ACPI_OPERAND_OBJECT **Elements;
211 1.1 christos ACPI_STATUS Status = AE_OK;
212 1.1 christos UINT32 ExpectedCount;
213 1.1 christos UINT32 Count;
214 1.1 christos UINT32 i;
215 1.1 christos
216 1.1 christos
217 1.1.1.12 christos ACPI_FUNCTION_TRACE (NsCheckPackage);
218 1.1 christos
219 1.1 christos
220 1.1 christos /* The package info for this name is in the next table entry */
221 1.1 christos
222 1.1 christos Package = Info->Predefined + 1;
223 1.1 christos
224 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
225 1.1 christos "%s Validating return Package of Type %X, Count %X\n",
226 1.1 christos Info->FullPathname, Package->RetInfo.Type,
227 1.1 christos ReturnObject->Package.Count));
228 1.1 christos
229 1.1 christos /*
230 1.1 christos * For variable-length Packages, we can safely remove all embedded
231 1.1 christos * and trailing NULL package elements
232 1.1 christos */
233 1.1 christos AcpiNsRemoveNullElements (Info, Package->RetInfo.Type, ReturnObject);
234 1.1 christos
235 1.1 christos /* Extract package count and elements array */
236 1.1 christos
237 1.1 christos Elements = ReturnObject->Package.Elements;
238 1.1 christos Count = ReturnObject->Package.Count;
239 1.1 christos
240 1.1 christos /*
241 1.1 christos * Most packages must have at least one element. The only exception
242 1.1 christos * is the variable-length package (ACPI_PTYPE1_VAR).
243 1.1 christos */
244 1.1 christos if (!Count)
245 1.1 christos {
246 1.1 christos if (Package->RetInfo.Type == ACPI_PTYPE1_VAR)
247 1.1 christos {
248 1.1.1.12 christos return_ACPI_STATUS (AE_OK);
249 1.1 christos }
250 1.1 christos
251 1.1 christos ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
252 1.1 christos "Return Package has no elements (empty)"));
253 1.1 christos
254 1.1.1.12 christos return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
255 1.1 christos }
256 1.1 christos
257 1.1 christos /*
258 1.1 christos * Decode the type of the expected package contents
259 1.1 christos *
260 1.1 christos * PTYPE1 packages contain no subpackages
261 1.1.1.2 christos * PTYPE2 packages contain subpackages
262 1.1 christos */
263 1.1 christos switch (Package->RetInfo.Type)
264 1.1 christos {
265 1.1.1.6 christos case ACPI_PTYPE_CUSTOM:
266 1.1.1.6 christos
267 1.1.1.6 christos Status = AcpiNsCustomPackage (Info, Elements, Count);
268 1.1.1.6 christos break;
269 1.1.1.6 christos
270 1.1 christos case ACPI_PTYPE1_FIXED:
271 1.1 christos /*
272 1.1.1.2 christos * The package count is fixed and there are no subpackages
273 1.1 christos *
274 1.1 christos * If package is too small, exit.
275 1.1 christos * If package is larger than expected, issue warning but continue
276 1.1 christos */
277 1.1 christos ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
278 1.1 christos if (Count < ExpectedCount)
279 1.1 christos {
280 1.1 christos goto PackageTooSmall;
281 1.1 christos }
282 1.1 christos else if (Count > ExpectedCount)
283 1.1 christos {
284 1.1 christos ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
285 1.1 christos "%s: Return Package is larger than needed - "
286 1.1 christos "found %u, expected %u\n",
287 1.1 christos Info->FullPathname, Count, ExpectedCount));
288 1.1 christos }
289 1.1 christos
290 1.1 christos /* Validate all elements of the returned package */
291 1.1 christos
292 1.1 christos Status = AcpiNsCheckPackageElements (Info, Elements,
293 1.1.1.5 christos Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
294 1.1.1.5 christos Package->RetInfo.ObjectType2, Package->RetInfo.Count2, 0);
295 1.1 christos break;
296 1.1 christos
297 1.1 christos case ACPI_PTYPE1_VAR:
298 1.1 christos /*
299 1.1.1.2 christos * The package count is variable, there are no subpackages, and all
300 1.1 christos * elements must be of the same type
301 1.1 christos */
302 1.1 christos for (i = 0; i < Count; i++)
303 1.1 christos {
304 1.1 christos Status = AcpiNsCheckObjectType (Info, Elements,
305 1.1.1.5 christos Package->RetInfo.ObjectType1, i);
306 1.1 christos if (ACPI_FAILURE (Status))
307 1.1 christos {
308 1.1.1.12 christos return_ACPI_STATUS (Status);
309 1.1 christos }
310 1.1.1.6 christos
311 1.1 christos Elements++;
312 1.1 christos }
313 1.1 christos break;
314 1.1 christos
315 1.1 christos case ACPI_PTYPE1_OPTION:
316 1.1 christos /*
317 1.1.1.2 christos * The package count is variable, there are no subpackages. There are
318 1.1 christos * a fixed number of required elements, and a variable number of
319 1.1 christos * optional elements.
320 1.1 christos *
321 1.1 christos * Check if package is at least as large as the minimum required
322 1.1 christos */
323 1.1 christos ExpectedCount = Package->RetInfo3.Count;
324 1.1 christos if (Count < ExpectedCount)
325 1.1 christos {
326 1.1 christos goto PackageTooSmall;
327 1.1 christos }
328 1.1 christos
329 1.1 christos /* Variable number of sub-objects */
330 1.1 christos
331 1.1 christos for (i = 0; i < Count; i++)
332 1.1 christos {
333 1.1 christos if (i < Package->RetInfo3.Count)
334 1.1 christos {
335 1.1 christos /* These are the required package elements (0, 1, or 2) */
336 1.1 christos
337 1.1 christos Status = AcpiNsCheckObjectType (Info, Elements,
338 1.1.1.5 christos Package->RetInfo3.ObjectType[i], i);
339 1.1 christos if (ACPI_FAILURE (Status))
340 1.1 christos {
341 1.1.1.12 christos return_ACPI_STATUS (Status);
342 1.1 christos }
343 1.1 christos }
344 1.1 christos else
345 1.1 christos {
346 1.1 christos /* These are the optional package elements */
347 1.1 christos
348 1.1 christos Status = AcpiNsCheckObjectType (Info, Elements,
349 1.1.1.5 christos Package->RetInfo3.TailObjectType, i);
350 1.1 christos if (ACPI_FAILURE (Status))
351 1.1 christos {
352 1.1.1.12 christos return_ACPI_STATUS (Status);
353 1.1 christos }
354 1.1 christos }
355 1.1.1.6 christos
356 1.1 christos Elements++;
357 1.1 christos }
358 1.1 christos break;
359 1.1 christos
360 1.1 christos case ACPI_PTYPE2_REV_FIXED:
361 1.1 christos
362 1.1 christos /* First element is the (Integer) revision */
363 1.1 christos
364 1.1.1.5 christos Status = AcpiNsCheckObjectType (
365 1.1.1.5 christos Info, Elements, ACPI_RTYPE_INTEGER, 0);
366 1.1 christos if (ACPI_FAILURE (Status))
367 1.1 christos {
368 1.1.1.12 christos return_ACPI_STATUS (Status);
369 1.1 christos }
370 1.1 christos
371 1.1 christos Elements++;
372 1.1 christos Count--;
373 1.1 christos
374 1.1.1.2 christos /* Examine the subpackages */
375 1.1 christos
376 1.1 christos Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
377 1.1 christos break;
378 1.1 christos
379 1.1 christos case ACPI_PTYPE2_PKG_COUNT:
380 1.1 christos
381 1.1.1.2 christos /* First element is the (Integer) count of subpackages to follow */
382 1.1 christos
383 1.1.1.5 christos Status = AcpiNsCheckObjectType (
384 1.1.1.5 christos Info, Elements, ACPI_RTYPE_INTEGER, 0);
385 1.1 christos if (ACPI_FAILURE (Status))
386 1.1 christos {
387 1.1.1.12 christos return_ACPI_STATUS (Status);
388 1.1 christos }
389 1.1 christos
390 1.1 christos /*
391 1.1 christos * Count cannot be larger than the parent package length, but allow it
392 1.1 christos * to be smaller. The >= accounts for the Integer above.
393 1.1 christos */
394 1.1 christos ExpectedCount = (UINT32) (*Elements)->Integer.Value;
395 1.1 christos if (ExpectedCount >= Count)
396 1.1 christos {
397 1.1 christos goto PackageTooSmall;
398 1.1 christos }
399 1.1 christos
400 1.1 christos Count = ExpectedCount;
401 1.1 christos Elements++;
402 1.1 christos
403 1.1.1.2 christos /* Examine the subpackages */
404 1.1 christos
405 1.1 christos Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
406 1.1 christos break;
407 1.1 christos
408 1.1 christos case ACPI_PTYPE2:
409 1.1 christos case ACPI_PTYPE2_FIXED:
410 1.1 christos case ACPI_PTYPE2_MIN:
411 1.1 christos case ACPI_PTYPE2_COUNT:
412 1.1 christos case ACPI_PTYPE2_FIX_VAR:
413 1.1 christos /*
414 1.1 christos * These types all return a single Package that consists of a
415 1.1.1.2 christos * variable number of subpackages.
416 1.1 christos *
417 1.1.1.2 christos * First, ensure that the first element is a subpackage. If not,
418 1.1 christos * the BIOS may have incorrectly returned the object as a single
419 1.1 christos * package instead of a Package of Packages (a common error if
420 1.1 christos * there is only one entry). We may be able to repair this by
421 1.1 christos * wrapping the returned Package with a new outer Package.
422 1.1 christos */
423 1.1 christos if (*Elements && ((*Elements)->Common.Type != ACPI_TYPE_PACKAGE))
424 1.1 christos {
425 1.1 christos /* Create the new outer package and populate it */
426 1.1 christos
427 1.1.1.5 christos Status = AcpiNsWrapWithPackage (
428 1.1.1.5 christos Info, ReturnObject, ReturnObjectPtr);
429 1.1 christos if (ACPI_FAILURE (Status))
430 1.1 christos {
431 1.1.1.12 christos return_ACPI_STATUS (Status);
432 1.1 christos }
433 1.1 christos
434 1.1 christos /* Update locals to point to the new package (of 1 element) */
435 1.1 christos
436 1.1 christos ReturnObject = *ReturnObjectPtr;
437 1.1 christos Elements = ReturnObject->Package.Elements;
438 1.1 christos Count = 1;
439 1.1 christos }
440 1.1 christos
441 1.1.1.2 christos /* Examine the subpackages */
442 1.1 christos
443 1.1 christos Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
444 1.1 christos break;
445 1.1 christos
446 1.1.1.4 christos case ACPI_PTYPE2_VAR_VAR:
447 1.1.1.4 christos /*
448 1.1.1.4 christos * Returns a variable list of packages, each with a variable list
449 1.1.1.4 christos * of objects.
450 1.1.1.4 christos */
451 1.1.1.4 christos break;
452 1.1.1.4 christos
453 1.1.1.2 christos case ACPI_PTYPE2_UUID_PAIR:
454 1.1.1.2 christos
455 1.1.1.2 christos /* The package must contain pairs of (UUID + type) */
456 1.1.1.2 christos
457 1.1.1.2 christos if (Count & 1)
458 1.1.1.2 christos {
459 1.1.1.2 christos ExpectedCount = Count + 1;
460 1.1.1.2 christos goto PackageTooSmall;
461 1.1.1.2 christos }
462 1.1.1.2 christos
463 1.1.1.2 christos while (Count > 0)
464 1.1.1.2 christos {
465 1.1.1.2 christos Status = AcpiNsCheckObjectType(Info, Elements,
466 1.1.1.6 christos Package->RetInfo.ObjectType1, 0);
467 1.1.1.2 christos if (ACPI_FAILURE(Status))
468 1.1.1.2 christos {
469 1.1.1.12 christos return_ACPI_STATUS (Status);
470 1.1.1.2 christos }
471 1.1.1.2 christos
472 1.1.1.2 christos /* Validate length of the UUID buffer */
473 1.1.1.2 christos
474 1.1.1.2 christos if ((*Elements)->Buffer.Length != 16)
475 1.1.1.2 christos {
476 1.1.1.2 christos ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
477 1.1.1.2 christos Info->NodeFlags, "Invalid length for UUID Buffer"));
478 1.1.1.12 christos return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
479 1.1.1.2 christos }
480 1.1.1.2 christos
481 1.1.1.2 christos Status = AcpiNsCheckObjectType(Info, Elements + 1,
482 1.1.1.6 christos Package->RetInfo.ObjectType2, 0);
483 1.1.1.2 christos if (ACPI_FAILURE(Status))
484 1.1.1.2 christos {
485 1.1.1.12 christos return_ACPI_STATUS (Status);
486 1.1.1.2 christos }
487 1.1.1.2 christos
488 1.1.1.2 christos Elements += 2;
489 1.1.1.2 christos Count -= 2;
490 1.1.1.6 christos }
491 1.1.1.6 christos break;
492 1.1.1.2 christos
493 1.1 christos default:
494 1.1 christos
495 1.1 christos /* Should not get here if predefined info table is correct */
496 1.1 christos
497 1.1 christos ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
498 1.1 christos "Invalid internal return type in table entry: %X",
499 1.1 christos Package->RetInfo.Type));
500 1.1 christos
501 1.1.1.12 christos return_ACPI_STATUS (AE_AML_INTERNAL);
502 1.1 christos }
503 1.1 christos
504 1.1.1.12 christos return_ACPI_STATUS (Status);
505 1.1 christos
506 1.1 christos
507 1.1 christos PackageTooSmall:
508 1.1 christos
509 1.1 christos /* Error exit for the case with an incorrect package count */
510 1.1 christos
511 1.1 christos ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
512 1.1 christos "Return Package is too small - found %u elements, expected %u",
513 1.1 christos Count, ExpectedCount));
514 1.1 christos
515 1.1.1.12 christos return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
516 1.1 christos }
517 1.1 christos
518 1.1 christos
519 1.1 christos /*******************************************************************************
520 1.1 christos *
521 1.1 christos * FUNCTION: AcpiNsCheckPackageList
522 1.1 christos *
523 1.1 christos * PARAMETERS: Info - Method execution information block
524 1.1 christos * Package - Pointer to package-specific info for method
525 1.1 christos * Elements - Element list of parent package. All elements
526 1.1 christos * of this list should be of type Package.
527 1.1 christos * Count - Count of subpackages
528 1.1 christos *
529 1.1 christos * RETURN: Status
530 1.1 christos *
531 1.1 christos * DESCRIPTION: Examine a list of subpackages
532 1.1 christos *
533 1.1 christos ******************************************************************************/
534 1.1 christos
535 1.1 christos static ACPI_STATUS
536 1.1 christos AcpiNsCheckPackageList (
537 1.1 christos ACPI_EVALUATE_INFO *Info,
538 1.1 christos const ACPI_PREDEFINED_INFO *Package,
539 1.1 christos ACPI_OPERAND_OBJECT **Elements,
540 1.1 christos UINT32 Count)
541 1.1 christos {
542 1.1 christos ACPI_OPERAND_OBJECT *SubPackage;
543 1.1 christos ACPI_OPERAND_OBJECT **SubElements;
544 1.1 christos ACPI_STATUS Status;
545 1.1 christos UINT32 ExpectedCount;
546 1.1 christos UINT32 i;
547 1.1 christos UINT32 j;
548 1.1 christos
549 1.1 christos
550 1.1 christos /*
551 1.1.1.2 christos * Validate each subpackage in the parent Package
552 1.1 christos *
553 1.1.1.2 christos * NOTE: assumes list of subpackages contains no NULL elements.
554 1.1 christos * Any NULL elements should have been removed by earlier call
555 1.1 christos * to AcpiNsRemoveNullElements.
556 1.1 christos */
557 1.1 christos for (i = 0; i < Count; i++)
558 1.1 christos {
559 1.1 christos SubPackage = *Elements;
560 1.1 christos SubElements = SubPackage->Package.Elements;
561 1.1 christos Info->ParentPackage = SubPackage;
562 1.1 christos
563 1.1 christos /* Each sub-object must be of type Package */
564 1.1 christos
565 1.1 christos Status = AcpiNsCheckObjectType (Info, &SubPackage,
566 1.1.1.6 christos ACPI_RTYPE_PACKAGE, i);
567 1.1 christos if (ACPI_FAILURE (Status))
568 1.1 christos {
569 1.1 christos return (Status);
570 1.1 christos }
571 1.1 christos
572 1.1.1.2 christos /* Examine the different types of expected subpackages */
573 1.1 christos
574 1.1 christos Info->ParentPackage = SubPackage;
575 1.1 christos switch (Package->RetInfo.Type)
576 1.1 christos {
577 1.1 christos case ACPI_PTYPE2:
578 1.1 christos case ACPI_PTYPE2_PKG_COUNT:
579 1.1 christos case ACPI_PTYPE2_REV_FIXED:
580 1.1 christos
581 1.1 christos /* Each subpackage has a fixed number of elements */
582 1.1 christos
583 1.1 christos ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
584 1.1 christos if (SubPackage->Package.Count < ExpectedCount)
585 1.1 christos {
586 1.1 christos goto PackageTooSmall;
587 1.1 christos }
588 1.1 christos
589 1.1 christos Status = AcpiNsCheckPackageElements (Info, SubElements,
590 1.1.1.6 christos Package->RetInfo.ObjectType1,
591 1.1.1.6 christos Package->RetInfo.Count1,
592 1.1.1.6 christos Package->RetInfo.ObjectType2,
593 1.1.1.6 christos Package->RetInfo.Count2, 0);
594 1.1 christos if (ACPI_FAILURE (Status))
595 1.1 christos {
596 1.1 christos return (Status);
597 1.1 christos }
598 1.1 christos break;
599 1.1 christos
600 1.1 christos case ACPI_PTYPE2_FIX_VAR:
601 1.1 christos /*
602 1.1 christos * Each subpackage has a fixed number of elements and an
603 1.1 christos * optional element
604 1.1 christos */
605 1.1 christos ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
606 1.1 christos if (SubPackage->Package.Count < ExpectedCount)
607 1.1 christos {
608 1.1 christos goto PackageTooSmall;
609 1.1 christos }
610 1.1 christos
611 1.1 christos Status = AcpiNsCheckPackageElements (Info, SubElements,
612 1.1.1.6 christos Package->RetInfo.ObjectType1,
613 1.1.1.6 christos Package->RetInfo.Count1,
614 1.1.1.6 christos Package->RetInfo.ObjectType2,
615 1.1.1.6 christos SubPackage->Package.Count - Package->RetInfo.Count1, 0);
616 1.1 christos if (ACPI_FAILURE (Status))
617 1.1 christos {
618 1.1 christos return (Status);
619 1.1 christos }
620 1.1 christos break;
621 1.1 christos
622 1.1.1.4 christos case ACPI_PTYPE2_VAR_VAR:
623 1.1.1.4 christos /*
624 1.1.1.4 christos * Each subpackage has a fixed or variable number of elements
625 1.1.1.4 christos */
626 1.1.1.4 christos break;
627 1.1.1.4 christos
628 1.1 christos case ACPI_PTYPE2_FIXED:
629 1.1 christos
630 1.1.1.2 christos /* Each subpackage has a fixed length */
631 1.1 christos
632 1.1 christos ExpectedCount = Package->RetInfo2.Count;
633 1.1 christos if (SubPackage->Package.Count < ExpectedCount)
634 1.1 christos {
635 1.1 christos goto PackageTooSmall;
636 1.1 christos }
637 1.1 christos
638 1.1.1.2 christos /* Check the type of each subpackage element */
639 1.1 christos
640 1.1 christos for (j = 0; j < ExpectedCount; j++)
641 1.1 christos {
642 1.1 christos Status = AcpiNsCheckObjectType (Info, &SubElements[j],
643 1.1.1.6 christos Package->RetInfo2.ObjectType[j], j);
644 1.1 christos if (ACPI_FAILURE (Status))
645 1.1 christos {
646 1.1 christos return (Status);
647 1.1 christos }
648 1.1 christos }
649 1.1 christos break;
650 1.1 christos
651 1.1 christos case ACPI_PTYPE2_MIN:
652 1.1 christos
653 1.1.1.2 christos /* Each subpackage has a variable but minimum length */
654 1.1 christos
655 1.1 christos ExpectedCount = Package->RetInfo.Count1;
656 1.1 christos if (SubPackage->Package.Count < ExpectedCount)
657 1.1 christos {
658 1.1 christos goto PackageTooSmall;
659 1.1 christos }
660 1.1 christos
661 1.1.1.2 christos /* Check the type of each subpackage element */
662 1.1 christos
663 1.1 christos Status = AcpiNsCheckPackageElements (Info, SubElements,
664 1.1.1.6 christos Package->RetInfo.ObjectType1,
665 1.1.1.6 christos SubPackage->Package.Count, 0, 0, 0);
666 1.1 christos if (ACPI_FAILURE (Status))
667 1.1 christos {
668 1.1 christos return (Status);
669 1.1 christos }
670 1.1 christos break;
671 1.1 christos
672 1.1 christos case ACPI_PTYPE2_COUNT:
673 1.1 christos /*
674 1.1 christos * First element is the (Integer) count of elements, including
675 1.1 christos * the count field (the ACPI name is NumElements)
676 1.1 christos */
677 1.1 christos Status = AcpiNsCheckObjectType (Info, SubElements,
678 1.1.1.6 christos ACPI_RTYPE_INTEGER, 0);
679 1.1 christos if (ACPI_FAILURE (Status))
680 1.1 christos {
681 1.1 christos return (Status);
682 1.1 christos }
683 1.1 christos
684 1.1 christos /*
685 1.1 christos * Make sure package is large enough for the Count and is
686 1.1 christos * is as large as the minimum size
687 1.1 christos */
688 1.1 christos ExpectedCount = (UINT32) (*SubElements)->Integer.Value;
689 1.1 christos if (SubPackage->Package.Count < ExpectedCount)
690 1.1 christos {
691 1.1 christos goto PackageTooSmall;
692 1.1 christos }
693 1.1.1.6 christos
694 1.1 christos if (SubPackage->Package.Count < Package->RetInfo.Count1)
695 1.1 christos {
696 1.1 christos ExpectedCount = Package->RetInfo.Count1;
697 1.1 christos goto PackageTooSmall;
698 1.1 christos }
699 1.1.1.6 christos
700 1.1 christos if (ExpectedCount == 0)
701 1.1 christos {
702 1.1 christos /*
703 1.1 christos * Either the NumEntries element was originally zero or it was
704 1.1 christos * a NULL element and repaired to an Integer of value zero.
705 1.1 christos * In either case, repair it by setting NumEntries to be the
706 1.1 christos * actual size of the subpackage.
707 1.1 christos */
708 1.1 christos ExpectedCount = SubPackage->Package.Count;
709 1.1 christos (*SubElements)->Integer.Value = ExpectedCount;
710 1.1 christos }
711 1.1 christos
712 1.1.1.2 christos /* Check the type of each subpackage element */
713 1.1 christos
714 1.1 christos Status = AcpiNsCheckPackageElements (Info, (SubElements + 1),
715 1.1.1.6 christos Package->RetInfo.ObjectType1,
716 1.1.1.6 christos (ExpectedCount - 1), 0, 0, 1);
717 1.1 christos if (ACPI_FAILURE (Status))
718 1.1 christos {
719 1.1 christos return (Status);
720 1.1 christos }
721 1.1 christos break;
722 1.1 christos
723 1.1 christos default: /* Should not get here, type was validated by caller */
724 1.1 christos
725 1.1.1.8 christos ACPI_ERROR ((AE_INFO, "Invalid Package type: %X",
726 1.1.1.8 christos Package->RetInfo.Type));
727 1.1 christos return (AE_AML_INTERNAL);
728 1.1 christos }
729 1.1 christos
730 1.1 christos Elements++;
731 1.1 christos }
732 1.1 christos
733 1.1 christos return (AE_OK);
734 1.1 christos
735 1.1 christos
736 1.1 christos PackageTooSmall:
737 1.1 christos
738 1.1.1.2 christos /* The subpackage count was smaller than required */
739 1.1 christos
740 1.1 christos ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
741 1.1.1.2 christos "Return SubPackage[%u] is too small - found %u elements, expected %u",
742 1.1 christos i, SubPackage->Package.Count, ExpectedCount));
743 1.1 christos
744 1.1 christos return (AE_AML_OPERAND_VALUE);
745 1.1 christos }
746 1.1 christos
747 1.1 christos
748 1.1 christos /*******************************************************************************
749 1.1 christos *
750 1.1.1.6 christos * FUNCTION: AcpiNsCustomPackage
751 1.1.1.6 christos *
752 1.1.1.6 christos * PARAMETERS: Info - Method execution information block
753 1.1.1.6 christos * Elements - Pointer to the package elements array
754 1.1.1.6 christos * Count - Element count for the package
755 1.1.1.6 christos *
756 1.1.1.6 christos * RETURN: Status
757 1.1.1.6 christos *
758 1.1.1.6 christos * DESCRIPTION: Check a returned package object for the correct count and
759 1.1.1.6 christos * correct type of all sub-objects.
760 1.1.1.6 christos *
761 1.1.1.6 christos * NOTE: Currently used for the _BIX method only. When needed for two or more
762 1.1.1.6 christos * methods, probably a detect/dispatch mechanism will be required.
763 1.1.1.6 christos *
764 1.1.1.6 christos ******************************************************************************/
765 1.1.1.6 christos
766 1.1.1.6 christos static ACPI_STATUS
767 1.1.1.6 christos AcpiNsCustomPackage (
768 1.1.1.6 christos ACPI_EVALUATE_INFO *Info,
769 1.1.1.6 christos ACPI_OPERAND_OBJECT **Elements,
770 1.1.1.6 christos UINT32 Count)
771 1.1.1.6 christos {
772 1.1.1.6 christos UINT32 ExpectedCount;
773 1.1.1.6 christos UINT32 Version;
774 1.1.1.6 christos ACPI_STATUS Status = AE_OK;
775 1.1.1.6 christos
776 1.1.1.6 christos
777 1.1.1.6 christos ACPI_FUNCTION_NAME (NsCustomPackage);
778 1.1.1.6 christos
779 1.1.1.6 christos
780 1.1.1.6 christos /* Get version number, must be Integer */
781 1.1.1.6 christos
782 1.1.1.6 christos if ((*Elements)->Common.Type != ACPI_TYPE_INTEGER)
783 1.1.1.6 christos {
784 1.1.1.6 christos ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
785 1.1.1.6 christos "Return Package has invalid object type for version number"));
786 1.1.1.6 christos return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
787 1.1.1.6 christos }
788 1.1.1.6 christos
789 1.1.1.6 christos Version = (UINT32) (*Elements)->Integer.Value;
790 1.1.1.6 christos ExpectedCount = 21; /* Version 1 */
791 1.1.1.6 christos
792 1.1.1.6 christos if (Version == 0)
793 1.1.1.6 christos {
794 1.1.1.6 christos ExpectedCount = 20; /* Version 0 */
795 1.1.1.6 christos }
796 1.1.1.6 christos
797 1.1.1.6 christos if (Count < ExpectedCount)
798 1.1.1.6 christos {
799 1.1.1.6 christos ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
800 1.1.1.6 christos "Return Package is too small - found %u elements, expected %u",
801 1.1.1.6 christos Count, ExpectedCount));
802 1.1.1.6 christos return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
803 1.1.1.6 christos }
804 1.1.1.6 christos else if (Count > ExpectedCount)
805 1.1.1.6 christos {
806 1.1.1.6 christos ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
807 1.1.1.6 christos "%s: Return Package is larger than needed - "
808 1.1.1.6 christos "found %u, expected %u\n",
809 1.1.1.6 christos Info->FullPathname, Count, ExpectedCount));
810 1.1.1.6 christos }
811 1.1.1.6 christos
812 1.1.1.6 christos /* Validate all elements of the returned package */
813 1.1.1.6 christos
814 1.1.1.6 christos Status = AcpiNsCheckPackageElements (Info, Elements,
815 1.1.1.6 christos ACPI_RTYPE_INTEGER, 16,
816 1.1.1.6 christos ACPI_RTYPE_STRING, 4, 0);
817 1.1.1.6 christos if (ACPI_FAILURE (Status))
818 1.1.1.6 christos {
819 1.1.1.6 christos return_ACPI_STATUS (Status);
820 1.1.1.6 christos }
821 1.1.1.6 christos
822 1.1.1.6 christos /* Version 1 has a single trailing integer */
823 1.1.1.6 christos
824 1.1.1.6 christos if (Version > 0)
825 1.1.1.6 christos {
826 1.1.1.6 christos Status = AcpiNsCheckPackageElements (Info, Elements + 20,
827 1.1.1.6 christos ACPI_RTYPE_INTEGER, 1, 0, 0, 20);
828 1.1.1.6 christos }
829 1.1.1.6 christos
830 1.1.1.6 christos return_ACPI_STATUS (Status);
831 1.1.1.6 christos }
832 1.1.1.6 christos
833 1.1.1.6 christos
834 1.1.1.6 christos /*******************************************************************************
835 1.1.1.6 christos *
836 1.1 christos * FUNCTION: AcpiNsCheckPackageElements
837 1.1 christos *
838 1.1 christos * PARAMETERS: Info - Method execution information block
839 1.1 christos * Elements - Pointer to the package elements array
840 1.1 christos * Type1 - Object type for first group
841 1.1 christos * Count1 - Count for first group
842 1.1 christos * Type2 - Object type for second group
843 1.1 christos * Count2 - Count for second group
844 1.1 christos * StartIndex - Start of the first group of elements
845 1.1 christos *
846 1.1 christos * RETURN: Status
847 1.1 christos *
848 1.1 christos * DESCRIPTION: Check that all elements of a package are of the correct object
849 1.1 christos * type. Supports up to two groups of different object types.
850 1.1 christos *
851 1.1 christos ******************************************************************************/
852 1.1 christos
853 1.1 christos static ACPI_STATUS
854 1.1 christos AcpiNsCheckPackageElements (
855 1.1 christos ACPI_EVALUATE_INFO *Info,
856 1.1 christos ACPI_OPERAND_OBJECT **Elements,
857 1.1 christos UINT8 Type1,
858 1.1 christos UINT32 Count1,
859 1.1 christos UINT8 Type2,
860 1.1 christos UINT32 Count2,
861 1.1 christos UINT32 StartIndex)
862 1.1 christos {
863 1.1 christos ACPI_OPERAND_OBJECT **ThisElement = Elements;
864 1.1 christos ACPI_STATUS Status;
865 1.1 christos UINT32 i;
866 1.1 christos
867 1.1 christos
868 1.1.1.12 christos ACPI_FUNCTION_TRACE (NsCheckPackageElements);
869 1.1.1.12 christos
870 1.1 christos /*
871 1.1 christos * Up to two groups of package elements are supported by the data
872 1.1 christos * structure. All elements in each group must be of the same type.
873 1.1 christos * The second group can have a count of zero.
874 1.1 christos */
875 1.1 christos for (i = 0; i < Count1; i++)
876 1.1 christos {
877 1.1 christos Status = AcpiNsCheckObjectType (Info, ThisElement,
878 1.1.1.6 christos Type1, i + StartIndex);
879 1.1 christos if (ACPI_FAILURE (Status))
880 1.1 christos {
881 1.1.1.12 christos return_ACPI_STATUS (Status);
882 1.1 christos }
883 1.1.1.6 christos
884 1.1 christos ThisElement++;
885 1.1 christos }
886 1.1 christos
887 1.1 christos for (i = 0; i < Count2; i++)
888 1.1 christos {
889 1.1 christos Status = AcpiNsCheckObjectType (Info, ThisElement,
890 1.1.1.6 christos Type2, (i + Count1 + StartIndex));
891 1.1 christos if (ACPI_FAILURE (Status))
892 1.1 christos {
893 1.1.1.12 christos return_ACPI_STATUS (Status);
894 1.1 christos }
895 1.1.1.6 christos
896 1.1 christos ThisElement++;
897 1.1 christos }
898 1.1 christos
899 1.1.1.12 christos return_ACPI_STATUS (AE_OK);
900 1.1 christos }
901