From owner-freebsd-drivers@freebsd.org Fri Jun 5 06:31:40 2020 Return-Path: Delivered-To: freebsd-drivers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 385E4341F0E; Fri, 5 Jun 2020 06:31:40 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Received: from gold.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "gate2.funkthat.com", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49dXqG4lH1z4CLn; Fri, 5 Jun 2020 06:31:38 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Received: from gold.funkthat.com (localhost [127.0.0.1]) by gold.funkthat.com (8.15.2/8.15.2) with ESMTPS id 0556VS7u001094 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 4 Jun 2020 23:31:28 -0700 (PDT) (envelope-from jmg@gold.funkthat.com) Received: (from jmg@localhost) by gold.funkthat.com (8.15.2/8.15.2/Submit) id 0556VSCx001092; Thu, 4 Jun 2020 23:31:28 -0700 (PDT) (envelope-from jmg) Date: Thu, 4 Jun 2020 23:31:28 -0700 From: John-Mark Gurney To: Mark Millard Cc: FreeBSD Hackers , freebsd-drivers@freebsd.org Subject: Re: Can we hook a device as device to two different parent devices? Message-ID: <20200605063128.GI4213@funkthat.com> Mail-Followup-To: Mark Millard , FreeBSD Hackers , freebsd-drivers@freebsd.org References: <20200604215300.GH4213@funkthat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 11.3-STABLE amd64 X-PGP-Fingerprint: D87A 235F FB71 1F3F 55B7 ED9B D5FF 5A51 C0AC 3D65 X-Files: The truth is out there X-URL: https://www.funkthat.com/ X-Resume: https://www.funkthat.com/~jmg/resume.html X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? User-Agent: Mutt/1.6.1 (2016-04-27) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (gold.funkthat.com [127.0.0.1]); Thu, 04 Jun 2020 23:31:28 -0700 (PDT) X-Rspamd-Queue-Id: 49dXqG4lH1z4CLn X-Spamd-Bar: + Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of jmg@gold.funkthat.com has no SPF policy when checking 208.87.223.18) smtp.mailfrom=jmg@gold.funkthat.com X-Spamd-Result: default: False [1.21 / 15.00]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-0.53)[-0.530]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[funkthat.com]; AUTH_NA(1.00)[]; NEURAL_SPAM_SHORT(0.05)[0.048]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_MEDIUM(-0.50)[-0.504]; R_SPF_NA(0.00)[no SPF record]; FREEMAIL_TO(0.00)[yahoo.com]; FORGED_SENDER(0.30)[jmg@funkthat.com,jmg@gold.funkthat.com]; SUBJECT_ENDS_QUESTION(1.00)[]; R_DKIM_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; FROM_NEQ_ENVFROM(0.00)[jmg@funkthat.com,jmg@gold.funkthat.com]; ASN(0.00)[asn:32354, ipnet:208.87.216.0/21, country:US] X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2020 06:31:40 -0000 Mark Millard wrote this message on Thu, Jun 04, 2020 at 16:01 -0700: > [I'm only trying to follow along for my own edification > in an area I'm not familiar with.] > > On 2020-Jun-4, at 14:53, John-Mark Gurney wrote: > > > Rajesh Kumar wrote this message on Fri, Jun 05, 2020 at 00:01 +0530: > >> Thanks Warner and Andriy for your answers. > >> > >> Having said they are two separate instances, if the child driver calls the > >> interface of two parents as below > >> device1_interface(child_dev), then device_get_parent(child_dev) in the > >> device1 interface will return device1 reference > >> device2_interface(child_dev), then device_get_parent(child_dev) in the > >> device2 interface will return device2 reference > >> > >> Is that right? > > > > I think you're confused. The device tree is a strict tree. This > > means that a device can have ONLY one parent. The multiple parents > > is simply saying that a device can attach at different points in the > > tree... > > > > example, you have a device dev that is declared as possibly having both this should have been: "a device driver dev". > > pci and simplebus: > > > > nexus0 > > acpi0 > > pcib0 > > pci0 > > hostb0 > > pcib1 > > pci1 > > dev0 > > ofwbus0 > > simplebus1 pnpinfo compat=simple-bus > > dev1 > > > > This example (and entirely made up, I've merged the tree from two > > different machines, running devinfo -v, only merged to make a point), > > dev0, when calling device_get_parent, will get the pci1 device, and > > dev1 when calling device_get_parent will get simplebus1... > > > > I think this might be what you said above, but couldn't follow the > > device1_interface(child_dev) part, as that didn't make sense to me... > > You have 3 "dev" names mentioned above: dev, dev0, dev1 > You mention "dev" as the "device". Yeah, seeing that now, I should have said the device driver dev.. dev is not an instance of the device driver... only dev0 and dev1 are instances (attached) of the device driver... > So am I to infer that for "dev" only one of dev0 vs. dev1 dev is like em, or igb.. it's the device driver name... dev0 or dev1 is an instance of the driver... > can be attached at a time (to its parent)? Code can still each instance, dev0 or dev1 or devX, will be attached to a (one) parent.. Each parent may have multiple instances of dev, say pci1 having dev0, dev2 and dev3... and above, simplebus1 could have dev1 and dev4 as children... > find out what the alternative would be for the other one > of the two, but having both dev0 and dev1 based attachments > at the same time can not be done? A device driver can be attached to different busses at the same time, but each instance of that driver can only be attached to one bus at a time... Hope this clarifies things... It's been a few years, but I did a presentation on writing device drivers in FreeBSD: https://people.freebsd.org/~jmg/drivers/freebsd.device.driver.slides.pdf on slide 4, talking about if_re.c, you can see: static devclass_t re_devclass; DRIVER_MODULE(re, pci, re_driver, re_devclass, 0, 0); DRIVER_MODULE(re, cardbus, re_driver, re_devclass, 0, 0); DRIVER_MODULE(miibus, re, miibus_driver, miibus_devclass, 0, 0); This shows that the re driver can be attached to either the pci bus, or the cardbus... When you boot a machine, you could have re0 and re1 that are PCI cards installed in the machine.. and then later you could plug in a cardbus card where the re driver attaches, and you'd now have re2 under cardbus... Warner has also done a presentation on newbus subclassing: https://people.freebsd.org/~imp/bsdcan2013-slides.pdf -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."