nsrepair2.c revision 1.10 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: nsrepair2 - Repair for objects returned by specific
4 1.1 jruoho * predefined methods
5 1.1 jruoho *
6 1.1 jruoho *****************************************************************************/
7 1.1 jruoho
8 1.3 jruoho /*
9 1.10 christos * Copyright (C) 2000 - 2017, Intel Corp.
10 1.1 jruoho * All rights reserved.
11 1.1 jruoho *
12 1.3 jruoho * Redistribution and use in source and binary forms, with or without
13 1.3 jruoho * modification, are permitted provided that the following conditions
14 1.3 jruoho * are met:
15 1.3 jruoho * 1. Redistributions of source code must retain the above copyright
16 1.3 jruoho * notice, this list of conditions, and the following disclaimer,
17 1.3 jruoho * without modification.
18 1.3 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.3 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
20 1.3 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
21 1.3 jruoho * including a substantially similar Disclaimer requirement for further
22 1.3 jruoho * binary redistribution.
23 1.3 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
24 1.3 jruoho * of any contributors may be used to endorse or promote products derived
25 1.3 jruoho * from this software without specific prior written permission.
26 1.3 jruoho *
27 1.3 jruoho * Alternatively, this software may be distributed under the terms of the
28 1.3 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
29 1.3 jruoho * Software Foundation.
30 1.3 jruoho *
31 1.3 jruoho * NO WARRANTY
32 1.3 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.3 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.3 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.3 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.3 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.3 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.3 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.3 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.3 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.3 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.3 jruoho * POSSIBILITY OF SUCH DAMAGES.
43 1.3 jruoho */
44 1.1 jruoho
45 1.1 jruoho #include "acpi.h"
46 1.1 jruoho #include "accommon.h"
47 1.1 jruoho #include "acnamesp.h"
48 1.1 jruoho
49 1.1 jruoho #define _COMPONENT ACPI_NAMESPACE
50 1.1 jruoho ACPI_MODULE_NAME ("nsrepair2")
51 1.1 jruoho
52 1.1 jruoho
53 1.1 jruoho /*
54 1.1 jruoho * Information structure and handler for ACPI predefined names that can
55 1.1 jruoho * be repaired on a per-name basis.
56 1.1 jruoho */
57 1.1 jruoho typedef
58 1.1 jruoho ACPI_STATUS (*ACPI_REPAIR_FUNCTION) (
59 1.5 christos ACPI_EVALUATE_INFO *Info,
60 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr);
61 1.1 jruoho
62 1.1 jruoho typedef struct acpi_repair_info
63 1.1 jruoho {
64 1.1 jruoho char Name[ACPI_NAME_SIZE];
65 1.1 jruoho ACPI_REPAIR_FUNCTION RepairFunction;
66 1.1 jruoho
67 1.1 jruoho } ACPI_REPAIR_INFO;
68 1.1 jruoho
69 1.1 jruoho
70 1.1 jruoho /* Local prototypes */
71 1.1 jruoho
72 1.1 jruoho static const ACPI_REPAIR_INFO *
73 1.5 christos AcpiNsMatchComplexRepair (
74 1.1 jruoho ACPI_NAMESPACE_NODE *Node);
75 1.1 jruoho
76 1.1 jruoho static ACPI_STATUS
77 1.1 jruoho AcpiNsRepair_ALR (
78 1.5 christos ACPI_EVALUATE_INFO *Info,
79 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr);
80 1.1 jruoho
81 1.1 jruoho static ACPI_STATUS
82 1.3 jruoho AcpiNsRepair_CID (
83 1.5 christos ACPI_EVALUATE_INFO *Info,
84 1.5 christos ACPI_OPERAND_OBJECT **ReturnObjectPtr);
85 1.5 christos
86 1.5 christos static ACPI_STATUS
87 1.5 christos AcpiNsRepair_CST (
88 1.5 christos ACPI_EVALUATE_INFO *Info,
89 1.3 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr);
90 1.3 jruoho
91 1.3 jruoho static ACPI_STATUS
92 1.1 jruoho AcpiNsRepair_FDE (
93 1.5 christos ACPI_EVALUATE_INFO *Info,
94 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr);
95 1.1 jruoho
96 1.1 jruoho static ACPI_STATUS
97 1.3 jruoho AcpiNsRepair_HID (
98 1.5 christos ACPI_EVALUATE_INFO *Info,
99 1.5 christos ACPI_OPERAND_OBJECT **ReturnObjectPtr);
100 1.5 christos
101 1.5 christos static ACPI_STATUS
102 1.5 christos AcpiNsRepair_PRT (
103 1.5 christos ACPI_EVALUATE_INFO *Info,
104 1.3 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr);
105 1.3 jruoho
106 1.3 jruoho static ACPI_STATUS
107 1.1 jruoho AcpiNsRepair_PSS (
108 1.5 christos ACPI_EVALUATE_INFO *Info,
109 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr);
110 1.1 jruoho
111 1.1 jruoho static ACPI_STATUS
112 1.1 jruoho AcpiNsRepair_TSS (
113 1.5 christos ACPI_EVALUATE_INFO *Info,
114 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr);
115 1.1 jruoho
116 1.1 jruoho static ACPI_STATUS
117 1.1 jruoho AcpiNsCheckSortedList (
118 1.5 christos ACPI_EVALUATE_INFO *Info,
119 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnObject,
120 1.5 christos UINT32 StartIndex,
121 1.1 jruoho UINT32 ExpectedCount,
122 1.1 jruoho UINT32 SortIndex,
123 1.1 jruoho UINT8 SortDirection,
124 1.9 christos const char *SortKeyName);
125 1.1 jruoho
126 1.5 christos /* Values for SortDirection above */
127 1.5 christos
128 1.5 christos #define ACPI_SORT_ASCENDING 0
129 1.5 christos #define ACPI_SORT_DESCENDING 1
130 1.5 christos
131 1.5 christos static void
132 1.5 christos AcpiNsRemoveElement (
133 1.5 christos ACPI_OPERAND_OBJECT *ObjDesc,
134 1.5 christos UINT32 Index);
135 1.5 christos
136 1.1 jruoho static void
137 1.1 jruoho AcpiNsSortList (
138 1.1 jruoho ACPI_OPERAND_OBJECT **Elements,
139 1.1 jruoho UINT32 Count,
140 1.1 jruoho UINT32 Index,
141 1.1 jruoho UINT8 SortDirection);
142 1.1 jruoho
143 1.1 jruoho
144 1.1 jruoho /*
145 1.1 jruoho * This table contains the names of the predefined methods for which we can
146 1.1 jruoho * perform more complex repairs.
147 1.1 jruoho *
148 1.1 jruoho * As necessary:
149 1.1 jruoho *
150 1.1 jruoho * _ALR: Sort the list ascending by AmbientIlluminance
151 1.3 jruoho * _CID: Strings: uppercase all, remove any leading asterisk
152 1.5 christos * _CST: Sort the list ascending by C state type
153 1.1 jruoho * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
154 1.1 jruoho * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
155 1.3 jruoho * _HID: Strings: uppercase all, remove any leading asterisk
156 1.5 christos * _PRT: Fix reversed SourceName and SourceIndex
157 1.1 jruoho * _PSS: Sort the list descending by Power
158 1.1 jruoho * _TSS: Sort the list descending by Power
159 1.1 jruoho *
160 1.1 jruoho * Names that must be packages, but cannot be sorted:
161 1.1 jruoho *
162 1.1 jruoho * _BCL: Values are tied to the Package index where they appear, and cannot
163 1.1 jruoho * be moved or sorted. These index values are used for _BQC and _BCM.
164 1.1 jruoho * However, we can fix the case where a buffer is returned, by converting
165 1.1 jruoho * it to a Package of integers.
166 1.1 jruoho */
167 1.1 jruoho static const ACPI_REPAIR_INFO AcpiNsRepairableNames[] =
168 1.1 jruoho {
169 1.1 jruoho {"_ALR", AcpiNsRepair_ALR},
170 1.3 jruoho {"_CID", AcpiNsRepair_CID},
171 1.5 christos {"_CST", AcpiNsRepair_CST},
172 1.1 jruoho {"_FDE", AcpiNsRepair_FDE},
173 1.1 jruoho {"_GTM", AcpiNsRepair_FDE}, /* _GTM has same repair as _FDE */
174 1.3 jruoho {"_HID", AcpiNsRepair_HID},
175 1.5 christos {"_PRT", AcpiNsRepair_PRT},
176 1.1 jruoho {"_PSS", AcpiNsRepair_PSS},
177 1.1 jruoho {"_TSS", AcpiNsRepair_TSS},
178 1.1 jruoho {{0,0,0,0}, NULL} /* Table terminator */
179 1.1 jruoho };
180 1.1 jruoho
181 1.1 jruoho
182 1.1 jruoho #define ACPI_FDE_FIELD_COUNT 5
183 1.1 jruoho #define ACPI_FDE_BYTE_BUFFER_SIZE 5
184 1.1 jruoho #define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (UINT32))
185 1.1 jruoho
186 1.1 jruoho
187 1.1 jruoho /******************************************************************************
188 1.1 jruoho *
189 1.1 jruoho * FUNCTION: AcpiNsComplexRepairs
190 1.1 jruoho *
191 1.5 christos * PARAMETERS: Info - Method execution information block
192 1.1 jruoho * Node - Namespace node for the method/object
193 1.1 jruoho * ValidateStatus - Original status of earlier validation
194 1.1 jruoho * ReturnObjectPtr - Pointer to the object returned from the
195 1.1 jruoho * evaluation of a method or object
196 1.1 jruoho *
197 1.1 jruoho * RETURN: Status. AE_OK if repair was successful. If name is not
198 1.1 jruoho * matched, ValidateStatus is returned.
199 1.1 jruoho *
200 1.1 jruoho * DESCRIPTION: Attempt to repair/convert a return object of a type that was
201 1.1 jruoho * not expected.
202 1.1 jruoho *
203 1.1 jruoho *****************************************************************************/
204 1.1 jruoho
205 1.1 jruoho ACPI_STATUS
206 1.1 jruoho AcpiNsComplexRepairs (
207 1.5 christos ACPI_EVALUATE_INFO *Info,
208 1.1 jruoho ACPI_NAMESPACE_NODE *Node,
209 1.1 jruoho ACPI_STATUS ValidateStatus,
210 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr)
211 1.1 jruoho {
212 1.1 jruoho const ACPI_REPAIR_INFO *Predefined;
213 1.1 jruoho ACPI_STATUS Status;
214 1.1 jruoho
215 1.1 jruoho
216 1.1 jruoho /* Check if this name is in the list of repairable names */
217 1.1 jruoho
218 1.5 christos Predefined = AcpiNsMatchComplexRepair (Node);
219 1.1 jruoho if (!Predefined)
220 1.1 jruoho {
221 1.1 jruoho return (ValidateStatus);
222 1.1 jruoho }
223 1.1 jruoho
224 1.5 christos Status = Predefined->RepairFunction (Info, ReturnObjectPtr);
225 1.1 jruoho return (Status);
226 1.1 jruoho }
227 1.1 jruoho
228 1.1 jruoho
229 1.1 jruoho /******************************************************************************
230 1.1 jruoho *
231 1.5 christos * FUNCTION: AcpiNsMatchComplexRepair
232 1.1 jruoho *
233 1.1 jruoho * PARAMETERS: Node - Namespace node for the method/object
234 1.1 jruoho *
235 1.1 jruoho * RETURN: Pointer to entry in repair table. NULL indicates not found.
236 1.1 jruoho *
237 1.1 jruoho * DESCRIPTION: Check an object name against the repairable object list.
238 1.1 jruoho *
239 1.1 jruoho *****************************************************************************/
240 1.1 jruoho
241 1.1 jruoho static const ACPI_REPAIR_INFO *
242 1.5 christos AcpiNsMatchComplexRepair (
243 1.1 jruoho ACPI_NAMESPACE_NODE *Node)
244 1.1 jruoho {
245 1.1 jruoho const ACPI_REPAIR_INFO *ThisName;
246 1.1 jruoho
247 1.1 jruoho
248 1.1 jruoho /* Search info table for a repairable predefined method/object name */
249 1.1 jruoho
250 1.1 jruoho ThisName = AcpiNsRepairableNames;
251 1.1 jruoho while (ThisName->RepairFunction)
252 1.1 jruoho {
253 1.1 jruoho if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
254 1.1 jruoho {
255 1.1 jruoho return (ThisName);
256 1.1 jruoho }
257 1.9 christos
258 1.1 jruoho ThisName++;
259 1.1 jruoho }
260 1.1 jruoho
261 1.1 jruoho return (NULL); /* Not found */
262 1.1 jruoho }
263 1.1 jruoho
264 1.1 jruoho
265 1.1 jruoho /******************************************************************************
266 1.1 jruoho *
267 1.1 jruoho * FUNCTION: AcpiNsRepair_ALR
268 1.1 jruoho *
269 1.5 christos * PARAMETERS: Info - Method execution information block
270 1.1 jruoho * ReturnObjectPtr - Pointer to the object returned from the
271 1.1 jruoho * evaluation of a method or object
272 1.1 jruoho *
273 1.1 jruoho * RETURN: Status. AE_OK if object is OK or was repaired successfully
274 1.1 jruoho *
275 1.1 jruoho * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
276 1.1 jruoho * ascending by the ambient illuminance values.
277 1.1 jruoho *
278 1.1 jruoho *****************************************************************************/
279 1.1 jruoho
280 1.1 jruoho static ACPI_STATUS
281 1.1 jruoho AcpiNsRepair_ALR (
282 1.5 christos ACPI_EVALUATE_INFO *Info,
283 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr)
284 1.1 jruoho {
285 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
286 1.1 jruoho ACPI_STATUS Status;
287 1.1 jruoho
288 1.1 jruoho
289 1.5 christos Status = AcpiNsCheckSortedList (Info, ReturnObject, 0, 2, 1,
290 1.9 christos ACPI_SORT_ASCENDING, "AmbientIlluminance");
291 1.1 jruoho
292 1.1 jruoho return (Status);
293 1.1 jruoho }
294 1.1 jruoho
295 1.1 jruoho
296 1.1 jruoho /******************************************************************************
297 1.1 jruoho *
298 1.1 jruoho * FUNCTION: AcpiNsRepair_FDE
299 1.1 jruoho *
300 1.5 christos * PARAMETERS: Info - Method execution information block
301 1.1 jruoho * ReturnObjectPtr - Pointer to the object returned from the
302 1.1 jruoho * evaluation of a method or object
303 1.1 jruoho *
304 1.1 jruoho * RETURN: Status. AE_OK if object is OK or was repaired successfully
305 1.1 jruoho *
306 1.1 jruoho * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
307 1.1 jruoho * value is a Buffer of 5 DWORDs. This function repairs a common
308 1.1 jruoho * problem where the return value is a Buffer of BYTEs, not
309 1.1 jruoho * DWORDs.
310 1.1 jruoho *
311 1.1 jruoho *****************************************************************************/
312 1.1 jruoho
313 1.1 jruoho static ACPI_STATUS
314 1.1 jruoho AcpiNsRepair_FDE (
315 1.5 christos ACPI_EVALUATE_INFO *Info,
316 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr)
317 1.1 jruoho {
318 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
319 1.1 jruoho ACPI_OPERAND_OBJECT *BufferObject;
320 1.1 jruoho UINT8 *ByteBuffer;
321 1.1 jruoho UINT32 *DwordBuffer;
322 1.1 jruoho UINT32 i;
323 1.1 jruoho
324 1.1 jruoho
325 1.1 jruoho ACPI_FUNCTION_NAME (NsRepair_FDE);
326 1.1 jruoho
327 1.1 jruoho
328 1.1 jruoho switch (ReturnObject->Common.Type)
329 1.1 jruoho {
330 1.1 jruoho case ACPI_TYPE_BUFFER:
331 1.1 jruoho
332 1.1 jruoho /* This is the expected type. Length should be (at least) 5 DWORDs */
333 1.1 jruoho
334 1.1 jruoho if (ReturnObject->Buffer.Length >= ACPI_FDE_DWORD_BUFFER_SIZE)
335 1.1 jruoho {
336 1.1 jruoho return (AE_OK);
337 1.1 jruoho }
338 1.1 jruoho
339 1.1 jruoho /* We can only repair if we have exactly 5 BYTEs */
340 1.1 jruoho
341 1.1 jruoho if (ReturnObject->Buffer.Length != ACPI_FDE_BYTE_BUFFER_SIZE)
342 1.1 jruoho {
343 1.9 christos ACPI_WARN_PREDEFINED ((AE_INFO,
344 1.9 christos Info->FullPathname, Info->NodeFlags,
345 1.1 jruoho "Incorrect return buffer length %u, expected %u",
346 1.1 jruoho ReturnObject->Buffer.Length, ACPI_FDE_DWORD_BUFFER_SIZE));
347 1.1 jruoho
348 1.1 jruoho return (AE_AML_OPERAND_TYPE);
349 1.1 jruoho }
350 1.1 jruoho
351 1.1 jruoho /* Create the new (larger) buffer object */
352 1.1 jruoho
353 1.9 christos BufferObject = AcpiUtCreateBufferObject (
354 1.9 christos ACPI_FDE_DWORD_BUFFER_SIZE);
355 1.1 jruoho if (!BufferObject)
356 1.1 jruoho {
357 1.1 jruoho return (AE_NO_MEMORY);
358 1.1 jruoho }
359 1.1 jruoho
360 1.1 jruoho /* Expand each byte to a DWORD */
361 1.1 jruoho
362 1.1 jruoho ByteBuffer = ReturnObject->Buffer.Pointer;
363 1.9 christos DwordBuffer = ACPI_CAST_PTR (UINT32,
364 1.9 christos BufferObject->Buffer.Pointer);
365 1.1 jruoho
366 1.1 jruoho for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++)
367 1.1 jruoho {
368 1.1 jruoho *DwordBuffer = (UINT32) *ByteBuffer;
369 1.1 jruoho DwordBuffer++;
370 1.1 jruoho ByteBuffer++;
371 1.1 jruoho }
372 1.1 jruoho
373 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
374 1.1 jruoho "%s Expanded Byte Buffer to expected DWord Buffer\n",
375 1.5 christos Info->FullPathname));
376 1.1 jruoho break;
377 1.1 jruoho
378 1.1 jruoho default:
379 1.5 christos
380 1.1 jruoho return (AE_AML_OPERAND_TYPE);
381 1.1 jruoho }
382 1.1 jruoho
383 1.1 jruoho /* Delete the original return object, return the new buffer object */
384 1.1 jruoho
385 1.1 jruoho AcpiUtRemoveReference (ReturnObject);
386 1.1 jruoho *ReturnObjectPtr = BufferObject;
387 1.1 jruoho
388 1.5 christos Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
389 1.1 jruoho return (AE_OK);
390 1.1 jruoho }
391 1.1 jruoho
392 1.1 jruoho
393 1.1 jruoho /******************************************************************************
394 1.1 jruoho *
395 1.3 jruoho * FUNCTION: AcpiNsRepair_CID
396 1.3 jruoho *
397 1.5 christos * PARAMETERS: Info - Method execution information block
398 1.3 jruoho * ReturnObjectPtr - Pointer to the object returned from the
399 1.3 jruoho * evaluation of a method or object
400 1.3 jruoho *
401 1.3 jruoho * RETURN: Status. AE_OK if object is OK or was repaired successfully
402 1.3 jruoho *
403 1.3 jruoho * DESCRIPTION: Repair for the _CID object. If a string, ensure that all
404 1.3 jruoho * letters are uppercase and that there is no leading asterisk.
405 1.3 jruoho * If a Package, ensure same for all string elements.
406 1.3 jruoho *
407 1.3 jruoho *****************************************************************************/
408 1.3 jruoho
409 1.3 jruoho static ACPI_STATUS
410 1.3 jruoho AcpiNsRepair_CID (
411 1.5 christos ACPI_EVALUATE_INFO *Info,
412 1.3 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr)
413 1.3 jruoho {
414 1.3 jruoho ACPI_STATUS Status;
415 1.3 jruoho ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
416 1.3 jruoho ACPI_OPERAND_OBJECT **ElementPtr;
417 1.3 jruoho ACPI_OPERAND_OBJECT *OriginalElement;
418 1.3 jruoho UINT16 OriginalRefCount;
419 1.3 jruoho UINT32 i;
420 1.3 jruoho
421 1.3 jruoho
422 1.3 jruoho /* Check for _CID as a simple string */
423 1.3 jruoho
424 1.3 jruoho if (ReturnObject->Common.Type == ACPI_TYPE_STRING)
425 1.3 jruoho {
426 1.5 christos Status = AcpiNsRepair_HID (Info, ReturnObjectPtr);
427 1.3 jruoho return (Status);
428 1.3 jruoho }
429 1.3 jruoho
430 1.3 jruoho /* Exit if not a Package */
431 1.3 jruoho
432 1.3 jruoho if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
433 1.3 jruoho {
434 1.3 jruoho return (AE_OK);
435 1.3 jruoho }
436 1.3 jruoho
437 1.3 jruoho /* Examine each element of the _CID package */
438 1.3 jruoho
439 1.3 jruoho ElementPtr = ReturnObject->Package.Elements;
440 1.3 jruoho for (i = 0; i < ReturnObject->Package.Count; i++)
441 1.3 jruoho {
442 1.3 jruoho OriginalElement = *ElementPtr;
443 1.3 jruoho OriginalRefCount = OriginalElement->Common.ReferenceCount;
444 1.3 jruoho
445 1.5 christos Status = AcpiNsRepair_HID (Info, ElementPtr);
446 1.3 jruoho if (ACPI_FAILURE (Status))
447 1.3 jruoho {
448 1.3 jruoho return (Status);
449 1.3 jruoho }
450 1.3 jruoho
451 1.3 jruoho /* Take care with reference counts */
452 1.3 jruoho
453 1.3 jruoho if (OriginalElement != *ElementPtr)
454 1.3 jruoho {
455 1.3 jruoho /* Element was replaced */
456 1.3 jruoho
457 1.3 jruoho (*ElementPtr)->Common.ReferenceCount =
458 1.3 jruoho OriginalRefCount;
459 1.3 jruoho
460 1.3 jruoho AcpiUtRemoveReference (OriginalElement);
461 1.3 jruoho }
462 1.3 jruoho
463 1.3 jruoho ElementPtr++;
464 1.3 jruoho }
465 1.3 jruoho
466 1.3 jruoho return (AE_OK);
467 1.3 jruoho }
468 1.3 jruoho
469 1.3 jruoho
470 1.3 jruoho /******************************************************************************
471 1.3 jruoho *
472 1.5 christos * FUNCTION: AcpiNsRepair_CST
473 1.5 christos *
474 1.5 christos * PARAMETERS: Info - Method execution information block
475 1.5 christos * ReturnObjectPtr - Pointer to the object returned from the
476 1.5 christos * evaluation of a method or object
477 1.5 christos *
478 1.5 christos * RETURN: Status. AE_OK if object is OK or was repaired successfully
479 1.5 christos *
480 1.5 christos * DESCRIPTION: Repair for the _CST object:
481 1.5 christos * 1. Sort the list ascending by C state type
482 1.5 christos * 2. Ensure type cannot be zero
483 1.6 christos * 3. A subpackage count of zero means _CST is meaningless
484 1.6 christos * 4. Count must match the number of C state subpackages
485 1.5 christos *
486 1.5 christos *****************************************************************************/
487 1.5 christos
488 1.5 christos static ACPI_STATUS
489 1.5 christos AcpiNsRepair_CST (
490 1.5 christos ACPI_EVALUATE_INFO *Info,
491 1.5 christos ACPI_OPERAND_OBJECT **ReturnObjectPtr)
492 1.5 christos {
493 1.5 christos ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
494 1.5 christos ACPI_OPERAND_OBJECT **OuterElements;
495 1.5 christos UINT32 OuterElementCount;
496 1.5 christos ACPI_OPERAND_OBJECT *ObjDesc;
497 1.5 christos ACPI_STATUS Status;
498 1.5 christos BOOLEAN Removing;
499 1.5 christos UINT32 i;
500 1.5 christos
501 1.5 christos
502 1.5 christos ACPI_FUNCTION_NAME (NsRepair_CST);
503 1.5 christos
504 1.5 christos
505 1.5 christos /*
506 1.5 christos * Check if the C-state type values are proportional.
507 1.5 christos */
508 1.5 christos OuterElementCount = ReturnObject->Package.Count - 1;
509 1.5 christos i = 0;
510 1.5 christos while (i < OuterElementCount)
511 1.5 christos {
512 1.5 christos OuterElements = &ReturnObject->Package.Elements[i + 1];
513 1.5 christos Removing = FALSE;
514 1.5 christos
515 1.5 christos if ((*OuterElements)->Package.Count == 0)
516 1.5 christos {
517 1.9 christos ACPI_WARN_PREDEFINED ((AE_INFO,
518 1.9 christos Info->FullPathname, Info->NodeFlags,
519 1.5 christos "SubPackage[%u] - removing entry due to zero count", i));
520 1.5 christos Removing = TRUE;
521 1.5 christos goto RemoveElement;
522 1.5 christos }
523 1.5 christos
524 1.5 christos ObjDesc = (*OuterElements)->Package.Elements[1]; /* Index1 = Type */
525 1.5 christos if ((UINT32) ObjDesc->Integer.Value == 0)
526 1.5 christos {
527 1.9 christos ACPI_WARN_PREDEFINED ((AE_INFO,
528 1.9 christos Info->FullPathname, Info->NodeFlags,
529 1.5 christos "SubPackage[%u] - removing entry due to invalid Type(0)", i));
530 1.5 christos Removing = TRUE;
531 1.5 christos }
532 1.5 christos
533 1.5 christos RemoveElement:
534 1.5 christos if (Removing)
535 1.5 christos {
536 1.5 christos AcpiNsRemoveElement (ReturnObject, i + 1);
537 1.5 christos OuterElementCount--;
538 1.5 christos }
539 1.5 christos else
540 1.5 christos {
541 1.5 christos i++;
542 1.5 christos }
543 1.5 christos }
544 1.5 christos
545 1.5 christos /* Update top-level package count, Type "Integer" checked elsewhere */
546 1.5 christos
547 1.5 christos ObjDesc = ReturnObject->Package.Elements[0];
548 1.5 christos ObjDesc->Integer.Value = OuterElementCount;
549 1.5 christos
550 1.5 christos /*
551 1.5 christos * Entries (subpackages) in the _CST Package must be sorted by the
552 1.5 christos * C-state type, in ascending order.
553 1.5 christos */
554 1.5 christos Status = AcpiNsCheckSortedList (Info, ReturnObject, 1, 4, 1,
555 1.9 christos ACPI_SORT_ASCENDING, "C-State Type");
556 1.5 christos if (ACPI_FAILURE (Status))
557 1.5 christos {
558 1.5 christos return (Status);
559 1.5 christos }
560 1.5 christos
561 1.5 christos return (AE_OK);
562 1.5 christos }
563 1.5 christos
564 1.5 christos
565 1.5 christos /******************************************************************************
566 1.5 christos *
567 1.3 jruoho * FUNCTION: AcpiNsRepair_HID
568 1.3 jruoho *
569 1.5 christos * PARAMETERS: Info - Method execution information block
570 1.3 jruoho * ReturnObjectPtr - Pointer to the object returned from the
571 1.3 jruoho * evaluation of a method or object
572 1.3 jruoho *
573 1.3 jruoho * RETURN: Status. AE_OK if object is OK or was repaired successfully
574 1.3 jruoho *
575 1.3 jruoho * DESCRIPTION: Repair for the _HID object. If a string, ensure that all
576 1.3 jruoho * letters are uppercase and that there is no leading asterisk.
577 1.3 jruoho *
578 1.3 jruoho *****************************************************************************/
579 1.3 jruoho
580 1.3 jruoho static ACPI_STATUS
581 1.3 jruoho AcpiNsRepair_HID (
582 1.5 christos ACPI_EVALUATE_INFO *Info,
583 1.3 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr)
584 1.3 jruoho {
585 1.3 jruoho ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
586 1.3 jruoho ACPI_OPERAND_OBJECT *NewString;
587 1.3 jruoho char *Source;
588 1.3 jruoho char *Dest;
589 1.3 jruoho
590 1.3 jruoho
591 1.3 jruoho ACPI_FUNCTION_NAME (NsRepair_HID);
592 1.3 jruoho
593 1.3 jruoho
594 1.3 jruoho /* We only care about string _HID objects (not integers) */
595 1.3 jruoho
596 1.3 jruoho if (ReturnObject->Common.Type != ACPI_TYPE_STRING)
597 1.3 jruoho {
598 1.3 jruoho return (AE_OK);
599 1.3 jruoho }
600 1.3 jruoho
601 1.3 jruoho if (ReturnObject->String.Length == 0)
602 1.3 jruoho {
603 1.9 christos ACPI_WARN_PREDEFINED ((AE_INFO,
604 1.9 christos Info->FullPathname, Info->NodeFlags,
605 1.3 jruoho "Invalid zero-length _HID or _CID string"));
606 1.3 jruoho
607 1.3 jruoho /* Return AE_OK anyway, let driver handle it */
608 1.3 jruoho
609 1.5 christos Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
610 1.3 jruoho return (AE_OK);
611 1.3 jruoho }
612 1.3 jruoho
613 1.3 jruoho /* It is simplest to always create a new string object */
614 1.3 jruoho
615 1.3 jruoho NewString = AcpiUtCreateStringObject (ReturnObject->String.Length);
616 1.3 jruoho if (!NewString)
617 1.3 jruoho {
618 1.3 jruoho return (AE_NO_MEMORY);
619 1.3 jruoho }
620 1.3 jruoho
621 1.3 jruoho /*
622 1.3 jruoho * Remove a leading asterisk if present. For some unknown reason, there
623 1.3 jruoho * are many machines in the field that contains IDs like this.
624 1.3 jruoho *
625 1.3 jruoho * Examples: "*PNP0C03", "*ACPI0003"
626 1.3 jruoho */
627 1.3 jruoho Source = ReturnObject->String.Pointer;
628 1.3 jruoho if (*Source == '*')
629 1.3 jruoho {
630 1.3 jruoho Source++;
631 1.3 jruoho NewString->String.Length--;
632 1.3 jruoho
633 1.3 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
634 1.5 christos "%s: Removed invalid leading asterisk\n", Info->FullPathname));
635 1.3 jruoho }
636 1.3 jruoho
637 1.3 jruoho /*
638 1.5 christos * Copy and uppercase the string. From the ACPI 5.0 specification:
639 1.3 jruoho *
640 1.3 jruoho * A valid PNP ID must be of the form "AAA####" where A is an uppercase
641 1.3 jruoho * letter and # is a hex digit. A valid ACPI ID must be of the form
642 1.5 christos * "NNNN####" where N is an uppercase letter or decimal digit, and
643 1.5 christos * # is a hex digit.
644 1.3 jruoho */
645 1.3 jruoho for (Dest = NewString->String.Pointer; *Source; Dest++, Source++)
646 1.3 jruoho {
647 1.8 christos *Dest = (char) toupper ((int) *Source);
648 1.3 jruoho }
649 1.3 jruoho
650 1.3 jruoho AcpiUtRemoveReference (ReturnObject);
651 1.3 jruoho *ReturnObjectPtr = NewString;
652 1.3 jruoho return (AE_OK);
653 1.3 jruoho }
654 1.3 jruoho
655 1.3 jruoho
656 1.3 jruoho /******************************************************************************
657 1.3 jruoho *
658 1.5 christos * FUNCTION: AcpiNsRepair_PRT
659 1.1 jruoho *
660 1.5 christos * PARAMETERS: Info - Method execution information block
661 1.1 jruoho * ReturnObjectPtr - Pointer to the object returned from the
662 1.1 jruoho * evaluation of a method or object
663 1.1 jruoho *
664 1.1 jruoho * RETURN: Status. AE_OK if object is OK or was repaired successfully
665 1.1 jruoho *
666 1.5 christos * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed
667 1.5 christos * SourceName and SourceIndex field, a common BIOS bug.
668 1.1 jruoho *
669 1.1 jruoho *****************************************************************************/
670 1.1 jruoho
671 1.1 jruoho static ACPI_STATUS
672 1.5 christos AcpiNsRepair_PRT (
673 1.5 christos ACPI_EVALUATE_INFO *Info,
674 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr)
675 1.1 jruoho {
676 1.5 christos ACPI_OPERAND_OBJECT *PackageObject = *ReturnObjectPtr;
677 1.5 christos ACPI_OPERAND_OBJECT **TopObjectList;
678 1.5 christos ACPI_OPERAND_OBJECT **SubObjectList;
679 1.5 christos ACPI_OPERAND_OBJECT *ObjDesc;
680 1.6 christos ACPI_OPERAND_OBJECT *SubPackage;
681 1.5 christos UINT32 ElementCount;
682 1.5 christos UINT32 Index;
683 1.5 christos
684 1.5 christos
685 1.5 christos /* Each element in the _PRT package is a subpackage */
686 1.1 jruoho
687 1.5 christos TopObjectList = PackageObject->Package.Elements;
688 1.5 christos ElementCount = PackageObject->Package.Count;
689 1.1 jruoho
690 1.6 christos /* Examine each subpackage */
691 1.6 christos
692 1.6 christos for (Index = 0; Index < ElementCount; Index++, TopObjectList++)
693 1.4 jruoho {
694 1.6 christos SubPackage = *TopObjectList;
695 1.6 christos SubObjectList = SubPackage->Package.Elements;
696 1.6 christos
697 1.6 christos /* Check for minimum required element count */
698 1.6 christos
699 1.6 christos if (SubPackage->Package.Count < 4)
700 1.6 christos {
701 1.6 christos continue;
702 1.6 christos }
703 1.5 christos
704 1.5 christos /*
705 1.5 christos * If the BIOS has erroneously reversed the _PRT SourceName (index 2)
706 1.5 christos * and the SourceIndex (index 3), fix it. _PRT is important enough to
707 1.5 christos * workaround this BIOS error. This also provides compatibility with
708 1.5 christos * other ACPI implementations.
709 1.5 christos */
710 1.5 christos ObjDesc = SubObjectList[3];
711 1.5 christos if (!ObjDesc || (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
712 1.5 christos {
713 1.5 christos SubObjectList[3] = SubObjectList[2];
714 1.5 christos SubObjectList[2] = ObjDesc;
715 1.5 christos Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
716 1.5 christos
717 1.6 christos ACPI_WARN_PREDEFINED ((AE_INFO,
718 1.6 christos Info->FullPathname, Info->NodeFlags,
719 1.5 christos "PRT[%X]: Fixed reversed SourceName and SourceIndex",
720 1.5 christos Index));
721 1.5 christos }
722 1.4 jruoho }
723 1.4 jruoho
724 1.5 christos return (AE_OK);
725 1.1 jruoho }
726 1.1 jruoho
727 1.1 jruoho
728 1.1 jruoho /******************************************************************************
729 1.1 jruoho *
730 1.1 jruoho * FUNCTION: AcpiNsRepair_PSS
731 1.1 jruoho *
732 1.5 christos * PARAMETERS: Info - Method execution information block
733 1.1 jruoho * ReturnObjectPtr - Pointer to the object returned from the
734 1.1 jruoho * evaluation of a method or object
735 1.1 jruoho *
736 1.1 jruoho * RETURN: Status. AE_OK if object is OK or was repaired successfully
737 1.1 jruoho *
738 1.1 jruoho * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
739 1.1 jruoho * by the CPU frequencies. Check that the power dissipation values
740 1.1 jruoho * are all proportional to CPU frequency (i.e., sorting by
741 1.1 jruoho * frequency should be the same as sorting by power.)
742 1.1 jruoho *
743 1.1 jruoho *****************************************************************************/
744 1.1 jruoho
745 1.1 jruoho static ACPI_STATUS
746 1.1 jruoho AcpiNsRepair_PSS (
747 1.5 christos ACPI_EVALUATE_INFO *Info,
748 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnObjectPtr)
749 1.1 jruoho {
750 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
751 1.1 jruoho ACPI_OPERAND_OBJECT **OuterElements;
752 1.1 jruoho UINT32 OuterElementCount;
753 1.1 jruoho ACPI_OPERAND_OBJECT **Elements;
754 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
755 1.1 jruoho UINT32 PreviousValue;
756 1.1 jruoho ACPI_STATUS Status;
757 1.1 jruoho UINT32 i;
758 1.1 jruoho
759 1.1 jruoho
760 1.1 jruoho /*
761 1.6 christos * Entries (subpackages) in the _PSS Package must be sorted by power
762 1.1 jruoho * dissipation, in descending order. If it appears that the list is
763 1.1 jruoho * incorrectly sorted, sort it. We sort by CpuFrequency, since this
764 1.1 jruoho * should be proportional to the power.
765 1.1 jruoho */
766 1.9 christos Status = AcpiNsCheckSortedList (Info, ReturnObject, 0, 6, 0,
767 1.9 christos ACPI_SORT_DESCENDING, "CpuFrequency");
768 1.1 jruoho if (ACPI_FAILURE (Status))
769 1.1 jruoho {
770 1.1 jruoho return (Status);
771 1.1 jruoho }
772 1.1 jruoho
773 1.1 jruoho /*
774 1.1 jruoho * We now know the list is correctly sorted by CPU frequency. Check if
775 1.1 jruoho * the power dissipation values are proportional.
776 1.1 jruoho */
777 1.1 jruoho PreviousValue = ACPI_UINT32_MAX;
778 1.1 jruoho OuterElements = ReturnObject->Package.Elements;
779 1.1 jruoho OuterElementCount = ReturnObject->Package.Count;
780 1.1 jruoho
781 1.1 jruoho for (i = 0; i < OuterElementCount; i++)
782 1.1 jruoho {
783 1.1 jruoho Elements = (*OuterElements)->Package.Elements;
784 1.1 jruoho ObjDesc = Elements[1]; /* Index1 = PowerDissipation */
785 1.1 jruoho
786 1.1 jruoho if ((UINT32) ObjDesc->Integer.Value > PreviousValue)
787 1.1 jruoho {
788 1.9 christos ACPI_WARN_PREDEFINED ((AE_INFO,
789 1.9 christos Info->FullPathname, Info->NodeFlags,
790 1.1 jruoho "SubPackage[%u,%u] - suspicious power dissipation values",
791 1.1 jruoho i-1, i));
792 1.1 jruoho }
793 1.1 jruoho
794 1.1 jruoho PreviousValue = (UINT32) ObjDesc->Integer.Value;
795 1.1 jruoho OuterElements++;
796 1.1 jruoho }
797 1.1 jruoho
798 1.1 jruoho return (AE_OK);
799 1.1 jruoho }
800 1.1 jruoho
801 1.1 jruoho
802 1.1 jruoho /******************************************************************************
803 1.1 jruoho *
804 1.5 christos * FUNCTION: AcpiNsRepair_TSS
805 1.5 christos *
806 1.5 christos * PARAMETERS: Info - Method execution information block
807 1.5 christos * ReturnObjectPtr - Pointer to the object returned from the
808 1.5 christos * evaluation of a method or object
809 1.5 christos *
810 1.5 christos * RETURN: Status. AE_OK if object is OK or was repaired successfully
811 1.5 christos *
812 1.5 christos * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
813 1.5 christos * descending by the power dissipation values.
814 1.5 christos *
815 1.5 christos *****************************************************************************/
816 1.5 christos
817 1.5 christos static ACPI_STATUS
818 1.5 christos AcpiNsRepair_TSS (
819 1.5 christos ACPI_EVALUATE_INFO *Info,
820 1.5 christos ACPI_OPERAND_OBJECT **ReturnObjectPtr)
821 1.5 christos {
822 1.5 christos ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
823 1.5 christos ACPI_STATUS Status;
824 1.5 christos ACPI_NAMESPACE_NODE *Node;
825 1.5 christos
826 1.5 christos
827 1.5 christos /*
828 1.5 christos * We can only sort the _TSS return package if there is no _PSS in the
829 1.5 christos * same scope. This is because if _PSS is present, the ACPI specification
830 1.5 christos * dictates that the _TSS Power Dissipation field is to be ignored, and
831 1.5 christos * therefore some BIOSs leave garbage values in the _TSS Power field(s).
832 1.5 christos * In this case, it is best to just return the _TSS package as-is.
833 1.5 christos * (May, 2011)
834 1.5 christos */
835 1.5 christos Status = AcpiNsGetNode (Info->Node, "^_PSS",
836 1.5 christos ACPI_NS_NO_UPSEARCH, &Node);
837 1.5 christos if (ACPI_SUCCESS (Status))
838 1.5 christos {
839 1.5 christos return (AE_OK);
840 1.5 christos }
841 1.5 christos
842 1.5 christos Status = AcpiNsCheckSortedList (Info, ReturnObject, 0, 5, 1,
843 1.9 christos ACPI_SORT_DESCENDING, "PowerDissipation");
844 1.5 christos
845 1.5 christos return (Status);
846 1.5 christos }
847 1.5 christos
848 1.5 christos
849 1.5 christos /******************************************************************************
850 1.5 christos *
851 1.1 jruoho * FUNCTION: AcpiNsCheckSortedList
852 1.1 jruoho *
853 1.5 christos * PARAMETERS: Info - Method execution information block
854 1.1 jruoho * ReturnObject - Pointer to the top-level returned object
855 1.6 christos * StartIndex - Index of the first subpackage
856 1.6 christos * ExpectedCount - Minimum length of each subpackage
857 1.6 christos * SortIndex - Subpackage entry to sort on
858 1.1 jruoho * SortDirection - Ascending or descending
859 1.1 jruoho * SortKeyName - Name of the SortIndex field
860 1.1 jruoho *
861 1.1 jruoho * RETURN: Status. AE_OK if the list is valid and is sorted correctly or
862 1.1 jruoho * has been repaired by sorting the list.
863 1.1 jruoho *
864 1.1 jruoho * DESCRIPTION: Check if the package list is valid and sorted correctly by the
865 1.1 jruoho * SortIndex. If not, then sort the list.
866 1.1 jruoho *
867 1.1 jruoho *****************************************************************************/
868 1.1 jruoho
869 1.1 jruoho static ACPI_STATUS
870 1.1 jruoho AcpiNsCheckSortedList (
871 1.5 christos ACPI_EVALUATE_INFO *Info,
872 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnObject,
873 1.5 christos UINT32 StartIndex,
874 1.1 jruoho UINT32 ExpectedCount,
875 1.1 jruoho UINT32 SortIndex,
876 1.1 jruoho UINT8 SortDirection,
877 1.9 christos const char *SortKeyName)
878 1.1 jruoho {
879 1.1 jruoho UINT32 OuterElementCount;
880 1.1 jruoho ACPI_OPERAND_OBJECT **OuterElements;
881 1.1 jruoho ACPI_OPERAND_OBJECT **Elements;
882 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
883 1.1 jruoho UINT32 i;
884 1.1 jruoho UINT32 PreviousValue;
885 1.1 jruoho
886 1.1 jruoho
887 1.1 jruoho ACPI_FUNCTION_NAME (NsCheckSortedList);
888 1.1 jruoho
889 1.1 jruoho
890 1.1 jruoho /* The top-level object must be a package */
891 1.1 jruoho
892 1.1 jruoho if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
893 1.1 jruoho {
894 1.1 jruoho return (AE_AML_OPERAND_TYPE);
895 1.1 jruoho }
896 1.1 jruoho
897 1.1 jruoho /*
898 1.6 christos * NOTE: assumes list of subpackages contains no NULL elements.
899 1.1 jruoho * Any NULL elements should have been removed by earlier call
900 1.1 jruoho * to AcpiNsRemoveNullElements.
901 1.1 jruoho */
902 1.1 jruoho OuterElementCount = ReturnObject->Package.Count;
903 1.5 christos if (!OuterElementCount || StartIndex >= OuterElementCount)
904 1.1 jruoho {
905 1.1 jruoho return (AE_AML_PACKAGE_LIMIT);
906 1.1 jruoho }
907 1.1 jruoho
908 1.5 christos OuterElements = &ReturnObject->Package.Elements[StartIndex];
909 1.5 christos OuterElementCount -= StartIndex;
910 1.5 christos
911 1.1 jruoho PreviousValue = 0;
912 1.1 jruoho if (SortDirection == ACPI_SORT_DESCENDING)
913 1.1 jruoho {
914 1.1 jruoho PreviousValue = ACPI_UINT32_MAX;
915 1.1 jruoho }
916 1.1 jruoho
917 1.1 jruoho /* Examine each subpackage */
918 1.1 jruoho
919 1.1 jruoho for (i = 0; i < OuterElementCount; i++)
920 1.1 jruoho {
921 1.1 jruoho /* Each element of the top-level package must also be a package */
922 1.1 jruoho
923 1.1 jruoho if ((*OuterElements)->Common.Type != ACPI_TYPE_PACKAGE)
924 1.1 jruoho {
925 1.1 jruoho return (AE_AML_OPERAND_TYPE);
926 1.1 jruoho }
927 1.1 jruoho
928 1.6 christos /* Each subpackage must have the minimum length */
929 1.1 jruoho
930 1.1 jruoho if ((*OuterElements)->Package.Count < ExpectedCount)
931 1.1 jruoho {
932 1.1 jruoho return (AE_AML_PACKAGE_LIMIT);
933 1.1 jruoho }
934 1.1 jruoho
935 1.1 jruoho Elements = (*OuterElements)->Package.Elements;
936 1.1 jruoho ObjDesc = Elements[SortIndex];
937 1.1 jruoho
938 1.1 jruoho if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
939 1.1 jruoho {
940 1.1 jruoho return (AE_AML_OPERAND_TYPE);
941 1.1 jruoho }
942 1.1 jruoho
943 1.1 jruoho /*
944 1.1 jruoho * The list must be sorted in the specified order. If we detect a
945 1.1 jruoho * discrepancy, sort the entire list.
946 1.1 jruoho */
947 1.1 jruoho if (((SortDirection == ACPI_SORT_ASCENDING) &&
948 1.1 jruoho (ObjDesc->Integer.Value < PreviousValue)) ||
949 1.1 jruoho ((SortDirection == ACPI_SORT_DESCENDING) &&
950 1.1 jruoho (ObjDesc->Integer.Value > PreviousValue)))
951 1.1 jruoho {
952 1.5 christos AcpiNsSortList (&ReturnObject->Package.Elements[StartIndex],
953 1.1 jruoho OuterElementCount, SortIndex, SortDirection);
954 1.1 jruoho
955 1.5 christos Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
956 1.1 jruoho
957 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
958 1.1 jruoho "%s: Repaired unsorted list - now sorted by %s\n",
959 1.5 christos Info->FullPathname, SortKeyName));
960 1.1 jruoho return (AE_OK);
961 1.1 jruoho }
962 1.1 jruoho
963 1.1 jruoho PreviousValue = (UINT32) ObjDesc->Integer.Value;
964 1.1 jruoho OuterElements++;
965 1.1 jruoho }
966 1.1 jruoho
967 1.1 jruoho return (AE_OK);
968 1.1 jruoho }
969 1.1 jruoho
970 1.1 jruoho
971 1.1 jruoho /******************************************************************************
972 1.1 jruoho *
973 1.1 jruoho * FUNCTION: AcpiNsSortList
974 1.1 jruoho *
975 1.1 jruoho * PARAMETERS: Elements - Package object element list
976 1.1 jruoho * Count - Element count for above
977 1.1 jruoho * Index - Sort by which package element
978 1.1 jruoho * SortDirection - Ascending or Descending sort
979 1.1 jruoho *
980 1.1 jruoho * RETURN: None
981 1.1 jruoho *
982 1.1 jruoho * DESCRIPTION: Sort the objects that are in a package element list.
983 1.1 jruoho *
984 1.1 jruoho * NOTE: Assumes that all NULL elements have been removed from the package,
985 1.1 jruoho * and that all elements have been verified to be of type Integer.
986 1.1 jruoho *
987 1.1 jruoho *****************************************************************************/
988 1.1 jruoho
989 1.1 jruoho static void
990 1.1 jruoho AcpiNsSortList (
991 1.1 jruoho ACPI_OPERAND_OBJECT **Elements,
992 1.1 jruoho UINT32 Count,
993 1.1 jruoho UINT32 Index,
994 1.1 jruoho UINT8 SortDirection)
995 1.1 jruoho {
996 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc1;
997 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc2;
998 1.1 jruoho ACPI_OPERAND_OBJECT *TempObj;
999 1.1 jruoho UINT32 i;
1000 1.1 jruoho UINT32 j;
1001 1.1 jruoho
1002 1.1 jruoho
1003 1.1 jruoho /* Simple bubble sort */
1004 1.1 jruoho
1005 1.1 jruoho for (i = 1; i < Count; i++)
1006 1.1 jruoho {
1007 1.1 jruoho for (j = (Count - 1); j >= i; j--)
1008 1.1 jruoho {
1009 1.1 jruoho ObjDesc1 = Elements[j-1]->Package.Elements[Index];
1010 1.1 jruoho ObjDesc2 = Elements[j]->Package.Elements[Index];
1011 1.1 jruoho
1012 1.1 jruoho if (((SortDirection == ACPI_SORT_ASCENDING) &&
1013 1.1 jruoho (ObjDesc1->Integer.Value > ObjDesc2->Integer.Value)) ||
1014 1.1 jruoho
1015 1.1 jruoho ((SortDirection == ACPI_SORT_DESCENDING) &&
1016 1.1 jruoho (ObjDesc1->Integer.Value < ObjDesc2->Integer.Value)))
1017 1.1 jruoho {
1018 1.1 jruoho TempObj = Elements[j-1];
1019 1.1 jruoho Elements[j-1] = Elements[j];
1020 1.1 jruoho Elements[j] = TempObj;
1021 1.1 jruoho }
1022 1.1 jruoho }
1023 1.1 jruoho }
1024 1.1 jruoho }
1025 1.5 christos
1026 1.5 christos
1027 1.5 christos /******************************************************************************
1028 1.5 christos *
1029 1.5 christos * FUNCTION: AcpiNsRemoveElement
1030 1.5 christos *
1031 1.5 christos * PARAMETERS: ObjDesc - Package object element list
1032 1.5 christos * Index - Index of element to remove
1033 1.5 christos *
1034 1.5 christos * RETURN: None
1035 1.5 christos *
1036 1.5 christos * DESCRIPTION: Remove the requested element of a package and delete it.
1037 1.5 christos *
1038 1.5 christos *****************************************************************************/
1039 1.5 christos
1040 1.5 christos static void
1041 1.5 christos AcpiNsRemoveElement (
1042 1.5 christos ACPI_OPERAND_OBJECT *ObjDesc,
1043 1.5 christos UINT32 Index)
1044 1.5 christos {
1045 1.5 christos ACPI_OPERAND_OBJECT **Source;
1046 1.5 christos ACPI_OPERAND_OBJECT **Dest;
1047 1.5 christos UINT32 Count;
1048 1.5 christos UINT32 NewCount;
1049 1.5 christos UINT32 i;
1050 1.5 christos
1051 1.5 christos
1052 1.5 christos ACPI_FUNCTION_NAME (NsRemoveElement);
1053 1.5 christos
1054 1.5 christos
1055 1.5 christos Count = ObjDesc->Package.Count;
1056 1.5 christos NewCount = Count - 1;
1057 1.5 christos
1058 1.5 christos Source = ObjDesc->Package.Elements;
1059 1.5 christos Dest = Source;
1060 1.5 christos
1061 1.5 christos /* Examine all elements of the package object, remove matched index */
1062 1.5 christos
1063 1.5 christos for (i = 0; i < Count; i++)
1064 1.5 christos {
1065 1.5 christos if (i == Index)
1066 1.5 christos {
1067 1.5 christos AcpiUtRemoveReference (*Source); /* Remove one ref for being in pkg */
1068 1.5 christos AcpiUtRemoveReference (*Source);
1069 1.5 christos }
1070 1.5 christos else
1071 1.5 christos {
1072 1.5 christos *Dest = *Source;
1073 1.5 christos Dest++;
1074 1.5 christos }
1075 1.9 christos
1076 1.5 christos Source++;
1077 1.5 christos }
1078 1.5 christos
1079 1.5 christos /* NULL terminate list and update the package count */
1080 1.5 christos
1081 1.5 christos *Dest = NULL;
1082 1.5 christos ObjDesc->Package.Count = NewCount;
1083 1.5 christos }
1084