From owner-freebsd-drivers@FreeBSD.ORG Sat Sep 14 18:25:38 2013 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 99B8D7E9 for ; Sat, 14 Sep 2013 18:25:38 +0000 (UTC) (envelope-from jmg@h2.funkthat.com) Received: from h2.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7A0122337 for ; Sat, 14 Sep 2013 18:25:38 +0000 (UTC) Received: from h2.funkthat.com (localhost [127.0.0.1]) by h2.funkthat.com (8.14.3/8.14.3) with ESMTP id r8EIPbET043120 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 14 Sep 2013 11:25:37 -0700 (PDT) (envelope-from jmg@h2.funkthat.com) Received: (from jmg@localhost) by h2.funkthat.com (8.14.3/8.14.3/Submit) id r8EIPbad043119; Sat, 14 Sep 2013 11:25:37 -0700 (PDT) (envelope-from jmg) Date: Sat, 14 Sep 2013 11:25:37 -0700 From: John-Mark Gurney To: Leonardo Passos Subject: Re: Device hierarchy Message-ID: <20130914182537.GZ68682@funkthat.com> Mail-Followup-To: Leonardo Passos , freebsd-drivers@freebsd.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Operating-System: FreeBSD 7.2-RELEASE i386 X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88 9322 9CB1 8F74 6D3F A396 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.2 (h2.funkthat.com [127.0.0.1]); Sat, 14 Sep 2013 11:25:37 -0700 (PDT) Cc: freebsd-drivers@freebsd.org X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Sep 2013 18:25:38 -0000 Leonardo Passos wrote this message on Sat, Sep 14, 2013 at 14:09 -0400: > Hi all, > > I am checking some code from the FreeBSD repository, and I came across a > situation that I could not explain, at least from the existing > documentation. > > Looking at sys/dev/ata/ata-raid.c in the 9.1 release, I see the following > module declaration (line 4616): > > static moduledata_t ata_raid_moduledata = > { "ataraid", ata_raid_module_event_handler, NULL }; > DECLARE_MODULE(ata, ata_raid_moduledata, SI_SUB_RAID, SI_ORDER_FIRST); > MODULE_VERSION(ataraid, 1); > MODULE_DEPEND(ataraid, ata, 1, 1, 1); > MODULE_DEPEND(ataraid, ad, 1, 1, 1); Read below, it looks like DECLARE_MODULE's name is the same: #define DECLARE_MODULE_WITH_MAXVER(name, data, sub, order, maxver) \ MODULE_DEPEND(name, kernel, __FreeBSD_version, \ __FreeBSD_version, maxver); \ MODULE_METADATA(_md_##name, MDT_MODULE, &data, #name); \ SYSINIT(name##module, sub, order, module_register_init, &data); \ struct __hack #define DECLARE_MODULE(name, data, sub, order) \ DECLARE_MODULE_WITH_MAXVER(name, data, sub, order, MODULE_KERNEL_MAXVER) and the first arg to SYSINIT is uniquifier... > Another weird situation appears in sys/dev/ata-isa.c (line 201): > > static driver_t ata_isa_driver = { > "ata", > ata_isa_methods, > sizeof(struct ata_channel), > }; > > DRIVER_MODULE(ata, isa, ata_isa_driver, ata_devclass, 0, 0); > MODULE_DEPEND(ata, ata, 1, 1, 1); > > Here, the driver module name is set to "ata", and later, it is stated that > ata depends on ata. Is the dependency referring to another ata module, at a > different level in the driver stacking? How are these names and > dependencies resolved? Here, MODULE_DEPEND should probably be: MODULE_DEPEND(isa/ata, ata, 1, 1, 1); but I'm not sure how that would/will work... Here DRIVER_MODULE does something special and names the module w/ the bus/name instead of just the first one, and why if you run kldstat -v, you'll see something like: 45 isa/ata in the output... But after looking at the MODULE_DEPEND, what really matters is that the first arg is unique per file since the macro only uses it to name symbols: #define MODULE_METADATA(uniquifier, type, data, cval) \ static struct mod_metadata _mod_metadata##uniquifier = { \ MDT_STRUCT_VERSION, \ type, \ data, \ cval \ }; \ DATA_SET(modmetadata_set, _mod_metadata##uniquifier) #define MODULE_DEPEND(module, mdepend, vmin, vpref, vmax) \ static struct mod_depend _##module##_depend_on_##mdepend = { \ vmin, \ vpref, \ vmax \ }; \ MODULE_METADATA(_md_##module##_on_##mdepend, MDT_DEPEND, \ &_##module##_depend_on_##mdepend, #mdepend) So, adding the slash is probably not useful... It should probably be made clear in MODULE_DEPEND that name is only used to uniquify the symbols and have no useful info... Maybe we should switch to using __LINE__ instead, and make name option/unused? We should probably change the first arg for MODULE_DEPEND and DECLARE_MODULE to be like SYSINIT's and name them uniquifier.. P.S. The macros I pasted came from sys/module.h. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."