ReactOS 0.4.15-dev-7654-g6bc40d3
nsrepair.c File Reference
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "acinterp.h"
#include "acpredef.h"
#include "amlresrc.h"
Include dependency graph for nsrepair.c:

Go to the source code of this file.

Macros

#define _COMPONENT   ACPI_NAMESPACE
 

Functions

static const ACPI_SIMPLE_REPAIR_INFOAcpiNsMatchSimpleRepair (ACPI_NAMESPACE_NODE *Node, UINT32 ReturnBtype, UINT32 PackageIndex)
 
ACPI_STATUS AcpiNsSimpleRepair (ACPI_EVALUATE_INFO *Info, UINT32 ExpectedBtypes, UINT32 PackageIndex, ACPI_OPERAND_OBJECT **ReturnObjectPtr)
 
ACPI_STATUS AcpiNsRepairNullElement (ACPI_EVALUATE_INFO *Info, UINT32 ExpectedBtypes, UINT32 PackageIndex, ACPI_OPERAND_OBJECT **ReturnObjectPtr)
 
void AcpiNsRemoveNullElements (ACPI_EVALUATE_INFO *Info, UINT8 PackageType, ACPI_OPERAND_OBJECT *ObjDesc)
 
ACPI_STATUS AcpiNsWrapWithPackage (ACPI_EVALUATE_INFO *Info, ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ObjDescPtr)
 

Variables

static const ACPI_SIMPLE_REPAIR_INFO AcpiObjectRepairInfo []
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_NAMESPACE

Definition at line 51 of file nsrepair.c.

Function Documentation

◆ AcpiNsMatchSimpleRepair()

static const ACPI_SIMPLE_REPAIR_INFO * AcpiNsMatchSimpleRepair ( ACPI_NAMESPACE_NODE Node,
UINT32  ReturnBtype,
UINT32  PackageIndex 
)
static

Definition at line 352 of file nsrepair.c.

356{
357 const ACPI_SIMPLE_REPAIR_INFO *ThisName;
358
359
360 /* Search info table for a repairable predefined method/object name */
361
362 ThisName = AcpiObjectRepairInfo;
363 while (ThisName->ObjectConverter)
364 {
365 if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, ThisName->Name))
366 {
367 /* Check if we can actually repair this name/type combination */
368
369 if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
371 PackageIndex == ThisName->PackageIndex))
372 {
373 return (ThisName);
374 }
375
376 return (NULL);
377 }
378
379 ThisName++;
380 }
381
382 return (NULL); /* Name was not found in the repair table */
383}
#define ACPI_ALL_PACKAGE_ELEMENTS
Definition: acnamesp.h:83
#define ACPI_COMPARE_NAMESEG(a, b)
Definition: actypes.h:564
#define NULL
Definition: types.h:112
static const ACPI_SIMPLE_REPAIR_INFO AcpiObjectRepairInfo[]
Definition: nsrepair.c:103
char Name[ACPI_NAMESEG_SIZE]
Definition: aclocal.h:463
ACPI_OBJECT_CONVERTER ObjectConverter
Definition: aclocal.h:466
Definition: dlist.c:348

Referenced by AcpiNsSimpleRepair().

◆ AcpiNsRemoveNullElements()

void AcpiNsRemoveNullElements ( ACPI_EVALUATE_INFO Info,
UINT8  PackageType,
ACPI_OPERAND_OBJECT ObjDesc 
)

Definition at line 494 of file nsrepair.c.

