summaryrefslogtreecommitdiff
path: root/include/sbi/sbi_hart_protection.h
blob: cafe6ee710f287b959ba63b945cc11c81ecbdf17 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2025 Ventana Micro Systems Inc.
 */

#ifndef __SBI_HART_PROTECTION_H__
#define __SBI_HART_PROTECTION_H__

#include <sbi/sbi_types.h>
#include <sbi/sbi_list.h>

struct sbi_scratch;
struct sbi_domain;

/** Different types of hart protection mechanisms */
enum sbi_hart_protection_type {
	SBI_HART_PROTECTION_TYPE_MEMORY = 0,
	SBI_HART_PROTECTION_TYPE_ID,
	SBI_HART_PROTECTION_TYPE_MAX
};

/** Representation of hart protection mechanism */
struct sbi_hart_protection {
	/** List head */
	struct sbi_dlist head;

	/** Name of the hart protection mechanism */
	char name[32];

	/** Type of the hart protection mechanism */
	enum sbi_hart_protection_type type;

	/** Ratings of the hart protection mechanism (higher is better) */
	unsigned long rating;

	/** Configure protection for current HART (Mandatory) */
	int (*configure)(struct sbi_scratch *scratch, struct sbi_domain *dom);

	/** Unconfigure protection for current HART (Optional) */
	void (*unconfigure)(struct sbi_scratch *scratch, struct sbi_domain *dom);

	/** Create temporary mapping to access address range on current HART (Optional) */
	int (*map_range)(struct sbi_scratch *scratch,
			 unsigned long base, unsigned long size);

	/** Destroy temporary mapping on current HART (Optional) */
	int (*unmap_range)(struct sbi_scratch *scratch,
			   unsigned long base, unsigned long size);
};

/**
 * Get a string containing names of protection mechanisms
 *
 * @param out_str pointer to output string
 * @param out_str_size maximum size of output string
 *
 * @return pointer to best hart memory protection mechanism
 */
void sbi_hart_protection_get_str(char *out_str, int out_str_size);

/**
 * Register a hart protection mechanism
 *
 * @param hprot pointer to hart protection mechanism
 *
 * @return 0 on success and negative error code on failure
 */
int sbi_hart_protection_register(struct sbi_hart_protection *hprot);

/**
 * Unregister a hart protection mechanism
 *
 * @param hprot pointer to hart protection mechanism
 */
void sbi_hart_protection_unregister(struct sbi_hart_protection *hprot);

/**
 * Configure protection for current HART
 *
 * @param scratch pointer to scratch space of current HART
 * @param dom pointer to the domain for which HART protection
 *        is being configured
 *
 * @return 0 on success and negative error code on failure
 */
int sbi_hart_protection_configure(struct sbi_scratch *scratch,
				  struct sbi_domain *dom);

/**
 * Unconfigure protection for current HART
 *
 * @param scratch pointer to scratch space of current HART
 * @param dom pointer to the domain for which HART protection
 *        is being unconfigured
 */
void sbi_hart_protection_unconfigure(struct sbi_scratch *scratch,
				     struct sbi_domain *dom);

/**
 * Re-configure protection for current HART
 *
 * @param scratch pointer to scratch space of current HART
 * @param current_dom pointer to the current domain for which
 *        HART protection is being unconfigured
 * @param next_dom pointer to the next domain for which HART
 *        protection is being configured
 */
int sbi_hart_protection_reconfigure(struct sbi_scratch *scratch,
				    struct sbi_domain *current_dom,
				    struct sbi_domain *next_dom);

/**
 * Create temporary mapping to access address range on current HART
 *
 * @param base base address of the temporary mapping
 * @param size size of the temporary mapping
 *
 * @return 0 on success and negative error code on failure
 */
int sbi_hart_protection_map_range(unsigned long base, unsigned long size);

/**
 * Destroy temporary mapping to access address range on current HART
 *
 * @param base base address of the temporary mapping
 * @param size size of the temporary mapping
 *
 * @return 0 on success and negative error code on failure
 */
int sbi_hart_protection_unmap_range(unsigned long base, unsigned long size);

#endif /* __SBI_HART_PROTECTION_H__ */