167754Smsmith/******************************************************************************* 267754Smsmith * 367754Smsmith * Module Name: rsutils - Utilities for the resource manager 467754Smsmith * 567754Smsmith ******************************************************************************/ 667754Smsmith 7316303Sjkim/****************************************************************************** 8316303Sjkim * 9316303Sjkim * 1. Copyright Notice 10316303Sjkim * 11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 1270243Smsmith * All rights reserved. 1367754Smsmith * 14316303Sjkim * 2. License 15316303Sjkim * 16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 17316303Sjkim * rights. You may have additional license terms from the party that provided 18316303Sjkim * you this software, covering your right to use that party's intellectual 19316303Sjkim * property rights. 20316303Sjkim * 21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an 23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered 26316303Sjkim * Code in any form, with the right to sublicense such rights; and 27316303Sjkim * 28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29316303Sjkim * license (with the right to sublicense), under only those claims of Intel 30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof 32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright 33316303Sjkim * license, and in no event shall the patent license extend to any additions 34316303Sjkim * to or modifications of the Original Intel Code. No other license or right 35316303Sjkim * is granted directly or by implication, estoppel or otherwise; 36316303Sjkim * 37316303Sjkim * The above copyright and patent license is granted only if the following 38316303Sjkim * conditions are met: 39316303Sjkim * 40316303Sjkim * 3. Conditions 41316303Sjkim * 42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43316303Sjkim * Redistribution of source code of any substantial portion of the Covered 44316303Sjkim * Code or modification with rights to further distribute source must include 45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions, 46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered 49316303Sjkim * Code and the date of any change. Licensee must include in that file the 50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 51316303Sjkim * must include a prominent statement that the modification is derived, 52316303Sjkim * directly or indirectly, from Original Intel Code. 53316303Sjkim * 54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55316303Sjkim * Redistribution of source code of any substantial portion of the Covered 56316303Sjkim * Code or modification without rights to further distribute source must 57316303Sjkim * include the following Disclaimer and Export Compliance provision in the 58316303Sjkim * documentation and/or other materials provided with distribution. In 59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any 60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the 61316303Sjkim * license from Licensee to its licensee is limited to the intellectual 62316303Sjkim * property embodied in the software Licensee provides to its licensee, and 63316303Sjkim * not to intellectual property embodied in modifications its licensee may 64316303Sjkim * make. 65316303Sjkim * 66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the 68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 69316303Sjkim * provision in the documentation and/or other materials provided with the 70316303Sjkim * distribution. 71316303Sjkim * 72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 73316303Sjkim * Intel Code. 74316303Sjkim * 75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 77316303Sjkim * other dealings in products derived from or relating to the Covered Code 78316303Sjkim * without prior written authorization from Intel. 79316303Sjkim * 80316303Sjkim * 4. Disclaimer and Export Compliance 81316303Sjkim * 82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88316303Sjkim * PARTICULAR PURPOSE. 89316303Sjkim * 90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97316303Sjkim * LIMITED REMEDY. 98316303Sjkim * 99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100316303Sjkim * software or system incorporating such software without first obtaining any 101316303Sjkim * required license or other approval from the U. S. Department of Commerce or 102316303Sjkim * any other agency or department of the United States Government. In the 103316303Sjkim * event Licensee exports any such software from the United States or 104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall 105316303Sjkim * ensure that the distribution and export/re-export of the software is in 106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process, 109316303Sjkim * software, or service, directly or indirectly, to any country for which the 110316303Sjkim * United States government or any agency thereof requires an export license, 111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining 112316303Sjkim * such license, approval or letter. 113316303Sjkim * 114316303Sjkim ***************************************************************************** 115316303Sjkim * 116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 117316303Sjkim * following license: 118316303Sjkim * 119217365Sjkim * Redistribution and use in source and binary forms, with or without 120217365Sjkim * modification, are permitted provided that the following conditions 121217365Sjkim * are met: 122217365Sjkim * 1. Redistributions of source code must retain the above copyright 123217365Sjkim * notice, this list of conditions, and the following disclaimer, 124217365Sjkim * without modification. 125217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 127217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 128217365Sjkim * including a substantially similar Disclaimer requirement for further 129217365Sjkim * binary redistribution. 130217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 131217365Sjkim * of any contributors may be used to endorse or promote products derived 132217365Sjkim * from this software without specific prior written permission. 13367754Smsmith * 134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145316303Sjkim * 146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 147217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 148217365Sjkim * Software Foundation. 14967754Smsmith * 150316303Sjkim *****************************************************************************/ 15167754Smsmith 152193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 153193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 154193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 155193341Sjkim#include <contrib/dev/acpica/include/acresrc.h> 15667754Smsmith 15767754Smsmith 15877424Smsmith#define _COMPONENT ACPI_RESOURCES 15991116Smsmith ACPI_MODULE_NAME ("rsutils") 16067754Smsmith 16167754Smsmith 16267754Smsmith/******************************************************************************* 16367754Smsmith * 164151937Sjkim * FUNCTION: AcpiRsDecodeBitmask 165151937Sjkim * 166151937Sjkim * PARAMETERS: Mask - Bitmask to decode 167151937Sjkim * List - Where the converted list is returned 168151937Sjkim * 169151937Sjkim * RETURN: Count of bits set (length of list) 170151937Sjkim * 171151937Sjkim * DESCRIPTION: Convert a bit mask into a list of values 172151937Sjkim * 173151937Sjkim ******************************************************************************/ 174151937Sjkim 175151937SjkimUINT8 176151937SjkimAcpiRsDecodeBitmask ( 177151937Sjkim UINT16 Mask, 178151937Sjkim UINT8 *List) 179151937Sjkim{ 180193267Sjkim UINT8 i; 181151937Sjkim UINT8 BitCount; 182151937Sjkim 183151937Sjkim 184167802Sjkim ACPI_FUNCTION_ENTRY (); 185167802Sjkim 186167802Sjkim 187151937Sjkim /* Decode the mask bits */ 188151937Sjkim 189151937Sjkim for (i = 0, BitCount = 0; Mask; i++) 190151937Sjkim { 191151937Sjkim if (Mask & 0x0001) 192151937Sjkim { 193193267Sjkim List[BitCount] = i; 194151937Sjkim BitCount++; 195151937Sjkim } 196151937Sjkim 197151937Sjkim Mask >>= 1; 198151937Sjkim } 199151937Sjkim 200151937Sjkim return (BitCount); 201151937Sjkim} 202151937Sjkim 203151937Sjkim 204151937Sjkim/******************************************************************************* 205151937Sjkim * 206151937Sjkim * FUNCTION: AcpiRsEncodeBitmask 207151937Sjkim * 208151937Sjkim * PARAMETERS: List - List of values to encode 209151937Sjkim * Count - Length of list 210151937Sjkim * 211151937Sjkim * RETURN: Encoded bitmask 212151937Sjkim * 213151937Sjkim * DESCRIPTION: Convert a list of values to an encoded bitmask 214151937Sjkim * 215151937Sjkim ******************************************************************************/ 216151937Sjkim 217151937SjkimUINT16 218151937SjkimAcpiRsEncodeBitmask ( 219151937Sjkim UINT8 *List, 220151937Sjkim UINT8 Count) 221151937Sjkim{ 222193267Sjkim UINT32 i; 223151937Sjkim UINT16 Mask; 224151937Sjkim 225151937Sjkim 226167802Sjkim ACPI_FUNCTION_ENTRY (); 227167802Sjkim 228167802Sjkim 229151937Sjkim /* Encode the list into a single bitmask */ 230151937Sjkim 231151937Sjkim for (i = 0, Mask = 0; i < Count; i++) 232151937Sjkim { 233193267Sjkim Mask |= (0x1 << List[i]); 234151937Sjkim } 235151937Sjkim 236151937Sjkim return (Mask); 237151937Sjkim} 238151937Sjkim 239151937Sjkim 240151937Sjkim/******************************************************************************* 241151937Sjkim * 242151937Sjkim * FUNCTION: AcpiRsMoveData 243151937Sjkim * 244151937Sjkim * PARAMETERS: Destination - Pointer to the destination descriptor 245151937Sjkim * Source - Pointer to the source descriptor 246151937Sjkim * ItemCount - How many items to move 247151937Sjkim * MoveType - Byte width 248151937Sjkim * 249151937Sjkim * RETURN: None 250151937Sjkim * 251151937Sjkim * DESCRIPTION: Move multiple data items from one descriptor to another. Handles 252151937Sjkim * alignment issues and endian issues if necessary, as configured 253151937Sjkim * via the ACPI_MOVE_* macros. (This is why a memcpy is not used) 254151937Sjkim * 255151937Sjkim ******************************************************************************/ 256151937Sjkim 257151937Sjkimvoid 258151937SjkimAcpiRsMoveData ( 259151937Sjkim void *Destination, 260151937Sjkim void *Source, 261151937Sjkim UINT16 ItemCount, 262151937Sjkim UINT8 MoveType) 263151937Sjkim{ 264193267Sjkim UINT32 i; 265151937Sjkim 266151937Sjkim 267167802Sjkim ACPI_FUNCTION_ENTRY (); 268167802Sjkim 269167802Sjkim 270151937Sjkim /* One move per item */ 271151937Sjkim 272151937Sjkim for (i = 0; i < ItemCount; i++) 273151937Sjkim { 274151937Sjkim switch (MoveType) 275151937Sjkim { 276151937Sjkim /* 277151937Sjkim * For the 8-bit case, we can perform the move all at once 278151937Sjkim * since there are no alignment or endian issues 279151937Sjkim */ 280151937Sjkim case ACPI_RSC_MOVE8: 281228110Sjkim case ACPI_RSC_MOVE_GPIO_RES: 282228110Sjkim case ACPI_RSC_MOVE_SERIAL_VEN: 283228110Sjkim case ACPI_RSC_MOVE_SERIAL_RES: 284250838Sjkim 285284583Sjkim memcpy (Destination, Source, ItemCount); 286151937Sjkim return; 287151937Sjkim 288151937Sjkim /* 289151937Sjkim * 16-, 32-, and 64-bit cases must use the move macros that perform 290238381Sjkim * endian conversion and/or accommodate hardware that cannot perform 291151937Sjkim * misaligned memory transfers 292151937Sjkim */ 293151937Sjkim case ACPI_RSC_MOVE16: 294228110Sjkim case ACPI_RSC_MOVE_GPIO_PIN: 295250838Sjkim 296298714Sjkim ACPI_MOVE_16_TO_16 ( 297298714Sjkim &ACPI_CAST_PTR (UINT16, Destination)[i], 298298714Sjkim &ACPI_CAST_PTR (UINT16, Source)[i]); 299151937Sjkim break; 300151937Sjkim 301151937Sjkim case ACPI_RSC_MOVE32: 302252279Sjkim 303298714Sjkim ACPI_MOVE_32_TO_32 ( 304298714Sjkim &ACPI_CAST_PTR (UINT32, Destination)[i], 305298714Sjkim &ACPI_CAST_PTR (UINT32, Source)[i]); 306151937Sjkim break; 307151937Sjkim 308151937Sjkim case ACPI_RSC_MOVE64: 309250838Sjkim 310298714Sjkim ACPI_MOVE_64_TO_64 ( 311298714Sjkim &ACPI_CAST_PTR (UINT64, Destination)[i], 312298714Sjkim &ACPI_CAST_PTR (UINT64, Source)[i]); 313151937Sjkim break; 314151937Sjkim 315151937Sjkim default: 316250838Sjkim 317151937Sjkim return; 318151937Sjkim } 319151937Sjkim } 320151937Sjkim} 321151937Sjkim 322151937Sjkim 323151937Sjkim/******************************************************************************* 324151937Sjkim * 325151937Sjkim * FUNCTION: AcpiRsSetResourceLength 326151937Sjkim * 327151937Sjkim * PARAMETERS: TotalLength - Length of the AML descriptor, including 328151937Sjkim * the header and length fields. 329151937Sjkim * Aml - Pointer to the raw AML descriptor 330151937Sjkim * 331151937Sjkim * RETURN: None 332151937Sjkim * 333151937Sjkim * DESCRIPTION: Set the ResourceLength field of an AML 334151937Sjkim * resource descriptor, both Large and Small descriptors are 335151937Sjkim * supported automatically. Note: Descriptor Type field must 336151937Sjkim * be valid. 337151937Sjkim * 338151937Sjkim ******************************************************************************/ 339151937Sjkim 340151937Sjkimvoid 341151937SjkimAcpiRsSetResourceLength ( 342151937Sjkim ACPI_RSDESC_SIZE TotalLength, 343151937Sjkim AML_RESOURCE *Aml) 344151937Sjkim{ 345151937Sjkim ACPI_RS_LENGTH ResourceLength; 346151937Sjkim 347151937Sjkim 348151937Sjkim ACPI_FUNCTION_ENTRY (); 349151937Sjkim 350151937Sjkim 351167802Sjkim /* Length is the total descriptor length minus the header length */ 352151937Sjkim 353167802Sjkim ResourceLength = (ACPI_RS_LENGTH) 354167802Sjkim (TotalLength - AcpiUtGetResourceHeaderLength (Aml)); 355167802Sjkim 356167802Sjkim /* Length is stored differently for large and small descriptors */ 357167802Sjkim 358151937Sjkim if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE) 359151937Sjkim { 360167802Sjkim /* Large descriptor -- bytes 1-2 contain the 16-bit length */ 361151937Sjkim 362298714Sjkim ACPI_MOVE_16_TO_16 ( 363298714Sjkim &Aml->LargeHeader.ResourceLength, &ResourceLength); 364151937Sjkim } 365151937Sjkim else 366151937Sjkim { 367298714Sjkim /* 368298714Sjkim * Small descriptor -- bits 2:0 of byte 0 contain the length 369298714Sjkim * Clear any existing length, preserving descriptor type bits 370298714Sjkim */ 371151937Sjkim Aml->SmallHeader.DescriptorType = (UINT8) 372298714Sjkim ((Aml->SmallHeader.DescriptorType & 373298714Sjkim ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK) 374151937Sjkim | ResourceLength); 375151937Sjkim } 376151937Sjkim} 377151937Sjkim 378151937Sjkim 379151937Sjkim/******************************************************************************* 380151937Sjkim * 381151937Sjkim * FUNCTION: AcpiRsSetResourceHeader 382151937Sjkim * 383151937Sjkim * PARAMETERS: DescriptorType - Byte to be inserted as the type 384151937Sjkim * TotalLength - Length of the AML descriptor, including 385151937Sjkim * the header and length fields. 386151937Sjkim * Aml - Pointer to the raw AML descriptor 387151937Sjkim * 388151937Sjkim * RETURN: None 389151937Sjkim * 390151937Sjkim * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML 391151937Sjkim * resource descriptor, both Large and Small descriptors are 392151937Sjkim * supported automatically 393151937Sjkim * 394151937Sjkim ******************************************************************************/ 395151937Sjkim 396151937Sjkimvoid 397151937SjkimAcpiRsSetResourceHeader ( 398151937Sjkim UINT8 DescriptorType, 399151937Sjkim ACPI_RSDESC_SIZE TotalLength, 400151937Sjkim AML_RESOURCE *Aml) 401151937Sjkim{ 402151937Sjkim ACPI_FUNCTION_ENTRY (); 403151937Sjkim 404151937Sjkim 405167802Sjkim /* Set the Resource Type */ 406151937Sjkim 407151937Sjkim Aml->SmallHeader.DescriptorType = DescriptorType; 408151937Sjkim 409151937Sjkim /* Set the Resource Length */ 410151937Sjkim 411151937Sjkim AcpiRsSetResourceLength (TotalLength, Aml); 412151937Sjkim} 413151937Sjkim 414151937Sjkim 415151937Sjkim/******************************************************************************* 416151937Sjkim * 417151937Sjkim * FUNCTION: AcpiRsStrcpy 418151937Sjkim * 419151937Sjkim * PARAMETERS: Destination - Pointer to the destination string 420151937Sjkim * Source - Pointer to the source string 421151937Sjkim * 422151937Sjkim * RETURN: String length, including NULL terminator 423151937Sjkim * 424151937Sjkim * DESCRIPTION: Local string copy that returns the string length, saving a 425151937Sjkim * strcpy followed by a strlen. 426151937Sjkim * 427151937Sjkim ******************************************************************************/ 428151937Sjkim 429151937Sjkimstatic UINT16 430151937SjkimAcpiRsStrcpy ( 431151937Sjkim char *Destination, 432151937Sjkim char *Source) 433151937Sjkim{ 434151937Sjkim UINT16 i; 435151937Sjkim 436151937Sjkim 437151937Sjkim ACPI_FUNCTION_ENTRY (); 438151937Sjkim 439151937Sjkim 440151937Sjkim for (i = 0; Source[i]; i++) 441151937Sjkim { 442151937Sjkim Destination[i] = Source[i]; 443151937Sjkim } 444151937Sjkim 445151937Sjkim Destination[i] = 0; 446151937Sjkim 447151937Sjkim /* Return string length including the NULL terminator */ 448151937Sjkim 449151937Sjkim return ((UINT16) (i + 1)); 450151937Sjkim} 451151937Sjkim 452151937Sjkim 453151937Sjkim/******************************************************************************* 454151937Sjkim * 455151937Sjkim * FUNCTION: AcpiRsGetResourceSource 456151937Sjkim * 457151937Sjkim * PARAMETERS: ResourceLength - Length field of the descriptor 458151937Sjkim * MinimumLength - Minimum length of the descriptor (minus 459151937Sjkim * any optional fields) 460151937Sjkim * ResourceSource - Where the ResourceSource is returned 461151937Sjkim * Aml - Pointer to the raw AML descriptor 462151937Sjkim * StringPtr - (optional) where to store the actual 463151937Sjkim * ResourceSource string 464151937Sjkim * 465167802Sjkim * RETURN: Length of the string plus NULL terminator, rounded up to native 466167802Sjkim * word boundary 467151937Sjkim * 468151937Sjkim * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor 469151937Sjkim * to an internal resource descriptor 470151937Sjkim * 471151937Sjkim ******************************************************************************/ 472151937Sjkim 473151937SjkimACPI_RS_LENGTH 474151937SjkimAcpiRsGetResourceSource ( 475151937Sjkim ACPI_RS_LENGTH ResourceLength, 476151937Sjkim ACPI_RS_LENGTH MinimumLength, 477151937Sjkim ACPI_RESOURCE_SOURCE *ResourceSource, 478151937Sjkim AML_RESOURCE *Aml, 479151937Sjkim char *StringPtr) 480151937Sjkim{ 481151937Sjkim ACPI_RSDESC_SIZE TotalLength; 482151937Sjkim UINT8 *AmlResourceSource; 483151937Sjkim 484151937Sjkim 485151937Sjkim ACPI_FUNCTION_ENTRY (); 486151937Sjkim 487151937Sjkim 488151937Sjkim TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER); 489167802Sjkim AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength); 490151937Sjkim 491151937Sjkim /* 492298714Sjkim * ResourceSource is present if the length of the descriptor is longer 493298714Sjkim * than the minimum length. 494151937Sjkim * 495151937Sjkim * Note: Some resource descriptors will have an additional null, so 496151937Sjkim * we add 1 to the minimum length. 497151937Sjkim */ 498167802Sjkim if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1)) 499151937Sjkim { 500151937Sjkim /* Get the ResourceSourceIndex */ 501151937Sjkim 502151937Sjkim ResourceSource->Index = AmlResourceSource[0]; 503151937Sjkim 504151937Sjkim ResourceSource->StringPtr = StringPtr; 505151937Sjkim if (!StringPtr) 506151937Sjkim { 507151937Sjkim /* 508151937Sjkim * String destination pointer is not specified; Set the String 509151937Sjkim * pointer to the end of the current ResourceSource structure. 510151937Sjkim */ 511298714Sjkim ResourceSource->StringPtr = ACPI_ADD_PTR ( 512298714Sjkim char, ResourceSource, sizeof (ACPI_RESOURCE_SOURCE)); 513151937Sjkim } 514151937Sjkim 515151937Sjkim /* 516167802Sjkim * In order for the Resource length to be a multiple of the native 517167802Sjkim * word, calculate the length of the string (+1 for NULL terminator) 518167802Sjkim * and expand to the next word multiple. 519151937Sjkim * 520151937Sjkim * Zero the entire area of the buffer. 521151937Sjkim */ 522284583Sjkim TotalLength = (UINT32) strlen ( 523167802Sjkim ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1; 524298714Sjkim 525167802Sjkim TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength); 526167802Sjkim 527284583Sjkim memset (ResourceSource->StringPtr, 0, TotalLength); 528151937Sjkim 529151937Sjkim /* Copy the ResourceSource string to the destination */ 530151937Sjkim 531298714Sjkim ResourceSource->StringLength = AcpiRsStrcpy ( 532298714Sjkim ResourceSource->StringPtr, 533167802Sjkim ACPI_CAST_PTR (char, &AmlResourceSource[1])); 534151937Sjkim 535151937Sjkim return ((ACPI_RS_LENGTH) TotalLength); 536151937Sjkim } 537151937Sjkim 538167802Sjkim /* ResourceSource is not present */ 539167802Sjkim 540167802Sjkim ResourceSource->Index = 0; 541167802Sjkim ResourceSource->StringLength = 0; 542167802Sjkim ResourceSource->StringPtr = NULL; 543167802Sjkim return (0); 544151937Sjkim} 545151937Sjkim 546167802Sjkim 547151937Sjkim/******************************************************************************* 548151937Sjkim * 549151937Sjkim * FUNCTION: AcpiRsSetResourceSource 550151937Sjkim * 551151937Sjkim * PARAMETERS: Aml - Pointer to the raw AML descriptor 552151937Sjkim * MinimumLength - Minimum length of the descriptor (minus 553151937Sjkim * any optional fields) 554151937Sjkim * ResourceSource - Internal ResourceSource 555151937Sjkim 556151937Sjkim * 557151937Sjkim * RETURN: Total length of the AML descriptor 558151937Sjkim * 559151937Sjkim * DESCRIPTION: Convert an optional ResourceSource from internal format to a 560151937Sjkim * raw AML resource descriptor 561151937Sjkim * 562151937Sjkim ******************************************************************************/ 563151937Sjkim 564151937SjkimACPI_RSDESC_SIZE 565151937SjkimAcpiRsSetResourceSource ( 566151937Sjkim AML_RESOURCE *Aml, 567151937Sjkim ACPI_RS_LENGTH MinimumLength, 568151937Sjkim ACPI_RESOURCE_SOURCE *ResourceSource) 569151937Sjkim{ 570151937Sjkim UINT8 *AmlResourceSource; 571151937Sjkim ACPI_RSDESC_SIZE DescriptorLength; 572151937Sjkim 573151937Sjkim 574151937Sjkim ACPI_FUNCTION_ENTRY (); 575151937Sjkim 576151937Sjkim 577151937Sjkim DescriptorLength = MinimumLength; 578151937Sjkim 579151937Sjkim /* Non-zero string length indicates presence of a ResourceSource */ 580151937Sjkim 581151937Sjkim if (ResourceSource->StringLength) 582151937Sjkim { 583151937Sjkim /* Point to the end of the AML descriptor */ 584151937Sjkim 585167802Sjkim AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength); 586151937Sjkim 587151937Sjkim /* Copy the ResourceSourceIndex */ 588151937Sjkim 589151937Sjkim AmlResourceSource[0] = (UINT8) ResourceSource->Index; 590151937Sjkim 591151937Sjkim /* Copy the ResourceSource string */ 592151937Sjkim 593284583Sjkim strcpy (ACPI_CAST_PTR (char, &AmlResourceSource[1]), 594167802Sjkim ResourceSource->StringPtr); 595151937Sjkim 596151937Sjkim /* 597151937Sjkim * Add the length of the string (+ 1 for null terminator) to the 598151937Sjkim * final descriptor length 599151937Sjkim */ 600298714Sjkim DescriptorLength += ((ACPI_RSDESC_SIZE) 601298714Sjkim ResourceSource->StringLength + 1); 602151937Sjkim } 603151937Sjkim 604151937Sjkim /* Return the new total length of the AML descriptor */ 605151937Sjkim 606151937Sjkim return (DescriptorLength); 607151937Sjkim} 608151937Sjkim 609151937Sjkim 610151937Sjkim/******************************************************************************* 611151937Sjkim * 61267754Smsmith * FUNCTION: AcpiRsGetPrtMethodData 61367754Smsmith * 614167802Sjkim * PARAMETERS: Node - Device node 615167802Sjkim * RetBuffer - Pointer to a buffer structure for the 616167802Sjkim * results 61767754Smsmith * 61877424Smsmith * RETURN: Status 61967754Smsmith * 62067754Smsmith * DESCRIPTION: This function is called to get the _PRT value of an object 62167754Smsmith * contained in an object specified by the handle passed in 62267754Smsmith * 62367754Smsmith * If the function fails an appropriate status will be returned 62467754Smsmith * and the contents of the callers buffer is undefined. 62567754Smsmith * 62667754Smsmith ******************************************************************************/ 62767754Smsmith 62867754SmsmithACPI_STATUS 62967754SmsmithAcpiRsGetPrtMethodData ( 630167802Sjkim ACPI_NAMESPACE_NODE *Node, 63167754Smsmith ACPI_BUFFER *RetBuffer) 63267754Smsmith{ 63399679Siwasaki ACPI_OPERAND_OBJECT *ObjDesc; 63467754Smsmith ACPI_STATUS Status; 63567754Smsmith 63667754Smsmith 637167802Sjkim ACPI_FUNCTION_TRACE (RsGetPrtMethodData); 63867754Smsmith 63967754Smsmith 64091116Smsmith /* Parameters guaranteed valid by caller */ 64167754Smsmith 642151937Sjkim /* Execute the method, no parameters */ 643151937Sjkim 644298714Sjkim Status = AcpiUtEvaluateObject ( 645298714Sjkim Node, METHOD_NAME__PRT, ACPI_BTYPE_PACKAGE, &ObjDesc); 64667754Smsmith if (ACPI_FAILURE (Status)) 64767754Smsmith { 64867754Smsmith return_ACPI_STATUS (Status); 64967754Smsmith } 65067754Smsmith 65167754Smsmith /* 65291116Smsmith * Create a resource linked list from the byte stream buffer that comes 65391116Smsmith * back from the _CRS method execution. 65467754Smsmith */ 65599679Siwasaki Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer); 65667754Smsmith 65791116Smsmith /* On exit, we must delete the object returned by EvaluateObject */ 65867754Smsmith 65999679Siwasaki AcpiUtRemoveReference (ObjDesc); 66067754Smsmith return_ACPI_STATUS (Status); 66167754Smsmith} 66267754Smsmith 66367754Smsmith 66467754Smsmith/******************************************************************************* 66567754Smsmith * 66667754Smsmith * FUNCTION: AcpiRsGetCrsMethodData 66767754Smsmith * 668167802Sjkim * PARAMETERS: Node - Device node 669167802Sjkim * RetBuffer - Pointer to a buffer structure for the 670167802Sjkim * results 67167754Smsmith * 67277424Smsmith * RETURN: Status 67367754Smsmith * 67467754Smsmith * DESCRIPTION: This function is called to get the _CRS value of an object 67567754Smsmith * contained in an object specified by the handle passed in 67667754Smsmith * 67767754Smsmith * If the function fails an appropriate status will be returned 67867754Smsmith * and the contents of the callers buffer is undefined. 67967754Smsmith * 68067754Smsmith ******************************************************************************/ 68167754Smsmith 68267754SmsmithACPI_STATUS 68367754SmsmithAcpiRsGetCrsMethodData ( 684167802Sjkim ACPI_NAMESPACE_NODE *Node, 68567754Smsmith ACPI_BUFFER *RetBuffer) 68667754Smsmith{ 68799679Siwasaki ACPI_OPERAND_OBJECT *ObjDesc; 68867754Smsmith ACPI_STATUS Status; 68967754Smsmith 69067754Smsmith 691167802Sjkim ACPI_FUNCTION_TRACE (RsGetCrsMethodData); 69267754Smsmith 69367754Smsmith 69491116Smsmith /* Parameters guaranteed valid by caller */ 69567754Smsmith 696151937Sjkim /* Execute the method, no parameters */ 697151937Sjkim 698298714Sjkim Status = AcpiUtEvaluateObject ( 699298714Sjkim Node, METHOD_NAME__CRS, ACPI_BTYPE_BUFFER, &ObjDesc); 70067754Smsmith if (ACPI_FAILURE (Status)) 70167754Smsmith { 70267754Smsmith return_ACPI_STATUS (Status); 70367754Smsmith } 70467754Smsmith 70567754Smsmith /* 70667754Smsmith * Make the call to create a resource linked list from the 70791116Smsmith * byte stream buffer that comes back from the _CRS method 70891116Smsmith * execution. 70967754Smsmith */ 71099679Siwasaki Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 71167754Smsmith 71267754Smsmith /* On exit, we must delete the object returned by evaluateObject */ 71367754Smsmith 71499679Siwasaki AcpiUtRemoveReference (ObjDesc); 71567754Smsmith return_ACPI_STATUS (Status); 71667754Smsmith} 71767754Smsmith 71867754Smsmith 71967754Smsmith/******************************************************************************* 72067754Smsmith * 72167754Smsmith * FUNCTION: AcpiRsGetPrsMethodData 72267754Smsmith * 723167802Sjkim * PARAMETERS: Node - Device node 724167802Sjkim * RetBuffer - Pointer to a buffer structure for the 725167802Sjkim * results 72667754Smsmith * 72777424Smsmith * RETURN: Status 72867754Smsmith * 72967754Smsmith * DESCRIPTION: This function is called to get the _PRS value of an object 73067754Smsmith * contained in an object specified by the handle passed in 73167754Smsmith * 73267754Smsmith * If the function fails an appropriate status will be returned 73367754Smsmith * and the contents of the callers buffer is undefined. 73467754Smsmith * 73567754Smsmith ******************************************************************************/ 73667754Smsmith 73767754SmsmithACPI_STATUS 73867754SmsmithAcpiRsGetPrsMethodData ( 739167802Sjkim ACPI_NAMESPACE_NODE *Node, 74067754Smsmith ACPI_BUFFER *RetBuffer) 74167754Smsmith{ 74299679Siwasaki ACPI_OPERAND_OBJECT *ObjDesc; 74367754Smsmith ACPI_STATUS Status; 74467754Smsmith 74567754Smsmith 746167802Sjkim ACPI_FUNCTION_TRACE (RsGetPrsMethodData); 74767754Smsmith 74867754Smsmith 74991116Smsmith /* Parameters guaranteed valid by caller */ 75067754Smsmith 751151937Sjkim /* Execute the method, no parameters */ 752151937Sjkim 753298714Sjkim Status = AcpiUtEvaluateObject ( 754298714Sjkim Node, METHOD_NAME__PRS, ACPI_BTYPE_BUFFER, &ObjDesc); 75567754Smsmith if (ACPI_FAILURE (Status)) 75667754Smsmith { 75767754Smsmith return_ACPI_STATUS (Status); 75867754Smsmith } 75967754Smsmith 760114237Snjl /* 761114237Snjl * Make the call to create a resource linked list from the 762114237Snjl * byte stream buffer that comes back from the _CRS method 763114237Snjl * execution. 764114237Snjl */ 765114237Snjl Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 76667754Smsmith 767114237Snjl /* On exit, we must delete the object returned by evaluateObject */ 76867754Smsmith 769114237Snjl AcpiUtRemoveReference (ObjDesc); 770114237Snjl return_ACPI_STATUS (Status); 771114237Snjl} 772114237Snjl 773114237Snjl 774114237Snjl/******************************************************************************* 775114237Snjl * 776228110Sjkim * FUNCTION: AcpiRsGetAeiMethodData 777228110Sjkim * 778228110Sjkim * PARAMETERS: Node - Device node 779228110Sjkim * RetBuffer - Pointer to a buffer structure for the 780228110Sjkim * results 781228110Sjkim * 782228110Sjkim * RETURN: Status 783228110Sjkim * 784228110Sjkim * DESCRIPTION: This function is called to get the _AEI value of an object 785228110Sjkim * contained in an object specified by the handle passed in 786228110Sjkim * 787228110Sjkim * If the function fails an appropriate status will be returned 788228110Sjkim * and the contents of the callers buffer is undefined. 789228110Sjkim * 790228110Sjkim ******************************************************************************/ 791228110Sjkim 792228110SjkimACPI_STATUS 793228110SjkimAcpiRsGetAeiMethodData ( 794228110Sjkim ACPI_NAMESPACE_NODE *Node, 795228110Sjkim ACPI_BUFFER *RetBuffer) 796228110Sjkim{ 797228110Sjkim ACPI_OPERAND_OBJECT *ObjDesc; 798228110Sjkim ACPI_STATUS Status; 799228110Sjkim 800228110Sjkim 801228110Sjkim ACPI_FUNCTION_TRACE (RsGetAeiMethodData); 802228110Sjkim 803228110Sjkim 804228110Sjkim /* Parameters guaranteed valid by caller */ 805228110Sjkim 806228110Sjkim /* Execute the method, no parameters */ 807228110Sjkim 808298714Sjkim Status = AcpiUtEvaluateObject ( 809298714Sjkim Node, METHOD_NAME__AEI, ACPI_BTYPE_BUFFER, &ObjDesc); 810228110Sjkim if (ACPI_FAILURE (Status)) 811228110Sjkim { 812228110Sjkim return_ACPI_STATUS (Status); 813228110Sjkim } 814228110Sjkim 815228110Sjkim /* 816228110Sjkim * Make the call to create a resource linked list from the 817228110Sjkim * byte stream buffer that comes back from the _CRS method 818228110Sjkim * execution. 819228110Sjkim */ 820228110Sjkim Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 821228110Sjkim 822228110Sjkim /* On exit, we must delete the object returned by evaluateObject */ 823228110Sjkim 824228110Sjkim AcpiUtRemoveReference (ObjDesc); 825228110Sjkim return_ACPI_STATUS (Status); 826228110Sjkim} 827228110Sjkim 828228110Sjkim 829228110Sjkim/******************************************************************************* 830228110Sjkim * 831114237Snjl * FUNCTION: AcpiRsGetMethodData 832114237Snjl * 833167802Sjkim * PARAMETERS: Handle - Handle to the containing object 834151937Sjkim * Path - Path to method, relative to Handle 835167802Sjkim * RetBuffer - Pointer to a buffer structure for the 836167802Sjkim * results 837114237Snjl * 838114237Snjl * RETURN: Status 839114237Snjl * 840114237Snjl * DESCRIPTION: This function is called to get the _CRS or _PRS value of an 841114237Snjl * object contained in an object specified by the handle passed in 842114237Snjl * 843114237Snjl * If the function fails an appropriate status will be returned 844114237Snjl * and the contents of the callers buffer is undefined. 845114237Snjl * 846114237Snjl ******************************************************************************/ 847114237Snjl 848114237SnjlACPI_STATUS 849114237SnjlAcpiRsGetMethodData ( 850114237Snjl ACPI_HANDLE Handle, 851298714Sjkim const char *Path, 852114237Snjl ACPI_BUFFER *RetBuffer) 853114237Snjl{ 854114237Snjl ACPI_OPERAND_OBJECT *ObjDesc; 855114237Snjl ACPI_STATUS Status; 856114237Snjl 857114237Snjl 858167802Sjkim ACPI_FUNCTION_TRACE (RsGetMethodData); 859114237Snjl 860114237Snjl 861114237Snjl /* Parameters guaranteed valid by caller */ 862114237Snjl 863151937Sjkim /* Execute the method, no parameters */ 864151937Sjkim 865298714Sjkim Status = AcpiUtEvaluateObject ( 866298714Sjkim ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle), 867245582Sjkim Path, ACPI_BTYPE_BUFFER, &ObjDesc); 868167802Sjkim if (ACPI_FAILURE (Status)) 869167802Sjkim { 870114237Snjl return_ACPI_STATUS (Status); 87167754Smsmith } 87267754Smsmith 87367754Smsmith /* 87467754Smsmith * Make the call to create a resource linked list from the 875114237Snjl * byte stream buffer that comes back from the method 87691116Smsmith * execution. 87767754Smsmith */ 87899679Siwasaki Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer); 87967754Smsmith 880114237Snjl /* On exit, we must delete the object returned by EvaluateObject */ 88167754Smsmith 88299679Siwasaki AcpiUtRemoveReference (ObjDesc); 88367754Smsmith return_ACPI_STATUS (Status); 88467754Smsmith} 88567754Smsmith 886167802Sjkim 88767754Smsmith/******************************************************************************* 88867754Smsmith * 88967754Smsmith * FUNCTION: AcpiRsSetSrsMethodData 89067754Smsmith * 891167802Sjkim * PARAMETERS: Node - Device node 892167802Sjkim * InBuffer - Pointer to a buffer structure of the 893167802Sjkim * parameter 89467754Smsmith * 89577424Smsmith * RETURN: Status 89667754Smsmith * 89767754Smsmith * DESCRIPTION: This function is called to set the _SRS of an object contained 89867754Smsmith * in an object specified by the handle passed in 89967754Smsmith * 90067754Smsmith * If the function fails an appropriate status will be returned 90167754Smsmith * and the contents of the callers buffer is undefined. 90267754Smsmith * 903167802Sjkim * Note: Parameters guaranteed valid by caller 904167802Sjkim * 90567754Smsmith ******************************************************************************/ 90667754Smsmith 90767754SmsmithACPI_STATUS 90867754SmsmithAcpiRsSetSrsMethodData ( 909167802Sjkim ACPI_NAMESPACE_NODE *Node, 91067754Smsmith ACPI_BUFFER *InBuffer) 91167754Smsmith{ 912167802Sjkim ACPI_EVALUATE_INFO *Info; 913167802Sjkim ACPI_OPERAND_OBJECT *Args[2]; 91467754Smsmith ACPI_STATUS Status; 91591116Smsmith ACPI_BUFFER Buffer; 91667754Smsmith 91767754Smsmith 918167802Sjkim ACPI_FUNCTION_TRACE (RsSetSrsMethodData); 91967754Smsmith 92067754Smsmith 921167802Sjkim /* Allocate and initialize the evaluation information block */ 92267754Smsmith 923167802Sjkim Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); 924167802Sjkim if (!Info) 925167802Sjkim { 926167802Sjkim return_ACPI_STATUS (AE_NO_MEMORY); 927167802Sjkim } 928167802Sjkim 929167802Sjkim Info->PrefixNode = Node; 930249663Sjkim Info->RelativePathname = METHOD_NAME__SRS; 931167802Sjkim Info->Parameters = Args; 932167802Sjkim Info->Flags = ACPI_IGNORE_RETURN_VALUE; 933167802Sjkim 93467754Smsmith /* 93567754Smsmith * The InBuffer parameter will point to a linked list of 936167802Sjkim * resource parameters. It needs to be formatted into a 93791116Smsmith * byte stream to be sent in as an input parameter to _SRS 93891116Smsmith * 93991116Smsmith * Convert the linked list into a byte stream 94067754Smsmith */ 94191116Smsmith Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER; 942272444Sjkim Status = AcpiRsCreateAmlResources (InBuffer, &Buffer); 94391116Smsmith if (ACPI_FAILURE (Status)) 94467754Smsmith { 945167802Sjkim goto Cleanup; 94667754Smsmith } 94767754Smsmith 948167802Sjkim /* Create and initialize the method parameter object */ 949151937Sjkim 950167802Sjkim Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER); 951167802Sjkim if (!Args[0]) 95284491Smsmith { 953167802Sjkim /* 954167802Sjkim * Must free the buffer allocated above (otherwise it is freed 955167802Sjkim * later) 956167802Sjkim */ 957167802Sjkim ACPI_FREE (Buffer.Pointer); 958167802Sjkim Status = AE_NO_MEMORY; 959167802Sjkim goto Cleanup; 96084491Smsmith } 96167754Smsmith 962167802Sjkim Args[0]->Buffer.Length = (UINT32) Buffer.Length; 963167802Sjkim Args[0]->Buffer.Pointer = Buffer.Pointer; 964167802Sjkim Args[0]->Common.Flags = AOPOBJ_DATA_VALID; 965167802Sjkim Args[1] = NULL; 966151937Sjkim 967167802Sjkim /* Execute the method, no return value is expected */ 96867754Smsmith 969167802Sjkim Status = AcpiNsEvaluate (Info); 970129684Snjl 971167802Sjkim /* Clean up and return the status from AcpiNsEvaluate */ 97267754Smsmith 973167802Sjkim AcpiUtRemoveReference (Args[0]); 974151937Sjkim 975167802SjkimCleanup: 976167802Sjkim ACPI_FREE (Info); 97767754Smsmith return_ACPI_STATUS (Status); 97867754Smsmith} 979