mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Alexander Aring <alex.aring@gmail.com>
To: Peter Mamonov <pmamonov@gmail.com>
Cc: barebox <barebox@lists.infradead.org>
Subject: Re: [RFC] device probe order
Date: Fri, 25 Dec 2015 11:21:34 +0100	[thread overview]
Message-ID: <20151225102133.GA570@omega> (raw)
In-Reply-To: <20151224191029.2d499b00@berta>

On Thu, Dec 24, 2015 at 07:10:29PM +0300, Peter Mamonov wrote:
> Let me summarize my efforts:
> 
> "Global variable" solution works fine, however it is not elegant enough:
> 
> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
> index 862444b..d06e001 100644
> --- a/drivers/usb/host/ehci-hcd.c
> +++ b/drivers/usb/host/ehci-hcd.c
> @@ -138,0 +139,2 @@ static struct descriptor {
> +int ehci_probed = 0;
> +
> @@ -1346,0 +1349,2 @@ static int ehci_probe(struct device_d *dev)
> +       ehci_probed = 1;
> +
> diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
> index 5a5314f..c99426c 100644
> --- a/drivers/usb/host/uhci-hcd.c
> +++ b/drivers/usb/host/uhci-hcd.c
> @@ -81,0 +82,2 @@
> +extern int ehci_probed;
> +
> @@ -1232,0 +1235,4 @@ static int uhci_probe(struct device_d *dev)
> +       if (!ehci_probed) {
> +               dev_err(dev, "PROBE_DEFER\n");
> +               return -EPROBE_DEFER;
> +       }
> 
> 

I think one of the big disadvantages here to this solution is that it
doesn't work when you have multiple ehci/uhci devices.

In linux it would be non-go, but barebox... don't know if barebox can
handle such setup.

> 
> "Device tree" solution doesn't work, because of_find_device_by_node()
> returns pointer to the device even though the device probe function
> wasn't called. The question is: how to tell if the device probe
> function was called?

I would say the easiest way is to check on "dev-priv", there you also
could get the "struct ehci_priv" if needed in uhci when companion is
there. The "dev->priv" will be set when running probe.

> 
> diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
> index c99426c..44eca36 100644
> --- a/drivers/usb/host/uhci-hcd.c
> +++ b/drivers/usb/host/uhci-hcd.c
> @@ -1234,0 +1235,20 @@ static int uhci_probe(struct device_d *dev)
> +       struct device_node *dn = dev->device_node, *companion;
> +
> +       if (dn) {
> +               companion = of_parse_phandle(dn, "companion", 0);
> +               if (companion && !of_find_device_by_node(companion)) {
> +                       dev_err(dev, "PROBE_DEFER\n");
> +                       return -EPROBE_DEFER;
> +               }
> +       }
> 

if (dn) {
	companion = of_parse_phandle(dn, "companion", 0);
	if (companion) {
		dev = of_find_device_by_node(companion);
		if (!dev || !dev->priv) {
			dev_err(dev, "PROBE_DEFER\n");
			return -EPROBE_DEFER;
		}
	}
}

if you need "struct ehci_priv" inside of uhci driver, then I would do
some static inline function for casting and doing:

"!ehci_get_priv(dev))" instead "dev->priv", but the access should be
then readonly only.

Don't know if this is a good and acceptable solution.

- Alex

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      reply	other threads:[~2015-12-25 10:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-23 16:10 Peter Mamonov
2015-12-23 16:35 ` Alexander Aring
2015-12-23 16:56   ` Peter Mamonov
2015-12-23 17:04     ` Alexander Aring
2015-12-24  9:48       ` Peter Mamonov
2015-12-24 13:42         ` Peter Mamonov
2016-01-04  8:56           ` Sascha Hauer
2015-12-23 19:46 ` Sascha Hauer
2015-12-24 10:46   ` Peter Mamonov
2015-12-24 14:35     ` Alexander Aring
2015-12-24 16:10       ` Peter Mamonov
2015-12-25 10:21         ` Alexander Aring [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151225102133.GA570@omega \
    --to=alex.aring@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=pmamonov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox