diff options
Diffstat (limited to 'drivers/of/address.c')
-rw-r--r-- | drivers/of/address.c | 67 |
1 files changed, 67 insertions, 0 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 | /* |