Subversion Repositories Kolibri OS

Rev

Rev 1498 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1498 Rev 2216
1
/******************************************************************************
1
/******************************************************************************
2
 *
2
 *
3
 * Module Name: evregion - ACPI AddressSpace (OpRegion) handler dispatch
3
 * Module Name: evregion - ACPI AddressSpace (OpRegion) handler dispatch
4
 *
4
 *
5
 *****************************************************************************/
5
 *****************************************************************************/
6
 
6
 
7
/******************************************************************************
7
/******************************************************************************
8
 *
8
 *
9
 * 1. Copyright Notice
9
 * 1. Copyright Notice
10
 *
10
 *
11
 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
11
 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
12
 * All rights reserved.
12
 * All rights reserved.
13
 *
13
 *
14
 * 2. License
14
 * 2. License
15
 *
15
 *
16
 * 2.1. This is your license from Intel Corp. under its intellectual property
16
 * 2.1. This is your license from Intel Corp. under its intellectual property
17
 * rights.  You may have additional license terms from the party that provided
17
 * rights.  You may have additional license terms from the party that provided
18
 * you this software, covering your right to use that party's intellectual
18
 * you this software, covering your right to use that party's intellectual
19
 * property rights.
19
 * property rights.
20
 *
20
 *
21
 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
21
 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22
 * copy of the source code appearing in this file ("Covered Code") an
22
 * copy of the source code appearing in this file ("Covered Code") an
23
 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
23
 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24
 * base code distributed originally by Intel ("Original Intel Code") to copy,
24
 * base code distributed originally by Intel ("Original Intel Code") to copy,
25
 * make derivatives, distribute, use and display any portion of the Covered
25
 * make derivatives, distribute, use and display any portion of the Covered
26
 * Code in any form, with the right to sublicense such rights; and
26
 * Code in any form, with the right to sublicense such rights; and
27
 *
27
 *
28
 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
28
 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29
 * license (with the right to sublicense), under only those claims of Intel
29
 * license (with the right to sublicense), under only those claims of Intel
30
 * patents that are infringed by the Original Intel Code, to make, use, sell,
30
 * patents that are infringed by the Original Intel Code, to make, use, sell,
31
 * offer to sell, and import the Covered Code and derivative works thereof
31
 * offer to sell, and import the Covered Code and derivative works thereof
32
 * solely to the minimum extent necessary to exercise the above copyright
32
 * solely to the minimum extent necessary to exercise the above copyright
33
 * license, and in no event shall the patent license extend to any additions
33
 * license, and in no event shall the patent license extend to any additions
34
 * to or modifications of the Original Intel Code.  No other license or right
34
 * to or modifications of the Original Intel Code.  No other license or right
35
 * is granted directly or by implication, estoppel or otherwise;
35
 * is granted directly or by implication, estoppel or otherwise;
36
 *
36
 *
37
 * The above copyright and patent license is granted only if the following
37
 * The above copyright and patent license is granted only if the following
38
 * conditions are met:
38
 * conditions are met:
39
 *
39
 *
40
 * 3. Conditions
40
 * 3. Conditions
41
 *
41
 *
42
 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
42
 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43
 * Redistribution of source code of any substantial portion of the Covered
43
 * Redistribution of source code of any substantial portion of the Covered
44
 * Code or modification with rights to further distribute source must include
44
 * Code or modification with rights to further distribute source must include
45
 * the above Copyright Notice, the above License, this list of Conditions,
45
 * the above Copyright Notice, the above License, this list of Conditions,
46
 * and the following Disclaimer and Export Compliance provision.  In addition,
46
 * and the following Disclaimer and Export Compliance provision.  In addition,
47
 * Licensee must cause all Covered Code to which Licensee contributes to
47
 * Licensee must cause all Covered Code to which Licensee contributes to
48
 * contain a file documenting the changes Licensee made to create that Covered
48
 * contain a file documenting the changes Licensee made to create that Covered
49
 * Code and the date of any change.  Licensee must include in that file the
49
 * Code and the date of any change.  Licensee must include in that file the
50
 * documentation of any changes made by any predecessor Licensee.  Licensee
50
 * documentation of any changes made by any predecessor Licensee.  Licensee
51
 * must include a prominent statement that the modification is derived,
51
 * must include a prominent statement that the modification is derived,
52
 * directly or indirectly, from Original Intel Code.
52
 * directly or indirectly, from Original Intel Code.
53
 *
53
 *
54
 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
54
 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55
 * Redistribution of source code of any substantial portion of the Covered
55
 * Redistribution of source code of any substantial portion of the Covered
56
 * Code or modification without rights to further distribute source must
56
 * Code or modification without rights to further distribute source must
57
 * include the following Disclaimer and Export Compliance provision in the
57
 * include the following Disclaimer and Export Compliance provision in the
58
 * documentation and/or other materials provided with distribution.  In
58
 * documentation and/or other materials provided with distribution.  In
59
 * addition, Licensee may not authorize further sublicense of source of any
59
 * addition, Licensee may not authorize further sublicense of source of any
60
 * portion of the Covered Code, and must include terms to the effect that the
60
 * portion of the Covered Code, and must include terms to the effect that the
61
 * license from Licensee to its licensee is limited to the intellectual
61
 * license from Licensee to its licensee is limited to the intellectual
62
 * property embodied in the software Licensee provides to its licensee, and
62
 * property embodied in the software Licensee provides to its licensee, and
63
 * not to intellectual property embodied in modifications its licensee may
63
 * not to intellectual property embodied in modifications its licensee may
64
 * make.
64
 * make.
65
 *
65
 *
66
 * 3.3. Redistribution of Executable. Redistribution in executable form of any
66
 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67
 * substantial portion of the Covered Code or modification must reproduce the
67
 * substantial portion of the Covered Code or modification must reproduce the
68
 * above Copyright Notice, and the following Disclaimer and Export Compliance
68
 * above Copyright Notice, and the following Disclaimer and Export Compliance
69
 * provision in the documentation and/or other materials provided with the
69
 * provision in the documentation and/or other materials provided with the
70
 * distribution.
70
 * distribution.
71
 *
71
 *
72
 * 3.4. Intel retains all right, title, and interest in and to the Original
72
 * 3.4. Intel retains all right, title, and interest in and to the Original
73
 * Intel Code.
73
 * Intel Code.
74
 *
74
 *
75
 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
75
 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76
 * Intel shall be used in advertising or otherwise to promote the sale, use or
76
 * Intel shall be used in advertising or otherwise to promote the sale, use or
77
 * other dealings in products derived from or relating to the Covered Code
77
 * other dealings in products derived from or relating to the Covered Code
78
 * without prior written authorization from Intel.
78
 * without prior written authorization from Intel.
79
 *
79
 *
80
 * 4. Disclaimer and Export Compliance
80
 * 4. Disclaimer and Export Compliance
81
 *
81
 *
82
 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
82
 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83
 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
83
 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84
 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
84
 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85
 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
85
 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86
 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
86
 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87
 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
87
 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88
 * PARTICULAR PURPOSE.
88
 * PARTICULAR PURPOSE.
89
 *
89
 *
90
 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
90
 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91
 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
91
 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92
 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
92
 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93
 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
93
 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94
 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
94
 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95
 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
95
 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96
 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
96
 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97
 * LIMITED REMEDY.
97
 * LIMITED REMEDY.
98
 *
98
 *
99
 * 4.3. Licensee shall not export, either directly or indirectly, any of this
99
 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100
 * software or system incorporating such software without first obtaining any
100
 * software or system incorporating such software without first obtaining any
101
 * required license or other approval from the U. S. Department of Commerce or
101
 * required license or other approval from the U. S. Department of Commerce or
102
 * any other agency or department of the United States Government.  In the
102
 * any other agency or department of the United States Government.  In the
103
 * event Licensee exports any such software from the United States or
103
 * event Licensee exports any such software from the United States or
104
 * re-exports any such software from a foreign destination, Licensee shall
104
 * re-exports any such software from a foreign destination, Licensee shall
105
 * ensure that the distribution and export/re-export of the software is in
105
 * ensure that the distribution and export/re-export of the software is in
106
 * compliance with all laws, regulations, orders, or other restrictions of the
106
 * compliance with all laws, regulations, orders, or other restrictions of the
107
 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
107
 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108
 * any of its subsidiaries will export/re-export any technical data, process,
108
 * any of its subsidiaries will export/re-export any technical data, process,
109
 * software, or service, directly or indirectly, to any country for which the
109
 * software, or service, directly or indirectly, to any country for which the
110
 * United States government or any agency thereof requires an export license,
110
 * United States government or any agency thereof requires an export license,
111
 * other governmental approval, or letter of assurance, without first obtaining
111
 * other governmental approval, or letter of assurance, without first obtaining
112
 * such license, approval or letter.
112
 * such license, approval or letter.
113
 *
113
 *
114
 *****************************************************************************/
114
 *****************************************************************************/
115
 
115
 
116
 
116
 
117
#define __EVREGION_C__
117
#define __EVREGION_C__
118
 
118
 
119
#include "acpi.h"
119
#include "acpi.h"
120
#include "accommon.h"
120
#include "accommon.h"
121
#include "acevents.h"
121
#include "acevents.h"
122
#include "acnamesp.h"
122
#include "acnamesp.h"
123
#include "acinterp.h"
123
#include "acinterp.h"
124
 
124
 
125
#define _COMPONENT          ACPI_EVENTS
125
#define _COMPONENT          ACPI_EVENTS
126
        ACPI_MODULE_NAME    ("evregion")
126
        ACPI_MODULE_NAME    ("evregion")
127
 
127
 
128
 
128
 
129
/* Local prototypes */
129
/* Local prototypes */
130
 
130
 
131
static BOOLEAN
131
static BOOLEAN
132
AcpiEvHasDefaultHandler (
132
AcpiEvHasDefaultHandler (
133
    ACPI_NAMESPACE_NODE     *Node,
133
    ACPI_NAMESPACE_NODE     *Node,
134
    ACPI_ADR_SPACE_TYPE     SpaceId);
134
    ACPI_ADR_SPACE_TYPE     SpaceId);
-
 
135
 
-
 
136
static void
-
 
137
AcpiEvOrphanEcRegMethod (
-
 
138
    void);
135
 
139
 
136
static ACPI_STATUS
140
static ACPI_STATUS
137
AcpiEvRegRun (
141
AcpiEvRegRun (
138
    ACPI_HANDLE             ObjHandle,
142
    ACPI_HANDLE             ObjHandle,
139
    UINT32                  Level,
143
    UINT32                  Level,
140
    void                    *Context,
144
    void                    *Context,
141
    void                    **ReturnValue);
145
    void                    **ReturnValue);
142
 
146
 
143
static ACPI_STATUS
147
static ACPI_STATUS
144
AcpiEvInstallHandler (
148
AcpiEvInstallHandler (
145
    ACPI_HANDLE             ObjHandle,
149
    ACPI_HANDLE             ObjHandle,
146
    UINT32                  Level,
150
    UINT32                  Level,
147
    void                    *Context,
151
    void                    *Context,
148
    void                    **ReturnValue);
152
    void                    **ReturnValue);
149
 
153
 
