167754Smsmith/******************************************************************************* 267754Smsmith * 377424Smsmith * Module Name: rsxface - Public interfaces to 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 __RSXFACE_C__ 4667754Smsmith 47193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 48193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 49193341Sjkim#include <contrib/dev/acpica/include/acresrc.h> 50193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 5167754Smsmith 5277424Smsmith#define _COMPONENT ACPI_RESOURCES 5391116Smsmith ACPI_MODULE_NAME ("rsxface") 5467754Smsmith 55151937Sjkim/* Local macros for 16,32-bit to 64-bit conversion */ 5667754Smsmith 57151937Sjkim#define ACPI_COPY_FIELD(Out, In, Field) ((Out)->Field = (In)->Field) 58151937Sjkim#define ACPI_COPY_ADDRESS(Out, In) \ 59151937Sjkim ACPI_COPY_FIELD(Out, In, ResourceType); \ 60151937Sjkim ACPI_COPY_FIELD(Out, In, ProducerConsumer); \ 61151937Sjkim ACPI_COPY_FIELD(Out, In, Decode); \ 62151937Sjkim ACPI_COPY_FIELD(Out, In, MinAddressFixed); \ 63151937Sjkim ACPI_COPY_FIELD(Out, In, MaxAddressFixed); \ 64151937Sjkim ACPI_COPY_FIELD(Out, In, Info); \ 65151937Sjkim ACPI_COPY_FIELD(Out, In, Granularity); \ 66151937Sjkim ACPI_COPY_FIELD(Out, In, Minimum); \ 67151937Sjkim ACPI_COPY_FIELD(Out, In, Maximum); \ 68151937Sjkim ACPI_COPY_FIELD(Out, In, TranslationOffset); \ 69151937Sjkim ACPI_COPY_FIELD(Out, In, AddressLength); \ 70151937Sjkim ACPI_COPY_FIELD(Out, In, ResourceSource); 71151937Sjkim 72151937Sjkim 73167802Sjkim/* Local prototypes */ 74167802Sjkim 75167802Sjkimstatic ACPI_STATUS 76167802SjkimAcpiRsMatchVendorResource ( 77167802Sjkim ACPI_RESOURCE *Resource, 78167802Sjkim void *Context); 79167802Sjkim 80167802Sjkimstatic ACPI_STATUS 81167802SjkimAcpiRsValidateParameters ( 82167802Sjkim ACPI_HANDLE DeviceHandle, 83167802Sjkim ACPI_BUFFER *Buffer, 84167802Sjkim ACPI_NAMESPACE_NODE **ReturnNode); 85167802Sjkim 86167802Sjkim 8767754Smsmith/******************************************************************************* 8867754Smsmith * 89167802Sjkim * FUNCTION: AcpiRsValidateParameters 90167802Sjkim * 91167802Sjkim * PARAMETERS: DeviceHandle - Handle to a device 92167802Sjkim * Buffer - Pointer to a data buffer 93167802Sjkim * ReturnNode - Pointer to where the device node is returned 94167802Sjkim * 95167802Sjkim * RETURN: Status 96167802Sjkim * 97167802Sjkim * DESCRIPTION: Common parameter validation for resource interfaces 98167802Sjkim * 99167802Sjkim ******************************************************************************/ 100167802Sjkim 101167802Sjkimstatic ACPI_STATUS 102167802SjkimAcpiRsValidateParameters ( 103167802Sjkim ACPI_HANDLE DeviceHandle, 104167802Sjkim ACPI_BUFFER *Buffer, 105167802Sjkim ACPI_NAMESPACE_NODE **ReturnNode) 106167802Sjkim{ 107167802Sjkim ACPI_STATUS Status; 108167802Sjkim ACPI_NAMESPACE_NODE *Node; 109167802Sjkim 110167802Sjkim 111167802Sjkim ACPI_FUNCTION_TRACE (RsValidateParameters); 112167802Sjkim 113167802Sjkim 114167802Sjkim /* 115167802Sjkim * Must have a valid handle to an ACPI device 116167802Sjkim */ 117167802Sjkim if (!DeviceHandle) 118167802Sjkim { 119167802Sjkim return_ACPI_STATUS (AE_BAD_PARAMETER); 120167802Sjkim } 121167802Sjkim 122200553Sjkim Node = AcpiNsValidateHandle (DeviceHandle); 123167802Sjkim if (!Node) 124167802Sjkim { 125167802Sjkim return_ACPI_STATUS (AE_BAD_PARAMETER); 126167802Sjkim } 127167802Sjkim 128167802Sjkim if (Node->Type != ACPI_TYPE_DEVICE) 129167802Sjkim { 130167802Sjkim return_ACPI_STATUS (AE_TYPE); 131167802Sjkim } 132167802Sjkim 133167802Sjkim /* 134167802Sjkim * Validate the user buffer object 135167802Sjkim * 136167802Sjkim * if there is a non-zero buffer length we also need a valid pointer in 137167802Sjkim * the buffer. If it's a zero buffer length, we'll be returning the 138167802Sjkim * needed buffer size (later), so keep going. 139167802Sjkim */ 140167802Sjkim Status = AcpiUtValidateBuffer (Buffer); 141167802Sjkim if (ACPI_FAILURE (Status)) 142167802Sjkim { 143167802Sjkim return_ACPI_STATUS (Status); 144167802Sjkim } 145167802Sjkim 146167802Sjkim *ReturnNode = Node; 147167802Sjkim return_ACPI_STATUS (AE_OK); 148167802Sjkim} 149167802Sjkim 150167802Sjkim 151167802Sjkim/******************************************************************************* 152167802Sjkim * 15367754Smsmith * FUNCTION: AcpiGetIrqRoutingTable 15467754Smsmith * 155167802Sjkim * PARAMETERS: DeviceHandle - Handle to the Bus device we are querying 156167802Sjkim * RetBuffer - Pointer to a buffer to receive the 15767754Smsmith * current resources for the device 15867754Smsmith * 15977424Smsmith * RETURN: Status 16067754Smsmith * 16167754Smsmith * DESCRIPTION: This function is called to get the IRQ routing table for a 162167802Sjkim * specific bus. The caller must first acquire a handle for the 163167802Sjkim * desired bus. The routine table is placed in the buffer pointed 16467754Smsmith * to by the RetBuffer variable parameter. 16567754Smsmith * 16667754Smsmith * If the function fails an appropriate status will be returned 16767754Smsmith * and the value of RetBuffer is undefined. 16867754Smsmith * 16967754Smsmith * This function attempts to execute the _PRT method contained in 17067754Smsmith * the object indicated by the passed DeviceHandle. 17167754Smsmith * 17267754Smsmith ******************************************************************************/ 17367754Smsmith 17467754SmsmithACPI_STATUS 17567754SmsmithAcpiGetIrqRoutingTable ( 17667754Smsmith ACPI_HANDLE DeviceHandle, 17767754Smsmith ACPI_BUFFER *RetBuffer) 17867754Smsmith{ 17967754Smsmith ACPI_STATUS Status; 180167802Sjkim ACPI_NAMESPACE_NODE *Node; 18167754Smsmith 18267754Smsmith 183167802Sjkim ACPI_FUNCTION_TRACE (AcpiGetIrqRoutingTable); 18467754Smsmith 18577424Smsmith 186167802Sjkim /* Validate parameters then dispatch to internal routine */ 18767754Smsmith 188167802Sjkim Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node); 18991116Smsmith if (ACPI_FAILURE (Status)) 19091116Smsmith { 19191116Smsmith return_ACPI_STATUS (Status); 19291116Smsmith } 19391116Smsmith 194167802Sjkim Status = AcpiRsGetPrtMethodData (Node, RetBuffer); 19567754Smsmith return_ACPI_STATUS (Status); 19667754Smsmith} 19767754Smsmith 198167802SjkimACPI_EXPORT_SYMBOL (AcpiGetIrqRoutingTable) 19967754Smsmith 200167802Sjkim 20167754Smsmith/******************************************************************************* 20267754Smsmith * 20367754Smsmith * FUNCTION: AcpiGetCurrentResources 20467754Smsmith * 205167802Sjkim * PARAMETERS: DeviceHandle - Handle to the device object for the 20667754Smsmith * device we are querying 207167802Sjkim * RetBuffer - Pointer to a buffer to receive the 20867754Smsmith * current resources for the device 20967754Smsmith * 21077424Smsmith * RETURN: Status 21167754Smsmith * 21267754Smsmith * DESCRIPTION: This function is called to get the current resources for a 213167802Sjkim * specific device. The caller must first acquire a handle for 214167802Sjkim * the desired device. The resource data is placed in the buffer 21567754Smsmith * pointed to by the RetBuffer variable parameter. 21667754Smsmith * 21767754Smsmith * If the function fails an appropriate status will be returned 21867754Smsmith * and the value of RetBuffer is undefined. 21967754Smsmith * 22067754Smsmith * This function attempts to execute the _CRS method contained in 22167754Smsmith * the object indicated by the passed DeviceHandle. 22267754Smsmith * 22367754Smsmith ******************************************************************************/ 22467754Smsmith 22567754SmsmithACPI_STATUS 22667754SmsmithAcpiGetCurrentResources ( 22767754Smsmith ACPI_HANDLE DeviceHandle, 22867754Smsmith ACPI_BUFFER *RetBuffer) 22967754Smsmith{ 23067754Smsmith ACPI_STATUS Status; 231167802Sjkim ACPI_NAMESPACE_NODE *Node; 23267754Smsmith 23367754Smsmith 234167802Sjkim ACPI_FUNCTION_TRACE (AcpiGetCurrentResources); 23567754Smsmith 23683174Smsmith 237167802Sjkim /* Validate parameters then dispatch to internal routine */ 23867754Smsmith 239167802Sjkim Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node); 24091116Smsmith if (ACPI_FAILURE (Status)) 24191116Smsmith { 24291116Smsmith return_ACPI_STATUS (Status); 24391116Smsmith } 24491116Smsmith 245167802Sjkim Status = AcpiRsGetCrsMethodData (Node, RetBuffer); 24667754Smsmith return_ACPI_STATUS (Status); 24767754Smsmith} 24867754Smsmith 249167802SjkimACPI_EXPORT_SYMBOL (AcpiGetCurrentResources) 25067754Smsmith 251167802Sjkim 25267754Smsmith/******************************************************************************* 25367754Smsmith * 25467754Smsmith * FUNCTION: AcpiGetPossibleResources 25567754Smsmith * 256167802Sjkim * PARAMETERS: DeviceHandle - Handle to the device object for the 25767754Smsmith * device we are querying 258167802Sjkim * RetBuffer - Pointer to a buffer to receive the 25967754Smsmith * resources for the device 26067754Smsmith * 26177424Smsmith * RETURN: Status 26267754Smsmith * 26367754Smsmith * DESCRIPTION: This function is called to get a list of the possible resources 264167802Sjkim * for a specific device. The caller must first acquire a handle 265167802Sjkim * for the desired device. The resource data is placed in the 26667754Smsmith * buffer pointed to by the RetBuffer variable. 26767754Smsmith * 26867754Smsmith * If the function fails an appropriate status will be returned 26967754Smsmith * and the value of RetBuffer is undefined. 27067754Smsmith * 27167754Smsmith ******************************************************************************/ 27267754Smsmith 27367754SmsmithACPI_STATUS 27467754SmsmithAcpiGetPossibleResources ( 27567754Smsmith ACPI_HANDLE DeviceHandle, 27667754Smsmith ACPI_BUFFER *RetBuffer) 27767754Smsmith{ 27867754Smsmith ACPI_STATUS Status; 279167802Sjkim ACPI_NAMESPACE_NODE *Node; 28067754Smsmith 28167754Smsmith 282167802Sjkim ACPI_FUNCTION_TRACE (AcpiGetPossibleResources); 28367754Smsmith 28477424Smsmith 285167802Sjkim /* Validate parameters then dispatch to internal routine */ 28667754Smsmith 287167802Sjkim Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node); 28891116Smsmith if (ACPI_FAILURE (Status)) 28991116Smsmith { 29091116Smsmith return_ACPI_STATUS (Status); 29191116Smsmith } 29291116Smsmith 293167802Sjkim Status = AcpiRsGetPrsMethodData (Node, RetBuffer); 29467754Smsmith return_ACPI_STATUS (Status); 29567754Smsmith} 29667754Smsmith 297167802SjkimACPI_EXPORT_SYMBOL (AcpiGetPossibleResources) 29867754Smsmith 299167802Sjkim 30067754Smsmith/******************************************************************************* 30167754Smsmith * 302167802Sjkim * FUNCTION: AcpiSetCurrentResources 303114237Snjl * 304167802Sjkim * PARAMETERS: DeviceHandle - Handle to the device object for the 305167802Sjkim * device we are setting resources 306167802Sjkim * InBuffer - Pointer to a buffer containing the 307167802Sjkim * resources to be set for the device 308114237Snjl * 309114237Snjl * RETURN: Status 310114237Snjl * 311167802Sjkim * DESCRIPTION: This function is called to set the current resources for a 312167802Sjkim * specific device. The caller must first acquire a handle for 313167802Sjkim * the desired device. The resource data is passed to the routine 314167802Sjkim * the buffer pointed to by the InBuffer variable. 315114237Snjl * 316114237Snjl ******************************************************************************/ 317114237Snjl 318114237SnjlACPI_STATUS 319167802SjkimAcpiSetCurrentResources ( 320167802Sjkim ACPI_HANDLE DeviceHandle, 321167802Sjkim ACPI_BUFFER *InBuffer) 322114237Snjl{ 323167802Sjkim ACPI_STATUS Status; 324167802Sjkim ACPI_NAMESPACE_NODE *Node; 325114237Snjl 326114237Snjl 327167802Sjkim ACPI_FUNCTION_TRACE (AcpiSetCurrentResources); 328114237Snjl 329114237Snjl 330167802Sjkim /* Validate the buffer, don't allow zero length */ 331167802Sjkim 332167802Sjkim if ((!InBuffer) || 333167802Sjkim (!InBuffer->Pointer) || 334167802Sjkim (!InBuffer->Length)) 335114237Snjl { 336114237Snjl return_ACPI_STATUS (AE_BAD_PARAMETER); 337114237Snjl } 338114237Snjl 339167802Sjkim /* Validate parameters then dispatch to internal routine */ 340167802Sjkim 341167802Sjkim Status = AcpiRsValidateParameters (DeviceHandle, InBuffer, &Node); 342114237Snjl if (ACPI_FAILURE (Status)) 343114237Snjl { 344114237Snjl return_ACPI_STATUS (Status); 345114237Snjl } 346114237Snjl 347167802Sjkim Status = AcpiRsSetSrsMethodData (Node, InBuffer); 348167802Sjkim return_ACPI_STATUS (Status); 349167802Sjkim} 350126372Snjl 351167802SjkimACPI_EXPORT_SYMBOL (AcpiSetCurrentResources) 352126372Snjl 353126372Snjl 354228110Sjkim/******************************************************************************* 355228110Sjkim * 356228110Sjkim * FUNCTION: AcpiGetEventResources 357228110Sjkim * 358228110Sjkim * PARAMETERS: DeviceHandle - Handle to the device object for the 359228110Sjkim * device we are getting resources 360228110Sjkim * InBuffer - Pointer to a buffer containing the 361228110Sjkim * resources to be set for the device 362228110Sjkim * 363228110Sjkim * RETURN: Status 364228110Sjkim * 365228110Sjkim * DESCRIPTION: This function is called to get the event resources for a 366228110Sjkim * specific device. The caller must first acquire a handle for 367228110Sjkim * the desired device. The resource data is passed to the routine 368228110Sjkim * the buffer pointed to by the InBuffer variable. Uses the 369228110Sjkim * _AEI method. 370228110Sjkim * 371228110Sjkim ******************************************************************************/ 372228110Sjkim 373228110SjkimACPI_STATUS 374228110SjkimAcpiGetEventResources ( 375228110Sjkim ACPI_HANDLE DeviceHandle, 376228110Sjkim ACPI_BUFFER *RetBuffer) 377228110Sjkim{ 378228110Sjkim ACPI_STATUS Status; 379228110Sjkim ACPI_NAMESPACE_NODE *Node; 380228110Sjkim 381228110Sjkim 382228110Sjkim ACPI_FUNCTION_TRACE (AcpiGetEventResources); 383228110Sjkim 384228110Sjkim 385228110Sjkim /* Validate parameters then dispatch to internal routine */ 386228110Sjkim 387228110Sjkim Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node); 388228110Sjkim if (ACPI_FAILURE (Status)) 389228110Sjkim { 390228110Sjkim return_ACPI_STATUS (Status); 391228110Sjkim } 392228110Sjkim 393228110Sjkim Status = AcpiRsGetAeiMethodData (Node, RetBuffer); 394228110Sjkim return_ACPI_STATUS (Status); 395228110Sjkim} 396228110Sjkim 397228110SjkimACPI_EXPORT_SYMBOL (AcpiGetEventResources) 398228110Sjkim 399228110Sjkim 400167802Sjkim/****************************************************************************** 401167802Sjkim * 402167802Sjkim * FUNCTION: AcpiResourceToAddress64 403167802Sjkim * 404167802Sjkim * PARAMETERS: Resource - Pointer to a resource 405167802Sjkim * Out - Pointer to the users's return buffer 406167802Sjkim * (a struct acpi_resource_address64) 407167802Sjkim * 408167802Sjkim * RETURN: Status 409167802Sjkim * 410167802Sjkim * DESCRIPTION: If the resource is an address16, address32, or address64, 411167802Sjkim * copy it to the address64 return buffer. This saves the 412167802Sjkim * caller from having to duplicate code for different-sized 413167802Sjkim * addresses. 414167802Sjkim * 415167802Sjkim ******************************************************************************/ 416167802Sjkim 417167802SjkimACPI_STATUS 418167802SjkimAcpiResourceToAddress64 ( 419167802Sjkim ACPI_RESOURCE *Resource, 420167802Sjkim ACPI_RESOURCE_ADDRESS64 *Out) 421167802Sjkim{ 422167802Sjkim ACPI_RESOURCE_ADDRESS16 *Address16; 423167802Sjkim ACPI_RESOURCE_ADDRESS32 *Address32; 424167802Sjkim 425167802Sjkim 426167802Sjkim if (!Resource || !Out) 427114237Snjl { 428167802Sjkim return (AE_BAD_PARAMETER); 429167802Sjkim } 430114237Snjl 431167802Sjkim /* Convert 16 or 32 address descriptor to 64 */ 432114237Snjl 433167802Sjkim switch (Resource->Type) 434167802Sjkim { 435167802Sjkim case ACPI_RESOURCE_TYPE_ADDRESS16: 436114237Snjl 437193267Sjkim Address16 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS16, &Resource->Data); 438167802Sjkim ACPI_COPY_ADDRESS (Out, Address16); 439167802Sjkim break; 440126372Snjl 441167802Sjkim case ACPI_RESOURCE_TYPE_ADDRESS32: 442114237Snjl 443193267Sjkim Address32 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS32, &Resource->Data); 444167802Sjkim ACPI_COPY_ADDRESS (Out, Address32); 445167802Sjkim break; 446114237Snjl 447167802Sjkim case ACPI_RESOURCE_TYPE_ADDRESS64: 448114237Snjl 449167802Sjkim /* Simple copy for 64 bit source */ 450114237Snjl 451167802Sjkim ACPI_MEMCPY (Out, &Resource->Data, sizeof (ACPI_RESOURCE_ADDRESS64)); 452167802Sjkim break; 453114237Snjl 454167802Sjkim default: 455250838Sjkim 456167802Sjkim return (AE_BAD_PARAMETER); 457167802Sjkim } 458114237Snjl 459167802Sjkim return (AE_OK); 460167802Sjkim} 461114237Snjl 462167802SjkimACPI_EXPORT_SYMBOL (AcpiResourceToAddress64) 463126372Snjl 464126372Snjl 465167802Sjkim/******************************************************************************* 466167802Sjkim * 467167802Sjkim * FUNCTION: AcpiGetVendorResource 468167802Sjkim * 469167802Sjkim * PARAMETERS: DeviceHandle - Handle for the parent device object 470167802Sjkim * Name - Method name for the parent resource 471167802Sjkim * (METHOD_NAME__CRS or METHOD_NAME__PRS) 472167802Sjkim * Uuid - Pointer to the UUID to be matched. 473167802Sjkim * includes both subtype and 16-byte UUID 474167802Sjkim * RetBuffer - Where the vendor resource is returned 475167802Sjkim * 476167802Sjkim * RETURN: Status 477167802Sjkim * 478245582Sjkim * DESCRIPTION: Walk a resource template for the specified device to find a 479167802Sjkim * vendor-defined resource that matches the supplied UUID and 480167802Sjkim * UUID subtype. Returns a ACPI_RESOURCE of type Vendor. 481167802Sjkim * 482167802Sjkim ******************************************************************************/ 483126372Snjl 484167802SjkimACPI_STATUS 485167802SjkimAcpiGetVendorResource ( 486167802Sjkim ACPI_HANDLE DeviceHandle, 487167802Sjkim char *Name, 488167802Sjkim ACPI_VENDOR_UUID *Uuid, 489167802Sjkim ACPI_BUFFER *RetBuffer) 490167802Sjkim{ 491167802Sjkim ACPI_VENDOR_WALK_INFO Info; 492167802Sjkim ACPI_STATUS Status; 493167802Sjkim 494167802Sjkim 495167802Sjkim /* Other parameters are validated by AcpiWalkResources */ 496167802Sjkim 497167802Sjkim if (!Uuid || !RetBuffer) 498167802Sjkim { 499167802Sjkim return (AE_BAD_PARAMETER); 500114237Snjl } 501114237Snjl 502167802Sjkim Info.Uuid = Uuid; 503167802Sjkim Info.Buffer = RetBuffer; 504167802Sjkim Info.Status = AE_NOT_EXIST; 505114237Snjl 506167802Sjkim /* Walk the _CRS or _PRS resource list for this device */ 507167802Sjkim 508167802Sjkim Status = AcpiWalkResources (DeviceHandle, Name, AcpiRsMatchVendorResource, 509167802Sjkim &Info); 510167802Sjkim if (ACPI_FAILURE (Status)) 511167802Sjkim { 512167802Sjkim return (Status); 513167802Sjkim } 514167802Sjkim 515167802Sjkim return (Info.Status); 516114237Snjl} 517114237Snjl 518167802SjkimACPI_EXPORT_SYMBOL (AcpiGetVendorResource) 519114237Snjl 520167802Sjkim 521114237Snjl/******************************************************************************* 522114237Snjl * 523167802Sjkim * FUNCTION: AcpiRsMatchVendorResource 52467754Smsmith * 525167802Sjkim * PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK 52667754Smsmith * 52777424Smsmith * RETURN: Status 52867754Smsmith * 529167802Sjkim * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID 53067754Smsmith * 53167754Smsmith ******************************************************************************/ 53267754Smsmith 533167802Sjkimstatic ACPI_STATUS 534167802SjkimAcpiRsMatchVendorResource ( 535167802Sjkim ACPI_RESOURCE *Resource, 536167802Sjkim void *Context) 53767754Smsmith{ 538167802Sjkim ACPI_VENDOR_WALK_INFO *Info = Context; 539167802Sjkim ACPI_RESOURCE_VENDOR_TYPED *Vendor; 540167802Sjkim ACPI_BUFFER *Buffer; 541167802Sjkim ACPI_STATUS Status; 54267754Smsmith 54367754Smsmith 544167802Sjkim /* Ignore all descriptors except Vendor */ 54567754Smsmith 546167802Sjkim if (Resource->Type != ACPI_RESOURCE_TYPE_VENDOR) 547167802Sjkim { 548167802Sjkim return (AE_OK); 549167802Sjkim } 55077424Smsmith 551167802Sjkim Vendor = &Resource->Data.VendorTyped; 552151937Sjkim 553167802Sjkim /* 554167802Sjkim * For a valid match, these conditions must hold: 555167802Sjkim * 556167802Sjkim * 1) Length of descriptor data must be at least as long as a UUID struct 557167802Sjkim * 2) The UUID subtypes must match 558167802Sjkim * 3) The UUID data must match 559167802Sjkim */ 560167802Sjkim if ((Vendor->ByteLength < (ACPI_UUID_LENGTH + 1)) || 561167802Sjkim (Vendor->UuidSubtype != Info->Uuid->Subtype) || 562167802Sjkim (ACPI_MEMCMP (Vendor->Uuid, Info->Uuid->Data, ACPI_UUID_LENGTH))) 56367754Smsmith { 564167802Sjkim return (AE_OK); 56567754Smsmith } 56667754Smsmith 567167802Sjkim /* Validate/Allocate/Clear caller buffer */ 568167802Sjkim 569167802Sjkim Buffer = Info->Buffer; 570167802Sjkim Status = AcpiUtInitializeBuffer (Buffer, Resource->Length); 571167802Sjkim if (ACPI_FAILURE (Status)) 572167802Sjkim { 573167802Sjkim return (Status); 574167802Sjkim } 575167802Sjkim 576167802Sjkim /* Found the correct resource, copy and return it */ 577167802Sjkim 578167802Sjkim ACPI_MEMCPY (Buffer->Pointer, Resource, Resource->Length); 579167802Sjkim Buffer->Length = Resource->Length; 580167802Sjkim 581167802Sjkim /* Found the desired descriptor, terminate resource walk */ 582167802Sjkim 583167802Sjkim Info->Status = AE_OK; 584167802Sjkim return (AE_CTRL_TERMINATE); 58567754Smsmith} 586114237Snjl 587114237Snjl 588167802Sjkim/******************************************************************************* 589114237Snjl * 590245582Sjkim * FUNCTION: AcpiWalkResourceBuffer 591114237Snjl * 592245582Sjkim * PARAMETERS: Buffer - Formatted buffer returned by one of the 593245582Sjkim * various Get*Resource functions 594167802Sjkim * UserFunction - Called for each resource 595167802Sjkim * Context - Passed to UserFunction 596114237Snjl * 597114237Snjl * RETURN: Status 598114237Snjl * 599245582Sjkim * DESCRIPTION: Walks the input resource template. The UserFunction is called 600245582Sjkim * once for each resource in the list. 601114237Snjl * 602114237Snjl ******************************************************************************/ 603114237Snjl 604114237SnjlACPI_STATUS 605245582SjkimAcpiWalkResourceBuffer ( 606245582Sjkim ACPI_BUFFER *Buffer, 607167802Sjkim ACPI_WALK_RESOURCE_CALLBACK UserFunction, 608167802Sjkim void *Context) 609114237Snjl{ 610245582Sjkim ACPI_STATUS Status = AE_OK; 611167802Sjkim ACPI_RESOURCE *Resource; 612167802Sjkim ACPI_RESOURCE *ResourceEnd; 613114237Snjl 614114237Snjl 615245582Sjkim ACPI_FUNCTION_TRACE (AcpiWalkResourceBuffer); 616167802Sjkim 617167802Sjkim 618167802Sjkim /* Parameter validation */ 619167802Sjkim 620245582Sjkim if (!Buffer || !Buffer->Pointer || !UserFunction) 621151937Sjkim { 622167802Sjkim return_ACPI_STATUS (AE_BAD_PARAMETER); 623167802Sjkim } 624117521Snjl 625245582Sjkim /* Buffer contains the resource list and length */ 626114237Snjl 627245582Sjkim Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer->Pointer); 628245582Sjkim ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Buffer->Pointer, Buffer->Length); 629117521Snjl 630167802Sjkim /* Walk the resource list until the EndTag is found (or buffer end) */ 631117521Snjl 632167802Sjkim while (Resource < ResourceEnd) 633167802Sjkim { 634246849Sjkim /* Sanity check the resource type */ 635114237Snjl 636167802Sjkim if (Resource->Type > ACPI_RESOURCE_TYPE_MAX) 637167802Sjkim { 638167802Sjkim Status = AE_AML_INVALID_RESOURCE_TYPE; 639167802Sjkim break; 640167802Sjkim } 641167802Sjkim 642246849Sjkim /* Sanity check the length. It must not be zero, or we loop forever */ 643246849Sjkim 644246849Sjkim if (!Resource->Length) 645246849Sjkim { 646246849Sjkim return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH); 647246849Sjkim } 648246849Sjkim 649167802Sjkim /* Invoke the user function, abort on any error returned */ 650167802Sjkim 651167802Sjkim Status = UserFunction (Resource, Context); 652167802Sjkim if (ACPI_FAILURE (Status)) 653167802Sjkim { 654167802Sjkim if (Status == AE_CTRL_TERMINATE) 655167802Sjkim { 656167802Sjkim /* This is an OK termination by the user function */ 657167802Sjkim 658167802Sjkim Status = AE_OK; 659167802Sjkim } 660167802Sjkim break; 661167802Sjkim } 662167802Sjkim 663167802Sjkim /* EndTag indicates end-of-list */ 664167802Sjkim 665167802Sjkim if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG) 666167802Sjkim { 667167802Sjkim break; 668167802Sjkim } 669167802Sjkim 670167802Sjkim /* Get the next resource descriptor */ 671167802Sjkim 672243347Sjkim Resource = ACPI_NEXT_RESOURCE (Resource); 673114237Snjl } 674114237Snjl 675245582Sjkim return_ACPI_STATUS (Status); 676245582Sjkim} 677245582Sjkim 678245582SjkimACPI_EXPORT_SYMBOL (AcpiWalkResourceBuffer) 679245582Sjkim 680245582Sjkim 681245582Sjkim/******************************************************************************* 682245582Sjkim * 683245582Sjkim * FUNCTION: AcpiWalkResources 684245582Sjkim * 685245582Sjkim * PARAMETERS: DeviceHandle - Handle to the device object for the 686245582Sjkim * device we are querying 687245582Sjkim * Name - Method name of the resources we want. 688245582Sjkim * (METHOD_NAME__CRS, METHOD_NAME__PRS, or 689245582Sjkim * METHOD_NAME__AEI) 690245582Sjkim * UserFunction - Called for each resource 691245582Sjkim * Context - Passed to UserFunction 692245582Sjkim * 693245582Sjkim * RETURN: Status 694245582Sjkim * 695245582Sjkim * DESCRIPTION: Retrieves the current or possible resource list for the 696245582Sjkim * specified device. The UserFunction is called once for 697245582Sjkim * each resource in the list. 698245582Sjkim * 699245582Sjkim ******************************************************************************/ 700245582Sjkim 701245582SjkimACPI_STATUS 702245582SjkimAcpiWalkResources ( 703245582Sjkim ACPI_HANDLE DeviceHandle, 704245582Sjkim char *Name, 705245582Sjkim ACPI_WALK_RESOURCE_CALLBACK UserFunction, 706245582Sjkim void *Context) 707245582Sjkim{ 708245582Sjkim ACPI_STATUS Status; 709245582Sjkim ACPI_BUFFER Buffer; 710245582Sjkim 711245582Sjkim 712245582Sjkim ACPI_FUNCTION_TRACE (AcpiWalkResources); 713245582Sjkim 714245582Sjkim 715245582Sjkim /* Parameter validation */ 716245582Sjkim 717245582Sjkim if (!DeviceHandle || !UserFunction || !Name || 718245582Sjkim (!ACPI_COMPARE_NAME (Name, METHOD_NAME__CRS) && 719245582Sjkim !ACPI_COMPARE_NAME (Name, METHOD_NAME__PRS) && 720245582Sjkim !ACPI_COMPARE_NAME (Name, METHOD_NAME__AEI))) 721245582Sjkim { 722245582Sjkim return_ACPI_STATUS (AE_BAD_PARAMETER); 723245582Sjkim } 724245582Sjkim 725245582Sjkim /* Get the _CRS/_PRS/_AEI resource list */ 726245582Sjkim 727245582Sjkim Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER; 728245582Sjkim Status = AcpiRsGetMethodData (DeviceHandle, Name, &Buffer); 729245582Sjkim if (ACPI_FAILURE (Status)) 730245582Sjkim { 731245582Sjkim return_ACPI_STATUS (Status); 732245582Sjkim } 733245582Sjkim 734245582Sjkim /* Walk the resource list and cleanup */ 735245582Sjkim 736245582Sjkim Status = AcpiWalkResourceBuffer (&Buffer, UserFunction, Context); 737167802Sjkim ACPI_FREE (Buffer.Pointer); 738167802Sjkim return_ACPI_STATUS (Status); 739114237Snjl} 740167802Sjkim 741167802SjkimACPI_EXPORT_SYMBOL (AcpiWalkResources) 742