From 07e461cd7e73a84f0e3757932b93cc80976fd749 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Wed, 21 May 2014 15:40:31 +0900 Subject: of: Ensure unique names without sacrificing determinism The way the driver core is implemented, every device using the same bus type is required to have a unique name because a symlink to each device is created in the appropriate /sys/bus/*/devices directory, and two identical names causes a collision. The current code handles the requirement by using an globally incremented counter that is appended to the device name. It works, but it means any change to device registration will change the assigned numbers. Instead, if we build up the name by using information from the parent nodes, then it can be guaranteed to be unique without adding a random number to the end of it. Signed-off-by: Grant Likely Cc: Ezequiel Garcia Cc: Rob Herring --- drivers/of/platform.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index d0009b3614af..95c133a0554b 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -68,17 +68,15 @@ EXPORT_SYMBOL(of_find_device_by_node); * of_device_make_bus_id - Use the device node data to assign a unique name * @dev: pointer to device structure that is linked to a device tree node * - * This routine will first try using either the dcr-reg or the reg property - * value to derive a unique name. As a last resort it will use the node - * name followed by a unique number. + * This routine will first try using the translated bus address to + * derive a unique name. If it cannot, then it will prepend names from + * parent nodes until a unique name can be derived. */ void of_device_make_bus_id(struct device *dev) { - static atomic_t bus_no_reg_magic; struct device_node *node = dev->of_node; const __be32 *reg; u64 addr; - int magic; #ifdef CONFIG_PPC_DCR /* @@ -100,25 +98,25 @@ void of_device_make_bus_id(struct device *dev) } #endif /* CONFIG_PPC_DCR */ - /* - * For MMIO, get the physical address - */ - reg = of_get_property(node, "reg", NULL); - if (reg) { - addr = of_translate_address(node, reg); - if (addr != OF_BAD_ADDR) { - dev_set_name(dev, "%llx.%s", - (unsigned long long)addr, node->name); + /* Construct the name, using parent nodes if necessary to ensure uniqueness */ + while (node->parent) { + /* + * If the address can be translated, then that is as much + * uniqueness as we need. Make it the first component and return + */ + reg = of_get_property(node, "reg", NULL); + if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) { + dev_set_name(dev, dev_name(dev) ? "%llx.%s:%s" : "%llx.%s", + (unsigned long long)addr, node->name, + dev_name(dev)); return; } - } - /* - * No BusID, use the node name and add a globally incremented - * counter (and pray...) - */ - magic = atomic_add_return(1, &bus_no_reg_magic); - dev_set_name(dev, "%s.%d", node->name, magic - 1); + /* format arguments only used if dev_name() resolves to NULL */ + dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s", + strrchr(node->full_name, '/') + 1, dev_name(dev)); + node = node->parent; + } } /** -- cgit v1.2.3 From ba52464a629fab2493925007b00f2ca65d02ed4e Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Fri, 23 May 2014 07:50:50 +0900 Subject: of: Stop naming platform_device using dcr address There is now a way to ensure all platform devices get a unique name when populated from the device tree, and the DCR_NATIVE code path is broken anyway. PowerPC Cell (PS3) is the only platform that actually uses this path. Most likely nobody will notice if it is killed. Remove the code and associated ugly #ifdef. The user-visible impact of this patch is that any DCR device on Cell will get a new name in the /sys/devices hierarchy. Signed-off-by: Grant Likely Cc: Rob Herring Cc: Benjamin Herrenschmidt --- arch/powerpc/include/asm/dcr-mmio.h | 4 ---- arch/powerpc/sysdev/dcr.c | 6 +++--- drivers/of/platform.c | 24 ------------------------ 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/arch/powerpc/include/asm/dcr-mmio.h b/arch/powerpc/include/asm/dcr-mmio.h index acd491dbd45a..93a68b28e695 100644 --- a/arch/powerpc/include/asm/dcr-mmio.h +++ b/arch/powerpc/include/asm/dcr-mmio.h @@ -51,10 +51,6 @@ static inline void dcr_write_mmio(dcr_host_mmio_t host, out_be32(host.token + ((host.base + dcr_n) * host.stride), value); } -extern u64 of_translate_dcr_address(struct device_node *dev, - unsigned int dcr_n, - unsigned int *stride); - #endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_DCR_MMIO_H */ diff --git a/arch/powerpc/sysdev/dcr.c b/arch/powerpc/sysdev/dcr.c index 1bd0eba4d355..e9056e438575 100644 --- a/arch/powerpc/sysdev/dcr.c +++ b/arch/powerpc/sysdev/dcr.c @@ -152,9 +152,9 @@ EXPORT_SYMBOL_GPL(dcr_resource_len); #ifdef CONFIG_PPC_DCR_MMIO -u64 of_translate_dcr_address(struct device_node *dev, - unsigned int dcr_n, - unsigned int *out_stride) +static u64 of_translate_dcr_address(struct device_node *dev, + unsigned int dcr_n, + unsigned int *out_stride) { struct device_node *dp; const u32 *p; diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 95c133a0554b..52780a72d09d 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -51,10 +51,6 @@ struct platform_device *of_find_device_by_node(struct device_node *np) } EXPORT_SYMBOL(of_find_device_by_node); -#if defined(CONFIG_PPC_DCR) -#include -#endif - #ifdef CONFIG_OF_ADDRESS /* * The following routines scan a subtree and registers a device for @@ -78,26 +74,6 @@ void of_device_make_bus_id(struct device *dev) const __be32 *reg; u64 addr; -#ifdef CONFIG_PPC_DCR - /* - * If it's a DCR based device, use 'd' for native DCRs - * and 'D' for MMIO DCRs. - */ - reg = of_get_property(node, "dcr-reg", NULL); - if (reg) { -#ifdef CONFIG_PPC_DCR_NATIVE - dev_set_name(dev, "d%x.%s", *reg, node->name); -#else /* CONFIG_PPC_DCR_NATIVE */ - u64 addr = of_translate_dcr_address(node, *reg, NULL); - if (addr != OF_BAD_ADDR) { - dev_set_name(dev, "D%llx.%s", - (unsigned long long)addr, node->name); - return; - } -#endif /* !CONFIG_PPC_DCR_NATIVE */ - } -#endif /* CONFIG_PPC_DCR */ - /* Construct the name, using parent nodes if necessary to ensure uniqueness */ while (node->parent) { /* -- cgit v1.2.3 From d2d3d7cd81e90e1ffac1a6eed7b3edcbf11f4c97 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Wed, 2 Apr 2014 09:47:01 +0200 Subject: of: Use NULL for pointers Commit 4485681939b9 (of/fdt: Clean up casting in unflattening path) modified unflatten_dt_node() to take a void * for the mem parameter instead of an unsigned long. One of the call sites wasn't updated. Signed-off-by: Thierry Reding Signed-off-by: Grant Likely Conflicts: drivers/of/fdt.c --- drivers/of/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index a6f83ea107ae..d429826b61a5 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -324,7 +324,7 @@ static void __unflatten_device_tree(void *blob, /* First pass, scan for size */ start = 0; - size = (unsigned long)unflatten_dt_node(blob, 0, &start, NULL, NULL, 0); + size = (unsigned long)unflatten_dt_node(blob, NULL, &start, NULL, NULL, 0); size = ALIGN(size, 4); pr_debug(" size is %lx, allocating...\n", size); -- cgit v1.2.3 From 947fdaad0627e277c5f3a2573203c4fab3db513b Mon Sep 17 00:00:00 2001 From: Xiubo Li Date: Thu, 17 Apr 2014 15:48:29 +0800 Subject: of: fix race between search and remove in of_update_property() The of_update_property() is intented to update a property in a node and if the property does not exist, will add it. The second search of the property is possibly won't be found, that maybe removed by other thread just before the second search begain. Using the __of_find_property() and __of_add_property() instead and move them into lock operations. Signed-off-by: Xiubo Li [grant.likely: conflict with another change in same function] Signed-off-by: Grant Likely --- drivers/of/base.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 6d4ee22708c9..63ae00ec72ff 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1800,7 +1800,7 @@ int of_update_property(struct device_node *np, struct property *newprop) { struct property **next, *oldprop; unsigned long flags; - int rc, found = 0; + int rc; rc = of_property_notify(OF_RECONFIG_UPDATE_PROPERTY, np, newprop); if (rc) @@ -1809,30 +1809,34 @@ int of_update_property(struct device_node *np, struct property *newprop) if (!newprop->name) return -EINVAL; - oldprop = of_find_property(np, newprop->name, NULL); - if (!oldprop) - return of_add_property(np, newprop); - raw_spin_lock_irqsave(&devtree_lock, flags); next = &np->properties; - while (*next) { + oldprop = __of_find_property(np, newprop->name, NULL); + if (!oldprop) { + /* add the new node */ + rc = __of_add_property(np, newprop); + } else while (*next) { + /* replace the node */ if (*next == oldprop) { - /* found the node */ newprop->next = oldprop->next; *next = newprop; oldprop->next = np->deadprops; np->deadprops = oldprop; - found = 1; break; } next = &(*next)->next; } raw_spin_unlock_irqrestore(&devtree_lock, flags); - if (!found) - return -ENODEV; + if (rc) + return rc; + + /* At early boot, bail out and defer setup to of_init() */ + if (!of_kset) + return 0; /* Update the sysfs attribute */ - sysfs_remove_bin_file(&np->kobj, &oldprop->attr); + if (oldprop) + sysfs_remove_bin_file(&np->kobj, &oldprop->attr); __of_add_property_sysfs(np, newprop); return 0; -- cgit v1.2.3 From ff5f762b44237deb83be7bf6db965eeafadfa3e1 Mon Sep 17 00:00:00 2001 From: Ian Molton Date: Mon, 28 Apr 2014 15:32:21 +0100 Subject: pci/of: Remove dead code Commit 98d9f30c820d509145757e6ecbc36013aa02f7bc "pci/of: Match PCI devices to OF nodes dynamically" introduced a lot of code derived from the PPC PCI code, including some likes which were redundant. Remove these lines. Reviewed-by: William Towle Signed-off-by: Ian Molton Signed-off-by: Grant Likely --- drivers/of/of_pci_irq.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/of/of_pci_irq.c b/drivers/of/of_pci_irq.c index 8736bc7676c5..7e4e21438e28 100644 --- a/drivers/of/of_pci_irq.c +++ b/drivers/of/of_pci_irq.c @@ -19,7 +19,6 @@ int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq struct device_node *dn, *ppnode; struct pci_dev *ppdev; u32 lspec; - __be32 lspec_be; __be32 laddr[3]; u8 pin; int rc; @@ -87,7 +86,6 @@ int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq out_irq->np = ppnode; out_irq->args_count = 1; out_irq->args[0] = lspec; - lspec_be = cpu_to_be32(lspec); laddr[0] = cpu_to_be32((pdev->bus->number << 16) | (pdev->devfn << 8)); laddr[1] = laddr[2] = cpu_to_be32(0); return of_irq_parse_raw(laddr, out_irq); -- cgit v1.2.3 From b44aa25d20e2ef6b824901cbc50a281791f3b421 Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Thu, 17 Apr 2014 18:42:01 +0100 Subject: of: Handle memory@0 node on PPC32 only In order to deal with an firmware bug on a specific ppc32 platform (longtrail), early_init_dt_scan_memory() looks for a node called memory@0 on all platforms. Restrict this quirk to ppc32 kernels only. Signed-off-by: Leif Lindholm Cc: linuxppc-dev@lists.ozlabs.org Cc: Grant Likely Cc: Mark Rutland Cc: devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/of/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index d429826b61a5..17be90f5445f 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -748,7 +748,7 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname, * The longtrail doesn't have a device_type on the * /memory node, so look for the node called /memory@0. */ - if (depth != 1 || strcmp(uname, "memory@0") != 0) + if (!IS_ENABLED(CONFIG_PPC32) || depth != 1 || strcmp(uname, "memory@0") != 0) return 0; } else if (strcmp(type, "memory") != 0) return 0; -- cgit v1.2.3 From 11d200e95f3e84c1102e4cc9863a3614fd41f3ad Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Fri, 14 Mar 2014 17:00:14 +0000 Subject: lib: add glibc style strchrnul() variant The strchrnul() variant helpfully returns a the end of the string instead of a NULL if the requested character is not found. This can simplify string parsing code since it doesn't need to expicitly check for a NULL return. If a valid string pointer is passed in, then a valid null terminated string will always come back out. Signed-off-by: Grant Likely --- include/linux/string.h | 3 +++ lib/string.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index ac889c5ea11b..d36977e029af 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -52,6 +52,9 @@ extern int strncasecmp(const char *s1, const char *s2, size_t n); #ifndef __HAVE_ARCH_STRCHR extern char * strchr(const char *,int); #endif +#ifndef __HAVE_ARCH_STRCHRNUL +extern char * strchrnul(const char *,int); +#endif #ifndef __HAVE_ARCH_STRNCHR extern char * strnchr(const char *, size_t, int); #endif diff --git a/lib/string.c b/lib/string.c index 9b1f9062a202..e0c20eb362f0 100644 --- a/lib/string.c +++ b/lib/string.c @@ -301,6 +301,24 @@ char *strchr(const char *s, int c) EXPORT_SYMBOL(strchr); #endif +#ifndef __HAVE_ARCH_STRCHRNUL +/** + * strchrnul - Find and return a character in a string, or end of string + * @s: The string to be searched + * @c: The character to search for + * + * Returns pointer to first occurrence of 'c' in s. If c is not found, then + * return a pointer to the null byte at the end of s. + */ +char *strchrnul(const char *s, int c) +{ + while (*s && *s != (char)c) + s++; + return (char *)s; +} +EXPORT_SYMBOL(strchrnul); +#endif + #ifndef __HAVE_ARCH_STRRCHR /** * strrchr - Find the last occurrence of a character in a string -- cgit v1.2.3 From 0d0e02d605c5696a5076510f564fefe659127aa4 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Thu, 22 May 2014 01:04:17 +0900 Subject: of: Create unlocked version of for_each_child_of_node() When iterating over nodes, sometimes it needs to be done when the DT lock is already held. This patch makes an unlocked version of the for_each_child_of_node() macro. Signed-off-by: Grant Likely --- drivers/of/base.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 63ae00ec72ff..9df50c74162c 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -695,6 +695,22 @@ struct device_node *of_get_next_parent(struct device_node *node) } EXPORT_SYMBOL(of_get_next_parent); +static struct device_node *__of_get_next_child(const struct device_node *node, + struct device_node *prev) +{ + struct device_node *next; + + next = prev ? prev->sibling : node->child; + for (; next; next = next->sibling) + if (of_node_get(next)) + break; + of_node_put(prev); + return next; +} +#define __for_each_child_of_node(parent, child) \ + for (child = __of_get_next_child(parent, NULL); child != NULL; \ + child = __of_get_next_child(parent, child)) + /** * of_get_next_child - Iterate a node childs * @node: parent node @@ -710,11 +726,7 @@ struct device_node *of_get_next_child(const struct device_node *node, unsigned long flags; raw_spin_lock_irqsave(&devtree_lock, flags); - next = prev ? prev->sibling : node->child; - for (; next; next = next->sibling) - if (of_node_get(next)) - break; - of_node_put(prev); + next = __of_get_next_child(node, prev); raw_spin_unlock_irqrestore(&devtree_lock, flags); return next; } -- cgit v1.2.3 From c22e650e66b862babe9c00bebb20b8029c7b0362 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Fri, 14 Mar 2014 17:07:12 +0000 Subject: of: Make of_find_node_by_path() handle /aliases Make of_find_node_by_path() handle aliases as prefixes. To make this work the name search is refactored to search by path component instead of by full string. This should be a more efficient search, and it makes it possible to start a search at a subnode of a tree. Signed-off-by: David Daney Signed-off-by: Pantelis Antoniou [grant.likely: Rework to not require allocating at runtime] Acked-by: Rob Herring Signed-off-by: Grant Likely --- drivers/of/base.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 9df50c74162c..e67b308819c9 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -783,23 +783,78 @@ struct device_node *of_get_child_by_name(const struct device_node *node, } EXPORT_SYMBOL(of_get_child_by_name); +static struct device_node *__of_find_node_by_path(struct device_node *parent, + const char *path) +{ + struct device_node *child; + int len = strchrnul(path, '/') - path; + + if (!len) + return NULL; + + __for_each_child_of_node(parent, child) { + const char *name = strrchr(child->full_name, '/'); + if (WARN(!name, "malformed device_node %s\n", child->full_name)) + continue; + name++; + if (strncmp(path, name, len) == 0 && (strlen(name) == len)) + return child; + } + return NULL; +} + /** * of_find_node_by_path - Find a node matching a full OF path - * @path: The full path to match + * @path: Either the full path to match, or if the path does not + * start with '/', the name of a property of the /aliases + * node (an alias). In the case of an alias, the node + * matching the alias' value will be returned. + * + * Valid paths: + * /foo/bar Full path + * foo Valid alias + * foo/bar Valid alias + relative path * * Returns a node pointer with refcount incremented, use * of_node_put() on it when done. */ struct device_node *of_find_node_by_path(const char *path) { - struct device_node *np = of_allnodes; + struct device_node *np = NULL; + struct property *pp; unsigned long flags; + if (strcmp(path, "/") == 0) + return of_node_get(of_allnodes); + + /* The path could begin with an alias */ + if (*path != '/') { + char *p = strchrnul(path, '/'); + int len = p - path; + + /* of_aliases must not be NULL */ + if (!of_aliases) + return NULL; + + for_each_property_of_node(of_aliases, pp) { + if (strlen(pp->name) == len && !strncmp(pp->name, path, len)) { + np = of_find_node_by_path(pp->value); + break; + } + } + if (!np) + return NULL; + path = p; + } + + /* Step down the tree matching path components */ raw_spin_lock_irqsave(&devtree_lock, flags); - for (; np; np = np->allnext) { - if (np->full_name && (of_node_cmp(np->full_name, path) == 0) - && of_node_get(np)) - break; + if (!np) + np = of_node_get(of_allnodes); + while (np && *path == '/') { + path++; /* Increment past '/' delimiter */ + np = __of_find_node_by_path(np, path); + path = strchrnul(path, '/'); } raw_spin_unlock_irqrestore(&devtree_lock, flags); return np; -- cgit v1.2.3 From ae91ff72e9132abe47f726424d9420fce004ca04 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Fri, 14 Mar 2014 13:53:10 +0000 Subject: of: Add a testcase for of_find_node_by_path() Add a testcase for the find_node_by_path() function to make sure it handles all the valid scenarios. Signed-off-by: Grant Likely --- drivers/of/selftest.c | 46 +++++++++++++++++++++++++++++ drivers/of/testcase-data/tests-phandle.dtsi | 6 +++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index 2588faaaa305..077314eebb95 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c @@ -31,6 +31,51 @@ static struct selftest_results { } \ } +static void __init of_selftest_find_node_by_name(void) +{ + struct device_node *np; + + np = of_find_node_by_path("/testcase-data"); + selftest(np && !strcmp("/testcase-data", np->full_name), + "find /testcase-data failed\n"); + of_node_put(np); + + /* Test if trailing '/' works */ + np = of_find_node_by_path("/testcase-data/"); + selftest(!np, "trailing '/' on /testcase-data/ should fail\n"); + + np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); + selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name), + "find /testcase-data/phandle-tests/consumer-a failed\n"); + of_node_put(np); + + np = of_find_node_by_path("testcase-alias"); + selftest(np && !strcmp("/testcase-data", np->full_name), + "find testcase-alias failed\n"); + of_node_put(np); + + /* Test if trailing '/' works on aliases */ + np = of_find_node_by_path("testcase-alias/"); + selftest(!np, "trailing '/' on testcase-alias/ should fail\n"); + + np = of_find_node_by_path("testcase-alias/phandle-tests/consumer-a"); + selftest(np && !strcmp("/testcase-data/phandle-tests/consumer-a", np->full_name), + "find testcase-alias/phandle-tests/consumer-a failed\n"); + of_node_put(np); + + np = of_find_node_by_path("/testcase-data/missing-path"); + selftest(!np, "non-existent path returned node %s\n", np->full_name); + of_node_put(np); + + np = of_find_node_by_path("missing-alias"); + selftest(!np, "non-existent alias returned node %s\n", np->full_name); + of_node_put(np); + + np = of_find_node_by_path("testcase-alias/missing-path"); + selftest(!np, "non-existent alias with relative path returned node %s\n", np->full_name); + of_node_put(np); +} + static void __init of_selftest_dynamic(void) { struct device_node *np; @@ -484,6 +529,7 @@ static int __init of_selftest(void) of_node_put(np); pr_info("start of selftest - you will see error messages\n"); + of_selftest_find_node_by_name(); of_selftest_dynamic(); of_selftest_parse_phandle_with_args(); of_selftest_property_match_string(); diff --git a/drivers/of/testcase-data/tests-phandle.dtsi b/drivers/of/testcase-data/tests-phandle.dtsi index 788a4c24b8f5..ce0fe083d406 100644 --- a/drivers/of/testcase-data/tests-phandle.dtsi +++ b/drivers/of/testcase-data/tests-phandle.dtsi @@ -1,6 +1,10 @@ / { - testcase-data { + aliases { + testcase-alias = &testcase; + }; + + testcase: testcase-data { security-password = "password"; duplicate-name = "duplicate"; duplicate-name { }; -- cgit v1.2.3 From ad69674e73a18dc3a8da557f4059ccf9389531a5 Mon Sep 17 00:00:00 2001 From: Grygorii Strashko Date: Tue, 20 May 2014 13:42:02 +0300 Subject: of/irq: do irq resolution in platform_get_irq_byname() The commit 9ec36cafe43bf835f8f29273597a5b0cbc8267ef "of/irq: do irq resolution in platform_get_irq" from Rob Herring - moves resolving of the interrupt resources in platform_get_irq(). But this solution isn't complete because platform_get_irq_byname() need to be modified the same way. Hence, fix it by adding interrupt resolution code at the platform_get_irq_byname() function too. Cc: Russell King Cc: Rob Herring Cc: Tony Lindgren Cc: Grant Likely Cc: Thierry Reding Signed-off-by: Grygorii Strashko Signed-off-by: Grant Likely --- drivers/base/platform.c | 7 +++++-- drivers/of/irq.c | 22 ++++++++++++++++++++++ include/linux/of_irq.h | 5 +++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 5b47210889e0..9e9227e1762d 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -131,9 +131,12 @@ EXPORT_SYMBOL_GPL(platform_get_resource_byname); */ int platform_get_irq_byname(struct platform_device *dev, const char *name) { - struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ, - name); + struct resource *r; + + if (IS_ENABLED(CONFIG_OF_IRQ) && dev->dev.of_node) + return of_irq_get_byname(dev->dev.of_node, name); + r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name); return r ? r->start : -ENXIO; } EXPORT_SYMBOL_GPL(platform_get_irq_byname); diff --git a/drivers/of/irq.c b/drivers/of/irq.c index 5aeb89411350..3e06a699352d 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -405,6 +405,28 @@ int of_irq_get(struct device_node *dev, int index) return irq_create_of_mapping(&oirq); } +/** + * of_irq_get_byname - Decode a node's IRQ and return it as a Linux irq number + * @dev: pointer to device tree node + * @name: irq name + * + * Returns Linux irq number on success, or -EPROBE_DEFER if the irq domain + * is not yet created, or error code in case of any other failure. + */ +int of_irq_get_byname(struct device_node *dev, const char *name) +{ + int index; + + if (unlikely(!name)) + return -EINVAL; + + index = of_property_match_string(dev, "interrupt-names", name); + if (index < 0) + return index; + + return of_irq_get(dev, index); +} + /** * of_irq_count - Count the number of IRQs a node uses * @dev: pointer to device tree node diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h index 6404253d810d..bfec136a6d1e 100644 --- a/include/linux/of_irq.h +++ b/include/linux/of_irq.h @@ -45,6 +45,7 @@ extern void of_irq_init(const struct of_device_id *matches); #ifdef CONFIG_OF_IRQ extern int of_irq_count(struct device_node *dev); extern int of_irq_get(struct device_node *dev, int index); +extern int of_irq_get_byname(struct device_node *dev, const char *name); #else static inline int of_irq_count(struct device_node *dev) { @@ -54,6 +55,10 @@ static inline int of_irq_get(struct device_node *dev, int index) { return 0; } +static inline int of_irq_get_byname(struct device_node *dev, const char *name) +{ + return 0; +} #endif #if defined(CONFIG_OF) -- cgit v1.2.3 From 08cf78ed41feaa21017487bad0a5a405c6cede43 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sun, 25 May 2014 22:50:06 +0400 Subject: of_pci_irq: kill useless variable in of_irq_parse_pci() The 'lspec' variable only caused pointless promotions from u8 to u32 on each loop iteration, while it's enough to promote only once, after the loop. Signed-off-by: Sergei Shtylyov Signed-off-by: Grant Likely --- drivers/of/of_pci_irq.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/of/of_pci_irq.c b/drivers/of/of_pci_irq.c index 7e4e21438e28..1710d9dc7fc2 100644 --- a/drivers/of/of_pci_irq.c +++ b/drivers/of/of_pci_irq.c @@ -18,7 +18,6 @@ int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq { struct device_node *dn, *ppnode; struct pci_dev *ppdev; - u32 lspec; __be32 laddr[3]; u8 pin; int rc; @@ -45,7 +44,6 @@ int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq return -ENODEV; /* Now we walk up the PCI tree */ - lspec = pin; for (;;) { /* Get the pci_dev of our parent */ ppdev = pdev->bus->self; @@ -79,13 +77,13 @@ int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq /* We can only get here if we hit a P2P bridge with no node, * let's do standard swizzling and try again */ - lspec = pci_swizzle_interrupt_pin(pdev, lspec); + pin = pci_swizzle_interrupt_pin(pdev, pin); pdev = ppdev; } out_irq->np = ppnode; out_irq->args_count = 1; - out_irq->args[0] = lspec; + out_irq->args[0] = pin; laddr[0] = cpu_to_be32((pdev->bus->number << 16) | (pdev->devfn << 8)); laddr[1] = laddr[2] = cpu_to_be32(0); return of_irq_parse_raw(laddr, out_irq); -- cgit v1.2.3