150
/* These are the address spaces that will get default handlers */
154
/* These are the address spaces that will get default handlers */
151
 
155
 
152
#define ACPI_NUM_DEFAULT_SPACES     4
156
#define ACPI_NUM_DEFAULT_SPACES     4
153
 
157
 
154
static UINT8        AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
158
static UINT8        AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
155
{
159
{
156
    ACPI_ADR_SPACE_SYSTEM_MEMORY,
160
    ACPI_ADR_SPACE_SYSTEM_MEMORY,
157
    ACPI_ADR_SPACE_SYSTEM_IO,
161
    ACPI_ADR_SPACE_SYSTEM_IO,
158
    ACPI_ADR_SPACE_PCI_CONFIG,
162
    ACPI_ADR_SPACE_PCI_CONFIG,
159
    ACPI_ADR_SPACE_DATA_TABLE
163
    ACPI_ADR_SPACE_DATA_TABLE
160
};
164
};
161
 
165
 
162
 
166
 
163
/*******************************************************************************
167
/*******************************************************************************
164
 *
168
 *
165
 * FUNCTION:    AcpiEvInstallRegionHandlers
169
 * FUNCTION:    AcpiEvInstallRegionHandlers
166
 *
170
 *
167
 * PARAMETERS:  None
171
 * PARAMETERS:  None
168
 *
172
 *
169
 * RETURN:      Status
173
 * RETURN:      Status
170
 *
174
 *
171
 * DESCRIPTION: Installs the core subsystem default address space handlers.
175
 * DESCRIPTION: Installs the core subsystem default address space handlers.
172
 *
176
 *
173
 ******************************************************************************/
177
 ******************************************************************************/
174
 
178
 
175
ACPI_STATUS
179
ACPI_STATUS
176
AcpiEvInstallRegionHandlers (
180
AcpiEvInstallRegionHandlers (
177
    void)
181
    void)
178
{
182
{
179
    ACPI_STATUS             Status;
183
    ACPI_STATUS             Status;
180
    UINT32                  i;
184
    UINT32                  i;
181
 
185
 
182
 
186
 
183
    ACPI_FUNCTION_TRACE (EvInstallRegionHandlers);
187
    ACPI_FUNCTION_TRACE (EvInstallRegionHandlers);
184
 
188
 
185
 
189
 
186
    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
190
    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
187
    if (ACPI_FAILURE (Status))
191
    if (ACPI_FAILURE (Status))
188
    {
192
    {
189
        return_ACPI_STATUS (Status);
193
        return_ACPI_STATUS (Status);
190
    }
194
    }
191
 
195
 
192
    /*
196
    /*
193
     * All address spaces (PCI Config, EC, SMBus) are scope dependent and
197
     * All address spaces (PCI Config, EC, SMBus) are scope dependent and
194
     * registration must occur for a specific device.
198
     * registration must occur for a specific device.
195
     *
199
     *
196
     * In the case of the system memory and IO address spaces there is
200
     * In the case of the system memory and IO address spaces there is
197
     * currently no device associated with the address space. For these we
201
     * currently no device associated with the address space. For these we
198
     * use the root.
202
     * use the root.
199
     *
203
     *
200
     * We install the default PCI config space handler at the root so that
204
     * We install the default PCI config space handler at the root so that
201
     * this space is immediately available even though the we have not
205
     * this space is immediately available even though the we have not
202
     * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
206
     * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
203
     * specification which states that the PCI config space must be always
207
     * specification which states that the PCI config space must be always
204
     * available -- even though we are nowhere near ready to find the PCI root
208
     * available -- even though we are nowhere near ready to find the PCI root
205
     * buses at this point.
209
     * buses at this point.
206
     *
210
     *
207
     * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
211
     * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
208
     * has already been installed (via AcpiInstallAddressSpaceHandler).
212
     * has already been installed (via AcpiInstallAddressSpaceHandler).
209
     * Similar for AE_SAME_HANDLER.
213
     * Similar for AE_SAME_HANDLER.
210
     */
214
     */
211
    for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
215
    for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
212
    {
216
    {
213
        Status = AcpiEvInstallSpaceHandler (AcpiGbl_RootNode,
217
        Status = AcpiEvInstallSpaceHandler (AcpiGbl_RootNode,
214
                    AcpiGbl_DefaultAddressSpaces[i],
218
                    AcpiGbl_DefaultAddressSpaces[i],
215
                    ACPI_DEFAULT_HANDLER, NULL, NULL);
219
                    ACPI_DEFAULT_HANDLER, NULL, NULL);
216
        switch (Status)
220
        switch (Status)
217
        {
221
        {
218
        case AE_OK:
222
        case AE_OK:
219
        case AE_SAME_HANDLER:
223
        case AE_SAME_HANDLER:
220
        case AE_ALREADY_EXISTS:
224
        case AE_ALREADY_EXISTS:
221
 
225
 
222
            /* These exceptions are all OK */
226
            /* These exceptions are all OK */
223
 
227
 
224
            Status = AE_OK;
228
            Status = AE_OK;
225
            break;
229
            break;
226
 
230
 
227
        default:
231
        default:
228
 
232
 
229
            goto UnlockAndExit;
233
            goto UnlockAndExit;
230
        }
234
        }
231
    }
235
    }
232
 
236
 
233
UnlockAndExit:
237
UnlockAndExit:
234
    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
238
    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
235
    return_ACPI_STATUS (Status);
239
    return_ACPI_STATUS (Status);
236
}
240
}
237
 
241
 
238
 
242
 
239
/*******************************************************************************
243
/*******************************************************************************
240
 *
244
 *
241
 * FUNCTION:    AcpiEvHasDefaultHandler
245
 * FUNCTION:    AcpiEvHasDefaultHandler
242
 *
246
 *
243
 * PARAMETERS:  Node                - Namespace node for the device
247
 * PARAMETERS:  Node                - Namespace node for the device
244
 *              SpaceId             - The address space ID
248
 *              SpaceId             - The address space ID
245
 *
249
 *
246
 * RETURN:      TRUE if default handler is installed, FALSE otherwise
250
 * RETURN:      TRUE if default handler is installed, FALSE otherwise
247
 *
251
 *
248
 * DESCRIPTION: Check if the default handler is installed for the requested
252
 * DESCRIPTION: Check if the default handler is installed for the requested
249
 *              space ID.
253
 *              space ID.
250
 *
254
 *
251
 ******************************************************************************/
255
 ******************************************************************************/
252
 
256
 
253
static BOOLEAN
257
static BOOLEAN
254
AcpiEvHasDefaultHandler (
258
AcpiEvHasDefaultHandler (
255
    ACPI_NAMESPACE_NODE     *Node,
259
    ACPI_NAMESPACE_NODE     *Node,
256
    ACPI_ADR_SPACE_TYPE     SpaceId)
260
    ACPI_ADR_SPACE_TYPE     SpaceId)
257
{
261
{
258
    ACPI_OPERAND_OBJECT     *ObjDesc;
262
    ACPI_OPERAND_OBJECT     *ObjDesc;
259
    ACPI_OPERAND_OBJECT     *HandlerObj;
263
    ACPI_OPERAND_OBJECT     *HandlerObj;
260
 
264
 
261
 
265
 
262
    /* Must have an existing internal object */
266
    /* Must have an existing internal object */
263
 
267
 
264
    ObjDesc = AcpiNsGetAttachedObject (Node);
268
    ObjDesc = AcpiNsGetAttachedObject (Node);
265
    if (ObjDesc)
269
    if (ObjDesc)
266
    {
270
    {
267
        HandlerObj = ObjDesc->Device.Handler;
271
        HandlerObj = ObjDesc->Device.Handler;
268
 
272
 
269
        /* Walk the linked list of handlers for this object */
273
        /* Walk the linked list of handlers for this object */
270
 
274
 
271
        while (HandlerObj)
275
        while (HandlerObj)
272
        {
276
        {
273
            if (HandlerObj->AddressSpace.SpaceId == SpaceId)
277
            if (HandlerObj->AddressSpace.SpaceId == SpaceId)
274
            {
278
            {
275
                if (HandlerObj->AddressSpace.HandlerFlags &
279
                if (HandlerObj->AddressSpace.HandlerFlags &
276
                        ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
280
                        ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
277
                {
281
                {
278
                    return (TRUE);
282
                    return (TRUE);
279
                }
283
                }
280
            }
284
            }
281
 
285
 
282
            HandlerObj = HandlerObj->AddressSpace.Next;
286
            HandlerObj = HandlerObj->AddressSpace.Next;
283
        }
287
        }
284
    }
288
    }
285
 
289
 
286
    return (FALSE);
290
    return (FALSE);
287
}
291
}
288
 
292
 
289
 
293
 
290
/*******************************************************************************
294
/*******************************************************************************
291
 *
295
 *
292
 * FUNCTION:    AcpiEvInitializeOpRegions
296
 * FUNCTION:    AcpiEvInitializeOpRegions
293
 *
297
 *
294
 * PARAMETERS:  None
298
 * PARAMETERS:  None
295
 *
299
 *
296
 * RETURN:      Status
300
 * RETURN:      Status
297
 *
301
 *
298
 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
302
 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
299
 *              an installed default region handler.
303
 *              an installed default region handler.
300
 *
304
 *
301
 ******************************************************************************/
305
 ******************************************************************************/
302
 
306
 
303
ACPI_STATUS
307
ACPI_STATUS
304
AcpiEvInitializeOpRegions (
308
AcpiEvInitializeOpRegions (
305
    void)
309
    void)
306
{
310
{
307
    ACPI_STATUS             Status;
311
    ACPI_STATUS             Status;
308
    UINT32                  i;
312
    UINT32                  i;
309
 
313
 
310
 
314
 
311
    ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
315
    ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
312
 
316
 
313
 
317
 
314
    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
318
    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
315
    if (ACPI_FAILURE (Status))
319
    if (ACPI_FAILURE (Status))
316
    {
320
    {
317
        return_ACPI_STATUS (Status);
321
        return_ACPI_STATUS (Status);
318
    }
322
    }
319
 
323
 
320
    /* Run the _REG methods for OpRegions in each default address space */
324
    /* Run the _REG methods for OpRegions in each default address space */
321
 
325
 
322
    for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
326
    for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
323
    {
327
    {
324
        /*
328
        /*
325
         * Make sure the installed handler is the DEFAULT handler. If not the
329
         * Make sure the installed handler is the DEFAULT handler. If not the
326
         * default, the _REG methods will have already been run (when the
330
         * default, the _REG methods will have already been run (when the
327
         * handler was installed)
331
         * handler was installed)
328
         */
332
         */
329
        if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode,
333
        if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode,
330
               AcpiGbl_DefaultAddressSpaces[i]))
334
               AcpiGbl_DefaultAddressSpaces[i]))
331
        {
335
        {
332
            Status = AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
336
            Status = AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
333
                        AcpiGbl_DefaultAddressSpaces[i]);
337
                        AcpiGbl_DefaultAddressSpaces[i]);
334
        }
338
        }
335
    }
339
    }
-
 
340
 
-
 
341
    AcpiGbl_RegMethodsExecuted = TRUE;
336
 
342
 
337
    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
343
    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
338
    return_ACPI_STATUS (Status);
