167754Smsmith/******************************************************************************* 267754Smsmith * 367754Smsmith * Module Name: rsutils - Utilities for the resource manager 467754Smsmith * 567754Smsmith ******************************************************************************/ 667754Smsmith 7217365Sjkim/* 8245582Sjkim * Copyright (C) 2000 - 2013, Intel Corp. 970243Smsmith * All rights reserved. 1067754Smsmith * 11217365Sjkim * Redistribution and use in source and binary forms, with or without 12217365Sjkim * modification, are permitted provided that the following conditions 13217365Sjkim * are met: 14217365Sjkim * 1. Redistributions of source code must retain the above copyright 15217365Sjkim * notice, this list of conditions, and the following disclaimer, 16217365Sjkim * without modification. 17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20217365Sjkim * including a substantially similar Disclaimer requirement for further 21217365Sjkim * binary redistribution. 22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23217365Sjkim * of any contributors may be used to endorse or promote products derived 24217365Sjkim * from this software without specific prior written permission. 2567754Smsmith * 26217365Sjkim * Alternatively, this software may be distributed under the terms of the 27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28217365Sjkim * Software Foundation. 2967754Smsmith * 30217365Sjkim * NO WARRANTY 31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 42217365Sjkim */ 4367754Smsmith 4467754Smsmith 4567754Smsmith#define __RSUTILS_C__ 4667754Smsmith 47193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 48193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 49193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 50193341Sjkim#include <contrib/dev/acpica/include/acresrc.h> 5167754Smsmith 5267754Smsmith 5377424Smsmith#define _COMPONENT ACPI_RESOURCES 5491116Smsmith ACPI_MODULE_NAME ("rsutils") 5567754Smsmith 5667754Smsmith 5767754Smsmith/******************************************************************************* 5867754Smsmith * 59151937Sjkim * FUNCTION: AcpiRsDecodeBitmask 60151937Sjkim * 61151937Sjkim * PARAMETERS: Mask - Bitmask to decode 62151937Sjkim * List - Where the converted list is returned 63151937Sjkim * 64151937Sjkim * RETURN: Count of bits set (length of list) 65151937Sjkim * 66151937Sjkim * DESCRIPTION: Convert a bit mask into a list of values 67151937Sjkim * 68151937Sjkim ******************************************************************************/ 69151937Sjkim 70151937SjkimUINT8 71151937SjkimAcpiRsDecodeBitmask ( 72151937Sjkim UINT16 Mask, 73151937Sjkim UINT8 *List) 74151937Sjkim{ 75193267Sjkim UINT8 i; 76151937Sjkim UINT8 BitCount; 77151937Sjkim 78151937Sjkim 79167802Sjkim ACPI_FUNCTION_ENTRY (); 80167802Sjkim 81167802Sjkim 82151937Sjkim /* Decode the mask bits */ 83151937Sjkim 84151937Sjkim for (i = 0, BitCount = 0; Mask; i++) 85151937Sjkim { 86151937Sjkim if (Mask & 0x0001) 87151937Sjkim { 88193267Sjkim List[BitCount] = i; 89151937Sjkim BitCount++; 90151937Sjkim } 91151937Sjkim 92151937Sjkim Mask >>= 1; 93151937Sjkim } 94151937Sjkim 95151937Sjkim return (BitCount); 96151937Sjkim} 97151937Sjkim 98151937Sjkim 99151937Sjkim/******************************************************************************* 100151937Sjkim * 101151937Sjkim * FUNCTION: AcpiRsEncodeBitmask 102151937Sjkim * 103151937Sjkim * PARAMETERS: List - List of values to encode 104151937Sjkim * Count - Length of list 105151937Sjkim * 106151937Sjkim * RETURN: Encoded bitmask 107151937Sjkim * 108151937Sjkim * DESCRIPTION: Convert a list of values to an encoded bitmask 109151937Sjkim * 110151937Sjkim ******************************************************************************/ 111151937Sjkim 112151937SjkimUINT16 113151937SjkimAcpiRsEncodeBitmask ( 114151937Sjkim UINT8 *List, 115151937Sjkim UINT8 Count) 116151937Sjkim{ 117193267Sjkim UINT32 i; 118151937Sjkim UINT16 Mask; 119151937Sjkim 120151937Sjkim 121167802Sjkim ACPI_FUNCTION_ENTRY (); 122167802Sjkim 123167802Sjkim 124151937Sjkim /* Encode the list into a single bitmask */ 125151937Sjkim 126151937Sjkim for (i = 0, Mask = 0; i < Count; i++) 127151937Sjkim { 128193267Sjkim Mask |= (0x1 << List[i]); 129151937Sjkim } 130151937Sjkim 131151937Sjkim return (Mask); 132151937Sjkim} 133151937Sjkim 134151937Sjkim 135151937Sjkim/******************************************************************************* 136151937Sjkim * 137151937Sjkim * FUNCTION: AcpiRsMoveData 138151937Sjkim * 139151937Sjkim * PARAMETERS: Destination - Pointer to the destination descriptor 140151937Sjkim * Source - Pointer to the source descriptor 141151937Sjkim * ItemCount - How many items to move 142151937Sjkim * MoveType - Byte width 143151937Sjkim * 144151937Sjkim * RETURN: None 145151937Sjkim * 146151937Sjkim * DESCRIPTION: Move multiple data items from one descriptor to another. Handles 147151937Sjkim * alignment issues and endian issues if necessary, as configured 148151937Sjkim * via the ACPI_MOVE_* macros. (This is why a memcpy is not used) 149151937Sjkim * 150151937Sjkim ******************************************************************************/ 151151937Sjkim 152151937Sjkimvoid 153151937SjkimAcpiRsMoveData ( 154151937Sjkim void *Destination, 155151937Sjkim void *Source, 156151937Sjkim UINT16 ItemCount, 157151937Sjkim UINT8 MoveType) 158151937Sjkim{ 159193267Sjkim UINT32 i; 160151937Sjkim 161151937Sjkim 162167802Sjkim ACPI_FUNCTION_ENTRY (); 163167802Sjkim 164167802Sjkim 165151937Sjkim /* One move per item */ 166151937Sjkim 167151937Sjkim for (i = 0; i < ItemCount; i++) 168151937Sjkim { 169151937Sjkim switch (MoveType) 170151937Sjkim { 171151937Sjkim /* 172151937Sjkim * For the 8-bit case, we can perform the move all at once 173151937Sjkim * since there are no alignment or endian issues 174151937Sjkim */ 175151937Sjkim case ACPI_RSC_MOVE8: 176228110Sjkim case ACPI_RSC_MOVE_GPIO_RES: 177228110Sjkim case ACPI_RSC_MOVE_SERIAL_VEN: 178228110Sjkim case ACPI_RSC_MOVE_SERIAL_RES: 179250838Sjkim 180151937Sjkim ACPI_MEMCPY (Destination, Source, ItemCount); 181151937Sjkim return; 182151937Sjkim 183151937Sjkim /* 184151937Sjkim * 16-, 32-, and 64-bit cases must use the move macros that perform 185238381Sjkim * endian conversion and/or accommodate hardware that cannot perform 186151937Sjkim * misaligned memory transfers 187151937Sjkim */ 188151937Sjkim case ACPI_RSC_MOVE16: 189228110Sjkim case ACPI_RSC_MOVE_GPIO_PIN: 190250838Sjkim 191167802Sjkim ACPI_MOVE_16_TO_16 (&ACPI_CAST_PTR (UINT16, Destination)[i], 192167802Sjkim &ACPI_CAST_PTR (UINT16, Source)[i]); 193151937Sjkim break; 194151937Sjkim 195151937Sjkim case ACPI_RSC_MOVE32: 196252279Sjkim 197167802Sjkim ACPI_MOVE_32_TO_32 (&ACPI_CAST_PTR (UINT32, Destination)[i], 198167802Sjkim &ACPI_CAST_PTR (UINT32, Source)[i]); 199151937Sjkim break; 200151937Sjkim 201151937Sjkim case ACPI_RSC_MOVE64: 202250838Sjkim 203167802Sjkim ACPI_MOVE_64_TO_64 (&ACPI_CAST_PTR (UINT64, Destination)[i], 204167802Sjkim &ACPI_CAST_PTR (UINT64, Source)[i]); 205151937Sjkim break; 206151937Sjkim 207151937Sjkim default: 208250838Sjkim 209151937Sjkim return; 210151937Sjkim } 211151937Sjkim } 212151937Sjkim} 213151937Sjkim 214151937Sjkim 215151937Sjkim/******************************************************************************* 216151937Sjkim * 217151937Sjkim * FUNCTION: AcpiRsSetResourceLength 218151937Sjkim * 219151937Sjkim * PARAMETERS: TotalLength - Length of the AML descriptor, including 220151937Sjkim * the header and length fields. 221151937Sjkim * Aml - Pointer to the raw AML descriptor 222151937Sjkim * 223151937Sjkim * RETURN: None 224151937Sjkim * 225151937Sjkim * DESCRIPTION: Set the ResourceLength field of an AML 226151937Sjkim * resource descriptor, both Large and Small descriptors are 227151937Sjkim * supported automatically. Note: Descriptor Type field must 228151937Sjkim * be valid. 229151937Sjkim * 230151937Sjkim ******************************************************************************/ 231151937Sjkim 232151937Sjkimvoid 233151937SjkimAcpiRsSetResourceLength ( 234151937Sjkim ACPI_RSDESC_SIZE TotalLength, 235151937Sjkim AML_RESOURCE *Aml) 236151937Sjkim{ 237151937Sjkim ACPI_RS_LENGTH ResourceLength; 238151937Sjkim 239151937Sjkim 240151937Sjkim ACPI_FUNCTION_ENTRY (); 241151937Sjkim 242151937Sjkim 243167802Sjkim /* Length is the total descriptor length minus the header length */ 244151937Sjkim 245167802Sjkim ResourceLength = (ACPI_RS_LENGTH) 246167802Sjkim (TotalLength - AcpiUtGetResourceHeaderLength (Aml)); 247167802Sjkim 248167802Sjkim /* Length is stored differently for large and small descriptors */ 249167802Sjkim 250151937Sjkim if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE) 251151937Sjkim { 252167802Sjkim /* Large descriptor -- bytes 1-2 contain the 16-bit length */ 253151937Sjkim 254151937Sjkim ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength); 255151937Sjkim } 256151937Sjkim else 257151937Sjkim { 258167802Sjkim /* Small descriptor -- bits 2:0 of byte 0 contain the length */ 259151937Sjkim 260151937Sjkim Aml->SmallHeader.DescriptorType = (UINT8) 261151937Sjkim 262151937Sjkim /* Clear any existing length, preserving descriptor type bits */ 263151937Sjkim 264151937Sjkim ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK) 265151937Sjkim 266151937Sjkim | ResourceLength); 267151937Sjkim } 268151937Sjkim} 269151937Sjkim 270151937Sjkim 271151937Sjkim/******************************************************************************* 272151937Sjkim * 273151937Sjkim * FUNCTION: AcpiRsSetResourceHeader 274151937Sjkim * 275151937Sjkim * PARAMETERS: DescriptorType - Byte to be inserted as the type 276151937Sjkim * TotalLength - Length of the AML descriptor, including 277151937Sjkim * the header and length fields. 278151937Sjkim * Aml - Pointer to the raw AML descriptor 279151937Sjkim * 280151937Sjkim * RETURN: None 281151937Sjkim * 282151937Sjkim * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML 283151937Sjkim * resource descriptor, both Large and Small descriptors are 284151937Sjkim * supported automatically 285151937Sjkim * 286151937Sjkim ******************************************************************************/ 287151937Sjkim 288151937Sjkimvoid 289151937SjkimAcpiRsSetResourceHeader ( 290151937Sjkim UINT8 DescriptorType, 291151937Sjkim ACPI_RSDESC_SIZE TotalLength, 292151937Sjkim AML_RESOURCE *Aml) 293151937Sjkim{ 294151937Sjkim ACPI_FUNCTION_ENTRY (); 295151937Sjkim 296151937Sjkim 297167802Sjkim /* Set the Resource Type */ 298151937Sjkim 299151937Sjkim Aml->SmallHeader.DescriptorType = DescriptorType; 300151937Sjkim 301151937Sjkim /* Set the Resource Length */ 302151937Sjkim 303151937Sjkim AcpiRsSetResourceLength (TotalLength, Aml); 304151937Sjkim} 305151937Sjkim 306151937Sjkim 307151937Sjkim/******************************************************************************* 308151937Sjkim * 309151937Sjkim * FUNCTION: AcpiRsStrcpy 310151937Sjkim * 311151937Sjkim * PARAMETERS: Destination - Pointer to the destination string 312151937Sjkim * Source - Pointer to the source string 313151937Sjkim * 314151937Sjkim * RETURN: String length, including NULL terminator 315151937Sjkim * 316151937Sjkim * DESCRIPTION: Local string copy that returns the string length, saving a 317151937Sjkim * strcpy followed by a strlen. 318151937Sjkim * 319151937Sjkim ******************************************************************************/ 320151937Sjkim 321151937Sjkimstatic UINT16 322151937SjkimAcpiRsStrcpy ( 323151937Sjkim char *Destination, 324151937Sjkim char *Source) 325151937Sjkim{ 326151937Sjkim UINT16 i; 327151937Sjkim 328151937Sjkim 329151937Sjkim ACPI_FUNCTION_ENTRY (); 330151937Sjkim 331151937Sjkim 332151937Sjkim for (i = 0; Source[i]; i++) 333151937Sjkim { 334151937Sjkim Destination[i] = Source[i]; 335151937Sjkim } 336151937Sjkim 337151937Sjkim Destination[i] = 0; 338151937Sjkim 339151937Sjkim /* Return string length including the NULL terminator */ 340151937Sjkim 341151937Sjkim return ((UINT16) (i + 1)); 342151937Sjkim} 343151937Sjkim 344151937Sjkim 345151937Sjkim/******************************************************************************* 346151937Sjkim * 347151937Sjkim * FUNCTION: AcpiRsGetResourceSource 348151937Sjkim * 349151937Sjkim * PARAMETERS: ResourceLength - Length field of the descriptor 350151937Sjkim * MinimumLength - Minimum length of the descriptor (minus 351151937Sjkim * any optional fields) 352151937Sjkim * ResourceSource - Where the ResourceSource is returned 353151937Sjkim * Aml - Pointer to the raw AML descriptor 354151937Sjkim * StringPtr - (optional) where to store the actual 355151937Sjkim * ResourceSource string 356151937Sjkim * 357167802Sjkim * RETURN: Length of the string plus NULL terminator, rounded up to native 358167802Sjkim * word boundary 359151937Sjkim * 360151937Sjkim * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor 361151937Sjkim * to an internal resource descriptor 362151937Sjkim * 363151937Sjkim ******************************************************************************/ 364151937Sjkim 365151937SjkimACPI_RS_LENGTH 366151937SjkimAcpiRsGetResourceSource ( 367151937Sjkim ACPI_RS_LENGTH ResourceLength, 368151937Sjkim ACPI_RS_LENGTH MinimumLength, 369151937Sjkim ACPI_RESOURCE_SOURCE *ResourceSource, 370151937Sjkim AML_RESOURCE *Aml, 371151937Sjkim char *StringPtr) 372151937Sjkim{ 373151937Sjkim ACPI_RSDESC_SIZE TotalLength; 374151937Sjkim UINT8 *AmlResourceSource; 375151937Sjkim 376151937Sjkim 377151937Sjkim ACPI_FUNCTION_ENTRY (); 378151937Sjkim 379151937Sjkim 380151937Sjkim TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER); 381167802Sjkim AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength); 382151937Sjkim 383151937Sjkim /* 384151937Sjkim * ResourceSource is present if the length of the descriptor is longer than 385151937Sjkim * the minimum length. 386151937Sjkim * 387151937Sjkim * Note: Some resource descriptors will have an additional null, so 388151937Sjkim * we add 1 to the minimum length. 389151937Sjkim */ 390167802Sjkim if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1)) 391151937Sjkim { 392151937Sjkim /* Get the ResourceSourceIndex */ 393151937Sjkim 394151937Sjkim ResourceSource->Index = AmlResourceSource[0]; 395151937Sjkim 396151937Sjkim ResourceSource->StringPtr = StringPtr; 397151937Sjkim if (!StringPtr) 398151937Sjkim { 399151937Sjkim /* 400151937Sjkim * String destination pointer is not specified; Set the String 401151937Sjkim * pointer to the end of the current ResourceSource structure. 402151937Sjkim */ 403167802Sjkim ResourceSource->StringPtr = ACPI_ADD_PTR (char, ResourceSource, 404167802Sjkim sizeof (ACPI_RESOURCE_SOURCE)); 405151937Sjkim } 406151937Sjkim 407151937Sjkim /* 408167802Sjkim * In order for the Resource length to be a multiple of the native 409167802Sjkim * word, calculate the length of the string (+1 for NULL terminator) 410167802Sjkim * and expand to the next word multiple. 411151937Sjkim * 412151937Sjkim * Zero the entire area of the buffer. 413151937Sjkim */ 414167802Sjkim TotalLength = (UINT32) ACPI_STRLEN ( 415167802Sjkim ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1; 416167802Sjkim TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength); 417167802Sjkim 418151937Sjkim ACPI_MEMSET (ResourceSource->StringPtr, 0, TotalLength); 419151937Sjkim 420151937Sjkim /* Copy the ResourceSource string to the destination */ 421151937Sjkim 422151937Sjkim ResourceSource->StringLength = AcpiRsStrcpy (ResourceSource->StringPtr, 423167802Sjkim ACPI_CAST_PTR (char, &AmlResourceSource[1])); 424151937Sjkim 425151937Sjkim return ((ACPI_RS_LENGTH) TotalLength); 426151937Sjkim } 427151937Sjkim 428167802Sjkim /* ResourceSource is not present */ 429167802Sjkim 430167802Sjkim ResourceSource->Index = 0; 431167802Sjkim ResourceSource->StringLength = 0; 432167802Sjkim ResourceSource->StringPtr = NULL; 433167802Sjkim return (0); 434151937Sjkim} 435151937Sjkim 436167802Sjkim 437151937Sjkim/******************************************************************************* 438151937Sjkim * 439151937Sjkim * FUNCTION: AcpiRsSetResourceSource 440151937Sjkim * 441151937Sjkim * PARAMETERS: Aml - Pointer to the raw AML descriptor 442151937Sjkim * MinimumLength - Minimum length of the descriptor (minus 443151937Sjkim * any optional fields) 444151937Sjkim * ResourceSource - Internal ResourceSource 445151937Sjkim 446151937Sjkim * 447151937Sjkim * RETURN: Total length of the AML descriptor 448151937Sjkim * 449151937Sjkim * DESCRIPTION: Convert an optional ResourceSource from internal format to a 450151937Sjkim * raw AML resource descriptor 451151937Sjkim * 452151937Sjkim ******************************************************************************/ 453151937Sjkim 454151937SjkimACPI_RSDESC_SIZE 455151937SjkimAcpiRsSetResourceSource ( 456151937Sjkim AML_RESOURCE *Aml, 457151937Sjkim ACPI_RS_LENGTH MinimumLength, 458151937Sjkim ACPI_RESOURCE_SOURCE *ResourceSource) 459151937Sjkim{ 460151937Sjkim UINT8 *AmlResourceSource; 461151937Sjkim ACPI_RSDESC_SIZE DescriptorLength; 462151937Sjkim 463151937Sjkim 464151937Sjkim ACPI_FUNCTION_ENTRY (); 465151937Sjkim 466151937Sjkim 467151937Sjkim DescriptorLength = MinimumLength; 468151937Sjkim 469151937Sjkim /* Non-zero string length indicates presence of a ResourceSource */ 470151937Sjkim 471151937Sjkim if (ResourceSource->StringLength) 472151937Sjkim { 473151937Sjkim /* Point to the end of the AML descriptor */ 474151937Sjkim 475167802Sjkim AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength); 476151937Sjkim 477151937Sjkim /* Copy the ResourceSourceIndex */ 478151937Sjkim 479151937Sjkim AmlResourceSource[0] = (UINT8) ResourceSource->Index; 480151937Sjkim 481151937Sjkim /* Copy the ResourceSource string */ 482151937Sjkim 483167802Sjkim ACPI_STRCPY (ACPI_CAST_PTR (char, &AmlResourceSource[1]), 484167802Sjkim ResourceSource->StringPtr); 485151937Sjkim 486151937Sjkim /* 487151937Sjkim * Add the length of the string (+ 1 for null terminator) to the 488151937Sjkim * final descriptor length 489151937Sjkim */ 490151937Sjkim DescriptorLength += ((ACPI_RSDESC_SIZE) ResourceSource->StringLength + 1); 491151937Sjkim } 492151937Sjkim 493151937Sjkim /* Return the new total length of the AML descriptor */ 494151937Sjkim 495151937Sjkim return (DescriptorLength); 496151937Sjkim} 497151937Sjkim 498151937Sjkim 499151937Sjkim/******************************************************************************* 500151937Sjkim * 50167754Smsmith * FUNCTION: AcpiRsGetPrtMethodData 50267754Smsmith * 503167802Sjkim * PARAMETERS: Node - Device node 504167802Sjkim * RetBuffer - Pointer to a buffer structure for the 505167802Sjkim * results 50667754Smsmith * 50777424Smsmith * RETURN: Status 50867754Smsmith * 50967754Smsmith * DESCRIPTION: This function is called to get the _PRT value of an object 51067754Smsmith * contained in an object specified by the handle passed in 51167754Smsmith * 51267754Smsmith * If the function fails an appropriate status will be returned 51367754Smsmith * and the contents of the callers buffer is undefined. 51467754Smsmith * 51567754Smsmith ******************************************************************************/ 51667754Smsmith 51767754SmsmithACPI_STATUS 51867754SmsmithAcpiRsGetPrtMethodData ( 519167802Sjkim ACPI_NAMESPACE_NODE *Node, 52067754Smsmith ACPI_BUFFER *RetBuffer) 52167754Smsmith{ 52299679Siwasaki ACPI_OPERAND_OBJECT *ObjDesc; 52367754Smsmith ACPI_STATUS Status; 52467754Smsmith 52567754Smsmith 526167802Sjkim ACPI_FUNCTION_TRACE (RsGetPrtMethodData); 52767754Smsmith 52867754Smsmith 52991116Smsmith /* Parameters guaranteed valid by caller */ 53067754Smsmith 531151937Sjkim /* Execute the method, no parameters */ 532151937Sjkim 533167802Sjkim Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRT, 534151937Sjkim ACPI_BTYPE_PACKAGE, &ObjDesc); 53567754Smsmith if (ACPI_FAILURE (Status)) 53667754Smsmith { 53767754Smsmith return_ACPI_STATUS (Status); 53867754Smsmith } 53967754Smsmith 54067754Smsmith /* 54191116Smsmith * Create a resource linked list from the byte stream buffer that comes 54291116Smsmith * back from the _CRS method execution. 54367754Smsmith */ 54499679Siwasaki Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer); 54567754Smsmith 54691116Smsmith /* On exit, we must delete the object returned by EvaluateObject */ 54767754Smsmith 54899679Siwasaki AcpiUtRemoveReference (ObjDesc); 54967754Smsmith return_ACPI_STATUS (Status); 55067754Smsmith} 55167754Smsmith 55267754Smsmith 55367754Smsmith/******************************************************************************* 55467754Smsmith * 55567754Smsmith * FUNCTION: AcpiRsGetCrsMethodData 55667754Smsmith * 557167802Sjkim * PARAMETERS: Node - Device node 558167802Sjkim * RetBuffer - Pointer to a buffer structure for the 559167802Sjkim * results 56067754Smsmith * 56177424Smsmith * RETURN: Status 56267754Smsmith * 56367754Smsmith * DESCRIPTION: This function is called to get the _CRS value of an object 56467754Smsmith * contained in an object specified by the handle passed in 56567754Smsmith * 56667754Smsmith * If the function fails an appropriate status will be returned 56767754Smsmith * and the contents of the callers buffer is undefined. 56867754Smsmith * 56967754Smsmith ******************************************************************************/ 57067754Smsmith 57167754SmsmithACPI_STATUS 57267754SmsmithAcpiRsGetCrsMethodData ( 573167802Sjkim ACPI_NAMESPACE_NODE *Node, 57467754Smsmith ACPI_BUFFER *RetBuffer) 57567754Smsmith{ 57699679Siwasaki ACPI_OPERAND_OBJECT *ObjDesc; 57767754Smsmith ACPI_STATUS Status; 57867754Smsmith 57967754Smsmith 580167802Sjkim ACPI_FUNCTION_TRACE (RsGetCrsMethodData); 58167754Smsmith 58267754Smsmith 58391116Smsmith /* Parameters guaranteed valid by caller */ 58467754Smsmith 585151937Sjkim /* Execute the method, no parameters */ 586151937Sjkim 587167802Sjkim Status = AcpiUtEvaluateObject (Node, METHOD_NAME__CRS, 588151937Sjkim ACPI_BTYPE_BUFFER, &ObjDesc); 58967754Smsmith if (ACPI_FAILURE (Status)) 59067754Smsmith { 59167754Smsmith return_ACPI_STATUS (Status); 59267754Smsmith } 59367754Smsmith 59467754Smsmith /* 59567754Smsmith * Make the call to create a resource linked list from the 59691116Smsmith * byte stream buffer that comes back from the _CRS method 59791116Smsmith * execution. 59867754Smsmith */ 59999679Siwasaki Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 60067754Smsmith 60167754Smsmith /* On exit, we must delete the object returned by evaluateObject */ 60267754Smsmith 60399679Siwasaki AcpiUtRemoveReference (ObjDesc); 60467754Smsmith return_ACPI_STATUS (Status); 60567754Smsmith} 60667754Smsmith 60767754Smsmith 60867754Smsmith/******************************************************************************* 60967754Smsmith * 61067754Smsmith * FUNCTION: AcpiRsGetPrsMethodData 61167754Smsmith * 612167802Sjkim * PARAMETERS: Node - Device node 613167802Sjkim * RetBuffer - Pointer to a buffer structure for the 614167802Sjkim * results 61567754Smsmith * 61677424Smsmith * RETURN: Status 61767754Smsmith * 61867754Smsmith * DESCRIPTION: This function is called to get the _PRS value of an object 61967754Smsmith * contained in an object specified by the handle passed in 62067754Smsmith * 62167754Smsmith * If the function fails an appropriate status will be returned 62267754Smsmith * and the contents of the callers buffer is undefined. 62367754Smsmith * 62467754Smsmith ******************************************************************************/ 62567754Smsmith 62667754SmsmithACPI_STATUS 62767754SmsmithAcpiRsGetPrsMethodData ( 628167802Sjkim ACPI_NAMESPACE_NODE *Node, 62967754Smsmith ACPI_BUFFER *RetBuffer) 63067754Smsmith{ 63199679Siwasaki ACPI_OPERAND_OBJECT *ObjDesc; 63267754Smsmith ACPI_STATUS Status; 63367754Smsmith 63467754Smsmith 635167802Sjkim ACPI_FUNCTION_TRACE (RsGetPrsMethodData); 63667754Smsmith 63767754Smsmith 63891116Smsmith /* Parameters guaranteed valid by caller */ 63967754Smsmith 640151937Sjkim /* Execute the method, no parameters */ 641151937Sjkim 642167802Sjkim Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRS, 643151937Sjkim ACPI_BTYPE_BUFFER, &ObjDesc); 64467754Smsmith if (ACPI_FAILURE (Status)) 64567754Smsmith { 64667754Smsmith return_ACPI_STATUS (Status); 64767754Smsmith } 64867754Smsmith 649114237Snjl /* 650114237Snjl * Make the call to create a resource linked list from the 651114237Snjl * byte stream buffer that comes back from the _CRS method 652114237Snjl * execution. 653114237Snjl */ 654114237Snjl Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 65567754Smsmith 656114237Snjl /* On exit, we must delete the object returned by evaluateObject */ 65767754Smsmith 658114237Snjl AcpiUtRemoveReference (ObjDesc); 659114237Snjl return_ACPI_STATUS (Status); 660114237Snjl} 661114237Snjl 662114237Snjl 663114237Snjl/******************************************************************************* 664114237Snjl * 665228110Sjkim * FUNCTION: AcpiRsGetAeiMethodData 666228110Sjkim * 667228110Sjkim * PARAMETERS: Node - Device node 668228110Sjkim * RetBuffer - Pointer to a buffer structure for the 669228110Sjkim * results 670228110Sjkim * 671228110Sjkim * RETURN: Status 672228110Sjkim * 673228110Sjkim * DESCRIPTION: This function is called to get the _AEI value of an object 674228110Sjkim * contained in an object specified by the handle passed in 675228110Sjkim * 676228110Sjkim * If the function fails an appropriate status will be returned 677228110Sjkim * and the contents of the callers buffer is undefined. 678228110Sjkim * 679228110Sjkim ******************************************************************************/ 680228110Sjkim 681228110SjkimACPI_STATUS 682228110SjkimAcpiRsGetAeiMethodData ( 683228110Sjkim ACPI_NAMESPACE_NODE *Node, 684228110Sjkim ACPI_BUFFER *RetBuffer) 685228110Sjkim{ 686228110Sjkim ACPI_OPERAND_OBJECT *ObjDesc; 687228110Sjkim ACPI_STATUS Status; 688228110Sjkim 689228110Sjkim 690228110Sjkim ACPI_FUNCTION_TRACE (RsGetAeiMethodData); 691228110Sjkim 692228110Sjkim 693228110Sjkim /* Parameters guaranteed valid by caller */ 694228110Sjkim 695228110Sjkim /* Execute the method, no parameters */ 696228110Sjkim 697228110Sjkim Status = AcpiUtEvaluateObject (Node, METHOD_NAME__AEI, 698228110Sjkim ACPI_BTYPE_BUFFER, &ObjDesc); 699228110Sjkim if (ACPI_FAILURE (Status)) 700228110Sjkim { 701228110Sjkim return_ACPI_STATUS (Status); 702228110Sjkim } 703228110Sjkim 704228110Sjkim /* 705228110Sjkim * Make the call to create a resource linked list from the 706228110Sjkim * byte stream buffer that comes back from the _CRS method 707228110Sjkim * execution. 708228110Sjkim */ 709228110Sjkim Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 710228110Sjkim 711228110Sjkim /* On exit, we must delete the object returned by evaluateObject */ 712228110Sjkim 713228110Sjkim AcpiUtRemoveReference (ObjDesc); 714228110Sjkim return_ACPI_STATUS (Status); 715228110Sjkim} 716228110Sjkim 717228110Sjkim 718228110Sjkim/******************************************************************************* 719228110Sjkim * 720114237Snjl * FUNCTION: AcpiRsGetMethodData 721114237Snjl * 722167802Sjkim * PARAMETERS: Handle - Handle to the containing object 723151937Sjkim * Path - Path to method, relative to Handle 724167802Sjkim * RetBuffer - Pointer to a buffer structure for the 725167802Sjkim * results 726114237Snjl * 727114237Snjl * RETURN: Status 728114237Snjl * 729114237Snjl * DESCRIPTION: This function is called to get the _CRS or _PRS value of an 730114237Snjl * object contained in an object specified by the handle passed in 731114237Snjl * 732114237Snjl * If the function fails an appropriate status will be returned 733114237Snjl * and the contents of the callers buffer is undefined. 734114237Snjl * 735114237Snjl ******************************************************************************/ 736114237Snjl 737114237SnjlACPI_STATUS 738114237SnjlAcpiRsGetMethodData ( 739114237Snjl ACPI_HANDLE Handle, 740114237Snjl char *Path, 741114237Snjl ACPI_BUFFER *RetBuffer) 742114237Snjl{ 743114237Snjl ACPI_OPERAND_OBJECT *ObjDesc; 744114237Snjl ACPI_STATUS Status; 745114237Snjl 746114237Snjl 747167802Sjkim ACPI_FUNCTION_TRACE (RsGetMethodData); 748114237Snjl 749114237Snjl 750114237Snjl /* Parameters guaranteed valid by caller */ 751114237Snjl 752151937Sjkim /* Execute the method, no parameters */ 753151937Sjkim 754245582Sjkim Status = AcpiUtEvaluateObject (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle), 755245582Sjkim Path, ACPI_BTYPE_BUFFER, &ObjDesc); 756167802Sjkim if (ACPI_FAILURE (Status)) 757167802Sjkim { 758114237Snjl return_ACPI_STATUS (Status); 75967754Smsmith } 76067754Smsmith 76167754Smsmith /* 76267754Smsmith * Make the call to create a resource linked list from the 763114237Snjl * byte stream buffer that comes back from the method 76491116Smsmith * execution. 76567754Smsmith */ 76699679Siwasaki Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 76767754Smsmith 768114237Snjl /* On exit, we must delete the object returned by EvaluateObject */ 76967754Smsmith 77099679Siwasaki AcpiUtRemoveReference (ObjDesc); 77167754Smsmith return_ACPI_STATUS (Status); 77267754Smsmith} 77367754Smsmith 774167802Sjkim 77567754Smsmith/******************************************************************************* 77667754Smsmith * 77767754Smsmith * FUNCTION: AcpiRsSetSrsMethodData 77867754Smsmith * 779167802Sjkim * PARAMETERS: Node - Device node 780167802Sjkim * InBuffer - Pointer to a buffer structure of the 781167802Sjkim * parameter 78267754Smsmith * 78377424Smsmith * RETURN: Status 78467754Smsmith * 78567754Smsmith * DESCRIPTION: This function is called to set the _SRS of an object contained 78667754Smsmith * in an object specified by the handle passed in 78767754Smsmith * 78867754Smsmith * If the function fails an appropriate status will be returned 78967754Smsmith * and the contents of the callers buffer is undefined. 79067754Smsmith * 791167802Sjkim * Note: Parameters guaranteed valid by caller 792167802Sjkim * 79367754Smsmith ******************************************************************************/ 79467754Smsmith 79567754SmsmithACPI_STATUS 79667754SmsmithAcpiRsSetSrsMethodData ( 797167802Sjkim ACPI_NAMESPACE_NODE *Node, 79867754Smsmith ACPI_BUFFER *InBuffer) 79967754Smsmith{ 800167802Sjkim ACPI_EVALUATE_INFO *Info; 801167802Sjkim ACPI_OPERAND_OBJECT *Args[2]; 80267754Smsmith ACPI_STATUS Status; 80391116Smsmith ACPI_BUFFER Buffer; 80467754Smsmith 80567754Smsmith 806167802Sjkim ACPI_FUNCTION_TRACE (RsSetSrsMethodData); 80767754Smsmith 80867754Smsmith 809167802Sjkim /* Allocate and initialize the evaluation information block */ 81067754Smsmith 811167802Sjkim Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); 812167802Sjkim if (!Info) 813167802Sjkim { 814167802Sjkim return_ACPI_STATUS (AE_NO_MEMORY); 815167802Sjkim } 816167802Sjkim 817167802Sjkim Info->PrefixNode = Node; 818249663Sjkim Info->RelativePathname = METHOD_NAME__SRS; 819167802Sjkim Info->Parameters = Args; 820167802Sjkim Info->Flags = ACPI_IGNORE_RETURN_VALUE; 821167802Sjkim 82267754Smsmith /* 82367754Smsmith * The InBuffer parameter will point to a linked list of 824167802Sjkim * resource parameters. It needs to be formatted into a 82591116Smsmith * byte stream to be sent in as an input parameter to _SRS 82691116Smsmith * 82791116Smsmith * Convert the linked list into a byte stream 82867754Smsmith */ 82991116Smsmith Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER; 830151937Sjkim Status = AcpiRsCreateAmlResources (InBuffer->Pointer, &Buffer); 83191116Smsmith if (ACPI_FAILURE (Status)) 83267754Smsmith { 833167802Sjkim goto Cleanup; 83467754Smsmith } 83567754Smsmith 836167802Sjkim /* Create and initialize the method parameter object */ 837151937Sjkim 838167802Sjkim Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER); 839167802Sjkim if (!Args[0]) 84084491Smsmith { 841167802Sjkim /* 842167802Sjkim * Must free the buffer allocated above (otherwise it is freed 843167802Sjkim * later) 844167802Sjkim */ 845167802Sjkim ACPI_FREE (Buffer.Pointer); 846167802Sjkim Status = AE_NO_MEMORY; 847167802Sjkim goto Cleanup; 84884491Smsmith } 84967754Smsmith 850167802Sjkim Args[0]->Buffer.Length = (UINT32) Buffer.Length; 851167802Sjkim Args[0]->Buffer.Pointer = Buffer.Pointer; 852167802Sjkim Args[0]->Common.Flags = AOPOBJ_DATA_VALID; 853167802Sjkim Args[1] = NULL; 854151937Sjkim 855167802Sjkim /* Execute the method, no return value is expected */ 85667754Smsmith 857167802Sjkim Status = AcpiNsEvaluate (Info); 858129684Snjl 859167802Sjkim /* Clean up and return the status from AcpiNsEvaluate */ 86067754Smsmith 861167802Sjkim AcpiUtRemoveReference (Args[0]); 862151937Sjkim 863167802SjkimCleanup: 864167802Sjkim ACPI_FREE (Info); 86567754Smsmith return_ACPI_STATUS (Status); 86667754Smsmith} 867