1 /*
2  * Copyright 2023 Google LLC
3  * Copyright 2023 Microsoft Corporation
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <zephyr/syscall_handler.h>
9 #include <zephyr/drivers/fuel_gauge.h>
10 
z_vrfy_fuel_gauge_get_prop(const struct device * dev,fuel_gauge_prop_t prop,union fuel_gauge_prop_val * val)11 static inline int z_vrfy_fuel_gauge_get_prop(const struct device *dev, fuel_gauge_prop_t prop,
12 					     union fuel_gauge_prop_val *val)
13 {
14 	union fuel_gauge_prop_val k_val;
15 
16 	Z_OOPS(Z_SYSCALL_DRIVER_FUEL_GAUGE(dev, get_property));
17 
18 	Z_OOPS(z_user_from_copy(&k_val, val, sizeof(union fuel_gauge_prop_val)));
19 
20 	int ret = z_impl_fuel_gauge_get_prop(dev, prop, &k_val);
21 
22 	Z_OOPS(z_user_to_copy(val, &k_val, sizeof(union fuel_gauge_prop_val)));
23 
24 	return ret;
25 }
26 
27 #include <syscalls/fuel_gauge_get_prop_mrsh.c>
28 
z_vrfy_fuel_gauge_get_props(const struct device * dev,fuel_gauge_prop_t * props,union fuel_gauge_prop_val * vals,size_t len)29 static inline int z_vrfy_fuel_gauge_get_props(const struct device *dev, fuel_gauge_prop_t *props,
30 					      union fuel_gauge_prop_val *vals, size_t len)
31 {
32 	union fuel_gauge_prop_val k_vals[len];
33 	fuel_gauge_prop_t k_props[len];
34 
35 	Z_OOPS(Z_SYSCALL_DRIVER_FUEL_GAUGE(dev, get_property));
36 
37 	Z_OOPS(z_user_from_copy(k_vals, vals, len * sizeof(union fuel_gauge_prop_val)));
38 	Z_OOPS(z_user_from_copy(k_props, props, len * sizeof(fuel_gauge_prop_t)));
39 
40 	int ret = z_impl_fuel_gauge_get_props(dev, k_props, k_vals, len);
41 
42 	Z_OOPS(z_user_to_copy(vals, k_vals, len * sizeof(union fuel_gauge_prop_val)));
43 
44 	return ret;
45 }
46 
47 #include <syscalls/fuel_gauge_get_props_mrsh.c>
48 
z_vrfy_fuel_gauge_set_prop(const struct device * dev,fuel_gauge_prop_t prop,union fuel_gauge_prop_val val)49 static inline int z_vrfy_fuel_gauge_set_prop(const struct device *dev, fuel_gauge_prop_t prop,
50 					     union fuel_gauge_prop_val val)
51 {
52 	Z_OOPS(Z_SYSCALL_DRIVER_FUEL_GAUGE(dev, set_property));
53 
54 	int ret = z_impl_fuel_gauge_set_prop(dev, prop, val);
55 
56 	return ret;
57 }
58 
59 #include <syscalls/fuel_gauge_set_prop_mrsh.c>
60 
z_vrfy_fuel_gauge_set_props(const struct device * dev,fuel_gauge_prop_t * props,union fuel_gauge_prop_val * vals,size_t len)61 static inline int z_vrfy_fuel_gauge_set_props(const struct device *dev, fuel_gauge_prop_t *props,
62 					      union fuel_gauge_prop_val *vals, size_t len)
63 {
64 	union fuel_gauge_prop_val k_vals[len];
65 	fuel_gauge_prop_t k_props[len];
66 
67 	Z_OOPS(Z_SYSCALL_DRIVER_FUEL_GAUGE(dev, set_property));
68 
69 	Z_OOPS(z_user_from_copy(k_vals, vals, len * sizeof(union fuel_gauge_prop_val)));
70 	Z_OOPS(z_user_from_copy(k_props, props, len * sizeof(fuel_gauge_prop_t)));
71 
72 	int ret = z_impl_fuel_gauge_set_props(dev, k_props, k_vals, len);
73 
74 	/* We only copy back vals because props will never be modified */
75 	Z_OOPS(z_user_to_copy(vals, k_vals, len * sizeof(union fuel_gauge_prop_val)));
76 
77 	return ret;
78 }
79 
80 #include <syscalls/fuel_gauge_set_props_mrsh.c>
81 
z_vrfy_fuel_gauge_get_buffer_prop(const struct device * dev,fuel_gauge_prop_t prop,void * dst,size_t dst_len)82 static inline int z_vrfy_fuel_gauge_get_buffer_prop(const struct device *dev,
83 						    fuel_gauge_prop_t prop, void *dst,
84 						    size_t dst_len)
85 {
86 	Z_OOPS(Z_SYSCALL_DRIVER_FUEL_GAUGE(dev, get_buffer_property));
87 
88 	Z_OOPS(Z_SYSCALL_MEMORY_WRITE(dst, dst_len));
89 
90 	int ret = z_impl_fuel_gauge_get_buffer_prop(dev, prop, dst, dst_len);
91 
92 	return ret;
93 }
94 
95 #include <syscalls/fuel_gauge_get_buffer_prop_mrsh.c>
96 
z_vrfy_fuel_gauge_battery_cutoff(const struct device * dev)97 static inline int z_vrfy_fuel_gauge_battery_cutoff(const struct device *dev)
98 {
99 	Z_OOPS(Z_SYSCALL_DRIVER_FUEL_GAUGE(dev, battery_cutoff));
100 
101 	return z_impl_fuel_gauge_battery_cutoff(dev);
102 }
103 
104 #include <syscalls/fuel_gauge_battery_cutoff_mrsh.c>
105