rslist.c revision 204773
1241675Suqs/******************************************************************************* 2241675Suqs * 3241675Suqs * Module Name: rslist - Linked list utilities 4241675Suqs * 5241675Suqs ******************************************************************************/ 6241675Suqs 7241675Suqs/****************************************************************************** 8241675Suqs * 9241675Suqs * 1. Copyright Notice 10241675Suqs * 11241675Suqs * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. 12241675Suqs * All rights reserved. 13241675Suqs * 14241675Suqs * 2. License 15241675Suqs * 16241675Suqs * 2.1. This is your license from Intel Corp. under its intellectual property 17241675Suqs * rights. You may have additional license terms from the party that provided 18241675Suqs * you this software, covering your right to use that party's intellectual 19241675Suqs * property rights. 20241675Suqs * 21241675Suqs * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22241675Suqs * copy of the source code appearing in this file ("Covered Code") an 23241675Suqs * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24241675Suqs * base code distributed originally by Intel ("Original Intel Code") to copy, 25241675Suqs * make derivatives, distribute, use and display any portion of the Covered 26241675Suqs * Code in any form, with the right to sublicense such rights; and 27241675Suqs * 28241675Suqs * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29241675Suqs * license (with the right to sublicense), under only those claims of Intel 30241675Suqs * patents that are infringed by the Original Intel Code, to make, use, sell, 31241675Suqs * offer to sell, and import the Covered Code and derivative works thereof 32241675Suqs * solely to the minimum extent necessary to exercise the above copyright 33241675Suqs * license, and in no event shall the patent license extend to any additions 34241675Suqs * to or modifications of the Original Intel Code. No other license or right 35241675Suqs * is granted directly or by implication, estoppel or otherwise; 36241675Suqs * 37241675Suqs * The above copyright and patent license is granted only if the following 38241675Suqs * conditions are met: 39241675Suqs * 40241675Suqs * 3. Conditions 41241675Suqs * 42241675Suqs * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43241675Suqs * Redistribution of source code of any substantial portion of the Covered 44241675Suqs * Code or modification with rights to further distribute source must include 45241675Suqs * the above Copyright Notice, the above License, this list of Conditions, 46241675Suqs * and the following Disclaimer and Export Compliance provision. In addition, 47241675Suqs * Licensee must cause all Covered Code to which Licensee contributes to 48241675Suqs * contain a file documenting the changes Licensee made to create that Covered 49241675Suqs * Code and the date of any change. Licensee must include in that file the 50241675Suqs * documentation of any changes made by any predecessor Licensee. Licensee 51241675Suqs * must include a prominent statement that the modification is derived, 52241675Suqs * directly or indirectly, from Original Intel Code. 53241675Suqs * 54241675Suqs * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55241675Suqs * Redistribution of source code of any substantial portion of the Covered 56241675Suqs * Code or modification without rights to further distribute source must 57241675Suqs * include the following Disclaimer and Export Compliance provision in the 58241675Suqs * documentation and/or other materials provided with distribution. In 59241675Suqs * addition, Licensee may not authorize further sublicense of source of any 60241675Suqs * portion of the Covered Code, and must include terms to the effect that the 61241675Suqs * license from Licensee to its licensee is limited to the intellectual 62241675Suqs * property embodied in the software Licensee provides to its licensee, and 63241675Suqs * not to intellectual property embodied in modifications its licensee may 64241675Suqs * make. 65241675Suqs * 66241675Suqs * 3.3. Redistribution of Executable. Redistribution in executable form of any 67241675Suqs * substantial portion of the Covered Code or modification must reproduce the 68241675Suqs * above Copyright Notice, and the following Disclaimer and Export Compliance 69241675Suqs * provision in the documentation and/or other materials provided with the 70241675Suqs * distribution. 71241675Suqs * 72241675Suqs * 3.4. Intel retains all right, title, and interest in and to the Original 73241675Suqs * Intel Code. 74241675Suqs * 75241675Suqs * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76241675Suqs * Intel shall be used in advertising or otherwise to promote the sale, use or 77241675Suqs * other dealings in products derived from or relating to the Covered Code 78241675Suqs * without prior written authorization from Intel. 79241675Suqs * 80241675Suqs * 4. Disclaimer and Export Compliance 81241675Suqs * 82241675Suqs * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83241675Suqs * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84241675Suqs * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85241675Suqs * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86241675Suqs * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87241675Suqs * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88241675Suqs * PARTICULAR PURPOSE. 89241675Suqs * 90241675Suqs * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91241675Suqs * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92241675Suqs * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93241675Suqs * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94241675Suqs * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95241675Suqs * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96241675Suqs * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97241675Suqs * LIMITED REMEDY. 98241675Suqs * 99241675Suqs * 4.3. Licensee shall not export, either directly or indirectly, any of this 100241675Suqs * software or system incorporating such software without first obtaining any 101241675Suqs * required license or other approval from the U. S. Department of Commerce or 102241675Suqs * any other agency or department of the United States Government. In the 103241675Suqs * event Licensee exports any such software from the United States or 104241675Suqs * re-exports any such software from a foreign destination, Licensee shall 105241675Suqs * ensure that the distribution and export/re-export of the software is in 106241675Suqs * compliance with all laws, regulations, orders, or other restrictions of the 107241675Suqs * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108241675Suqs * any of its subsidiaries will export/re-export any technical data, process, 109241675Suqs * software, or service, directly or indirectly, to any country for which the 110241675Suqs * United States government or any agency thereof requires an export license, 111241675Suqs * other governmental approval, or letter of assurance, without first obtaining 112241675Suqs * such license, approval or letter. 113241675Suqs * 114241675Suqs *****************************************************************************/ 115241675Suqs 116241675Suqs#define __RSLIST_C__ 117241675Suqs 118241675Suqs#include <contrib/dev/acpica/include/acpi.h> 119241675Suqs#include <contrib/dev/acpica/include/accommon.h> 120241675Suqs#include <contrib/dev/acpica/include/acresrc.h> 121241675Suqs 122241675Suqs#define _COMPONENT ACPI_RESOURCES 123241675Suqs ACPI_MODULE_NAME ("rslist") 124241675Suqs 125241675Suqs 126241675Suqs/******************************************************************************* 127241675Suqs * 128241675Suqs * FUNCTION: AcpiRsConvertAmlToResources 129241675Suqs * 130241675Suqs * PARAMETERS: ACPI_WALK_AML_CALLBACK 131241675Suqs * ResourcePtr - Pointer to the buffer that will 132241675Suqs * contain the output structures 133241675Suqs * 134241675Suqs * RETURN: Status 135241675Suqs * 136241675Suqs * DESCRIPTION: Convert an AML resource to an internal representation of the 137241675Suqs * resource that is aligned and easier to access. 138241675Suqs * 139241675Suqs ******************************************************************************/ 140241675Suqs 141241675SuqsACPI_STATUS 142241675SuqsAcpiRsConvertAmlToResources ( 143241675Suqs UINT8 *Aml, 144241675Suqs UINT32 Length, 145241675Suqs UINT32 Offset, 146241675Suqs UINT8 ResourceIndex, 147241675Suqs void *Context) 148241675Suqs{ 149241675Suqs ACPI_RESOURCE **ResourcePtr = ACPI_CAST_INDIRECT_PTR ( 150241675Suqs ACPI_RESOURCE, Context); 151241675Suqs ACPI_RESOURCE *Resource; 152241675Suqs ACPI_STATUS Status; 153241675Suqs 154241675Suqs 155241675Suqs ACPI_FUNCTION_TRACE (RsConvertAmlToResources); 156241675Suqs 157241675Suqs 158241675Suqs /* 159241675Suqs * Check that the input buffer and all subsequent pointers into it 160241675Suqs * are aligned on a native word boundary. Most important on IA64 161241675Suqs */ 162241675Suqs Resource = *ResourcePtr; 163241675Suqs if (ACPI_IS_MISALIGNED (Resource)) 164241675Suqs { 165241675Suqs ACPI_WARNING ((AE_INFO, 166241675Suqs "Misaligned resource pointer %p", Resource)); 167241675Suqs } 168241675Suqs 169241675Suqs /* Convert the AML byte stream resource to a local resource struct */ 170241675Suqs 171241675Suqs Status = AcpiRsConvertAmlToResource ( 172241675Suqs Resource, ACPI_CAST_PTR (AML_RESOURCE, Aml), 173241675Suqs AcpiGbl_GetResourceDispatch[ResourceIndex]); 174241675Suqs if (ACPI_FAILURE (Status)) 175241675Suqs { 176241675Suqs ACPI_EXCEPTION ((AE_INFO, Status, 177241675Suqs "Could not convert AML resource (Type 0x%X)", *Aml)); 178241675Suqs return_ACPI_STATUS (Status); 179241675Suqs } 180241675Suqs 181241675Suqs ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES, 182241675Suqs "Type %.2X, AmlLength %.2X InternalLength %.2X\n", 183241675Suqs AcpiUtGetResourceType (Aml), Length, 184241675Suqs Resource->Length)); 185241675Suqs 186241675Suqs /* Point to the next structure in the output buffer */ 187241675Suqs 188241675Suqs *ResourcePtr = ACPI_ADD_PTR (void, Resource, Resource->Length); 189241675Suqs return_ACPI_STATUS (AE_OK); 190241675Suqs} 191241675Suqs 192241675Suqs 193241675Suqs/******************************************************************************* 194241675Suqs * 195241675Suqs * FUNCTION: AcpiRsConvertResourcesToAml 196241675Suqs * 197241675Suqs * PARAMETERS: Resource - Pointer to the resource linked list 198241675Suqs * AmlSizeNeeded - Calculated size of the byte stream 199241675Suqs * needed from calling AcpiRsGetAmlLength() 200241675Suqs * The size of the OutputBuffer is 201241675Suqs * guaranteed to be >= AmlSizeNeeded 202241675Suqs * OutputBuffer - Pointer to the buffer that will 203241675Suqs * contain the byte stream 204241675Suqs * 205241675Suqs * RETURN: Status 206241675Suqs * 207241675Suqs * DESCRIPTION: Takes the resource linked list and parses it, creating a 208241675Suqs * byte stream of resources in the caller's output buffer 209241675Suqs * 210241675Suqs ******************************************************************************/ 211241675Suqs 212241675SuqsACPI_STATUS 213241675SuqsAcpiRsConvertResourcesToAml ( 214241675Suqs ACPI_RESOURCE *Resource, 215241675Suqs ACPI_SIZE AmlSizeNeeded, 216241675Suqs UINT8 *OutputBuffer) 217241675Suqs{ 218241675Suqs UINT8 *Aml = OutputBuffer; 219241675Suqs UINT8 *EndAml = OutputBuffer + AmlSizeNeeded; 220241675Suqs ACPI_STATUS Status; 221241675Suqs 222241675Suqs 223241675Suqs ACPI_FUNCTION_TRACE (RsConvertResourcesToAml); 224241675Suqs 225241675Suqs 226241675Suqs /* Walk the resource descriptor list, convert each descriptor */ 227241675Suqs 228241675Suqs while (Aml < EndAml) 229241675Suqs { 230241675Suqs /* Validate the (internal) Resource Type */ 231241675Suqs 232241675Suqs if (Resource->Type > ACPI_RESOURCE_TYPE_MAX) 233241675Suqs { 234241675Suqs ACPI_ERROR ((AE_INFO, 235241675Suqs "Invalid descriptor type (0x%X) in resource list", 236241675Suqs Resource->Type)); 237241675Suqs return_ACPI_STATUS (AE_BAD_DATA); 238241675Suqs } 239241675Suqs 240241675Suqs /* Perform the conversion */ 241241675Suqs 242241675Suqs Status = AcpiRsConvertResourceToAml (Resource, 243241675Suqs ACPI_CAST_PTR (AML_RESOURCE, Aml), 244241675Suqs AcpiGbl_SetResourceDispatch[Resource->Type]); 245241675Suqs if (ACPI_FAILURE (Status)) 246241675Suqs { 247241675Suqs ACPI_EXCEPTION ((AE_INFO, Status, 248241675Suqs "Could not convert resource (type 0x%X) to AML", 249241675Suqs Resource->Type)); 250241675Suqs return_ACPI_STATUS (Status); 251241675Suqs } 252241675Suqs 253241675Suqs /* Perform final sanity check on the new AML resource descriptor */ 254241675Suqs 255241675Suqs Status = AcpiUtValidateResource ( 256241675Suqs ACPI_CAST_PTR (AML_RESOURCE, Aml), NULL); 257241675Suqs if (ACPI_FAILURE (Status)) 258241675Suqs { 259241675Suqs return_ACPI_STATUS (Status); 260241675Suqs } 261241675Suqs 262241675Suqs /* Check for end-of-list, normal exit */ 263241675Suqs 264241675Suqs if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG) 265241675Suqs { 266241675Suqs /* An End Tag indicates the end of the input Resource Template */ 267241675Suqs 268241675Suqs return_ACPI_STATUS (AE_OK); 269241675Suqs } 270241675Suqs 271241675Suqs /* 272241675Suqs * Extract the total length of the new descriptor and set the 273241675Suqs * Aml to point to the next (output) resource descriptor 274241675Suqs */ 275241675Suqs Aml += AcpiUtGetDescriptorLength (Aml); 276241675Suqs 277241675Suqs /* Point to the next input resource descriptor */ 278241675Suqs 279241675Suqs Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length); 280241675Suqs } 281241675Suqs 282241675Suqs /* Completed buffer, but did not find an EndTag resource descriptor */ 283241675Suqs 284241675Suqs return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG); 285241675Suqs} 286241675Suqs 287241675Suqs