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