evregion.c revision 1.1.1.3.16.1 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1.1.3.16.1 rmind * Module Name: evregion - Operation Region support
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.3.16.1 rmind * Copyright (C) 2000 - 2013, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho
45 1.1 jruoho #define __EVREGION_C__
46 1.1 jruoho
47 1.1 jruoho #include "acpi.h"
48 1.1 jruoho #include "accommon.h"
49 1.1 jruoho #include "acevents.h"
50 1.1 jruoho #include "acnamesp.h"
51 1.1 jruoho #include "acinterp.h"
52 1.1 jruoho
53 1.1 jruoho #define _COMPONENT ACPI_EVENTS
54 1.1 jruoho ACPI_MODULE_NAME ("evregion")
55 1.1 jruoho
56 1.1 jruoho
57 1.1.1.3.16.1 rmind extern UINT8 AcpiGbl_DefaultAddressSpaces[];
58 1.1 jruoho
59 1.1.1.3.16.1 rmind /* Local prototypes */
60 1.1 jruoho
61 1.1.1.3 jruoho static void
62 1.1.1.3 jruoho AcpiEvOrphanEcRegMethod (
63 1.1.1.3.16.1 rmind ACPI_NAMESPACE_NODE *EcDeviceNode);
64 1.1.1.3 jruoho
65 1.1 jruoho static ACPI_STATUS
66 1.1 jruoho AcpiEvRegRun (
67 1.1 jruoho ACPI_HANDLE ObjHandle,
68 1.1 jruoho UINT32 Level,
69 1.1 jruoho void *Context,
70 1.1 jruoho void **ReturnValue);
71 1.1 jruoho
72 1.1 jruoho
73 1.1 jruoho /*******************************************************************************
74 1.1 jruoho *
75 1.1 jruoho * FUNCTION: AcpiEvInitializeOpRegions
76 1.1 jruoho *
77 1.1 jruoho * PARAMETERS: None
78 1.1 jruoho *
79 1.1 jruoho * RETURN: Status
80 1.1 jruoho *
81 1.1 jruoho * DESCRIPTION: Execute _REG methods for all Operation Regions that have
82 1.1 jruoho * an installed default region handler.
83 1.1 jruoho *
84 1.1 jruoho ******************************************************************************/
85 1.1 jruoho
86 1.1 jruoho ACPI_STATUS
87 1.1 jruoho AcpiEvInitializeOpRegions (
88 1.1 jruoho void)
89 1.1 jruoho {
90 1.1 jruoho ACPI_STATUS Status;
91 1.1 jruoho UINT32 i;
92 1.1 jruoho
93 1.1 jruoho
94 1.1 jruoho ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
95 1.1 jruoho
96 1.1 jruoho
97 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
98 1.1 jruoho if (ACPI_FAILURE (Status))
99 1.1 jruoho {
100 1.1 jruoho return_ACPI_STATUS (Status);
101 1.1 jruoho }
102 1.1 jruoho
103 1.1 jruoho /* Run the _REG methods for OpRegions in each default address space */
104 1.1 jruoho
105 1.1 jruoho for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
106 1.1 jruoho {
107 1.1 jruoho /*
108 1.1 jruoho * Make sure the installed handler is the DEFAULT handler. If not the
109 1.1 jruoho * default, the _REG methods will have already been run (when the
110 1.1 jruoho * handler was installed)
111 1.1 jruoho */
112 1.1 jruoho if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode,
113 1.1 jruoho AcpiGbl_DefaultAddressSpaces[i]))
114 1.1 jruoho {
115 1.1 jruoho Status = AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
116 1.1 jruoho AcpiGbl_DefaultAddressSpaces[i]);
117 1.1 jruoho }
118 1.1 jruoho }
119 1.1 jruoho
120 1.1.1.2 jruoho AcpiGbl_RegMethodsExecuted = TRUE;
121 1.1.1.2 jruoho
122 1.1 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
123 1.1 jruoho return_ACPI_STATUS (Status);
124 1.1 jruoho }
125 1.1 jruoho
126 1.1 jruoho
127 1.1 jruoho /*******************************************************************************
128 1.1 jruoho *
129 1.1 jruoho * FUNCTION: AcpiEvAddressSpaceDispatch
130 1.1 jruoho *
131 1.1 jruoho * PARAMETERS: RegionObj - Internal region object
132 1.1.1.3.16.1 rmind * FieldObj - Corresponding field. Can be NULL.
133 1.1 jruoho * Function - Read or Write operation
134 1.1 jruoho * RegionOffset - Where in the region to read or write
135 1.1 jruoho * BitWidth - Field width in bits (8, 16, 32, or 64)
136 1.1 jruoho * Value - Pointer to in or out value, must be
137 1.1 jruoho * a full 64-bit integer
138 1.1 jruoho *
139 1.1 jruoho * RETURN: Status
140 1.1 jruoho *
141 1.1 jruoho * DESCRIPTION: Dispatch an address space or operation region access to
142 1.1 jruoho * a previously installed handler.
143 1.1 jruoho *
144 1.1 jruoho ******************************************************************************/
145 1.1 jruoho
146 1.1 jruoho ACPI_STATUS
147 1.1 jruoho AcpiEvAddressSpaceDispatch (
148 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj,
149 1.1.1.3.16.1 rmind ACPI_OPERAND_OBJECT *FieldObj,
150 1.1 jruoho UINT32 Function,
151 1.1 jruoho UINT32 RegionOffset,
152 1.1 jruoho UINT32 BitWidth,
153 1.1 jruoho UINT64 *Value)
154 1.1 jruoho {
155 1.1 jruoho ACPI_STATUS Status;
156 1.1 jruoho ACPI_ADR_SPACE_HANDLER Handler;
157 1.1 jruoho ACPI_ADR_SPACE_SETUP RegionSetup;
158 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerDesc;
159 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj2;
160 1.1 jruoho void *RegionContext = NULL;
161 1.1.1.3.16.1 rmind ACPI_CONNECTION_INFO *Context;
162 1.1 jruoho
163 1.1 jruoho
164 1.1 jruoho ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
165 1.1 jruoho
166 1.1 jruoho
167 1.1 jruoho RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
168 1.1 jruoho if (!RegionObj2)
169 1.1 jruoho {
170 1.1 jruoho return_ACPI_STATUS (AE_NOT_EXIST);
171 1.1 jruoho }
172 1.1 jruoho
173 1.1 jruoho /* Ensure that there is a handler associated with this region */
174 1.1 jruoho
175 1.1 jruoho HandlerDesc = RegionObj->Region.Handler;
176 1.1 jruoho if (!HandlerDesc)
177 1.1 jruoho {
178 1.1 jruoho ACPI_ERROR ((AE_INFO,
179 1.1 jruoho "No handler for Region [%4.4s] (%p) [%s]",
180 1.1 jruoho AcpiUtGetNodeName (RegionObj->Region.Node),
181 1.1 jruoho RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
182 1.1 jruoho
183 1.1 jruoho return_ACPI_STATUS (AE_NOT_EXIST);
184 1.1 jruoho }
185 1.1 jruoho
186 1.1.1.3.16.1 rmind Context = HandlerDesc->AddressSpace.Context;
187 1.1.1.3.16.1 rmind
188 1.1 jruoho /*
189 1.1 jruoho * It may be the case that the region has never been initialized.
190 1.1 jruoho * Some types of regions require special init code
191 1.1 jruoho */
192 1.1 jruoho if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
193 1.1 jruoho {
194 1.1 jruoho /* This region has not been initialized yet, do it */
195 1.1 jruoho
196 1.1 jruoho RegionSetup = HandlerDesc->AddressSpace.Setup;
197 1.1 jruoho if (!RegionSetup)
198 1.1 jruoho {
199 1.1 jruoho /* No initialization routine, exit with error */
200 1.1 jruoho
201 1.1 jruoho ACPI_ERROR ((AE_INFO,
202 1.1 jruoho "No init routine for region(%p) [%s]",
203 1.1 jruoho RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
204 1.1 jruoho return_ACPI_STATUS (AE_NOT_EXIST);
205 1.1 jruoho }
206 1.1 jruoho
207 1.1 jruoho /*
208 1.1 jruoho * We must exit the interpreter because the region setup will
209 1.1 jruoho * potentially execute control methods (for example, the _REG method
210 1.1 jruoho * for this region)
211 1.1 jruoho */
212 1.1 jruoho AcpiExExitInterpreter ();
213 1.1 jruoho
214 1.1 jruoho Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
215 1.1.1.3.16.1 rmind Context, &RegionContext);
216 1.1 jruoho
217 1.1 jruoho /* Re-enter the interpreter */
218 1.1 jruoho
219 1.1 jruoho AcpiExEnterInterpreter ();
220 1.1 jruoho
221 1.1 jruoho /* Check for failure of the Region Setup */
222 1.1 jruoho
223 1.1 jruoho if (ACPI_FAILURE (Status))
224 1.1 jruoho {
225 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
226 1.1 jruoho "During region initialization: [%s]",
227 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
228 1.1 jruoho return_ACPI_STATUS (Status);
229 1.1 jruoho }
230 1.1 jruoho
231 1.1 jruoho /* Region initialization may have been completed by RegionSetup */
232 1.1 jruoho
233 1.1 jruoho if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
234 1.1 jruoho {
235 1.1 jruoho RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
236 1.1 jruoho
237 1.1.1.3.16.1 rmind /*
238 1.1.1.3.16.1 rmind * Save the returned context for use in all accesses to
239 1.1.1.3.16.1 rmind * the handler for this particular region
240 1.1.1.3.16.1 rmind */
241 1.1.1.3.16.1 rmind if (!(RegionObj2->Extra.RegionContext))
242 1.1 jruoho {
243 1.1 jruoho RegionObj2->Extra.RegionContext = RegionContext;
244 1.1 jruoho }
245 1.1 jruoho }
246 1.1 jruoho }
247 1.1 jruoho
248 1.1 jruoho /* We have everything we need, we can invoke the address space handler */
249 1.1 jruoho
250 1.1 jruoho Handler = HandlerDesc->AddressSpace.Handler;
251 1.1 jruoho
252 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
253 1.1 jruoho "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
254 1.1 jruoho &RegionObj->Region.Handler->AddressSpace, Handler,
255 1.1 jruoho ACPI_FORMAT_NATIVE_UINT (RegionObj->Region.Address + RegionOffset),
256 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
257 1.1 jruoho
258 1.1.1.3.16.1 rmind /*
259 1.1.1.3.16.1 rmind * Special handling for GenericSerialBus and GeneralPurposeIo:
260 1.1.1.3.16.1 rmind * There are three extra parameters that must be passed to the
261 1.1.1.3.16.1 rmind * handler via the context:
262 1.1.1.3.16.1 rmind * 1) Connection buffer, a resource template from Connection() op.
263 1.1.1.3.16.1 rmind * 2) Length of the above buffer.
264 1.1.1.3.16.1 rmind * 3) Actual access length from the AccessAs() op.
265 1.1.1.3.16.1 rmind */
266 1.1.1.3.16.1 rmind if (((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS) ||
267 1.1.1.3.16.1 rmind (RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO)) &&
268 1.1.1.3.16.1 rmind Context &&
269 1.1.1.3.16.1 rmind FieldObj)
270 1.1.1.3.16.1 rmind {
271 1.1.1.3.16.1 rmind /* Get the Connection (ResourceTemplate) buffer */
272 1.1.1.3.16.1 rmind
273 1.1.1.3.16.1 rmind Context->Connection = FieldObj->Field.ResourceBuffer;
274 1.1.1.3.16.1 rmind Context->Length = FieldObj->Field.ResourceLength;
275 1.1.1.3.16.1 rmind Context->AccessLength = FieldObj->Field.AccessLength;
276 1.1.1.3.16.1 rmind }
277 1.1.1.3.16.1 rmind
278 1.1 jruoho if (!(HandlerDesc->AddressSpace.HandlerFlags &
279 1.1 jruoho ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
280 1.1 jruoho {
281 1.1 jruoho /*
282 1.1 jruoho * For handlers other than the default (supplied) handlers, we must
283 1.1 jruoho * exit the interpreter because the handler *might* block -- we don't
284 1.1 jruoho * know what it will do, so we can't hold the lock on the intepreter.
285 1.1 jruoho */
286 1.1 jruoho AcpiExExitInterpreter();
287 1.1 jruoho }
288 1.1 jruoho
289 1.1 jruoho /* Call the handler */
290 1.1 jruoho
291 1.1 jruoho Status = Handler (Function,
292 1.1 jruoho (RegionObj->Region.Address + RegionOffset), BitWidth, Value,
293 1.1.1.3.16.1 rmind Context, RegionObj2->Extra.RegionContext);
294 1.1 jruoho
295 1.1 jruoho if (ACPI_FAILURE (Status))
296 1.1 jruoho {
297 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
298 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
299 1.1 jruoho }
300 1.1 jruoho
301 1.1 jruoho if (!(HandlerDesc->AddressSpace.HandlerFlags &
302 1.1 jruoho ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
303 1.1 jruoho {
304 1.1 jruoho /*
305 1.1 jruoho * We just returned from a non-default handler, we must re-enter the
306 1.1 jruoho * interpreter
307 1.1 jruoho */
308 1.1 jruoho AcpiExEnterInterpreter ();
309 1.1 jruoho }
310 1.1 jruoho
311 1.1 jruoho return_ACPI_STATUS (Status);
312 1.1 jruoho }
313 1.1 jruoho
314 1.1 jruoho
315 1.1 jruoho /*******************************************************************************
316 1.1 jruoho *
317 1.1 jruoho * FUNCTION: AcpiEvDetachRegion
318 1.1 jruoho *
319 1.1 jruoho * PARAMETERS: RegionObj - Region Object
320 1.1 jruoho * AcpiNsIsLocked - Namespace Region Already Locked?
321 1.1 jruoho *
322 1.1 jruoho * RETURN: None
323 1.1 jruoho *
324 1.1 jruoho * DESCRIPTION: Break the association between the handler and the region
325 1.1 jruoho * this is a two way association.
326 1.1 jruoho *
327 1.1 jruoho ******************************************************************************/
328 1.1 jruoho
329 1.1 jruoho void
330 1.1 jruoho AcpiEvDetachRegion(
331 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj,
332 1.1 jruoho BOOLEAN AcpiNsIsLocked)
333 1.1 jruoho {
334 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerObj;
335 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
336 1.1 jruoho ACPI_OPERAND_OBJECT **LastObjPtr;
337 1.1 jruoho ACPI_ADR_SPACE_SETUP RegionSetup;
338 1.1 jruoho void **RegionContext;
339 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj2;
340 1.1 jruoho ACPI_STATUS Status;
341 1.1 jruoho
342 1.1 jruoho
343 1.1 jruoho ACPI_FUNCTION_TRACE (EvDetachRegion);
344 1.1 jruoho
345 1.1 jruoho
346 1.1 jruoho RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
347 1.1 jruoho if (!RegionObj2)
348 1.1 jruoho {
349 1.1 jruoho return_VOID;
350 1.1 jruoho }
351 1.1 jruoho RegionContext = &RegionObj2->Extra.RegionContext;
352 1.1 jruoho
353 1.1 jruoho /* Get the address handler from the region object */
354 1.1 jruoho
355 1.1 jruoho HandlerObj = RegionObj->Region.Handler;
356 1.1 jruoho if (!HandlerObj)
357 1.1 jruoho {
358 1.1 jruoho /* This region has no handler, all done */
359 1.1 jruoho
360 1.1 jruoho return_VOID;
361 1.1 jruoho }
362 1.1 jruoho
363 1.1 jruoho /* Find this region in the handler's list */
364 1.1 jruoho
365 1.1 jruoho ObjDesc = HandlerObj->AddressSpace.RegionList;
366 1.1 jruoho LastObjPtr = &HandlerObj->AddressSpace.RegionList;
367 1.1 jruoho
368 1.1 jruoho while (ObjDesc)
369 1.1 jruoho {
370 1.1 jruoho /* Is this the correct Region? */
371 1.1 jruoho
372 1.1 jruoho if (ObjDesc == RegionObj)
373 1.1 jruoho {
374 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
375 1.1 jruoho "Removing Region %p from address handler %p\n",
376 1.1 jruoho RegionObj, HandlerObj));
377 1.1 jruoho
378 1.1 jruoho /* This is it, remove it from the handler's list */
379 1.1 jruoho
380 1.1 jruoho *LastObjPtr = ObjDesc->Region.Next;
381 1.1 jruoho ObjDesc->Region.Next = NULL; /* Must clear field */
382 1.1 jruoho
383 1.1 jruoho if (AcpiNsIsLocked)
384 1.1 jruoho {
385 1.1 jruoho Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
386 1.1 jruoho if (ACPI_FAILURE (Status))
387 1.1 jruoho {
388 1.1 jruoho return_VOID;
389 1.1 jruoho }
390 1.1 jruoho }
391 1.1 jruoho
392 1.1 jruoho /* Now stop region accesses by executing the _REG method */
393 1.1 jruoho
394 1.1.1.3 jruoho Status = AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_DISCONNECT);
395 1.1 jruoho if (ACPI_FAILURE (Status))
396 1.1 jruoho {
397 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
398 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
399 1.1 jruoho }
400 1.1 jruoho
401 1.1 jruoho if (AcpiNsIsLocked)
402 1.1 jruoho {
403 1.1 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
404 1.1 jruoho if (ACPI_FAILURE (Status))
405 1.1 jruoho {
406 1.1 jruoho return_VOID;
407 1.1 jruoho }
408 1.1 jruoho }
409 1.1 jruoho
410 1.1 jruoho /*
411 1.1 jruoho * If the region has been activated, call the setup handler with
412 1.1 jruoho * the deactivate notification
413 1.1 jruoho */
414 1.1 jruoho if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
415 1.1 jruoho {
416 1.1 jruoho RegionSetup = HandlerObj->AddressSpace.Setup;
417 1.1 jruoho Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
418 1.1 jruoho HandlerObj->AddressSpace.Context, RegionContext);
419 1.1 jruoho
420 1.1.1.3.16.1 rmind /*
421 1.1.1.3.16.1 rmind * RegionContext should have been released by the deactivate
422 1.1.1.3.16.1 rmind * operation. We don't need access to it anymore here.
423 1.1.1.3.16.1 rmind */
424 1.1.1.3.16.1 rmind if (RegionContext)
425 1.1.1.3.16.1 rmind {
426 1.1.1.3.16.1 rmind *RegionContext = NULL;
427 1.1.1.3.16.1 rmind }
428 1.1.1.3.16.1 rmind
429 1.1 jruoho /* Init routine may fail, Just ignore errors */
430 1.1 jruoho
431 1.1 jruoho if (ACPI_FAILURE (Status))
432 1.1 jruoho {
433 1.1 jruoho ACPI_EXCEPTION ((AE_INFO, Status,
434 1.1 jruoho "from region handler - deactivate, [%s]",
435 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
436 1.1 jruoho }
437 1.1 jruoho
438 1.1 jruoho RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
439 1.1 jruoho }
440 1.1 jruoho
441 1.1 jruoho /*
442 1.1 jruoho * Remove handler reference in the region
443 1.1 jruoho *
444 1.1 jruoho * NOTE: this doesn't mean that the region goes away, the region
445 1.1 jruoho * is just inaccessible as indicated to the _REG method
446 1.1 jruoho *
447 1.1 jruoho * If the region is on the handler's list, this must be the
448 1.1 jruoho * region's handler
449 1.1 jruoho */
450 1.1 jruoho RegionObj->Region.Handler = NULL;
451 1.1 jruoho AcpiUtRemoveReference (HandlerObj);
452 1.1 jruoho
453 1.1 jruoho return_VOID;
454 1.1 jruoho }
455 1.1 jruoho
456 1.1 jruoho /* Walk the linked list of handlers */
457 1.1 jruoho
458 1.1 jruoho LastObjPtr = &ObjDesc->Region.Next;
459 1.1 jruoho ObjDesc = ObjDesc->Region.Next;
460 1.1 jruoho }
461 1.1 jruoho
462 1.1 jruoho /* If we get here, the region was not in the handler's region list */
463 1.1 jruoho
464 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
465 1.1 jruoho "Cannot remove region %p from address handler %p\n",
466 1.1 jruoho RegionObj, HandlerObj));
467 1.1 jruoho
468 1.1 jruoho return_VOID;
469 1.1 jruoho }
470 1.1 jruoho
471 1.1 jruoho
472 1.1 jruoho /*******************************************************************************
473 1.1 jruoho *
474 1.1 jruoho * FUNCTION: AcpiEvAttachRegion
475 1.1 jruoho *
476 1.1 jruoho * PARAMETERS: HandlerObj - Handler Object
477 1.1 jruoho * RegionObj - Region Object
478 1.1 jruoho * AcpiNsIsLocked - Namespace Region Already Locked?
479 1.1 jruoho *
480 1.1 jruoho * RETURN: None
481 1.1 jruoho *
482 1.1 jruoho * DESCRIPTION: Create the association between the handler and the region
483 1.1 jruoho * this is a two way association.
484 1.1 jruoho *
485 1.1 jruoho ******************************************************************************/
486 1.1 jruoho
487 1.1 jruoho ACPI_STATUS
488 1.1 jruoho AcpiEvAttachRegion (
489 1.1 jruoho ACPI_OPERAND_OBJECT *HandlerObj,
490 1.1 jruoho ACPI_OPERAND_OBJECT *RegionObj,
491 1.1 jruoho BOOLEAN AcpiNsIsLocked)
492 1.1 jruoho {
493 1.1 jruoho
494 1.1 jruoho ACPI_FUNCTION_TRACE (EvAttachRegion);
495 1.1 jruoho
496 1.1 jruoho
497 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
498 1.1 jruoho "Adding Region [%4.4s] %p to address handler %p [%s]\n",
499 1.1 jruoho AcpiUtGetNodeName (RegionObj->Region.Node),
500 1.1 jruoho RegionObj, HandlerObj,
501 1.1 jruoho AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
502 1.1 jruoho
503 1.1 jruoho /* Link this region to the front of the handler's list */
504 1.1 jruoho
505 1.1 jruoho RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
506 1.1 jruoho HandlerObj->AddressSpace.RegionList = RegionObj;
507 1.1 jruoho
508 1.1 jruoho /* Install the region's handler */
509 1.1 jruoho
510 1.1 jruoho if (RegionObj->Region.Handler)
511 1.1 jruoho {
512 1.1 jruoho return_ACPI_STATUS (AE_ALREADY_EXISTS);
513 1.1 jruoho }
514 1.1 jruoho
515 1.1 jruoho RegionObj->Region.Handler = HandlerObj;
516 1.1 jruoho AcpiUtAddReference (HandlerObj);
517 1.1 jruoho
518 1.1 jruoho return_ACPI_STATUS (AE_OK);
519 1.1 jruoho }
520 1.1 jruoho
521 1.1 jruoho
522 1.1 jruoho /*******************************************************************************
523 1.1 jruoho *
524 1.1.1.3.16.1 rmind * FUNCTION: AcpiEvExecuteRegMethod
525 1.1 jruoho *
526 1.1.1.3.16.1 rmind * PARAMETERS: RegionObj - Region object
527 1.1.1.3.16.1 rmind * Function - Passed to _REG: On (1) or Off (0)
528 1.1 jruoho *
529 1.1 jruoho * RETURN: Status
530 1.1 jruoho *
531 1.1.1.3.16.1 rmind * DESCRIPTION: Execute _REG method for a region
532 1.1 jruoho *
533 1.1 jruoho ******************************************************************************/
534 1.1 jruoho
535 1.1 jruoho ACPI_STATUS
536 1.1.1.3.16.1 rmind AcpiEvExecuteRegMethod (
537 1.1.1.3.16.1 rmind ACPI_OPERAND_OBJECT *RegionObj,
538 1.1.1.3.16.1 rmind UINT32 Function)
539 1.1 jruoho {
540 1.1.1.3.16.1 rmind ACPI_EVALUATE_INFO *Info;
541 1.1.1.3.16.1 rmind ACPI_OPERAND_OBJECT *Args[3];
542 1.1.1.3.16.1 rmind ACPI_OPERAND_OBJECT *RegionObj2;
543 1.1 jruoho ACPI_STATUS Status;
544 1.1 jruoho
545 1.1 jruoho
546 1.1.1.3.16.1 rmind ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
547 1.1 jruoho
548 1.1 jruoho
549 1.1.1.3.16.1 rmind RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
550 1.1.1.3.16.1 rmind if (!RegionObj2)
551 1.1 jruoho {
552 1.1.1.3.16.1 rmind return_ACPI_STATUS (AE_NOT_EXIST);
553 1.1 jruoho }
554 1.1 jruoho
555 1.1.1.3.16.1 rmind if (RegionObj2->Extra.Method_REG == NULL)
556 1.1 jruoho {
557 1.1.1.3.16.1 rmind return_ACPI_STATUS (AE_OK);
558 1.1 jruoho }
559 1.1 jruoho
560 1.1.1.3.16.1 rmind /* Allocate and initialize the evaluation information block */
561 1.1 jruoho
562 1.1.1.3.16.1 rmind Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
563 1.1.1.3.16.1 rmind if (!Info)
564 1.1 jruoho {
565 1.1.1.3.16.1 rmind return_ACPI_STATUS (AE_NO_MEMORY);
566 1.1 jruoho }
567 1.1 jruoho
568 1.1.1.3.16.1 rmind Info->PrefixNode = RegionObj2->Extra.Method_REG;
569 1.1.1.3.16.1 rmind Info->RelativePathname = NULL;
570 1.1.1.3.16.1 rmind Info->Parameters = Args;
571 1.1.1.3.16.1 rmind Info->Flags = ACPI_IGNORE_RETURN_VALUE;
572 1.1 jruoho
573 1.1 jruoho /*
574 1.1.1.3.16.1 rmind * The _REG method has two arguments:
575 1.1.1.3.16.1 rmind *
576 1.1.1.3.16.1 rmind * Arg0 - Integer:
577 1.1.1.3.16.1 rmind * Operation region space ID Same value as RegionObj->Region.SpaceId
578 1.1 jruoho *
579 1.1.1.3.16.1 rmind * Arg1 - Integer:
580 1.1.1.3.16.1 rmind * connection status 1 for connecting the handler, 0 for disconnecting
581 1.1.1.3.16.1 rmind * the handler (Passed as a parameter)
582 1.1 jruoho */
583 1.1.1.3.16.1 rmind Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId);
584 1.1.1.3.16.1 rmind if (!Args[0])
585 1.1 jruoho {
586 1.1 jruoho Status = AE_NO_MEMORY;
587 1.1.1.3.16.1 rmind goto Cleanup1;
588 1.1 jruoho }
589 1.1 jruoho
590 1.1.1.3.16.1 rmind Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function);
591 1.1.1.3.16.1 rmind if (!Args[1])
592 1.1.1.3.16.1 rmind {
593 1.1.1.3.16.1 rmind Status = AE_NO_MEMORY;
594 1.1.1.3.16.1 rmind goto Cleanup2;
595 1.1.1.3.16.1 rmind }
596 1.1 jruoho
597 1.1.1.3.16.1 rmind Args[2] = NULL; /* Terminate list */
598 1.1 jruoho
599 1.1.1.3.16.1 rmind /* Execute the method, no return value */
600 1.1 jruoho
601 1.1.1.3.16.1 rmind ACPI_DEBUG_EXEC (
602 1.1.1.3.16.1 rmind AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
603 1.1 jruoho
604 1.1.1.3.16.1 rmind Status = AcpiNsEvaluate (Info);
605 1.1.1.3.16.1 rmind AcpiUtRemoveReference (Args[1]);
606 1.1 jruoho
607 1.1.1.3.16.1 rmind Cleanup2:
608 1.1.1.3.16.1 rmind AcpiUtRemoveReference (Args[0]);
609 1.1 jruoho
610 1.1.1.3.16.1 rmind Cleanup1:
611 1.1.1.3.16.1 rmind ACPI_FREE (Info);
612 1.1 jruoho return_ACPI_STATUS (Status);
613 1.1 jruoho }
614 1.1 jruoho
615 1.1 jruoho
616 1.1 jruoho /*******************************************************************************
617 1.1 jruoho *
618 1.1 jruoho * FUNCTION: AcpiEvExecuteRegMethods
619 1.1 jruoho *
620 1.1 jruoho * PARAMETERS: Node - Namespace node for the device
621 1.1 jruoho * SpaceId - The address space ID
622 1.1 jruoho *
623 1.1 jruoho * RETURN: Status
624 1.1 jruoho *
625 1.1 jruoho * DESCRIPTION: Run all _REG methods for the input Space ID;
626 1.1 jruoho * Note: assumes namespace is locked, or system init time.
627 1.1 jruoho *
628 1.1 jruoho ******************************************************************************/
629 1.1 jruoho
630 1.1 jruoho ACPI_STATUS
631 1.1 jruoho AcpiEvExecuteRegMethods (
632 1.1 jruoho ACPI_NAMESPACE_NODE *Node,
633 1.1 jruoho ACPI_ADR_SPACE_TYPE SpaceId)
634 1.1 jruoho {
635 1.1 jruoho ACPI_STATUS Status;
636 1.1 jruoho
637 1.1 jruoho
638 1.1 jruoho ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
639 1.1 jruoho
640 1.1 jruoho
641 1.1 jruoho /*
642 1.1 jruoho * Run all _REG methods for all Operation Regions for this space ID. This
643 1.1 jruoho * is a separate walk in order to handle any interdependencies between
644 1.1 jruoho * regions and _REG methods. (i.e. handlers must be installed for all
645 1.1 jruoho * regions of this Space ID before we can run any _REG methods)
646 1.1 jruoho */
647 1.1 jruoho Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
648 1.1 jruoho ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL,
649 1.1 jruoho &SpaceId, NULL);
650 1.1 jruoho
651 1.1.1.3 jruoho /* Special case for EC: handle "orphan" _REG methods with no region */
652 1.1.1.3 jruoho
653 1.1.1.3 jruoho if (SpaceId == ACPI_ADR_SPACE_EC)
654 1.1.1.3 jruoho {
655 1.1.1.3.16.1 rmind AcpiEvOrphanEcRegMethod (Node);
656 1.1.1.3 jruoho }
657 1.1.1.3 jruoho
658 1.1 jruoho return_ACPI_STATUS (Status);
659 1.1 jruoho }
660 1.1 jruoho
661 1.1 jruoho
662 1.1 jruoho /*******************************************************************************
663 1.1 jruoho *
664 1.1 jruoho * FUNCTION: AcpiEvRegRun
665 1.1 jruoho *
666 1.1 jruoho * PARAMETERS: WalkNamespace callback
667 1.1 jruoho *
668 1.1 jruoho * DESCRIPTION: Run _REG method for region objects of the requested spaceID
669 1.1 jruoho *
670 1.1 jruoho ******************************************************************************/
671 1.1 jruoho
672 1.1 jruoho static ACPI_STATUS
673 1.1 jruoho AcpiEvRegRun (
674 1.1 jruoho ACPI_HANDLE ObjHandle,
675 1.1 jruoho UINT32 Level,
676 1.1 jruoho void *Context,
677 1.1 jruoho void **ReturnValue)
678 1.1 jruoho {
679 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc;
680 1.1 jruoho ACPI_NAMESPACE_NODE *Node;
681 1.1 jruoho ACPI_ADR_SPACE_TYPE SpaceId;
682 1.1 jruoho ACPI_STATUS Status;
683 1.1 jruoho
684 1.1 jruoho
685 1.1 jruoho SpaceId = *ACPI_CAST_PTR (ACPI_ADR_SPACE_TYPE, Context);
686 1.1 jruoho
687 1.1 jruoho /* Convert and validate the device handle */
688 1.1 jruoho
689 1.1 jruoho Node = AcpiNsValidateHandle (ObjHandle);
690 1.1 jruoho if (!Node)
691 1.1 jruoho {
692 1.1 jruoho return (AE_BAD_PARAMETER);
693 1.1 jruoho }
694 1.1 jruoho
695 1.1 jruoho /*
696 1.1 jruoho * We only care about regions.and objects that are allowed to have address
697 1.1 jruoho * space handlers
698 1.1 jruoho */
699 1.1 jruoho if ((Node->Type != ACPI_TYPE_REGION) &&
700 1.1 jruoho (Node != AcpiGbl_RootNode))
701 1.1 jruoho {
702 1.1 jruoho return (AE_OK);
703 1.1 jruoho }
704 1.1 jruoho
705 1.1 jruoho /* Check for an existing internal object */
706 1.1 jruoho
707 1.1 jruoho ObjDesc = AcpiNsGetAttachedObject (Node);
708 1.1 jruoho if (!ObjDesc)
709 1.1 jruoho {
710 1.1 jruoho /* No object, just exit */
711 1.1 jruoho
712 1.1 jruoho return (AE_OK);
713 1.1 jruoho }
714 1.1 jruoho
715 1.1 jruoho /* Object is a Region */
716 1.1 jruoho
717 1.1 jruoho if (ObjDesc->Region.SpaceId != SpaceId)
718 1.1 jruoho {
719 1.1 jruoho /* This region is for a different address space, just ignore it */
720 1.1 jruoho
721 1.1 jruoho return (AE_OK);
722 1.1 jruoho }
723 1.1 jruoho
724 1.1.1.3 jruoho Status = AcpiEvExecuteRegMethod (ObjDesc, ACPI_REG_CONNECT);
725 1.1 jruoho return (Status);
726 1.1 jruoho }
727 1.1 jruoho
728 1.1.1.3 jruoho
729 1.1.1.3 jruoho /*******************************************************************************
730 1.1.1.3 jruoho *
731 1.1.1.3 jruoho * FUNCTION: AcpiEvOrphanEcRegMethod
732 1.1.1.3 jruoho *
733 1.1.1.3.16.1 rmind * PARAMETERS: EcDeviceNode - Namespace node for an EC device
734 1.1.1.3 jruoho *
735 1.1.1.3 jruoho * RETURN: None
736 1.1.1.3 jruoho *
737 1.1.1.3 jruoho * DESCRIPTION: Execute an "orphan" _REG method that appears under the EC
738 1.1.1.3 jruoho * device. This is a _REG method that has no corresponding region
739 1.1.1.3 jruoho * within the EC device scope. The orphan _REG method appears to
740 1.1.1.3 jruoho * have been enabled by the description of the ECDT in the ACPI
741 1.1.1.3 jruoho * specification: "The availability of the region space can be
742 1.1.1.3 jruoho * detected by providing a _REG method object underneath the
743 1.1.1.3 jruoho * Embedded Controller device."
744 1.1.1.3 jruoho *
745 1.1.1.3.16.1 rmind * To quickly access the EC device, we use the EcDeviceNode used
746 1.1.1.3.16.1 rmind * during EC handler installation. Otherwise, we would need to
747 1.1.1.3.16.1 rmind * perform a time consuming namespace walk, executing _HID
748 1.1.1.3.16.1 rmind * methods to find the EC device.
749 1.1.1.3.16.1 rmind *
750 1.1.1.3.16.1 rmind * MUTEX: Assumes the namespace is locked
751 1.1.1.3 jruoho *
752 1.1.1.3 jruoho ******************************************************************************/
753 1.1.1.3 jruoho
754 1.1.1.3 jruoho static void
755 1.1.1.3 jruoho AcpiEvOrphanEcRegMethod (
756 1.1.1.3.16.1 rmind ACPI_NAMESPACE_NODE *EcDeviceNode)
757 1.1.1.3 jruoho {
758 1.1.1.3.16.1 rmind ACPI_HANDLE RegMethod;
759 1.1.1.3.16.1 rmind ACPI_NAMESPACE_NODE *NextNode;
760 1.1.1.3 jruoho ACPI_STATUS Status;
761 1.1.1.3 jruoho ACPI_OBJECT_LIST Args;
762 1.1.1.3 jruoho ACPI_OBJECT Objects[2];
763 1.1.1.3 jruoho
764 1.1.1.3 jruoho
765 1.1.1.3 jruoho ACPI_FUNCTION_TRACE (EvOrphanEcRegMethod);
766 1.1.1.3 jruoho
767 1.1.1.3 jruoho
768 1.1.1.3.16.1 rmind if (!EcDeviceNode)
769 1.1.1.3 jruoho {
770 1.1.1.3 jruoho return_VOID;
771 1.1.1.3 jruoho }
772 1.1.1.3 jruoho
773 1.1.1.3 jruoho /* Namespace is currently locked, must release */
774 1.1.1.3 jruoho
775 1.1.1.3 jruoho (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
776 1.1.1.3 jruoho
777 1.1.1.3 jruoho /* Get a handle to a _REG method immediately under the EC device */
778 1.1.1.3 jruoho
779 1.1.1.3.16.1 rmind Status = AcpiGetHandle (EcDeviceNode, METHOD_NAME__REG, &RegMethod);
780 1.1.1.3 jruoho if (ACPI_FAILURE (Status))
781 1.1.1.3 jruoho {
782 1.1.1.3.16.1 rmind goto Exit; /* There is no _REG method present */
783 1.1.1.3 jruoho }
784 1.1.1.3 jruoho
785 1.1.1.3 jruoho /*
786 1.1.1.3 jruoho * Execute the _REG method only if there is no Operation Region in
787 1.1.1.3 jruoho * this scope with the Embedded Controller space ID. Otherwise, it
788 1.1.1.3 jruoho * will already have been executed. Note, this allows for Regions
789 1.1.1.3 jruoho * with other space IDs to be present; but the code below will then
790 1.1.1.3.16.1 rmind * execute the _REG method with the EmbeddedControl SpaceID argument.
791 1.1.1.3 jruoho */
792 1.1.1.3 jruoho NextNode = AcpiNsGetNextNode (EcDeviceNode, NULL);
793 1.1.1.3 jruoho while (NextNode)
794 1.1.1.3 jruoho {
795 1.1.1.3 jruoho if ((NextNode->Type == ACPI_TYPE_REGION) &&
796 1.1.1.3 jruoho (NextNode->Object) &&
797 1.1.1.3 jruoho (NextNode->Object->Region.SpaceId == ACPI_ADR_SPACE_EC))
798 1.1.1.3 jruoho {
799 1.1.1.3.16.1 rmind goto Exit; /* Do not execute the _REG */
800 1.1.1.3 jruoho }
801 1.1.1.3.16.1 rmind
802 1.1.1.3 jruoho NextNode = AcpiNsGetNextNode (EcDeviceNode, NextNode);
803 1.1.1.3 jruoho }
804 1.1.1.3 jruoho
805 1.1.1.3.16.1 rmind /* Evaluate the _REG(EmbeddedControl,Connect) method */
806 1.1.1.3 jruoho
807 1.1.1.3 jruoho Args.Count = 2;
808 1.1.1.3 jruoho Args.Pointer = Objects;
809 1.1.1.3 jruoho Objects[0].Type = ACPI_TYPE_INTEGER;
810 1.1.1.3 jruoho Objects[0].Integer.Value = ACPI_ADR_SPACE_EC;
811 1.1.1.3 jruoho Objects[1].Type = ACPI_TYPE_INTEGER;
812 1.1.1.3 jruoho Objects[1].Integer.Value = ACPI_REG_CONNECT;
813 1.1.1.3 jruoho
814 1.1.1.3 jruoho Status = AcpiEvaluateObject (RegMethod, NULL, &Args, NULL);
815 1.1.1.3 jruoho
816 1.1.1.3 jruoho Exit:
817 1.1.1.3 jruoho /* We ignore all errors from above, don't care */
818 1.1.1.3 jruoho
819 1.1.1.3 jruoho Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
820 1.1.1.3 jruoho return_VOID;
821 1.1.1.3 jruoho }
822