@@ -15,24 +15,38 @@ static uint32_t timer_freq = 0;
1515void vmm_arch_profile_init ()
1616{
1717 if (cpu_is_master ()) {
18- /**
19- * Since there is no firmware in cortex-r platforms, we need to initialize the system
20- * counter.
21- */
22- volatile struct generic_timer_cntctrl * timer_ctl ;
23- timer_ctl = (struct generic_timer_cntctrl * )mem_alloc_map_dev (& cpu ()-> as , SEC_HYP_PRIVATE ,
24- platform .arch .generic_timer .base_addr , platform .arch .generic_timer .base_addr ,
25- sizeof (struct generic_timer_cntctrl ));
26-
27- timer_ctl -> CNTCR |= GENERIC_TIMER_CNTCTL_CNTCR_EN ;
28- fence_ord_write ();
29-
30- timer_freq = timer_ctl -> CNTDIF0 ;
31-
32- mem_unmap (& cpu ()-> as , (vaddr_t )timer_ctl , sizeof (struct generic_timer_cntctrl ), false);
18+ unsigned long cur_cntfrq = sysreg_cntfrq_el0_read ();
19+ if (cur_cntfrq != 0UL ) {
20+ timer_freq = (uint32_t )cur_cntfrq ;
21+ } else {
22+ #ifdef PLAT_GENERIC_TIMER_FREQ_HZ
23+ timer_freq = (uint32_t )PLAT_GENERIC_TIMER_FREQ_HZ ;
24+ #else
25+ if (platform .arch .generic_timer .base_addr == 0 ) {
26+ ERROR ("generic timer base_addr undefined; cannot init system counter" );
27+ } else {
28+ volatile struct generic_timer_cntctrl * timer_ctl ;
29+ timer_ctl = (struct generic_timer_cntctrl * )mem_alloc_map_dev (& cpu ()-> as ,
30+ SEC_HYP_PRIVATE , platform .arch .generic_timer .base_addr ,
31+ platform .arch .generic_timer .base_addr , sizeof (struct generic_timer_cntctrl ));
32+
33+ timer_ctl -> CNTCR |= GENERIC_TIMER_CNTCTL_CNTCR_EN ;
34+ fence_ord_write ();
35+
36+ timer_freq = (uint32_t )timer_ctl -> CNTDIF0 ;
37+
38+ mem_unmap (& cpu ()-> as , (vaddr_t )timer_ctl , sizeof (struct generic_timer_cntctrl ),
39+ false);
40+ }
41+ #endif
42+ }
3343 }
3444
3545 cpu_sync_barrier (& cpu_glb_sync );
3646
47+ /* Program CNTFRQ_EL0 and verify. */
3748 sysreg_cntfrq_el0_write (timer_freq );
49+ if (sysreg_cntfrq_el0_read () != (unsigned long )timer_freq ) {
50+ ERROR ("failed to program CNTFRQ_EL0 to %u Hz" , timer_freq );
51+ }
3852}
0 commit comments