Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/debug/debug_stream/debug_stream_slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <user/debug_stream_slot.h>
#include <zephyr/kernel.h>

#ifdef CONFIG_USERSPACE
#include <zephyr/internal/syscall_handler.h>
#endif

LOG_MODULE_REGISTER(debug_stream_slot);

struct cpu_mutex {
Expand Down Expand Up @@ -66,7 +70,7 @@ debug_stream_get_circular_buffer(struct debug_stream_section_descriptor *desc, u
return (struct debug_stream_circular_buf *) (((uint8_t *)hdr) + desc->offset);
}

int debug_stream_slot_send_record(struct debug_stream_record *rec)
int z_impl_debug_stream_slot_send_record(struct debug_stream_record *rec)
{
struct debug_stream_section_descriptor desc = { 0 };
struct debug_stream_circular_buf *buf =
Expand Down Expand Up @@ -119,6 +123,16 @@ int debug_stream_slot_send_record(struct debug_stream_record *rec)
return 0;
}

#ifdef CONFIG_USERSPACE
static inline int z_vrfy_debug_stream_slot_send_record(struct debug_stream_record *rec)
{
K_OOPS(K_SYSCALL_MEMORY_READ(rec, sizeof(*rec)));
K_OOPS(K_SYSCALL_MEMORY_READ(rec, rec->size_words * sizeof(uint32_t)));
return z_impl_debug_stream_slot_send_record(rec);
}
#include <zephyr/syscalls/debug_stream_slot_send_record_mrsh.c>
#endif

static int debug_stream_slot_init(void)
{
struct debug_stream_slot_hdr *hdr = debug_stream_get_slot();
Expand Down
1 change: 1 addition & 0 deletions src/debug/debug_stream/debug_stream_text_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void ds_msg(const char *format, ...)
ds_vamsg(format, args);
va_end(args);
}
EXPORT_SYMBOL(ds_msg);

#if defined(CONFIG_EXCEPTION_DUMP_HOOK)
/* The debug stream debug window slot is 4k, and when it is split
Expand Down
11 changes: 10 additions & 1 deletion src/include/user/debug_stream_slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ struct debug_stream_record;
* -ENODEV if debug stream slot is not configured
* -ENOMEM if the record is too big
*/
int debug_stream_slot_send_record(struct debug_stream_record *rec);
#if defined(__ZEPHYR__) && defined(CONFIG_USERSPACE)
__syscall int debug_stream_slot_send_record(struct debug_stream_record *rec);
#else
int z_impl_debug_stream_slot_send_record(struct debug_stream_record *rec);
#define debug_stream_slot_send_record z_impl_debug_stream_slot_send_record
#endif

#if defined(__ZEPHYR__) && defined(CONFIG_USERSPACE)
#include <zephyr/syscalls/debug_stream_slot.h>
#endif
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really called from any non-Zephyr build? If this is Zephyr only, you could use the simpler boilet plate of having __syscall declaration always and let Zephyr build system generate the boiletplate for userspace and non-userspace builds. We can't use this for syscalls that are only used in some user-space builds, but this seems generic enough, so the simpler boilerplate could work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kv2019i Ok, what exactly are you suggesting? I searched for other syscall implementations, but all seem to follow this pattern, with minor variations.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsarha I mean like "work/zephyr/include/zephyr/device.h", just mark with "__syscall" without any ifdefs.
In implementation file work/zephyr/kernel/device.c you have the z_impl_foo() always and only have the verification code under ifdefs. We can't do this for many of our added syscalls in SOF as they are not enabled fo rall user-space configs, but if something is enabled whenever CONFIG_USERSPACE is set, we can use the standard boilerplate.


#endif /* __SOC_DEBUG_WINDOW_SLOT_H__ */
2 changes: 2 additions & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/lib/fast-get.h)
zephyr_syscall_header(include/rtos/alloc.h)
zephyr_library_sources_ifdef(CONFIG_SOF_USERSPACE_INTERFACE_ALLOC syscall/alloc.c)

zephyr_syscall_header(${SOF_SRC_PATH}/include/user/debug_stream_slot.h)

zephyr_library_link_libraries(SOF)
target_link_libraries(SOF INTERFACE zephyr_interface)

Expand Down
Loading