1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4433d6423SLionel Sambuc * ACPI Namespace oriented interfaces
5433d6423SLionel Sambuc *
6433d6423SLionel Sambuc *****************************************************************************/
7433d6423SLionel Sambuc
8*29492bb7SDavid van Moolenbroek /*
9*29492bb7SDavid van Moolenbroek * Copyright (C) 2000 - 2014, Intel Corp.
10433d6423SLionel Sambuc * All rights reserved.
11433d6423SLionel Sambuc *
12*29492bb7SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
13*29492bb7SDavid van Moolenbroek * modification, are permitted provided that the following conditions
14*29492bb7SDavid van Moolenbroek * are met:
15*29492bb7SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
16*29492bb7SDavid van Moolenbroek * notice, this list of conditions, and the following disclaimer,
17*29492bb7SDavid van Moolenbroek * without modification.
18*29492bb7SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19*29492bb7SDavid van Moolenbroek * substantially similar to the "NO WARRANTY" disclaimer below
20*29492bb7SDavid van Moolenbroek * ("Disclaimer") and any redistribution must be conditioned upon
21*29492bb7SDavid van Moolenbroek * including a substantially similar Disclaimer requirement for further
22*29492bb7SDavid van Moolenbroek * binary redistribution.
23*29492bb7SDavid van Moolenbroek * 3. Neither the names of the above-listed copyright holders nor the names
24*29492bb7SDavid van Moolenbroek * of any contributors may be used to endorse or promote products derived
25*29492bb7SDavid van Moolenbroek * from this software without specific prior written permission.
26433d6423SLionel Sambuc *
27*29492bb7SDavid van Moolenbroek * Alternatively, this software may be distributed under the terms of the
28*29492bb7SDavid van Moolenbroek * GNU General Public License ("GPL") version 2 as published by the Free
29*29492bb7SDavid van Moolenbroek * Software Foundation.
30433d6423SLionel Sambuc *
31*29492bb7SDavid van Moolenbroek * NO WARRANTY
32*29492bb7SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33*29492bb7SDavid van Moolenbroek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34*29492bb7SDavid van Moolenbroek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35*29492bb7SDavid van Moolenbroek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36*29492bb7SDavid van Moolenbroek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37*29492bb7SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38*29492bb7SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39*29492bb7SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40*29492bb7SDavid van Moolenbroek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41*29492bb7SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42*29492bb7SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGES.
43*29492bb7SDavid van Moolenbroek */
44433d6423SLionel Sambuc
45*29492bb7SDavid van Moolenbroek #define EXPORT_ACPI_INTERFACES
46433d6423SLionel Sambuc
47433d6423SLionel Sambuc #include "acpi.h"
48433d6423SLionel Sambuc #include "accommon.h"
49433d6423SLionel Sambuc #include "acnamesp.h"
50433d6423SLionel Sambuc #include "acparser.h"
51433d6423SLionel Sambuc #include "amlcode.h"
52433d6423SLionel Sambuc
53433d6423SLionel Sambuc
54433d6423SLionel Sambuc #define _COMPONENT ACPI_NAMESPACE
55433d6423SLionel Sambuc ACPI_MODULE_NAME ("nsxfname")
56433d6423SLionel Sambuc
57433d6423SLionel Sambuc /* Local prototypes */
58433d6423SLionel Sambuc
59433d6423SLionel Sambuc static char *
60433d6423SLionel Sambuc AcpiNsCopyDeviceId (
61*29492bb7SDavid van Moolenbroek ACPI_PNP_DEVICE_ID *Dest,
62*29492bb7SDavid van Moolenbroek ACPI_PNP_DEVICE_ID *Source,
63433d6423SLionel Sambuc char *StringArea);
64433d6423SLionel Sambuc
65433d6423SLionel Sambuc
66433d6423SLionel Sambuc /******************************************************************************
67433d6423SLionel Sambuc *
68433d6423SLionel Sambuc * FUNCTION: AcpiGetHandle
69433d6423SLionel Sambuc *
70433d6423SLionel Sambuc * PARAMETERS: Parent - Object to search under (search scope).
71433d6423SLionel Sambuc * Pathname - Pointer to an asciiz string containing the
72433d6423SLionel Sambuc * name
73433d6423SLionel Sambuc * RetHandle - Where the return handle is returned
74433d6423SLionel Sambuc *
75433d6423SLionel Sambuc * RETURN: Status
76433d6423SLionel Sambuc *
77433d6423SLionel Sambuc * DESCRIPTION: This routine will search for a caller specified name in the
78433d6423SLionel Sambuc * name space. The caller can restrict the search region by
79433d6423SLionel Sambuc * specifying a non NULL parent. The parent value is itself a
80433d6423SLionel Sambuc * namespace handle.
81433d6423SLionel Sambuc *
82433d6423SLionel Sambuc ******************************************************************************/
83433d6423SLionel Sambuc
84433d6423SLionel Sambuc ACPI_STATUS
AcpiGetHandle(ACPI_HANDLE Parent,ACPI_STRING Pathname,ACPI_HANDLE * RetHandle)85433d6423SLionel Sambuc AcpiGetHandle (
86433d6423SLionel Sambuc ACPI_HANDLE Parent,
87433d6423SLionel Sambuc ACPI_STRING Pathname,
88433d6423SLionel Sambuc ACPI_HANDLE *RetHandle)
89433d6423SLionel Sambuc {
90433d6423SLionel Sambuc ACPI_STATUS Status;
91433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node = NULL;
92433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *PrefixNode = NULL;
93433d6423SLionel Sambuc
94433d6423SLionel Sambuc
95433d6423SLionel Sambuc ACPI_FUNCTION_ENTRY ();
96433d6423SLionel Sambuc
97433d6423SLionel Sambuc
98433d6423SLionel Sambuc /* Parameter Validation */
99433d6423SLionel Sambuc
100433d6423SLionel Sambuc if (!RetHandle || !Pathname)
101433d6423SLionel Sambuc {
102433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
103433d6423SLionel Sambuc }
104433d6423SLionel Sambuc
105433d6423SLionel Sambuc /* Convert a parent handle to a prefix node */
106433d6423SLionel Sambuc
107433d6423SLionel Sambuc if (Parent)
108433d6423SLionel Sambuc {
109433d6423SLionel Sambuc PrefixNode = AcpiNsValidateHandle (Parent);
110433d6423SLionel Sambuc if (!PrefixNode)
111433d6423SLionel Sambuc {
112433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
113433d6423SLionel Sambuc }
114433d6423SLionel Sambuc }
115433d6423SLionel Sambuc
116433d6423SLionel Sambuc /*
117433d6423SLionel Sambuc * Valid cases are:
118433d6423SLionel Sambuc * 1) Fully qualified pathname
119433d6423SLionel Sambuc * 2) Parent + Relative pathname
120433d6423SLionel Sambuc *
121433d6423SLionel Sambuc * Error for <null Parent + relative path>
122433d6423SLionel Sambuc */
123*29492bb7SDavid van Moolenbroek if (ACPI_IS_ROOT_PREFIX (Pathname[0]))
124433d6423SLionel Sambuc {
125433d6423SLionel Sambuc /* Pathname is fully qualified (starts with '\') */
126433d6423SLionel Sambuc
127433d6423SLionel Sambuc /* Special case for root-only, since we can't search for it */
128433d6423SLionel Sambuc
129433d6423SLionel Sambuc if (!ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH))
130433d6423SLionel Sambuc {
131433d6423SLionel Sambuc *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode);
132433d6423SLionel Sambuc return (AE_OK);
133433d6423SLionel Sambuc }
134433d6423SLionel Sambuc }
135433d6423SLionel Sambuc else if (!PrefixNode)
136433d6423SLionel Sambuc {
137433d6423SLionel Sambuc /* Relative path with null prefix is disallowed */
138433d6423SLionel Sambuc
139433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
140433d6423SLionel Sambuc }
141433d6423SLionel Sambuc
142433d6423SLionel Sambuc /* Find the Node and convert to a handle */
143433d6423SLionel Sambuc
144433d6423SLionel Sambuc Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node);
145433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
146433d6423SLionel Sambuc {
147433d6423SLionel Sambuc *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
148433d6423SLionel Sambuc }
149433d6423SLionel Sambuc
150433d6423SLionel Sambuc return (Status);
151433d6423SLionel Sambuc }
152433d6423SLionel Sambuc
ACPI_EXPORT_SYMBOL(AcpiGetHandle)153433d6423SLionel Sambuc ACPI_EXPORT_SYMBOL (AcpiGetHandle)
154433d6423SLionel Sambuc
155433d6423SLionel Sambuc
156433d6423SLionel Sambuc /******************************************************************************
157433d6423SLionel Sambuc *
158433d6423SLionel Sambuc * FUNCTION: AcpiGetName
159433d6423SLionel Sambuc *
160433d6423SLionel Sambuc * PARAMETERS: Handle - Handle to be converted to a pathname
161433d6423SLionel Sambuc * NameType - Full pathname or single segment
162433d6423SLionel Sambuc * Buffer - Buffer for returned path
163433d6423SLionel Sambuc *
164433d6423SLionel Sambuc * RETURN: Pointer to a string containing the fully qualified Name.
165433d6423SLionel Sambuc *
166433d6423SLionel Sambuc * DESCRIPTION: This routine returns the fully qualified name associated with
167433d6423SLionel Sambuc * the Handle parameter. This and the AcpiPathnameToHandle are
168433d6423SLionel Sambuc * complementary functions.
169433d6423SLionel Sambuc *
170433d6423SLionel Sambuc ******************************************************************************/
171433d6423SLionel Sambuc
172433d6423SLionel Sambuc ACPI_STATUS
173433d6423SLionel Sambuc AcpiGetName (
174433d6423SLionel Sambuc ACPI_HANDLE Handle,
175433d6423SLionel Sambuc UINT32 NameType,
176433d6423SLionel Sambuc ACPI_BUFFER *Buffer)
177433d6423SLionel Sambuc {
178433d6423SLionel Sambuc ACPI_STATUS Status;
179433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node;
180*29492bb7SDavid van Moolenbroek char *NodeName;
181433d6423SLionel Sambuc
182433d6423SLionel Sambuc
183433d6423SLionel Sambuc /* Parameter validation */
184433d6423SLionel Sambuc
185433d6423SLionel Sambuc if (NameType > ACPI_NAME_TYPE_MAX)
186433d6423SLionel Sambuc {
187433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
188433d6423SLionel Sambuc }
189433d6423SLionel Sambuc
190433d6423SLionel Sambuc Status = AcpiUtValidateBuffer (Buffer);
191433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
192433d6423SLionel Sambuc {
193433d6423SLionel Sambuc return (Status);
194433d6423SLionel Sambuc }
195433d6423SLionel Sambuc
196433d6423SLionel Sambuc if (NameType == ACPI_FULL_PATHNAME)
197433d6423SLionel Sambuc {
198433d6423SLionel Sambuc /* Get the full pathname (From the namespace root) */
199433d6423SLionel Sambuc
200433d6423SLionel Sambuc Status = AcpiNsHandleToPathname (Handle, Buffer);
201433d6423SLionel Sambuc return (Status);
202433d6423SLionel Sambuc }
203433d6423SLionel Sambuc
204433d6423SLionel Sambuc /*
205433d6423SLionel Sambuc * Wants the single segment ACPI name.
206433d6423SLionel Sambuc * Validate handle and convert to a namespace Node
207433d6423SLionel Sambuc */
208433d6423SLionel Sambuc Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
209433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
210433d6423SLionel Sambuc {
211433d6423SLionel Sambuc return (Status);
212433d6423SLionel Sambuc }
213433d6423SLionel Sambuc
214433d6423SLionel Sambuc Node = AcpiNsValidateHandle (Handle);
215433d6423SLionel Sambuc if (!Node)
216433d6423SLionel Sambuc {
217433d6423SLionel Sambuc Status = AE_BAD_PARAMETER;
218433d6423SLionel Sambuc goto UnlockAndExit;
219433d6423SLionel Sambuc }
220433d6423SLionel Sambuc
221433d6423SLionel Sambuc /* Validate/Allocate/Clear caller buffer */
222433d6423SLionel Sambuc
223433d6423SLionel Sambuc Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
224433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
225433d6423SLionel Sambuc {
226433d6423SLionel Sambuc goto UnlockAndExit;
227433d6423SLionel Sambuc }
228433d6423SLionel Sambuc
229433d6423SLionel Sambuc /* Just copy the ACPI name from the Node and zero terminate it */
230433d6423SLionel Sambuc
231*29492bb7SDavid van Moolenbroek NodeName = AcpiUtGetNodeName (Node);
232*29492bb7SDavid van Moolenbroek ACPI_MOVE_NAME (Buffer->Pointer, NodeName);
233433d6423SLionel Sambuc ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
234433d6423SLionel Sambuc Status = AE_OK;
235433d6423SLionel Sambuc
236433d6423SLionel Sambuc
237433d6423SLionel Sambuc UnlockAndExit:
238433d6423SLionel Sambuc
239433d6423SLionel Sambuc (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
240433d6423SLionel Sambuc return (Status);
241433d6423SLionel Sambuc }
242433d6423SLionel Sambuc
ACPI_EXPORT_SYMBOL(AcpiGetName)243433d6423SLionel Sambuc ACPI_EXPORT_SYMBOL (AcpiGetName)
244433d6423SLionel Sambuc
245433d6423SLionel Sambuc
246433d6423SLionel Sambuc /******************************************************************************
247433d6423SLionel Sambuc *
248433d6423SLionel Sambuc * FUNCTION: AcpiNsCopyDeviceId
249433d6423SLionel Sambuc *
250*29492bb7SDavid van Moolenbroek * PARAMETERS: Dest - Pointer to the destination PNP_DEVICE_ID
251*29492bb7SDavid van Moolenbroek * Source - Pointer to the source PNP_DEVICE_ID
252433d6423SLionel Sambuc * StringArea - Pointer to where to copy the dest string
253433d6423SLionel Sambuc *
254433d6423SLionel Sambuc * RETURN: Pointer to the next string area
255433d6423SLionel Sambuc *
256*29492bb7SDavid van Moolenbroek * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
257433d6423SLionel Sambuc *
258433d6423SLionel Sambuc ******************************************************************************/
259433d6423SLionel Sambuc
260433d6423SLionel Sambuc static char *
261433d6423SLionel Sambuc AcpiNsCopyDeviceId (
262*29492bb7SDavid van Moolenbroek ACPI_PNP_DEVICE_ID *Dest,
263*29492bb7SDavid van Moolenbroek ACPI_PNP_DEVICE_ID *Source,
264433d6423SLionel Sambuc char *StringArea)
265433d6423SLionel Sambuc {
266*29492bb7SDavid van Moolenbroek
267*29492bb7SDavid van Moolenbroek /* Create the destination PNP_DEVICE_ID */
268433d6423SLionel Sambuc
269433d6423SLionel Sambuc Dest->String = StringArea;
270433d6423SLionel Sambuc Dest->Length = Source->Length;
271433d6423SLionel Sambuc
272433d6423SLionel Sambuc /* Copy actual string and return a pointer to the next string area */
273433d6423SLionel Sambuc
274433d6423SLionel Sambuc ACPI_MEMCPY (StringArea, Source->String, Source->Length);
275433d6423SLionel Sambuc return (StringArea + Source->Length);
276433d6423SLionel Sambuc }
277433d6423SLionel Sambuc
278433d6423SLionel Sambuc
279433d6423SLionel Sambuc /******************************************************************************
280433d6423SLionel Sambuc *
281433d6423SLionel Sambuc * FUNCTION: AcpiGetObjectInfo
282433d6423SLionel Sambuc *
283433d6423SLionel Sambuc * PARAMETERS: Handle - Object Handle
284433d6423SLionel Sambuc * ReturnBuffer - Where the info is returned
285433d6423SLionel Sambuc *
286433d6423SLionel Sambuc * RETURN: Status
287433d6423SLionel Sambuc *
288433d6423SLionel Sambuc * DESCRIPTION: Returns information about an object as gleaned from the
289433d6423SLionel Sambuc * namespace node and possibly by running several standard
290433d6423SLionel Sambuc * control methods (Such as in the case of a device.)
291433d6423SLionel Sambuc *
292*29492bb7SDavid van Moolenbroek * For Device and Processor objects, run the Device _HID, _UID, _CID, _SUB,
293*29492bb7SDavid van Moolenbroek * _STA, _ADR, _SxW, and _SxD methods.
294433d6423SLionel Sambuc *
295433d6423SLionel Sambuc * Note: Allocates the return buffer, must be freed by the caller.
296433d6423SLionel Sambuc *
297433d6423SLionel Sambuc ******************************************************************************/
298433d6423SLionel Sambuc
299433d6423SLionel Sambuc ACPI_STATUS
AcpiGetObjectInfo(ACPI_HANDLE Handle,ACPI_DEVICE_INFO ** ReturnBuffer)300433d6423SLionel Sambuc AcpiGetObjectInfo (
301433d6423SLionel Sambuc ACPI_HANDLE Handle,
302433d6423SLionel Sambuc ACPI_DEVICE_INFO **ReturnBuffer)
303433d6423SLionel Sambuc {
304433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node;
305433d6423SLionel Sambuc ACPI_DEVICE_INFO *Info;
306*29492bb7SDavid van Moolenbroek ACPI_PNP_DEVICE_ID_LIST *CidList = NULL;
307*29492bb7SDavid van Moolenbroek ACPI_PNP_DEVICE_ID *Hid = NULL;
308*29492bb7SDavid van Moolenbroek ACPI_PNP_DEVICE_ID *Uid = NULL;
309*29492bb7SDavid van Moolenbroek ACPI_PNP_DEVICE_ID *Sub = NULL;
310433d6423SLionel Sambuc char *NextIdString;
311433d6423SLionel Sambuc ACPI_OBJECT_TYPE Type;
312433d6423SLionel Sambuc ACPI_NAME Name;
313433d6423SLionel Sambuc UINT8 ParamCount= 0;
314433d6423SLionel Sambuc UINT8 Valid = 0;
315433d6423SLionel Sambuc UINT32 InfoSize;
316433d6423SLionel Sambuc UINT32 i;
317433d6423SLionel Sambuc ACPI_STATUS Status;
318433d6423SLionel Sambuc
319433d6423SLionel Sambuc
320433d6423SLionel Sambuc /* Parameter validation */
321433d6423SLionel Sambuc
322433d6423SLionel Sambuc if (!Handle || !ReturnBuffer)
323433d6423SLionel Sambuc {
324433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
325433d6423SLionel Sambuc }
326433d6423SLionel Sambuc
327433d6423SLionel Sambuc Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
328433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
329433d6423SLionel Sambuc {
330*29492bb7SDavid van Moolenbroek return (Status);
331433d6423SLionel Sambuc }
332433d6423SLionel Sambuc
333433d6423SLionel Sambuc Node = AcpiNsValidateHandle (Handle);
334433d6423SLionel Sambuc if (!Node)
335433d6423SLionel Sambuc {
336433d6423SLionel Sambuc (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
337433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
338433d6423SLionel Sambuc }
339433d6423SLionel Sambuc
340433d6423SLionel Sambuc /* Get the namespace node data while the namespace is locked */
341433d6423SLionel Sambuc
342433d6423SLionel Sambuc InfoSize = sizeof (ACPI_DEVICE_INFO);
343433d6423SLionel Sambuc Type = Node->Type;
344433d6423SLionel Sambuc Name = Node->Name.Integer;
345433d6423SLionel Sambuc
346433d6423SLionel Sambuc if (Node->Type == ACPI_TYPE_METHOD)
347433d6423SLionel Sambuc {
348433d6423SLionel Sambuc ParamCount = Node->Object->Method.ParamCount;
349433d6423SLionel Sambuc }
350433d6423SLionel Sambuc
351433d6423SLionel Sambuc Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
352433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
353433d6423SLionel Sambuc {
354433d6423SLionel Sambuc return (Status);
355433d6423SLionel Sambuc }
356433d6423SLionel Sambuc
357433d6423SLionel Sambuc if ((Type == ACPI_TYPE_DEVICE) ||
358433d6423SLionel Sambuc (Type == ACPI_TYPE_PROCESSOR))
359433d6423SLionel Sambuc {
360433d6423SLionel Sambuc /*
361433d6423SLionel Sambuc * Get extra info for ACPI Device/Processor objects only:
362*29492bb7SDavid van Moolenbroek * Run the Device _HID, _UID, _SUB, and _CID methods.
363433d6423SLionel Sambuc *
364433d6423SLionel Sambuc * Note: none of these methods are required, so they may or may
365433d6423SLionel Sambuc * not be present for this device. The Info->Valid bitfield is used
366433d6423SLionel Sambuc * to indicate which methods were found and run successfully.
367433d6423SLionel Sambuc */
368433d6423SLionel Sambuc
369433d6423SLionel Sambuc /* Execute the Device._HID method */
370433d6423SLionel Sambuc
371433d6423SLionel Sambuc Status = AcpiUtExecute_HID (Node, &Hid);
372433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
373433d6423SLionel Sambuc {
374433d6423SLionel Sambuc InfoSize += Hid->Length;
375433d6423SLionel Sambuc Valid |= ACPI_VALID_HID;
376433d6423SLionel Sambuc }
377433d6423SLionel Sambuc
378433d6423SLionel Sambuc /* Execute the Device._UID method */
379433d6423SLionel Sambuc
380433d6423SLionel Sambuc Status = AcpiUtExecute_UID (Node, &Uid);
381433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
382433d6423SLionel Sambuc {
383433d6423SLionel Sambuc InfoSize += Uid->Length;
384433d6423SLionel Sambuc Valid |= ACPI_VALID_UID;
385433d6423SLionel Sambuc }
386433d6423SLionel Sambuc
387*29492bb7SDavid van Moolenbroek /* Execute the Device._SUB method */
388*29492bb7SDavid van Moolenbroek
389*29492bb7SDavid van Moolenbroek Status = AcpiUtExecute_SUB (Node, &Sub);
390*29492bb7SDavid van Moolenbroek if (ACPI_SUCCESS (Status))
391*29492bb7SDavid van Moolenbroek {
392*29492bb7SDavid van Moolenbroek InfoSize += Sub->Length;
393*29492bb7SDavid van Moolenbroek Valid |= ACPI_VALID_SUB;
394*29492bb7SDavid van Moolenbroek }
395*29492bb7SDavid van Moolenbroek
396433d6423SLionel Sambuc /* Execute the Device._CID method */
397433d6423SLionel Sambuc
398433d6423SLionel Sambuc Status = AcpiUtExecute_CID (Node, &CidList);
399433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
400433d6423SLionel Sambuc {
401433d6423SLionel Sambuc /* Add size of CID strings and CID pointer array */
402433d6423SLionel Sambuc
403*29492bb7SDavid van Moolenbroek InfoSize += (CidList->ListSize - sizeof (ACPI_PNP_DEVICE_ID_LIST));
404433d6423SLionel Sambuc Valid |= ACPI_VALID_CID;
405433d6423SLionel Sambuc }
406433d6423SLionel Sambuc }
407433d6423SLionel Sambuc
408433d6423SLionel Sambuc /*
409433d6423SLionel Sambuc * Now that we have the variable-length data, we can allocate the
410433d6423SLionel Sambuc * return buffer
411433d6423SLionel Sambuc */
412433d6423SLionel Sambuc Info = ACPI_ALLOCATE_ZEROED (InfoSize);
413433d6423SLionel Sambuc if (!Info)
414433d6423SLionel Sambuc {
415433d6423SLionel Sambuc Status = AE_NO_MEMORY;
416433d6423SLionel Sambuc goto Cleanup;
417433d6423SLionel Sambuc }
418433d6423SLionel Sambuc
419433d6423SLionel Sambuc /* Get the fixed-length data */
420433d6423SLionel Sambuc
421433d6423SLionel Sambuc if ((Type == ACPI_TYPE_DEVICE) ||
422433d6423SLionel Sambuc (Type == ACPI_TYPE_PROCESSOR))
423433d6423SLionel Sambuc {
424433d6423SLionel Sambuc /*
425433d6423SLionel Sambuc * Get extra info for ACPI Device/Processor objects only:
426433d6423SLionel Sambuc * Run the _STA, _ADR and, SxW, and _SxD methods.
427433d6423SLionel Sambuc *
428*29492bb7SDavid van Moolenbroek * Notes: none of these methods are required, so they may or may
429433d6423SLionel Sambuc * not be present for this device. The Info->Valid bitfield is used
430433d6423SLionel Sambuc * to indicate which methods were found and run successfully.
431*29492bb7SDavid van Moolenbroek *
432*29492bb7SDavid van Moolenbroek * For _STA, if the method does not exist, then (as per the ACPI
433*29492bb7SDavid van Moolenbroek * specification), the returned CurrentStatus flags will indicate
434*29492bb7SDavid van Moolenbroek * that the device is present/functional/enabled. Otherwise, the
435*29492bb7SDavid van Moolenbroek * CurrentStatus flags reflect the value returned from _STA.
436433d6423SLionel Sambuc */
437433d6423SLionel Sambuc
438433d6423SLionel Sambuc /* Execute the Device._STA method */
439433d6423SLionel Sambuc
440433d6423SLionel Sambuc Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
441433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
442433d6423SLionel Sambuc {
443433d6423SLionel Sambuc Valid |= ACPI_VALID_STA;
444433d6423SLionel Sambuc }
445433d6423SLionel Sambuc
446433d6423SLionel Sambuc /* Execute the Device._ADR method */
447433d6423SLionel Sambuc
448433d6423SLionel Sambuc Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
449433d6423SLionel Sambuc &Info->Address);
450433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
451433d6423SLionel Sambuc {
452433d6423SLionel Sambuc Valid |= ACPI_VALID_ADR;
453433d6423SLionel Sambuc }
454433d6423SLionel Sambuc
455433d6423SLionel Sambuc /* Execute the Device._SxW methods */
456433d6423SLionel Sambuc
457433d6423SLionel Sambuc Status = AcpiUtExecutePowerMethods (Node,
458433d6423SLionel Sambuc AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS,
459433d6423SLionel Sambuc Info->LowestDstates);
460433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
461433d6423SLionel Sambuc {
462433d6423SLionel Sambuc Valid |= ACPI_VALID_SXWS;
463433d6423SLionel Sambuc }
464433d6423SLionel Sambuc
465433d6423SLionel Sambuc /* Execute the Device._SxD methods */
466433d6423SLionel Sambuc
467433d6423SLionel Sambuc Status = AcpiUtExecutePowerMethods (Node,
468433d6423SLionel Sambuc AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS,
469433d6423SLionel Sambuc Info->HighestDstates);
470433d6423SLionel Sambuc if (ACPI_SUCCESS (Status))
471433d6423SLionel Sambuc {
472433d6423SLionel Sambuc Valid |= ACPI_VALID_SXDS;
473433d6423SLionel Sambuc }
474433d6423SLionel Sambuc }
475433d6423SLionel Sambuc
476433d6423SLionel Sambuc /*
477433d6423SLionel Sambuc * Create a pointer to the string area of the return buffer.
478433d6423SLionel Sambuc * Point to the end of the base ACPI_DEVICE_INFO structure.
479433d6423SLionel Sambuc */
480433d6423SLionel Sambuc NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids);
481433d6423SLionel Sambuc if (CidList)
482433d6423SLionel Sambuc {
483*29492bb7SDavid van Moolenbroek /* Point past the CID PNP_DEVICE_ID array */
484433d6423SLionel Sambuc
485*29492bb7SDavid van Moolenbroek NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_PNP_DEVICE_ID));
486433d6423SLionel Sambuc }
487433d6423SLionel Sambuc
488433d6423SLionel Sambuc /*
489*29492bb7SDavid van Moolenbroek * Copy the HID, UID, SUB, and CIDs to the return buffer.
490*29492bb7SDavid van Moolenbroek * The variable-length strings are copied to the reserved area
491*29492bb7SDavid van Moolenbroek * at the end of the buffer.
492433d6423SLionel Sambuc *
493433d6423SLionel Sambuc * For HID and CID, check if the ID is a PCI Root Bridge.
494433d6423SLionel Sambuc */
495433d6423SLionel Sambuc if (Hid)
496433d6423SLionel Sambuc {
497433d6423SLionel Sambuc NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId,
498433d6423SLionel Sambuc Hid, NextIdString);
499433d6423SLionel Sambuc
500433d6423SLionel Sambuc if (AcpiUtIsPciRootBridge (Hid->String))
501433d6423SLionel Sambuc {
502433d6423SLionel Sambuc Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
503433d6423SLionel Sambuc }
504433d6423SLionel Sambuc }
505433d6423SLionel Sambuc
506433d6423SLionel Sambuc if (Uid)
507433d6423SLionel Sambuc {
508433d6423SLionel Sambuc NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId,
509433d6423SLionel Sambuc Uid, NextIdString);
510433d6423SLionel Sambuc }
511433d6423SLionel Sambuc
512*29492bb7SDavid van Moolenbroek if (Sub)
513*29492bb7SDavid van Moolenbroek {
514*29492bb7SDavid van Moolenbroek NextIdString = AcpiNsCopyDeviceId (&Info->SubsystemId,
515*29492bb7SDavid van Moolenbroek Sub, NextIdString);
516*29492bb7SDavid van Moolenbroek }
517*29492bb7SDavid van Moolenbroek
518433d6423SLionel Sambuc if (CidList)
519433d6423SLionel Sambuc {
520433d6423SLionel Sambuc Info->CompatibleIdList.Count = CidList->Count;
521433d6423SLionel Sambuc Info->CompatibleIdList.ListSize = CidList->ListSize;
522433d6423SLionel Sambuc
523433d6423SLionel Sambuc /* Copy each CID */
524433d6423SLionel Sambuc
525433d6423SLionel Sambuc for (i = 0; i < CidList->Count; i++)
526433d6423SLionel Sambuc {
527433d6423SLionel Sambuc NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i],
528433d6423SLionel Sambuc &CidList->Ids[i], NextIdString);
529433d6423SLionel Sambuc
530433d6423SLionel Sambuc if (AcpiUtIsPciRootBridge (CidList->Ids[i].String))
531433d6423SLionel Sambuc {
532433d6423SLionel Sambuc Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
533433d6423SLionel Sambuc }
534433d6423SLionel Sambuc }
535433d6423SLionel Sambuc }
536433d6423SLionel Sambuc
537433d6423SLionel Sambuc /* Copy the fixed-length data */
538433d6423SLionel Sambuc
539433d6423SLionel Sambuc Info->InfoSize = InfoSize;
540433d6423SLionel Sambuc Info->Type = Type;
541433d6423SLionel Sambuc Info->Name = Name;
542433d6423SLionel Sambuc Info->ParamCount = ParamCount;
543433d6423SLionel Sambuc Info->Valid = Valid;
544433d6423SLionel Sambuc
545433d6423SLionel Sambuc *ReturnBuffer = Info;
546433d6423SLionel Sambuc Status = AE_OK;
547433d6423SLionel Sambuc
548433d6423SLionel Sambuc
549433d6423SLionel Sambuc Cleanup:
550433d6423SLionel Sambuc if (Hid)
551433d6423SLionel Sambuc {
552433d6423SLionel Sambuc ACPI_FREE (Hid);
553433d6423SLionel Sambuc }
554433d6423SLionel Sambuc if (Uid)
555433d6423SLionel Sambuc {
556433d6423SLionel Sambuc ACPI_FREE (Uid);
557433d6423SLionel Sambuc }
558*29492bb7SDavid van Moolenbroek if (Sub)
559*29492bb7SDavid van Moolenbroek {
560*29492bb7SDavid van Moolenbroek ACPI_FREE (Sub);
561*29492bb7SDavid van Moolenbroek }
562433d6423SLionel Sambuc if (CidList)
563433d6423SLionel Sambuc {
564433d6423SLionel Sambuc ACPI_FREE (CidList);
565433d6423SLionel Sambuc }
566433d6423SLionel Sambuc return (Status);
567433d6423SLionel Sambuc }
568433d6423SLionel Sambuc
ACPI_EXPORT_SYMBOL(AcpiGetObjectInfo)569433d6423SLionel Sambuc ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
570433d6423SLionel Sambuc
571433d6423SLionel Sambuc
572433d6423SLionel Sambuc /******************************************************************************
573433d6423SLionel Sambuc *
574433d6423SLionel Sambuc * FUNCTION: AcpiInstallMethod
575433d6423SLionel Sambuc *
576433d6423SLionel Sambuc * PARAMETERS: Buffer - An ACPI table containing one control method
577433d6423SLionel Sambuc *
578433d6423SLionel Sambuc * RETURN: Status
579433d6423SLionel Sambuc *
580433d6423SLionel Sambuc * DESCRIPTION: Install a control method into the namespace. If the method
581433d6423SLionel Sambuc * name already exists in the namespace, it is overwritten. The
582433d6423SLionel Sambuc * input buffer must contain a valid DSDT or SSDT containing a
583433d6423SLionel Sambuc * single control method.
584433d6423SLionel Sambuc *
585433d6423SLionel Sambuc ******************************************************************************/
586433d6423SLionel Sambuc
587433d6423SLionel Sambuc ACPI_STATUS
588433d6423SLionel Sambuc AcpiInstallMethod (
589433d6423SLionel Sambuc UINT8 *Buffer)
590433d6423SLionel Sambuc {
591433d6423SLionel Sambuc ACPI_TABLE_HEADER *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);
592433d6423SLionel Sambuc UINT8 *AmlBuffer;
593433d6423SLionel Sambuc UINT8 *AmlStart;
594433d6423SLionel Sambuc char *Path;
595433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node;
596433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *MethodObj;
597433d6423SLionel Sambuc ACPI_PARSE_STATE ParserState;
598433d6423SLionel Sambuc UINT32 AmlLength;
599433d6423SLionel Sambuc UINT16 Opcode;
600433d6423SLionel Sambuc UINT8 MethodFlags;
601433d6423SLionel Sambuc ACPI_STATUS Status;
602433d6423SLionel Sambuc
603433d6423SLionel Sambuc
604433d6423SLionel Sambuc /* Parameter validation */
605433d6423SLionel Sambuc
606433d6423SLionel Sambuc if (!Buffer)
607433d6423SLionel Sambuc {
608433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
609433d6423SLionel Sambuc }
610433d6423SLionel Sambuc
611433d6423SLionel Sambuc /* Table must be a DSDT or SSDT */
612433d6423SLionel Sambuc
613433d6423SLionel Sambuc if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) &&
614433d6423SLionel Sambuc !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
615433d6423SLionel Sambuc {
616433d6423SLionel Sambuc return (AE_BAD_HEADER);
617433d6423SLionel Sambuc }
618433d6423SLionel Sambuc
619433d6423SLionel Sambuc /* First AML opcode in the table must be a control method */
620433d6423SLionel Sambuc
621433d6423SLionel Sambuc ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);
622433d6423SLionel Sambuc Opcode = AcpiPsPeekOpcode (&ParserState);
623433d6423SLionel Sambuc if (Opcode != AML_METHOD_OP)
624433d6423SLionel Sambuc {
625433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
626433d6423SLionel Sambuc }
627433d6423SLionel Sambuc
628433d6423SLionel Sambuc /* Extract method information from the raw AML */
629433d6423SLionel Sambuc
630433d6423SLionel Sambuc ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);
631433d6423SLionel Sambuc ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);
632433d6423SLionel Sambuc Path = AcpiPsGetNextNamestring (&ParserState);
633433d6423SLionel Sambuc MethodFlags = *ParserState.Aml++;
634433d6423SLionel Sambuc AmlStart = ParserState.Aml;
635433d6423SLionel Sambuc AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);
636433d6423SLionel Sambuc
637433d6423SLionel Sambuc /*
638433d6423SLionel Sambuc * Allocate resources up-front. We don't want to have to delete a new
639433d6423SLionel Sambuc * node from the namespace if we cannot allocate memory.
640433d6423SLionel Sambuc */
641433d6423SLionel Sambuc AmlBuffer = ACPI_ALLOCATE (AmlLength);
642433d6423SLionel Sambuc if (!AmlBuffer)
643433d6423SLionel Sambuc {
644433d6423SLionel Sambuc return (AE_NO_MEMORY);
645433d6423SLionel Sambuc }
646433d6423SLionel Sambuc
647433d6423SLionel Sambuc MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
648433d6423SLionel Sambuc if (!MethodObj)
649433d6423SLionel Sambuc {
650433d6423SLionel Sambuc ACPI_FREE (AmlBuffer);
651433d6423SLionel Sambuc return (AE_NO_MEMORY);
652433d6423SLionel Sambuc }
653433d6423SLionel Sambuc
654433d6423SLionel Sambuc /* Lock namespace for AcpiNsLookup, we may be creating a new node */
655433d6423SLionel Sambuc
656433d6423SLionel Sambuc Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
657433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
658433d6423SLionel Sambuc {
659433d6423SLionel Sambuc goto ErrorExit;
660433d6423SLionel Sambuc }
661433d6423SLionel Sambuc
662433d6423SLionel Sambuc /* The lookup either returns an existing node or creates a new one */
663433d6423SLionel Sambuc
664433d6423SLionel Sambuc Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
665433d6423SLionel Sambuc ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
666433d6423SLionel Sambuc
667433d6423SLionel Sambuc (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
668433d6423SLionel Sambuc
669433d6423SLionel Sambuc if (ACPI_FAILURE (Status)) /* NsLookup */
670433d6423SLionel Sambuc {
671433d6423SLionel Sambuc if (Status != AE_ALREADY_EXISTS)
672433d6423SLionel Sambuc {
673433d6423SLionel Sambuc goto ErrorExit;
674433d6423SLionel Sambuc }
675433d6423SLionel Sambuc
676433d6423SLionel Sambuc /* Node existed previously, make sure it is a method node */
677433d6423SLionel Sambuc
678433d6423SLionel Sambuc if (Node->Type != ACPI_TYPE_METHOD)
679433d6423SLionel Sambuc {
680433d6423SLionel Sambuc Status = AE_TYPE;
681433d6423SLionel Sambuc goto ErrorExit;
682433d6423SLionel Sambuc }
683433d6423SLionel Sambuc }
684433d6423SLionel Sambuc
685433d6423SLionel Sambuc /* Copy the method AML to the local buffer */
686433d6423SLionel Sambuc
687433d6423SLionel Sambuc ACPI_MEMCPY (AmlBuffer, AmlStart, AmlLength);
688433d6423SLionel Sambuc
689433d6423SLionel Sambuc /* Initialize the method object with the new method's information */
690433d6423SLionel Sambuc
691433d6423SLionel Sambuc MethodObj->Method.AmlStart = AmlBuffer;
692433d6423SLionel Sambuc MethodObj->Method.AmlLength = AmlLength;
693433d6423SLionel Sambuc
694433d6423SLionel Sambuc MethodObj->Method.ParamCount = (UINT8)
695433d6423SLionel Sambuc (MethodFlags & AML_METHOD_ARG_COUNT);
696433d6423SLionel Sambuc
697433d6423SLionel Sambuc if (MethodFlags & AML_METHOD_SERIALIZED)
698433d6423SLionel Sambuc {
699*29492bb7SDavid van Moolenbroek MethodObj->Method.InfoFlags = ACPI_METHOD_SERIALIZED;
700*29492bb7SDavid van Moolenbroek
701433d6423SLionel Sambuc MethodObj->Method.SyncLevel = (UINT8)
702433d6423SLionel Sambuc ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
703433d6423SLionel Sambuc }
704433d6423SLionel Sambuc
705433d6423SLionel Sambuc /*
706433d6423SLionel Sambuc * Now that it is complete, we can attach the new method object to
707433d6423SLionel Sambuc * the method Node (detaches/deletes any existing object)
708433d6423SLionel Sambuc */
709*29492bb7SDavid van Moolenbroek Status = AcpiNsAttachObject (Node, MethodObj, ACPI_TYPE_METHOD);
710433d6423SLionel Sambuc
711433d6423SLionel Sambuc /*
712433d6423SLionel Sambuc * Flag indicates AML buffer is dynamic, must be deleted later.
713433d6423SLionel Sambuc * Must be set only after attach above.
714433d6423SLionel Sambuc */
715433d6423SLionel Sambuc Node->Flags |= ANOBJ_ALLOCATED_BUFFER;
716433d6423SLionel Sambuc
717433d6423SLionel Sambuc /* Remove local reference to the method object */
718433d6423SLionel Sambuc
719433d6423SLionel Sambuc AcpiUtRemoveReference (MethodObj);
720433d6423SLionel Sambuc return (Status);
721433d6423SLionel Sambuc
722433d6423SLionel Sambuc
723433d6423SLionel Sambuc ErrorExit:
724433d6423SLionel Sambuc
725433d6423SLionel Sambuc ACPI_FREE (AmlBuffer);
726433d6423SLionel Sambuc ACPI_FREE (MethodObj);
727433d6423SLionel Sambuc return (Status);
728433d6423SLionel Sambuc }
729433d6423SLionel Sambuc
730433d6423SLionel Sambuc ACPI_EXPORT_SYMBOL (AcpiInstallMethod)
731