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
32 #define _COMPONENT ACPI_EXECUTER
33 MODULE_NAME ("amregion")
36 /*******************************************************************************
38 * FUNCTION: Acpi_aml_system_memory_space_handler
40 * PARAMETERS: Function - Read or Write operation
41 * Address - Where in the space to read or write
42 * Bit_width - Field width in bits (8, 16, or 32)
43 * Value - Pointer to in or out value
44 * Handler_context - Pointer to Handler's context
45 * Region_context - Pointer to context specific to the
50 * DESCRIPTION: Handler for the System Memory address space (Op Region)
52 ******************************************************************************/
55 acpi_aml_system_memory_space_handler (
57 ACPI_PHYSICAL_ADDRESS address
,
60 void *handler_context
,
63 ACPI_STATUS status
= AE_OK
;
64 void *logical_addr_ptr
= NULL
;
65 MEM_HANDLER_CONTEXT
*mem_info
= region_context
;
69 /* Validate and translate the bit width */
85 return (AE_AML_OPERAND_VALUE
);
91 * Does the request fit into the cached memory mapping?
92 * Is 1) Address below the current mapping? OR
93 * 2) Address beyond the current mapping?
96 if ((address
< mem_info
->mapped_physical_address
) ||
97 (((ACPI_INTEGER
) address
+ length
) >
98 ((ACPI_INTEGER
) mem_info
->mapped_physical_address
+ mem_info
->mapped_length
))) {
100 * The request cannot be resolved by the current memory mapping;
101 * Delete the existing mapping and create a new one.
104 if (mem_info
->mapped_length
) {
105 /* Valid mapping, delete it */
107 acpi_os_unmap_memory (mem_info
->mapped_logical_address
,
108 mem_info
->mapped_length
);
111 mem_info
->mapped_length
= 0; /* In case of failure below */
113 /* Create a new mapping starting at the address given */
115 status
= acpi_os_map_memory (address
, SYSMEM_REGION_WINDOW_SIZE
,
116 (void **) &mem_info
->mapped_logical_address
);
117 if (ACPI_FAILURE (status
)) {
121 /* TBD: should these pointers go to 64-bit in all cases ? */
123 mem_info
->mapped_physical_address
= address
;
124 mem_info
->mapped_length
= SYSMEM_REGION_WINDOW_SIZE
;
129 * Generate a logical pointer corresponding to the address we want to
133 /* TBD: should these pointers go to 64-bit in all cases ? */
135 logical_addr_ptr
= mem_info
->mapped_logical_address
+
136 ((ACPI_INTEGER
) address
- (ACPI_INTEGER
) mem_info
->mapped_physical_address
);
138 /* Perform the memory read or write */
142 case ADDRESS_SPACE_READ
:
146 *value
= (u32
)* (u8
*) logical_addr_ptr
;
150 MOVE_UNALIGNED16_TO_32 (value
, logical_addr_ptr
);
154 MOVE_UNALIGNED32_TO_32 (value
, logical_addr_ptr
);
161 case ADDRESS_SPACE_WRITE
:
165 *(u8
*) logical_addr_ptr
= (u8
) *value
;
169 MOVE_UNALIGNED16_TO_16 (logical_addr_ptr
, value
);
173 MOVE_UNALIGNED32_TO_32 (logical_addr_ptr
, value
);
181 status
= AE_BAD_PARAMETER
;
189 /*******************************************************************************
191 * FUNCTION: Acpi_aml_system_io_space_handler
193 * PARAMETERS: Function - Read or Write operation
194 * Address - Where in the space to read or write
195 * Bit_width - Field width in bits (8, 16, or 32)
196 * Value - Pointer to in or out value
197 * Handler_context - Pointer to Handler's context
198 * Region_context - Pointer to context specific to the
203 * DESCRIPTION: Handler for the System IO address space (Op Region)
205 ******************************************************************************/
208 acpi_aml_system_io_space_handler (
210 ACPI_PHYSICAL_ADDRESS address
,
213 void *handler_context
,
214 void *region_context
)
216 ACPI_STATUS status
= AE_OK
;
219 /* Decode the function parameter */
223 case ADDRESS_SPACE_READ
:
229 *value
= (u32
) acpi_os_in8 ((ACPI_IO_ADDRESS
) address
);
233 *value
= (u32
) acpi_os_in16 ((ACPI_IO_ADDRESS
) address
);
237 *value
= acpi_os_in32 ((ACPI_IO_ADDRESS
) address
);
241 status
= AE_AML_OPERAND_VALUE
;
247 case ADDRESS_SPACE_WRITE
:
252 acpi_os_out8 ((ACPI_IO_ADDRESS
) address
, (u8
) *value
);
256 acpi_os_out16 ((ACPI_IO_ADDRESS
) address
, (u16
) *value
);
260 acpi_os_out32 ((ACPI_IO_ADDRESS
) address
, *value
);
264 status
= AE_AML_OPERAND_VALUE
;
271 status
= AE_BAD_PARAMETER
;
278 /*******************************************************************************
280 * FUNCTION: Acpi_aml_pci_config_space_handler
282 * PARAMETERS: Function - Read or Write operation
283 * Address - Where in the space to read or write
284 * Bit_width - Field width in bits (8, 16, or 32)
285 * Value - Pointer to in or out value
286 * Handler_context - Pointer to Handler's context
287 * Region_context - Pointer to context specific to the
292 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
294 ******************************************************************************/
297 acpi_aml_pci_config_space_handler (
299 ACPI_PHYSICAL_ADDRESS address
,
302 void *handler_context
,
303 void *region_context
)
305 ACPI_STATUS status
= AE_OK
;
309 PCI_HANDLER_CONTEXT
*PCIcontext
;
313 * The arguments to Acpi_os(Read|Write)Pci_cfg(Byte|Word|Dword) are:
315 * Seg_bus - 0xSSSSBBBB - SSSS is the PCI bus segment
316 * BBBB is the PCI bus number
318 * Dev_func - 0xDDDDFFFF - DDDD is the PCI device number
319 * FFFF is the PCI device function number
321 * Reg_num - Config space register must be < 40h
323 * Value - input value for write, output for read
327 PCIcontext
= (PCI_HANDLER_CONTEXT
*) region_context
;
329 pci_bus
= LOWORD(PCIcontext
->seg
) << 16;
330 pci_bus
|= LOWORD(PCIcontext
->bus
);
332 dev_func
= PCIcontext
->dev_func
;
334 pci_reg
= (u8
) address
;
338 case ADDRESS_SPACE_READ
:
343 /* PCI Register width */
346 status
= acpi_os_read_pci_cfg_byte (pci_bus
, dev_func
, pci_reg
,
351 status
= acpi_os_read_pci_cfg_word (pci_bus
, dev_func
, pci_reg
,
356 status
= acpi_os_read_pci_cfg_dword (pci_bus
, dev_func
, pci_reg
,
361 status
= AE_AML_OPERAND_VALUE
;
363 } /* Switch bit_width */
368 case ADDRESS_SPACE_WRITE
:
371 /* PCI Register width */
374 status
= acpi_os_write_pci_cfg_byte (pci_bus
, dev_func
, pci_reg
,
379 status
= acpi_os_write_pci_cfg_word (pci_bus
, dev_func
, pci_reg
,
384 status
= acpi_os_write_pci_cfg_dword (pci_bus
, dev_func
, pci_reg
,
389 status
= AE_AML_OPERAND_VALUE
;
391 } /* Switch bit_width */
398 status
= AE_BAD_PARAMETER
;