1 /*
2  * Copyright (c) 2020 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/drivers/espi.h>
8 #include <zephyr/syscall_handler.h>
9 
10 
z_vrfy_espi_config(const struct device * dev,struct espi_cfg * cfg)11 static inline int z_vrfy_espi_config(const struct device *dev,
12 				     struct espi_cfg *cfg)
13 {
14 	struct  espi_cfg cfg_copy;
15 
16 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, config));
17 	Z_OOPS(z_user_from_copy(&cfg_copy, cfg,
18 				sizeof(struct espi_cfg)));
19 
20 	return z_impl_espi_config(dev, &cfg_copy);
21 }
22 #include <syscalls/espi_config_mrsh.c>
23 
z_vrfy_espi_get_channel_status(const struct device * dev,enum espi_channel ch)24 static inline bool z_vrfy_espi_get_channel_status(const struct device *dev,
25 						  enum espi_channel ch)
26 {
27 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, get_channel_status));
28 
29 	return z_impl_espi_get_channel_status(dev, ch);
30 }
31 #include <syscalls/espi_get_channel_status_mrsh.c>
32 
z_vrfy_espi_read_lpc_request(const struct device * dev,enum lpc_peripheral_opcode op,uint32_t * data)33 static inline int z_vrfy_espi_read_lpc_request(const struct device *dev,
34 					       enum lpc_peripheral_opcode op,
35 					       uint32_t *data)
36 {
37 	int ret;
38 	uint32_t data_copy;
39 
40 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, read_lpc_request));
41 
42 	ret = z_impl_espi_read_lpc_request(dev, op, &data_copy);
43 	Z_OOPS(z_user_to_copy(data, &data_copy, sizeof(uint8_t)));
44 
45 	return ret;
46 }
47 #include <syscalls/espi_read_lpc_request_mrsh.c>
48 
z_vrfy_espi_write_lpc_request(const struct device * dev,enum lpc_peripheral_opcode op,uint32_t * data)49 static inline int z_vrfy_espi_write_lpc_request(const struct device *dev,
50 						enum lpc_peripheral_opcode op,
51 						uint32_t *data)
52 {
53 	uint32_t data_copy;
54 
55 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, write_lpc_request));
56 	Z_OOPS(z_user_from_copy(&data_copy, data, sizeof(*data)));
57 
58 	return z_impl_espi_write_lpc_request(dev, op, &data_copy);
59 }
60 #include <syscalls/espi_write_lpc_request_mrsh.c>
61 
z_vrfy_espi_send_vwire(const struct device * dev,enum espi_vwire_signal signal,uint8_t level)62 static inline int z_vrfy_espi_send_vwire(const struct device *dev,
63 					 enum espi_vwire_signal signal,
64 					 uint8_t level)
65 {
66 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, send_vwire));
67 
68 	return z_impl_espi_send_vwire(dev, signal, level);
69 }
70 #include <syscalls/espi_send_vwire_mrsh.c>
71 
z_vrfy_espi_receive_vwire(const struct device * dev,enum espi_vwire_signal signal,uint8_t * level)72 static inline int z_vrfy_espi_receive_vwire(const struct device *dev,
73 					    enum espi_vwire_signal signal,
74 					    uint8_t *level)
75 {
76 	int ret;
77 	uint8_t level_copy;
78 
79 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, receive_vwire));
80 
81 	ret = z_impl_espi_receive_vwire(dev, signal, &level_copy);
82 	Z_OOPS(z_user_to_copy(level, &level_copy, sizeof(uint8_t)));
83 
84 	return ret;
85 }
86 #include <syscalls/espi_receive_vwire_mrsh.c>
87 
z_vrfy_espi_read_request(const struct device * dev,struct espi_request_packet * req)88 static inline int z_vrfy_espi_read_request(const struct device *dev,
89 					   struct espi_request_packet *req)
90 {
91 	int ret;
92 	struct  espi_request_packet req_copy;
93 
94 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, read_request));
95 	Z_OOPS(z_user_from_copy(&req_copy, req,
96 				sizeof(struct espi_request_packet)));
97 	Z_OOPS(Z_SYSCALL_MEMORY_WRITE(req_copy.data, req_copy.len));
98 
99 	ret = z_impl_espi_read_request(dev, &req_copy);
100 
101 	Z_OOPS(z_user_to_copy(req, &req_copy,
102 			      sizeof(struct espi_request_packet)));
103 
104 	return ret;
105 }
106 #include <syscalls/espi_read_request_mrsh.c>
107 
z_vrfy_espi_write_request(const struct device * dev,struct espi_request_packet * req)108 static inline int z_vrfy_espi_write_request(const struct device *dev,
109 					    struct espi_request_packet *req)
110 {
111 	int ret;
112 	struct  espi_request_packet req_copy;
113 
114 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, write_request));
115 	Z_OOPS(Z_SYSCALL_MEMORY_READ(req->data, req->len));
116 	Z_OOPS(z_user_from_copy(&req_copy, req,
117 				sizeof(struct espi_request_packet)));
118 
119 	ret = z_impl_espi_write_request(dev, &req_copy);
120 
121 	return ret;
122 }
123 #include <syscalls/espi_write_request_mrsh.c>
124 
z_vrfy_espi_send_oob(const struct device * dev,struct espi_oob_packet * pckt)125 static inline int z_vrfy_espi_send_oob(const struct device *dev,
126 				       struct espi_oob_packet *pckt)
127 {
128 	int ret;
129 	struct  espi_oob_packet pckt_copy;
130 
131 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, send_oob));
132 	Z_OOPS(Z_SYSCALL_MEMORY_READ(pckt->buf, pckt->len));
133 	Z_OOPS(z_user_from_copy(&pckt_copy, pckt,
134 				sizeof(struct espi_oob_packet)));
135 
136 	ret = z_impl_espi_send_oob(dev, &pckt_copy);
137 
138 	return ret;
139 }
140 #include <syscalls/espi_send_oob_mrsh.c>
141 
z_vrfy_espi_receive_oob(const struct device * dev,struct espi_oob_packet * pckt)142 static inline int z_vrfy_espi_receive_oob(const struct device *dev,
143 					  struct espi_oob_packet *pckt)
144 {
145 	int ret;
146 	struct  espi_oob_packet pckt_copy;
147 
148 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, receive_oob));
149 	Z_OOPS(z_user_from_copy(&pckt_copy, pckt,
150 				sizeof(struct espi_oob_packet)));
151 	Z_OOPS(Z_SYSCALL_MEMORY_WRITE(pckt->buf, pckt->len));
152 
153 	ret = z_impl_espi_receive_oob(dev, &pckt_copy);
154 	Z_OOPS(z_user_to_copy(pckt, &pckt_copy,
155 			      sizeof(struct espi_oob_packet)));
156 
157 	return ret;
158 }
159 #include <syscalls/espi_receive_oob_mrsh.c>
160 
z_vrfy_espi_read_flash(const struct device * dev,struct espi_flash_packet * pckt)161 static inline int z_vrfy_espi_read_flash(const struct device *dev,
162 					 struct espi_flash_packet *pckt)
163 {
164 	int ret;
165 	struct  espi_flash_packet pckt_copy;
166 
167 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, flash_read));
168 	Z_OOPS(z_user_from_copy(&pckt_copy, pckt,
169 				sizeof(struct espi_flash_packet)));
170 	Z_OOPS(Z_SYSCALL_MEMORY_WRITE(pckt->buf, pckt->len));
171 
172 	ret = z_impl_espi_read_flash(dev, pckt);
173 	Z_OOPS(z_user_to_copy(pckt, &pckt_copy,
174 			      sizeof(struct espi_flash_packet)));
175 
176 	return ret;
177 }
178 #include <syscalls/espi_read_flash_mrsh.c>
179 
z_vrfy_espi_write_flash(const struct device * dev,struct espi_flash_packet * pckt)180 static inline int z_vrfy_espi_write_flash(const struct device *dev,
181 					  struct espi_flash_packet *pckt)
182 {
183 	int ret;
184 	struct  espi_flash_packet pckt_copy;
185 
186 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, flash_write));
187 	Z_OOPS(z_user_from_copy(&pckt_copy, pckt,
188 				sizeof(struct espi_flash_packet)));
189 	Z_OOPS(Z_SYSCALL_MEMORY_READ(pckt->buf, pckt->len));
190 
191 	ret = z_impl_espi_write_flash(dev, &pckt_copy);
192 
193 	return ret;
194 }
195 #include <syscalls/espi_write_flash_mrsh.c>
196 
z_vrfy_espi_flash_erase(const struct device * dev,struct espi_flash_packet * pckt)197 static inline int z_vrfy_espi_flash_erase(const struct device *dev,
198 					  struct espi_flash_packet *pckt)
199 {
200 	int ret;
201 	struct  espi_flash_packet pckt_copy;
202 
203 	Z_OOPS(Z_SYSCALL_DRIVER_ESPI(dev, flash_write));
204 	Z_OOPS(z_user_from_copy(&pckt_copy, pckt,
205 				sizeof(struct espi_flash_packet)));
206 	Z_OOPS(Z_SYSCALL_MEMORY_READ(pckt->buf, pckt->len));
207 
208 	ret = z_impl_espi_flash_erase(dev, &pckt_copy);
209 
210 	return ret;
211 }
212 #include <syscalls/espi_flash_erase_mrsh.c>
213