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/flash.h>
9
z_vrfy_flash_read(const struct device * dev,off_t offset,void * data,size_t len)10 static inline int z_vrfy_flash_read(const struct device *dev, off_t offset,
11 void *data, size_t len)
12 {
13 K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, read));
14 K_OOPS(K_SYSCALL_MEMORY_WRITE(data, len));
15 return z_impl_flash_read((const struct device *)dev, offset,
16 (void *)data,
17 len);
18 }
19 #include <syscalls/flash_read_mrsh.c>
20
z_vrfy_flash_write(const struct device * dev,off_t offset,const void * data,size_t len)21 static inline int z_vrfy_flash_write(const struct device *dev, off_t offset,
22 const void *data, size_t len)
23 {
24 K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, write));
25 K_OOPS(K_SYSCALL_MEMORY_READ(data, len));
26 return z_impl_flash_write((const struct device *)dev, offset,
27 (const void *)data, len);
28 }
29 #include <syscalls/flash_write_mrsh.c>
30
z_vrfy_flash_erase(const struct device * dev,off_t offset,size_t size)31 static inline int z_vrfy_flash_erase(const struct device *dev, off_t offset,
32 size_t size)
33 {
34 K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, erase));
35 return z_impl_flash_erase((const struct device *)dev, offset, size);
36 }
37 #include <syscalls/flash_erase_mrsh.c>
38
z_vrfy_flash_get_write_block_size(const struct device * dev)39 static inline size_t z_vrfy_flash_get_write_block_size(const struct device *dev)
40 {
41 K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_FLASH));
42 return z_impl_flash_get_write_block_size(dev);
43 }
44 #include <syscalls/flash_get_write_block_size_mrsh.c>
45
z_vrfy_flash_get_parameters(const struct device * dev)46 static inline const struct flash_parameters *z_vrfy_flash_get_parameters(const struct device *dev)
47 {
48 K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, get_parameters));
49 return z_impl_flash_get_parameters(dev);
50 }
51 #include <syscalls/flash_get_parameters_mrsh.c>
52
53 #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)54 static inline int z_vrfy_flash_get_page_info_by_offs(const struct device *dev,
55 off_t offs,
56 struct flash_pages_info *info)
57 {
58 K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, page_layout));
59 K_OOPS(K_SYSCALL_MEMORY_WRITE(info, sizeof(struct flash_pages_info)));
60 return z_impl_flash_get_page_info_by_offs((const struct device *)dev,
61 offs,
62 (struct flash_pages_info *)info);
63 }
64 #include <syscalls/flash_get_page_info_by_offs_mrsh.c>
65
z_vrfy_flash_get_page_info_by_idx(const struct device * dev,uint32_t idx,struct flash_pages_info * info)66 static inline int z_vrfy_flash_get_page_info_by_idx(const struct device *dev,
67 uint32_t idx,
68 struct flash_pages_info *info)
69 {
70 K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, page_layout));
71 K_OOPS(K_SYSCALL_MEMORY_WRITE(info, sizeof(struct flash_pages_info)));
72 return z_impl_flash_get_page_info_by_idx((const struct device *)dev,
73 idx,
74 (struct flash_pages_info *)info);
75 }
76 #include <syscalls/flash_get_page_info_by_idx_mrsh.c>
77
z_vrfy_flash_get_page_count(const struct device * dev)78 static inline size_t z_vrfy_flash_get_page_count(const struct device *dev)
79 {
80 K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, page_layout));
81 return z_impl_flash_get_page_count((const struct device *)dev);
82 }
83 #include <syscalls/flash_get_page_count_mrsh.c>
84
85 #endif /* CONFIG_FLASH_PAGE_LAYOUT */
86
87 #ifdef CONFIG_FLASH_JESD216_API
88
z_vrfy_flash_sfdp_read(const struct device * dev,off_t offset,void * data,size_t len)89 static inline int z_vrfy_flash_sfdp_read(const struct device *dev,
90 off_t offset,
91 void *data, size_t len)
92 {
93 K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, sfdp_read));
94 K_OOPS(K_SYSCALL_MEMORY_WRITE(data, len));
95 return z_impl_flash_sfdp_read(dev, offset, data, len);
96 }
97 #include <syscalls/flash_sfdp_read_mrsh.c>
98
z_vrfy_flash_read_jedec_id(const struct device * dev,uint8_t * id)99 static inline int z_vrfy_flash_read_jedec_id(const struct device *dev,
100 uint8_t *id)
101 {
102 K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, read_jedec_id));
103 K_OOPS(K_SYSCALL_MEMORY_WRITE(id, 3));
104 return z_impl_flash_read_jedec_id(dev, id);
105 }
106 #include <syscalls/flash_read_jedec_id_mrsh.c>
107
108 #endif /* CONFIG_FLASH_JESD216_API */
109
110 #ifdef CONFIG_FLASH_EX_OP_ENABLED
111
z_vrfy_flash_ex_op(const struct device * dev,uint16_t code,const uintptr_t in,void * out)112 static inline int z_vrfy_flash_ex_op(const struct device *dev, uint16_t code,
113 const uintptr_t in, void *out)
114 {
115 K_OOPS(K_SYSCALL_DRIVER_FLASH(dev, ex_op));
116
117 /*
118 * If the code is a vendor code, then ex_op function have to perform
119 * verification. Zephyr codes should be verified here, but currently
120 * there are no Zephyr extended codes yet.
121 */
122
123 return z_impl_flash_ex_op(dev, code, in, out);
124 }
125 #include <syscalls/flash_ex_op_mrsh.c>
126
127 #endif /* CONFIG_FLASH_EX_OP_ENABLED */
128