rsutils.c revision 193341
167754Smsmith/******************************************************************************* 267754Smsmith * 367754Smsmith * Module Name: rsutils - Utilities for the resource manager 467754Smsmith * 567754Smsmith ******************************************************************************/ 667754Smsmith 767754Smsmith/****************************************************************************** 867754Smsmith * 967754Smsmith * 1. Copyright Notice 1067754Smsmith * 11193267Sjkim * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp. 1270243Smsmith * All rights reserved. 1367754Smsmith * 1467754Smsmith * 2. License 1567754Smsmith * 1667754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property 1767754Smsmith * rights. You may have additional license terms from the party that provided 1867754Smsmith * you this software, covering your right to use that party's intellectual 1967754Smsmith * property rights. 2067754Smsmith * 2167754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2267754Smsmith * copy of the source code appearing in this file ("Covered Code") an 2367754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2467754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy, 2567754Smsmith * make derivatives, distribute, use and display any portion of the Covered 2667754Smsmith * Code in any form, with the right to sublicense such rights; and 2767754Smsmith * 2867754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 2967754Smsmith * license (with the right to sublicense), under only those claims of Intel 3067754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell, 3167754Smsmith * offer to sell, and import the Covered Code and derivative works thereof 3267754Smsmith * solely to the minimum extent necessary to exercise the above copyright 3367754Smsmith * license, and in no event shall the patent license extend to any additions 3467754Smsmith * to or modifications of the Original Intel Code. No other license or right 3567754Smsmith * is granted directly or by implication, estoppel or otherwise; 3667754Smsmith * 3767754Smsmith * The above copyright and patent license is granted only if the following 3867754Smsmith * conditions are met: 3967754Smsmith * 4067754Smsmith * 3. Conditions 4167754Smsmith * 4267754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4367754Smsmith * Redistribution of source code of any substantial portion of the Covered 4467754Smsmith * Code or modification with rights to further distribute source must include 4567754Smsmith * the above Copyright Notice, the above License, this list of Conditions, 4667754Smsmith * and the following Disclaimer and Export Compliance provision. In addition, 4767754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to 4867754Smsmith * contain a file documenting the changes Licensee made to create that Covered 4967754Smsmith * Code and the date of any change. Licensee must include in that file the 5067754Smsmith * documentation of any changes made by any predecessor Licensee. Licensee 5167754Smsmith * must include a prominent statement that the modification is derived, 5267754Smsmith * directly or indirectly, from Original Intel Code. 5367754Smsmith * 5467754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5567754Smsmith * Redistribution of source code of any substantial portion of the Covered 5667754Smsmith * Code or modification without rights to further distribute source must 5767754Smsmith * include the following Disclaimer and Export Compliance provision in the 5867754Smsmith * documentation and/or other materials provided with distribution. In 5967754Smsmith * addition, Licensee may not authorize further sublicense of source of any 6067754Smsmith * portion of the Covered Code, and must include terms to the effect that the 6167754Smsmith * license from Licensee to its licensee is limited to the intellectual 6267754Smsmith * property embodied in the software Licensee provides to its licensee, and 6367754Smsmith * not to intellectual property embodied in modifications its licensee may 6467754Smsmith * make. 6567754Smsmith * 6667754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any 6767754Smsmith * substantial portion of the Covered Code or modification must reproduce the 6867754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance 6967754Smsmith * provision in the documentation and/or other materials provided with the 7067754Smsmith * distribution. 7167754Smsmith * 7267754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original 7367754Smsmith * Intel Code. 7467754Smsmith * 7567754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7667754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or 7767754Smsmith * other dealings in products derived from or relating to the Covered Code 7867754Smsmith * without prior written authorization from Intel. 7967754Smsmith * 8067754Smsmith * 4. Disclaimer and Export Compliance 8167754Smsmith * 8267754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8367754Smsmith * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8467754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8567754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8667754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8767754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 8867754Smsmith * PARTICULAR PURPOSE. 8967754Smsmith * 9067754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9167754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9267754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9367754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9467754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9567754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9667754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9767754Smsmith * LIMITED REMEDY. 9867754Smsmith * 9967754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this 10067754Smsmith * software or system incorporating such software without first obtaining any 10167754Smsmith * required license or other approval from the U. S. Department of Commerce or 10267754Smsmith * any other agency or department of the United States Government. In the 10367754Smsmith * event Licensee exports any such software from the United States or 10467754Smsmith * re-exports any such software from a foreign destination, Licensee shall 10567754Smsmith * ensure that the distribution and export/re-export of the software is in 10667754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the 10767754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor 10867754Smsmith * any of its subsidiaries will export/re-export any technical data, process, 10967754Smsmith * software, or service, directly or indirectly, to any country for which the 11067754Smsmith * United States government or any agency thereof requires an export license, 11167754Smsmith * other governmental approval, or letter of assurance, without first obtaining 11267754Smsmith * such license, approval or letter. 11367754Smsmith * 11467754Smsmith *****************************************************************************/ 11567754Smsmith 11667754Smsmith 11767754Smsmith#define __RSUTILS_C__ 11867754Smsmith 119193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 120193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 121193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 122193341Sjkim#include <contrib/dev/acpica/include/acresrc.h> 12367754Smsmith 12467754Smsmith 12577424Smsmith#define _COMPONENT ACPI_RESOURCES 12691116Smsmith ACPI_MODULE_NAME ("rsutils") 12767754Smsmith 12867754Smsmith 12967754Smsmith/******************************************************************************* 13067754Smsmith * 131151937Sjkim * FUNCTION: AcpiRsDecodeBitmask 132151937Sjkim * 133151937Sjkim * PARAMETERS: Mask - Bitmask to decode 134151937Sjkim * List - Where the converted list is returned 135151937Sjkim * 136151937Sjkim * RETURN: Count of bits set (length of list) 137151937Sjkim * 138151937Sjkim * DESCRIPTION: Convert a bit mask into a list of values 139151937Sjkim * 140151937Sjkim ******************************************************************************/ 141151937Sjkim 142151937SjkimUINT8 143151937SjkimAcpiRsDecodeBitmask ( 144151937Sjkim UINT16 Mask, 145151937Sjkim UINT8 *List) 146151937Sjkim{ 147193267Sjkim UINT8 i; 148151937Sjkim UINT8 BitCount; 149151937Sjkim 150151937Sjkim 151167802Sjkim ACPI_FUNCTION_ENTRY (); 152167802Sjkim 153167802Sjkim 154151937Sjkim /* Decode the mask bits */ 155151937Sjkim 156151937Sjkim for (i = 0, BitCount = 0; Mask; i++) 157151937Sjkim { 158151937Sjkim if (Mask & 0x0001) 159151937Sjkim { 160193267Sjkim List[BitCount] = i; 161151937Sjkim BitCount++; 162151937Sjkim } 163151937Sjkim 164151937Sjkim Mask >>= 1; 165151937Sjkim } 166151937Sjkim 167151937Sjkim return (BitCount); 168151937Sjkim} 169151937Sjkim 170151937Sjkim 171151937Sjkim/******************************************************************************* 172151937Sjkim * 173151937Sjkim * FUNCTION: AcpiRsEncodeBitmask 174151937Sjkim * 175151937Sjkim * PARAMETERS: List - List of values to encode 176151937Sjkim * Count - Length of list 177151937Sjkim * 178151937Sjkim * RETURN: Encoded bitmask 179151937Sjkim * 180151937Sjkim * DESCRIPTION: Convert a list of values to an encoded bitmask 181151937Sjkim * 182151937Sjkim ******************************************************************************/ 183151937Sjkim 184151937SjkimUINT16 185151937SjkimAcpiRsEncodeBitmask ( 186151937Sjkim UINT8 *List, 187151937Sjkim UINT8 Count) 188151937Sjkim{ 189193267Sjkim UINT32 i; 190151937Sjkim UINT16 Mask; 191151937Sjkim 192151937Sjkim 193167802Sjkim ACPI_FUNCTION_ENTRY (); 194167802Sjkim 195167802Sjkim 196151937Sjkim /* Encode the list into a single bitmask */ 197151937Sjkim 198151937Sjkim for (i = 0, Mask = 0; i < Count; i++) 199151937Sjkim { 200193267Sjkim Mask |= (0x1 << List[i]); 201151937Sjkim } 202151937Sjkim 203151937Sjkim return (Mask); 204151937Sjkim} 205151937Sjkim 206151937Sjkim 207151937Sjkim/******************************************************************************* 208151937Sjkim * 209151937Sjkim * FUNCTION: AcpiRsMoveData 210151937Sjkim * 211151937Sjkim * PARAMETERS: Destination - Pointer to the destination descriptor 212151937Sjkim * Source - Pointer to the source descriptor 213151937Sjkim * ItemCount - How many items to move 214151937Sjkim * MoveType - Byte width 215151937Sjkim * 216151937Sjkim * RETURN: None 217151937Sjkim * 218151937Sjkim * DESCRIPTION: Move multiple data items from one descriptor to another. Handles 219151937Sjkim * alignment issues and endian issues if necessary, as configured 220151937Sjkim * via the ACPI_MOVE_* macros. (This is why a memcpy is not used) 221151937Sjkim * 222151937Sjkim ******************************************************************************/ 223151937Sjkim 224151937Sjkimvoid 225151937SjkimAcpiRsMoveData ( 226151937Sjkim void *Destination, 227151937Sjkim void *Source, 228151937Sjkim UINT16 ItemCount, 229151937Sjkim UINT8 MoveType) 230151937Sjkim{ 231193267Sjkim UINT32 i; 232151937Sjkim 233151937Sjkim 234167802Sjkim ACPI_FUNCTION_ENTRY (); 235167802Sjkim 236167802Sjkim 237151937Sjkim /* One move per item */ 238151937Sjkim 239151937Sjkim for (i = 0; i < ItemCount; i++) 240151937Sjkim { 241151937Sjkim switch (MoveType) 242151937Sjkim { 243151937Sjkim /* 244151937Sjkim * For the 8-bit case, we can perform the move all at once 245151937Sjkim * since there are no alignment or endian issues 246151937Sjkim */ 247151937Sjkim case ACPI_RSC_MOVE8: 248151937Sjkim ACPI_MEMCPY (Destination, Source, ItemCount); 249151937Sjkim return; 250151937Sjkim 251151937Sjkim /* 252151937Sjkim * 16-, 32-, and 64-bit cases must use the move macros that perform 253151937Sjkim * endian conversion and/or accomodate hardware that cannot perform 254151937Sjkim * misaligned memory transfers 255151937Sjkim */ 256151937Sjkim case ACPI_RSC_MOVE16: 257167802Sjkim ACPI_MOVE_16_TO_16 (&ACPI_CAST_PTR (UINT16, Destination)[i], 258167802Sjkim &ACPI_CAST_PTR (UINT16, Source)[i]); 259151937Sjkim break; 260151937Sjkim 261151937Sjkim case ACPI_RSC_MOVE32: 262167802Sjkim ACPI_MOVE_32_TO_32 (&ACPI_CAST_PTR (UINT32, Destination)[i], 263167802Sjkim &ACPI_CAST_PTR (UINT32, Source)[i]); 264151937Sjkim break; 265151937Sjkim 266151937Sjkim case ACPI_RSC_MOVE64: 267167802Sjkim ACPI_MOVE_64_TO_64 (&ACPI_CAST_PTR (UINT64, Destination)[i], 268167802Sjkim &ACPI_CAST_PTR (UINT64, Source)[i]); 269151937Sjkim break; 270151937Sjkim 271151937Sjkim default: 272151937Sjkim return; 273151937Sjkim } 274151937Sjkim } 275151937Sjkim} 276151937Sjkim 277151937Sjkim 278151937Sjkim/******************************************************************************* 279151937Sjkim * 280151937Sjkim * FUNCTION: AcpiRsSetResourceLength 281151937Sjkim * 282151937Sjkim * PARAMETERS: TotalLength - Length of the AML descriptor, including 283151937Sjkim * the header and length fields. 284151937Sjkim * Aml - Pointer to the raw AML descriptor 285151937Sjkim * 286151937Sjkim * RETURN: None 287151937Sjkim * 288151937Sjkim * DESCRIPTION: Set the ResourceLength field of an AML 289151937Sjkim * resource descriptor, both Large and Small descriptors are 290151937Sjkim * supported automatically. Note: Descriptor Type field must 291151937Sjkim * be valid. 292151937Sjkim * 293151937Sjkim ******************************************************************************/ 294151937Sjkim 295151937Sjkimvoid 296151937SjkimAcpiRsSetResourceLength ( 297151937Sjkim ACPI_RSDESC_SIZE TotalLength, 298151937Sjkim AML_RESOURCE *Aml) 299151937Sjkim{ 300151937Sjkim ACPI_RS_LENGTH ResourceLength; 301151937Sjkim 302151937Sjkim 303151937Sjkim ACPI_FUNCTION_ENTRY (); 304151937Sjkim 305151937Sjkim 306167802Sjkim /* Length is the total descriptor length minus the header length */ 307151937Sjkim 308167802Sjkim ResourceLength = (ACPI_RS_LENGTH) 309167802Sjkim (TotalLength - AcpiUtGetResourceHeaderLength (Aml)); 310167802Sjkim 311167802Sjkim /* Length is stored differently for large and small descriptors */ 312167802Sjkim 313151937Sjkim if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE) 314151937Sjkim { 315167802Sjkim /* Large descriptor -- bytes 1-2 contain the 16-bit length */ 316151937Sjkim 317151937Sjkim ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength); 318151937Sjkim } 319151937Sjkim else 320151937Sjkim { 321167802Sjkim /* Small descriptor -- bits 2:0 of byte 0 contain the length */ 322151937Sjkim 323151937Sjkim Aml->SmallHeader.DescriptorType = (UINT8) 324151937Sjkim 325151937Sjkim /* Clear any existing length, preserving descriptor type bits */ 326151937Sjkim 327151937Sjkim ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK) 328151937Sjkim 329151937Sjkim | ResourceLength); 330151937Sjkim } 331151937Sjkim} 332151937Sjkim 333151937Sjkim 334151937Sjkim/******************************************************************************* 335151937Sjkim * 336151937Sjkim * FUNCTION: AcpiRsSetResourceHeader 337151937Sjkim * 338151937Sjkim * PARAMETERS: DescriptorType - Byte to be inserted as the type 339151937Sjkim * TotalLength - Length of the AML descriptor, including 340151937Sjkim * the header and length fields. 341151937Sjkim * Aml - Pointer to the raw AML descriptor 342151937Sjkim * 343151937Sjkim * RETURN: None 344151937Sjkim * 345151937Sjkim * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML 346151937Sjkim * resource descriptor, both Large and Small descriptors are 347151937Sjkim * supported automatically 348151937Sjkim * 349151937Sjkim ******************************************************************************/ 350151937Sjkim 351151937Sjkimvoid 352151937SjkimAcpiRsSetResourceHeader ( 353151937Sjkim UINT8 DescriptorType, 354151937Sjkim ACPI_RSDESC_SIZE TotalLength, 355151937Sjkim AML_RESOURCE *Aml) 356151937Sjkim{ 357151937Sjkim ACPI_FUNCTION_ENTRY (); 358151937Sjkim 359151937Sjkim 360167802Sjkim /* Set the Resource Type */ 361151937Sjkim 362151937Sjkim Aml->SmallHeader.DescriptorType = DescriptorType; 363151937Sjkim 364151937Sjkim /* Set the Resource Length */ 365151937Sjkim 366151937Sjkim AcpiRsSetResourceLength (TotalLength, Aml); 367151937Sjkim} 368151937Sjkim 369151937Sjkim 370151937Sjkim/******************************************************************************* 371151937Sjkim * 372151937Sjkim * FUNCTION: AcpiRsStrcpy 373151937Sjkim * 374151937Sjkim * PARAMETERS: Destination - Pointer to the destination string 375151937Sjkim * Source - Pointer to the source string 376151937Sjkim * 377151937Sjkim * RETURN: String length, including NULL terminator 378151937Sjkim * 379151937Sjkim * DESCRIPTION: Local string copy that returns the string length, saving a 380151937Sjkim * strcpy followed by a strlen. 381151937Sjkim * 382151937Sjkim ******************************************************************************/ 383151937Sjkim 384151937Sjkimstatic UINT16 385151937SjkimAcpiRsStrcpy ( 386151937Sjkim char *Destination, 387151937Sjkim char *Source) 388151937Sjkim{ 389151937Sjkim UINT16 i; 390151937Sjkim 391151937Sjkim 392151937Sjkim ACPI_FUNCTION_ENTRY (); 393151937Sjkim 394151937Sjkim 395151937Sjkim for (i = 0; Source[i]; i++) 396151937Sjkim { 397151937Sjkim Destination[i] = Source[i]; 398151937Sjkim } 399151937Sjkim 400151937Sjkim Destination[i] = 0; 401151937Sjkim 402151937Sjkim /* Return string length including the NULL terminator */ 403151937Sjkim 404151937Sjkim return ((UINT16) (i + 1)); 405151937Sjkim} 406151937Sjkim 407151937Sjkim 408151937Sjkim/******************************************************************************* 409151937Sjkim * 410151937Sjkim * FUNCTION: AcpiRsGetResourceSource 411151937Sjkim * 412151937Sjkim * PARAMETERS: ResourceLength - Length field of the descriptor 413151937Sjkim * MinimumLength - Minimum length of the descriptor (minus 414151937Sjkim * any optional fields) 415151937Sjkim * ResourceSource - Where the ResourceSource is returned 416151937Sjkim * Aml - Pointer to the raw AML descriptor 417151937Sjkim * StringPtr - (optional) where to store the actual 418151937Sjkim * ResourceSource string 419151937Sjkim * 420167802Sjkim * RETURN: Length of the string plus NULL terminator, rounded up to native 421167802Sjkim * word boundary 422151937Sjkim * 423151937Sjkim * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor 424151937Sjkim * to an internal resource descriptor 425151937Sjkim * 426151937Sjkim ******************************************************************************/ 427151937Sjkim 428151937SjkimACPI_RS_LENGTH 429151937SjkimAcpiRsGetResourceSource ( 430151937Sjkim ACPI_RS_LENGTH ResourceLength, 431151937Sjkim ACPI_RS_LENGTH MinimumLength, 432151937Sjkim ACPI_RESOURCE_SOURCE *ResourceSource, 433151937Sjkim AML_RESOURCE *Aml, 434151937Sjkim char *StringPtr) 435151937Sjkim{ 436151937Sjkim ACPI_RSDESC_SIZE TotalLength; 437151937Sjkim UINT8 *AmlResourceSource; 438151937Sjkim 439151937Sjkim 440151937Sjkim ACPI_FUNCTION_ENTRY (); 441151937Sjkim 442151937Sjkim 443151937Sjkim TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER); 444167802Sjkim AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength); 445151937Sjkim 446151937Sjkim /* 447151937Sjkim * ResourceSource is present if the length of the descriptor is longer than 448151937Sjkim * the minimum length. 449151937Sjkim * 450151937Sjkim * Note: Some resource descriptors will have an additional null, so 451151937Sjkim * we add 1 to the minimum length. 452151937Sjkim */ 453167802Sjkim if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1)) 454151937Sjkim { 455151937Sjkim /* Get the ResourceSourceIndex */ 456151937Sjkim 457151937Sjkim ResourceSource->Index = AmlResourceSource[0]; 458151937Sjkim 459151937Sjkim ResourceSource->StringPtr = StringPtr; 460151937Sjkim if (!StringPtr) 461151937Sjkim { 462151937Sjkim /* 463151937Sjkim * String destination pointer is not specified; Set the String 464151937Sjkim * pointer to the end of the current ResourceSource structure. 465151937Sjkim */ 466167802Sjkim ResourceSource->StringPtr = ACPI_ADD_PTR (char, ResourceSource, 467167802Sjkim sizeof (ACPI_RESOURCE_SOURCE)); 468151937Sjkim } 469151937Sjkim 470151937Sjkim /* 471167802Sjkim * In order for the Resource length to be a multiple of the native 472167802Sjkim * word, calculate the length of the string (+1 for NULL terminator) 473167802Sjkim * and expand to the next word multiple. 474151937Sjkim * 475151937Sjkim * Zero the entire area of the buffer. 476151937Sjkim */ 477167802Sjkim TotalLength = (UINT32) ACPI_STRLEN ( 478167802Sjkim ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1; 479167802Sjkim TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength); 480167802Sjkim 481151937Sjkim ACPI_MEMSET (ResourceSource->StringPtr, 0, TotalLength); 482151937Sjkim 483151937Sjkim /* Copy the ResourceSource string to the destination */ 484151937Sjkim 485151937Sjkim ResourceSource->StringLength = AcpiRsStrcpy (ResourceSource->StringPtr, 486167802Sjkim ACPI_CAST_PTR (char, &AmlResourceSource[1])); 487151937Sjkim 488151937Sjkim return ((ACPI_RS_LENGTH) TotalLength); 489151937Sjkim } 490151937Sjkim 491167802Sjkim /* ResourceSource is not present */ 492167802Sjkim 493167802Sjkim ResourceSource->Index = 0; 494167802Sjkim ResourceSource->StringLength = 0; 495167802Sjkim ResourceSource->StringPtr = NULL; 496167802Sjkim return (0); 497151937Sjkim} 498151937Sjkim 499167802Sjkim 500151937Sjkim/******************************************************************************* 501151937Sjkim * 502151937Sjkim * FUNCTION: AcpiRsSetResourceSource 503151937Sjkim * 504151937Sjkim * PARAMETERS: Aml - Pointer to the raw AML descriptor 505151937Sjkim * MinimumLength - Minimum length of the descriptor (minus 506151937Sjkim * any optional fields) 507151937Sjkim * ResourceSource - Internal ResourceSource 508151937Sjkim 509151937Sjkim * 510151937Sjkim * RETURN: Total length of the AML descriptor 511151937Sjkim * 512151937Sjkim * DESCRIPTION: Convert an optional ResourceSource from internal format to a 513151937Sjkim * raw AML resource descriptor 514151937Sjkim * 515151937Sjkim ******************************************************************************/ 516151937Sjkim 517151937SjkimACPI_RSDESC_SIZE 518151937SjkimAcpiRsSetResourceSource ( 519151937Sjkim AML_RESOURCE *Aml, 520151937Sjkim ACPI_RS_LENGTH MinimumLength, 521151937Sjkim ACPI_RESOURCE_SOURCE *ResourceSource) 522151937Sjkim{ 523151937Sjkim UINT8 *AmlResourceSource; 524151937Sjkim ACPI_RSDESC_SIZE DescriptorLength; 525151937Sjkim 526151937Sjkim 527151937Sjkim ACPI_FUNCTION_ENTRY (); 528151937Sjkim 529151937Sjkim 530151937Sjkim DescriptorLength = MinimumLength; 531151937Sjkim 532151937Sjkim /* Non-zero string length indicates presence of a ResourceSource */ 533151937Sjkim 534151937Sjkim if (ResourceSource->StringLength) 535151937Sjkim { 536151937Sjkim /* Point to the end of the AML descriptor */ 537151937Sjkim 538167802Sjkim AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength); 539151937Sjkim 540151937Sjkim /* Copy the ResourceSourceIndex */ 541151937Sjkim 542151937Sjkim AmlResourceSource[0] = (UINT8) ResourceSource->Index; 543151937Sjkim 544151937Sjkim /* Copy the ResourceSource string */ 545151937Sjkim 546167802Sjkim ACPI_STRCPY (ACPI_CAST_PTR (char, &AmlResourceSource[1]), 547167802Sjkim ResourceSource->StringPtr); 548151937Sjkim 549151937Sjkim /* 550151937Sjkim * Add the length of the string (+ 1 for null terminator) to the 551151937Sjkim * final descriptor length 552151937Sjkim */ 553151937Sjkim DescriptorLength += ((ACPI_RSDESC_SIZE) ResourceSource->StringLength + 1); 554151937Sjkim } 555151937Sjkim 556151937Sjkim /* Return the new total length of the AML descriptor */ 557151937Sjkim 558151937Sjkim return (DescriptorLength); 559151937Sjkim} 560151937Sjkim 561151937Sjkim 562151937Sjkim/******************************************************************************* 563151937Sjkim * 56467754Smsmith * FUNCTION: AcpiRsGetPrtMethodData 56567754Smsmith * 566167802Sjkim * PARAMETERS: Node - Device node 567167802Sjkim * RetBuffer - Pointer to a buffer structure for the 568167802Sjkim * results 56967754Smsmith * 57077424Smsmith * RETURN: Status 57167754Smsmith * 57267754Smsmith * DESCRIPTION: This function is called to get the _PRT value of an object 57367754Smsmith * contained in an object specified by the handle passed in 57467754Smsmith * 57567754Smsmith * If the function fails an appropriate status will be returned 57667754Smsmith * and the contents of the callers buffer is undefined. 57767754Smsmith * 57867754Smsmith ******************************************************************************/ 57967754Smsmith 58067754SmsmithACPI_STATUS 58167754SmsmithAcpiRsGetPrtMethodData ( 582167802Sjkim ACPI_NAMESPACE_NODE *Node, 58367754Smsmith ACPI_BUFFER *RetBuffer) 58467754Smsmith{ 58599679Siwasaki ACPI_OPERAND_OBJECT *ObjDesc; 58667754Smsmith ACPI_STATUS Status; 58767754Smsmith 58867754Smsmith 589167802Sjkim ACPI_FUNCTION_TRACE (RsGetPrtMethodData); 59067754Smsmith 59167754Smsmith 59291116Smsmith /* Parameters guaranteed valid by caller */ 59367754Smsmith 594151937Sjkim /* Execute the method, no parameters */ 595151937Sjkim 596167802Sjkim Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRT, 597151937Sjkim ACPI_BTYPE_PACKAGE, &ObjDesc); 59867754Smsmith if (ACPI_FAILURE (Status)) 59967754Smsmith { 60067754Smsmith return_ACPI_STATUS (Status); 60167754Smsmith } 60267754Smsmith 60367754Smsmith /* 60491116Smsmith * Create a resource linked list from the byte stream buffer that comes 60591116Smsmith * back from the _CRS method execution. 60667754Smsmith */ 60799679Siwasaki Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer); 60867754Smsmith 60991116Smsmith /* On exit, we must delete the object returned by EvaluateObject */ 61067754Smsmith 61199679Siwasaki AcpiUtRemoveReference (ObjDesc); 61267754Smsmith return_ACPI_STATUS (Status); 61367754Smsmith} 61467754Smsmith 61567754Smsmith 61667754Smsmith/******************************************************************************* 61767754Smsmith * 61867754Smsmith * FUNCTION: AcpiRsGetCrsMethodData 61967754Smsmith * 620167802Sjkim * PARAMETERS: Node - Device node 621167802Sjkim * RetBuffer - Pointer to a buffer structure for the 622167802Sjkim * results 62367754Smsmith * 62477424Smsmith * RETURN: Status 62567754Smsmith * 62667754Smsmith * DESCRIPTION: This function is called to get the _CRS value of an object 62767754Smsmith * contained in an object specified by the handle passed in 62867754Smsmith * 62967754Smsmith * If the function fails an appropriate status will be returned 63067754Smsmith * and the contents of the callers buffer is undefined. 63167754Smsmith * 63267754Smsmith ******************************************************************************/ 63367754Smsmith 63467754SmsmithACPI_STATUS 63567754SmsmithAcpiRsGetCrsMethodData ( 636167802Sjkim ACPI_NAMESPACE_NODE *Node, 63767754Smsmith ACPI_BUFFER *RetBuffer) 63867754Smsmith{ 63999679Siwasaki ACPI_OPERAND_OBJECT *ObjDesc; 64067754Smsmith ACPI_STATUS Status; 64167754Smsmith 64267754Smsmith 643167802Sjkim ACPI_FUNCTION_TRACE (RsGetCrsMethodData); 64467754Smsmith 64567754Smsmith 64691116Smsmith /* Parameters guaranteed valid by caller */ 64767754Smsmith 648151937Sjkim /* Execute the method, no parameters */ 649151937Sjkim 650167802Sjkim Status = AcpiUtEvaluateObject (Node, METHOD_NAME__CRS, 651151937Sjkim ACPI_BTYPE_BUFFER, &ObjDesc); 65267754Smsmith if (ACPI_FAILURE (Status)) 65367754Smsmith { 65467754Smsmith return_ACPI_STATUS (Status); 65567754Smsmith } 65667754Smsmith 65767754Smsmith /* 65867754Smsmith * Make the call to create a resource linked list from the 65991116Smsmith * byte stream buffer that comes back from the _CRS method 66091116Smsmith * execution. 66167754Smsmith */ 66299679Siwasaki Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 66367754Smsmith 66467754Smsmith /* On exit, we must delete the object returned by evaluateObject */ 66567754Smsmith 66699679Siwasaki AcpiUtRemoveReference (ObjDesc); 66767754Smsmith return_ACPI_STATUS (Status); 66867754Smsmith} 66967754Smsmith 67067754Smsmith 67167754Smsmith/******************************************************************************* 67267754Smsmith * 67367754Smsmith * FUNCTION: AcpiRsGetPrsMethodData 67467754Smsmith * 675167802Sjkim * PARAMETERS: Node - Device node 676167802Sjkim * RetBuffer - Pointer to a buffer structure for the 677167802Sjkim * results 67867754Smsmith * 67977424Smsmith * RETURN: Status 68067754Smsmith * 68167754Smsmith * DESCRIPTION: This function is called to get the _PRS value of an object 68267754Smsmith * contained in an object specified by the handle passed in 68367754Smsmith * 68467754Smsmith * If the function fails an appropriate status will be returned 68567754Smsmith * and the contents of the callers buffer is undefined. 68667754Smsmith * 68767754Smsmith ******************************************************************************/ 68867754Smsmith 68967754SmsmithACPI_STATUS 69067754SmsmithAcpiRsGetPrsMethodData ( 691167802Sjkim ACPI_NAMESPACE_NODE *Node, 69267754Smsmith ACPI_BUFFER *RetBuffer) 69367754Smsmith{ 69499679Siwasaki ACPI_OPERAND_OBJECT *ObjDesc; 69567754Smsmith ACPI_STATUS Status; 69667754Smsmith 69767754Smsmith 698167802Sjkim ACPI_FUNCTION_TRACE (RsGetPrsMethodData); 69967754Smsmith 70067754Smsmith 70191116Smsmith /* Parameters guaranteed valid by caller */ 70267754Smsmith 703151937Sjkim /* Execute the method, no parameters */ 704151937Sjkim 705167802Sjkim Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRS, 706151937Sjkim ACPI_BTYPE_BUFFER, &ObjDesc); 70767754Smsmith if (ACPI_FAILURE (Status)) 70867754Smsmith { 70967754Smsmith return_ACPI_STATUS (Status); 71067754Smsmith } 71167754Smsmith 712114237Snjl /* 713114237Snjl * Make the call to create a resource linked list from the 714114237Snjl * byte stream buffer that comes back from the _CRS method 715114237Snjl * execution. 716114237Snjl */ 717114237Snjl Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 71867754Smsmith 719114237Snjl /* On exit, we must delete the object returned by evaluateObject */ 72067754Smsmith 721114237Snjl AcpiUtRemoveReference (ObjDesc); 722114237Snjl return_ACPI_STATUS (Status); 723114237Snjl} 724114237Snjl 725114237Snjl 726114237Snjl/******************************************************************************* 727114237Snjl * 728114237Snjl * FUNCTION: AcpiRsGetMethodData 729114237Snjl * 730167802Sjkim * PARAMETERS: Handle - Handle to the containing object 731151937Sjkim * Path - Path to method, relative to Handle 732167802Sjkim * RetBuffer - Pointer to a buffer structure for the 733167802Sjkim * results 734114237Snjl * 735114237Snjl * RETURN: Status 736114237Snjl * 737114237Snjl * DESCRIPTION: This function is called to get the _CRS or _PRS value of an 738114237Snjl * object contained in an object specified by the handle passed in 739114237Snjl * 740114237Snjl * If the function fails an appropriate status will be returned 741114237Snjl * and the contents of the callers buffer is undefined. 742114237Snjl * 743114237Snjl ******************************************************************************/ 744114237Snjl 745114237SnjlACPI_STATUS 746114237SnjlAcpiRsGetMethodData ( 747114237Snjl ACPI_HANDLE Handle, 748114237Snjl char *Path, 749114237Snjl ACPI_BUFFER *RetBuffer) 750114237Snjl{ 751114237Snjl ACPI_OPERAND_OBJECT *ObjDesc; 752114237Snjl ACPI_STATUS Status; 753114237Snjl 754114237Snjl 755167802Sjkim ACPI_FUNCTION_TRACE (RsGetMethodData); 756114237Snjl 757114237Snjl 758114237Snjl /* Parameters guaranteed valid by caller */ 759114237Snjl 760151937Sjkim /* Execute the method, no parameters */ 761151937Sjkim 762114237Snjl Status = AcpiUtEvaluateObject (Handle, Path, ACPI_BTYPE_BUFFER, &ObjDesc); 763167802Sjkim if (ACPI_FAILURE (Status)) 764167802Sjkim { 765114237Snjl return_ACPI_STATUS (Status); 76667754Smsmith } 76767754Smsmith 76867754Smsmith /* 76967754Smsmith * Make the call to create a resource linked list from the 770114237Snjl * byte stream buffer that comes back from the method 77191116Smsmith * execution. 77267754Smsmith */ 77399679Siwasaki Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 77467754Smsmith 775114237Snjl /* On exit, we must delete the object returned by EvaluateObject */ 77667754Smsmith 77799679Siwasaki AcpiUtRemoveReference (ObjDesc); 77867754Smsmith return_ACPI_STATUS (Status); 77967754Smsmith} 78067754Smsmith 781167802Sjkim 78267754Smsmith/******************************************************************************* 78367754Smsmith * 78467754Smsmith * FUNCTION: AcpiRsSetSrsMethodData 78567754Smsmith * 786167802Sjkim * PARAMETERS: Node - Device node 787167802Sjkim * InBuffer - Pointer to a buffer structure of the 788167802Sjkim * parameter 78967754Smsmith * 79077424Smsmith * RETURN: Status 79167754Smsmith * 79267754Smsmith * DESCRIPTION: This function is called to set the _SRS of an object contained 79367754Smsmith * in an object specified by the handle passed in 79467754Smsmith * 79567754Smsmith * If the function fails an appropriate status will be returned 79667754Smsmith * and the contents of the callers buffer is undefined. 79767754Smsmith * 798167802Sjkim * Note: Parameters guaranteed valid by caller 799167802Sjkim * 80067754Smsmith ******************************************************************************/ 80167754Smsmith 80267754SmsmithACPI_STATUS 80367754SmsmithAcpiRsSetSrsMethodData ( 804167802Sjkim ACPI_NAMESPACE_NODE *Node, 80567754Smsmith ACPI_BUFFER *InBuffer) 80667754Smsmith{ 807167802Sjkim ACPI_EVALUATE_INFO *Info; 808167802Sjkim ACPI_OPERAND_OBJECT *Args[2]; 80967754Smsmith ACPI_STATUS Status; 81091116Smsmith ACPI_BUFFER Buffer; 81167754Smsmith 81267754Smsmith 813167802Sjkim ACPI_FUNCTION_TRACE (RsSetSrsMethodData); 81467754Smsmith 81567754Smsmith 816167802Sjkim /* Allocate and initialize the evaluation information block */ 81767754Smsmith 818167802Sjkim Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); 819167802Sjkim if (!Info) 820167802Sjkim { 821167802Sjkim return_ACPI_STATUS (AE_NO_MEMORY); 822167802Sjkim } 823167802Sjkim 824167802Sjkim Info->PrefixNode = Node; 825167802Sjkim Info->Pathname = METHOD_NAME__SRS; 826167802Sjkim Info->Parameters = Args; 827167802Sjkim Info->Flags = ACPI_IGNORE_RETURN_VALUE; 828167802Sjkim 82967754Smsmith /* 83067754Smsmith * The InBuffer parameter will point to a linked list of 831167802Sjkim * resource parameters. It needs to be formatted into a 83291116Smsmith * byte stream to be sent in as an input parameter to _SRS 83391116Smsmith * 83491116Smsmith * Convert the linked list into a byte stream 83567754Smsmith */ 83691116Smsmith Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER; 837151937Sjkim Status = AcpiRsCreateAmlResources (InBuffer->Pointer, &Buffer); 83891116Smsmith if (ACPI_FAILURE (Status)) 83967754Smsmith { 840167802Sjkim goto Cleanup; 84167754Smsmith } 84267754Smsmith 843167802Sjkim /* Create and initialize the method parameter object */ 844151937Sjkim 845167802Sjkim Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER); 846167802Sjkim if (!Args[0]) 84784491Smsmith { 848167802Sjkim /* 849167802Sjkim * Must free the buffer allocated above (otherwise it is freed 850167802Sjkim * later) 851167802Sjkim */ 852167802Sjkim ACPI_FREE (Buffer.Pointer); 853167802Sjkim Status = AE_NO_MEMORY; 854167802Sjkim goto Cleanup; 85584491Smsmith } 85667754Smsmith 857167802Sjkim Args[0]->Buffer.Length = (UINT32) Buffer.Length; 858167802Sjkim Args[0]->Buffer.Pointer = Buffer.Pointer; 859167802Sjkim Args[0]->Common.Flags = AOPOBJ_DATA_VALID; 860167802Sjkim Args[1] = NULL; 861151937Sjkim 862167802Sjkim /* Execute the method, no return value is expected */ 86367754Smsmith 864167802Sjkim Status = AcpiNsEvaluate (Info); 865129684Snjl 866167802Sjkim /* Clean up and return the status from AcpiNsEvaluate */ 86767754Smsmith 868167802Sjkim AcpiUtRemoveReference (Args[0]); 869151937Sjkim 870167802SjkimCleanup: 871167802Sjkim ACPI_FREE (Info); 87267754Smsmith return_ACPI_STATUS (Status); 87367754Smsmith} 87467754Smsmith 875