1 /* Copyright 2019 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
4 #ifndef METAL__MEMORY_H
5 #define METAL__MEMORY_H
13 * @brief API for enumerating memory blocks
16 struct _metal_memory_attributes {
25 * @brief A handle for a memory block
28 const uintptr_t _base_address;
30 const struct _metal_memory_attributes _attrs;
34 * @brief Get the memory block which services the given address
36 * Given a physical memory address, get a handle for the memory block to which
37 * that address is mapped.
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
42 struct metal_memory *metal_get_memory_from_address(const uintptr_t address);
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
49 inline uintptr_t metal_memory_get_base_address(const struct metal_memory *memory) {
50 return memory->_base_address;
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
58 inline size_t metal_memory_get_size(const struct metal_memory *memory) {
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
67 inline int metal_memory_supports_atomics(const struct metal_memory *memory) {
68 return memory->_attrs.A;
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
76 inline int metal_memory_is_cachable(const struct metal_memory *memory) {
77 return memory->_attrs.C;
80 #endif /* METAL__MEMORY_H */