498{
500 ACPI_OPERAND_OBJECT **Dest;
502 UINT32 NewCount;
503 UINT32 i;
504
505
506 ACPI_FUNCTION_NAME (NsRemoveNullElements);
507
508
509 /*
510 * We can safely remove all NULL elements from these package types:
511 * PTYPE1_VAR packages contain a variable number of simple data types.
512 * PTYPE2 packages contain a variable number of subpackages.
513 */
514 switch (PackageType)
515 {
516 case ACPI_PTYPE1_VAR:
517 case ACPI_PTYPE2:
521 case ACPI_PTYPE2_MIN:
524 break;
525
526 default:
530 return;
531 }
532
533 Count = ObjDesc->Package.Count;
534 NewCount = Count;
535
536 Source = ObjDesc->Package.Elements;
537 Dest = Source;
538
539 /* Examine all elements of the package object, remove nulls */
540
541 for (i = 0; i < Count; i++)
542 {
543 if (!*Source)
544 {
545 NewCount--;
546 }
547 else
548 {
549 *Dest = *Source;
550 Dest++;
551 }
552
553 Source++;
554 }
555
556 /* Update parent package if any null elements were removed */
557
558 if (NewCount < Count)
559 {
561 "%s: Found and removed %u NULL elements\n",
562 Info->FullPathname, (Count - NewCount)));
563
564 /* NULL terminate list and update the package count */
565
566 *Dest = NULL;
567 ObjDesc->Package.Count = NewCount;
568 }
569}
unsigned int UINT32
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_DB_REPAIR
Definition: acoutput.h:154
#define ACPI_FUNCTION_NAME(a)
Definition: acoutput.h:479
@ ACPI_PTYPE2_FIX_VAR
Definition: acpredef.h:132
@ ACPI_PTYPE2_REV_FIXED
Definition: acpredef.h:131
@ ACPI_PTYPE1_VAR
Definition: acpredef.h:124
@ ACPI_PTYPE2_FIXED
Definition: acpredef.h:129
@ ACPI_PTYPE2_PKG_COUNT
Definition: acpredef.h:128
@ ACPI_PTYPE1_FIXED
Definition: acpredef.h:123
@ ACPI_PTYPE2_MIN
Definition: acpredef.h:130
@ ACPI_PTYPE2
Definition: acpredef.h:126
@ ACPI_PTYPE2_COUNT
Definition: acpredef.h:127
@ ACPI_PTYPE1_OPTION
Definition: acpredef.h:125
@ ACPI_PTYPE2_VAR_VAR
Definition: acpredef.h:133
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
int Count
Definition: noreturn.cpp:7
union acpi_operand_object ** Elements
Definition: acobject.h:161
ACPI_OBJECT_PACKAGE Package
Definition: acobject.h:523
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690

Referenced by AcpiNsCheckPackage().

◆ AcpiNsRepairNullElement()

ACPI_STATUS AcpiNsRepairNullElement ( ACPI_EVALUATE_INFO Info,
UINT32  ExpectedBtypes,
UINT32  PackageIndex,
ACPI_OPERAND_OBJECT **  ReturnObjectPtr 
)

Definition at line 405 of file nsrepair.c.

410{
411 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
413
414
415 ACPI_FUNCTION_NAME (NsRepairNullElement);
416
417
418 /* No repair needed if return object is non-NULL */
419
420 if (ReturnObject)
421 {
422 return (AE_OK);
423 }
424
425 /*
426 * Attempt to repair a NULL element of a Package object. This applies to
427 * predefined names that return a fixed-length package and each element
428 * is required. It does not apply to variable-length packages where NULL
429 * elements are allowed, especially at the end of the package.
430 */
431 if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
432 {
433 /* Need an Integer - create a zero-value integer */
434
436 }
437 else if (ExpectedBtypes & ACPI_RTYPE_STRING)
438 {
439 /* Need a String - create a NULL string */
440
442 }
443 else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
444 {
445 /* Need a Buffer - create a zero-length buffer */
446
448 }
449 else
450 {
451 /* Error for all other expected types */
452
453 return (AE_AML_OPERAND_TYPE);
454 }
455
456 if (!NewObject)
457 {
458 return (AE_NO_MEMORY);
459 }
460
461 /* Set the reference count according to the parent Package object */
462
463 NewObject->Common.ReferenceCount =
464 Info->ParentPackage->Common.ReferenceCount;
465
467 "%s: Converted NULL package element to expected %s at index %u\n",
468 Info->FullPathname, AcpiUtGetObjectTypeName (NewObject),
469 PackageIndex));
470
471 *ReturnObjectPtr = NewObject;
472 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
473 return (AE_OK);
474}
unsigned long long UINT64
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define AE_AML_OPERAND_TYPE
Definition: acexcep.h:182
#define AE_OK
Definition: acexcep.h:97
#define ACPI_RTYPE_STRING
Definition: aclocal.h:479
#define ACPI_RTYPE_INTEGER
Definition: aclocal.h:478
#define ACPI_RTYPE_BUFFER
Definition: aclocal.h:480
#define ACPI_OBJECT_REPAIRED
Definition: acstruct.h:235
ACPI_OPERAND_OBJECT * AcpiUtCreateIntegerObject(UINT64 Value)
Definition: utobject.c:223
ACPI_OPERAND_OBJECT * AcpiUtCreateStringObject(ACPI_SIZE StringSize)
Definition: utobject.c:320
const char * AcpiUtGetObjectTypeName(ACPI_OPERAND_OBJECT *ObjDesc)
Definition: utdecode.c:264
ACPI_OPERAND_OBJECT * AcpiUtCreateBufferObject(ACPI_SIZE BufferSize)
Definition: utobject.c:258
_Inout_opt_ PACCESS_STATE _In_opt_ ACCESS_MASK _In_ ULONG _Out_opt_ PVOID * NewObject
Definition: obfuncs.h:74

