1 /*
2  * Copyright (c) 2018 Alexander Wachter
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/internal/syscall_handler.h>
8 #include <zephyr/drivers/can.h>
9 
z_vrfy_can_calc_timing(const struct device * dev,struct can_timing * res,uint32_t bitrate,uint16_t sample_pnt)10 static int z_vrfy_can_calc_timing(const struct device *dev, struct can_timing *res,
11 				  uint32_t bitrate, uint16_t sample_pnt)
12 {
13 	struct can_timing res_copy;
14 	int err;
15 
16 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, get_core_clock));
17 	K_OOPS(k_usermode_from_copy(&res_copy, res, sizeof(res_copy)));
18 
19 	err = z_impl_can_calc_timing(dev, &res_copy, bitrate, sample_pnt);
20 	K_OOPS(k_usermode_to_copy(res, &res_copy, sizeof(*res)));
21 
22 	return err;
23 }
24 #include <zephyr/syscalls/can_calc_timing_mrsh.c>
25 
z_vrfy_can_set_timing(const struct device * dev,const struct can_timing * timing)26 static inline int z_vrfy_can_set_timing(const struct device *dev,
27 					const struct can_timing *timing)
28 {
29 	struct can_timing timing_copy;
30 
31 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, set_timing));
32 	K_OOPS(k_usermode_from_copy(&timing_copy, timing, sizeof(timing_copy)));
33 
34 	return z_impl_can_set_timing(dev, &timing_copy);
35 }
36 #include <zephyr/syscalls/can_set_timing_mrsh.c>
37 
z_vrfy_can_get_core_clock(const struct device * dev,uint32_t * rate)38 static inline int z_vrfy_can_get_core_clock(const struct device *dev,
39 					    uint32_t *rate)
40 {
41 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, get_core_clock));
42 	K_OOPS(K_SYSCALL_MEMORY_WRITE(rate, sizeof(*rate)));
43 
44 	return z_impl_can_get_core_clock(dev, rate);
45 }
46 #include <zephyr/syscalls/can_get_core_clock_mrsh.c>
47 
z_vrfy_can_get_bitrate_min(const struct device * dev)48 static inline uint32_t z_vrfy_can_get_bitrate_min(const struct device *dev)
49 {
50 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
51 
52 	return z_impl_can_get_bitrate_min(dev);
53 }
54 #include <zephyr/syscalls/can_get_bitrate_min_mrsh.c>
55 
z_vrfy_can_get_bitrate_max(const struct device * dev)56 static inline uint32_t z_vrfy_can_get_bitrate_max(const struct device *dev)
57 {
58 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
59 
60 	return z_impl_can_get_bitrate_max(dev);
61 }
62 #include <zephyr/syscalls/can_get_bitrate_max_mrsh.c>
63 
z_vrfy_can_get_timing_min(const struct device * dev)64 static inline const struct can_timing *z_vrfy_can_get_timing_min(const struct device *dev)
65 {
66 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
67 
68 	return z_impl_can_get_timing_min(dev);
69 }
70 #include <zephyr/syscalls/can_get_timing_min_mrsh.c>
71 
z_vrfy_can_get_timing_max(const struct device * dev)72 static inline const struct can_timing *z_vrfy_can_get_timing_max(const struct device *dev)
73 {
74 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
75 
76 	return z_impl_can_get_timing_max(dev);
77 }
78 #include <zephyr/syscalls/can_get_timing_max_mrsh.c>
79 
80 #ifdef CONFIG_CAN_FD_MODE
81 
z_vrfy_can_calc_timing_data(const struct device * dev,struct can_timing * res,uint32_t bitrate,uint16_t sample_pnt)82 static int z_vrfy_can_calc_timing_data(const struct device *dev, struct can_timing *res,
83 				       uint32_t bitrate, uint16_t sample_pnt)
84 {
85 	struct can_timing res_copy;
86 	int err;
87 
88 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, get_core_clock));
89 	K_OOPS(k_usermode_from_copy(&res_copy, res, sizeof(res_copy)));
90 
91 	err = z_impl_can_calc_timing_data(dev, &res_copy, bitrate, sample_pnt);
92 	K_OOPS(k_usermode_to_copy(res, &res_copy, sizeof(*res)));
93 
94 	return err;
95 }
96 #include <zephyr/syscalls/can_calc_timing_data_mrsh.c>
97 
z_vrfy_can_get_timing_data_min(const struct device * dev)98 static inline const struct can_timing *z_vrfy_can_get_timing_data_min(const struct device *dev)
99 {
100 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
101 
102 	return z_impl_can_get_timing_data_min(dev);
103 }
104 #include <zephyr/syscalls/can_get_timing_data_min_mrsh.c>
105 
z_vrfy_can_get_timing_data_max(const struct device * dev)106 static inline const struct can_timing *z_vrfy_can_get_timing_data_max(const struct device *dev)
107 {
108 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
109 
110 	return z_impl_can_get_timing_data_max(dev);
111 }
112 #include <zephyr/syscalls/can_get_timing_data_max_mrsh.c>
113 
z_vrfy_can_set_timing_data(const struct device * dev,const struct can_timing * timing_data)114 static inline int z_vrfy_can_set_timing_data(const struct device *dev,
115 					     const struct can_timing *timing_data)
116 {
117 	struct can_timing timing_data_copy;
118 
119 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, set_timing_data));
120 	K_OOPS(k_usermode_from_copy(&timing_data_copy, timing_data, sizeof(timing_data_copy)));
121 
122 	return z_impl_can_set_timing_data(dev, &timing_data_copy);
123 }
124 #include <zephyr/syscalls/can_set_timing_data_mrsh.c>
125 
z_vrfy_can_set_bitrate_data(const struct device * dev,uint32_t bitrate_data)126 static inline int z_vrfy_can_set_bitrate_data(const struct device *dev,
127 					      uint32_t bitrate_data)
128 {
129 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, set_timing_data));
130 
131 	return z_impl_can_set_bitrate_data(dev, bitrate_data);
132 }
133 #include <zephyr/syscalls/can_set_bitrate_data_mrsh.c>
134 
135 #endif /* CONFIG_CAN_FD_MODE */
136 
z_vrfy_can_get_max_filters(const struct device * dev,bool ide)137 static inline int z_vrfy_can_get_max_filters(const struct device *dev, bool ide)
138 {
139 	/* Optional API function */
140 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
141 
142 	return z_impl_can_get_max_filters(dev, ide);
143 }
144 #include <zephyr/syscalls/can_get_max_filters_mrsh.c>
145 
z_vrfy_can_get_capabilities(const struct device * dev,can_mode_t * cap)146 static inline int z_vrfy_can_get_capabilities(const struct device *dev, can_mode_t *cap)
147 {
148 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, get_capabilities));
149 	K_OOPS(K_SYSCALL_MEMORY_WRITE(cap, sizeof(*cap)));
150 
151 	return z_impl_can_get_capabilities(dev, cap);
152 }
153 #include <zephyr/syscalls/can_get_capabilities_mrsh.c>
154 
z_vrfy_can_get_transceiver(const struct device * dev)155 static inline const struct device *z_vrfy_can_get_transceiver(const struct device *dev)
156 {
157 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
158 
159 	return z_impl_can_get_transceiver(dev);
160 }
161 #include <zephyr/syscalls/can_get_transceiver_mrsh.c>
162 
z_vrfy_can_start(const struct device * dev)163 static inline int z_vrfy_can_start(const struct device *dev)
164 {
165 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, start));
166 
167 	return z_impl_can_start(dev);
168 }
169 #include <zephyr/syscalls/can_start_mrsh.c>
170 
z_vrfy_can_stop(const struct device * dev)171 static inline int z_vrfy_can_stop(const struct device *dev)
172 {
173 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, stop));
174 
175 	return z_impl_can_stop(dev);
176 }
177 #include <zephyr/syscalls/can_stop_mrsh.c>
178 
z_vrfy_can_set_mode(const struct device * dev,can_mode_t mode)179 static inline int z_vrfy_can_set_mode(const struct device *dev, can_mode_t mode)
180 {
181 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, set_mode));
182 
183 	return z_impl_can_set_mode(dev, mode);
184 }
185 #include <zephyr/syscalls/can_set_mode_mrsh.c>
186 
z_vrfy_can_get_mode(const struct device * dev)187 static inline can_mode_t z_vrfy_can_get_mode(const struct device *dev)
188 {
189 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
190 
191 	return z_impl_can_get_mode(dev);
192 }
193 #include <zephyr/syscalls/can_get_mode_mrsh.c>
194 
z_vrfy_can_set_bitrate(const struct device * dev,uint32_t bitrate)195 static inline int z_vrfy_can_set_bitrate(const struct device *dev, uint32_t bitrate)
196 {
197 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, set_timing));
198 
199 	return z_impl_can_set_bitrate(dev, bitrate);
200 }
201 #include <zephyr/syscalls/can_set_bitrate_mrsh.c>
202 
z_vrfy_can_send(const struct device * dev,const struct can_frame * frame,k_timeout_t timeout,can_tx_callback_t callback,void * user_data)203 static inline int z_vrfy_can_send(const struct device *dev,
204 				  const struct can_frame *frame,
205 				  k_timeout_t timeout,
206 				  can_tx_callback_t callback,
207 				  void *user_data)
208 {
209 	struct can_frame frame_copy;
210 
211 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, send));
212 	K_OOPS(k_usermode_from_copy(&frame_copy, frame, sizeof(frame_copy)));
213 	K_OOPS(K_SYSCALL_VERIFY_MSG(callback == NULL, "callbacks may not be set from user mode"));
214 
215 	return z_impl_can_send(dev, &frame_copy, timeout, callback, user_data);
216 }
217 #include <zephyr/syscalls/can_send_mrsh.c>
218 
z_vrfy_can_add_rx_filter_msgq(const struct device * dev,struct k_msgq * msgq,const struct can_filter * filter)219 static inline int z_vrfy_can_add_rx_filter_msgq(const struct device *dev,
220 						struct k_msgq *msgq,
221 						const struct can_filter *filter)
222 {
223 	struct can_filter filter_copy;
224 
225 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, add_rx_filter));
226 	K_OOPS(K_SYSCALL_OBJ(msgq, K_OBJ_MSGQ));
227 	K_OOPS(k_usermode_from_copy(&filter_copy, filter, sizeof(filter_copy)));
228 
229 	return z_impl_can_add_rx_filter_msgq(dev, msgq, &filter_copy);
230 }
231 #include <zephyr/syscalls/can_add_rx_filter_msgq_mrsh.c>
232 
z_vrfy_can_remove_rx_filter(const struct device * dev,int filter_id)233 static inline void z_vrfy_can_remove_rx_filter(const struct device *dev, int filter_id)
234 {
235 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, remove_rx_filter));
236 
237 	z_impl_can_remove_rx_filter(dev, filter_id);
238 }
239 #include <zephyr/syscalls/can_remove_rx_filter_mrsh.c>
240 
z_vrfy_can_get_state(const struct device * dev,enum can_state * state,struct can_bus_err_cnt * err_cnt)241 static inline int z_vrfy_can_get_state(const struct device *dev, enum can_state *state,
242 				       struct can_bus_err_cnt *err_cnt)
243 {
244 	K_OOPS(K_SYSCALL_DRIVER_CAN(dev, get_state));
245 
246 	if (state != NULL) {
247 		K_OOPS(K_SYSCALL_MEMORY_WRITE(state, sizeof(*state)));
248 	}
249 
250 	if (err_cnt != NULL) {
251 		K_OOPS(K_SYSCALL_MEMORY_WRITE(err_cnt, sizeof(*err_cnt)));
252 	}
253 
254 	return z_impl_can_get_state(dev, state, err_cnt);
255 }
256 #include <zephyr/syscalls/can_get_state_mrsh.c>
257 
258 #ifdef CONFIG_CAN_MANUAL_RECOVERY_MODE
z_vrfy_can_recover(const struct device * dev,k_timeout_t timeout)259 static inline int z_vrfy_can_recover(const struct device *dev, k_timeout_t timeout)
260 {
261 	/* Optional API function */
262 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
263 
264 	return z_impl_can_recover(dev, timeout);
265 }
266 #include <zephyr/syscalls/can_recover_mrsh.c>
267 #endif /* CONFIG_CAN_MANUAL_RECOVERY_MODE */
268 
269 #ifdef CONFIG_CAN_STATS
270 
z_vrfy_can_stats_get_bit_errors(const struct device * dev)271 static inline uint32_t z_vrfy_can_stats_get_bit_errors(const struct device *dev)
272 {
273 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
274 
275 	return z_impl_can_stats_get_bit_errors(dev);
276 }
277 #include <zephyr/syscalls/can_stats_get_bit_errors_mrsh.c>
278 
z_vrfy_can_stats_get_bit0_errors(const struct device * dev)279 static inline uint32_t z_vrfy_can_stats_get_bit0_errors(const struct device *dev)
280 {
281 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
282 
283 	return z_impl_can_stats_get_bit0_errors(dev);
284 }
285 #include <zephyr/syscalls/can_stats_get_bit0_errors_mrsh.c>
286 
z_vrfy_can_stats_get_bit1_errors(const struct device * dev)287 static inline uint32_t z_vrfy_can_stats_get_bit1_errors(const struct device *dev)
288 {
289 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
290 
291 	return z_impl_can_stats_get_bit1_errors(dev);
292 }
293 #include <zephyr/syscalls/can_stats_get_bit1_errors_mrsh.c>
294 
z_vrfy_can_stats_get_stuff_errors(const struct device * dev)295 static inline uint32_t z_vrfy_can_stats_get_stuff_errors(const struct device *dev)
296 {
297 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
298 
299 	return z_impl_can_stats_get_stuff_errors(dev);
300 }
301 #include <zephyr/syscalls/can_stats_get_stuff_errors_mrsh.c>
302 
z_vrfy_can_stats_get_crc_errors(const struct device * dev)303 static inline uint32_t z_vrfy_can_stats_get_crc_errors(const struct device *dev)
304 {
305 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
306 
307 	return z_impl_can_stats_get_crc_errors(dev);
308 }
309 #include <zephyr/syscalls/can_stats_get_crc_errors_mrsh.c>
310 
z_vrfy_can_stats_get_form_errors(const struct device * dev)311 static inline uint32_t z_vrfy_can_stats_get_form_errors(const struct device *dev)
312 {
313 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
314 
315 	return z_impl_can_stats_get_form_errors(dev);
316 }
317 #include <zephyr/syscalls/can_stats_get_form_errors_mrsh.c>
318 
z_vrfy_can_stats_get_ack_errors(const struct device * dev)319 static inline uint32_t z_vrfy_can_stats_get_ack_errors(const struct device *dev)
320 {
321 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
322 
323 	return z_impl_can_stats_get_ack_errors(dev);
324 }
325 #include <zephyr/syscalls/can_stats_get_ack_errors_mrsh.c>
326 
z_vrfy_can_stats_get_rx_overruns(const struct device * dev)327 static inline uint32_t z_vrfy_can_stats_get_rx_overruns(const struct device *dev)
328 {
329 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
330 
331 	return z_impl_can_stats_get_rx_overruns(dev);
332 }
333 #include <zephyr/syscalls/can_stats_get_rx_overruns_mrsh.c>
334 
335 #endif /* CONFIG_CAN_STATS */
336