|
| 1 | +/** |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * Copyright (c) Bao Project and Contributors. All rights reserved. |
| 4 | + */ |
| 5 | + |
| 6 | +#include <bao.h> |
| 7 | +#include <vmm.h> |
| 8 | +#include <platform.h> |
| 9 | +#include <arch/generic_timer.h> |
| 10 | +#include <cpu.h> |
| 11 | +#include <fences.h> |
| 12 | + |
| 13 | +static uint32_t timer_freq = 0; |
| 14 | + |
| 15 | +void vmm_arch_profile_init() |
| 16 | +{ |
| 17 | + if (cpu_is_master()) { |
| 18 | + unsigned long cur_cntfrq = sysreg_cntfrq_el0_read(); |
| 19 | + if (cur_cntfrq != 0UL) { |
| 20 | + timer_freq = (uint32_t)cur_cntfrq; |
| 21 | +<<<<<<< HEAD |
| 22 | + } else if (platform.arch.generic_timer.fixed_freq != 0) |
| 23 | + timer_freq = (uint32_t)PLAT_GENERIC_TIMER_FREQ_HZ; |
| 24 | + } else { |
| 25 | + |
| 26 | + if (platform.arch.generic_timer.base_addr == 0) { |
| 27 | + ERROR("generic timer base_addr undefined; cannot init system counter"); |
| 28 | + } |
| 29 | + |
| 30 | + volatile struct generic_timer_cntctrl* timer_ctl; |
| 31 | + timer_ctl = (struct generic_timer_cntctrl*)mem_alloc_map_dev(&cpu()->as, |
| 32 | + SEC_HYP_PRIVATE, platform.arch.generic_timer.base_addr, |
| 33 | + platform.arch.generic_timer.base_addr, sizeof(struct generic_timer_cntctrl)); |
| 34 | + |
| 35 | + timer_ctl->CNTCR |= GENERIC_TIMER_CNTCTL_CNTCR_EN; |
| 36 | + fence_ord_write(); |
| 37 | + |
| 38 | + timer_freq = (uint32_t)timer_ctl->CNTDIF0; |
| 39 | + |
| 40 | + mem_unmap(&cpu()->as, (vaddr_t)timer_ctl, sizeof(struct generic_timer_cntctrl), |
| 41 | + false); |
| 42 | +======= |
| 43 | + } else { |
| 44 | +#ifdef PLAT_GENERIC_TIMER_FREQ_HZ |
| 45 | + timer_freq = (uint32_t)PLAT_GENERIC_TIMER_FREQ_HZ; |
| 46 | +#else |
| 47 | + if (platform.arch.generic_timer.base_addr == 0) { |
| 48 | + ERROR("generic timer base_addr undefined; cannot init system counter"); |
| 49 | + } else { |
| 50 | + volatile struct generic_timer_cntctrl* timer_ctl; |
| 51 | + timer_ctl = (struct generic_timer_cntctrl*)mem_alloc_map_dev(&cpu()->as, |
| 52 | + SEC_HYP_PRIVATE, platform.arch.generic_timer.base_addr, |
| 53 | + platform.arch.generic_timer.base_addr, sizeof(struct generic_timer_cntctrl)); |
| 54 | + |
| 55 | + timer_ctl->CNTCR |= GENERIC_TIMER_CNTCTL_CNTCR_EN; |
| 56 | + fence_ord_write(); |
| 57 | + |
| 58 | + timer_freq = (uint32_t)timer_ctl->CNTDIF0; |
| 59 | + |
| 60 | + mem_unmap(&cpu()->as, (vaddr_t)timer_ctl, sizeof(struct generic_timer_cntctrl), |
| 61 | + false); |
| 62 | + } |
| 63 | +#endif |
| 64 | +>>>>>>> 0ea60453 (feat(armv8r): handle different timer init cases) |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + cpu_sync_barrier(&cpu_glb_sync); |
| 69 | + |
| 70 | + /* Program CNTFRQ_EL0 and verify. */ |
| 71 | + sysreg_cntfrq_el0_write(timer_freq); |
| 72 | + if (sysreg_cntfrq_el0_read() != (unsigned long)timer_freq) { |
| 73 | + ERROR("failed to program CNTFRQ_EL0 to %u Hz", timer_freq); |
| 74 | + } |
| 75 | +} |
0 commit comments