1 /*
2 * Copyright (c) 2017 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/internal/syscall_handler.h>
8 #include <zephyr/drivers/counter.h>
9
10 /* For those APIs that just take one argument which is a counter driver
11 * instance and return an integral value
12 */
13 #define COUNTER_HANDLER(name) \
14 static inline int z_vrfy_counter_##name(const struct device *dev) \
15 { \
16 K_OOPS(K_SYSCALL_DRIVER_COUNTER(dev, name)); \
17 return z_impl_counter_ ## name((const struct device *)dev); \
18 }
19
20 COUNTER_HANDLER(get_pending_int)
COUNTER_HANDLER(stop)21 COUNTER_HANDLER(stop)
22 COUNTER_HANDLER(start)
23
24 #include <zephyr/syscalls/counter_get_pending_int_mrsh.c>
25 #include <zephyr/syscalls/counter_stop_mrsh.c>
26 #include <zephyr/syscalls/counter_start_mrsh.c>
27
28 static inline bool z_vrfy_counter_is_counting_up(const struct device *dev)
29 {
30 K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
31 return z_impl_counter_is_counting_up((const struct device *)dev);
32 }
33 #include <zephyr/syscalls/counter_is_counting_up_mrsh.c>
34
z_vrfy_counter_get_num_of_channels(const struct device * dev)35 static inline uint8_t z_vrfy_counter_get_num_of_channels(const struct device *dev)
36 {
37 K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
38 return z_impl_counter_get_num_of_channels((const struct device *)dev);
39 }
40 #include <zephyr/syscalls/counter_get_num_of_channels_mrsh.c>
41
z_vrfy_counter_get_frequency(const struct device * dev)42 static inline uint32_t z_vrfy_counter_get_frequency(const struct device *dev)
43 {
44 K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
45 return z_impl_counter_get_frequency((const struct device *)dev);
46 }
47 #include <zephyr/syscalls/counter_get_frequency_mrsh.c>
48
z_vrfy_counter_us_to_ticks(const struct device * dev,uint64_t us)49 static inline uint32_t z_vrfy_counter_us_to_ticks(const struct device *dev,
50 uint64_t us)
51 {
52 K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
53 return z_impl_counter_us_to_ticks((const struct device *)dev,
54 (uint64_t)us);
55 }
56 #include <zephyr/syscalls/counter_us_to_ticks_mrsh.c>
57
z_vrfy_counter_ticks_to_us(const struct device * dev,uint32_t ticks)58 static inline uint64_t z_vrfy_counter_ticks_to_us(const struct device *dev,
59 uint32_t ticks)
60 {
61 K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
62 return z_impl_counter_ticks_to_us((const struct device *)dev,
63 (uint32_t)ticks);
64 }
65 #include <zephyr/syscalls/counter_ticks_to_us_mrsh.c>
66
z_vrfy_counter_get_value(const struct device * dev,uint32_t * ticks)67 static inline int z_vrfy_counter_get_value(const struct device *dev,
68 uint32_t *ticks)
69 {
70 K_OOPS(K_SYSCALL_DRIVER_COUNTER(dev, get_value));
71 K_OOPS(K_SYSCALL_MEMORY_WRITE(ticks, sizeof(*ticks)));
72 return z_impl_counter_get_value((const struct device *)dev, ticks);
73 }
74 #include <zephyr/syscalls/counter_get_value_mrsh.c>
75
z_vrfy_counter_get_value_64(const struct device * dev,uint64_t * ticks)76 static inline int z_vrfy_counter_get_value_64(const struct device *dev,
77 uint64_t *ticks)
78 {
79 K_OOPS(K_SYSCALL_DRIVER_COUNTER(dev, get_value_64));
80 K_OOPS(K_SYSCALL_MEMORY_WRITE(ticks, sizeof(*ticks)));
81 return z_impl_counter_get_value_64((const struct device *)dev, ticks);
82 }
83 #include <zephyr/syscalls/counter_get_value_64_mrsh.c>
84
z_vrfy_counter_set_channel_alarm(const struct device * dev,uint8_t chan_id,const struct counter_alarm_cfg * alarm_cfg)85 static inline int z_vrfy_counter_set_channel_alarm(const struct device *dev,
86 uint8_t chan_id,
87 const struct counter_alarm_cfg *alarm_cfg)
88 {
89 struct counter_alarm_cfg cfg_copy;
90
91 K_OOPS(K_SYSCALL_DRIVER_COUNTER(dev, set_alarm));
92 K_OOPS(k_usermode_from_copy(&cfg_copy, alarm_cfg, sizeof(cfg_copy)));
93 K_OOPS(K_SYSCALL_VERIFY_MSG(cfg_copy.callback == NULL,
94 "callbacks may not be set from user mode"));
95 return z_impl_counter_set_channel_alarm((const struct device *)dev,
96 (uint8_t)chan_id,
97 (const struct counter_alarm_cfg *)&cfg_copy);
98
99 }
100 #include <zephyr/syscalls/counter_set_channel_alarm_mrsh.c>
101
z_vrfy_counter_cancel_channel_alarm(const struct device * dev,uint8_t chan_id)102 static inline int z_vrfy_counter_cancel_channel_alarm(const struct device *dev,
103 uint8_t chan_id)
104 {
105 K_OOPS(K_SYSCALL_DRIVER_COUNTER(dev, cancel_alarm));
106 return z_impl_counter_cancel_channel_alarm((const struct device *)dev,
107 (uint8_t)chan_id);
108 }
109 #include <zephyr/syscalls/counter_cancel_channel_alarm_mrsh.c>
110
z_vrfy_counter_set_top_value(const struct device * dev,const struct counter_top_cfg * cfg)111 static inline int z_vrfy_counter_set_top_value(const struct device *dev,
112 const struct counter_top_cfg
113 *cfg)
114 {
115 struct counter_top_cfg cfg_copy;
116
117 K_OOPS(K_SYSCALL_DRIVER_COUNTER(dev, set_top_value));
118 K_OOPS(k_usermode_from_copy(&cfg_copy, cfg, sizeof(cfg_copy)));
119 K_OOPS(K_SYSCALL_VERIFY_MSG(cfg_copy.callback == NULL,
120 "callbacks may not be set from user mode"));
121 return z_impl_counter_set_top_value((const struct device *)dev,
122 (const struct counter_top_cfg *)
123 &cfg_copy);
124 }
125 #include <zephyr/syscalls/counter_set_top_value_mrsh.c>
126
z_vrfy_counter_get_top_value(const struct device * dev)127 static inline uint32_t z_vrfy_counter_get_top_value(const struct device *dev)
128 {
129 K_OOPS(K_SYSCALL_DRIVER_COUNTER(dev, get_top_value));
130 return z_impl_counter_get_top_value((const struct device *)dev);
131 }
132 #include <zephyr/syscalls/counter_get_top_value_mrsh.c>
133
z_vrfy_counter_get_max_top_value(const struct device * dev)134 static inline uint32_t z_vrfy_counter_get_max_top_value(const struct device *dev)
135 {
136 K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
137 return z_impl_counter_get_max_top_value((const struct device *)dev);
138 }
139 #include <zephyr/syscalls/counter_get_max_top_value_mrsh.c>
140
z_vrfy_counter_get_guard_period(const struct device * dev,uint32_t flags)141 static inline uint32_t z_vrfy_counter_get_guard_period(const struct device *dev,
142 uint32_t flags)
143 {
144 K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
145 return z_impl_counter_get_guard_period((const struct device *)dev,
146 flags);
147 }
148 #include <zephyr/syscalls/counter_get_guard_period_mrsh.c>
149
z_vrfy_counter_set_guard_period(const struct device * dev,uint32_t ticks,uint32_t flags)150 static inline int z_vrfy_counter_set_guard_period(const struct device *dev,
151 uint32_t ticks, uint32_t flags)
152 {
153 K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
154 return z_impl_counter_set_guard_period((const struct device *)dev,
155 ticks,
156 flags);
157 }
158 #include <zephyr/syscalls/counter_set_guard_period_mrsh.c>
159