]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/freedom-metal/metal/memory.h
Update RISCC-V-RV32-SiFive_HiFive1_FreedomStudio project to latest tools and metal...
[freertos] / FreeRTOS / Demo / RISC-V_RV32_SiFive_HiFive1_FreedomStudio / freedom-metal / metal / memory.h
1 /* Copyright 2019 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
3
4 #ifndef METAL__MEMORY_H
5 #define METAL__MEMORY_H
6
7 #include <stdint.h>
8 #include <stddef.h>
9
10 /*!
11  * @file memory.h
12  *
13  * @brief API for enumerating memory blocks
14  */
15
16 struct _metal_memory_attributes {
17         unsigned int R : 1;
18         unsigned int W : 1;
19         unsigned int X : 1;
20         unsigned int C : 1;
21         unsigned int A : 1;
22 };
23
24 /*!
25  * @brief A handle for a memory block
26  */
27 struct metal_memory {
28         const uintptr_t _base_address;
29         const size_t _size;
30         const struct _metal_memory_attributes _attrs;
31 };
32
33 /*!
34  * @brief Get the memory block which services the given address
35  *
36  * Given a physical memory address, get a handle for the memory block to which
37  * that address is mapped.
38  *
39  * @param address The address to query
40  * @return The memory block handle, or NULL if the address is not mapped to a memory block
41  */
42 struct metal_memory *metal_get_memory_from_address(const uintptr_t address);
43
44 /*!
45  * @brief Get the base address for a memory block
46  * @param memory The handle for the memory block
47  * @return The base address of the memory block
48  */
49 __inline__ uintptr_t metal_memory_get_base_address(const struct metal_memory *memory) {
50         return memory->_base_address;
51 }
52
53 /*!
54  * @brief Get the size of a memory block
55  * @param memory The handle for the memory block
56  * @return The size of the memory block
57  */
58 __inline__ size_t metal_memory_get_size(const struct metal_memory *memory) {
59         return memory->_size;
60 }
61
62 /*!
63  * @brief Query if a memory block supports atomic operations
64  * @param memory The handle for the memory block
65  * @return nonzero if the memory block supports atomic operations
66  */
67 __inline__ int metal_memory_supports_atomics(const struct metal_memory *memory) {
68         return memory->_attrs.A;
69 }
70
71 /*!
72  * @brief Query if a memory block is cacheable
73  * @param memory The handle for the memory block
74  * @return nonzero if the memory block is cachable
75  */
76 __inline__ int metal_memory_is_cachable(const struct metal_memory *memory) {
77         return memory->_attrs.C;
78 }
79
80 #endif /* METAL__MEMORY_H */
81