1 1.1 christos /****************************************************************************** 2 1.1 christos * 3 1.1.1.6 christos * Module Name: aeregion - Handler for operation regions 4 1.1 christos * 5 1.1 christos *****************************************************************************/ 6 1.1 christos 7 1.1.1.16 christos /****************************************************************************** 8 1.1.1.16 christos * 9 1.1.1.16 christos * 1. Copyright Notice 10 1.1.1.16 christos * 11 1.1.1.17 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp. 12 1.1 christos * All rights reserved. 13 1.1 christos * 14 1.1.1.16 christos * 2. License 15 1.1.1.16 christos * 16 1.1.1.16 christos * 2.1. This is your license from Intel Corp. under its intellectual property 17 1.1.1.16 christos * rights. You may have additional license terms from the party that provided 18 1.1.1.16 christos * you this software, covering your right to use that party's intellectual 19 1.1.1.16 christos * property rights. 20 1.1.1.16 christos * 21 1.1.1.16 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 1.1.1.16 christos * copy of the source code appearing in this file ("Covered Code") an 23 1.1.1.16 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 1.1.1.16 christos * base code distributed originally by Intel ("Original Intel Code") to copy, 25 1.1.1.16 christos * make derivatives, distribute, use and display any portion of the Covered 26 1.1.1.16 christos * Code in any form, with the right to sublicense such rights; and 27 1.1.1.16 christos * 28 1.1.1.16 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 1.1.1.16 christos * license (with the right to sublicense), under only those claims of Intel 30 1.1.1.16 christos * patents that are infringed by the Original Intel Code, to make, use, sell, 31 1.1.1.16 christos * offer to sell, and import the Covered Code and derivative works thereof 32 1.1.1.16 christos * solely to the minimum extent necessary to exercise the above copyright 33 1.1.1.16 christos * license, and in no event shall the patent license extend to any additions 34 1.1.1.16 christos * to or modifications of the Original Intel Code. No other license or right 35 1.1.1.16 christos * is granted directly or by implication, estoppel or otherwise; 36 1.1.1.16 christos * 37 1.1.1.16 christos * The above copyright and patent license is granted only if the following 38 1.1.1.16 christos * conditions are met: 39 1.1.1.16 christos * 40 1.1.1.16 christos * 3. Conditions 41 1.1.1.16 christos * 42 1.1.1.16 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 1.1.1.16 christos * Redistribution of source code of any substantial portion of the Covered 44 1.1.1.16 christos * Code or modification with rights to further distribute source must include 45 1.1.1.16 christos * the above Copyright Notice, the above License, this list of Conditions, 46 1.1.1.16 christos * and the following Disclaimer and Export Compliance provision. In addition, 47 1.1.1.16 christos * Licensee must cause all Covered Code to which Licensee contributes to 48 1.1.1.16 christos * contain a file documenting the changes Licensee made to create that Covered 49 1.1.1.16 christos * Code and the date of any change. Licensee must include in that file the 50 1.1.1.16 christos * documentation of any changes made by any predecessor Licensee. Licensee 51 1.1.1.16 christos * must include a prominent statement that the modification is derived, 52 1.1.1.16 christos * directly or indirectly, from Original Intel Code. 53 1.1.1.16 christos * 54 1.1.1.16 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 1.1.1.16 christos * Redistribution of source code of any substantial portion of the Covered 56 1.1.1.16 christos * Code or modification without rights to further distribute source must 57 1.1.1.16 christos * include the following Disclaimer and Export Compliance provision in the 58 1.1.1.16 christos * documentation and/or other materials provided with distribution. In 59 1.1.1.16 christos * addition, Licensee may not authorize further sublicense of source of any 60 1.1.1.16 christos * portion of the Covered Code, and must include terms to the effect that the 61 1.1.1.16 christos * license from Licensee to its licensee is limited to the intellectual 62 1.1.1.16 christos * property embodied in the software Licensee provides to its licensee, and 63 1.1.1.16 christos * not to intellectual property embodied in modifications its licensee may 64 1.1.1.16 christos * make. 65 1.1.1.16 christos * 66 1.1.1.16 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 1.1.1.16 christos * substantial portion of the Covered Code or modification must reproduce the 68 1.1.1.16 christos * above Copyright Notice, and the following Disclaimer and Export Compliance 69 1.1.1.16 christos * provision in the documentation and/or other materials provided with the 70 1.1.1.16 christos * distribution. 71 1.1.1.16 christos * 72 1.1.1.16 christos * 3.4. Intel retains all right, title, and interest in and to the Original 73 1.1.1.16 christos * Intel Code. 74 1.1.1.16 christos * 75 1.1.1.16 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 1.1.1.16 christos * Intel shall be used in advertising or otherwise to promote the sale, use or 77 1.1.1.16 christos * other dealings in products derived from or relating to the Covered Code 78 1.1.1.16 christos * without prior written authorization from Intel. 79 1.1.1.16 christos * 80 1.1.1.16 christos * 4. Disclaimer and Export Compliance 81 1.1.1.16 christos * 82 1.1.1.16 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 1.1.1.16 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 1.1.1.16 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 1.1.1.16 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 1.1.1.16 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 1.1.1.16 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 1.1.1.16 christos * PARTICULAR PURPOSE. 89 1.1.1.16 christos * 90 1.1.1.16 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 1.1.1.16 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 1.1.1.16 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 1.1.1.16 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 1.1.1.16 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 1.1.1.16 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 1.1.1.16 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 1.1.1.16 christos * LIMITED REMEDY. 98 1.1.1.16 christos * 99 1.1.1.16 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 1.1.1.16 christos * software or system incorporating such software without first obtaining any 101 1.1.1.16 christos * required license or other approval from the U. S. Department of Commerce or 102 1.1.1.16 christos * any other agency or department of the United States Government. In the 103 1.1.1.16 christos * event Licensee exports any such software from the United States or 104 1.1.1.16 christos * re-exports any such software from a foreign destination, Licensee shall 105 1.1.1.16 christos * ensure that the distribution and export/re-export of the software is in 106 1.1.1.16 christos * compliance with all laws, regulations, orders, or other restrictions of the 107 1.1.1.16 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 1.1.1.16 christos * any of its subsidiaries will export/re-export any technical data, process, 109 1.1.1.16 christos * software, or service, directly or indirectly, to any country for which the 110 1.1.1.16 christos * United States government or any agency thereof requires an export license, 111 1.1.1.16 christos * other governmental approval, or letter of assurance, without first obtaining 112 1.1.1.16 christos * such license, approval or letter. 113 1.1.1.16 christos * 114 1.1.1.16 christos ***************************************************************************** 115 1.1.1.16 christos * 116 1.1.1.16 christos * Alternatively, you may choose to be licensed under the terms of the 117 1.1.1.16 christos * following license: 118 1.1.1.16 christos * 119 1.1 christos * Redistribution and use in source and binary forms, with or without 120 1.1 christos * modification, are permitted provided that the following conditions 121 1.1 christos * are met: 122 1.1 christos * 1. Redistributions of source code must retain the above copyright 123 1.1 christos * notice, this list of conditions, and the following disclaimer, 124 1.1 christos * without modification. 125 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below 127 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon 128 1.1 christos * including a substantially similar Disclaimer requirement for further 129 1.1 christos * binary redistribution. 130 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names 131 1.1 christos * of any contributors may be used to endorse or promote products derived 132 1.1 christos * from this software without specific prior written permission. 133 1.1 christos * 134 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 1.1.1.12 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 1.1.1.16 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 1.1.1.16 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 1.1.1.16 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 1.1.1.16 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 1.1.1.16 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 1.1.1.16 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 1.1.1.16 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 1.1.1.16 christos * 146 1.1.1.16 christos * Alternatively, you may choose to be licensed under the terms of the 147 1.1.1.16 christos * GNU General Public License ("GPL") version 2 as published by the Free 148 1.1.1.16 christos * Software Foundation. 149 1.1.1.16 christos * 150 1.1.1.16 christos *****************************************************************************/ 151 1.1 christos 152 1.1 christos #include "aecommon.h" 153 1.1 christos 154 1.1 christos #define _COMPONENT ACPI_TOOLS 155 1.1 christos ACPI_MODULE_NAME ("aeregion") 156 1.1 christos 157 1.1 christos 158 1.1 christos static AE_DEBUG_REGIONS AeRegions; 159 1.1 christos 160 1.1 christos 161 1.1 christos /****************************************************************************** 162 1.1 christos * 163 1.1 christos * FUNCTION: AeRegionHandler 164 1.1 christos * 165 1.1 christos * PARAMETERS: Standard region handler parameters 166 1.1 christos * 167 1.1 christos * RETURN: Status 168 1.1 christos * 169 1.1 christos * DESCRIPTION: Test handler - Handles some dummy regions via memory that can 170 1.1 christos * be manipulated in Ring 3. Simulates actual reads and writes. 171 1.1 christos * 172 1.1 christos *****************************************************************************/ 173 1.1 christos 174 1.1 christos ACPI_STATUS 175 1.1 christos AeRegionHandler ( 176 1.1 christos UINT32 Function, 177 1.1 christos ACPI_PHYSICAL_ADDRESS Address, 178 1.1 christos UINT32 BitWidth, 179 1.1 christos UINT64 *Value, 180 1.1 christos void *HandlerContext, 181 1.1 christos void *RegionContext) 182 1.1 christos { 183 1.1 christos 184 1.1 christos ACPI_OPERAND_OBJECT *RegionObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, RegionContext); 185 1.1 christos UINT8 *Buffer = ACPI_CAST_PTR (UINT8, Value); 186 1.1 christos UINT8 *OldBuffer; 187 1.1 christos UINT8 *NewBuffer; 188 1.1 christos ACPI_PHYSICAL_ADDRESS BaseAddress; 189 1.1 christos ACPI_PHYSICAL_ADDRESS BaseAddressEnd; 190 1.1 christos ACPI_PHYSICAL_ADDRESS RegionAddress; 191 1.1 christos ACPI_PHYSICAL_ADDRESS RegionAddressEnd; 192 1.1.1.9 christos UINT32 Length; 193 1.1.1.9 christos UINT8 DataLength; 194 1.1.1.9 christos UINT8 *DataBuffer; 195 1.1 christos BOOLEAN BufferExists; 196 1.1 christos BOOLEAN BufferResize; 197 1.1 christos AE_REGION *RegionElement; 198 1.1 christos void *BufferValue; 199 1.1 christos ACPI_STATUS Status; 200 1.1 christos UINT32 ByteWidth; 201 1.1 christos UINT32 RegionLength; 202 1.1 christos UINT32 i; 203 1.1 christos UINT8 SpaceId; 204 1.1 christos ACPI_CONNECTION_INFO *MyContext; 205 1.1 christos UINT32 Value1; 206 1.1 christos UINT32 Value2; 207 1.1 christos ACPI_RESOURCE *Resource; 208 1.1.1.13 christos char Uuid[ACPI_PRM_INPUT_BUFFER_SIZE + 1]; 209 1.1 christos 210 1.1 christos 211 1.1 christos ACPI_FUNCTION_NAME (AeRegionHandler); 212 1.1 christos 213 1.1.1.9 christos 214 1.1.1.9 christos /* If the object is not a region, simply return */ 215 1.1.1.9 christos 216 1.1 christos if (RegionObject->Region.Type != ACPI_TYPE_REGION) 217 1.1 christos { 218 1.1 christos return (AE_OK); 219 1.1 christos } 220 1.1 christos 221 1.1 christos /* Check that we actually got back our context parameter */ 222 1.1 christos 223 1.1 christos if (HandlerContext != &AeMyContext) 224 1.1 christos { 225 1.1.1.9 christos AcpiOsPrintf ( 226 1.1.1.9 christos "Region handler received incorrect context %p, should be %p\n", 227 1.1 christos HandlerContext, &AeMyContext); 228 1.1 christos } 229 1.1 christos 230 1.1 christos MyContext = ACPI_CAST_PTR (ACPI_CONNECTION_INFO, HandlerContext); 231 1.1 christos 232 1.1 christos /* 233 1.1 christos * Find the region's address space and length before searching 234 1.1 christos * the linked list. 235 1.1 christos */ 236 1.1 christos BaseAddress = RegionObject->Region.Address; 237 1.1.1.9 christos Length = RegionObject->Region.Length; 238 1.1 christos SpaceId = RegionObject->Region.SpaceId; 239 1.1 christos 240 1.1.1.4 christos ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, 241 1.1.1.8 christos "Operation Region request on %s at 0x%X, BitWidth 0x%X, RegionLength 0x%X\n", 242 1.1.1.4 christos AcpiUtGetRegionName (RegionObject->Region.SpaceId), 243 1.1.1.8 christos (UINT32) Address, BitWidth, (UINT32) Length)); 244 1.1 christos 245 1.1 christos /* 246 1.1 christos * Region support can be disabled with the -do option. 247 1.1 christos * We use this to support dynamically loaded tables where we pass a valid 248 1.1 christos * address to the AML. 249 1.1 christos */ 250 1.1 christos if (AcpiGbl_DbOpt_NoRegionSupport) 251 1.1 christos { 252 1.1 christos BufferValue = ACPI_TO_POINTER (Address); 253 1.1 christos ByteWidth = (BitWidth / 8); 254 1.1 christos 255 1.1 christos if (BitWidth % 8) 256 1.1 christos { 257 1.1 christos ByteWidth += 1; 258 1.1 christos } 259 1.1 christos goto DoFunction; 260 1.1 christos } 261 1.1 christos 262 1.1 christos switch (SpaceId) 263 1.1 christos { 264 1.1 christos case ACPI_ADR_SPACE_SYSTEM_IO: 265 1.1 christos /* 266 1.1 christos * For I/O space, exercise the port validation 267 1.1 christos * Note: ReadPort currently always returns all ones, length=BitLength 268 1.1 christos */ 269 1.1 christos switch (Function & ACPI_IO_MASK) 270 1.1 christos { 271 1.1 christos case ACPI_READ: 272 1.1 christos 273 1.1 christos if (BitWidth == 64) 274 1.1 christos { 275 1.1 christos /* Split the 64-bit request into two 32-bit requests */ 276 1.1 christos 277 1.1 christos Status = AcpiHwReadPort (Address, &Value1, 32); 278 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwReadPort, Status); 279 1.1 christos Status = AcpiHwReadPort (Address+4, &Value2, 32); 280 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwReadPort, Status); 281 1.1 christos 282 1.1 christos *Value = Value1 | ((UINT64) Value2 << 32); 283 1.1 christos } 284 1.1 christos else 285 1.1 christos { 286 1.1 christos Status = AcpiHwReadPort (Address, &Value1, BitWidth); 287 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwReadPort, Status); 288 1.1 christos *Value = (UINT64) Value1; 289 1.1 christos } 290 1.1 christos break; 291 1.1 christos 292 1.1 christos case ACPI_WRITE: 293 1.1 christos 294 1.1 christos if (BitWidth == 64) 295 1.1 christos { 296 1.1 christos /* Split the 64-bit request into two 32-bit requests */ 297 1.1 christos 298 1.1 christos Status = AcpiHwWritePort (Address, ACPI_LODWORD (*Value), 32); 299 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwWritePort, Status); 300 1.1 christos Status = AcpiHwWritePort (Address+4, ACPI_HIDWORD (*Value), 32); 301 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwWritePort, Status); 302 1.1 christos } 303 1.1 christos else 304 1.1 christos { 305 1.1 christos Status = AcpiHwWritePort (Address, (UINT32) *Value, BitWidth); 306 1.1.1.4 christos ACPI_CHECK_OK (AcpiHwWritePort, Status); 307 1.1 christos } 308 1.1 christos break; 309 1.1 christos 310 1.1 christos default: 311 1.1 christos 312 1.1 christos Status = AE_BAD_PARAMETER; 313 1.1 christos break; 314 1.1 christos } 315 1.1 christos 316 1.1 christos if (ACPI_FAILURE (Status)) 317 1.1 christos { 318 1.1 christos return (Status); 319 1.1 christos } 320 1.1 christos 321 1.1 christos /* Now go ahead and simulate the hardware */ 322 1.1 christos break; 323 1.1 christos 324 1.1 christos /* 325 1.1 christos * SMBus and GenericSerialBus support the various bidirectional 326 1.1 christos * protocols. 327 1.1 christos */ 328 1.1 christos case ACPI_ADR_SPACE_SMBUS: 329 1.1 christos case ACPI_ADR_SPACE_GSBUS: /* ACPI 5.0 */ 330 1.1 christos 331 1.1.1.9 christos Status = AcpiExGetProtocolBufferLength ((Function >> 16), &Length); 332 1.1.1.9 christos if (ACPI_FAILURE (Status)) 333 1.1 christos { 334 1.1.1.9 christos AcpiOsPrintf ("AcpiExec: Invalid SMbus/GSbus protocol ID: 0x%X\n", 335 1.1.1.9 christos (Function >> 16)); 336 1.1.1.9 christos return (Status); 337 1.1.1.9 christos } 338 1.1 christos 339 1.1.1.9 christos /* Adjust for fixed SMBus buffer size */ 340 1.1 christos 341 1.1.1.9 christos if ((SpaceId == ACPI_ADR_SPACE_SMBUS) && 342 1.1.1.9 christos (Length > ACPI_SMBUS_DATA_SIZE)) 343 1.1.1.9 christos { 344 1.1.1.9 christos Length = ACPI_SMBUS_DATA_SIZE; /* SMBus buffer is fixed-length */ 345 1.1 christos } 346 1.1 christos 347 1.1 christos if (AcpiGbl_DisplayRegionAccess) 348 1.1 christos { 349 1.1 christos AcpiOsPrintf ("AcpiExec: %s " 350 1.1.1.9 christos "%s: Attr %X Addr %.4X BaseAddr %.4X Length %.2X BitWidth %X BufLen %X\n", 351 1.1 christos AcpiUtGetRegionName (SpaceId), 352 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ", 353 1.1 christos (UINT32) (Function >> 16), 354 1.1 christos (UINT32) Address, (UINT32) BaseAddress, 355 1.1 christos Length, BitWidth, Buffer[1]); 356 1.1 christos 357 1.1 christos /* GenericSerialBus has a Connection() parameter */ 358 1.1 christos 359 1.1.1.9 christos if ((SpaceId == ACPI_ADR_SPACE_GSBUS) && MyContext) 360 1.1 christos { 361 1.1 christos Status = AcpiBufferToResource (MyContext->Connection, 362 1.1 christos MyContext->Length, &Resource); 363 1.1.1.9 christos if (ACPI_SUCCESS (Status)) 364 1.1.1.9 christos { 365 1.1.1.9 christos ACPI_FREE (Resource); 366 1.1.1.9 christos } 367 1.1 christos 368 1.1.1.10 christos AcpiOsPrintf (" [AccessLength %.2X Connection %p]", 369 1.1 christos MyContext->AccessLength, MyContext->Connection); 370 1.1 christos } 371 1.1.1.9 christos 372 1.1 christos AcpiOsPrintf ("\n"); 373 1.1 christos } 374 1.1 christos 375 1.1.1.9 christos DataBuffer = &Buffer[2]; 376 1.1.1.9 christos DataLength = (UINT8) Length; 377 1.1.1.9 christos 378 1.1 christos /* Setup the return buffer. Note: ASLTS depends on these fill values */ 379 1.1 christos 380 1.1.1.9 christos if (Length == ACPI_MAX_GSBUS_DATA_SIZE) 381 1.1.1.9 christos { 382 1.1.1.9 christos DataLength = 0x20; /* For ASLTS only */ 383 1.1.1.9 christos } 384 1.1.1.9 christos 385 1.1 christos for (i = 0; i < Length; i++) 386 1.1 christos { 387 1.1.1.9 christos DataBuffer[i] = (UINT8) (0xA0 + i); 388 1.1 christos } 389 1.1 christos 390 1.1.1.9 christos Buffer[0] = 0; /* Return Status, OK */ 391 1.1.1.9 christos Buffer[1] = DataLength; /* Length of valid data */ 392 1.1 christos return (AE_OK); 393 1.1 christos 394 1.1 christos case ACPI_ADR_SPACE_IPMI: /* ACPI 4.0 */ 395 1.1 christos 396 1.1 christos if (AcpiGbl_DisplayRegionAccess) 397 1.1 christos { 398 1.1 christos AcpiOsPrintf ("AcpiExec: IPMI " 399 1.1 christos "%s: Attr %X Addr %.4X BaseAddr %.4X Len %.2X Width %X BufLen %X\n", 400 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ", 401 1.1 christos (UINT32) (Function >> 16), (UINT32) Address, (UINT32) BaseAddress, 402 1.1 christos Length, BitWidth, Buffer[1]); 403 1.1 christos } 404 1.1 christos 405 1.1 christos /* 406 1.1 christos * Regardless of a READ or WRITE, this handler is passed a 66-byte 407 1.1 christos * buffer in which to return the IPMI status/length/data. 408 1.1 christos * 409 1.1 christos * Return some example data to show use of the bidirectional buffer 410 1.1 christos */ 411 1.1.1.9 christos Buffer[0] = 0; /* Status byte */ 412 1.1.1.9 christos Buffer[1] = ACPI_IPMI_DATA_SIZE; /* Return buffer data length */ 413 1.1.1.9 christos Buffer[2] = 0; /* Completion code */ 414 1.1.1.9 christos Buffer[3] = 0; /* Reserved */ 415 1.1 christos 416 1.1 christos /* 417 1.1 christos * Fill the 66-byte buffer with the return data. 418 1.1 christos * Note: ASLTS depends on these fill values. 419 1.1 christos */ 420 1.1.1.9 christos for (i = 4; i < ACPI_IPMI_BUFFER_SIZE; i++) 421 1.1 christos { 422 1.1 christos Buffer[i] = (UINT8) (i); 423 1.1 christos } 424 1.1 christos return (AE_OK); 425 1.1 christos 426 1.1 christos /* 427 1.1 christos * GPIO has some special semantics: 428 1.1 christos * 1) Address is the pin number index into the Connection() pin list 429 1.1 christos * 2) BitWidth is the actual number of bits (pins) defined by the field 430 1.1 christos */ 431 1.1 christos case ACPI_ADR_SPACE_GPIO: /* ACPI 5.0 */ 432 1.1 christos 433 1.1 christos if (AcpiGbl_DisplayRegionAccess) 434 1.1 christos { 435 1.1 christos AcpiOsPrintf ("AcpiExec: GPIO " 436 1.1.1.9 christos "%s: Address %.4X Length %X BitWidth %X Conn %p\n", 437 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ", 438 1.1.1.9 christos (UINT32) Address, Length, BitWidth, MyContext->Connection); 439 1.1 christos } 440 1.1.1.9 christos 441 1.1.1.9 christos /* Now perform the "normal" SystemMemory handling, for AcpiExec only */ 442 1.1.1.9 christos break; 443 1.1 christos 444 1.1.1.10 christos /* 445 1.1.1.10 christos * PCC operation region will write the entire subspace's data and expect 446 1.1.1.10 christos * a response from the hardware. For acpiexec, we'll fill the buffer with 447 1.1.1.10 christos * default values. Note: ASLTS will depend on these values. 448 1.1.1.10 christos */ 449 1.1.1.10 christos case ACPI_ADR_SPACE_PLATFORM_COMM: /* ACPI 6.3 */ 450 1.1.1.13 christos 451 1.1.1.10 christos if (AcpiGbl_DisplayRegionAccess) 452 1.1.1.10 christos { 453 1.1.1.10 christos AcpiOsPrintf ("AcpiExec: PCC Write : Addr %.4X Width %X\n", 454 1.1.1.10 christos (UINT32) Address, BitWidth); 455 1.1.1.10 christos } 456 1.1.1.10 christos for (i = 0; i < Length; ++i) 457 1.1.1.10 christos { 458 1.1.1.10 christos Buffer[i] = (UINT8) i; 459 1.1.1.10 christos } 460 1.1.1.10 christos return (AE_OK); 461 1.1.1.10 christos 462 1.1.1.13 christos case ACPI_ADR_SPACE_PLATFORM_RT: 463 1.1.1.13 christos 464 1.1.1.13 christos AcpiOsPrintf ("Acpiexec: PRM %s invoked\n", 465 1.1.1.13 christos (Function & ACPI_IO_MASK) ? "Write" : "Read "); 466 1.1.1.13 christos 467 1.1.1.13 christos if ((Function & ACPI_IO_MASK) == ACPI_WRITE) 468 1.1.1.13 christos { 469 1.1.1.13 christos AcpiUtConvertUuidToString((char *) Buffer + 10, Uuid); 470 1.1.1.13 christos AcpiOsPrintf ("Mode: %u GUID: %s\n", Buffer[0], Uuid); 471 1.1.1.13 christos } 472 1.1.1.13 christos 473 1.1.1.13 christos /* Unpack the input buffer and print the contents for debug */ 474 1.1.1.13 christos 475 1.1.1.13 christos break; 476 1.1.1.13 christos 477 1.1 christos default: 478 1.1 christos break; 479 1.1 christos } 480 1.1 christos 481 1.1 christos /* 482 1.1 christos * Search through the linked list for this region's buffer 483 1.1 christos */ 484 1.1 christos BufferExists = FALSE; 485 1.1 christos BufferResize = FALSE; 486 1.1 christos RegionElement = AeRegions.RegionList; 487 1.1 christos 488 1.1 christos if (AeRegions.NumberOfRegions) 489 1.1 christos { 490 1.1 christos BaseAddressEnd = BaseAddress + Length - 1; 491 1.1 christos while (!BufferExists && RegionElement) 492 1.1 christos { 493 1.1 christos RegionAddress = RegionElement->Address; 494 1.1 christos RegionAddressEnd = RegionElement->Address + RegionElement->Length - 1; 495 1.1 christos RegionLength = RegionElement->Length; 496 1.1 christos 497 1.1 christos /* 498 1.1 christos * Overlapping Region Support 499 1.1 christos * 500 1.1 christos * While searching through the region buffer list, determine if an 501 1.1 christos * overlap exists between the requested buffer space and the current 502 1.1 christos * RegionElement space. If there is an overlap then replace the old 503 1.1 christos * buffer with a new buffer of increased size before continuing to 504 1.1 christos * do the read or write 505 1.1 christos */ 506 1.1 christos if (RegionElement->SpaceId != SpaceId || 507 1.1 christos BaseAddressEnd < RegionAddress || 508 1.1 christos BaseAddress > RegionAddressEnd) 509 1.1 christos { 510 1.1 christos /* 511 1.1 christos * Requested buffer is outside of the current RegionElement 512 1.1 christos * bounds 513 1.1 christos */ 514 1.1 christos RegionElement = RegionElement->NextRegion; 515 1.1 christos } 516 1.1 christos else 517 1.1 christos { 518 1.1 christos /* 519 1.1 christos * Some amount of buffer space sharing exists. There are 4 cases 520 1.1 christos * to consider: 521 1.1 christos * 522 1.1 christos * 1. Right overlap 523 1.1 christos * 2. Left overlap 524 1.1 christos * 3. Left and right overlap 525 1.1 christos * 4. Fully contained - no resizing required 526 1.1 christos */ 527 1.1 christos BufferExists = TRUE; 528 1.1 christos 529 1.1 christos if ((BaseAddress >= RegionAddress) && 530 1.1 christos (BaseAddress <= RegionAddressEnd) && 531 1.1 christos (BaseAddressEnd > RegionAddressEnd)) 532 1.1 christos { 533 1.1 christos /* Right overlap */ 534 1.1 christos 535 1.1.1.2 christos RegionElement->Length = (UINT32) (BaseAddress - 536 1.1.1.2 christos RegionAddress + Length); 537 1.1 christos BufferResize = TRUE; 538 1.1 christos } 539 1.1 christos 540 1.1 christos else if ((BaseAddressEnd >= RegionAddress) && 541 1.1 christos (BaseAddressEnd <= RegionAddressEnd) && 542 1.1 christos (BaseAddress < RegionAddress)) 543 1.1 christos { 544 1.1 christos /* Left overlap */ 545 1.1 christos 546 1.1 christos RegionElement->Address = BaseAddress; 547 1.1.1.2 christos RegionElement->Length = (UINT32) (RegionAddress - 548 1.1.1.2 christos BaseAddress + RegionElement->Length); 549 1.1 christos BufferResize = TRUE; 550 1.1 christos } 551 1.1 christos 552 1.1 christos else if ((BaseAddress < RegionAddress) && 553 1.1 christos (BaseAddressEnd > RegionAddressEnd)) 554 1.1 christos { 555 1.1 christos /* Left and right overlap */ 556 1.1 christos 557 1.1 christos RegionElement->Address = BaseAddress; 558 1.1 christos RegionElement->Length = Length; 559 1.1 christos BufferResize = TRUE; 560 1.1 christos } 561 1.1 christos 562 1.1 christos /* 563 1.1 christos * only remaining case is fully contained for which we don't 564 1.1 christos * need to do anything 565 1.1 christos */ 566 1.1 christos if (BufferResize) 567 1.1 christos { 568 1.1 christos NewBuffer = AcpiOsAllocate (RegionElement->Length); 569 1.1 christos if (!NewBuffer) 570 1.1 christos { 571 1.1 christos return (AE_NO_MEMORY); 572 1.1 christos } 573 1.1 christos 574 1.1 christos OldBuffer = RegionElement->Buffer; 575 1.1 christos RegionElement->Buffer = NewBuffer; 576 1.1 christos NewBuffer = NULL; 577 1.1 christos 578 1.1 christos /* Initialize the region with the default fill value */ 579 1.1 christos 580 1.1.1.3 christos memset (RegionElement->Buffer, 581 1.1 christos AcpiGbl_RegionFillValue, RegionElement->Length); 582 1.1 christos 583 1.1 christos /* 584 1.1 christos * Get BufferValue to point (within the new buffer) to the 585 1.1 christos * base address of the old buffer 586 1.1 christos */ 587 1.1 christos BufferValue = (UINT8 *) RegionElement->Buffer + 588 1.1 christos (UINT64) RegionAddress - 589 1.1 christos (UINT64) RegionElement->Address; 590 1.1 christos 591 1.1 christos /* 592 1.1 christos * Copy the old buffer to its same location within the new 593 1.1 christos * buffer 594 1.1 christos */ 595 1.1.1.3 christos memcpy (BufferValue, OldBuffer, RegionLength); 596 1.1 christos AcpiOsFree (OldBuffer); 597 1.1 christos } 598 1.1 christos } 599 1.1 christos } 600 1.1 christos } 601 1.1 christos 602 1.1 christos /* 603 1.1 christos * If the Region buffer does not exist, create it now 604 1.1 christos */ 605 1.1 christos if (!BufferExists) 606 1.1 christos { 607 1.1 christos /* Do the memory allocations first */ 608 1.1 christos 609 1.1 christos RegionElement = AcpiOsAllocate (sizeof (AE_REGION)); 610 1.1 christos if (!RegionElement) 611 1.1 christos { 612 1.1 christos return (AE_NO_MEMORY); 613 1.1 christos } 614 1.1 christos 615 1.1 christos RegionElement->Buffer = AcpiOsAllocate (Length); 616 1.1 christos if (!RegionElement->Buffer) 617 1.1 christos { 618 1.1 christos AcpiOsFree (RegionElement); 619 1.1 christos return (AE_NO_MEMORY); 620 1.1 christos } 621 1.1 christos 622 1.1 christos /* Initialize the region with the default fill value */ 623 1.1 christos 624 1.1.1.3 christos memset (RegionElement->Buffer, AcpiGbl_RegionFillValue, Length); 625 1.1 christos 626 1.1 christos RegionElement->Address = BaseAddress; 627 1.1 christos RegionElement->Length = Length; 628 1.1 christos RegionElement->SpaceId = SpaceId; 629 1.1 christos RegionElement->NextRegion = NULL; 630 1.1 christos 631 1.1 christos /* 632 1.1 christos * Increment the number of regions and put this one 633 1.1 christos * at the head of the list as it will probably get accessed 634 1.1 christos * more often anyway. 635 1.1 christos */ 636 1.1 christos AeRegions.NumberOfRegions += 1; 637 1.1 christos 638 1.1 christos if (AeRegions.RegionList) 639 1.1 christos { 640 1.1 christos RegionElement->NextRegion = AeRegions.RegionList; 641 1.1 christos } 642 1.1 christos 643 1.1 christos AeRegions.RegionList = RegionElement; 644 1.1 christos } 645 1.1 christos 646 1.1 christos /* Calculate the size of the memory copy */ 647 1.1 christos 648 1.1 christos ByteWidth = (BitWidth / 8); 649 1.1 christos if (BitWidth % 8) 650 1.1 christos { 651 1.1 christos ByteWidth += 1; 652 1.1 christos } 653 1.1 christos 654 1.1 christos /* 655 1.1 christos * The buffer exists and is pointed to by RegionElement. 656 1.1 christos * We now need to verify the request is valid and perform the operation. 657 1.1 christos * 658 1.1 christos * NOTE: RegionElement->Length is in bytes, therefore it we compare against 659 1.1 christos * ByteWidth (see above) 660 1.1 christos */ 661 1.1 christos if ((RegionObject->Region.SpaceId != ACPI_ADR_SPACE_GPIO) && 662 1.1 christos ((UINT64) Address + ByteWidth) > 663 1.1 christos ((UINT64)(RegionElement->Address) + RegionElement->Length)) 664 1.1 christos { 665 1.1 christos ACPI_WARNING ((AE_INFO, 666 1.1.1.4 christos "Request on [%4.4s] is beyond region limit " 667 1.1.1.4 christos "Req-0x%X+0x%X, Base=0x%X, Len-0x%X", 668 1.1 christos (RegionObject->Region.Node)->Name.Ascii, (UINT32) Address, 669 1.1 christos ByteWidth, (UINT32)(RegionElement->Address), 670 1.1 christos RegionElement->Length)); 671 1.1 christos 672 1.1 christos return (AE_AML_REGION_LIMIT); 673 1.1 christos } 674 1.1 christos 675 1.1 christos /* 676 1.1 christos * Get BufferValue to point to the "address" in the buffer 677 1.1 christos */ 678 1.1 christos BufferValue = ((UINT8 *) RegionElement->Buffer + 679 1.1.1.4 christos ((UINT64) Address - (UINT64) RegionElement->Address)); 680 1.1 christos 681 1.1 christos DoFunction: 682 1.1 christos /* 683 1.1 christos * Perform a read or write to the buffer space 684 1.1 christos */ 685 1.1 christos switch (Function) 686 1.1 christos { 687 1.1 christos case ACPI_READ: 688 1.1 christos /* 689 1.1 christos * Set the pointer Value to whatever is in the buffer 690 1.1 christos */ 691 1.1.1.3 christos memcpy (Value, BufferValue, ByteWidth); 692 1.1 christos break; 693 1.1 christos 694 1.1 christos case ACPI_WRITE: 695 1.1 christos /* 696 1.1 christos * Write the contents of Value to the buffer 697 1.1 christos */ 698 1.1.1.3 christos memcpy (BufferValue, Value, ByteWidth); 699 1.1 christos break; 700 1.1 christos 701 1.1 christos default: 702 1.1 christos 703 1.1 christos return (AE_BAD_PARAMETER); 704 1.1 christos } 705 1.1 christos 706 1.1 christos if (AcpiGbl_DisplayRegionAccess) 707 1.1 christos { 708 1.1 christos switch (SpaceId) 709 1.1 christos { 710 1.1 christos case ACPI_ADR_SPACE_SYSTEM_MEMORY: 711 1.1 christos 712 1.1 christos AcpiOsPrintf ("AcpiExec: SystemMemory " 713 1.1.1.9 christos "%s: Val %.8X Addr %.4X BitWidth %X [REGION: BaseAddr %.4X Len %.2X]\n", 714 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ", 715 1.1 christos (UINT32) *Value, (UINT32) Address, BitWidth, (UINT32) BaseAddress, Length); 716 1.1 christos break; 717 1.1 christos 718 1.1.1.9 christos case ACPI_ADR_SPACE_GSBUS: 719 1.1.1.9 christos 720 1.1.1.9 christos AcpiOsPrintf ("AcpiExec: GenericSerialBus\n"); 721 1.1.1.9 christos break; 722 1.1.1.9 christos 723 1.1 christos case ACPI_ADR_SPACE_GPIO: /* ACPI 5.0 */ 724 1.1 christos 725 1.1 christos /* This space is required to always be ByteAcc */ 726 1.1 christos 727 1.1 christos Status = AcpiBufferToResource (MyContext->Connection, 728 1.1 christos MyContext->Length, &Resource); 729 1.1 christos 730 1.1 christos AcpiOsPrintf ("AcpiExec: GeneralPurposeIo " 731 1.1.1.9 christos "%s: %.8X Addr %.4X BaseAddr %.4X Length %.2X " 732 1.1.1.9 christos "BitWidth %X AccLen %.2X Conn %p\n", 733 1.1 christos (Function & ACPI_IO_MASK) ? "Write" : "Read ", (UINT32) *Value, 734 1.1 christos (UINT32) Address, (UINT32) BaseAddress, Length, BitWidth, 735 1.1 christos MyContext->AccessLength, MyContext->Connection); 736 1.1.1.9 christos if (ACPI_SUCCESS (Status)) 737 1.1.1.9 christos { 738 1.1.1.9 christos ACPI_FREE (Resource); 739 1.1.1.9 christos } 740 1.1 christos break; 741 1.1 christos 742 1.1 christos default: 743 1.1 christos 744 1.1.1.9 christos AcpiOsPrintf ("AcpiExec: Region access on SpaceId %2.2X\n", SpaceId); 745 1.1 christos break; 746 1.1 christos } 747 1.1 christos } 748 1.1 christos 749 1.1 christos return (AE_OK); 750 1.1 christos } 751