From 51204a8d1152231f2e7a84b8199f2b4c1d89b766 Mon Sep 17 00:00:00 2001 From: Liang Yi Date: Mon, 12 Apr 2021 12:07:59 +0800 Subject: [PATCH] hv/mod_timer: separate delay functions from the timer module Modules that use udelay() should include "delay.h" explicitly. Tracked-On: #5920 Signed-off-by: Rong Liu Reviewed-by: Jason Chen CJ --- doc/acrn.doxyfile | 1 + hypervisor/Makefile | 1 + hypervisor/arch/x86/cpu.c | 1 + hypervisor/arch/x86/lapic.c | 1 + hypervisor/arch/x86/pm.c | 1 + hypervisor/arch/x86/timer.c | 13 ------------- hypervisor/common/delay.c | 21 +++++++++++++++++++++ hypervisor/dm/vpci/vsriov.c | 1 + hypervisor/include/arch/x86/asm/timer.h | 2 -- hypervisor/include/common/delay.h | 21 +++++++++++++++++++++ 10 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 hypervisor/common/delay.c create mode 100644 hypervisor/include/common/delay.h diff --git a/doc/acrn.doxyfile b/doc/acrn.doxyfile index 98251a6a0..e9a51ca34 100644 --- a/doc/acrn.doxyfile +++ b/doc/acrn.doxyfile @@ -819,6 +819,7 @@ INPUT = custom-doxygen/mainpage.md \ ../hypervisor/include/common/hypercall.h \ ../hypervisor/include/common/irq.h \ ../hypervisor/include/common/ticks.h \ + ../hypervisor/include/common/delay.h \ ../hypervisor/include/common/ptdev.h \ ../hypervisor/include/public/acrn_common.h \ ../hypervisor/include/public/acrn_hv_defs.h \ diff --git a/hypervisor/Makefile b/hypervisor/Makefile index 7750c0edf..77cfcacf6 100644 --- a/hypervisor/Makefile +++ b/hypervisor/Makefile @@ -230,6 +230,7 @@ HW_S_SRCS += arch/x86/sched.S HW_C_SRCS += arch/x86/rdt.c HW_C_SRCS += arch/x86/sgx.c HW_C_SRCS += common/ticks.c +HW_C_SRCS += common/delay.c HW_C_SRCS += common/irq.c HW_C_SRCS += common/softirq.c HW_C_SRCS += common/schedule.c diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index acc20d5ae..abd867bdd 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -33,6 +33,7 @@ #include #include #include +#include #define CPU_UP_TIMEOUT 100U /* millisecond */ #define CPU_DOWN_TIMEOUT 100U /* millisecond */ diff --git a/hypervisor/arch/x86/lapic.c b/hypervisor/arch/x86/lapic.c index d570cd97c..237b1fde4 100644 --- a/hypervisor/arch/x86/lapic.c +++ b/hypervisor/arch/x86/lapic.c @@ -12,6 +12,7 @@ #include #include #include +#include /* intr_lapic_icr_delivery_mode */ #define INTR_LAPIC_ICR_FIXED 0x0U diff --git a/hypervisor/arch/x86/pm.c b/hypervisor/arch/x86/pm.c index 621b9c122..800d50df1 100644 --- a/hypervisor/arch/x86/pm.c +++ b/hypervisor/arch/x86/pm.c @@ -17,6 +17,7 @@ #include #include #include +#include struct cpu_context cpu_ctx; diff --git a/hypervisor/arch/x86/timer.c b/hypervisor/arch/x86/timer.c index fc601eaa0..2c73efda1 100644 --- a/hypervisor/arch/x86/timer.c +++ b/hypervisor/arch/x86/timer.c @@ -200,16 +200,3 @@ void timer_init(void) init_tsc_deadline_timer(); } } - -void udelay(uint32_t us) -{ - uint64_t dest_tsc, delta_tsc; - - /* Calculate number of ticks to wait */ - delta_tsc = us_to_ticks(us); - dest_tsc = rdtsc() + delta_tsc; - - /* Loop until time expired */ - while (rdtsc() < dest_tsc) { - } -} diff --git a/hypervisor/common/delay.c b/hypervisor/common/delay.c new file mode 100644 index 000000000..8edf93b68 --- /dev/null +++ b/hypervisor/common/delay.c @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2021 Intel Corporation. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +void udelay(uint32_t us) +{ + uint64_t end, delta; + + /* Calculate number of ticks to wait */ + delta = us_to_ticks(us); + end = cpu_ticks() + delta; + + /* Loop until time expired */ + while (cpu_ticks() < end) { + } +} diff --git a/hypervisor/dm/vpci/vsriov.c b/hypervisor/dm/vpci/vsriov.c index 3f13ce6e9..fb4c46dd3 100644 --- a/hypervisor/dm/vpci/vsriov.c +++ b/hypervisor/dm/vpci/vsriov.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "vpci_priv.h" diff --git a/hypervisor/include/arch/x86/asm/timer.h b/hypervisor/include/arch/x86/asm/timer.h index 796ec00b6..51f9da1aa 100644 --- a/hypervisor/include/arch/x86/asm/timer.h +++ b/hypervisor/include/arch/x86/asm/timer.h @@ -48,8 +48,6 @@ struct hv_timer { /* External Interfaces */ -void udelay(uint32_t us); - /** * @brief Initialize a timer structure. * diff --git a/hypervisor/include/common/delay.h b/hypervisor/include/common/delay.h new file mode 100644 index 000000000..4e5252322 --- /dev/null +++ b/hypervisor/include/common/delay.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2021 Intel Corporation. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef COMMON_DELAY_H +#define COMMON_DELAY_H + +#include + +/** + * @brief Busy wait a few micro seconds. + * + * @param[in] us micro seconds to delay. + * + * @retval None + */ +void udelay(uint32_t us); + +#endif /* COMMON_DELAY_H */