344
    return_ACPI_STATUS (Status);
339
}
345
}
340
 
346
 
341
 
347
 
342
/*******************************************************************************
348
/*******************************************************************************
343
 *
349
 *
344
 * FUNCTION:    AcpiEvExecuteRegMethod
350
 * FUNCTION:    AcpiEvExecuteRegMethod
345
 *
351
 *
346
 * PARAMETERS:  RegionObj           - Region object
352
 * PARAMETERS:  RegionObj           - Region object
347
 *              Function            - Passed to _REG: On (1) or Off (0)
353
 *              Function            - Passed to _REG: On (1) or Off (0)
348
 *
354
 *
349
 * RETURN:      Status
355
 * RETURN:      Status
350
 *
356
 *
351
 * DESCRIPTION: Execute _REG method for a region
357
 * DESCRIPTION: Execute _REG method for a region
352
 *
358
 *
353
 ******************************************************************************/
359
 ******************************************************************************/
354
 
360
 
355
ACPI_STATUS
361
ACPI_STATUS
356
AcpiEvExecuteRegMethod (
362
AcpiEvExecuteRegMethod (
357
    ACPI_OPERAND_OBJECT     *RegionObj,
363
    ACPI_OPERAND_OBJECT     *RegionObj,
358
    UINT32                  Function)
364
    UINT32                  Function)
359
{
365
{
360
    ACPI_EVALUATE_INFO      *Info;
366
    ACPI_EVALUATE_INFO      *Info;
361
    ACPI_OPERAND_OBJECT     *Args[3];
367
    ACPI_OPERAND_OBJECT     *Args[3];
362
    ACPI_OPERAND_OBJECT     *RegionObj2;
368
    ACPI_OPERAND_OBJECT     *RegionObj2;
363
    ACPI_STATUS             Status;
369
    ACPI_STATUS             Status;
364
 
370
 
365
 
371
 
366
    ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
372
    ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
367
 
373
 
368
 
374
 
369
    RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
375
    RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
370
    if (!RegionObj2)
376
    if (!RegionObj2)
371
    {
377
    {
372
        return_ACPI_STATUS (AE_NOT_EXIST);
378
        return_ACPI_STATUS (AE_NOT_EXIST);
373
    }
379
    }
374
 
380
 
375
    if (RegionObj2->Extra.Method_REG == NULL)
381
    if (RegionObj2->Extra.Method_REG == NULL)
376
    {
382
    {
377
        return_ACPI_STATUS (AE_OK);
383
        return_ACPI_STATUS (AE_OK);
378
    }
384
    }
379
 
385
 
380
    /* Allocate and initialize the evaluation information block */
386
    /* Allocate and initialize the evaluation information block */
381
 
387
 
382
    Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
388
    Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
383
    if (!Info)
389
    if (!Info)
384
    {
390
    {
385
        return_ACPI_STATUS (AE_NO_MEMORY);
391
        return_ACPI_STATUS (AE_NO_MEMORY);
386
    }
392
    }
387
 
393
 
388
    Info->PrefixNode = RegionObj2->Extra.Method_REG;
394
    Info->PrefixNode = RegionObj2->Extra.Method_REG;
389
    Info->Pathname = NULL;
395
    Info->Pathname = NULL;
390
    Info->Parameters = Args;
396
    Info->Parameters = Args;
391
    Info->Flags = ACPI_IGNORE_RETURN_VALUE;
397
    Info->Flags = ACPI_IGNORE_RETURN_VALUE;
392
 
398
 
393
    /*
399
    /*
394
     * The _REG method has two arguments:
400
     * The _REG method has two arguments:
395
     *
401
     *
396
     * Arg0 - Integer:
402
     * Arg0 - Integer:
397
     *  Operation region space ID Same value as RegionObj->Region.SpaceId
403
     *  Operation region space ID Same value as RegionObj->Region.SpaceId
398
     *
404
     *
399
     * Arg1 - Integer:
405
     * Arg1 - Integer:
400
     *  connection status 1 for connecting the handler, 0 for disconnecting
406
     *  connection status 1 for connecting the handler, 0 for disconnecting
401
     *  the handler (Passed as a parameter)
407
     *  the handler (Passed as a parameter)
402
     */
408
     */
403
    Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId);
409
    Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId);
404
    if (!Args[0])
410
    if (!Args[0])
405
    {
411
    {
406
        Status = AE_NO_MEMORY;
412
        Status = AE_NO_MEMORY;
407
        goto Cleanup1;
413
        goto Cleanup1;
408
    }
414
    }
409
 
415
 
410
    Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function);
416
    Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function);
411
    if (!Args[1])
417
    if (!Args[1])
412
    {
418
    {
413
        Status = AE_NO_MEMORY;
419
        Status = AE_NO_MEMORY;
414
        goto Cleanup2;
420
        goto Cleanup2;
415
    }
421
    }
416
 
422
 
417
    Args[2] = NULL; /* Terminate list */
423
    Args[2] = NULL; /* Terminate list */
418
 
424
 
419
    /* Execute the method, no return value */
425
    /* Execute the method, no return value */
420
 
426
 
421
    ACPI_DEBUG_EXEC (
427
    ACPI_DEBUG_EXEC (
422
        AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
428
        AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
423
 
429
 
424
    Status = AcpiNsEvaluate (Info);
430
    Status = AcpiNsEvaluate (Info);
425
    AcpiUtRemoveReference (Args[1]);
431
    AcpiUtRemoveReference (Args[1]);
426
 
432
 
427
Cleanup2:
433
Cleanup2:
428
    AcpiUtRemoveReference (Args[0]);
434
    AcpiUtRemoveReference (Args[0]);
429
 
435
 
430
Cleanup1:
436
Cleanup1:
431
    ACPI_FREE (Info);
437
    ACPI_FREE (Info);
432
    return_ACPI_STATUS (Status);
438
    return_ACPI_STATUS (Status);
433
}
439
}
434
 
440
 
435
 
441
 
436
/*******************************************************************************
442
/*******************************************************************************
437
 *
443
 *
438
 * FUNCTION:    AcpiEvAddressSpaceDispatch
444
 * FUNCTION:    AcpiEvAddressSpaceDispatch
439
 *
445
 *
440
 * PARAMETERS:  RegionObj           - Internal region object
446
 * PARAMETERS:  RegionObj           - Internal region object
441
 *              Function            - Read or Write operation
447
 *              Function            - Read or Write operation
442
 *              RegionOffset        - Where in the region to read or write
448
 *              RegionOffset        - Where in the region to read or write
443
 *              BitWidth            - Field width in bits (8, 16, 32, or 64)
449
 *              BitWidth            - Field width in bits (8, 16, 32, or 64)
444
 *              Value               - Pointer to in or out value, must be
450
 *              Value               - Pointer to in or out value, must be
445
 *                                    a full 64-bit integer
451
 *                                    a full 64-bit integer
446
 *
452
 *
447
 * RETURN:      Status
453
 * RETURN:      Status
448
 *
454
 *
449
 * DESCRIPTION: Dispatch an address space or operation region access to
455
 * DESCRIPTION: Dispatch an address space or operation region access to
450
 *              a previously installed handler.
456
 *              a previously installed handler.
451
 *
457
 *
452
 ******************************************************************************/
458
 ******************************************************************************/
453
 
459
 
454
ACPI_STATUS
460
ACPI_STATUS
455
AcpiEvAddressSpaceDispatch (
461
AcpiEvAddressSpaceDispatch (
456
    ACPI_OPERAND_OBJECT     *RegionObj,
462
    ACPI_OPERAND_OBJECT     *RegionObj,
457
    UINT32                  Function,
463
    UINT32                  Function,
458
    UINT32                  RegionOffset,
464
    UINT32                  RegionOffset,
459
    UINT32                  BitWidth,
465
    UINT32                  BitWidth,
460
    UINT64                  *Value)
466
    UINT64                  *Value)
