mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-11-29 00:55:08 +00:00
hv: multi-arch reconstruct spinlock library
Extract common interface to include/lib/spinlock.h, and invoke the variant implementation of arch. Refine assemble macro code in case that ASSEMBLER defined. Tracked-On: #8803 Signed-off-by: Haoyu Tang <haoyu.tang@intel.com> Reviewed-by: Yifan Liu <yifan1.liu@intel.com> Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
57
hypervisor/include/lib/spinlock.h
Normal file
57
hypervisor/include/lib/spinlock.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef SPINLOCK_H
|
||||
#define SPINLOCK_H
|
||||
|
||||
#ifndef ASSEMBLER
|
||||
#include <types.h>
|
||||
#include <rtl.h>
|
||||
#include <asm/cpu.h>
|
||||
#include <asm/lib/spinlock.h>
|
||||
|
||||
/* The common spinlock type */
|
||||
typedef arch_spinlock_t spinlock_t;
|
||||
|
||||
/* The mandatory functions should be implemented by arch spinlock library */
|
||||
static inline void arch_spinlock_obtain(arch_spinlock_t *lock);
|
||||
static inline void arch_spinlock_release(arch_spinlock_t *lock);
|
||||
|
||||
/* Function prototypes */
|
||||
static inline void spinlock_init(spinlock_t *lock)
|
||||
{
|
||||
(void)memset(lock, 0U, sizeof(spinlock_t));
|
||||
}
|
||||
|
||||
static inline void spinlock_irqsave_obtain(spinlock_t *lock, uint64_t * flags)
|
||||
{
|
||||
CPU_INT_ALL_DISABLE(flags);
|
||||
arch_spinlock_obtain(lock);
|
||||
}
|
||||
|
||||
static inline void spinlock_irqrestore_release(spinlock_t *lock, uint64_t flags)
|
||||
{
|
||||
arch_spinlock_release(lock);
|
||||
CPU_INT_ALL_RESTORE(flags);
|
||||
}
|
||||
|
||||
static inline void spinlock_obtain(spinlock_t *lock)
|
||||
{
|
||||
return arch_spinlock_obtain(lock);
|
||||
}
|
||||
|
||||
static inline void spinlock_release(spinlock_t *lock)
|
||||
{
|
||||
return arch_spinlock_release(lock);
|
||||
}
|
||||
|
||||
#else /* ASSEMBLER */
|
||||
#include <asm/lib/spinlock.h>
|
||||
#define spinlock_obtain arch_spinlock_obtain
|
||||
#define spinlock_release arch_spinlock_release
|
||||
#endif /* ASSEMBLER */
|
||||
|
||||
#endif /* SPINLOCK_H */
|
||||
Reference in New Issue
Block a user