1ae115bc7Smrj /****************************************************************************** 2ae115bc7Smrj * 3ae115bc7Smrj * Module Name: nsxfname - Public interfaces to the ACPI subsystem 4ae115bc7Smrj * ACPI Namespace oriented interfaces 5ae115bc7Smrj * 6ae115bc7Smrj *****************************************************************************/ 7ae115bc7Smrj 826f3cdf0SGordon Ross /* 9*385cc6b4SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp. 10ae115bc7Smrj * All rights reserved. 11ae115bc7Smrj * 1226f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without 1326f3cdf0SGordon Ross * modification, are permitted provided that the following conditions 1426f3cdf0SGordon Ross * are met: 1526f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright 1626f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer, 1726f3cdf0SGordon Ross * without modification. 1826f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1926f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below 2026f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon 2126f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further 2226f3cdf0SGordon Ross * binary redistribution. 2326f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names 2426f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived 2526f3cdf0SGordon Ross * from this software without specific prior written permission. 26ae115bc7Smrj * 2726f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the 2826f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free 2926f3cdf0SGordon Ross * Software Foundation. 30ae115bc7Smrj * 3126f3cdf0SGordon Ross * NO WARRANTY 3226f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3326f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3426f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3526f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3626f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3726f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3826f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3926f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4026f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4126f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4226f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES. 4326f3cdf0SGordon Ross */ 44ae115bc7Smrj 45*385cc6b4SJerry Jelinek #define EXPORT_ACPI_INTERFACES 46ae115bc7Smrj 47ae115bc7Smrj #include "acpi.h" 48aa2aa9a6SDana Myers #include "accommon.h" 49ae115bc7Smrj #include "acnamesp.h" 50aa2aa9a6SDana Myers #include "acparser.h" 51aa2aa9a6SDana Myers #include "amlcode.h" 52ae115bc7Smrj 53ae115bc7Smrj 54ae115bc7Smrj #define _COMPONENT ACPI_NAMESPACE 55ae115bc7Smrj ACPI_MODULE_NAME ("nsxfname") 56ae115bc7Smrj 5757190917SDana Myers /* Local prototypes */ 5857190917SDana Myers 5957190917SDana Myers static char * 6057190917SDana Myers AcpiNsCopyDeviceId ( 61*385cc6b4SJerry Jelinek ACPI_PNP_DEVICE_ID *Dest, 62*385cc6b4SJerry Jelinek ACPI_PNP_DEVICE_ID *Source, 6357190917SDana Myers char *StringArea); 6457190917SDana Myers 65ae115bc7Smrj 66ae115bc7Smrj /****************************************************************************** 67ae115bc7Smrj * 68ae115bc7Smrj * FUNCTION: AcpiGetHandle 69ae115bc7Smrj * 70ae115bc7Smrj * PARAMETERS: Parent - Object to search under (search scope). 71ae115bc7Smrj * Pathname - Pointer to an asciiz string containing the 72ae115bc7Smrj * name 73ae115bc7Smrj * RetHandle - Where the return handle is returned 74ae115bc7Smrj * 75ae115bc7Smrj * RETURN: Status 76ae115bc7Smrj * 77ae115bc7Smrj * DESCRIPTION: This routine will search for a caller specified name in the 78ae115bc7Smrj * name space. The caller can restrict the search region by 79ae115bc7Smrj * specifying a non NULL parent. The parent value is itself a 80ae115bc7Smrj * namespace handle. 81ae115bc7Smrj * 82ae115bc7Smrj ******************************************************************************/ 83ae115bc7Smrj 84ae115bc7Smrj ACPI_STATUS 85ae115bc7Smrj AcpiGetHandle ( 86ae115bc7Smrj ACPI_HANDLE Parent, 87ae115bc7Smrj ACPI_STRING Pathname, 88ae115bc7Smrj ACPI_HANDLE *RetHandle) 89ae115bc7Smrj { 90ae115bc7Smrj ACPI_STATUS Status; 91ae115bc7Smrj ACPI_NAMESPACE_NODE *Node = NULL; 92ae115bc7Smrj ACPI_NAMESPACE_NODE *PrefixNode = NULL; 93ae115bc7Smrj 94ae115bc7Smrj 95ae115bc7Smrj ACPI_FUNCTION_ENTRY (); 96ae115bc7Smrj 97ae115bc7Smrj 98ae115bc7Smrj /* Parameter Validation */ 99ae115bc7Smrj 100ae115bc7Smrj if (!RetHandle || !Pathname) 101ae115bc7Smrj { 102ae115bc7Smrj return (AE_BAD_PARAMETER); 103ae115bc7Smrj } 104ae115bc7Smrj 105ae115bc7Smrj /* Convert a parent handle to a prefix node */ 106ae115bc7Smrj 107ae115bc7Smrj if (Parent) 108ae115bc7Smrj { 10926f3cdf0SGordon Ross PrefixNode = AcpiNsValidateHandle (Parent); 110ae115bc7Smrj if (!PrefixNode) 111ae115bc7Smrj { 112ae115bc7Smrj return (AE_BAD_PARAMETER); 113ae115bc7Smrj } 114db2bae30SDana Myers } 115ae115bc7Smrj 116db2bae30SDana Myers /* 117db2bae30SDana Myers * Valid cases are: 118db2bae30SDana Myers * 1) Fully qualified pathname 119db2bae30SDana Myers * 2) Parent + Relative pathname 120db2bae30SDana Myers * 121db2bae30SDana Myers * Error for <null Parent + relative path> 122db2bae30SDana Myers */ 123*385cc6b4SJerry Jelinek if (ACPI_IS_ROOT_PREFIX (Pathname[0])) 124ae115bc7Smrj { 125db2bae30SDana Myers /* Pathname is fully qualified (starts with '\') */ 126ae115bc7Smrj 127db2bae30SDana Myers /* Special case for root-only, since we can't search for it */ 128ae115bc7Smrj 129*385cc6b4SJerry Jelinek if (!strcmp (Pathname, ACPI_NS_ROOT_PATH)) 130ae115bc7Smrj { 13126f3cdf0SGordon Ross *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode); 132ae115bc7Smrj return (AE_OK); 133ae115bc7Smrj } 134db2bae30SDana Myers } 135db2bae30SDana Myers else if (!PrefixNode) 136db2bae30SDana Myers { 137db2bae30SDana Myers /* Relative path with null prefix is disallowed */ 138ae115bc7Smrj 139db2bae30SDana Myers return (AE_BAD_PARAMETER); 140db2bae30SDana Myers } 141ae115bc7Smrj 142db2bae30SDana Myers /* Find the Node and convert to a handle */ 143db2bae30SDana Myers 144db2bae30SDana Myers Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node); 145ae115bc7Smrj if (ACPI_SUCCESS (Status)) 146ae115bc7Smrj { 14726f3cdf0SGordon Ross *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node); 148ae115bc7Smrj } 149ae115bc7Smrj 150ae115bc7Smrj return (Status); 151ae115bc7Smrj } 152ae115bc7Smrj 153ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiGetHandle) 154ae115bc7Smrj 155ae115bc7Smrj 156ae115bc7Smrj /****************************************************************************** 157ae115bc7Smrj * 158ae115bc7Smrj * FUNCTION: AcpiGetName 159ae115bc7Smrj * 160ae115bc7Smrj * PARAMETERS: Handle - Handle to be converted to a pathname 161ae115bc7Smrj * NameType - Full pathname or single segment 162ae115bc7Smrj * Buffer - Buffer for returned path 163ae115bc7Smrj * 164ae115bc7Smrj * RETURN: Pointer to a string containing the fully qualified Name. 165ae115bc7Smrj * 166ae115bc7Smrj * DESCRIPTION: This routine returns the fully qualified name associated with 167ae115bc7Smrj * the Handle parameter. This and the AcpiPathnameToHandle are 168ae115bc7Smrj * complementary functions. 169ae115bc7Smrj * 170ae115bc7Smrj ******************************************************************************/ 171ae115bc7Smrj 172ae115bc7Smrj ACPI_STATUS 173ae115bc7Smrj AcpiGetName ( 174ae115bc7Smrj ACPI_HANDLE Handle, 175ae115bc7Smrj UINT32 NameType, 176ae115bc7Smrj ACPI_BUFFER *Buffer) 177ae115bc7Smrj { 178ae115bc7Smrj ACPI_STATUS Status; 179ae115bc7Smrj ACPI_NAMESPACE_NODE *Node; 180*385cc6b4SJerry Jelinek const char *NodeName; 181ae115bc7Smrj 182ae115bc7Smrj 183ae115bc7Smrj /* Parameter validation */ 184ae115bc7Smrj 185ae115bc7Smrj if (NameType > ACPI_NAME_TYPE_MAX) 186ae115bc7Smrj { 187ae115bc7Smrj return (AE_BAD_PARAMETER); 188ae115bc7Smrj } 189ae115bc7Smrj 190ae115bc7Smrj Status = AcpiUtValidateBuffer (Buffer); 191ae115bc7Smrj if (ACPI_FAILURE (Status)) 192ae115bc7Smrj { 193ae115bc7Smrj return (Status); 194ae115bc7Smrj } 195ae115bc7Smrj 196*385cc6b4SJerry Jelinek if (NameType == ACPI_FULL_PATHNAME || 197*385cc6b4SJerry Jelinek NameType == ACPI_FULL_PATHNAME_NO_TRAILING) 198ae115bc7Smrj { 199ae115bc7Smrj /* Get the full pathname (From the namespace root) */ 200ae115bc7Smrj 201*385cc6b4SJerry Jelinek Status = AcpiNsHandleToPathname (Handle, Buffer, 202*385cc6b4SJerry Jelinek NameType == ACPI_FULL_PATHNAME ? FALSE : TRUE); 203ae115bc7Smrj return (Status); 204ae115bc7Smrj } 205ae115bc7Smrj 206ae115bc7Smrj /* 207ae115bc7Smrj * Wants the single segment ACPI name. 208ae115bc7Smrj * Validate handle and convert to a namespace Node 209ae115bc7Smrj */ 210ae115bc7Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 211ae115bc7Smrj if (ACPI_FAILURE (Status)) 212ae115bc7Smrj { 213ae115bc7Smrj return (Status); 214ae115bc7Smrj } 215ae115bc7Smrj 21626f3cdf0SGordon Ross Node = AcpiNsValidateHandle (Handle); 217ae115bc7Smrj if (!Node) 218ae115bc7Smrj { 219ae115bc7Smrj Status = AE_BAD_PARAMETER; 220ae115bc7Smrj goto UnlockAndExit; 221ae115bc7Smrj } 222ae115bc7Smrj 223ae115bc7Smrj /* Validate/Allocate/Clear caller buffer */ 224ae115bc7Smrj 225ae115bc7Smrj Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH); 226ae115bc7Smrj if (ACPI_FAILURE (Status)) 227ae115bc7Smrj { 228ae115bc7Smrj goto UnlockAndExit; 229ae115bc7Smrj } 230ae115bc7Smrj 231ae115bc7Smrj /* Just copy the ACPI name from the Node and zero terminate it */ 232ae115bc7Smrj 233*385cc6b4SJerry Jelinek NodeName = AcpiUtGetNodeName (Node); 234*385cc6b4SJerry Jelinek ACPI_MOVE_NAME (Buffer->Pointer, NodeName); 235ae115bc7Smrj ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0; 236ae115bc7Smrj Status = AE_OK; 237ae115bc7Smrj 238ae115bc7Smrj 239ae115bc7Smrj UnlockAndExit: 240ae115bc7Smrj 241ae115bc7Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 242ae115bc7Smrj return (Status); 243ae115bc7Smrj } 244ae115bc7Smrj 245ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiGetName) 246ae115bc7Smrj 247ae115bc7Smrj 248ae115bc7Smrj /****************************************************************************** 249ae115bc7Smrj * 25057190917SDana Myers * FUNCTION: AcpiNsCopyDeviceId 25157190917SDana Myers * 252*385cc6b4SJerry Jelinek * PARAMETERS: Dest - Pointer to the destination PNP_DEVICE_ID 253*385cc6b4SJerry Jelinek * Source - Pointer to the source PNP_DEVICE_ID 25457190917SDana Myers * StringArea - Pointer to where to copy the dest string 25557190917SDana Myers * 25657190917SDana Myers * RETURN: Pointer to the next string area 25757190917SDana Myers * 258*385cc6b4SJerry Jelinek * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data. 25957190917SDana Myers * 26057190917SDana Myers ******************************************************************************/ 26157190917SDana Myers 26257190917SDana Myers static char * 26357190917SDana Myers AcpiNsCopyDeviceId ( 264*385cc6b4SJerry Jelinek ACPI_PNP_DEVICE_ID *Dest, 265*385cc6b4SJerry Jelinek ACPI_PNP_DEVICE_ID *Source, 26657190917SDana Myers char *StringArea) 26757190917SDana Myers { 268*385cc6b4SJerry Jelinek /* Create the destination PNP_DEVICE_ID */ 26957190917SDana Myers 27057190917SDana Myers Dest->String = StringArea; 27157190917SDana Myers Dest->Length = Source->Length; 27257190917SDana Myers 27357190917SDana Myers /* Copy actual string and return a pointer to the next string area */ 27457190917SDana Myers 275*385cc6b4SJerry Jelinek memcpy (StringArea, Source->String, Source->Length); 27657190917SDana Myers return (StringArea + Source->Length); 27757190917SDana Myers } 27857190917SDana Myers 27957190917SDana Myers 28057190917SDana Myers /****************************************************************************** 28157190917SDana Myers * 282ae115bc7Smrj * FUNCTION: AcpiGetObjectInfo 283ae115bc7Smrj * 284ae115bc7Smrj * PARAMETERS: Handle - Object Handle 28557190917SDana Myers * ReturnBuffer - Where the info is returned 286ae115bc7Smrj * 287ae115bc7Smrj * RETURN: Status 288ae115bc7Smrj * 289ae115bc7Smrj * DESCRIPTION: Returns information about an object as gleaned from the 290ae115bc7Smrj * namespace node and possibly by running several standard 291ae115bc7Smrj * control methods (Such as in the case of a device.) 292ae115bc7Smrj * 29357190917SDana Myers * For Device and Processor objects, run the Device _HID, _UID, _CID, _STA, 294*385cc6b4SJerry Jelinek * _CLS, _ADR, _SxW, and _SxD methods. 29557190917SDana Myers * 29657190917SDana Myers * Note: Allocates the return buffer, must be freed by the caller. 29757190917SDana Myers * 298*385cc6b4SJerry Jelinek * Note: This interface is intended to be used during the initial device 299*385cc6b4SJerry Jelinek * discovery namespace traversal. Therefore, no complex methods can be 300*385cc6b4SJerry Jelinek * executed, especially those that access operation regions. Therefore, do 301*385cc6b4SJerry Jelinek * not add any additional methods that could cause problems in this area. 302*385cc6b4SJerry Jelinek * this was the fate of the _SUB method which was found to cause such 303*385cc6b4SJerry Jelinek * problems and was removed (11/2015). 304*385cc6b4SJerry Jelinek * 305ae115bc7Smrj ******************************************************************************/ 306ae115bc7Smrj 307ae115bc7Smrj ACPI_STATUS 308ae115bc7Smrj AcpiGetObjectInfo ( 309ae115bc7Smrj ACPI_HANDLE Handle, 31057190917SDana Myers ACPI_DEVICE_INFO **ReturnBuffer) 311ae115bc7Smrj { 312ae115bc7Smrj ACPI_NAMESPACE_NODE *Node; 313ae115bc7Smrj ACPI_DEVICE_INFO *Info; 314*385cc6b4SJerry Jelinek ACPI_PNP_DEVICE_ID_LIST *CidList = NULL; 315*385cc6b4SJerry Jelinek ACPI_PNP_DEVICE_ID *Hid = NULL; 316*385cc6b4SJerry Jelinek ACPI_PNP_DEVICE_ID *Uid = NULL; 317*385cc6b4SJerry Jelinek ACPI_PNP_DEVICE_ID *Cls = NULL; 31857190917SDana Myers char *NextIdString; 31957190917SDana Myers ACPI_OBJECT_TYPE Type; 32057190917SDana Myers ACPI_NAME Name; 32157190917SDana Myers UINT8 ParamCount= 0; 322*385cc6b4SJerry Jelinek UINT16 Valid = 0; 32357190917SDana Myers UINT32 InfoSize; 32457190917SDana Myers UINT32 i; 32557190917SDana Myers ACPI_STATUS Status; 326ae115bc7Smrj 327ae115bc7Smrj 328ae115bc7Smrj /* Parameter validation */ 329ae115bc7Smrj 33057190917SDana Myers if (!Handle || !ReturnBuffer) 331ae115bc7Smrj { 332ae115bc7Smrj return (AE_BAD_PARAMETER); 333ae115bc7Smrj } 334ae115bc7Smrj 335ae115bc7Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 336ae115bc7Smrj if (ACPI_FAILURE (Status)) 337ae115bc7Smrj { 338*385cc6b4SJerry Jelinek return (Status); 339ae115bc7Smrj } 340ae115bc7Smrj 34126f3cdf0SGordon Ross Node = AcpiNsValidateHandle (Handle); 342ae115bc7Smrj if (!Node) 343ae115bc7Smrj { 344ae115bc7Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 34557190917SDana Myers return (AE_BAD_PARAMETER); 346ae115bc7Smrj } 347ae115bc7Smrj 34857190917SDana Myers /* Get the namespace node data while the namespace is locked */ 349ae115bc7Smrj 35057190917SDana Myers InfoSize = sizeof (ACPI_DEVICE_INFO); 35157190917SDana Myers Type = Node->Type; 35257190917SDana Myers Name = Node->Name.Integer; 353ae115bc7Smrj 354db2bae30SDana Myers if (Node->Type == ACPI_TYPE_METHOD) 355db2bae30SDana Myers { 35657190917SDana Myers ParamCount = Node->Object->Method.ParamCount; 357db2bae30SDana Myers } 358db2bae30SDana Myers 359ae115bc7Smrj Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 360ae115bc7Smrj if (ACPI_FAILURE (Status)) 361ae115bc7Smrj { 36257190917SDana Myers return (Status); 363ae115bc7Smrj } 364ae115bc7Smrj 36557190917SDana Myers if ((Type == ACPI_TYPE_DEVICE) || 36657190917SDana Myers (Type == ACPI_TYPE_PROCESSOR)) 367ae115bc7Smrj { 368ae115bc7Smrj /* 36957190917SDana Myers * Get extra info for ACPI Device/Processor objects only: 370*385cc6b4SJerry Jelinek * Run the Device _HID, _UID, _CLS, and _CID methods. 371ae115bc7Smrj * 372ae115bc7Smrj * Note: none of these methods are required, so they may or may 373ae115bc7Smrj * not be present for this device. The Info->Valid bitfield is used 37457190917SDana Myers * to indicate which methods were found and run successfully. 375ae115bc7Smrj */ 376ae115bc7Smrj 377ae115bc7Smrj /* Execute the Device._HID method */ 378ae115bc7Smrj 37957190917SDana Myers Status = AcpiUtExecute_HID (Node, &Hid); 380ae115bc7Smrj if (ACPI_SUCCESS (Status)) 381ae115bc7Smrj { 38257190917SDana Myers InfoSize += Hid->Length; 38357190917SDana Myers Valid |= ACPI_VALID_HID; 384ae115bc7Smrj } 385ae115bc7Smrj 386ae115bc7Smrj /* Execute the Device._UID method */ 387ae115bc7Smrj 38857190917SDana Myers Status = AcpiUtExecute_UID (Node, &Uid); 389ae115bc7Smrj if (ACPI_SUCCESS (Status)) 390ae115bc7Smrj { 39157190917SDana Myers InfoSize += Uid->Length; 39257190917SDana Myers Valid |= ACPI_VALID_UID; 393ae115bc7Smrj } 394ae115bc7Smrj 395ae115bc7Smrj /* Execute the Device._CID method */ 396ae115bc7Smrj 397ae115bc7Smrj Status = AcpiUtExecute_CID (Node, &CidList); 398ae115bc7Smrj if (ACPI_SUCCESS (Status)) 399ae115bc7Smrj { 40057190917SDana Myers /* Add size of CID strings and CID pointer array */ 40157190917SDana Myers 402*385cc6b4SJerry Jelinek InfoSize += (CidList->ListSize - sizeof (ACPI_PNP_DEVICE_ID_LIST)); 40357190917SDana Myers Valid |= ACPI_VALID_CID; 404ae115bc7Smrj } 405*385cc6b4SJerry Jelinek 406*385cc6b4SJerry Jelinek /* Execute the Device._CLS method */ 407*385cc6b4SJerry Jelinek 408*385cc6b4SJerry Jelinek Status = AcpiUtExecute_CLS (Node, &Cls); 409*385cc6b4SJerry Jelinek if (ACPI_SUCCESS (Status)) 410*385cc6b4SJerry Jelinek { 411*385cc6b4SJerry Jelinek InfoSize += Cls->Length; 412*385cc6b4SJerry Jelinek Valid |= ACPI_VALID_CLS; 413*385cc6b4SJerry Jelinek } 41457190917SDana Myers } 41557190917SDana Myers 41657190917SDana Myers /* 41757190917SDana Myers * Now that we have the variable-length data, we can allocate the 41857190917SDana Myers * return buffer 41957190917SDana Myers */ 42057190917SDana Myers Info = ACPI_ALLOCATE_ZEROED (InfoSize); 42157190917SDana Myers if (!Info) 42257190917SDana Myers { 42357190917SDana Myers Status = AE_NO_MEMORY; 42457190917SDana Myers goto Cleanup; 42557190917SDana Myers } 42657190917SDana Myers 42757190917SDana Myers /* Get the fixed-length data */ 42857190917SDana Myers 42957190917SDana Myers if ((Type == ACPI_TYPE_DEVICE) || 43057190917SDana Myers (Type == ACPI_TYPE_PROCESSOR)) 43157190917SDana Myers { 43257190917SDana Myers /* 43357190917SDana Myers * Get extra info for ACPI Device/Processor objects only: 43457190917SDana Myers * Run the _STA, _ADR and, SxW, and _SxD methods. 43557190917SDana Myers * 436*385cc6b4SJerry Jelinek * Notes: none of these methods are required, so they may or may 43757190917SDana Myers * not be present for this device. The Info->Valid bitfield is used 43857190917SDana Myers * to indicate which methods were found and run successfully. 439*385cc6b4SJerry Jelinek * 440*385cc6b4SJerry Jelinek * For _STA, if the method does not exist, then (as per the ACPI 441*385cc6b4SJerry Jelinek * specification), the returned CurrentStatus flags will indicate 442*385cc6b4SJerry Jelinek * that the device is present/functional/enabled. Otherwise, the 443*385cc6b4SJerry Jelinek * CurrentStatus flags reflect the value returned from _STA. 44457190917SDana Myers */ 445ae115bc7Smrj 446ae115bc7Smrj /* Execute the Device._STA method */ 447ae115bc7Smrj 448ae115bc7Smrj Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus); 449ae115bc7Smrj if (ACPI_SUCCESS (Status)) 450ae115bc7Smrj { 45157190917SDana Myers Valid |= ACPI_VALID_STA; 452ae115bc7Smrj } 453ae115bc7Smrj 454ae115bc7Smrj /* Execute the Device._ADR method */ 455ae115bc7Smrj 456ae115bc7Smrj Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node, 457ae115bc7Smrj &Info->Address); 458ae115bc7Smrj if (ACPI_SUCCESS (Status)) 459ae115bc7Smrj { 46057190917SDana Myers Valid |= ACPI_VALID_ADR; 46157190917SDana Myers } 46257190917SDana Myers 46357190917SDana Myers /* Execute the Device._SxW methods */ 46457190917SDana Myers 46557190917SDana Myers Status = AcpiUtExecutePowerMethods (Node, 46657190917SDana Myers AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS, 46757190917SDana Myers Info->LowestDstates); 46857190917SDana Myers if (ACPI_SUCCESS (Status)) 46957190917SDana Myers { 47057190917SDana Myers Valid |= ACPI_VALID_SXWS; 471ae115bc7Smrj } 472ae115bc7Smrj 473ae115bc7Smrj /* Execute the Device._SxD methods */ 474ae115bc7Smrj 47557190917SDana Myers Status = AcpiUtExecutePowerMethods (Node, 47657190917SDana Myers AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS, 47757190917SDana Myers Info->HighestDstates); 478ae115bc7Smrj if (ACPI_SUCCESS (Status)) 479ae115bc7Smrj { 48057190917SDana Myers Valid |= ACPI_VALID_SXDS; 481ae115bc7Smrj } 482ae115bc7Smrj } 483ae115bc7Smrj 48457190917SDana Myers /* 48557190917SDana Myers * Create a pointer to the string area of the return buffer. 48657190917SDana Myers * Point to the end of the base ACPI_DEVICE_INFO structure. 48757190917SDana Myers */ 48857190917SDana Myers NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids); 48957190917SDana Myers if (CidList) 490ae115bc7Smrj { 491*385cc6b4SJerry Jelinek /* Point past the CID PNP_DEVICE_ID array */ 49257190917SDana Myers 493*385cc6b4SJerry Jelinek NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_PNP_DEVICE_ID)); 494ae115bc7Smrj } 495ae115bc7Smrj 49657190917SDana Myers /* 49757190917SDana Myers * Copy the HID, UID, and CIDs to the return buffer. The variable-length 49857190917SDana Myers * strings are copied to the reserved area at the end of the buffer. 49957190917SDana Myers * 50057190917SDana Myers * For HID and CID, check if the ID is a PCI Root Bridge. 50157190917SDana Myers */ 50257190917SDana Myers if (Hid) 50357190917SDana Myers { 50457190917SDana Myers NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId, 50557190917SDana Myers Hid, NextIdString); 506ae115bc7Smrj 50757190917SDana Myers if (AcpiUtIsPciRootBridge (Hid->String)) 50857190917SDana Myers { 50957190917SDana Myers Info->Flags |= ACPI_PCI_ROOT_BRIDGE; 51057190917SDana Myers } 51157190917SDana Myers } 51257190917SDana Myers 51357190917SDana Myers if (Uid) 51457190917SDana Myers { 51557190917SDana Myers NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId, 51657190917SDana Myers Uid, NextIdString); 51757190917SDana Myers } 518ae115bc7Smrj 519ae115bc7Smrj if (CidList) 520ae115bc7Smrj { 52157190917SDana Myers Info->CompatibleIdList.Count = CidList->Count; 52257190917SDana Myers Info->CompatibleIdList.ListSize = CidList->ListSize; 52357190917SDana Myers 52457190917SDana Myers /* Copy each CID */ 52557190917SDana Myers 52657190917SDana Myers for (i = 0; i < CidList->Count; i++) 52757190917SDana Myers { 52857190917SDana Myers NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i], 52957190917SDana Myers &CidList->Ids[i], NextIdString); 53057190917SDana Myers 53157190917SDana Myers if (AcpiUtIsPciRootBridge (CidList->Ids[i].String)) 53257190917SDana Myers { 53357190917SDana Myers Info->Flags |= ACPI_PCI_ROOT_BRIDGE; 534ae115bc7Smrj } 53557190917SDana Myers } 53657190917SDana Myers } 53757190917SDana Myers 538*385cc6b4SJerry Jelinek if (Cls) 539*385cc6b4SJerry Jelinek { 540*385cc6b4SJerry Jelinek NextIdString = AcpiNsCopyDeviceId (&Info->ClassCode, 541*385cc6b4SJerry Jelinek Cls, NextIdString); 542*385cc6b4SJerry Jelinek } 543*385cc6b4SJerry Jelinek 54457190917SDana Myers /* Copy the fixed-length data */ 54557190917SDana Myers 54657190917SDana Myers Info->InfoSize = InfoSize; 54757190917SDana Myers Info->Type = Type; 54857190917SDana Myers Info->Name = Name; 54957190917SDana Myers Info->ParamCount = ParamCount; 55057190917SDana Myers Info->Valid = Valid; 55157190917SDana Myers 55257190917SDana Myers *ReturnBuffer = Info; 55357190917SDana Myers Status = AE_OK; 554ae115bc7Smrj 555ae115bc7Smrj 556ae115bc7Smrj Cleanup: 55757190917SDana Myers if (Hid) 55857190917SDana Myers { 55957190917SDana Myers ACPI_FREE (Hid); 56057190917SDana Myers } 56157190917SDana Myers if (Uid) 56257190917SDana Myers { 56357190917SDana Myers ACPI_FREE (Uid); 56457190917SDana Myers } 565ae115bc7Smrj if (CidList) 566ae115bc7Smrj { 567ae115bc7Smrj ACPI_FREE (CidList); 568ae115bc7Smrj } 569*385cc6b4SJerry Jelinek if (Cls) 570*385cc6b4SJerry Jelinek { 571*385cc6b4SJerry Jelinek ACPI_FREE (Cls); 572*385cc6b4SJerry Jelinek } 573ae115bc7Smrj return (Status); 574ae115bc7Smrj } 575ae115bc7Smrj 576ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo) 577ae115bc7Smrj 578aa2aa9a6SDana Myers 579aa2aa9a6SDana Myers /****************************************************************************** 580aa2aa9a6SDana Myers * 581aa2aa9a6SDana Myers * FUNCTION: AcpiInstallMethod 582aa2aa9a6SDana Myers * 583aa2aa9a6SDana Myers * PARAMETERS: Buffer - An ACPI table containing one control method 584aa2aa9a6SDana Myers * 585aa2aa9a6SDana Myers * RETURN: Status 586aa2aa9a6SDana Myers * 587aa2aa9a6SDana Myers * DESCRIPTION: Install a control method into the namespace. If the method 588aa2aa9a6SDana Myers * name already exists in the namespace, it is overwritten. The 589aa2aa9a6SDana Myers * input buffer must contain a valid DSDT or SSDT containing a 590aa2aa9a6SDana Myers * single control method. 591aa2aa9a6SDana Myers * 592aa2aa9a6SDana Myers ******************************************************************************/ 593aa2aa9a6SDana Myers 594aa2aa9a6SDana Myers ACPI_STATUS 595aa2aa9a6SDana Myers AcpiInstallMethod ( 596aa2aa9a6SDana Myers UINT8 *Buffer) 597aa2aa9a6SDana Myers { 598aa2aa9a6SDana Myers ACPI_TABLE_HEADER *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer); 599aa2aa9a6SDana Myers UINT8 *AmlBuffer; 600aa2aa9a6SDana Myers UINT8 *AmlStart; 601aa2aa9a6SDana Myers char *Path; 602aa2aa9a6SDana Myers ACPI_NAMESPACE_NODE *Node; 603aa2aa9a6SDana Myers ACPI_OPERAND_OBJECT *MethodObj; 604aa2aa9a6SDana Myers ACPI_PARSE_STATE ParserState; 605aa2aa9a6SDana Myers UINT32 AmlLength; 606aa2aa9a6SDana Myers UINT16 Opcode; 607aa2aa9a6SDana Myers UINT8 MethodFlags; 608aa2aa9a6SDana Myers ACPI_STATUS Status; 609aa2aa9a6SDana Myers 610aa2aa9a6SDana Myers 611aa2aa9a6SDana Myers /* Parameter validation */ 612aa2aa9a6SDana Myers 613aa2aa9a6SDana Myers if (!Buffer) 614aa2aa9a6SDana Myers { 615aa2aa9a6SDana Myers return (AE_BAD_PARAMETER); 616aa2aa9a6SDana Myers } 617aa2aa9a6SDana Myers 618aa2aa9a6SDana Myers /* Table must be a DSDT or SSDT */ 619aa2aa9a6SDana Myers 620aa2aa9a6SDana Myers if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) && 621aa2aa9a6SDana Myers !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT)) 622aa2aa9a6SDana Myers { 623aa2aa9a6SDana Myers return (AE_BAD_HEADER); 624aa2aa9a6SDana Myers } 625aa2aa9a6SDana Myers 626aa2aa9a6SDana Myers /* First AML opcode in the table must be a control method */ 627aa2aa9a6SDana Myers 628aa2aa9a6SDana Myers ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER); 629aa2aa9a6SDana Myers Opcode = AcpiPsPeekOpcode (&ParserState); 630aa2aa9a6SDana Myers if (Opcode != AML_METHOD_OP) 631aa2aa9a6SDana Myers { 632aa2aa9a6SDana Myers return (AE_BAD_PARAMETER); 633aa2aa9a6SDana Myers } 634aa2aa9a6SDana Myers 635aa2aa9a6SDana Myers /* Extract method information from the raw AML */ 636aa2aa9a6SDana Myers 637aa2aa9a6SDana Myers ParserState.Aml += AcpiPsGetOpcodeSize (Opcode); 638aa2aa9a6SDana Myers ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState); 639aa2aa9a6SDana Myers Path = AcpiPsGetNextNamestring (&ParserState); 640*385cc6b4SJerry Jelinek 641aa2aa9a6SDana Myers MethodFlags = *ParserState.Aml++; 642aa2aa9a6SDana Myers AmlStart = ParserState.Aml; 643aa2aa9a6SDana Myers AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart); 644aa2aa9a6SDana Myers 645aa2aa9a6SDana Myers /* 646aa2aa9a6SDana Myers * Allocate resources up-front. We don't want to have to delete a new 647aa2aa9a6SDana Myers * node from the namespace if we cannot allocate memory. 648aa2aa9a6SDana Myers */ 649aa2aa9a6SDana Myers AmlBuffer = ACPI_ALLOCATE (AmlLength); 650aa2aa9a6SDana Myers if (!AmlBuffer) 651aa2aa9a6SDana Myers { 652aa2aa9a6SDana Myers return (AE_NO_MEMORY); 653aa2aa9a6SDana Myers } 654aa2aa9a6SDana Myers 655aa2aa9a6SDana Myers MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD); 656aa2aa9a6SDana Myers if (!MethodObj) 657aa2aa9a6SDana Myers { 658aa2aa9a6SDana Myers ACPI_FREE (AmlBuffer); 659aa2aa9a6SDana Myers return (AE_NO_MEMORY); 660aa2aa9a6SDana Myers } 661aa2aa9a6SDana Myers 662aa2aa9a6SDana Myers /* Lock namespace for AcpiNsLookup, we may be creating a new node */ 663aa2aa9a6SDana Myers 664aa2aa9a6SDana Myers Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 665aa2aa9a6SDana Myers if (ACPI_FAILURE (Status)) 666aa2aa9a6SDana Myers { 667aa2aa9a6SDana Myers goto ErrorExit; 668aa2aa9a6SDana Myers } 669aa2aa9a6SDana Myers 670aa2aa9a6SDana Myers /* The lookup either returns an existing node or creates a new one */ 671aa2aa9a6SDana Myers 672aa2aa9a6SDana Myers Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1, 673aa2aa9a6SDana Myers ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node); 674aa2aa9a6SDana Myers 675aa2aa9a6SDana Myers (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 676aa2aa9a6SDana Myers 677aa2aa9a6SDana Myers if (ACPI_FAILURE (Status)) /* NsLookup */ 678aa2aa9a6SDana Myers { 679aa2aa9a6SDana Myers if (Status != AE_ALREADY_EXISTS) 680aa2aa9a6SDana Myers { 681aa2aa9a6SDana Myers goto ErrorExit; 682aa2aa9a6SDana Myers } 683aa2aa9a6SDana Myers 684aa2aa9a6SDana Myers /* Node existed previously, make sure it is a method node */ 685aa2aa9a6SDana Myers 686aa2aa9a6SDana Myers if (Node->Type != ACPI_TYPE_METHOD) 687aa2aa9a6SDana Myers { 688aa2aa9a6SDana Myers Status = AE_TYPE; 689aa2aa9a6SDana Myers goto ErrorExit; 690aa2aa9a6SDana Myers } 691aa2aa9a6SDana Myers } 692aa2aa9a6SDana Myers 693aa2aa9a6SDana Myers /* Copy the method AML to the local buffer */ 694aa2aa9a6SDana Myers 695*385cc6b4SJerry Jelinek memcpy (AmlBuffer, AmlStart, AmlLength); 696aa2aa9a6SDana Myers 697aa2aa9a6SDana Myers /* Initialize the method object with the new method's information */ 698aa2aa9a6SDana Myers 699aa2aa9a6SDana Myers MethodObj->Method.AmlStart = AmlBuffer; 700aa2aa9a6SDana Myers MethodObj->Method.AmlLength = AmlLength; 701aa2aa9a6SDana Myers 702aa2aa9a6SDana Myers MethodObj->Method.ParamCount = (UINT8) 703aa2aa9a6SDana Myers (MethodFlags & AML_METHOD_ARG_COUNT); 704aa2aa9a6SDana Myers 705aa2aa9a6SDana Myers if (MethodFlags & AML_METHOD_SERIALIZED) 706aa2aa9a6SDana Myers { 70726f3cdf0SGordon Ross MethodObj->Method.InfoFlags = ACPI_METHOD_SERIALIZED; 70826f3cdf0SGordon Ross 709aa2aa9a6SDana Myers MethodObj->Method.SyncLevel = (UINT8) 710aa2aa9a6SDana Myers ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4); 711aa2aa9a6SDana Myers } 712aa2aa9a6SDana Myers 713aa2aa9a6SDana Myers /* 714aa2aa9a6SDana Myers * Now that it is complete, we can attach the new method object to 715aa2aa9a6SDana Myers * the method Node (detaches/deletes any existing object) 716aa2aa9a6SDana Myers */ 71726f3cdf0SGordon Ross Status = AcpiNsAttachObject (Node, MethodObj, ACPI_TYPE_METHOD); 718aa2aa9a6SDana Myers 719aa2aa9a6SDana Myers /* 720aa2aa9a6SDana Myers * Flag indicates AML buffer is dynamic, must be deleted later. 721aa2aa9a6SDana Myers * Must be set only after attach above. 722aa2aa9a6SDana Myers */ 723aa2aa9a6SDana Myers Node->Flags |= ANOBJ_ALLOCATED_BUFFER; 724aa2aa9a6SDana Myers 725aa2aa9a6SDana Myers /* Remove local reference to the method object */ 726aa2aa9a6SDana Myers 727aa2aa9a6SDana Myers AcpiUtRemoveReference (MethodObj); 728aa2aa9a6SDana Myers return (Status); 729aa2aa9a6SDana Myers 730aa2aa9a6SDana Myers 731aa2aa9a6SDana Myers ErrorExit: 732aa2aa9a6SDana Myers 733aa2aa9a6SDana Myers ACPI_FREE (AmlBuffer); 734aa2aa9a6SDana Myers ACPI_FREE (MethodObj); 735aa2aa9a6SDana Myers return (Status); 736aa2aa9a6SDana Myers } 737aa2aa9a6SDana Myers 738aa2aa9a6SDana Myers ACPI_EXPORT_SYMBOL (AcpiInstallMethod) 739