- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / interpreter / amregion.c
blobdfe4fab85928950f5e1861dea675f39dda175149
2 /******************************************************************************
4 * Module Name: amregion - ACPI default Op_region (address space) handlers
5 * $Revision: 41 $
7 *****************************************************************************/
9 /*
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
28 #include "acpi.h"
29 #include "acinterp.h"
30 #include "amlcode.h"
31 #include "acnamesp.h"
32 #include "achware.h"
33 #include "acevents.h"
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
50 * accessed region
52 * RETURN: Status
54 * DESCRIPTION: Handler for the System Memory address space (Op Region)
56 ******************************************************************************/
58 ACPI_STATUS
59 acpi_aml_system_memory_space_handler (
60 u32 function,
61 ACPI_PHYSICAL_ADDRESS address,
62 u32 bit_width,
63 u32 *value,
64 void *handler_context,
65 void *region_context)
67 ACPI_STATUS status = AE_OK;
68 void *logical_addr_ptr = NULL;
69 MEM_HANDLER_CONTEXT *mem_info = region_context;
70 u32 length;
73 /* Validate and translate the bit width */
75 switch (bit_width)
77 case 8:
78 length = 1;
79 break;
81 case 16:
82 length = 2;
83 break;
85 case 32:
86 length = 4;
87 break;
89 default:
90 return (AE_AML_OPERAND_VALUE);
91 break;
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)) {
124 return (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
136 * access
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 */
146 switch (function)
149 case ADDRESS_SPACE_READ:
151 switch (bit_width)
153 case 8:
154 *value = (u32)* (u8 *) logical_addr_ptr;
155 break;
157 case 16:
158 MOVE_UNALIGNED16_TO_32 (value, logical_addr_ptr);
159 break;
161 case 32:
162 MOVE_UNALIGNED32_TO_32 (value, logical_addr_ptr);
163 break;
166 break;
169 case ADDRESS_SPACE_WRITE:
171 switch (bit_width)
173 case 8:
174 *(u8 *) logical_addr_ptr = (u8) *value;
175 break;
177 case 16:
178 MOVE_UNALIGNED16_TO_16 (logical_addr_ptr, value);
179 break;
181 case 32:
182 MOVE_UNALIGNED32_TO_32 (logical_addr_ptr, value);
183 break;
186 break;
189 default:
190 status = AE_BAD_PARAMETER;
191 break;
194 return (status);
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
208 * accessed region
210 * RETURN: Status
212 * DESCRIPTION: Handler for the System IO address space (Op Region)
214 ******************************************************************************/
216 ACPI_STATUS
217 acpi_aml_system_io_space_handler (
218 u32 function,
219 ACPI_PHYSICAL_ADDRESS address,
220 u32 bit_width,
221 u32 *value,
222 void *handler_context,
223 void *region_context)
225 ACPI_STATUS status = AE_OK;
228 /* Decode the function parameter */
230 switch (function)
233 case ADDRESS_SPACE_READ:
235 switch (bit_width)
237 /* I/O Port width */
239 case 8:
240 *value = (u32) acpi_os_in8 ((ACPI_IO_ADDRESS) address);
241 break;
243 case 16:
244 *value = (u32) acpi_os_in16 ((ACPI_IO_ADDRESS) address);
245 break;
247 case 32:
248 *value = acpi_os_in32 ((ACPI_IO_ADDRESS) address);
249 break;
251 default:
252 status = AE_AML_OPERAND_VALUE;
255 break;
258 case ADDRESS_SPACE_WRITE:
260 switch (bit_width)
262 /* I/O Port width */
263 case 8:
264 acpi_os_out8 ((ACPI_IO_ADDRESS) address, (u8) *value);
265 break;
267 case 16:
268 acpi_os_out16 ((ACPI_IO_ADDRESS) address, (u16) *value);
269 break;
271 case 32:
272 acpi_os_out32 ((ACPI_IO_ADDRESS) address, *value);
273 break;
275 default:
276 status = AE_AML_OPERAND_VALUE;
279 break;
282 default:
283 status = AE_BAD_PARAMETER;
284 break;
287 return (status);
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
300 * accessed region
302 * RETURN: Status
304 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
306 ******************************************************************************/
308 ACPI_STATUS
309 acpi_aml_pci_config_space_handler (
310 u32 function,
311 ACPI_PHYSICAL_ADDRESS address,
312 u32 bit_width,
313 u32 *value,
314 void *handler_context,
315 void *region_context)
317 ACPI_STATUS status = AE_OK;
318 u32 pci_bus;
319 u32 dev_func;
320 u8 pci_reg;
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;
348 switch (function)
351 case ADDRESS_SPACE_READ:
353 *value = 0;
355 switch (bit_width)
357 /* PCI Register width */
359 case 8:
360 status = acpi_os_read_pci_cfg_byte (pci_bus, dev_func, pci_reg,
361 (u8 *) value);
362 break;
364 case 16:
365 status = acpi_os_read_pci_cfg_word (pci_bus, dev_func, pci_reg,
366 (u16 *) value);
367 break;
369 case 32:
370 status = acpi_os_read_pci_cfg_dword (pci_bus, dev_func, pci_reg,
371 value);
372 break;
374 default:
375 status = AE_AML_OPERAND_VALUE;
377 } /* Switch bit_width */
379 break;
382 case ADDRESS_SPACE_WRITE:
384 switch (bit_width)
386 /* PCI Register width */
388 case 8:
389 status = acpi_os_write_pci_cfg_byte (pci_bus, dev_func, pci_reg,
390 *(u8 *) value);
391 break;
393 case 16:
394 status = acpi_os_write_pci_cfg_word (pci_bus, dev_func, pci_reg,
395 *(u16 *) value);
396 break;
398 case 32:
399 status = acpi_os_write_pci_cfg_dword (pci_bus, dev_func, pci_reg,
400 *value);
401 break;
403 default:
404 status = AE_AML_OPERAND_VALUE;
406 } /* Switch bit_width */
408 break;
411 default:
413 status = AE_BAD_PARAMETER;
414 break;
418 return (status);