diff options
Diffstat (limited to 'sys/contrib/dev/acpica/rsutils.c')
-rw-r--r-- | sys/contrib/dev/acpica/rsutils.c | 550 |
1 files changed, 519 insertions, 31 deletions
diff --git a/sys/contrib/dev/acpica/rsutils.c b/sys/contrib/dev/acpica/rsutils.c index 96d27e0..72cb9bf 100644 --- a/sys/contrib/dev/acpica/rsutils.c +++ b/sys/contrib/dev/acpica/rsutils.c @@ -1,7 +1,7 @@ /******************************************************************************* * * Module Name: rsutils - Utilities for the resource manager - * $Revision: 39 $ + * $Revision: 1.50 $ * ******************************************************************************/ @@ -9,7 +9,7 @@ * * 1. Copyright Notice * - * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp. + * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp. * All rights reserved. * * 2. License @@ -128,6 +128,489 @@ /******************************************************************************* * + * FUNCTION: AcpiRsDecodeBitmask + * + * PARAMETERS: Mask - Bitmask to decode + * List - Where the converted list is returned + * + * RETURN: Count of bits set (length of list) + * + * DESCRIPTION: Convert a bit mask into a list of values + * + ******************************************************************************/ + +UINT8 +AcpiRsDecodeBitmask ( + UINT16 Mask, + UINT8 *List) +{ + ACPI_NATIVE_UINT i; + UINT8 BitCount; + + + /* Decode the mask bits */ + + for (i = 0, BitCount = 0; Mask; i++) + { + if (Mask & 0x0001) + { + List[BitCount] = (UINT8) i; + BitCount++; + } + + Mask >>= 1; + } + + return (BitCount); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiRsEncodeBitmask + * + * PARAMETERS: List - List of values to encode + * Count - Length of list + * + * RETURN: Encoded bitmask + * + * DESCRIPTION: Convert a list of values to an encoded bitmask + * + ******************************************************************************/ + +UINT16 +AcpiRsEncodeBitmask ( + UINT8 *List, + UINT8 Count) +{ + ACPI_NATIVE_UINT i; + UINT16 Mask; + + + /* Encode the list into a single bitmask */ + + for (i = 0, Mask = 0; i < Count; i++) + { + Mask |= (0x0001 << List[i]); + } + + return (Mask); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiRsMoveData + * + * PARAMETERS: Destination - Pointer to the destination descriptor + * Source - Pointer to the source descriptor + * ItemCount - How many items to move + * MoveType - Byte width + * + * RETURN: None + * + * DESCRIPTION: Move multiple data items from one descriptor to another. Handles + * alignment issues and endian issues if necessary, as configured + * via the ACPI_MOVE_* macros. (This is why a memcpy is not used) + * + ******************************************************************************/ + +void +AcpiRsMoveData ( + void *Destination, + void *Source, + UINT16 ItemCount, + UINT8 MoveType) +{ + ACPI_NATIVE_UINT i; + + + /* One move per item */ + + for (i = 0; i < ItemCount; i++) + { + switch (MoveType) + { + /* + * For the 8-bit case, we can perform the move all at once + * since there are no alignment or endian issues + */ + case ACPI_RSC_MOVE8: + ACPI_MEMCPY (Destination, Source, ItemCount); + return; + + /* + * 16-, 32-, and 64-bit cases must use the move macros that perform + * endian conversion and/or accomodate hardware that cannot perform + * misaligned memory transfers + */ + case ACPI_RSC_MOVE16: + ACPI_MOVE_16_TO_16 (&((UINT16 *) Destination)[i], + &((UINT16 *) Source)[i]); + break; + + case ACPI_RSC_MOVE32: + ACPI_MOVE_32_TO_32 (&((UINT32 *) Destination)[i], + &((UINT32 *) Source)[i]); + break; + + case ACPI_RSC_MOVE64: + ACPI_MOVE_64_TO_64 (&((UINT64 *) Destination)[i], + &((UINT64 *) Source)[i]); + break; + + default: + return; + } + } +} + + +/******************************************************************************* + * + * FUNCTION: AcpiRsGetResourceInfo + * + * PARAMETERS: ResourceType - Byte 0 of a resource descriptor + * + * RETURN: Pointer to the resource conversion handler + * + * DESCRIPTION: Extract the Resource Type/Name from the first byte of + * a resource descriptor. + * + ******************************************************************************/ + +ACPI_RESOURCE_INFO * +AcpiRsGetResourceInfo ( + UINT8 ResourceType) +{ + ACPI_RESOURCE_INFO *SizeInfo; + + + ACPI_FUNCTION_ENTRY (); + + + /* Determine if this is a small or large resource */ + + if (ResourceType & ACPI_RESOURCE_NAME_LARGE) + { + /* Large Resource Type -- bits 6:0 contain the name */ + + if (ResourceType > ACPI_RESOURCE_NAME_LARGE_MAX) + { + return (NULL); + } + + SizeInfo = &AcpiGbl_LgResourceInfo [ + (ResourceType & ACPI_RESOURCE_NAME_LARGE_MASK)]; + } + else + { + /* Small Resource Type -- bits 6:3 contain the name */ + + SizeInfo = &AcpiGbl_SmResourceInfo [ + ((ResourceType & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3)]; + } + + /* Zero entry indicates an invalid resource type */ + + if (!SizeInfo->MinimumInternalStructLength) + { + return (NULL); + } + + return (SizeInfo); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiRsSetResourceLength + * + * PARAMETERS: TotalLength - Length of the AML descriptor, including + * the header and length fields. + * Aml - Pointer to the raw AML descriptor + * + * RETURN: None + * + * DESCRIPTION: Set the ResourceLength field of an AML + * resource descriptor, both Large and Small descriptors are + * supported automatically. Note: Descriptor Type field must + * be valid. + * + ******************************************************************************/ + +void +AcpiRsSetResourceLength ( + ACPI_RSDESC_SIZE TotalLength, + AML_RESOURCE *Aml) +{ + ACPI_RS_LENGTH ResourceLength; + + + ACPI_FUNCTION_ENTRY (); + + + /* Determine if this is a small or large resource */ + + if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE) + { + /* Large Resource type -- bytes 1-2 contain the 16-bit length */ + + ResourceLength = (ACPI_RS_LENGTH) + (TotalLength - sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Insert length into the Large descriptor length field */ + + ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength); + } + else + { + /* Small Resource type -- bits 2:0 of byte 0 contain the length */ + + ResourceLength = (ACPI_RS_LENGTH) + (TotalLength - sizeof (AML_RESOURCE_SMALL_HEADER)); + + /* Insert length into the descriptor type byte */ + + Aml->SmallHeader.DescriptorType = (UINT8) + + /* Clear any existing length, preserving descriptor type bits */ + + ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK) + + | ResourceLength); + } +} + + +/******************************************************************************* + * + * FUNCTION: AcpiRsSetResourceHeader + * + * PARAMETERS: DescriptorType - Byte to be inserted as the type + * TotalLength - Length of the AML descriptor, including + * the header and length fields. + * Aml - Pointer to the raw AML descriptor + * + * RETURN: None + * + * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML + * resource descriptor, both Large and Small descriptors are + * supported automatically + * + ******************************************************************************/ + +void +AcpiRsSetResourceHeader ( + UINT8 DescriptorType, + ACPI_RSDESC_SIZE TotalLength, + AML_RESOURCE *Aml) +{ + ACPI_FUNCTION_ENTRY (); + + + /* Set the Descriptor Type */ + + Aml->SmallHeader.DescriptorType = DescriptorType; + + /* Set the Resource Length */ + + AcpiRsSetResourceLength (TotalLength, Aml); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiRsStrcpy + * + * PARAMETERS: Destination - Pointer to the destination string + * Source - Pointer to the source string + * + * RETURN: String length, including NULL terminator + * + * DESCRIPTION: Local string copy that returns the string length, saving a + * strcpy followed by a strlen. + * + ******************************************************************************/ + +static UINT16 +AcpiRsStrcpy ( + char *Destination, + char *Source) +{ + UINT16 i; + + + ACPI_FUNCTION_ENTRY (); + + + for (i = 0; Source[i]; i++) + { + Destination[i] = Source[i]; + } + + Destination[i] = 0; + + /* Return string length including the NULL terminator */ + + return ((UINT16) (i + 1)); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiRsGetResourceSource + * + * PARAMETERS: ResourceLength - Length field of the descriptor + * MinimumLength - Minimum length of the descriptor (minus + * any optional fields) + * ResourceSource - Where the ResourceSource is returned + * Aml - Pointer to the raw AML descriptor + * StringPtr - (optional) where to store the actual + * ResourceSource string + * + * RETURN: Length of the string plus NULL terminator, rounded up to 32 bit + * + * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor + * to an internal resource descriptor + * + ******************************************************************************/ + +ACPI_RS_LENGTH +AcpiRsGetResourceSource ( + ACPI_RS_LENGTH ResourceLength, + ACPI_RS_LENGTH MinimumLength, + ACPI_RESOURCE_SOURCE *ResourceSource, + AML_RESOURCE *Aml, + char *StringPtr) +{ + ACPI_RSDESC_SIZE TotalLength; + UINT8 *AmlResourceSource; + + + ACPI_FUNCTION_ENTRY (); + + + TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER); + AmlResourceSource = ((UINT8 *) Aml) + MinimumLength; + + /* + * ResourceSource is present if the length of the descriptor is longer than + * the minimum length. + * + * Note: Some resource descriptors will have an additional null, so + * we add 1 to the minimum length. + */ + if (TotalLength > (ACPI_RSDESC_SIZE )(MinimumLength + 1)) + { + /* Get the ResourceSourceIndex */ + + ResourceSource->Index = AmlResourceSource[0]; + + ResourceSource->StringPtr = StringPtr; + if (!StringPtr) + { + /* + * String destination pointer is not specified; Set the String + * pointer to the end of the current ResourceSource structure. + */ + ResourceSource->StringPtr = (char *) + ((UINT8 *) ResourceSource) + sizeof (ACPI_RESOURCE_SOURCE); + } + + /* + * In order for the StructSize to fall on a 32-bit boundary, calculate + * the length of the string (+1 for the NULL terminator) and expand the + * StructSize to the next 32-bit boundary. + * + * Zero the entire area of the buffer. + */ + TotalLength = ACPI_ROUND_UP_TO_32BITS ( + ACPI_STRLEN ((char *) &AmlResourceSource[1]) + 1); + ACPI_MEMSET (ResourceSource->StringPtr, 0, TotalLength); + + /* Copy the ResourceSource string to the destination */ + + ResourceSource->StringLength = AcpiRsStrcpy (ResourceSource->StringPtr, + (char *) &AmlResourceSource[1]); + + return ((ACPI_RS_LENGTH) TotalLength); + } + else + { + /* ResourceSource is not present */ + + ResourceSource->Index = 0; + ResourceSource->StringLength = 0; + ResourceSource->StringPtr = NULL; + return (0); + } +} + +/******************************************************************************* + * + * FUNCTION: AcpiRsSetResourceSource + * + * PARAMETERS: Aml - Pointer to the raw AML descriptor + * MinimumLength - Minimum length of the descriptor (minus + * any optional fields) + * ResourceSource - Internal ResourceSource + + * + * RETURN: Total length of the AML descriptor + * + * DESCRIPTION: Convert an optional ResourceSource from internal format to a + * raw AML resource descriptor + * + ******************************************************************************/ + +ACPI_RSDESC_SIZE +AcpiRsSetResourceSource ( + AML_RESOURCE *Aml, + ACPI_RS_LENGTH MinimumLength, + ACPI_RESOURCE_SOURCE *ResourceSource) +{ + UINT8 *AmlResourceSource; + ACPI_RSDESC_SIZE DescriptorLength; + + + ACPI_FUNCTION_ENTRY (); + + + DescriptorLength = MinimumLength; + + /* Non-zero string length indicates presence of a ResourceSource */ + + if (ResourceSource->StringLength) + { + /* Point to the end of the AML descriptor */ + + AmlResourceSource = ((UINT8 *) Aml) + MinimumLength; + + /* Copy the ResourceSourceIndex */ + + AmlResourceSource[0] = (UINT8) ResourceSource->Index; + + /* Copy the ResourceSource string */ + + ACPI_STRCPY ((char *) &AmlResourceSource[1], + ResourceSource->StringPtr); + + /* + * Add the length of the string (+ 1 for null terminator) to the + * final descriptor length + */ + DescriptorLength += ((ACPI_RSDESC_SIZE) ResourceSource->StringLength + 1); + } + + /* Return the new total length of the AML descriptor */ + + return (DescriptorLength); +} + + +/******************************************************************************* + * * FUNCTION: AcpiRsGetPrtMethodData * * PARAMETERS: Handle - a handle to the containing object @@ -158,10 +641,10 @@ AcpiRsGetPrtMethodData ( /* Parameters guaranteed valid by caller */ - /* - * Execute the method, no parameters - */ - Status = AcpiUtEvaluateObject (Handle, "_PRT", ACPI_BTYPE_PACKAGE, &ObjDesc); + /* Execute the method, no parameters */ + + Status = AcpiUtEvaluateObject (Handle, METHOD_NAME__PRT, + ACPI_BTYPE_PACKAGE, &ObjDesc); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); @@ -212,10 +695,10 @@ AcpiRsGetCrsMethodData ( /* Parameters guaranteed valid by caller */ - /* - * Execute the method, no parameters - */ - Status = AcpiUtEvaluateObject (Handle, "_CRS", ACPI_BTYPE_BUFFER, &ObjDesc); + /* Execute the method, no parameters */ + + Status = AcpiUtEvaluateObject (Handle, METHOD_NAME__CRS, + ACPI_BTYPE_BUFFER, &ObjDesc); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); @@ -267,10 +750,10 @@ AcpiRsGetPrsMethodData ( /* Parameters guaranteed valid by caller */ - /* - * Execute the method, no parameters - */ - Status = AcpiUtEvaluateObject (Handle, "_PRS", ACPI_BTYPE_BUFFER, &ObjDesc); + /* Execute the method, no parameters */ + + Status = AcpiUtEvaluateObject (Handle, METHOD_NAME__PRS, + ACPI_BTYPE_BUFFER, &ObjDesc); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); @@ -295,6 +778,7 @@ AcpiRsGetPrsMethodData ( * FUNCTION: AcpiRsGetMethodData * * PARAMETERS: Handle - a handle to the containing object + * Path - Path to method, relative to Handle * RetBuffer - a pointer to a buffer structure for the * results * @@ -323,9 +807,8 @@ AcpiRsGetMethodData ( /* Parameters guaranteed valid by caller */ - /* - * Execute the method, no parameters - */ + /* Execute the method, no parameters */ + Status = AcpiUtEvaluateObject (Handle, Path, ACPI_BTYPE_BUFFER, &ObjDesc); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); @@ -386,15 +869,14 @@ AcpiRsSetSrsMethodData ( * Convert the linked list into a byte stream */ Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER; - Status = AcpiRsCreateByteStream (InBuffer->Pointer, &Buffer); + Status = AcpiRsCreateAmlResources (InBuffer->Pointer, &Buffer); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } - /* - * Init the param object - */ + /* Init the param object */ + Params[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER); if (!Params[0]) { @@ -402,9 +884,8 @@ AcpiRsSetSrsMethodData ( return_ACPI_STATUS (AE_NO_MEMORY); } - /* - * Set up the parameter object - */ + /* Set up the parameter object */ + Params[0]->Buffer.Length = (UINT32) Buffer.Length; Params[0]->Buffer.Pointer = Buffer.Pointer; Params[0]->Common.Flags = AOPOBJ_DATA_VALID; @@ -414,14 +895,21 @@ AcpiRsSetSrsMethodData ( Info.Parameters = Params; Info.ParameterType = ACPI_PARAM_ARGS; - /* - * Execute the method, no return value - */ - Status = AcpiNsEvaluateRelative ("_SRS", &Info); + /* Execute the method, no return value */ + + Status = AcpiNsEvaluateRelative (METHOD_NAME__SRS, &Info); + if (ACPI_SUCCESS (Status)) + { + /* Delete any return object (especially if ImplicitReturn is enabled) */ + + if (Info.ReturnObject) + { + AcpiUtRemoveReference (Info.ReturnObject); + } + } + + /* Clean up and return the status from AcpiNsEvaluateRelative */ - /* - * Clean up and return the status from AcpiNsEvaluateRelative - */ AcpiUtRemoveReference (Params[0]); return_ACPI_STATUS (Status); } |