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