2 /******************************************************************************
4 * Module Name: exregion - ACPI default op_region (address space) handlers
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #include <acpi/acpi.h>
49 #define _COMPONENT ACPI_EXECUTER
50 ACPI_MODULE_NAME("exregion")
52 /*******************************************************************************
54 * FUNCTION: acpi_ex_system_memory_space_handler
56 * PARAMETERS: Function - Read or Write operation
57 * Address - Where in the space to read or write
58 * bit_width - Field width in bits (8, 16, or 32)
59 * Value - Pointer to in or out value
60 * handler_context - Pointer to Handler's context
61 * region_context - Pointer to context specific to the
66 * DESCRIPTION: Handler for the System Memory address space (Op Region)
68 ******************************************************************************/
70 acpi_ex_system_memory_space_handler(u32 function
,
71 acpi_physical_address address
,
74 void *handler_context
, void *region_context
)
76 acpi_status status
= AE_OK
;
77 void *logical_addr_ptr
= NULL
;
78 struct acpi_mem_space_context
*mem_info
= region_context
;
81 acpi_size page_boundary_map_length
;
82 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
86 ACPI_FUNCTION_TRACE(ex_system_memory_space_handler
);
88 /* Validate and translate the bit width */
108 ACPI_ERROR((AE_INFO
, "Invalid SystemMemory width %d",
110 return_ACPI_STATUS(AE_AML_OPERAND_VALUE
);
113 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
115 * Hardware does not support non-aligned data transfers, we must verify
118 (void)acpi_ut_short_divide((acpi_integer
) address
, length
, NULL
,
120 if (remainder
!= 0) {
121 return_ACPI_STATUS(AE_AML_ALIGNMENT
);
126 * Does the request fit into the cached memory mapping?
127 * Is 1) Address below the current mapping? OR
128 * 2) Address beyond the current mapping?
130 if ((address
< mem_info
->mapped_physical_address
) ||
131 (((acpi_integer
) address
+ length
) > ((acpi_integer
)
133 mapped_physical_address
+
134 mem_info
->mapped_length
))) {
136 * The request cannot be resolved by the current memory mapping;
137 * Delete the existing mapping and create a new one.
139 if (mem_info
->mapped_length
) {
141 /* Valid mapping, delete it */
143 acpi_os_unmap_memory(mem_info
->mapped_logical_address
,
144 mem_info
->mapped_length
);
148 * Attempt to map from the requested address to the end of the region.
149 * However, we will never map more than one page, nor will we cross
152 map_length
= (acpi_size
)
153 ((mem_info
->address
+ mem_info
->length
) - address
);
156 * If mapping the entire remaining portion of the region will cross
157 * a page boundary, just map up to the page boundary, do not cross.
158 * On some systems, crossing a page boundary while mapping regions
159 * can cause warnings if the pages have different attributes
160 * due to resource management
162 page_boundary_map_length
=
163 ACPI_ROUND_UP(address
, ACPI_DEFAULT_PAGE_SIZE
) - address
;
165 if (!page_boundary_map_length
) {
166 page_boundary_map_length
= ACPI_DEFAULT_PAGE_SIZE
;
169 if (map_length
> page_boundary_map_length
) {
170 map_length
= page_boundary_map_length
;
173 /* Create a new mapping starting at the address given */
175 mem_info
->mapped_logical_address
= acpi_os_map_memory((acpi_physical_address
) address
, map_length
);
176 if (!mem_info
->mapped_logical_address
) {
178 "Could not map memory at %8.8X%8.8X, size %X",
179 ACPI_FORMAT_NATIVE_UINT(address
),
181 mem_info
->mapped_length
= 0;
182 return_ACPI_STATUS(AE_NO_MEMORY
);
185 /* Save the physical address and mapping size */
187 mem_info
->mapped_physical_address
= address
;
188 mem_info
->mapped_length
= map_length
;
192 * Generate a logical pointer corresponding to the address we want to
195 logical_addr_ptr
= mem_info
->mapped_logical_address
+
196 ((acpi_integer
) address
-
197 (acpi_integer
) mem_info
->mapped_physical_address
);
199 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
200 "System-Memory (width %d) R/W %d Address=%8.8X%8.8X\n",
202 ACPI_FORMAT_NATIVE_UINT(address
)));
205 * Perform the memory read or write
207 * Note: For machines that do not support non-aligned transfers, the target
208 * address was checked for alignment above. We do not attempt to break the
209 * transfer up into smaller (byte-size) chunks because the AML specifically
210 * asked for a transfer width that the hardware may require.
218 *value
= (acpi_integer
) ACPI_GET8(logical_addr_ptr
);
222 *value
= (acpi_integer
) ACPI_GET16(logical_addr_ptr
);
226 *value
= (acpi_integer
) ACPI_GET32(logical_addr_ptr
);
230 *value
= (acpi_integer
) ACPI_GET64(logical_addr_ptr
);
234 /* bit_width was already validated */
243 ACPI_SET8(logical_addr_ptr
) = (u8
) * value
;
247 ACPI_SET16(logical_addr_ptr
) = (u16
) * value
;
251 ACPI_SET32(logical_addr_ptr
) = (u32
) * value
;
255 ACPI_SET64(logical_addr_ptr
) = (u64
) * value
;
259 /* bit_width was already validated */
265 status
= AE_BAD_PARAMETER
;
269 return_ACPI_STATUS(status
);
272 /*******************************************************************************
274 * FUNCTION: acpi_ex_system_io_space_handler
276 * PARAMETERS: Function - Read or Write operation
277 * Address - Where in the space to read or write
278 * bit_width - Field width in bits (8, 16, or 32)
279 * Value - Pointer to in or out value
280 * handler_context - Pointer to Handler's context
281 * region_context - Pointer to context specific to the
286 * DESCRIPTION: Handler for the System IO address space (Op Region)
288 ******************************************************************************/
291 acpi_ex_system_io_space_handler(u32 function
,
292 acpi_physical_address address
,
294 acpi_integer
* value
,
295 void *handler_context
, void *region_context
)
297 acpi_status status
= AE_OK
;
300 ACPI_FUNCTION_TRACE(ex_system_io_space_handler
);
302 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
303 "System-IO (width %d) R/W %d Address=%8.8X%8.8X\n",
305 ACPI_FORMAT_NATIVE_UINT(address
)));
307 /* Decode the function parameter */
312 status
= acpi_hw_read_port((acpi_io_address
) address
,
313 &value32
, bit_width
);
319 status
= acpi_hw_write_port((acpi_io_address
) address
,
320 (u32
) * value
, bit_width
);
324 status
= AE_BAD_PARAMETER
;
328 return_ACPI_STATUS(status
);
331 /*******************************************************************************
333 * FUNCTION: acpi_ex_pci_config_space_handler
335 * PARAMETERS: Function - Read or Write operation
336 * Address - Where in the space to read or write
337 * bit_width - Field width in bits (8, 16, or 32)
338 * Value - Pointer to in or out value
339 * handler_context - Pointer to Handler's context
340 * region_context - Pointer to context specific to the
345 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
347 ******************************************************************************/
350 acpi_ex_pci_config_space_handler(u32 function
,
351 acpi_physical_address address
,
353 acpi_integer
* value
,
354 void *handler_context
, void *region_context
)
356 acpi_status status
= AE_OK
;
357 struct acpi_pci_id
*pci_id
;
361 ACPI_FUNCTION_TRACE(ex_pci_config_space_handler
);
364 * The arguments to acpi_os(Read|Write)pci_configuration are:
366 * pci_segment is the PCI bus segment range 0-31
367 * pci_bus is the PCI bus number range 0-255
368 * pci_device is the PCI device number range 0-31
369 * pci_function is the PCI device function number
370 * pci_register is the Config space register range 0-255 bytes
372 * Value - input value for write, output address for read
375 pci_id
= (struct acpi_pci_id
*)region_context
;
376 pci_register
= (u16
) (u32
) address
;
378 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
379 "Pci-Config %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
380 function
, bit_width
, pci_id
->segment
, pci_id
->bus
,
381 pci_id
->device
, pci_id
->function
, pci_register
));
386 status
= acpi_os_read_pci_configuration(pci_id
, pci_register
,
387 &value32
, bit_width
);
393 status
= acpi_os_write_pci_configuration(pci_id
, pci_register
,
399 status
= AE_BAD_PARAMETER
;
403 return_ACPI_STATUS(status
);
406 /*******************************************************************************
408 * FUNCTION: acpi_ex_cmos_space_handler
410 * PARAMETERS: Function - Read or Write operation
411 * Address - Where in the space to read or write
412 * bit_width - Field width in bits (8, 16, or 32)
413 * Value - Pointer to in or out value
414 * handler_context - Pointer to Handler's context
415 * region_context - Pointer to context specific to the
420 * DESCRIPTION: Handler for the CMOS address space (Op Region)
422 ******************************************************************************/
425 acpi_ex_cmos_space_handler(u32 function
,
426 acpi_physical_address address
,
428 acpi_integer
* value
,
429 void *handler_context
, void *region_context
)
431 acpi_status status
= AE_OK
;
433 ACPI_FUNCTION_TRACE(ex_cmos_space_handler
);
435 return_ACPI_STATUS(status
);
438 /*******************************************************************************
440 * FUNCTION: acpi_ex_pci_bar_space_handler
442 * PARAMETERS: Function - Read or Write operation
443 * Address - Where in the space to read or write
444 * bit_width - Field width in bits (8, 16, or 32)
445 * Value - Pointer to in or out value
446 * handler_context - Pointer to Handler's context
447 * region_context - Pointer to context specific to the
452 * DESCRIPTION: Handler for the PCI bar_target address space (Op Region)
454 ******************************************************************************/
457 acpi_ex_pci_bar_space_handler(u32 function
,
458 acpi_physical_address address
,
460 acpi_integer
* value
,
461 void *handler_context
, void *region_context
)
463 acpi_status status
= AE_OK
;
465 ACPI_FUNCTION_TRACE(ex_pci_bar_space_handler
);
467 return_ACPI_STATUS(status
);
470 /*******************************************************************************
472 * FUNCTION: acpi_ex_data_table_space_handler
474 * PARAMETERS: Function - Read or Write operation
475 * Address - Where in the space to read or write
476 * bit_width - Field width in bits (8, 16, or 32)
477 * Value - Pointer to in or out value
478 * handler_context - Pointer to Handler's context
479 * region_context - Pointer to context specific to the
484 * DESCRIPTION: Handler for the Data Table address space (Op Region)
486 ******************************************************************************/
489 acpi_ex_data_table_space_handler(u32 function
,
490 acpi_physical_address address
,
492 acpi_integer
* value
,
493 void *handler_context
, void *region_context
)
495 ACPI_FUNCTION_TRACE(ex_data_table_space_handler
);
497 /* Perform the memory read or write */
502 ACPI_MEMCPY(ACPI_CAST_PTR(char, value
),
503 ACPI_PHYSADDR_TO_PTR(address
),
504 ACPI_DIV_8(bit_width
));
510 return_ACPI_STATUS(AE_SUPPORT
);
513 return_ACPI_STATUS(AE_OK
);