1 /******************************************************************************
3 * Module Name: exregion - ACPI default OpRegion (address space) handlers
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
45 #define __EXREGION_C__
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acinterp.h>
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exregion")
56 /*******************************************************************************
58 * FUNCTION: AcpiExSystemMemorySpaceHandler
60 * PARAMETERS: Function - Read or Write operation
61 * Address - Where in the space to read or write
62 * BitWidth - Field width in bits (8, 16, or 32)
63 * Value - Pointer to in or out value
64 * HandlerContext - Pointer to Handler's context
65 * RegionContext - Pointer to context specific to the
70 * DESCRIPTION: Handler for the System Memory address space (Op Region)
72 ******************************************************************************/
75 AcpiExSystemMemorySpaceHandler (
77 ACPI_PHYSICAL_ADDRESS Address,
83 ACPI_STATUS Status = AE_OK;
84 void *LogicalAddrPtr = NULL;
85 ACPI_MEM_SPACE_CONTEXT *MemInfo = RegionContext;
88 ACPI_SIZE PageBoundaryMapLength;
89 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
94 ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler);
97 /* Validate and translate the bit width */
123 ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %u",
125 return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
128 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
130 * Hardware does not support non-aligned data transfers, we must verify
133 (void) AcpiUtShortDivide ((UINT64) Address, Length, NULL, &Remainder);
136 return_ACPI_STATUS (AE_AML_ALIGNMENT);
141 * Does the request fit into the cached memory mapping?
142 * Is 1) Address below the current mapping? OR
143 * 2) Address beyond the current mapping?
145 if ((Address < MemInfo->MappedPhysicalAddress) ||
146 (((UINT64) Address + Length) >
148 MemInfo->MappedPhysicalAddress + MemInfo->MappedLength)))
151 * The request cannot be resolved by the current memory mapping;
152 * Delete the existing mapping and create a new one.
154 if (MemInfo->MappedLength)
156 /* Valid mapping, delete it */
158 AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress,
159 MemInfo->MappedLength);
163 * October 2009: Attempt to map from the requested address to the
164 * end of the region. However, we will never map more than one
165 * page, nor will we cross a page boundary.
167 MapLength = (ACPI_SIZE)
168 ((MemInfo->Address + MemInfo->Length) - Address);
171 * If mapping the entire remaining portion of the region will cross
172 * a page boundary, just map up to the page boundary, do not cross.
173 * On some systems, crossing a page boundary while mapping regions
174 * can cause warnings if the pages have different attributes
175 * due to resource management.
177 * This has the added benefit of constraining a single mapping to
178 * one page, which is similar to the original code that used a 4k
181 PageBoundaryMapLength =
182 ACPI_ROUND_UP (Address, ACPI_DEFAULT_PAGE_SIZE) - Address;
183 if (PageBoundaryMapLength == 0)
185 PageBoundaryMapLength = ACPI_DEFAULT_PAGE_SIZE;
188 if (MapLength > PageBoundaryMapLength)
190 MapLength = PageBoundaryMapLength;
193 /* Create a new mapping starting at the address given */
195 MemInfo->MappedLogicalAddress = AcpiOsMapMemory (
196 (ACPI_PHYSICAL_ADDRESS) Address, MapLength);
197 if (!MemInfo->MappedLogicalAddress)
199 ACPI_ERROR ((AE_INFO,
200 "Could not map memory at 0x%8.8X%8.8X, size %u",
201 ACPI_FORMAT_NATIVE_UINT (Address), (UINT32) MapLength));
202 MemInfo->MappedLength = 0;
203 return_ACPI_STATUS (AE_NO_MEMORY);
206 /* Save the physical address and mapping size */
208 MemInfo->MappedPhysicalAddress = Address;
209 MemInfo->MappedLength = MapLength;
213 * Generate a logical pointer corresponding to the address we want to
216 LogicalAddrPtr = MemInfo->MappedLogicalAddress +
217 ((UINT64) Address - (UINT64) MemInfo->MappedPhysicalAddress);
219 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
220 "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
221 BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
224 * Perform the memory read or write
226 * Note: For machines that do not support non-aligned transfers, the target
227 * address was checked for alignment above. We do not attempt to break the
228 * transfer up into smaller (byte-size) chunks because the AML specifically
229 * asked for a transfer width that the hardware may require.
240 *Value = (UINT64) ACPI_GET8 (LogicalAddrPtr);
245 *Value = (UINT64) ACPI_GET16 (LogicalAddrPtr);
250 *Value = (UINT64) ACPI_GET32 (LogicalAddrPtr);
255 *Value = (UINT64) ACPI_GET64 (LogicalAddrPtr);
260 /* BitWidth was already validated */
272 ACPI_SET8 (LogicalAddrPtr, *Value);
277 ACPI_SET16 (LogicalAddrPtr, *Value);
282 ACPI_SET32 (LogicalAddrPtr, *Value);
287 ACPI_SET64 (LogicalAddrPtr, *Value);
292 /* BitWidth was already validated */
300 Status = AE_BAD_PARAMETER;
304 return_ACPI_STATUS (Status);
308 /*******************************************************************************
310 * FUNCTION: AcpiExSystemIoSpaceHandler
312 * PARAMETERS: Function - Read or Write operation
313 * Address - Where in the space to read or write
314 * BitWidth - Field width in bits (8, 16, or 32)
315 * Value - Pointer to in or out value
316 * HandlerContext - Pointer to Handler's context
317 * RegionContext - Pointer to context specific to the
322 * DESCRIPTION: Handler for the System IO address space (Op Region)
324 ******************************************************************************/
327 AcpiExSystemIoSpaceHandler (
329 ACPI_PHYSICAL_ADDRESS Address,
332 void *HandlerContext,
335 ACPI_STATUS Status = AE_OK;
339 ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler);
342 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
343 "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
344 BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
346 /* Decode the function parameter */
352 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address,
359 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address,
360 (UINT32) *Value, BitWidth);
365 Status = AE_BAD_PARAMETER;
369 return_ACPI_STATUS (Status);
373 /*******************************************************************************
375 * FUNCTION: AcpiExPciConfigSpaceHandler
377 * PARAMETERS: Function - Read or Write operation
378 * Address - Where in the space to read or write
379 * BitWidth - Field width in bits (8, 16, or 32)
380 * Value - Pointer to in or out value
381 * HandlerContext - Pointer to Handler's context
382 * RegionContext - Pointer to context specific to the
387 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
389 ******************************************************************************/
392 AcpiExPciConfigSpaceHandler (
394 ACPI_PHYSICAL_ADDRESS Address,
397 void *HandlerContext,
400 ACPI_STATUS Status = AE_OK;
405 ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler);
409 * The arguments to AcpiOs(Read|Write)PciConfiguration are:
411 * PciSegment is the PCI bus segment range 0-31
412 * PciBus is the PCI bus number range 0-255
413 * PciDevice is the PCI device number range 0-31
414 * PciFunction is the PCI device function number
415 * PciRegister is the Config space register range 0-255 bytes
417 * Value - input value for write, output address for read
420 PciId = (ACPI_PCI_ID *) RegionContext;
421 PciRegister = (UINT16) (UINT32) Address;
423 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
424 "Pci-Config %u (%u) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
425 Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device,
426 PciId->Function, PciRegister));
433 Status = AcpiOsReadPciConfiguration (PciId, PciRegister,
439 Status = AcpiOsWritePciConfiguration (PciId, PciRegister,
445 Status = AE_BAD_PARAMETER;
449 return_ACPI_STATUS (Status);
453 /*******************************************************************************
455 * FUNCTION: AcpiExCmosSpaceHandler
457 * PARAMETERS: Function - Read or Write operation
458 * Address - Where in the space to read or write
459 * BitWidth - Field width in bits (8, 16, or 32)
460 * Value - Pointer to in or out value
461 * HandlerContext - Pointer to Handler's context
462 * RegionContext - Pointer to context specific to the
467 * DESCRIPTION: Handler for the CMOS address space (Op Region)
469 ******************************************************************************/
472 AcpiExCmosSpaceHandler (
474 ACPI_PHYSICAL_ADDRESS Address,
477 void *HandlerContext,
480 ACPI_STATUS Status = AE_OK;
483 ACPI_FUNCTION_TRACE (ExCmosSpaceHandler);
486 return_ACPI_STATUS (Status);
490 /*******************************************************************************
492 * FUNCTION: AcpiExPciBarSpaceHandler
494 * PARAMETERS: Function - Read or Write operation
495 * Address - Where in the space to read or write
496 * BitWidth - Field width in bits (8, 16, or 32)
497 * Value - Pointer to in or out value
498 * HandlerContext - Pointer to Handler's context
499 * RegionContext - Pointer to context specific to the
504 * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
506 ******************************************************************************/
509 AcpiExPciBarSpaceHandler (
511 ACPI_PHYSICAL_ADDRESS Address,
514 void *HandlerContext,
517 ACPI_STATUS Status = AE_OK;
520 ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler);
523 return_ACPI_STATUS (Status);
527 /*******************************************************************************
529 * FUNCTION: AcpiExDataTableSpaceHandler
531 * PARAMETERS: Function - Read or Write operation
532 * Address - Where in the space to read or write
533 * BitWidth - Field width in bits (8, 16, or 32)
534 * Value - Pointer to in or out value
535 * HandlerContext - Pointer to Handler's context
536 * RegionContext - Pointer to context specific to the
541 * DESCRIPTION: Handler for the Data Table address space (Op Region)
543 ******************************************************************************/
546 AcpiExDataTableSpaceHandler (
548 ACPI_PHYSICAL_ADDRESS Address,
551 void *HandlerContext,
554 ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler);
558 * Perform the memory read or write. The BitWidth was already
565 ACPI_MEMCPY (ACPI_CAST_PTR (char, Value), ACPI_PHYSADDR_TO_PTR (Address),
566 ACPI_DIV_8 (BitWidth));
571 ACPI_MEMCPY (ACPI_PHYSADDR_TO_PTR (Address), ACPI_CAST_PTR (char, Value),
572 ACPI_DIV_8 (BitWidth));
577 return_ACPI_STATUS (AE_BAD_PARAMETER);
580 return_ACPI_STATUS (AE_OK);