2 /******************************************************************************
4 * Module Name: amregion - ACPI default Op_region (address space) handlers
7 *****************************************************************************/
10 * Copyright (C) 2000, 2001 R. Byron Moore
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #define _COMPONENT ACPI_EXECUTER
37 MODULE_NAME ("amregion")
40 /*******************************************************************************
42 * FUNCTION: Acpi_aml_system_memory_space_handler
44 * PARAMETERS: Function - Read or Write operation
45 * Address - Where in the space to read or write
46 * Bit_width - Field width in bits (8, 16, or 32)
47 * Value - Pointer to in or out value
48 * Handler_context - Pointer to Handler's context
49 * Region_context - Pointer to context specific to the
54 * DESCRIPTION: Handler for the System Memory address space (Op Region)
56 ******************************************************************************/
59 acpi_aml_system_memory_space_handler (
61 ACPI_PHYSICAL_ADDRESS address
,
64 void *handler_context
,
67 ACPI_STATUS status
= AE_OK
;
68 void *logical_addr_ptr
= NULL
;
69 MEM_HANDLER_CONTEXT
*mem_info
= region_context
;
73 /* Validate and translate the bit width */
89 return (AE_AML_OPERAND_VALUE
);
95 * Does the request fit into the cached memory mapping?
96 * Is 1) Address below the current mapping? OR
97 * 2) Address beyond the current mapping?
100 if ((address
< mem_info
->mapped_physical_address
) ||
101 (((ACPI_INTEGER
) address
+ length
) >
102 ((ACPI_INTEGER
) mem_info
->mapped_physical_address
+ mem_info
->mapped_length
))) {
104 * The request cannot be resolved by the current memory mapping;
105 * Delete the existing mapping and create a new one.
108 if (mem_info
->mapped_length
) {
109 /* Valid mapping, delete it */
111 acpi_os_unmap_memory (mem_info
->mapped_logical_address
,
112 mem_info
->mapped_length
);
115 mem_info
->mapped_length
= 0; /* In case of failure below */
117 /* Create a new mapping starting at the address given */
119 status
= acpi_os_map_memory (address
, SYSMEM_REGION_WINDOW_SIZE
,
120 (void **) &mem_info
->mapped_logical_address
);
121 if (ACPI_FAILURE (status
)) {
125 /* TBD: should these pointers go to 64-bit in all cases ? */
127 mem_info
->mapped_physical_address
= address
;
128 mem_info
->mapped_length
= SYSMEM_REGION_WINDOW_SIZE
;
133 * Generate a logical pointer corresponding to the address we want to
137 /* TBD: should these pointers go to 64-bit in all cases ? */
139 logical_addr_ptr
= mem_info
->mapped_logical_address
+
140 ((ACPI_INTEGER
) address
- (ACPI_INTEGER
) mem_info
->mapped_physical_address
);
142 /* Perform the memory read or write */
146 case ADDRESS_SPACE_READ
:
150 *value
= (u32
)* (u8
*) logical_addr_ptr
;
154 MOVE_UNALIGNED16_TO_32 (value
, logical_addr_ptr
);
158 MOVE_UNALIGNED32_TO_32 (value
, logical_addr_ptr
);
165 case ADDRESS_SPACE_WRITE
:
169 *(u8
*) logical_addr_ptr
= (u8
) *value
;
173 MOVE_UNALIGNED16_TO_16 (logical_addr_ptr
, value
);
177 MOVE_UNALIGNED32_TO_32 (logical_addr_ptr
, value
);
185 status
= AE_BAD_PARAMETER
;
193 /*******************************************************************************
195 * FUNCTION: Acpi_aml_system_io_space_handler
197 * PARAMETERS: Function - Read or Write operation
198 * Address - Where in the space to read or write
199 * Bit_width - Field width in bits (8, 16, or 32)
200 * Value - Pointer to in or out value
201 * Handler_context - Pointer to Handler's context
202 * Region_context - Pointer to context specific to the
207 * DESCRIPTION: Handler for the System IO address space (Op Region)
209 ******************************************************************************/
212 acpi_aml_system_io_space_handler (
214 ACPI_PHYSICAL_ADDRESS address
,
217 void *handler_context
,
218 void *region_context
)
220 ACPI_STATUS status
= AE_OK
;
223 /* Decode the function parameter */
227 case ADDRESS_SPACE_READ
:
233 *value
= (u32
) acpi_os_in8 ((ACPI_IO_ADDRESS
) address
);
237 *value
= (u32
) acpi_os_in16 ((ACPI_IO_ADDRESS
) address
);
241 *value
= acpi_os_in32 ((ACPI_IO_ADDRESS
) address
);
245 status
= AE_AML_OPERAND_VALUE
;
251 case ADDRESS_SPACE_WRITE
:
256 acpi_os_out8 ((ACPI_IO_ADDRESS
) address
, (u8
) *value
);
260 acpi_os_out16 ((ACPI_IO_ADDRESS
) address
, (u16
) *value
);
264 acpi_os_out32 ((ACPI_IO_ADDRESS
) address
, *value
);
268 status
= AE_AML_OPERAND_VALUE
;
275 status
= AE_BAD_PARAMETER
;
282 /*******************************************************************************
284 * FUNCTION: Acpi_aml_pci_config_space_handler
286 * PARAMETERS: Function - Read or Write operation
287 * Address - Where in the space to read or write
288 * Bit_width - Field width in bits (8, 16, or 32)
289 * Value - Pointer to in or out value
290 * Handler_context - Pointer to Handler's context
291 * Region_context - Pointer to context specific to the
296 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
298 ******************************************************************************/
301 acpi_aml_pci_config_space_handler (
303 ACPI_PHYSICAL_ADDRESS address
,
306 void *handler_context
,
307 void *region_context
)
309 ACPI_STATUS status
= AE_OK
;
313 PCI_HANDLER_CONTEXT
*PCIcontext
;
317 * The arguments to Acpi_os(Read|Write)Pci_cfg(Byte|Word|Dword) are:
319 * Seg_bus - 0xSSSSBBBB - SSSS is the PCI bus segment
320 * BBBB is the PCI bus number
322 * Dev_func - 0xDDDDFFFF - DDDD is the PCI device number
323 * FFFF is the PCI device function number
325 * Reg_num - Config space register must be < 40h
327 * Value - input value for write, output for read
331 PCIcontext
= (PCI_HANDLER_CONTEXT
*) region_context
;
333 pci_bus
= LOWORD(PCIcontext
->seg
) << 16;
334 pci_bus
|= LOWORD(PCIcontext
->bus
);
336 dev_func
= PCIcontext
->dev_func
;
338 pci_reg
= (u8
) address
;
342 case ADDRESS_SPACE_READ
:
347 /* PCI Register width */
350 status
= acpi_os_read_pci_cfg_byte (pci_bus
, dev_func
, pci_reg
,
355 status
= acpi_os_read_pci_cfg_word (pci_bus
, dev_func
, pci_reg
,
360 status
= acpi_os_read_pci_cfg_dword (pci_bus
, dev_func
, pci_reg
,
365 status
= AE_AML_OPERAND_VALUE
;
367 } /* Switch bit_width */
372 case ADDRESS_SPACE_WRITE
:
375 /* PCI Register width */
378 status
= acpi_os_write_pci_cfg_byte (pci_bus
, dev_func
, pci_reg
,
383 status
= acpi_os_write_pci_cfg_word (pci_bus
, dev_func
, pci_reg
,
388 status
= acpi_os_write_pci_cfg_dword (pci_bus
, dev_func
, pci_reg
,
393 status
= AE_AML_OPERAND_VALUE
;
395 } /* Switch bit_width */
402 status
= AE_BAD_PARAMETER
;