Skip to content

Commit 4c4ca6a

Browse files
lyakhlgirdwood
authored andcommitted
fast-get: convert to syscalls
Convert fast_get() and fast_put() to syscalls. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 8cea89e commit 4c4ca6a

3 files changed

Lines changed: 45 additions & 6 deletions

File tree

src/include/sof/lib/fast-get.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@
1111
#include <stddef.h>
1212

1313
struct k_heap;
14-
const void *fast_get(struct k_heap *heap, const void * const dram_ptr, size_t size);
15-
void fast_put(struct k_heap *heap, const void *sram_ptr);
14+
15+
#if defined(__ZEPHYR__) && defined(CONFIG_SOF)
16+
#include <zephyr/toolchain.h>
17+
18+
__syscall const void *fast_get(struct k_heap *heap, const void * const dram_ptr, size_t size);
19+
__syscall void fast_put(struct k_heap *heap, const void *sram_ptr);
20+
#include <zephyr/syscalls/fast-get.h>
21+
#else
22+
const void *z_impl_fast_get(struct k_heap *heap, const void * const dram_ptr, size_t size);
23+
void z_impl_fast_put(struct k_heap *heap, const void *sram_ptr);
24+
#define fast_get z_impl_fast_get
25+
#define fast_put z_impl_fast_put
26+
#endif /* __ZEPHYR__ */
1627

1728
#endif /* __SOF_LIB_FAST_GET_H__ */

zephyr/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ zephyr_library_sources_ifdef(CONFIG_SHELL
529529
sof_shell.c
530530
)
531531

532+
zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/lib/fast-get.h)
533+
532534
zephyr_library_link_libraries(SOF)
533535
target_link_libraries(SOF INTERFACE zephyr_interface)
534536

zephyr/lib/fast-get.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static struct sof_fast_get_entry *fast_get_find_entry(struct sof_fast_get_data *
8080
return NULL;
8181
}
8282

83-
const void *fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
83+
const void *z_impl_fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
8484
{
8585
struct sof_fast_get_data *data = &fast_get_data;
8686
struct sof_fast_get_entry *entry;
@@ -131,7 +131,7 @@ const void *fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
131131

132132
return ret;
133133
}
134-
EXPORT_SYMBOL(fast_get);
134+
EXPORT_SYMBOL(z_impl_fast_get);
135135

136136
static struct sof_fast_get_entry *fast_put_find_entry(struct sof_fast_get_data *data,
137137
const void *sram_ptr)
@@ -146,7 +146,7 @@ static struct sof_fast_get_entry *fast_put_find_entry(struct sof_fast_get_data *
146146
return NULL;
147147
}
148148

149-
void fast_put(struct k_heap *heap, const void *sram_ptr)
149+
void z_impl_fast_put(struct k_heap *heap, const void *sram_ptr)
150150
{
151151
struct sof_fast_get_data *data = &fast_get_data;
152152
struct sof_fast_get_entry *entry;
@@ -168,4 +168,30 @@ void fast_put(struct k_heap *heap, const void *sram_ptr)
168168
entry ? entry->size : 0, entry ? entry->refcount : 0);
169169
k_spin_unlock(&data->lock, key);
170170
}
171-
EXPORT_SYMBOL(fast_put);
171+
EXPORT_SYMBOL(z_impl_fast_put);
172+
173+
#ifdef CONFIG_USERSPACE
174+
void z_vrfy_fast_put(struct k_heap *heap, const void *sram_ptr)
175+
{
176+
K_OOPS(K_SYSCALL_MEMORY_WRITE(heap, sizeof(*heap)));
177+
K_OOPS(K_SYSCALL_MEMORY_WRITE(heap->heap.heap, sizeof(*heap->heap.heap)));
178+
/*
179+
* FIXME: we don't know how much SRAM has been allocated, so cannot
180+
* check. Should fast_put() be changed to pass a size argument?
181+
*/
182+
183+
z_impl_fast_put(heap, sram_ptr);
184+
}
185+
#include <zephyr/syscalls/mod_fast_put_mrsh.c>
186+
187+
const void *z_vrfy_fast_get(struct k_heap *heap, const void *dram_ptr, size_t size)
188+
{
189+
K_OOPS(K_SYSCALL_MEMORY_WRITE(heap, sizeof(*heap)));
190+
K_OOPS(K_SYSCALL_MEMORY_WRITE(heap->heap.heap, sizeof(*heap->heap.heap)));
191+
/* We cannot (easily) verify the actual heapp memory */
192+
K_OOPS(K_SYSCALL_MEMORY_READ(dram_ptr, size));
193+
194+
return z_impl_fast_get(heap, dram_ptr, size);
195+
}
196+
#include <zephyr/syscalls/mod_fast_get_mrsh.c>
197+
#endif

0 commit comments

Comments
 (0)