2016-04-08 11:44:55 +02:00
|
|
|
/** @file
|
|
|
|
FDT client library for ARM's TimerDxe
|
|
|
|
|
|
|
|
Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
|
|
|
|
|
2019-04-04 01:03:23 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2016-04-08 11:44:55 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <Uefi.h>
|
|
|
|
|
|
|
|
#include <Library/BaseLib.h>
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/PcdLib.h>
|
|
|
|
#include <Library/UefiBootServicesTableLib.h>
|
|
|
|
|
|
|
|
#include <Protocol/FdtClient.h>
|
|
|
|
|
|
|
|
#pragma pack (1)
|
|
|
|
typedef struct {
|
|
|
|
UINT32 Type;
|
|
|
|
UINT32 Number;
|
|
|
|
UINT32 Flags;
|
|
|
|
} INTERRUPT_PROPERTY;
|
|
|
|
#pragma pack ()
|
|
|
|
|
|
|
|
RETURN_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ArmVirtTimerFdtClientLibConstructor (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
FDT_CLIENT_PROTOCOL *FdtClient;
|
|
|
|
CONST INTERRUPT_PROPERTY *InterruptProp;
|
|
|
|
UINT32 PropSize;
|
|
|
|
INT32 SecIntrNum, IntrNum, VirtIntrNum, HypIntrNum;
|
2023-09-19 12:20:25 +02:00
|
|
|
INT32 HypVirtIntrNum;
|
2016-10-21 11:59:36 +02:00
|
|
|
RETURN_STATUS PcdStatus;
|
2021-12-05 23:53:52 +01:00
|
|
|
|
2016-04-08 11:44:55 +02:00
|
|
|
Status = gBS->LocateProtocol (
|
|
|
|
&gFdtClientProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
(VOID **)&FdtClient
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
Status = FdtClient->FindCompatibleNodeProperty (
|
|
|
|
FdtClient,
|
|
|
|
"arm,armv7-timer",
|
|
|
|
"interrupts",
|
|
|
|
(CONST VOID **)&InterruptProp,
|
|
|
|
&PropSize
|
|
|
|
);
|
|
|
|
if (Status == EFI_NOT_FOUND) {
|
|
|
|
Status = FdtClient->FindCompatibleNodeProperty (
|
|
|
|
FdtClient,
|
|
|
|
"arm,armv8-timer",
|
|
|
|
"interrupts",
|
|
|
|
(CONST VOID **)&InterruptProp,
|
|
|
|
&PropSize
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2023-09-19 12:20:25 +02:00
|
|
|
// - interrupts : Interrupt list for secure, non-secure, virtual,
|
|
|
|
// hypervisor and hypervisor virtual timers, in that order.
|
2016-04-08 11:44:55 +02:00
|
|
|
//
|
2023-09-19 12:20:25 +02:00
|
|
|
ASSERT (PropSize >= 36);
|
2016-04-08 11:44:55 +02:00
|
|
|
|
|
|
|
SecIntrNum = SwapBytes32 (InterruptProp[0].Number)
|
|
|
|
+ (InterruptProp[0].Type ? 16 : 0);
|
|
|
|
IntrNum = SwapBytes32 (InterruptProp[1].Number)
|
|
|
|
+ (InterruptProp[1].Type ? 16 : 0);
|
|
|
|
VirtIntrNum = SwapBytes32 (InterruptProp[2].Number)
|
|
|
|
+ (InterruptProp[2].Type ? 16 : 0);
|
|
|
|
HypIntrNum = PropSize < 48 ? 0 : SwapBytes32 (InterruptProp[3].Number)
|
|
|
|
+ (InterruptProp[3].Type ? 16 : 0);
|
2023-09-19 12:20:25 +02:00
|
|
|
HypVirtIntrNum = PropSize < 60 ? 0 : SwapBytes32 (InterruptProp[4].Number)
|
|
|
|
+ (InterruptProp[4].Type ? 16 : 0);
|
2021-12-05 23:53:52 +01:00
|
|
|
|
2021-11-17 04:21:15 +01:00
|
|
|
DEBUG ((
|
|
|
|
DEBUG_INFO,
|
|
|
|
"Found Timer interrupts %d, %d, %d, %d\n",
|
2016-04-08 11:44:55 +02:00
|
|
|
SecIntrNum,
|
|
|
|
IntrNum,
|
|
|
|
VirtIntrNum,
|
|
|
|
HypIntrNum
|
|
|
|
));
|
|
|
|
|
2016-10-21 11:59:36 +02:00
|
|
|
PcdStatus = PcdSet32S (PcdArmArchTimerSecIntrNum, SecIntrNum);
|
|
|
|
ASSERT_RETURN_ERROR (PcdStatus);
|
|
|
|
PcdStatus = PcdSet32S (PcdArmArchTimerIntrNum, IntrNum);
|
|
|
|
ASSERT_RETURN_ERROR (PcdStatus);
|
|
|
|
PcdStatus = PcdSet32S (PcdArmArchTimerVirtIntrNum, VirtIntrNum);
|
|
|
|
ASSERT_RETURN_ERROR (PcdStatus);
|
|
|
|
PcdStatus = PcdSet32S (PcdArmArchTimerHypIntrNum, HypIntrNum);
|
|
|
|
ASSERT_RETURN_ERROR (PcdStatus);
|
2023-09-19 12:20:25 +02:00
|
|
|
PcdStatus = PcdSet32S (PcdArmArchTimerHypVirtIntrNum, HypVirtIntrNum);
|
|
|
|
ASSERT_RETURN_ERROR (PcdStatus);
|
2016-04-08 11:44:55 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|