From owner-freebsd-drivers@FreeBSD.ORG Sat Sep 14 23:30:00 2013 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id F28859BE for ; Sat, 14 Sep 2013 23:29:59 +0000 (UTC) (envelope-from lnrdpss@gmail.com) Received: from mail-ve0-x22e.google.com (mail-ve0-x22e.google.com [IPv6:2607:f8b0:400c:c01::22e]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B2B722176 for ; Sat, 14 Sep 2013 23:29:59 +0000 (UTC) Received: by mail-ve0-f174.google.com with SMTP id jy13so1989799veb.5 for ; Sat, 14 Sep 2013 16:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=n03JH7YtbFCYj92qLatPUN5hrWLA1pZVohnAsgLKXjc=; b=xoTosJ1UD/djw0WlAKGGakPHlxNcP0NhtW6JzDgzWiDE1NYjDrh5BYLW4vkgciDsZB /Nph3U5hfaygUCUT9ZvwYRdn6MjiBHghCreo3GZKfNbgWyTwDfg+vWRBwoYsLFgZDy6Y y7E7LQD+sx8KqQOl4V+IbuJV9B6KObHP94xKk0fXKE6YkF17pQgRmOXc9SJYJfCJiFdi uz33RSsb7yF6YVCkRpAzFuCKX7aV2JXyxpXs8yoLP/1ryXJv4NO/+dNLMXbUYa+07C3A KZhsbWA10/YlaXJ5bp6ANoG1yi6XTF7ge20yomN9rXIp9ZW3nAF6Bqe6FNufSprusvAA 6RAQ== MIME-Version: 1.0 X-Received: by 10.52.227.6 with SMTP id rw6mr16194368vdc.19.1379201398673; Sat, 14 Sep 2013 16:29:58 -0700 (PDT) Received: by 10.221.17.130 with HTTP; Sat, 14 Sep 2013 16:29:58 -0700 (PDT) In-Reply-To: <20130914182537.GZ68682@funkthat.com> References: <20130914182537.GZ68682@funkthat.com> Date: Sat, 14 Sep 2013 19:29:58 -0400 Message-ID: Subject: Re: Device hierarchy From: Leonardo Passos To: freebsd-drivers@freebsd.org, jmg@funkthat.com Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 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 23:30:00 -0000 Thanks John-Mark. That was very insightful :) On Sat, Sep 14, 2013 at 2:25 PM, John-Mark Gurney wrote: > 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." >