Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: exregion - ACPI default op_region (address space) handlers |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | c8100dc | 2016-01-15 08:17:03 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2016, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "acinterp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define _COMPONENT ACPI_EXECUTER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 49 | ACPI_MODULE_NAME("exregion") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | /******************************************************************************* |
| 52 | * |
| 53 | * FUNCTION: acpi_ex_system_memory_space_handler |
| 54 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 55 | * PARAMETERS: function - Read or Write operation |
| 56 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 58 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | acpi_ex_system_memory_space_handler(u32 function, |
| 70 | acpi_physical_address address, |
| 71 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 72 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 73 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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; |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 79 | acpi_size map_length; |
| 80 | acpi_size page_boundary_map_length; |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 81 | #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 82 | u32 remainder; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #endif |
| 84 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 85 | ACPI_FUNCTION_TRACE(ex_system_memory_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | /* Validate and translate the bit width */ |
| 88 | |
| 89 | switch (bit_width) { |
| 90 | case 8: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | length = 1; |
| 93 | break; |
| 94 | |
| 95 | case 16: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | length = 2; |
| 98 | break; |
| 99 | |
| 100 | case 32: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | length = 4; |
| 103 | break; |
| 104 | |
| 105 | case 64: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | length = 8; |
| 108 | break; |
| 109 | |
| 110 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 111 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 112 | ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %u", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 113 | bit_width)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 114 | return_ACPI_STATUS(AE_AML_OPERAND_VALUE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 117 | #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | /* |
| 119 | * Hardware does not support non-aligned data transfers, we must verify |
| 120 | * the request. |
| 121 | */ |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 122 | (void)acpi_ut_short_divide((u64) address, length, NULL, &remainder); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | if (remainder != 0) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | return_ACPI_STATUS(AE_AML_ALIGNMENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | #endif |
| 127 | |
| 128 | /* |
| 129 | * Does the request fit into the cached memory mapping? |
| 130 | * Is 1) Address below the current mapping? OR |
| 131 | * 2) Address beyond the current mapping? |
| 132 | */ |
| 133 | if ((address < mem_info->mapped_physical_address) || |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 134 | (((u64) address + length) > ((u64) |
| 135 | mem_info->mapped_physical_address + |
| 136 | mem_info->mapped_length))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* |
| 138 | * The request cannot be resolved by the current memory mapping; |
| 139 | * Delete the existing mapping and create a new one. |
| 140 | */ |
| 141 | if (mem_info->mapped_length) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | /* Valid mapping, delete it */ |
| 144 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | acpi_os_unmap_memory(mem_info->mapped_logical_address, |
| 146 | mem_info->mapped_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 150 | * October 2009: Attempt to map from the requested address to the |
| 151 | * end of the region. However, we will never map more than one |
| 152 | * page, nor will we cross a page boundary. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | */ |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 154 | map_length = (acpi_size) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 155 | ((mem_info->address + mem_info->length) - address); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 156 | |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 157 | /* |
| 158 | * If mapping the entire remaining portion of the region will cross |
| 159 | * a page boundary, just map up to the page boundary, do not cross. |
| 160 | * On some systems, crossing a page boundary while mapping regions |
| 161 | * can cause warnings if the pages have different attributes |
Lv Zheng | 75c8044 | 2012-12-19 05:36:49 +0000 | [diff] [blame] | 162 | * due to resource management. |
| 163 | * |
| 164 | * This has the added benefit of constraining a single mapping to |
| 165 | * one page, which is similar to the original code that used a 4k |
| 166 | * maximum window. |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 167 | */ |
Bob Moore | 938ed10 | 2015-04-13 11:49:54 +0800 | [diff] [blame] | 168 | page_boundary_map_length = (acpi_size) |
| 169 | (ACPI_ROUND_UP(address, ACPI_DEFAULT_PAGE_SIZE) - address); |
Lv Zheng | 739dcbb | 2012-12-20 01:07:26 +0000 | [diff] [blame] | 170 | if (page_boundary_map_length == 0) { |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 171 | page_boundary_map_length = ACPI_DEFAULT_PAGE_SIZE; |
| 172 | } |
| 173 | |
| 174 | if (map_length > page_boundary_map_length) { |
| 175 | map_length = page_boundary_map_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* Create a new mapping starting at the address given */ |
| 179 | |
Lv Zheng | ea28492 | 2015-04-13 11:48:31 +0800 | [diff] [blame] | 180 | mem_info->mapped_logical_address = |
| 181 | acpi_os_map_memory(address, map_length); |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 182 | if (!mem_info->mapped_logical_address) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 183 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 184 | "Could not map memory at 0x%8.8X%8.8X, size %u", |
Lv Zheng | 1d0a0b2 | 2015-04-13 11:48:52 +0800 | [diff] [blame] | 185 | ACPI_FORMAT_UINT64(address), |
Lv Zheng | 18ae902 | 2015-04-13 11:48:12 +0800 | [diff] [blame] | 186 | (u32)map_length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | mem_info->mapped_length = 0; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 188 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /* Save the physical address and mapping size */ |
| 192 | |
| 193 | mem_info->mapped_physical_address = address; |
Bob Moore | d410ee5 | 2009-10-22 09:11:11 +0800 | [diff] [blame] | 194 | mem_info->mapped_length = map_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Generate a logical pointer corresponding to the address we want to |
| 199 | * access |
| 200 | */ |
| 201 | logical_addr_ptr = mem_info->mapped_logical_address + |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 202 | ((u64) address - (u64) mem_info->mapped_physical_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bob Moore | b27d659 | 2010-05-26 11:47:13 +0800 | [diff] [blame] | 205 | "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] | 206 | bit_width, function, ACPI_FORMAT_UINT64(address))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | /* |
| 209 | * Perform the memory read or write |
| 210 | * |
| 211 | * Note: For machines that do not support non-aligned transfers, the target |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 212 | * 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] | 213 | * transfer up into smaller (byte-size) chunks because the AML specifically |
| 214 | * asked for a transfer width that the hardware may require. |
| 215 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | switch (function) { |
| 217 | case ACPI_READ: |
| 218 | |
| 219 | *value = 0; |
| 220 | switch (bit_width) { |
| 221 | case 8: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 222 | |
| 223 | *value = (u64)ACPI_GET8(logical_addr_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | break; |
| 225 | |
| 226 | case 16: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 227 | |
| 228 | *value = (u64)ACPI_GET16(logical_addr_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | break; |
| 230 | |
| 231 | case 32: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 232 | |
| 233 | *value = (u64)ACPI_GET32(logical_addr_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | break; |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | case 64: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 237 | |
| 238 | *value = (u64)ACPI_GET64(logical_addr_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | break; |
Bob Moore | 59fa850 | 2007-02-02 19:48:23 +0300 | [diff] [blame] | 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | /* bit_width was already validated */ |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | break; |
| 246 | } |
| 247 | break; |
| 248 | |
| 249 | case ACPI_WRITE: |
| 250 | |
| 251 | switch (bit_width) { |
| 252 | case 8: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 253 | |
Lv Zheng | 57bf6ae | 2012-12-19 05:38:24 +0000 | [diff] [blame] | 254 | ACPI_SET8(logical_addr_ptr, *value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | break; |
| 256 | |
| 257 | case 16: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 258 | |
Lv Zheng | 57bf6ae | 2012-12-19 05:38:24 +0000 | [diff] [blame] | 259 | ACPI_SET16(logical_addr_ptr, *value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | break; |
| 261 | |
| 262 | case 32: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 263 | |
Lv Zheng | 57bf6ae | 2012-12-19 05:38:24 +0000 | [diff] [blame] | 264 | ACPI_SET32(logical_addr_ptr, *value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | break; |
| 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | case 64: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 268 | |
Lv Zheng | 57bf6ae | 2012-12-19 05:38:24 +0000 | [diff] [blame] | 269 | ACPI_SET64(logical_addr_ptr, *value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | /* bit_width was already validated */ |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | break; |
| 277 | } |
| 278 | break; |
| 279 | |
| 280 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | status = AE_BAD_PARAMETER; |
| 283 | break; |
| 284 | } |
| 285 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 286 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | /******************************************************************************* |
| 290 | * |
| 291 | * FUNCTION: acpi_ex_system_io_space_handler |
| 292 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 293 | * PARAMETERS: function - Read or Write operation |
| 294 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 296 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | * handler_context - Pointer to Handler's context |
| 298 | * region_context - Pointer to context specific to the |
| 299 | * accessed region |
| 300 | * |
| 301 | * RETURN: Status |
| 302 | * |
| 303 | * DESCRIPTION: Handler for the System IO address space (Op Region) |
| 304 | * |
| 305 | ******************************************************************************/ |
| 306 | |
| 307 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | acpi_ex_system_io_space_handler(u32 function, |
| 309 | acpi_physical_address address, |
| 310 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 311 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 312 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 314 | acpi_status status = AE_OK; |
| 315 | u32 value32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 317 | ACPI_FUNCTION_TRACE(ex_system_io_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bob Moore | b27d659 | 2010-05-26 11:47:13 +0800 | [diff] [blame] | 320 | "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] | 321 | bit_width, function, ACPI_FORMAT_UINT64(address))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | /* Decode the function parameter */ |
| 324 | |
| 325 | switch (function) { |
| 326 | case ACPI_READ: |
| 327 | |
Bob Moore | 7f07190 | 2009-03-19 09:37:47 +0800 | [diff] [blame] | 328 | status = acpi_hw_read_port((acpi_io_address) address, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | &value32, bit_width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | *value = value32; |
| 331 | break; |
| 332 | |
| 333 | case ACPI_WRITE: |
| 334 | |
Bob Moore | 7f07190 | 2009-03-19 09:37:47 +0800 | [diff] [blame] | 335 | status = acpi_hw_write_port((acpi_io_address) address, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 336 | (u32) * value, bit_width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | break; |
| 338 | |
| 339 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | status = AE_BAD_PARAMETER; |
| 342 | break; |
| 343 | } |
| 344 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | /******************************************************************************* |
| 349 | * |
| 350 | * FUNCTION: acpi_ex_pci_config_space_handler |
| 351 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 352 | * PARAMETERS: function - Read or Write operation |
| 353 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 355 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | * handler_context - Pointer to Handler's context |
| 357 | * region_context - Pointer to context specific to the |
| 358 | * accessed region |
| 359 | * |
| 360 | * RETURN: Status |
| 361 | * |
| 362 | * DESCRIPTION: Handler for the PCI Config address space (Op Region) |
| 363 | * |
| 364 | ******************************************************************************/ |
| 365 | |
| 366 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 367 | acpi_ex_pci_config_space_handler(u32 function, |
| 368 | acpi_physical_address address, |
| 369 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 370 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 371 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 373 | acpi_status status = AE_OK; |
| 374 | struct acpi_pci_id *pci_id; |
| 375 | u16 pci_register; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 377 | ACPI_FUNCTION_TRACE(ex_pci_config_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
| 379 | /* |
| 380 | * The arguments to acpi_os(Read|Write)pci_configuration are: |
| 381 | * |
| 382 | * pci_segment is the PCI bus segment range 0-31 |
| 383 | * pci_bus is the PCI bus number range 0-255 |
| 384 | * pci_device is the PCI device number range 0-31 |
| 385 | * pci_function is the PCI device function number |
| 386 | * pci_register is the Config space register range 0-255 bytes |
| 387 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 388 | * value - input value for write, output address for read |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | * |
| 390 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 391 | pci_id = (struct acpi_pci_id *)region_context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | pci_register = (u16) (u32) address; |
| 393 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 394 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 395 | "Pci-Config %u (%u) Seg(%04x) Bus(%04x) " |
| 396 | "Dev(%04x) Func(%04x) Reg(%04x)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 397 | function, bit_width, pci_id->segment, pci_id->bus, |
| 398 | pci_id->device, pci_id->function, pci_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | switch (function) { |
| 401 | case ACPI_READ: |
| 402 | |
Lv Zheng | bb42cc2 | 2013-10-31 09:29:49 +0800 | [diff] [blame] | 403 | *value = 0; |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 404 | status = |
| 405 | acpi_os_read_pci_configuration(pci_id, pci_register, value, |
| 406 | bit_width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | break; |
| 408 | |
| 409 | case ACPI_WRITE: |
| 410 | |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 411 | status = |
| 412 | acpi_os_write_pci_configuration(pci_id, pci_register, |
| 413 | *value, bit_width); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | break; |
| 415 | |
| 416 | default: |
| 417 | |
| 418 | status = AE_BAD_PARAMETER; |
| 419 | break; |
| 420 | } |
| 421 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | /******************************************************************************* |
| 426 | * |
| 427 | * FUNCTION: acpi_ex_cmos_space_handler |
| 428 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 429 | * PARAMETERS: function - Read or Write operation |
| 430 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 432 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | * handler_context - Pointer to Handler's context |
| 434 | * region_context - Pointer to context specific to the |
| 435 | * accessed region |
| 436 | * |
| 437 | * RETURN: Status |
| 438 | * |
| 439 | * DESCRIPTION: Handler for the CMOS address space (Op Region) |
| 440 | * |
| 441 | ******************************************************************************/ |
| 442 | |
| 443 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 444 | acpi_ex_cmos_space_handler(u32 function, |
| 445 | acpi_physical_address address, |
| 446 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 447 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 448 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 452 | ACPI_FUNCTION_TRACE(ex_cmos_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | /******************************************************************************* |
| 458 | * |
| 459 | * FUNCTION: acpi_ex_pci_bar_space_handler |
| 460 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 461 | * PARAMETERS: function - Read or Write operation |
| 462 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 464 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | * handler_context - Pointer to Handler's context |
| 466 | * region_context - Pointer to context specific to the |
| 467 | * accessed region |
| 468 | * |
| 469 | * RETURN: Status |
| 470 | * |
| 471 | * DESCRIPTION: Handler for the PCI bar_target address space (Op Region) |
| 472 | * |
| 473 | ******************************************************************************/ |
| 474 | |
| 475 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 476 | acpi_ex_pci_bar_space_handler(u32 function, |
| 477 | acpi_physical_address address, |
| 478 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 479 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 480 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 482 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 484 | ACPI_FUNCTION_TRACE(ex_pci_bar_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 486 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | /******************************************************************************* |
| 490 | * |
| 491 | * FUNCTION: acpi_ex_data_table_space_handler |
| 492 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 493 | * PARAMETERS: function - Read or Write operation |
| 494 | * address - Where in the space to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | * bit_width - Field width in bits (8, 16, or 32) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 496 | * value - Pointer to in or out value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | * handler_context - Pointer to Handler's context |
| 498 | * region_context - Pointer to context specific to the |
| 499 | * accessed region |
| 500 | * |
| 501 | * RETURN: Status |
| 502 | * |
| 503 | * DESCRIPTION: Handler for the Data Table address space (Op Region) |
| 504 | * |
| 505 | ******************************************************************************/ |
| 506 | |
| 507 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 508 | acpi_ex_data_table_space_handler(u32 function, |
| 509 | acpi_physical_address address, |
| 510 | u32 bit_width, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 511 | u64 *value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 512 | void *handler_context, void *region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 514 | ACPI_FUNCTION_TRACE(ex_data_table_space_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Bob Moore | c1637e9 | 2010-04-01 11:09:00 +0800 | [diff] [blame] | 516 | /* |
| 517 | * Perform the memory read or write. The bit_width was already |
| 518 | * validated. |
| 519 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | switch (function) { |
| 521 | case ACPI_READ: |
| 522 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 523 | memcpy(ACPI_CAST_PTR(char, value), |
| 524 | ACPI_PHYSADDR_TO_PTR(address), ACPI_DIV_8(bit_width)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | break; |
| 526 | |
| 527 | case ACPI_WRITE: |
Bob Moore | c1637e9 | 2010-04-01 11:09:00 +0800 | [diff] [blame] | 528 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 529 | memcpy(ACPI_PHYSADDR_TO_PTR(address), |
| 530 | ACPI_CAST_PTR(char, value), ACPI_DIV_8(bit_width)); |
Bob Moore | c1637e9 | 2010-04-01 11:09:00 +0800 | [diff] [blame] | 531 | break; |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | default: |
| 534 | |
Bob Moore | c1637e9 | 2010-04-01 11:09:00 +0800 | [diff] [blame] | 535 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 538 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |