All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe-Gsx/Oe8HsFggBc27wqDAHg@public.gmane.org>
To: Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Frank Rowand
	<frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Benjamin Herrenschmidt
	<benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [RFC/PATCH] dt: Add of_device_compatible_match()
Date: Thu, 07 Jul 2016 16:29:22 +1000	[thread overview]
Message-ID: <1467872962.20157.1.camel@ellerman.id.au> (raw)
In-Reply-To: <1466981246.20278.27.camel-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>

On Mon, 2016-06-27 at 08:47 +1000, Benjamin Herrenschmidt wrote:
> This provides an equivalent of of_fdt_match() for non-flat trees.
> 
> This is more practical than matching an array of of_device_id structs
> when converting a bunch of existing users of of_fdt_match().
> 
> Signed-off-by: Benjamin Herrenschmidt <benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
> ---
> 
> This is a pre-requisite for some work I'm doing to move the platform
> identification in arch/powerpc until after we have unflattened the
> device-tree. Rewriting all those lists as of_device_id's would be
> significantly cumbersome.
> 
> Note: untested other than it compiles. I want an agreement on the
> interface ASAP since the conversion of all the platforms is a burden
> I'd like to avoid doing twice.


Any comments on this?

We need it as a pre-req for a powerpc series, so unless anyone yells I'll merge
it via there.

cheers

> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index ebf84e3..429c594 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -493,6 +493,28 @@ int of_device_is_compatible(const struct device_node *device,
>  }
>  EXPORT_SYMBOL(of_device_is_compatible);
>  
> +/** Checks if the device is compatible with any of the entries in
> + *  a NULL terminated array of strings. Returns the best match
> + *  score or 0.
> + */
> +int of_device_compatible_match(struct device_node *device,
> +			       const char *const *compat)
> +{
> +	unsigned int tmp, score = 0;
> +
> +	if (!compat)
> +		return 0;
> +
> +	while (*compat) {
> +		tmp = of_device_is_compatible(device, *compat);
> +		if (tmp && (score == 0 || (tmp < score)))
> +			score = tmp;
> +		compat++;
> +	}
> +
> +	return score;
> +}
> +
>  /**
>   * of_machine_is_compatible - Test root of device tree for a given compatible value
>   * @compat: compatible string to look for in root node's compatible property.
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 74eb28c..33c184d 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -324,6 +324,8 @@ extern int of_property_read_string_helper(const struct device_node *np,
>  					      const char **out_strs, size_t sz, int index);
>  extern int of_device_is_compatible(const struct device_node *device,
>  				   const char *);
> +extern int of_device_compatible_match(struct device_node *device,
> +				      const char *const *compat);
>  extern bool of_device_is_available(const struct device_node *device);
>  extern bool of_device_is_big_endian(const struct device_node *device);
>  extern const void *of_get_property(const struct device_node *node,
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2016-07-07  6:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-26 22:47 [RFC/PATCH] dt: Add of_device_compatible_match() Benjamin Herrenschmidt
     [not found] ` <1466981246.20278.27.camel-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>
2016-07-07  6:29   ` Michael Ellerman [this message]
     [not found]     ` <1467872962.20157.1.camel-Gsx/Oe8HsFggBc27wqDAHg@public.gmane.org>
2016-07-07  7:23       ` Arnd Bergmann
2016-07-07 16:45       ` Frank Rowand
2016-07-07 16:42   ` Frank Rowand
     [not found]     ` <577E868E.30702-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-07-07 22:25       ` Benjamin Herrenschmidt

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=1467872962.20157.1.camel@ellerman.id.au \
    --to=mpe-gsx/oe8hsfggbc27wqdahg@public.gmane.org \
    --cc=benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.