Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of/address: Use propper endianess in get_flags

This patch changes u32 to __be32 for all "ranges", "prop" and "addr" and
such. Those variables are pointing to the device tree which containts
intergers in big endian format.
Most functions are doing it right because of_read_number() is doing the
right thing for them. of_bus_isa_get_flags(), of_bus_pci_get_flags() and
of_bus_isa_map() were accessing the data directly and were doing it wrong.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Sebastian Siewior and committed by
Benjamin Herrenschmidt
982cf004 518fdae2

+32 -30
+1 -1
arch/powerpc/include/asm/prom.h
··· 42 42 43 43 /* Translate a DMA address from device space to CPU space */ 44 44 extern u64 of_translate_dma_address(struct device_node *dev, 45 - const u32 *in_addr); 45 + const __be32 *in_addr); 46 46 47 47 #ifdef CONFIG_PCI 48 48 extern unsigned long pci_address_to_pio(phys_addr_t address);
+28 -26
drivers/of/address.c
··· 12 12 (ns) > 0) 13 13 14 14 static struct of_bus *of_match_bus(struct device_node *np); 15 - static int __of_address_to_resource(struct device_node *dev, const u32 *addrp, 16 - u64 size, unsigned int flags, 15 + static int __of_address_to_resource(struct device_node *dev, 16 + const __be32 *addrp, u64 size, unsigned int flags, 17 17 struct resource *r); 18 18 19 19 /* Debug utility */ 20 20 #ifdef DEBUG 21 - static void of_dump_addr(const char *s, const u32 *addr, int na) 21 + static void of_dump_addr(const char *s, const __be32 *addr, int na) 22 22 { 23 23 printk(KERN_DEBUG "%s", s); 24 24 while (na--) ··· 26 26 printk("\n"); 27 27 } 28 28 #else 29 - static void of_dump_addr(const char *s, const u32 *addr, int na) { } 29 + static void of_dump_addr(const char *s, const __be32 *addr, int na) { } 30 30 #endif 31 31 32 32 /* Callbacks for bus specific translators */ ··· 36 36 int (*match)(struct device_node *parent); 37 37 void (*count_cells)(struct device_node *child, 38 38 int *addrc, int *sizec); 39 - u64 (*map)(u32 *addr, const u32 *range, 39 + u64 (*map)(u32 *addr, const __be32 *range, 40 40 int na, int ns, int pna); 41 41 int (*translate)(u32 *addr, u64 offset, int na); 42 - unsigned int (*get_flags)(const u32 *addr); 42 + unsigned int (*get_flags)(const __be32 *addr); 43 43 }; 44 44 45 45 /* ··· 55 55 *sizec = of_n_size_cells(dev); 56 56 } 57 57 58 - static u64 of_bus_default_map(u32 *addr, const u32 *range, 58 + static u64 of_bus_default_map(u32 *addr, const __be32 *range, 59 59 int na, int ns, int pna) 60 60 { 61 61 u64 cp, s, da; ··· 85 85 return 0; 86 86 } 87 87 88 - static unsigned int of_bus_default_get_flags(const u32 *addr) 88 + static unsigned int of_bus_default_get_flags(const __be32 *addr) 89 89 { 90 90 return IORESOURCE_MEM; 91 91 } ··· 110 110 *sizec = 2; 111 111 } 112 112 113 - static unsigned int of_bus_pci_get_flags(const u32 *addr) 113 + static unsigned int of_bus_pci_get_flags(const __be32 *addr) 114 114 { 115 115 unsigned int flags = 0; 116 - u32 w = addr[0]; 116 + u32 w = be32_to_cpup(addr); 117 117 118 118 switch((w >> 24) & 0x03) { 119 119 case 0x01: ··· 129 129 return flags; 130 130 } 131 131 132 - static u64 of_bus_pci_map(u32 *addr, const u32 *range, int na, int ns, int pna) 132 + static u64 of_bus_pci_map(u32 *addr, const __be32 *range, int na, int ns, 133 + int pna) 133 134 { 134 135 u64 cp, s, da; 135 136 unsigned int af, rf; ··· 161 160 return of_bus_default_translate(addr + 1, offset, na - 1); 162 161 } 163 162 164 - const u32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size, 163 + const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size, 165 164 unsigned int *flags) 166 165 { 167 166 const __be32 *prop; ··· 208 207 int of_pci_address_to_resource(struct device_node *dev, int bar, 209 208 struct resource *r) 210 209 { 211 - const u32 *addrp; 210 + const __be32 *addrp; 212 211 u64 size; 213 212 unsigned int flags; 214 213 ··· 238 237 *sizec = 1; 239 238 } 240 239 241 - static u64 of_bus_isa_map(u32 *addr, const u32 *range, int na, int ns, int pna) 240 + static u64 of_bus_isa_map(u32 *addr, const __be32 *range, int na, int ns, 241 + int pna) 242 242 { 243 243 u64 cp, s, da; 244 244 245 245 /* Check address type match */ 246 - if ((addr[0] ^ range[0]) & 0x00000001) 246 + if ((addr[0] ^ range[0]) & cpu_to_be32(1)) 247 247 return OF_BAD_ADDR; 248 248 249 249 /* Read address values, skipping high cell */ ··· 266 264 return of_bus_default_translate(addr + 1, offset, na - 1); 267 265 } 268 266 269 - static unsigned int of_bus_isa_get_flags(const u32 *addr) 267 + static unsigned int of_bus_isa_get_flags(const __be32 *addr) 270 268 { 271 269 unsigned int flags = 0; 272 - u32 w = addr[0]; 270 + u32 w = be32_to_cpup(addr); 273 271 274 272 if (w & 1) 275 273 flags |= IORESOURCE_IO; ··· 332 330 struct of_bus *pbus, u32 *addr, 333 331 int na, int ns, int pna, const char *rprop) 334 332 { 335 - const u32 *ranges; 333 + const __be32 *ranges; 336 334 unsigned int rlen; 337 335 int rone; 338 336 u64 offset = OF_BAD_ADDR; ··· 400 398 * that can be mapped to a cpu physical address). This is not really specified 401 399 * that way, but this is traditionally the way IBM at least do things 402 400 */ 403 - u64 __of_translate_address(struct device_node *dev, const u32 *in_addr, 401 + u64 __of_translate_address(struct device_node *dev, const __be32 *in_addr, 404 402 const char *rprop) 405 403 { 406 404 struct device_node *parent = NULL; ··· 477 475 return result; 478 476 } 479 477 480 - u64 of_translate_address(struct device_node *dev, const u32 *in_addr) 478 + u64 of_translate_address(struct device_node *dev, const __be32 *in_addr) 481 479 { 482 480 return __of_translate_address(dev, in_addr, "ranges"); 483 481 } 484 482 EXPORT_SYMBOL(of_translate_address); 485 483 486 - u64 of_translate_dma_address(struct device_node *dev, const u32 *in_addr) 484 + u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr) 487 485 { 488 486 return __of_translate_address(dev, in_addr, "dma-ranges"); 489 487 } 490 488 EXPORT_SYMBOL(of_translate_dma_address); 491 489 492 - const u32 *of_get_address(struct device_node *dev, int index, u64 *size, 490 + const __be32 *of_get_address(struct device_node *dev, int index, u64 *size, 493 491 unsigned int *flags) 494 492 { 495 - const u32 *prop; 493 + const __be32 *prop; 496 494 unsigned int psize; 497 495 struct device_node *parent; 498 496 struct of_bus *bus; ··· 527 525 } 528 526 EXPORT_SYMBOL(of_get_address); 529 527 530 - static int __of_address_to_resource(struct device_node *dev, const u32 *addrp, 531 - u64 size, unsigned int flags, 528 + static int __of_address_to_resource(struct device_node *dev, 529 + const __be32 *addrp, u64 size, unsigned int flags, 532 530 struct resource *r) 533 531 { 534 532 u64 taddr; ··· 566 564 int of_address_to_resource(struct device_node *dev, int index, 567 565 struct resource *r) 568 566 { 569 - const u32 *addrp; 567 + const __be32 *addrp; 570 568 u64 size; 571 569 unsigned int flags; 572 570
+3 -3
include/linux/of_address.h
··· 3 3 #include <linux/ioport.h> 4 4 #include <linux/of.h> 5 5 6 - extern u64 of_translate_address(struct device_node *np, const u32 *addr); 6 + extern u64 of_translate_address(struct device_node *np, const __be32 *addr); 7 7 extern int of_address_to_resource(struct device_node *dev, int index, 8 8 struct resource *r); 9 9 extern void __iomem *of_iomap(struct device_node *device, int index); ··· 21 21 #endif 22 22 23 23 #ifdef CONFIG_PCI 24 - extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no, 24 + extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, 25 25 u64 *size, unsigned int *flags); 26 26 extern int of_pci_address_to_resource(struct device_node *dev, int bar, 27 27 struct resource *r); ··· 32 32 return -ENOSYS; 33 33 } 34 34 35 - static inline const u32 *of_get_pci_address(struct device_node *dev, 35 + static inline const __be32 *of_get_pci_address(struct device_node *dev, 36 36 int bar_no, u64 *size, unsigned int *flags) 37 37 { 38 38 return NULL;