Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Jun 2020 23:31:28 -0700
From:      John-Mark Gurney <jmg@funkthat.com>
To:        Mark Millard <marklmi@yahoo.com>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>, freebsd-drivers@freebsd.org
Subject:   Re: Can we hook a device as device to two different parent devices?
Message-ID:  <20200605063128.GI4213@funkthat.com>
In-Reply-To: <C0CDA802-8990-41AF-91B2-C371593E6D19@yahoo.com>
References:  <CAAO%2BANOB8m6OjRY-FOVVHQi3vdcCEnHdjE2s3xoHdh0rjaTruQ@mail.gmail.com> <c1b611bc-4fa7-7975-da3f-e7c68a26e92b@FreeBSD.org> <CANCZdfpF%2BaiZYLRHo-NOizZcAuBz%2BXhsqYvXTazHrMVz_%2Bh=3w@mail.gmail.com> <CAAO%2BANOQfY3AUy5o9BP22O5Uxp83crAXNhFrOeMcmsStkk4Y-w@mail.gmail.com> <20200604215300.GH4213@funkthat.com> <C0CDA802-8990-41AF-91B2-C371593E6D19@yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <jmg at funkthat.com> 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."



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200605063128.GI4213>