static UINT16 RsGetBufferDataLength ( ACPI_PARSE_OBJECT *InitializerOp) { UINT16 ExtraDataSize = 0; ACPI_PARSE_OBJECT *DataList; /* Find the byte-initializer list */ while (InitializerOp) { if (InitializerOp->Asl.ParseOpcode == PARSEOP_DATABUFFER) { /* First child is the optional length (ignore it here) */ DataList = InitializerOp->Asl.Child; DataList = ASL_GET_PEER_NODE (DataList); /* Count the data items (each one is a byte of data) */ while (DataList) { ExtraDataSize++; DataList = ASL_GET_PEER_NODE (DataList); } return (ExtraDataSize); } InitializerOp = ASL_GET_PEER_NODE (InitializerOp); } return (ExtraDataSize); }
void RsCheckListForDuplicates ( ACPI_PARSE_OBJECT *Op) { ACPI_PARSE_OBJECT *NextValueOp = Op; ACPI_PARSE_OBJECT *NextOp; UINT32 Value; if (!Op) { return; } /* Search list once for each value in the list */ while (NextValueOp) { Value = (UINT32) NextValueOp->Asl.Value.Integer; /* Compare this value to all remaining values in the list */ NextOp = ASL_GET_PEER_NODE (NextValueOp); while (NextOp) { if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) { /* Compare values */ if (Value == (UINT32) NextOp->Asl.Value.Integer) { /* Emit error only once per duplicate node */ if (!(NextOp->Asl.CompileFlags & NODE_IS_DUPLICATE)) { NextOp->Asl.CompileFlags |= NODE_IS_DUPLICATE; AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM, NextOp, NULL); } } } NextOp = ASL_GET_PEER_NODE (NextOp); } NextValueOp = ASL_GET_PEER_NODE (NextValueOp); } }
static UINT16 RsGetInterruptDataLength ( ACPI_PARSE_OBJECT *InitializerOp) { UINT16 InterruptLength; UINT32 i; /* Count the interrupt numbers */ InterruptLength = 0; for (i = 0; InitializerOp; i++) { InitializerOp = ASL_GET_PEER_NODE (InitializerOp); /* Interrupt list starts at offset 10 (Gpio descriptors) */ if (i >= 10) { InterruptLength += 2; } } return (InterruptLength); }
ACPI_PARSE_OBJECT * RsCompleteNodeAndGetNext ( ACPI_PARSE_OBJECT *Op) { /* Mark this node unused */ Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; /* Move on to the next peer node in the initializer list */ return (ASL_GET_PEER_NODE (Op)); }
UINT16 RsGetStringDataLength ( ACPI_PARSE_OBJECT *InitializerOp) { while (InitializerOp) { if (InitializerOp->Asl.ParseOpcode == PARSEOP_STRING_LITERAL) { return ((UINT16) (strlen (InitializerOp->Asl.Value.String) + 1)); } InitializerOp = ASL_GET_PEER_NODE (InitializerOp); } return 0; }
BOOLEAN AnLastStatementIsReturn ( ACPI_PARSE_OBJECT *Op) { ACPI_PARSE_OBJECT *Next; /* Check if last statement is a return */ Next = ASL_GET_CHILD_NODE (Op); while (Next) { if ((!Next->Asl.Next) && (Next->Asl.ParseOpcode == PARSEOP_RETURN)) { return (TRUE); } Next = ASL_GET_PEER_NODE (Next); } return (FALSE); }
static ACPI_STATUS LdLoadResourceElements ( ACPI_PARSE_OBJECT *Op, ACPI_WALK_STATE *WalkState) { ACPI_PARSE_OBJECT *InitializerOp = NULL; ACPI_NAMESPACE_NODE *Node; ACPI_STATUS Status; /* * Enter the resource name into the namespace. Name must not already exist. * This opens a scope, so later field names are guaranteed to be new/unique. */ Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath, ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND, WalkState, &Node); if (ACPI_FAILURE (Status)) { if (Status == AE_ALREADY_EXISTS) { /* Actual node causing the error was saved in ParentMethod */ AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod, Op->Asl.Namepath); return (AE_OK); } return (Status); } Node->Value = (UINT32) Op->Asl.Value.Integer; Node->Op = Op; Op->Asl.Node = Node; /* * Now enter the predefined fields, for easy lookup when referenced * by the source ASL */ InitializerOp = ASL_GET_CHILD_NODE (Op); while (InitializerOp) { if (InitializerOp->Asl.ExternalName) { Status = AcpiNsLookup (WalkState->ScopeInfo, InitializerOp->Asl.ExternalName, ACPI_TYPE_LOCAL_RESOURCE_FIELD, ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node); if (ACPI_FAILURE (Status)) { return (Status); } /* * Store the field offset and length in the namespace node * so it can be used when the field is referenced */ Node->Value = InitializerOp->Asl.Value.Tag.BitOffset; Node->Length = InitializerOp->Asl.Value.Tag.BitLength; InitializerOp->Asl.Node = Node; Node->Op = InitializerOp; } InitializerOp = ASL_GET_PEER_NODE (InitializerOp); } return (AE_OK); }
void RsDoResourceTemplate ( ACPI_PARSE_OBJECT *Op) { ACPI_PARSE_OBJECT *BufferLengthOp; ACPI_PARSE_OBJECT *BufferOp; ACPI_PARSE_OBJECT *DescriptorTypeOp; ACPI_PARSE_OBJECT *LastOp = NULL; UINT32 CurrentByteOffset = 0; ASL_RESOURCE_NODE HeadRnode; ASL_RESOURCE_NODE *PreviousRnode; ASL_RESOURCE_NODE *Rnode; UINT8 State; /* Mark parent as containing a resource template */ if (Op->Asl.Parent) { Op->Asl.Parent->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC; } /* ResourceTemplate Opcode is first (Op) */ /* Buffer Length node is first child */ BufferLengthOp = ASL_GET_CHILD_NODE (Op); /* Buffer Op is first peer */ BufferOp = ASL_GET_PEER_NODE (BufferLengthOp); /* First Descriptor type is next */ DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp); /* * Process all resource descriptors in the list * Note: It is assumed that the EndTag node has been automatically * inserted at the end of the template by the parser. */ State = ACPI_RSTATE_NORMAL; PreviousRnode = &HeadRnode; while (DescriptorTypeOp) { DescriptorTypeOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC; Rnode = RsDoOneResourceDescriptor (DescriptorTypeOp, CurrentByteOffset, &State); /* * Update current byte offset to indicate the number of bytes from the * start of the buffer. Buffer can include multiple descriptors, we * must keep track of the offset of not only each descriptor, but each * element (field) within each descriptor as well. */ CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode); /* Get the next descriptor in the list */ LastOp = DescriptorTypeOp; DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp); } if (State == ACPI_RSTATE_DEPENDENT_LIST) { if (LastOp) { LastOp = LastOp->Asl.Parent; } AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL); } /* * Transform the nodes into the following * * Op -> AML_BUFFER_OP * First Child -> BufferLength * Second Child -> Descriptor Buffer (raw byte data) */ Op->Asl.ParseOpcode = PARSEOP_BUFFER; Op->Asl.AmlOpcode = AML_BUFFER_OP; Op->Asl.CompileFlags = NODE_AML_PACKAGE | NODE_IS_RESOURCE_DESC; BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER; BufferLengthOp->Asl.Value.Integer = CurrentByteOffset; (void) OpcSetOptimalIntegerSize (BufferLengthOp); BufferOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; BufferOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN; BufferOp->Asl.AmlOpcodeLength = 0; BufferOp->Asl.AmlLength = CurrentByteOffset; BufferOp->Asl.Value.Buffer = (UINT8 *) HeadRnode.Next; BufferOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DATA; return; }
static void OpnDoBuffer ( ACPI_PARSE_OBJECT *Op) { ACPI_PARSE_OBJECT *InitializerOp; ACPI_PARSE_OBJECT *BufferLengthOp; /* Optional arguments for this opcode with defaults */ UINT32 BufferLength = 0; /* Opcode and package length first */ /* Buffer Length is next, followed by the initializer list */ BufferLengthOp = Op->Asl.Child; InitializerOp = BufferLengthOp->Asl.Next; /* * If the BufferLength is not an INTEGER or was not specified in the ASL * (DEFAULT_ARG), it is a TermArg that is * evaluated at run-time, and we are therefore finished. */ if ((BufferLengthOp->Asl.ParseOpcode != PARSEOP_INTEGER) && (BufferLengthOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)) { return; } /* * We want to count the number of items in the initializer list, because if * it is larger than the buffer length, we will define the buffer size * to be the size of the initializer list (as per the ACPI Specification) */ switch (InitializerOp->Asl.ParseOpcode) { case PARSEOP_INTEGER: case PARSEOP_BYTECONST: case PARSEOP_WORDCONST: case PARSEOP_DWORDCONST: /* The peer list contains the byte list (if any...) */ while (InitializerOp) { /* For buffers, this is a list of raw bytes */ InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE; InitializerOp->Asl.AmlLength = 1; InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; BufferLength++; InitializerOp = ASL_GET_PEER_NODE (InitializerOp); } break; case PARSEOP_STRING_LITERAL: /* * Only one initializer, the string. Buffer must be big enough to hold * the string plus the null termination byte */ BufferLength = strlen (InitializerOp->Asl.Value.String) + 1; InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER; InitializerOp->Asl.AmlLength = BufferLength; InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; break; case PARSEOP_RAW_DATA: /* Buffer nodes are already initialized (e.g. Unicode operator) */ return; case PARSEOP_DEFAULT_ARG: break; default: AslError (ASL_ERROR, ASL_MSG_INVALID_OPERAND, InitializerOp, "Unknown buffer initializer opcode"); printf ("Unknown buffer initializer opcode [%s]\n", UtGetOpName (InitializerOp->Asl.ParseOpcode)); return; } /* Check if initializer list is longer than the buffer length */ if (BufferLengthOp->Asl.Value.Integer > BufferLength) { BufferLength = (UINT32) BufferLengthOp->Asl.Value.Integer; } if (!BufferLength) { /* No length AND no items -- issue notice */ AslError (ASL_REMARK, ASL_MSG_BUFFER_LENGTH, BufferLengthOp, NULL); /* But go ahead and put the buffer length of zero into the AML */ } /* * Just set the buffer size node to be the buffer length, regardless * of whether it was previously an integer or a default_arg placeholder */ BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER; BufferLengthOp->Asl.AmlOpcode = AML_DWORD_OP; BufferLengthOp->Asl.Value.Integer = BufferLength; (void) OpcSetOptimalIntegerSize (BufferLengthOp); /* Remaining nodes are handled via the tree walk */ }
ASL_RESOURCE_NODE * RsDoInterruptDescriptor ( ASL_RESOURCE_INFO *Info) { AML_RESOURCE *Descriptor; AML_RESOURCE *Rover = NULL; ACPI_PARSE_OBJECT *InitializerOp; ASL_RESOURCE_NODE *Rnode; UINT16 StringLength = 0; UINT32 OptionIndex = 0; UINT32 CurrentByteOffset; UINT32 i; BOOLEAN HasResSourceIndex = FALSE; UINT8 ResSourceIndex = 0; UINT8 *ResSourceString = NULL; InitializerOp = Info->DescriptorTypeOp->Asl.Child; CurrentByteOffset = Info->CurrentByteOffset; StringLength = RsGetStringDataLength (InitializerOp); /* Count the interrupt numbers */ for (i = 0; InitializerOp; i++) { InitializerOp = ASL_GET_PEER_NODE (InitializerOp); if (i <= 6) { if (i == 3 && InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) { /* * ResourceSourceIndex was specified, always make room for * it, even if the ResourceSource was omitted. */ OptionIndex++; } continue; } OptionIndex += 4; } InitializerOp = Info->DescriptorTypeOp->Asl.Child; Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_EXTENDED_IRQ) + 1 + OptionIndex + StringLength); Descriptor = Rnode->Buffer; Descriptor->ExtendedIrq.DescriptorType = ACPI_RESOURCE_NAME_EXTENDED_IRQ; /* * Initial descriptor length -- may be enlarged if there are * optional fields present */ Descriptor->ExtendedIrq.ResourceLength = 2; /* Flags and table length byte */ Descriptor->ExtendedIrq.InterruptCount = 0; Rover = ACPI_CAST_PTR (AML_RESOURCE, (&(Descriptor->ExtendedIrq.Interrupts[0]))); /* Process all child initialization nodes */ for (i = 0; InitializerOp; i++) { switch (i) { case 0: /* Resource Usage (Default: consumer (1) */ RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 0, 1); break; case 1: /* Interrupt Type (or Mode - edge/level) */ RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 1, 0); RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTTYPE, CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 1); break; case 2: /* Interrupt Level (or Polarity - Active high/low) */ RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 2, 0); RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTLEVEL, CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 2); break; case 3: /* Share Type - Default: exclusive (0) */ RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 3, 0); RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTSHARE, CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 3); break; case 4: /* ResSourceIndex [Optional Field - BYTE] */ if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) { HasResSourceIndex = TRUE; ResSourceIndex = (UINT8) InitializerOp->Asl.Value.Integer; } break; case 5: /* ResSource [Optional Field - STRING] */ if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && (InitializerOp->Asl.Value.String)) { if (StringLength) { ResSourceString = (UINT8 *) InitializerOp->Asl.Value.String; } /* ResourceSourceIndex must also be valid */ if (!HasResSourceIndex) { AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX, InitializerOp, NULL); } } #if 0 /* * Not a valid ResourceSource, ResourceSourceIndex must also * be invalid */ else if (HasResSourceIndex) { AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE, InitializerOp, NULL); } #endif break; case 6: /* ResourceTag */ UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp); break; default: /* * Interrupt Numbers come through here, repeatedly */ /* Maximum 255 interrupts allowed for this descriptor */ if (Descriptor->ExtendedIrq.InterruptCount == 255) { AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_LIST, InitializerOp, NULL); return (Rnode); } /* Each interrupt number must be a 32-bit value */ if (InitializerOp->Asl.Value.Integer > ACPI_UINT32_MAX) { AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_NUMBER, InitializerOp, NULL); } /* Save the integer and move pointer to the next one */ Rover->DwordItem = (UINT32) InitializerOp->Asl.Value.Integer; Rover = ACPI_ADD_PTR (AML_RESOURCE, &(Rover->DwordItem), 4); Descriptor->ExtendedIrq.InterruptCount++; Descriptor->ExtendedIrq.ResourceLength += 4; /* Case 7: First interrupt number in list */ if (i == 7) { if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) { /* Must be at least one interrupt */ AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_LIST_MIN, InitializerOp, NULL); } /* Check now for duplicates in list */ RsCheckListForDuplicates (InitializerOp); /* Create a named field at the start of the list */ RsCreateDwordField (InitializerOp, ACPI_RESTAG_INTERRUPT, CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Interrupts[0])); } } InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); } /* Add optional ResSourceIndex if present */ if (HasResSourceIndex) { Rover->ByteItem = ResSourceIndex; Rover = ACPI_ADD_PTR (AML_RESOURCE, &(Rover->ByteItem), 1); Descriptor->ExtendedIrq.ResourceLength += 1; } /* Add optional ResSource string if present */ if (StringLength && ResSourceString) { strcpy ((char *) Rover, (char *) ResSourceString); Rover = ACPI_ADD_PTR ( AML_RESOURCE, &(Rover->ByteItem), StringLength); Descriptor->ExtendedIrq.ResourceLength = (UINT16) (Descriptor->ExtendedIrq.ResourceLength + StringLength); } Rnode->BufferLength = (ASL_RESDESC_OFFSET (ExtendedIrq.Interrupts[0]) - ASL_RESDESC_OFFSET (ExtendedIrq.DescriptorType)) + OptionIndex + StringLength; return (Rnode); }
void RsDoResourceTemplate ( ACPI_PARSE_OBJECT *Op) { ACPI_PARSE_OBJECT *BufferLengthOp; ACPI_PARSE_OBJECT *BufferOp; ACPI_PARSE_OBJECT *DescriptorTypeOp; ACPI_PARSE_OBJECT *LastOp = NULL; ASL_RESOURCE_DESC *Descriptor; UINT32 CurrentByteOffset = 0; ASL_RESOURCE_NODE HeadRnode; ASL_RESOURCE_NODE *PreviousRnode; ASL_RESOURCE_NODE *Rnode; UINT8 State; /* ResourceTemplate Opcode is first (Op) */ /* Buffer Length node is first child */ BufferLengthOp = ASL_GET_CHILD_NODE (Op); /* Buffer Op is first peer */ BufferOp = ASL_GET_PEER_NODE (BufferLengthOp); /* First Descriptor type is next */ DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp); /* Process all resource descriptors in the list */ State = ACPI_RSTATE_NORMAL; PreviousRnode = &HeadRnode; while (DescriptorTypeOp) { Rnode = RsDoOneResourceDescriptor (DescriptorTypeOp, CurrentByteOffset, &State); /* * Update current byte offset to indicate the number of bytes from the * start of the buffer. Buffer can include multiple descriptors, we * must keep track of the offset of not only each descriptor, but each * element (field) within each descriptor as well. */ CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode); /* Get the next descriptor in the list */ LastOp = DescriptorTypeOp; DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp); } if (State == ACPI_RSTATE_DEPENDENT_LIST) { if (LastOp) { LastOp = LastOp->Asl.Parent; } AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL); } /* * Insert the EndTag descriptor after all other descriptors have been processed */ Rnode = RsAllocateResourceNode (sizeof (ASL_END_TAG_DESC)); Descriptor = Rnode->Buffer; Descriptor->Et.DescriptorType = ACPI_RDESC_TYPE_END_TAG | ASL_RDESC_END_TAG_SIZE; Descriptor->Et.Checksum = 0; CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode); /* * Transform the nodes into the following * * Op -> AML_BUFFER_OP * First Child -> BufferLength * Second Child -> Descriptor Buffer (raw byte data) */ Op->Asl.ParseOpcode = PARSEOP_BUFFER; Op->Asl.AmlOpcode = AML_BUFFER_OP; Op->Asl.CompileFlags = NODE_AML_PACKAGE; BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER; BufferLengthOp->Asl.Value.Integer = CurrentByteOffset; (void) OpcSetOptimalIntegerSize (BufferLengthOp); BufferOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; BufferOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN; BufferOp->Asl.AmlOpcodeLength = 0; BufferOp->Asl.AmlLength = CurrentByteOffset; BufferOp->Asl.Value.Buffer = (UINT8 *) HeadRnode.Next; return; }