blob: 3f182a4d04b9bf8800f068c4d23776e189371e5f [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001/*
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 */
13static inline void __sca_write64(uint64_t *ptr, uint64_t val)
14{
15 *ptr = val;
16}
Javier Almansa Sobrinoc4ad5b02022-07-05 19:05:14 +010017#define SCA_WRITE64(_p, _v) __sca_write64((uint64_t *)(_p), ((uint64_t)(_v)))
Soby Mathewb4c6df42022-11-09 11:13:29 +000018
19/* Single-Copy Atomic 64-bit write with RELEASE memory ordering semantics*/
20static inline void __sca_write64_release(uint64_t *ptr, uint64_t val)
21{
22 *ptr = val;
23}
Javier Almansa Sobrinoc4ad5b02022-07-05 19:05:14 +010024#define SCA_WRITE64_RELEASE(_p, _v) __sca_write64_release((uint64_t *)(_p), ((uint64_t)(_v)))
Soby Mathewb4c6df42022-11-09 11:13:29 +000025
26/* Single-Copy Atomic 64-bit read */
27static inline uint64_t __sca_read64(uint64_t *ptr)
28{
29 return *ptr;
30}
Javier Almansa Sobrinoc4ad5b02022-07-05 19:05:14 +010031#define SCA_READ64(_p) ((typeof(*(_p)))__sca_read64((uint64_t *)(_p)))
Soby Mathewb4c6df42022-11-09 11:13:29 +000032
33/* Single-Copy Atomic 64-bit read with ACQUIRE memory ordering semantics */
34static inline uint64_t __sca_read64_acquire(uint64_t *ptr)
35{
36 return *ptr;
37}
Javier Almansa Sobrinoc4ad5b02022-07-05 19:05:14 +010038#define SCA_READ64_ACQUIRE(_p) ((typeof(*(_p)))__sca_read64_acquire((uint64_t *)(_p)))
Soby Mathewb4c6df42022-11-09 11:13:29 +000039
40#endif /* MEMORY_H */