[ACPICA]
[reactos.git] / reactos / drivers / bus / acpi / acpica / namespace / nsxfname.c
1 /******************************************************************************
2 *
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
5 *
6 *****************************************************************************/
7
8 /******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117 #define EXPORT_ACPI_INTERFACES
118
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "acnamesp.h"
122 #include "acparser.h"
123 #include "amlcode.h"
124
125
126 #define _COMPONENT ACPI_NAMESPACE
127 ACPI_MODULE_NAME ("nsxfname")
128
129 /* Local prototypes */
130
131 static char *
132 AcpiNsCopyDeviceId (
133 ACPI_PNP_DEVICE_ID *Dest,
134 ACPI_PNP_DEVICE_ID *Source,
135 char *StringArea);
136
137
138 /******************************************************************************
139 *
140 * FUNCTION: AcpiGetHandle
141 *
142 * PARAMETERS: Parent - Object to search under (search scope).
143 * Pathname - Pointer to an asciiz string containing the
144 * name
145 * RetHandle - Where the return handle is returned
146 *
147 * RETURN: Status
148 *
149 * DESCRIPTION: This routine will search for a caller specified name in the
150 * name space. The caller can restrict the search region by
151 * specifying a non NULL parent. The parent value is itself a
152 * namespace handle.
153 *
154 ******************************************************************************/
155
156 ACPI_STATUS
157 AcpiGetHandle (
158 ACPI_HANDLE Parent,
159 ACPI_STRING Pathname,
160 ACPI_HANDLE *RetHandle)
161 {
162 ACPI_STATUS Status;
163 ACPI_NAMESPACE_NODE *Node = NULL;
164 ACPI_NAMESPACE_NODE *PrefixNode = NULL;
165
166
167 ACPI_FUNCTION_ENTRY ();
168
169
170 /* Parameter Validation */
171
172 if (!RetHandle || !Pathname)
173 {
174 return (AE_BAD_PARAMETER);
175 }
176
177 /* Convert a parent handle to a prefix node */
178
179 if (Parent)
180 {
181 PrefixNode = AcpiNsValidateHandle (Parent);
182 if (!PrefixNode)
183 {
184 return (AE_BAD_PARAMETER);
185 }
186 }
187
188 /*
189 * Valid cases are:
190 * 1) Fully qualified pathname
191 * 2) Parent + Relative pathname
192 *
193 * Error for <null Parent + relative path>
194 */
195 if (ACPI_IS_ROOT_PREFIX (Pathname[0]))
196 {
197 /* Pathname is fully qualified (starts with '\') */
198
199 /* Special case for root-only, since we can't search for it */
200
201 if (!strcmp (Pathname, ACPI_NS_ROOT_PATH))
202 {
203 *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode);
204 return (AE_OK);
205 }
206 }
207 else if (!PrefixNode)
208 {
209 /* Relative path with null prefix is disallowed */
210
211 return (AE_BAD_PARAMETER);
212 }
213
214 /* Find the Node and convert to a handle */
215
216 Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node);
217 if (ACPI_SUCCESS (Status))
218 {
219 *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
220 }
221
222 return (Status);
223 }
224
225 ACPI_EXPORT_SYMBOL (AcpiGetHandle)
226
227
228 /******************************************************************************
229 *
230 * FUNCTION: AcpiGetName
231 *
232 * PARAMETERS: Handle - Handle to be converted to a pathname
233 * NameType - Full pathname or single segment
234 * Buffer - Buffer for returned path
235 *
236 * RETURN: Pointer to a string containing the fully qualified Name.
237 *
238 * DESCRIPTION: This routine returns the fully qualified name associated with
239 * the Handle parameter. This and the AcpiPathnameToHandle are
240 * complementary functions.
241 *
242 ******************************************************************************/
243
244 ACPI_STATUS
245 AcpiGetName (
246 ACPI_HANDLE Handle,
247 UINT32 NameType,
248 ACPI_BUFFER *Buffer)
249 {
250 ACPI_STATUS Status;
251 ACPI_NAMESPACE_NODE *Node;
252 const char *NodeName;
253
254
255 /* Parameter validation */
256
257 if (NameType > ACPI_NAME_TYPE_MAX)
258 {
259 return (AE_BAD_PARAMETER);
260 }
261
262 Status = AcpiUtValidateBuffer (Buffer);
263 if (ACPI_FAILURE (Status))
264 {
265 return (Status);
266 }
267
268 if (NameType == ACPI_FULL_PATHNAME ||
269 NameType == ACPI_FULL_PATHNAME_NO_TRAILING)
270 {
271 /* Get the full pathname (From the namespace root) */
272
273 Status = AcpiNsHandleToPathname (Handle, Buffer,
274 NameType == ACPI_FULL_PATHNAME ? FALSE : TRUE);
275 return (Status);
276 }
277
278 /*
279 * Wants the single segment ACPI name.
280 * Validate handle and convert to a namespace Node
281 */
282 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
283 if (ACPI_FAILURE (Status))
284 {
285 return (Status);
286 }
287
288 Node = AcpiNsValidateHandle (Handle);
289 if (!Node)
290 {
291 Status = AE_BAD_PARAMETER;
292 goto UnlockAndExit;
293 }
294
295 /* Validate/Allocate/Clear caller buffer */
296
297 Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
298 if (ACPI_FAILURE (Status))
299 {
300 goto UnlockAndExit;
301 }
302
303 /* Just copy the ACPI name from the Node and zero terminate it */
304
305 NodeName = AcpiUtGetNodeName (Node);
306 ACPI_MOVE_NAME (Buffer->Pointer, NodeName);
307 ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
308 Status = AE_OK;
309
310
311 UnlockAndExit:
312
313 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
314 return (Status);
315 }
316
317 ACPI_EXPORT_SYMBOL (AcpiGetName)
318
319
320 /******************************************************************************
321 *
322 * FUNCTION: AcpiNsCopyDeviceId
323 *
324 * PARAMETERS: Dest - Pointer to the destination PNP_DEVICE_ID
325 * Source - Pointer to the source PNP_DEVICE_ID
326 * StringArea - Pointer to where to copy the dest string
327 *
328 * RETURN: Pointer to the next string area
329 *
330 * DESCRIPTION: Copy a single PNP_DEVICE_ID, including the string data.
331 *
332 ******************************************************************************/
333
334 static char *
335 AcpiNsCopyDeviceId (
336 ACPI_PNP_DEVICE_ID *Dest,
337 ACPI_PNP_DEVICE_ID *Source,
338 char *StringArea)
339 {
340 /* Create the destination PNP_DEVICE_ID */
341
342 Dest->String = StringArea;
343 Dest->Length = Source->Length;
344
345 /* Copy actual string and return a pointer to the next string area */
346
347 memcpy (StringArea, Source->String, Source->Length);
348 return (StringArea + Source->Length);
349 }
350
351
352 /******************************************************************************
353 *
354 * FUNCTION: AcpiGetObjectInfo
355 *
356 * PARAMETERS: Handle - Object Handle
357 * ReturnBuffer - Where the info is returned
358 *
359 * RETURN: Status
360 *
361 * DESCRIPTION: Returns information about an object as gleaned from the
362 * namespace node and possibly by running several standard
363 * control methods (Such as in the case of a device.)
364 *
365 * For Device and Processor objects, run the Device _HID, _UID, _CID, _STA,
366 * _CLS, _ADR, _SxW, and _SxD methods.
367 *
368 * Note: Allocates the return buffer, must be freed by the caller.
369 *
370 * Note: This interface is intended to be used during the initial device
371 * discovery namespace traversal. Therefore, no complex methods can be
372 * executed, especially those that access operation regions. Therefore, do
373 * not add any additional methods that could cause problems in this area.
374 * this was the fate of the _SUB method which was found to cause such
375 * problems and was removed (11/2015).
376 *
377 ******************************************************************************/
378
379 ACPI_STATUS
380 AcpiGetObjectInfo (
381 ACPI_HANDLE Handle,
382 ACPI_DEVICE_INFO **ReturnBuffer)
383 {
384 ACPI_NAMESPACE_NODE *Node;
385 ACPI_DEVICE_INFO *Info;
386 ACPI_PNP_DEVICE_ID_LIST *CidList = NULL;
387 ACPI_PNP_DEVICE_ID *Hid = NULL;
388 ACPI_PNP_DEVICE_ID *Uid = NULL;
389 ACPI_PNP_DEVICE_ID *Cls = NULL;
390 char *NextIdString;
391 ACPI_OBJECT_TYPE Type;
392 ACPI_NAME Name;
393 UINT8 ParamCount= 0;
394 UINT16 Valid = 0;
395 UINT32 InfoSize;
396 UINT32 i;
397 ACPI_STATUS Status;
398
399
400 /* Parameter validation */
401
402 if (!Handle || !ReturnBuffer)
403 {
404 return (AE_BAD_PARAMETER);
405 }
406
407 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
408 if (ACPI_FAILURE (Status))
409 {
410 return (Status);
411 }
412
413 Node = AcpiNsValidateHandle (Handle);
414 if (!Node)
415 {
416 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
417 return (AE_BAD_PARAMETER);
418 }
419
420 /* Get the namespace node data while the namespace is locked */
421
422 InfoSize = sizeof (ACPI_DEVICE_INFO);
423 Type = Node->Type;
424 Name = Node->Name.Integer;
425
426 if (Node->Type == ACPI_TYPE_METHOD)
427 {
428 ParamCount = Node->Object->Method.ParamCount;
429 }
430
431 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
432 if (ACPI_FAILURE (Status))
433 {
434 return (Status);
435 }
436
437 if ((Type == ACPI_TYPE_DEVICE) ||
438 (Type == ACPI_TYPE_PROCESSOR))
439 {
440 /*
441 * Get extra info for ACPI Device/Processor objects only:
442 * Run the Device _HID, _UID, _CLS, and _CID methods.
443 *
444 * Note: none of these methods are required, so they may or may
445 * not be present for this device. The Info->Valid bitfield is used
446 * to indicate which methods were found and run successfully.
447 */
448
449 /* Execute the Device._HID method */
450
451 Status = AcpiUtExecute_HID (Node, &Hid);
452 if (ACPI_SUCCESS (Status))
453 {
454 InfoSize += Hid->Length;
455 Valid |= ACPI_VALID_HID;
456 }
457
458 /* Execute the Device._UID method */
459
460 Status = AcpiUtExecute_UID (Node, &Uid);
461 if (ACPI_SUCCESS (Status))
462 {
463 InfoSize += Uid->Length;
464 Valid |= ACPI_VALID_UID;
465 }
466
467 /* Execute the Device._CID method */
468
469 Status = AcpiUtExecute_CID (Node, &CidList);
470 if (ACPI_SUCCESS (Status))
471 {
472 /* Add size of CID strings and CID pointer array */
473
474 InfoSize += (CidList->ListSize - sizeof (ACPI_PNP_DEVICE_ID_LIST));
475 Valid |= ACPI_VALID_CID;
476 }
477
478 /* Execute the Device._CLS method */
479
480 Status = AcpiUtExecute_CLS (Node, &Cls);
481 if (ACPI_SUCCESS (Status))
482 {
483 InfoSize += Cls->Length;
484 Valid |= ACPI_VALID_CLS;
485 }
486 }
487
488 /*
489 * Now that we have the variable-length data, we can allocate the
490 * return buffer
491 */
492 Info = ACPI_ALLOCATE_ZEROED (InfoSize);
493 if (!Info)
494 {
495 Status = AE_NO_MEMORY;
496 goto Cleanup;
497 }
498
499 /* Get the fixed-length data */
500
501 if ((Type == ACPI_TYPE_DEVICE) ||
502 (Type == ACPI_TYPE_PROCESSOR))
503 {
504 /*
505 * Get extra info for ACPI Device/Processor objects only:
506 * Run the _STA, _ADR and, SxW, and _SxD methods.
507 *
508 * Notes: none of these methods are required, so they may or may
509 * not be present for this device. The Info->Valid bitfield is used
510 * to indicate which methods were found and run successfully.
511 *
512 * For _STA, if the method does not exist, then (as per the ACPI
513 * specification), the returned CurrentStatus flags will indicate
514 * that the device is present/functional/enabled. Otherwise, the
515 * CurrentStatus flags reflect the value returned from _STA.
516 */
517
518 /* Execute the Device._STA method */
519
520 Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
521 if (ACPI_SUCCESS (Status))
522 {
523 Valid |= ACPI_VALID_STA;
524 }
525
526 /* Execute the Device._ADR method */
527
528 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
529 &Info->Address);
530 if (ACPI_SUCCESS (Status))
531 {
532 Valid |= ACPI_VALID_ADR;
533 }
534
535 /* Execute the Device._SxW methods */
536
537 Status = AcpiUtExecutePowerMethods (Node,
538 AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS,
539 Info->LowestDstates);
540 if (ACPI_SUCCESS (Status))
541 {
542 Valid |= ACPI_VALID_SXWS;
543 }
544
545 /* Execute the Device._SxD methods */
546
547 Status = AcpiUtExecutePowerMethods (Node,
548 AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS,
549 Info->HighestDstates);
550 if (ACPI_SUCCESS (Status))
551 {
552 Valid |= ACPI_VALID_SXDS;
553 }
554 }
555
556 /*
557 * Create a pointer to the string area of the return buffer.
558 * Point to the end of the base ACPI_DEVICE_INFO structure.
559 */
560 NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids);
561 if (CidList)
562 {
563 /* Point past the CID PNP_DEVICE_ID array */
564
565 NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_PNP_DEVICE_ID));
566 }
567
568 /*
569 * Copy the HID, UID, and CIDs to the return buffer. The variable-length
570 * strings are copied to the reserved area at the end of the buffer.
571 *
572 * For HID and CID, check if the ID is a PCI Root Bridge.
573 */
574 if (Hid)
575 {
576 NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId,
577 Hid, NextIdString);
578
579 if (AcpiUtIsPciRootBridge (Hid->String))
580 {
581 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
582 }
583 }
584
585 if (Uid)
586 {
587 NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId,
588 Uid, NextIdString);
589 }
590
591 if (CidList)
592 {
593 Info->CompatibleIdList.Count = CidList->Count;
594 Info->CompatibleIdList.ListSize = CidList->ListSize;
595
596 /* Copy each CID */
597
598 for (i = 0; i < CidList->Count; i++)
599 {
600 NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i],
601 &CidList->Ids[i], NextIdString);
602
603 if (AcpiUtIsPciRootBridge (CidList->Ids[i].String))
604 {
605 Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
606 }
607 }
608 }
609
610 if (Cls)
611 {
612 NextIdString = AcpiNsCopyDeviceId (&Info->ClassCode,
613 Cls, NextIdString);
614 }
615
616 /* Copy the fixed-length data */
617
618 Info->InfoSize = InfoSize;
619 Info->Type = Type;
620 Info->Name = Name;
621 Info->ParamCount = ParamCount;
622 Info->Valid = Valid;
623
624 *ReturnBuffer = Info;
625 Status = AE_OK;
626
627
628 Cleanup:
629 if (Hid)
630 {
631 ACPI_FREE (Hid);
632 }
633 if (Uid)
634 {
635 ACPI_FREE (Uid);
636 }
637 if (CidList)
638 {
639 ACPI_FREE (CidList);
640 }
641 if (Cls)
642 {
643 ACPI_FREE (Cls);
644 }
645 return (Status);
646 }
647
648 ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
649
650
651 /******************************************************************************
652 *
653 * FUNCTION: AcpiInstallMethod
654 *
655 * PARAMETERS: Buffer - An ACPI table containing one control method
656 *
657 * RETURN: Status
658 *
659 * DESCRIPTION: Install a control method into the namespace. If the method
660 * name already exists in the namespace, it is overwritten. The
661 * input buffer must contain a valid DSDT or SSDT containing a
662 * single control method.
663 *
664 ******************************************************************************/
665
666 ACPI_STATUS
667 AcpiInstallMethod (
668 UINT8 *Buffer)
669 {
670 ACPI_TABLE_HEADER *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);
671 UINT8 *AmlBuffer;
672 UINT8 *AmlStart;
673 char *Path;
674 ACPI_NAMESPACE_NODE *Node;
675 ACPI_OPERAND_OBJECT *MethodObj;
676 ACPI_PARSE_STATE ParserState;
677 UINT32 AmlLength;
678 UINT16 Opcode;
679 UINT8 MethodFlags;
680 ACPI_STATUS Status;
681
682
683 /* Parameter validation */
684
685 if (!Buffer)
686 {
687 return (AE_BAD_PARAMETER);
688 }
689
690 /* Table must be a DSDT or SSDT */
691
692 if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) &&
693 !ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
694 {
695 return (AE_BAD_HEADER);
696 }
697
698 /* First AML opcode in the table must be a control method */
699
700 ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);
701 Opcode = AcpiPsPeekOpcode (&ParserState);
702 if (Opcode != AML_METHOD_OP)
703 {
704 return (AE_BAD_PARAMETER);
705 }
706
707 /* Extract method information from the raw AML */
708
709 ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);
710 ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);
711 Path = AcpiPsGetNextNamestring (&ParserState);
712
713 MethodFlags = *ParserState.Aml++;
714 AmlStart = ParserState.Aml;
715 AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);
716
717 /*
718 * Allocate resources up-front. We don't want to have to delete a new
719 * node from the namespace if we cannot allocate memory.
720 */
721 AmlBuffer = ACPI_ALLOCATE (AmlLength);
722 if (!AmlBuffer)
723 {
724 return (AE_NO_MEMORY);
725 }
726
727 MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
728 if (!MethodObj)
729 {
730 ACPI_FREE (AmlBuffer);
731 return (AE_NO_MEMORY);
732 }
733
734 /* Lock namespace for AcpiNsLookup, we may be creating a new node */
735
736 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
737 if (ACPI_FAILURE (Status))
738 {
739 goto ErrorExit;
740 }
741
742 /* The lookup either returns an existing node or creates a new one */
743
744 Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
745 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
746
747 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
748
749 if (ACPI_FAILURE (Status)) /* NsLookup */
750 {
751 if (Status != AE_ALREADY_EXISTS)
752 {
753 goto ErrorExit;
754 }
755
756 /* Node existed previously, make sure it is a method node */
757
758 if (Node->Type != ACPI_TYPE_METHOD)
759 {
760 Status = AE_TYPE;
761 goto ErrorExit;
762 }
763 }
764
765 /* Copy the method AML to the local buffer */
766
767 memcpy (AmlBuffer, AmlStart, AmlLength);
768
769 /* Initialize the method object with the new method's information */
770
771 MethodObj->Method.AmlStart = AmlBuffer;
772 MethodObj->Method.AmlLength = AmlLength;
773
774 MethodObj->Method.ParamCount = (UINT8)
775 (MethodFlags & AML_METHOD_ARG_COUNT);
776
777 if (MethodFlags & AML_METHOD_SERIALIZED)
778 {
779 MethodObj->Method.InfoFlags = ACPI_METHOD_SERIALIZED;
780
781 MethodObj->Method.SyncLevel = (UINT8)
782 ((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
783 }
784
785 /*
786 * Now that it is complete, we can attach the new method object to
787 * the method Node (detaches/deletes any existing object)
788 */
789 Status = AcpiNsAttachObject (Node, MethodObj, ACPI_TYPE_METHOD);
790
791 /*
792 * Flag indicates AML buffer is dynamic, must be deleted later.
793 * Must be set only after attach above.
794 */
795 Node->Flags |= ANOBJ_ALLOCATED_BUFFER;
796
797 /* Remove local reference to the method object */
798
799 AcpiUtRemoveReference (MethodObj);
800 return (Status);
801
802
803 ErrorExit:
804
805 ACPI_FREE (AmlBuffer);
806 ACPI_FREE (MethodObj);
807 return (Status);
808 }
809
810 ACPI_EXPORT_SYMBOL (AcpiInstallMethod)