1 /******************************************************************************
3 * Module Name: exregion - ACPI default OpRegion (address space) handlers
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define __EXREGION_C__
51 #define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME ("exregion")
55 /*******************************************************************************
57 * FUNCTION: AcpiExSystemMemorySpaceHandler
59 * PARAMETERS: Function - Read or Write operation
60 * Address - Where in the space to read or write
61 * BitWidth - Field width in bits (8, 16, or 32)
62 * Value - Pointer to in or out value
63 * HandlerContext - Pointer to Handler's context
64 * RegionContext - Pointer to context specific to the
69 * DESCRIPTION: Handler for the System Memory address space (Op Region)
71 ******************************************************************************/
74 AcpiExSystemMemorySpaceHandler (
76 ACPI_PHYSICAL_ADDRESS Address,
82 ACPI_STATUS Status = AE_OK;
83 void *LogicalAddrPtr = NULL;
84 ACPI_MEM_SPACE_CONTEXT *MemInfo = RegionContext;
87 ACPI_SIZE PageBoundaryMapLength;
88 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
93 ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler);
96 /* Validate and translate the bit width */
122 ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %u",
124 return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
127 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
129 * Hardware does not support non-aligned data transfers, we must verify
132 (void) AcpiUtShortDivide ((UINT64) Address, Length, NULL, &Remainder);
135 return_ACPI_STATUS (AE_AML_ALIGNMENT);
140 * Does the request fit into the cached memory mapping?
141 * Is 1) Address below the current mapping? OR
142 * 2) Address beyond the current mapping?
144 if ((Address < MemInfo->MappedPhysicalAddress) ||
145 (((UINT64) Address + Length) >
147 MemInfo->MappedPhysicalAddress + MemInfo->MappedLength)))
150 * The request cannot be resolved by the current memory mapping;
151 * Delete the existing mapping and create a new one.
153 if (MemInfo->MappedLength)
155 /* Valid mapping, delete it */
157 AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress,
158 MemInfo->MappedLength);
162 * October 2009: Attempt to map from the requested address to the
163 * end of the region. However, we will never map more than one
164 * page, nor will we cross a page boundary.
166 MapLength = (ACPI_SIZE)
167 ((MemInfo->Address + MemInfo->Length) - Address);
170 * If mapping the entire remaining portion of the region will cross
171 * a page boundary, just map up to the page boundary, do not cross.
172 * On some systems, crossing a page boundary while mapping regions
173 * can cause warnings if the pages have different attributes
174 * due to resource management.
176 * This has the added benefit of constraining a single mapping to
177 * one page, which is similar to the original code that used a 4k
180 PageBoundaryMapLength =
181 ACPI_ROUND_UP (Address, ACPI_DEFAULT_PAGE_SIZE) - Address;
182 if (PageBoundaryMapLength == 0)
184 PageBoundaryMapLength = ACPI_DEFAULT_PAGE_SIZE;
187 if (MapLength > PageBoundaryMapLength)
189 MapLength = PageBoundaryMapLength;
192 /* Create a new mapping starting at the address given */
194 MemInfo->MappedLogicalAddress = AcpiOsMapMemory (
195 (ACPI_PHYSICAL_ADDRESS) Address, MapLength);
196 if (!MemInfo->MappedLogicalAddress)
198 ACPI_ERROR ((AE_INFO,
199 "Could not map memory at 0x%8.8X%8.8X, size %u",
200 ACPI_FORMAT_NATIVE_UINT (Address), (UINT32) MapLength));
201 MemInfo->MappedLength = 0;
202 return_ACPI_STATUS (AE_NO_MEMORY);
205 /* Save the physical address and mapping size */
207 MemInfo->MappedPhysicalAddress = Address;
208 MemInfo->MappedLength = MapLength;
212 * Generate a logical pointer corresponding to the address we want to
215 LogicalAddrPtr = MemInfo->MappedLogicalAddress +
216 ((UINT64) Address - (UINT64) MemInfo->MappedPhysicalAddress);
218 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
219 "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
220 BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
223 * Perform the memory read or write
225 * Note: For machines that do not support non-aligned transfers, the target
226 * address was checked for alignment above. We do not attempt to break the
227 * transfer up into smaller (byte-size) chunks because the AML specifically
228 * asked for a transfer width that the hardware may require.
239 *Value = (UINT64) ACPI_GET8 (LogicalAddrPtr);
244 *Value = (UINT64) ACPI_GET16 (LogicalAddrPtr);
249 *Value = (UINT64) ACPI_GET32 (LogicalAddrPtr);
254 *Value = (UINT64) ACPI_GET64 (LogicalAddrPtr);
259 /* BitWidth was already validated */
271 ACPI_SET8 (LogicalAddrPtr, *Value);
276 ACPI_SET16 (LogicalAddrPtr, *Value);
281 ACPI_SET32 (LogicalAddrPtr, *Value);
286 ACPI_SET64 (LogicalAddrPtr, *Value);
291 /* BitWidth was already validated */
299 Status = AE_BAD_PARAMETER;
303 return_ACPI_STATUS (Status);
307 /*******************************************************************************
309 * FUNCTION: AcpiExSystemIoSpaceHandler
311 * PARAMETERS: Function - Read or Write operation
312 * Address - Where in the space to read or write
313 * BitWidth - Field width in bits (8, 16, or 32)
314 * Value - Pointer to in or out value
315 * HandlerContext - Pointer to Handler's context
316 * RegionContext - Pointer to context specific to the
321 * DESCRIPTION: Handler for the System IO address space (Op Region)
323 ******************************************************************************/
326 AcpiExSystemIoSpaceHandler (
328 ACPI_PHYSICAL_ADDRESS Address,
331 void *HandlerContext,
334 ACPI_STATUS Status = AE_OK;
338 ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler);
341 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
342 "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
343 BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
345 /* Decode the function parameter */
351 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address,
358 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address,
359 (UINT32) *Value, BitWidth);
364 Status = AE_BAD_PARAMETER;
368 return_ACPI_STATUS (Status);
372 /*******************************************************************************
374 * FUNCTION: AcpiExPciConfigSpaceHandler
376 * PARAMETERS: Function - Read or Write operation
377 * Address - Where in the space to read or write
378 * BitWidth - Field width in bits (8, 16, or 32)
379 * Value - Pointer to in or out value
380 * HandlerContext - Pointer to Handler's context
381 * RegionContext - Pointer to context specific to the
386 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
388 ******************************************************************************/
391 AcpiExPciConfigSpaceHandler (
393 ACPI_PHYSICAL_ADDRESS Address,
396 void *HandlerContext,
399 ACPI_STATUS Status = AE_OK;
404 ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler);
408 * The arguments to AcpiOs(Read|Write)PciConfiguration are:
410 * PciSegment is the PCI bus segment range 0-31
411 * PciBus is the PCI bus number range 0-255
412 * PciDevice is the PCI device number range 0-31
413 * PciFunction is the PCI device function number
414 * PciRegister is the Config space register range 0-255 bytes
416 * Value - input value for write, output address for read
419 PciId = (ACPI_PCI_ID *) RegionContext;
420 PciRegister = (UINT16) (UINT32) Address;
422 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
423 "Pci-Config %u (%u) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
424 Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device,
425 PciId->Function, PciRegister));
432 Status = AcpiOsReadPciConfiguration (PciId, PciRegister,
438 Status = AcpiOsWritePciConfiguration (PciId, PciRegister,
444 Status = AE_BAD_PARAMETER;
448 return_ACPI_STATUS (Status);
452 /*******************************************************************************
454 * FUNCTION: AcpiExCmosSpaceHandler
456 * PARAMETERS: Function - Read or Write operation
457 * Address - Where in the space to read or write
458 * BitWidth - Field width in bits (8, 16, or 32)
459 * Value - Pointer to in or out value
460 * HandlerContext - Pointer to Handler's context
461 * RegionContext - Pointer to context specific to the
466 * DESCRIPTION: Handler for the CMOS address space (Op Region)
468 ******************************************************************************/
471 AcpiExCmosSpaceHandler (
473 ACPI_PHYSICAL_ADDRESS Address,
476 void *HandlerContext,
479 ACPI_STATUS Status = AE_OK;
482 ACPI_FUNCTION_TRACE (ExCmosSpaceHandler);
485 return_ACPI_STATUS (Status);
489 /*******************************************************************************
491 * FUNCTION: AcpiExPciBarSpaceHandler
493 * PARAMETERS: Function - Read or Write operation
494 * Address - Where in the space to read or write
495 * BitWidth - Field width in bits (8, 16, or 32)
496 * Value - Pointer to in or out value
497 * HandlerContext - Pointer to Handler's context
498 * RegionContext - Pointer to context specific to the
503 * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
505 ******************************************************************************/
508 AcpiExPciBarSpaceHandler (
510 ACPI_PHYSICAL_ADDRESS Address,
513 void *HandlerContext,
516 ACPI_STATUS Status = AE_OK;
519 ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler);
522 return_ACPI_STATUS (Status);
526 /*******************************************************************************
528 * FUNCTION: AcpiExDataTableSpaceHandler
530 * PARAMETERS: Function - Read or Write operation
531 * Address - Where in the space to read or write
532 * BitWidth - Field width in bits (8, 16, or 32)
533 * Value - Pointer to in or out value
534 * HandlerContext - Pointer to Handler's context
535 * RegionContext - Pointer to context specific to the
540 * DESCRIPTION: Handler for the Data Table address space (Op Region)
542 ******************************************************************************/
545 AcpiExDataTableSpaceHandler (
547 ACPI_PHYSICAL_ADDRESS Address,
550 void *HandlerContext,
553 ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler);
557 * Perform the memory read or write. The BitWidth was already
564 ACPI_MEMCPY (ACPI_CAST_PTR (char, Value), ACPI_PHYSADDR_TO_PTR (Address),
565 ACPI_DIV_8 (BitWidth));
570 ACPI_MEMCPY (ACPI_PHYSADDR_TO_PTR (Address), ACPI_CAST_PTR (char, Value),
571 ACPI_DIV_8 (BitWidth));
576 return_ACPI_STATUS (AE_BAD_PARAMETER);
579 return_ACPI_STATUS (AE_OK);