3 * Copyright (c) 2011-2013, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Chipset/AArch64.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/ArmLib.h>
19 #include <Library/BaseLib.h>
20 #include <Library/DebugLib.h>
21 #include "AArch64Lib.h"
22 #include "ArmLibPrivate.h"
23 #include <Library/ArmArchTimer.h>
28 IN ARM_ARCH_TIMER_REGS Reg
,
32 // Check if the Generic/Architecture timer is implemented
33 if (ArmIsArchTimerImplemented ()) {
38 *((UINTN
*)DstBuf
) = ArmReadCntFrq ();
42 *((UINT64
*)DstBuf
) = ArmReadCntPct ();
46 *((UINTN
*)DstBuf
) = ArmReadCntkCtl();
50 *((UINTN
*)DstBuf
) = ArmReadCntpTval ();
54 *((UINTN
*)DstBuf
) = ArmReadCntpCtl ();
58 *((UINTN
*)DstBuf
) = ArmReadCntvTval ();
62 *((UINTN
*)DstBuf
) = ArmReadCntvCtl ();
66 *((UINT64
*)DstBuf
) = ArmReadCntvCt ();
70 *((UINT64
*)DstBuf
) = ArmReadCntpCval ();
74 *((UINT64
*)DstBuf
) = ArmReadCntvCval ();
78 *((UINT64
*)DstBuf
) = ArmReadCntvOff ();
85 DEBUG ((EFI_D_ERROR
, "The register is related to Hypervisor Mode. Can't perform requested operation\n "));
89 DEBUG ((EFI_D_ERROR
, "Unknown ARM Generic Timer register %x. \n ", Reg
));
92 DEBUG ((EFI_D_ERROR
, "Attempt to read ARM Generic Timer registers. But ARM Generic Timer extension is not implemented \n "));
99 ArmArchTimerWriteReg (
100 IN ARM_ARCH_TIMER_REGS Reg
,
104 // Check if the Generic/Architecture timer is implemented
105 if (ArmIsArchTimerImplemented ()) {
110 ArmWriteCntFrq (*((UINTN
*)SrcBuf
));
114 DEBUG ((EFI_D_ERROR
, "Can't write to Read Only Register: CNTPCT \n"));
118 ArmWriteCntkCtl (*((UINTN
*)SrcBuf
));
122 ArmWriteCntpTval (*((UINTN
*)SrcBuf
));
126 ArmWriteCntpCtl (*((UINTN
*)SrcBuf
));
130 ArmWriteCntvTval (*((UINTN
*)SrcBuf
));
134 ArmWriteCntvCtl (*((UINTN
*)SrcBuf
));
138 DEBUG ((EFI_D_ERROR
, "Can't write to Read Only Register: CNTVCT \n"));
142 ArmWriteCntpCval (*((UINT64
*)SrcBuf
) );
146 ArmWriteCntvCval (*((UINT64
*)SrcBuf
) );
150 ArmWriteCntvOff (*((UINT64
*)SrcBuf
));
157 DEBUG ((EFI_D_ERROR
, "The register is related to Hypervisor Mode. Can't perform requested operation\n "));
161 DEBUG ((EFI_D_ERROR
, "Unknown ARM Generic Timer register %x. \n ", Reg
));
164 DEBUG ((EFI_D_ERROR
, "Attempt to write to ARM Generic Timer registers. But ARM Generic Timer extension is not implemented \n "));