461
{
467
{
462
    ACPI_STATUS             Status;
468
    ACPI_STATUS             Status;
463
    ACPI_ADR_SPACE_HANDLER  Handler;
469
    ACPI_ADR_SPACE_HANDLER  Handler;
464
    ACPI_ADR_SPACE_SETUP    RegionSetup;
470
    ACPI_ADR_SPACE_SETUP    RegionSetup;
465
    ACPI_OPERAND_OBJECT     *HandlerDesc;
471
    ACPI_OPERAND_OBJECT     *HandlerDesc;
466
    ACPI_OPERAND_OBJECT     *RegionObj2;
472
    ACPI_OPERAND_OBJECT     *RegionObj2;
467
    void                    *RegionContext = NULL;
473
    void                    *RegionContext = NULL;
468
 
474
 
469
 
475
 
470
    ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
476
    ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
471
 
477
 
472
 
478
 
473
    RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
479
    RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
474
    if (!RegionObj2)
480
    if (!RegionObj2)
475
    {
481
    {
476
        return_ACPI_STATUS (AE_NOT_EXIST);
482
        return_ACPI_STATUS (AE_NOT_EXIST);
477
    }
483
    }
478
 
484
 
479
    /* Ensure that there is a handler associated with this region */
485
    /* Ensure that there is a handler associated with this region */
480
 
486
 
481
    HandlerDesc = RegionObj->Region.Handler;
487
    HandlerDesc = RegionObj->Region.Handler;
482
    if (!HandlerDesc)
488
    if (!HandlerDesc)
483
    {
489
    {
484
        ACPI_ERROR ((AE_INFO,
490
        ACPI_ERROR ((AE_INFO,
485
            "No handler for Region [%4.4s] (%p) [%s]",
491
            "No handler for Region [%4.4s] (%p) [%s]",
486
            AcpiUtGetNodeName (RegionObj->Region.Node),
492
            AcpiUtGetNodeName (RegionObj->Region.Node),
487
            RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
493
            RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
488
 
494
 
489
        return_ACPI_STATUS (AE_NOT_EXIST);
495
        return_ACPI_STATUS (AE_NOT_EXIST);
490
    }
496
    }
491
 
497
 
492
    /*
498
    /*
493
     * It may be the case that the region has never been initialized.
499
     * It may be the case that the region has never been initialized.
494
     * Some types of regions require special init code
500
     * Some types of regions require special init code
495
     */
501
     */
496
    if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
502
    if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
497
    {
503
    {
498
        /* This region has not been initialized yet, do it */
504
        /* This region has not been initialized yet, do it */
499
 
505
 
500
        RegionSetup = HandlerDesc->AddressSpace.Setup;
506
        RegionSetup = HandlerDesc->AddressSpace.Setup;
501
        if (!RegionSetup)
507
        if (!RegionSetup)
502
        {
508
        {
503
            /* No initialization routine, exit with error */
509
            /* No initialization routine, exit with error */
504
 
510
 
505
            ACPI_ERROR ((AE_INFO,
511
            ACPI_ERROR ((AE_INFO,
506
                "No init routine for region(%p) [%s]",
512
                "No init routine for region(%p) [%s]",
507
                RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
513
                RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
508
            return_ACPI_STATUS (AE_NOT_EXIST);
514
            return_ACPI_STATUS (AE_NOT_EXIST);
509
        }
515
        }
510
 
516
 
511
        /*
517
        /*
512
         * We must exit the interpreter because the region setup will
518
         * We must exit the interpreter because the region setup will
513
         * potentially execute control methods (for example, the _REG method
519
         * potentially execute control methods (for example, the _REG method
514
         * for this region)
520
         * for this region)
515
         */
521
         */
516
        AcpiExExitInterpreter ();
522
        AcpiExExitInterpreter ();
517
 
523
 
518
        Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
524
        Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
519
                    HandlerDesc->AddressSpace.Context, &RegionContext);
525
                    HandlerDesc->AddressSpace.Context, &RegionContext);
520
 
526
 
521
        /* Re-enter the interpreter */
527
        /* Re-enter the interpreter */
522
 
528
 
523
        AcpiExEnterInterpreter ();
529
        AcpiExEnterInterpreter ();
524
 
530
 
525
        /* Check for failure of the Region Setup */
531
        /* Check for failure of the Region Setup */
526
 
532
 
527
        if (ACPI_FAILURE (Status))
533
        if (ACPI_FAILURE (Status))
528
        {
534
        {
529
            ACPI_EXCEPTION ((AE_INFO, Status,
535
            ACPI_EXCEPTION ((AE_INFO, Status,
530
                "During region initialization: [%s]",
536
                "During region initialization: [%s]",
531
                AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
537
                AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
532
            return_ACPI_STATUS (Status);
538
            return_ACPI_STATUS (Status);
533
        }
539
        }
534
 
540
 
535
        /* Region initialization may have been completed by RegionSetup */
541
        /* Region initialization may have been completed by RegionSetup */
536
 
542
 
537
        if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
543
        if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
538
        {
544
        {
539
            RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
545
            RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
540
 
546
 
541
            if (RegionObj2->Extra.RegionContext)
547
            if (RegionObj2->Extra.RegionContext)
542
            {
548
            {
543
                /* The handler for this region was already installed */
549
                /* The handler for this region was already installed */
544
 
550
 
545
                ACPI_FREE (RegionContext);
551
                ACPI_FREE (RegionContext);
546
            }
552
            }
547
            else
553
            else
548
            {
554
            {
549
                /*
555
                /*
550
                 * Save the returned context for use in all accesses to
556
                 * Save the returned context for use in all accesses to
551
                 * this particular region
557
                 * this particular region
552
                 */
558
                 */
553
                RegionObj2->Extra.RegionContext = RegionContext;
559
                RegionObj2->Extra.RegionContext = RegionContext;
554
            }
560
            }
555
        }
561
        }
556
    }
562
    }
557
 
563
 
558
    /* We have everything we need, we can invoke the address space handler */
564
    /* We have everything we need, we can invoke the address space handler */
559
 
565
 
560
    Handler = HandlerDesc->AddressSpace.Handler;
566
    Handler = HandlerDesc->AddressSpace.Handler;
561
 
567
 
562
    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
568
    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
563
        "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
569
        "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
564
        &RegionObj->Region.Handler->AddressSpace, Handler,
570
        &RegionObj->Region.Handler->AddressSpace, Handler,
565
        ACPI_FORMAT_NATIVE_UINT (RegionObj->Region.Address + RegionOffset),
571
        ACPI_FORMAT_NATIVE_UINT (RegionObj->Region.Address + RegionOffset),
566
        AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
572
        AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
567
 
573
 
568
    if (!(HandlerDesc->AddressSpace.HandlerFlags &
574
    if (!(HandlerDesc->AddressSpace.HandlerFlags &
569
            ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
575
            ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
570
    {
576
    {
571
        /*
577
        /*
572
         * For handlers other than the default (supplied) handlers, we must
578
         * For handlers other than the default (supplied) handlers, we must
573
         * exit the interpreter because the handler *might* block -- we don't
579
         * exit the interpreter because the handler *might* block -- we don't
574
         * know what it will do, so we can't hold the lock on the intepreter.
580
         * know what it will do, so we can't hold the lock on the intepreter.
575
         */
581
         */
576
        AcpiExExitInterpreter();
582
        AcpiExExitInterpreter();
577
    }
583
    }
578
 
584
 
579
    /* Call the handler */
585
    /* Call the handler */
580
 
586
 
581
    Status = Handler (Function,
587
    Status = Handler (Function,
582
        (RegionObj->Region.Address + RegionOffset), BitWidth, Value,
588
        (RegionObj->Region.Address + RegionOffset), BitWidth, Value,
583
        HandlerDesc->AddressSpace.Context, RegionObj2->Extra.RegionContext);
589
        HandlerDesc->AddressSpace.Context, RegionObj2->Extra.RegionContext);
584
 
590
 
585
    if (ACPI_FAILURE (Status))
591
    if (ACPI_FAILURE (Status))
586
    {
592
    {
587
        ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
593
        ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
588
            AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
594
            AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
589
    }
595
    }
590
 
596
 
591
    if (!(HandlerDesc->AddressSpace.HandlerFlags &
597
    if (!(HandlerDesc->AddressSpace.HandlerFlags &
592
            ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
598
            ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
593
    {
599
    {
594
        /*
600
        /*
595
         * We just returned from a non-default handler, we must re-enter the
601
         * We just returned from a non-default handler, we must re-enter the
596
         * interpreter
602
         * interpreter
597
         */
603
         */
598
       AcpiExEnterInterpreter ();
604
       AcpiExEnterInterpreter ();
599
    }
605
    }
600
 
606
 
601
    return_ACPI_STATUS (Status);
607
    return_ACPI_STATUS (Status);
602
}
608
}
603
 
609
 
604
 
610
 
605
/*******************************************************************************
611
/*******************************************************************************
606
 *
612
 *
607
 * FUNCTION:    AcpiEvDetachRegion
613
 * FUNCTION:    AcpiEvDetachRegion
608
 *
614
 *
609
 * PARAMETERS:  RegionObj           - Region Object
615
 * PARAMETERS:  RegionObj           - Region Object
610
 *              AcpiNsIsLocked      - Namespace Region Already Locked?
616
 *              AcpiNsIsLocked      - Namespace Region Already Locked?
611
 *
617
 *
612
 * RETURN:      None
618
 * RETURN:      None
613
 *
619
 *
614
 * DESCRIPTION: Break the association between the handler and the region
620
 * DESCRIPTION: Break the association between the handler and the region
615
 *              this is a two way association.
621
 *              this is a two way association.
616
 *
622
 *
617
 ******************************************************************************/
623
 ******************************************************************************/
618
 
624
 
619
void
625
void
620
AcpiEvDetachRegion(
626
AcpiEvDetachRegion(
621
    ACPI_OPERAND_OBJECT     *RegionObj,
627
    ACPI_OPERAND_OBJECT     *RegionObj,
622
    BOOLEAN                 AcpiNsIsLocked)
628
    BOOLEAN                 AcpiNsIsLocked)
623
{
629
{
624
    ACPI_OPERAND_OBJECT     *HandlerObj;
630
    ACPI_OPERAND_OBJECT     *HandlerObj;
625
    ACPI_OPERAND_OBJECT     *ObjDesc;
631
    ACPI_OPERAND_OBJECT     *ObjDesc;
626
    ACPI_OPERAND_OBJECT     **LastObjPtr;
632
    ACPI_OPERAND_OBJECT     **LastObjPtr;
627
    ACPI_ADR_SPACE_SETUP    RegionSetup;
633
    ACPI_ADR_SPACE_SETUP    RegionSetup;
628
    void                    **RegionContext;
634
    void                    **RegionContext;
629
    ACPI_OPERAND_OBJECT     *RegionObj2;
635
    ACPI_OPERAND_OBJECT     *RegionObj2;
630
    ACPI_STATUS             Status;
636
    ACPI_STATUS             Status;
631
 
637
 
632
 
638
 
633
    ACPI_FUNCTION_TRACE (EvDetachRegion);
639
    ACPI_FUNCTION_TRACE (EvDetachRegion);
634
 
640
 
635
 
641
 
636
    RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
642
    RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
637
    if (!RegionObj2)
643
    if (!RegionObj2)
638
    {
644
    {
639
        return_VOID;
645
        return_VOID;
640
    }
646
    }
641
    RegionContext = &RegionObj2->Extra.RegionContext;
647
    RegionContext = &RegionObj2->Extra.RegionContext;
642
 
648
 
643
    /* Get the address handler from the region object */
649
    /* Get the address handler from the region object */
644
 
650
 
645
    HandlerObj = RegionObj->Region.Handler;
651
    HandlerObj = RegionObj->Region.Handler;
646
    if (!HandlerObj)
652
    if (!HandlerObj)
647
    {
653
    {
648
        /* This region has no handler, all done */
654
        /* This region has no handler, all done */
649
 
655
 
650
        return_VOID;
656
        return_VOID;
651
    }
657
    }
652
 
658
 
653
    /* Find this region in the handler's list */
659
    /* Find this region in the handler's list */
654
 
660
 
655
    ObjDesc = HandlerObj->AddressSpace.RegionList;
661
    ObjDesc = HandlerObj->AddressSpace.RegionList;
656
    LastObjPtr = &HandlerObj->AddressSpace.RegionList;
662
    LastObjPtr = &HandlerObj->AddressSpace.RegionList;
657
 
663
 
658
    while (ObjDesc)
664
    while (ObjDesc)
659
    {
665
    {
660
        /* Is this the correct Region? */
666
        /* Is this the correct Region? */
661
 
667
 
662
        if (ObjDesc == RegionObj)
668
        if (ObjDesc == RegionObj)
663
        {
669
        {
664
            ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
670
            ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
665
                "Removing Region %p from address handler %p\n",
671
                "Removing Region %p from address handler %p\n",
666
                RegionObj, HandlerObj));
672
                RegionObj, HandlerObj));
667
 
673
 
668
            /* This is it, remove it from the handler's list */
674
            /* This is it, remove it from the handler's list */
669
 
675
 
670
            *LastObjPtr = ObjDesc->Region.Next;
676
            *LastObjPtr = ObjDesc->Region.Next;
671
            ObjDesc->Region.Next = NULL;        /* Must clear field */
677
            ObjDesc->Region.Next = NULL;        /* Must clear field */
672
 
678
 
673
            if (AcpiNsIsLocked)
679
            if (AcpiNsIsLocked)
674
            {
680
            {
675
                Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
681
                Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
676
                if (ACPI_FAILURE (Status))
682
                if (ACPI_FAILURE (Status))
677
                {
683
                {
678
                    return_VOID;
684
                    return_VOID;
679
                }
685
                }
680
            }
686
            }
681
 
687
 
682
            /* Now stop region accesses by executing the _REG method */
688
            /* Now stop region accesses by executing the _REG method */
683
 
689
 
684
            Status = AcpiEvExecuteRegMethod (RegionObj, 0);
690
            Status = AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_DISCONNECT);
685
            if (ACPI_FAILURE (Status))
691
            if (ACPI_FAILURE (Status))
686
            {
692
            {
687
                ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
693
                ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
688
                    AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
694
                    AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
689
            }
695
            }
690
 
696
 
691
            if (AcpiNsIsLocked)
697
            if (AcpiNsIsLocked)
692
            {
698
            {
693
                Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
699
                Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
694
                if (ACPI_FAILURE (Status))
700
                if (ACPI_FAILURE (Status))
695
                {
701
                {
696
                    return_VOID;
702
                    return_VOID;
697
                }
703
                }
698
            }
704
            }
699
 
705
 
700
            /*
706
            /*
701
             * If the region has been activated, call the setup handler with
707
             * If the region has been activated, call the setup handler with
702
             * the deactivate notification
708
             * the deactivate notification
703
             */
709
             */
704
            if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
710
            if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
705
            {
711
            {
706
                RegionSetup = HandlerObj->AddressSpace.Setup;
712
                RegionSetup = HandlerObj->AddressSpace.Setup;
707
                Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
713
                Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
708
                    HandlerObj->AddressSpace.Context, RegionContext);
714
                    HandlerObj->AddressSpace.Context, RegionContext);
709
 
715
 
710
                /* Init routine may fail, Just ignore errors */
716
                /* Init routine may fail, Just ignore errors */
711
 
717
 
712
                if (ACPI_FAILURE (Status))
718
                if (ACPI_FAILURE (Status))
713
                {
719
                {
714
                    ACPI_EXCEPTION ((AE_INFO, Status,
720
                    ACPI_EXCEPTION ((AE_INFO, Status,
715
                        "from region handler - deactivate, [%s]",
721
                        "from region handler - deactivate, [%s]",
716
                        AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
722
                        AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
717
                }
723
                }
718
 
724
 
719
                RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
725
                RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
720
            }
726
            }
721
 
727
 
722
            /*
728
            /*
723
             * Remove handler reference in the region
729
             * Remove handler reference in the region
724
             *
730
             *
725
             * NOTE: this doesn't mean that the region goes away, the region
731
             * NOTE: this doesn't mean that the region goes away, the region
726
             * is just inaccessible as indicated to the _REG method
732
             * is just inaccessible as indicated to the _REG method
727
             *
733
             *
728
             * If the region is on the handler's list, this must be the
734
             * If the region is on the handler's list, this must be the
729
             * region's handler
735
             * region's handler
730
             */
736
             */
731
            RegionObj->Region.Handler = NULL;
737
            RegionObj->Region.Handler = NULL;
732
            AcpiUtRemoveReference (HandlerObj);
738
            AcpiUtRemoveReference (HandlerObj);
733
 
739
 
734
            return_VOID;
740
            return_VOID;
735
        }
741
        }
736
 
742
 
737
        /* Walk the linked list of handlers */
743
        /* Walk the linked list of handlers */
738
 
744
 
739
        LastObjPtr = &ObjDesc->Region.Next;
745
        LastObjPtr = &ObjDesc->Region.Next;
740
        ObjDesc = ObjDesc->Region.Next;
746
        ObjDesc = ObjDesc->Region.Next;
741
    }
747
    }
742
 
748
 
743
    /* If we get here, the region was not in the handler's region list */
749
    /* If we get here, the region was not in the handler's region list */
744
 
750
 
745
    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
751
    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
746
        "Cannot remove region %p from address handler %p\n",
752
        "Cannot remove region %p from address handler %p\n",
747
        RegionObj, HandlerObj));
753
        RegionObj, HandlerObj));
748
 
754
 
749
    return_VOID;
755
    return_VOID;
750
}
756
}
751
 
757
 
752
 
758
 
753
/*******************************************************************************
759
/*******************************************************************************
754
 *
760
 *
755
 * FUNCTION:    AcpiEvAttachRegion
761
 * FUNCTION:    AcpiEvAttachRegion
756
 *
762
 *
757
 * PARAMETERS:  HandlerObj          - Handler Object
763
 * PARAMETERS:  HandlerObj          - Handler Object
758
 *              RegionObj           - Region Object
764
 *              RegionObj           - Region Object
759
 *              AcpiNsIsLocked      - Namespace Region Already Locked?
765
 *              AcpiNsIsLocked      - Namespace Region Already Locked?
760
 *
766
 *
761
 * RETURN:      None
767
 * RETURN:      None
762
 *
768
 *
763
 * DESCRIPTION: Create the association between the handler and the region
769
 * DESCRIPTION: Create the association between the handler and the region
764
 *              this is a two way association.
770
 *              this is a two way association.
765
 *
771
 *
766
 ******************************************************************************/
772
 ******************************************************************************/
767
 
773
 
768
ACPI_STATUS
774
ACPI_STATUS
769
AcpiEvAttachRegion (
775
AcpiEvAttachRegion (
770
    ACPI_OPERAND_OBJECT     *HandlerObj,
776
    ACPI_OPERAND_OBJECT     *HandlerObj,
771
    ACPI_OPERAND_OBJECT     *RegionObj,
777
    ACPI_OPERAND_OBJECT     *RegionObj,
772
    BOOLEAN                 AcpiNsIsLocked)
778
    BOOLEAN                 AcpiNsIsLocked)
773
{
779
{
774
 
780
 
775
    ACPI_FUNCTION_TRACE (EvAttachRegion);
781
    ACPI_FUNCTION_TRACE (EvAttachRegion);
776
 
782
 
777
 
783
 
778
    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
784
    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
779
        "Adding Region [%4.4s] %p to address handler %p [%s]\n",
785
        "Adding Region [%4.4s] %p to address handler %p [%s]\n",
780
        AcpiUtGetNodeName (RegionObj->Region.Node),
786
        AcpiUtGetNodeName (RegionObj->Region.Node),
781
        RegionObj, HandlerObj,
787
        RegionObj, HandlerObj,
782
        AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
788
        AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
783
 
789
 
784
    /* Link this region to the front of the handler's list */
790
    /* Link this region to the front of the handler's list */
785
 
791
 
786
    RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
792
    RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
787
    HandlerObj->AddressSpace.RegionList = RegionObj;
793
    HandlerObj->AddressSpace.RegionList = RegionObj;
788
 
794
 
789
    /* Install the region's handler */
795
    /* Install the region's handler */
790
 
796
 
791
    if (RegionObj->Region.Handler)
797
    if (RegionObj->Region.Handler)
792
    {
798
    {
793
        return_ACPI_STATUS (AE_ALREADY_EXISTS);
799
        return_ACPI_STATUS (AE_ALREADY_EXISTS);
794
    }
800
    }
795
 
801
 
796
    RegionObj->Region.Handler = HandlerObj;
802
    RegionObj->Region.Handler = HandlerObj;
797
    AcpiUtAddReference (HandlerObj);
803
    AcpiUtAddReference (HandlerObj);
798
 
804
 
799
    return_ACPI_STATUS (AE_OK);
805
    return_ACPI_STATUS (AE_OK);
800
}
806
}
801
 
807
 
802
 
808
 
803
/*******************************************************************************
809
/*******************************************************************************
804
 *
810
 *
805
 * FUNCTION:    AcpiEvInstallHandler
811
 * FUNCTION:    AcpiEvInstallHandler
806
 *
812
 *
807
 * PARAMETERS:  WalkNamespace callback
813
 * PARAMETERS:  WalkNamespace callback
808
 *
814
 *
809
 * DESCRIPTION: This routine installs an address handler into objects that are
815
 * DESCRIPTION: This routine installs an address handler into objects that are
810
 *              of type Region or Device.
816
 *              of type Region or Device.
811
 *
817
 *
812
 *              If the Object is a Device, and the device has a handler of
818
 *              If the Object is a Device, and the device has a handler of
813
 *              the same type then the search is terminated in that branch.
819
 *              the same type then the search is terminated in that branch.
814
 *
820
 *
815
 *              This is because the existing handler is closer in proximity
821
 *              This is because the existing handler is closer in proximity
816
 *              to any more regions than the one we are trying to install.
822
 *              to any more regions than the one we are trying to install.
817
 *
823
 *
818
 ******************************************************************************/
824
 ******************************************************************************/
819
 
825
 
820
static ACPI_STATUS
826
static ACPI_STATUS
821
AcpiEvInstallHandler (
827
AcpiEvInstallHandler (
822
    ACPI_HANDLE             ObjHandle,
828
    ACPI_HANDLE             ObjHandle,
823
    UINT32                  Level,
829
    UINT32                  Level,
824
    void                    *Context,
830
    void                    *Context,
825
    void                    **ReturnValue)
831
    void                    **ReturnValue)
826
{
832
{
827
    ACPI_OPERAND_OBJECT     *HandlerObj;
833
    ACPI_OPERAND_OBJECT     *HandlerObj;
828
    ACPI_OPERAND_OBJECT     *NextHandlerObj;
834
    ACPI_OPERAND_OBJECT     *NextHandlerObj;
829
    ACPI_OPERAND_OBJECT     *ObjDesc;
835
    ACPI_OPERAND_OBJECT     *ObjDesc;
830
    ACPI_NAMESPACE_NODE     *Node;
836
    ACPI_NAMESPACE_NODE     *Node;
831
    ACPI_STATUS             Status;
837
    ACPI_STATUS             Status;
832
 
838
 
833
 
839
 
834
    ACPI_FUNCTION_NAME (EvInstallHandler);
840
    ACPI_FUNCTION_NAME (EvInstallHandler);
835
 
841
 
836
 
842
 
837
    HandlerObj = (ACPI_OPERAND_OBJECT  *) Context;
843
    HandlerObj = (ACPI_OPERAND_OBJECT  *) Context;
838
 
844
 
839
    /* Parameter validation */
845
    /* Parameter validation */
840
 
846
 
841
    if (!HandlerObj)
847
    if (!HandlerObj)
842
    {
848
    {
843
        return (AE_OK);
849
        return (AE_OK);
844
    }
850
    }
845
 
851
 
846
    /* Convert and validate the device handle */
852
    /* Convert and validate the device handle */
847
 
853
 
848
    Node = AcpiNsValidateHandle (ObjHandle);
854
    Node = AcpiNsValidateHandle (ObjHandle);
849
    if (!Node)
855
    if (!Node)
850
    {
856
    {
851
        return (AE_BAD_PARAMETER);
857
        return (AE_BAD_PARAMETER);
852
    }
858
    }
853
 
859
 
854
    /*
860
    /*
855
     * We only care about regions and objects that are allowed to have
861
     * We only care about regions and objects that are allowed to have
856
     * address space handlers
862
     * address space handlers
857
     */
863
     */
858
    if ((Node->Type != ACPI_TYPE_DEVICE) &&
864
    if ((Node->Type != ACPI_TYPE_DEVICE) &&
859
        (Node->Type != ACPI_TYPE_REGION) &&
865
        (Node->Type != ACPI_TYPE_REGION) &&
860
        (Node != AcpiGbl_RootNode))
866
        (Node != AcpiGbl_RootNode))
861
    {
867
    {
862
        return (AE_OK);
868
        return (AE_OK);
863
    }
869
    }
864
 
870
 
865
    /* Check for an existing internal object */
871
    /* Check for an existing internal object */
866
 
872
 
867
    ObjDesc = AcpiNsGetAttachedObject (Node);
873
    ObjDesc = AcpiNsGetAttachedObject (Node);
868
    if (!ObjDesc)
874
    if (!ObjDesc)
869
    {
875
    {
870
        /* No object, just exit */
876
        /* No object, just exit */
871
 
877
 
872
        return (AE_OK);
878
        return (AE_OK);
873
    }
879
    }
874
 
880
 
875
    /* Devices are handled different than regions */
881
    /* Devices are handled different than regions */
876
 
882
 
877
    if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
883
    if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
878
    {
884
    {
879
        /* Check if this Device already has a handler for this address space */
885
        /* Check if this Device already has a handler for this address space */
880
 
886
 
881
        NextHandlerObj = ObjDesc->Device.Handler;
887
        NextHandlerObj = ObjDesc->Device.Handler;
882
        while (NextHandlerObj)
888
        while (NextHandlerObj)
883
        {
889
        {
884
            /* Found a handler, is it for the same address space? */
890
            /* Found a handler, is it for the same address space? */
885
 
891
 
886
            if (NextHandlerObj->AddressSpace.SpaceId ==
892
            if (NextHandlerObj->AddressSpace.SpaceId ==
887
                    HandlerObj->AddressSpace.SpaceId)
893
                    HandlerObj->AddressSpace.SpaceId)
888
            {
894
            {
889
                ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
895
                ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
890
                    "Found handler for region [%s] in device %p(%p) "
896
                    "Found handler for region [%s] in device %p(%p) "
891
                    "handler %p\n",
897
                    "handler %p\n",
892
                    AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
898
                    AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
893
                    ObjDesc, NextHandlerObj, HandlerObj));
899
                    ObjDesc, NextHandlerObj, HandlerObj));
894
 
900
 
895
                /*
901
                /*
896
                 * Since the object we found it on was a device, then it
902
                 * Since the object we found it on was a device, then it
897
                 * means that someone has already installed a handler for
903
                 * means that someone has already installed a handler for
898
                 * the branch of the namespace from this device on. Just
904
                 * the branch of the namespace from this device on. Just
899
                 * bail out telling the walk routine to not traverse this
905
                 * bail out telling the walk routine to not traverse this
900
                 * branch. This preserves the scoping rule for handlers.
906
                 * branch. This preserves the scoping rule for handlers.
901
                 */
907
                 */
902
                return (AE_CTRL_DEPTH);
908
                return (AE_CTRL_DEPTH);
903
            }
909
            }
904
 
910
 
905
            /* Walk the linked list of handlers attached to this device */
911
            /* Walk the linked list of handlers attached to this device */
906
 
912
 
907
            NextHandlerObj = NextHandlerObj->AddressSpace.Next;
913
            NextHandlerObj = NextHandlerObj->AddressSpace.Next;
908
        }
914
        }
909
 
915
 
910
        /*
916
        /*
911
         * As long as the device didn't have a handler for this space we
917
         * As long as the device didn't have a handler for this space we
912
         * don't care about it. We just ignore it and proceed.
918
         * don't care about it. We just ignore it and proceed.
913
         */
919
         */
914
        return (AE_OK);
920
        return (AE_OK);
915
    }
921
    }
916
 
922
 
917
    /* Object is a Region */
923
    /* Object is a Region */
918
 
924
 
919
    if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
925
    if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
920
    {
926
    {
921
        /* This region is for a different address space, just ignore it */
927
        /* This region is for a different address space, just ignore it */
922
 
928
 
923
        return (AE_OK);
929
        return (AE_OK);
924
    }
930
    }
925
 
931
 
926
    /*
932
    /*
927
     * Now we have a region and it is for the handler's address space type.
933
     * Now we have a region and it is for the handler's address space type.
928
     *
934
     *
929
     * First disconnect region for any previous handler (if any)
935
     * First disconnect region for any previous handler (if any)
930
     */
936
     */
931
    AcpiEvDetachRegion (ObjDesc, FALSE);
937
    AcpiEvDetachRegion (ObjDesc, FALSE);
932
 
938
 
933
    /* Connect the region to the new handler */
939
    /* Connect the region to the new handler */
934
 
940
 
935
    Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
941
    Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
936
    return (Status);
942
    return (Status);
937
}
943
}
938
 
944
 
939
 
945
 
940
/*******************************************************************************
946
/*******************************************************************************
941
 *
947
 *
942
 * FUNCTION:    AcpiEvInstallSpaceHandler
948
 * FUNCTION:    AcpiEvInstallSpaceHandler
943
 *
949
 *
944
 * PARAMETERS:  Node            - Namespace node for the device
950
 * PARAMETERS:  Node            - Namespace node for the device
945
 *              SpaceId         - The address space ID
951
 *              SpaceId         - The address space ID
946
 *              Handler         - Address of the handler
952
 *              Handler         - Address of the handler
947
 *              Setup           - Address of the setup function
953
 *              Setup           - Address of the setup function
948
 *              Context         - Value passed to the handler on each access
954
 *              Context         - Value passed to the handler on each access
949
 *
955
 *
950
 * RETURN:      Status
956
 * RETURN:      Status
951
 *
957
 *
952
 * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
958
 * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
953
 *              Assumes namespace is locked
959
 *              Assumes namespace is locked
954
 *
960
 *
955
 ******************************************************************************/
961
 ******************************************************************************/
956
 
962
 
957
ACPI_STATUS
963
ACPI_STATUS
958
AcpiEvInstallSpaceHandler (
964
AcpiEvInstallSpaceHandler (
959
    ACPI_NAMESPACE_NODE     *Node,
965
    ACPI_NAMESPACE_NODE     *Node,
960
    ACPI_ADR_SPACE_TYPE     SpaceId,
966
    ACPI_ADR_SPACE_TYPE     SpaceId,
961
    ACPI_ADR_SPACE_HANDLER  Handler,
967
    ACPI_ADR_SPACE_HANDLER  Handler,
962
    ACPI_ADR_SPACE_SETUP    Setup,
968
    ACPI_ADR_SPACE_SETUP    Setup,
963
    void                    *Context)
969
    void                    *Context)
964
{
970
{
965
    ACPI_OPERAND_OBJECT     *ObjDesc;
971
    ACPI_OPERAND_OBJECT     *ObjDesc;
966
    ACPI_OPERAND_OBJECT     *HandlerObj;
972
    ACPI_OPERAND_OBJECT     *HandlerObj;
967
    ACPI_STATUS             Status;
973
    ACPI_STATUS             Status;
968
    ACPI_OBJECT_TYPE        Type;
974
    ACPI_OBJECT_TYPE        Type;
969
    UINT8                  Flags = 0;
975
    UINT8                  Flags = 0;
970
 
976
 
971
 
977
 
972
    ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
978
    ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
973
 
979
 
974
 
980
 
975
    /*
981
    /*
976
     * This registration is valid for only the types below and the root. This
982
     * This registration is valid for only the types below and the root. This
977
     * is where the default handlers get placed.
983
     * is where the default handlers get placed.
978
     */
984
     */
979
    if ((Node->Type != ACPI_TYPE_DEVICE)     &&
985
    if ((Node->Type != ACPI_TYPE_DEVICE)     &&
980
        (Node->Type != ACPI_TYPE_PROCESSOR)  &&
986
        (Node->Type != ACPI_TYPE_PROCESSOR)  &&
981
        (Node->Type != ACPI_TYPE_THERMAL)    &&
987
        (Node->Type != ACPI_TYPE_THERMAL)    &&
982
        (Node != AcpiGbl_RootNode))
988
        (Node != AcpiGbl_RootNode))
983
    {
989
    {
984
        Status = AE_BAD_PARAMETER;
990
        Status = AE_BAD_PARAMETER;
985
        goto UnlockAndExit;
991
        goto UnlockAndExit;
986
    }
992
    }
987
 
993
 
988
    if (Handler == ACPI_DEFAULT_HANDLER)
994
    if (Handler == ACPI_DEFAULT_HANDLER)
989
    {
995
    {
990
        Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
996
        Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
991
 
997
 
992
        switch (SpaceId)
998
        switch (SpaceId)
993
        {
999
        {
994
        case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1000
        case ACPI_ADR_SPACE_SYSTEM_MEMORY:
995
            Handler = AcpiExSystemMemorySpaceHandler;
1001
            Handler = AcpiExSystemMemorySpaceHandler;
996
            Setup   = AcpiEvSystemMemoryRegionSetup;
1002
            Setup   = AcpiEvSystemMemoryRegionSetup;
997
            break;
1003
            break;
998
 
1004
 
999
        case ACPI_ADR_SPACE_SYSTEM_IO:
1005
        case ACPI_ADR_SPACE_SYSTEM_IO:
1000
            Handler = AcpiExSystemIoSpaceHandler;
1006
            Handler = AcpiExSystemIoSpaceHandler;
1001
            Setup   = AcpiEvIoSpaceRegionSetup;
1007
            Setup   = AcpiEvIoSpaceRegionSetup;
1002
            break;
1008
            break;
1003
 
1009
 
1004
        case ACPI_ADR_SPACE_PCI_CONFIG:
1010
        case ACPI_ADR_SPACE_PCI_CONFIG:
1005
            Handler = AcpiExPciConfigSpaceHandler;
1011
            Handler = AcpiExPciConfigSpaceHandler;
1006
            Setup   = AcpiEvPciConfigRegionSetup;
1012
            Setup   = AcpiEvPciConfigRegionSetup;
1007
            break;
1013
            break;
1008
 
1014
 
1009
        case ACPI_ADR_SPACE_CMOS:
1015
        case ACPI_ADR_SPACE_CMOS:
1010
            Handler = AcpiExCmosSpaceHandler;
1016
            Handler = AcpiExCmosSpaceHandler;
1011
            Setup   = AcpiEvCmosRegionSetup;
1017
            Setup   = AcpiEvCmosRegionSetup;
1012
            break;
1018
            break;
1013
 
1019
 
1014
        case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1020
        case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1015
            Handler = AcpiExPciBarSpaceHandler;
1021
            Handler = AcpiExPciBarSpaceHandler;
1016
            Setup   = AcpiEvPciBarRegionSetup;
1022
            Setup   = AcpiEvPciBarRegionSetup;
1017
            break;
1023
            break;
1018
 
1024
 
1019
        case ACPI_ADR_SPACE_DATA_TABLE:
1025
        case ACPI_ADR_SPACE_DATA_TABLE:
1020
            Handler = AcpiExDataTableSpaceHandler;
1026
            Handler = AcpiExDataTableSpaceHandler;
1021
            Setup   = NULL;
1027
            Setup   = NULL;
1022
            break;
1028
            break;
1023
 
1029
 
1024
        default:
1030
        default:
1025
            Status = AE_BAD_PARAMETER;
1031
            Status = AE_BAD_PARAMETER;
1026
            goto UnlockAndExit;
1032
            goto UnlockAndExit;
1027
        }
1033
        }
1028
    }
1034
    }
1029
 
1035
 
1030
    /* If the caller hasn't specified a setup routine, use the default */
1036
    /* If the caller hasn't specified a setup routine, use the default */
1031
 
1037
 
1032
    if (!Setup)
1038
    if (!Setup)
1033
    {
1039
    {
1034
        Setup = AcpiEvDefaultRegionSetup;
1040
        Setup = AcpiEvDefaultRegionSetup;
1035
    }
1041
    }
1036
 
1042
 
1037
    /* Check for an existing internal object */
1043
    /* Check for an existing internal object */
1038
 
1044
 
1039
    ObjDesc = AcpiNsGetAttachedObject (Node);
1045
    ObjDesc = AcpiNsGetAttachedObject (Node);
1040
    if (ObjDesc)
1046
    if (ObjDesc)
1041
    {
1047
    {
1042
        /*
1048
        /*
1043
         * The attached device object already exists. Make sure the handler
1049
         * The attached device object already exists. Make sure the handler
1044
         * is not already installed.
1050
         * is not already installed.
1045
         */
1051
         */
1046
        HandlerObj = ObjDesc->Device.Handler;
1052
        HandlerObj = ObjDesc->Device.Handler;
1047
 
1053
 
1048
        /* Walk the handler list for this device */
1054
        /* Walk the handler list for this device */
1049
 
1055
 
1050
        while (HandlerObj)
1056
        while (HandlerObj)
1051
        {
1057
        {
1052
            /* Same SpaceId indicates a handler already installed */
1058
            /* Same SpaceId indicates a handler already installed */
1053
 
1059
 
1054
            if (HandlerObj->AddressSpace.SpaceId == SpaceId)
1060
            if (HandlerObj->AddressSpace.SpaceId == SpaceId)
1055
            {
1061
            {
1056
                if (HandlerObj->AddressSpace.Handler == Handler)
1062
                if (HandlerObj->AddressSpace.Handler == Handler)
1057
                {
1063
                {
1058
                    /*
1064
                    /*
1059
                     * It is (relatively) OK to attempt to install the SAME
1065
                     * It is (relatively) OK to attempt to install the SAME
1060
                     * handler twice. This can easily happen with the
1066
                     * handler twice. This can easily happen with the
1061
                     * PCI_Config space.
1067
                     * PCI_Config space.
1062
                     */
1068
                     */
1063
                    Status = AE_SAME_HANDLER;
1069
                    Status = AE_SAME_HANDLER;
1064
                    goto UnlockAndExit;
1070
                    goto UnlockAndExit;
1065
                }
1071
                }
1066
                else
1072
                else
1067
                {
1073
                {
1068
                    /* A handler is already installed */
1074
                    /* A handler is already installed */
1069
 
1075
 
1070
                    Status = AE_ALREADY_EXISTS;
1076
                    Status = AE_ALREADY_EXISTS;
1071
                }
1077
                }
1072
                goto UnlockAndExit;
1078
                goto UnlockAndExit;
1073
            }
1079
            }
1074
 
1080
 
1075
            /* Walk the linked list of handlers */
1081
            /* Walk the linked list of handlers */
1076
 
1082
 
1077
            HandlerObj = HandlerObj->AddressSpace.Next;
1083
            HandlerObj = HandlerObj->AddressSpace.Next;
1078
        }
1084
        }
1079
    }
1085
    }
1080
    else
1086
    else
1081
    {
1087
    {
1082
        ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1088
        ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1083
            "Creating object on Device %p while installing handler\n", Node));
1089
            "Creating object on Device %p while installing handler\n", Node));
1084
 
1090
 
1085
        /* ObjDesc does not exist, create one */
1091
        /* ObjDesc does not exist, create one */
1086
 
1092
 
1087
        if (Node->Type == ACPI_TYPE_ANY)
1093
        if (Node->Type == ACPI_TYPE_ANY)
1088
        {
1094
        {
1089
            Type = ACPI_TYPE_DEVICE;
1095
            Type = ACPI_TYPE_DEVICE;
1090
        }
1096
        }
1091
        else
1097
        else
1092
        {
1098
        {
1093
            Type = Node->Type;
1099
            Type = Node->Type;
1094
        }
1100
        }
1095
 
1101
 
1096
        ObjDesc = AcpiUtCreateInternalObject (Type);
1102
        ObjDesc = AcpiUtCreateInternalObject (Type);
1097
        if (!ObjDesc)
1103
        if (!ObjDesc)
1098
        {
1104
        {
1099
            Status = AE_NO_MEMORY;
1105
            Status = AE_NO_MEMORY;
1100
            goto UnlockAndExit;
1106
            goto UnlockAndExit;
1101
        }
1107
        }
1102
 
1108
 
1103
        /* Init new descriptor */
1109
        /* Init new descriptor */
1104
 
1110
 
1105
        ObjDesc->Common.Type = (UINT8) Type;
1111
        ObjDesc->Common.Type = (UINT8) Type;
1106
 
1112
 
1107
        /* Attach the new object to the Node */
1113
        /* Attach the new object to the Node */
1108
 
1114
 
1109
        Status = AcpiNsAttachObject (Node, ObjDesc, Type);
1115
        Status = AcpiNsAttachObject (Node, ObjDesc, Type);
1110
 
1116
 
1111
        /* Remove local reference to the object */
1117
        /* Remove local reference to the object */
1112
 
1118
 
1113
        AcpiUtRemoveReference (ObjDesc);
1119
        AcpiUtRemoveReference (ObjDesc);
1114
 
1120
 
1115
        if (ACPI_FAILURE (Status))
1121
        if (ACPI_FAILURE (Status))
1116
        {
1122
        {
1117
            goto UnlockAndExit;
1123
            goto UnlockAndExit;
1118
        }
1124
        }
1119
    }
1125
    }
1120
 
1126
 
1121
    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1127
    ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1122
        "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
1128
        "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
1123
        AcpiUtGetRegionName (SpaceId), SpaceId,
1129
        AcpiUtGetRegionName (SpaceId), SpaceId,
1124
        AcpiUtGetNodeName (Node), Node, ObjDesc));
1130
        AcpiUtGetNodeName (Node), Node, ObjDesc));
1125
 
1131
 
1126
    /*
1132
    /*
1127
     * Install the handler
1133
     * Install the handler
1128
     *
1134
     *
1129
     * At this point there is no existing handler. Just allocate the object
1135
     * At this point there is no existing handler. Just allocate the object
1130
     * for the handler and link it into the list.
1136
     * for the handler and link it into the list.
1131
     */
1137
     */
1132
    HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
1138
    HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
1133
    if (!HandlerObj)
1139
    if (!HandlerObj)
1134
    {
1140
    {
1135
        Status = AE_NO_MEMORY;
1141
        Status = AE_NO_MEMORY;
1136
        goto UnlockAndExit;
1142
        goto UnlockAndExit;
1137
    }
1143
    }
1138
 
1144
 
1139
    /* Init handler obj */
1145
    /* Init handler obj */
1140
 
1146
 
1141
    HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
1147
    HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
1142
    HandlerObj->AddressSpace.HandlerFlags = Flags;
1148
    HandlerObj->AddressSpace.HandlerFlags = Flags;
1143
    HandlerObj->AddressSpace.RegionList = NULL;
1149
    HandlerObj->AddressSpace.RegionList = NULL;
1144
    HandlerObj->AddressSpace.Node = Node;
1150
    HandlerObj->AddressSpace.Node = Node;
1145
    HandlerObj->AddressSpace.Handler = Handler;
1151
    HandlerObj->AddressSpace.Handler = Handler;
1146
    HandlerObj->AddressSpace.Context = Context;
1152
    HandlerObj->AddressSpace.Context = Context;
1147
    HandlerObj->AddressSpace.Setup  = Setup;
1153
    HandlerObj->AddressSpace.Setup  = Setup;
1148
 
1154
 
1149
    /* Install at head of Device.AddressSpace list */
1155
    /* Install at head of Device.AddressSpace list */
1150
 
1156
 
1151
    HandlerObj->AddressSpace.Next = ObjDesc->Device.Handler;
1157
    HandlerObj->AddressSpace.Next = ObjDesc->Device.Handler;
1152
 
1158
 
1153
    /*
1159
    /*
1154
     * The Device object is the first reference on the HandlerObj.
1160
     * The Device object is the first reference on the HandlerObj.
1155
     * Each region that uses the handler adds a reference.
1161
     * Each region that uses the handler adds a reference.
1156
     */
1162
     */
1157
    ObjDesc->Device.Handler = HandlerObj;
1163
    ObjDesc->Device.Handler = HandlerObj;
1158
 
1164
 
1159
    /*
1165
    /*
1160
     * Walk the namespace finding all of the regions this
1166
     * Walk the namespace finding all of the regions this
1161
     * handler will manage.
1167
     * handler will manage.
1162
     *
1168
     *
1163
     * Start at the device and search the branch toward
1169
     * Start at the device and search the branch toward
1164
     * the leaf nodes until either the leaf is encountered or
1170
     * the leaf nodes until either the leaf is encountered or
1165
     * a device is detected that has an address handler of the
1171
     * a device is detected that has an address handler of the
1166
     * same type.
1172
     * same type.
1167
     *
1173
     *
1168
     * In either case, back up and search down the remainder
1174
     * In either case, back up and search down the remainder
1169
     * of the branch
1175
     * of the branch
1170
     */
1176
     */
1171
    Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1177
    Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1172
                ACPI_NS_WALK_UNLOCK, AcpiEvInstallHandler, NULL,
1178
                ACPI_NS_WALK_UNLOCK, AcpiEvInstallHandler, NULL,
1173
                HandlerObj, NULL);
