Subject: Re: device tree traversal, round 2
To: Jachym Holecek <freza@dspfpga.com>
From: Quentin Garnier <cube@cubidou.net>
List: tech-kern
Date: 07/14/2007 19:42:15
--oNLI4EWr1RPQuPCf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Jul 21, 2006 at 02:15:42PM +0200, Jachym Holecek wrote:
> Hello,
>=20
> I made some changes to the device tree traversal API [*]:
>=20
>   * Change names as per chap's comment (s/DIF_TOPDOWN/DIF_PREORDER,
>     s/DIF_DOWNTOP/DIF_POSTORDER).
>   * Remove traversal stack depth limit from device_iterator_alloc().
>   * Make it possible to reuse one iterator object for either traversal
>     direction.
>   * Fix allocation bug (thanks Magnus Larsson).
>=20
> New usage example:
>=20
> 	deviter_t 		di;
> 	device_t 		dv;
>=20
> 	di =3D device_iterator_alloc();
> 	if (di =3D=3D NULL)
> 		panic("borked");
>=20
> 	device_iterator_init(di, TAILQ_FIRST(&alldevs),
> 	    DIF_PREORDER | DIF_WAITOK);
>=20
> 	while ((dv =3D device_iterator_foreach(di)) !=3D NULL)
> 		printf("FOO %s\n", device_xname(dv));
>=20
> 	device_iterator_init(di, TAILQ_FIRST(&alldevs),
> 	    DIF_POSTORDER | DIF_WAITOK);
>=20
> 	while ((dv =3D device_iterator_foreach(di)) !=3D NULL)
> 		printf("BAR %s\n", device_xname(dv));
>=20
> 	device_iterator_free(di);
>=20
> I've kept DIF_NOWAIT at place -- while I agree we should avoid allocations
> from interrupt context, I'd like to keep the option available _for now_.
>=20
> Attached is the implementation itself (subr_devtree.c -> sys/kern/) and
> a patch to be applied under sys/.
>=20
> Looks OK to commit?

Why didn't this hit the tree?  I have one comment about the example
above:  you need a slightly different API if you want to go through all
devices.  The first device in alldevs might not be the parent of all
devices, because there can be several root devices.

--=20
Quentin Garnier - cube@cubidou.net - cube@NetBSD.org
"You could have made it, spitting out benchmarks
Owe it to yourself not to fail"
Amplifico, Spitting Out Benchmarks, Hometakes Vol. 2, 2005.

--oNLI4EWr1RPQuPCf
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (NetBSD)

iQEVAwUBRpkK9tgoQloHrPnoAQKhagf/e7QVUgtLT4nGBYaPVkM+eNMiSPbg6Bif
RdSOsUvgRjxh2bqjzKXCbWaxMCQHH+XIgDS5+UZUnZ+YQsxDzBKieTvQ082ZlYCW
NkAfkuuvjuSeoRbNuEjeguJV4VOz0dHhlkH695agUD0m2BL9kC4sjK30MbfPCLCQ
REEyskSRZCorQiOXP5REFIuINgvb9LYer3jYdm5f0IyY+4/ywJ7Q0nTjTAvNoQsB
2SxUKi75DNopjsEOTrarD4gVmcYTxWGxt96o5bmFTX2E807joXgTzgI+8Hfc/bzR
cZ9gQ5T4c7CzGS2q0eAvGib7D+6o77zsE081phjgu4dOuwV78Vfl2g==
=4Hi3
-----END PGP SIGNATURE-----

--oNLI4EWr1RPQuPCf--