From owner-freebsd-hackers@FreeBSD.ORG Sun Sep 5 19:19:14 2004 Return-Path: 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 6891316A4CE for ; Sun, 5 Sep 2004 19:19:14 +0000 (GMT) Received: from vsmtp14.tin.it (vsmtp14.tin.it [212.216.176.118]) by mx1.FreeBSD.org (Postfix) with ESMTP id E7A6743D31 for ; Sun, 5 Sep 2004 19:19:13 +0000 (GMT) (envelope-from gerarra@tin.it) Received: from ims3a.cp.tin.it (192.168.70.103) by vsmtp14.tin.it (7.0.027) id 40967D8E01512A1B; Sun, 5 Sep 2004 21:19:13 +0200 Received: from [192.168.70.183] by ims3a.cp.tin.it with HTTP; Sun, 5 Sep 2004 21:19:12 +0200 Date: Sun, 5 Sep 2004 21:19:12 +0200 Message-ID: <411972290001A708@ims3a.cp.tin.it> In-Reply-To: From: gerarra@tin.it To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable cc: ctodd@chrismiller.com Subject: RE: KLD and USB driver X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Sep 2004 19:19:14 -0000 >I'm working on a usb device driver I've derived from existing drivers in= >sys/dev/usb (4.10-RELEASE). > >I can successfully load and unload the module, but the usb subsystem doe= s >not appear to see the driver. However if I compile my driver in the >kernel, the usb sub system uses the driver correctly. Unfortunately this= >is making it time consuming to test changes to my driver code as I have to >compile the kernel each time. > >I haven't see this used in the existing usb drivers code, but I tried >using the "KLD Skeleton" from the FreeBSD Architecture Handbook. >Although I see the uprintf output at the terminal when load/unloading th= e >module, the usb subsystem does not use my driver. Like the existing usb >drivers, I'm using USB_DECLARE_DRIVER and DRIVER_MODULE statements. > >Is the KLD DECLARE_MODULE code really necessary for this driver (doesn't= >USB_DECLARE_DRIVER make the driver available already)? How can I determi= ne >why the driver works when compiled in the kernel, but not when dynamical= ly >loaded? I'm able to load/unload the uhid and ugen drivers and they work as >expected. FreeBSD is dived into subsystems and every subsystem contains a certain number of components. To mantain specific order starting subsystems SYSIN= IT macro is provided by the kernel; very struct sysinit obj has a double-cod= e priority referencing subsystem priority and priority within the subsystem= (you can give a look to them in sys/kernel.h, enum sysinit_sub_id and enu= m sysinit_elem_order enumerations). When you code a generic KLD, DECLARE_MO= DULE macro is provided to manage linking; between the other things a struct sy= sinit obj is done (through a call to SYSINIT macro) and initialized within a sp= ecified subsystem and with a specified priority inside the subsystem, to let modu= le start properly. DRIVER_MODULE just does that: among the other things, cal= ls DECLARE_MODULE linking the new module in the DRIVERS subsystems. USB_DECL= ARE_DRIVER, instead, just defines some functions to manage your usb driver. In the en= d, the real linking is done by DRIVER_MODULE and you should not use DECLARE_= MODULE (DRIVER_MODULE alredy does). However for a review of the code the complet= e source code might be provided. greetings rookie