1179
                HandlerObj, NULL);
1174
 
1180
 
1175
UnlockAndExit:
1181
UnlockAndExit:
1176
    return_ACPI_STATUS (Status);
1182
    return_ACPI_STATUS (Status);
1177
}
1183
}
1178
 
1184
 
1179
 
1185
 
1180
/*******************************************************************************
1186
/*******************************************************************************
1181
 *
1187
 *
1182
 * FUNCTION:    AcpiEvExecuteRegMethods
1188
 * FUNCTION:    AcpiEvExecuteRegMethods
1183
 *
1189
 *
1184
 * PARAMETERS:  Node            - Namespace node for the device
1190
 * PARAMETERS:  Node            - Namespace node for the device
1185
 *              SpaceId         - The address space ID
1191
 *              SpaceId         - The address space ID
1186
 *
1192
 *
1187
 * RETURN:      Status
1193
 * RETURN:      Status
1188
 *
1194
 *
1189
 * DESCRIPTION: Run all _REG methods for the input Space ID;
1195
 * DESCRIPTION: Run all _REG methods for the input Space ID;
1190
 *              Note: assumes namespace is locked, or system init time.
1196
 *              Note: assumes namespace is locked, or system init time.
1191
 *
1197
 *
1192
 ******************************************************************************/
