/*
 * Copyright (c) 2016 Hisilicon Limited
 *. All rights reserved.
 * SPDX-License-Identifier: BSD-2-Clause-Patent
 *
 */

#include <IndustryStandard/Acpi.h>
#include "Hi1616Platform.h"

#define MCFG_VERSION  0x1

#pragma pack(1)
typedef struct
{
   UINT64 ullBaseAddress;
   UINT16 usSegGroupNum;
   UINT8  ucStartBusNum;
   UINT8  ucEndBusNum;
   UINT32 Reserved2;
}EFI_MCFG_CONFIG_STRUCTURE;

typedef struct
{
   EFI_ACPI_DESCRIPTION_HEADER Header;
   UINT64 Reserved1;
}EFI_MCFG_TABLE_CONFIG;

typedef struct
{
   EFI_MCFG_TABLE_CONFIG Acpi_Table_Mcfg;
   EFI_MCFG_CONFIG_STRUCTURE Config_Structure[8];
}EFI_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_TABLE;
#pragma pack()

EFI_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_TABLE Mcfg=
{
  {
      {
        EFI_ACPI_6_1_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE,
        sizeof (EFI_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_TABLE),
        MCFG_VERSION,
        0x00,                                                     // Checksum will be updated at runtime
        {EFI_ACPI_ARM_OEM_ID},
        EFI_ACPI_ARM_OEM_TABLE_ID,
        EFI_ACPI_ARM_OEM_REVISION,
        EFI_ACPI_ARM_CREATOR_ID,
        EFI_ACPI_ARM_CREATOR_REVISION
      },
      0x0000000000000000,                                 //Reserved
  },
  {
    //1p NA PCIe2
    {
      0xa0000000,                                         //Base Address
      0x2,                                                //Segment Group Number
      0xF8,                                               //Start Bus Number
      0xFF,                                               //End Bus Number
      0x00000000,                                         //Reserved
    },
    //1p NB PCIe0
    {
      0x8a0000000,                                        //Base Address
      0x4,                                                //Segment Group Number
      0x88,                                               //Start Bus Number
      0x8f,                                               //End Bus Number
      0x00000000,                                         //Reserved
    },
    //1p NB PCIe1
    {
      0x8b0000000,                                        //Base Address
      0x5,                                                //Segment Group Number
      0x78,                                                //Start Bus Number
      0x7F,                                                //End Bus Number
      0x00000000,                                         //Reserved
    },
    //1p NB PCIe2
    {
      0x8a0000000,                                        //Base Address
      0x6,                                                //Segment Group Number
      0xc0,                                               //Start Bus Number
      0xc7,                                               //End Bus Number
      0x00000000,                                         //Reserved
    },
    //1p NB PCIe3
    {
      0x8b0000000,                                        //Base Address
      0x7,                                                //Segment Group Number
      0x90,                                               //Start Bus Number
      0x97,                                               //End Bus Number
      0x00000000,                                         //Reserved
    },
    //2P NA PCIe2
    {
      0x64000000000,                                      //Base Address
      0xa,                                                //Segment Group Number
      0x10,                                               //Start Bus Number
      0x1f,                                               //End Bus Number
      0x00000000,                                         //Reserved
    },
    //2P NB PCIe0
    {
      0x74000000000,                                      //Base Address
      0xc,                                                //Segment Group Number
      0x20,                                               //Start Bus Number
      0x2f,                                               //End Bus Number
      0x00000000,                                         //Reserved
    },
    //2P NB PCIe1
    {
      0x78000000000,                                      //Base Address
      0xd,                                                //Segment Group Number
      0x30,                                               //Start Bus Number
      0x3f,                                               //End Bus Number
      0x00000000,                                         //Reserved
    },
  }
};

//
// Reference the table being generated to prevent the optimizer from removing the
// data structure from the executable
//
VOID* CONST ReferenceAcpiTable = &Mcfg;
