1 /******************************************************************************
3 * Module Name: aeregion - Operation region support for acpiexec
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12 * All rights reserved.
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
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
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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
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
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 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "aecommon.h"
154 #define _COMPONENT ACPI_TOOLS
155 ACPI_MODULE_NAME ("aeregion")
158 /* Local prototypes */
162 ACPI_HANDLE RegionHandle,
164 void *HandlerContext,
165 void **RegionContext);
169 ACPI_HANDLE ObjHandle,
175 AeInstallPciHandler (
176 ACPI_HANDLE ObjHandle,
182 static AE_DEBUG_REGIONS AeRegions;
183 BOOLEAN AcpiGbl_DisplayRegionAccess = FALSE;
184 ACPI_CONNECTION_INFO AeMyContext;
188 * We will override some of the default region handlers, especially
189 * the SystemMemory handler, which must be implemented locally.
190 * These handlers are installed "early" - before any _REG methods
191 * are executed - since they are special in the sense that the ACPI spec
192 * declares that they must "always be available". Cannot override the
193 * DataTable region handler either -- needed for test execution.
195 * NOTE: The local region handler will simulate access to these address
196 * spaces by creating a memory buffer behind each operation region.
198 static ACPI_ADR_SPACE_TYPE DefaultSpaceIdList[] =
200 ACPI_ADR_SPACE_SYSTEM_MEMORY,
201 ACPI_ADR_SPACE_SYSTEM_IO,
202 ACPI_ADR_SPACE_PCI_CONFIG,
207 * We will install handlers for some of the various address space IDs.
208 * Test one user-defined address space (used by aslts).
210 #define ACPI_ADR_SPACE_USER_DEFINED1 0x80
211 #define ACPI_ADR_SPACE_USER_DEFINED2 0xE4
213 static ACPI_ADR_SPACE_TYPE SpaceIdList[] =
215 ACPI_ADR_SPACE_SMBUS,
217 ACPI_ADR_SPACE_PCI_BAR_TARGET,
220 ACPI_ADR_SPACE_GSBUS,
221 ACPI_ADR_SPACE_FIXED_HARDWARE,
222 ACPI_ADR_SPACE_USER_DEFINED1,
223 ACPI_ADR_SPACE_USER_DEFINED2
227 /******************************************************************************
229 * FUNCTION: AeRegionInit
231 * PARAMETERS: Region init handler
235 * DESCRIPTION: Opregion init function.
237 *****************************************************************************/
241 ACPI_HANDLE RegionHandle,
243 void *HandlerContext,
244 void **RegionContext)
247 if (Function == ACPI_REGION_DEACTIVATE)
249 *RegionContext = NULL;
253 *RegionContext = RegionHandle;
260 /******************************************************************************
262 * FUNCTION: AeOverrideRegionHandlers
268 * DESCRIPTION: Override the default region handlers for memory, i/o, and
269 * pci_config. Also install a handler for EC. This is part of
270 * the "install early handlers" functionality.
272 *****************************************************************************/
275 AeOverrideRegionHandlers (
282 * Install handlers that will override the default handlers for some of
285 for (i = 0; i < ACPI_ARRAY_LENGTH (DefaultSpaceIdList); i++)
287 /* Install handler at the root object */
289 Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
290 DefaultSpaceIdList[i], AeRegionHandler,
291 AeRegionInit, &AeMyContext);
293 if (ACPI_FAILURE (Status))
295 ACPI_EXCEPTION ((AE_INFO, Status,
296 "Could not install an OpRegion handler for %s space(%u)",
297 AcpiUtGetRegionName ((UINT8) DefaultSpaceIdList[i]),
298 DefaultSpaceIdList[i]));
304 /******************************************************************************
306 * FUNCTION: AeInstallRegionHandlers
312 * DESCRIPTION: Install handlers for the address spaces other than memory,
313 * i/o, and pci_config.
315 *****************************************************************************/
318 AeInstallRegionHandlers (
325 * Install handlers for some of the "device driver" address spaces
326 * such as SMBus, etc.
328 for (i = 0; i < ACPI_ARRAY_LENGTH (SpaceIdList); i++)
330 /* Install handler at the root object */
332 Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT,
333 SpaceIdList[i], AeRegionHandler,
334 AeRegionInit, &AeMyContext);
336 if (ACPI_FAILURE (Status))
338 ACPI_EXCEPTION ((AE_INFO, Status,
339 "Could not install an OpRegion handler for %s space(%u)",
340 AcpiUtGetRegionName((UINT8) SpaceIdList[i]), SpaceIdList[i]));
347 /*******************************************************************************
349 * FUNCTION: AeInstallDeviceHandlers,
350 * AeInstallEcHandler,
351 * AeInstallPciHandler
353 * PARAMETERS: ACPI_WALK_NAMESPACE callback
357 * DESCRIPTION: Walk entire namespace, install a handler for every EC
358 * and PCI device found.
360 ******************************************************************************/
364 ACPI_HANDLE ObjHandle,
372 /* Install the handler for this EC device */
374 Status = AcpiInstallAddressSpaceHandler (ObjHandle, ACPI_ADR_SPACE_EC,
375 AeRegionHandler, AeRegionInit, &AeMyContext);
376 if (ACPI_FAILURE (Status))
378 ACPI_EXCEPTION ((AE_INFO, Status,
379 "Could not install an OpRegion handler for EC device (%p)",
388 AeInstallPciHandler (
389 ACPI_HANDLE ObjHandle,
397 /* Install memory and I/O handlers for the PCI device */
399 Status = AcpiInstallAddressSpaceHandler (ObjHandle, ACPI_ADR_SPACE_SYSTEM_IO,
400 AeRegionHandler, AeRegionInit, &AeMyContext);
401 if (ACPI_FAILURE (Status))
403 ACPI_EXCEPTION ((AE_INFO, Status,
404 "Could not install an OpRegion handler for PCI device (%p)",
408 Status = AcpiInstallAddressSpaceHandler (ObjHandle, ACPI_ADR_SPACE_SYSTEM_MEMORY,
409 AeRegionHandler, AeRegionInit, &AeMyContext);
410 if (ACPI_FAILURE (Status))
412 ACPI_EXCEPTION ((AE_INFO, Status,
413 "Could not install an OpRegion handler for PCI device (%p)",
417 return (AE_CTRL_TERMINATE);
422 AeInstallDeviceHandlers (
426 /* Find all Embedded Controller devices */
428 AcpiGetDevices ("PNP0C09", AeInstallEcHandler, NULL, NULL);
430 /* Install a PCI handler */
432 AcpiGetDevices ("PNP0A08", AeInstallPciHandler, NULL, NULL);
437 /******************************************************************************
439 * FUNCTION: AeRegionHandler
441 * PARAMETERS: Standard region handler parameters
445 * DESCRIPTION: Test handler - Handles some dummy regions via memory that can
446 * be manipulated in Ring 3. Simulates actual reads and writes.
448 *****************************************************************************/
453 ACPI_PHYSICAL_ADDRESS Address,
456 void *HandlerContext,
460 ACPI_OPERAND_OBJECT *RegionObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, RegionContext);
461 UINT8 *Buffer = ACPI_CAST_PTR (UINT8, Value);
464 ACPI_PHYSICAL_ADDRESS BaseAddress;
465 ACPI_PHYSICAL_ADDRESS BaseAddressEnd;
466 ACPI_PHYSICAL_ADDRESS RegionAddress;
467 ACPI_PHYSICAL_ADDRESS RegionAddressEnd;
469 BOOLEAN BufferExists;
470 BOOLEAN BufferResize;
471 AE_REGION *RegionElement;
478 ACPI_CONNECTION_INFO *MyContext;
481 ACPI_RESOURCE *Resource;
484 ACPI_FUNCTION_NAME (AeRegionHandler);
487 * If the object is not a region, simply return
489 if (RegionObject->Region.Type != ACPI_TYPE_REGION)
494 /* Check that we actually got back our context parameter */
496 if (HandlerContext != &AeMyContext)
498 printf ("Region handler received incorrect context %p, should be %p\n",
499 HandlerContext, &AeMyContext);
502 MyContext = ACPI_CAST_PTR (ACPI_CONNECTION_INFO, HandlerContext);
505 * Find the region's address space and length before searching
508 BaseAddress = RegionObject->Region.Address;
509 Length = (ACPI_SIZE) RegionObject->Region.Length;
510 SpaceId = RegionObject->Region.SpaceId;
512 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
513 "Operation Region request on %s at 0x%X\n",
514 AcpiUtGetRegionName (RegionObject->Region.SpaceId),
518 * Region support can be disabled with the -do option.
519 * We use this to support dynamically loaded tables where we pass a valid
520 * address to the AML.
522 if (AcpiGbl_DbOpt_NoRegionSupport)
524 BufferValue = ACPI_TO_POINTER (Address);
525 ByteWidth = (BitWidth / 8);
536 case ACPI_ADR_SPACE_SYSTEM_IO:
538 * For I/O space, exercise the port validation
539 * Note: ReadPort currently always returns all ones, length=BitLength
541 switch (Function & ACPI_IO_MASK)
547 /* Split the 64-bit request into two 32-bit requests */
549 Status = AcpiHwReadPort (Address, &Value1, 32);
550 ACPI_CHECK_OK (AcpiHwReadPort, Status);
551 Status = AcpiHwReadPort (Address+4, &Value2, 32);
552 ACPI_CHECK_OK (AcpiHwReadPort, Status);
554 *Value = Value1 | ((UINT64) Value2 << 32);
558 Status = AcpiHwReadPort (Address, &Value1, BitWidth);
559 ACPI_CHECK_OK (AcpiHwReadPort, Status);
560 *Value = (UINT64) Value1;
568 /* Split the 64-bit request into two 32-bit requests */
570 Status = AcpiHwWritePort (Address, ACPI_LODWORD (*Value), 32);
571 ACPI_CHECK_OK (AcpiHwWritePort, Status);
572 Status = AcpiHwWritePort (Address+4, ACPI_HIDWORD (*Value), 32);
573 ACPI_CHECK_OK (AcpiHwWritePort, Status);
577 Status = AcpiHwWritePort (Address, (UINT32) *Value, BitWidth);
578 ACPI_CHECK_OK (AcpiHwWritePort, Status);
584 Status = AE_BAD_PARAMETER;
588 if (ACPI_FAILURE (Status))
593 /* Now go ahead and simulate the hardware */
597 * SMBus and GenericSerialBus support the various bidirectional
600 case ACPI_ADR_SPACE_SMBUS:
601 case ACPI_ADR_SPACE_GSBUS: /* ACPI 5.0 */
605 switch (Function & ACPI_IO_MASK)
609 switch (Function >> 16)
611 case AML_FIELD_ATTRIB_QUICK:
616 case AML_FIELD_ATTRIB_SEND_RCV:
617 case AML_FIELD_ATTRIB_BYTE:
622 case AML_FIELD_ATTRIB_WORD:
623 case AML_FIELD_ATTRIB_WORD_CALL:
628 case AML_FIELD_ATTRIB_BLOCK:
629 case AML_FIELD_ATTRIB_BLOCK_CALL:
634 case AML_FIELD_ATTRIB_MULTIBYTE:
635 case AML_FIELD_ATTRIB_RAW_BYTES:
636 case AML_FIELD_ATTRIB_RAW_PROCESS:
638 Length = MyContext->AccessLength;
649 switch (Function >> 16)
651 case AML_FIELD_ATTRIB_QUICK:
652 case AML_FIELD_ATTRIB_SEND_RCV:
653 case AML_FIELD_ATTRIB_BYTE:
654 case AML_FIELD_ATTRIB_WORD:
655 case AML_FIELD_ATTRIB_BLOCK:
660 case AML_FIELD_ATTRIB_WORD_CALL:
664 case AML_FIELD_ATTRIB_BLOCK_CALL:
668 case AML_FIELD_ATTRIB_MULTIBYTE:
669 case AML_FIELD_ATTRIB_RAW_BYTES:
670 case AML_FIELD_ATTRIB_RAW_PROCESS:
672 Length = MyContext->AccessLength;
686 if (AcpiGbl_DisplayRegionAccess)
688 AcpiOsPrintf ("AcpiExec: %s "
689 "%s: Attr %X Addr %.4X BaseAddr %.4X Len %.2X Width %X BufLen %X",
690 AcpiUtGetRegionName (SpaceId),
691 (Function & ACPI_IO_MASK) ? "Write" : "Read ",
692 (UINT32) (Function >> 16),
693 (UINT32) Address, (UINT32) BaseAddress,
694 Length, BitWidth, Buffer[1]);
696 /* GenericSerialBus has a Connection() parameter */
698 if (SpaceId == ACPI_ADR_SPACE_GSBUS)
700 Status = AcpiBufferToResource (MyContext->Connection,
701 MyContext->Length, &Resource);
703 AcpiOsPrintf (" [AccLen %.2X Conn %p]",
704 MyContext->AccessLength, MyContext->Connection);
709 /* Setup the return buffer. Note: ASLTS depends on these fill values */
711 for (i = 0; i < Length; i++)
713 Buffer[i+2] = (UINT8) (0xA0 + i);
717 Buffer[1] = (UINT8) Length;
721 case ACPI_ADR_SPACE_IPMI: /* ACPI 4.0 */
723 if (AcpiGbl_DisplayRegionAccess)
725 AcpiOsPrintf ("AcpiExec: IPMI "
726 "%s: Attr %X Addr %.4X BaseAddr %.4X Len %.2X Width %X BufLen %X\n",
727 (Function & ACPI_IO_MASK) ? "Write" : "Read ",
728 (UINT32) (Function >> 16), (UINT32) Address, (UINT32) BaseAddress,
729 Length, BitWidth, Buffer[1]);
733 * Regardless of a READ or WRITE, this handler is passed a 66-byte
734 * buffer in which to return the IPMI status/length/data.
736 * Return some example data to show use of the bidirectional buffer
738 Buffer[0] = 0; /* Status byte */
739 Buffer[1] = 64; /* Return buffer data length */
740 Buffer[2] = 0; /* Completion code */
741 Buffer[3] = 0; /* Reserved */
744 * Fill the 66-byte buffer with the return data.
745 * Note: ASLTS depends on these fill values.
747 for (i = 4; i < 66; i++)
749 Buffer[i] = (UINT8) (i);
754 * GPIO has some special semantics:
755 * 1) Address is the pin number index into the Connection() pin list
756 * 2) BitWidth is the actual number of bits (pins) defined by the field
758 case ACPI_ADR_SPACE_GPIO: /* ACPI 5.0 */
760 if (AcpiGbl_DisplayRegionAccess)
762 AcpiOsPrintf ("AcpiExec: GPIO "
763 "%s: Addr %.4X Width %X Conn %p\n",
764 (Function & ACPI_IO_MASK) ? "Write" : "Read ",
765 (UINT32) Address, BitWidth, MyContext->Connection);
774 * Search through the linked list for this region's buffer
776 BufferExists = FALSE;
777 BufferResize = FALSE;
778 RegionElement = AeRegions.RegionList;
780 if (AeRegions.NumberOfRegions)
782 BaseAddressEnd = BaseAddress + Length - 1;
783 while (!BufferExists && RegionElement)
785 RegionAddress = RegionElement->Address;
786 RegionAddressEnd = RegionElement->Address + RegionElement->Length - 1;
787 RegionLength = RegionElement->Length;
790 * Overlapping Region Support
792 * While searching through the region buffer list, determine if an
793 * overlap exists between the requested buffer space and the current
794 * RegionElement space. If there is an overlap then replace the old
795 * buffer with a new buffer of increased size before continuing to
796 * do the read or write
798 if (RegionElement->SpaceId != SpaceId ||
799 BaseAddressEnd < RegionAddress ||
800 BaseAddress > RegionAddressEnd)
803 * Requested buffer is outside of the current RegionElement
806 RegionElement = RegionElement->NextRegion;
811 * Some amount of buffer space sharing exists. There are 4 cases
816 * 3. Left and right overlap
817 * 4. Fully contained - no resizing required
821 if ((BaseAddress >= RegionAddress) &&
822 (BaseAddress <= RegionAddressEnd) &&
823 (BaseAddressEnd > RegionAddressEnd))
827 RegionElement->Length = (UINT32) (BaseAddress -
828 RegionAddress + Length);
832 else if ((BaseAddressEnd >= RegionAddress) &&
833 (BaseAddressEnd <= RegionAddressEnd) &&
834 (BaseAddress < RegionAddress))
838 RegionElement->Address = BaseAddress;
839 RegionElement->Length = (UINT32) (RegionAddress -
840 BaseAddress + RegionElement->Length);
844 else if ((BaseAddress < RegionAddress) &&
845 (BaseAddressEnd > RegionAddressEnd))
847 /* Left and right overlap */
849 RegionElement->Address = BaseAddress;
850 RegionElement->Length = Length;
855 * only remaining case is fully contained for which we don't
856 * need to do anything
860 NewBuffer = AcpiOsAllocate (RegionElement->Length);
863 return (AE_NO_MEMORY);
866 OldBuffer = RegionElement->Buffer;
867 RegionElement->Buffer = NewBuffer;
870 /* Initialize the region with the default fill value */
872 memset (RegionElement->Buffer,
873 AcpiGbl_RegionFillValue, RegionElement->Length);
876 * Get BufferValue to point (within the new buffer) to the
877 * base address of the old buffer
879 BufferValue = (UINT8 *) RegionElement->Buffer +
880 (UINT64) RegionAddress -
881 (UINT64) RegionElement->Address;
884 * Copy the old buffer to its same location within the new
887 memcpy (BufferValue, OldBuffer, RegionLength);
888 AcpiOsFree (OldBuffer);
895 * If the Region buffer does not exist, create it now
899 /* Do the memory allocations first */
901 RegionElement = AcpiOsAllocate (sizeof (AE_REGION));
904 return (AE_NO_MEMORY);
907 RegionElement->Buffer = AcpiOsAllocate (Length);
908 if (!RegionElement->Buffer)
910 AcpiOsFree (RegionElement);
911 return (AE_NO_MEMORY);
914 /* Initialize the region with the default fill value */
916 memset (RegionElement->Buffer, AcpiGbl_RegionFillValue, Length);
918 RegionElement->Address = BaseAddress;
919 RegionElement->Length = Length;
920 RegionElement->SpaceId = SpaceId;
921 RegionElement->NextRegion = NULL;
924 * Increment the number of regions and put this one
925 * at the head of the list as it will probably get accessed
928 AeRegions.NumberOfRegions += 1;
930 if (AeRegions.RegionList)
932 RegionElement->NextRegion = AeRegions.RegionList;
935 AeRegions.RegionList = RegionElement;
938 /* Calculate the size of the memory copy */
940 ByteWidth = (BitWidth / 8);
948 * The buffer exists and is pointed to by RegionElement.
949 * We now need to verify the request is valid and perform the operation.
951 * NOTE: RegionElement->Length is in bytes, therefore it we compare against
952 * ByteWidth (see above)
954 if ((RegionObject->Region.SpaceId != ACPI_ADR_SPACE_GPIO) &&
955 ((UINT64) Address + ByteWidth) >
956 ((UINT64)(RegionElement->Address) + RegionElement->Length))
958 ACPI_WARNING ((AE_INFO,
959 "Request on [%4.4s] is beyond region limit "
960 "Req-0x%X+0x%X, Base=0x%X, Len-0x%X",
961 (RegionObject->Region.Node)->Name.Ascii, (UINT32) Address,
962 ByteWidth, (UINT32)(RegionElement->Address),
963 RegionElement->Length));
965 return (AE_AML_REGION_LIMIT);
969 * Get BufferValue to point to the "address" in the buffer
971 BufferValue = ((UINT8 *) RegionElement->Buffer +
972 ((UINT64) Address - (UINT64) RegionElement->Address));
976 * Perform a read or write to the buffer space
982 * Set the pointer Value to whatever is in the buffer
984 memcpy (Value, BufferValue, ByteWidth);
989 * Write the contents of Value to the buffer
991 memcpy (BufferValue, Value, ByteWidth);
996 return (AE_BAD_PARAMETER);
999 if (AcpiGbl_DisplayRegionAccess)
1003 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
1005 AcpiOsPrintf ("AcpiExec: SystemMemory "
1006 "%s: Val %.8X Addr %.4X Width %X [REGION: BaseAddr %.4X Len %.2X]\n",
1007 (Function & ACPI_IO_MASK) ? "Write" : "Read ",
1008 (UINT32) *Value, (UINT32) Address, BitWidth, (UINT32) BaseAddress, Length);
1011 case ACPI_ADR_SPACE_GPIO: /* ACPI 5.0 */
1013 /* This space is required to always be ByteAcc */
1015 Status = AcpiBufferToResource (MyContext->Connection,
1016 MyContext->Length, &Resource);
1018 AcpiOsPrintf ("AcpiExec: GeneralPurposeIo "
1019 "%s: Val %.8X Addr %.4X BaseAddr %.4X Len %.2X Width %X AccLen %.2X Conn %p\n",
1020 (Function & ACPI_IO_MASK) ? "Write" : "Read ", (UINT32) *Value,
1021 (UINT32) Address, (UINT32) BaseAddress, Length, BitWidth,
1022 MyContext->AccessLength, MyContext->Connection);