ReactOS 0.4.16-dev-329-g9223134
exprep.c File Reference
#include "acpi.h"
#include "accommon.h"
#include "acinterp.h"
#include "amlcode.h"
#include "acnamesp.h"
#include "acdispat.h"
Include dependency graph for exprep.c:

Go to the source code of this file.

Macros

#define _COMPONENT   ACPI_EXECUTER
 

Functions

static UINT32 AcpiExDecodeFieldAccess (ACPI_OPERAND_OBJECT *ObjDesc, UINT8 FieldFlags, UINT32 *ReturnByteAlignment)
 
ACPI_STATUS AcpiExPrepCommonFieldObject (ACPI_OPERAND_OBJECT *ObjDesc, UINT8 FieldFlags, UINT8 FieldAttribute, UINT32 FieldBitPosition, UINT32 FieldBitLength)
 
ACPI_STATUS AcpiExPrepFieldValue (ACPI_CREATE_FIELD_INFO *Info)
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_EXECUTER

Definition at line 52 of file exprep.c.

Function Documentation

◆ AcpiExDecodeFieldAccess()

static UINT32 AcpiExDecodeFieldAccess ( ACPI_OPERAND_OBJECT ObjDesc,
UINT8  FieldFlags,
UINT32 ReturnByteAlignment 
)
static

Definition at line 243 of file exprep.c.

247{
248 UINT32 Access;
249 UINT32 ByteAlignment;
250 UINT32 BitLength;
251
252
253 ACPI_FUNCTION_TRACE (ExDecodeFieldAccess);
254
255
256 Access = (FieldFlags & AML_FIELD_ACCESS_TYPE_MASK);
257
258 switch (Access)
259 {
261
262#ifdef ACPI_UNDER_DEVELOPMENT
263 ByteAlignment =
264 AcpiExGenerateAccess (ObjDesc->CommonField.StartFieldBitOffset,
265 ObjDesc->CommonField.BitLength,
266 0xFFFFFFFF /* Temp until we pass RegionLength as parameter */);
267 BitLength = ByteAlignment * 8;
268#endif
269
270 ByteAlignment = 1;
271 BitLength = 8;
272 break;
273
275 case AML_FIELD_ACCESS_BUFFER: /* ACPI 2.0 (SMBus Buffer) */
276
277 ByteAlignment = 1;
278 BitLength = 8;
279 break;
280
282
283 ByteAlignment = 2;
284 BitLength = 16;
285 break;
286
288
289 ByteAlignment = 4;
290 BitLength = 32;
291 break;
292
293 case AML_FIELD_ACCESS_QWORD: /* ACPI 2.0 */
294
295 ByteAlignment = 8;
296 BitLength = 64;
297 break;
298
299 default:
300
301 /* Invalid field access type */
302
304 "Unknown field access type 0x%X",
305 Access));
306
307 return_UINT32 (0);
308 }
309
310 if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
311 {
312 /*
313 * BufferField access can be on any byte boundary, so the
314 * ByteAlignment is always 1 byte -- regardless of any ByteAlignment
315 * implied by the field access type.
316 */
317 ByteAlignment = 1;
318 }
319
320 *ReturnByteAlignment = ByteAlignment;
321 return_UINT32 (BitLength);
322}
unsigned int UINT32
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define AE_INFO
Definition: acoutput.h:230
#define return_UINT32(s)
Definition: acoutput.h:501
#define ACPI_TYPE_BUFFER_FIELD
Definition: actypes.h:701
#define AML_FIELD_ACCESS_TYPE_MASK
Definition: amlcode.h:442
@ AML_FIELD_ACCESS_BYTE
Definition: amlcode.h:452
@ AML_FIELD_ACCESS_ANY
Definition: amlcode.h:451
@ AML_FIELD_ACCESS_WORD
Definition: amlcode.h:453
@ AML_FIELD_ACCESS_DWORD
Definition: amlcode.h:454
@ AML_FIELD_ACCESS_BUFFER
Definition: amlcode.h:456
@ AML_FIELD_ACCESS_QWORD
Definition: amlcode.h:455
ACPI_OBJECT_COMMON Common
Definition: acobject.h:519
ACPI_OBJECT_FIELD_COMMON CommonField
Definition: acobject.h:533

Referenced by AcpiExPrepCommonFieldObject().

◆ AcpiExPrepCommonFieldObject()

ACPI_STATUS AcpiExPrepCommonFieldObject ( ACPI_OPERAND_OBJECT ObjDesc,
UINT8  FieldFlags,
UINT8  FieldAttribute,
UINT32  FieldBitPosition,
UINT32  FieldBitLength 
)

Definition at line 347 of file exprep.c.

