2 /******************************************************************************
4 * Module Name: exregion - ACPI default op_region (address space) handlers
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2005, R. Byron Moore
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.
46 #include <acpi/acpi.h>
47 #include <acpi/acinterp.h>
50 #define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME ("exregion")
54 /*******************************************************************************
56 * FUNCTION: acpi_ex_system_memory_space_handler
58 * PARAMETERS: Function - Read or Write operation
59 * Address - Where in the space to read or write
60 * bit_width - Field width in bits (8, 16, or 32)
61 * Value - Pointer to in or out value
62 * handler_context - Pointer to Handler's context
63 * region_context - Pointer to context specific to the
68 * DESCRIPTION: Handler for the System Memory address space (Op Region)
70 ******************************************************************************/
73 acpi_ex_system_memory_space_handler (
75 acpi_physical_address address
,
78 void *handler_context
,
81 acpi_status status
= AE_OK
;
82 void *logical_addr_ptr
= NULL
;
83 struct acpi_mem_space_context
*mem_info
= region_context
;
85 acpi_size window_size
;
86 #ifndef ACPI_MISALIGNED_TRANSFERS
90 ACPI_FUNCTION_TRACE ("ex_system_memory_space_handler");
93 /* Validate and translate the bit width */
113 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Invalid system_memory width %d\n",
115 return_ACPI_STATUS (AE_AML_OPERAND_VALUE
);
118 #ifndef ACPI_MISALIGNED_TRANSFERS
120 * Hardware does not support non-aligned data transfers, we must verify
123 (void) acpi_ut_short_divide ((acpi_integer
) address
, length
, NULL
, &remainder
);
124 if (remainder
!= 0) {
125 return_ACPI_STATUS (AE_AML_ALIGNMENT
);
130 * Does the request fit into the cached memory mapping?
131 * Is 1) Address below the current mapping? OR
132 * 2) Address beyond the current mapping?
134 if ((address
< mem_info
->mapped_physical_address
) ||
135 (((acpi_integer
) address
+ length
) >
137 mem_info
->mapped_physical_address
+ mem_info
->mapped_length
))) {
139 * The request cannot be resolved by the current memory mapping;
140 * Delete the existing mapping and create a new one.
142 if (mem_info
->mapped_length
) {
143 /* Valid mapping, delete it */
145 acpi_os_unmap_memory (mem_info
->mapped_logical_address
,
146 mem_info
->mapped_length
);
150 * Don't attempt to map memory beyond the end of the region, and
151 * constrain the maximum mapping size to something reasonable.
153 window_size
= (acpi_size
)
154 ((mem_info
->address
+ mem_info
->length
) - address
);
156 if (window_size
> ACPI_SYSMEM_REGION_WINDOW_SIZE
) {
157 window_size
= ACPI_SYSMEM_REGION_WINDOW_SIZE
;
160 /* Create a new mapping starting at the address given */
162 status
= acpi_os_map_memory (address
, window_size
,
163 (void **) &mem_info
->mapped_logical_address
);
164 if (ACPI_FAILURE (status
)) {
165 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
166 "Could not map memory at %8.8X%8.8X, size %X\n",
167 ACPI_FORMAT_UINT64 (address
), (u32
) window_size
));
168 mem_info
->mapped_length
= 0;
169 return_ACPI_STATUS (status
);
172 /* Save the physical address and mapping size */
174 mem_info
->mapped_physical_address
= address
;
175 mem_info
->mapped_length
= window_size
;
179 * Generate a logical pointer corresponding to the address we want to
182 logical_addr_ptr
= mem_info
->mapped_logical_address
+
183 ((acpi_integer
) address
-
184 (acpi_integer
) mem_info
->mapped_physical_address
);
186 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
187 "system_memory %d (%d width) Address=%8.8X%8.8X\n",
189 ACPI_FORMAT_UINT64 (address
)));
192 * Perform the memory read or write
194 * Note: For machines that do not support non-aligned transfers, the target
195 * address was checked for alignment above. We do not attempt to break the
196 * transfer up into smaller (byte-size) chunks because the AML specifically
197 * asked for a transfer width that the hardware may require.
205 *value
= (acpi_integer
) *((u8
*) logical_addr_ptr
);
209 *value
= (acpi_integer
) *((u16
*) logical_addr_ptr
);
213 *value
= (acpi_integer
) *((u32
*) logical_addr_ptr
);
216 #if ACPI_MACHINE_WIDTH != 16
218 *value
= (acpi_integer
) *((u64
*) logical_addr_ptr
);
222 /* bit_width was already validated */
231 *(u8
*) logical_addr_ptr
= (u8
) *value
;
235 *(u16
*) logical_addr_ptr
= (u16
) *value
;
239 *(u32
*) logical_addr_ptr
= (u32
) *value
;
242 #if ACPI_MACHINE_WIDTH != 16
244 *(u64
*) logical_addr_ptr
= (u64
) *value
;
249 /* bit_width was already validated */
255 status
= AE_BAD_PARAMETER
;
259 return_ACPI_STATUS (status
);
263 /*******************************************************************************
265 * FUNCTION: acpi_ex_system_io_space_handler
267 * PARAMETERS: Function - Read or Write operation
268 * Address - Where in the space to read or write
269 * bit_width - Field width in bits (8, 16, or 32)
270 * Value - Pointer to in or out value
271 * handler_context - Pointer to Handler's context
272 * region_context - Pointer to context specific to the
277 * DESCRIPTION: Handler for the System IO address space (Op Region)
279 ******************************************************************************/
282 acpi_ex_system_io_space_handler (
284 acpi_physical_address address
,
287 void *handler_context
,
288 void *region_context
)
290 acpi_status status
= AE_OK
;
294 ACPI_FUNCTION_TRACE ("ex_system_io_space_handler");
297 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
298 "system_iO %d (%d width) Address=%8.8X%8.8X\n", function
, bit_width
,
299 ACPI_FORMAT_UINT64 (address
)));
301 /* Decode the function parameter */
306 status
= acpi_os_read_port ((acpi_io_address
) address
,
307 &value32
, bit_width
);
313 status
= acpi_os_write_port ((acpi_io_address
) address
,
314 (u32
) *value
, bit_width
);
318 status
= AE_BAD_PARAMETER
;
322 return_ACPI_STATUS (status
);
326 /*******************************************************************************
328 * FUNCTION: acpi_ex_pci_config_space_handler
330 * PARAMETERS: Function - Read or Write operation
331 * Address - Where in the space to read or write
332 * bit_width - Field width in bits (8, 16, or 32)
333 * Value - Pointer to in or out value
334 * handler_context - Pointer to Handler's context
335 * region_context - Pointer to context specific to the
340 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
342 ******************************************************************************/
345 acpi_ex_pci_config_space_handler (
347 acpi_physical_address address
,
350 void *handler_context
,
351 void *region_context
)
353 acpi_status status
= AE_OK
;
354 struct acpi_pci_id
*pci_id
;
358 ACPI_FUNCTION_TRACE ("ex_pci_config_space_handler");
362 * The arguments to acpi_os(Read|Write)pci_configuration are:
364 * pci_segment is the PCI bus segment range 0-31
365 * pci_bus is the PCI bus number range 0-255
366 * pci_device is the PCI device number range 0-31
367 * pci_function is the PCI device function number
368 * pci_register is the Config space register range 0-255 bytes
370 * Value - input value for write, output address for read
373 pci_id
= (struct acpi_pci_id
*) region_context
;
374 pci_register
= (u16
) (u32
) address
;
376 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
377 "pci_config %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
378 function
, bit_width
, pci_id
->segment
, pci_id
->bus
, pci_id
->device
,
379 pci_id
->function
, pci_register
));
385 status
= acpi_os_read_pci_configuration (pci_id
, pci_register
,
391 status
= acpi_os_write_pci_configuration (pci_id
, pci_register
,
397 status
= AE_BAD_PARAMETER
;
401 return_ACPI_STATUS (status
);
405 /*******************************************************************************
407 * FUNCTION: acpi_ex_cmos_space_handler
409 * PARAMETERS: Function - Read or Write operation
410 * Address - Where in the space to read or write
411 * bit_width - Field width in bits (8, 16, or 32)
412 * Value - Pointer to in or out value
413 * handler_context - Pointer to Handler's context
414 * region_context - Pointer to context specific to the
419 * DESCRIPTION: Handler for the CMOS address space (Op Region)
421 ******************************************************************************/
424 acpi_ex_cmos_space_handler (
426 acpi_physical_address address
,
429 void *handler_context
,
430 void *region_context
)
432 acpi_status status
= AE_OK
;
435 ACPI_FUNCTION_TRACE ("ex_cmos_space_handler");
438 return_ACPI_STATUS (status
);
442 /*******************************************************************************
444 * FUNCTION: acpi_ex_pci_bar_space_handler
446 * PARAMETERS: Function - Read or Write operation
447 * Address - Where in the space to read or write
448 * bit_width - Field width in bits (8, 16, or 32)
449 * Value - Pointer to in or out value
450 * handler_context - Pointer to Handler's context
451 * region_context - Pointer to context specific to the
456 * DESCRIPTION: Handler for the PCI bar_target address space (Op Region)
458 ******************************************************************************/
461 acpi_ex_pci_bar_space_handler (
463 acpi_physical_address address
,
466 void *handler_context
,
467 void *region_context
)
469 acpi_status status
= AE_OK
;
472 ACPI_FUNCTION_TRACE ("ex_pci_bar_space_handler");
475 return_ACPI_STATUS (status
);
479 /*******************************************************************************
481 * FUNCTION: acpi_ex_data_table_space_handler
483 * PARAMETERS: Function - Read or Write operation
484 * Address - Where in the space to read or write
485 * bit_width - Field width in bits (8, 16, or 32)
486 * Value - Pointer to in or out value
487 * handler_context - Pointer to Handler's context
488 * region_context - Pointer to context specific to the
493 * DESCRIPTION: Handler for the Data Table address space (Op Region)
495 ******************************************************************************/
498 acpi_ex_data_table_space_handler (
500 acpi_physical_address address
,
503 void *handler_context
,
504 void *region_context
)
506 acpi_status status
= AE_OK
;
507 u32 byte_width
= ACPI_DIV_8 (bit_width
);
509 char *logical_addr_ptr
;
512 ACPI_FUNCTION_TRACE ("ex_data_table_space_handler");
515 logical_addr_ptr
= ACPI_PHYSADDR_TO_PTR (address
);
517 /* Perform the memory read or write */
522 for (i
= 0; i
< byte_width
; i
++) {
523 ((char *) value
) [i
] = logical_addr_ptr
[i
];
530 return_ACPI_STATUS (AE_SUPPORT
);
533 return_ACPI_STATUS (status
);