1272286Sjkim/****************************************************************************** 2272286Sjkim * 3272286Sjkim * Module Name: aslmapenter - Build resource descriptor/device maps 4272286Sjkim * 5272286Sjkim *****************************************************************************/ 6272286Sjkim 7316303Sjkim/****************************************************************************** 8316303Sjkim * 9316303Sjkim * 1. Copyright Notice 10316303Sjkim * 11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12272286Sjkim * All rights reserved. 13272286Sjkim * 14316303Sjkim * 2. License 15316303Sjkim * 16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 17316303Sjkim * rights. You may have additional license terms from the party that provided 18316303Sjkim * you this software, covering your right to use that party's intellectual 19316303Sjkim * property rights. 20316303Sjkim * 21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an 23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered 26316303Sjkim * Code in any form, with the right to sublicense such rights; and 27316303Sjkim * 28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29316303Sjkim * license (with the right to sublicense), under only those claims of Intel 30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof 32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright 33316303Sjkim * license, and in no event shall the patent license extend to any additions 34316303Sjkim * to or modifications of the Original Intel Code. No other license or right 35316303Sjkim * is granted directly or by implication, estoppel or otherwise; 36316303Sjkim * 37316303Sjkim * The above copyright and patent license is granted only if the following 38316303Sjkim * conditions are met: 39316303Sjkim * 40316303Sjkim * 3. Conditions 41316303Sjkim * 42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43316303Sjkim * Redistribution of source code of any substantial portion of the Covered 44316303Sjkim * Code or modification with rights to further distribute source must include 45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions, 46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered 49316303Sjkim * Code and the date of any change. Licensee must include in that file the 50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 51316303Sjkim * must include a prominent statement that the modification is derived, 52316303Sjkim * directly or indirectly, from Original Intel Code. 53316303Sjkim * 54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55316303Sjkim * Redistribution of source code of any substantial portion of the Covered 56316303Sjkim * Code or modification without rights to further distribute source must 57316303Sjkim * include the following Disclaimer and Export Compliance provision in the 58316303Sjkim * documentation and/or other materials provided with distribution. In 59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any 60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the 61316303Sjkim * license from Licensee to its licensee is limited to the intellectual 62316303Sjkim * property embodied in the software Licensee provides to its licensee, and 63316303Sjkim * not to intellectual property embodied in modifications its licensee may 64316303Sjkim * make. 65316303Sjkim * 66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the 68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 69316303Sjkim * provision in the documentation and/or other materials provided with the 70316303Sjkim * distribution. 71316303Sjkim * 72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 73316303Sjkim * Intel Code. 74316303Sjkim * 75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 77316303Sjkim * other dealings in products derived from or relating to the Covered Code 78316303Sjkim * without prior written authorization from Intel. 79316303Sjkim * 80316303Sjkim * 4. Disclaimer and Export Compliance 81316303Sjkim * 82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88316303Sjkim * PARTICULAR PURPOSE. 89316303Sjkim * 90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97316303Sjkim * LIMITED REMEDY. 98316303Sjkim * 99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100316303Sjkim * software or system incorporating such software without first obtaining any 101316303Sjkim * required license or other approval from the U. S. Department of Commerce or 102316303Sjkim * any other agency or department of the United States Government. In the 103316303Sjkim * event Licensee exports any such software from the United States or 104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall 105316303Sjkim * ensure that the distribution and export/re-export of the software is in 106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process, 109316303Sjkim * software, or service, directly or indirectly, to any country for which the 110316303Sjkim * United States government or any agency thereof requires an export license, 111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining 112316303Sjkim * such license, approval or letter. 113316303Sjkim * 114316303Sjkim ***************************************************************************** 115316303Sjkim * 116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 117316303Sjkim * following license: 118316303Sjkim * 119272286Sjkim * Redistribution and use in source and binary forms, with or without 120272286Sjkim * modification, are permitted provided that the following conditions 121272286Sjkim * are met: 122272286Sjkim * 1. Redistributions of source code must retain the above copyright 123272286Sjkim * notice, this list of conditions, and the following disclaimer, 124272286Sjkim * without modification. 125272286Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126272286Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 127272286Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 128272286Sjkim * including a substantially similar Disclaimer requirement for further 129272286Sjkim * binary redistribution. 130272286Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 131272286Sjkim * of any contributors may be used to endorse or promote products derived 132272286Sjkim * from this software without specific prior written permission. 133272286Sjkim * 134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145316303Sjkim * 146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 147272286Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 148272286Sjkim * Software Foundation. 149272286Sjkim * 150316303Sjkim *****************************************************************************/ 151272286Sjkim 152272444Sjkim#include <contrib/dev/acpica/include/acpi.h> 153272444Sjkim#include <contrib/dev/acpica/include/accommon.h> 154272444Sjkim#include <contrib/dev/acpica/include/acapps.h> 155272444Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h> 156272286Sjkim 157272286Sjkim/* This module used for application-level code only */ 158272286Sjkim 159272286Sjkim#define _COMPONENT ACPI_COMPILER 160272286Sjkim ACPI_MODULE_NAME ("aslmapenter") 161272286Sjkim 162272286Sjkim/* Local prototypes */ 163272286Sjkim 164272286Sjkimstatic ACPI_GPIO_INFO * 165272286SjkimMpCreateGpioInfo ( 166272286Sjkim UINT16 PinNumber, 167272286Sjkim char *DeviceName); 168272286Sjkim 169272286Sjkimstatic ACPI_SERIAL_INFO * 170272286SjkimMpCreateSerialInfo ( 171272286Sjkim char *DeviceName, 172272286Sjkim UINT16 Address); 173272286Sjkim 174272286Sjkim 175272286Sjkim/******************************************************************************* 176272286Sjkim * 177272286Sjkim * FUNCTION: MpSaveGpioInfo 178272286Sjkim * 179272286Sjkim * PARAMETERS: Resource - GPIO resource descriptor 180272286Sjkim * PinCount - From GPIO descriptor 181272286Sjkim * PinList - From GPIO descriptor 182272286Sjkim * DeviceName - The "ResourceSource" name 183272286Sjkim * 184272286Sjkim * RETURN: None 185272286Sjkim * 186272286Sjkim * DESCRIPTION: External Interface. 187272286Sjkim * Save GPIO resource descriptor information. 188272286Sjkim * Creates new GPIO info blocks, one for each pin defined by the 189272286Sjkim * GPIO descriptor. 190272286Sjkim * 191272286Sjkim ******************************************************************************/ 192272286Sjkim 193272286Sjkimvoid 194272286SjkimMpSaveGpioInfo ( 195272286Sjkim ACPI_PARSE_OBJECT *Op, 196272286Sjkim AML_RESOURCE *Resource, 197272286Sjkim UINT32 PinCount, 198272286Sjkim UINT16 *PinList, 199272286Sjkim char *DeviceName) 200272286Sjkim{ 201272286Sjkim ACPI_GPIO_INFO *Info; 202272286Sjkim UINT32 i; 203272286Sjkim 204272286Sjkim 205272286Sjkim /* Mapfile option enabled? */ 206272286Sjkim 207272286Sjkim if (!Gbl_MapfileFlag) 208272286Sjkim { 209272286Sjkim return; 210272286Sjkim } 211272286Sjkim 212272286Sjkim /* Create an info block for each pin defined in the descriptor */ 213272286Sjkim 214272286Sjkim for (i = 0; i < PinCount; i++) 215272286Sjkim { 216272286Sjkim Info = MpCreateGpioInfo (PinList[i], DeviceName); 217272286Sjkim 218272286Sjkim Info->Op = Op; 219272286Sjkim Info->DeviceName = DeviceName; 220272286Sjkim Info->PinCount = PinCount; 221272286Sjkim Info->PinIndex = i; 222272286Sjkim Info->PinNumber = PinList[i]; 223272286Sjkim Info->Type = Resource->Gpio.ConnectionType; 224272286Sjkim Info->Direction = (UINT8) (Resource->Gpio.IntFlags & 0x0003); /* _IOR, for IO descriptor */ 225272286Sjkim Info->Polarity = (UINT8) ((Resource->Gpio.IntFlags >> 1) & 0x0003); /* _POL, for INT descriptor */ 226272286Sjkim } 227272286Sjkim} 228272286Sjkim 229272286Sjkim 230272286Sjkim/******************************************************************************* 231272286Sjkim * 232272286Sjkim * FUNCTION: MpSaveSerialInfo 233272286Sjkim * 234272286Sjkim * PARAMETERS: Resource - A Serial resource descriptor 235272286Sjkim * DeviceName - The "ResourceSource" name. 236272286Sjkim * 237272286Sjkim * RETURN: None 238272286Sjkim * 239272286Sjkim * DESCRIPTION: External Interface. 240272286Sjkim * Save serial resource descriptor information. 241272286Sjkim * Creates a new serial info block. 242272286Sjkim * 243272286Sjkim ******************************************************************************/ 244272286Sjkim 245272286Sjkimvoid 246272286SjkimMpSaveSerialInfo ( 247272286Sjkim ACPI_PARSE_OBJECT *Op, 248272286Sjkim AML_RESOURCE *Resource, 249272286Sjkim char *DeviceName) 250272286Sjkim{ 251272286Sjkim ACPI_SERIAL_INFO *Info; 252272286Sjkim UINT16 Address; 253272286Sjkim UINT32 Speed; 254272286Sjkim 255272286Sjkim 256272286Sjkim /* Mapfile option enabled? */ 257272286Sjkim 258272286Sjkim if (!Gbl_MapfileFlag) 259272286Sjkim { 260272286Sjkim return; 261272286Sjkim } 262272286Sjkim 263272286Sjkim if (Resource->DescriptorType != ACPI_RESOURCE_NAME_SERIAL_BUS) 264272286Sjkim { 265272286Sjkim return; 266272286Sjkim } 267272286Sjkim 268272286Sjkim /* Extract address and speed from the resource descriptor */ 269272286Sjkim 270272286Sjkim switch (Resource->CommonSerialBus.Type) 271272286Sjkim { 272272286Sjkim case AML_RESOURCE_I2C_SERIALBUSTYPE: 273272286Sjkim 274272286Sjkim Address = Resource->I2cSerialBus.SlaveAddress; 275272286Sjkim Speed = Resource->I2cSerialBus.ConnectionSpeed; 276272286Sjkim break; 277272286Sjkim 278272286Sjkim case AML_RESOURCE_SPI_SERIALBUSTYPE: 279272286Sjkim 280272286Sjkim Address = Resource->SpiSerialBus.DeviceSelection; 281272286Sjkim Speed = Resource->SpiSerialBus.ConnectionSpeed; 282272286Sjkim break; 283272286Sjkim 284272286Sjkim case AML_RESOURCE_UART_SERIALBUSTYPE: 285272286Sjkim 286272286Sjkim Address = 0; 287272286Sjkim Speed = Resource->UartSerialBus.DefaultBaudRate; 288272286Sjkim break; 289272286Sjkim 290272286Sjkim default: /* Invalid bus subtype */ 291272286Sjkim return; 292272286Sjkim } 293272286Sjkim 294272286Sjkim Info = MpCreateSerialInfo (DeviceName, Address); 295272286Sjkim 296272286Sjkim Info->Op = Op; 297272286Sjkim Info->DeviceName = DeviceName; 298272286Sjkim Info->Resource = Resource; 299272286Sjkim Info->Address = Address; 300272286Sjkim Info->Speed = Speed; 301272286Sjkim} 302272286Sjkim 303272286Sjkim 304272286Sjkim/******************************************************************************* 305272286Sjkim * 306272286Sjkim * FUNCTION: MpCreateGpioInfo 307272286Sjkim * 308272286Sjkim * PARAMETERS: PinNumber - GPIO pin number 309272286Sjkim * DeviceName - The "ResourceSource" name 310272286Sjkim * 311272286Sjkim * RETURN: New GPIO info block. 312272286Sjkim * 313272286Sjkim * DESCRIPTION: Create a new GPIO info block and place it on the global list. 314272286Sjkim * The list is sorted by GPIO device names first, and pin numbers 315272286Sjkim * secondarily. 316272286Sjkim * 317272286Sjkim ******************************************************************************/ 318272286Sjkim 319272286Sjkimstatic ACPI_GPIO_INFO * 320272286SjkimMpCreateGpioInfo ( 321272286Sjkim UINT16 PinNumber, 322272286Sjkim char *DeviceName) 323272286Sjkim{ 324272286Sjkim ACPI_GPIO_INFO *Info; 325272286Sjkim ACPI_GPIO_INFO *NextGpio; 326272286Sjkim ACPI_GPIO_INFO *PrevGpio; 327281396Sjkim char *Buffer; 328272286Sjkim 329272286Sjkim 330272286Sjkim /* 331272286Sjkim * Allocate a new info block and insert it into the global GPIO list 332272286Sjkim * sorted by both source device name and then the pin number. There is 333272286Sjkim * one block per pin. 334272286Sjkim */ 335327557Sjkim Buffer = UtLocalCacheCalloc (sizeof (ACPI_GPIO_INFO)); 336281396Sjkim Info = ACPI_CAST_PTR (ACPI_GPIO_INFO, Buffer); 337272286Sjkim 338272286Sjkim NextGpio = Gbl_GpioList; 339272286Sjkim PrevGpio = NULL; 340272286Sjkim if (!Gbl_GpioList) 341272286Sjkim { 342272286Sjkim Gbl_GpioList = Info; 343272286Sjkim Info->Next = NULL; 344272286Sjkim return (Info); 345272286Sjkim } 346272286Sjkim 347272286Sjkim /* Sort on source DeviceName first */ 348272286Sjkim 349272286Sjkim while (NextGpio && 350298714Sjkim (strcmp (DeviceName, NextGpio->DeviceName) > 0)) 351272286Sjkim { 352272286Sjkim PrevGpio = NextGpio; 353272286Sjkim NextGpio = NextGpio->Next; 354272286Sjkim } 355272286Sjkim 356272286Sjkim /* Now sort on the PinNumber */ 357272286Sjkim 358272286Sjkim while (NextGpio && 359298714Sjkim (NextGpio->PinNumber < PinNumber) && 360298714Sjkim !strcmp (DeviceName, NextGpio->DeviceName)) 361272286Sjkim { 362272286Sjkim PrevGpio = NextGpio; 363272286Sjkim NextGpio = NextGpio->Next; 364272286Sjkim } 365272286Sjkim 366272286Sjkim /* Finish the list insertion */ 367272286Sjkim 368272286Sjkim if (PrevGpio) 369272286Sjkim { 370272286Sjkim PrevGpio->Next = Info; 371272286Sjkim } 372272286Sjkim else 373272286Sjkim { 374272286Sjkim Gbl_GpioList = Info; 375272286Sjkim } 376272286Sjkim 377272286Sjkim Info->Next = NextGpio; 378272286Sjkim return (Info); 379272286Sjkim} 380272286Sjkim 381272286Sjkim 382272286Sjkim/******************************************************************************* 383272286Sjkim * 384272286Sjkim * FUNCTION: MpCreateSerialInfo 385272286Sjkim * 386272286Sjkim * PARAMETERS: DeviceName - The "ResourceSource" name. 387272286Sjkim * Address - Physical address for the device 388272286Sjkim * 389272286Sjkim * RETURN: New Serial info block. 390272286Sjkim * 391272286Sjkim * DESCRIPTION: Create a new Serial info block and place it on the global list. 392272286Sjkim * The list is sorted by Serial device names first, and addresses 393272286Sjkim * secondarily. 394272286Sjkim * 395272286Sjkim ******************************************************************************/ 396272286Sjkim 397272286Sjkimstatic ACPI_SERIAL_INFO * 398272286SjkimMpCreateSerialInfo ( 399272286Sjkim char *DeviceName, 400272286Sjkim UINT16 Address) 401272286Sjkim{ 402272286Sjkim ACPI_SERIAL_INFO *Info; 403272286Sjkim ACPI_SERIAL_INFO *NextSerial; 404272286Sjkim ACPI_SERIAL_INFO *PrevSerial; 405281396Sjkim char *Buffer; 406272286Sjkim 407272286Sjkim 408272286Sjkim /* 409272286Sjkim * Allocate a new info block and insert it into the global Serial list 410272286Sjkim * sorted by both source device name and then the address. 411272286Sjkim */ 412327557Sjkim Buffer = UtLocalCacheCalloc (sizeof (ACPI_SERIAL_INFO)); 413281396Sjkim Info = ACPI_CAST_PTR (ACPI_SERIAL_INFO, Buffer); 414272286Sjkim 415272286Sjkim NextSerial = Gbl_SerialList; 416272286Sjkim PrevSerial = NULL; 417272286Sjkim if (!Gbl_SerialList) 418272286Sjkim { 419272286Sjkim Gbl_SerialList = Info; 420272286Sjkim Info->Next = NULL; 421272286Sjkim return (Info); 422272286Sjkim } 423272286Sjkim 424272286Sjkim /* Sort on source DeviceName */ 425272286Sjkim 426272286Sjkim while (NextSerial && 427284583Sjkim (strcmp (DeviceName, NextSerial->DeviceName) > 0)) 428272286Sjkim { 429272286Sjkim PrevSerial = NextSerial; 430272286Sjkim NextSerial = NextSerial->Next; 431272286Sjkim } 432272286Sjkim 433272286Sjkim /* Now sort on the Address */ 434272286Sjkim 435272286Sjkim while (NextSerial && 436272286Sjkim (NextSerial->Address < Address) && 437284583Sjkim !strcmp (DeviceName, NextSerial->DeviceName)) 438272286Sjkim { 439272286Sjkim PrevSerial = NextSerial; 440272286Sjkim NextSerial = NextSerial->Next; 441272286Sjkim } 442272286Sjkim 443272286Sjkim /* Finish the list insertion */ 444272286Sjkim 445272286Sjkim if (PrevSerial) 446272286Sjkim { 447272286Sjkim PrevSerial->Next = Info; 448272286Sjkim } 449272286Sjkim else 450272286Sjkim { 451272286Sjkim Gbl_SerialList = Info; 452272286Sjkim } 453272286Sjkim 454272286Sjkim Info->Next = NextSerial; 455272286Sjkim return (Info); 456272286Sjkim} 457