Referenced by AcpiNsSimpleRepair().

◆ AcpiNsSimpleRepair()

ACPI_STATUS AcpiNsSimpleRepair ( ACPI_EVALUATE_INFO Info,
UINT32  ExpectedBtypes,
UINT32  PackageIndex,
ACPI_OPERAND_OBJECT **  ReturnObjectPtr 
)

Definition at line 153 of file nsrepair.c.

158{
159 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
162 const ACPI_SIMPLE_REPAIR_INFO *Predefined;
163
164
165 ACPI_FUNCTION_NAME (NsSimpleRepair);
166
167
168 /*
169 * Special repairs for certain names that are in the repair table.
170 * Check if this name is in the list of repairable names.
171 */
172 Predefined = AcpiNsMatchSimpleRepair (Info->Node,
173 Info->ReturnBtype, PackageIndex);
174 if (Predefined)
175 {
176 if (!ReturnObject)
177 {
178 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
179 ACPI_WARN_ALWAYS, "Missing expected return value"));
180 }
181
182 Status = Predefined->ObjectConverter (Info->Node, ReturnObject,
183 &NewObject);
184 if (ACPI_FAILURE (Status))
185 {
186 /* A fatal error occurred during a conversion */
187
189 "During return object analysis"));
190 return (Status);
191 }
192 if (NewObject)
193 {
194 goto ObjectRepaired;
195 }
196 }
197
198 /*
199 * Do not perform simple object repair unless the return type is not
200 * expected.
201 */
202 if (Info->ReturnBtype & ExpectedBtypes)
203 {
204 return (AE_OK);
205 }
206
207 /*
208 * At this point, we know that the type of the returned object was not
209 * one of the expected types for this predefined name. Attempt to
210 * repair the object by converting it to one of the expected object
211 * types for this predefined name.
212 */
213
214 /*
215 * If there is no return value, check if we require a return value for
216 * this predefined name. Either one return value is expected, or none,
217 * for both methods and other objects.
218 *
219 * Try to fix if there was no return object. Warning if failed to fix.
220 */
221 if (!ReturnObject)
222 {
223 if (ExpectedBtypes && (!(ExpectedBtypes & ACPI_RTYPE_NONE)))
224 {
225 if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
226 {
227 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
228 ACPI_WARN_ALWAYS, "Found unexpected NULL package element"));
229
230 Status = AcpiNsRepairNullElement (Info, ExpectedBtypes,
231 PackageIndex, ReturnObjectPtr);
232 if (ACPI_SUCCESS (Status))
233 {
234 return (AE_OK); /* Repair was successful */
235 }
236 }
237 else
238 {
239 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
240 ACPI_WARN_ALWAYS, "Missing expected return value"));
241 }
242
243 return (AE_AML_NO_RETURN_VALUE);
244 }
245 }
246
247 if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
248 {
249 Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
250 if (ACPI_SUCCESS (Status))
251 {
252 goto ObjectRepaired;
253 }
254 }
255 if (ExpectedBtypes & ACPI_RTYPE_STRING)
256 {
257 Status = AcpiNsConvertToString (ReturnObject, &NewObject);
258 if (ACPI_SUCCESS (Status))
259 {
260 goto ObjectRepaired;
261 }
262 }
263 if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
264 {
265 Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
266 if (ACPI_SUCCESS (Status))
267 {
268 goto ObjectRepaired;
269 }
270 }
271 if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
272 {
273 /*
274 * A package is expected. We will wrap the existing object with a
275 * new package object. It is often the case that if a variable-length
276 * package is required, but there is only a single object needed, the
277 * BIOS will return that object instead of wrapping it with a Package
278 * object. Note: after the wrapping, the package will be validated
279 * for correct contents (expected object type or types).
280 */
281 Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject);
282 if (ACPI_SUCCESS (Status))
283 {
284 /*
285 * The original object just had its reference count
286 * incremented for being inserted into the new package.
287 */
288 *ReturnObjectPtr = NewObject; /* New Package object */
289 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
290 return (AE_OK);
291 }
292 }
293
294 /* We cannot repair this object */
295
296 return (AE_AML_OPERAND_TYPE);
297
298
299ObjectRepaired:
300
301 /* Object was successfully repaired */
302
303 if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
304 {
305 /* Update reference count of new object */
306
307 if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED))
308 {
309 NewObject->Common.ReferenceCount =
310 ReturnObject->Common.ReferenceCount;
311 }
312
314 "%s: Converted %s to expected %s at Package index %u\n",
315 Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
316 AcpiUtGetObjectTypeName (NewObject), PackageIndex));
317 }
318 else
319 {
321 "%s: Converted %s to expected %s\n",
322 Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
324 }
325
326 /* Delete old object, install the new return object */
327
328 AcpiUtRemoveReference (ReturnObject);
329 *ReturnObjectPtr = NewObject;
330 Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
331 return (AE_OK);
332}
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_AML_NO_RETURN_VALUE
Definition: acexcep.h:197
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
#define ACPI_RTYPE_PACKAGE
Definition: aclocal.h:481
#define ACPI_RTYPE_NONE
Definition: aclocal.h:477
#define ACPI_WARN_PREDEFINED(plist)
Definition: acmacros.h:464
#define ACPI_NOT_PACKAGE_ELEMENT
Definition: acnamesp.h:82
ACPI_STATUS AcpiNsConvertToString(ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
Definition: nsconvert.c:141
ACPI_STATUS AcpiNsConvertToBuffer(ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
Definition: nsconvert.c:233
ACPI_STATUS AcpiNsConvertToInteger(ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
Definition: nsconvert.c:70
#define ACPI_WARN_ALWAYS
Definition: acnamesp.h:87
#define ACPI_EXCEPTION(plist)
Definition: acoutput.h:239
#define AE_INFO
Definition: acoutput.h:230
#define ACPI_OBJECT_WRAPPED
Definition: acstruct.h:236
UINT32 ACPI_STATUS
Definition: actypes.h:460
void AcpiUtRemoveReference(ACPI_OPERAND_OBJECT *Object)
Definition: utdelete.c:790
Status
Definition: gdiplustypes.h:25
ACPI_STATUS AcpiNsWrapWithPackage(ACPI_EVALUATE_INFO *Info, ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ObjDescPtr)
Definition: nsrepair.c:597
static const ACPI_SIMPLE_REPAIR_INFO * AcpiNsMatchSimpleRepair(ACPI_NAMESPACE_NODE *Node, UINT32 ReturnBtype, UINT32 PackageIndex)
Definition: nsrepair.c:352
ACPI_STATUS AcpiNsRepairNullElement(ACPI_EVALUATE_INFO *Info, UINT32 ExpectedBtypes, UINT32 PackageIndex, ACPI_OPERAND_OBJECT **ReturnObjectPtr)
Definition: nsrepair.c:405
ACPI_OBJECT_COMMON Common
Definition: acobject.h:519

Referenced by AcpiNsCheckObjectType().

◆ AcpiNsWrapWithPackage()

ACPI_STATUS AcpiNsWrapWithPackage ( ACPI_EVALUATE_INFO Info,
ACPI_OPERAND_OBJECT OriginalObject,
ACPI_OPERAND_OBJECT **  ObjDescPtr 
)

Definition at line 597 of file nsrepair.c.

601{
602 ACPI_OPERAND_OBJECT *PkgObjDesc;
603
604
605 ACPI_FUNCTION_NAME (NsWrapWithPackage);
606
607
608 /*
609 * Create the new outer package and populate it. The new
610 * package will have a single element, the lone sub-object.
611 */
612 PkgObjDesc = AcpiUtCreatePackageObject (1);
613 if (!PkgObjDesc)
614 {
615 return (AE_NO_MEMORY);
616 }
617
618 PkgObjDesc->Package.Elements[0] = OriginalObject;
619
621 "%s: Wrapped %s with expected Package object\n",
622 Info->FullPathname, AcpiUtGetObjectTypeName (OriginalObject)));
623
624 /* Return the new object in the object pointer */
625
626 *ObjDescPtr = PkgObjDesc;
628 return (AE_OK);
629}
ACPI_OPERAND_OBJECT * AcpiUtCreatePackageObject(UINT32 Count)
Definition: utobject.c:174

Referenced by AcpiNsCheckPackage(), and AcpiNsSimpleRepair().

Variable Documentation

◆ AcpiObjectRepairInfo

const ACPI_SIMPLE_REPAIR_INFO AcpiObjectRepairInfo[]
static
Initial value:
=
{
{ "_MLS", ACPI_RTYPE_STRING, 1,
{ {0,0,0,0}, 0, 0, NULL }
}
ACPI_STATUS AcpiNsConvertToResource(ACPI_NAMESPACE_NODE *Scope, ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
Definition: nsconvert.c:420
ACPI_STATUS AcpiNsConvertToUnicode(ACPI_NAMESPACE_NODE *Scope, ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
Definition: nsconvert.c:345
ACPI_STATUS AcpiNsConvertToReference(ACPI_NAMESPACE_NODE *Scope, ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
Definition: nsconvert.c:506

Definition at line 103 of file nsrepair.c.

Referenced by AcpiNsMatchSimpleRepair().