Subject: Re: about autoconf
To: ycchang <ycchang@cirx.org>
From: Jochen Kunz <jkunz@unixag-kl.fh-kl.de>
List: tech-kern
Date: 09/09/2003 11:21:30
On 2003.09.08 21:49 ycchang wrote:

>  My question is what the differences between config_found_sm() and
> config_search(), although it says that there are two cases when
> integrating a device on a bus : direct configuration and indirect
> configuration, the former often uses config_found_sm() to find child 
> devices, and conversely the later uses config_search().
Maybe that wasn't clear enugh descibed in my document?

Some busses can detect the presence of a particular child device on a
particular "address" (=locator argument in the kernel config file), e.g.
PCI. So the bus driver knows "there is this device". Therefore it calls
config_found_sm(). config_found_sm() looks in the driver table of the
kernel for the best matching child device driver by using
config_search()[1]. If a child is found its attach function is called by
config_found_sm(). I.e. the bus driver calls for each child device it
detects config_found_sm() and all is done. The bus driver doesn't need
to care about to call the child device attach function. => direct
configuration

Some busses can _not_ detect the presence of a particular child device
on a particular "address", e.g. ISA. So the bus driver calls
config_search() _once_ to find _all_ its child devices. config_search()
doesn't care about calling the childs attach functions. The bus driver
has to care about this via the "func()" parameter to the config_search()
function.[2] config_search() calls the "func()" function for each
potential child. The bus driver has to supply this "func()" function. It
has to apply the match function of the current child and if a match was
found it calls config_attach() for the child. => indirect configuration

config_search() is the function in autoconf(9) that iterates over all
child drivers of a given bus that are in the booting kernel. This can be
used to find the best match for a particular physical device (direct
configuration)[1]. Or a bus driver uses it to apply a bus speciffic
function to all potentional child drivers. This bus speciffic function
cares about matching and attaching a child (indirect configuration). 

You may look at sys/dev/pci/pci.c pci_enumerate_bus_generic() and
pci_probe_device() and at sys/dev/isa/isa.c isaattach() and isasearch()
for examples. 

[1] As decribed in an other mail in this thread, there may be several
drivers for the same physical device. A driver can beat an other driver
by a higher return value of the match function. This way only a single
driver can attach to the physical device, the one that knows how to
handle this physical divice best. 

[2] The "func()" parameter to config_search() is usually NULL when
called via config_found_sm(). 
-- 


tschüß,
       Jochen

Homepage: http://www.unixag-kl.fh-kl.de/~jkunz/