summaryrefslogtreecommitdiff
path: root/FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/bsp/install/include/metal/memory.h
blob: b62d8b25a3cf4db00c6010ff6eb2547cd1bc4c4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Copyright 2019 SiFive, Inc */
/* SPDX-License-Identifier: Apache-2.0 */

#ifndef METAL__MEMORY_H
#define METAL__MEMORY_H

#include <stdint.h>
#include <stddef.h>

/*!
 * @file memory.h
 *
 * @brief API for enumerating memory blocks
 */

struct _metal_memory_attributes {
	int R : 1;
	int W : 1;
	int X : 1;
	int C : 1;
	int A : 1;
};

/*!
 * @brief A handle for a memory block
 */
struct metal_memory {
	const uintptr_t _base_address;
	const size_t _size;
	const struct _metal_memory_attributes _attrs;
};

/*!
 * @brief Get the memory block which services the given address
 *
 * Given a physical memory address, get a handle for the memory block to which
 * that address is mapped.
 *
 * @param address The address to query
 * @return The memory block handle, or NULL if the address is not mapped to a memory block
 */
struct metal_memory *metal_get_memory_from_address(const uintptr_t address);

/*!
 * @brief Get the base address for a memory block
 * @param memory The handle for the memory block
 * @return The base address of the memory block
 */
inline uintptr_t metal_memory_get_base_address(const struct metal_memory *memory) {
	return memory->_base_address;
}

/*!
 * @brief Get the size of a memory block
 * @param memory The handle for the memory block
 * @return The size of the memory block
 */
inline size_t metal_memory_get_size(const struct metal_memory *memory) {
	return memory->_size;
}

/*!
 * @brief Query if a memory block supports atomic operations
 * @param memory The handle for the memory block
 * @return nonzero if the memory block supports atomic operations
 */
inline int metal_memory_supports_atomics(const struct metal_memory *memory) {
	return memory->_attrs.A;
}

/*!
 * @brief Query if a memory block is cacheable
 * @param memory The handle for the memory block
 * @return nonzero if the memory block is cachable
 */
inline int metal_memory_is_cachable(const struct metal_memory *memory) {
	return memory->_attrs.C;
}

#endif /* METAL__MEMORY_H */