1 /******************************************************************************
3 * Module Name: exregion - ACPI default OpRegion (address space) handlers
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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.
49 #define _COMPONENT ACPI_EXECUTER
50 ACPI_MODULE_NAME ("exregion")
53 /*******************************************************************************
55 * FUNCTION: AcpiExSystemMemorySpaceHandler
57 * PARAMETERS: Function - Read or Write operation
58 * Address - Where in the space to read or write
59 * BitWidth - Field width in bits (8, 16, or 32)
60 * Value - Pointer to in or out value
61 * HandlerContext - Pointer to Handler's context
62 * RegionContext - Pointer to context specific to the
67 * DESCRIPTION: Handler for the System Memory address space (Op Region)
69 ******************************************************************************/
72 AcpiExSystemMemorySpaceHandler (
74 ACPI_PHYSICAL_ADDRESS Address,
80 ACPI_STATUS Status = AE_OK;
81 void *LogicalAddrPtr = NULL;
82 ACPI_MEM_SPACE_CONTEXT *MemInfo = RegionContext;
85 ACPI_SIZE PageBoundaryMapLength;
86 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
91 ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler);
94 /* Validate and translate the bit width */
120 ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %u",
122 return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
125 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
127 * Hardware does not support non-aligned data transfers, we must verify
130 (void) AcpiUtShortDivide ((UINT64) Address, Length, NULL, &Remainder);
133 return_ACPI_STATUS (AE_AML_ALIGNMENT);
138 * Does the request fit into the cached memory mapping?
139 * Is 1) Address below the current mapping? OR
140 * 2) Address beyond the current mapping?
142 if ((Address < MemInfo->MappedPhysicalAddress) ||
143 (((UINT64) Address + Length) >
145 MemInfo->MappedPhysicalAddress + MemInfo->MappedLength)))
148 * The request cannot be resolved by the current memory mapping;
149 * Delete the existing mapping and create a new one.
151 if (MemInfo->MappedLength)
153 /* Valid mapping, delete it */
155 AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress,
156 MemInfo->MappedLength);
160 * October 2009: Attempt to map from the requested address to the
161 * end of the region. However, we will never map more than one
162 * page, nor will we cross a page boundary.
164 MapLength = (ACPI_SIZE)
165 ((MemInfo->Address + MemInfo->Length) - Address);
168 * If mapping the entire remaining portion of the region will cross
169 * a page boundary, just map up to the page boundary, do not cross.
170 * On some systems, crossing a page boundary while mapping regions
171 * can cause warnings if the pages have different attributes
172 * due to resource management.
174 * This has the added benefit of constraining a single mapping to
175 * one page, which is similar to the original code that used a 4k
178 PageBoundaryMapLength = (ACPI_SIZE)
179 (ACPI_ROUND_UP (Address, ACPI_DEFAULT_PAGE_SIZE) - Address);
180 if (PageBoundaryMapLength == 0)
182 PageBoundaryMapLength = ACPI_DEFAULT_PAGE_SIZE;
185 if (MapLength > PageBoundaryMapLength)
187 MapLength = PageBoundaryMapLength;
190 /* Create a new mapping starting at the address given */
192 MemInfo->MappedLogicalAddress = AcpiOsMapMemory (Address, MapLength);
193 if (!MemInfo->MappedLogicalAddress)
195 ACPI_ERROR ((AE_INFO,
196 "Could not map memory at 0x%8.8X%8.8X, size %u",
197 ACPI_FORMAT_UINT64 (Address), (UINT32) MapLength));
198 MemInfo->MappedLength = 0;
199 return_ACPI_STATUS (AE_NO_MEMORY);
202 /* Save the physical address and mapping size */
204 MemInfo->MappedPhysicalAddress = Address;
205 MemInfo->MappedLength = MapLength;
209 * Generate a logical pointer corresponding to the address we want to
212 LogicalAddrPtr = MemInfo->MappedLogicalAddress +
213 ((UINT64) Address - (UINT64) MemInfo->MappedPhysicalAddress);
215 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
216 "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
217 BitWidth, Function, ACPI_FORMAT_UINT64 (Address)));
220 * Perform the memory read or write
222 * Note: For machines that do not support non-aligned transfers, the target
223 * address was checked for alignment above. We do not attempt to break the
224 * transfer up into smaller (byte-size) chunks because the AML specifically
225 * asked for a transfer width that the hardware may require.
236 *Value = (UINT64) ACPI_GET8 (LogicalAddrPtr);
241 *Value = (UINT64) ACPI_GET16 (LogicalAddrPtr);
246 *Value = (UINT64) ACPI_GET32 (LogicalAddrPtr);
251 *Value = (UINT64) ACPI_GET64 (LogicalAddrPtr);
256 /* BitWidth was already validated */
268 ACPI_SET8 (LogicalAddrPtr, *Value);
273 ACPI_SET16 (LogicalAddrPtr, *Value);
278 ACPI_SET32 (LogicalAddrPtr, *Value);
283 ACPI_SET64 (LogicalAddrPtr, *Value);
288 /* BitWidth was already validated */
296 Status = AE_BAD_PARAMETER;
300 return_ACPI_STATUS (Status);
304 /*******************************************************************************
306 * FUNCTION: AcpiExSystemIoSpaceHandler
308 * PARAMETERS: Function - Read or Write operation
309 * Address - Where in the space to read or write
310 * BitWidth - Field width in bits (8, 16, or 32)
311 * Value - Pointer to in or out value
312 * HandlerContext - Pointer to Handler's context
313 * RegionContext - Pointer to context specific to the
318 * DESCRIPTION: Handler for the System IO address space (Op Region)
320 ******************************************************************************/
323 AcpiExSystemIoSpaceHandler (
325 ACPI_PHYSICAL_ADDRESS Address,
328 void *HandlerContext,
331 ACPI_STATUS Status = AE_OK;
335 ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler);
338 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
339 "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
340 BitWidth, Function, ACPI_FORMAT_UINT64 (Address)));
342 /* Decode the function parameter */
348 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address,
355 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address,
356 (UINT32) *Value, BitWidth);
361 Status = AE_BAD_PARAMETER;
365 return_ACPI_STATUS (Status);
369 /*******************************************************************************
371 * FUNCTION: AcpiExPciConfigSpaceHandler
373 * PARAMETERS: Function - Read or Write operation
374 * Address - Where in the space to read or write
375 * BitWidth - Field width in bits (8, 16, or 32)
376 * Value - Pointer to in or out value
377 * HandlerContext - Pointer to Handler's context
378 * RegionContext - Pointer to context specific to the
383 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
385 ******************************************************************************/
388 AcpiExPciConfigSpaceHandler (
390 ACPI_PHYSICAL_ADDRESS Address,
393 void *HandlerContext,
396 ACPI_STATUS Status = AE_OK;
401 ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler);
405 * The arguments to AcpiOs(Read|Write)PciConfiguration are:
407 * PciSegment is the PCI bus segment range 0-31
408 * PciBus is the PCI bus number range 0-255
409 * PciDevice is the PCI device number range 0-31
410 * PciFunction is the PCI device function number
411 * PciRegister is the Config space register range 0-255 bytes
413 * Value - input value for write, output address for read
416 PciId = (ACPI_PCI_ID *) RegionContext;
417 PciRegister = (UINT16) (UINT32) Address;
419 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
420 "Pci-Config %u (%u) Seg(%04x) Bus(%04x) "
421 "Dev(%04x) Func(%04x) Reg(%04x)\n",
422 Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device,
423 PciId->Function, PciRegister));
430 Status = AcpiOsReadPciConfiguration (
431 PciId, PciRegister, Value, BitWidth);
436 Status = AcpiOsWritePciConfiguration (
437 PciId, PciRegister, *Value, BitWidth);
442 Status = AE_BAD_PARAMETER;
446 return_ACPI_STATUS (Status);
450 /*******************************************************************************
452 * FUNCTION: AcpiExCmosSpaceHandler
454 * PARAMETERS: Function - Read or Write operation
455 * Address - Where in the space to read or write
456 * BitWidth - Field width in bits (8, 16, or 32)
457 * Value - Pointer to in or out value
458 * HandlerContext - Pointer to Handler's context
459 * RegionContext - Pointer to context specific to the
464 * DESCRIPTION: Handler for the CMOS address space (Op Region)
466 ******************************************************************************/
469 AcpiExCmosSpaceHandler (
471 ACPI_PHYSICAL_ADDRESS Address,
474 void *HandlerContext,
477 ACPI_STATUS Status = AE_OK;
480 ACPI_FUNCTION_TRACE (ExCmosSpaceHandler);
483 return_ACPI_STATUS (Status);
487 /*******************************************************************************
489 * FUNCTION: AcpiExPciBarSpaceHandler
491 * PARAMETERS: Function - Read or Write operation
492 * Address - Where in the space to read or write
493 * BitWidth - Field width in bits (8, 16, or 32)
494 * Value - Pointer to in or out value
495 * HandlerContext - Pointer to Handler's context
496 * RegionContext - Pointer to context specific to the
501 * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
503 ******************************************************************************/
506 AcpiExPciBarSpaceHandler (
508 ACPI_PHYSICAL_ADDRESS Address,
511 void *HandlerContext,
514 ACPI_STATUS Status = AE_OK;
517 ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler);
520 return_ACPI_STATUS (Status);
524 /*******************************************************************************
526 * FUNCTION: AcpiExDataTableSpaceHandler
528 * PARAMETERS: Function - Read or Write operation
529 * Address - Where in the space to read or write
530 * BitWidth - Field width in bits (8, 16, or 32)
531 * Value - Pointer to in or out value
532 * HandlerContext - Pointer to Handler's context
533 * RegionContext - Pointer to context specific to the
538 * DESCRIPTION: Handler for the Data Table address space (Op Region)
540 ******************************************************************************/
543 AcpiExDataTableSpaceHandler (
545 ACPI_PHYSICAL_ADDRESS Address,
548 void *HandlerContext,
551 ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler);
555 * Perform the memory read or write. The BitWidth was already
562 memcpy (ACPI_CAST_PTR (char, Value), ACPI_PHYSADDR_TO_PTR (Address),
563 ACPI_DIV_8 (BitWidth));
568 memcpy (ACPI_PHYSADDR_TO_PTR (Address), ACPI_CAST_PTR (char, Value),
569 ACPI_DIV_8 (BitWidth));
574 return_ACPI_STATUS (AE_BAD_PARAMETER);
577 return_ACPI_STATUS (AE_OK);