Home | History | Annotate | Line # | Download | only in compiler
aslmapenter.c revision 1.1
      1 /******************************************************************************
      2  *
      3  * Module Name: aslmapenter - Build resource descriptor/device maps
      4  *
      5  *****************************************************************************/
      6 
      7 /*
      8  * Copyright (C) 2000 - 2014, Intel Corp.
      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 
     44 #include "acpi.h"
     45 #include "accommon.h"
     46 #include "acapps.h"
     47 #include "aslcompiler.h"
     48 
     49 /* This module used for application-level code only */
     50 
     51 #define _COMPONENT          ACPI_COMPILER
     52         ACPI_MODULE_NAME    ("aslmapenter")
     53 
     54 /* Local prototypes */
     55 
     56 static ACPI_GPIO_INFO *
     57 MpCreateGpioInfo (
     58     UINT16                  PinNumber,
     59     char                    *DeviceName);
     60 
     61 static ACPI_SERIAL_INFO *
     62 MpCreateSerialInfo (
     63     char                    *DeviceName,
     64     UINT16                  Address);
     65 
     66 
     67 /*******************************************************************************
     68  *
     69  * FUNCTION:    MpSaveGpioInfo
     70  *
     71  * PARAMETERS:  Resource                - GPIO resource descriptor
     72  *              PinCount                - From GPIO descriptor
     73  *              PinList                 - From GPIO descriptor
     74  *              DeviceName              - The "ResourceSource" name
     75  *
     76  * RETURN:      None
     77  *
     78  * DESCRIPTION: External Interface.
     79  *              Save GPIO resource descriptor information.
     80  *              Creates new GPIO info blocks, one for each pin defined by the
     81  *              GPIO descriptor.
     82  *
     83  ******************************************************************************/
     84 
     85 void
     86 MpSaveGpioInfo (
     87     ACPI_PARSE_OBJECT       *Op,
     88     AML_RESOURCE            *Resource,
     89     UINT32                  PinCount,
     90     UINT16                  *PinList,
     91     char                    *DeviceName)
     92 {
     93     ACPI_GPIO_INFO          *Info;
     94     UINT32                  i;
     95 
     96 
     97     /* Mapfile option enabled? */
     98 
     99     if (!Gbl_MapfileFlag)
    100     {
    101         return;
    102     }
    103 
    104     /* Create an info block for each pin defined in the descriptor */
    105 
    106     for (i = 0; i < PinCount; i++)
    107     {
    108         Info = MpCreateGpioInfo (PinList[i], DeviceName);
    109 
    110         Info->Op = Op;
    111         Info->DeviceName = DeviceName;
    112         Info->PinCount = PinCount;
    113         Info->PinIndex = i;
    114         Info->PinNumber = PinList[i];
    115         Info->Type = Resource->Gpio.ConnectionType;
    116         Info->Direction = (UINT8) (Resource->Gpio.IntFlags & 0x0003);       /* _IOR, for IO descriptor */
    117         Info->Polarity = (UINT8) ((Resource->Gpio.IntFlags >> 1) & 0x0003); /* _POL, for INT descriptor */
    118     }
    119 }
    120 
    121 
    122 /*******************************************************************************
    123  *
    124  * FUNCTION:    MpSaveSerialInfo
    125  *
    126  * PARAMETERS:  Resource                - A Serial resource descriptor
    127  *              DeviceName              - The "ResourceSource" name.
    128  *
    129  * RETURN:      None
    130  *
    131  * DESCRIPTION: External Interface.
    132  *              Save serial resource descriptor information.
    133  *              Creates a new serial info block.
    134  *
    135  ******************************************************************************/
    136 
    137 void
    138 MpSaveSerialInfo (
    139     ACPI_PARSE_OBJECT       *Op,
    140     AML_RESOURCE            *Resource,
    141     char                    *DeviceName)
    142 {
    143     ACPI_SERIAL_INFO        *Info;
    144     UINT16                  Address;
    145     UINT32                  Speed;
    146 
    147 
    148     /* Mapfile option enabled? */
    149 
    150     if (!Gbl_MapfileFlag)
    151     {
    152         return;
    153     }
    154 
    155     if (Resource->DescriptorType != ACPI_RESOURCE_NAME_SERIAL_BUS)
    156     {
    157         return;
    158     }
    159 
    160     /* Extract address and speed from the resource descriptor */
    161 
    162     switch (Resource->CommonSerialBus.Type)
    163     {
    164     case AML_RESOURCE_I2C_SERIALBUSTYPE:
    165 
    166         Address = Resource->I2cSerialBus.SlaveAddress;
    167         Speed = Resource->I2cSerialBus.ConnectionSpeed;
    168         break;
    169 
    170     case AML_RESOURCE_SPI_SERIALBUSTYPE:
    171 
    172         Address = Resource->SpiSerialBus.DeviceSelection;
    173         Speed = Resource->SpiSerialBus.ConnectionSpeed;
    174         break;
    175 
    176     case AML_RESOURCE_UART_SERIALBUSTYPE:
    177 
    178         Address = 0;
    179         Speed = Resource->UartSerialBus.DefaultBaudRate;
    180         break;
    181 
    182     default:    /* Invalid bus subtype */
    183         return;
    184     }
    185 
    186     Info = MpCreateSerialInfo (DeviceName, Address);
    187 
    188     Info->Op = Op;
    189     Info->DeviceName = DeviceName;
    190     Info->Resource = Resource;
    191     Info->Address = Address;
    192     Info->Speed = Speed;
    193 }
    194 
    195 
    196 /*******************************************************************************
    197  *
    198  * FUNCTION:    MpCreateGpioInfo
    199  *
    200  * PARAMETERS:  PinNumber               - GPIO pin number
    201  *              DeviceName              - The "ResourceSource" name
    202  *
    203  * RETURN:      New GPIO info block.
    204  *
    205  * DESCRIPTION: Create a new GPIO info block and place it on the global list.
    206  *              The list is sorted by GPIO device names first, and pin numbers
    207  *              secondarily.
    208  *
    209  ******************************************************************************/
    210 
    211 static ACPI_GPIO_INFO *
    212 MpCreateGpioInfo (
    213     UINT16                  PinNumber,
    214     char                    *DeviceName)
    215 {
    216     ACPI_GPIO_INFO          *Info;
    217     ACPI_GPIO_INFO          *NextGpio;
    218     ACPI_GPIO_INFO          *PrevGpio;
    219 
    220 
    221     /*
    222      * Allocate a new info block and insert it into the global GPIO list
    223      * sorted by both source device name and then the pin number. There is
    224      * one block per pin.
    225      */
    226     Info = ACPI_CAST_PTR (ACPI_GPIO_INFO,
    227         UtStringCacheCalloc (sizeof (ACPI_GPIO_INFO)));
    228 
    229     NextGpio = Gbl_GpioList;
    230     PrevGpio = NULL;
    231     if (!Gbl_GpioList)
    232     {
    233         Gbl_GpioList = Info;
    234         Info->Next = NULL;
    235         return (Info);
    236     }
    237 
    238     /* Sort on source DeviceName first */
    239 
    240     while (NextGpio &&
    241             (ACPI_STRCMP (DeviceName, NextGpio->DeviceName) > 0))
    242     {
    243         PrevGpio = NextGpio;
    244         NextGpio = NextGpio->Next;
    245     }
    246 
    247     /* Now sort on the PinNumber */
    248 
    249     while (NextGpio &&
    250             (NextGpio->PinNumber < PinNumber) &&
    251             !ACPI_STRCMP (DeviceName, NextGpio->DeviceName))
    252     {
    253         PrevGpio = NextGpio;
    254         NextGpio = NextGpio->Next;
    255     }
    256 
    257     /* Finish the list insertion */
    258 
    259     if (PrevGpio)
    260     {
    261         PrevGpio->Next = Info;
    262     }
    263     else
    264     {
    265         Gbl_GpioList = Info;
    266     }
    267 
    268     Info->Next = NextGpio;
    269     return (Info);
    270 }
    271 
    272 
    273 /*******************************************************************************
    274  *
    275  * FUNCTION:    MpCreateSerialInfo
    276  *
    277  * PARAMETERS:  DeviceName              - The "ResourceSource" name.
    278  *              Address                 - Physical address for the device
    279  *
    280  * RETURN:      New Serial info block.
    281  *
    282  * DESCRIPTION: Create a new Serial info block and place it on the global list.
    283  *              The list is sorted by Serial device names first, and addresses
    284  *              secondarily.
    285  *
    286  ******************************************************************************/
    287 
    288 static ACPI_SERIAL_INFO *
    289 MpCreateSerialInfo (
    290     char                    *DeviceName,
    291     UINT16                  Address)
    292 {
    293     ACPI_SERIAL_INFO        *Info;
    294     ACPI_SERIAL_INFO        *NextSerial;
    295     ACPI_SERIAL_INFO        *PrevSerial;
    296 
    297 
    298     /*
    299      * Allocate a new info block and insert it into the global Serial list
    300      * sorted by both source device name and then the address.
    301      */
    302     Info = ACPI_CAST_PTR (ACPI_SERIAL_INFO,
    303         UtStringCacheCalloc (sizeof (ACPI_SERIAL_INFO)));
    304 
    305     NextSerial = Gbl_SerialList;
    306     PrevSerial = NULL;
    307     if (!Gbl_SerialList)
    308     {
    309         Gbl_SerialList = Info;
    310         Info->Next = NULL;
    311         return (Info);
    312     }
    313 
    314     /* Sort on source DeviceName */
    315 
    316     while (NextSerial &&
    317         (ACPI_STRCMP (DeviceName, NextSerial->DeviceName) > 0))
    318     {
    319         PrevSerial = NextSerial;
    320         NextSerial = NextSerial->Next;
    321     }
    322 
    323     /* Now sort on the Address */
    324 
    325     while (NextSerial &&
    326         (NextSerial->Address < Address) &&
    327         !ACPI_STRCMP (DeviceName, NextSerial->DeviceName))
    328     {
    329         PrevSerial = NextSerial;
    330         NextSerial = NextSerial->Next;
    331     }
    332 
    333     /* Finish the list insertion */
    334 
    335     if (PrevSerial)
    336     {
    337         PrevSerial->Next = Info;
    338     }
    339     else
    340     {
    341         Gbl_SerialList = Info;
    342     }
    343 
    344     Info->Next = NextSerial;
    345     return (Info);
    346 }
    347