diff options
| author | Olof Johansson <olof@lixom.net> | 2013-06-01 01:56:35 -0400 |
|---|---|---|
| committer | Olof Johansson <olof@lixom.net> | 2013-06-01 01:56:35 -0400 |
| commit | 4abbb75b6d77dc3d48d18abfc2d75c652cf432e3 (patch) | |
| tree | 546989da02e3e7d0eee8c763a30f8216bbbdc87e /drivers/of | |
| parent | b54338b30e0caa6212a409c1abb0856bed75643e (diff) | |
| parent | 4e23d3f505e8acfeac7cc33d4113fbb5a25c3090 (diff) | |
Merge tag 'of_pci-3.11' of git://git.infradead.org/users/jcooper/linux into next/cleanup
From Jason Cooper, of/pci changes for v3.11.
The patches had Reviewed-by: from Rob Herring on the lists, but seems to
have been missed from the commit messages. These will be required as a base
for some of the other functionality in this merge window, so taking it through
arm-soc.
Signed-off-by: Olof Johansson <olof@lixom.net>
* tag 'of_pci-3.11' of git://git.infradead.org/users/jcooper/linux:
of/pci: Add of_pci_parse_bus_range() function
of/pci: Add of_pci_get_devfn() function
of/pci: Provide support for parsing PCI DT ranges property
Diffstat (limited to 'drivers/of')
| -rw-r--r-- | drivers/of/address.c | 67 | ||||
| -rw-r--r-- | drivers/of/of_pci.c | 59 |
2 files changed, 121 insertions, 5 deletions
diff --git a/drivers/of/address.c b/drivers/of/address.c index 04da786c84d2..fdd0636a987d 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c | |||
| @@ -227,6 +227,73 @@ int of_pci_address_to_resource(struct device_node *dev, int bar, | |||
| 227 | return __of_address_to_resource(dev, addrp, size, flags, NULL, r); | 227 | return __of_address_to_resource(dev, addrp, size, flags, NULL, r); |
| 228 | } | 228 | } |
| 229 | EXPORT_SYMBOL_GPL(of_pci_address_to_resource); | 229 | EXPORT_SYMBOL_GPL(of_pci_address_to_resource); |
| 230 | |||
| 231 | int of_pci_range_parser_init(struct of_pci_range_parser *parser, | ||
| 232 | struct device_node *node) | ||
| 233 | { | ||
| 234 | const int na = 3, ns = 2; | ||
| 235 | int rlen; | ||
| 236 | |||
| 237 | parser->node = node; | ||
| 238 | parser->pna = of_n_addr_cells(node); | ||
| 239 | parser->np = parser->pna + na + ns; | ||
| 240 | |||
| 241 | parser->range = of_get_property(node, "ranges", &rlen); | ||
| 242 | if (parser->range == NULL) | ||
| 243 | return -ENOENT; | ||
| 244 | |||
| 245 | parser->end = parser->range + rlen / sizeof(__be32); | ||
| 246 | |||
| 247 | return 0; | ||
| 248 | } | ||
| 249 | EXPORT_SYMBOL_GPL(of_pci_range_parser_init); | ||
| 250 | |||
| 251 | struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, | ||
| 252 | struct of_pci_range *range) | ||
| 253 | { | ||
| 254 | const int na = 3, ns = 2; | ||
| 255 | |||
| 256 | if (!range) | ||
| 257 | return NULL; | ||
| 258 | |||
| 259 | if (!parser->range || parser->range + parser->np > parser->end) | ||
| 260 | return NULL; | ||
| 261 | |||
| 262 | range->pci_space = parser->range[0]; | ||
| 263 | range->flags = of_bus_pci_get_flags(parser->range); | ||
| 264 | range->pci_addr = of_read_number(parser->range + 1, ns); | ||
| 265 | range->cpu_addr = of_translate_address(parser->node, | ||
| 266 | parser->range + na); | ||
| 267 | range->size = of_read_number(parser->range + parser->pna + na, ns); | ||
| 268 | |||
| 269 | parser->range += parser->np; | ||
| 270 | |||
| 271 | /* Now consume following elements while they are contiguous */ | ||
| 272 | while (parser->range + parser->np <= parser->end) { | ||
| 273 | u32 flags, pci_space; | ||
| 274 | u64 pci_addr, cpu_addr, size; | ||
| 275 | |||
| 276 | pci_space = be32_to_cpup(parser->range); | ||
| 277 | flags = of_bus_pci_get_flags(parser->range); | ||
| 278 | pci_addr = of_read_number(parser->range + 1, ns); | ||
| 279 | cpu_addr = of_translate_address(parser->node, | ||
| 280 | parser->range + na); | ||
| 281 | size = of_read_number(parser->range + parser->pna + na, ns); | ||
| 282 | |||
| 283 | if (flags != range->flags) | ||
| 284 | break; | ||
| 285 | if (pci_addr != range->pci_addr + range->size || | ||
| 286 | cpu_addr != range->cpu_addr + range->size) | ||
| 287 | break; | ||
| 288 | |||
| 289 | range->size += size; | ||
| 290 | parser->range += parser->np; | ||
| 291 | } | ||
| 292 | |||
| 293 | return range; | ||
| 294 | } | ||
| 295 | EXPORT_SYMBOL_GPL(of_pci_range_parser_one); | ||
| 296 | |||
| 230 | #endif /* CONFIG_PCI */ | 297 | #endif /* CONFIG_PCI */ |
| 231 | 298 | ||
| 232 | /* | 299 | /* |
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 13e37e2d8ec1..42c687a820ac 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c | |||
| @@ -5,14 +5,15 @@ | |||
| 5 | #include <asm/prom.h> | 5 | #include <asm/prom.h> |
| 6 | 6 | ||
| 7 | static inline int __of_pci_pci_compare(struct device_node *node, | 7 | static inline int __of_pci_pci_compare(struct device_node *node, |
| 8 | unsigned int devfn) | 8 | unsigned int data) |
| 9 | { | 9 | { |
| 10 | unsigned int size; | 10 | int devfn; |
| 11 | const __be32 *reg = of_get_property(node, "reg", &size); | ||
| 12 | 11 | ||
| 13 | if (!reg || size < 5 * sizeof(__be32)) | 12 | devfn = of_pci_get_devfn(node); |
| 13 | if (devfn < 0) | ||
| 14 | return 0; | 14 | return 0; |
| 15 | return ((be32_to_cpup(®[0]) >> 8) & 0xff) == devfn; | 15 | |
| 16 | return devfn == data; | ||
| 16 | } | 17 | } |
| 17 | 18 | ||
| 18 | struct device_node *of_pci_find_child_device(struct device_node *parent, | 19 | struct device_node *of_pci_find_child_device(struct device_node *parent, |
| @@ -40,3 +41,51 @@ struct device_node *of_pci_find_child_device(struct device_node *parent, | |||
| 40 | return NULL; | 41 | return NULL; |
| 41 | } | 42 | } |
| 42 | EXPORT_SYMBOL_GPL(of_pci_find_child_device); | 43 | EXPORT_SYMBOL_GPL(of_pci_find_child_device); |
| 44 | |||
| 45 | /** | ||
| 46 | * of_pci_get_devfn() - Get device and function numbers for a device node | ||
| 47 | * @np: device node | ||
| 48 | * | ||
| 49 | * Parses a standard 5-cell PCI resource and returns an 8-bit value that can | ||
| 50 | * be passed to the PCI_SLOT() and PCI_FUNC() macros to extract the device | ||
| 51 | * and function numbers respectively. On error a negative error code is | ||
| 52 | * returned. | ||
| 53 | */ | ||
| 54 | int of_pci_get_devfn(struct device_node *np) | ||
| 55 | { | ||
| 56 | unsigned int size; | ||
| 57 | const __be32 *reg; | ||
| 58 | |||
| 59 | reg = of_get_property(np, "reg", &size); | ||
| 60 | |||
| 61 | if (!reg || size < 5 * sizeof(__be32)) | ||
| 62 | return -EINVAL; | ||
| 63 | |||
| 64 | return (be32_to_cpup(reg) >> 8) & 0xff; | ||
| 65 | } | ||
| 66 | EXPORT_SYMBOL_GPL(of_pci_get_devfn); | ||
| 67 | |||
| 68 | /** | ||
| 69 | * of_pci_parse_bus_range() - parse the bus-range property of a PCI device | ||
| 70 | * @node: device node | ||
| 71 | * @res: address to a struct resource to return the bus-range | ||
| 72 | * | ||
| 73 | * Returns 0 on success or a negative error-code on failure. | ||
| 74 | */ | ||
| 75 | int of_pci_parse_bus_range(struct device_node *node, struct resource *res) | ||
| 76 | { | ||
| 77 | const __be32 *values; | ||
| 78 | int len; | ||
| 79 | |||
| 80 | values = of_get_property(node, "bus-range", &len); | ||
| 81 | if (!values || len < sizeof(*values) * 2) | ||
| 82 | return -EINVAL; | ||
| 83 | |||
| 84 | res->name = node->name; | ||
| 85 | res->start = be32_to_cpup(values++); | ||
| 86 | res->end = be32_to_cpup(values); | ||
| 87 | res->flags = IORESOURCE_BUS; | ||
| 88 | |||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | EXPORT_SYMBOL_GPL(of_pci_parse_bus_range); | ||