353{
354 UINT32 AccessBitWidth;
355 UINT32 ByteAlignment;
356 UINT32 NearestByteAddress;
357
358
359 ACPI_FUNCTION_TRACE (ExPrepCommonFieldObject);
360
361
362 /*
363 * Note: the structure being initialized is the
364 * ACPI_COMMON_FIELD_INFO; No structure fields outside of the common
365 * area are initialized by this procedure.
366 */
367 ObjDesc->CommonField.FieldFlags = FieldFlags;
368 ObjDesc->CommonField.Attribute = FieldAttribute;
369 ObjDesc->CommonField.BitLength = FieldBitLength;
370
371 /*
372 * Decode the access type so we can compute offsets. The access type gives
373 * two pieces of information - the width of each field access and the
374 * necessary ByteAlignment (address granularity) of the access.
375 *
376 * For AnyAcc, the AccessBitWidth is the largest width that is both
377 * necessary and possible in an attempt to access the whole field in one
378 * I/O operation. However, for AnyAcc, the ByteAlignment is always one
379 * byte.
380 *
381 * For all Buffer Fields, the ByteAlignment is always one byte.
382 *
383 * For all other access types (Byte, Word, Dword, Qword), the Bitwidth is
384 * the same (equivalent) as the ByteAlignment.
385 */
386 AccessBitWidth = AcpiExDecodeFieldAccess (
387 ObjDesc, FieldFlags, &ByteAlignment);
388 if (!AccessBitWidth)
389 {
391 }
392
393 /* Setup width (access granularity) fields (values are: 1, 2, 4, 8) */
394
395 ObjDesc->CommonField.AccessByteWidth = (UINT8)
396 ACPI_DIV_8 (AccessBitWidth);
397
398 /*
399 * BaseByteOffset is the address of the start of the field within the
400 * region. It is the byte address of the first *datum* (field-width data
401 * unit) of the field. (i.e., the first datum that contains at least the
402 * first *bit* of the field.)
403 *
404 * Note: ByteAlignment is always either equal to the AccessBitWidth or 8
405 * (Byte access), and it defines the addressing granularity of the parent
406 * region or buffer.
407 */
408 NearestByteAddress =
409 ACPI_ROUND_BITS_DOWN_TO_BYTES (FieldBitPosition);
410 ObjDesc->CommonField.BaseByteOffset = (UINT32)
411 ACPI_ROUND_DOWN (NearestByteAddress, ByteAlignment);
412
413 /*
414 * StartFieldBitOffset is the offset of the first bit of the field within
415 * a field datum.
416 */
417 ObjDesc->CommonField.StartFieldBitOffset = (UINT8)
418 (FieldBitPosition - ACPI_MUL_8 (ObjDesc->CommonField.BaseByteOffset));
419
421}
unsigned char UINT8
#define AE_AML_OPERAND_VALUE
Definition: acexcep.h:183
#define AE_OK
Definition: acexcep.h:97
#define ACPI_ROUND_DOWN(value, boundary)
Definition: acmacros.h:239
#define ACPI_MUL_8(a)
Definition: acmacros.h:215
#define ACPI_DIV_8(a)
Definition: acmacros.h:214
#define ACPI_ROUND_BITS_DOWN_TO_BYTES(a)
Definition: acmacros.h:257
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
static UINT32 AcpiExDecodeFieldAccess(ACPI_OPERAND_OBJECT *ObjDesc, UINT8 FieldFlags, UINT32 *ReturnByteAlignment)
Definition: exprep.c:243

Referenced by AcpiDsInitBufferField(), and AcpiExPrepFieldValue().

◆ AcpiExPrepFieldValue()

ACPI_STATUS AcpiExPrepFieldValue ( ACPI_CREATE_FIELD_INFO Info)

Definition at line 438 of file exprep.c.

