17c478bd9Sstevel@tonic-gate /*******************************************************************************
27c478bd9Sstevel@tonic-gate *
327f7c583Smyers * Module Name: nseval - Object evaluation, includes control method execution
47c478bd9Sstevel@tonic-gate *
57c478bd9Sstevel@tonic-gate ******************************************************************************/
67c478bd9Sstevel@tonic-gate
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi *
9*35786f68SRobert Mustacchi * 1. Copyright Notice
10*35786f68SRobert Mustacchi *
11*35786f68SRobert Mustacchi * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
127c478bd9Sstevel@tonic-gate * All rights reserved.
137c478bd9Sstevel@tonic-gate *
14*35786f68SRobert Mustacchi * 2. License
15*35786f68SRobert Mustacchi *
16*35786f68SRobert Mustacchi * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi * property rights.
20*35786f68SRobert Mustacchi *
21*35786f68SRobert Mustacchi * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi *
28*35786f68SRobert Mustacchi * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi *
37*35786f68SRobert Mustacchi * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi * conditions are met:
39*35786f68SRobert Mustacchi *
40*35786f68SRobert Mustacchi * 3. Conditions
41*35786f68SRobert Mustacchi *
42*35786f68SRobert Mustacchi * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi *
54*35786f68SRobert Mustacchi * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi * make.
65*35786f68SRobert Mustacchi
66*35786f68SRobert Mustacchi *
67*35786f68SRobert Mustacchi * 3.3. Redistribution of Executable. Redistribution in executable form of any
68*35786f68SRobert Mustacchi * substantial portion of the Covered Code or modification must reproduce the
69*35786f68SRobert Mustacchi * above Copyright Notice, and the following Disclaimer and Export Compliance
70*35786f68SRobert Mustacchi * provision in the documentation and/or other materials provided with the
71*35786f68SRobert Mustacchi * distribution.
72*35786f68SRobert Mustacchi *
73*35786f68SRobert Mustacchi * 3.4. Intel retains all right, title, and interest in and to the Original
74*35786f68SRobert Mustacchi * Intel Code.
75*35786f68SRobert Mustacchi *
76*35786f68SRobert Mustacchi * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77*35786f68SRobert Mustacchi * Intel shall be used in advertising or otherwise to promote the sale, use or
78*35786f68SRobert Mustacchi * other dealings in products derived from or relating to the Covered Code
79*35786f68SRobert Mustacchi * without prior written authorization from Intel.
80*35786f68SRobert Mustacchi *
81*35786f68SRobert Mustacchi * 4. Disclaimer and Export Compliance
82*35786f68SRobert Mustacchi *
83*35786f68SRobert Mustacchi * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84*35786f68SRobert Mustacchi * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85*35786f68SRobert Mustacchi * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86*35786f68SRobert Mustacchi * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87*35786f68SRobert Mustacchi * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88*35786f68SRobert Mustacchi * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89*35786f68SRobert Mustacchi * PARTICULAR PURPOSE.
90*35786f68SRobert Mustacchi *
91*35786f68SRobert Mustacchi * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92*35786f68SRobert Mustacchi * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93*35786f68SRobert Mustacchi * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94*35786f68SRobert Mustacchi * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95*35786f68SRobert Mustacchi * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96*35786f68SRobert Mustacchi * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97*35786f68SRobert Mustacchi * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98*35786f68SRobert Mustacchi * LIMITED REMEDY.
99*35786f68SRobert Mustacchi *
100*35786f68SRobert Mustacchi * 4.3. Licensee shall not export, either directly or indirectly, any of this
101*35786f68SRobert Mustacchi * software or system incorporating such software without first obtaining any
102*35786f68SRobert Mustacchi * required license or other approval from the U. S. Department of Commerce or
103*35786f68SRobert Mustacchi * any other agency or department of the United States Government. In the
104*35786f68SRobert Mustacchi * event Licensee exports any such software from the United States or
105*35786f68SRobert Mustacchi * re-exports any such software from a foreign destination, Licensee shall
106*35786f68SRobert Mustacchi * ensure that the distribution and export/re-export of the software is in
107*35786f68SRobert Mustacchi * compliance with all laws, regulations, orders, or other restrictions of the
108*35786f68SRobert Mustacchi * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109*35786f68SRobert Mustacchi * any of its subsidiaries will export/re-export any technical data, process,
110*35786f68SRobert Mustacchi * software, or service, directly or indirectly, to any country for which the
111*35786f68SRobert Mustacchi * United States government or any agency thereof requires an export license,
112*35786f68SRobert Mustacchi * other governmental approval, or letter of assurance, without first obtaining
113*35786f68SRobert Mustacchi * such license, approval or letter.
114*35786f68SRobert Mustacchi *
115*35786f68SRobert Mustacchi *****************************************************************************
116*35786f68SRobert Mustacchi *
117*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
118*35786f68SRobert Mustacchi * following license:
119*35786f68SRobert Mustacchi *
12026f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
12126f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
12226f3cdf0SGordon Ross * are met:
12326f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
12426f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
12526f3cdf0SGordon Ross * without modification.
12626f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12726f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
12826f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
12926f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
13026f3cdf0SGordon Ross * binary redistribution.
13126f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
13226f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
13326f3cdf0SGordon Ross * from this software without specific prior written permission.
13426f3cdf0SGordon Ross *
13526f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13626f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137*35786f68SRobert Mustacchi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13826f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139*35786f68SRobert Mustacchi * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140*35786f68SRobert Mustacchi * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141*35786f68SRobert Mustacchi * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142*35786f68SRobert Mustacchi * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143*35786f68SRobert Mustacchi * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144*35786f68SRobert Mustacchi * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145*35786f68SRobert Mustacchi * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146*35786f68SRobert Mustacchi *
147*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
148*35786f68SRobert Mustacchi * GNU General Public License ("GPL") version 2 as published by the Free
149*35786f68SRobert Mustacchi * Software Foundation.
150*35786f68SRobert Mustacchi *
151*35786f68SRobert Mustacchi *****************************************************************************/
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate #include "acpi.h"
154aa2aa9a6SDana Myers #include "accommon.h"
1557c478bd9Sstevel@tonic-gate #include "acparser.h"
1567c478bd9Sstevel@tonic-gate #include "acinterp.h"
1577c478bd9Sstevel@tonic-gate #include "acnamesp.h"
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate #define _COMPONENT ACPI_NAMESPACE
1617c478bd9Sstevel@tonic-gate ACPI_MODULE_NAME ("nseval")
1627c478bd9Sstevel@tonic-gate
16357190917SDana Myers /* Local prototypes */
16457190917SDana Myers
16557190917SDana Myers static void
16657190917SDana Myers AcpiNsExecModuleCode (
16757190917SDana Myers ACPI_OPERAND_OBJECT *MethodObj,
16857190917SDana Myers ACPI_EVALUATE_INFO *Info);
16957190917SDana Myers
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate /*******************************************************************************
1727c478bd9Sstevel@tonic-gate *
17327f7c583Smyers * FUNCTION: AcpiNsEvaluate
1747c478bd9Sstevel@tonic-gate *
1757b1019a6SJerry Jelinek * PARAMETERS: Info - Evaluation info block, contains these fields
1767b1019a6SJerry Jelinek * and more:
17727f7c583Smyers * PrefixNode - Prefix or Method/Object Node to execute
1787b1019a6SJerry Jelinek * RelativePath - Name of method to execute, If NULL, the
17927f7c583Smyers * Node is the object to execute
1807c478bd9Sstevel@tonic-gate * Parameters - List of parameters to pass to the method,
1817c478bd9Sstevel@tonic-gate * terminated by NULL. Params itself may be
1827c478bd9Sstevel@tonic-gate * NULL if no parameters are being passed.
1837c478bd9Sstevel@tonic-gate * ParameterType - Type of Parameter list
1847c478bd9Sstevel@tonic-gate * ReturnObject - Where to put method's return value (if
1857c478bd9Sstevel@tonic-gate * any). If NULL, no value is returned.
18627f7c583Smyers * Flags - ACPI_IGNORE_RETURN_VALUE to delete return
1877c478bd9Sstevel@tonic-gate *
1887c478bd9Sstevel@tonic-gate * RETURN: Status
1897c478bd9Sstevel@tonic-gate *
19027f7c583Smyers * DESCRIPTION: Execute a control method or return the current value of an
19127f7c583Smyers * ACPI namespace object.
1927c478bd9Sstevel@tonic-gate *
19327f7c583Smyers * MUTEX: Locks interpreter
1947c478bd9Sstevel@tonic-gate *
1957c478bd9Sstevel@tonic-gate ******************************************************************************/
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiNsEvaluate(ACPI_EVALUATE_INFO * Info)19827f7c583Smyers AcpiNsEvaluate (
19927f7c583Smyers ACPI_EVALUATE_INFO *Info)
2007c478bd9Sstevel@tonic-gate {
2017c478bd9Sstevel@tonic-gate ACPI_STATUS Status;
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate
20427f7c583Smyers ACPI_FUNCTION_TRACE (NsEvaluate);
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate if (!Info)
2087c478bd9Sstevel@tonic-gate {
2097c478bd9Sstevel@tonic-gate return_ACPI_STATUS (AE_BAD_PARAMETER);
2107c478bd9Sstevel@tonic-gate }
2117c478bd9Sstevel@tonic-gate
2127b1019a6SJerry Jelinek if (!Info->Node)
2137b1019a6SJerry Jelinek {
2147b1019a6SJerry Jelinek /*
2157b1019a6SJerry Jelinek * Get the actual namespace node for the target object if we
2167b1019a6SJerry Jelinek * need to. Handles these cases:
2177b1019a6SJerry Jelinek *
2187b1019a6SJerry Jelinek * 1) Null node, valid pathname from root (absolute path)
2197b1019a6SJerry Jelinek * 2) Node and valid pathname (path relative to Node)
2207b1019a6SJerry Jelinek * 3) Node, Null pathname
2217b1019a6SJerry Jelinek */
2227b1019a6SJerry Jelinek Status = AcpiNsGetNode (Info->PrefixNode, Info->RelativePathname,
2237b1019a6SJerry Jelinek ACPI_NS_NO_UPSEARCH, &Info->Node);
2247b1019a6SJerry Jelinek if (ACPI_FAILURE (Status))
2257b1019a6SJerry Jelinek {
2267b1019a6SJerry Jelinek return_ACPI_STATUS (Status);
2277b1019a6SJerry Jelinek }
2287b1019a6SJerry Jelinek }
2297b1019a6SJerry Jelinek
2307b1019a6SJerry Jelinek /*
2317b1019a6SJerry Jelinek * For a method alias, we must grab the actual method node so that
2327b1019a6SJerry Jelinek * proper scoping context will be established before execution.
2337b1019a6SJerry Jelinek */
2347b1019a6SJerry Jelinek if (AcpiNsGetType (Info->Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
2357b1019a6SJerry Jelinek {
2367b1019a6SJerry Jelinek Info->Node = ACPI_CAST_PTR (
2377b1019a6SJerry Jelinek ACPI_NAMESPACE_NODE, Info->Node->Object);
2387b1019a6SJerry Jelinek }
2397b1019a6SJerry Jelinek
2407b1019a6SJerry Jelinek /* Complete the info block initialization */
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate Info->ReturnObject = NULL;
2437b1019a6SJerry Jelinek Info->NodeFlags = Info->Node->Flags;
2447b1019a6SJerry Jelinek Info->ObjDesc = AcpiNsGetAttachedObject (Info->Node);
2457b1019a6SJerry Jelinek
2467b1019a6SJerry Jelinek ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
2477b1019a6SJerry Jelinek Info->RelativePathname, Info->Node,
2487b1019a6SJerry Jelinek AcpiNsGetAttachedObject (Info->Node)));
2497b1019a6SJerry Jelinek
2507b1019a6SJerry Jelinek /* Get info if we have a predefined name (_HID, etc.) */
2517b1019a6SJerry Jelinek
2527b1019a6SJerry Jelinek Info->Predefined = AcpiUtMatchPredefinedMethod (Info->Node->Name.Ascii);
2537b1019a6SJerry Jelinek
2547b1019a6SJerry Jelinek /* Get the full pathname to the object, for use in warning messages */
2557b1019a6SJerry Jelinek
2567b1019a6SJerry Jelinek Info->FullPathname = AcpiNsGetNormalizedPathname (Info->Node, TRUE);
2577b1019a6SJerry Jelinek if (!Info->FullPathname)
2587b1019a6SJerry Jelinek {
2597b1019a6SJerry Jelinek return_ACPI_STATUS (AE_NO_MEMORY);
2607b1019a6SJerry Jelinek }
2617b1019a6SJerry Jelinek
2627b1019a6SJerry Jelinek /* Count the number of arguments being passed in */
2637b1019a6SJerry Jelinek
264aa2aa9a6SDana Myers Info->ParamCount = 0;
2657b1019a6SJerry Jelinek if (Info->Parameters)
2667b1019a6SJerry Jelinek {
2677b1019a6SJerry Jelinek while (Info->Parameters[Info->ParamCount])
2687b1019a6SJerry Jelinek {
2697b1019a6SJerry Jelinek Info->ParamCount++;
2707b1019a6SJerry Jelinek }
2717b1019a6SJerry Jelinek
2727b1019a6SJerry Jelinek /* Warn on impossible argument count */
2737b1019a6SJerry Jelinek
2747b1019a6SJerry Jelinek if (Info->ParamCount > ACPI_METHOD_NUM_ARGS)
2757b1019a6SJerry Jelinek {
2767b1019a6SJerry Jelinek ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS,
2777b1019a6SJerry Jelinek "Excess arguments (%u) - using only %u",
2787b1019a6SJerry Jelinek Info->ParamCount, ACPI_METHOD_NUM_ARGS));
2797b1019a6SJerry Jelinek
2807b1019a6SJerry Jelinek Info->ParamCount = ACPI_METHOD_NUM_ARGS;
2817b1019a6SJerry Jelinek }
2827b1019a6SJerry Jelinek }
2837c478bd9Sstevel@tonic-gate
28427f7c583Smyers /*
2857b1019a6SJerry Jelinek * For predefined names: Check that the declared argument count
2867b1019a6SJerry Jelinek * matches the ACPI spec -- otherwise this is a BIOS error.
28727f7c583Smyers */
2887b1019a6SJerry Jelinek AcpiNsCheckAcpiCompliance (Info->FullPathname, Info->Node,
2897b1019a6SJerry Jelinek Info->Predefined);
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate /*
2927b1019a6SJerry Jelinek * For all names: Check that the incoming argument count for
2937b1019a6SJerry Jelinek * this method/object matches the actual ASL/AML definition.
2947c478bd9Sstevel@tonic-gate */
2957b1019a6SJerry Jelinek AcpiNsCheckArgumentCount (Info->FullPathname, Info->Node,
2967b1019a6SJerry Jelinek Info->ParamCount, Info->Predefined);
2977c478bd9Sstevel@tonic-gate
2987b1019a6SJerry Jelinek /* For predefined names: Typecheck all incoming arguments */
29927f7c583Smyers
3007b1019a6SJerry Jelinek AcpiNsCheckArgumentTypes (Info);
301aa2aa9a6SDana Myers
3027c478bd9Sstevel@tonic-gate /*
3037b1019a6SJerry Jelinek * Three major evaluation cases:
3047c478bd9Sstevel@tonic-gate *
3057b1019a6SJerry Jelinek * 1) Object types that cannot be evaluated by definition
3067b1019a6SJerry Jelinek * 2) The object is a control method -- execute it
3077b1019a6SJerry Jelinek * 3) The object is not a method -- just return it's current value
3087c478bd9Sstevel@tonic-gate */
3097b1019a6SJerry Jelinek switch (AcpiNsGetType (Info->Node))
3107c478bd9Sstevel@tonic-gate {
311*35786f68SRobert Mustacchi case ACPI_TYPE_ANY:
3127b1019a6SJerry Jelinek case ACPI_TYPE_DEVICE:
3137b1019a6SJerry Jelinek case ACPI_TYPE_EVENT:
3147b1019a6SJerry Jelinek case ACPI_TYPE_MUTEX:
3157b1019a6SJerry Jelinek case ACPI_TYPE_REGION:
3167b1019a6SJerry Jelinek case ACPI_TYPE_THERMAL:
3177b1019a6SJerry Jelinek case ACPI_TYPE_LOCAL_SCOPE:
3187c478bd9Sstevel@tonic-gate /*
319*35786f68SRobert Mustacchi * 1) Disallow evaluation of these object types. For these,
320*35786f68SRobert Mustacchi * object evaluation is undefined.
3217c478bd9Sstevel@tonic-gate */
3227b1019a6SJerry Jelinek ACPI_ERROR ((AE_INFO,
323*35786f68SRobert Mustacchi "%s: This object type [%s] "
324*35786f68SRobert Mustacchi "never contains data and cannot be evaluated",
325*35786f68SRobert Mustacchi Info->FullPathname, AcpiUtGetTypeName (Info->Node->Type)));
3267c478bd9Sstevel@tonic-gate
3277b1019a6SJerry Jelinek Status = AE_TYPE;
3287b1019a6SJerry Jelinek goto Cleanup;
3297c478bd9Sstevel@tonic-gate
3307b1019a6SJerry Jelinek case ACPI_TYPE_METHOD:
3317b1019a6SJerry Jelinek /*
3327b1019a6SJerry Jelinek * 2) Object is a control method - execute it
3337b1019a6SJerry Jelinek */
3347c478bd9Sstevel@tonic-gate
3357b1019a6SJerry Jelinek /* Verify that there is a method object associated with this node */
336db2bae30SDana Myers
3377b1019a6SJerry Jelinek if (!Info->ObjDesc)
338db2bae30SDana Myers {
3397b1019a6SJerry Jelinek ACPI_ERROR ((AE_INFO, "%s: Method has no attached sub-object",
3407b1019a6SJerry Jelinek Info->FullPathname));
3417b1019a6SJerry Jelinek Status = AE_NULL_OBJECT;
3427b1019a6SJerry Jelinek goto Cleanup;
343db2bae30SDana Myers }
344db2bae30SDana Myers
34527f7c583Smyers ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
3467b1019a6SJerry Jelinek "**** Execute method [%s] at AML address %p length %X\n",
3477b1019a6SJerry Jelinek Info->FullPathname,
34827f7c583Smyers Info->ObjDesc->Method.AmlStart + 1,
34927f7c583Smyers Info->ObjDesc->Method.AmlLength - 1));
3507c478bd9Sstevel@tonic-gate
35127f7c583Smyers /*
35227f7c583Smyers * Any namespace deletion must acquire both the namespace and
35327f7c583Smyers * interpreter locks to ensure that no thread is using the portion of
35427f7c583Smyers * the namespace that is being deleted.
35527f7c583Smyers *
35627f7c583Smyers * Execute the method via the interpreter. The interpreter is locked
35727f7c583Smyers * here before calling into the AML parser
35827f7c583Smyers */
359db2bae30SDana Myers AcpiExEnterInterpreter ();
36027f7c583Smyers Status = AcpiPsExecuteMethod (Info);
36127f7c583Smyers AcpiExExitInterpreter ();
3627b1019a6SJerry Jelinek break;
3637b1019a6SJerry Jelinek
3647b1019a6SJerry Jelinek default:
36527f7c583Smyers /*
3667b1019a6SJerry Jelinek * 3) All other non-method objects -- get the current object value
36727f7c583Smyers */
3687c478bd9Sstevel@tonic-gate
36927f7c583Smyers /*
3707b1019a6SJerry Jelinek * Some objects require additional resolution steps (e.g., the Node
3717b1019a6SJerry Jelinek * may be a field that must be read, etc.) -- we can't just grab
3727b1019a6SJerry Jelinek * the object out of the node.
37327f7c583Smyers *
37427f7c583Smyers * Use ResolveNodeToValue() to get the associated value.
37527f7c583Smyers *
37627f7c583Smyers * NOTE: we can get away with passing in NULL for a walk state because
3777b1019a6SJerry Jelinek * the Node is guaranteed to not be a reference to either a method
37827f7c583Smyers * local or a method argument (because this interface is never called
37927f7c583Smyers * from a running method.)
38027f7c583Smyers *
38127f7c583Smyers * Even though we do not directly invoke the interpreter for object
3827b1019a6SJerry Jelinek * resolution, we must lock it because we could access an OpRegion.
3837b1019a6SJerry Jelinek * The OpRegion access code assumes that the interpreter is locked.
38427f7c583Smyers */
385db2bae30SDana Myers AcpiExEnterInterpreter ();
3867c478bd9Sstevel@tonic-gate
3877b1019a6SJerry Jelinek /* TBD: ResolveNodeToValue has a strange interface, fix */
3887c478bd9Sstevel@tonic-gate
3897b1019a6SJerry Jelinek Info->ReturnObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->Node);
3907b1019a6SJerry Jelinek
3917b1019a6SJerry Jelinek Status = AcpiExResolveNodeToValue (ACPI_CAST_INDIRECT_PTR (
3927b1019a6SJerry Jelinek ACPI_NAMESPACE_NODE, &Info->ReturnObject), NULL);
39327f7c583Smyers AcpiExExitInterpreter ();
3947c478bd9Sstevel@tonic-gate
3957b1019a6SJerry Jelinek if (ACPI_FAILURE (Status))
3967c478bd9Sstevel@tonic-gate {
3977b1019a6SJerry Jelinek Info->ReturnObject = NULL;
3987b1019a6SJerry Jelinek goto Cleanup;
3997c478bd9Sstevel@tonic-gate }
4007b1019a6SJerry Jelinek
4017b1019a6SJerry Jelinek ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returned object %p [%s]\n",
4027b1019a6SJerry Jelinek Info->ReturnObject,
4037b1019a6SJerry Jelinek AcpiUtGetObjectTypeName (Info->ReturnObject)));
4047b1019a6SJerry Jelinek
4057b1019a6SJerry Jelinek Status = AE_CTRL_RETURN_VALUE; /* Always has a "return value" */
4067b1019a6SJerry Jelinek break;
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate
40927f7c583Smyers /*
4107b1019a6SJerry Jelinek * For predefined names, check the return value against the ACPI
4117b1019a6SJerry Jelinek * specification. Some incorrect return value types are repaired.
41227f7c583Smyers */
4137b1019a6SJerry Jelinek (void) AcpiNsCheckReturnValue (Info->Node, Info, Info->ParamCount,
4147b1019a6SJerry Jelinek Status, &Info->ReturnObject);
415aa2aa9a6SDana Myers
416aa2aa9a6SDana Myers /* Check if there is a return value that must be dealt with */
417aa2aa9a6SDana Myers
41827f7c583Smyers if (Status == AE_CTRL_RETURN_VALUE)
41927f7c583Smyers {
42027f7c583Smyers /* If caller does not want the return value, delete it */
42127f7c583Smyers
42227f7c583Smyers if (Info->Flags & ACPI_IGNORE_RETURN_VALUE)
42327f7c583Smyers {
42427f7c583Smyers AcpiUtRemoveReference (Info->ReturnObject);
42527f7c583Smyers Info->ReturnObject = NULL;
42627f7c583Smyers }
42727f7c583Smyers
42827f7c583Smyers /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
42927f7c583Smyers
43027f7c583Smyers Status = AE_OK;
43127f7c583Smyers }
432*35786f68SRobert Mustacchi else if (ACPI_FAILURE(Status))
433*35786f68SRobert Mustacchi {
434*35786f68SRobert Mustacchi /* If ReturnObject exists, delete it */
435*35786f68SRobert Mustacchi
436*35786f68SRobert Mustacchi if (Info->ReturnObject)
437*35786f68SRobert Mustacchi {
438*35786f68SRobert Mustacchi AcpiUtRemoveReference (Info->ReturnObject);
439*35786f68SRobert Mustacchi Info->ReturnObject = NULL;
440*35786f68SRobert Mustacchi }
441*35786f68SRobert Mustacchi }
44227f7c583Smyers
44327f7c583Smyers ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
4447b1019a6SJerry Jelinek "*** Completed evaluation of object %s ***\n",
4457b1019a6SJerry Jelinek Info->RelativePathname));
4467c478bd9Sstevel@tonic-gate
4477b1019a6SJerry Jelinek Cleanup:
44827f7c583Smyers /*
44927f7c583Smyers * Namespace was unlocked by the handling AcpiNs* function, so we
4507b1019a6SJerry Jelinek * just free the pathname and return
45127f7c583Smyers */
4527b1019a6SJerry Jelinek ACPI_FREE (Info->FullPathname);
4537b1019a6SJerry Jelinek Info->FullPathname = NULL;
4547c478bd9Sstevel@tonic-gate return_ACPI_STATUS (Status);
4557c478bd9Sstevel@tonic-gate }
4567c478bd9Sstevel@tonic-gate
45757190917SDana Myers
45857190917SDana Myers /*******************************************************************************
45957190917SDana Myers *
46057190917SDana Myers * FUNCTION: AcpiNsExecModuleCodeList
46157190917SDana Myers *
46257190917SDana Myers * PARAMETERS: None
46357190917SDana Myers *
46457190917SDana Myers * RETURN: None. Exceptions during method execution are ignored, since
46557190917SDana Myers * we cannot abort a table load.
46657190917SDana Myers *
46757190917SDana Myers * DESCRIPTION: Execute all elements of the global module-level code list.
46857190917SDana Myers * Each element is executed as a single control method.
46957190917SDana Myers *
470*35786f68SRobert Mustacchi * NOTE: With this option enabled, each block of detected executable AML
471*35786f68SRobert Mustacchi * code that is outside of any control method is wrapped with a temporary
472*35786f68SRobert Mustacchi * control method object and placed on a global list. The methods on this
473*35786f68SRobert Mustacchi * list are executed below.
474*35786f68SRobert Mustacchi *
475*35786f68SRobert Mustacchi * This function executes the module-level code for all tables only after
476*35786f68SRobert Mustacchi * all of the tables have been loaded. It is a legacy option and is
477*35786f68SRobert Mustacchi * not compatible with other ACPI implementations. See AcpiNsLoadTable.
478*35786f68SRobert Mustacchi *
479*35786f68SRobert Mustacchi * This function will be removed when the legacy option is removed.
480*35786f68SRobert Mustacchi *
48157190917SDana Myers ******************************************************************************/
48257190917SDana Myers
48357190917SDana Myers void
AcpiNsExecModuleCodeList(void)48457190917SDana Myers AcpiNsExecModuleCodeList (
48557190917SDana Myers void)
48657190917SDana Myers {
48757190917SDana Myers ACPI_OPERAND_OBJECT *Prev;
48857190917SDana Myers ACPI_OPERAND_OBJECT *Next;
48957190917SDana Myers ACPI_EVALUATE_INFO *Info;
49057190917SDana Myers UINT32 MethodCount = 0;
49157190917SDana Myers
49257190917SDana Myers
49357190917SDana Myers ACPI_FUNCTION_TRACE (NsExecModuleCodeList);
49457190917SDana Myers
49557190917SDana Myers
49657190917SDana Myers /* Exit now if the list is empty */
49757190917SDana Myers
49857190917SDana Myers Next = AcpiGbl_ModuleCodeList;
49957190917SDana Myers if (!Next)
50057190917SDana Myers {
501*35786f68SRobert Mustacchi ACPI_DEBUG_PRINT ((ACPI_DB_INIT_NAMES,
502*35786f68SRobert Mustacchi "Legacy MLC block list is empty\n"));
503*35786f68SRobert Mustacchi
50457190917SDana Myers return_VOID;
50557190917SDana Myers }
50657190917SDana Myers
50757190917SDana Myers /* Allocate the evaluation information block */
50857190917SDana Myers
50957190917SDana Myers Info = ACPI_ALLOCATE (sizeof (ACPI_EVALUATE_INFO));
51057190917SDana Myers if (!Info)
51157190917SDana Myers {
51257190917SDana Myers return_VOID;
51357190917SDana Myers }
51457190917SDana Myers
51557190917SDana Myers /* Walk the list, executing each "method" */
51657190917SDana Myers
51757190917SDana Myers while (Next)
51857190917SDana Myers {
51957190917SDana Myers Prev = Next;
52057190917SDana Myers Next = Next->Method.Mutex;
52157190917SDana Myers
52257190917SDana Myers /* Clear the link field and execute the method */
52357190917SDana Myers
52457190917SDana Myers Prev->Method.Mutex = NULL;
52557190917SDana Myers AcpiNsExecModuleCode (Prev, Info);
52657190917SDana Myers MethodCount++;
52757190917SDana Myers
52857190917SDana Myers /* Delete the (temporary) method object */
52957190917SDana Myers
53057190917SDana Myers AcpiUtRemoveReference (Prev);
53157190917SDana Myers }
53257190917SDana Myers
5337b1019a6SJerry Jelinek ACPI_INFO ((
53457190917SDana Myers "Executed %u blocks of module-level executable AML code",
53557190917SDana Myers MethodCount));
53657190917SDana Myers
53757190917SDana Myers ACPI_FREE (Info);
53857190917SDana Myers AcpiGbl_ModuleCodeList = NULL;
53957190917SDana Myers return_VOID;
54057190917SDana Myers }
54157190917SDana Myers
54257190917SDana Myers
54357190917SDana Myers /*******************************************************************************
54457190917SDana Myers *
54557190917SDana Myers * FUNCTION: AcpiNsExecModuleCode
54657190917SDana Myers *
54757190917SDana Myers * PARAMETERS: MethodObj - Object container for the module-level code
54857190917SDana Myers * Info - Info block for method evaluation
54957190917SDana Myers *
55057190917SDana Myers * RETURN: None. Exceptions during method execution are ignored, since
55157190917SDana Myers * we cannot abort a table load.
55257190917SDana Myers *
55357190917SDana Myers * DESCRIPTION: Execute a control method containing a block of module-level
55457190917SDana Myers * executable AML code. The control method is temporarily
55557190917SDana Myers * installed to the root node, then evaluated.
55657190917SDana Myers *
55757190917SDana Myers ******************************************************************************/
55857190917SDana Myers
55957190917SDana Myers static void
AcpiNsExecModuleCode(ACPI_OPERAND_OBJECT * MethodObj,ACPI_EVALUATE_INFO * Info)56057190917SDana Myers AcpiNsExecModuleCode (
56157190917SDana Myers ACPI_OPERAND_OBJECT *MethodObj,
56257190917SDana Myers ACPI_EVALUATE_INFO *Info)
56357190917SDana Myers {
56457190917SDana Myers ACPI_OPERAND_OBJECT *ParentObj;
56557190917SDana Myers ACPI_NAMESPACE_NODE *ParentNode;
56657190917SDana Myers ACPI_OBJECT_TYPE Type;
56757190917SDana Myers ACPI_STATUS Status;
56857190917SDana Myers
56957190917SDana Myers
57057190917SDana Myers ACPI_FUNCTION_TRACE (NsExecModuleCode);
57157190917SDana Myers
57257190917SDana Myers
57357190917SDana Myers /*
57457190917SDana Myers * Get the parent node. We cheat by using the NextObject field
57557190917SDana Myers * of the method object descriptor.
57657190917SDana Myers */
5777b1019a6SJerry Jelinek ParentNode = ACPI_CAST_PTR (
5787b1019a6SJerry Jelinek ACPI_NAMESPACE_NODE, MethodObj->Method.NextObject);
57957190917SDana Myers Type = AcpiNsGetType (ParentNode);
58057190917SDana Myers
58126f3cdf0SGordon Ross /*
58226f3cdf0SGordon Ross * Get the region handler and save it in the method object. We may need
58326f3cdf0SGordon Ross * this if an operation region declaration causes a _REG method to be run.
58426f3cdf0SGordon Ross *
58526f3cdf0SGordon Ross * We can't do this in AcpiPsLinkModuleCode because
58626f3cdf0SGordon Ross * AcpiGbl_RootNode->Object is NULL at PASS1.
58726f3cdf0SGordon Ross */
58826f3cdf0SGordon Ross if ((Type == ACPI_TYPE_DEVICE) && ParentNode->Object)
58926f3cdf0SGordon Ross {
59026f3cdf0SGordon Ross MethodObj->Method.Dispatch.Handler =
59126f3cdf0SGordon Ross ParentNode->Object->Device.Handler;
59226f3cdf0SGordon Ross }
59326f3cdf0SGordon Ross
59457190917SDana Myers /* Must clear NextObject (AcpiNsAttachObject needs the field) */
59557190917SDana Myers
59657190917SDana Myers MethodObj->Method.NextObject = NULL;
59757190917SDana Myers
59857190917SDana Myers /* Initialize the evaluation information block */
59957190917SDana Myers
6007b1019a6SJerry Jelinek memset (Info, 0, sizeof (ACPI_EVALUATE_INFO));
60157190917SDana Myers Info->PrefixNode = ParentNode;
60257190917SDana Myers
60357190917SDana Myers /*
6047b1019a6SJerry Jelinek * Get the currently attached parent object. Add a reference,
6057b1019a6SJerry Jelinek * because the ref count will be decreased when the method object
6067b1019a6SJerry Jelinek * is installed to the parent node.
60757190917SDana Myers */
60857190917SDana Myers ParentObj = AcpiNsGetAttachedObject (ParentNode);
60957190917SDana Myers if (ParentObj)
61057190917SDana Myers {
61157190917SDana Myers AcpiUtAddReference (ParentObj);
61257190917SDana Myers }
61357190917SDana Myers
61457190917SDana Myers /* Install the method (module-level code) in the parent node */
61557190917SDana Myers
6167b1019a6SJerry Jelinek Status = AcpiNsAttachObject (ParentNode, MethodObj, ACPI_TYPE_METHOD);
61757190917SDana Myers if (ACPI_FAILURE (Status))
61857190917SDana Myers {
61957190917SDana Myers goto Exit;
62057190917SDana Myers }
62157190917SDana Myers
62257190917SDana Myers /* Execute the parent node as a control method */
62357190917SDana Myers
62457190917SDana Myers Status = AcpiNsEvaluate (Info);
62557190917SDana Myers
6267b1019a6SJerry Jelinek ACPI_DEBUG_PRINT ((ACPI_DB_INIT_NAMES,
6277b1019a6SJerry Jelinek "Executed module-level code at %p\n",
62857190917SDana Myers MethodObj->Method.AmlStart));
62957190917SDana Myers
63057190917SDana Myers /* Delete a possible implicit return value (in slack mode) */
63157190917SDana Myers
63257190917SDana Myers if (Info->ReturnObject)
63357190917SDana Myers {
63426f3cdf0SGordon Ross AcpiUtRemoveReference (Info->ReturnObject);
63557190917SDana Myers }
63657190917SDana Myers
63757190917SDana Myers /* Detach the temporary method object */
63857190917SDana Myers
63957190917SDana Myers AcpiNsDetachObject (ParentNode);
64057190917SDana Myers
64157190917SDana Myers /* Restore the original parent object */
64257190917SDana Myers
64357190917SDana Myers if (ParentObj)
64457190917SDana Myers {
64557190917SDana Myers Status = AcpiNsAttachObject (ParentNode, ParentObj, Type);
64657190917SDana Myers }
64757190917SDana Myers else
64857190917SDana Myers {
64957190917SDana Myers ParentNode->Type = (UINT8) Type;
65057190917SDana Myers }
65157190917SDana Myers
65257190917SDana Myers Exit:
65357190917SDana Myers if (ParentObj)
65457190917SDana Myers {
65557190917SDana Myers AcpiUtRemoveReference (ParentObj);
65657190917SDana Myers }
65757190917SDana Myers return_VOID;
65857190917SDana Myers }
659