diff options
author | Anup Patel <apatel@ventanamicro.com> | 2023-06-05 12:22:37 +0530 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2023-06-05 15:42:50 +0530 |
commit | aad7a377051136c2e0f4adeea2689167a294d2b4 (patch) | |
tree | fe26dd981339ae0f2f4d72aeda7d6869ed14d9cd | |
parent | bdde2ecd27af1ac158669809f6658376fb5137ab (diff) | |
download | opensbi-aad7a377051136c2e0f4adeea2689167a294d2b4.zip opensbi-aad7a377051136c2e0f4adeea2689167a294d2b4.tar.gz opensbi-aad7a377051136c2e0f4adeea2689167a294d2b4.tar.bz2 |
include: sbi_scratch: Add helper macros to access data type
Reading and writing a data type in scratch space is a very common
use-case so let us add related helper macros in sbi_scratch.h.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
-rw-r--r-- | include/sbi/sbi_scratch.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h index 2966188..58f2d06 100644 --- a/include/sbi/sbi_scratch.h +++ b/include/sbi/sbi_scratch.h @@ -174,6 +174,23 @@ void sbi_scratch_free_offset(unsigned long offset); #define sbi_scratch_thishart_offset_ptr(offset) \ (void *)((char *)sbi_scratch_thishart_ptr() + (offset)) +/** Allocate offset for a data type in sbi_scratch */ +#define sbi_scratch_alloc_type_offset(__type) \ + sbi_scratch_alloc_offset(sizeof(__type)) + +/** Read a data type from sbi_scratch at given offset */ +#define sbi_scratch_read_type(__scratch, __type, __offset) \ +({ \ + *((__type *)sbi_scratch_offset_ptr((__scratch), (__offset))); \ +}) + +/** Write a data type to sbi_scratch at given offset */ +#define sbi_scratch_write_type(__scratch, __type, __offset, __ptr) \ +do { \ + *((__type *)sbi_scratch_offset_ptr((__scratch), (__offset))) \ + = (__type)(__ptr); \ +} while (0) + /** HART id to scratch table */ extern struct sbi_scratch *hartid_to_scratch_table[]; |