Deleted Added
full compact
nsrepair.c (199337) nsrepair.c (200553)
1/******************************************************************************
2 *
3 * Module Name: nsrepair - Repair for objects returned by predefined methods
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *

--- 105 unchanged lines hidden (view full) ---

114 *****************************************************************************/
115
116#define __NSREPAIR_C__
117
118#include <contrib/dev/acpica/include/acpi.h>
119#include <contrib/dev/acpica/include/accommon.h>
120#include <contrib/dev/acpica/include/acnamesp.h>
121#include <contrib/dev/acpica/include/acinterp.h>
1/******************************************************************************
2 *
3 * Module Name: nsrepair - Repair for objects returned by predefined methods
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *

--- 105 unchanged lines hidden (view full) ---

114 *****************************************************************************/
115
116#define __NSREPAIR_C__
117
118#include <contrib/dev/acpica/include/acpi.h>
119#include <contrib/dev/acpica/include/accommon.h>
120#include <contrib/dev/acpica/include/acnamesp.h>
121#include <contrib/dev/acpica/include/acinterp.h>
122#include <contrib/dev/acpica/include/acpredef.h>
123
124#define _COMPONENT ACPI_NAMESPACE
125 ACPI_MODULE_NAME ("nsrepair")
126
127
128/*******************************************************************************
129 *
122
123#define _COMPONENT ACPI_NAMESPACE
124 ACPI_MODULE_NAME ("nsrepair")
125
126
127/*******************************************************************************
128 *
129 * This module attempts to repair or convert objects returned by the
130 * predefined methods to an object type that is expected, as per the ACPI
131 * specification. The need for this code is dictated by the many machines that
132 * return incorrect types for the standard predefined methods. Performing these
133 * conversions here, in one place, eliminates the need for individual ACPI
134 * device drivers to do the same. Note: Most of these conversions are different
135 * than the internal object conversion routines used for implicit object
136 * conversion.
137 *
138 * The following conversions can be performed as necessary:
139 *
140 * Integer -> String
141 * Integer -> Buffer
142 * String -> Integer
143 * String -> Buffer
144 * Buffer -> Integer
145 * Buffer -> String
146 * Buffer -> Package of Integers
147 * Package -> Package of one Package
148 *
149 ******************************************************************************/
150
151
152/* Local prototypes */
153
154static ACPI_STATUS
155AcpiNsConvertToInteger (
156 ACPI_OPERAND_OBJECT *OriginalObject,
157 ACPI_OPERAND_OBJECT **ReturnObject);
158
159static ACPI_STATUS
160AcpiNsConvertToString (
161 ACPI_OPERAND_OBJECT *OriginalObject,
162 ACPI_OPERAND_OBJECT **ReturnObject);
163
164static ACPI_STATUS
165AcpiNsConvertToBuffer (
166 ACPI_OPERAND_OBJECT *OriginalObject,
167 ACPI_OPERAND_OBJECT **ReturnObject);
168
169static ACPI_STATUS
170AcpiNsConvertToPackage (
171 ACPI_OPERAND_OBJECT *OriginalObject,
172 ACPI_OPERAND_OBJECT **ReturnObject);
173
174
175/*******************************************************************************
176 *
130 * FUNCTION: AcpiNsRepairObject
131 *
132 * PARAMETERS: Data - Pointer to validation data structure
133 * ExpectedBtypes - Object types expected
134 * PackageIndex - Index of object within parent package (if
135 * applicable - ACPI_NOT_PACKAGE_ELEMENT
136 * otherwise)
137 * ReturnObjectPtr - Pointer to the object returned from the

--- 10 unchanged lines hidden (view full) ---

148AcpiNsRepairObject (
149 ACPI_PREDEFINED_DATA *Data,
150 UINT32 ExpectedBtypes,
151 UINT32 PackageIndex,
152 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
153{
154 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
155 ACPI_OPERAND_OBJECT *NewObject;
177 * FUNCTION: AcpiNsRepairObject
178 *
179 * PARAMETERS: Data - Pointer to validation data structure
180 * ExpectedBtypes - Object types expected
181 * PackageIndex - Index of object within parent package (if
182 * applicable - ACPI_NOT_PACKAGE_ELEMENT
183 * otherwise)
184 * ReturnObjectPtr - Pointer to the object returned from the

--- 10 unchanged lines hidden (view full) ---

195AcpiNsRepairObject (
196 ACPI_PREDEFINED_DATA *Data,
197 UINT32 ExpectedBtypes,
198 UINT32 PackageIndex,
199 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
200{
201 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
202 ACPI_OPERAND_OBJECT *NewObject;
156 ACPI_SIZE Length;
157 ACPI_STATUS Status;
158
159
203 ACPI_STATUS Status;
204
205
206 ACPI_FUNCTION_NAME (NsRepairObject);
207
208
160 /*
161 * At this point, we know that the type of the returned object was not
162 * one of the expected types for this predefined name. Attempt to
209 /*
210 * At this point, we know that the type of the returned object was not
211 * one of the expected types for this predefined name. Attempt to
163 * repair the object. Only a limited number of repairs are possible.
212 * repair the object by converting it to one of the expected object
213 * types for this predefined name.
164 */
214 */
165 switch (ReturnObject->Common.Type)
215 if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
166 {
216 {
217 Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
218 if (ACPI_SUCCESS (Status))
219 {
220 goto ObjectRepaired;
221 }
222 }
223 if (ExpectedBtypes & ACPI_RTYPE_STRING)
224 {
225 Status = AcpiNsConvertToString (ReturnObject, &NewObject);
226 if (ACPI_SUCCESS (Status))
227 {
228 goto ObjectRepaired;
229 }
230 }
231 if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
232 {
233 Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
234 if (ACPI_SUCCESS (Status))
235 {
236 goto ObjectRepaired;
237 }
238 }
239 if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
240 {
241 Status = AcpiNsConvertToPackage (ReturnObject, &NewObject);
242 if (ACPI_SUCCESS (Status))
243 {
244 goto ObjectRepaired;
245 }
246 }
247
248 /* We cannot repair this object */
249
250 return (AE_AML_OPERAND_TYPE);
251
252
253ObjectRepaired:
254
255 /* Object was successfully repaired */
256
257 /*
258 * If the original object is a package element, we need to:
259 * 1. Set the reference count of the new object to match the
260 * reference count of the old object.
261 * 2. Decrement the reference count of the original object.
262 */
263 if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
264 {
265 NewObject->Common.ReferenceCount =
266 ReturnObject->Common.ReferenceCount;
267
268 if (ReturnObject->Common.ReferenceCount > 1)
269 {
270 ReturnObject->Common.ReferenceCount--;
271 }
272
273 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
274 "%s: Converted %s to expected %s at index %u\n",
275 Data->Pathname, AcpiUtGetObjectTypeName (ReturnObject),
276 AcpiUtGetObjectTypeName (NewObject), PackageIndex));
277 }
278 else
279 {
280 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
281 "%s: Converted %s to expected %s\n",
282 Data->Pathname, AcpiUtGetObjectTypeName (ReturnObject),
283 AcpiUtGetObjectTypeName (NewObject)));
284 }
285
286 /* Delete old object, install the new return object */
287
288 AcpiUtRemoveReference (ReturnObject);
289 *ReturnObjectPtr = NewObject;
290 Data->Flags |= ACPI_OBJECT_REPAIRED;
291 return (AE_OK);
292}
293
294
295/*******************************************************************************
296 *
297 * FUNCTION: AcpiNsConvertToInteger
298 *
299 * PARAMETERS: OriginalObject - Object to be converted
300 * ReturnObject - Where the new converted object is returned
301 *
302 * RETURN: Status. AE_OK if conversion was successful.
303 *
304 * DESCRIPTION: Attempt to convert a String/Buffer object to an Integer.
305 *
306 ******************************************************************************/
307
308static ACPI_STATUS
309AcpiNsConvertToInteger (
310 ACPI_OPERAND_OBJECT *OriginalObject,
311 ACPI_OPERAND_OBJECT **ReturnObject)
312{
313 ACPI_OPERAND_OBJECT *NewObject;
314 ACPI_STATUS Status;
315 UINT64 Value = 0;
316 UINT32 i;
317
318
319 switch (OriginalObject->Common.Type)
320 {
321 case ACPI_TYPE_STRING:
322
323 /* String-to-Integer conversion */
324
325 Status = AcpiUtStrtoul64 (OriginalObject->String.Pointer,
326 ACPI_ANY_BASE, &Value);
327 if (ACPI_FAILURE (Status))
328 {
329 return (Status);
330 }
331 break;
332
167 case ACPI_TYPE_BUFFER:
168
333 case ACPI_TYPE_BUFFER:
334
169 /* Does the method/object legally return a string? */
335 /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */
170
336
171 if (!(ExpectedBtypes & ACPI_RTYPE_STRING))
337 if (OriginalObject->Buffer.Length > 8)
172 {
173 return (AE_AML_OPERAND_TYPE);
174 }
175
338 {
339 return (AE_AML_OPERAND_TYPE);
340 }
341
342 /* Extract each buffer byte to create the integer */
343
344 for (i = 0; i < OriginalObject->Buffer.Length; i++)
345 {
346 Value |= ((UINT64) OriginalObject->Buffer.Pointer[i] << (i * 8));
347 }
348 break;
349
350 default:
351 return (AE_AML_OPERAND_TYPE);
352 }
353
354 NewObject = AcpiUtCreateIntegerObject (Value);
355 if (!NewObject)
356 {
357 return (AE_NO_MEMORY);
358 }
359
360 *ReturnObject = NewObject;
361 return (AE_OK);
362}
363
364
365/*******************************************************************************
366 *
367 * FUNCTION: AcpiNsConvertToString
368 *
369 * PARAMETERS: OriginalObject - Object to be converted
370 * ReturnObject - Where the new converted object is returned
371 *
372 * RETURN: Status. AE_OK if conversion was successful.
373 *
374 * DESCRIPTION: Attempt to convert a Integer/Buffer object to a String.
375 *
376 ******************************************************************************/
377
378static ACPI_STATUS
379AcpiNsConvertToString (
380 ACPI_OPERAND_OBJECT *OriginalObject,
381 ACPI_OPERAND_OBJECT **ReturnObject)
382{
383 ACPI_OPERAND_OBJECT *NewObject;
384 ACPI_SIZE Length;
385 ACPI_STATUS Status;
386
387
388 switch (OriginalObject->Common.Type)
389 {
390 case ACPI_TYPE_INTEGER:
176 /*
391 /*
177 * Have a Buffer, expected a String, convert. Use a ToString
392 * Integer-to-String conversion. Commonly, convert
393 * an integer of value 0 to a NULL string. The last element of
394 * _BIF and _BIX packages occasionally need this fix.
395 */
396 if (OriginalObject->Integer.Value == 0)
397 {
398 /* Allocate a new NULL string object */
399
400 NewObject = AcpiUtCreateStringObject (0);
401 if (!NewObject)
402 {
403 return (AE_NO_MEMORY);
404 }
405 }
406 else
407 {
408 Status = AcpiExConvertToString (OriginalObject, &NewObject,
409 ACPI_IMPLICIT_CONVERT_HEX);
410 if (ACPI_FAILURE (Status))
411 {
412 return (Status);
413 }
414 }
415 break;
416
417 case ACPI_TYPE_BUFFER:
418 /*
419 * Buffer-to-String conversion. Use a ToString
178 * conversion, no transform performed on the buffer data. The best
179 * example of this is the _BIF method, where the string data from
180 * the battery is often (incorrectly) returned as buffer object(s).
181 */
182 Length = 0;
420 * conversion, no transform performed on the buffer data. The best
421 * example of this is the _BIF method, where the string data from
422 * the battery is often (incorrectly) returned as buffer object(s).
423 */
424 Length = 0;
183 while ((Length < ReturnObject->Buffer.Length) &&
184 (ReturnObject->Buffer.Pointer[Length]))
425 while ((Length < OriginalObject->Buffer.Length) &&
426 (OriginalObject->Buffer.Pointer[Length]))
185 {
186 Length++;
187 }
188
189 /* Allocate a new string object */
190
191 NewObject = AcpiUtCreateStringObject (Length);
192 if (!NewObject)
193 {
194 return (AE_NO_MEMORY);
195 }
196
197 /*
198 * Copy the raw buffer data with no transform. String is already NULL
199 * terminated at Length+1.
200 */
201 ACPI_MEMCPY (NewObject->String.Pointer,
427 {
428 Length++;
429 }
430
431 /* Allocate a new string object */
432
433 NewObject = AcpiUtCreateStringObject (Length);
434 if (!NewObject)
435 {
436 return (AE_NO_MEMORY);
437 }
438
439 /*
440 * Copy the raw buffer data with no transform. String is already NULL
441 * terminated at Length+1.
442 */
443 ACPI_MEMCPY (NewObject->String.Pointer,
202 ReturnObject->Buffer.Pointer, Length);
444 OriginalObject->Buffer.Pointer, Length);
203 break;
204
445 break;
446
447 default:
448 return (AE_AML_OPERAND_TYPE);
449 }
205
450
451 *ReturnObject = NewObject;
452 return (AE_OK);
453}
454
455
456/*******************************************************************************
457 *
458 * FUNCTION: AcpiNsConvertToBuffer
459 *
460 * PARAMETERS: OriginalObject - Object to be converted
461 * ReturnObject - Where the new converted object is returned
462 *
463 * RETURN: Status. AE_OK if conversion was successful.
464 *
465 * DESCRIPTION: Attempt to convert a Integer/String/Package object to a Buffer.
466 *
467 ******************************************************************************/
468
469static ACPI_STATUS
470AcpiNsConvertToBuffer (
471 ACPI_OPERAND_OBJECT *OriginalObject,
472 ACPI_OPERAND_OBJECT **ReturnObject)
473{
474 ACPI_OPERAND_OBJECT *NewObject;
475 ACPI_STATUS Status;
476 ACPI_OPERAND_OBJECT **Elements;
477 UINT32 *DwordBuffer;
478 UINT32 Count;
479 UINT32 i;
480
481
482 switch (OriginalObject->Common.Type)
483 {
206 case ACPI_TYPE_INTEGER:
484 case ACPI_TYPE_INTEGER:
485 /*
486 * Integer-to-Buffer conversion.
487 * Convert the Integer to a packed-byte buffer. _MAT and other
488 * objects need this sometimes, if a read has been performed on a
489 * Field object that is less than or equal to the global integer
490 * size (32 or 64 bits).
491 */
492 Status = AcpiExConvertToBuffer (OriginalObject, &NewObject);
493 if (ACPI_FAILURE (Status))
494 {
495 return (Status);
496 }
497 break;
207
498
208 /* 1) Does the method/object legally return a buffer? */
499 case ACPI_TYPE_STRING:
209
500
210 if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
501 /* String-to-Buffer conversion. Simple data copy */
502
503 NewObject = AcpiUtCreateBufferObject (OriginalObject->String.Length);
504 if (!NewObject)
211 {
505 {
212 /*
213 * Convert the Integer to a packed-byte buffer. _MAT needs
214 * this sometimes, if a read has been performed on a Field
215 * object that is less than or equal to the global integer
216 * size (32 or 64 bits).
217 */
218 Status = AcpiExConvertToBuffer (ReturnObject, &NewObject);
219 if (ACPI_FAILURE (Status))
220 {
221 return (Status);
222 }
506 return (AE_NO_MEMORY);
223 }
224
507 }
508
225 /* 2) Does the method/object legally return a string? */
509 ACPI_MEMCPY (NewObject->Buffer.Pointer,
510 OriginalObject->String.Pointer, OriginalObject->String.Length);
511 break;
226
512
227 else if (ExpectedBtypes & ACPI_RTYPE_STRING)
513 case ACPI_TYPE_PACKAGE:
514 /*
515 * This case is often seen for predefined names that must return a
516 * Buffer object with multiple DWORD integers within. For example,
517 * _FDE and _GTM. The Package can be converted to a Buffer.
518 */
519
520 /* All elements of the Package must be integers */
521
522 Elements = OriginalObject->Package.Elements;
523 Count = OriginalObject->Package.Count;
524
525 for (i = 0; i < Count; i++)
228 {
526 {
229 /*
230 * The only supported Integer-to-String conversion is to convert
231 * an integer of value 0 to a NULL string. The last element of
232 * _BIF and _BIX packages occasionally need this fix.
233 */
234 if (ReturnObject->Integer.Value != 0)
527 if ((!*Elements) ||
528 ((*Elements)->Common.Type != ACPI_TYPE_INTEGER))
235 {
236 return (AE_AML_OPERAND_TYPE);
237 }
529 {
530 return (AE_AML_OPERAND_TYPE);
531 }
532 Elements++;
533 }
238
534
239 /* Allocate a new NULL string object */
535 /* Create the new buffer object to replace the Package */
240
536
241 NewObject = AcpiUtCreateStringObject (0);
242 if (!NewObject)
243 {
244 return (AE_NO_MEMORY);
245 }
246 }
247 else
537 NewObject = AcpiUtCreateBufferObject (ACPI_MUL_4 (Count));
538 if (!NewObject)
248 {
539 {
249 return (AE_AML_OPERAND_TYPE);
540 return (AE_NO_MEMORY);
250 }
541 }
251 break;
252
542
543 /* Copy the package elements (integers) to the buffer as DWORDs */
253
544
254 default:
545 Elements = OriginalObject->Package.Elements;
546 DwordBuffer = ACPI_CAST_PTR (UINT32, NewObject->Buffer.Pointer);
255
547
256 /* We cannot repair this object */
548 for (i = 0; i < Count; i++)
549 {
550 *DwordBuffer = (UINT32) (*Elements)->Integer.Value;
551 DwordBuffer++;
552 Elements++;
553 }
554 break;
257
555
556 default:
258 return (AE_AML_OPERAND_TYPE);
259 }
260
557 return (AE_AML_OPERAND_TYPE);
558 }
559
261 /* Object was successfully repaired */
560 *ReturnObject = NewObject;
561 return (AE_OK);
562}
262
563
263 /*
264 * If the original object is a package element, we need to:
265 * 1. Set the reference count of the new object to match the
266 * reference count of the old object.
267 * 2. Decrement the reference count of the original object.
268 */
269 if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
564
565/*******************************************************************************
566 *
567 * FUNCTION: AcpiNsConvertToPackage
568 *
569 * PARAMETERS: OriginalObject - Object to be converted
570 * ReturnObject - Where the new converted object is returned
571 *
572 * RETURN: Status. AE_OK if conversion was successful.
573 *
574 * DESCRIPTION: Attempt to convert a Buffer object to a Package. Each byte of
575 * the buffer is converted to a single integer package element.
576 *
577 ******************************************************************************/
578
579static ACPI_STATUS
580AcpiNsConvertToPackage (
581 ACPI_OPERAND_OBJECT *OriginalObject,
582 ACPI_OPERAND_OBJECT **ReturnObject)
583{
584 ACPI_OPERAND_OBJECT *NewObject;
585 ACPI_OPERAND_OBJECT **Elements;
586 UINT32 Length;
587 UINT8 *Buffer;
588
589
590 switch (OriginalObject->Common.Type)
270 {
591 {
271 NewObject->Common.ReferenceCount =
272 ReturnObject->Common.ReferenceCount;
592 case ACPI_TYPE_BUFFER:
273
593
274 if (ReturnObject->Common.ReferenceCount > 1)
594 /* Buffer-to-Package conversion */
595
596 Length = OriginalObject->Buffer.Length;
597 NewObject = AcpiUtCreatePackageObject (Length);
598 if (!NewObject)
275 {
599 {
276 ReturnObject->Common.ReferenceCount--;
600 return (AE_NO_MEMORY);
277 }
278
601 }
602
279 ACPI_INFO_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
280 "Converted %s to expected %s at index %u",
281 AcpiUtGetObjectTypeName (ReturnObject),
282 AcpiUtGetObjectTypeName (NewObject), PackageIndex));
283 }
284 else
285 {
286 ACPI_INFO_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
287 "Converted %s to expected %s",
288 AcpiUtGetObjectTypeName (ReturnObject),
289 AcpiUtGetObjectTypeName (NewObject)));
290 }
603 /* Convert each buffer byte to an integer package element */
291
604
292 /* Delete old object, install the new return object */
605 Elements = NewObject->Package.Elements;
606 Buffer = OriginalObject->Buffer.Pointer;
293
607
294 AcpiUtRemoveReference (ReturnObject);
295 *ReturnObjectPtr = NewObject;
296 Data->Flags |= ACPI_OBJECT_REPAIRED;
608 while (Length--)
609 {
610 *Elements = AcpiUtCreateIntegerObject ((UINT64) *Buffer);
611 if (!*Elements)
612 {
613 AcpiUtRemoveReference (NewObject);
614 return (AE_NO_MEMORY);
615 }
616 Elements++;
617 Buffer++;
618 }
619 break;
620
621 default:
622 return (AE_AML_OPERAND_TYPE);
623 }
624
625 *ReturnObject = NewObject;
297 return (AE_OK);
298}
299
300
301/*******************************************************************************
302 *
303 * FUNCTION: AcpiNsRepairPackageList
304 *

--- 20 unchanged lines hidden (view full) ---

325ACPI_STATUS
326AcpiNsRepairPackageList (
327 ACPI_PREDEFINED_DATA *Data,
328 ACPI_OPERAND_OBJECT **ObjDescPtr)
329{
330 ACPI_OPERAND_OBJECT *PkgObjDesc;
331
332
626 return (AE_OK);
627}
628
629
630/*******************************************************************************
631 *
632 * FUNCTION: AcpiNsRepairPackageList
633 *

--- 20 unchanged lines hidden (view full) ---

654ACPI_STATUS
655AcpiNsRepairPackageList (
656 ACPI_PREDEFINED_DATA *Data,
657 ACPI_OPERAND_OBJECT **ObjDescPtr)
658{
659 ACPI_OPERAND_OBJECT *PkgObjDesc;
660
661
662 ACPI_FUNCTION_NAME (NsRepairPackageList);
663
664
333 /*
334 * Create the new outer package and populate it. The new package will
335 * have a single element, the lone subpackage.
336 */
337 PkgObjDesc = AcpiUtCreatePackageObject (1);
338 if (!PkgObjDesc)
339 {
340 return (AE_NO_MEMORY);
341 }
342
343 PkgObjDesc->Package.Elements[0] = *ObjDescPtr;
344
345 /* Return the new object in the object pointer */
346
347 *ObjDescPtr = PkgObjDesc;
348 Data->Flags |= ACPI_OBJECT_REPAIRED;
349
665 /*
666 * Create the new outer package and populate it. The new package will
667 * have a single element, the lone subpackage.
668 */
669 PkgObjDesc = AcpiUtCreatePackageObject (1);
670 if (!PkgObjDesc)
671 {
672 return (AE_NO_MEMORY);
673 }
674
675 PkgObjDesc->Package.Elements[0] = *ObjDescPtr;
676
677 /* Return the new object in the object pointer */
678
679 *ObjDescPtr = PkgObjDesc;
680 Data->Flags |= ACPI_OBJECT_REPAIRED;
681
350 ACPI_INFO_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
351 "Repaired Incorrectly formed Package"));
682 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
683 "%s: Repaired incorrectly formed Package\n", Data->Pathname));
352
353 return (AE_OK);
354}
684
685 return (AE_OK);
686}