1 /******************************************************************************
3 * Module Name: exregion - ACPI default op_region (address space) handlers
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, 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.
44 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_EXECUTER
49 ACPI_MODULE_NAME("exregion")
51 /*******************************************************************************
53 * FUNCTION: acpi_ex_system_memory_space_handler
55 * PARAMETERS: function - Read or Write operation
56 * address - Where in the space to read or write
57 * bit_width - Field width in bits (8, 16, or 32)
58 * value - Pointer to in or out value
59 * handler_context - Pointer to Handler's context
60 * region_context - Pointer to context specific to the
65 * DESCRIPTION: Handler for the System Memory address space (Op Region)
67 ******************************************************************************/
69 acpi_ex_system_memory_space_handler(u32 function,
70 acpi_physical_address address,
73 void *handler_context, void *region_context)
75 acpi_status status = AE_OK;
76 void *logical_addr_ptr = NULL;
77 struct acpi_mem_space_context *mem_info = region_context;
80 acpi_size page_boundary_map_length;
81 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
85 ACPI_FUNCTION_TRACE(ex_system_memory_space_handler);
87 /* Validate and translate the bit width */
107 ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %u",
109 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
112 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
114 * Hardware does not support non-aligned data transfers, we must verify
117 (void)acpi_ut_short_divide((u64) address, length, NULL, &remainder);
118 if (remainder != 0) {
119 return_ACPI_STATUS(AE_AML_ALIGNMENT);
124 * Does the request fit into the cached memory mapping?
125 * Is 1) Address below the current mapping? OR
126 * 2) Address beyond the current mapping?
128 if ((address < mem_info->mapped_physical_address) ||
129 (((u64) address + length) > ((u64)
130 mem_info->mapped_physical_address +
131 mem_info->mapped_length))) {
133 * The request cannot be resolved by the current memory mapping;
134 * Delete the existing mapping and create a new one.
136 if (mem_info->mapped_length) {
138 /* Valid mapping, delete it */
140 acpi_os_unmap_memory(mem_info->mapped_logical_address,
141 mem_info->mapped_length);
145 * Attempt to map from the requested address to the end of the region.
146 * However, we will never map more than one page, nor will we cross
149 map_length = (acpi_size)
150 ((mem_info->address + mem_info->length) - address);
153 * If mapping the entire remaining portion of the region will cross
154 * a page boundary, just map up to the page boundary, do not cross.
155 * On some systems, crossing a page boundary while mapping regions
156 * can cause warnings if the pages have different attributes
157 * due to resource management
159 page_boundary_map_length =
160 ACPI_ROUND_UP(address, ACPI_DEFAULT_PAGE_SIZE) - address;
162 if (!page_boundary_map_length) {
163 page_boundary_map_length = ACPI_DEFAULT_PAGE_SIZE;
166 if (map_length > page_boundary_map_length) {
167 map_length = page_boundary_map_length;
170 /* Create a new mapping starting at the address given */
172 mem_info->mapped_logical_address = acpi_os_map_memory((acpi_physical_address) address, map_length);
173 if (!mem_info->mapped_logical_address) {
175 "Could not map memory at 0x%8.8X%8.8X, size %u",
176 ACPI_FORMAT_NATIVE_UINT(address),
178 mem_info->mapped_length = 0;
179 return_ACPI_STATUS(AE_NO_MEMORY);
182 /* Save the physical address and mapping size */
184 mem_info->mapped_physical_address = address;
185 mem_info->mapped_length = map_length;
189 * Generate a logical pointer corresponding to the address we want to
192 logical_addr_ptr = mem_info->mapped_logical_address +
193 ((u64) address - (u64) mem_info->mapped_physical_address);
195 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
196 "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
198 ACPI_FORMAT_NATIVE_UINT(address)));
201 * Perform the memory read or write
203 * Note: For machines that do not support non-aligned transfers, the target
204 * address was checked for alignment above. We do not attempt to break the
205 * transfer up into smaller (byte-size) chunks because the AML specifically
206 * asked for a transfer width that the hardware may require.
214 *value = (u64) ACPI_GET8(logical_addr_ptr);
218 *value = (u64) ACPI_GET16(logical_addr_ptr);
222 *value = (u64) ACPI_GET32(logical_addr_ptr);
226 *value = (u64) ACPI_GET64(logical_addr_ptr);
230 /* bit_width was already validated */
239 ACPI_SET8(logical_addr_ptr) = (u8) * value;
243 ACPI_SET16(logical_addr_ptr) = (u16) * value;
247 ACPI_SET32(logical_addr_ptr) = (u32) * value;
251 ACPI_SET64(logical_addr_ptr) = (u64) * value;
255 /* bit_width was already validated */
261 status = AE_BAD_PARAMETER;
265 return_ACPI_STATUS(status);
268 /*******************************************************************************
270 * FUNCTION: acpi_ex_system_io_space_handler
272 * PARAMETERS: function - Read or Write operation
273 * address - Where in the space to read or write
274 * bit_width - Field width in bits (8, 16, or 32)
275 * value - Pointer to in or out value
276 * handler_context - Pointer to Handler's context
277 * region_context - Pointer to context specific to the
282 * DESCRIPTION: Handler for the System IO address space (Op Region)
284 ******************************************************************************/
287 acpi_ex_system_io_space_handler(u32 function,
288 acpi_physical_address address,
291 void *handler_context, void *region_context)
293 acpi_status status = AE_OK;
296 ACPI_FUNCTION_TRACE(ex_system_io_space_handler);
298 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
299 "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
301 ACPI_FORMAT_NATIVE_UINT(address)));
303 /* Decode the function parameter */
308 status = acpi_hw_read_port((acpi_io_address) address,
309 &value32, bit_width);
315 status = acpi_hw_write_port((acpi_io_address) address,
316 (u32) * value, bit_width);
320 status = AE_BAD_PARAMETER;
324 return_ACPI_STATUS(status);
327 /*******************************************************************************
329 * FUNCTION: acpi_ex_pci_config_space_handler
331 * PARAMETERS: function - Read or Write operation
332 * address - Where in the space to read or write
333 * bit_width - Field width in bits (8, 16, or 32)
334 * value - Pointer to in or out value
335 * handler_context - Pointer to Handler's context
336 * region_context - Pointer to context specific to the
341 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
343 ******************************************************************************/
346 acpi_ex_pci_config_space_handler(u32 function,
347 acpi_physical_address address,
350 void *handler_context, void *region_context)
352 acpi_status status = AE_OK;
353 struct acpi_pci_id *pci_id;
356 ACPI_FUNCTION_TRACE(ex_pci_config_space_handler);
359 * The arguments to acpi_os(Read|Write)pci_configuration are:
361 * pci_segment is the PCI bus segment range 0-31
362 * pci_bus is the PCI bus number range 0-255
363 * pci_device is the PCI device number range 0-31
364 * pci_function is the PCI device function number
365 * pci_register is the Config space register range 0-255 bytes
367 * value - input value for write, output address for read
370 pci_id = (struct acpi_pci_id *)region_context;
371 pci_register = (u16) (u32) address;
373 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
374 "Pci-Config %u (%u) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
375 function, bit_width, pci_id->segment, pci_id->bus,
376 pci_id->device, pci_id->function, pci_register));
381 status = acpi_os_read_pci_configuration(pci_id, pci_register,
387 status = acpi_os_write_pci_configuration(pci_id, pci_register,
393 status = AE_BAD_PARAMETER;
397 return_ACPI_STATUS(status);
400 /*******************************************************************************
402 * FUNCTION: acpi_ex_cmos_space_handler
404 * PARAMETERS: function - Read or Write operation
405 * address - Where in the space to read or write
406 * bit_width - Field width in bits (8, 16, or 32)
407 * value - Pointer to in or out value
408 * handler_context - Pointer to Handler's context
409 * region_context - Pointer to context specific to the
414 * DESCRIPTION: Handler for the CMOS address space (Op Region)
416 ******************************************************************************/
419 acpi_ex_cmos_space_handler(u32 function,
420 acpi_physical_address address,
423 void *handler_context, void *region_context)
425 acpi_status status = AE_OK;
427 ACPI_FUNCTION_TRACE(ex_cmos_space_handler);
429 return_ACPI_STATUS(status);
432 /*******************************************************************************
434 * FUNCTION: acpi_ex_pci_bar_space_handler
436 * PARAMETERS: function - Read or Write operation
437 * address - Where in the space to read or write
438 * bit_width - Field width in bits (8, 16, or 32)
439 * value - Pointer to in or out value
440 * handler_context - Pointer to Handler's context
441 * region_context - Pointer to context specific to the
446 * DESCRIPTION: Handler for the PCI bar_target address space (Op Region)
448 ******************************************************************************/
451 acpi_ex_pci_bar_space_handler(u32 function,
452 acpi_physical_address address,
455 void *handler_context, void *region_context)
457 acpi_status status = AE_OK;
459 ACPI_FUNCTION_TRACE(ex_pci_bar_space_handler);
461 return_ACPI_STATUS(status);
464 /*******************************************************************************
466 * FUNCTION: acpi_ex_data_table_space_handler
468 * PARAMETERS: function - Read or Write operation
469 * address - Where in the space to read or write
470 * bit_width - Field width in bits (8, 16, or 32)
471 * value - Pointer to in or out value
472 * handler_context - Pointer to Handler's context
473 * region_context - Pointer to context specific to the
478 * DESCRIPTION: Handler for the Data Table address space (Op Region)
480 ******************************************************************************/
483 acpi_ex_data_table_space_handler(u32 function,
484 acpi_physical_address address,
487 void *handler_context, void *region_context)
489 ACPI_FUNCTION_TRACE(ex_data_table_space_handler);
492 * Perform the memory read or write. The bit_width was already
498 ACPI_MEMCPY(ACPI_CAST_PTR(char, value),
499 ACPI_PHYSADDR_TO_PTR(address),
500 ACPI_DIV_8(bit_width));
505 ACPI_MEMCPY(ACPI_PHYSADDR_TO_PTR(address),
506 ACPI_CAST_PTR(char, value), ACPI_DIV_8(bit_width));
511 return_ACPI_STATUS(AE_BAD_PARAMETER);
514 return_ACPI_STATUS(AE_OK);