1198
 ******************************************************************************/
1193
 
1199
 
1194
ACPI_STATUS
1200
ACPI_STATUS
1195
AcpiEvExecuteRegMethods (
1201
AcpiEvExecuteRegMethods (
1196
    ACPI_NAMESPACE_NODE     *Node,
1202
    ACPI_NAMESPACE_NODE     *Node,
1197
    ACPI_ADR_SPACE_TYPE     SpaceId)
1203
    ACPI_ADR_SPACE_TYPE     SpaceId)
1198
{
1204
{
1199
    ACPI_STATUS             Status;
1205
    ACPI_STATUS             Status;
1200
 
1206
 
1201
 
1207
 
1202
    ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
1208
    ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
1203
 
1209
 
1204
 
1210
 
1205
    /*
1211
    /*
1206
     * Run all _REG methods for all Operation Regions for this space ID. This
1212
     * Run all _REG methods for all Operation Regions for this space ID. This
1207
     * is a separate walk in order to handle any interdependencies between
1213
     * is a separate walk in order to handle any interdependencies between
1208
     * regions and _REG methods. (i.e. handlers must be installed for all
1214
     * regions and _REG methods. (i.e. handlers must be installed for all
1209
     * regions of this Space ID before we can run any _REG methods)
1215
     * regions of this Space ID before we can run any _REG methods)
1210
     */
1216
     */
1211
    Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1217
    Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1212
                ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL,
1218
                ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL,
1213
                &SpaceId, NULL);
1219
                &SpaceId, NULL);
