1 /*******************************************************************************
3 * Module Name: rsmisc - Miscellaneous 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.
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acresrc.h>
50 #define _COMPONENT ACPI_RESOURCES
51 ACPI_MODULE_NAME ("rsmisc")
54 #define INIT_RESOURCE_TYPE(i) i->ResourceOffset
55 #define INIT_RESOURCE_LENGTH(i) i->AmlOffset
56 #define INIT_TABLE_LENGTH(i) i->Value
58 #define COMPARE_OPCODE(i) i->ResourceOffset
59 #define COMPARE_TARGET(i) i->AmlOffset
60 #define COMPARE_VALUE(i) i->Value
63 /*******************************************************************************
65 * FUNCTION: AcpiRsConvertAmlToResource
67 * PARAMETERS: Resource - Pointer to the resource descriptor
68 * Aml - Where the AML descriptor is returned
69 * Info - Pointer to appropriate conversion table
73 * DESCRIPTION: Convert an external AML resource descriptor to the corresponding
74 * internal resource descriptor
76 ******************************************************************************/
79 AcpiRsConvertAmlToResource (
80 ACPI_RESOURCE *Resource,
82 ACPI_RSCONVERT_INFO *Info)
84 ACPI_RS_LENGTH AmlResourceLength;
89 UINT8 FlagsMode = FALSE;
94 ACPI_FUNCTION_TRACE (RsConvertAmlToResource);
99 return_ACPI_STATUS (AE_BAD_PARAMETER);
102 if (((ACPI_SIZE) Resource) & 0x3)
104 /* Each internal resource struct is expected to be 32-bit aligned */
106 ACPI_WARNING ((AE_INFO,
107 "Misaligned resource pointer (get): %p Type 0x%2.2X Length %u",
108 Resource, Resource->Type, Resource->Length));
111 /* Extract the resource Length field (does not include header length) */
113 AmlResourceLength = AcpiUtGetResourceLength (Aml);
116 * First table entry must be ACPI_RSC_INITxxx and must contain the
117 * table length (# of table entries)
119 Count = INIT_TABLE_LENGTH (Info);
123 * Source is the external AML byte stream buffer,
124 * destination is the internal resource descriptor
126 Source = ACPI_ADD_PTR (void, Aml, Info->AmlOffset);
127 Destination = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset);
129 switch (Info->Opcode)
131 case ACPI_RSC_INITGET:
133 * Get the resource type and the initial (minimum) length
135 ACPI_MEMSET (Resource, 0, INIT_RESOURCE_LENGTH (Info));
136 Resource->Type = INIT_RESOURCE_TYPE (Info);
137 Resource->Length = INIT_RESOURCE_LENGTH (Info);
140 case ACPI_RSC_INITSET:
143 case ACPI_RSC_FLAGINIT:
148 case ACPI_RSC_1BITFLAG:
150 * Mask and shift the flag bit
152 ACPI_SET8 (Destination,
153 ((ACPI_GET8 (Source) >> Info->Value) & 0x01));
156 case ACPI_RSC_2BITFLAG:
158 * Mask and shift the flag bits
160 ACPI_SET8 (Destination,
161 ((ACPI_GET8 (Source) >> Info->Value) & 0x03));
164 case ACPI_RSC_3BITFLAG:
166 * Mask and shift the flag bits
168 ACPI_SET8 (Destination,
169 ((ACPI_GET8 (Source) >> Info->Value) & 0x07));
174 ItemCount = ACPI_GET8 (Source);
175 ACPI_SET8 (Destination, ItemCount);
177 Resource->Length = Resource->Length +
178 (Info->Value * (ItemCount - 1));
181 case ACPI_RSC_COUNT16:
183 ItemCount = AmlResourceLength;
184 ACPI_SET16 (Destination, ItemCount);
186 Resource->Length = Resource->Length +
187 (Info->Value * (ItemCount - 1));
190 case ACPI_RSC_COUNT_GPIO_PIN:
192 Target = ACPI_ADD_PTR (void, Aml, Info->Value);
193 ItemCount = ACPI_GET16 (Target) - ACPI_GET16 (Source);
195 Resource->Length = Resource->Length + ItemCount;
196 ItemCount = ItemCount / 2;
197 ACPI_SET16 (Destination, ItemCount);
200 case ACPI_RSC_COUNT_GPIO_VEN:
202 ItemCount = ACPI_GET8 (Source);
203 ACPI_SET8 (Destination, ItemCount);
205 Resource->Length = Resource->Length +
206 (Info->Value * ItemCount);
209 case ACPI_RSC_COUNT_GPIO_RES:
211 * Vendor data is optional (length/offset may both be zero)
212 * Examine vendor data length field first
214 Target = ACPI_ADD_PTR (void, Aml, (Info->Value + 2));
215 if (ACPI_GET16 (Target))
217 /* Use vendor offset to get resource source length */
219 Target = ACPI_ADD_PTR (void, Aml, Info->Value);
220 ItemCount = ACPI_GET16 (Target) - ACPI_GET16 (Source);
224 /* No vendor data to worry about */
226 ItemCount = Aml->LargeHeader.ResourceLength +
227 sizeof (AML_RESOURCE_LARGE_HEADER) -
231 Resource->Length = Resource->Length + ItemCount;
232 ACPI_SET16 (Destination, ItemCount);
235 case ACPI_RSC_COUNT_SERIAL_VEN:
237 ItemCount = ACPI_GET16 (Source) - Info->Value;
239 Resource->Length = Resource->Length + ItemCount;
240 ACPI_SET16 (Destination, ItemCount);
243 case ACPI_RSC_COUNT_SERIAL_RES:
245 ItemCount = (AmlResourceLength +
246 sizeof (AML_RESOURCE_LARGE_HEADER)) -
247 ACPI_GET16 (Source) - Info->Value;
249 Resource->Length = Resource->Length + ItemCount;
250 ACPI_SET16 (Destination, ItemCount);
253 case ACPI_RSC_LENGTH:
255 Resource->Length = Resource->Length + Info->Value;
259 case ACPI_RSC_MOVE16:
260 case ACPI_RSC_MOVE32:
261 case ACPI_RSC_MOVE64:
263 * Raw data move. Use the Info value field unless ItemCount has
264 * been previously initialized via a COUNT opcode
268 ItemCount = Info->Value;
270 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
273 case ACPI_RSC_MOVE_GPIO_PIN:
275 /* Generate and set the PIN data pointer */
277 Target = (char *) ACPI_ADD_PTR (void, Resource,
278 (Resource->Length - ItemCount * 2));
279 *(UINT16 **) Destination = ACPI_CAST_PTR (UINT16, Target);
281 /* Copy the PIN data */
283 Source = ACPI_ADD_PTR (void, Aml, ACPI_GET16 (Source));
284 AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
287 case ACPI_RSC_MOVE_GPIO_RES:
289 /* Generate and set the ResourceSource string pointer */
291 Target = (char *) ACPI_ADD_PTR (void, Resource,
292 (Resource->Length - ItemCount));
293 *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
295 /* Copy the ResourceSource string */
297 Source = ACPI_ADD_PTR (void, Aml, ACPI_GET16 (Source));
298 AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
301 case ACPI_RSC_MOVE_SERIAL_VEN:
303 /* Generate and set the Vendor Data pointer */
305 Target = (char *) ACPI_ADD_PTR (void, Resource,
306 (Resource->Length - ItemCount));
307 *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
309 /* Copy the Vendor Data */
311 Source = ACPI_ADD_PTR (void, Aml, Info->Value);
312 AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
315 case ACPI_RSC_MOVE_SERIAL_RES:
317 /* Generate and set the ResourceSource string pointer */
319 Target = (char *) ACPI_ADD_PTR (void, Resource,
320 (Resource->Length - ItemCount));
321 *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
323 /* Copy the ResourceSource string */
325 Source = ACPI_ADD_PTR (void, Aml, (ACPI_GET16 (Source) + Info->Value));
326 AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
331 ACPI_MEMSET (Destination, Info->AmlOffset, Info->Value);
336 Target = ACPI_ADD_PTR (char, Resource, Info->Value);
337 ACPI_MEMCPY (Destination, Source, ACPI_GET16 (Target));
340 case ACPI_RSC_ADDRESS:
342 * Common handler for address descriptor flags
344 if (!AcpiRsGetAddressCommon (Resource, Aml))
346 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
350 case ACPI_RSC_SOURCE:
352 * Optional ResourceSource (Index and String)
355 AcpiRsGetResourceSource (AmlResourceLength, Info->Value,
356 Destination, Aml, NULL);
359 case ACPI_RSC_SOURCEX:
361 * Optional ResourceSource (Index and String). This is the more
362 * complicated case used by the Interrupt() macro
364 Target = ACPI_ADD_PTR (char, Resource,
365 Info->AmlOffset + (ItemCount * 4));
368 AcpiRsGetResourceSource (AmlResourceLength, (ACPI_RS_LENGTH)
369 (((ItemCount - 1) * sizeof (UINT32)) + Info->Value),
370 Destination, Aml, Target);
373 case ACPI_RSC_BITMASK:
375 * 8-bit encoded bitmask (DMA macro)
377 ItemCount = AcpiRsDecodeBitmask (ACPI_GET8 (Source), Destination);
380 Resource->Length += (ItemCount - 1);
383 Target = ACPI_ADD_PTR (char, Resource, Info->Value);
384 ACPI_SET8 (Target, ItemCount);
387 case ACPI_RSC_BITMASK16:
389 * 16-bit encoded bitmask (IRQ macro)
391 ACPI_MOVE_16_TO_16 (&Temp16, Source);
393 ItemCount = AcpiRsDecodeBitmask (Temp16, Destination);
396 Resource->Length += (ItemCount - 1);
399 Target = ACPI_ADD_PTR (char, Resource, Info->Value);
400 ACPI_SET8 (Target, ItemCount);
403 case ACPI_RSC_EXIT_NE:
405 * Control - Exit conversion if not equal
407 switch (Info->ResourceOffset)
409 case ACPI_RSC_COMPARE_AML_LENGTH:
411 if (AmlResourceLength != Info->Value)
417 case ACPI_RSC_COMPARE_VALUE:
419 if (ACPI_GET8 (Source) != Info->Value)
427 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode"));
428 return_ACPI_STATUS (AE_BAD_PARAMETER);
434 ACPI_ERROR ((AE_INFO, "Invalid conversion opcode"));
435 return_ACPI_STATUS (AE_BAD_PARAMETER);
445 /* Round the resource struct length up to the next boundary (32 or 64) */
447 Resource->Length = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (Resource->Length);
449 return_ACPI_STATUS (AE_OK);
453 /*******************************************************************************
455 * FUNCTION: AcpiRsConvertResourceToAml
457 * PARAMETERS: Resource - Pointer to the resource descriptor
458 * Aml - Where the AML descriptor is returned
459 * Info - Pointer to appropriate conversion table
463 * DESCRIPTION: Convert an internal resource descriptor to the corresponding
464 * external AML resource descriptor.
466 ******************************************************************************/
469 AcpiRsConvertResourceToAml (
470 ACPI_RESOURCE *Resource,
472 ACPI_RSCONVERT_INFO *Info)
477 ACPI_RSDESC_SIZE AmlLength = 0;
480 UINT16 ItemCount = 0;
483 ACPI_FUNCTION_TRACE (RsConvertResourceToAml);
488 return_ACPI_STATUS (AE_BAD_PARAMETER);
492 * First table entry must be ACPI_RSC_INITxxx and must contain the
493 * table length (# of table entries)
495 Count = INIT_TABLE_LENGTH (Info);
500 * Source is the internal resource descriptor,
501 * destination is the external AML byte stream buffer
503 Source = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset);
504 Destination = ACPI_ADD_PTR (void, Aml, Info->AmlOffset);
506 switch (Info->Opcode)
508 case ACPI_RSC_INITSET:
510 ACPI_MEMSET (Aml, 0, INIT_RESOURCE_LENGTH (Info));
511 AmlLength = INIT_RESOURCE_LENGTH (Info);
512 AcpiRsSetResourceHeader (INIT_RESOURCE_TYPE (Info), AmlLength, Aml);
515 case ACPI_RSC_INITGET:
518 case ACPI_RSC_FLAGINIT:
520 * Clear the flag byte
522 ACPI_SET8 (Destination, 0);
525 case ACPI_RSC_1BITFLAG:
527 * Mask and shift the flag bit
529 ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
530 ((ACPI_GET8 (Source) & 0x01) << Info->Value));
533 case ACPI_RSC_2BITFLAG:
535 * Mask and shift the flag bits
537 ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
538 ((ACPI_GET8 (Source) & 0x03) << Info->Value));
541 case ACPI_RSC_3BITFLAG:
543 * Mask and shift the flag bits
545 ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
546 ((ACPI_GET8 (Source) & 0x07) << Info->Value));
551 ItemCount = ACPI_GET8 (Source);
552 ACPI_SET8 (Destination, ItemCount);
554 AmlLength = (UINT16) (AmlLength + (Info->Value * (ItemCount - 1)));
557 case ACPI_RSC_COUNT16:
559 ItemCount = ACPI_GET16 (Source);
560 AmlLength = (UINT16) (AmlLength + ItemCount);
561 AcpiRsSetResourceLength (AmlLength, Aml);
564 case ACPI_RSC_COUNT_GPIO_PIN:
566 ItemCount = ACPI_GET16 (Source);
567 ACPI_SET16 (Destination, AmlLength);
569 AmlLength = (UINT16) (AmlLength + ItemCount * 2);
570 Target = ACPI_ADD_PTR (void, Aml, Info->Value);
571 ACPI_SET16 (Target, AmlLength);
572 AcpiRsSetResourceLength (AmlLength, Aml);
575 case ACPI_RSC_COUNT_GPIO_VEN:
577 ItemCount = ACPI_GET16 (Source);
578 ACPI_SET16 (Destination, ItemCount);
580 AmlLength = (UINT16) (AmlLength + (Info->Value * ItemCount));
581 AcpiRsSetResourceLength (AmlLength, Aml);
584 case ACPI_RSC_COUNT_GPIO_RES:
586 /* Set resource source string length */
588 ItemCount = ACPI_GET16 (Source);
589 ACPI_SET16 (Destination, AmlLength);
591 /* Compute offset for the Vendor Data */
593 AmlLength = (UINT16) (AmlLength + ItemCount);
594 Target = ACPI_ADD_PTR (void, Aml, Info->Value);
596 /* Set vendor offset only if there is vendor data */
598 if (Resource->Data.Gpio.VendorLength)
600 ACPI_SET16 (Target, AmlLength);
603 AcpiRsSetResourceLength (AmlLength, Aml);
606 case ACPI_RSC_COUNT_SERIAL_VEN:
608 ItemCount = ACPI_GET16 (Source);
609 ACPI_SET16 (Destination, ItemCount + Info->Value);
610 AmlLength = (UINT16) (AmlLength + ItemCount);
611 AcpiRsSetResourceLength (AmlLength, Aml);
614 case ACPI_RSC_COUNT_SERIAL_RES:
616 ItemCount = ACPI_GET16 (Source);
617 AmlLength = (UINT16) (AmlLength + ItemCount);
618 AcpiRsSetResourceLength (AmlLength, Aml);
621 case ACPI_RSC_LENGTH:
623 AcpiRsSetResourceLength (Info->Value, Aml);
627 case ACPI_RSC_MOVE16:
628 case ACPI_RSC_MOVE32:
629 case ACPI_RSC_MOVE64:
633 ItemCount = Info->Value;
635 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
638 case ACPI_RSC_MOVE_GPIO_PIN:
640 Destination = (char *) ACPI_ADD_PTR (void, Aml,
641 ACPI_GET16 (Destination));
642 Source = * (UINT16 **) Source;
643 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
646 case ACPI_RSC_MOVE_GPIO_RES:
648 /* Used for both ResourceSource string and VendorData */
650 Destination = (char *) ACPI_ADD_PTR (void, Aml,
651 ACPI_GET16 (Destination));
652 Source = * (UINT8 **) Source;
653 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
656 case ACPI_RSC_MOVE_SERIAL_VEN:
658 Destination = (char *) ACPI_ADD_PTR (void, Aml,
659 (AmlLength - ItemCount));
660 Source = * (UINT8 **) Source;
661 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
664 case ACPI_RSC_MOVE_SERIAL_RES:
666 Destination = (char *) ACPI_ADD_PTR (void, Aml,
667 (AmlLength - ItemCount));
668 Source = * (UINT8 **) Source;
669 AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
672 case ACPI_RSC_ADDRESS:
674 /* Set the Resource Type, General Flags, and Type-Specific Flags */
676 AcpiRsSetAddressCommon (Aml, Resource);
679 case ACPI_RSC_SOURCEX:
681 * Optional ResourceSource (Index and String)
683 AmlLength = AcpiRsSetResourceSource (
684 Aml, (ACPI_RS_LENGTH) AmlLength, Source);
685 AcpiRsSetResourceLength (AmlLength, Aml);
688 case ACPI_RSC_SOURCE:
690 * Optional ResourceSource (Index and String). This is the more
691 * complicated case used by the Interrupt() macro
693 AmlLength = AcpiRsSetResourceSource (Aml, Info->Value, Source);
694 AcpiRsSetResourceLength (AmlLength, Aml);
697 case ACPI_RSC_BITMASK:
699 * 8-bit encoded bitmask (DMA macro)
701 ACPI_SET8 (Destination,
702 AcpiRsEncodeBitmask (Source,
703 *ACPI_ADD_PTR (UINT8, Resource, Info->Value)));
706 case ACPI_RSC_BITMASK16:
708 * 16-bit encoded bitmask (IRQ macro)
710 Temp16 = AcpiRsEncodeBitmask (Source,
711 *ACPI_ADD_PTR (UINT8, Resource, Info->Value));
712 ACPI_MOVE_16_TO_16 (Destination, &Temp16);
715 case ACPI_RSC_EXIT_LE:
717 * Control - Exit conversion if less than or equal
719 if (ItemCount <= Info->Value)
725 case ACPI_RSC_EXIT_NE:
727 * Control - Exit conversion if not equal
729 switch (COMPARE_OPCODE (Info))
731 case ACPI_RSC_COMPARE_VALUE:
733 if (*ACPI_ADD_PTR (UINT8, Resource,
734 COMPARE_TARGET (Info)) != COMPARE_VALUE (Info))
742 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode"));
743 return_ACPI_STATUS (AE_BAD_PARAMETER);
747 case ACPI_RSC_EXIT_EQ:
749 * Control - Exit conversion if equal
751 if (*ACPI_ADD_PTR (UINT8, Resource,
752 COMPARE_TARGET (Info)) == COMPARE_VALUE (Info))
760 ACPI_ERROR ((AE_INFO, "Invalid conversion opcode"));
761 return_ACPI_STATUS (AE_BAD_PARAMETER);
769 return_ACPI_STATUS (AE_OK);
774 /* Previous resource validations */
776 if (Aml->ExtAddress64.RevisionID != AML_RESOURCE_EXTENDED_ADDRESS_REVISION)
778 return_ACPI_STATUS (AE_SUPPORT);
781 if (Resource->Data.StartDpf.PerformanceRobustness >= 3)
783 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
786 if (((Aml->Irq.Flags & 0x09) == 0x00) ||
787 ((Aml->Irq.Flags & 0x09) == 0x09))
790 * Only [ActiveHigh, EdgeSensitive] or [ActiveLow, LevelSensitive]
791 * polarity/trigger interrupts are allowed (ACPI spec, section
792 * "IRQ Format"), so 0x00 and 0x09 are illegal.
794 ACPI_ERROR ((AE_INFO,
795 "Invalid interrupt polarity/trigger in resource list, 0x%X",
797 return_ACPI_STATUS (AE_BAD_DATA);
800 Resource->Data.ExtendedIrq.InterruptCount = Temp8;
803 /* Must have at least one IRQ */
805 return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
808 if (Resource->Data.Dma.Transfer == 0x03)
810 ACPI_ERROR ((AE_INFO,
811 "Invalid DMA.Transfer preference (3)"));
812 return_ACPI_STATUS (AE_BAD_DATA);