3 * Copyright (c) 2011 - 2014, 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/ArmV7.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/MemoryAllocationLib.h>
19 #include <Library/ArmLib.h>
20 #include <Library/BaseLib.h>
21 #include <Library/DebugLib.h>
23 #include "ArmLibPrivate.h"
24 #include <Library/ArmArchTimer.h>
29 IN ARM_ARCH_TIMER_REGS Reg
,
33 // Check if the Generic/Architecture timer is implemented
34 if (ArmIsArchTimerImplemented ()) {
37 *((UINTN
*)DstBuf
) = ArmReadCntFrq ();
41 *((UINT64
*)DstBuf
) = ArmReadCntPct ();
45 *((UINTN
*)DstBuf
) = ArmReadCntkCtl();
49 *((UINTN
*)DstBuf
) = ArmReadCntpTval ();
53 *((UINTN
*)DstBuf
) = ArmReadCntpCtl ();
57 *((UINTN
*)DstBuf
) = ArmReadCntvTval ();
61 *((UINTN
*)DstBuf
) = ArmReadCntvCtl ();
65 *((UINT64
*)DstBuf
) = ArmReadCntvCt ();
69 *((UINT64
*)DstBuf
) = ArmReadCntpCval ();
73 *((UINT64
*)DstBuf
) = ArmReadCntvCval ();
77 *((UINT64
*)DstBuf
) = ArmReadCntvOff ();
84 DEBUG ((EFI_D_ERROR
, "The register is related to Hypervisor Mode. Can't perform requested operation\n "));
88 DEBUG ((EFI_D_ERROR
, "Unknown ARM Generic Timer register %x. \n ", Reg
));
91 DEBUG ((EFI_D_ERROR
, "Attempt to read ARM Generic Timer registers. But ARM Generic Timer extension is not implemented \n "));
95 *((UINT64
*)DstBuf
) = 0;
100 ArmArchTimerWriteReg (
101 IN ARM_ARCH_TIMER_REGS Reg
,
105 // Check if the Generic/Architecture timer is implemented
106 if (ArmIsArchTimerImplemented ()) {
111 ArmWriteCntFrq (*((UINTN
*)SrcBuf
));
115 DEBUG ((EFI_D_ERROR
, "Can't write to Read Only Register: CNTPCT \n"));
119 ArmWriteCntkCtl (*((UINTN
*)SrcBuf
));
123 ArmWriteCntpTval (*((UINTN
*)SrcBuf
));
127 ArmWriteCntpCtl (*((UINTN
*)SrcBuf
));
131 ArmWriteCntvTval (*((UINTN
*)SrcBuf
));
135 ArmWriteCntvCtl (*((UINTN
*)SrcBuf
));
139 DEBUG ((EFI_D_ERROR
, "Can't write to Read Only Register: CNTVCT \n"));
143 ArmWriteCntpCval (*((UINT64
*)SrcBuf
) );
147 ArmWriteCntvCval (*((UINT64
*)SrcBuf
) );
151 ArmWriteCntvOff (*((UINT64
*)SrcBuf
));
158 DEBUG ((EFI_D_ERROR
, "The register is related to Hypervisor Mode. Can't perform requested operation\n "));
162 DEBUG ((EFI_D_ERROR
, "Unknown ARM Generic Timer register %x. \n ", Reg
));
165 DEBUG ((EFI_D_ERROR
, "Attempt to write to ARM Generic Timer registers. But ARM Generic Timer extension is not implemented \n "));