Message ID | e6cf01d41502b15e688b6f5aa5c3b68c62b8ac64.1701878821.git.christophe.leroy@csgroup.eu |
---|---|
State | Not Applicable |
Headers | show |
Series | [v1,1/4] of: Add of_machine_compatible_match() | expand |
Context | Check | Description |
---|---|---|
robh/checkpatch | warning | total: 0 errors, 1 warnings, 45 lines checked |
robh/patch-applied | fail | build log |
On Wed, Dec 06, 2023 at 05:13:34PM +0100, Christophe Leroy wrote: > Most probe functions that do not use the 'compatible' string do > nothing else than checking whether the machine is compatible with > one of the strings in a NULL terminated table of strings. > > Define that table of strings in ppc_md structure and check it directly > from probe_machine() instead of using ppc_md.probe() for that. > > Keep checking in ppc_md.probe() only for more complex probing. > > All .compatible could be replaced with a single element NULL > terminated list but that's not worth the churn. Can be do incrementaly > in follow-up patches. > > Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> > --- > arch/powerpc/include/asm/machdep.h | 1 + > arch/powerpc/kernel/setup-common.c | 2 ++ > arch/powerpc/platforms/40x/ppc40x_simple.c | 9 +++------ > arch/powerpc/platforms/512x/mpc512x_generic.c | 4 +--- > arch/powerpc/platforms/52xx/lite5200.c | 10 +--------- > arch/powerpc/platforms/52xx/mpc5200_simple.c | 10 +--------- > arch/powerpc/platforms/83xx/mpc830x_rdb.c | 10 +--------- > arch/powerpc/platforms/83xx/mpc831x_rdb.c | 10 +--------- > arch/powerpc/platforms/83xx/mpc837x_rdb.c | 10 +--------- > arch/powerpc/platforms/85xx/corenet_generic.c | 2 +- > arch/powerpc/platforms/85xx/tqm85xx.c | 10 +--------- > 11 files changed, 14 insertions(+), 64 deletions(-) > -/* > - * Called very early, MMU is off, device-tree isn't unflattened > - */ Certainly an out of date comment as the unflattened API was being called. Reviewed-by: Rob Herring <robh@kernel.org>
On Wed, Dec 06, 2023 at 05:13:35PM +0100, Christophe Leroy wrote: > Replace all usages of of_root by of_find_node_by_path("/") > > Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> > --- > arch/powerpc/kernel/secure_boot.c | 8 ++++++-- > arch/powerpc/kexec/ranges.c | 8 +++++--- > arch/powerpc/mm/drmem.c | 10 +++++----- > arch/powerpc/mm/numa.c | 6 ++++-- > arch/powerpc/platforms/52xx/efika.c | 4 +++- > arch/powerpc/platforms/pasemi/pci.c | 4 +++- > arch/powerpc/platforms/pseries/lparcfg.c | 6 +++++- > arch/powerpc/platforms/pseries/setup.c | 12 +++++++++--- > 8 files changed, 40 insertions(+), 18 deletions(-) Reviewed-by: Rob Herring <robh@kernel.org>
On Wed, 06 Dec 2023 17:13:32 +0100, Christophe Leroy wrote: > From: Michael Ellerman <mpe@ellerman.id.au> > > We have of_machine_is_compatible() to check if a machine is compatible > with a single compatible string. However some code is able to support > multiple compatible boards, and so wants to check for one of many > compatible strings. > > So add of_machine_compatible_match() which takes a NULL terminated > array of compatible strings to check against the root node's > compatible property. > > Compared to an open coded match this is slightly more self > documenting, and also avoids the caller needing to juggle the root > node either directly or via of_find_node_by_path(). > > Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> > Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> > --- > drivers/of/base.c | 21 +++++++++++++++++++++ > include/linux/of.h | 6 ++++++ > 2 files changed, 27 insertions(+) > Reviewed-by: Rob Herring <robh@kernel.org>
diff --git a/drivers/of/base.c b/drivers/of/base.c index 8d93cb6ea9cd..9020be2eb4d5 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -394,6 +394,27 @@ int of_device_compatible_match(const struct device_node *device, } EXPORT_SYMBOL_GPL(of_device_compatible_match); +/** + * of_machine_compatible_match - Test root of device tree against a compatible array + * @compats: NULL terminated array of compatible strings to look for in root node's compatible property. + * + * Returns true if the root node has any of the given compatible values in its + * compatible property. + */ +bool of_machine_compatible_match(const char *const *compats) +{ + struct device_node *root; + int rc = 0; + + root = of_find_node_by_path("/"); + if (root) { + rc = of_device_compatible_match(root, compats); + of_node_put(root); + } + + return rc != 0; +} + /** * 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 6a9ddf20e79a..e3418babc203 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -403,6 +403,7 @@ extern int of_alias_get_id(struct device_node *np, const char *stem); extern int of_alias_get_highest_id(const char *stem); extern int of_machine_is_compatible(const char *compat); +bool of_machine_compatible_match(const char *const *compats); extern int of_add_property(struct device_node *np, struct property *prop); extern int of_remove_property(struct device_node *np, struct property *prop); @@ -808,6 +809,11 @@ static inline int of_remove_property(struct device_node *np, struct property *pr return 0; } +static inline bool of_machine_compatible_match(const char *const *compats) +{ + return false; +} + static inline bool of_console_check(const struct device_node *dn, const char *name, int index) { return false;