Skip to content

Commit 0c6588f

Browse files
Jordan Yatesnashif
authored andcommitted
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 <[email protected]>
1 parent ec331c6 commit 0c6588f

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

include/device.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,17 @@ static inline bool device_is_ready(const struct device *dev)
679679
* List of devicetree dependency ordinals (if any),
680680
* DEVICE_HANDLE_SEP,
681681
* List of injected dependency ordinals (if any),
682+
* DEVICE_HANDLE_SEP,
683+
* List of devicetree supporting ordinals (if any),
682684
* }
683685
*
684686
* After processing in gen_handles.py, the format is updated to:
685687
* {
686688
* List of existing devicetree dependency handles (if any),
687689
* DEVICE_HANDLE_SEP,
688690
* List of injected dependency ordinals (if any),
691+
* DEVICE_HANDLE_SEP,
692+
* List of existing devicetree support handles (if any),
689693
* DEVICE_HANDLE_NULL padding to original length (at least one)
690694
* }
691695
*
@@ -717,6 +721,9 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
717721
)) \
718722
DEVICE_HANDLE_SEP, \
719723
Z_DEVICE_EXTRA_HANDLES(__VA_ARGS__) \
724+
DEVICE_HANDLE_SEP, \
725+
COND_CODE_1(DT_NODE_EXISTS(node_id), \
726+
(DT_SUPPORTS_DEP_ORDS(node_id)), ()) \
720727
};
721728

722729
#define Z_DEVICE_DEFINE_INIT(node_id, dev_name, pm_control_fn) \

scripts/gen_handles.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,19 @@ def main():
240240
hvi = 1
241241
handle.dev_deps = []
242242
handle.ext_deps = []
243-
deps = handle.dev_deps
243+
handle.dev_sups = []
244+
hdls = handle.dev_deps
244245
while hvi < len(hv):
245246
h = hv[hvi]
246247
if h == DEVICE_HANDLE_ENDS:
247248
break
248249
if h == DEVICE_HANDLE_SEP:
249-
deps = handle.ext_deps
250+
if hdls == handle.dev_deps:
251+
hdls = handle.ext_deps
252+
else:
253+
hdls = handle.dev_sups
250254
else:
251-
deps.append(h)
255+
hdls.append(h)
252256
n = edt
253257
hvi += 1
254258

@@ -261,6 +265,7 @@ def main():
261265
for sn in used_nodes:
262266
# Where we're storing the final set of nodes: these are all used
263267
sn.__depends = set()
268+
sn.__supports = set()
264269

265270
deps = set(sn.depends_on)
266271
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():
273278
# forward the dependency up one level
274279
for ddn in dn.depends_on:
275280
deps.add(ddn)
276-
debug("final deps:\n\t%s\n" % ("\n\t".join([ _dn.path for _dn in sn.__depends])))
281+
debug("Final deps:\n\t%s\n" % ("\n\t".join([ _dn.path for _dn in sn.__depends])))
282+
283+
sups = set(sn.required_by)
284+
debug("\nOrig sups:\n\t%s" % ("\n\t".join([dn.path for dn in sups])))
285+
while len(sups) > 0:
286+
dn = sups.pop()
287+
if dn in used_nodes:
288+
# this is used
289+
sn.__supports.add(dn)
290+
debug("\nFinal sups:\n\t%s" % ("\n\t".join([dn.path for dn in sn.__supports])))
277291

278292
with open(args.output_source, "w") as fp:
279293
fp.write('#include <device.h>\n')
@@ -284,6 +298,7 @@ def main():
284298
assert hs, "no hs for %s" % (dev.sym.name,)
285299
dep_paths = []
286300
ext_paths = []
301+
sup_paths = []
287302
hdls = []
288303

289304
sn = hs.node
@@ -294,13 +309,24 @@ def main():
294309
dep_paths.append(dn.path)
295310
else:
296311
dep_paths.append('(%s)' % dn.path)
312+
297313
# Force separator to signal start of injected dependencies
298314
hdls.append(DEVICE_HANDLE_SEP)
299315
if len(hs.ext_deps) > 0:
300316
# TODO: map these to something smaller?
301317
ext_paths.extend(map(str, hs.ext_deps))
302318
hdls.extend(hs.ext_deps)
303319

320+
# Force separator to signal start of supported devices
321+
hdls.append(DEVICE_HANDLE_SEP)
322+
if len(hs.dev_sups) > 0:
323+
for dn in sn.required_by:
324+
if dn in sn.__supports:
325+
sup_paths.append(dn.path)
326+
else:
327+
sup_paths.append('(%s)' % dn.path)
328+
hdls.extend(dn.__device.dev_handle for dn in sn.__supports)
329+
304330
# When CONFIG_USERSPACE is enabled the pre-built elf is
305331
# also used to get hashes that identify kernel objects by
306332
# address. We can't allow the size of any object in the
@@ -317,9 +343,14 @@ def main():
317343
]
318344

319345
if len(dep_paths) > 0:
320-
lines.append(' * - %s' % ('\n * - '.join(dep_paths)))
346+
lines.append(' * Direct Dependencies:')
347+
lines.append(' * - %s' % ('\n * - '.join(dep_paths)))
321348
if len(ext_paths) > 0:
322-
lines.append(' * + %s' % ('\n * + '.join(ext_paths)))
349+
lines.append(' * Injected Dependencies:')
350+
lines.append(' * - %s' % ('\n * - '.join(ext_paths)))
351+
if len(sup_paths) > 0:
352+
lines.append(' * Supported:')
353+
lines.append(' * - %s' % ('\n * - '.join(sup_paths)))
323354

324355
lines.extend([
325356
' */',

0 commit comments

Comments
 (0)