Subject: Re: device tree traversal, round 2
To: Jachym Holecek <freza@NetBSD.org>
From: Quentin Garnier <cube@cubidou.net>
List: tech-kern
Date: 07/16/2007 17:24:55
--HsYKTmaHn9HHfM39
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Jul 16, 2007 at 01:11:30PM +0200, Jachym Holecek wrote:
> # Quentin Garnier 2007-07-14:
> > On Fri, Jul 21, 2006 at 02:15:42PM +0200, Jachym Holecek wrote:
> > > 	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
> > Why didn't this hit the tree?
>=20
> I got sidetracked and never came up with an user of the API, so I thought
> I'd wait for actual need. Do you have some application in mind? Maybe

No, but I'm interested in the part where alldevs is changed into a tree.

I realized a couple days ago that in the case of indirect configuration,
you could very well have FSTAR instances where the driver's probe method
would be expected to find possibly more than one device;  the parent bus
might still want to know what its childrent devices are from time to
time, and if it doesn't get a device_t back, it has to find the
information somwehere else...

> Jared's power management code would find it handy?

Maybe;  he'd be able to tell.

> > I have one comment about the example above: you need a slightly differe=
nt
> > 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 ro=
ot
> > devices.
>=20
> True, I can revisit the API over the weekend.

I was thinking of having a static "root" device, and attach stuff to it.
We could even do away with config_root*.

--=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.

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

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

iQEVAwUBRpuNx9goQloHrPnoAQLiegf9GlPC0xmTlBXny0u1vf4sKExMYdV93bBh
h88xZpjZoqxtuucQ1HR4aMJqX7ls487FBSbSgjLnYVrwUPMqjhtOWBkrKA9pTmWU
MIbihrN3Z2Cz4uL6QRprxrGwanvOGVZ9TjTlYbZw+Bs1Pakz7LS0YbYyFclChdj5
33JwmMR9UfwcsKoDH0CD/DXYzVC875UIrlQlod4H4BL5k61wn42QlhRPW557IVCB
CDk++lcSbH0U26t1SLRgh6LF1r/c4cZdJpZeLJoZT7nfFWubb1WTr0YyiVGWXIAH
3n0KqLuZD8ir8EPZAiUi2tzelbv2iRjWJVRpsP0OF998Wk9a8xi2sA==
=iSbv
-----END PGP SIGNATURE-----

--HsYKTmaHn9HHfM39--