xref: /freebsd/sys/sys/bus_san.h (revision 95ee2897)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2019 Andrew Turner
5  * Copyright (c) 2021 The FreeBSD Foundation
6  *
7  * This software was developed by SRI International and the University of
8  * Cambridge Computer Laboratory (Department of Computer Science and
9  * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
10  * DARPA SSITH research programme.
11  *
12  * Portions of this software were written by Mark Johnston under sponsorship by
13  * the FreeBSD Foundation.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the distribution.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  */
36 
37 #ifndef _SYS_BUS_SAN_H_
38 #define	_SYS_BUS_SAN_H_
39 
40 #ifndef _MACHINE_BUS_H_
41 #error do not include this header, use machine/bus.h
42 #endif
43 
44 #define	BUS_SAN_MULTI(sp, rw, width, type)				\
45 	void sp##_bus_space_##rw##_multi_##width(bus_space_tag_t, 	\
46 	    bus_space_handle_t, bus_size_t, type *, bus_size_t);	\
47 	void sp##_bus_space_##rw##_multi_stream_##width(bus_space_tag_t, \
48 	    bus_space_handle_t, bus_size_t, type *, bus_size_t);	\
49 	void sp##_bus_space_##rw##_region_##width(bus_space_tag_t,	\
50 	    bus_space_handle_t, bus_size_t, type *, bus_size_t);	\
51 	void sp##_bus_space_##rw##_region_stream_##width(bus_space_tag_t, \
52 	    bus_space_handle_t, bus_size_t, type *, bus_size_t)
53 
54 #define	BUS_SAN_READ(sp, width, type)					\
55 	type sp##_bus_space_read_##width(bus_space_tag_t, 		\
56 	    bus_space_handle_t, bus_size_t);				\
57 	type sp##_bus_space_read_stream_##width(bus_space_tag_t,	\
58 	    bus_space_handle_t, bus_size_t);				\
59 	BUS_SAN_MULTI(sp, read, width, type)
60 
61 #define	BUS_SAN_WRITE(sp, width, type)					\
62 	void sp##_bus_space_write_##width(bus_space_tag_t, 		\
63 	    bus_space_handle_t, bus_size_t, type);			\
64 	void sp##_bus_space_write_stream_##width(bus_space_tag_t,	\
65 	    bus_space_handle_t, bus_size_t, type);			\
66 	BUS_SAN_MULTI(sp, write, width, const type)
67 
68 #define	BUS_SAN_SET(sp, width, type)					\
69 	void sp##_bus_space_set_multi_##width(bus_space_tag_t,		\
70 	    bus_space_handle_t, bus_size_t, type, bus_size_t);		\
71 	void sp##_bus_space_set_multi_stream_##width(bus_space_tag_t,	\
72 	    bus_space_handle_t, bus_size_t, type, bus_size_t);		\
73 	void sp##_bus_space_set_region_##width(bus_space_tag_t,		\
74 	    bus_space_handle_t, bus_size_t, type, bus_size_t);		\
75 	void sp##_bus_space_set_region_stream_##width(bus_space_tag_t,	\
76 	    bus_space_handle_t, bus_size_t, type, bus_size_t)
77 
78 #define	BUS_SAN_COPY(sp, width, type)					\
79 	void sp##_bus_space_copy_region_##width(bus_space_tag_t,	\
80 	    bus_space_handle_t,	bus_size_t, bus_space_handle_t,		\
81 	    bus_size_t, bus_size_t);					\
82 	void sp##_bus_space_copy_region_stream_##width(bus_space_tag_t, \
83 	    bus_space_handle_t,	bus_size_t, bus_space_handle_t,		\
84 	    bus_size_t, bus_size_t);
85 
86 #define	BUS_SAN_PEEK(sp, width, type)					\
87 	int sp##_bus_space_peek_##width(bus_space_tag_t, 		\
88 	    bus_space_handle_t, bus_size_t, type *);
89 
90 #define	BUS_SAN_POKE(sp, width, type)					\
91 	int sp##_bus_space_poke_##width(bus_space_tag_t, 		\
92 	    bus_space_handle_t, bus_size_t, type);
93 
94 #define	_BUS_SAN_MISC(sp)						\
95 	int sp##_bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,	\
96 	    int, bus_space_handle_t *);					\
97 	void sp##_bus_space_unmap(bus_space_tag_t, bus_space_handle_t,	\
98 	    bus_size_t);						\
99 	int sp##_bus_space_subregion(bus_space_tag_t, bus_space_handle_t,\
100 	    bus_size_t, bus_size_t, bus_space_handle_t *);		\
101 	int sp##_bus_space_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t,\
102 	    bus_size_t, bus_size_t, bus_size_t, int, bus_addr_t *,	\
103 	    bus_space_handle_t *);					\
104 	void sp##_bus_space_free(bus_space_tag_t, bus_space_handle_t,	\
105 	    bus_size_t);						\
106 	void sp##_bus_space_barrier(bus_space_tag_t, bus_space_handle_t,\
107 	    bus_size_t, bus_size_t, int);
108 
109 #define	BUS_SAN_MISC(sp)						\
110 	_BUS_SAN_MISC(sp)
111 
112 #define	_BUS_SAN_FUNCS(sp, width, type)					\
113 	BUS_SAN_READ(sp, width, type);					\
114 	BUS_SAN_WRITE(sp, width, type);					\
115 	BUS_SAN_SET(sp, width, type);					\
116 	BUS_SAN_COPY(sp, width, type)					\
117 	BUS_SAN_PEEK(sp, width, type);					\
118 	BUS_SAN_POKE(sp, width, type)
119 
120 #define	BUS_SAN_FUNCS(width, type)					\
121 	_BUS_SAN_FUNCS(SAN_INTERCEPTOR_PREFIX, width, type)
122 
123 BUS_SAN_FUNCS(1, uint8_t);
124 BUS_SAN_FUNCS(2, uint16_t);
125 BUS_SAN_FUNCS(4, uint32_t);
126 BUS_SAN_FUNCS(8, uint64_t);
127 BUS_SAN_MISC(SAN_INTERCEPTOR_PREFIX);
128 
129 #ifndef SAN_RUNTIME
130 
131 #define	BUS_SAN(func)							\
132 	__CONCAT(SAN_INTERCEPTOR_PREFIX, __CONCAT(_bus_space_, func))
133 
134 #define	bus_space_map			BUS_SAN(map)
135 #define	bus_space_unmap			BUS_SAN(unmap)
136 #define	bus_space_subregion		BUS_SAN(subregion)
137 #define	bus_space_alloc			BUS_SAN(alloc)
138 #define	bus_space_free			BUS_SAN(free)
139 #define	bus_space_barrier		BUS_SAN(barrier)
140 
141 #define	bus_space_read_1		BUS_SAN(read_1)
142 #define	bus_space_read_stream_1		BUS_SAN(read_stream_1)
143 #define	bus_space_read_multi_1		BUS_SAN(read_multi_1)
144 #define	bus_space_read_multi_stream_1	BUS_SAN(read_multi_stream_1)
145 #define	bus_space_read_region_1		BUS_SAN(read_region_1)
146 #define	bus_space_read_region_stream_1	BUS_SAN(read_region_stream_1)
147 #define	bus_space_write_1		BUS_SAN(write_1)
148 #define	bus_space_write_stream_1	BUS_SAN(write_stream_1)
149 #define	bus_space_write_multi_1		BUS_SAN(write_multi_1)
150 #define	bus_space_write_multi_stream_1	BUS_SAN(write_multi_stream_1)
151 #define	bus_space_write_region_1	BUS_SAN(write_region_1)
152 #define	bus_space_write_region_stream_1	BUS_SAN(write_region_stream_1)
153 #define	bus_space_set_multi_1		BUS_SAN(set_multi_1)
154 #define	bus_space_set_multi_stream_1	BUS_SAN(set_multi_stream_1)
155 #define	bus_space_set_region_1		BUS_SAN(set_region_1)
156 #define	bus_space_set_region_stream_1	BUS_SAN(set_region_stream_1)
157 #define	bus_space_copy_multi_1		BUS_SAN(copy_multi_1)
158 #define	bus_space_copy_multi_stream_1	BUS_SAN(copy_multi_stream_1)
159 #define	bus_space_poke_1		BUS_SAN(poke_1)
160 #define	bus_space_peek_1		BUS_SAN(peek_1)
161 
162 #define	bus_space_read_2		BUS_SAN(read_2)
163 #define	bus_space_read_stream_2		BUS_SAN(read_stream_2)
164 #define	bus_space_read_multi_2		BUS_SAN(read_multi_2)
165 #define	bus_space_read_multi_stream_2	BUS_SAN(read_multi_stream_2)
166 #define	bus_space_read_region_2		BUS_SAN(read_region_2)
167 #define	bus_space_read_region_stream_2	BUS_SAN(read_region_stream_2)
168 #define	bus_space_write_2		BUS_SAN(write_2)
169 #define	bus_space_write_stream_2	BUS_SAN(write_stream_2)
170 #define	bus_space_write_multi_2		BUS_SAN(write_multi_2)
171 #define	bus_space_write_multi_stream_2	BUS_SAN(write_multi_stream_2)
172 #define	bus_space_write_region_2	BUS_SAN(write_region_2)
173 #define	bus_space_write_region_stream_2	BUS_SAN(write_region_stream_2)
174 #define	bus_space_set_multi_2		BUS_SAN(set_multi_2)
175 #define	bus_space_set_multi_stream_2	BUS_SAN(set_multi_stream_2)
176 #define	bus_space_set_region_2		BUS_SAN(set_region_2)
177 #define	bus_space_set_region_stream_2	BUS_SAN(set_region_stream_2)
178 #define	bus_space_copy_multi_2		BUS_SAN(copy_multi_2)
179 #define	bus_space_copy_multi_stream_2	BUS_SAN(copy_multi_stream_2)
180 #define	bus_space_poke_2		BUS_SAN(poke_2)
181 #define	bus_space_peek_2		BUS_SAN(peek_2)
182 
183 #define	bus_space_read_4		BUS_SAN(read_4)
184 #define	bus_space_read_stream_4		BUS_SAN(read_stream_4)
185 #define	bus_space_read_multi_4		BUS_SAN(read_multi_4)
186 #define	bus_space_read_multi_stream_4	BUS_SAN(read_multi_stream_4)
187 #define	bus_space_read_region_4		BUS_SAN(read_region_4)
188 #define	bus_space_read_region_stream_4	BUS_SAN(read_region_stream_4)
189 #define	bus_space_write_4		BUS_SAN(write_4)
190 #define	bus_space_write_stream_4	BUS_SAN(write_stream_4)
191 #define	bus_space_write_multi_4		BUS_SAN(write_multi_4)
192 #define	bus_space_write_multi_stream_4	BUS_SAN(write_multi_stream_4)
193 #define	bus_space_write_region_4	BUS_SAN(write_region_4)
194 #define	bus_space_write_region_stream_4	BUS_SAN(write_region_stream_4)
195 #define	bus_space_set_multi_4		BUS_SAN(set_multi_4)
196 #define	bus_space_set_multi_stream_4	BUS_SAN(set_multi_stream_4)
197 #define	bus_space_set_region_4		BUS_SAN(set_region_4)
198 #define	bus_space_set_region_stream_4	BUS_SAN(set_region_stream_4)
199 #define	bus_space_copy_multi_4		BUS_SAN(copy_multi_4)
200 #define	bus_space_copy_multi_stream_4	BUS_SAN(copy_multi_stream_4)
201 #define	bus_space_poke_4		BUS_SAN(poke_4)
202 #define	bus_space_peek_4		BUS_SAN(peek_4)
203 
204 #define	bus_space_read_8		BUS_SAN(read_8)
205 #define	bus_space_read_stream_8		BUS_SAN(read_stream_8)
206 #define	bus_space_read_multi_8		BUS_SAN(read_multi_8)
207 #define	bus_space_read_multi_stream_8	BUS_SAN(read_multi_stream_8)
208 #define	bus_space_read_region_8		BUS_SAN(read_region_8)
209 #define	bus_space_read_region_stream_8	BUS_SAN(read_region_stream_8)
210 #define	bus_space_write_8		BUS_SAN(write_8)
211 #define	bus_space_write_stream_8	BUS_SAN(write_stream_8)
212 #define	bus_space_write_multi_8		BUS_SAN(write_multi_8)
213 #define	bus_space_write_multi_stream_8	BUS_SAN(write_multi_stream_8)
214 #define	bus_space_write_region_8	BUS_SAN(write_region_8)
215 #define	bus_space_write_region_stream_8	BUS_SAN(write_region_stream_8)
216 #define	bus_space_set_multi_8		BUS_SAN(set_multi_8)
217 #define	bus_space_set_multi_stream_8	BUS_SAN(set_multi_stream_8)
218 #define	bus_space_set_region_8		BUS_SAN(set_region_8)
219 #define	bus_space_set_region_stream_8	BUS_SAN(set_region_stream_8)
220 #define	bus_space_copy_multi_8		BUS_SAN(copy_multi_8)
221 #define	bus_space_copy_multi_stream_8	BUS_SAN(copy_multi_stream_8)
222 #define	bus_space_poke_8		BUS_SAN(poke_8)
223 #define	bus_space_peek_8		BUS_SAN(peek_8)
224 
225 #endif /* !SAN_RUNTIME */
226 
227 #endif /* !_SYS_BUS_SAN_H_ */
228