-
 
1220
 
-
 
1221
    /* Special case for EC: handle "orphan" _REG methods with no region */
-
 
1222
 
-
 
1223
    if (SpaceId == ACPI_ADR_SPACE_EC)
-
 
1224
    {
-
 
1225
        AcpiEvOrphanEcRegMethod ();
-
 
1226
    }
1214
 
1227
 
1215
    return_ACPI_STATUS (Status);
1228
    return_ACPI_STATUS (Status);
1216
}
1229
}
1217
 
1230
 
1218
 
1231
 
1219
/*******************************************************************************
1232
/*******************************************************************************
1220
 *
1233
 *
1221
 * FUNCTION:    AcpiEvRegRun
1234
 * FUNCTION:    AcpiEvRegRun
1222
 *
1235
 *
1223
 * PARAMETERS:  WalkNamespace callback
1236
 * PARAMETERS:  WalkNamespace callback
1224
 *
1237
 *
1225
 * DESCRIPTION: Run _REG method for region objects of the requested spaceID
1238
 * DESCRIPTION: Run _REG method for region objects of the requested spaceID
1226
 *
1239
 *
1227
 ******************************************************************************/
1240
 ******************************************************************************/
1228
 
1241
 
1229
static ACPI_STATUS
1242
static ACPI_STATUS
1230
AcpiEvRegRun (
1243
AcpiEvRegRun (
1231
    ACPI_HANDLE             ObjHandle,
1244
    ACPI_HANDLE             ObjHandle,
1232
    UINT32                  Level,
1245
    UINT32                  Level,
1233
    void                    *Context,
1246
    void                    *Context,
1234
    void                    **ReturnValue)
1247
    void                    **ReturnValue)
