1ae115bc7Smrj /******************************************************************************* 2ae115bc7Smrj * 3ae115bc7Smrj * Module Name: rscreate - Create resource lists/tables 4ae115bc7Smrj * 5ae115bc7Smrj ******************************************************************************/ 6ae115bc7Smrj 726f3cdf0SGordon Ross /* 8*385cc6b4SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp. 9ae115bc7Smrj * All rights reserved. 10ae115bc7Smrj * 1126f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without 1226f3cdf0SGordon Ross * modification, are permitted provided that the following conditions 1326f3cdf0SGordon Ross * are met: 1426f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright 1526f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer, 1626f3cdf0SGordon Ross * without modification. 1726f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1826f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below 1926f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon 2026f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further 2126f3cdf0SGordon Ross * binary redistribution. 2226f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names 2326f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived 2426f3cdf0SGordon Ross * from this software without specific prior written permission. 25ae115bc7Smrj * 2626f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the 2726f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free 2826f3cdf0SGordon Ross * Software Foundation. 29ae115bc7Smrj * 3026f3cdf0SGordon Ross * NO WARRANTY 3126f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3226f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3326f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3426f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3526f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3626f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3726f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3826f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 3926f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4026f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4126f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES. 4226f3cdf0SGordon Ross */ 43ae115bc7Smrj 44ae115bc7Smrj #include "acpi.h" 45aa2aa9a6SDana Myers #include "accommon.h" 46ae115bc7Smrj #include "acresrc.h" 47ae115bc7Smrj #include "acnamesp.h" 48ae115bc7Smrj 49ae115bc7Smrj #define _COMPONENT ACPI_RESOURCES 50ae115bc7Smrj ACPI_MODULE_NAME ("rscreate") 51ae115bc7Smrj 52ae115bc7Smrj 53ae115bc7Smrj /******************************************************************************* 54ae115bc7Smrj * 55*385cc6b4SJerry Jelinek * FUNCTION: AcpiBufferToResource 56*385cc6b4SJerry Jelinek * 57*385cc6b4SJerry Jelinek * PARAMETERS: AmlBuffer - Pointer to the resource byte stream 58*385cc6b4SJerry Jelinek * AmlBufferLength - Length of the AmlBuffer 59*385cc6b4SJerry Jelinek * ResourcePtr - Where the converted resource is returned 60*385cc6b4SJerry Jelinek * 61*385cc6b4SJerry Jelinek * RETURN: Status 62*385cc6b4SJerry Jelinek * 63*385cc6b4SJerry Jelinek * DESCRIPTION: Convert a raw AML buffer to a resource list 64*385cc6b4SJerry Jelinek * 65*385cc6b4SJerry Jelinek ******************************************************************************/ 66*385cc6b4SJerry Jelinek 67*385cc6b4SJerry Jelinek ACPI_STATUS 68*385cc6b4SJerry Jelinek AcpiBufferToResource ( 69*385cc6b4SJerry Jelinek UINT8 *AmlBuffer, 70*385cc6b4SJerry Jelinek UINT16 AmlBufferLength, 71*385cc6b4SJerry Jelinek ACPI_RESOURCE **ResourcePtr) 72*385cc6b4SJerry Jelinek { 73*385cc6b4SJerry Jelinek ACPI_STATUS Status; 74*385cc6b4SJerry Jelinek ACPI_SIZE ListSizeNeeded; 75*385cc6b4SJerry Jelinek void *Resource; 76*385cc6b4SJerry Jelinek void *CurrentResourcePtr; 77*385cc6b4SJerry Jelinek 78*385cc6b4SJerry Jelinek 79*385cc6b4SJerry Jelinek ACPI_FUNCTION_TRACE (AcpiBufferToResource); 80*385cc6b4SJerry Jelinek 81*385cc6b4SJerry Jelinek 82*385cc6b4SJerry Jelinek /* 83*385cc6b4SJerry Jelinek * Note: we allow AE_AML_NO_RESOURCE_END_TAG, since an end tag 84*385cc6b4SJerry Jelinek * is not required here. 85*385cc6b4SJerry Jelinek */ 86*385cc6b4SJerry Jelinek 87*385cc6b4SJerry Jelinek /* Get the required length for the converted resource */ 88*385cc6b4SJerry Jelinek 89*385cc6b4SJerry Jelinek Status = AcpiRsGetListLength ( 90*385cc6b4SJerry Jelinek AmlBuffer, AmlBufferLength, &ListSizeNeeded); 91*385cc6b4SJerry Jelinek if (Status == AE_AML_NO_RESOURCE_END_TAG) 92*385cc6b4SJerry Jelinek { 93*385cc6b4SJerry Jelinek Status = AE_OK; 94*385cc6b4SJerry Jelinek } 95*385cc6b4SJerry Jelinek if (ACPI_FAILURE (Status)) 96*385cc6b4SJerry Jelinek { 97*385cc6b4SJerry Jelinek return_ACPI_STATUS (Status); 98*385cc6b4SJerry Jelinek } 99*385cc6b4SJerry Jelinek 100*385cc6b4SJerry Jelinek /* Allocate a buffer for the converted resource */ 101*385cc6b4SJerry Jelinek 102*385cc6b4SJerry Jelinek Resource = ACPI_ALLOCATE_ZEROED (ListSizeNeeded); 103*385cc6b4SJerry Jelinek CurrentResourcePtr = Resource; 104*385cc6b4SJerry Jelinek if (!Resource) 105*385cc6b4SJerry Jelinek { 106*385cc6b4SJerry Jelinek return_ACPI_STATUS (AE_NO_MEMORY); 107*385cc6b4SJerry Jelinek } 108*385cc6b4SJerry Jelinek 109*385cc6b4SJerry Jelinek /* Perform the AML-to-Resource conversion */ 110*385cc6b4SJerry Jelinek 111*385cc6b4SJerry Jelinek Status = AcpiUtWalkAmlResources (NULL, AmlBuffer, AmlBufferLength, 112*385cc6b4SJerry Jelinek AcpiRsConvertAmlToResources, &CurrentResourcePtr); 113*385cc6b4SJerry Jelinek if (Status == AE_AML_NO_RESOURCE_END_TAG) 114*385cc6b4SJerry Jelinek { 115*385cc6b4SJerry Jelinek Status = AE_OK; 116*385cc6b4SJerry Jelinek } 117*385cc6b4SJerry Jelinek if (ACPI_FAILURE (Status)) 118*385cc6b4SJerry Jelinek { 119*385cc6b4SJerry Jelinek ACPI_FREE (Resource); 120*385cc6b4SJerry Jelinek } 121*385cc6b4SJerry Jelinek else 122*385cc6b4SJerry Jelinek { 123*385cc6b4SJerry Jelinek *ResourcePtr = Resource; 124*385cc6b4SJerry Jelinek } 125*385cc6b4SJerry Jelinek 126*385cc6b4SJerry Jelinek return_ACPI_STATUS (Status); 127*385cc6b4SJerry Jelinek } 128*385cc6b4SJerry Jelinek 129*385cc6b4SJerry Jelinek ACPI_EXPORT_SYMBOL (AcpiBufferToResource) 130*385cc6b4SJerry Jelinek 131*385cc6b4SJerry Jelinek 132*385cc6b4SJerry Jelinek /******************************************************************************* 133*385cc6b4SJerry Jelinek * 134ae115bc7Smrj * FUNCTION: AcpiRsCreateResourceList 135ae115bc7Smrj * 136ae115bc7Smrj * PARAMETERS: AmlBuffer - Pointer to the resource byte stream 137ae115bc7Smrj * OutputBuffer - Pointer to the user's buffer 138ae115bc7Smrj * 139ae115bc7Smrj * RETURN: Status: AE_OK if okay, else a valid ACPI_STATUS code 140ae115bc7Smrj * If OutputBuffer is not large enough, OutputBufferLength 141ae115bc7Smrj * indicates how large OutputBuffer should be, else it 142ae115bc7Smrj * indicates how may UINT8 elements of OutputBuffer are valid. 143ae115bc7Smrj * 144ae115bc7Smrj * DESCRIPTION: Takes the byte stream returned from a _CRS, _PRS control method 145ae115bc7Smrj * execution and parses the stream to create a linked list 146ae115bc7Smrj * of device resources. 147ae115bc7Smrj * 148ae115bc7Smrj ******************************************************************************/ 149ae115bc7Smrj 150ae115bc7Smrj ACPI_STATUS 151ae115bc7Smrj AcpiRsCreateResourceList ( 152ae115bc7Smrj ACPI_OPERAND_OBJECT *AmlBuffer, 153ae115bc7Smrj ACPI_BUFFER *OutputBuffer) 154ae115bc7Smrj { 155ae115bc7Smrj 156ae115bc7Smrj ACPI_STATUS Status; 157ae115bc7Smrj UINT8 *AmlStart; 158ae115bc7Smrj ACPI_SIZE ListSizeNeeded = 0; 159ae115bc7Smrj UINT32 AmlBufferLength; 160ae115bc7Smrj void *Resource; 161ae115bc7Smrj 162ae115bc7Smrj 163ae115bc7Smrj ACPI_FUNCTION_TRACE (RsCreateResourceList); 164ae115bc7Smrj 165ae115bc7Smrj 166ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlBuffer = %p\n", 167ae115bc7Smrj AmlBuffer)); 168ae115bc7Smrj 169ae115bc7Smrj /* Params already validated, so we don't re-validate here */ 170ae115bc7Smrj 171ae115bc7Smrj AmlBufferLength = AmlBuffer->Buffer.Length; 172ae115bc7Smrj AmlStart = AmlBuffer->Buffer.Pointer; 173ae115bc7Smrj 174ae115bc7Smrj /* 175ae115bc7Smrj * Pass the AmlBuffer into a module that can calculate 176ae115bc7Smrj * the buffer size needed for the linked list 177ae115bc7Smrj */ 178ae115bc7Smrj Status = AcpiRsGetListLength (AmlStart, AmlBufferLength, 179ae115bc7Smrj &ListSizeNeeded); 180ae115bc7Smrj 181ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status=%X ListSizeNeeded=%X\n", 182ae115bc7Smrj Status, (UINT32) ListSizeNeeded)); 183ae115bc7Smrj if (ACPI_FAILURE (Status)) 184ae115bc7Smrj { 185ae115bc7Smrj return_ACPI_STATUS (Status); 186ae115bc7Smrj } 187ae115bc7Smrj 188ae115bc7Smrj /* Validate/Allocate/Clear caller buffer */ 189ae115bc7Smrj 190ae115bc7Smrj Status = AcpiUtInitializeBuffer (OutputBuffer, ListSizeNeeded); 191ae115bc7Smrj if (ACPI_FAILURE (Status)) 192ae115bc7Smrj { 193ae115bc7Smrj return_ACPI_STATUS (Status); 194ae115bc7Smrj } 195ae115bc7Smrj 196ae115bc7Smrj /* Do the conversion */ 197ae115bc7Smrj 198ae115bc7Smrj Resource = OutputBuffer->Pointer; 199*385cc6b4SJerry Jelinek Status = AcpiUtWalkAmlResources (NULL, AmlStart, AmlBufferLength, 200ae115bc7Smrj AcpiRsConvertAmlToResources, &Resource); 201ae115bc7Smrj if (ACPI_FAILURE (Status)) 202ae115bc7Smrj { 203ae115bc7Smrj return_ACPI_STATUS (Status); 204ae115bc7Smrj } 205ae115bc7Smrj 206ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", 207ae115bc7Smrj OutputBuffer->Pointer, (UINT32) OutputBuffer->Length)); 208ae115bc7Smrj return_ACPI_STATUS (AE_OK); 209ae115bc7Smrj } 210ae115bc7Smrj 211ae115bc7Smrj 212ae115bc7Smrj /******************************************************************************* 213ae115bc7Smrj * 214ae115bc7Smrj * FUNCTION: AcpiRsCreatePciRoutingTable 215ae115bc7Smrj * 216*385cc6b4SJerry Jelinek * PARAMETERS: PackageObject - Pointer to a package containing one 217*385cc6b4SJerry Jelinek * of more ACPI_OPERAND_OBJECTs 218ae115bc7Smrj * OutputBuffer - Pointer to the user's buffer 219ae115bc7Smrj * 220ae115bc7Smrj * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code. 221ae115bc7Smrj * If the OutputBuffer is too small, the error will be 222ae115bc7Smrj * AE_BUFFER_OVERFLOW and OutputBuffer->Length will point 223ae115bc7Smrj * to the size buffer needed. 224ae115bc7Smrj * 225ae115bc7Smrj * DESCRIPTION: Takes the ACPI_OPERAND_OBJECT package and creates a 226ae115bc7Smrj * linked list of PCI interrupt descriptions 227ae115bc7Smrj * 228ae115bc7Smrj * NOTE: It is the caller's responsibility to ensure that the start of the 229ae115bc7Smrj * output buffer is aligned properly (if necessary). 230ae115bc7Smrj * 231ae115bc7Smrj ******************************************************************************/ 232ae115bc7Smrj 233ae115bc7Smrj ACPI_STATUS 234ae115bc7Smrj AcpiRsCreatePciRoutingTable ( 235ae115bc7Smrj ACPI_OPERAND_OBJECT *PackageObject, 236ae115bc7Smrj ACPI_BUFFER *OutputBuffer) 237ae115bc7Smrj { 238ae115bc7Smrj UINT8 *Buffer; 239ae115bc7Smrj ACPI_OPERAND_OBJECT **TopObjectList; 240ae115bc7Smrj ACPI_OPERAND_OBJECT **SubObjectList; 241ae115bc7Smrj ACPI_OPERAND_OBJECT *ObjDesc; 242ae115bc7Smrj ACPI_SIZE BufferSizeNeeded = 0; 243ae115bc7Smrj UINT32 NumberOfElements; 244ae115bc7Smrj UINT32 Index; 245ae115bc7Smrj ACPI_PCI_ROUTING_TABLE *UserPrt; 246ae115bc7Smrj ACPI_NAMESPACE_NODE *Node; 247ae115bc7Smrj ACPI_STATUS Status; 248ae115bc7Smrj ACPI_BUFFER PathBuffer; 249ae115bc7Smrj 250ae115bc7Smrj 251ae115bc7Smrj ACPI_FUNCTION_TRACE (RsCreatePciRoutingTable); 252ae115bc7Smrj 253ae115bc7Smrj 254ae115bc7Smrj /* Params already validated, so we don't re-validate here */ 255ae115bc7Smrj 256ae115bc7Smrj /* Get the required buffer length */ 257ae115bc7Smrj 258*385cc6b4SJerry Jelinek Status = AcpiRsGetPciRoutingTableLength ( 259*385cc6b4SJerry Jelinek PackageObject,&BufferSizeNeeded); 260ae115bc7Smrj if (ACPI_FAILURE (Status)) 261ae115bc7Smrj { 262ae115bc7Smrj return_ACPI_STATUS (Status); 263ae115bc7Smrj } 264ae115bc7Smrj 265ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "BufferSizeNeeded = %X\n", 266ae115bc7Smrj (UINT32) BufferSizeNeeded)); 267ae115bc7Smrj 268ae115bc7Smrj /* Validate/Allocate/Clear caller buffer */ 269ae115bc7Smrj 270ae115bc7Smrj Status = AcpiUtInitializeBuffer (OutputBuffer, BufferSizeNeeded); 271ae115bc7Smrj if (ACPI_FAILURE (Status)) 272ae115bc7Smrj { 273ae115bc7Smrj return_ACPI_STATUS (Status); 274ae115bc7Smrj } 275ae115bc7Smrj 276ae115bc7Smrj /* 277db2bae30SDana Myers * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a 27826f3cdf0SGordon Ross * package that in turn contains an UINT64 Address, a UINT8 Pin, 279db2bae30SDana Myers * a Name, and a UINT8 SourceIndex. 280ae115bc7Smrj */ 281ae115bc7Smrj TopObjectList = PackageObject->Package.Elements; 282ae115bc7Smrj NumberOfElements = PackageObject->Package.Count; 283ae115bc7Smrj Buffer = OutputBuffer->Pointer; 284ae115bc7Smrj UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer); 285ae115bc7Smrj 286ae115bc7Smrj for (Index = 0; Index < NumberOfElements; Index++) 287ae115bc7Smrj { 288ae115bc7Smrj /* 289ae115bc7Smrj * Point UserPrt past this current structure 290ae115bc7Smrj * 291ae115bc7Smrj * NOTE: On the first iteration, UserPrt->Length will 292ae115bc7Smrj * be zero because we cleared the return buffer earlier 293ae115bc7Smrj */ 294ae115bc7Smrj Buffer += UserPrt->Length; 295ae115bc7Smrj UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer); 296ae115bc7Smrj 297ae115bc7Smrj /* 298*385cc6b4SJerry Jelinek * Fill in the Length field with the information we have at this 299*385cc6b4SJerry Jelinek * point. The minus four is to subtract the size of the UINT8 300*385cc6b4SJerry Jelinek * Source[4] member because it is added below. 301ae115bc7Smrj */ 302ae115bc7Smrj UserPrt->Length = (sizeof (ACPI_PCI_ROUTING_TABLE) - 4); 303ae115bc7Smrj 304*385cc6b4SJerry Jelinek /* Each subpackage must be of length 4 */ 305ae115bc7Smrj 306ae115bc7Smrj if ((*TopObjectList)->Package.Count != 4) 307ae115bc7Smrj { 308ae115bc7Smrj ACPI_ERROR ((AE_INFO, 30926f3cdf0SGordon Ross "(PRT[%u]) Need package of length 4, found length %u", 310ae115bc7Smrj Index, (*TopObjectList)->Package.Count)); 311ae115bc7Smrj return_ACPI_STATUS (AE_AML_PACKAGE_LIMIT); 312ae115bc7Smrj } 313ae115bc7Smrj 314ae115bc7Smrj /* 315*385cc6b4SJerry Jelinek * Dereference the subpackage. 316ae115bc7Smrj * The SubObjectList will now point to an array of the four IRQ 317ae115bc7Smrj * elements: [Address, Pin, Source, SourceIndex] 318ae115bc7Smrj */ 319ae115bc7Smrj SubObjectList = (*TopObjectList)->Package.Elements; 320ae115bc7Smrj 321ae115bc7Smrj /* 1) First subobject: Dereference the PRT.Address */ 322ae115bc7Smrj 323ae115bc7Smrj ObjDesc = SubObjectList[0]; 324*385cc6b4SJerry Jelinek if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER) 325ae115bc7Smrj { 326*385cc6b4SJerry Jelinek ACPI_ERROR ((AE_INFO, 327*385cc6b4SJerry Jelinek "(PRT[%u].Address) Need Integer, found %s", 328ae115bc7Smrj Index, AcpiUtGetObjectTypeName (ObjDesc))); 329ae115bc7Smrj return_ACPI_STATUS (AE_BAD_DATA); 330ae115bc7Smrj } 331ae115bc7Smrj 332db2bae30SDana Myers UserPrt->Address = ObjDesc->Integer.Value; 333db2bae30SDana Myers 334ae115bc7Smrj /* 2) Second subobject: Dereference the PRT.Pin */ 335ae115bc7Smrj 336ae115bc7Smrj ObjDesc = SubObjectList[1]; 337*385cc6b4SJerry Jelinek if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER) 338ae115bc7Smrj { 33926f3cdf0SGordon Ross ACPI_ERROR ((AE_INFO, "(PRT[%u].Pin) Need Integer, found %s", 340ae115bc7Smrj Index, AcpiUtGetObjectTypeName (ObjDesc))); 341ae115bc7Smrj return_ACPI_STATUS (AE_BAD_DATA); 342ae115bc7Smrj } 343ae115bc7Smrj 344db2bae30SDana Myers UserPrt->Pin = (UINT32) ObjDesc->Integer.Value; 345db2bae30SDana Myers 346db2bae30SDana Myers /* 347ae115bc7Smrj * 3) Third subobject: Dereference the PRT.SourceName 348ae115bc7Smrj * The name may be unresolved (slack mode), so allow a null object 349ae115bc7Smrj */ 350ae115bc7Smrj ObjDesc = SubObjectList[2]; 351ae115bc7Smrj if (ObjDesc) 352ae115bc7Smrj { 353aa2aa9a6SDana Myers switch (ObjDesc->Common.Type) 354ae115bc7Smrj { 355ae115bc7Smrj case ACPI_TYPE_LOCAL_REFERENCE: 356ae115bc7Smrj 357db2bae30SDana Myers if (ObjDesc->Reference.Class != ACPI_REFCLASS_NAME) 358ae115bc7Smrj { 359ae115bc7Smrj ACPI_ERROR ((AE_INFO, 36026f3cdf0SGordon Ross "(PRT[%u].Source) Need name, found Reference Class 0x%X", 361db2bae30SDana Myers Index, ObjDesc->Reference.Class)); 362ae115bc7Smrj return_ACPI_STATUS (AE_BAD_DATA); 363ae115bc7Smrj } 364ae115bc7Smrj 365ae115bc7Smrj Node = ObjDesc->Reference.Node; 366ae115bc7Smrj 367ae115bc7Smrj /* Use *remaining* length of the buffer as max for pathname */ 368ae115bc7Smrj 369ae115bc7Smrj PathBuffer.Length = OutputBuffer->Length - 370ae115bc7Smrj (UINT32) ((UINT8 *) UserPrt->Source - 371ae115bc7Smrj (UINT8 *) OutputBuffer->Pointer); 372ae115bc7Smrj PathBuffer.Pointer = UserPrt->Source; 373ae115bc7Smrj 374*385cc6b4SJerry Jelinek Status = AcpiNsHandleToPathname ( 375*385cc6b4SJerry Jelinek (ACPI_HANDLE) Node, &PathBuffer, FALSE); 376ae115bc7Smrj 377ae115bc7Smrj /* +1 to include null terminator */ 378ae115bc7Smrj 379*385cc6b4SJerry Jelinek UserPrt->Length += (UINT32) strlen (UserPrt->Source) + 1; 380ae115bc7Smrj break; 381ae115bc7Smrj 382ae115bc7Smrj case ACPI_TYPE_STRING: 383ae115bc7Smrj 384*385cc6b4SJerry Jelinek strcpy (UserPrt->Source, ObjDesc->String.Pointer); 385ae115bc7Smrj 386ae115bc7Smrj /* 387ae115bc7Smrj * Add to the Length field the length of the string 388ae115bc7Smrj * (add 1 for terminator) 389ae115bc7Smrj */ 390ae115bc7Smrj UserPrt->Length += ObjDesc->String.Length + 1; 391ae115bc7Smrj break; 392ae115bc7Smrj 393ae115bc7Smrj case ACPI_TYPE_INTEGER: 394ae115bc7Smrj /* 395*385cc6b4SJerry Jelinek * If this is a number, then the Source Name is NULL, since 396*385cc6b4SJerry Jelinek * the entire buffer was zeroed out, we can leave this alone. 397ae115bc7Smrj * 398ae115bc7Smrj * Add to the Length field the length of the UINT32 NULL 399ae115bc7Smrj */ 400ae115bc7Smrj UserPrt->Length += sizeof (UINT32); 401ae115bc7Smrj break; 402ae115bc7Smrj 403ae115bc7Smrj default: 404ae115bc7Smrj 405ae115bc7Smrj ACPI_ERROR ((AE_INFO, 40626f3cdf0SGordon Ross "(PRT[%u].Source) Need Ref/String/Integer, found %s", 407ae115bc7Smrj Index, AcpiUtGetObjectTypeName (ObjDesc))); 408ae115bc7Smrj return_ACPI_STATUS (AE_BAD_DATA); 409ae115bc7Smrj } 410ae115bc7Smrj } 411ae115bc7Smrj 412ae115bc7Smrj /* Now align the current length */ 413ae115bc7Smrj 414ae115bc7Smrj UserPrt->Length = (UINT32) ACPI_ROUND_UP_TO_64BIT (UserPrt->Length); 415ae115bc7Smrj 416ae115bc7Smrj /* 4) Fourth subobject: Dereference the PRT.SourceIndex */ 417ae115bc7Smrj 418ae115bc7Smrj ObjDesc = SubObjectList[3]; 419*385cc6b4SJerry Jelinek if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER) 420ae115bc7Smrj { 421ae115bc7Smrj ACPI_ERROR ((AE_INFO, 42226f3cdf0SGordon Ross "(PRT[%u].SourceIndex) Need Integer, found %s", 423ae115bc7Smrj Index, AcpiUtGetObjectTypeName (ObjDesc))); 424ae115bc7Smrj return_ACPI_STATUS (AE_BAD_DATA); 425ae115bc7Smrj } 426ae115bc7Smrj 427db2bae30SDana Myers UserPrt->SourceIndex = (UINT32) ObjDesc->Integer.Value; 428db2bae30SDana Myers 429ae115bc7Smrj /* Point to the next ACPI_OPERAND_OBJECT in the top level package */ 430ae115bc7Smrj 431ae115bc7Smrj TopObjectList++; 432ae115bc7Smrj } 433ae115bc7Smrj 434ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", 435ae115bc7Smrj OutputBuffer->Pointer, (UINT32) OutputBuffer->Length)); 436ae115bc7Smrj return_ACPI_STATUS (AE_OK); 437ae115bc7Smrj } 438ae115bc7Smrj 439ae115bc7Smrj 440ae115bc7Smrj /******************************************************************************* 441ae115bc7Smrj * 442ae115bc7Smrj * FUNCTION: AcpiRsCreateAmlResources 443ae115bc7Smrj * 444*385cc6b4SJerry Jelinek * PARAMETERS: ResourceList - Pointer to the resource list buffer 445*385cc6b4SJerry Jelinek * OutputBuffer - Where the AML buffer is returned 446ae115bc7Smrj * 447ae115bc7Smrj * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code. 448ae115bc7Smrj * If the OutputBuffer is too small, the error will be 449ae115bc7Smrj * AE_BUFFER_OVERFLOW and OutputBuffer->Length will point 450ae115bc7Smrj * to the size buffer needed. 451ae115bc7Smrj * 452*385cc6b4SJerry Jelinek * DESCRIPTION: Converts a list of device resources to an AML bytestream 453*385cc6b4SJerry Jelinek * to be used as input for the _SRS control method. 454ae115bc7Smrj * 455ae115bc7Smrj ******************************************************************************/ 456ae115bc7Smrj 457ae115bc7Smrj ACPI_STATUS 458ae115bc7Smrj AcpiRsCreateAmlResources ( 459*385cc6b4SJerry Jelinek ACPI_BUFFER *ResourceList, 460ae115bc7Smrj ACPI_BUFFER *OutputBuffer) 461ae115bc7Smrj { 462ae115bc7Smrj ACPI_STATUS Status; 463ae115bc7Smrj ACPI_SIZE AmlSizeNeeded = 0; 464ae115bc7Smrj 465ae115bc7Smrj 466ae115bc7Smrj ACPI_FUNCTION_TRACE (RsCreateAmlResources); 467ae115bc7Smrj 468ae115bc7Smrj 469*385cc6b4SJerry Jelinek /* Params already validated, no need to re-validate here */ 470ae115bc7Smrj 471*385cc6b4SJerry Jelinek ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ResourceList Buffer = %p\n", 472*385cc6b4SJerry Jelinek ResourceList->Pointer)); 473*385cc6b4SJerry Jelinek 474*385cc6b4SJerry Jelinek /* Get the buffer size needed for the AML byte stream */ 475*385cc6b4SJerry Jelinek 476*385cc6b4SJerry Jelinek Status = AcpiRsGetAmlLength ( 477*385cc6b4SJerry Jelinek ResourceList->Pointer, ResourceList->Length, &AmlSizeNeeded); 478ae115bc7Smrj 479ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "AmlSizeNeeded=%X, %s\n", 480ae115bc7Smrj (UINT32) AmlSizeNeeded, AcpiFormatException (Status))); 481ae115bc7Smrj if (ACPI_FAILURE (Status)) 482ae115bc7Smrj { 483ae115bc7Smrj return_ACPI_STATUS (Status); 484ae115bc7Smrj } 485ae115bc7Smrj 486ae115bc7Smrj /* Validate/Allocate/Clear caller buffer */ 487ae115bc7Smrj 488ae115bc7Smrj Status = AcpiUtInitializeBuffer (OutputBuffer, AmlSizeNeeded); 489ae115bc7Smrj if (ACPI_FAILURE (Status)) 490ae115bc7Smrj { 491ae115bc7Smrj return_ACPI_STATUS (Status); 492ae115bc7Smrj } 493ae115bc7Smrj 494ae115bc7Smrj /* Do the conversion */ 495ae115bc7Smrj 496*385cc6b4SJerry Jelinek Status = AcpiRsConvertResourcesToAml (ResourceList->Pointer, 497*385cc6b4SJerry Jelinek AmlSizeNeeded, OutputBuffer->Pointer); 498ae115bc7Smrj if (ACPI_FAILURE (Status)) 499ae115bc7Smrj { 500ae115bc7Smrj return_ACPI_STATUS (Status); 501ae115bc7Smrj } 502ae115bc7Smrj 503ae115bc7Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", 504ae115bc7Smrj OutputBuffer->Pointer, (UINT32) OutputBuffer->Length)); 505ae115bc7Smrj return_ACPI_STATUS (AE_OK); 506ae115bc7Smrj } 507