Browse Source

init: drop device union from struct init_entry

Such union is rather redundant, considering a simple const cast can be
done when initializing the init entry. Note that the init_entry does not
need to be touched now that struct device stores the init call. It is
merely an init entry sorted by linker scripts, so we can intertwine
devices and SYS_INIT.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
pull/85182/head
Gerard Marull-Paretas 6 months ago committed by Henrik Brix Andersen
parent
commit
3f6add69da
  1. 8
      include/zephyr/device.h
  2. 7
      include/zephyr/init.h
  3. 4
      kernel/init.c
  4. 20
      tests/lib/devicetree/devices/src/main.c

8
include/zephyr/device.h

@ -1156,18 +1156,14 @@ device_get_dt_nodelabels(const struct device *dev)
static const Z_DECL_ALIGN(struct init_entry) __used __noasan Z_INIT_ENTRY_SECTION( \ static const Z_DECL_ALIGN(struct init_entry) __used __noasan Z_INIT_ENTRY_SECTION( \
level, prio, Z_DEVICE_INIT_SUB_PRIO(node_id)) \ level, prio, Z_DEVICE_INIT_SUB_PRIO(node_id)) \
Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \ Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \
COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), \ .dev = (const struct device *)&DEVICE_NAME_GET(dev_id) \
(.dev = { .dev_rw = &DEVICE_NAME_GET(dev_id)}), \
(.dev = { .dev = &DEVICE_NAME_GET(dev_id)})) \
} }
#define Z_DEFER_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id) \ #define Z_DEFER_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id) \
static const Z_DECL_ALIGN(struct init_entry) __used __noasan \ static const Z_DECL_ALIGN(struct init_entry) __used __noasan \
__attribute__((__section__(".z_deferred_init"))) \ __attribute__((__section__(".z_deferred_init"))) \
Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \ Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \
COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), \ .dev = (const struct device *)&DEVICE_NAME_GET(dev_id) \
(.dev = { .dev_rw = &DEVICE_NAME_GET(dev_id)}), \
(.dev = { .dev = &DEVICE_NAME_GET(dev_id)})) \
} }
/** /**

7
include/zephyr/init.h

@ -73,12 +73,7 @@ struct init_entry {
* If the init entry belongs to a device, this fields stores a * If the init entry belongs to a device, this fields stores a
* reference to it, otherwise it is set to NULL. * reference to it, otherwise it is set to NULL.
*/ */
union { const struct device *dev;
const struct device *dev;
#ifdef CONFIG_DEVICE_MUTABLE
struct device *dev_rw;
#endif
} dev;
}; };
/** @cond INTERNAL_HIDDEN */ /** @cond INTERNAL_HIDDEN */

4
kernel/init.c

@ -360,7 +360,7 @@ static void z_sys_init_run_level(enum init_level level)
const struct init_entry *entry; const struct init_entry *entry;
for (entry = levels[level]; entry < levels[level+1]; entry++) { for (entry = levels[level]; entry < levels[level+1]; entry++) {
const struct device *dev = entry->dev.dev; const struct device *dev = entry->dev;
int result; int result;
sys_trace_sys_init_enter(entry, level); sys_trace_sys_init_enter(entry, level);
@ -381,7 +381,7 @@ int z_impl_device_init(const struct device *dev)
} }
STRUCT_SECTION_FOREACH_ALTERNATE(_deferred_init, init_entry, entry) { STRUCT_SECTION_FOREACH_ALTERNATE(_deferred_init, init_entry, entry) {
if (entry->dev.dev == dev) { if (entry->dev == dev) {
return do_device_init(dev); return do_device_init(dev);
} }
} }

20
tests/lib/devicetree/devices/src/main.c

@ -64,25 +64,25 @@ DEVICE_DT_DEFINE(TEST_NOLABEL, dev_init, NULL,
ZTEST(devicetree_devices, test_init_get) ZTEST(devicetree_devices, test_init_get)
{ {
/* Check device pointers */ /* Check device pointers */
zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIO)->dev.dev, zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIO)->dev,
DEVICE_DT_GET(TEST_GPIO), NULL); DEVICE_DT_GET(TEST_GPIO), NULL);
zassert_equal(DEVICE_INIT_DT_GET(TEST_I2C)->dev.dev, zassert_equal(DEVICE_INIT_DT_GET(TEST_I2C)->dev,
DEVICE_DT_GET(TEST_I2C), NULL); DEVICE_DT_GET(TEST_I2C), NULL);
zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVA)->dev.dev, zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVA)->dev,
DEVICE_DT_GET(TEST_DEVA), NULL); DEVICE_DT_GET(TEST_DEVA), NULL);
zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVB)->dev.dev, zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVB)->dev,
DEVICE_DT_GET(TEST_DEVB), NULL); DEVICE_DT_GET(TEST_DEVB), NULL);
zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIOX)->dev.dev, zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIOX)->dev,
DEVICE_DT_GET(TEST_GPIOX), NULL); DEVICE_DT_GET(TEST_GPIOX), NULL);
zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVC)->dev.dev, zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVC)->dev,
DEVICE_DT_GET(TEST_DEVC), NULL); DEVICE_DT_GET(TEST_DEVC), NULL);
zassert_equal(DEVICE_INIT_DT_GET(TEST_PARTITION)->dev.dev, zassert_equal(DEVICE_INIT_DT_GET(TEST_PARTITION)->dev,
DEVICE_DT_GET(TEST_PARTITION), NULL); DEVICE_DT_GET(TEST_PARTITION), NULL);
zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIO_INJECTED)->dev.dev, zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIO_INJECTED)->dev,
DEVICE_DT_GET(TEST_GPIO_INJECTED), NULL); DEVICE_DT_GET(TEST_GPIO_INJECTED), NULL);
zassert_equal(DEVICE_INIT_GET(manual_dev)->dev.dev, zassert_equal(DEVICE_INIT_GET(manual_dev)->dev,
DEVICE_GET(manual_dev), NULL); DEVICE_GET(manual_dev), NULL);
zassert_equal(DEVICE_INIT_DT_GET(TEST_NOLABEL)->dev.dev, zassert_equal(DEVICE_INIT_DT_GET(TEST_NOLABEL)->dev,
DEVICE_DT_GET(TEST_NOLABEL), NULL); DEVICE_DT_GET(TEST_NOLABEL), NULL);
/* Check init functions */ /* Check init functions */

Loading…
Cancel
Save