From 54c45250943a1173ab8b3c803a8077bfc35b5563 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Mon, 19 Jul 2021 10:54:39 -0700 Subject: [PATCH] device: give device state variables a linker section This groups the device state variables in their own linker section. This is needed for demand paging as these variables are needed during boot where the paging mechanism has not been initialized. These variables need to be in the pinned section so they can be accessed during boot. Note that if device PM is not enabled, the device state variables are put into BSS. So we need to pin these. Signed-off-by: Daniel Leung --- include/device.h | 5 ++++- include/linker/common-ram.ld | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/device.h b/include/device.h index 9d862caac28..3a4b1699faa 100644 --- a/include/device.h +++ b/include/device.h @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -835,7 +836,8 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts"); * is associated with the device */ #define Z_DEVICE_STATE_DEFINE(node_id, dev_name) \ - static struct device_state Z_DEVICE_STATE_NAME(dev_name) = { \ + static struct device_state Z_DEVICE_STATE_NAME(dev_name) \ + __attribute__((__section__(".z_devstate"))) = { \ .pm = { \ .flags = ATOMIC_INIT(COND_CODE_1( \ DT_NODE_EXISTS(node_id), \ @@ -851,6 +853,7 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts"); .pm = &Z_DEVICE_STATE_NAME(dev_name).pm, #else #define Z_DEVICE_STATE_DEFINE(node_id, dev_name) \ + __pinned_bss \ static struct device_state Z_DEVICE_STATE_NAME(dev_name); #define Z_DEVICE_DEFINE_PM_INIT(dev_name, pm_control_fn) #endif diff --git a/include/linker/common-ram.ld b/include/linker/common-ram.ld index 6148f518d76..4cec4cecca4 100644 --- a/include/linker/common-ram.ld +++ b/include/linker/common-ram.ld @@ -23,6 +23,15 @@ } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) #endif + SECTION_DATA_PROLOGUE(device_states,,) + { + /* Device states used by the device objects. */ + __device_states_start = .; + KEEP(*(".z_devstate")); + KEEP(*(".z_devstate.*")); + __device_states_end = .; + } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) + #if CONFIG_PM_DEVICE SECTION_DATA_PROLOGUE(pm_device_slots, (NOLOAD),) {