440{
441 ACPI_OPERAND_OBJECT *ObjDesc;
442 ACPI_OPERAND_OBJECT *SecondDesc = NULL;
444 UINT32 AccessByteWidth;
445 UINT32 Type;
446
447
448 ACPI_FUNCTION_TRACE (ExPrepFieldValue);
449
450
451 /* Parameter validation */
452
453 if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD)
454 {
455 if (!Info->RegionNode)
456 {
457 ACPI_ERROR ((AE_INFO, "Null RegionNode"));
459 }
460
461 Type = AcpiNsGetType (Info->RegionNode);
462 if (Type != ACPI_TYPE_REGION)
463 {
464 ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)",
466
468 }
469 }
470
471 /* Allocate a new field object */
472
473 ObjDesc = AcpiUtCreateInternalObject (Info->FieldType);
474 if (!ObjDesc)
475 {
477 }
478
479 /* Initialize areas of the object that are common to all fields */
480
481 ObjDesc->CommonField.Node = Info->FieldNode;
483 Info->FieldFlags, Info->Attribute,
484 Info->FieldBitPosition, Info->FieldBitLength);
485 if (ACPI_FAILURE (Status))
486 {
487 AcpiUtDeleteObjectDesc (ObjDesc);
489 }
490
491 /* Initialize areas of the object that are specific to the field type */
492
493 switch (Info->FieldType)
494 {
496
497 ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode);
498
499 /* Fields specific to GenericSerialBus fields */
500
501 ObjDesc->Field.AccessLength = Info->AccessLength;
502
503 if (Info->ConnectionNode)
504 {
505 SecondDesc = Info->ConnectionNode->Object;
506 if (!(SecondDesc->Common.Flags & AOPOBJ_DATA_VALID))
507 {
508 Status = AcpiDsGetBufferArguments (SecondDesc);
509 if (ACPI_FAILURE (Status))
510 {
511 AcpiUtDeleteObjectDesc (ObjDesc);
513 }
514 }
515
516 ObjDesc->Field.ResourceBuffer =
517 SecondDesc->Buffer.Pointer;
518 ObjDesc->Field.ResourceLength =
519 (UINT16) SecondDesc->Buffer.Length;
520 }
521 else if (Info->ResourceBuffer)
522 {
523 ObjDesc->Field.ResourceBuffer = Info->ResourceBuffer;
524 ObjDesc->Field.ResourceLength = Info->ResourceLength;
525 }
526
527 ObjDesc->Field.PinNumberIndex = Info->PinNumberIndex;
528
529 /* Allow full data read from EC address space */
530
531 if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
532 (ObjDesc->CommonField.BitLength > 8))
533 {
534 AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES (
535 ObjDesc->CommonField.BitLength);
536
537 /* Maximum byte width supported is 255 */
538
539 if (AccessByteWidth < 256)
540 {
541 ObjDesc->CommonField.AccessByteWidth =
542 (UINT8) AccessByteWidth;
543 }
544 }
545
547 "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n",
548 ObjDesc->Field.StartFieldBitOffset,
549 ObjDesc->Field.BaseByteOffset,
550 ObjDesc->Field.AccessByteWidth,
551 ObjDesc->Field.RegionObj));
552 break;
553
555
556 ObjDesc->BankField.Value = Info->BankValue;
557 ObjDesc->BankField.RegionObj =
558 AcpiNsGetAttachedObject (Info->RegionNode);
559 ObjDesc->BankField.BankObj =
560 AcpiNsGetAttachedObject (Info->RegisterNode);
561
562 /* An additional reference for the attached objects */
563
566
568 "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n",
569 ObjDesc->BankField.StartFieldBitOffset,
570 ObjDesc->BankField.BaseByteOffset,
571 ObjDesc->Field.AccessByteWidth,
572 ObjDesc->BankField.RegionObj,
573 ObjDesc->BankField.BankObj));
574
575 /*
576 * Remember location in AML stream of the field unit
577 * opcode and operands -- since the BankValue
578 * operands must be evaluated.
579 */
580 SecondDesc = ObjDesc->Common.NextObject;
582 Info->DataRegisterNode)->Named.Data;
584 Info->DataRegisterNode)->Named.Length;
585
586 break;
587
589
590 /* Get the Index and Data registers */
591
592 ObjDesc->IndexField.IndexObj =
593 AcpiNsGetAttachedObject (Info->RegisterNode);
594 ObjDesc->IndexField.DataObj =
595 AcpiNsGetAttachedObject (Info->DataRegisterNode);
596
597 if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj)
598 {
599 ACPI_ERROR ((AE_INFO, "Null Index Object during field prep"));
600 AcpiUtDeleteObjectDesc (ObjDesc);
602 }
603
604 /* An additional reference for the attached objects */
605
608
609 /*
610 * April 2006: Changed to match MS behavior
611 *
612 * The value written to the Index register is the byte offset of the
613 * target field in units of the granularity of the IndexField
614 *
615 * Previously, the value was calculated as an index in terms of the
616 * width of the Data register, as below:
617 *
618 * ObjDesc->IndexField.Value = (UINT32)
619 * (Info->FieldBitPosition / ACPI_MUL_8 (
620 * ObjDesc->Field.AccessByteWidth));
621 *
622 * February 2006: Tried value as a byte offset:
623 * ObjDesc->IndexField.Value = (UINT32)
624 * ACPI_DIV_8 (Info->FieldBitPosition);
625 */
626 ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN (
627 ACPI_DIV_8 (Info->FieldBitPosition),
628 ObjDesc->IndexField.AccessByteWidth);
629
631 "IndexField: BitOff %X, Off %X, Value %X, "
632 "Gran %X, Index %p, Data %p\n",
633 ObjDesc->IndexField.StartFieldBitOffset,
634 ObjDesc->IndexField.BaseByteOffset,
635 ObjDesc->IndexField.Value,
636 ObjDesc->Field.AccessByteWidth,
637 ObjDesc->IndexField.IndexObj,
638 ObjDesc->IndexField.DataObj));
639 break;
640
641 default:
642
643 /* No other types should get here */
644
645 break;
646 }
647
648 /*
649 * Store the constructed descriptor (ObjDesc) into the parent Node,
650 * preserving the current type of that NamedObj.
651 */
653 Info->FieldNode, ObjDesc, AcpiNsGetType (Info->FieldNode));
654
656 "Set NamedObj %p [%4.4s], ObjDesc %p\n",
657 Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc));
658
659 /* Remove local reference to the object */
660
661 AcpiUtRemoveReference (ObjDesc);
663}
unsigned short UINT16
Type
Definition: Type.h:7
#define AE_AML_NO_OPERAND
Definition: acexcep.h:181
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_AML_INTERNAL
Definition: acexcep.h:194
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define AE_AML_OPERAND_TYPE
Definition: acexcep.h:182
#define ACPI_ROUND_BITS_UP_TO_BYTES(a)
Definition: acmacros.h:256
ACPI_OPERAND_OBJECT * AcpiNsGetAttachedObject(ACPI_NAMESPACE_NODE *Node)
Definition: nsobject.c:308
ACPI_OBJECT_TYPE AcpiNsGetType(ACPI_NAMESPACE_NODE *Node)
Definition: nsutils.c:120
ACPI_STATUS AcpiNsAttachObject(ACPI_NAMESPACE_NODE *Node, ACPI_OPERAND_OBJECT *Object, ACPI_OBJECT_TYPE Type)
Definition: nsobject.c:76
#define AOPOBJ_DATA_VALID
Definition: acobject.h:96
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_DB_BFIELD
Definition: acoutput.h:168
#define ACPI_ADR_SPACE_EC
Definition: actypes.h:864
#define ACPI_TYPE_LOCAL_BANK_FIELD
Definition: actypes.h:717
#define ACPI_TYPE_REGION
Definition: actypes.h:697
#define ACPI_TYPE_LOCAL_REGION_FIELD
Definition: actypes.h:716
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_CAST_PTR(t, p)
Definition: actypes.h:544
#define ACPI_TYPE_LOCAL_INDEX_FIELD
Definition: actypes.h:718
#define AcpiUtCreateInternalObject(t)
Definition: acutils.h:681
const char * AcpiUtGetTypeName(ACPI_OBJECT_TYPE Type)
Definition: utdecode.c:250
const char * AcpiUtGetNodeName(void *Object)
Definition: utdecode.c:306
void AcpiUtRemoveReference(ACPI_OPERAND_OBJECT *Object)
Definition: utdelete.c:790
void AcpiUtDeleteObjectDesc(ACPI_OPERAND_OBJECT *Object)
Definition: utobject.c:473
void AcpiUtAddReference(ACPI_OPERAND_OBJECT *Object)
Definition: utdelete.c:752
#define NULL
Definition: types.h:112
ACPI_STATUS AcpiDsGetBufferArguments(ACPI_OPERAND_OBJECT *ObjDesc)
Definition: dsargs.c:294
ACPI_STATUS AcpiExPrepCommonFieldObject(ACPI_OPERAND_OBJECT *ObjDesc, UINT8 FieldFlags, UINT8 FieldAttribute, UINT32 FieldBitPosition, UINT32 FieldBitLength)
Definition: exprep.c:347
Status
Definition: gdiplustypes.h:25
ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object * RegionObj
Definition: acobject.h:358
union acpi_operand_object * BankObj
Definition: acobject.h:359
UINT32 AmlLength
Definition: acobject.h:485
UINT8 * AmlStart
Definition: acobject.h:484
ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO union acpi_operand_object * IndexObj
Definition: acobject.h:373
union acpi_operand_object * DataObj
Definition: acobject.h:374
ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO UINT16 ResourceLength
Definition: acobject.h:345
union acpi_operand_object * RegionObj
Definition: acobject.h:346
ACPI_OBJECT_COMMON_HEADER UINT8 SpaceId
Definition: acobject.h:202
ACPI_OBJECT_REGION_FIELD Field
Definition: acobject.h:534
ACPI_OBJECT_BANK_FIELD BankField
Definition: acobject.h:536
ACPI_OBJECT_REGION Region
Definition: acobject.h:527
ACPI_OBJECT_EXTRA Extra
Definition: acobject.h:541
ACPI_OBJECT_INDEX_FIELD IndexField
Definition: acobject.h:537
ACPI_OBJECT_BUFFER Buffer
Definition: acobject.h:522
_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 AcpiDsGetFieldNames().