1 /*
2 * Copyright (c) 2017 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <drivers/uart.h>
8 #include <syscall_handler.h>
9
10 #define UART_SIMPLE(op_) \
11 static inline int z_vrfy_uart_##op_(const struct device *dev) \
12 { \
13 Z_OOPS(Z_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 Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, op_)); \
21 z_impl_uart_ ## op_(dev); \
22 }
23
UART_SIMPLE(err_check)24 UART_SIMPLE(err_check)
25 #include <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 Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, poll_in));
31 Z_OOPS(Z_SYSCALL_MEMORY_WRITE(p_char, sizeof(unsigned char)));
32 return z_impl_uart_poll_in(dev, p_char);
33 }
34 #include <syscalls/uart_poll_in_mrsh.c>
35
z_vrfy_uart_poll_out(const struct device * dev,unsigned char out_char)36 static inline void z_vrfy_uart_poll_out(const struct device *dev,
37 unsigned char out_char)
38 {
39 Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, poll_out));
40 z_impl_uart_poll_out((const struct device *)dev, out_char);
41 }
42 #include <syscalls/uart_poll_out_mrsh.c>
43
z_vrfy_uart_config_get(const struct device * dev,struct uart_config * cfg)44 static inline int z_vrfy_uart_config_get(const struct device *dev,
45 struct uart_config *cfg)
46 {
47 Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, config_get));
48 Z_OOPS(Z_SYSCALL_MEMORY_WRITE(cfg, sizeof(struct uart_config)));
49
50 return z_impl_uart_config_get(dev, cfg);
51 }
52 #include <syscalls/uart_config_get_mrsh.c>
53
z_vrfy_uart_configure(const struct device * dev,const struct uart_config * cfg)54 static inline int z_vrfy_uart_configure(const struct device *dev,
55 const struct uart_config *cfg)
56 {
57 Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, config_get));
58 Z_OOPS(Z_SYSCALL_MEMORY_READ(cfg, sizeof(struct uart_config)));
59
60 return z_impl_uart_configure(dev, cfg);
61 }
62 #include <syscalls/uart_configure_mrsh.c>
63
64 #ifdef CONFIG_UART_ASYNC_API
65 /* callback_set() excluded as we don't allow ISR callback installation from
66 * user mode
67 *
68 * rx_buf_rsp() excluded as it's designed to be called from ISR callbacks
69 */
70
z_vrfy_uart_tx(const struct device * dev,const uint8_t * buf,size_t len,int32_t timeout)71 static inline int z_vrfy_uart_tx(const struct device *dev, const uint8_t *buf,
72 size_t len, int32_t timeout)
73 {
74 Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, tx));
75 Z_OOPS(Z_SYSCALL_MEMORY_READ(buf, len));
76 return z_impl_uart_tx(dev, buf, len, timeout);
77 }
78 #include <syscalls/uart_tx_mrsh.c>
79
80 UART_SIMPLE(tx_abort);
81 #include <syscalls/uart_tx_abort_mrsh.c>
82
z_vrfy_uart_rx_enable(const struct device * dev,uint8_t * buf,size_t len,int32_t timeout)83 static inline int z_vrfy_uart_rx_enable(const struct device *dev,
84 uint8_t *buf,
85 size_t len, int32_t timeout)
86 {
87 Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, rx_enable));
88 Z_OOPS(Z_SYSCALL_MEMORY_WRITE(buf, len));
89 return z_impl_uart_rx_enable(dev, buf, len, timeout);
90 }
91 #include <syscalls/uart_rx_enable_mrsh.c>
92
93 UART_SIMPLE(rx_disable);
94 #include <syscalls/uart_rx_disable_mrsh.c>
95 #endif /* CONFIG_UART_ASYNC_API */
96
97 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
98 UART_SIMPLE_VOID(irq_tx_enable)
UART_SIMPLE_VOID(irq_tx_disable)99 UART_SIMPLE_VOID(irq_tx_disable)
100 UART_SIMPLE_VOID(irq_rx_enable)
101 UART_SIMPLE_VOID(irq_rx_disable)
102 UART_SIMPLE_VOID(irq_err_enable)
103 UART_SIMPLE_VOID(irq_err_disable)
104 UART_SIMPLE(irq_is_pending)
105 UART_SIMPLE(irq_update)
106 #include <syscalls/uart_irq_tx_enable_mrsh.c>
107 #include <syscalls/uart_irq_tx_disable_mrsh.c>
108 #include <syscalls/uart_irq_rx_enable_mrsh.c>
109 #include <syscalls/uart_irq_rx_disable_mrsh.c>
110 #include <syscalls/uart_irq_err_enable_mrsh.c>
111 #include <syscalls/uart_irq_err_disable_mrsh.c>
112 #include <syscalls/uart_irq_is_pending_mrsh.c>
113 #include <syscalls/uart_irq_update_mrsh.c>
114 #endif /* CONFIG_UART_INTERRUPT_DRIVEN */
115
116 #ifdef CONFIG_UART_LINE_CTRL
117 static inline int z_vrfy_uart_line_ctrl_set(const struct device *dev,
118 uint32_t ctrl, uint32_t val)
119 {
120 Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, line_ctrl_set));
121 return z_impl_uart_line_ctrl_set((const struct device *)dev, ctrl,
122 val);
123 }
124 #include <syscalls/uart_line_ctrl_set_mrsh.c>
125
z_vrfy_uart_line_ctrl_get(const struct device * dev,uint32_t ctrl,uint32_t * val)126 static inline int z_vrfy_uart_line_ctrl_get(const struct device *dev,
127 uint32_t ctrl, uint32_t *val)
128 {
129 Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, line_ctrl_get));
130 Z_OOPS(Z_SYSCALL_MEMORY_WRITE(val, sizeof(uint32_t)));
131 return z_impl_uart_line_ctrl_get((const struct device *)dev, ctrl,
132 (uint32_t *)val);
133 }
134 #include <syscalls/uart_line_ctrl_get_mrsh.c>
135 #endif /* CONFIG_UART_LINE_CTRL */
136
137 #ifdef CONFIG_UART_DRV_CMD
z_vrfy_uart_drv_cmd(const struct device * dev,uint32_t cmd,uint32_t p)138 static inline int z_vrfy_uart_drv_cmd(const struct device *dev, uint32_t cmd,
139 uint32_t p)
140 {
141 Z_OOPS(Z_SYSCALL_DRIVER_UART(dev, drv_cmd));
142 return z_impl_uart_drv_cmd((const struct device *)dev, cmd, p);
143 }
144 #include <syscalls/uart_drv_cmd_mrsh.c>
145 #endif /* CONFIG_UART_DRV_CMD */
146