1 /*
2  * Copyright (c) 2017 Intel Corporation
3  * Copyright (c) 2024 Nordic Semiconductor ASA
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <zephyr/internal/syscall_handler.h>
9 #include <zephyr/drivers/flash.h>
10 
z_vrfy_flash_read(const struct device * dev,off_t offset,void * data,size_t len)11 static inline int z_vrfy_flash_read(const struct device *dev, off_t offset,
12 				    void *data, size_t len)
13 {
14 	K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, read));
15 	K_OOPS(K_SYSCALL_MEMORY_WRITE(data, len));
16 	return z_impl_flash_read((const struct device *)dev, offset,
17 				 (void *)data,
18 				 len);
19 }
20 #include <zephyr/syscalls/flash_read_mrsh.c>
21 
z_vrfy_flash_write(const struct device * dev,off_t offset,const void * data,size_t len)22 static inline int z_vrfy_flash_write(const struct device *dev, off_t offset,
23 				     const void *data, size_t len)
24 {
25 	K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, write));
26 	K_OOPS(K_SYSCALL_MEMORY_READ(data, len));
27 	return z_impl_flash_write((const struct device *)dev, offset,
28 				  (const void *)data, len);
29 }
30 #include <zephyr/syscalls/flash_write_mrsh.c>
31 
z_vrfy_flash_erase(const struct device * dev,off_t offset,size_t size)32 static inline int z_vrfy_flash_erase(const struct device *dev, off_t offset,
33 				     size_t size)
34 {
35 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_FLASH));
36 	return z_impl_flash_erase((const struct device *)dev, offset, size);
37 }
38 #include <zephyr/syscalls/flash_erase_mrsh.c>
39 
z_vrfy_flash_get_size(const struct device * dev,uint64_t * size)40 static inline int z_vrfy_flash_get_size(const struct device *dev, uint64_t *size)
41 {
42 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_FLASH));
43 	K_OOPS(K_SYSCALL_MEMORY_WRITE(size, sizeof(*size)));
44 	return z_impl_flash_get_size((const struct device *)dev, size);
45 }
46 #include <zephyr/syscalls/flash_get_size_mrsh.c>
47 
z_vrfy_flash_get_write_block_size(const struct device * dev)48 static inline size_t z_vrfy_flash_get_write_block_size(const struct device *dev)
49 {
50 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_FLASH));
51 	return z_impl_flash_get_write_block_size(dev);
52 }
53 #include <zephyr/syscalls/flash_get_write_block_size_mrsh.c>
54 
z_vrfy_flash_get_parameters(const struct device * dev)55 static inline const struct flash_parameters *z_vrfy_flash_get_parameters(const struct device *dev)
56 {
57 	K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, get_parameters));
58 	return z_impl_flash_get_parameters(dev);
59 }
60 #include <zephyr/syscalls/flash_get_parameters_mrsh.c>
61 
z_vrfy_flash_fill(const struct device * dev,uint8_t val,off_t offset,size_t size)62 int z_vrfy_flash_fill(const struct device *dev, uint8_t val, off_t offset,
63 		      size_t size)
64 {
65 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_FLASH));
66 	return z_impl_flash_fill(dev, val, offset, size);
67 }
68 #include <zephyr/syscalls/flash_fill_mrsh.c>
69 
z_vrfy_flash_flatten(const struct device * dev,off_t offset,size_t size)70 int z_vrfy_flash_flatten(const struct device *dev, off_t offset, size_t size)
71 {
72 	K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_FLASH));
73 	return z_impl_flash_flatten(dev, offset, size);
74 }
75 
76 #include <zephyr/syscalls/flash_flatten_mrsh.c>
77 
78 #ifdef CONFIG_FLASH_PAGE_LAYOUT
z_vrfy_flash_get_page_info_by_offs(const struct device * dev,off_t offs,struct flash_pages_info * info)79 static inline int z_vrfy_flash_get_page_info_by_offs(const struct device *dev,
80 						     off_t offs,
81 						     struct flash_pages_info *info)
82 {
83 	K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, page_layout));
84 	K_OOPS(K_SYSCALL_MEMORY_WRITE(info, sizeof(struct flash_pages_info)));
85 	return z_impl_flash_get_page_info_by_offs((const struct device *)dev,
86 						  offs,
87 						  (struct flash_pages_info *)info);
88 }
89 #include <zephyr/syscalls/flash_get_page_info_by_offs_mrsh.c>
90 
z_vrfy_flash_get_page_info_by_idx(const struct device * dev,uint32_t idx,struct flash_pages_info * info)91 static inline int z_vrfy_flash_get_page_info_by_idx(const struct device *dev,
92 						    uint32_t idx,
93 						    struct flash_pages_info *info)
94 {
95 	K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, page_layout));
96 	K_OOPS(K_SYSCALL_MEMORY_WRITE(info, sizeof(struct flash_pages_info)));
97 	return z_impl_flash_get_page_info_by_idx((const struct device *)dev,
98 						 idx,
99 						 (struct flash_pages_info *)info);
100 }
101 #include <zephyr/syscalls/flash_get_page_info_by_idx_mrsh.c>
102 
z_vrfy_flash_get_page_count(const struct device * dev)103 static inline size_t z_vrfy_flash_get_page_count(const struct device *dev)
104 {
105 	K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, page_layout));
106 	return z_impl_flash_get_page_count((const struct device *)dev);
107 }
108 #include <zephyr/syscalls/flash_get_page_count_mrsh.c>
109 
110 #endif /* CONFIG_FLASH_PAGE_LAYOUT */
111 
112 #ifdef CONFIG_FLASH_JESD216_API
113 
z_vrfy_flash_sfdp_read(const struct device * dev,off_t offset,void * data,size_t len)114 static inline int z_vrfy_flash_sfdp_read(const struct device *dev,
115 					 off_t offset,
116 					 void *data, size_t len)
117 {
118 	K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, sfdp_read));
119 	K_OOPS(K_SYSCALL_MEMORY_WRITE(data, len));
120 	return z_impl_flash_sfdp_read(dev, offset, data, len);
121 }
122 #include <zephyr/syscalls/flash_sfdp_read_mrsh.c>
123 
z_vrfy_flash_read_jedec_id(const struct device * dev,uint8_t * id)124 static inline int z_vrfy_flash_read_jedec_id(const struct device *dev,
125 					     uint8_t *id)
126 {
127 	K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, read_jedec_id));
128 	K_OOPS(K_SYSCALL_MEMORY_WRITE(id, 3));
129 	return z_impl_flash_read_jedec_id(dev, id);
130 }
131 #include <zephyr/syscalls/flash_read_jedec_id_mrsh.c>
132 
133 #endif /* CONFIG_FLASH_JESD216_API */
134 
135 #ifdef CONFIG_FLASH_EX_OP_ENABLED
136 
z_vrfy_flash_ex_op(const struct device * dev,uint16_t code,const uintptr_t in,void * out)137 static inline int z_vrfy_flash_ex_op(const struct device *dev, uint16_t code,
138 				     const uintptr_t in, void *out)
139 {
140 	K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, ex_op));
141 
142 	/*
143 	 * If the code is a vendor code, then ex_op function have to perform
144 	 * verification. Zephyr codes should be verified here, but currently
145 	 * there are no Zephyr extended codes yet.
146 	 */
147 
148 	return z_impl_flash_ex_op(dev, code, in, out);
149 }
150 #include <zephyr/syscalls/flash_ex_op_mrsh.c>
151 
152 #endif /* CONFIG_FLASH_EX_OP_ENABLED */
153