Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: exregion - ACPI default op_region (address space) handlers |
| 5 | * |
Bob Moore | da6f832 | 2018-01-04 10:06:38 -0800 | [diff] [blame] | 6 | * Copyright (C) 2000 - 2018, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 11 | #include "accommon.h" |
| 12 | #include "acinterp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #define _COMPONENT ACPI_EXECUTER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 15 | ACPI_MODULE_NAME("exregion") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | /******************************************************************************* |
| 18 | * |
| 19 | * FUNCTION: acpi_ex_system_memory_space_handler |
| 20 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 21 | * PARAMETERS: function - Read or Write operation |
| 22 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 24 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | * handler_context - Pointer to Handler's context |
| 26 | * region_context - Pointer to context specific to the |
| 27 | * accessed region |
| 28 | * |
| 29 | * RETURN: Status |
| 30 | * |
| 31 | * DESCRIPTION: Handler for the System Memory address space (Op Region) |
| 32 | * |
| 33 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 35 | acpi_ex_system_memory_space_handler(u32 function, |
| 36 | acpi_physical_address address, |
| 37 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 38 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 39 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 41 | acpi_status status = AE_OK; |
| 42 | void *logical_addr_ptr = NULL; |
| 43 | struct acpi_mem_space_context *mem_info = region_context; |
| 44 | u32 length; |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 45 | acpi_size map_length; |
| 46 | acpi_size page_boundary_map_length; |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 47 | #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | u32 remainder; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #endif |
| 50 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 51 | ACPI_FUNCTION_TRACE(ex_system_memory_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /* Validate and translate the bit width */ |
| 54 | |
| 55 | switch (bit_width) { |
| 56 | case 8: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | length = 1; |
| 59 | break; |
| 60 | |
| 61 | case 16: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | length = 2; |
| 64 | break; |
| 65 | |
| 66 | case 32: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | length = 4; |
| 69 | break; |
| 70 | |
| 71 | case 64: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | length = 8; |
| 74 | break; |
| 75 | |
| 76 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 77 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 78 | ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %u", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 79 | bit_width)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | return_ACPI_STATUS(AE_AML_OPERAND_VALUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 83 | #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* |
| 85 | * Hardware does not support non-aligned data transfers, we must verify |
| 86 | * the request. |
| 87 | */ |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 88 | (void)acpi_ut_short_divide((u64) address, length, NULL, &remainder); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | if (remainder != 0) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | return_ACPI_STATUS(AE_AML_ALIGNMENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | #endif |
| 93 | |
| 94 | /* |
| 95 | * Does the request fit into the cached memory mapping? |
| 96 | * Is 1) Address below the current mapping? OR |
| 97 | * 2) Address beyond the current mapping? |
| 98 | */ |
| 99 | if ((address < mem_info->mapped_physical_address) || |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 100 | (((u64) address + length) > ((u64) |
| 101 | mem_info->mapped_physical_address + |
| 102 | mem_info->mapped_length))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | /* |
| 104 | * The request cannot be resolved by the current memory mapping; |
| 105 | * Delete the existing mapping and create a new one. |
| 106 | */ |
| 107 | if (mem_info->mapped_length) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | /* Valid mapping, delete it */ |
| 110 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | acpi_os_unmap_memory(mem_info->mapped_logical_address, |
| 112 | mem_info->mapped_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /* |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 116 | * October 2009: Attempt to map from the requested address to the |
| 117 | * end of the region. However, we will never map more than one |
| 118 | * page, nor will we cross a page boundary. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | */ |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 120 | map_length = (acpi_size) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 | ((mem_info->address + mem_info->length) - address); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 122 | |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 123 | /* |
| 124 | * If mapping the entire remaining portion of the region will cross |
| 125 | * a page boundary, just map up to the page boundary, do not cross. |
| 126 | * On some systems, crossing a page boundary while mapping regions |
| 127 | * can cause warnings if the pages have different attributes |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 128 | * due to resource management. |
| 129 | * |
| 130 | * This has the added benefit of constraining a single mapping to |
| 131 | * one page, which is similar to the original code that used a 4k |
| 132 | * maximum window. |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 133 | */ |
Bob Moore | 938ed10 | 2015-04-13 11:49:54 +0800 | [diff] [blame] | 134 | page_boundary_map_length = (acpi_size) |
| 135 | (ACPI_ROUND_UP(address, ACPI_DEFAULT_PAGE_SIZE) - address); |
Lv Zheng | 739dcbb | 2012-12-20 01:07:26 +0000 | [diff] [blame] | 136 | if (page_boundary_map_length == 0) { |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 137 | page_boundary_map_length = ACPI_DEFAULT_PAGE_SIZE; |
| 138 | } |
| 139 | |
| 140 | if (map_length > page_boundary_map_length) { |
| 141 | map_length = page_boundary_map_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* Create a new mapping starting at the address given */ |
| 145 | |
Lv Zheng | ea28492 | 2015-04-13 11:48:31 +0800 | [diff] [blame] | 146 | mem_info->mapped_logical_address = |
| 147 | acpi_os_map_memory(address, map_length); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 148 | if (!mem_info->mapped_logical_address) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 149 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 150 | "Could not map memory at 0x%8.8X%8.8X, size %u", |
Lv Zheng | 1d0a0b2 | 2015-04-13 11:48:52 +0800 | [diff] [blame] | 151 | ACPI_FORMAT_UINT64(address), |
Lv Zheng | 18ae902 | 2015-04-13 11:48:12 +0800 | [diff] [blame] | 152 | (u32)map_length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | mem_info->mapped_length = 0; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 154 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /* Save the physical address and mapping size */ |
| 158 | |
| 159 | mem_info->mapped_physical_address = address; |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 160 | mem_info->mapped_length = map_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /* |
| 164 | * Generate a logical pointer corresponding to the address we want to |
| 165 | * access |
| 166 | */ |
| 167 | logical_addr_ptr = mem_info->mapped_logical_address + |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 168 | ((u64) address - (u64) mem_info->mapped_physical_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bob Moore | b27d659 | 2010-05-26 11:47:13 +0800 | [diff] [blame] | 171 | "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n", |
Lv Zheng | 1d0a0b2 | 2015-04-13 11:48:52 +0800 | [diff] [blame] | 172 | bit_width, function, ACPI_FORMAT_UINT64(address))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | /* |
| 175 | * Perform the memory read or write |
| 176 | * |
| 177 | * Note: For machines that do not support non-aligned transfers, the target |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 178 | * address was checked for alignment above. We do not attempt to break the |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | * transfer up into smaller (byte-size) chunks because the AML specifically |
| 180 | * asked for a transfer width that the hardware may require. |
| 181 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | switch (function) { |
| 183 | case ACPI_READ: |
| 184 | |
| 185 | *value = 0; |
| 186 | switch (bit_width) { |
| 187 | case 8: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 188 | |
| 189 | *value = (u64)ACPI_GET8(logical_addr_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | break; |
| 191 | |
| 192 | case 16: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 193 | |
| 194 | *value = (u64)ACPI_GET16(logical_addr_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | break; |
| 196 | |
| 197 | case 32: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 198 | |
| 199 | *value = (u64)ACPI_GET32(logical_addr_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | break; |
| 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | case 64: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 203 | |
| 204 | *value = (u64)ACPI_GET64(logical_addr_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | break; |
Bob Moore | 59fa850 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /* bit_width was already validated */ |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | break; |
| 212 | } |
| 213 | break; |
| 214 | |
| 215 | case ACPI_WRITE: |
| 216 | |
| 217 | switch (bit_width) { |
| 218 | case 8: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 219 | |
Lv Zheng | 57bf6ae | 2012-12-19 05:38:24 +0000 | [diff] [blame] | 220 | ACPI_SET8(logical_addr_ptr, *value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | break; |
| 222 | |
| 223 | case 16: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 224 | |
Lv Zheng | 57bf6ae | 2012-12-19 05:38:24 +0000 | [diff] [blame] | 225 | ACPI_SET16(logical_addr_ptr, *value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | break; |
| 227 | |
| 228 | case 32: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 229 | |
Lv Zheng | 57bf6ae | 2012-12-19 05:38:24 +0000 | [diff] [blame] | 230 | ACPI_SET32(logical_addr_ptr, *value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | break; |
| 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | case 64: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 234 | |
Lv Zheng | 57bf6ae | 2012-12-19 05:38:24 +0000 | [diff] [blame] | 235 | ACPI_SET64(logical_addr_ptr, *value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | /* bit_width was already validated */ |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | break; |
| 243 | } |
| 244 | break; |
| 245 | |
| 246 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | status = AE_BAD_PARAMETER; |
| 249 | break; |
| 250 | } |
| 251 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | /******************************************************************************* |
| 256 | * |
| 257 | * FUNCTION: acpi_ex_system_io_space_handler |
| 258 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 259 | * PARAMETERS: function - Read or Write operation |
| 260 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 262 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | * handler_context - Pointer to Handler's context |
| 264 | * region_context - Pointer to context specific to the |
| 265 | * accessed region |
| 266 | * |
| 267 | * RETURN: Status |
| 268 | * |
| 269 | * DESCRIPTION: Handler for the System IO address space (Op Region) |
| 270 | * |
| 271 | ******************************************************************************/ |
| 272 | |
| 273 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | acpi_ex_system_io_space_handler(u32 function, |
| 275 | acpi_physical_address address, |
| 276 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 277 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 278 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 280 | acpi_status status = AE_OK; |
| 281 | u32 value32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 283 | ACPI_FUNCTION_TRACE(ex_system_io_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bob Moore | b27d659 | 2010-05-26 11:47:13 +0800 | [diff] [blame] | 286 | "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n", |
Lv Zheng | 1d0a0b2 | 2015-04-13 11:48:52 +0800 | [diff] [blame] | 287 | bit_width, function, ACPI_FORMAT_UINT64(address))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | /* Decode the function parameter */ |
| 290 | |
| 291 | switch (function) { |
| 292 | case ACPI_READ: |
| 293 | |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 294 | status = acpi_hw_read_port((acpi_io_address)address, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 295 | &value32, bit_width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | *value = value32; |
| 297 | break; |
| 298 | |
| 299 | case ACPI_WRITE: |
| 300 | |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 301 | status = acpi_hw_write_port((acpi_io_address)address, |
| 302 | (u32)*value, bit_width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | break; |
| 304 | |
| 305 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | status = AE_BAD_PARAMETER; |
| 308 | break; |
| 309 | } |
| 310 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 311 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | /******************************************************************************* |
| 315 | * |
| 316 | * FUNCTION: acpi_ex_pci_config_space_handler |
| 317 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 318 | * PARAMETERS: function - Read or Write operation |
| 319 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 321 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | * handler_context - Pointer to Handler's context |
| 323 | * region_context - Pointer to context specific to the |
| 324 | * accessed region |
| 325 | * |
| 326 | * RETURN: Status |
| 327 | * |
| 328 | * DESCRIPTION: Handler for the PCI Config address space (Op Region) |
| 329 | * |
| 330 | ******************************************************************************/ |
| 331 | |
| 332 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | acpi_ex_pci_config_space_handler(u32 function, |
| 334 | acpi_physical_address address, |
| 335 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 336 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 339 | acpi_status status = AE_OK; |
| 340 | struct acpi_pci_id *pci_id; |
| 341 | u16 pci_register; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 343 | ACPI_FUNCTION_TRACE(ex_pci_config_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
| 345 | /* |
| 346 | * The arguments to acpi_os(Read|Write)pci_configuration are: |
| 347 | * |
| 348 | * pci_segment is the PCI bus segment range 0-31 |
| 349 | * pci_bus is the PCI bus number range 0-255 |
| 350 | * pci_device is the PCI device number range 0-31 |
| 351 | * pci_function is the PCI device function number |
| 352 | * pci_register is the Config space register range 0-255 bytes |
| 353 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 354 | * value - input value for write, output address for read |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | * |
| 356 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 357 | pci_id = (struct acpi_pci_id *)region_context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | pci_register = (u16) (u32) address; |
| 359 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 360 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 361 | "Pci-Config %u (%u) Seg(%04x) Bus(%04x) " |
| 362 | "Dev(%04x) Func(%04x) Reg(%04x)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 363 | function, bit_width, pci_id->segment, pci_id->bus, |
| 364 | pci_id->device, pci_id->function, pci_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | switch (function) { |
| 367 | case ACPI_READ: |
| 368 | |
Lv Zheng | bb42cc2 | 2013-10-31 09:29:49 +0800 | [diff] [blame] | 369 | *value = 0; |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 370 | status = |
| 371 | acpi_os_read_pci_configuration(pci_id, pci_register, value, |
| 372 | bit_width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | break; |
| 374 | |
| 375 | case ACPI_WRITE: |
| 376 | |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 377 | status = |
| 378 | acpi_os_write_pci_configuration(pci_id, pci_register, |
| 379 | *value, bit_width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | break; |
| 381 | |
| 382 | default: |
| 383 | |
| 384 | status = AE_BAD_PARAMETER; |
| 385 | break; |
| 386 | } |
| 387 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 388 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | /******************************************************************************* |
| 392 | * |
| 393 | * FUNCTION: acpi_ex_cmos_space_handler |
| 394 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 395 | * PARAMETERS: function - Read or Write operation |
| 396 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 398 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 409 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 410 | acpi_ex_cmos_space_handler(u32 function, |
| 411 | acpi_physical_address address, |
| 412 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 413 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 414 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 418 | ACPI_FUNCTION_TRACE(ex_cmos_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | /******************************************************************************* |
| 424 | * |
| 425 | * FUNCTION: acpi_ex_pci_bar_space_handler |
| 426 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 427 | * PARAMETERS: function - Read or Write operation |
| 428 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 430 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 441 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 442 | acpi_ex_pci_bar_space_handler(u32 function, |
| 443 | acpi_physical_address address, |
| 444 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 445 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 446 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 448 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 450 | ACPI_FUNCTION_TRACE(ex_pci_bar_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 452 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | /******************************************************************************* |
| 456 | * |
| 457 | * FUNCTION: acpi_ex_data_table_space_handler |
| 458 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 459 | * PARAMETERS: function - Read or Write operation |
| 460 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 462 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 473 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 474 | acpi_ex_data_table_space_handler(u32 function, |
| 475 | acpi_physical_address address, |
| 476 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 477 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 478 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 480 | ACPI_FUNCTION_TRACE(ex_data_table_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Bob Moore | c1637e9 | 2010-04-01 11:09:00 +0800 | [diff] [blame] | 482 | /* |
| 483 | * Perform the memory read or write. The bit_width was already |
| 484 | * validated. |
| 485 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | switch (function) { |
| 487 | case ACPI_READ: |
| 488 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 489 | memcpy(ACPI_CAST_PTR(char, value), |
| 490 | ACPI_PHYSADDR_TO_PTR(address), ACPI_DIV_8(bit_width)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | break; |
| 492 | |
| 493 | case ACPI_WRITE: |
Bob Moore | c1637e9 | 2010-04-01 11:09:00 +0800 | [diff] [blame] | 494 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 495 | memcpy(ACPI_PHYSADDR_TO_PTR(address), |
| 496 | ACPI_CAST_PTR(char, value), ACPI_DIV_8(bit_width)); |
Bob Moore | c1637e9 | 2010-04-01 11:09:00 +0800 | [diff] [blame] | 497 | break; |
| 498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | default: |
| 500 | |
Bob Moore | c1637e9 | 2010-04-01 11:09:00 +0800 | [diff] [blame] | 501 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 504 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |