1 /*
2  * Copyright (c) 2018 Alexander Wachter
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/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 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, get_core_clock));
17 	Z_OOPS(z_user_from_copy(&res_copy, res, sizeof(res_copy)));
18 
19 	err = z_impl_can_calc_timing(dev, &res_copy, bitrate, sample_pnt);
20 	Z_OOPS(z_user_to_copy(res, &res_copy, sizeof(*res)));
21 
22 	return err;
23 }
24 #include <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 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_timing));
32 	Z_OOPS(z_user_from_copy(&timing_copy, timing, sizeof(timing_copy)));
33 
34 	return z_impl_can_set_timing(dev, &timing_copy);
35 }
36 #include <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 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, get_core_clock));
42 	Z_OOPS(Z_SYSCALL_MEMORY_WRITE(rate, sizeof(*rate)));
43 
44 	return z_impl_can_get_core_clock(dev, rate);
45 }
46 #include <syscalls/can_get_core_clock_mrsh.c>
47 
z_vrfy_can_get_max_bitrate(const struct device * dev,uint32_t * max_bitrate)48 static inline int z_vrfy_can_get_max_bitrate(const struct device *dev,
49 					     uint32_t *max_bitrate)
50 {
51 	/* Optional API function */
52 	Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
53 	Z_OOPS(Z_SYSCALL_MEMORY_WRITE(max_bitrate, sizeof(*max_bitrate)));
54 
55 	return z_impl_can_get_max_bitrate(dev, max_bitrate);
56 }
57 #include <syscalls/can_get_max_bitrate_mrsh.c>
58 
z_vrfy_can_get_timing_min(const struct device * dev)59 static inline const struct can_timing *z_vrfy_can_get_timing_min(const struct device *dev)
60 {
61 	Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
62 
63 	return z_impl_can_get_timing_min(dev);
64 }
65 #include <syscalls/can_get_timing_min_mrsh.c>
66 
z_vrfy_can_get_timing_max(const struct device * dev)67 static inline const struct can_timing *z_vrfy_can_get_timing_max(const struct device *dev)
68 {
69 	Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
70 
71 	return z_impl_can_get_timing_max(dev);
72 }
73 #include <syscalls/can_get_timing_max_mrsh.c>
74 
75 #ifdef CONFIG_CAN_FD_MODE
76 
z_vrfy_can_calc_timing_data(const struct device * dev,struct can_timing * res,uint32_t bitrate,uint16_t sample_pnt)77 static int z_vrfy_can_calc_timing_data(const struct device *dev, struct can_timing *res,
78 				       uint32_t bitrate, uint16_t sample_pnt)
79 {
80 	struct can_timing res_copy;
81 	int err;
82 
83 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, get_core_clock));
84 	Z_OOPS(z_user_from_copy(&res_copy, res, sizeof(res_copy)));
85 
86 	err = z_impl_can_calc_timing_data(dev, &res_copy, bitrate, sample_pnt);
87 	Z_OOPS(z_user_to_copy(res, &res_copy, sizeof(*res)));
88 
89 	return err;
90 }
91 #include <syscalls/can_calc_timing_data_mrsh.c>
92 
z_vrfy_can_get_timing_data_min(const struct device * dev)93 static inline const struct can_timing *z_vrfy_can_get_timing_data_min(const struct device *dev)
94 {
95 	Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
96 
97 	return z_impl_can_get_timing_data_min(dev);
98 }
99 #include <syscalls/can_get_timing_data_min_mrsh.c>
100 
z_vrfy_can_get_timing_data_max(const struct device * dev)101 static inline const struct can_timing *z_vrfy_can_get_timing_data_max(const struct device *dev)
102 {
103 	Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
104 
105 	return z_impl_can_get_timing_data_max(dev);
106 }
107 #include <syscalls/can_get_timing_data_max_mrsh.c>
108 
z_vrfy_can_set_timing_data(const struct device * dev,const struct can_timing * timing_data)109 static inline int z_vrfy_can_set_timing_data(const struct device *dev,
110 					     const struct can_timing *timing_data)
111 {
112 	struct can_timing timing_data_copy;
113 
114 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_timing_data));
115 	Z_OOPS(z_user_from_copy(&timing_data_copy, timing_data, sizeof(timing_data_copy)));
116 
117 	return z_impl_can_set_timing_data(dev, &timing_data_copy);
118 }
119 #include <syscalls/can_set_timing_data_mrsh.c>
120 
z_vrfy_can_set_bitrate_data(const struct device * dev,uint32_t bitrate_data)121 static inline int z_vrfy_can_set_bitrate_data(const struct device *dev,
122 					      uint32_t bitrate_data)
123 {
124 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_timing_data));
125 
126 	return z_impl_can_set_bitrate_data(dev, bitrate_data);
127 }
128 #include <syscalls/can_set_bitrate_data_mrsh.c>
129 
130 #endif /* CONFIG_CAN_FD_MODE */
131 
z_vrfy_can_get_max_filters(const struct device * dev,bool ide)132 static inline int z_vrfy_can_get_max_filters(const struct device *dev, bool ide)
133 {
134 	/* Optional API function */
135 	Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
136 
137 	return z_impl_can_get_max_filters(dev, ide);
138 }
139 #include <syscalls/can_get_max_filters_mrsh.c>
140 
z_vrfy_can_get_capabilities(const struct device * dev,can_mode_t * cap)141 static inline int z_vrfy_can_get_capabilities(const struct device *dev, can_mode_t *cap)
142 {
143 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, get_capabilities));
144 	Z_OOPS(Z_SYSCALL_MEMORY_WRITE(cap, sizeof(*cap)));
145 
146 	return z_impl_can_get_capabilities(dev, cap);
147 }
148 #include <syscalls/can_get_capabilities_mrsh.c>
149 
z_vrfy_can_start(const struct device * dev)150 static inline int z_vrfy_can_start(const struct device *dev)
151 {
152 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, start));
153 
154 	return z_impl_can_start(dev);
155 }
156 #include <syscalls/can_start_mrsh.c>
157 
z_vrfy_can_stop(const struct device * dev)158 static inline int z_vrfy_can_stop(const struct device *dev)
159 {
160 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, stop));
161 
162 	return z_impl_can_stop(dev);
163 }
164 #include <syscalls/can_stop_mrsh.c>
165 
z_vrfy_can_set_mode(const struct device * dev,can_mode_t mode)166 static inline int z_vrfy_can_set_mode(const struct device *dev, can_mode_t mode)
167 {
168 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_mode));
169 
170 	return z_impl_can_set_mode(dev, mode);
171 }
172 #include <syscalls/can_set_mode_mrsh.c>
173 
z_vrfy_can_set_bitrate(const struct device * dev,uint32_t bitrate)174 static inline int z_vrfy_can_set_bitrate(const struct device *dev, uint32_t bitrate)
175 {
176 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_timing));
177 
178 	return z_impl_can_set_bitrate(dev, bitrate);
179 }
180 #include <syscalls/can_set_bitrate_mrsh.c>
181 
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)182 static inline int z_vrfy_can_send(const struct device *dev,
183 				  const struct can_frame *frame,
184 				  k_timeout_t timeout,
185 				  can_tx_callback_t callback,
186 				  void *user_data)
187 {
188 	struct can_frame frame_copy;
189 
190 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, send));
191 	Z_OOPS(z_user_from_copy(&frame_copy, frame, sizeof(frame_copy)));
192 	Z_OOPS(Z_SYSCALL_VERIFY_MSG(callback == NULL, "callbacks may not be set from user mode"));
193 
194 	return z_impl_can_send(dev, &frame_copy, timeout, callback, user_data);
195 }
196 #include <syscalls/can_send_mrsh.c>
197 
z_vrfy_can_add_rx_filter_msgq(const struct device * dev,struct k_msgq * msgq,const struct can_filter * filter)198 static inline int z_vrfy_can_add_rx_filter_msgq(const struct device *dev,
199 						struct k_msgq *msgq,
200 						const struct can_filter *filter)
201 {
202 	struct can_filter filter_copy;
203 
204 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, add_rx_filter));
205 	Z_OOPS(Z_SYSCALL_OBJ(msgq, K_OBJ_MSGQ));
206 	Z_OOPS(z_user_from_copy(&filter_copy, filter, sizeof(filter_copy)));
207 
208 	return z_impl_can_add_rx_filter_msgq(dev, msgq, &filter_copy);
209 }
210 #include <syscalls/can_add_rx_filter_msgq_mrsh.c>
211 
z_vrfy_can_remove_rx_filter(const struct device * dev,int filter_id)212 static inline void z_vrfy_can_remove_rx_filter(const struct device *dev, int filter_id)
213 {
214 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, remove_rx_filter));
215 
216 	z_impl_can_remove_rx_filter(dev, filter_id);
217 }
218 #include <syscalls/can_remove_rx_filter_mrsh.c>
219 
z_vrfy_can_get_state(const struct device * dev,enum can_state * state,struct can_bus_err_cnt * err_cnt)220 static inline int z_vrfy_can_get_state(const struct device *dev, enum can_state *state,
221 				       struct can_bus_err_cnt *err_cnt)
222 {
223 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, get_state));
224 
225 	if (state != NULL) {
226 		Z_OOPS(Z_SYSCALL_MEMORY_WRITE(state, sizeof(*state)));
227 	}
228 
229 	if (err_cnt != NULL) {
230 		Z_OOPS(Z_SYSCALL_MEMORY_WRITE(err_cnt, sizeof(*err_cnt)));
231 	}
232 
233 	return z_impl_can_get_state(dev, state, err_cnt);
234 }
235 #include <syscalls/can_get_state_mrsh.c>
236 
237 #ifndef CONFIG_CAN_AUTO_BUS_OFF_RECOVERY
z_vrfy_can_recover(const struct device * dev,k_timeout_t timeout)238 static inline int z_vrfy_can_recover(const struct device *dev, k_timeout_t timeout)
239 {
240 	Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, recover));
241 
242 	return z_impl_can_recover(dev, timeout);
243 }
244 #include <syscalls/can_recover_mrsh.c>
245 #endif /* CONFIG_CAN_AUTO_BUS_OFF_RECOVERY */
246