1 /******************************************************************************
3 * Module Name: exregion - ACPI default OpRegion (address space) handlers
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2021, 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
;
83 ACPI_MEM_MAPPING
*Mm
= MemInfo
->CurMm
;
86 ACPI_SIZE PageBoundaryMapLength
;
87 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
92 ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler
);
95 /* Validate and translate the bit width */
121 ACPI_ERROR ((AE_INFO
, "Invalid SystemMemory width %u",
123 return_ACPI_STATUS (AE_AML_OPERAND_VALUE
);
126 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
128 * Hardware does not support non-aligned data transfers, we must verify
131 (void) AcpiUtShortDivide ((UINT64
) Address
, Length
, NULL
, &Remainder
);
134 return_ACPI_STATUS (AE_AML_ALIGNMENT
);
139 * Does the request fit into the cached memory mapping?
140 * Is 1) Address below the current mapping? OR
141 * 2) Address beyond the current mapping?
143 if (!Mm
|| (Address
< Mm
->PhysicalAddress
) ||
144 ((UINT64
) Address
+ Length
> (UINT64
) Mm
->PhysicalAddress
+ Mm
->Length
))
147 * The request cannot be resolved by the current memory mapping.
149 * Look for an existing saved mapping covering the address range
150 * at hand. If found, save it as the current one and carry out
153 for (Mm
= MemInfo
->FirstMm
; Mm
; Mm
= Mm
->NextMm
)
155 if (Mm
== MemInfo
->CurMm
)
160 if (Address
< Mm
->PhysicalAddress
)
165 if ((UINT64
) Address
+ Length
> (UINT64
) Mm
->PhysicalAddress
+ Mm
->Length
)
174 /* Create a new mappings list entry */
176 Mm
= ACPI_ALLOCATE_ZEROED(sizeof(*Mm
));
180 "Unable to save memory mapping at 0x%8.8X%8.8X, size %u",
181 ACPI_FORMAT_UINT64(Address
), Length
));
182 return_ACPI_STATUS(AE_NO_MEMORY
);
186 * October 2009: Attempt to map from the requested address to the
187 * end of the region. However, we will never map more than one
188 * page, nor will we cross a page boundary.
190 MapLength
= (ACPI_SIZE
)
191 ((MemInfo
->Address
+ MemInfo
->Length
) - Address
);
194 * If mapping the entire remaining portion of the region will cross
195 * a page boundary, just map up to the page boundary, do not cross.
196 * On some systems, crossing a page boundary while mapping regions
197 * can cause warnings if the pages have different attributes
198 * due to resource management.
200 * This has the added benefit of constraining a single mapping to
201 * one page, which is similar to the original code that used a 4k
204 PageBoundaryMapLength
= (ACPI_SIZE
)
205 (ACPI_ROUND_UP (Address
, ACPI_DEFAULT_PAGE_SIZE
) - Address
);
206 if (PageBoundaryMapLength
== 0)
208 PageBoundaryMapLength
= ACPI_DEFAULT_PAGE_SIZE
;
211 if (MapLength
> PageBoundaryMapLength
)
213 MapLength
= PageBoundaryMapLength
;
216 /* Create a new mapping starting at the address given */
218 LogicalAddrPtr
= AcpiOsMapMemory(Address
, MapLength
);
221 ACPI_ERROR ((AE_INFO
,
222 "Could not map memory at 0x%8.8X%8.8X, size %u",
223 ACPI_FORMAT_UINT64 (Address
), (UINT32
) MapLength
));
225 return_ACPI_STATUS (AE_NO_MEMORY
);
228 /* Save the physical address and mapping size */
230 Mm
->LogicalAddress
= LogicalAddrPtr
;
231 Mm
->PhysicalAddress
= Address
;
232 Mm
->Length
= MapLength
;
235 * Add the new entry to the mappigs list and save it as the
238 Mm
->NextMm
= MemInfo
->FirstMm
;
239 MemInfo
->FirstMm
= Mm
;
245 * Generate a logical pointer corresponding to the address we want to
248 LogicalAddrPtr
= Mm
->LogicalAddress
+
249 ((UINT64
) Address
- (UINT64
) Mm
->PhysicalAddress
);
251 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
252 "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
253 BitWidth
, Function
, ACPI_FORMAT_UINT64 (Address
)));
256 * Perform the memory read or write
258 * Note: For machines that do not support non-aligned transfers, the target
259 * address was checked for alignment above. We do not attempt to break the
260 * transfer up into smaller (byte-size) chunks because the AML specifically
261 * asked for a transfer width that the hardware may require.
272 *Value
= (UINT64
) ACPI_GET8 (LogicalAddrPtr
);
277 *Value
= (UINT64
) ACPI_GET16 (LogicalAddrPtr
);
282 *Value
= (UINT64
) ACPI_GET32 (LogicalAddrPtr
);
287 *Value
= (UINT64
) ACPI_GET64 (LogicalAddrPtr
);
292 /* BitWidth was already validated */
304 ACPI_SET8 (LogicalAddrPtr
, *Value
);
309 ACPI_SET16 (LogicalAddrPtr
, *Value
);
314 ACPI_SET32 (LogicalAddrPtr
, *Value
);
319 ACPI_SET64 (LogicalAddrPtr
, *Value
);
324 /* BitWidth was already validated */
332 Status
= AE_BAD_PARAMETER
;
336 return_ACPI_STATUS (Status
);
340 /*******************************************************************************
342 * FUNCTION: AcpiExSystemIoSpaceHandler
344 * PARAMETERS: Function - Read or Write operation
345 * Address - Where in the space to read or write
346 * BitWidth - Field width in bits (8, 16, or 32)
347 * Value - Pointer to in or out value
348 * HandlerContext - Pointer to Handler's context
349 * RegionContext - Pointer to context specific to the
354 * DESCRIPTION: Handler for the System IO address space (Op Region)
356 ******************************************************************************/
359 AcpiExSystemIoSpaceHandler (
361 ACPI_PHYSICAL_ADDRESS Address
,
364 void *HandlerContext
,
367 ACPI_STATUS Status
= AE_OK
;
371 ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler
);
374 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
375 "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
376 BitWidth
, Function
, ACPI_FORMAT_UINT64 (Address
)));
378 /* Decode the function parameter */
384 Status
= AcpiHwReadPort ((ACPI_IO_ADDRESS
) Address
,
391 Status
= AcpiHwWritePort ((ACPI_IO_ADDRESS
) Address
,
392 (UINT32
) *Value
, BitWidth
);
397 Status
= AE_BAD_PARAMETER
;
401 return_ACPI_STATUS (Status
);
405 /*******************************************************************************
407 * FUNCTION: AcpiExPciConfigSpaceHandler
409 * PARAMETERS: Function - Read or Write operation
410 * Address - Where in the space to read or write
411 * BitWidth - Field width in bits (8, 16, or 32)
412 * Value - Pointer to in or out value
413 * HandlerContext - Pointer to Handler's context
414 * RegionContext - Pointer to context specific to the
419 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
421 ******************************************************************************/
424 AcpiExPciConfigSpaceHandler (
426 ACPI_PHYSICAL_ADDRESS Address
,
429 void *HandlerContext
,
432 ACPI_STATUS Status
= AE_OK
;
437 ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler
);
441 * The arguments to AcpiOs(Read|Write)PciConfiguration are:
443 * PciSegment is the PCI bus segment range 0-31
444 * PciBus is the PCI bus number range 0-255
445 * PciDevice is the PCI device number range 0-31
446 * PciFunction is the PCI device function number
447 * PciRegister is the Config space register range 0-255 bytes
449 * Value - input value for write, output address for read
452 PciId
= (ACPI_PCI_ID
*) RegionContext
;
453 PciRegister
= (UINT16
) (UINT32
) Address
;
455 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
456 "Pci-Config %u (%u) Seg(%04x) Bus(%04x) "
457 "Dev(%04x) Func(%04x) Reg(%04x)\n",
458 Function
, BitWidth
, PciId
->Segment
, PciId
->Bus
, PciId
->Device
,
459 PciId
->Function
, PciRegister
));
466 Status
= AcpiOsReadPciConfiguration (
467 PciId
, PciRegister
, Value
, BitWidth
);
472 Status
= AcpiOsWritePciConfiguration (
473 PciId
, PciRegister
, *Value
, BitWidth
);
478 Status
= AE_BAD_PARAMETER
;
482 return_ACPI_STATUS (Status
);
486 /*******************************************************************************
488 * FUNCTION: AcpiExCmosSpaceHandler
490 * PARAMETERS: Function - Read or Write operation
491 * Address - Where in the space to read or write
492 * BitWidth - Field width in bits (8, 16, or 32)
493 * Value - Pointer to in or out value
494 * HandlerContext - Pointer to Handler's context
495 * RegionContext - Pointer to context specific to the
500 * DESCRIPTION: Handler for the CMOS address space (Op Region)
502 ******************************************************************************/
505 AcpiExCmosSpaceHandler (
507 ACPI_PHYSICAL_ADDRESS Address
,
510 void *HandlerContext
,
513 ACPI_STATUS Status
= AE_OK
;
516 ACPI_FUNCTION_TRACE (ExCmosSpaceHandler
);
519 return_ACPI_STATUS (Status
);
523 /*******************************************************************************
525 * FUNCTION: AcpiExPciBarSpaceHandler
527 * PARAMETERS: Function - Read or Write operation
528 * Address - Where in the space to read or write
529 * BitWidth - Field width in bits (8, 16, or 32)
530 * Value - Pointer to in or out value
531 * HandlerContext - Pointer to Handler's context
532 * RegionContext - Pointer to context specific to the
537 * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
539 ******************************************************************************/
542 AcpiExPciBarSpaceHandler (
544 ACPI_PHYSICAL_ADDRESS Address
,
547 void *HandlerContext
,
550 ACPI_STATUS Status
= AE_OK
;
553 ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler
);
556 return_ACPI_STATUS (Status
);
560 /*******************************************************************************
562 * FUNCTION: AcpiExDataTableSpaceHandler
564 * PARAMETERS: Function - Read or Write operation
565 * Address - Where in the space to read or write
566 * BitWidth - Field width in bits (8, 16, or 32)
567 * Value - Pointer to in or out value
568 * HandlerContext - Pointer to Handler's context
569 * RegionContext - Pointer to context specific to the
574 * DESCRIPTION: Handler for the Data Table address space (Op Region)
576 ******************************************************************************/
579 AcpiExDataTableSpaceHandler (
581 ACPI_PHYSICAL_ADDRESS Address
,
584 void *HandlerContext
,
587 ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler
);
591 * Perform the memory read or write. The BitWidth was already
598 memcpy (ACPI_CAST_PTR (char, Value
), ACPI_PHYSADDR_TO_PTR (Address
),
599 ACPI_DIV_8 (BitWidth
));
604 memcpy (ACPI_PHYSADDR_TO_PTR (Address
), ACPI_CAST_PTR (char, Value
),
605 ACPI_DIV_8 (BitWidth
));
610 return_ACPI_STATUS (AE_BAD_PARAMETER
);
613 return_ACPI_STATUS (AE_OK
);