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>
diff --git a/scripts/gen_handles.py b/scripts/gen_handles.py
index 033f01e..441ad64 100755
--- a/scripts/gen_handles.py
+++ b/scripts/gen_handles.py
@@ -240,15 +240,19 @@
         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 @@
     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 @@
                 # 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 @@
             assert hs, "no hs for %s" % (dev.sym.name,)
             dep_paths = []
             ext_paths = []
+            sup_paths = []
             hdls = []
 
             sn = hs.node
@@ -294,6 +309,7 @@
                         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 @@
                 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 @@
             ]
 
             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([
                 ' */',