167754Smsmith/******************************************************************************* 267754Smsmith * 377424Smsmith * Module Name: rscreate - Create resource lists/tables 467754Smsmith * 567754Smsmith ******************************************************************************/ 667754Smsmith 7217365Sjkim/* 8306536Sjkim * Copyright (C) 2000 - 2016, 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 89306536Sjkim Status = AcpiRsGetListLength ( 90306536Sjkim AmlBuffer, AmlBufferLength, &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, 112306536Sjkim 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, 200306536Sjkim 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", 207306536Sjkim 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 258306536Sjkim Status = AcpiRsGetPciRoutingTableLength ( 259306536Sjkim PackageObject,&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 */ 281306536Sjkim TopObjectList = PackageObject->Package.Elements; 28287031Smsmith NumberOfElements = PackageObject->Package.Count; 283306536Sjkim Buffer = OutputBuffer->Pointer; 284306536Sjkim 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 /* 298306536Sjkim * Fill in the Length field with the information we have at this 299306536Sjkim * point. The minus four is to subtract the size of the UINT8 300306536Sjkim * Source[4] member 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 { 326306536Sjkim ACPI_ERROR ((AE_INFO, 327306536Sjkim "(PRT[%u].Address) Need Integer, found %s", 328107325Siwasaki Index, AcpiUtGetObjectTypeName (ObjDesc))); 32987031Smsmith return_ACPI_STATUS (AE_BAD_DATA); 33087031Smsmith } 33167754Smsmith 332193267Sjkim UserPrt->Address = ObjDesc->Integer.Value; 333193267Sjkim 334151937Sjkim /* 2) Second subobject: Dereference the PRT.Pin */ 335151937Sjkim 336107325Siwasaki ObjDesc = SubObjectList[1]; 337281075Sdim if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER) 33887031Smsmith { 339204773Sjkim ACPI_ERROR ((AE_INFO, "(PRT[%u].Pin) Need Integer, found %s", 340107325Siwasaki Index, AcpiUtGetObjectTypeName (ObjDesc))); 34187031Smsmith return_ACPI_STATUS (AE_BAD_DATA); 34287031Smsmith } 34367754Smsmith 344193267Sjkim UserPrt->Pin = (UINT32) ObjDesc->Integer.Value; 345193267Sjkim 346167802Sjkim /* 347167802Sjkim * 3) Third subobject: Dereference the PRT.SourceName 348167802Sjkim * The name may be unresolved (slack mode), so allow a null object 349167802Sjkim */ 350107325Siwasaki ObjDesc = SubObjectList[2]; 351167802Sjkim if (ObjDesc) 35287031Smsmith { 353193267Sjkim switch (ObjDesc->Common.Type) 35467754Smsmith { 355167802Sjkim case ACPI_TYPE_LOCAL_REFERENCE: 35667754Smsmith 357193267Sjkim if (ObjDesc->Reference.Class != ACPI_REFCLASS_NAME) 358167802Sjkim { 359167802Sjkim ACPI_ERROR ((AE_INFO, 360204773Sjkim "(PRT[%u].Source) Need name, found Reference Class 0x%X", 361193267Sjkim Index, ObjDesc->Reference.Class)); 362167802Sjkim return_ACPI_STATUS (AE_BAD_DATA); 363167802Sjkim } 36467754Smsmith 365167802Sjkim Node = ObjDesc->Reference.Node; 36667754Smsmith 367167802Sjkim /* Use *remaining* length of the buffer as max for pathname */ 36867754Smsmith 369167802Sjkim PathBuffer.Length = OutputBuffer->Length - 370306536Sjkim (UINT32) ((UINT8 *) UserPrt->Source - 371306536Sjkim (UINT8 *) OutputBuffer->Pointer); 372167802Sjkim PathBuffer.Pointer = UserPrt->Source; 37367754Smsmith 374306536Sjkim Status = AcpiNsHandleToPathname ( 375306536Sjkim (ACPI_HANDLE) Node, &PathBuffer, FALSE); 376151937Sjkim 377167802Sjkim /* +1 to include null terminator */ 37877424Smsmith 379306536Sjkim UserPrt->Length += (UINT32) strlen (UserPrt->Source) + 1; 380167802Sjkim break; 38173561Smsmith 382167802Sjkim case ACPI_TYPE_STRING: 38373561Smsmith 384306536Sjkim strcpy (UserPrt->Source, ObjDesc->String.Pointer); 38573561Smsmith 386167802Sjkim /* 387167802Sjkim * Add to the Length field the length of the string 388167802Sjkim * (add 1 for terminator) 389167802Sjkim */ 390167802Sjkim UserPrt->Length += ObjDesc->String.Length + 1; 391167802Sjkim break; 39273561Smsmith 393167802Sjkim case ACPI_TYPE_INTEGER: 394167802Sjkim /* 395306536Sjkim * If this is a number, then the Source Name is NULL, since 396306536Sjkim * the entire buffer was zeroed out, we can leave this alone. 397167802Sjkim * 398167802Sjkim * Add to the Length field the length of the UINT32 NULL 399167802Sjkim */ 400167802Sjkim UserPrt->Length += sizeof (UINT32); 401167802Sjkim break; 40273561Smsmith 403167802Sjkim default: 404167802Sjkim 405167802Sjkim ACPI_ERROR ((AE_INFO, 406204773Sjkim "(PRT[%u].Source) Need Ref/String/Integer, found %s", 407167802Sjkim Index, AcpiUtGetObjectTypeName (ObjDesc))); 408167802Sjkim return_ACPI_STATUS (AE_BAD_DATA); 409167802Sjkim } 41087031Smsmith } 41167754Smsmith 41287031Smsmith /* Now align the current length */ 41373561Smsmith 414167802Sjkim UserPrt->Length = (UINT32) ACPI_ROUND_UP_TO_64BIT (UserPrt->Length); 41567754Smsmith 416151937Sjkim /* 4) Fourth subobject: Dereference the PRT.SourceIndex */ 417151937Sjkim 418107325Siwasaki ObjDesc = SubObjectList[3]; 419281075Sdim if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER) 42087031Smsmith { 421167802Sjkim ACPI_ERROR ((AE_INFO, 422204773Sjkim "(PRT[%u].SourceIndex) Need Integer, found %s", 423107325Siwasaki Index, AcpiUtGetObjectTypeName (ObjDesc))); 42487031Smsmith return_ACPI_STATUS (AE_BAD_DATA); 42587031Smsmith } 42667754Smsmith 427193267Sjkim UserPrt->SourceIndex = (UINT32) ObjDesc->Integer.Value; 428193267Sjkim 429107325Siwasaki /* Point to the next ACPI_OPERAND_OBJECT in the top level package */ 43091116Smsmith 43187031Smsmith TopObjectList++; 43267754Smsmith } 43367754Smsmith 43491116Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", 435306536Sjkim OutputBuffer->Pointer, (UINT32) OutputBuffer->Length)); 43667754Smsmith return_ACPI_STATUS (AE_OK); 43767754Smsmith} 43867754Smsmith 43967754Smsmith 44067754Smsmith/******************************************************************************* 44167754Smsmith * 442151937Sjkim * FUNCTION: AcpiRsCreateAmlResources 44367754Smsmith * 444281075Sdim * PARAMETERS: ResourceList - Pointer to the resource list buffer 445281075Sdim * OutputBuffer - Where the AML buffer is returned 44667754Smsmith * 44767754Smsmith * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code. 44867754Smsmith * If the OutputBuffer is too small, the error will be 44991116Smsmith * AE_BUFFER_OVERFLOW and OutputBuffer->Length will point 45067754Smsmith * to the size buffer needed. 45167754Smsmith * 452281075Sdim * DESCRIPTION: Converts a list of device resources to an AML bytestream 453281075Sdim * to be used as input for the _SRS control method. 45467754Smsmith * 45567754Smsmith ******************************************************************************/ 45667754Smsmith 45767754SmsmithACPI_STATUS 458151937SjkimAcpiRsCreateAmlResources ( 459281075Sdim ACPI_BUFFER *ResourceList, 46091116Smsmith ACPI_BUFFER *OutputBuffer) 46167754Smsmith{ 46267754Smsmith ACPI_STATUS Status; 463151937Sjkim ACPI_SIZE AmlSizeNeeded = 0; 46467754Smsmith 46567754Smsmith 466167802Sjkim ACPI_FUNCTION_TRACE (RsCreateAmlResources); 46767754Smsmith 46867754Smsmith 469281075Sdim /* Params already validated, no need to re-validate here */ 47067754Smsmith 471281075Sdim ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ResourceList Buffer = %p\n", 472281075Sdim ResourceList->Pointer)); 47367754Smsmith 474281075Sdim /* Get the buffer size needed for the AML byte stream */ 475281075Sdim 476306536Sjkim Status = AcpiRsGetAmlLength ( 477306536Sjkim ResourceList->Pointer, ResourceList->Length, &AmlSizeNeeded); 478281075Sdim 479151937Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n", 480151937Sjkim (UINT32) AmlSizeNeeded, AcpiFormatException (Status))); 48167754Smsmith if (ACPI_FAILURE (Status)) 48267754Smsmith { 48367754Smsmith return_ACPI_STATUS (Status); 48467754Smsmith } 48567754Smsmith 48691116Smsmith /* Validate/Allocate/Clear caller buffer */ 48791116Smsmith 488151937Sjkim Status = AcpiUtInitializeBuffer (OutputBuffer, AmlSizeNeeded); 48991116Smsmith if (ACPI_FAILURE (Status)) 49067754Smsmith { 49191116Smsmith return_ACPI_STATUS (Status); 49287031Smsmith } 49367754Smsmith 49491116Smsmith /* Do the conversion */ 49567754Smsmith 496281075Sdim Status = AcpiRsConvertResourcesToAml (ResourceList->Pointer, 497306536Sjkim AmlSizeNeeded, OutputBuffer->Pointer); 49887031Smsmith if (ACPI_FAILURE (Status)) 49967754Smsmith { 50087031Smsmith return_ACPI_STATUS (Status); 50167754Smsmith } 50267754Smsmith 50391116Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", 504281075Sdim OutputBuffer->Pointer, (UINT32) OutputBuffer->Length)); 50567754Smsmith return_ACPI_STATUS (AE_OK); 50667754Smsmith} 507