From owner-freebsd-hackers@freebsd.org Thu Jun 4 21:53:06 2020 Return-Path: Delivered-To: freebsd-hackers@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 785893338A5; Thu, 4 Jun 2020 21:53:06 +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 49dKJx1SpVz43h0; Thu, 4 Jun 2020 21:53:04 +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 054Lr0t4086490 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 4 Jun 2020 14:53:00 -0700 (PDT) (envelope-from jmg@gold.funkthat.com) Received: (from jmg@localhost) by gold.funkthat.com (8.15.2/8.15.2/Submit) id 054Lr0Tm086489; Thu, 4 Jun 2020 14:53:00 -0700 (PDT) (envelope-from jmg) Date: Thu, 4 Jun 2020 14:53:00 -0700 From: John-Mark Gurney To: Rajesh Kumar Cc: Warner Losh , Andriy Gapon , freebsd-drivers@freebsd.org, FreeBSD Hackers Subject: Re: Can we hook a device as device to two different parent devices? Message-ID: <20200604215300.GH4213@funkthat.com> Mail-Followup-To: Rajesh Kumar , Warner Losh , Andriy Gapon , freebsd-drivers@freebsd.org, FreeBSD Hackers References: 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 14:53:00 -0700 (PDT) X-Rspamd-Queue-Id: 49dKJx1SpVz43h0 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 [2.19 / 15.00]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[funkthat.com]; AUTH_NA(1.00)[]; NEURAL_SPAM_MEDIUM(0.01)[0.012]; RCPT_COUNT_FIVE(0.00)[5]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_SHORT(-0.42)[-0.422]; NEURAL_SPAM_LONG(0.40)[0.401]; R_SPF_NA(0.00)[no SPF record]; FREEMAIL_TO(0.00)[gmail.com]; FORGED_SENDER(0.30)[jmg@funkthat.com,jmg@gold.funkthat.com]; SUBJECT_ENDS_QUESTION(1.00)[]; R_DKIM_NA(0.00)[]; ASN(0.00)[asn:32354, ipnet:208.87.216.0/21, country:US]; RCVD_COUNT_TWO(0.00)[2]; FROM_NEQ_ENVFROM(0.00)[jmg@funkthat.com,jmg@gold.funkthat.com] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Jun 2020 21:53:06 -0000 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 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... > On Wed, Jun 3, 2020 at 8:59 PM Warner Losh wrote: > > > > > > > On Wed, Jun 3, 2020, 8:29 AM Andriy Gapon wrote: > > > >> On 03/06/2020 14:20, Rajesh Kumar wrote: > >> > Hi, > >> > > >> > Is it really possible to declare a module with two parents? Like the > >> > following declarations in the same driver. > >> > > >> > devclass_t test_dev_devclass; > >> > static DEFINE_CLASS_0(test_dev, test_dev_driver, test_dev_methods, > >> > sizeof(struct test_dev_ctx)); > >> > DRIVER_MODULE(test_dev, *device1*, test_dev_driver, test_dev_devclass, > >> > NULL, NULL); > >> > DRIVER_MODULE(test_dev, *device2*, test_dev_driver, test_dev_devclass, > >> > NULL, NULL); > >> > > >> > I see similar references in other drivers attaching to both simpleus and > >> > ofwbus. So, If it's possible, how to get the reference for both the > >> > parents? device_get_parent(test_dev) will give reference of one parent > >> > only right, so how to get the reference of the desired parent? > >> > >> A device can have only one parent. > >> The declaration you quoted describes a _driver_ that can attach to devices > >> hanging off two different buses. They would still be different devices. > >> > > > > Yes. You can have a driver attach to multiple bus types, but each instance > > has a unique parent one exactly on of them. > > > > If you need to talk to other devices, you'll need to find them by name or > > other means. > > > > Warner > > > > > > > >> -- > >> Andriy Gapon > >> _______________________________________________ > >> freebsd-drivers@freebsd.org mailing list > >> https://lists.freebsd.org/mailman/listinfo/freebsd-drivers > >> To unsubscribe, send any mail to "freebsd-drivers-unsubscribe@freebsd.org > >> " > >> > > > _______________________________________________ > freebsd-drivers@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-drivers > To unsubscribe, send any mail to "freebsd-drivers-unsubscribe@freebsd.org" -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."