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