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 | } |
Javier Almansa Sobrino | c4ad5b0 | 2022-07-05 19:05:14 +0100 | [diff] [blame] | 17 | #define SCA_WRITE64(_p, _v) __sca_write64((uint64_t *)(_p), ((uint64_t)(_v))) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 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 | } |
Javier Almansa Sobrino | c4ad5b0 | 2022-07-05 19:05:14 +0100 | [diff] [blame] | 24 | #define SCA_WRITE64_RELEASE(_p, _v) __sca_write64_release((uint64_t *)(_p), ((uint64_t)(_v))) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 25 | |
| 26 | /* Single-Copy Atomic 64-bit read */ |
| 27 | static inline uint64_t __sca_read64(uint64_t *ptr) |
| 28 | { |
| 29 | return *ptr; |
| 30 | } |
Javier Almansa Sobrino | c4ad5b0 | 2022-07-05 19:05:14 +0100 | [diff] [blame] | 31 | #define SCA_READ64(_p) ((typeof(*(_p)))__sca_read64((uint64_t *)(_p))) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 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 | } |
Javier Almansa Sobrino | c4ad5b0 | 2022-07-05 19:05:14 +0100 | [diff] [blame] | 38 | #define SCA_READ64_ACQUIRE(_p) ((typeof(*(_p)))__sca_read64_acquire((uint64_t *)(_p))) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 39 | |
AlexeiFedorov | d6d93d8 | 2024-02-13 16:52:11 +0000 | [diff] [blame] | 40 | /* Single-Copy Atomic 16-bit read */ |
| 41 | static inline uint16_t __sca_read16(uint16_t *ptr) |
| 42 | { |
| 43 | return *ptr; |
| 44 | } |
| 45 | #define SCA_READ16(_p) ((typeof(*(_p)))__sca_read16((uint16_t *)(_p))) |
| 46 | |
| 47 | /* Single-Copy Atomic 16-bit read with ACQUIRE memory ordering semantics */ |
| 48 | static inline uint16_t __sca_read16_acquire(uint16_t *ptr) |
| 49 | { |
| 50 | return *ptr; |
| 51 | } |
| 52 | #define SCA_READ16_ACQUIRE(_p) ((typeof(*(_p)))__sca_read16_acquire((uint16_t *)(_p))) |
| 53 | |
| 54 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 55 | #endif /* MEMORY_H */ |