1 /******************************************************************************
2 *
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45 #define __NSXFNAME_C__
46
47 #include "acpi.h"
48 #include "accommon.h"
49 #include "acnamesp.h"
50 #include "acparser.h"
51 #include "amlcode.h"
52
53
54 #define _COMPONENT ACPI_NAMESPACE
55 ACPI_MODULE_NAME ("nsxfname")
56
57 /* Local prototypes */
58
59 static char *
60 AcpiNsCopyDeviceId (
61 ACPI_DEVICE_ID *Dest,
62 ACPI_DEVICE_ID *Source,
63 char *StringArea);
64
65
66 /******************************************************************************
67 *
68 * FUNCTION: AcpiGetHandle
69 *
70 * PARAMETERS: Parent - Object to search under (search scope).
71 * Pathname - Pointer to an asciiz string containing the
72 * name
73 * RetHandle - Where the return handle is returned
74 *
75 * RETURN: Status
76 *
77 * DESCRIPTION: This routine will search for a caller specified name in the
78 * name space. The caller can restrict the search region by
79 * specifying a non NULL parent. The parent value is itself a
80 * namespace handle.
81 *
82 ******************************************************************************/
103 }
104
105 /* Convert a parent handle to a prefix node */
106
107 if (Parent)
108 {
109 PrefixNode = AcpiNsValidateHandle (Parent);
110 if (!PrefixNode)
111 {
112 return (AE_BAD_PARAMETER);
113 }
114 }
115
116 /*
117 * Valid cases are:
118 * 1) Fully qualified pathname
119 * 2) Parent + Relative pathname
120 *
121 * Error for <null Parent + relative path>
122 */
123 if (AcpiNsValidRootPrefix (Pathname[0]))
124 {
125 /* Pathname is fully qualified (starts with '\') */
126
127 /* Special case for root-only, since we can't search for it */
128
129 if (!ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH))
130 {
131 *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode);
132 return (AE_OK);
133 }
134 }
135 else if (!PrefixNode)
136 {
137 /* Relative path with null prefix is disallowed */
138
139 return (AE_BAD_PARAMETER);
140 }
141
142 /* Find the Node and convert to a handle */
143
160 * PARAMETERS: Handle - Handle to be converted to a pathname
161 * NameType - Full pathname or single segment
162 * Buffer - Buffer for returned path
163 *
164 * RETURN: Pointer to a string containing the fully qualified Name.
165 *
166 * DESCRIPTION: This routine returns the fully qualified name associated with
167 * the Handle parameter. This and the AcpiPathnameToHandle are
168 * complementary functions.
169 *
170 ******************************************************************************/
171
172 ACPI_STATUS
173 AcpiGetName (
174 ACPI_HANDLE Handle,
175 UINT32 NameType,
176 ACPI_BUFFER *Buffer)
177 {
178 ACPI_STATUS Status;
179 ACPI_NAMESPACE_NODE *Node;
180
181
182 /* Parameter validation */
183
184 if (NameType > ACPI_NAME_TYPE_MAX)
185 {
186 return (AE_BAD_PARAMETER);
187 }
188
189 Status = AcpiUtValidateBuffer (Buffer);
190 if (ACPI_FAILURE (Status))
191 {
192 return (Status);
193 }
194
195 if (NameType == ACPI_FULL_PATHNAME)
196 {
197 /* Get the full pathname (From the namespace root) */
198
199 Status = AcpiNsHandleToPathname (Handle, Buffer);
210 return (Status);
211 }
212
213 Node = AcpiNsValidateHandle (Handle);
214 if (!Node)
215 {
216 Status = AE_BAD_PARAMETER;
217 goto UnlockAndExit;
218 }
219
220 /* Validate/Allocate/Clear caller buffer */
221
222 Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
223 if (ACPI_FAILURE (Status))
224 {
225 goto UnlockAndExit;
226 }
227
228 /* Just copy the ACPI name from the Node and zero terminate it */
229
230 ACPI_STRNCPY (Buffer->Pointer, AcpiUtGetNodeName (Node),
231 ACPI_NAME_SIZE);
232 ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
233 Status = AE_OK;
234
235
236 UnlockAndExit:
237
238 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
239 return (Status);
240 }
241
242 ACPI_EXPORT_SYMBOL (AcpiGetName)
243
244
245 /******************************************************************************
246 *
247 * FUNCTION: AcpiNsCopyDeviceId
248 *
249 * PARAMETERS: Dest - Pointer to the destination DEVICE_ID
250 * Source - Pointer to the source DEVICE_ID
251 * StringArea - Pointer to where to copy the dest string
252 *
253 * RETURN: Pointer to the next string area
254 *
255 * DESCRIPTION: Copy a single DEVICE_ID, including the string data.
256 *
257 ******************************************************************************/
258
259 static char *
260 AcpiNsCopyDeviceId (
261 ACPI_DEVICE_ID *Dest,
262 ACPI_DEVICE_ID *Source,
263 char *StringArea)
264 {
265 /* Create the destination DEVICE_ID */
266
267 Dest->String = StringArea;
268 Dest->Length = Source->Length;
269
270 /* Copy actual string and return a pointer to the next string area */
271
272 ACPI_MEMCPY (StringArea, Source->String, Source->Length);
273 return (StringArea + Source->Length);
274 }
275
276
277 /******************************************************************************
278 *
279 * FUNCTION: AcpiGetObjectInfo
280 *
281 * PARAMETERS: Handle - Object Handle
282 * ReturnBuffer - Where the info is returned
283 *
284 * RETURN: Status
285 *
286 * DESCRIPTION: Returns information about an object as gleaned from the
287 * namespace node and possibly by running several standard
288 * control methods (Such as in the case of a device.)
289 *
290 * For Device and Processor objects, run the Device _HID, _UID, _CID, _STA,
291 * _ADR, _SxW, and _SxD methods.
292 *
293 * Note: Allocates the return buffer, must be freed by the caller.
294 *
295 ******************************************************************************/
296
297 ACPI_STATUS
298 AcpiGetObjectInfo (
299 ACPI_HANDLE Handle,
300 ACPI_DEVICE_INFO **ReturnBuffer)
301 {
302 ACPI_NAMESPACE_NODE *Node;
303 ACPI_DEVICE_INFO *Info;
304 ACPI_DEVICE_ID_LIST *CidList = NULL;
305 ACPI_DEVICE_ID *Hid = NULL;
306 ACPI_DEVICE_ID *Uid = NULL;
307 char *NextIdString;
308 ACPI_OBJECT_TYPE Type;
309 ACPI_NAME Name;
310 UINT8 ParamCount= 0;
311 UINT8 Valid = 0;
312 UINT32 InfoSize;
313 UINT32 i;
314 ACPI_STATUS Status;
315
316
317 /* Parameter validation */
318
319 if (!Handle || !ReturnBuffer)
320 {
321 return (AE_BAD_PARAMETER);
322 }
323
324 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
325 if (ACPI_FAILURE (Status))
326 {
327 goto Cleanup;
328 }
329
330 Node = AcpiNsValidateHandle (Handle);
331 if (!Node)
332 {
333 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
334 return (AE_BAD_PARAMETER);
335 }
336
337 /* Get the namespace node data while the namespace is locked */
338
339 InfoSize = sizeof (ACPI_DEVICE_INFO);
340 Type = Node->Type;
341 Name = Node->Name.Integer;
342
343 if (Node->Type == ACPI_TYPE_METHOD)
344 {
345 ParamCount = Node->Object->Method.ParamCount;
346 }
347
348 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
349 if (ACPI_FAILURE (Status))
350 {
351 return (Status);
352 }
353
354 if ((Type == ACPI_TYPE_DEVICE) ||
355 (Type == ACPI_TYPE_PROCESSOR))
356 {
357 /*
358 * Get extra info for ACPI Device/Processor objects only:
359 * Run the Device _HID, _UID, and _CID methods.
360 *
361 * Note: none of these methods are required, so they may or may
362 * not be present for this device. The Info->Valid bitfield is used
363 * to indicate which methods were found and run successfully.
364 */
365
366 /* Execute the Device._HID method */
367
368 Status = AcpiUtExecute_HID (Node, &Hid);
369 if (ACPI_SUCCESS (Status))
370 {
371 InfoSize += Hid->Length;
372 Valid |= ACPI_VALID_HID;
373 }
374
375 /* Execute the Device._UID method */
376
377 Status = AcpiUtExecute_UID (Node, &Uid);
378 if (ACPI_SUCCESS (Status))
379 {
380 InfoSize += Uid->Length;
381 Valid |= ACPI_VALID_UID;
382 }
383
384 /* Execute the Device._CID method */
385
386 Status = AcpiUtExecute_CID (Node, &CidList);
387 if (ACPI_SUCCESS (Status))
388 {
389 /* Add size of CID strings and CID pointer array */
390
391 InfoSize += (CidList->ListSize - sizeof (ACPI_DEVICE_ID_LIST));
392 Valid |= ACPI_VALID_CID;
393 }
394 }
395
396 /*
397 * Now that we have the variable-length data, we can allocate the
398 * return buffer
399 */
400 Info = ACPI_ALLOCATE_ZEROED (InfoSize);
401 if (!Info)
402 {
403 Status = AE_NO_MEMORY;
404 goto Cleanup;
405 }
406
407 /* Get the fixed-length data */
408
409 if ((Type == ACPI_TYPE_DEVICE) ||
410 (Type == ACPI_TYPE_PROCESSOR))
411 {
412 /*
413 * Get extra info for ACPI Device/Processor objects only:
414 * Run the _STA, _ADR and, SxW, and _SxD methods.
415 *
416 * Note: none of these methods are required, so they may or may
417 * not be present for this device. The Info->Valid bitfield is used
418 * to indicate which methods were found and run successfully.
419 */
420
421 /* Execute the Device._STA method */
422
423 Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
424 if (ACPI_SUCCESS (Status))
425 {
426 Valid |= ACPI_VALID_STA;
427 }
428
429 /* Execute the Device._ADR method */
430
431 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
432 &Info->Address);
433 if (ACPI_SUCCESS (Status))
434 {
435 Valid |= ACPI_VALID_ADR;
436 }
437
438 /* Execute the Device._SxW methods */
446 }
447
448 /* Execute the Device._SxD methods */
449
450 Status = AcpiUtExecutePowerMethods (Node,
451 AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS,
452 Info->HighestDstates);
453 if (ACPI_SUCCESS (Status))
454 {
455 Valid |= ACPI_VALID_SXDS;
456 }
457 }
458
459 /*
460 * Create a pointer to the string area of the return buffer.
461 * Point to the end of the base ACPI_DEVICE_INFO structure.
462 */
463 NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids);
464 if (CidList)
465 {
466 /* Point past the CID DEVICE_ID array */
467
468 NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_DEVICE_ID));
469 }
470
471 /*
472 * Copy the HID, UID, and CIDs to the return buffer. The variable-length
473 * strings are copied to the reserved area at the end of the buffer.
474 *
475 * For HID and CID, check if the ID is a PCI Root Bridge.
476 */
477 if (Hid)
478 {
479 NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId,
480 Hid, NextIdString);
481
482 if (AcpiUtIsPciRootBridge (Hid->String))
483 {
484 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
485 }
486 }
487
488 if (Uid)
489 {
490 NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId,
491 Uid, NextIdString);
492 }
493
494 if (CidList)
495 {
496 Info->CompatibleIdList.Count = CidList->Count;
497 Info->CompatibleIdList.ListSize = CidList->ListSize;
498
499 /* Copy each CID */
500
501 for (i = 0; i < CidList->Count; i++)
502 {
503 NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i],
504 &CidList->Ids[i], NextIdString);
505
506 if (AcpiUtIsPciRootBridge (CidList->Ids[i].String))
507 {
508 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
509 }
510 }
511 }
512
513 /* Copy the fixed-length data */
514
515 Info->InfoSize = InfoSize;
516 Info->Type = Type;
517 Info->Name = Name;
518 Info->ParamCount = ParamCount;
519 Info->Valid = Valid;
520
521 *ReturnBuffer = Info;
522 Status = AE_OK;
523
524
525 Cleanup:
526 if (Hid)
527 {
528 ACPI_FREE (Hid);
529 }
530 if (Uid)
531 {
532 ACPI_FREE (Uid);
533 }
534 if (CidList)
535 {
536 ACPI_FREE (CidList);
537 }
538 return (Status);
539 }
540
541 ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
542
543
544 /******************************************************************************
545 *
546 * FUNCTION: AcpiInstallMethod
547 *
548 * PARAMETERS: Buffer - An ACPI table containing one control method
549 *
550 * RETURN: Status
551 *
552 * DESCRIPTION: Install a control method into the namespace. If the method
553 * name already exists in the namespace, it is overwritten. The
|
1 /******************************************************************************
2 *
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000 - 2013, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45 #define __NSXFNAME_C__
46 #define EXPORT_ACPI_INTERFACES
47
48 #include "acpi.h"
49 #include "accommon.h"
50 #include "acnamesp.h"
51 #include "acparser.h"
52 #include "amlcode.h"
53
54
55 #define _COMPONENT ACPI_NAMESPACE
56 ACPI_MODULE_NAME ("nsxfname")
57
58 /* Local prototypes */
59
60 static char *
61 AcpiNsCopyDeviceId (
62 ACPI_PNP_DEVICE_ID *Dest,
63 ACPI_PNP_DEVICE_ID *Source,
64 char *StringArea);
65
66
67 /******************************************************************************
68 *
69 * FUNCTION: AcpiGetHandle
70 *
71 * PARAMETERS: Parent - Object to search under (search scope).
72 * Pathname - Pointer to an asciiz string containing the
73 * name
74 * RetHandle - Where the return handle is returned
75 *
76 * RETURN: Status
77 *
78 * DESCRIPTION: This routine will search for a caller specified name in the
79 * name space. The caller can restrict the search region by
80 * specifying a non NULL parent. The parent value is itself a
81 * namespace handle.
82 *
83 ******************************************************************************/
104 }
105
106 /* Convert a parent handle to a prefix node */
107
108 if (Parent)
109 {
110 PrefixNode = AcpiNsValidateHandle (Parent);
111 if (!PrefixNode)
112 {
113 return (AE_BAD_PARAMETER);
114 }
115 }
116
117 /*
118 * Valid cases are:
119 * 1) Fully qualified pathname
120 * 2) Parent + Relative pathname
121 *
122 * Error for <null Parent + relative path>
123 */
124 if (ACPI_IS_ROOT_PREFIX (Pathname[0]))
125 {
126 /* Pathname is fully qualified (starts with '\') */
127
128 /* Special case for root-only, since we can't search for it */
129
130 if (!ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH))
131 {
132 *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode);
133 return (AE_OK);
134 }
135 }
136 else if (!PrefixNode)
137 {
138 /* Relative path with null prefix is disallowed */
139
140 return (AE_BAD_PARAMETER);
141 }
142
143 /* Find the Node and convert to a handle */
144
161 * PARAMETERS: Handle - Handle to be converted to a pathname
162 * NameType - Full pathname or single segment
163 * Buffer - Buffer for returned path
164 *
165 * RETURN: Pointer to a string containing the fully qualified Name.
166 *
167 * DESCRIPTION: This routine returns the fully qualified name associated with
168 * the Handle parameter. This and the AcpiPathnameToHandle are
169 * complementary functions.
170 *
171 ******************************************************************************/
172
173 ACPI_STATUS
174 AcpiGetName (
175 ACPI_HANDLE Handle,
176 UINT32 NameType,
177 ACPI_BUFFER *Buffer)
178 {
179 ACPI_STATUS Status;
180 ACPI_NAMESPACE_NODE *Node;
181 char *NodeName;
182
183
184 /* Parameter validation */
185
186 if (NameType > ACPI_NAME_TYPE_MAX)
187 {
188 return (AE_BAD_PARAMETER);
189 }
190
191 Status = AcpiUtValidateBuffer (Buffer);
192 if (ACPI_FAILURE (Status))
193 {
194 return (Status);
195 }
196
197 if (NameType == ACPI_FULL_PATHNAME)
198 {
199 /* Get the full pathname (From the namespace root) */
200
201 Status = AcpiNsHandleToPathname (Handle, Buffer);
212 return (Status);
213 }
214
215 Node = AcpiNsValidateHandle (Handle);
216 if (!Node)
217 {
218 Status = AE_BAD_PARAMETER;
219 goto UnlockAndExit;
220 }
221
222 /* Validate/Allocate/Clear caller buffer */
223
224 Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
225 if (ACPI_FAILURE (Status))
226 {
227 goto UnlockAndExit;
228 }
229
230 /* Just copy the ACPI name from the Node and zero terminate it */
231
232 NodeName = AcpiUtGetNodeName (Node);
233 ACPI_MOVE_NAME (Buffer->Pointer, NodeName);
234 ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
235 Status = AE_OK;
236
237
238 UnlockAndExit:
239
240 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
241 return (Status);
242 }
243
244 ACPI_EXPORT_SYMBOL (AcpiGetName)
245
246
247 /******************************************************************************
248 *
249 * FUNCTION: AcpiNsCopyDeviceId
250 *
251 * PARAMETERS: Dest - Pointer to the destination PNP_DEVICE_ID
252 * Source - Pointer to the source PNP_DEVICE_ID
253 * StringArea - Pointer to where to copy the dest string
254 *
255 * RETURN: Pointer to the next string area
256 *
257 * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
258 *
259 ******************************************************************************/
260
261 static char *
262 AcpiNsCopyDeviceId (
263 ACPI_PNP_DEVICE_ID *Dest,
264 ACPI_PNP_DEVICE_ID *Source,
265 char *StringArea)
266 {
267
268 /* Create the destination PNP_DEVICE_ID */
269
270 Dest->String = StringArea;
271 Dest->Length = Source->Length;
272
273 /* Copy actual string and return a pointer to the next string area */
274
275 ACPI_MEMCPY (StringArea, Source->String, Source->Length);
276 return (StringArea + Source->Length);
277 }
278
279
280 /******************************************************************************
281 *
282 * FUNCTION: AcpiGetObjectInfo
283 *
284 * PARAMETERS: Handle - Object Handle
285 * ReturnBuffer - Where the info is returned
286 *
287 * RETURN: Status
288 *
289 * DESCRIPTION: Returns information about an object as gleaned from the
290 * namespace node and possibly by running several standard
291 * control methods (Such as in the case of a device.)
292 *
293 * For Device and Processor objects, run the Device _HID, _UID, _CID, _SUB,
294 * _STA, _ADR, _SxW, and _SxD methods.
295 *
296 * Note: Allocates the return buffer, must be freed by the caller.
297 *
298 ******************************************************************************/
299
300 ACPI_STATUS
301 AcpiGetObjectInfo (
302 ACPI_HANDLE Handle,
303 ACPI_DEVICE_INFO **ReturnBuffer)
304 {
305 ACPI_NAMESPACE_NODE *Node;
306 ACPI_DEVICE_INFO *Info;
307 ACPI_PNP_DEVICE_ID_LIST *CidList = NULL;
308 ACPI_PNP_DEVICE_ID *Hid = NULL;
309 ACPI_PNP_DEVICE_ID *Uid = NULL;
310 ACPI_PNP_DEVICE_ID *Sub = NULL;
311 char *NextIdString;
312 ACPI_OBJECT_TYPE Type;
313 ACPI_NAME Name;
314 UINT8 ParamCount= 0;
315 UINT8 Valid = 0;
316 UINT32 InfoSize;
317 UINT32 i;
318 ACPI_STATUS Status;
319
320
321 /* Parameter validation */
322
323 if (!Handle || !ReturnBuffer)
324 {
325 return (AE_BAD_PARAMETER);
326 }
327
328 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
329 if (ACPI_FAILURE (Status))
330 {
331 return (Status);
332 }
333
334 Node = AcpiNsValidateHandle (Handle);
335 if (!Node)
336 {
337 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
338 return (AE_BAD_PARAMETER);
339 }
340
341 /* Get the namespace node data while the namespace is locked */
342
343 InfoSize = sizeof (ACPI_DEVICE_INFO);
344 Type = Node->Type;
345 Name = Node->Name.Integer;
346
347 if (Node->Type == ACPI_TYPE_METHOD)
348 {
349 ParamCount = Node->Object->Method.ParamCount;
350 }
351
352 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
353 if (ACPI_FAILURE (Status))
354 {
355 return (Status);
356 }
357
358 if ((Type == ACPI_TYPE_DEVICE) ||
359 (Type == ACPI_TYPE_PROCESSOR))
360 {
361 /*
362 * Get extra info for ACPI Device/Processor objects only:
363 * Run the Device _HID, _UID, _SUB, and _CID methods.
364 *
365 * Note: none of these methods are required, so they may or may
366 * not be present for this device. The Info->Valid bitfield is used
367 * to indicate which methods were found and run successfully.
368 */
369
370 /* Execute the Device._HID method */
371
372 Status = AcpiUtExecute_HID (Node, &Hid);
373 if (ACPI_SUCCESS (Status))
374 {
375 InfoSize += Hid->Length;
376 Valid |= ACPI_VALID_HID;
377 }
378
379 /* Execute the Device._UID method */
380
381 Status = AcpiUtExecute_UID (Node, &Uid);
382 if (ACPI_SUCCESS (Status))
383 {
384 InfoSize += Uid->Length;
385 Valid |= ACPI_VALID_UID;
386 }
387
388 /* Execute the Device._SUB method */
389
390 Status = AcpiUtExecute_SUB (Node, &Sub);
391 if (ACPI_SUCCESS (Status))
392 {
393 InfoSize += Sub->Length;
394 Valid |= ACPI_VALID_SUB;
395 }
396
397 /* Execute the Device._CID method */
398
399 Status = AcpiUtExecute_CID (Node, &CidList);
400 if (ACPI_SUCCESS (Status))
401 {
402 /* Add size of CID strings and CID pointer array */
403
404 InfoSize += (CidList->ListSize - sizeof (ACPI_PNP_DEVICE_ID_LIST));
405 Valid |= ACPI_VALID_CID;
406 }
407 }
408
409 /*
410 * Now that we have the variable-length data, we can allocate the
411 * return buffer
412 */
413 Info = ACPI_ALLOCATE_ZEROED (InfoSize);
414 if (!Info)
415 {
416 Status = AE_NO_MEMORY;
417 goto Cleanup;
418 }
419
420 /* Get the fixed-length data */
421
422 if ((Type == ACPI_TYPE_DEVICE) ||
423 (Type == ACPI_TYPE_PROCESSOR))
424 {
425 /*
426 * Get extra info for ACPI Device/Processor objects only:
427 * Run the _STA, _ADR and, SxW, and _SxD methods.
428 *
429 * Notes: none of these methods are required, so they may or may
430 * not be present for this device. The Info->Valid bitfield is used
431 * to indicate which methods were found and run successfully.
432 *
433 * For _STA, if the method does not exist, then (as per the ACPI
434 * specification), the returned CurrentStatus flags will indicate
435 * that the device is present/functional/enabled. Otherwise, the
436 * CurrentStatus flags reflect the value returned from _STA.
437 */
438
439 /* Execute the Device._STA method */
440
441 Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
442 if (ACPI_SUCCESS (Status))
443 {
444 Valid |= ACPI_VALID_STA;
445 }
446
447 /* Execute the Device._ADR method */
448
449 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
450 &Info->Address);
451 if (ACPI_SUCCESS (Status))
452 {
453 Valid |= ACPI_VALID_ADR;
454 }
455
456 /* Execute the Device._SxW methods */
464 }
465
466 /* Execute the Device._SxD methods */
467
468 Status = AcpiUtExecutePowerMethods (Node,
469 AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS,
470 Info->HighestDstates);
471 if (ACPI_SUCCESS (Status))
472 {
473 Valid |= ACPI_VALID_SXDS;
474 }
475 }
476
477 /*
478 * Create a pointer to the string area of the return buffer.
479 * Point to the end of the base ACPI_DEVICE_INFO structure.
480 */
481 NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids);
482 if (CidList)
483 {
484 /* Point past the CID PNP_DEVICE_ID array */
485
486 NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_PNP_DEVICE_ID));
487 }
488
489 /*
490 * Copy the HID, UID, SUB, and CIDs to the return buffer.
491 * The variable-length strings are copied to the reserved area
492 * at the end of the buffer.
493 *
494 * For HID and CID, check if the ID is a PCI Root Bridge.
495 */
496 if (Hid)
497 {
498 NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId,
499 Hid, NextIdString);
500
501 if (AcpiUtIsPciRootBridge (Hid->String))
502 {
503 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
504 }
505 }
506
507 if (Uid)
508 {
509 NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId,
510 Uid, NextIdString);
511 }
512
513 if (Sub)
514 {
515 NextIdString = AcpiNsCopyDeviceId (&Info->SubsystemId,
516 Sub, NextIdString);
517 }
518
519 if (CidList)
520 {
521 Info->CompatibleIdList.Count = CidList->Count;
522 Info->CompatibleIdList.ListSize = CidList->ListSize;
523
524 /* Copy each CID */
525
526 for (i = 0; i < CidList->Count; i++)
527 {
528 NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i],
529 &CidList->Ids[i], NextIdString);
530
531 if (AcpiUtIsPciRootBridge (CidList->Ids[i].String))
532 {
533 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
534 }
535 }
536 }
537
538 /* Copy the fixed-length data */
539
540 Info->InfoSize = InfoSize;
541 Info->Type = Type;
542 Info->Name = Name;
543 Info->ParamCount = ParamCount;
544 Info->Valid = Valid;
545
546 *ReturnBuffer = Info;
547 Status = AE_OK;
548
549
550 Cleanup:
551 if (Hid)
552 {
553 ACPI_FREE (Hid);
554 }
555 if (Uid)
556 {
557 ACPI_FREE (Uid);
558 }
559 if (Sub)
560 {
561 ACPI_FREE (Sub);
562 }
563 if (CidList)
564 {
565 ACPI_FREE (CidList);
566 }
567 return (Status);
568 }
569
570 ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
571
572
573 /******************************************************************************
574 *
575 * FUNCTION: AcpiInstallMethod
576 *
577 * PARAMETERS: Buffer - An ACPI table containing one control method
578 *
579 * RETURN: Status
580 *
581 * DESCRIPTION: Install a control method into the namespace. If the method
582 * name already exists in the namespace, it is overwritten. The
|