Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / components / executer / exregion.c
blob304cfe6262f68701aff90972ba0fdaa8013a2e3b
1 /******************************************************************************
3 * Module Name: exregion - ACPI default OpRegion (address space) handlers
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 "acpi.h"
48 #include "accommon.h"
49 #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
66 * accessed region
68 * RETURN: Status
70 * DESCRIPTION: Handler for the System Memory address space (Op Region)
72 ******************************************************************************/
74 ACPI_STATUS
75 AcpiExSystemMemorySpaceHandler (
76 UINT32 Function,
77 ACPI_PHYSICAL_ADDRESS Address,
78 UINT32 BitWidth,
79 UINT64 *Value,
80 void *HandlerContext,
81 void *RegionContext)
83 ACPI_STATUS Status = AE_OK;
84 void *LogicalAddrPtr = NULL;
85 ACPI_MEM_SPACE_CONTEXT *MemInfo = RegionContext;
86 UINT32 Length;
87 ACPI_SIZE MapLength;
88 ACPI_SIZE PageBoundaryMapLength;
89 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
90 UINT32 Remainder;
91 #endif
94 ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler);
97 /* Validate and translate the bit width */
99 switch (BitWidth)
101 case 8:
103 Length = 1;
104 break;
106 case 16:
108 Length = 2;
109 break;
111 case 32:
113 Length = 4;
114 break;
116 case 64:
118 Length = 8;
119 break;
121 default:
123 ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %u",
124 BitWidth));
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
131 * the request.
133 (void) AcpiUtShortDivide ((UINT64) Address, Length, NULL, &Remainder);
134 if (Remainder != 0)
136 return_ACPI_STATUS (AE_AML_ALIGNMENT);
138 #endif
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) >
147 ((UINT64)
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
179 * maximum window.
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
214 * access
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.
231 switch (Function)
233 case ACPI_READ:
235 *Value = 0;
236 switch (BitWidth)
238 case 8:
240 *Value = (UINT64) ACPI_GET8 (LogicalAddrPtr);
241 break;
243 case 16:
245 *Value = (UINT64) ACPI_GET16 (LogicalAddrPtr);
246 break;
248 case 32:
250 *Value = (UINT64) ACPI_GET32 (LogicalAddrPtr);
251 break;
253 case 64:
255 *Value = (UINT64) ACPI_GET64 (LogicalAddrPtr);
256 break;
258 default:
260 /* BitWidth was already validated */
262 break;
264 break;
266 case ACPI_WRITE:
268 switch (BitWidth)
270 case 8:
272 ACPI_SET8 (LogicalAddrPtr, *Value);
273 break;
275 case 16:
277 ACPI_SET16 (LogicalAddrPtr, *Value);
278 break;
280 case 32:
282 ACPI_SET32 (LogicalAddrPtr, *Value);
283 break;
285 case 64:
287 ACPI_SET64 (LogicalAddrPtr, *Value);
288 break;
290 default:
292 /* BitWidth was already validated */
294 break;
296 break;
298 default:
300 Status = AE_BAD_PARAMETER;
301 break;
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
318 * accessed region
320 * RETURN: Status
322 * DESCRIPTION: Handler for the System IO address space (Op Region)
324 ******************************************************************************/
326 ACPI_STATUS
327 AcpiExSystemIoSpaceHandler (
328 UINT32 Function,
329 ACPI_PHYSICAL_ADDRESS Address,
330 UINT32 BitWidth,
331 UINT64 *Value,
332 void *HandlerContext,
333 void *RegionContext)
335 ACPI_STATUS Status = AE_OK;
336 UINT32 Value32;
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 */
348 switch (Function)
350 case ACPI_READ:
352 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address,
353 &Value32, BitWidth);
354 *Value = Value32;
355 break;
357 case ACPI_WRITE:
359 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address,
360 (UINT32) *Value, BitWidth);
361 break;
363 default:
365 Status = AE_BAD_PARAMETER;
366 break;
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
383 * accessed region
385 * RETURN: Status
387 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
389 ******************************************************************************/
391 ACPI_STATUS
392 AcpiExPciConfigSpaceHandler (
393 UINT32 Function,
394 ACPI_PHYSICAL_ADDRESS Address,
395 UINT32 BitWidth,
396 UINT64 *Value,
397 void *HandlerContext,
398 void *RegionContext)
400 ACPI_STATUS Status = AE_OK;
401 ACPI_PCI_ID *PciId;
402 UINT16 PciRegister;
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));
428 switch (Function)
430 case ACPI_READ:
432 *Value = 0;
433 Status = AcpiOsReadPciConfiguration (PciId, PciRegister,
434 Value, BitWidth);
435 break;
437 case ACPI_WRITE:
439 Status = AcpiOsWritePciConfiguration (PciId, PciRegister,
440 *Value, BitWidth);
441 break;
443 default:
445 Status = AE_BAD_PARAMETER;
446 break;
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
463 * accessed region
465 * RETURN: Status
467 * DESCRIPTION: Handler for the CMOS address space (Op Region)
469 ******************************************************************************/
471 ACPI_STATUS
472 AcpiExCmosSpaceHandler (
473 UINT32 Function,
474 ACPI_PHYSICAL_ADDRESS Address,
475 UINT32 BitWidth,
476 UINT64 *Value,
477 void *HandlerContext,
478 void *RegionContext)
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
500 * accessed region
502 * RETURN: Status
504 * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
506 ******************************************************************************/
508 ACPI_STATUS
509 AcpiExPciBarSpaceHandler (
510 UINT32 Function,
511 ACPI_PHYSICAL_ADDRESS Address,
512 UINT32 BitWidth,
513 UINT64 *Value,
514 void *HandlerContext,
515 void *RegionContext)
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
537 * accessed region
539 * RETURN: Status
541 * DESCRIPTION: Handler for the Data Table address space (Op Region)
543 ******************************************************************************/
545 ACPI_STATUS
546 AcpiExDataTableSpaceHandler (
547 UINT32 Function,
548 ACPI_PHYSICAL_ADDRESS Address,
549 UINT32 BitWidth,
550 UINT64 *Value,
551 void *HandlerContext,
552 void *RegionContext)
554 ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler);
558 * Perform the memory read or write. The BitWidth was already
559 * validated.
561 switch (Function)
563 case ACPI_READ:
565 ACPI_MEMCPY (ACPI_CAST_PTR (char, Value), ACPI_PHYSADDR_TO_PTR (Address),
566 ACPI_DIV_8 (BitWidth));
567 break;
569 case ACPI_WRITE:
571 ACPI_MEMCPY (ACPI_PHYSADDR_TO_PTR (Address), ACPI_CAST_PTR (char, Value),
572 ACPI_DIV_8 (BitWidth));
573 break;
575 default:
577 return_ACPI_STATUS (AE_BAD_PARAMETER);
580 return_ACPI_STATUS (AE_OK);