Sync usage with man page.
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / tools / acpiexec / aehandlers.c
bloba108fde02e065289280de30e67ac5d6b459f02a2
1 /******************************************************************************
3 * Module Name: aehandlers - Various handlers for acpiexec
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
14 * 2. License
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.
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
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;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
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.
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.
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.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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.
80 * 4. Disclaimer and Export Compliance
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.
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.
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.
114 *****************************************************************************/
116 #include "aecommon.h"
118 #define _COMPONENT ACPI_TOOLS
119 ACPI_MODULE_NAME ("aehandlers")
121 /* Local prototypes */
123 void
124 AeNotifyHandler (
125 ACPI_HANDLE Device,
126 UINT32 Value,
127 void *Context);
129 void
130 AeDeviceNotifyHandler (
131 ACPI_HANDLE Device,
132 UINT32 Value,
133 void *Context);
135 ACPI_STATUS
136 AeExceptionHandler (
137 ACPI_STATUS AmlStatus,
138 ACPI_NAME Name,
139 UINT16 Opcode,
140 UINT32 AmlOffset,
141 void *Context);
143 ACPI_STATUS
144 AeTableHandler (
145 UINT32 Event,
146 void *Table,
147 void *Context);
149 ACPI_STATUS
150 AeRegionInit (
151 ACPI_HANDLE RegionHandle,
152 UINT32 Function,
153 void *HandlerContext,
154 void **RegionContext);
156 void
157 AeAttachedDataHandler (
158 ACPI_HANDLE Object,
159 void *Data);
161 UINT32 SigintCount = 0;
162 AE_DEBUG_REGIONS AeRegions;
165 /******************************************************************************
167 * FUNCTION: AeCtrlCHandler
169 * PARAMETERS: Sig
171 * RETURN: none
173 * DESCRIPTION: Control-C handler. Abort running control method if any.
175 *****************************************************************************/
177 void __cdecl
178 AeCtrlCHandler (
179 int Sig)
182 signal (SIGINT, SIG_IGN);
183 SigintCount++;
185 AcpiOsPrintf ("Caught a ctrl-c (#%d)\n\n", SigintCount);
187 if (AcpiGbl_MethodExecuting)
189 AcpiGbl_AbortMethod = TRUE;
190 signal (SIGINT, AeCtrlCHandler);
192 if (SigintCount < 10)
194 return;
198 exit (0);
202 /******************************************************************************
204 * FUNCTION: AeNotifyHandler
206 * PARAMETERS: Standard notify handler parameters
208 * RETURN: Status
210 * DESCRIPTION: System notify handler for AcpiExec utility. Used by the ASL
211 * test suite(s) to communicate errors and other information to
212 * this utility via the Notify() operator.
214 *****************************************************************************/
216 void
217 AeNotifyHandler (
218 ACPI_HANDLE Device,
219 UINT32 Value,
220 void *Context)
223 switch (Value)
225 #if 0
226 case 0:
227 printf ("[AcpiExec] Method Error 0x%X: Results not equal\n", Value);
228 if (AcpiGbl_DebugFile)
230 AcpiOsPrintf ("[AcpiExec] Method Error: Results not equal\n");
232 break;
235 case 1:
236 printf ("[AcpiExec] Method Error: Incorrect numeric result\n");
237 if (AcpiGbl_DebugFile)
239 AcpiOsPrintf ("[AcpiExec] Method Error: Incorrect numeric result\n");
241 break;
244 case 2:
245 printf ("[AcpiExec] Method Error: An operand was overwritten\n");
246 if (AcpiGbl_DebugFile)
248 AcpiOsPrintf ("[AcpiExec] Method Error: An operand was overwritten\n");
250 break;
252 #endif
254 default:
255 printf ("[AcpiExec] Received a System Notify on [%4.4s] %p Value 0x%2.2X (%s)\n",
256 AcpiUtGetNodeName (Device), Device, Value,
257 AcpiUtGetNotifyName (Value));
258 if (AcpiGbl_DebugFile)
260 AcpiOsPrintf ("[AcpiExec] Received a system notify, Value 0x%2.2X\n", Value);
263 (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL);
264 break;
270 /******************************************************************************
272 * FUNCTION: AeDeviceNotifyHandler
274 * PARAMETERS: Standard notify handler parameters
276 * RETURN: Status
278 * DESCRIPTION: Device notify handler for AcpiExec utility. Used by the ASL
279 * test suite(s) to communicate errors and other information to
280 * this utility via the Notify() operator.
282 *****************************************************************************/
284 void
285 AeDeviceNotifyHandler (
286 ACPI_HANDLE Device,
287 UINT32 Value,
288 void *Context)
291 printf ("[AcpiExec] Received a Device Notify on [%4.4s] %p Value 0x%2.2X (%s)\n",
292 AcpiUtGetNodeName (Device), Device, Value,
293 AcpiUtGetNotifyName (Value));
294 if (AcpiGbl_DebugFile)
296 AcpiOsPrintf ("[AcpiExec] Received a device notify, Value 0x%2.2X\n", Value);
299 (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL);
303 /******************************************************************************
305 * FUNCTION: AeExceptionHandler
307 * PARAMETERS: Standard exception handler parameters
309 * RETURN: Status
311 * DESCRIPTION: System exception handler for AcpiExec utility.
313 *****************************************************************************/
315 ACPI_STATUS
316 AeExceptionHandler (
317 ACPI_STATUS AmlStatus,
318 ACPI_NAME Name,
319 UINT16 Opcode,
320 UINT32 AmlOffset,
321 void *Context)
323 ACPI_STATUS NewAmlStatus = AmlStatus;
324 ACPI_STATUS Status;
325 ACPI_BUFFER ReturnObj;
326 ACPI_OBJECT_LIST ArgList;
327 ACPI_OBJECT Arg[3];
328 const char *Exception;
331 Exception = AcpiFormatException (AmlStatus);
332 AcpiOsPrintf ("[AcpiExec] Exception %s during execution ", Exception);
333 if (Name)
335 AcpiOsPrintf ("of method [%4.4s]", (char *) &Name);
337 else
339 AcpiOsPrintf ("at module level (table load)");
341 AcpiOsPrintf (" Opcode [%s] @%X\n", AcpiPsGetOpcodeName (Opcode), AmlOffset);
344 * Invoke the _ERR method if present
346 * Setup parameter object
348 ArgList.Count = 3;
349 ArgList.Pointer = Arg;
351 Arg[0].Type = ACPI_TYPE_INTEGER;
352 Arg[0].Integer.Value = AmlStatus;
354 Arg[1].Type = ACPI_TYPE_STRING;
355 Arg[1].String.Pointer = ACPI_CAST_PTR (char, Exception);
356 Arg[1].String.Length = ACPI_STRLEN (Exception);
358 Arg[2].Type = ACPI_TYPE_INTEGER;
359 Arg[2].Integer.Value = ACPI_TO_INTEGER (AcpiOsGetThreadId());
361 /* Setup return buffer */
363 ReturnObj.Pointer = NULL;
364 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
366 Status = AcpiEvaluateObject (NULL, "\\_ERR", &ArgList, &ReturnObj);
367 if (ACPI_SUCCESS (Status))
369 if (ReturnObj.Pointer)
371 /* Override original status */
373 NewAmlStatus = (ACPI_STATUS)
374 ((ACPI_OBJECT *) ReturnObj.Pointer)->Integer.Value;
376 AcpiOsFree (ReturnObj.Pointer);
379 else if (Status != AE_NOT_FOUND)
381 AcpiOsPrintf ("[AcpiExec] Could not execute _ERR method, %s\n",
382 AcpiFormatException (Status));
385 /* Global override */
387 if (AcpiGbl_IgnoreErrors)
389 NewAmlStatus = AE_OK;
392 if (NewAmlStatus != AmlStatus)
394 AcpiOsPrintf ("[AcpiExec] Exception override, new status %s\n",
395 AcpiFormatException (NewAmlStatus));
398 return (NewAmlStatus);
402 /******************************************************************************
404 * FUNCTION: AeTableHandler
406 * PARAMETERS: Table handler
408 * RETURN: Status
410 * DESCRIPTION: System table handler for AcpiExec utility.
412 *****************************************************************************/
414 char *TableEvents[] =
416 "LOAD",
417 "UNLOAD",
418 "UNKNOWN"
421 ACPI_STATUS
422 AeTableHandler (
423 UINT32 Event,
424 void *Table,
425 void *Context)
428 if (Event > ACPI_NUM_TABLE_EVENTS)
430 Event = ACPI_NUM_TABLE_EVENTS;
433 /* TBD: could dump entire table header, need a header dump routine */
435 printf ("[AcpiExec] Table Event %s, [%4.4s] %p\n",
436 TableEvents[Event], ((ACPI_TABLE_HEADER *) Table)->Signature, Table);
437 return (AE_OK);
441 /******************************************************************************
443 * FUNCTION: AeGpeHandler
445 * DESCRIPTION: GPE handler for acpiexec
447 *****************************************************************************/
449 UINT32
450 AeGpeHandler (
451 void *Context)
453 AcpiOsPrintf ("Received a GPE at handler\n");
454 return (0);
458 /******************************************************************************
460 * FUNCTION: AeAttachedDataHandler
462 * DESCRIPTION: Handler for deletion of nodes with attached data (attached via
463 * AcpiAttachData)
465 *****************************************************************************/
467 void
468 AeAttachedDataHandler (
469 ACPI_HANDLE Object,
470 void *Data)
472 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Data);
475 AcpiOsPrintf ("Received an attached data deletion on %4.4s\n",
476 Node->Name.Ascii);
480 /******************************************************************************
482 * FUNCTION: AeRegionInit
484 * PARAMETERS: None
486 * RETURN: Status
488 * DESCRIPTION: Opregion init function.
490 *****************************************************************************/
492 ACPI_STATUS
493 AeRegionInit (
494 ACPI_HANDLE RegionHandle,
495 UINT32 Function,
496 void *HandlerContext,
497 void **RegionContext)
500 * Real simple, set the RegionContext to the RegionHandle
502 *RegionContext = RegionHandle;
504 return AE_OK;
508 /******************************************************************************
510 * FUNCTION: AeInstallHandlers
512 * PARAMETERS: None
514 * RETURN: Status
516 * DESCRIPTION: Install handlers for the AcpiExec utility.
518 *****************************************************************************/
520 ACPI_ADR_SPACE_TYPE SpaceId[] = {0, 1, 2, 3, 4, 5, 6, 7, 0x80};
521 #define AEXEC_NUM_REGIONS 9
523 ACPI_STATUS
524 AeInstallHandlers (void)
526 ACPI_STATUS Status;
527 UINT32 i;
528 ACPI_HANDLE Handle;
531 ACPI_FUNCTION_ENTRY ();
534 Status = AcpiInstallTableHandler (AeTableHandler, NULL);
535 if (ACPI_FAILURE (Status))
537 printf ("Could not install table handler, %s\n",
538 AcpiFormatException (Status));
541 Status = AcpiInstallExceptionHandler (AeExceptionHandler);
542 if (ACPI_FAILURE (Status))
544 printf ("Could not install exception handler, %s\n",
545 AcpiFormatException (Status));
548 /* Install global notify handler */
550 Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
551 AeNotifyHandler, NULL);
552 if (ACPI_FAILURE (Status))
554 printf ("Could not install a global notify handler, %s\n",
555 AcpiFormatException (Status));
558 Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_DEVICE_NOTIFY,
559 AeDeviceNotifyHandler, NULL);
560 if (ACPI_FAILURE (Status))
562 printf ("Could not install a global notify handler, %s\n",
563 AcpiFormatException (Status));
566 Status = AcpiGetHandle (NULL, "\\_SB", &Handle);
567 if (ACPI_SUCCESS (Status))
569 Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
570 AeNotifyHandler, NULL);
571 if (ACPI_FAILURE (Status))
573 printf ("Could not install a notify handler, %s\n",
574 AcpiFormatException (Status));
577 Status = AcpiRemoveNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
578 AeNotifyHandler);
579 if (ACPI_FAILURE (Status))
581 printf ("Could not remove a notify handler, %s\n",
582 AcpiFormatException (Status));
585 Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
586 AeNotifyHandler, NULL);
587 Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY,
588 AeNotifyHandler);
589 Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
590 AeNotifyHandler, NULL);
591 if (ACPI_FAILURE (Status))
593 printf ("Could not install a notify handler, %s\n",
594 AcpiFormatException (Status));
597 Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle);
598 Status = AcpiDetachData (Handle, AeAttachedDataHandler);
599 Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle);
601 else
603 printf ("No _SB_ found, %s\n", AcpiFormatException (Status));
606 /* Set a handler for all supported operation regions */
608 for (i = 0; i < AEXEC_NUM_REGIONS; i++)
610 Status = AcpiRemoveAddressSpaceHandler (AcpiGbl_RootNode,
611 SpaceId[i], AeRegionHandler);
613 /* Install handler at the root object.
614 * TBD: all default handlers should be installed here!
616 Status = AcpiInstallAddressSpaceHandler (AcpiGbl_RootNode,
617 SpaceId[i], AeRegionHandler, AeRegionInit, NULL);
618 if (ACPI_FAILURE (Status))
620 ACPI_EXCEPTION ((AE_INFO, Status,
621 "Could not install an OpRegion handler for %s space(%d)",
622 AcpiUtGetRegionName((UINT8) SpaceId[i]), SpaceId[i]));
623 return (Status);
628 * Initialize the global Region Handler space
629 * MCW 3/23/00
631 AeRegions.NumberOfRegions = 0;
632 AeRegions.RegionList = NULL;
634 return Status;
638 /******************************************************************************
640 * FUNCTION: AeRegionHandler
642 * PARAMETERS: Standard region handler parameters
644 * RETURN: Status
646 * DESCRIPTION: Test handler - Handles some dummy regions via memory that can
647 * be manipulated in Ring 3. Simulates actual reads and writes.
649 *****************************************************************************/
651 ACPI_STATUS
652 AeRegionHandler (
653 UINT32 Function,
654 ACPI_PHYSICAL_ADDRESS Address,
655 UINT32 BitWidth,
656 ACPI_INTEGER *Value,
657 void *HandlerContext,
658 void *RegionContext)
661 ACPI_OPERAND_OBJECT *RegionObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, RegionContext);
662 UINT8 *Buffer = ACPI_CAST_PTR (UINT8, Value);
663 ACPI_PHYSICAL_ADDRESS BaseAddress;
664 ACPI_SIZE Length;
665 BOOLEAN BufferExists;
666 AE_REGION *RegionElement;
667 void *BufferValue;
668 ACPI_STATUS Status;
669 UINT32 ByteWidth;
670 UINT32 i;
671 UINT8 SpaceId;
674 ACPI_FUNCTION_NAME (AeRegionHandler);
677 * If the object is not a region, simply return
679 if (RegionObject->Region.Type != ACPI_TYPE_REGION)
681 return AE_OK;
685 * Region support can be disabled with the -r option.
686 * We use this to support dynamically loaded tables where we pass a valid
687 * address to the AML.
689 if (AcpiGbl_DbOpt_NoRegionSupport)
691 BufferValue = ACPI_TO_POINTER (Address);
692 ByteWidth = (BitWidth / 8);
694 if (BitWidth % 8)
696 ByteWidth += 1;
698 goto DoFunction;
702 * Find the region's address space and length before searching
703 * the linked list.
705 BaseAddress = RegionObject->Region.Address;
706 Length = (ACPI_SIZE) RegionObject->Region.Length;
707 SpaceId = RegionObject->Region.SpaceId;
709 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, "Operation Region request on %s at 0x%X\n",
710 AcpiUtGetRegionName (RegionObject->Region.SpaceId),
711 (UINT32) Address));
713 switch (SpaceId)
715 case ACPI_ADR_SPACE_SYSTEM_IO:
717 * For I/O space, exercise the port validation
719 switch (Function & ACPI_IO_MASK)
721 case ACPI_READ:
722 Status = AcpiHwReadPort (Address, (UINT32 *) Value, BitWidth);
723 break;
725 case ACPI_WRITE:
726 Status = AcpiHwWritePort (Address, (UINT32) *Value, BitWidth);
727 break;
729 default:
730 Status = AE_BAD_PARAMETER;
731 break;
734 if (ACPI_FAILURE (Status))
736 return (Status);
739 /* Now go ahead and simulate the hardware */
740 break;
743 case ACPI_ADR_SPACE_SMBUS:
745 Length = 0;
747 switch (Function & ACPI_IO_MASK)
749 case ACPI_READ:
750 switch (Function >> 16)
752 case AML_FIELD_ATTRIB_SMB_QUICK:
753 case AML_FIELD_ATTRIB_SMB_SEND_RCV:
754 case AML_FIELD_ATTRIB_SMB_BYTE:
755 Length = 1;
756 break;
758 case AML_FIELD_ATTRIB_SMB_WORD:
759 case AML_FIELD_ATTRIB_SMB_WORD_CALL:
760 Length = 2;
761 break;
763 case AML_FIELD_ATTRIB_SMB_BLOCK:
764 case AML_FIELD_ATTRIB_SMB_BLOCK_CALL:
765 Length = 32;
766 break;
768 default:
769 break;
771 break;
773 case ACPI_WRITE:
774 switch (Function >> 16)
776 case AML_FIELD_ATTRIB_SMB_QUICK:
777 case AML_FIELD_ATTRIB_SMB_SEND_RCV:
778 case AML_FIELD_ATTRIB_SMB_BYTE:
779 case AML_FIELD_ATTRIB_SMB_WORD:
780 case AML_FIELD_ATTRIB_SMB_BLOCK:
781 Length = 0;
782 break;
784 case AML_FIELD_ATTRIB_SMB_WORD_CALL:
785 Length = 2;
786 break;
788 case AML_FIELD_ATTRIB_SMB_BLOCK_CALL:
789 Length = 32;
790 break;
792 default:
793 break;
795 break;
797 default:
798 break;
801 for (i = 0; i < Length; i++)
803 Buffer[i+2] = (UINT8) (0xA0 + i);
806 Buffer[0] = 0x7A;
807 Buffer[1] = (UINT8) Length;
808 return (AE_OK);
811 case ACPI_ADR_SPACE_IPMI: /* ACPI 4.0 */
813 AcpiOsPrintf ("AcpiExec: Received IPMI request: "
814 "Address %X BaseAddress %X Length %X Width %X BufferLength %u\n",
815 (UINT32) Address, (UINT32) BaseAddress,
816 Length, BitWidth, Buffer[1]);
819 * Regardless of a READ or WRITE, this handler is passed a 66-byte
820 * buffer in which to return the IPMI status/length/data.
822 * Return some example data to show use of the bidirectional buffer
824 Buffer[0] = 0; /* Status byte */
825 Buffer[1] = 64; /* Return buffer data length */
826 Buffer[2] = 0; /* Completion code */
827 Buffer[3] = 0x34; /* Power measurement */
828 Buffer[4] = 0x12; /* Power measurement */
829 Buffer[65] = 0xEE; /* last buffer byte */
830 return (AE_OK);
832 default:
833 break;
837 * Search through the linked list for this region's buffer
839 BufferExists = FALSE;
840 RegionElement = AeRegions.RegionList;
842 if (AeRegions.NumberOfRegions)
844 while (!BufferExists && RegionElement)
846 if (RegionElement->Address == BaseAddress &&
847 RegionElement->Length == Length &&
848 RegionElement->SpaceId == SpaceId)
850 BufferExists = TRUE;
852 else
854 RegionElement = RegionElement->NextRegion;
860 * If the Region buffer does not exist, create it now
862 if (!BufferExists)
865 * Do the memory allocations first
867 RegionElement = AcpiOsAllocate (sizeof (AE_REGION));
868 if (!RegionElement)
870 return AE_NO_MEMORY;
873 RegionElement->Buffer = AcpiOsAllocate (Length);
874 if (!RegionElement->Buffer)
876 AcpiOsFree (RegionElement);
877 return AE_NO_MEMORY;
880 ACPI_MEMSET (RegionElement->Buffer, 0, Length);
881 RegionElement->Address = BaseAddress;
882 RegionElement->Length = Length;
883 RegionElement->SpaceId = SpaceId;
884 RegionElement->NextRegion = NULL;
887 * Increment the number of regions and put this one
888 * at the head of the list as it will probably get accessed
889 * more often anyway.
891 AeRegions.NumberOfRegions += 1;
893 if (AeRegions.RegionList)
895 RegionElement->NextRegion = AeRegions.RegionList;
898 AeRegions.RegionList = RegionElement;
902 * Calculate the size of the memory copy
904 ByteWidth = (BitWidth / 8);
906 if (BitWidth % 8)
908 ByteWidth += 1;
912 * The buffer exists and is pointed to by RegionElement.
913 * We now need to verify the request is valid and perform the operation.
915 * NOTE: RegionElement->Length is in bytes, therefore it we compare against
916 * ByteWidth (see above)
918 if (((ACPI_INTEGER) Address + ByteWidth) >
919 ((ACPI_INTEGER)(RegionElement->Address) + RegionElement->Length))
921 ACPI_WARNING ((AE_INFO,
922 "Request on [%4.4s] is beyond region limit Req-%X+%X, Base=%X, Len-%X",
923 (RegionObject->Region.Node)->Name.Ascii, (UINT32) Address,
924 ByteWidth, (UINT32)(RegionElement->Address),
925 RegionElement->Length));
927 return AE_AML_REGION_LIMIT;
931 * Get BufferValue to point to the "address" in the buffer
933 BufferValue = ((UINT8 *) RegionElement->Buffer +
934 ((ACPI_INTEGER) Address - (ACPI_INTEGER) RegionElement->Address));
936 DoFunction:
939 * Perform a read or write to the buffer space
941 switch (Function)
943 case ACPI_READ:
945 * Set the pointer Value to whatever is in the buffer
947 ACPI_MEMCPY (Value, BufferValue, ByteWidth);
948 break;
950 case ACPI_WRITE:
952 * Write the contents of Value to the buffer
954 ACPI_MEMCPY (BufferValue, Value, ByteWidth);
955 break;
957 default:
958 return AE_BAD_PARAMETER;
960 return AE_OK;