1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
10 * @brief API for configuring caches
15 struct __metal_cache_vtable {
16 void (*init)(struct metal_cache *cache, int ways);
17 int (*get_enabled_ways)(struct metal_cache *cache);
18 int (*set_enabled_ways)(struct metal_cache *cache, int ways);
22 * @brief a handle for a cache
25 const struct __metal_cache_vtable *vtable;
29 * @brief Initialize a cache
30 * @param cache The handle for the cache to initialize
31 * @param ways The number of ways to enable
33 * Initializes a cache with the requested number of ways enabled.
35 inline void metal_cache_init(struct metal_cache *cache, int ways) {
36 return cache->vtable->init(cache, ways);
40 * @brief Get the current number of enabled cache ways
41 * @param cache The handle for the cache
42 * @return The current number of enabled cache ways
44 inline int metal_cache_get_enabled_ways(struct metal_cache *cache) {
45 return cache->vtable->get_enabled_ways(cache);
49 * @brief Enable the requested number of cache ways
50 * @param cache The handle for the cache
51 * @param ways The number of ways to enabled
52 * @return 0 if the ways are successfully enabled
54 inline int metal_cache_set_enabled_ways(struct metal_cache *cache, int ways) {
55 return cache->vtable->set_enabled_ways(cache, ways);