2015-07-28 22:45:36 +02:00
|
|
|
/** @file
|
|
|
|
ArmGicArchLib library class implementation for DT based virt platforms
|
|
|
|
|
2016-04-08 11:44:51 +02:00
|
|
|
Copyright (c) 2015 - 2016, Linaro Ltd. All rights reserved.<BR>
|
2015-07-28 22:45:36 +02:00
|
|
|
|
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <Base.h>
|
2016-04-08 11:44:51 +02:00
|
|
|
#include <Uefi.h>
|
2015-07-28 22:45:36 +02:00
|
|
|
|
|
|
|
#include <Library/ArmGicLib.h>
|
|
|
|
#include <Library/ArmGicArchLib.h>
|
2016-04-08 11:44:51 +02:00
|
|
|
#include <Library/BaseLib.h>
|
2015-07-28 22:45:36 +02:00
|
|
|
#include <Library/DebugLib.h>
|
2016-04-08 11:44:51 +02:00
|
|
|
#include <Library/PcdLib.h>
|
|
|
|
#include <Library/UefiBootServicesTableLib.h>
|
|
|
|
|
|
|
|
#include <Protocol/FdtClient.h>
|
2015-07-28 22:45:36 +02:00
|
|
|
|
|
|
|
STATIC ARM_GIC_ARCH_REVISION mGicArchRevision;
|
|
|
|
|
|
|
|
RETURN_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ArmVirtGicArchLibConstructor (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2016-04-08 11:44:51 +02:00
|
|
|
UINT32 IccSre;
|
|
|
|
FDT_CLIENT_PROTOCOL *FdtClient;
|
|
|
|
CONST UINT64 *Reg;
|
2016-09-15 15:15:14 +02:00
|
|
|
UINT32 RegSize;
|
|
|
|
UINTN AddressCells, SizeCells;
|
2016-04-08 11:44:51 +02:00
|
|
|
UINTN GicRevision;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT64 DistBase, CpuBase, RedistBase;
|
2016-10-21 11:59:36 +02:00
|
|
|
RETURN_STATUS PcdStatus;
|
2015-07-28 22:45:36 +02:00
|
|
|
|
2016-04-08 11:44:51 +02:00
|
|
|
Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,
|
|
|
|
(VOID **)&FdtClient);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
GicRevision = 2;
|
|
|
|
Status = FdtClient->FindCompatibleNodeReg (FdtClient, "arm,cortex-a15-gic",
|
2016-09-15 15:15:14 +02:00
|
|
|
(CONST VOID **)&Reg, &AddressCells, &SizeCells,
|
|
|
|
&RegSize);
|
2016-04-08 11:44:51 +02:00
|
|
|
if (Status == EFI_NOT_FOUND) {
|
|
|
|
GicRevision = 3;
|
|
|
|
Status = FdtClient->FindCompatibleNodeReg (FdtClient, "arm,gic-v3",
|
2016-09-15 15:15:14 +02:00
|
|
|
(CONST VOID **)&Reg, &AddressCells, &SizeCells,
|
|
|
|
&RegSize);
|
2016-04-08 11:44:51 +02:00
|
|
|
}
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (GicRevision) {
|
2015-07-28 22:45:36 +02:00
|
|
|
|
|
|
|
case 3:
|
2016-04-08 11:44:51 +02:00
|
|
|
//
|
|
|
|
// The GIC v3 DT binding describes a series of at least 3 physical (base
|
|
|
|
// addresses, size) pairs: the distributor interface (GICD), at least one
|
|
|
|
// redistributor region (GICR) containing dedicated redistributor
|
|
|
|
// interfaces for all individual CPUs, and the CPU interface (GICC).
|
|
|
|
// Under virtualization, we assume that the first redistributor region
|
|
|
|
// listed covers the boot CPU. Also, our GICv3 driver only supports the
|
|
|
|
// system register CPU interface, so we can safely ignore the MMIO version
|
|
|
|
// which is listed after the sequence of redistributor interfaces.
|
|
|
|
// This means we are only interested in the first two memory regions
|
|
|
|
// supplied, and ignore everything else.
|
|
|
|
//
|
|
|
|
ASSERT (RegSize >= 32);
|
|
|
|
|
|
|
|
// RegProp[0..1] == { GICD base, GICD size }
|
|
|
|
DistBase = SwapBytes64 (Reg[0]);
|
2016-10-21 07:50:24 +02:00
|
|
|
ASSERT (DistBase < MAX_UINTN);
|
2016-04-08 11:44:51 +02:00
|
|
|
|
|
|
|
// RegProp[2..3] == { GICR base, GICR size }
|
|
|
|
RedistBase = SwapBytes64 (Reg[2]);
|
2016-10-21 07:50:24 +02:00
|
|
|
ASSERT (RedistBase < MAX_UINTN);
|
2016-04-08 11:44:51 +02:00
|
|
|
|
2016-10-21 11:59:36 +02:00
|
|
|
PcdStatus = PcdSet64S (PcdGicDistributorBase, DistBase);
|
|
|
|
ASSERT_RETURN_ERROR (PcdStatus);
|
|
|
|
PcdStatus = PcdSet64S (PcdGicRedistributorsBase, RedistBase);
|
|
|
|
ASSERT_RETURN_ERROR (PcdStatus);
|
2016-04-08 11:44:51 +02:00
|
|
|
|
|
|
|
DEBUG ((EFI_D_INFO, "Found GIC v3 (re)distributor @ 0x%Lx (0x%Lx)\n",
|
|
|
|
DistBase, RedistBase));
|
|
|
|
|
2015-07-28 22:45:36 +02:00
|
|
|
//
|
|
|
|
// The default implementation of ArmGicArchLib is responsible for enabling
|
|
|
|
// the system register interface on the GICv3 if one is found. So let's do
|
|
|
|
// the same here.
|
|
|
|
//
|
|
|
|
IccSre = ArmGicV3GetControlSystemRegisterEnable ();
|
|
|
|
if (!(IccSre & ICC_SRE_EL2_SRE)) {
|
|
|
|
ArmGicV3SetControlSystemRegisterEnable (IccSre | ICC_SRE_EL2_SRE);
|
|
|
|
IccSre = ArmGicV3GetControlSystemRegisterEnable ();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Unlike the default implementation, there is no fall through to GICv2
|
|
|
|
// mode if this GICv3 cannot be driven in native mode due to the fact
|
|
|
|
// that the System Register interface is unavailable.
|
|
|
|
//
|
|
|
|
ASSERT (IccSre & ICC_SRE_EL2_SRE);
|
|
|
|
|
|
|
|
mGicArchRevision = ARM_GIC_ARCH_REVISION_3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2016-04-08 11:44:51 +02:00
|
|
|
ASSERT (RegSize == 32);
|
|
|
|
|
|
|
|
DistBase = SwapBytes64 (Reg[0]);
|
|
|
|
CpuBase = SwapBytes64 (Reg[2]);
|
2016-10-21 07:50:24 +02:00
|
|
|
ASSERT (DistBase < MAX_UINTN);
|
|
|
|
ASSERT (CpuBase < MAX_UINTN);
|
2016-04-08 11:44:51 +02:00
|
|
|
|
2016-10-21 11:59:36 +02:00
|
|
|
PcdStatus = PcdSet64S (PcdGicDistributorBase, DistBase);
|
|
|
|
ASSERT_RETURN_ERROR (PcdStatus);
|
|
|
|
PcdStatus = PcdSet64S (PcdGicInterruptInterfaceBase, CpuBase);
|
|
|
|
ASSERT_RETURN_ERROR (PcdStatus);
|
2016-04-08 11:44:51 +02:00
|
|
|
|
|
|
|
DEBUG ((EFI_D_INFO, "Found GIC @ 0x%Lx/0x%Lx\n", DistBase, CpuBase));
|
|
|
|
|
2015-07-28 22:45:36 +02:00
|
|
|
mGicArchRevision = ARM_GIC_ARCH_REVISION_2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG ((EFI_D_ERROR, "%a: No GIC revision specified!\n", __FUNCTION__));
|
|
|
|
return RETURN_NOT_FOUND;
|
|
|
|
}
|
|
|
|
return RETURN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ARM_GIC_ARCH_REVISION
|
|
|
|
EFIAPI
|
|
|
|
ArmGicGetSupportedArchRevision (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return mGicArchRevision;
|
|
|
|
}
|