Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Jun 2020 14:53:00 -0700
From:      John-Mark Gurney <jmg@funkthat.com>
To:        Rajesh Kumar <rajfbsd@gmail.com>
Cc:        Warner Losh <imp@bsdimp.com>, Andriy Gapon <avg@freebsd.org>, freebsd-drivers@freebsd.org, FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Re: Can we hook a device as device to two different parent devices?
Message-ID:  <20200604215300.GH4213@funkthat.com>
In-Reply-To: <CAAO%2BANOQfY3AUy5o9BP22O5Uxp83crAXNhFrOeMcmsStkk4Y-w@mail.gmail.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>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <imp@bsdimp.com> wrote:
> 
> >
> >
> > On Wed, Jun 3, 2020, 8:29 AM Andriy Gapon <avg@freebsd.org> 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."



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