lib: update libmetal to SHA db77c464..
Origin: https://github.com/OpenAMP/libmetal commit: db77c464376e603bc46122b38a7956c87597895b Status: merge libmetal new version after removing useless dirs. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
87e9e7f2c5
commit
0b23894a04
2
README
2
README
|
@ -27,7 +27,7 @@ URL:
|
||||||
https://github.com/OpenAMP/libmetal
|
https://github.com/OpenAMP/libmetal
|
||||||
|
|
||||||
commit:
|
commit:
|
||||||
f1e8154b6392838a7c68871ab03400112b1e59b7
|
db77c464376e603bc46122b38a7956c87597895b
|
||||||
|
|
||||||
Maintained-by:
|
Maintained-by:
|
||||||
External
|
External
|
||||||
|
|
|
@ -3,6 +3,10 @@ if (POLICY CMP0048)
|
||||||
cmake_policy(SET CMP0048 NEW)
|
cmake_policy(SET CMP0048 NEW)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (POLICY CMP0077)
|
||||||
|
cmake_policy(SET CMP0077 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
list (APPEND CMAKE_MODULE_PATH
|
list (APPEND CMAKE_MODULE_PATH
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
|
||||||
|
|
|
@ -25,7 +25,7 @@ find_library (HUGETLBFS_LIBRARY NAMES ${HUGETLBFS_NAMES})
|
||||||
# handle the QUIETLY and REQUIRED arguments and set HUGETLBFS_FOUND to TRUE if
|
# handle the QUIETLY and REQUIRED arguments and set HUGETLBFS_FOUND to TRUE if
|
||||||
# all listed variables are TRUE
|
# all listed variables are TRUE
|
||||||
include (FindPackageHandleStandardArgs)
|
include (FindPackageHandleStandardArgs)
|
||||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS (HUGETLBFS DEFAULT_MSG HUGETLBFS_LIBRARY HUGETLBFS_INCLUDE_DIR)
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS (HugeTLBFS DEFAULT_MSG HUGETLBFS_LIBRARY HUGETLBFS_INCLUDE_DIR)
|
||||||
|
|
||||||
if (HUGETLBFS_FOUND)
|
if (HUGETLBFS_FOUND)
|
||||||
set (HUGETLBFS_LIBRARIES ${HUGETLBFS_LIBRARY})
|
set (HUGETLBFS_LIBRARIES ${HUGETLBFS_LIBRARY})
|
||||||
|
|
|
@ -25,7 +25,7 @@ find_library (LIBSYSFS_LIBRARY NAMES ${LIBSYSFS_NAMES})
|
||||||
# handle the QUIETLY and REQUIRED arguments and set LIBSYSFS_FOUND to TRUE if
|
# handle the QUIETLY and REQUIRED arguments and set LIBSYSFS_FOUND to TRUE if
|
||||||
# all listed variables are TRUE
|
# all listed variables are TRUE
|
||||||
include (FindPackageHandleStandardArgs)
|
include (FindPackageHandleStandardArgs)
|
||||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS (LIBSYSFS DEFAULT_MSG LIBSYSFS_LIBRARY LIBSYSFS_INCLUDE_DIR)
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS (LibSysFS DEFAULT_MSG LIBSYSFS_LIBRARY LIBSYSFS_INCLUDE_DIR)
|
||||||
|
|
||||||
if (LIBSYSFS_FOUND)
|
if (LIBSYSFS_FOUND)
|
||||||
set (LIBSYSFS_LIBRARIES ${LIBSYSFS_LIBRARY})
|
set (LIBSYSFS_LIBRARIES ${LIBSYSFS_LIBRARY})
|
||||||
|
|
|
@ -14,8 +14,87 @@
|
||||||
|
|
||||||
#include <metal/config.h>
|
#include <metal/config.h>
|
||||||
|
|
||||||
#if defined(HAVE_STDATOMIC_H) && !defined(__STDC_NO_ATOMICS__) && \
|
#if defined(__cplusplus)
|
||||||
!defined(__cplusplus)
|
# include <cstdint>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* <atomic> has the same functionality as <stdatomic.h> but all members are only
|
||||||
|
* accessible in the std namespace. As the rest of libmetal is pure C, it does
|
||||||
|
* not know about namespaces, even when compiled as part of a C++ file. So we
|
||||||
|
* just export the members of <atomic> into the global namespace.
|
||||||
|
*/
|
||||||
|
# include <atomic>
|
||||||
|
using std::atomic_flag;
|
||||||
|
using std::memory_order;
|
||||||
|
|
||||||
|
using std::atomic_bool;
|
||||||
|
using std::atomic_char;
|
||||||
|
using std::atomic_schar;
|
||||||
|
using std::atomic_uchar;
|
||||||
|
using std::atomic_short;
|
||||||
|
using std::atomic_ushort;
|
||||||
|
using std::atomic_int;
|
||||||
|
using std::atomic_uint;
|
||||||
|
using std::atomic_long;
|
||||||
|
using std::atomic_ulong;
|
||||||
|
using std::atomic_llong;
|
||||||
|
using std::atomic_ullong;
|
||||||
|
using std::atomic_char16_t;
|
||||||
|
using std::atomic_char32_t;
|
||||||
|
using std::atomic_wchar_t;
|
||||||
|
using std::atomic_int_least8_t;
|
||||||
|
using std::atomic_uint_least8_t;
|
||||||
|
using std::atomic_int_least16_t;
|
||||||
|
using std::atomic_uint_least16_t;
|
||||||
|
using std::atomic_int_least32_t;
|
||||||
|
using std::atomic_uint_least32_t;
|
||||||
|
using std::atomic_int_least64_t;
|
||||||
|
using std::atomic_uint_least64_t;
|
||||||
|
using std::atomic_int_fast8_t;
|
||||||
|
using std::atomic_uint_fast8_t;
|
||||||
|
using std::atomic_int_fast16_t;
|
||||||
|
using std::atomic_uint_fast16_t;
|
||||||
|
using std::atomic_int_fast32_t;
|
||||||
|
using std::atomic_uint_fast32_t;
|
||||||
|
using std::atomic_int_fast64_t;
|
||||||
|
using std::atomic_uint_fast64_t;
|
||||||
|
using std::atomic_intptr_t;
|
||||||
|
using std::atomic_uintptr_t;
|
||||||
|
using std::atomic_size_t;
|
||||||
|
using std::atomic_ptrdiff_t;
|
||||||
|
using std::atomic_intmax_t;
|
||||||
|
using std::atomic_uintmax_t;
|
||||||
|
|
||||||
|
using std::atomic_flag_test_and_set;
|
||||||
|
using std::atomic_flag_test_and_set_explicit;
|
||||||
|
using std::atomic_flag_clear;
|
||||||
|
using std::atomic_flag_clear_explicit;
|
||||||
|
using std::atomic_init;
|
||||||
|
using std::atomic_is_lock_free;
|
||||||
|
using std::atomic_store;
|
||||||
|
using std::atomic_store_explicit;
|
||||||
|
using std::atomic_load;
|
||||||
|
using std::atomic_load_explicit;
|
||||||
|
using std::atomic_exchange;
|
||||||
|
using std::atomic_exchange_explicit;
|
||||||
|
using std::atomic_compare_exchange_strong;
|
||||||
|
using std::atomic_compare_exchange_strong_explicit;
|
||||||
|
using std::atomic_compare_exchange_weak;
|
||||||
|
using std::atomic_compare_exchange_weak_explicit;
|
||||||
|
using std::atomic_fetch_add;
|
||||||
|
using std::atomic_fetch_add_explicit;
|
||||||
|
using std::atomic_fetch_sub;
|
||||||
|
using std::atomic_fetch_sub_explicit;
|
||||||
|
using std::atomic_fetch_or;
|
||||||
|
using std::atomic_fetch_or_explicit;
|
||||||
|
using std::atomic_fetch_xor;
|
||||||
|
using std::atomic_fetch_xor_explicit;
|
||||||
|
using std::atomic_fetch_and;
|
||||||
|
using std::atomic_fetch_and_explicit;
|
||||||
|
using std::atomic_thread_fence;
|
||||||
|
using std::atomic_signal_fence;
|
||||||
|
|
||||||
|
#elif defined(HAVE_STDATOMIC_H) && !defined(__STDC_NO_ATOMICS__)
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
# include <stdatomic.h>
|
# include <stdatomic.h>
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
|
|
|
@ -63,10 +63,10 @@ typedef enum {
|
||||||
atomic_load(OBJ)
|
atomic_load(OBJ)
|
||||||
#define atomic_exchange(OBJ, DES) \
|
#define atomic_exchange(OBJ, DES) \
|
||||||
({ \
|
({ \
|
||||||
typeof(OBJ) obj = (OBJ); \
|
__typeof__(OBJ) obj = (OBJ); \
|
||||||
typeof(*obj) des = (DES); \
|
__typeof__(*obj) des = (DES); \
|
||||||
typeof(*obj) expval; \
|
__typeof__(*obj) expval; \
|
||||||
typeof(*obj) oldval = atomic_load(obj); \
|
__typeof__(*obj) oldval = atomic_load(obj); \
|
||||||
do { \
|
do { \
|
||||||
expval = oldval; \
|
expval = oldval; \
|
||||||
oldval = __sync_val_compare_and_swap( \
|
oldval = __sync_val_compare_and_swap( \
|
||||||
|
@ -78,10 +78,10 @@ typedef enum {
|
||||||
atomic_exchange((OBJ), (DES))
|
atomic_exchange((OBJ), (DES))
|
||||||
#define atomic_compare_exchange_strong(OBJ, EXP, DES) \
|
#define atomic_compare_exchange_strong(OBJ, EXP, DES) \
|
||||||
({ \
|
({ \
|
||||||
typeof(OBJ) obj = (OBJ); \
|
__typeof__(OBJ) obj = (OBJ); \
|
||||||
typeof(EXP) exp = (EXP); \
|
__typeof__(EXP) exp = (EXP); \
|
||||||
typeof(*obj) expval = *exp; \
|
__typeof__(*obj) expval = *exp; \
|
||||||
typeof(*obj) oldval = __sync_val_compare_and_swap( \
|
__typeof__(*obj) oldval = __sync_val_compare_and_swap( \
|
||||||
obj, expval, (DES)); \
|
obj, expval, (DES)); \
|
||||||
*exp = oldval; \
|
*exp = oldval; \
|
||||||
oldval == expval; \
|
oldval == expval; \
|
||||||
|
|
|
@ -20,6 +20,17 @@ extern "C" {
|
||||||
#define metal_align(n) __attribute__((aligned(n)))
|
#define metal_align(n) __attribute__((aligned(n)))
|
||||||
#define metal_weak __attribute__((weak))
|
#define metal_weak __attribute__((weak))
|
||||||
|
|
||||||
|
#if defined(__STRICT_ANSI__)
|
||||||
|
#define metal_asm __asm__
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* Even though __asm__ is always available in mainline GCC, we use asm in
|
||||||
|
* the non-strict modes for compatibility with other compilers that define
|
||||||
|
* __GNUC__
|
||||||
|
*/
|
||||||
|
#define metal_asm asm
|
||||||
|
#endif
|
||||||
|
|
||||||
#define METAL_PACKED_BEGIN
|
#define METAL_PACKED_BEGIN
|
||||||
#define METAL_PACKED_END __attribute__((__packed__))
|
#define METAL_PACKED_END __attribute__((__packed__))
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ extern "C" {
|
||||||
#define restrict __restrict__
|
#define restrict __restrict__
|
||||||
#define metal_align(n) __attribute__((aligned(n)))
|
#define metal_align(n) __attribute__((aligned(n)))
|
||||||
#define metal_weak __attribute__((weak))
|
#define metal_weak __attribute__((weak))
|
||||||
|
#define metal_asm asm
|
||||||
|
|
||||||
#define METAL_PACKED_BEGIN __packed
|
#define METAL_PACKED_BEGIN __packed
|
||||||
#define METAL_PACKED_END
|
#define METAL_PACKED_END
|
||||||
|
|
|
@ -274,16 +274,21 @@ metal_io_write(struct metal_io_region *io, unsigned long offset,
|
||||||
if (io->ops.write)
|
if (io->ops.write)
|
||||||
(*io->ops.write)(io, offset, value, order, width);
|
(*io->ops.write)(io, offset, value, order, width);
|
||||||
else if (ptr && sizeof(atomic_uchar) == width)
|
else if (ptr && sizeof(atomic_uchar) == width)
|
||||||
atomic_store_explicit((atomic_uchar *)ptr, value, order);
|
atomic_store_explicit((atomic_uchar *)ptr, (unsigned char)value,
|
||||||
|
order);
|
||||||
else if (ptr && sizeof(atomic_ushort) == width)
|
else if (ptr && sizeof(atomic_ushort) == width)
|
||||||
atomic_store_explicit((atomic_ushort *)ptr, value, order);
|
atomic_store_explicit((atomic_ushort *)ptr,
|
||||||
|
(unsigned short)value, order);
|
||||||
else if (ptr && sizeof(atomic_uint) == width)
|
else if (ptr && sizeof(atomic_uint) == width)
|
||||||
atomic_store_explicit((atomic_uint *)ptr, value, order);
|
atomic_store_explicit((atomic_uint *)ptr, (unsigned int)value,
|
||||||
|
order);
|
||||||
else if (ptr && sizeof(atomic_ulong) == width)
|
else if (ptr && sizeof(atomic_ulong) == width)
|
||||||
atomic_store_explicit((atomic_ulong *)ptr, value, order);
|
atomic_store_explicit((atomic_ulong *)ptr, (unsigned long)value,
|
||||||
|
order);
|
||||||
#ifndef NO_ATOMIC_64_SUPPORT
|
#ifndef NO_ATOMIC_64_SUPPORT
|
||||||
else if (ptr && sizeof(atomic_ullong) == width)
|
else if (ptr && sizeof(atomic_ullong) == width)
|
||||||
atomic_store_explicit((atomic_ullong *)ptr, value, order);
|
atomic_store_explicit((atomic_ullong *)ptr,
|
||||||
|
(unsigned long long)value, order);
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
metal_assert(0);
|
metal_assert(0);
|
||||||
|
|
|
@ -12,6 +12,11 @@
|
||||||
#ifndef __METAL_AARCH64_CPU__H__
|
#ifndef __METAL_AARCH64_CPU__H__
|
||||||
#define __METAL_AARCH64_CPU__H__
|
#define __METAL_AARCH64_CPU__H__
|
||||||
|
|
||||||
#define metal_cpu_yield() asm volatile("yield")
|
#include <metal/compiler.h>
|
||||||
|
|
||||||
|
static inline void metal_cpu_yield(void)
|
||||||
|
{
|
||||||
|
metal_asm volatile("yield");
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* __METAL_AARCH64_CPU__H__ */
|
#endif /* __METAL_AARCH64_CPU__H__ */
|
||||||
|
|
|
@ -12,6 +12,11 @@
|
||||||
#ifndef __METAL_X86_CPU__H__
|
#ifndef __METAL_X86_CPU__H__
|
||||||
#define __METAL_X86_CPU__H__
|
#define __METAL_X86_CPU__H__
|
||||||
|
|
||||||
#define metal_cpu_yield() asm volatile("rep; nop")
|
#include <metal/compiler.h>
|
||||||
|
|
||||||
|
static inline void metal_cpu_yield(void)
|
||||||
|
{
|
||||||
|
metal_asm volatile("rep; nop");
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* __METAL_X86_CPU__H__ */
|
#endif /* __METAL_X86_CPU__H__ */
|
||||||
|
|
|
@ -12,6 +12,11 @@
|
||||||
#ifndef __METAL_X86_64_CPU__H__
|
#ifndef __METAL_X86_64_CPU__H__
|
||||||
#define __METAL_X86_64_CPU__H__
|
#define __METAL_X86_64_CPU__H__
|
||||||
|
|
||||||
#define metal_cpu_yield() asm volatile("rep; nop")
|
#include <metal/compiler.h>
|
||||||
|
|
||||||
|
static inline void metal_cpu_yield(void)
|
||||||
|
{
|
||||||
|
metal_asm volatile("rep; nop");
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* __METAL_X86_64_CPU__H__ */
|
#endif /* __METAL_X86_64_CPU__H__ */
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#define __METAL_FREERTOS_MUTEX__H__
|
#define __METAL_FREERTOS_MUTEX__H__
|
||||||
|
|
||||||
#include <metal/atomic.h>
|
#include <metal/atomic.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -27,11 +26,14 @@ typedef struct {
|
||||||
atomic_int v;
|
atomic_int v;
|
||||||
} metal_mutex_t;
|
} metal_mutex_t;
|
||||||
|
|
||||||
|
#define METAL_MUTEX_UNLOCKED 0
|
||||||
|
#define METAL_MUTEX_LOCKED 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* METAL_MUTEX_INIT - used for initializing an mutex elmenet in a static struct
|
* METAL_MUTEX_INIT - used for initializing an mutex element in a static struct
|
||||||
* or global
|
* or global
|
||||||
*/
|
*/
|
||||||
#define METAL_MUTEX_INIT(m) { ATOMIC_VAR_INIT(0) }
|
#define METAL_MUTEX_INIT(m) { ATOMIC_VAR_INIT(METAL_MUTEX_UNLOCKED) }
|
||||||
/*
|
/*
|
||||||
* METAL_MUTEX_DEFINE - used for defining and initializing a global or
|
* METAL_MUTEX_DEFINE - used for defining and initializing a global or
|
||||||
* static singleton mutex
|
* static singleton mutex
|
||||||
|
@ -40,7 +42,7 @@ typedef struct {
|
||||||
|
|
||||||
static inline void __metal_mutex_init(metal_mutex_t *mutex)
|
static inline void __metal_mutex_init(metal_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
atomic_store(&mutex->v, 0);
|
atomic_store(&mutex->v, METAL_MUTEX_UNLOCKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void __metal_mutex_deinit(metal_mutex_t *mutex)
|
static inline void __metal_mutex_deinit(metal_mutex_t *mutex)
|
||||||
|
@ -50,19 +52,29 @@ static inline void __metal_mutex_deinit(metal_mutex_t *mutex)
|
||||||
|
|
||||||
static inline int __metal_mutex_try_acquire(metal_mutex_t *mutex)
|
static inline int __metal_mutex_try_acquire(metal_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
return 1 - atomic_flag_test_and_set(&mutex->v);
|
int unlocked = METAL_MUTEX_UNLOCKED;
|
||||||
|
|
||||||
|
if (atomic_compare_exchange_strong(&mutex->v, &unlocked,
|
||||||
|
METAL_MUTEX_LOCKED)) {
|
||||||
|
return 1; /* acquired */
|
||||||
|
} else {
|
||||||
|
return 0; /* not acquired */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void __metal_mutex_acquire(metal_mutex_t *mutex)
|
static inline void __metal_mutex_acquire(metal_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
while (atomic_flag_test_and_set(&mutex->v)) {
|
int unlocked = METAL_MUTEX_UNLOCKED;
|
||||||
|
|
||||||
|
while (!atomic_compare_exchange_weak(&mutex->v, &unlocked,
|
||||||
|
METAL_MUTEX_LOCKED)) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void __metal_mutex_release(metal_mutex_t *mutex)
|
static inline void __metal_mutex_release(metal_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
atomic_flag_clear(&mutex->v);
|
atomic_store(&mutex->v, METAL_MUTEX_UNLOCKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int __metal_mutex_is_acquired(metal_mutex_t *mutex)
|
static inline int __metal_mutex_is_acquired(metal_mutex_t *mutex)
|
||||||
|
|
|
@ -64,7 +64,7 @@ void metal_machine_cache_invalidate(void *addr, unsigned int len)
|
||||||
*/
|
*/
|
||||||
void metal_weak metal_generic_default_poll(void)
|
void metal_weak metal_generic_default_poll(void)
|
||||||
{
|
{
|
||||||
asm volatile("wfi");
|
metal_asm volatile("wfi");
|
||||||
}
|
}
|
||||||
|
|
||||||
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
||||||
|
|
|
@ -58,7 +58,7 @@ void metal_machine_cache_invalidate(void *addr, unsigned int len)
|
||||||
*/
|
*/
|
||||||
void metal_weak metal_generic_default_poll(void)
|
void metal_weak metal_generic_default_poll(void)
|
||||||
{
|
{
|
||||||
asm volatile("wfi");
|
metal_asm volatile("wfi");
|
||||||
}
|
}
|
||||||
|
|
||||||
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
||||||
|
|
|
@ -58,7 +58,7 @@ void metal_machine_cache_invalidate(void *addr, unsigned int len)
|
||||||
*/
|
*/
|
||||||
void metal_weak metal_generic_default_poll(void)
|
void metal_weak metal_generic_default_poll(void)
|
||||||
{
|
{
|
||||||
asm volatile("wfi");
|
metal_asm volatile("wfi");
|
||||||
}
|
}
|
||||||
|
|
||||||
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
||||||
|
|
|
@ -27,8 +27,8 @@ unsigned int sys_irq_save_disable(void)
|
||||||
{
|
{
|
||||||
unsigned int state;
|
unsigned int state;
|
||||||
|
|
||||||
asm volatile(" mfs %0, rmsr \n"
|
metal_asm volatile(" mfs %0, rmsr\n"
|
||||||
" msrclr r0, %1 \n"
|
" msrclr r0, %1\n"
|
||||||
: "=r"(state)
|
: "=r"(state)
|
||||||
: "i"(MSR_IE)
|
: "i"(MSR_IE)
|
||||||
: "memory");
|
: "memory");
|
||||||
|
@ -41,9 +41,9 @@ void sys_irq_restore_enable(unsigned int flags)
|
||||||
unsigned int tmp;
|
unsigned int tmp;
|
||||||
|
|
||||||
if (flags)
|
if (flags)
|
||||||
asm volatile(" msrset %0, %1 \n"
|
metal_asm volatile(" msrset %0, %1\n"
|
||||||
: "=r"(tmp)
|
: "=r"(tmp)
|
||||||
: "i"(MSR_IE)
|
: "i"(MSR_IE)
|
||||||
: "memory");
|
: "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,9 +52,9 @@ unsigned int sys_irq_save_disable(void)
|
||||||
{
|
{
|
||||||
unsigned int tmp, state;
|
unsigned int tmp, state;
|
||||||
|
|
||||||
asm volatile (" mfs %0, rmsr \n"
|
metal_asm volatile (" mfs %0, rmsr\n"
|
||||||
" andi %1, %0, %2 \n"
|
" andi %1, %0, %2\n"
|
||||||
" mts rmsr, %1 \n"
|
" mts rmsr, %1\n"
|
||||||
: "=r"(state), "=r"(tmp)
|
: "=r"(state), "=r"(tmp)
|
||||||
: "i"(~MSR_IE)
|
: "i"(~MSR_IE)
|
||||||
: "memory");
|
: "memory");
|
||||||
|
@ -67,9 +67,9 @@ void sys_irq_restore_enable(unsigned int flags)
|
||||||
unsigned int tmp;
|
unsigned int tmp;
|
||||||
|
|
||||||
if (flags)
|
if (flags)
|
||||||
asm volatile(" mfs %0, rmsr \n"
|
metal_asm volatile(" mfs %0, rmsr\n"
|
||||||
" or %0, %0, %1 \n"
|
" or %0, %0, %1\n"
|
||||||
" mts rmsr, %0 \n"
|
" mts rmsr, %0\n"
|
||||||
: "=r"(tmp)
|
: "=r"(tmp)
|
||||||
: "r"(flags)
|
: "r"(flags)
|
||||||
: "memory");
|
: "memory");
|
||||||
|
@ -135,7 +135,7 @@ void metal_machine_cache_invalidate(void *addr, unsigned int len)
|
||||||
*/
|
*/
|
||||||
void metal_weak metal_generic_default_poll(void)
|
void metal_weak metal_generic_default_poll(void)
|
||||||
{
|
{
|
||||||
asm volatile("nop");
|
metal_asm volatile("nop");
|
||||||
}
|
}
|
||||||
|
|
||||||
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
||||||
|
|
|
@ -26,11 +26,14 @@ typedef struct {
|
||||||
atomic_int v;
|
atomic_int v;
|
||||||
} metal_mutex_t;
|
} metal_mutex_t;
|
||||||
|
|
||||||
|
#define METAL_MUTEX_UNLOCKED 0
|
||||||
|
#define METAL_MUTEX_LOCKED 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* METAL_MUTEX_INIT - used for initializing an mutex elmenet in a static struct
|
* METAL_MUTEX_INIT - used for initializing an mutex element in a static struct
|
||||||
* or global
|
* or global
|
||||||
*/
|
*/
|
||||||
#define METAL_MUTEX_INIT(m) { ATOMIC_VAR_INIT(0) }
|
#define METAL_MUTEX_INIT(m) { ATOMIC_VAR_INIT(METAL_MUTEX_UNLOCKED) }
|
||||||
/*
|
/*
|
||||||
* METAL_MUTEX_DEFINE - used for defining and initializing a global or
|
* METAL_MUTEX_DEFINE - used for defining and initializing a global or
|
||||||
* static singleton mutex
|
* static singleton mutex
|
||||||
|
@ -39,7 +42,7 @@ typedef struct {
|
||||||
|
|
||||||
static inline void __metal_mutex_init(metal_mutex_t *mutex)
|
static inline void __metal_mutex_init(metal_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
atomic_store(&mutex->v, 0);
|
atomic_store(&mutex->v, METAL_MUTEX_UNLOCKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void __metal_mutex_deinit(metal_mutex_t *mutex)
|
static inline void __metal_mutex_deinit(metal_mutex_t *mutex)
|
||||||
|
@ -49,19 +52,29 @@ static inline void __metal_mutex_deinit(metal_mutex_t *mutex)
|
||||||
|
|
||||||
static inline int __metal_mutex_try_acquire(metal_mutex_t *mutex)
|
static inline int __metal_mutex_try_acquire(metal_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
return 1 - atomic_flag_test_and_set(&mutex->v);
|
int unlocked = METAL_MUTEX_UNLOCKED;
|
||||||
|
|
||||||
|
if (atomic_compare_exchange_strong(&mutex->v, &unlocked,
|
||||||
|
METAL_MUTEX_LOCKED)) {
|
||||||
|
return 1; /* acquired */
|
||||||
|
} else {
|
||||||
|
return 0; /* not acquired */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void __metal_mutex_acquire(metal_mutex_t *mutex)
|
static inline void __metal_mutex_acquire(metal_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
while (atomic_flag_test_and_set(&mutex->v)) {
|
int unlocked = METAL_MUTEX_UNLOCKED;
|
||||||
|
|
||||||
|
while (!atomic_compare_exchange_weak(&mutex->v, &unlocked,
|
||||||
|
METAL_MUTEX_LOCKED)) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void __metal_mutex_release(metal_mutex_t *mutex)
|
static inline void __metal_mutex_release(metal_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
atomic_flag_clear(&mutex->v);
|
atomic_store(&mutex->v, METAL_MUTEX_UNLOCKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int __metal_mutex_is_acquired(metal_mutex_t *mutex)
|
static inline int __metal_mutex_is_acquired(metal_mutex_t *mutex)
|
||||||
|
|
|
@ -61,7 +61,7 @@ void metal_machine_cache_invalidate(void *addr, unsigned int len)
|
||||||
*/
|
*/
|
||||||
void metal_weak metal_generic_default_poll(void)
|
void metal_weak metal_generic_default_poll(void)
|
||||||
{
|
{
|
||||||
asm volatile("wfi");
|
metal_asm volatile("wfi");
|
||||||
}
|
}
|
||||||
|
|
||||||
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
||||||
|
|
|
@ -58,7 +58,7 @@ void metal_machine_cache_invalidate(void *addr, unsigned int len)
|
||||||
*/
|
*/
|
||||||
void metal_weak metal_generic_default_poll(void)
|
void metal_weak metal_generic_default_poll(void)
|
||||||
{
|
{
|
||||||
asm volatile("wfi");
|
metal_asm volatile("wfi");
|
||||||
}
|
}
|
||||||
|
|
||||||
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
||||||
|
|
|
@ -58,7 +58,7 @@ void metal_machine_cache_invalidate(void *addr, unsigned int len)
|
||||||
*/
|
*/
|
||||||
void metal_weak metal_generic_default_poll(void)
|
void metal_weak metal_generic_default_poll(void)
|
||||||
{
|
{
|
||||||
asm volatile("wfi");
|
metal_asm volatile("wfi");
|
||||||
}
|
}
|
||||||
|
|
||||||
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
|
||||||
|
|
|
@ -18,7 +18,7 @@ unsigned long long metal_get_timestamp(void)
|
||||||
struct timespec tp;
|
struct timespec tp;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = clock_systimespec(&tp);
|
r = clock_systime_timespec(&tp);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
t = (unsigned long long)tp.tv_sec * NSEC_PER_SEC;
|
t = (unsigned long long)tp.tv_sec * NSEC_PER_SEC;
|
||||||
t += tp.tv_nsec;
|
t += tp.tv_nsec;
|
||||||
|
|
|
@ -18,5 +18,5 @@
|
||||||
*/
|
*/
|
||||||
void metal_weak metal_generic_default_poll(void)
|
void metal_weak metal_generic_default_poll(void)
|
||||||
{
|
{
|
||||||
__asm__ __volatile__("wfi");
|
metal_asm __volatile__("wfi");
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <metal/time.h>
|
#include <metal/time.h>
|
||||||
#include <sys_clock.h>
|
#include <kernel.h>
|
||||||
|
|
||||||
extern volatile uint64_t _sys_clock_tick_count;
|
|
||||||
|
|
||||||
unsigned long long metal_get_timestamp(void)
|
unsigned long long metal_get_timestamp(void)
|
||||||
{
|
{
|
||||||
return (unsigned long long)_sys_clock_tick_count;
|
return (unsigned long long)k_uptime_ticks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue