device: iterable supported devices

Add supported device information to the device `handles` array. This
enables API's to iterate over supported devices for power management
purposes.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2021-08-20 18:31:18 +10:00 committed by Anas Nashif
commit 0c6588ff47
2 changed files with 44 additions and 6 deletions

View file

@ -679,6 +679,8 @@ static inline bool device_is_ready(const struct device *dev)
* List of devicetree dependency ordinals (if any),
* DEVICE_HANDLE_SEP,
* List of injected dependency ordinals (if any),
* DEVICE_HANDLE_SEP,
* List of devicetree supporting ordinals (if any),
* }
*
* After processing in gen_handles.py, the format is updated to:
@ -686,6 +688,8 @@ static inline bool device_is_ready(const struct device *dev)
* List of existing devicetree dependency handles (if any),
* DEVICE_HANDLE_SEP,
* List of injected dependency ordinals (if any),
* DEVICE_HANDLE_SEP,
* List of existing devicetree support handles (if any),
* DEVICE_HANDLE_NULL padding to original length (at least one)
* }
*
@ -717,6 +721,9 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
)) \
DEVICE_HANDLE_SEP, \
Z_DEVICE_EXTRA_HANDLES(__VA_ARGS__) \
DEVICE_HANDLE_SEP, \
COND_CODE_1(DT_NODE_EXISTS(node_id), \
(DT_SUPPORTS_DEP_ORDS(node_id)), ()) \
};
#define Z_DEVICE_DEFINE_INIT(node_id, dev_name, pm_control_fn) \

View file

@ -240,15 +240,19 @@ def main():
hvi = 1
handle.dev_deps = []
handle.ext_deps = []
deps = handle.dev_deps
handle.dev_sups = []
hdls = handle.dev_deps
while hvi < len(hv):
h = hv[hvi]
if h == DEVICE_HANDLE_ENDS:
break
if h == DEVICE_HANDLE_SEP:
deps = handle.ext_deps
if hdls == handle.dev_deps:
hdls = handle.ext_deps
else:
hdls = handle.dev_sups
else:
deps.append(h)
hdls.append(h)
n = edt
hvi += 1
@ -261,6 +265,7 @@ def main():
for sn in used_nodes:
# Where we're storing the final set of nodes: these are all used
sn.__depends = set()
sn.__supports = set()
deps = set(sn.depends_on)
debug("\nNode: %s\nOrig deps:\n\t%s" % (sn.path, "\n\t".join([dn.path for dn in deps])))
@ -273,7 +278,16 @@ def main():
# forward the dependency up one level
for ddn in dn.depends_on:
deps.add(ddn)
debug("final deps:\n\t%s\n" % ("\n\t".join([ _dn.path for _dn in sn.__depends])))
debug("Final deps:\n\t%s\n" % ("\n\t".join([ _dn.path for _dn in sn.__depends])))
sups = set(sn.required_by)
debug("\nOrig sups:\n\t%s" % ("\n\t".join([dn.path for dn in sups])))
while len(sups) > 0:
dn = sups.pop()
if dn in used_nodes:
# this is used
sn.__supports.add(dn)
debug("\nFinal sups:\n\t%s" % ("\n\t".join([dn.path for dn in sn.__supports])))
with open(args.output_source, "w") as fp:
fp.write('#include <device.h>\n')
@ -284,6 +298,7 @@ def main():
assert hs, "no hs for %s" % (dev.sym.name,)
dep_paths = []
ext_paths = []
sup_paths = []
hdls = []
sn = hs.node
@ -294,6 +309,7 @@ def main():
dep_paths.append(dn.path)
else:
dep_paths.append('(%s)' % dn.path)
# Force separator to signal start of injected dependencies
hdls.append(DEVICE_HANDLE_SEP)
if len(hs.ext_deps) > 0:
@ -301,6 +317,16 @@ def main():
ext_paths.extend(map(str, hs.ext_deps))
hdls.extend(hs.ext_deps)
# Force separator to signal start of supported devices
hdls.append(DEVICE_HANDLE_SEP)
if len(hs.dev_sups) > 0:
for dn in sn.required_by:
if dn in sn.__supports:
sup_paths.append(dn.path)
else:
sup_paths.append('(%s)' % dn.path)
hdls.extend(dn.__device.dev_handle for dn in sn.__supports)
# When CONFIG_USERSPACE is enabled the pre-built elf is
# also used to get hashes that identify kernel objects by
# address. We can't allow the size of any object in the
@ -317,9 +343,14 @@ def main():
]
if len(dep_paths) > 0:
lines.append(' * - %s' % ('\n * - '.join(dep_paths)))
lines.append(' * Direct Dependencies:')
lines.append(' * - %s' % ('\n * - '.join(dep_paths)))
if len(ext_paths) > 0:
lines.append(' * + %s' % ('\n * + '.join(ext_paths)))
lines.append(' * Injected Dependencies:')
lines.append(' * - %s' % ('\n * - '.join(ext_paths)))
if len(sup_paths) > 0:
lines.append(' * Supported:')
lines.append(' * - %s' % ('\n * - '.join(sup_paths)))
lines.extend([
' */',