Skip to content

Commit c708a17

Browse files
gmarullnashif
authored andcommitted
pm: device: remove CONFIG_PM_MAX_DEVICES
When a device is defined a new pointer to a device will be created in the "z_pm_device_slots" region, effectively creating a device array with the same size as the number of system devices. This array is then used by the device PM subsystem to keep track of suspended devices during power transitions. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent c9656cf commit c708a17

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

include/device.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,27 @@ int device_busy_check(const struct device *chk_dev);
692692
#define Z_DEVICE_EXTRA_HANDLES(...) \
693693
FOR_EACH_NONEMPTY_TERM(IDENTITY, (,), __VA_ARGS__)
694694

695+
/* If device power management is enabled, this macro defines a pointer to a
696+
* device in the z_pm_device_slots region. When invoked for each device, this
697+
* will effectively result in a device pointer array with the same size of the
698+
* actual devices list. This is used internally by the device PM subsystem to
699+
* keep track of suspended devices during system power transitions.
700+
*/
701+
#if CONFIG_PM_DEVICE
702+
#define Z_DEVICE_DEFINE_PM_SLOT(dev_name) \
703+
static const Z_DECL_ALIGN(struct device *) \
704+
_CONCAT(__pm_device_slot_, DEVICE_NAME_GET(dev_name)) __used \
705+
__attribute__((__section__(".z_pm_device_slots")));
706+
#else
707+
#define Z_DEVICE_DEFINE_PM_SLOT(dev_name)
708+
#endif
709+
695710
/* Construct objects that are referenced from struct device. These
696711
* include power management and dependency handles.
697712
*/
698713
#define Z_DEVICE_DEFINE_PRE(node_id, dev_name, ...) \
699-
Z_DEVICE_DEFINE_HANDLES(node_id, dev_name, __VA_ARGS__)
714+
Z_DEVICE_DEFINE_HANDLES(node_id, dev_name, __VA_ARGS__) \
715+
Z_DEVICE_DEFINE_PM_SLOT(dev_name)
700716

701717

702718
/* Initial build provides a record that associates the device object

include/linker/common-ram.ld

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@
3737
__device_end = .;
3838
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
3939

40+
#if CONFIG_PM_DEVICE
41+
SECTION_DATA_PROLOGUE(pm_device_slots, (NOLOAD),)
42+
{
43+
__pm_device_slots_start = .;
44+
KEEP(*(".z_pm_device_slots"));
45+
__pm_device_slots_end = .;
46+
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
47+
#endif
48+
4049
SECTION_DATA_PROLOGUE(initshell,,)
4150
{
4251
/* link in shell initialization objects for all modules that

subsys/pm/Kconfig

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ config DEVICE_POWER_MANAGEMENT
6060
help
6161
This option is deprecated, please use CONFIG_PM_DEVICE instead.
6262

63-
config PM_MAX_DEVICES
64-
int "Max number of devices support power management"
65-
depends on PM_DEVICE
66-
default 15
67-
6863
config PM_DEVICE_RUNTIME
6964
bool "Runtime Device Power Management"
7065
depends on PM_DEVICE

subsys/pm/device.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ LOG_MODULE_DECLARE(power);
1818
extern const struct device __device_start[];
1919
extern const struct device __device_end[];
2020

21-
/* Indexes into all_devices for devices that support pm,
22-
* in dependency order (later may depend on earlier).
23-
*/
24-
static const struct device *pm_devices[CONFIG_PM_MAX_DEVICES];
21+
extern const struct device *__pm_device_slots_start[];
2522

2623
/* Number of devices successfully suspended. */
2724
static size_t num_susp;
@@ -77,10 +74,8 @@ static int _pm_devices(uint32_t state)
7774
return rc;
7875
}
7976

80-
pm_devices[num_susp] = dev;
77+
__pm_device_slots_start[num_susp] = dev;
8178
num_susp++;
82-
__ASSERT(num_susp < CONFIG_PM_MAX_DEVICES,
83-
"Number of pm devices > CONFIG_PM_MAX_DEVICES");
8479
}
8580
}
8681

@@ -107,7 +102,7 @@ void pm_resume_devices(void)
107102
size_t i;
108103

109104
for (i = 0; i < num_susp; i++) {
110-
pm_device_state_set(pm_devices[i],
105+
pm_device_state_set(__pm_device_slots_start[i],
111106
PM_DEVICE_STATE_ACTIVE,
112107
NULL, NULL);
113108
}

0 commit comments

Comments
 (0)