2 /******************************************************************************
4 * Module Name: amregion - ACPI default Op_region (address space) handlers
7 *****************************************************************************/
10 * Copyright (C) 2000 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 INTERPRETER
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 */
90 return (AE_AML_OPERAND_VALUE
);
96 * Does the request fit into the cached memory mapping?
97 * Is 1) Address below the current mapping? OR
98 * 2) Address beyond the current mapping?
101 if ((address
< mem_info
->mapped_physical_address
) ||
102 ((address
+ length
) >
103 (mem_info
->mapped_physical_address
+ mem_info
->mapped_length
)))
106 * The request cannot be resolved by the current memory mapping;
107 * Delete the existing mapping and create a new one.
110 if (mem_info
->mapped_length
) {
111 /* Valid mapping, delete it */
113 acpi_os_unmap_memory (mem_info
->mapped_logical_address
,
114 mem_info
->mapped_length
);
117 mem_info
->mapped_length
= 0; /* In case of failure below */
119 /* Create a new mapping starting at the address given */
121 status
= acpi_os_map_memory (address
, SYSMEM_REGION_WINDOW_SIZE
,
122 (void **) &mem_info
->mapped_logical_address
);
123 if (ACPI_FAILURE (status
)) {
127 /* TBD: should these pointers go to 64-bit in all cases ? */
129 mem_info
->mapped_physical_address
= address
;
130 mem_info
->mapped_length
= SYSMEM_REGION_WINDOW_SIZE
;
135 * Generate a logical pointer corresponding to the address we want to
139 /* TBD: should these pointers go to 64-bit in all cases ? */
141 logical_addr_ptr
= mem_info
->mapped_logical_address
+
142 (address
- mem_info
->mapped_physical_address
);
144 /* Perform the memory read or write */
149 case ADDRESS_SPACE_READ
:
154 *value
= (u32
)* (u8
*) logical_addr_ptr
;
158 MOVE_UNALIGNED16_TO_32 (value
, logical_addr_ptr
);
162 MOVE_UNALIGNED32_TO_32 (value
, logical_addr_ptr
);
169 case ADDRESS_SPACE_WRITE
:
174 *(u8
*) logical_addr_ptr
= (u8
) *value
;
178 MOVE_UNALIGNED16_TO_16 (logical_addr_ptr
, value
);
182 MOVE_UNALIGNED32_TO_32 (logical_addr_ptr
, value
);
190 status
= AE_BAD_PARAMETER
;
198 /*******************************************************************************
200 * FUNCTION: Acpi_aml_system_io_space_handler
202 * PARAMETERS: Function - Read or Write operation
203 * Address - Where in the space to read or write
204 * Bit_width - Field width in bits (8, 16, or 32)
205 * Value - Pointer to in or out value
206 * Handler_context - Pointer to Handler's context
207 * Region_context - Pointer to context specific to the
212 * DESCRIPTION: Handler for the System IO address space (Op Region)
214 ******************************************************************************/
217 acpi_aml_system_io_space_handler (
219 ACPI_PHYSICAL_ADDRESS address
,
222 void *handler_context
,
223 void *region_context
)
225 ACPI_STATUS status
= AE_OK
;
228 /* Decode the function parameter */
233 case ADDRESS_SPACE_READ
:
240 *value
= (u32
) acpi_os_in8 ((ACPI_IO_ADDRESS
) address
);
244 *value
= (u32
) acpi_os_in16 ((ACPI_IO_ADDRESS
) address
);
248 *value
= acpi_os_in32 ((ACPI_IO_ADDRESS
) address
);
252 status
= AE_AML_OPERAND_VALUE
;
258 case ADDRESS_SPACE_WRITE
:
264 acpi_os_out8 ((ACPI_IO_ADDRESS
) address
, (u8
) *value
);
268 acpi_os_out16 ((ACPI_IO_ADDRESS
) address
, (u16
) *value
);
272 acpi_os_out32 ((ACPI_IO_ADDRESS
) address
, *value
);
276 status
= AE_AML_OPERAND_VALUE
;
283 status
= AE_BAD_PARAMETER
;
290 /*******************************************************************************
292 * FUNCTION: Acpi_aml_pci_config_space_handler
294 * PARAMETERS: Function - Read or Write operation
295 * Address - Where in the space to read or write
296 * Bit_width - Field width in bits (8, 16, or 32)
297 * Value - Pointer to in or out value
298 * Handler_context - Pointer to Handler's context
299 * Region_context - Pointer to context specific to the
304 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
306 ******************************************************************************/
309 acpi_aml_pci_config_space_handler (
311 ACPI_PHYSICAL_ADDRESS address
,
314 void *handler_context
,
315 void *region_context
)
317 ACPI_STATUS status
= AE_OK
;
321 PCI_HANDLER_CONTEXT
*PCIcontext
;
325 * The arguments to Acpi_os(Read|Write)Pci_cfg(Byte|Word|Dword) are:
327 * Seg_bus - 0xSSSSBBBB - SSSS is the PCI bus segment
328 * BBBB is the PCI bus number
330 * Dev_func - 0xDDDDFFFF - DDDD is the PCI device number
331 * FFFF is the PCI device function number
333 * Reg_num - Config space register must be < 40h
335 * Value - input value for write, output for read
339 PCIcontext
= (PCI_HANDLER_CONTEXT
*) region_context
;
341 pci_bus
= LOWORD(PCIcontext
->seg
) << 16;
342 pci_bus
|= LOWORD(PCIcontext
->bus
);
344 dev_func
= PCIcontext
->dev_func
;
346 pci_reg
= (u8
) address
;
351 case ADDRESS_SPACE_READ
:
357 /* PCI Register width */
360 status
= acpi_os_read_pci_cfg_byte (pci_bus
, dev_func
, pci_reg
,
365 status
= acpi_os_read_pci_cfg_word (pci_bus
, dev_func
, pci_reg
,
370 status
= acpi_os_read_pci_cfg_dword (pci_bus
, dev_func
, pci_reg
,
375 status
= AE_AML_OPERAND_VALUE
;
377 } /* Switch bit_width */
382 case ADDRESS_SPACE_WRITE
:
386 /* PCI Register width */
389 status
= acpi_os_write_pci_cfg_byte (pci_bus
, dev_func
, pci_reg
,
394 status
= acpi_os_write_pci_cfg_word (pci_bus
, dev_func
, pci_reg
,
399 status
= acpi_os_write_pci_cfg_dword (pci_bus
, dev_func
, pci_reg
,
404 status
= AE_AML_OPERAND_VALUE
;
406 } /* Switch bit_width */
413 status
= AE_BAD_PARAMETER
;