From owner-freebsd-hackers@FreeBSD.ORG Mon Nov 21 18:28:39 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DFF3416A41F for ; Mon, 21 Nov 2005 18:28:39 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from speedfactory.net (mail6.speedfactory.net [66.23.216.219]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6239543D46 for ; Mon, 21 Nov 2005 18:28:39 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unverified [66.23.211.162]) by speedfactory.net (SurgeMail 3.5b3) with ESMTP id 2372368 for multiple; Mon, 21 Nov 2005 13:28:49 -0500 Received: from localhost (john@localhost [127.0.0.1]) by server.baldwin.cx (8.13.1/8.13.1) with ESMTP id jALISZjo070492; Mon, 21 Nov 2005 13:28:35 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Mon, 21 Nov 2005 13:25:38 -0500 User-Agent: KMail/1.8.2 References: <87ab37ab0511210807p64282a42i657aeca9ef481e3d@mail.gmail.com> In-Reply-To: <87ab37ab0511210807p64282a42i657aeca9ef481e3d@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511211325.39808.jhb@freebsd.org> X-Spam-Status: No, score=-2.8 required=4.2 tests=ALL_TRUSTED autolearn=failed version=3.0.2 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on server.baldwin.cx X-Server: High Performance Mail Server - http://surgemail.com r=1653887525 Cc: kylin Subject: Re: sysinit how does nexus find legacy's driver? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Nov 2005 18:28:40 -0000 On Monday 21 November 2005 11:07 am, kylin wrote: > The nexus_attach(device_t dev) will call > > int > bus_generic_probe(device_t dev) > { > devclass_t dc = dev->devclass; > driverlink_t dl; > > TAILQ_FOREACH(dl, &dc->drivers, link) {//here configure has point out > the relation? > DEVICE_IDENTIFY(dl->driver, dev);//here refer to the son's > IDENTIFY,make son's device structure > } > > return (0); > } > the question is > in TAILQ_FOREACH(dl, &dc->drivers, link) > how does nexus get legacy's driver in its devclass ? > have it done in the SI_SUB_DRIVER part?of initialization? > > What happen during sSI_SUB_DRIVER ,does devclass for each driver > initialized? > > > May be the before SI_SUB_CONFIGURE, SI_SUB_DRIVER will first be > implement ,and the relative drivers will connect to each other. > I am sure that in autoconf.c ,the dl->link does not be add in ,so > where does the nexus find legacy? > In devclass_find_inernal > TAILQ_FOREACH(dc, &devclasses, link) { > if (!strcmp(dc->name, classname)) > break; > }found nothing , > > ////////////////// It's a lot of magic. :) Each driver is a kernel module declared via DRIVER_MODULE(): #define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ \ static struct driver_module_data name##_##busname##_driver_mod = { \ evh, arg, \ #busname, \ (kobj_class_t) &driver, \ &devclass \ }; \ \ static moduledata_t name##_##busname##_mod = { \ #busname "/" #name, \ driver_module_handler, \ &name##_##busname##_driver_mod \ }; \ DECLARE_MODULE(name##_##busname, name##_##busname##_mod, \ SI_SUB_DRIVERS, SI_ORDER_MIDDLE) This causes driver_module_handler() to be run at SI_SUB_DRIVERS for each driver in the kernel. One of the things that function does is add the driver to the parent driver's devclass: int driver_module_handler(module_t mod, int what, void *arg) { ... switch (what) { case MOD_LOAD: ... driver = dmd->dmd_driver; PDEBUG(("Loading module: driver %s on bus %s", DRIVERNAME(driver), dmd->dmd_busname)); error = devclass_add_driver(bus_devclass, driver); if (error) break; ... } That adds the driver to the dc_drivers list. Thus, when you see: DRIVER_MODULE(legacy, nexus, legacy_driver, legacy_devclass, 0, 0); in legacy.c, that results in legacy_driver being attached to the devclass for the nexus driver. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org