Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | */ |
| 5 | |
| 6 | #ifndef MEMORY_H |
| 7 | #define MEMORY_H |
| 8 | |
| 9 | #include <stddef.h> |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | /* Single-Copy Atomic 64-bit write */ |
| 13 | static inline void __sca_write64(uint64_t *ptr, uint64_t val) |
| 14 | { |
| 15 | *ptr = val; |
| 16 | } |
| 17 | #define SCA_WRITE64(_p, _v) __sca_write64((void *)(_p), ((uint64_t)(_v))) |
| 18 | |
| 19 | /* Single-Copy Atomic 64-bit write with RELEASE memory ordering semantics*/ |
| 20 | static inline void __sca_write64_release(uint64_t *ptr, uint64_t val) |
| 21 | { |
| 22 | *ptr = val; |
| 23 | } |
| 24 | #define SCA_WRITE64_RELEASE(_p, _v) __sca_write64_release((void *)(_p), ((uint64_t)(_v))) |
| 25 | |
| 26 | /* Single-Copy Atomic 64-bit read */ |
| 27 | static inline uint64_t __sca_read64(uint64_t *ptr) |
| 28 | { |
| 29 | return *ptr; |
| 30 | } |
| 31 | #define SCA_READ64(_p) ((typeof(*(_p)))__sca_read64((void *)(_p))) |
| 32 | |
| 33 | /* Single-Copy Atomic 64-bit read with ACQUIRE memory ordering semantics */ |
| 34 | static inline uint64_t __sca_read64_acquire(uint64_t *ptr) |
| 35 | { |
| 36 | return *ptr; |
| 37 | } |
| 38 | #define SCA_READ64_ACQUIRE(_p) ((typeof(*(_p)))__sca_read64_acquire((void *)(_p))) |
| 39 | |
| 40 | #endif /* MEMORY_H */ |