1 /*******************************************************************************
   2  *
   3  * Module Name: rsaddr - Address resource descriptors (16/32/64)
   4  *
   5  ******************************************************************************/
   6 
   7 /*
   8  * Copyright (C) 2000 - 2013, 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 #define __RSADDR_C__
  45 
  46 #include "acpi.h"
  47 #include "accommon.h"
  48 #include "acresrc.h"
  49 
  50 #define _COMPONENT          ACPI_RESOURCES
  51         ACPI_MODULE_NAME    ("rsaddr")
  52 
  53 
  54 /*******************************************************************************
  55  *
  56  * AcpiRsConvertAddress16 - All WORD (16-bit) address resources
  57  *
  58  ******************************************************************************/
  59 
  60 ACPI_RSCONVERT_INFO     AcpiRsConvertAddress16[5] =
  61 {
  62     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_ADDRESS16,
  63                         ACPI_RS_SIZE (ACPI_RESOURCE_ADDRESS16),
  64                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertAddress16)},
  65 
  66     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_ADDRESS16,
  67                         sizeof (AML_RESOURCE_ADDRESS16),
  68                         0},
  69 
  70     /* Resource Type, General Flags, and Type-Specific Flags */
  71 
  72     {ACPI_RSC_ADDRESS,  0, 0, 0},
  73 
  74     /*
  75      * These fields are contiguous in both the source and destination:
  76      * Address Granularity
  77      * Address Range Minimum
  78      * Address Range Maximum
  79      * Address Translation Offset
  80      * Address Length
  81      */
  82     {ACPI_RSC_MOVE16,   ACPI_RS_OFFSET (Data.Address16.Granularity),
  83                         AML_OFFSET (Address16.Granularity),
  84                         5},
  85 
  86     /* Optional ResourceSource (Index and String) */
  87 
  88     {ACPI_RSC_SOURCE,   ACPI_RS_OFFSET (Data.Address16.ResourceSource),
  89                         0,
  90                         sizeof (AML_RESOURCE_ADDRESS16)}
  91 };
  92 
  93 
  94 /*******************************************************************************
  95  *
  96  * AcpiRsConvertAddress32 - All DWORD (32-bit) address resources
  97  *
  98  ******************************************************************************/
  99 
 100 ACPI_RSCONVERT_INFO     AcpiRsConvertAddress32[5] =
 101 {
 102     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_ADDRESS32,
 103                         ACPI_RS_SIZE (ACPI_RESOURCE_ADDRESS32),
 104                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertAddress32)},
 105 
 106     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_ADDRESS32,
 107                         sizeof (AML_RESOURCE_ADDRESS32),
 108                         0},
 109 
 110     /* Resource Type, General Flags, and Type-Specific Flags */
 111 
 112     {ACPI_RSC_ADDRESS,  0, 0, 0},
 113 
 114     /*
 115      * These fields are contiguous in both the source and destination:
 116      * Address Granularity
 117      * Address Range Minimum
 118      * Address Range Maximum
 119      * Address Translation Offset
 120      * Address Length
 121      */
 122     {ACPI_RSC_MOVE32,   ACPI_RS_OFFSET (Data.Address32.Granularity),
 123                         AML_OFFSET (Address32.Granularity),
 124                         5},
 125 
 126     /* Optional ResourceSource (Index and String) */
 127 
 128     {ACPI_RSC_SOURCE,   ACPI_RS_OFFSET (Data.Address32.ResourceSource),
 129                         0,
 130                         sizeof (AML_RESOURCE_ADDRESS32)}
 131 };
 132 
 133 
 134 /*******************************************************************************
 135  *
 136  * AcpiRsConvertAddress64 - All QWORD (64-bit) address resources
 137  *
 138  ******************************************************************************/
 139 
 140 ACPI_RSCONVERT_INFO     AcpiRsConvertAddress64[5] =
 141 {
 142     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_ADDRESS64,
 143                         ACPI_RS_SIZE (ACPI_RESOURCE_ADDRESS64),
 144                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertAddress64)},
 145 
 146     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_ADDRESS64,
 147                         sizeof (AML_RESOURCE_ADDRESS64),
 148                         0},
 149 
 150     /* Resource Type, General Flags, and Type-Specific Flags */
 151 
 152     {ACPI_RSC_ADDRESS,  0, 0, 0},
 153 
 154     /*
 155      * These fields are contiguous in both the source and destination:
 156      * Address Granularity
 157      * Address Range Minimum
 158      * Address Range Maximum
 159      * Address Translation Offset
 160      * Address Length
 161      */
 162     {ACPI_RSC_MOVE64,   ACPI_RS_OFFSET (Data.Address64.Granularity),
 163                         AML_OFFSET (Address64.Granularity),
 164                         5},
 165 
 166     /* Optional ResourceSource (Index and String) */
 167 
 168     {ACPI_RSC_SOURCE,   ACPI_RS_OFFSET (Data.Address64.ResourceSource),
 169                         0,
 170                         sizeof (AML_RESOURCE_ADDRESS64)}
 171 };
 172 
 173 
 174 /*******************************************************************************
 175  *
 176  * AcpiRsConvertExtAddress64 - All Extended (64-bit) address resources
 177  *
 178  ******************************************************************************/
 179 
 180 ACPI_RSCONVERT_INFO     AcpiRsConvertExtAddress64[5] =
 181 {
 182     {ACPI_RSC_INITGET,  ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64,
 183                         ACPI_RS_SIZE (ACPI_RESOURCE_EXTENDED_ADDRESS64),
 184                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertExtAddress64)},
 185 
 186     {ACPI_RSC_INITSET,  ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64,
 187                         sizeof (AML_RESOURCE_EXTENDED_ADDRESS64),
 188                         0},
 189 
 190     /* Resource Type, General Flags, and Type-Specific Flags */
 191 
 192     {ACPI_RSC_ADDRESS,  0, 0, 0},
 193 
 194     /* Revision ID */
 195 
 196     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.ExtAddress64.RevisionID),
 197                         AML_OFFSET (ExtAddress64.RevisionID),
 198                         1},
 199     /*
 200      * These fields are contiguous in both the source and destination:
 201      * Address Granularity
 202      * Address Range Minimum
 203      * Address Range Maximum
 204      * Address Translation Offset
 205      * Address Length
 206      * Type-Specific Attribute
 207      */
 208     {ACPI_RSC_MOVE64,   ACPI_RS_OFFSET (Data.ExtAddress64.Granularity),
 209                         AML_OFFSET (ExtAddress64.Granularity),
 210                         6}
 211 };
 212 
 213 
 214 /*******************************************************************************
 215  *
 216  * AcpiRsConvertGeneralFlags - Flags common to all address descriptors
 217  *
 218  ******************************************************************************/
 219 
 220 static ACPI_RSCONVERT_INFO  AcpiRsConvertGeneralFlags[6] =
 221 {
 222     {ACPI_RSC_FLAGINIT, 0, AML_OFFSET (Address.Flags),
 223                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertGeneralFlags)},
 224 
 225     /* Resource Type (Memory, Io, BusNumber, etc.) */
 226 
 227     {ACPI_RSC_MOVE8,    ACPI_RS_OFFSET (Data.Address.ResourceType),
 228                         AML_OFFSET (Address.ResourceType),
 229                         1},
 230 
 231     /* General Flags - Consume, Decode, MinFixed, MaxFixed */
 232 
 233     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.ProducerConsumer),
 234                         AML_OFFSET (Address.Flags),
 235                         0},
 236 
 237     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.Decode),
 238                         AML_OFFSET (Address.Flags),
 239                         1},
 240 
 241     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.MinAddressFixed),
 242                         AML_OFFSET (Address.Flags),
 243                         2},
 244 
 245     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.MaxAddressFixed),
 246                         AML_OFFSET (Address.Flags),
 247                         3}
 248 };
 249 
 250 
 251 /*******************************************************************************
 252  *
 253  * AcpiRsConvertMemFlags - Flags common to Memory address descriptors
 254  *
 255  ******************************************************************************/
 256 
 257 static ACPI_RSCONVERT_INFO  AcpiRsConvertMemFlags[5] =
 258 {
 259     {ACPI_RSC_FLAGINIT, 0, AML_OFFSET (Address.SpecificFlags),
 260                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertMemFlags)},
 261 
 262     /* Memory-specific flags */
 263 
 264     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Mem.WriteProtect),
 265                         AML_OFFSET (Address.SpecificFlags),
 266                         0},
 267 
 268     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Mem.Caching),
 269                         AML_OFFSET (Address.SpecificFlags),
 270                         1},
 271 
 272     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Mem.RangeType),
 273                         AML_OFFSET (Address.SpecificFlags),
 274                         3},
 275 
 276     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Mem.Translation),
 277                         AML_OFFSET (Address.SpecificFlags),
 278                         5}
 279 };
 280 
 281 
 282 /*******************************************************************************
 283  *
 284  * AcpiRsConvertIoFlags - Flags common to I/O address descriptors
 285  *
 286  ******************************************************************************/
 287 
 288 static ACPI_RSCONVERT_INFO  AcpiRsConvertIoFlags[4] =
 289 {
 290     {ACPI_RSC_FLAGINIT, 0, AML_OFFSET (Address.SpecificFlags),
 291                         ACPI_RSC_TABLE_SIZE (AcpiRsConvertIoFlags)},
 292 
 293     /* I/O-specific flags */
 294 
 295     {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Io.RangeType),
 296                         AML_OFFSET (Address.SpecificFlags),
 297                         0},
 298 
 299     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Io.Translation),
 300                         AML_OFFSET (Address.SpecificFlags),
 301                         4},
 302 
 303     {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET (Data.Address.Info.Io.TranslationType),
 304                         AML_OFFSET (Address.SpecificFlags),
 305                         5}
 306 };
 307 
 308 
 309 /*******************************************************************************
 310  *
 311  * FUNCTION:    AcpiRsGetAddressCommon
 312  *
 313  * PARAMETERS:  Resource            - Pointer to the internal resource struct
 314  *              Aml                 - Pointer to the AML resource descriptor
 315  *
 316  * RETURN:      TRUE if the ResourceType field is OK, FALSE otherwise
 317  *
 318  * DESCRIPTION: Convert common flag fields from a raw AML resource descriptor
 319  *              to an internal resource descriptor
 320  *
 321  ******************************************************************************/
 322 
 323 BOOLEAN
 324 AcpiRsGetAddressCommon (
 325     ACPI_RESOURCE           *Resource,
 326     AML_RESOURCE            *Aml)
 327 {
 328     ACPI_FUNCTION_ENTRY ();
 329 
 330 
 331     /* Validate the Resource Type */
 332 
 333     if ((Aml->Address.ResourceType > 2) && (Aml->Address.ResourceType < 0xC0))
 334     {
 335         return (FALSE);
 336     }
 337 
 338     /* Get the Resource Type and General Flags */
 339 
 340     (void) AcpiRsConvertAmlToResource (Resource, Aml, AcpiRsConvertGeneralFlags);
 341 
 342     /* Get the Type-Specific Flags (Memory and I/O descriptors only) */
 343 
 344     if (Resource->Data.Address.ResourceType == ACPI_MEMORY_RANGE)
 345     {
 346         (void) AcpiRsConvertAmlToResource (Resource, Aml, AcpiRsConvertMemFlags);
 347     }
 348     else if (Resource->Data.Address.ResourceType == ACPI_IO_RANGE)
 349     {
 350         (void) AcpiRsConvertAmlToResource (Resource, Aml, AcpiRsConvertIoFlags);
 351     }
 352     else
 353     {
 354         /* Generic resource type, just grab the TypeSpecific byte */
 355 
 356         Resource->Data.Address.Info.TypeSpecific = Aml->Address.SpecificFlags;
 357     }
 358 
 359     return (TRUE);
 360 }
 361 
 362 
 363 /*******************************************************************************
 364  *
 365  * FUNCTION:    AcpiRsSetAddressCommon
 366  *
 367  * PARAMETERS:  Aml                 - Pointer to the AML resource descriptor
 368  *              Resource            - Pointer to the internal resource struct
 369  *
 370  * RETURN:      None
 371  *
 372  * DESCRIPTION: Convert common flag fields from a resource descriptor to an
 373  *              AML descriptor
 374  *
 375  ******************************************************************************/
 376 
 377 void
 378 AcpiRsSetAddressCommon (
 379     AML_RESOURCE            *Aml,
 380     ACPI_RESOURCE           *Resource)
 381 {
 382     ACPI_FUNCTION_ENTRY ();
 383 
 384 
 385     /* Set the Resource Type and General Flags */
 386 
 387     (void) AcpiRsConvertResourceToAml (Resource, Aml, AcpiRsConvertGeneralFlags);
 388 
 389     /* Set the Type-Specific Flags (Memory and I/O descriptors only) */
 390 
 391     if (Resource->Data.Address.ResourceType == ACPI_MEMORY_RANGE)
 392     {
 393         (void) AcpiRsConvertResourceToAml (Resource, Aml, AcpiRsConvertMemFlags);
 394     }
 395     else if (Resource->Data.Address.ResourceType == ACPI_IO_RANGE)
 396     {
 397         (void) AcpiRsConvertResourceToAml (Resource, Aml, AcpiRsConvertIoFlags);
 398     }
 399     else
 400     {
 401         /* Generic resource type, just copy the TypeSpecific byte */
 402 
 403         Aml->Address.SpecificFlags = Resource->Data.Address.Info.TypeSpecific;
 404     }
 405 }