ACPICA: Cosmetic changes only, no functional changes
[linux-2.6/mini2440.git] / drivers / acpi / executer / exregion.c
blobcbc67884454f33c7320564ba326bc0e4226b2ae6
2 /******************************************************************************
4 * Module Name: exregion - ACPI default op_region (address space) handlers
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2007, 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
14 * are met:
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.
31 * NO WARRANTY
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acinterp.h>
48 #define _COMPONENT ACPI_EXECUTER
49 ACPI_MODULE_NAME("exregion")
51 /*******************************************************************************
53 * FUNCTION: acpi_ex_system_memory_space_handler
55 * PARAMETERS: Function - Read or Write operation
56 * Address - Where in the space to read or write
57 * bit_width - Field width in bits (8, 16, or 32)
58 * Value - Pointer to in or out value
59 * handler_context - Pointer to Handler's context
60 * region_context - Pointer to context specific to the
61 * accessed region
63 * RETURN: Status
65 * DESCRIPTION: Handler for the System Memory address space (Op Region)
67 ******************************************************************************/
68 acpi_status
69 acpi_ex_system_memory_space_handler(u32 function,
70 acpi_physical_address address,
71 u32 bit_width,
72 acpi_integer * value,
73 void *handler_context, void *region_context)
75 acpi_status status = AE_OK;
76 void *logical_addr_ptr = NULL;
77 struct acpi_mem_space_context *mem_info = region_context;
78 u32 length;
79 acpi_size window_size;
80 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
81 u32 remainder;
82 #endif
84 ACPI_FUNCTION_TRACE(ex_system_memory_space_handler);
86 /* Validate and translate the bit width */
88 switch (bit_width) {
89 case 8:
90 length = 1;
91 break;
93 case 16:
94 length = 2;
95 break;
97 case 32:
98 length = 4;
99 break;
101 case 64:
102 length = 8;
103 break;
105 default:
106 ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %d",
107 bit_width));
108 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
111 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
113 * Hardware does not support non-aligned data transfers, we must verify
114 * the request.
116 (void)acpi_ut_short_divide((acpi_integer) address, length, NULL,
117 &remainder);
118 if (remainder != 0) {
119 return_ACPI_STATUS(AE_AML_ALIGNMENT);
121 #endif
124 * Does the request fit into the cached memory mapping?
125 * Is 1) Address below the current mapping? OR
126 * 2) Address beyond the current mapping?
128 if ((address < mem_info->mapped_physical_address) ||
129 (((acpi_integer) address + length) > ((acpi_integer)
130 mem_info->
131 mapped_physical_address +
132 mem_info->mapped_length))) {
134 * The request cannot be resolved by the current memory mapping;
135 * Delete the existing mapping and create a new one.
137 if (mem_info->mapped_length) {
139 /* Valid mapping, delete it */
141 acpi_os_unmap_memory(mem_info->mapped_logical_address,
142 mem_info->mapped_length);
146 * Don't attempt to map memory beyond the end of the region, and
147 * constrain the maximum mapping size to something reasonable.
149 window_size = (acpi_size)
150 ((mem_info->address + mem_info->length) - address);
152 if (window_size > ACPI_SYSMEM_REGION_WINDOW_SIZE) {
153 window_size = ACPI_SYSMEM_REGION_WINDOW_SIZE;
156 /* Create a new mapping starting at the address given */
158 mem_info->mapped_logical_address =
159 acpi_os_map_memory((acpi_native_uint) address, window_size);
160 if (!mem_info->mapped_logical_address) {
161 ACPI_ERROR((AE_INFO,
162 "Could not map memory at %8.8X%8.8X, size %X",
163 ACPI_FORMAT_NATIVE_UINT(address),
164 (u32) window_size));
165 mem_info->mapped_length = 0;
166 return_ACPI_STATUS(AE_NO_MEMORY);
169 /* Save the physical address and mapping size */
171 mem_info->mapped_physical_address = address;
172 mem_info->mapped_length = window_size;
176 * Generate a logical pointer corresponding to the address we want to
177 * access
179 logical_addr_ptr = mem_info->mapped_logical_address +
180 ((acpi_integer) address -
181 (acpi_integer) mem_info->mapped_physical_address);
183 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
184 "System-Memory (width %d) R/W %d Address=%8.8X%8.8X\n",
185 bit_width, function,
186 ACPI_FORMAT_NATIVE_UINT(address)));
189 * Perform the memory read or write
191 * Note: For machines that do not support non-aligned transfers, the target
192 * address was checked for alignment above. We do not attempt to break the
193 * transfer up into smaller (byte-size) chunks because the AML specifically
194 * asked for a transfer width that the hardware may require.
196 switch (function) {
197 case ACPI_READ:
199 *value = 0;
200 switch (bit_width) {
201 case 8:
202 *value = (acpi_integer) ACPI_GET8(logical_addr_ptr);
203 break;
205 case 16:
206 *value = (acpi_integer) ACPI_GET16(logical_addr_ptr);
207 break;
209 case 32:
210 *value = (acpi_integer) ACPI_GET32(logical_addr_ptr);
211 break;
213 case 64:
214 *value = (acpi_integer) ACPI_GET64(logical_addr_ptr);
215 break;
217 default:
218 /* bit_width was already validated */
219 break;
221 break;
223 case ACPI_WRITE:
225 switch (bit_width) {
226 case 8:
227 ACPI_SET8(logical_addr_ptr) = (u8) * value;
228 break;
230 case 16:
231 ACPI_SET16(logical_addr_ptr) = (u16) * value;
232 break;
234 case 32:
235 ACPI_SET32(logical_addr_ptr) = (u32) * value;
236 break;
238 case 64:
239 ACPI_SET64(logical_addr_ptr) = (u64) * value;
240 break;
242 default:
243 /* bit_width was already validated */
244 break;
246 break;
248 default:
249 status = AE_BAD_PARAMETER;
250 break;
253 return_ACPI_STATUS(status);
256 /*******************************************************************************
258 * FUNCTION: acpi_ex_system_io_space_handler
260 * PARAMETERS: Function - Read or Write operation
261 * Address - Where in the space to read or write
262 * bit_width - Field width in bits (8, 16, or 32)
263 * Value - Pointer to in or out value
264 * handler_context - Pointer to Handler's context
265 * region_context - Pointer to context specific to the
266 * accessed region
268 * RETURN: Status
270 * DESCRIPTION: Handler for the System IO address space (Op Region)
272 ******************************************************************************/
274 acpi_status
275 acpi_ex_system_io_space_handler(u32 function,
276 acpi_physical_address address,
277 u32 bit_width,
278 acpi_integer * value,
279 void *handler_context, void *region_context)
281 acpi_status status = AE_OK;
282 u32 value32;
284 ACPI_FUNCTION_TRACE(ex_system_io_space_handler);
286 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
287 "System-IO (width %d) R/W %d Address=%8.8X%8.8X\n",
288 bit_width, function,
289 ACPI_FORMAT_NATIVE_UINT(address)));
291 /* Decode the function parameter */
293 switch (function) {
294 case ACPI_READ:
296 status = acpi_os_read_port((acpi_io_address) address,
297 &value32, bit_width);
298 *value = value32;
299 break;
301 case ACPI_WRITE:
303 status = acpi_os_write_port((acpi_io_address) address,
304 (u32) * value, bit_width);
305 break;
307 default:
308 status = AE_BAD_PARAMETER;
309 break;
312 return_ACPI_STATUS(status);
315 /*******************************************************************************
317 * FUNCTION: acpi_ex_pci_config_space_handler
319 * PARAMETERS: Function - Read or Write operation
320 * Address - Where in the space to read or write
321 * bit_width - Field width in bits (8, 16, or 32)
322 * Value - Pointer to in or out value
323 * handler_context - Pointer to Handler's context
324 * region_context - Pointer to context specific to the
325 * accessed region
327 * RETURN: Status
329 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
331 ******************************************************************************/
333 acpi_status
334 acpi_ex_pci_config_space_handler(u32 function,
335 acpi_physical_address address,
336 u32 bit_width,
337 acpi_integer * value,
338 void *handler_context, void *region_context)
340 acpi_status status = AE_OK;
341 struct acpi_pci_id *pci_id;
342 u16 pci_register;
343 u32 value32;
345 ACPI_FUNCTION_TRACE(ex_pci_config_space_handler);
348 * The arguments to acpi_os(Read|Write)pci_configuration are:
350 * pci_segment is the PCI bus segment range 0-31
351 * pci_bus is the PCI bus number range 0-255
352 * pci_device is the PCI device number range 0-31
353 * pci_function is the PCI device function number
354 * pci_register is the Config space register range 0-255 bytes
356 * Value - input value for write, output address for read
359 pci_id = (struct acpi_pci_id *)region_context;
360 pci_register = (u16) (u32) address;
362 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
363 "Pci-Config %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
364 function, bit_width, pci_id->segment, pci_id->bus,
365 pci_id->device, pci_id->function, pci_register));
367 switch (function) {
368 case ACPI_READ:
370 status = acpi_os_read_pci_configuration(pci_id, pci_register,
371 &value32, bit_width);
372 *value = value32;
373 break;
375 case ACPI_WRITE:
377 status = acpi_os_write_pci_configuration(pci_id, pci_register,
378 *value, bit_width);
379 break;
381 default:
383 status = AE_BAD_PARAMETER;
384 break;
387 return_ACPI_STATUS(status);
390 /*******************************************************************************
392 * FUNCTION: acpi_ex_cmos_space_handler
394 * PARAMETERS: Function - Read or Write operation
395 * Address - Where in the space to read or write
396 * bit_width - Field width in bits (8, 16, or 32)
397 * Value - Pointer to in or out value
398 * handler_context - Pointer to Handler's context
399 * region_context - Pointer to context specific to the
400 * accessed region
402 * RETURN: Status
404 * DESCRIPTION: Handler for the CMOS address space (Op Region)
406 ******************************************************************************/
408 acpi_status
409 acpi_ex_cmos_space_handler(u32 function,
410 acpi_physical_address address,
411 u32 bit_width,
412 acpi_integer * value,
413 void *handler_context, void *region_context)
415 acpi_status status = AE_OK;
417 ACPI_FUNCTION_TRACE(ex_cmos_space_handler);
419 return_ACPI_STATUS(status);
422 /*******************************************************************************
424 * FUNCTION: acpi_ex_pci_bar_space_handler
426 * PARAMETERS: Function - Read or Write operation
427 * Address - Where in the space to read or write
428 * bit_width - Field width in bits (8, 16, or 32)
429 * Value - Pointer to in or out value
430 * handler_context - Pointer to Handler's context
431 * region_context - Pointer to context specific to the
432 * accessed region
434 * RETURN: Status
436 * DESCRIPTION: Handler for the PCI bar_target address space (Op Region)
438 ******************************************************************************/
440 acpi_status
441 acpi_ex_pci_bar_space_handler(u32 function,
442 acpi_physical_address address,
443 u32 bit_width,
444 acpi_integer * value,
445 void *handler_context, void *region_context)
447 acpi_status status = AE_OK;
449 ACPI_FUNCTION_TRACE(ex_pci_bar_space_handler);
451 return_ACPI_STATUS(status);
454 /*******************************************************************************
456 * FUNCTION: acpi_ex_data_table_space_handler
458 * PARAMETERS: Function - Read or Write operation
459 * Address - Where in the space to read or write
460 * bit_width - Field width in bits (8, 16, or 32)
461 * Value - Pointer to in or out value
462 * handler_context - Pointer to Handler's context
463 * region_context - Pointer to context specific to the
464 * accessed region
466 * RETURN: Status
468 * DESCRIPTION: Handler for the Data Table address space (Op Region)
470 ******************************************************************************/
472 acpi_status
473 acpi_ex_data_table_space_handler(u32 function,
474 acpi_physical_address address,
475 u32 bit_width,
476 acpi_integer * value,
477 void *handler_context, void *region_context)
479 ACPI_FUNCTION_TRACE(ex_data_table_space_handler);
481 /* Perform the memory read or write */
483 switch (function) {
484 case ACPI_READ:
486 ACPI_MEMCPY(ACPI_CAST_PTR(char, value),
487 ACPI_PHYSADDR_TO_PTR(address),
488 ACPI_DIV_8(bit_width));
489 break;
491 case ACPI_WRITE:
492 default:
494 return_ACPI_STATUS(AE_SUPPORT);
497 return_ACPI_STATUS(AE_OK);