1235
{
1248
{
1236
    ACPI_OPERAND_OBJECT     *ObjDesc;
1249
    ACPI_OPERAND_OBJECT     *ObjDesc;
1237
    ACPI_NAMESPACE_NODE     *Node;
1250
    ACPI_NAMESPACE_NODE     *Node;
1238
    ACPI_ADR_SPACE_TYPE     SpaceId;
1251
    ACPI_ADR_SPACE_TYPE     SpaceId;
1239
    ACPI_STATUS             Status;
1252
    ACPI_STATUS             Status;
1240
 
1253
 
1241
 
1254
 
1242
    SpaceId = *ACPI_CAST_PTR (ACPI_ADR_SPACE_TYPE, Context);
1255
    SpaceId = *ACPI_CAST_PTR (ACPI_ADR_SPACE_TYPE, Context);
1243
 
1256
 
1244
    /* Convert and validate the device handle */
1257
    /* Convert and validate the device handle */
1245
 
1258
 
1246
    Node = AcpiNsValidateHandle (ObjHandle);
1259
    Node = AcpiNsValidateHandle (ObjHandle);
1247
    if (!Node)
1260
    if (!Node)
1248
    {
1261
    {
1249
        return (AE_BAD_PARAMETER);
1262
        return (AE_BAD_PARAMETER);
1250
    }
1263
    }
1251
 
1264
 
1252
    /*
1265
    /*
1253
     * We only care about regions.and objects that are allowed to have address
1266
     * We only care about regions.and objects that are allowed to have address
1254
     * space handlers
1267
     * space handlers
1255
     */
1268
     */
1256
    if ((Node->Type != ACPI_TYPE_REGION) &&
1269
    if ((Node->Type != ACPI_TYPE_REGION) &&
1257
        (Node != AcpiGbl_RootNode))
1270
        (Node != AcpiGbl_RootNode))
1258
    {
1271
    {
1259
        return (AE_OK);
1272
        return (AE_OK);
1260
    }
1273
    }
1261
 
1274
 
1262
    /* Check for an existing internal object */
1275
    /* Check for an existing internal object */
1263
 
1276
 
1264
    ObjDesc = AcpiNsGetAttachedObject (Node);
1277
    ObjDesc = AcpiNsGetAttachedObject (Node);
1265
    if (!ObjDesc)
1278
    if (!ObjDesc)
1266
    {
1279
    {
1267
        /* No object, just exit */
1280
        /* No object, just exit */
1268
 
1281
 
1269
        return (AE_OK);
1282
        return (AE_OK);
1270
    }
1283
    }
1271
 
1284
 
1272
    /* Object is a Region */
1285
    /* Object is a Region */
1273
 
1286
 
1274
    if (ObjDesc->Region.SpaceId != SpaceId)
1287
    if (ObjDesc->Region.SpaceId != SpaceId)
1275
    {
1288
    {
1276
        /* This region is for a different address space, just ignore it */
1289
        /* This region is for a different address space, just ignore it */
1277
 
1290
 
1278
        return (AE_OK);
1291
        return (AE_OK);
1279
    }
1292
    }
1280
 
1293
 
1281
    Status = AcpiEvExecuteRegMethod (ObjDesc, 1);
1294
    Status = AcpiEvExecuteRegMethod (ObjDesc, ACPI_REG_CONNECT);
1282
    return (Status);
1295
    return (Status);
1283
}
1296
}
-
 
1297
 
-
 
1298
 
-
 
1299
/*******************************************************************************
-
 
1300
 *
-
 
1301
 * FUNCTION:    AcpiEvOrphanEcRegMethod
-
 
1302
 *
-
 
1303
 * PARAMETERS:  None
-
 
1304
 *
-
 
1305
 * RETURN:      None
-
 
1306
 *
-
 
1307
 * DESCRIPTION: Execute an "orphan" _REG method that appears under the EC
-
 
1308
 *              device. This is a _REG method that has no corresponding region
-
 
1309
 *              within the EC device scope. The orphan _REG method appears to
-
 
1310
 *              have been enabled by the description of the ECDT in the ACPI
-
 
1311
 *              specification: "The availability of the region space can be
-
 
1312
 *              detected by providing a _REG method object underneath the
-
 
1313
 *              Embedded Controller device."
-
 
1314
 *
-
 
1315
 *              To quickly access the EC device, we use the EC_ID that appears
-
 
1316
 *              within the ECDT. Otherwise, we would need to perform a time-
-
 
1317
 *              consuming namespace walk, executing _HID methods to find the
-
 
1318
 *              EC device.
-
 
1319
 *
-
 
1320
 ******************************************************************************/
-
 
1321
 
-
 
1322
static void
-
 
1323
AcpiEvOrphanEcRegMethod (
-
 
1324
    void)
-
 
1325
{
-
 
1326
    ACPI_TABLE_ECDT         *Table;
-
 
1327
    ACPI_STATUS             Status;
-
 
1328
    ACPI_OBJECT_LIST        Args;
-
 
1329
    ACPI_OBJECT             Objects[2];
-
 
1330
    ACPI_NAMESPACE_NODE     *EcDeviceNode;
-
 
1331
    ACPI_NAMESPACE_NODE     *RegMethod;
-
 
1332
    ACPI_NAMESPACE_NODE     *NextNode;
-
 
1333
 
-
 
1334
 
-
 
1335
    ACPI_FUNCTION_TRACE (EvOrphanEcRegMethod);
-
 
1336
 
-
 
1337
 
-
 
1338
    /* Get the ECDT (if present in system) */
-
 
1339
 
-
 
1340
    Status = AcpiGetTable (ACPI_SIG_ECDT, 0,
-
 
1341
        ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &Table));
-
 
1342
    if (ACPI_FAILURE (Status))
-
 
1343
    {
-
 
1344
        return_VOID;
-
 
1345
    }
-
 
1346
 
-
 
1347
    /* We need a valid EC_ID string */
-
 
1348
 
-
 
1349
    if (!(*Table->Id))
-
 
1350
    {
-
 
1351
        return_VOID;
-
 
1352
    }
-
 
1353
 
-
 
1354
    /* Namespace is currently locked, must release */
-
 
1355
 
-
 
1356
    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
-
 
1357
 
-
 
1358
    /* Get a handle to the EC device referenced in the ECDT */
-
 
1359
 
-
 
1360
    Status = AcpiGetHandle (NULL,
-
 
1361
        ACPI_CAST_PTR (char, Table->Id),
-
 
1362
        ACPI_CAST_PTR (ACPI_HANDLE, &EcDeviceNode));
-
 
1363
    if (ACPI_FAILURE (Status))
-
 
1364
    {
-
 
1365
        goto Exit;
-
 
1366
    }
-
 
1367
 
-
 
1368
    /* Get a handle to a _REG method immediately under the EC device */
-
 
1369
 
-
 
1370
    Status = AcpiGetHandle (EcDeviceNode,
-
 
1371
        METHOD_NAME__REG, ACPI_CAST_PTR (ACPI_HANDLE, &RegMethod));
-
 
1372
    if (ACPI_FAILURE (Status))
-
 
1373
    {
-
 
1374
        goto Exit;
-
 
1375
    }
-
 
1376
 
-
 
1377
    /*
-
 
1378
     * Execute the _REG method only if there is no Operation Region in
-
 
1379
     * this scope with the Embedded Controller space ID. Otherwise, it
-
 
1380
     * will already have been executed. Note, this allows for Regions
-
 
1381
     * with other space IDs to be present; but the code below will then
-
 
1382
     * execute the _REG method with the EC space ID argument.
-
 
1383
     */
-
 
1384
    NextNode = AcpiNsGetNextNode (EcDeviceNode, NULL);
-
 
1385
    while (NextNode)
-
 
1386
    {
-
 
1387
        if ((NextNode->Type == ACPI_TYPE_REGION) &&
-
 
1388
            (NextNode->Object) &&
-
 
1389
            (NextNode->Object->Region.SpaceId == ACPI_ADR_SPACE_EC))
-
 
1390
        {
-
 
1391
            goto Exit; /* Do not execute _REG */
-
 
1392
        }
-
 
1393
        NextNode = AcpiNsGetNextNode (EcDeviceNode, NextNode);
-
 
1394
    }
-
 
1395
 
-
 
1396
    /* Evaluate the _REG(EC,Connect) method */
-
 
1397
 
-
 
1398
    Args.Count = 2;
-
 
1399
    Args.Pointer = Objects;
-
 
1400
    Objects[0].Type = ACPI_TYPE_INTEGER;
-
 
1401
    Objects[0].Integer.Value = ACPI_ADR_SPACE_EC;
-
 
1402
    Objects[1].Type = ACPI_TYPE_INTEGER;
-
 
1403
    Objects[1].Integer.Value = ACPI_REG_CONNECT;
-
 
1404
 
-
 
1405
    Status = AcpiEvaluateObject (RegMethod, NULL, &Args, NULL);
-
 
1406
 
-
 
1407
Exit:
-
 
1408
    /* We ignore all errors from above, don't care */
-
 
1409
 
-
 
1410
    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
-
 
1411
    return_VOID;
-
 
1412
}