1 /*
2 * Copyright (c) 2017 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/drivers/uart.h>
8 #include <zephyr/internal/syscall_handler.h>
9
10 #define UART_SIMPLE(op_) \
11 static inline int z_vrfy_uart_##op_(const struct device *dev) \
12 { \
13 K_OOPS(K_SYSCALL_DRIVER_UART(dev, op_)); \
14 return z_impl_uart_ ## op_(dev); \
15 }
16
17 #define UART_SIMPLE_VOID(op_) \
18 static inline void z_vrfy_uart_##op_(const struct device *dev) \
19 { \
20 K_OOPS(K_SYSCALL_DRIVER_UART(dev, op_)); \
21 z_impl_uart_ ## op_(dev); \
22 }
23
UART_SIMPLE(err_check)24 UART_SIMPLE(err_check)
25 #include <zephyr/syscalls/uart_err_check_mrsh.c>
26
27 static inline int z_vrfy_uart_poll_in(const struct device *dev,
28 unsigned char *p_char)
29 {
30 K_OOPS(K_SYSCALL_DRIVER_UART(dev, poll_in));
31 K_OOPS(K_SYSCALL_MEMORY_WRITE(p_char, sizeof(unsigned char)));
32 return z_impl_uart_poll_in(dev, p_char);
33 }
34 #include <zephyr/syscalls/uart_poll_in_mrsh.c>
35
z_vrfy_uart_poll_in_u16(const struct device * dev,uint16_t * p_u16)36 static inline int z_vrfy_uart_poll_in_u16(const struct device *dev,
37 uint16_t *p_u16)
38 {
39 K_OOPS(K_SYSCALL_DRIVER_UART(dev, poll_in));
40 K_OOPS(K_SYSCALL_MEMORY_WRITE(p_u16, sizeof(uint16_t)));
41 return z_impl_uart_poll_in_u16(dev, p_u16);
42 }
43 #include <zephyr/syscalls/uart_poll_in_u16_mrsh.c>
44
z_vrfy_uart_poll_out(const struct device * dev,unsigned char out_char)45 static inline void z_vrfy_uart_poll_out(const struct device *dev,
46 unsigned char out_char)
47 {
48 K_OOPS(K_SYSCALL_DRIVER_UART(dev, poll_out));
49 z_impl_uart_poll_out((const struct device *)dev, out_char);
50 }
51 #include <zephyr/syscalls/uart_poll_out_mrsh.c>
52
z_vrfy_uart_poll_out_u16(const struct device * dev,uint16_t out_u16)53 static inline void z_vrfy_uart_poll_out_u16(const struct device *dev,
54 uint16_t out_u16)
55 {
56 K_OOPS(K_SYSCALL_DRIVER_UART(dev, poll_out));
57 z_impl_uart_poll_out_u16((const struct device *)dev, out_u16);
58 }
59 #include <zephyr/syscalls/uart_poll_out_u16_mrsh.c>
60
61 #ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
z_vrfy_uart_config_get(const struct device * dev,struct uart_config * cfg)62 static inline int z_vrfy_uart_config_get(const struct device *dev,
63 struct uart_config *cfg)
64 {
65 K_OOPS(K_SYSCALL_DRIVER_UART(dev, config_get));
66 K_OOPS(K_SYSCALL_MEMORY_WRITE(cfg, sizeof(struct uart_config)));
67
68 return z_impl_uart_config_get(dev, cfg);
69 }
70 #include <zephyr/syscalls/uart_config_get_mrsh.c>
71
z_vrfy_uart_configure(const struct device * dev,const struct uart_config * cfg)72 static inline int z_vrfy_uart_configure(const struct device *dev,
73 const struct uart_config *cfg)
74 {
75 K_OOPS(K_SYSCALL_DRIVER_UART(dev, config_get));
76 K_OOPS(K_SYSCALL_MEMORY_READ(cfg, sizeof(struct uart_config)));
77
78 return z_impl_uart_configure(dev, cfg);
79 }
80 #include <zephyr/syscalls/uart_configure_mrsh.c>
81 #endif
82
83 #ifdef CONFIG_UART_ASYNC_API
84 /* callback_set() excluded as we don't allow ISR callback installation from
85 * user mode
86 *
87 * rx_buf_rsp() excluded as it's designed to be called from ISR callbacks
88 */
89
z_vrfy_uart_tx(const struct device * dev,const uint8_t * buf,size_t len,int32_t timeout)90 static inline int z_vrfy_uart_tx(const struct device *dev, const uint8_t *buf,
91 size_t len, int32_t timeout)
92 {
93 K_OOPS(K_SYSCALL_DRIVER_UART(dev, tx));
94 K_OOPS(K_SYSCALL_MEMORY_READ(buf, len));
95 return z_impl_uart_tx(dev, buf, len, timeout);
96 }
97 #include <zephyr/syscalls/uart_tx_mrsh.c>
98
99 #ifdef CONFIG_UART_WIDE_DATA
z_vrfy_uart_tx_u16(const struct device * dev,const uint16_t * buf,size_t len,int32_t timeout)100 static inline int z_vrfy_uart_tx_u16(const struct device *dev,
101 const uint16_t *buf,
102 size_t len, int32_t timeout)
103 {
104 K_OOPS(K_SYSCALL_DRIVER_UART(dev, tx));
105 K_OOPS(K_SYSCALL_MEMORY_ARRAY_READ(buf, len, sizeof(uint16_t)));
106 return z_impl_uart_tx_u16(dev, buf, len, timeout);
107 }
108 #include <zephyr/syscalls/uart_tx_u16_mrsh.c>
109 #endif
110
111 UART_SIMPLE(tx_abort);
112 #include <zephyr/syscalls/uart_tx_abort_mrsh.c>
113
z_vrfy_uart_rx_enable(const struct device * dev,uint8_t * buf,size_t len,int32_t timeout)114 static inline int z_vrfy_uart_rx_enable(const struct device *dev,
115 uint8_t *buf,
116 size_t len, int32_t timeout)
117 {
118 K_OOPS(K_SYSCALL_DRIVER_UART(dev, rx_enable));
119 K_OOPS(K_SYSCALL_MEMORY_WRITE(buf, len));
120 return z_impl_uart_rx_enable(dev, buf, len, timeout);
121 }
122 #include <zephyr/syscalls/uart_rx_enable_mrsh.c>
123
124 #ifdef CONFIG_UART_WIDE_DATA
z_vrfy_uart_rx_enable_u16(const struct device * dev,uint16_t * buf,size_t len,int32_t timeout)125 static inline int z_vrfy_uart_rx_enable_u16(const struct device *dev,
126 uint16_t *buf,
127 size_t len, int32_t timeout)
128 {
129 K_OOPS(K_SYSCALL_DRIVER_UART(dev, rx_enable));
130 K_OOPS(K_SYSCALL_MEMORY_ARRAY_WRITE(buf, len, sizeof(uint16_t)));
131 return z_impl_uart_rx_enable_u16(dev, buf, len, timeout);
132 }
133 #include <zephyr/syscalls/uart_rx_enable_u16_mrsh.c>
134 #endif
135
136 UART_SIMPLE(rx_disable);
137 #include <zephyr/syscalls/uart_rx_disable_mrsh.c>
138 #endif /* CONFIG_UART_ASYNC_API */
139
140 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
141 UART_SIMPLE_VOID(irq_tx_enable)
UART_SIMPLE_VOID(irq_tx_disable)142 UART_SIMPLE_VOID(irq_tx_disable)
143 UART_SIMPLE_VOID(irq_rx_enable)
144 UART_SIMPLE_VOID(irq_rx_disable)
145 UART_SIMPLE_VOID(irq_err_enable)
146 UART_SIMPLE_VOID(irq_err_disable)
147 UART_SIMPLE(irq_is_pending)
148 UART_SIMPLE(irq_update)
149 #include <zephyr/syscalls/uart_irq_tx_enable_mrsh.c>
150 #include <zephyr/syscalls/uart_irq_tx_disable_mrsh.c>
151 #include <zephyr/syscalls/uart_irq_rx_enable_mrsh.c>
152 #include <zephyr/syscalls/uart_irq_rx_disable_mrsh.c>
153 #include <zephyr/syscalls/uart_irq_err_enable_mrsh.c>
154 #include <zephyr/syscalls/uart_irq_err_disable_mrsh.c>
155 #include <zephyr/syscalls/uart_irq_is_pending_mrsh.c>
156 #include <zephyr/syscalls/uart_irq_update_mrsh.c>
157 #endif /* CONFIG_UART_INTERRUPT_DRIVEN */
158
159 #ifdef CONFIG_UART_LINE_CTRL
160 static inline int z_vrfy_uart_line_ctrl_set(const struct device *dev,
161 uint32_t ctrl, uint32_t val)
162 {
163 K_OOPS(K_SYSCALL_DRIVER_UART(dev, line_ctrl_set));
164 return z_impl_uart_line_ctrl_set((const struct device *)dev, ctrl,
165 val);
166 }
167 #include <zephyr/syscalls/uart_line_ctrl_set_mrsh.c>
168
z_vrfy_uart_line_ctrl_get(const struct device * dev,uint32_t ctrl,uint32_t * val)169 static inline int z_vrfy_uart_line_ctrl_get(const struct device *dev,
170 uint32_t ctrl, uint32_t *val)
171 {
172 K_OOPS(K_SYSCALL_DRIVER_UART(dev, line_ctrl_get));
173 K_OOPS(K_SYSCALL_MEMORY_WRITE(val, sizeof(uint32_t)));
174 return z_impl_uart_line_ctrl_get((const struct device *)dev, ctrl,
175 (uint32_t *)val);
176 }
177 #include <zephyr/syscalls/uart_line_ctrl_get_mrsh.c>
178 #endif /* CONFIG_UART_LINE_CTRL */
179
180 #ifdef CONFIG_UART_DRV_CMD
z_vrfy_uart_drv_cmd(const struct device * dev,uint32_t cmd,uint32_t p)181 static inline int z_vrfy_uart_drv_cmd(const struct device *dev, uint32_t cmd,
182 uint32_t p)
183 {
184 K_OOPS(K_SYSCALL_DRIVER_UART(dev, drv_cmd));
185 return z_impl_uart_drv_cmd((const struct device *)dev, cmd, p);
186 }
187 #include <zephyr/syscalls/uart_drv_cmd_mrsh.c>
188 #endif /* CONFIG_UART_DRV_CMD */
189