xref: /freebsd/sys/sys/bus_san.h (revision 9768746b)
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  * $FreeBSD$
37  */
38 
39 #ifndef _SYS_BUS_SAN_H_
40 #define	_SYS_BUS_SAN_H_
41 
42 #ifndef _MACHINE_BUS_H_
43 #error do not include this header, use machine/bus.h
44 #endif
45 
46 #define	BUS_SAN_MULTI(sp, rw, width, type)				\
47 	void sp##_bus_space_##rw##_multi_##width(bus_space_tag_t, 	\
48 	    bus_space_handle_t, bus_size_t, type *, bus_size_t);	\
49 	void sp##_bus_space_##rw##_multi_stream_##width(bus_space_tag_t, \
50 	    bus_space_handle_t, bus_size_t, type *, bus_size_t);	\
51 	void sp##_bus_space_##rw##_region_##width(bus_space_tag_t,	\
52 	    bus_space_handle_t, bus_size_t, type *, bus_size_t);	\
53 	void sp##_bus_space_##rw##_region_stream_##width(bus_space_tag_t, \
54 	    bus_space_handle_t, bus_size_t, type *, bus_size_t)
55 
56 #define	BUS_SAN_READ(sp, width, type)					\
57 	type sp##_bus_space_read_##width(bus_space_tag_t, 		\
58 	    bus_space_handle_t, bus_size_t);				\
59 	type sp##_bus_space_read_stream_##width(bus_space_tag_t,	\
60 	    bus_space_handle_t, bus_size_t);				\
61 	BUS_SAN_MULTI(sp, read, width, type)
62 
63 #define	BUS_SAN_WRITE(sp, width, type)					\
64 	void sp##_bus_space_write_##width(bus_space_tag_t, 		\
65 	    bus_space_handle_t, bus_size_t, type);			\
66 	void sp##_bus_space_write_stream_##width(bus_space_tag_t,	\
67 	    bus_space_handle_t, bus_size_t, type);			\
68 	BUS_SAN_MULTI(sp, write, width, const type)
69 
70 #define	BUS_SAN_SET(sp, width, type)					\
71 	void sp##_bus_space_set_multi_##width(bus_space_tag_t,		\
72 	    bus_space_handle_t, bus_size_t, type, bus_size_t);		\
73 	void sp##_bus_space_set_multi_stream_##width(bus_space_tag_t,	\
74 	    bus_space_handle_t, bus_size_t, type, bus_size_t);		\
75 	void sp##_bus_space_set_region_##width(bus_space_tag_t,		\
76 	    bus_space_handle_t, bus_size_t, type, bus_size_t);		\
77 	void sp##_bus_space_set_region_stream_##width(bus_space_tag_t,	\
78 	    bus_space_handle_t, bus_size_t, type, bus_size_t)
79 
80 #define	BUS_SAN_COPY(sp, width, type)					\
81 	void sp##_bus_space_copy_region_##width(bus_space_tag_t,	\
82 	    bus_space_handle_t,	bus_size_t, bus_space_handle_t,		\
83 	    bus_size_t, bus_size_t);					\
84 	void sp##_bus_space_copy_region_stream_##width(bus_space_tag_t, \
85 	    bus_space_handle_t,	bus_size_t, bus_space_handle_t,		\
86 	    bus_size_t, bus_size_t);
87 
88 #define	BUS_SAN_PEEK(sp, width, type)					\
89 	int sp##_bus_space_peek_##width(bus_space_tag_t, 		\
90 	    bus_space_handle_t, bus_size_t, type *);
91 
92 #define	BUS_SAN_POKE(sp, width, type)					\
93 	int sp##_bus_space_poke_##width(bus_space_tag_t, 		\
94 	    bus_space_handle_t, bus_size_t, type);
95 
96 #define	_BUS_SAN_MISC(sp)						\
97 	int sp##_bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,	\
98 	    int, bus_space_handle_t *);					\
99 	void sp##_bus_space_unmap(bus_space_tag_t, bus_space_handle_t,	\
100 	    bus_size_t);						\
101 	int sp##_bus_space_subregion(bus_space_tag_t, bus_space_handle_t,\
102 	    bus_size_t, bus_size_t, bus_space_handle_t *);		\
103 	int sp##_bus_space_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t,\
104 	    bus_size_t, bus_size_t, bus_size_t, int, bus_addr_t *,	\
105 	    bus_space_handle_t *);					\
106 	void sp##_bus_space_free(bus_space_tag_t, bus_space_handle_t,	\
107 	    bus_size_t);						\
108 	void sp##_bus_space_barrier(bus_space_tag_t, bus_space_handle_t,\
109 	    bus_size_t, bus_size_t, int);
110 
111 #define	BUS_SAN_MISC(sp)						\
112 	_BUS_SAN_MISC(sp)
113 
114 #define	_BUS_SAN_FUNCS(sp, width, type)					\
115 	BUS_SAN_READ(sp, width, type);					\
116 	BUS_SAN_WRITE(sp, width, type);					\
117 	BUS_SAN_SET(sp, width, type);					\
118 	BUS_SAN_COPY(sp, width, type)					\
119 	BUS_SAN_PEEK(sp, width, type);					\
120 	BUS_SAN_POKE(sp, width, type)
121 
122 #define	BUS_SAN_FUNCS(width, type)					\
123 	_BUS_SAN_FUNCS(SAN_INTERCEPTOR_PREFIX, width, type)
124 
125 BUS_SAN_FUNCS(1, uint8_t);
126 BUS_SAN_FUNCS(2, uint16_t);
127 BUS_SAN_FUNCS(4, uint32_t);
128 BUS_SAN_FUNCS(8, uint64_t);
129 BUS_SAN_MISC(SAN_INTERCEPTOR_PREFIX);
130 
131 #ifndef SAN_RUNTIME
132 
133 #define	BUS_SAN(func)							\
134 	__CONCAT(SAN_INTERCEPTOR_PREFIX, __CONCAT(_bus_space_, func))
135 
136 #define	bus_space_map			BUS_SAN(map)
137 #define	bus_space_unmap			BUS_SAN(unmap)
138 #define	bus_space_subregion		BUS_SAN(subregion)
139 #define	bus_space_alloc			BUS_SAN(alloc)
140 #define	bus_space_free			BUS_SAN(free)
141 #define	bus_space_barrier		BUS_SAN(barrier)
142 
143 #define	bus_space_read_1		BUS_SAN(read_1)
144 #define	bus_space_read_stream_1		BUS_SAN(read_stream_1)
145 #define	bus_space_read_multi_1		BUS_SAN(read_multi_1)
146 #define	bus_space_read_multi_stream_1	BUS_SAN(read_multi_stream_1)
147 #define	bus_space_read_region_1		BUS_SAN(read_region_1)
148 #define	bus_space_read_region_stream_1	BUS_SAN(read_region_stream_1)
149 #define	bus_space_write_1		BUS_SAN(write_1)
150 #define	bus_space_write_stream_1	BUS_SAN(write_stream_1)
151 #define	bus_space_write_multi_1		BUS_SAN(write_multi_1)
152 #define	bus_space_write_multi_stream_1	BUS_SAN(write_multi_stream_1)
153 #define	bus_space_write_region_1	BUS_SAN(write_region_1)
154 #define	bus_space_write_region_stream_1	BUS_SAN(write_region_stream_1)
155 #define	bus_space_set_multi_1		BUS_SAN(set_multi_1)
156 #define	bus_space_set_multi_stream_1	BUS_SAN(set_multi_stream_1)
157 #define	bus_space_set_region_1		BUS_SAN(set_region_1)
158 #define	bus_space_set_region_stream_1	BUS_SAN(set_region_stream_1)
159 #define	bus_space_copy_multi_1		BUS_SAN(copy_multi_1)
160 #define	bus_space_copy_multi_stream_1	BUS_SAN(copy_multi_stream_1)
161 #define	bus_space_poke_1		BUS_SAN(poke_1)
162 #define	bus_space_peek_1		BUS_SAN(peek_1)
163 
164 #define	bus_space_read_2		BUS_SAN(read_2)
165 #define	bus_space_read_stream_2		BUS_SAN(read_stream_2)
166 #define	bus_space_read_multi_2		BUS_SAN(read_multi_2)
167 #define	bus_space_read_multi_stream_2	BUS_SAN(read_multi_stream_2)
168 #define	bus_space_read_region_2		BUS_SAN(read_region_2)
169 #define	bus_space_read_region_stream_2	BUS_SAN(read_region_stream_2)
170 #define	bus_space_write_2		BUS_SAN(write_2)
171 #define	bus_space_write_stream_2	BUS_SAN(write_stream_2)
172 #define	bus_space_write_multi_2		BUS_SAN(write_multi_2)
173 #define	bus_space_write_multi_stream_2	BUS_SAN(write_multi_stream_2)
174 #define	bus_space_write_region_2	BUS_SAN(write_region_2)
175 #define	bus_space_write_region_stream_2	BUS_SAN(write_region_stream_2)
176 #define	bus_space_set_multi_2		BUS_SAN(set_multi_2)
177 #define	bus_space_set_multi_stream_2	BUS_SAN(set_multi_stream_2)
178 #define	bus_space_set_region_2		BUS_SAN(set_region_2)
179 #define	bus_space_set_region_stream_2	BUS_SAN(set_region_stream_2)
180 #define	bus_space_copy_multi_2		BUS_SAN(copy_multi_2)
181 #define	bus_space_copy_multi_stream_2	BUS_SAN(copy_multi_stream_2)
182 #define	bus_space_poke_2		BUS_SAN(poke_2)
183 #define	bus_space_peek_2		BUS_SAN(peek_2)
184 
185 #define	bus_space_read_4		BUS_SAN(read_4)
186 #define	bus_space_read_stream_4		BUS_SAN(read_stream_4)
187 #define	bus_space_read_multi_4		BUS_SAN(read_multi_4)
188 #define	bus_space_read_multi_stream_4	BUS_SAN(read_multi_stream_4)
189 #define	bus_space_read_region_4		BUS_SAN(read_region_4)
190 #define	bus_space_read_region_stream_4	BUS_SAN(read_region_stream_4)
191 #define	bus_space_write_4		BUS_SAN(write_4)
192 #define	bus_space_write_stream_4	BUS_SAN(write_stream_4)
193 #define	bus_space_write_multi_4		BUS_SAN(write_multi_4)
194 #define	bus_space_write_multi_stream_4	BUS_SAN(write_multi_stream_4)
195 #define	bus_space_write_region_4	BUS_SAN(write_region_4)
196 #define	bus_space_write_region_stream_4	BUS_SAN(write_region_stream_4)
197 #define	bus_space_set_multi_4		BUS_SAN(set_multi_4)
198 #define	bus_space_set_multi_stream_4	BUS_SAN(set_multi_stream_4)
199 #define	bus_space_set_region_4		BUS_SAN(set_region_4)
200 #define	bus_space_set_region_stream_4	BUS_SAN(set_region_stream_4)
201 #define	bus_space_copy_multi_4		BUS_SAN(copy_multi_4)
202 #define	bus_space_copy_multi_stream_4	BUS_SAN(copy_multi_stream_4)
203 #define	bus_space_poke_4		BUS_SAN(poke_4)
204 #define	bus_space_peek_4		BUS_SAN(peek_4)
205 
206 #define	bus_space_read_8		BUS_SAN(read_8)
207 #define	bus_space_read_stream_8		BUS_SAN(read_stream_8)
208 #define	bus_space_read_multi_8		BUS_SAN(read_multi_8)
209 #define	bus_space_read_multi_stream_8	BUS_SAN(read_multi_stream_8)
210 #define	bus_space_read_region_8		BUS_SAN(read_region_8)
211 #define	bus_space_read_region_stream_8	BUS_SAN(read_region_stream_8)
212 #define	bus_space_write_8		BUS_SAN(write_8)
213 #define	bus_space_write_stream_8	BUS_SAN(write_stream_8)
214 #define	bus_space_write_multi_8		BUS_SAN(write_multi_8)
215 #define	bus_space_write_multi_stream_8	BUS_SAN(write_multi_stream_8)
216 #define	bus_space_write_region_8	BUS_SAN(write_region_8)
217 #define	bus_space_write_region_stream_8	BUS_SAN(write_region_stream_8)
218 #define	bus_space_set_multi_8		BUS_SAN(set_multi_8)
219 #define	bus_space_set_multi_stream_8	BUS_SAN(set_multi_stream_8)
220 #define	bus_space_set_region_8		BUS_SAN(set_region_8)
221 #define	bus_space_set_region_stream_8	BUS_SAN(set_region_stream_8)
222 #define	bus_space_copy_multi_8		BUS_SAN(copy_multi_8)
223 #define	bus_space_copy_multi_stream_8	BUS_SAN(copy_multi_stream_8)
224 #define	bus_space_poke_8		BUS_SAN(poke_8)
225 #define	bus_space_peek_8		BUS_SAN(peek_8)
226 
227 #endif /* !SAN_RUNTIME */
228 
229 #endif /* !_SYS_BUS_SAN_H_ */
230