]> git.proxmox.com Git - mirror_edk2.git/blame - Omap35xxPkg/Library/DebugAgentTimerLib/DebugAgentTimerLib.c
Omap35xxPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / Omap35xxPkg / Library / DebugAgentTimerLib / DebugAgentTimerLib.c
CommitLineData
43263288 1/** @file\r
2 Debug Agent timer lib for OMAP 35xx.\r
3\r
3d70643b 4 Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
3402aac7 5\r
538311f7 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
43263288 7\r
8**/\r
9#include <Base.h>\r
1e57a462 10#include <Library/BaseLib.h>\r
11#include <Library/IoLib.h>\r
12#include <Library/OmapLib.h>\r
43263288 13#include <Library/ArmLib.h>\r
1e57a462 14#include <Library/PcdLib.h>\r
43263288 15\r
1e57a462 16#include <Omap3530/Omap3530.h>\r
43263288 17\r
18\r
19volatile UINT32 gVector;\r
1e57a462 20\r
21// Cached registers\r
22volatile UINT32 gTISR;\r
23volatile UINT32 gTCLR;\r
24volatile UINT32 gTLDR;\r
25volatile UINT32 gTCRR;\r
26volatile UINT32 gTIER;\r
43263288 27\r
28VOID\r
29EnableInterruptSource (\r
30 VOID\r
31 )\r
32{\r
33 UINTN Bank;\r
34 UINTN Bit;\r
35\r
36 // Map vector to FIQ, IRQ is default\r
37 MmioWrite32 (INTCPS_ILR (gVector), 1);\r
38\r
39 Bank = gVector / 32;\r
40 Bit = 1UL << (gVector % 32);\r
3402aac7 41\r
43263288 42 MmioWrite32 (INTCPS_MIR_CLEAR(Bank), Bit);\r
43}\r
44\r
45VOID\r
46DisableInterruptSource (\r
47 VOID\r
48 )\r
49{\r
50 UINTN Bank;\r
51 UINTN Bit;\r
3402aac7 52\r
43263288 53 Bank = gVector / 32;\r
3402aac7 54 Bit = 1UL << (gVector % 32);\r
43263288 55\r
56 MmioWrite32 (INTCPS_MIR_SET(Bank), Bit);\r
57}\r
58\r
59\r
60\r
61/**\r
62 Setup all the hardware needed for the debug agents timer.\r
63\r
64 This function is used to set up debug enviroment. It may enable interrupts.\r
65\r
66**/\r
67VOID\r
68EFIAPI\r
69DebugAgentTimerIntialize (\r
70 VOID\r
71 )\r
72{\r
73 UINT32 TimerBaseAddress;\r
9e4f210c 74 UINT32 TimerNumber;\r
43263288 75\r
9e4f210c 76 TimerNumber = PcdGet32(PcdOmap35xxDebugAgentTimer);\r
1e57a462 77 gVector = InterruptVectorForTimer (TimerNumber);\r
43263288 78\r
1e57a462 79 // Set up the timer registers\r
80 TimerBaseAddress = TimerBase (TimerNumber);\r
81 gTISR = TimerBaseAddress + GPTIMER_TISR;\r
82 gTCLR = TimerBaseAddress + GPTIMER_TCLR;\r
83 gTLDR = TimerBaseAddress + GPTIMER_TLDR;\r
84 gTCRR = TimerBaseAddress + GPTIMER_TCRR;\r
85 gTIER = TimerBaseAddress + GPTIMER_TIER;\r
43263288 86\r
9e4f210c 87 if ((TimerNumber < 2) || (TimerNumber > 9)) {\r
88 // This code assumes one the General Purpose timers is used\r
89 // GPT2 - GPT9\r
90 CpuDeadLoop ();\r
91 }\r
92 // Set source clock for GPT2 - GPT9 to SYS_CLK\r
3402aac7 93 MmioOr32 (CM_CLKSEL_PER, 1 << (TimerNumber - 2));\r
9e4f210c 94\r
43263288 95}\r
3402aac7
RC
96\r
97\r
43263288 98/**\r
99 Set the period for the debug agent timer. Zero means disable the timer.\r
100\r
101 @param[in] TimerPeriodMilliseconds Frequency of the debug agent timer.\r
102\r
3402aac7 103**/\r
43263288 104VOID\r
105EFIAPI\r
106DebugAgentTimerSetPeriod (\r
107 IN UINT32 TimerPeriodMilliseconds\r
108 )\r
109{\r
1e57a462 110 UINT64 TimerCount;\r
111 INT32 LoadValue;\r
3402aac7 112\r
1e57a462 113 if (TimerPeriodMilliseconds == 0) {\r
114 // Turn off GPTIMER3\r
115 MmioWrite32 (gTCLR, TCLR_ST_OFF);\r
3402aac7 116\r
1e57a462 117 DisableInterruptSource ();\r
3402aac7 118 } else {\r
1e57a462 119 // Calculate required timer count\r
120 TimerCount = DivU64x32(TimerPeriodMilliseconds * 1000000, PcdGet32(PcdDebugAgentTimerFreqNanoSeconds));\r
121\r
122 // Set GPTIMER5 Load register\r
123 LoadValue = (INT32) -TimerCount;\r
124 MmioWrite32 (gTLDR, LoadValue);\r
125 MmioWrite32 (gTCRR, LoadValue);\r
126\r
127 // Enable Overflow interrupt\r
128 MmioWrite32 (gTIER, TIER_TCAR_IT_DISABLE | TIER_OVF_IT_ENABLE | TIER_MAT_IT_DISABLE);\r
129\r
130 // Turn on GPTIMER3, it will reload at overflow\r
131 MmioWrite32 (gTCLR, TCLR_AR_AUTORELOAD | TCLR_ST_ON);\r
132\r
133 EnableInterruptSource ();\r
134 }\r
43263288 135}\r
3402aac7 136\r
43263288 137\r
138/**\r
3402aac7
RC
139 Perform End Of Interrupt for the debug agent timer. This is called in the\r
140 interrupt handler after the interrupt has been processed.\r
43263288 141\r
3402aac7 142**/\r
43263288 143VOID\r
144EFIAPI\r
145DebugAgentTimerEndOfInterrupt (\r
146 VOID\r
147 )\r
148{\r
1e57a462 149 // Clear all timer interrupts\r
3402aac7 150 MmioWrite32 (gTISR, TISR_CLEAR_ALL);\r
1e57a462 151\r
152 // Poll interrupt status bits to ensure clearing\r
43263288 153 while ((MmioRead32 (gTISR) & TISR_ALL_INTERRUPT_MASK) != TISR_NO_INTERRUPTS_PENDING);\r
154\r
155 MmioWrite32 (INTCPS_CONTROL, INTCPS_CONTROL_NEWFIQAGR);\r
cf93a378 156 ArmDataSynchronizationBarrier ();\r
43263288 157\r
158}\r
9e4f210c 159\r