Received: from PACIFIC-CARRIER-ANNEX.MIT.EDU by po7.MIT.EDU (5.61/4.7) id AA26634; Thu, 14 Mar 96 15:42:37 EST
Received: from pain.lcs.mit.edu by MIT.EDU with SMTP
	id AA28964; Thu, 14 Mar 96 15:41:52 EST
Received: (from daemon@localhost) by pain.lcs.mit.edu (8.7.4/8.6.12) id PAA29004; Thu, 14 Mar 1996 15:13:04 -0500 (EST)
Received: from lestat.nas.nasa.gov by pain.lcs.mit.edu (8.7.4/8.6.12) with ESMTP id OAA28075 for <netbsd-developers@netbsd.org>; Thu, 14 Mar 1996 14:53:07 -0500 (EST)
Received: from localhost (localhost [127.0.0.1]) by lestat.nas.nasa.gov (8.7.4/8.6.12) with SMTP id LAA12787 for <netbsd-developers@netbsd.org>; Thu, 14 Mar 1996 11:50:36 -0800 (PST)
Message-Id: <199603141950.LAA12787@lestat.nas.nasa.gov>
X-Authentication-Warning: lestat.nas.nasa.gov: Host localhost [127.0.0.1] didn't use HELO protocol
To: netbsd-developers@NetBSD.ORG
Subject: devices on multple parents...
Reply-To: Jason Thorpe <thorpej@nas.nasa.gov>
From: Jason Thorpe <thorpej@nas.nasa.gov>
Date: Thu, 14 Mar 1996 11:50:35 -0800
Sender: owner-netbsd-developers@NetBSD.ORG
Precedence: first-class
X-Loop: netbsd-developers@NetBSD.ORG

Folks ...

As you may or may not have heard before, I'm getting ready to check in 
some changes that will affect *every* new config driver in the source tree.

The problem that's being addressed can probably be demonstrated best by 
citing the Alpha port.  The Alpha port can potentially have 3 "le" 
drivers: turbochannel, pci, and isa.  The meat of the driver remains the 
same, however the match/attach semantics are much different.

The problem, of course, lies in the fact that match/attach is directly 
coupled to the rest of the driver.  Declaring le* at tc? and le0 at isa? 
loses, because of multiple instances of "lecd".

At USENIX, we discussed a solution to this, that being the cfdriver gets 
the name of the bus included in it, i.e. "le_isa_cd".  This also had 
problems, because unit numbering became kind of hairy...

Chris has kindly architected a solution.  This solution decouples the 
match/attach from the cfdriver.  A new structure is introduced, called 
"cfattach".  The cfdata for a given config entry contains references to 
cfdriver (which will be shared) and cfattach (which will be unique).

For most drivers, the changes are purely mechanical.  In the Old Way, 
your files.xxx entry and autoconfig glue looked like this:

device foo at bar: zap

struct cfdriver foocd = {
	NULL, "foo", foomatch, fooattach, DV_DULL, sizeof(foo_softc)
};

Under the New Way, they look like this:

device foo: zap
attach foo at bar

struct cfattach foo_ca = {
	foomatch, fooattach
};

struct cfdriver foo_ca = {
	NULL, "foo", DV_DULL, sizeof(foo_softc)
};

Now, say for example, you have a foo at isa and a foo at pci:

device foo: zap
attach foo at isa with foo_isa
attach foo at pci with foo_pci

In your isa driver:

struct cfattach foo_isa_ca = {
	foo_isa_match, foo_isa_attach
};

...and pci:

struct cfattach foo_pci_ca = {
	foo_pci_match, foo_pci_attach
};

...and in the code in sys/dev/ic/foo.c

struct cfdriver foo_cd = {
	NULL, "foo", DV_DULL, sizeof(foo_softc)
};

Chris's changes also fix a long-standing limitation in the 
autoconfiguration code, that being one couln't have multiple cloned 
device declarations if they attached to different parents.  I.e. the 
following now works:

le*	at tc? ...
le*	at pci? ...

...and the unit numbers stay in-synch.

Anyhow, Chris converted the i386 port for me, and I've converted the 
sparc port thus-far.  I'm going to make an attempt to catch every driver 
in the tree, but, of course, to err is human.

So, this is somewhat of a warning ...

When you update your sources after I commit these changes (hopefully on 
Monday) you'll have to first and foremost rebuild and install a new 
version of config(8).  I apologize in advance if some kernels don't 
link/compile after I frob with everything...  Like I said, the changes 
are mostly mechanical, but if you have any questions, please ask.

Ciao.

--------------------------------------------------------------------------
Jason R. Thorpe                                       thorpej@nas.nasa.gov
NASA Ames Research Center                               Home: 408.866.1912
NAS: M/S 258-6                                          Work: 415.604.0935
Moffett Field, CA 94035                                Pager: 415.428.6939
