1*3446Smrj /******************************************************************************* 2*3446Smrj * 3*3446Smrj * Module Name: rsutils - Utilities for the resource manager 4*3446Smrj * $Revision: 1.66 $ 5*3446Smrj * 6*3446Smrj ******************************************************************************/ 7*3446Smrj 8*3446Smrj /****************************************************************************** 9*3446Smrj * 10*3446Smrj * 1. Copyright Notice 11*3446Smrj * 12*3446Smrj * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp. 13*3446Smrj * All rights reserved. 14*3446Smrj * 15*3446Smrj * 2. License 16*3446Smrj * 17*3446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property 18*3446Smrj * rights. You may have additional license terms from the party that provided 19*3446Smrj * you this software, covering your right to use that party's intellectual 20*3446Smrj * property rights. 21*3446Smrj * 22*3446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23*3446Smrj * copy of the source code appearing in this file ("Covered Code") an 24*3446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25*3446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy, 26*3446Smrj * make derivatives, distribute, use and display any portion of the Covered 27*3446Smrj * Code in any form, with the right to sublicense such rights; and 28*3446Smrj * 29*3446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30*3446Smrj * license (with the right to sublicense), under only those claims of Intel 31*3446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell, 32*3446Smrj * offer to sell, and import the Covered Code and derivative works thereof 33*3446Smrj * solely to the minimum extent necessary to exercise the above copyright 34*3446Smrj * license, and in no event shall the patent license extend to any additions 35*3446Smrj * to or modifications of the Original Intel Code. No other license or right 36*3446Smrj * is granted directly or by implication, estoppel or otherwise; 37*3446Smrj * 38*3446Smrj * The above copyright and patent license is granted only if the following 39*3446Smrj * conditions are met: 40*3446Smrj * 41*3446Smrj * 3. Conditions 42*3446Smrj * 43*3446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44*3446Smrj * Redistribution of source code of any substantial portion of the Covered 45*3446Smrj * Code or modification with rights to further distribute source must include 46*3446Smrj * the above Copyright Notice, the above License, this list of Conditions, 47*3446Smrj * and the following Disclaimer and Export Compliance provision. In addition, 48*3446Smrj * Licensee must cause all Covered Code to which Licensee contributes to 49*3446Smrj * contain a file documenting the changes Licensee made to create that Covered 50*3446Smrj * Code and the date of any change. Licensee must include in that file the 51*3446Smrj * documentation of any changes made by any predecessor Licensee. Licensee 52*3446Smrj * must include a prominent statement that the modification is derived, 53*3446Smrj * directly or indirectly, from Original Intel Code. 54*3446Smrj * 55*3446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56*3446Smrj * Redistribution of source code of any substantial portion of the Covered 57*3446Smrj * Code or modification without rights to further distribute source must 58*3446Smrj * include the following Disclaimer and Export Compliance provision in the 59*3446Smrj * documentation and/or other materials provided with distribution. In 60*3446Smrj * addition, Licensee may not authorize further sublicense of source of any 61*3446Smrj * portion of the Covered Code, and must include terms to the effect that the 62*3446Smrj * license from Licensee to its licensee is limited to the intellectual 63*3446Smrj * property embodied in the software Licensee provides to its licensee, and 64*3446Smrj * not to intellectual property embodied in modifications its licensee may 65*3446Smrj * make. 66*3446Smrj * 67*3446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any 68*3446Smrj * substantial portion of the Covered Code or modification must reproduce the 69*3446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance 70*3446Smrj * provision in the documentation and/or other materials provided with the 71*3446Smrj * distribution. 72*3446Smrj * 73*3446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original 74*3446Smrj * Intel Code. 75*3446Smrj * 76*3446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77*3446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or 78*3446Smrj * other dealings in products derived from or relating to the Covered Code 79*3446Smrj * without prior written authorization from Intel. 80*3446Smrj * 81*3446Smrj * 4. Disclaimer and Export Compliance 82*3446Smrj * 83*3446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84*3446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85*3446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86*3446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87*3446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88*3446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89*3446Smrj * PARTICULAR PURPOSE. 90*3446Smrj * 91*3446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92*3446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93*3446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94*3446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95*3446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96*3446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97*3446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98*3446Smrj * LIMITED REMEDY. 99*3446Smrj * 100*3446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this 101*3446Smrj * software or system incorporating such software without first obtaining any 102*3446Smrj * required license or other approval from the U. S. Department of Commerce or 103*3446Smrj * any other agency or department of the United States Government. In the 104*3446Smrj * event Licensee exports any such software from the United States or 105*3446Smrj * re-exports any such software from a foreign destination, Licensee shall 106*3446Smrj * ensure that the distribution and export/re-export of the software is in 107*3446Smrj * compliance with all laws, regulations, orders, or other restrictions of the 108*3446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109*3446Smrj * any of its subsidiaries will export/re-export any technical data, process, 110*3446Smrj * software, or service, directly or indirectly, to any country for which the 111*3446Smrj * United States government or any agency thereof requires an export license, 112*3446Smrj * other governmental approval, or letter of assurance, without first obtaining 113*3446Smrj * such license, approval or letter. 114*3446Smrj * 115*3446Smrj *****************************************************************************/ 116*3446Smrj 117*3446Smrj 118*3446Smrj #define __RSUTILS_C__ 119*3446Smrj 120*3446Smrj #include "acpi.h" 121*3446Smrj #include "acnamesp.h" 122*3446Smrj #include "acresrc.h" 123*3446Smrj 124*3446Smrj 125*3446Smrj #define _COMPONENT ACPI_RESOURCES 126*3446Smrj ACPI_MODULE_NAME ("rsutils") 127*3446Smrj 128*3446Smrj 129*3446Smrj /******************************************************************************* 130*3446Smrj * 131*3446Smrj * FUNCTION: AcpiRsDecodeBitmask 132*3446Smrj * 133*3446Smrj * PARAMETERS: Mask - Bitmask to decode 134*3446Smrj * List - Where the converted list is returned 135*3446Smrj * 136*3446Smrj * RETURN: Count of bits set (length of list) 137*3446Smrj * 138*3446Smrj * DESCRIPTION: Convert a bit mask into a list of values 139*3446Smrj * 140*3446Smrj ******************************************************************************/ 141*3446Smrj 142*3446Smrj UINT8 143*3446Smrj AcpiRsDecodeBitmask ( 144*3446Smrj UINT16 Mask, 145*3446Smrj UINT8 *List) 146*3446Smrj { 147*3446Smrj ACPI_NATIVE_UINT i; 148*3446Smrj UINT8 BitCount; 149*3446Smrj 150*3446Smrj 151*3446Smrj ACPI_FUNCTION_ENTRY (); 152*3446Smrj 153*3446Smrj 154*3446Smrj /* Decode the mask bits */ 155*3446Smrj 156*3446Smrj for (i = 0, BitCount = 0; Mask; i++) 157*3446Smrj { 158*3446Smrj if (Mask & 0x0001) 159*3446Smrj { 160*3446Smrj List[BitCount] = (UINT8) i; 161*3446Smrj BitCount++; 162*3446Smrj } 163*3446Smrj 164*3446Smrj Mask >>= 1; 165*3446Smrj } 166*3446Smrj 167*3446Smrj return (BitCount); 168*3446Smrj } 169*3446Smrj 170*3446Smrj 171*3446Smrj /******************************************************************************* 172*3446Smrj * 173*3446Smrj * FUNCTION: AcpiRsEncodeBitmask 174*3446Smrj * 175*3446Smrj * PARAMETERS: List - List of values to encode 176*3446Smrj * Count - Length of list 177*3446Smrj * 178*3446Smrj * RETURN: Encoded bitmask 179*3446Smrj * 180*3446Smrj * DESCRIPTION: Convert a list of values to an encoded bitmask 181*3446Smrj * 182*3446Smrj ******************************************************************************/ 183*3446Smrj 184*3446Smrj UINT16 185*3446Smrj AcpiRsEncodeBitmask ( 186*3446Smrj UINT8 *List, 187*3446Smrj UINT8 Count) 188*3446Smrj { 189*3446Smrj ACPI_NATIVE_UINT i; 190*3446Smrj UINT16 Mask; 191*3446Smrj 192*3446Smrj 193*3446Smrj ACPI_FUNCTION_ENTRY (); 194*3446Smrj 195*3446Smrj 196*3446Smrj /* Encode the list into a single bitmask */ 197*3446Smrj 198*3446Smrj for (i = 0, Mask = 0; i < Count; i++) 199*3446Smrj { 200*3446Smrj Mask |= (0x0001 << List[i]); 201*3446Smrj } 202*3446Smrj 203*3446Smrj return (Mask); 204*3446Smrj } 205*3446Smrj 206*3446Smrj 207*3446Smrj /******************************************************************************* 208*3446Smrj * 209*3446Smrj * FUNCTION: AcpiRsMoveData 210*3446Smrj * 211*3446Smrj * PARAMETERS: Destination - Pointer to the destination descriptor 212*3446Smrj * Source - Pointer to the source descriptor 213*3446Smrj * ItemCount - How many items to move 214*3446Smrj * MoveType - Byte width 215*3446Smrj * 216*3446Smrj * RETURN: None 217*3446Smrj * 218*3446Smrj * DESCRIPTION: Move multiple data items from one descriptor to another. Handles 219*3446Smrj * alignment issues and endian issues if necessary, as configured 220*3446Smrj * via the ACPI_MOVE_* macros. (This is why a memcpy is not used) 221*3446Smrj * 222*3446Smrj ******************************************************************************/ 223*3446Smrj 224*3446Smrj void 225*3446Smrj AcpiRsMoveData ( 226*3446Smrj void *Destination, 227*3446Smrj void *Source, 228*3446Smrj UINT16 ItemCount, 229*3446Smrj UINT8 MoveType) 230*3446Smrj { 231*3446Smrj ACPI_NATIVE_UINT i; 232*3446Smrj 233*3446Smrj 234*3446Smrj ACPI_FUNCTION_ENTRY (); 235*3446Smrj 236*3446Smrj 237*3446Smrj /* One move per item */ 238*3446Smrj 239*3446Smrj for (i = 0; i < ItemCount; i++) 240*3446Smrj { 241*3446Smrj switch (MoveType) 242*3446Smrj { 243*3446Smrj /* 244*3446Smrj * For the 8-bit case, we can perform the move all at once 245*3446Smrj * since there are no alignment or endian issues 246*3446Smrj */ 247*3446Smrj case ACPI_RSC_MOVE8: 248*3446Smrj ACPI_MEMCPY (Destination, Source, ItemCount); 249*3446Smrj return; 250*3446Smrj 251*3446Smrj /* 252*3446Smrj * 16-, 32-, and 64-bit cases must use the move macros that perform 253*3446Smrj * endian conversion and/or accomodate hardware that cannot perform 254*3446Smrj * misaligned memory transfers 255*3446Smrj */ 256*3446Smrj case ACPI_RSC_MOVE16: 257*3446Smrj ACPI_MOVE_16_TO_16 (&ACPI_CAST_PTR (UINT16, Destination)[i], 258*3446Smrj &ACPI_CAST_PTR (UINT16, Source)[i]); 259*3446Smrj break; 260*3446Smrj 261*3446Smrj case ACPI_RSC_MOVE32: 262*3446Smrj ACPI_MOVE_32_TO_32 (&ACPI_CAST_PTR (UINT32, Destination)[i], 263*3446Smrj &ACPI_CAST_PTR (UINT32, Source)[i]); 264*3446Smrj break; 265*3446Smrj 266*3446Smrj case ACPI_RSC_MOVE64: 267*3446Smrj ACPI_MOVE_64_TO_64 (&ACPI_CAST_PTR (UINT64, Destination)[i], 268*3446Smrj &ACPI_CAST_PTR (UINT64, Source)[i]); 269*3446Smrj break; 270*3446Smrj 271*3446Smrj default: 272*3446Smrj return; 273*3446Smrj } 274*3446Smrj } 275*3446Smrj } 276*3446Smrj 277*3446Smrj 278*3446Smrj /******************************************************************************* 279*3446Smrj * 280*3446Smrj * FUNCTION: AcpiRsSetResourceLength 281*3446Smrj * 282*3446Smrj * PARAMETERS: TotalLength - Length of the AML descriptor, including 283*3446Smrj * the header and length fields. 284*3446Smrj * Aml - Pointer to the raw AML descriptor 285*3446Smrj * 286*3446Smrj * RETURN: None 287*3446Smrj * 288*3446Smrj * DESCRIPTION: Set the ResourceLength field of an AML 289*3446Smrj * resource descriptor, both Large and Small descriptors are 290*3446Smrj * supported automatically. Note: Descriptor Type field must 291*3446Smrj * be valid. 292*3446Smrj * 293*3446Smrj ******************************************************************************/ 294*3446Smrj 295*3446Smrj void 296*3446Smrj AcpiRsSetResourceLength ( 297*3446Smrj ACPI_RSDESC_SIZE TotalLength, 298*3446Smrj AML_RESOURCE *Aml) 299*3446Smrj { 300*3446Smrj ACPI_RS_LENGTH ResourceLength; 301*3446Smrj 302*3446Smrj 303*3446Smrj ACPI_FUNCTION_ENTRY (); 304*3446Smrj 305*3446Smrj 306*3446Smrj /* Length is the total descriptor length minus the header length */ 307*3446Smrj 308*3446Smrj ResourceLength = (ACPI_RS_LENGTH) 309*3446Smrj (TotalLength - AcpiUtGetResourceHeaderLength (Aml)); 310*3446Smrj 311*3446Smrj /* Length is stored differently for large and small descriptors */ 312*3446Smrj 313*3446Smrj if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE) 314*3446Smrj { 315*3446Smrj /* Large descriptor -- bytes 1-2 contain the 16-bit length */ 316*3446Smrj 317*3446Smrj ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength); 318*3446Smrj } 319*3446Smrj else 320*3446Smrj { 321*3446Smrj /* Small descriptor -- bits 2:0 of byte 0 contain the length */ 322*3446Smrj 323*3446Smrj Aml->SmallHeader.DescriptorType = (UINT8) 324*3446Smrj 325*3446Smrj /* Clear any existing length, preserving descriptor type bits */ 326*3446Smrj 327*3446Smrj ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK) 328*3446Smrj 329*3446Smrj | ResourceLength); 330*3446Smrj } 331*3446Smrj } 332*3446Smrj 333*3446Smrj 334*3446Smrj /******************************************************************************* 335*3446Smrj * 336*3446Smrj * FUNCTION: AcpiRsSetResourceHeader 337*3446Smrj * 338*3446Smrj * PARAMETERS: DescriptorType - Byte to be inserted as the type 339*3446Smrj * TotalLength - Length of the AML descriptor, including 340*3446Smrj * the header and length fields. 341*3446Smrj * Aml - Pointer to the raw AML descriptor 342*3446Smrj * 343*3446Smrj * RETURN: None 344*3446Smrj * 345*3446Smrj * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML 346*3446Smrj * resource descriptor, both Large and Small descriptors are 347*3446Smrj * supported automatically 348*3446Smrj * 349*3446Smrj ******************************************************************************/ 350*3446Smrj 351*3446Smrj void 352*3446Smrj AcpiRsSetResourceHeader ( 353*3446Smrj UINT8 DescriptorType, 354*3446Smrj ACPI_RSDESC_SIZE TotalLength, 355*3446Smrj AML_RESOURCE *Aml) 356*3446Smrj { 357*3446Smrj ACPI_FUNCTION_ENTRY (); 358*3446Smrj 359*3446Smrj 360*3446Smrj /* Set the Resource Type */ 361*3446Smrj 362*3446Smrj Aml->SmallHeader.DescriptorType = DescriptorType; 363*3446Smrj 364*3446Smrj /* Set the Resource Length */ 365*3446Smrj 366*3446Smrj AcpiRsSetResourceLength (TotalLength, Aml); 367*3446Smrj } 368*3446Smrj 369*3446Smrj 370*3446Smrj /******************************************************************************* 371*3446Smrj * 372*3446Smrj * FUNCTION: AcpiRsStrcpy 373*3446Smrj * 374*3446Smrj * PARAMETERS: Destination - Pointer to the destination string 375*3446Smrj * Source - Pointer to the source string 376*3446Smrj * 377*3446Smrj * RETURN: String length, including NULL terminator 378*3446Smrj * 379*3446Smrj * DESCRIPTION: Local string copy that returns the string length, saving a 380*3446Smrj * strcpy followed by a strlen. 381*3446Smrj * 382*3446Smrj ******************************************************************************/ 383*3446Smrj 384*3446Smrj static UINT16 385*3446Smrj AcpiRsStrcpy ( 386*3446Smrj char *Destination, 387*3446Smrj char *Source) 388*3446Smrj { 389*3446Smrj UINT16 i; 390*3446Smrj 391*3446Smrj 392*3446Smrj ACPI_FUNCTION_ENTRY (); 393*3446Smrj 394*3446Smrj 395*3446Smrj for (i = 0; Source[i]; i++) 396*3446Smrj { 397*3446Smrj Destination[i] = Source[i]; 398*3446Smrj } 399*3446Smrj 400*3446Smrj Destination[i] = 0; 401*3446Smrj 402*3446Smrj /* Return string length including the NULL terminator */ 403*3446Smrj 404*3446Smrj return ((UINT16) (i + 1)); 405*3446Smrj } 406*3446Smrj 407*3446Smrj 408*3446Smrj /******************************************************************************* 409*3446Smrj * 410*3446Smrj * FUNCTION: AcpiRsGetResourceSource 411*3446Smrj * 412*3446Smrj * PARAMETERS: ResourceLength - Length field of the descriptor 413*3446Smrj * MinimumLength - Minimum length of the descriptor (minus 414*3446Smrj * any optional fields) 415*3446Smrj * ResourceSource - Where the ResourceSource is returned 416*3446Smrj * Aml - Pointer to the raw AML descriptor 417*3446Smrj * StringPtr - (optional) where to store the actual 418*3446Smrj * ResourceSource string 419*3446Smrj * 420*3446Smrj * RETURN: Length of the string plus NULL terminator, rounded up to native 421*3446Smrj * word boundary 422*3446Smrj * 423*3446Smrj * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor 424*3446Smrj * to an internal resource descriptor 425*3446Smrj * 426*3446Smrj ******************************************************************************/ 427*3446Smrj 428*3446Smrj ACPI_RS_LENGTH 429*3446Smrj AcpiRsGetResourceSource ( 430*3446Smrj ACPI_RS_LENGTH ResourceLength, 431*3446Smrj ACPI_RS_LENGTH MinimumLength, 432*3446Smrj ACPI_RESOURCE_SOURCE *ResourceSource, 433*3446Smrj AML_RESOURCE *Aml, 434*3446Smrj char *StringPtr) 435*3446Smrj { 436*3446Smrj ACPI_RSDESC_SIZE TotalLength; 437*3446Smrj UINT8 *AmlResourceSource; 438*3446Smrj 439*3446Smrj 440*3446Smrj ACPI_FUNCTION_ENTRY (); 441*3446Smrj 442*3446Smrj 443*3446Smrj TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER); 444*3446Smrj AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength); 445*3446Smrj 446*3446Smrj /* 447*3446Smrj * ResourceSource is present if the length of the descriptor is longer than 448*3446Smrj * the minimum length. 449*3446Smrj * 450*3446Smrj * Note: Some resource descriptors will have an additional null, so 451*3446Smrj * we add 1 to the minimum length. 452*3446Smrj */ 453*3446Smrj if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1)) 454*3446Smrj { 455*3446Smrj /* Get the ResourceSourceIndex */ 456*3446Smrj 457*3446Smrj ResourceSource->Index = AmlResourceSource[0]; 458*3446Smrj 459*3446Smrj ResourceSource->StringPtr = StringPtr; 460*3446Smrj if (!StringPtr) 461*3446Smrj { 462*3446Smrj /* 463*3446Smrj * String destination pointer is not specified; Set the String 464*3446Smrj * pointer to the end of the current ResourceSource structure. 465*3446Smrj */ 466*3446Smrj ResourceSource->StringPtr = ACPI_ADD_PTR (char, ResourceSource, 467*3446Smrj sizeof (ACPI_RESOURCE_SOURCE)); 468*3446Smrj } 469*3446Smrj 470*3446Smrj /* 471*3446Smrj * In order for the Resource length to be a multiple of the native 472*3446Smrj * word, calculate the length of the string (+1 for NULL terminator) 473*3446Smrj * and expand to the next word multiple. 474*3446Smrj * 475*3446Smrj * Zero the entire area of the buffer. 476*3446Smrj */ 477*3446Smrj TotalLength = (UINT32) ACPI_STRLEN ( 478*3446Smrj ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1; 479*3446Smrj TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength); 480*3446Smrj 481*3446Smrj ACPI_MEMSET (ResourceSource->StringPtr, 0, TotalLength); 482*3446Smrj 483*3446Smrj /* Copy the ResourceSource string to the destination */ 484*3446Smrj 485*3446Smrj ResourceSource->StringLength = AcpiRsStrcpy (ResourceSource->StringPtr, 486*3446Smrj ACPI_CAST_PTR (char, &AmlResourceSource[1])); 487*3446Smrj 488*3446Smrj return ((ACPI_RS_LENGTH) TotalLength); 489*3446Smrj } 490*3446Smrj 491*3446Smrj /* ResourceSource is not present */ 492*3446Smrj 493*3446Smrj ResourceSource->Index = 0; 494*3446Smrj ResourceSource->StringLength = 0; 495*3446Smrj ResourceSource->StringPtr = NULL; 496*3446Smrj return (0); 497*3446Smrj } 498*3446Smrj 499*3446Smrj 500*3446Smrj /******************************************************************************* 501*3446Smrj * 502*3446Smrj * FUNCTION: AcpiRsSetResourceSource 503*3446Smrj * 504*3446Smrj * PARAMETERS: Aml - Pointer to the raw AML descriptor 505*3446Smrj * MinimumLength - Minimum length of the descriptor (minus 506*3446Smrj * any optional fields) 507*3446Smrj * ResourceSource - Internal ResourceSource 508*3446Smrj 509*3446Smrj * 510*3446Smrj * RETURN: Total length of the AML descriptor 511*3446Smrj * 512*3446Smrj * DESCRIPTION: Convert an optional ResourceSource from internal format to a 513*3446Smrj * raw AML resource descriptor 514*3446Smrj * 515*3446Smrj ******************************************************************************/ 516*3446Smrj 517*3446Smrj ACPI_RSDESC_SIZE 518*3446Smrj AcpiRsSetResourceSource ( 519*3446Smrj AML_RESOURCE *Aml, 520*3446Smrj ACPI_RS_LENGTH MinimumLength, 521*3446Smrj ACPI_RESOURCE_SOURCE *ResourceSource) 522*3446Smrj { 523*3446Smrj UINT8 *AmlResourceSource; 524*3446Smrj ACPI_RSDESC_SIZE DescriptorLength; 525*3446Smrj 526*3446Smrj 527*3446Smrj ACPI_FUNCTION_ENTRY (); 528*3446Smrj 529*3446Smrj 530*3446Smrj DescriptorLength = MinimumLength; 531*3446Smrj 532*3446Smrj /* Non-zero string length indicates presence of a ResourceSource */ 533*3446Smrj 534*3446Smrj if (ResourceSource->StringLength) 535*3446Smrj { 536*3446Smrj /* Point to the end of the AML descriptor */ 537*3446Smrj 538*3446Smrj AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength); 539*3446Smrj 540*3446Smrj /* Copy the ResourceSourceIndex */ 541*3446Smrj 542*3446Smrj AmlResourceSource[0] = (UINT8) ResourceSource->Index; 543*3446Smrj 544*3446Smrj /* Copy the ResourceSource string */ 545*3446Smrj 546*3446Smrj ACPI_STRCPY (ACPI_CAST_PTR (char, &AmlResourceSource[1]), 547*3446Smrj ResourceSource->StringPtr); 548*3446Smrj 549*3446Smrj /* 550*3446Smrj * Add the length of the string (+ 1 for null terminator) to the 551*3446Smrj * final descriptor length 552*3446Smrj */ 553*3446Smrj DescriptorLength += ((ACPI_RSDESC_SIZE) ResourceSource->StringLength + 1); 554*3446Smrj } 555*3446Smrj 556*3446Smrj /* Return the new total length of the AML descriptor */ 557*3446Smrj 558*3446Smrj return (DescriptorLength); 559*3446Smrj } 560*3446Smrj 561*3446Smrj 562*3446Smrj /******************************************************************************* 563*3446Smrj * 564*3446Smrj * FUNCTION: AcpiRsGetPrtMethodData 565*3446Smrj * 566*3446Smrj * PARAMETERS: Node - Device node 567*3446Smrj * RetBuffer - Pointer to a buffer structure for the 568*3446Smrj * results 569*3446Smrj * 570*3446Smrj * RETURN: Status 571*3446Smrj * 572*3446Smrj * DESCRIPTION: This function is called to get the _PRT value of an object 573*3446Smrj * contained in an object specified by the handle passed in 574*3446Smrj * 575*3446Smrj * If the function fails an appropriate status will be returned 576*3446Smrj * and the contents of the callers buffer is undefined. 577*3446Smrj * 578*3446Smrj ******************************************************************************/ 579*3446Smrj 580*3446Smrj ACPI_STATUS 581*3446Smrj AcpiRsGetPrtMethodData ( 582*3446Smrj ACPI_NAMESPACE_NODE *Node, 583*3446Smrj ACPI_BUFFER *RetBuffer) 584*3446Smrj { 585*3446Smrj ACPI_OPERAND_OBJECT *ObjDesc; 586*3446Smrj ACPI_STATUS Status; 587*3446Smrj 588*3446Smrj 589*3446Smrj ACPI_FUNCTION_TRACE (RsGetPrtMethodData); 590*3446Smrj 591*3446Smrj 592*3446Smrj /* Parameters guaranteed valid by caller */ 593*3446Smrj 594*3446Smrj /* Execute the method, no parameters */ 595*3446Smrj 596*3446Smrj Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRT, 597*3446Smrj ACPI_BTYPE_PACKAGE, &ObjDesc); 598*3446Smrj if (ACPI_FAILURE (Status)) 599*3446Smrj { 600*3446Smrj return_ACPI_STATUS (Status); 601*3446Smrj } 602*3446Smrj 603*3446Smrj /* 604*3446Smrj * Create a resource linked list from the byte stream buffer that comes 605*3446Smrj * back from the _CRS method execution. 606*3446Smrj */ 607*3446Smrj Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer); 608*3446Smrj 609*3446Smrj /* On exit, we must delete the object returned by EvaluateObject */ 610*3446Smrj 611*3446Smrj AcpiUtRemoveReference (ObjDesc); 612*3446Smrj return_ACPI_STATUS (Status); 613*3446Smrj } 614*3446Smrj 615*3446Smrj 616*3446Smrj /******************************************************************************* 617*3446Smrj * 618*3446Smrj * FUNCTION: AcpiRsGetCrsMethodData 619*3446Smrj * 620*3446Smrj * PARAMETERS: Node - Device node 621*3446Smrj * RetBuffer - Pointer to a buffer structure for the 622*3446Smrj * results 623*3446Smrj * 624*3446Smrj * RETURN: Status 625*3446Smrj * 626*3446Smrj * DESCRIPTION: This function is called to get the _CRS value of an object 627*3446Smrj * contained in an object specified by the handle passed in 628*3446Smrj * 629*3446Smrj * If the function fails an appropriate status will be returned 630*3446Smrj * and the contents of the callers buffer is undefined. 631*3446Smrj * 632*3446Smrj ******************************************************************************/ 633*3446Smrj 634*3446Smrj ACPI_STATUS 635*3446Smrj AcpiRsGetCrsMethodData ( 636*3446Smrj ACPI_NAMESPACE_NODE *Node, 637*3446Smrj ACPI_BUFFER *RetBuffer) 638*3446Smrj { 639*3446Smrj ACPI_OPERAND_OBJECT *ObjDesc; 640*3446Smrj ACPI_STATUS Status; 641*3446Smrj 642*3446Smrj 643*3446Smrj ACPI_FUNCTION_TRACE (RsGetCrsMethodData); 644*3446Smrj 645*3446Smrj 646*3446Smrj /* Parameters guaranteed valid by caller */ 647*3446Smrj 648*3446Smrj /* Execute the method, no parameters */ 649*3446Smrj 650*3446Smrj Status = AcpiUtEvaluateObject (Node, METHOD_NAME__CRS, 651*3446Smrj ACPI_BTYPE_BUFFER, &ObjDesc); 652*3446Smrj if (ACPI_FAILURE (Status)) 653*3446Smrj { 654*3446Smrj return_ACPI_STATUS (Status); 655*3446Smrj } 656*3446Smrj 657*3446Smrj /* 658*3446Smrj * Make the call to create a resource linked list from the 659*3446Smrj * byte stream buffer that comes back from the _CRS method 660*3446Smrj * execution. 661*3446Smrj */ 662*3446Smrj Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 663*3446Smrj 664*3446Smrj /* On exit, we must delete the object returned by evaluateObject */ 665*3446Smrj 666*3446Smrj AcpiUtRemoveReference (ObjDesc); 667*3446Smrj return_ACPI_STATUS (Status); 668*3446Smrj } 669*3446Smrj 670*3446Smrj 671*3446Smrj /******************************************************************************* 672*3446Smrj * 673*3446Smrj * FUNCTION: AcpiRsGetPrsMethodData 674*3446Smrj * 675*3446Smrj * PARAMETERS: Node - Device node 676*3446Smrj * RetBuffer - Pointer to a buffer structure for the 677*3446Smrj * results 678*3446Smrj * 679*3446Smrj * RETURN: Status 680*3446Smrj * 681*3446Smrj * DESCRIPTION: This function is called to get the _PRS value of an object 682*3446Smrj * contained in an object specified by the handle passed in 683*3446Smrj * 684*3446Smrj * If the function fails an appropriate status will be returned 685*3446Smrj * and the contents of the callers buffer is undefined. 686*3446Smrj * 687*3446Smrj ******************************************************************************/ 688*3446Smrj 689*3446Smrj ACPI_STATUS 690*3446Smrj AcpiRsGetPrsMethodData ( 691*3446Smrj ACPI_NAMESPACE_NODE *Node, 692*3446Smrj ACPI_BUFFER *RetBuffer) 693*3446Smrj { 694*3446Smrj ACPI_OPERAND_OBJECT *ObjDesc; 695*3446Smrj ACPI_STATUS Status; 696*3446Smrj 697*3446Smrj 698*3446Smrj ACPI_FUNCTION_TRACE (RsGetPrsMethodData); 699*3446Smrj 700*3446Smrj 701*3446Smrj /* Parameters guaranteed valid by caller */ 702*3446Smrj 703*3446Smrj /* Execute the method, no parameters */ 704*3446Smrj 705*3446Smrj Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRS, 706*3446Smrj ACPI_BTYPE_BUFFER, &ObjDesc); 707*3446Smrj if (ACPI_FAILURE (Status)) 708*3446Smrj { 709*3446Smrj return_ACPI_STATUS (Status); 710*3446Smrj } 711*3446Smrj 712*3446Smrj /* 713*3446Smrj * Make the call to create a resource linked list from the 714*3446Smrj * byte stream buffer that comes back from the _CRS method 715*3446Smrj * execution. 716*3446Smrj */ 717*3446Smrj Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 718*3446Smrj 719*3446Smrj /* On exit, we must delete the object returned by evaluateObject */ 720*3446Smrj 721*3446Smrj AcpiUtRemoveReference (ObjDesc); 722*3446Smrj return_ACPI_STATUS (Status); 723*3446Smrj } 724*3446Smrj 725*3446Smrj 726*3446Smrj /******************************************************************************* 727*3446Smrj * 728*3446Smrj * FUNCTION: AcpiRsGetMethodData 729*3446Smrj * 730*3446Smrj * PARAMETERS: Handle - Handle to the containing object 731*3446Smrj * Path - Path to method, relative to Handle 732*3446Smrj * RetBuffer - Pointer to a buffer structure for the 733*3446Smrj * results 734*3446Smrj * 735*3446Smrj * RETURN: Status 736*3446Smrj * 737*3446Smrj * DESCRIPTION: This function is called to get the _CRS or _PRS value of an 738*3446Smrj * object contained in an object specified by the handle passed in 739*3446Smrj * 740*3446Smrj * If the function fails an appropriate status will be returned 741*3446Smrj * and the contents of the callers buffer is undefined. 742*3446Smrj * 743*3446Smrj ******************************************************************************/ 744*3446Smrj 745*3446Smrj ACPI_STATUS 746*3446Smrj AcpiRsGetMethodData ( 747*3446Smrj ACPI_HANDLE Handle, 748*3446Smrj char *Path, 749*3446Smrj ACPI_BUFFER *RetBuffer) 750*3446Smrj { 751*3446Smrj ACPI_OPERAND_OBJECT *ObjDesc; 752*3446Smrj ACPI_STATUS Status; 753*3446Smrj 754*3446Smrj 755*3446Smrj ACPI_FUNCTION_TRACE (RsGetMethodData); 756*3446Smrj 757*3446Smrj 758*3446Smrj /* Parameters guaranteed valid by caller */ 759*3446Smrj 760*3446Smrj /* Execute the method, no parameters */ 761*3446Smrj 762*3446Smrj Status = AcpiUtEvaluateObject (Handle, Path, ACPI_BTYPE_BUFFER, &ObjDesc); 763*3446Smrj if (ACPI_FAILURE (Status)) 764*3446Smrj { 765*3446Smrj return_ACPI_STATUS (Status); 766*3446Smrj } 767*3446Smrj 768*3446Smrj /* 769*3446Smrj * Make the call to create a resource linked list from the 770*3446Smrj * byte stream buffer that comes back from the method 771*3446Smrj * execution. 772*3446Smrj */ 773*3446Smrj Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 774*3446Smrj 775*3446Smrj /* On exit, we must delete the object returned by EvaluateObject */ 776*3446Smrj 777*3446Smrj AcpiUtRemoveReference (ObjDesc); 778*3446Smrj return_ACPI_STATUS (Status); 779*3446Smrj } 780*3446Smrj 781*3446Smrj 782*3446Smrj /******************************************************************************* 783*3446Smrj * 784*3446Smrj * FUNCTION: AcpiRsSetSrsMethodData 785*3446Smrj * 786*3446Smrj * PARAMETERS: Node - Device node 787*3446Smrj * InBuffer - Pointer to a buffer structure of the 788*3446Smrj * parameter 789*3446Smrj * 790*3446Smrj * RETURN: Status 791*3446Smrj * 792*3446Smrj * DESCRIPTION: This function is called to set the _SRS of an object contained 793*3446Smrj * in an object specified by the handle passed in 794*3446Smrj * 795*3446Smrj * If the function fails an appropriate status will be returned 796*3446Smrj * and the contents of the callers buffer is undefined. 797*3446Smrj * 798*3446Smrj * Note: Parameters guaranteed valid by caller 799*3446Smrj * 800*3446Smrj ******************************************************************************/ 801*3446Smrj 802*3446Smrj ACPI_STATUS 803*3446Smrj AcpiRsSetSrsMethodData ( 804*3446Smrj ACPI_NAMESPACE_NODE *Node, 805*3446Smrj ACPI_BUFFER *InBuffer) 806*3446Smrj { 807*3446Smrj ACPI_EVALUATE_INFO *Info; 808*3446Smrj ACPI_OPERAND_OBJECT *Args[2]; 809*3446Smrj ACPI_STATUS Status; 810*3446Smrj ACPI_BUFFER Buffer; 811*3446Smrj 812*3446Smrj 813*3446Smrj ACPI_FUNCTION_TRACE (RsSetSrsMethodData); 814*3446Smrj 815*3446Smrj 816*3446Smrj /* Allocate and initialize the evaluation information block */ 817*3446Smrj 818*3446Smrj Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); 819*3446Smrj if (!Info) 820*3446Smrj { 821*3446Smrj return_ACPI_STATUS (AE_NO_MEMORY); 822*3446Smrj } 823*3446Smrj 824*3446Smrj Info->PrefixNode = Node; 825*3446Smrj Info->Pathname = METHOD_NAME__SRS; 826*3446Smrj Info->Parameters = Args; 827*3446Smrj Info->ParameterType = ACPI_PARAM_ARGS; 828*3446Smrj Info->Flags = ACPI_IGNORE_RETURN_VALUE; 829*3446Smrj 830*3446Smrj /* 831*3446Smrj * The InBuffer parameter will point to a linked list of 832*3446Smrj * resource parameters. It needs to be formatted into a 833*3446Smrj * byte stream to be sent in as an input parameter to _SRS 834*3446Smrj * 835*3446Smrj * Convert the linked list into a byte stream 836*3446Smrj */ 837*3446Smrj Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER; 838*3446Smrj Status = AcpiRsCreateAmlResources (InBuffer->Pointer, &Buffer); 839*3446Smrj if (ACPI_FAILURE (Status)) 840*3446Smrj { 841*3446Smrj goto Cleanup; 842*3446Smrj } 843*3446Smrj 844*3446Smrj /* Create and initialize the method parameter object */ 845*3446Smrj 846*3446Smrj Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER); 847*3446Smrj if (!Args[0]) 848*3446Smrj { 849*3446Smrj /* 850*3446Smrj * Must free the buffer allocated above (otherwise it is freed 851*3446Smrj * later) 852*3446Smrj */ 853*3446Smrj ACPI_FREE (Buffer.Pointer); 854*3446Smrj Status = AE_NO_MEMORY; 855*3446Smrj goto Cleanup; 856*3446Smrj } 857*3446Smrj 858*3446Smrj Args[0]->Buffer.Length = (UINT32) Buffer.Length; 859*3446Smrj Args[0]->Buffer.Pointer = Buffer.Pointer; 860*3446Smrj Args[0]->Common.Flags = AOPOBJ_DATA_VALID; 861*3446Smrj Args[1] = NULL; 862*3446Smrj 863*3446Smrj /* Execute the method, no return value is expected */ 864*3446Smrj 865*3446Smrj Status = AcpiNsEvaluate (Info); 866*3446Smrj 867*3446Smrj /* Clean up and return the status from AcpiNsEvaluate */ 868*3446Smrj 869*3446Smrj AcpiUtRemoveReference (Args[0]); 870*3446Smrj 871*3446Smrj Cleanup: 872*3446Smrj ACPI_FREE (Info); 873*3446Smrj return_ACPI_STATUS (Status); 874*3446Smrj } 875*3446Smrj 876