/** @file

  Multiple APIC Description Table (MADT)

  Copyright (c) 2017, Linaro Ltd. All rights reserved.<BR>
  Copyright (C) 2018, Marvell International Ltd. and its affiliates.<BR>

  SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <Library/AcpiLib.h>

#include "AcpiHeader.h"

// active low, level triggered
#define GTDT_GTIMER_FLAGS  EFI_ACPI_6_0_GTDT_TIMER_FLAG_ALWAYS_ON_CAPABILITY

// active high, level triggered
#define GTDT_WDG_FLAGS     0x0

#pragma pack(1)
typedef struct {
  EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLE        Header;
  EFI_ACPI_6_0_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE   SbsaWatchdog;
} ACPI_6_0_GTDT_STRUCTURE;
#pragma pack()

ACPI_6_0_GTDT_STRUCTURE Gtdt = {
  {
    __ACPI_HEADER (EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE,
                   ACPI_6_0_GTDT_STRUCTURE,
                   EFI_ACPI_6_0_GENERIC_TIMER_DESCRIPTION_TABLE_REVISION),
    0xFFFFFFFFFFFFFFFF,                             // UINT64  PhysicalAddress
    0,                                              // UINT32  Reserved
    FixedPcdGet32 (PcdArmArchTimerSecIntrNum),      // UINT32  SecureEL1TimerGSIV
    GTDT_GTIMER_FLAGS,                              // UINT32  SecureEL1TimerFlags
    FixedPcdGet32 (PcdArmArchTimerIntrNum),         // UINT32  NonSecureEL1TimerGSIV
    GTDT_GTIMER_FLAGS,                              // UINT32  NonSecureEL1TimerFlags
    FixedPcdGet32 (PcdArmArchTimerVirtIntrNum),     // UINT32  VirtualTimerGSIV
    GTDT_GTIMER_FLAGS,                              // UINT32  VirtualTimerFlags
    FixedPcdGet32 (PcdArmArchTimerHypIntrNum),      // UINT32  NonSecureEL2TimerGSIV
    GTDT_GTIMER_FLAGS,                              // UINT32  NonSecureEL2TimerFlags
    0xFFFFFFFFFFFFFFFF,                             // UINT64  CntReadBaseAddress
    0x1,                                            // UINT32  PlatformTimerCount
    sizeof (Gtdt.Header)                            // UINT32  PlatformTimerOffset
  }, {
    EFI_ACPI_6_0_GTDT_SBSA_GENERIC_WATCHDOG,        // UINT8   Type
    sizeof (Gtdt.SbsaWatchdog),                     // UINT16  Length
    0x0,                                            // UINT8   Reserved
    FixedPcdGet64 (PcdGenericWatchdogRefreshBase),  // UINT64  RefreshFramePhysicalAddress
    FixedPcdGet64 (PcdGenericWatchdogControlBase),  // UINT64  WatchdogControlFramePhysicalAddress
    FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum),   // UINT32  WatchdogTimerGSIV
    GTDT_WDG_FLAGS                                  // UINT32  WatchdogTimerFlags
  },
};

VOID CONST * CONST ReferenceAcpiTable = &Gtdt;
