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
13 changes: 13 additions & 0 deletions include/zephyr/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,19 @@ __syscall const struct device *device_get_binding(const char *name);
*/
size_t z_device_get_all_static(const struct device **devices);

/**
* @brief Verify that a device was set to a deferred initialization
*
* Indictase whether the provided device pointer is part of deferred init
* device section, indicating its related DTS node has 'zephyr,deferred-init'
* attribute set.
*
* @param dev pointer to the device in question.
* @retval true If the device was set to a deferred initialization
* @retval false Otherwise
*/
__syscall bool device_is_deferred_init(const struct device *dev);

/**
* @brief Verify that a device is ready for use.
*
Expand Down
23 changes: 23 additions & 0 deletions kernel/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ static inline const struct device *z_vrfy_device_get_binding(const char *name)
}
#include <zephyr/syscalls/device_get_binding_mrsh.c>

static inline bool z_vrfy_device_is_deferred_init(const struct device *dev)
{
K_OOPS(K_SYSCALL_OBJ_INIT(dev, K_OBJ_ANY));

return z_impl_device_is_deferred_init(dev);
}
#include <zephyr/syscalls/device_is_deferred_init_mrsh.c>

static inline bool z_vrfy_device_is_ready(const struct device *dev)
{
K_OOPS(K_SYSCALL_OBJ_INIT(dev, K_OBJ_ANY));
Expand Down Expand Up @@ -129,6 +137,21 @@ size_t z_device_get_all_static(struct device const **devices)
return cnt;
}

bool z_impl_device_is_deferred_init(const struct device *dev)
{
if (dev == NULL) {
return false;
}

STRUCT_SECTION_FOREACH_ALTERNATE(_deferred_init, init_entry, entry) {
if (entry->dev == dev) {
return true;
}
}

return false;
}

bool z_impl_device_is_ready(const struct device *dev)
{
/*
Expand Down
2 changes: 2 additions & 0 deletions tests/kernel/device/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ ZTEST(device, test_deferred_init)
{
int ret;

zassert_true(device_is_deferred_init(FAKEDEFERDRIVER0));

zassert_false(device_is_ready(FAKEDEFERDRIVER0));

ret = device_init(FAKEDEFERDRIVER0);
Expand Down