Subject: Re: device tree traversal
To: None <tech-kern@netbsd.org>
From: Christos Zoulas <christos@astron.com>
List: tech-kern
Date: 07/02/2006 19:28:17
In article <20060702191750.GA1918@hanele.uamt.feec.vutbr.cz>,
Jachym Holecek  <freza@dspfpga.com> wrote:
>-=-=-=-=-=-
>
>Hello,
>
>below is an implementation of device tree iterator API. This will be
>needed for proper powerhooks, recursive drvctl(8) detach and possibly
>config_{de,}activate could benefit too. The usage is quite simple:
>
>	deviter_t 		di;
>	device_t 		dv;
>
>	/* Allocate recursion context of max depth 16, topdown dir. */
>	di = device_iterator_alloc(16, DIF_WAITOK | DIF_TOPDOWN);
>	if (di == NULL)
>		handle_enomem();
>
>	/* Setup to traverse (device_t)parent's subtree. */
>	device_iterator_init(di, parent);
>
>	while ((dv = device_iterator_foreach(di)) != NULL)
>		perform_stuff_on_device(dv);
>
>	/* Free the context. */
>	device_iterator_free(di);
>
>There are two possible iterator types: DIF_TOPDOWN will handle
>parents before their children, DIF_DOWNTOP will handle children before
>their parents. The attached files give a concrete example -- given
>device hierarchy devtree.dot (graphics/graphviz format), topdown
>pass on "mainbus0" yields devtree.topdown while downtop pass gives
>devtree.downtop.
>
>Comments? Would it be OK to commit?

I like it :-)

christos