device: Revise how initialization status is being handled
In order to make all device instances constant, driver_api pointer is not set to NULL anymore if initialization failed. Instead, have a bitfield dedicated to it. Fixes #27399 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
7967aa6af0
commit
aac9e2c5e3
3 changed files with 33 additions and 21 deletions
|
@ -245,10 +245,7 @@ size_t z_device_get_all_static(struct device **devices);
|
|||
*
|
||||
* @return true if and only if the device is available for use.
|
||||
*/
|
||||
static inline bool z_device_ready(const struct device *dev)
|
||||
{
|
||||
return dev->api != NULL;
|
||||
}
|
||||
bool z_device_ready(const struct device *dev);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
|
|
@ -14,18 +14,27 @@
|
|||
#endif
|
||||
|
||||
/*
|
||||
* Space for storing per device busy bitmap. Since we do not know beforehand
|
||||
* the number of devices, we go through the below mechanism to allocate the
|
||||
* required space.
|
||||
* Space for storing per device init status and busy bitmap in case PM is
|
||||
* enabled. Since we do not know beforehand the number of devices,
|
||||
* we go through the below mechanism to allocate the required space.
|
||||
* Both are made of 1 bit per-device instance, so we compute the size of
|
||||
* of an entire bitfield, aligned on 32bits.
|
||||
*/
|
||||
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
|
||||
#define DEVICE_COUNT \
|
||||
((__device_end - __device_start) / _DEVICE_STRUCT_SIZEOF)
|
||||
#define DEV_BUSY_SZ (((DEVICE_COUNT + 31) / 32) * 4)
|
||||
#define DEVICE_BITFIELD_SIZE (((DEVICE_COUNT + 31) / 32) * 4)
|
||||
|
||||
#define DEVICE_INIT_STATUS_BITFIELD() \
|
||||
FILL(0x00); \
|
||||
__device_init_status_start = .; \
|
||||
. = . + DEVICE_BITFIELD_SIZE; \
|
||||
__device_init_status_end = .;
|
||||
|
||||
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
|
||||
#define DEVICE_BUSY_BITFIELD() \
|
||||
FILL(0x00) ; \
|
||||
FILL(0x00); \
|
||||
__device_busy_start = .; \
|
||||
. = . + DEV_BUSY_SZ; \
|
||||
. = . + DEVICE_BITFIELD_SIZE; \
|
||||
__device_busy_end = .;
|
||||
#else
|
||||
#define DEVICE_BUSY_BITFIELD()
|
||||
|
@ -44,6 +53,7 @@
|
|||
CREATE_OBJ_LEVEL(device, APPLICATION)
|
||||
CREATE_OBJ_LEVEL(device, SMP)
|
||||
__device_end = .;
|
||||
DEVICE_INIT_STATUS_BITFIELD()
|
||||
DEVICE_BUSY_BITFIELD()
|
||||
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ extern const struct init_entry __init_SMP_start[];
|
|||
extern struct device __device_start[];
|
||||
extern struct device __device_end[];
|
||||
|
||||
extern uint32_t __device_init_status_start[];
|
||||
|
||||
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
|
||||
extern uint32_t __device_busy_start[];
|
||||
extern uint32_t __device_busy_end[];
|
||||
|
@ -57,21 +59,18 @@ void z_sys_init_run_level(int32_t level)
|
|||
|
||||
for (entry = levels[level]; entry < levels[level+1]; entry++) {
|
||||
struct device *dev = entry->dev;
|
||||
int retval;
|
||||
|
||||
if (dev != NULL) {
|
||||
z_object_init(dev);
|
||||
}
|
||||
|
||||
retval = entry->init(dev);
|
||||
if (retval != 0) {
|
||||
if (dev) {
|
||||
/* Initialization failed. Clear the API struct
|
||||
* so that device_get_binding() will not succeed
|
||||
* for it.
|
||||
*/
|
||||
dev->api = NULL;
|
||||
}
|
||||
if ((entry->init(dev) == 0) && (dev != NULL)) {
|
||||
/* Initialization was successful.
|
||||
* Set the init status bit so device is declared ready.
|
||||
*/
|
||||
sys_bitfield_set_bit(
|
||||
(mem_addr_t) __device_init_status_start,
|
||||
(dev - __device_start));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +120,12 @@ size_t z_device_get_all_static(struct device **devices)
|
|||
return __device_end - __device_start;
|
||||
}
|
||||
|
||||
bool z_device_ready(const struct device *dev)
|
||||
{
|
||||
return !!(sys_bitfield_test_bit((mem_addr_t)__device_init_status_start,
|
||||
(dev - __device_start)));
|
||||
}
|
||||
|
||||
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
|
||||
int device_pm_control_nop(struct device *unused_device,
|
||||
uint32_t unused_ctrl_command,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue