Sync usage with man page.
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / executer / exregion.c
blob958dc4e0670559ab272e4de6980060d8b4e5a50a
2 /******************************************************************************
4 * Module Name: exregion - ACPI default OpRegion (address space) handlers
6 *****************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13 * All rights reserved.
15 * 2. License
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
41 * 3. Conditions
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #define __EXREGION_C__
120 #include "acpi.h"
121 #include "accommon.h"
122 #include "acinterp.h"
125 #define _COMPONENT ACPI_EXECUTER
126 ACPI_MODULE_NAME ("exregion")
129 /*******************************************************************************
131 * FUNCTION: AcpiExSystemMemorySpaceHandler
133 * PARAMETERS: Function - Read or Write operation
134 * Address - Where in the space to read or write
135 * BitWidth - Field width in bits (8, 16, or 32)
136 * Value - Pointer to in or out value
137 * HandlerContext - Pointer to Handler's context
138 * RegionContext - Pointer to context specific to the
139 * accessed region
141 * RETURN: Status
143 * DESCRIPTION: Handler for the System Memory address space (Op Region)
145 ******************************************************************************/
147 ACPI_STATUS
148 AcpiExSystemMemorySpaceHandler (
149 UINT32 Function,
150 ACPI_PHYSICAL_ADDRESS Address,
151 UINT32 BitWidth,
152 ACPI_INTEGER *Value,
153 void *HandlerContext,
154 void *RegionContext)
156 ACPI_STATUS Status = AE_OK;
157 void *LogicalAddrPtr = NULL;
158 ACPI_MEM_SPACE_CONTEXT *MemInfo = RegionContext;
159 UINT32 Length;
160 ACPI_SIZE WindowSize;
161 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
162 UINT32 Remainder;
163 #endif
166 ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler);
169 /* Validate and translate the bit width */
171 switch (BitWidth)
173 case 8:
174 Length = 1;
175 break;
177 case 16:
178 Length = 2;
179 break;
181 case 32:
182 Length = 4;
183 break;
185 case 64:
186 Length = 8;
187 break;
189 default:
190 ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %d",
191 BitWidth));
192 return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
195 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
197 * Hardware does not support non-aligned data transfers, we must verify
198 * the request.
200 (void) AcpiUtShortDivide ((ACPI_INTEGER) Address, Length, NULL, &Remainder);
201 if (Remainder != 0)
203 return_ACPI_STATUS (AE_AML_ALIGNMENT);
205 #endif
208 * Does the request fit into the cached memory mapping?
209 * Is 1) Address below the current mapping? OR
210 * 2) Address beyond the current mapping?
212 if ((Address < MemInfo->MappedPhysicalAddress) ||
213 (((ACPI_INTEGER) Address + Length) >
214 ((ACPI_INTEGER)
215 MemInfo->MappedPhysicalAddress + MemInfo->MappedLength)))
218 * The request cannot be resolved by the current memory mapping;
219 * Delete the existing mapping and create a new one.
221 if (MemInfo->MappedLength)
223 /* Valid mapping, delete it */
225 AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress,
226 MemInfo->MappedLength);
230 * Don't attempt to map memory beyond the end of the region, and
231 * constrain the maximum mapping size to something reasonable.
233 WindowSize = (ACPI_SIZE)
234 ((MemInfo->Address + MemInfo->Length) - Address);
236 if (WindowSize > ACPI_SYSMEM_REGION_WINDOW_SIZE)
238 WindowSize = ACPI_SYSMEM_REGION_WINDOW_SIZE;
241 /* Create a new mapping starting at the address given */
243 MemInfo->MappedLogicalAddress = AcpiOsMapMemory (
244 (ACPI_PHYSICAL_ADDRESS) Address, WindowSize);
245 if (!MemInfo->MappedLogicalAddress)
247 ACPI_ERROR ((AE_INFO,
248 "Could not map memory at %8.8X%8.8X, size %X",
249 ACPI_FORMAT_NATIVE_UINT (Address), (UINT32) WindowSize));
250 MemInfo->MappedLength = 0;
251 return_ACPI_STATUS (AE_NO_MEMORY);
254 /* Save the physical address and mapping size */
256 MemInfo->MappedPhysicalAddress = Address;
257 MemInfo->MappedLength = WindowSize;
261 * Generate a logical pointer corresponding to the address we want to
262 * access
264 LogicalAddrPtr = MemInfo->MappedLogicalAddress +
265 ((ACPI_INTEGER) Address - (ACPI_INTEGER) MemInfo->MappedPhysicalAddress);
267 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
268 "System-Memory (width %d) R/W %d Address=%8.8X%8.8X\n",
269 BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
272 * Perform the memory read or write
274 * Note: For machines that do not support non-aligned transfers, the target
275 * address was checked for alignment above. We do not attempt to break the
276 * transfer up into smaller (byte-size) chunks because the AML specifically
277 * asked for a transfer width that the hardware may require.
279 switch (Function)
281 case ACPI_READ:
283 *Value = 0;
284 switch (BitWidth)
286 case 8:
287 *Value = (ACPI_INTEGER) ACPI_GET8 (LogicalAddrPtr);
288 break;
290 case 16:
291 *Value = (ACPI_INTEGER) ACPI_GET16 (LogicalAddrPtr);
292 break;
294 case 32:
295 *Value = (ACPI_INTEGER) ACPI_GET32 (LogicalAddrPtr);
296 break;
298 case 64:
299 *Value = (ACPI_INTEGER) ACPI_GET64 (LogicalAddrPtr);
300 break;
302 default:
303 /* BitWidth was already validated */
304 break;
306 break;
308 case ACPI_WRITE:
310 switch (BitWidth)
312 case 8:
313 ACPI_SET8 (LogicalAddrPtr) = (UINT8) *Value;
314 break;
316 case 16:
317 ACPI_SET16 (LogicalAddrPtr) = (UINT16) *Value;
318 break;
320 case 32:
321 ACPI_SET32 ( LogicalAddrPtr) = (UINT32) *Value;
322 break;
324 case 64:
325 ACPI_SET64 (LogicalAddrPtr) = (UINT64) *Value;
326 break;
328 default:
329 /* BitWidth was already validated */
330 break;
332 break;
334 default:
335 Status = AE_BAD_PARAMETER;
336 break;
339 return_ACPI_STATUS (Status);
343 /*******************************************************************************
345 * FUNCTION: AcpiExSystemIoSpaceHandler
347 * PARAMETERS: Function - Read or Write operation
348 * Address - Where in the space to read or write
349 * BitWidth - Field width in bits (8, 16, or 32)
350 * Value - Pointer to in or out value
351 * HandlerContext - Pointer to Handler's context
352 * RegionContext - Pointer to context specific to the
353 * accessed region
355 * RETURN: Status
357 * DESCRIPTION: Handler for the System IO address space (Op Region)
359 ******************************************************************************/
361 ACPI_STATUS
362 AcpiExSystemIoSpaceHandler (
363 UINT32 Function,
364 ACPI_PHYSICAL_ADDRESS Address,
365 UINT32 BitWidth,
366 ACPI_INTEGER *Value,
367 void *HandlerContext,
368 void *RegionContext)
370 ACPI_STATUS Status = AE_OK;
371 UINT32 Value32;
374 ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler);
377 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
378 "System-IO (width %d) R/W %d Address=%8.8X%8.8X\n",
379 BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
381 /* Decode the function parameter */
383 switch (Function)
385 case ACPI_READ:
387 Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address,
388 &Value32, BitWidth);
389 *Value = Value32;
390 break;
392 case ACPI_WRITE:
394 Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address,
395 (UINT32) *Value, BitWidth);
396 break;
398 default:
399 Status = AE_BAD_PARAMETER;
400 break;
403 return_ACPI_STATUS (Status);
407 /*******************************************************************************
409 * FUNCTION: AcpiExPciConfigSpaceHandler
411 * PARAMETERS: Function - Read or Write operation
412 * Address - Where in the space to read or write
413 * BitWidth - Field width in bits (8, 16, or 32)
414 * Value - Pointer to in or out value
415 * HandlerContext - Pointer to Handler's context
416 * RegionContext - Pointer to context specific to the
417 * accessed region
419 * RETURN: Status
421 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
423 ******************************************************************************/
425 ACPI_STATUS
426 AcpiExPciConfigSpaceHandler (
427 UINT32 Function,
428 ACPI_PHYSICAL_ADDRESS Address,
429 UINT32 BitWidth,
430 ACPI_INTEGER *Value,
431 void *HandlerContext,
432 void *RegionContext)
434 ACPI_STATUS Status = AE_OK;
435 ACPI_PCI_ID *PciId;
436 UINT16 PciRegister;
439 ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler);
443 * The arguments to AcpiOs(Read|Write)PciConfiguration are:
445 * PciSegment is the PCI bus segment range 0-31
446 * PciBus is the PCI bus number range 0-255
447 * PciDevice is the PCI device number range 0-31
448 * PciFunction is the PCI device function number
449 * PciRegister is the Config space register range 0-255 bytes
451 * Value - input value for write, output address for read
454 PciId = (ACPI_PCI_ID *) RegionContext;
455 PciRegister = (UINT16) (UINT32) Address;
457 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
458 "Pci-Config %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
459 Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device,
460 PciId->Function, PciRegister));
462 switch (Function)
464 case ACPI_READ:
466 *Value = 0;
467 Status = AcpiOsReadPciConfiguration (PciId, PciRegister,
468 Value, BitWidth);
469 break;
471 case ACPI_WRITE:
473 Status = AcpiOsWritePciConfiguration (PciId, PciRegister,
474 *Value, BitWidth);
475 break;
477 default:
479 Status = AE_BAD_PARAMETER;
480 break;
483 return_ACPI_STATUS (Status);
487 /*******************************************************************************
489 * FUNCTION: AcpiExCmosSpaceHandler
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
497 * accessed region
499 * RETURN: Status
501 * DESCRIPTION: Handler for the CMOS address space (Op Region)
503 ******************************************************************************/
505 ACPI_STATUS
506 AcpiExCmosSpaceHandler (
507 UINT32 Function,
508 ACPI_PHYSICAL_ADDRESS Address,
509 UINT32 BitWidth,
510 ACPI_INTEGER *Value,
511 void *HandlerContext,
512 void *RegionContext)
514 ACPI_STATUS Status = AE_OK;
517 ACPI_FUNCTION_TRACE (ExCmosSpaceHandler);
520 return_ACPI_STATUS (Status);
524 /*******************************************************************************
526 * FUNCTION: AcpiExPciBarSpaceHandler
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
534 * accessed region
536 * RETURN: Status
538 * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
540 ******************************************************************************/
542 ACPI_STATUS
543 AcpiExPciBarSpaceHandler (
544 UINT32 Function,
545 ACPI_PHYSICAL_ADDRESS Address,
546 UINT32 BitWidth,
547 ACPI_INTEGER *Value,
548 void *HandlerContext,
549 void *RegionContext)
551 ACPI_STATUS Status = AE_OK;
554 ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler);
557 return_ACPI_STATUS (Status);
561 /*******************************************************************************
563 * FUNCTION: AcpiExDataTableSpaceHandler
565 * PARAMETERS: Function - Read or Write operation
566 * Address - Where in the space to read or write
567 * BitWidth - Field width in bits (8, 16, or 32)
568 * Value - Pointer to in or out value
569 * HandlerContext - Pointer to Handler's context
570 * RegionContext - Pointer to context specific to the
571 * accessed region
573 * RETURN: Status
575 * DESCRIPTION: Handler for the Data Table address space (Op Region)
577 ******************************************************************************/
579 ACPI_STATUS
580 AcpiExDataTableSpaceHandler (
581 UINT32 Function,
582 ACPI_PHYSICAL_ADDRESS Address,
583 UINT32 BitWidth,
584 ACPI_INTEGER *Value,
585 void *HandlerContext,
586 void *RegionContext)
588 ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler);
591 /* Perform the memory read or write */
593 switch (Function)
595 case ACPI_READ:
597 ACPI_MEMCPY (ACPI_CAST_PTR (char, Value), ACPI_PHYSADDR_TO_PTR (Address),
598 ACPI_DIV_8 (BitWidth));
599 break;
601 case ACPI_WRITE:
602 default:
604 return_ACPI_STATUS (AE_SUPPORT);
607 return_ACPI_STATUS (AE_OK);