File: cache.c

package info (click to toggle)
opensbi 1.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,480 kB
  • sloc: ansic: 34,934; python: 4,658; asm: 1,113; makefile: 639; sh: 329
file content (46 lines) | stat: -rw-r--r-- 740 bytes parent folder | download
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
/*
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2025 SiFive Inc.
 */

#include <sbi/sbi_error.h>
#include <sbi_utils/cache/cache.h>

static SBI_LIST_HEAD(cache_list);

struct cache_device *cache_find(u32 id)
{
	struct cache_device *dev;

	sbi_list_for_each_entry(dev, &cache_list, node) {
		if (dev->id == id)
			return dev;
	}

	return NULL;
}

int cache_add(struct cache_device *dev)
{
	if (!dev)
		return SBI_ENODEV;

	if (cache_find(dev->id))
		return SBI_EALREADY;

	sbi_list_add(&dev->node, &cache_list);

	return SBI_OK;
}

int cache_flush_all(struct cache_device *dev)
{
	if (!dev)
		return SBI_ENODEV;

	if (!dev->ops || !dev->ops->cache_flush_all)
		return SBI_ENOTSUPP;

	return dev->ops->cache_flush_all(dev);
}