summaryrefslogtreecommitdiff
path: root/FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_GCC/freedom-metal/metal/cache.h
blob: a8a60ada6ff322c42eb248a35592309412248109 (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
/* Copyright 2018 SiFive, Inc */
/* SPDX-License-Identifier: Apache-2.0 */

#ifndef METAL__CACHE_H
#define METAL__CACHE_H

/*!
 * @file cache.h
 *
 * @brief API for configuring caches
 */

struct metal_cache;

struct __metal_cache_vtable {
	void (*init)(struct metal_cache *cache, int ways);
	int (*get_enabled_ways)(struct metal_cache *cache);
	int (*set_enabled_ways)(struct metal_cache *cache, int ways);
};

/*!
 * @brief a handle for a cache
 */
struct metal_cache {
	const struct __metal_cache_vtable *vtable;
};

/*!
 * @brief Initialize a cache
 * @param cache The handle for the cache to initialize
 * @param ways The number of ways to enable
 *
 * Initializes a cache with the requested number of ways enabled.
 */
inline void metal_cache_init(struct metal_cache *cache, int ways) {
	return cache->vtable->init(cache, ways);
}

/*!
 * @brief Get the current number of enabled cache ways
 * @param cache The handle for the cache
 * @return The current number of enabled cache ways
 */
inline int metal_cache_get_enabled_ways(struct metal_cache *cache) {
	return cache->vtable->get_enabled_ways(cache);
}

/*!
 * @brief Enable the requested number of cache ways
 * @param cache The handle for the cache
 * @param ways The number of ways to enabled
 * @return 0 if the ways are successfully enabled
 */
inline int metal_cache_set_enabled_ways(struct metal_cache *cache, int ways) {
	return cache->vtable->set_enabled_ways(cache, ways);
}

#endif