blob: 3cc97ba48b364262ccc47fe0a11bfa9ee7bf0345 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/******************************************************************************
3 *
4 * Module Name: exregion - ACPI default op_region (address space) handlers
5 *
6 *****************************************************************************/
7
8/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05009 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * All rights reserved.
11 *
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.
26 *
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.
30 *
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.
43 */
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("exregion")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/*******************************************************************************
52 *
53 * FUNCTION: acpi_ex_system_memory_space_handler
54 *
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
62 *
63 * RETURN: Status
64 *
65 * DESCRIPTION: Handler for the System Memory address space (Op Region)
66 *
67 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070068acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040069acpi_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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Len Brown4be44fc2005-08-05 00:44:28 -040075 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;
Bob Moore08978312005-10-21 00:00:00 -040080#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
Len Brown4be44fc2005-08-05 00:44:28 -040081 u32 remainder;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#endif
83
Bob Mooreb229cf92006-04-21 17:15:00 -040084 ACPI_FUNCTION_TRACE(ex_system_memory_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 /* Validate and translate the bit width */
87
88 switch (bit_width) {
89 case 8:
90 length = 1;
91 break;
92
93 case 16:
94 length = 2;
95 break;
96
97 case 32:
98 length = 4;
99 break;
100
101 case 64:
102 length = 8;
103 break;
104
105 default:
Bob Mooreb229cf92006-04-21 17:15:00 -0400106 ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %d",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500107 bit_width));
Len Brown4be44fc2005-08-05 00:44:28 -0400108 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 }
110
Bob Moore08978312005-10-21 00:00:00 -0400111#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 /*
113 * Hardware does not support non-aligned data transfers, we must verify
114 * the request.
115 */
Len Brown4be44fc2005-08-05 00:44:28 -0400116 (void)acpi_ut_short_divide((acpi_integer) address, length, NULL,
117 &remainder);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 if (remainder != 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400119 return_ACPI_STATUS(AE_AML_ALIGNMENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121#endif
122
123 /*
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?
127 */
128 if ((address < mem_info->mapped_physical_address) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400129 (((acpi_integer) address + length) > ((acpi_integer)
130 mem_info->
131 mapped_physical_address +
132 mem_info->mapped_length))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 /*
134 * The request cannot be resolved by the current memory mapping;
135 * Delete the existing mapping and create a new one.
136 */
137 if (mem_info->mapped_length) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 /* Valid mapping, delete it */
140
Len Brown4be44fc2005-08-05 00:44:28 -0400141 acpi_os_unmap_memory(mem_info->mapped_logical_address,
142 mem_info->mapped_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
144
145 /*
146 * Don't attempt to map memory beyond the end of the region, and
147 * constrain the maximum mapping size to something reasonable.
148 */
Robert Moore44f6c012005-04-18 22:49:35 -0400149 window_size = (acpi_size)
Len Brown4be44fc2005-08-05 00:44:28 -0400150 ((mem_info->address + mem_info->length) - address);
Robert Moore44f6c012005-04-18 22:49:35 -0400151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 if (window_size > ACPI_SYSMEM_REGION_WINDOW_SIZE) {
153 window_size = ACPI_SYSMEM_REGION_WINDOW_SIZE;
154 }
155
156 /* Create a new mapping starting at the address given */
157
Len Brown4be44fc2005-08-05 00:44:28 -0400158 status = acpi_os_map_memory(address, window_size,
159 (void **)&mem_info->
160 mapped_logical_address);
161 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500162 ACPI_ERROR((AE_INFO,
163 "Could not map memory at %8.8X%8.8X, size %X",
164 ACPI_FORMAT_UINT64(address),
165 (u32) window_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 mem_info->mapped_length = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400167 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
169
170 /* Save the physical address and mapping size */
171
172 mem_info->mapped_physical_address = address;
173 mem_info->mapped_length = window_size;
174 }
175
176 /*
177 * Generate a logical pointer corresponding to the address we want to
178 * access
179 */
180 logical_addr_ptr = mem_info->mapped_logical_address +
Len Brown4be44fc2005-08-05 00:44:28 -0400181 ((acpi_integer) address -
182 (acpi_integer) mem_info->mapped_physical_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Len Brown4be44fc2005-08-05 00:44:28 -0400184 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moore83135242006-10-03 00:00:00 -0400185 "System-Memory (width %d) R/W %d Address=%8.8X%8.8X\n",
186 bit_width, function, ACPI_FORMAT_UINT64(address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Len Brown4be44fc2005-08-05 00:44:28 -0400188 /*
189 * Perform the memory read or write
190 *
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.
195 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 switch (function) {
197 case ACPI_READ:
198
199 *value = 0;
200 switch (bit_width) {
201 case 8:
Bob Moorec51a4de2005-11-17 13:07:00 -0500202 *value = (acpi_integer) ACPI_GET8(logical_addr_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 break;
204
205 case 16:
Bob Moorec51a4de2005-11-17 13:07:00 -0500206 *value = (acpi_integer) ACPI_GET16(logical_addr_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 break;
208
209 case 32:
Bob Moorec51a4de2005-11-17 13:07:00 -0500210 *value = (acpi_integer) ACPI_GET32(logical_addr_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 break;
212
213#if ACPI_MACHINE_WIDTH != 16
214 case 64:
Bob Moorec51a4de2005-11-17 13:07:00 -0500215 *value = (acpi_integer) ACPI_GET64(logical_addr_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 break;
217#endif
218 default:
219 /* bit_width was already validated */
220 break;
221 }
222 break;
223
224 case ACPI_WRITE:
225
226 switch (bit_width) {
227 case 8:
Bob Moorec51a4de2005-11-17 13:07:00 -0500228 ACPI_SET8(logical_addr_ptr) = (u8) * value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 break;
230
231 case 16:
Bob Moorec51a4de2005-11-17 13:07:00 -0500232 ACPI_SET16(logical_addr_ptr) = (u16) * value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 break;
234
235 case 32:
Bob Moorec51a4de2005-11-17 13:07:00 -0500236 ACPI_SET32(logical_addr_ptr) = (u32) * value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 break;
238
239#if ACPI_MACHINE_WIDTH != 16
240 case 64:
Bob Moorec51a4de2005-11-17 13:07:00 -0500241 ACPI_SET64(logical_addr_ptr) = (u64) * value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 break;
243#endif
244
245 default:
246 /* bit_width was already validated */
247 break;
248 }
249 break;
250
251 default:
252 status = AE_BAD_PARAMETER;
253 break;
254 }
255
Len Brown4be44fc2005-08-05 00:44:28 -0400256 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259/*******************************************************************************
260 *
261 * FUNCTION: acpi_ex_system_io_space_handler
262 *
263 * PARAMETERS: Function - Read or Write operation
264 * Address - Where in the space to read or write
265 * bit_width - Field width in bits (8, 16, or 32)
266 * Value - Pointer to in or out value
267 * handler_context - Pointer to Handler's context
268 * region_context - Pointer to context specific to the
269 * accessed region
270 *
271 * RETURN: Status
272 *
273 * DESCRIPTION: Handler for the System IO address space (Op Region)
274 *
275 ******************************************************************************/
276
277acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400278acpi_ex_system_io_space_handler(u32 function,
279 acpi_physical_address address,
280 u32 bit_width,
281 acpi_integer * value,
282 void *handler_context, void *region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Len Brown4be44fc2005-08-05 00:44:28 -0400284 acpi_status status = AE_OK;
285 u32 value32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Bob Mooreb229cf92006-04-21 17:15:00 -0400287 ACPI_FUNCTION_TRACE(ex_system_io_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Len Brown4be44fc2005-08-05 00:44:28 -0400289 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moore83135242006-10-03 00:00:00 -0400290 "System-IO (width %d) R/W %d Address=%8.8X%8.8X\n",
291 bit_width, function, ACPI_FORMAT_UINT64(address)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 /* Decode the function parameter */
294
295 switch (function) {
296 case ACPI_READ:
297
Len Brown4be44fc2005-08-05 00:44:28 -0400298 status = acpi_os_read_port((acpi_io_address) address,
299 &value32, bit_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 *value = value32;
301 break;
302
303 case ACPI_WRITE:
304
Len Brown4be44fc2005-08-05 00:44:28 -0400305 status = acpi_os_write_port((acpi_io_address) address,
306 (u32) * value, bit_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 break;
308
309 default:
310 status = AE_BAD_PARAMETER;
311 break;
312 }
313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317/*******************************************************************************
318 *
319 * FUNCTION: acpi_ex_pci_config_space_handler
320 *
321 * PARAMETERS: Function - Read or Write operation
322 * Address - Where in the space to read or write
323 * bit_width - Field width in bits (8, 16, or 32)
324 * Value - Pointer to in or out value
325 * handler_context - Pointer to Handler's context
326 * region_context - Pointer to context specific to the
327 * accessed region
328 *
329 * RETURN: Status
330 *
331 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
332 *
333 ******************************************************************************/
334
335acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400336acpi_ex_pci_config_space_handler(u32 function,
337 acpi_physical_address address,
338 u32 bit_width,
339 acpi_integer * value,
340 void *handler_context, void *region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Len Brown4be44fc2005-08-05 00:44:28 -0400342 acpi_status status = AE_OK;
343 struct acpi_pci_id *pci_id;
344 u16 pci_register;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Bob Mooreb229cf92006-04-21 17:15:00 -0400346 ACPI_FUNCTION_TRACE(ex_pci_config_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 /*
349 * The arguments to acpi_os(Read|Write)pci_configuration are:
350 *
351 * pci_segment is the PCI bus segment range 0-31
352 * pci_bus is the PCI bus number range 0-255
353 * pci_device is the PCI device number range 0-31
354 * pci_function is the PCI device function number
355 * pci_register is the Config space register range 0-255 bytes
356 *
357 * Value - input value for write, output address for read
358 *
359 */
Len Brown4be44fc2005-08-05 00:44:28 -0400360 pci_id = (struct acpi_pci_id *)region_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 pci_register = (u16) (u32) address;
362
Len Brown4be44fc2005-08-05 00:44:28 -0400363 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bob Moore83135242006-10-03 00:00:00 -0400364 "Pci-Config %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400365 function, bit_width, pci_id->segment, pci_id->bus,
366 pci_id->device, pci_id->function, pci_register));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 switch (function) {
369 case ACPI_READ:
370
371 *value = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400372 status = acpi_os_read_pci_configuration(pci_id, pci_register,
373 value, bit_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 break;
375
376 case ACPI_WRITE:
377
Len Brown4be44fc2005-08-05 00:44:28 -0400378 status = acpi_os_write_pci_configuration(pci_id, pci_register,
379 *value, bit_width);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 break;
381
382 default:
383
384 status = AE_BAD_PARAMETER;
385 break;
386 }
387
Len Brown4be44fc2005-08-05 00:44:28 -0400388 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391/*******************************************************************************
392 *
393 * FUNCTION: acpi_ex_cmos_space_handler
394 *
395 * PARAMETERS: Function - Read or Write operation
396 * Address - Where in the space to read or write
397 * bit_width - Field width in bits (8, 16, or 32)
398 * Value - Pointer to in or out value
399 * handler_context - Pointer to Handler's context
400 * region_context - Pointer to context specific to the
401 * accessed region
402 *
403 * RETURN: Status
404 *
405 * DESCRIPTION: Handler for the CMOS address space (Op Region)
406 *
407 ******************************************************************************/
408
409acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400410acpi_ex_cmos_space_handler(u32 function,
411 acpi_physical_address address,
412 u32 bit_width,
413 acpi_integer * value,
414 void *handler_context, void *region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
Len Brown4be44fc2005-08-05 00:44:28 -0400416 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Bob Mooreb229cf92006-04-21 17:15:00 -0400418 ACPI_FUNCTION_TRACE(ex_cmos_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Len Brown4be44fc2005-08-05 00:44:28 -0400420 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423/*******************************************************************************
424 *
425 * FUNCTION: acpi_ex_pci_bar_space_handler
426 *
427 * PARAMETERS: Function - Read or Write operation
428 * Address - Where in the space to read or write
429 * bit_width - Field width in bits (8, 16, or 32)
430 * Value - Pointer to in or out value
431 * handler_context - Pointer to Handler's context
432 * region_context - Pointer to context specific to the
433 * accessed region
434 *
435 * RETURN: Status
436 *
437 * DESCRIPTION: Handler for the PCI bar_target address space (Op Region)
438 *
439 ******************************************************************************/
440
441acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400442acpi_ex_pci_bar_space_handler(u32 function,
443 acpi_physical_address address,
444 u32 bit_width,
445 acpi_integer * value,
446 void *handler_context, void *region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Len Brown4be44fc2005-08-05 00:44:28 -0400448 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Bob Mooreb229cf92006-04-21 17:15:00 -0400450 ACPI_FUNCTION_TRACE(ex_pci_bar_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Len Brown4be44fc2005-08-05 00:44:28 -0400452 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453}
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455/*******************************************************************************
456 *
457 * FUNCTION: acpi_ex_data_table_space_handler
458 *
459 * PARAMETERS: Function - Read or Write operation
460 * Address - Where in the space to read or write
461 * bit_width - Field width in bits (8, 16, or 32)
462 * Value - Pointer to in or out value
463 * handler_context - Pointer to Handler's context
464 * region_context - Pointer to context specific to the
465 * accessed region
466 *
467 * RETURN: Status
468 *
469 * DESCRIPTION: Handler for the Data Table address space (Op Region)
470 *
471 ******************************************************************************/
472
473acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400474acpi_ex_data_table_space_handler(u32 function,
475 acpi_physical_address address,
476 u32 bit_width,
477 acpi_integer * value,
478 void *handler_context, void *region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Bob Mooreb229cf92006-04-21 17:15:00 -0400480 ACPI_FUNCTION_TRACE(ex_data_table_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Robert Moore44f6c012005-04-18 22:49:35 -0400482 /* Perform the memory read or write */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 switch (function) {
485 case ACPI_READ:
486
Bob Moore41195322006-05-26 16:36:00 -0400487 ACPI_MEMCPY(ACPI_CAST_PTR(char, value),
488 ACPI_PHYSADDR_TO_PTR(address),
489 ACPI_DIV_8(bit_width));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 break;
491
492 case ACPI_WRITE:
493 default:
494
Len Brown4be44fc2005-08-05 00:44:28 -0400495 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497
Bob Moore41195322006-05-26 16:36:00 -0400498 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499}