1 /******************************************************************************
3 * Module Name: aslrestype2 - Miscellaneous Large resource descriptors
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include <contrib/dev/acpica/compiler/aslcompiler.h>
46 #include "aslcompiler.y.h"
47 #include <contrib/dev/acpica/include/amlcode.h>
49 #define _COMPONENT ACPI_COMPILER
50 ACPI_MODULE_NAME ("aslrestype2")
53 * This module contains miscellaneous large resource descriptors:
60 /*******************************************************************************
62 * FUNCTION: RsDoGeneralRegisterDescriptor
64 * PARAMETERS: Op - Parent resource descriptor parse node
65 * CurrentByteOffset - Offset into the resource template AML
66 * buffer (to track references to the desc)
68 * RETURN: Completed resource node
70 * DESCRIPTION: Construct a long "Register" descriptor
72 ******************************************************************************/
75 RsDoGeneralRegisterDescriptor (
76 ACPI_PARSE_OBJECT *Op,
77 UINT32 CurrentByteOffset)
79 AML_RESOURCE *Descriptor;
80 ACPI_PARSE_OBJECT *InitializerOp;
81 ASL_RESOURCE_NODE *Rnode;
85 InitializerOp = Op->Asl.Child;
86 Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_GENERIC_REGISTER));
88 Descriptor = Rnode->Buffer;
89 Descriptor->GenericReg.DescriptorType = ACPI_RESOURCE_NAME_GENERIC_REGISTER;
90 Descriptor->GenericReg.ResourceLength = 12;
92 /* Process all child initialization nodes */
94 for (i = 0; InitializerOp; i++)
98 case 0: /* Address space */
100 Descriptor->GenericReg.AddressSpaceId = (UINT8) InitializerOp->Asl.Value.Integer;
101 RsCreateByteField (InitializerOp, ACPI_RESTAG_ADDRESSSPACE,
102 CurrentByteOffset + ASL_RESDESC_OFFSET (GenericReg.AddressSpaceId));
105 case 1: /* Register Bit Width */
107 Descriptor->GenericReg.BitWidth = (UINT8) InitializerOp->Asl.Value.Integer;
108 RsCreateByteField (InitializerOp, ACPI_RESTAG_REGISTERBITWIDTH,
109 CurrentByteOffset + ASL_RESDESC_OFFSET (GenericReg.BitWidth));
112 case 2: /* Register Bit Offset */
114 Descriptor->GenericReg.BitOffset = (UINT8) InitializerOp->Asl.Value.Integer;
115 RsCreateByteField (InitializerOp, ACPI_RESTAG_REGISTERBITOFFSET,
116 CurrentByteOffset + ASL_RESDESC_OFFSET (GenericReg.BitOffset));
119 case 3: /* Register Address */
121 Descriptor->GenericReg.Address = InitializerOp->Asl.Value.Integer;
122 RsCreateQwordField (InitializerOp, ACPI_RESTAG_ADDRESS,
123 CurrentByteOffset + ASL_RESDESC_OFFSET (GenericReg.Address));
126 case 4: /* Access Size (ACPI 3.0) */
128 Descriptor->GenericReg.AccessSize = (UINT8) InitializerOp->Asl.Value.Integer;
129 RsCreateByteField (InitializerOp, ACPI_RESTAG_ACCESSSIZE,
130 CurrentByteOffset + ASL_RESDESC_OFFSET (GenericReg.AccessSize));
132 if (Descriptor->GenericReg.AccessSize > AML_FIELD_ACCESS_QWORD)
134 AslError (ASL_ERROR, ASL_MSG_INVALID_ACCESS_SIZE,
135 InitializerOp, NULL);
139 case 5: /* ResourceTag (ACPI 3.0b) */
141 UtAttachNamepathToOwner (Op, InitializerOp);
146 AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL);
150 InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
156 /*******************************************************************************
158 * FUNCTION: RsDoInterruptDescriptor
160 * PARAMETERS: Op - Parent resource descriptor parse node
161 * CurrentByteOffset - Offset into the resource template AML
162 * buffer (to track references to the desc)
164 * RETURN: Completed resource node
166 * DESCRIPTION: Construct a long "Interrupt" descriptor
168 ******************************************************************************/
171 RsDoInterruptDescriptor (
172 ACPI_PARSE_OBJECT *Op,
173 UINT32 CurrentByteOffset)
175 AML_RESOURCE *Descriptor;
176 AML_RESOURCE *Rover = NULL;
177 ACPI_PARSE_OBJECT *InitializerOp;
178 ASL_RESOURCE_NODE *Rnode;
179 UINT16 StringLength = 0;
180 UINT32 OptionIndex = 0;
182 BOOLEAN HasResSourceIndex = FALSE;
183 UINT8 ResSourceIndex = 0;
184 UINT8 *ResSourceString = NULL;
187 InitializerOp = Op->Asl.Child;
188 StringLength = RsGetStringDataLength (InitializerOp);
190 /* Count the interrupt numbers */
192 for (i = 0; InitializerOp; i++)
194 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
199 InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
202 * ResourceSourceIndex was specified, always make room for
203 * it, even if the ResourceSource was omitted.
214 InitializerOp = Op->Asl.Child;
215 Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_EXTENDED_IRQ) +
216 1 + OptionIndex + StringLength);
218 Descriptor = Rnode->Buffer;
219 Descriptor->ExtendedIrq.DescriptorType = ACPI_RESOURCE_NAME_EXTENDED_IRQ;
222 * Initial descriptor length -- may be enlarged if there are
223 * optional fields present
225 Descriptor->ExtendedIrq.ResourceLength = 2; /* Flags and table length byte */
226 Descriptor->ExtendedIrq.InterruptCount = 0;
228 Rover = ACPI_CAST_PTR (AML_RESOURCE,
229 (&(Descriptor->ExtendedIrq.Interrupts[0])));
231 /* Process all child initialization nodes */
233 for (i = 0; InitializerOp; i++)
237 case 0: /* Resource Usage (Default: consumer (1) */
239 RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 0, 1);
242 case 1: /* Interrupt Type (or Mode - edge/level) */
244 RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 1, 0);
245 RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTTYPE,
246 CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 1);
249 case 2: /* Interrupt Level (or Polarity - Active high/low) */
251 RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 2, 0);
252 RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTLEVEL,
253 CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 2);
256 case 3: /* Share Type - Default: exclusive (0) */
258 RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 3, 0);
259 RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTSHARE,
260 CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 3);
263 case 4: /* ResSourceIndex [Optional Field - BYTE] */
265 if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
267 HasResSourceIndex = TRUE;
268 ResSourceIndex = (UINT8) InitializerOp->Asl.Value.Integer;
272 case 5: /* ResSource [Optional Field - STRING] */
274 if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
275 (InitializerOp->Asl.Value.String))
279 ResSourceString = (UINT8 *) InitializerOp->Asl.Value.String;
282 /* ResourceSourceIndex must also be valid */
284 if (!HasResSourceIndex)
286 AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
287 InitializerOp, NULL);
293 * Not a valid ResourceSource, ResourceSourceIndex must also
296 else if (HasResSourceIndex)
298 AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
299 InitializerOp, NULL);
304 case 6: /* ResourceTag */
306 UtAttachNamepathToOwner (Op, InitializerOp);
311 * Interrupt Numbers come through here, repeatedly
314 /* Maximum 255 interrupts allowed for this descriptor */
316 if (Descriptor->ExtendedIrq.InterruptCount == 255)
318 AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_LIST,
319 InitializerOp, NULL);
323 /* Each interrupt number must be a 32-bit value */
325 if (InitializerOp->Asl.Value.Integer > ACPI_UINT32_MAX)
327 AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_NUMBER,
328 InitializerOp, NULL);
331 /* Save the integer and move pointer to the next one */
333 Rover->DwordItem = (UINT32) InitializerOp->Asl.Value.Integer;
334 Rover = ACPI_ADD_PTR (AML_RESOURCE, &(Rover->DwordItem), 4);
335 Descriptor->ExtendedIrq.InterruptCount++;
336 Descriptor->ExtendedIrq.ResourceLength += 4;
338 /* Case 7: First interrupt number in list */
342 if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
344 /* Must be at least one interrupt */
346 AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_LIST_MIN,
347 InitializerOp, NULL);
350 /* Check now for duplicates in list */
352 RsCheckListForDuplicates (InitializerOp);
354 /* Create a named field at the start of the list */
356 RsCreateDwordField (InitializerOp, ACPI_RESTAG_INTERRUPT,
358 ASL_RESDESC_OFFSET (ExtendedIrq.Interrupts[0]));
362 InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
366 /* Add optional ResSourceIndex if present */
368 if (HasResSourceIndex)
370 Rover->ByteItem = ResSourceIndex;
371 Rover = ACPI_ADD_PTR (AML_RESOURCE, &(Rover->ByteItem), 1);
372 Descriptor->ExtendedIrq.ResourceLength += 1;
375 /* Add optional ResSource string if present */
377 if (StringLength && ResSourceString)
380 strcpy ((char *) Rover, (char *) ResSourceString);
381 Rover = ACPI_ADD_PTR (
382 AML_RESOURCE, &(Rover->ByteItem), StringLength);
384 Descriptor->ExtendedIrq.ResourceLength = (UINT16)
385 (Descriptor->ExtendedIrq.ResourceLength + StringLength);
388 Rnode->BufferLength = (ASL_RESDESC_OFFSET (ExtendedIrq.Interrupts[0]) -
389 ASL_RESDESC_OFFSET (ExtendedIrq.DescriptorType))
390 + OptionIndex + StringLength;
395 /*******************************************************************************
397 * FUNCTION: RsDoVendorLargeDescriptor
399 * PARAMETERS: Op - Parent resource descriptor parse node
400 * CurrentByteOffset - Offset into the resource template AML
401 * buffer (to track references to the desc)
403 * RETURN: Completed resource node
405 * DESCRIPTION: Construct a long "VendorLong" descriptor
407 ******************************************************************************/
410 RsDoVendorLargeDescriptor (
411 ACPI_PARSE_OBJECT *Op,
412 UINT32 CurrentByteOffset)
414 AML_RESOURCE *Descriptor;
415 ACPI_PARSE_OBJECT *InitializerOp;
416 ASL_RESOURCE_NODE *Rnode;
421 /* Count the number of data bytes */
423 InitializerOp = Op->Asl.Child;
424 InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
426 for (i = 0; InitializerOp; i++)
428 if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
432 InitializerOp = InitializerOp->Asl.Next;
435 InitializerOp = Op->Asl.Child;
436 InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
437 Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_VENDOR_LARGE) + i);
439 Descriptor = Rnode->Buffer;
440 Descriptor->VendorLarge.DescriptorType = ACPI_RESOURCE_NAME_VENDOR_LARGE;
441 Descriptor->VendorLarge.ResourceLength = (UINT16) i;
443 /* Point to end-of-descriptor for vendor data */
445 VendorData = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_LARGE_HEADER);
447 /* Process all child initialization nodes */
449 for (i = 0; InitializerOp; i++)
451 if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
456 VendorData[i] = (UINT8) InitializerOp->Asl.Value.Integer;
457 InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);