Subject: Re: Device configuration question
To: Paul Goyette <paul@whooppee.com>
From: Martin Husemann <martin@rumolt.teuto.de>
List: tech-kern
Date: 08/11/1997 09:10:02
Paul Goyette wrote:

> So, given a pointer to the grf_softc for a particular grf, how can I
> determine, in a supported way, if there is an ite attached to that grf?
> Keeping in mind, of course, that an ite might be attached to any of
> several grfs...

I'm no expert on this and don't know the Mac port, so just a few tries:

For frequent use: cast the "struct device *parent" passed to ite_attach
to grf_softc and fill in a pointer to the ite_softc (initialized to NULL
by grp_attach before)? Not good, if there's any chance of an ite attaching
to something completely different. Not good information hidding, no clean
encapsulation.

Do something like scsi device drivers do with scsibusses: the bus passes
the address of a struct scsi_link to the attaching device, which fills in
his adress?

For infrequent use (like yours sound) something like this?

static struct device *
find_ite_at_grf(grf)
	struct device *grf;
{
	struct device *dev;
	for (dev = alldevs.tqh_first; dev; dev = dev->dv_list.tqe_next)
		if (strcmp(dev->dv_cfdata->cf_driver->cd_name, "ite") == 0)
			if (dev->dv_parent == grf)
				return dev;
	return NULL;
}

I hope this is OK, as I've just done something similar in my code over the
weekend ;-)


Martin