167754Smsmith/******************************************************************************* 267754Smsmith * 377424Smsmith * Module Name: rscreate - Create resource lists/tables 467754Smsmith * 567754Smsmith ******************************************************************************/ 667754Smsmith 7217365Sjkim/* 8281075Sdim * Copyright (C) 2000 - 2015, Intel Corp. 970243Smsmith * All rights reserved. 1067754Smsmith * 11217365Sjkim * Redistribution and use in source and binary forms, with or without 12217365Sjkim * modification, are permitted provided that the following conditions 13217365Sjkim * are met: 14217365Sjkim * 1. Redistributions of source code must retain the above copyright 15217365Sjkim * notice, this list of conditions, and the following disclaimer, 16217365Sjkim * without modification. 17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20217365Sjkim * including a substantially similar Disclaimer requirement for further 21217365Sjkim * binary redistribution. 22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23217365Sjkim * of any contributors may be used to endorse or promote products derived 24217365Sjkim * from this software without specific prior written permission. 2567754Smsmith * 26217365Sjkim * Alternatively, this software may be distributed under the terms of the 27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28217365Sjkim * Software Foundation. 2967754Smsmith * 30217365Sjkim * NO WARRANTY 31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 42217365Sjkim */ 4367754Smsmith 44193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 45193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 46193341Sjkim#include <contrib/dev/acpica/include/acresrc.h> 47193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 4867754Smsmith 4977424Smsmith#define _COMPONENT ACPI_RESOURCES 5091116Smsmith ACPI_MODULE_NAME ("rscreate") 5167754Smsmith 5267754Smsmith 5367754Smsmith/******************************************************************************* 5467754Smsmith * 55228110Sjkim * FUNCTION: AcpiBufferToResource 56228110Sjkim * 57228110Sjkim * PARAMETERS: AmlBuffer - Pointer to the resource byte stream 58228110Sjkim * AmlBufferLength - Length of the AmlBuffer 59228110Sjkim * ResourcePtr - Where the converted resource is returned 60228110Sjkim * 61228110Sjkim * RETURN: Status 62228110Sjkim * 63228110Sjkim * DESCRIPTION: Convert a raw AML buffer to a resource list 64228110Sjkim * 65228110Sjkim ******************************************************************************/ 66228110Sjkim 67228110SjkimACPI_STATUS 68228110SjkimAcpiBufferToResource ( 69228110Sjkim UINT8 *AmlBuffer, 70228110Sjkim UINT16 AmlBufferLength, 71228110Sjkim ACPI_RESOURCE **ResourcePtr) 72228110Sjkim{ 73228110Sjkim ACPI_STATUS Status; 74228110Sjkim ACPI_SIZE ListSizeNeeded; 75228110Sjkim void *Resource; 76228110Sjkim void *CurrentResourcePtr; 77228110Sjkim 78281075Sdim 79281075Sdim ACPI_FUNCTION_TRACE (AcpiBufferToResource); 80281075Sdim 81281075Sdim 82228110Sjkim /* 83228110Sjkim * Note: we allow AE_AML_NO_RESOURCE_END_TAG, since an end tag 84228110Sjkim * is not required here. 85228110Sjkim */ 86228110Sjkim 87228110Sjkim /* Get the required length for the converted resource */ 88228110Sjkim 89228110Sjkim Status = AcpiRsGetListLength (AmlBuffer, AmlBufferLength, 90228110Sjkim &ListSizeNeeded); 91228110Sjkim if (Status == AE_AML_NO_RESOURCE_END_TAG) 92228110Sjkim { 93228110Sjkim Status = AE_OK; 94228110Sjkim } 95228110Sjkim if (ACPI_FAILURE (Status)) 96228110Sjkim { 97281075Sdim return_ACPI_STATUS (Status); 98228110Sjkim } 99228110Sjkim 100228110Sjkim /* Allocate a buffer for the converted resource */ 101228110Sjkim 102228110Sjkim Resource = ACPI_ALLOCATE_ZEROED (ListSizeNeeded); 103228110Sjkim CurrentResourcePtr = Resource; 104228110Sjkim if (!Resource) 105228110Sjkim { 106281075Sdim return_ACPI_STATUS (AE_NO_MEMORY); 107228110Sjkim } 108228110Sjkim 109228110Sjkim /* Perform the AML-to-Resource conversion */ 110228110Sjkim 111243347Sjkim Status = AcpiUtWalkAmlResources (NULL, AmlBuffer, AmlBufferLength, 112228110Sjkim AcpiRsConvertAmlToResources, &CurrentResourcePtr); 113228110Sjkim if (Status == AE_AML_NO_RESOURCE_END_TAG) 114228110Sjkim { 115228110Sjkim Status = AE_OK; 116228110Sjkim } 117228110Sjkim if (ACPI_FAILURE (Status)) 118228110Sjkim { 119228110Sjkim ACPI_FREE (Resource); 120228110Sjkim } 121228110Sjkim else 122228110Sjkim { 123228110Sjkim *ResourcePtr = Resource; 124228110Sjkim } 125228110Sjkim 126281075Sdim return_ACPI_STATUS (Status); 127228110Sjkim} 128228110Sjkim 129281075SdimACPI_EXPORT_SYMBOL (AcpiBufferToResource) 130228110Sjkim 131281075Sdim 132228110Sjkim/******************************************************************************* 133228110Sjkim * 13467754Smsmith * FUNCTION: AcpiRsCreateResourceList 13567754Smsmith * 136151937Sjkim * PARAMETERS: AmlBuffer - Pointer to the resource byte stream 137151937Sjkim * OutputBuffer - Pointer to the user's buffer 13867754Smsmith * 139151937Sjkim * RETURN: Status: AE_OK if okay, else a valid ACPI_STATUS code 14067754Smsmith * If OutputBuffer is not large enough, OutputBufferLength 14167754Smsmith * indicates how large OutputBuffer should be, else it 14267754Smsmith * indicates how may UINT8 elements of OutputBuffer are valid. 14367754Smsmith * 14467754Smsmith * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method 14567754Smsmith * execution and parses the stream to create a linked list 14667754Smsmith * of device resources. 14767754Smsmith * 14867754Smsmith ******************************************************************************/ 14967754Smsmith 15067754SmsmithACPI_STATUS 15167754SmsmithAcpiRsCreateResourceList ( 152151937Sjkim ACPI_OPERAND_OBJECT *AmlBuffer, 15391116Smsmith ACPI_BUFFER *OutputBuffer) 15467754Smsmith{ 15567754Smsmith 15667754Smsmith ACPI_STATUS Status; 157151937Sjkim UINT8 *AmlStart; 15891116Smsmith ACPI_SIZE ListSizeNeeded = 0; 159151937Sjkim UINT32 AmlBufferLength; 160167802Sjkim void *Resource; 16167754Smsmith 16267754Smsmith 163167802Sjkim ACPI_FUNCTION_TRACE (RsCreateResourceList); 16467754Smsmith 16567754Smsmith 166151937Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlBuffer = %p\n", 167151937Sjkim AmlBuffer)); 16867754Smsmith 169151937Sjkim /* Params already validated, so we don't re-validate here */ 17067754Smsmith 171151937Sjkim AmlBufferLength = AmlBuffer->Buffer.Length; 172151937Sjkim AmlStart = AmlBuffer->Buffer.Pointer; 173151937Sjkim 17467754Smsmith /* 175151937Sjkim * Pass the AmlBuffer into a module that can calculate 17667754Smsmith * the buffer size needed for the linked list 17767754Smsmith */ 178151937Sjkim Status = AcpiRsGetListLength (AmlStart, AmlBufferLength, 17977424Smsmith &ListSizeNeeded); 18067754Smsmith 18182367Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n", 18299679Siwasaki Status, (UINT32) ListSizeNeeded)); 18367754Smsmith if (ACPI_FAILURE (Status)) 18467754Smsmith { 18567754Smsmith return_ACPI_STATUS (Status); 18667754Smsmith } 18767754Smsmith 18891116Smsmith /* Validate/Allocate/Clear caller buffer */ 18991116Smsmith 19091116Smsmith Status = AcpiUtInitializeBuffer (OutputBuffer, ListSizeNeeded); 19191116Smsmith if (ACPI_FAILURE (Status)) 19267754Smsmith { 19391116Smsmith return_ACPI_STATUS (Status); 19487031Smsmith } 19567754Smsmith 19691116Smsmith /* Do the conversion */ 19767754Smsmith 198167802Sjkim Resource = OutputBuffer->Pointer; 199243347Sjkim Status = AcpiUtWalkAmlResources (NULL, AmlStart, AmlBufferLength, 200167802Sjkim AcpiRsConvertAmlToResources, &Resource); 20187031Smsmith if (ACPI_FAILURE (Status)) 20267754Smsmith { 20387031Smsmith return_ACPI_STATUS (Status); 20467754Smsmith } 20567754Smsmith 20691116Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", 20799679Siwasaki OutputBuffer->Pointer, (UINT32) OutputBuffer->Length)); 20867754Smsmith return_ACPI_STATUS (AE_OK); 20967754Smsmith} 21067754Smsmith 21167754Smsmith 21267754Smsmith/******************************************************************************* 21367754Smsmith * 21467754Smsmith * FUNCTION: AcpiRsCreatePciRoutingTable 21567754Smsmith * 216238381Sjkim * PARAMETERS: PackageObject - Pointer to a package containing one 217238381Sjkim * of more ACPI_OPERAND_OBJECTs 21867754Smsmith * OutputBuffer - Pointer to the user's buffer 21967754Smsmith * 22067754Smsmith * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code. 22167754Smsmith * If the OutputBuffer is too small, the error will be 22291116Smsmith * AE_BUFFER_OVERFLOW and OutputBuffer->Length will point 22367754Smsmith * to the size buffer needed. 22467754Smsmith * 225238381Sjkim * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT package and creates a 22667754Smsmith * linked list of PCI interrupt descriptions 22767754Smsmith * 22891116Smsmith * NOTE: It is the caller's responsibility to ensure that the start of the 22991116Smsmith * output buffer is aligned properly (if necessary). 23091116Smsmith * 23167754Smsmith ******************************************************************************/ 23267754Smsmith 23367754SmsmithACPI_STATUS 23467754SmsmithAcpiRsCreatePciRoutingTable ( 23567754Smsmith ACPI_OPERAND_OBJECT *PackageObject, 23691116Smsmith ACPI_BUFFER *OutputBuffer) 23767754Smsmith{ 23891116Smsmith UINT8 *Buffer; 239107325Siwasaki ACPI_OPERAND_OBJECT **TopObjectList; 240107325Siwasaki ACPI_OPERAND_OBJECT **SubObjectList; 241107325Siwasaki ACPI_OPERAND_OBJECT *ObjDesc; 24291116Smsmith ACPI_SIZE BufferSizeNeeded = 0; 243107325Siwasaki UINT32 NumberOfElements; 244107325Siwasaki UINT32 Index; 245107325Siwasaki ACPI_PCI_ROUTING_TABLE *UserPrt; 24673561Smsmith ACPI_NAMESPACE_NODE *Node; 24767754Smsmith ACPI_STATUS Status; 24891116Smsmith ACPI_BUFFER PathBuffer; 24967754Smsmith 25067754Smsmith 251167802Sjkim ACPI_FUNCTION_TRACE (RsCreatePciRoutingTable); 25267754Smsmith 25367754Smsmith 25491116Smsmith /* Params already validated, so we don't re-validate here */ 25591116Smsmith 256151937Sjkim /* Get the required buffer length */ 257151937Sjkim 25899679Siwasaki Status = AcpiRsGetPciRoutingTableLength (PackageObject, 25977424Smsmith &BufferSizeNeeded); 26091116Smsmith if (ACPI_FAILURE (Status)) 26177424Smsmith { 26277424Smsmith return_ACPI_STATUS (Status); 26377424Smsmith } 26467754Smsmith 265114237Snjl ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "BufferSizeNeeded = %X\n", 266107325Siwasaki (UINT32) BufferSizeNeeded)); 26777424Smsmith 26891116Smsmith /* Validate/Allocate/Clear caller buffer */ 26987031Smsmith 27091116Smsmith Status = AcpiUtInitializeBuffer (OutputBuffer, BufferSizeNeeded); 27191116Smsmith if (ACPI_FAILURE (Status)) 27287031Smsmith { 27391116Smsmith return_ACPI_STATUS (Status); 27487031Smsmith } 27587031Smsmith 27667754Smsmith /* 277193267Sjkim * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a 278202771Sjkim * package that in turn contains an UINT64 Address, a UINT8 Pin, 279193267Sjkim * a Name, and a UINT8 SourceIndex. 28067754Smsmith */ 28187031Smsmith TopObjectList = PackageObject->Package.Elements; 28287031Smsmith NumberOfElements = PackageObject->Package.Count; 28391116Smsmith Buffer = OutputBuffer->Pointer; 28499679Siwasaki UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer); 28587031Smsmith 28687031Smsmith for (Index = 0; Index < NumberOfElements; Index++) 28767754Smsmith { 28867754Smsmith /* 28987031Smsmith * Point UserPrt past this current structure 29087031Smsmith * 29187031Smsmith * NOTE: On the first iteration, UserPrt->Length will 29287031Smsmith * be zero because we cleared the return buffer earlier 29367754Smsmith */ 29487031Smsmith Buffer += UserPrt->Length; 29599679Siwasaki UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer); 29667754Smsmith 29767754Smsmith /* 29891116Smsmith * Fill in the Length field with the information we have at this point. 29991116Smsmith * The minus four is to subtract the size of the UINT8 Source[4] member 30091116Smsmith * because it is added below. 30167754Smsmith */ 302107325Siwasaki UserPrt->Length = (sizeof (ACPI_PCI_ROUTING_TABLE) - 4); 30367754Smsmith 304281075Sdim /* Each subpackage must be of length 4 */ 305107325Siwasaki 306107325Siwasaki if ((*TopObjectList)->Package.Count != 4) 307107325Siwasaki { 308167802Sjkim ACPI_ERROR ((AE_INFO, 309204773Sjkim "(PRT[%u]) Need package of length 4, found length %u", 310107325Siwasaki Index, (*TopObjectList)->Package.Count)); 311107325Siwasaki return_ACPI_STATUS (AE_AML_PACKAGE_LIMIT); 312107325Siwasaki } 313107325Siwasaki 31487031Smsmith /* 315281075Sdim * Dereference the subpackage. 31691116Smsmith * The SubObjectList will now point to an array of the four IRQ 317107325Siwasaki * elements: [Address, Pin, Source, SourceIndex] 31887031Smsmith */ 319107325Siwasaki SubObjectList = (*TopObjectList)->Package.Elements; 32069450Smsmith 321151937Sjkim /* 1) First subobject: Dereference the PRT.Address */ 322151937Sjkim 323107325Siwasaki ObjDesc = SubObjectList[0]; 324281075Sdim if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER) 32567754Smsmith { 326204773Sjkim ACPI_ERROR ((AE_INFO, "(PRT[%u].Address) Need Integer, found %s", 327107325Siwasaki Index, AcpiUtGetObjectTypeName (ObjDesc))); 32887031Smsmith return_ACPI_STATUS (AE_BAD_DATA); 32987031Smsmith } 33067754Smsmith 331193267Sjkim UserPrt->Address = ObjDesc->Integer.Value; 332193267Sjkim 333151937Sjkim /* 2) Second subobject: Dereference the PRT.Pin */ 334151937Sjkim 335107325Siwasaki ObjDesc = SubObjectList[1]; 336281075Sdim if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER) 33787031Smsmith { 338204773Sjkim ACPI_ERROR ((AE_INFO, "(PRT[%u].Pin) Need Integer, found %s", 339107325Siwasaki Index, AcpiUtGetObjectTypeName (ObjDesc))); 34087031Smsmith return_ACPI_STATUS (AE_BAD_DATA); 34187031Smsmith } 34267754Smsmith 343193267Sjkim UserPrt->Pin = (UINT32) ObjDesc->Integer.Value; 344193267Sjkim 345167802Sjkim /* 346167802Sjkim * 3) Third subobject: Dereference the PRT.SourceName 347167802Sjkim * The name may be unresolved (slack mode), so allow a null object 348167802Sjkim */ 349107325Siwasaki ObjDesc = SubObjectList[2]; 350167802Sjkim if (ObjDesc) 35187031Smsmith { 352193267Sjkim switch (ObjDesc->Common.Type) 35367754Smsmith { 354167802Sjkim case ACPI_TYPE_LOCAL_REFERENCE: 35567754Smsmith 356193267Sjkim if (ObjDesc->Reference.Class != ACPI_REFCLASS_NAME) 357167802Sjkim { 358167802Sjkim ACPI_ERROR ((AE_INFO, 359204773Sjkim "(PRT[%u].Source) Need name, found Reference Class 0x%X", 360193267Sjkim Index, ObjDesc->Reference.Class)); 361167802Sjkim return_ACPI_STATUS (AE_BAD_DATA); 362167802Sjkim } 36367754Smsmith 364167802Sjkim Node = ObjDesc->Reference.Node; 36567754Smsmith 366167802Sjkim /* Use *remaining* length of the buffer as max for pathname */ 36767754Smsmith 368167802Sjkim PathBuffer.Length = OutputBuffer->Length - 369167802Sjkim (UINT32) ((UINT8 *) UserPrt->Source - 370167802Sjkim (UINT8 *) OutputBuffer->Pointer); 371167802Sjkim PathBuffer.Pointer = UserPrt->Source; 37267754Smsmith 373167802Sjkim Status = AcpiNsHandleToPathname ((ACPI_HANDLE) Node, &PathBuffer); 374151937Sjkim 375167802Sjkim /* +1 to include null terminator */ 37677424Smsmith 377167802Sjkim UserPrt->Length += (UINT32) ACPI_STRLEN (UserPrt->Source) + 1; 378167802Sjkim break; 37973561Smsmith 380167802Sjkim case ACPI_TYPE_STRING: 38173561Smsmith 382167802Sjkim ACPI_STRCPY (UserPrt->Source, ObjDesc->String.Pointer); 38373561Smsmith 384167802Sjkim /* 385167802Sjkim * Add to the Length field the length of the string 386167802Sjkim * (add 1 for terminator) 387167802Sjkim */ 388167802Sjkim UserPrt->Length += ObjDesc->String.Length + 1; 389167802Sjkim break; 39073561Smsmith 391167802Sjkim case ACPI_TYPE_INTEGER: 392167802Sjkim /* 393167802Sjkim * If this is a number, then the Source Name is NULL, since the 394167802Sjkim * entire buffer was zeroed out, we can leave this alone. 395167802Sjkim * 396167802Sjkim * Add to the Length field the length of the UINT32 NULL 397167802Sjkim */ 398167802Sjkim UserPrt->Length += sizeof (UINT32); 399167802Sjkim break; 40073561Smsmith 401167802Sjkim default: 402167802Sjkim 403167802Sjkim ACPI_ERROR ((AE_INFO, 404204773Sjkim "(PRT[%u].Source) Need Ref/String/Integer, found %s", 405167802Sjkim Index, AcpiUtGetObjectTypeName (ObjDesc))); 406167802Sjkim return_ACPI_STATUS (AE_BAD_DATA); 407167802Sjkim } 40887031Smsmith } 40967754Smsmith 41087031Smsmith /* Now align the current length */ 41173561Smsmith 412167802Sjkim UserPrt->Length = (UINT32) ACPI_ROUND_UP_TO_64BIT (UserPrt->Length); 41367754Smsmith 414151937Sjkim /* 4) Fourth subobject: Dereference the PRT.SourceIndex */ 415151937Sjkim 416107325Siwasaki ObjDesc = SubObjectList[3]; 417281075Sdim if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER) 41887031Smsmith { 419167802Sjkim ACPI_ERROR ((AE_INFO, 420204773Sjkim "(PRT[%u].SourceIndex) Need Integer, found %s", 421107325Siwasaki Index, AcpiUtGetObjectTypeName (ObjDesc))); 42287031Smsmith return_ACPI_STATUS (AE_BAD_DATA); 42387031Smsmith } 42467754Smsmith 425193267Sjkim UserPrt->SourceIndex = (UINT32) ObjDesc->Integer.Value; 426193267Sjkim 427107325Siwasaki /* Point to the next ACPI_OPERAND_OBJECT in the top level package */ 42891116Smsmith 42987031Smsmith TopObjectList++; 43067754Smsmith } 43167754Smsmith 43291116Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", 43399679Siwasaki OutputBuffer->Pointer, (UINT32) OutputBuffer->Length)); 43467754Smsmith return_ACPI_STATUS (AE_OK); 43567754Smsmith} 43667754Smsmith 43767754Smsmith 43867754Smsmith/******************************************************************************* 43967754Smsmith * 440151937Sjkim * FUNCTION: AcpiRsCreateAmlResources 44167754Smsmith * 442281075Sdim * PARAMETERS: ResourceList - Pointer to the resource list buffer 443281075Sdim * OutputBuffer - Where the AML buffer is returned 44467754Smsmith * 44567754Smsmith * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code. 44667754Smsmith * If the OutputBuffer is too small, the error will be 44791116Smsmith * AE_BUFFER_OVERFLOW and OutputBuffer->Length will point 44867754Smsmith * to the size buffer needed. 44967754Smsmith * 450281075Sdim * DESCRIPTION: Converts a list of device resources to an AML bytestream 451281075Sdim * to be used as input for the _SRS control method. 45267754Smsmith * 45367754Smsmith ******************************************************************************/ 45467754Smsmith 45567754SmsmithACPI_STATUS 456151937SjkimAcpiRsCreateAmlResources ( 457281075Sdim ACPI_BUFFER *ResourceList, 45891116Smsmith ACPI_BUFFER *OutputBuffer) 45967754Smsmith{ 46067754Smsmith ACPI_STATUS Status; 461151937Sjkim ACPI_SIZE AmlSizeNeeded = 0; 46267754Smsmith 46367754Smsmith 464167802Sjkim ACPI_FUNCTION_TRACE (RsCreateAmlResources); 46567754Smsmith 46667754Smsmith 467281075Sdim /* Params already validated, no need to re-validate here */ 46867754Smsmith 469281075Sdim ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ResourceList Buffer = %p\n", 470281075Sdim ResourceList->Pointer)); 47167754Smsmith 472281075Sdim /* Get the buffer size needed for the AML byte stream */ 473281075Sdim 474281075Sdim Status = AcpiRsGetAmlLength (ResourceList->Pointer, 475281075Sdim ResourceList->Length, &AmlSizeNeeded); 476281075Sdim 477151937Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n", 478151937Sjkim (UINT32) AmlSizeNeeded, AcpiFormatException (Status))); 47967754Smsmith if (ACPI_FAILURE (Status)) 48067754Smsmith { 48167754Smsmith return_ACPI_STATUS (Status); 48267754Smsmith } 48367754Smsmith 48491116Smsmith /* Validate/Allocate/Clear caller buffer */ 48591116Smsmith 486151937Sjkim Status = AcpiUtInitializeBuffer (OutputBuffer, AmlSizeNeeded); 48791116Smsmith if (ACPI_FAILURE (Status)) 48867754Smsmith { 48991116Smsmith return_ACPI_STATUS (Status); 49087031Smsmith } 49167754Smsmith 49291116Smsmith /* Do the conversion */ 49367754Smsmith 494281075Sdim Status = AcpiRsConvertResourcesToAml (ResourceList->Pointer, 495281075Sdim AmlSizeNeeded, OutputBuffer->Pointer); 49687031Smsmith if (ACPI_FAILURE (Status)) 49767754Smsmith { 49887031Smsmith return_ACPI_STATUS (Status); 49967754Smsmith } 50067754Smsmith 50191116Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", 502281075Sdim OutputBuffer->Pointer, (UINT32) OutputBuffer->Length)); 50367754Smsmith return_ACPI_STATUS (AE_OK); 50467754Smsmith} 505