aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel
diff options
context:
space:
mode:
authorAnton Blanchard <anton@samba.org>2013-08-06 12:01:41 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2013-08-14 01:33:30 -0400
commita795dc548a973ff2a124a800718f0c99bcf78ea2 (patch)
treec5bcda8033dd8456831cf1c119b9ad0410b27f67 /arch/powerpc/kernel
parent7560d32757392f91a1b5714c309add266b336c5a (diff)
powerpc: Make OF PCI device tree accesses endian safe
Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc/kernel')
-rw-r--r--arch/powerpc/kernel/pci-common.c6
-rw-r--r--arch/powerpc/kernel/pci_of_scan.c23
2 files changed, 16 insertions, 13 deletions
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index ec6c9db7b392..eae0ee00ca25 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -667,7 +667,7 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar,
667void pci_process_bridge_OF_ranges(struct pci_controller *hose, 667void pci_process_bridge_OF_ranges(struct pci_controller *hose,
668 struct device_node *dev, int primary) 668 struct device_node *dev, int primary)
669{ 669{
670 const u32 *ranges; 670 const __be32 *ranges;
671 int rlen; 671 int rlen;
672 int pna = of_n_addr_cells(dev); 672 int pna = of_n_addr_cells(dev);
673 int np = pna + 5; 673 int np = pna + 5;
@@ -687,7 +687,7 @@ void pci_process_bridge_OF_ranges(struct pci_controller *hose,
687 /* Parse it */ 687 /* Parse it */
688 while ((rlen -= np * 4) >= 0) { 688 while ((rlen -= np * 4) >= 0) {
689 /* Read next ranges element */ 689 /* Read next ranges element */
690 pci_space = ranges[0]; 690 pci_space = of_read_number(ranges, 1);
691 pci_addr = of_read_number(ranges + 1, 2); 691 pci_addr = of_read_number(ranges + 1, 2);
692 cpu_addr = of_translate_address(dev, ranges + 3); 692 cpu_addr = of_translate_address(dev, ranges + 3);
693 size = of_read_number(ranges + pna + 3, 2); 693 size = of_read_number(ranges + pna + 3, 2);
@@ -704,7 +704,7 @@ void pci_process_bridge_OF_ranges(struct pci_controller *hose,
704 /* Now consume following elements while they are contiguous */ 704 /* Now consume following elements while they are contiguous */
705 for (; rlen >= np * sizeof(u32); 705 for (; rlen >= np * sizeof(u32);
706 ranges += np, rlen -= np * 4) { 706 ranges += np, rlen -= np * 4) {
707 if (ranges[0] != pci_space) 707 if (of_read_number(ranges, 1) != pci_space)
708 break; 708 break;
709 pci_next = of_read_number(ranges + 1, 2); 709 pci_next = of_read_number(ranges + 1, 2);
710 cpu_next = of_translate_address(dev, ranges + 3); 710 cpu_next = of_translate_address(dev, ranges + 3);
diff --git a/arch/powerpc/kernel/pci_of_scan.c b/arch/powerpc/kernel/pci_of_scan.c
index 15d9105323bf..4368ec6fdc8c 100644
--- a/arch/powerpc/kernel/pci_of_scan.c
+++ b/arch/powerpc/kernel/pci_of_scan.c
@@ -24,12 +24,12 @@
24 */ 24 */
25static u32 get_int_prop(struct device_node *np, const char *name, u32 def) 25static u32 get_int_prop(struct device_node *np, const char *name, u32 def)
26{ 26{
27 const u32 *prop; 27 const __be32 *prop;
28 int len; 28 int len;
29 29
30 prop = of_get_property(np, name, &len); 30 prop = of_get_property(np, name, &len);
31 if (prop && len >= 4) 31 if (prop && len >= 4)
32 return *prop; 32 return of_read_number(prop, 1);
33 return def; 33 return def;
34} 34}
35 35
@@ -77,7 +77,7 @@ static void of_pci_parse_addrs(struct device_node *node, struct pci_dev *dev)
77 unsigned int flags; 77 unsigned int flags;
78 struct pci_bus_region region; 78 struct pci_bus_region region;
79 struct resource *res; 79 struct resource *res;
80 const u32 *addrs; 80 const __be32 *addrs;
81 u32 i; 81 u32 i;
82 int proplen; 82 int proplen;
83 83
@@ -86,14 +86,14 @@ static void of_pci_parse_addrs(struct device_node *node, struct pci_dev *dev)
86 return; 86 return;
87 pr_debug(" parse addresses (%d bytes) @ %p\n", proplen, addrs); 87 pr_debug(" parse addresses (%d bytes) @ %p\n", proplen, addrs);
88 for (; proplen >= 20; proplen -= 20, addrs += 5) { 88 for (; proplen >= 20; proplen -= 20, addrs += 5) {
89 flags = pci_parse_of_flags(addrs[0], 0); 89 flags = pci_parse_of_flags(of_read_number(addrs, 1), 0);
90 if (!flags) 90 if (!flags)
91 continue; 91 continue;
92 base = of_read_number(&addrs[1], 2); 92 base = of_read_number(&addrs[1], 2);
93 size = of_read_number(&addrs[3], 2); 93 size = of_read_number(&addrs[3], 2);
94 if (!size) 94 if (!size)
95 continue; 95 continue;
96 i = addrs[0] & 0xff; 96 i = of_read_number(addrs, 1) & 0xff;
97 pr_debug(" base: %llx, size: %llx, i: %x\n", 97 pr_debug(" base: %llx, size: %llx, i: %x\n",
98 (unsigned long long)base, 98 (unsigned long long)base,
99 (unsigned long long)size, i); 99 (unsigned long long)size, i);
@@ -207,7 +207,7 @@ void of_scan_pci_bridge(struct pci_dev *dev)
207{ 207{
208 struct device_node *node = dev->dev.of_node; 208 struct device_node *node = dev->dev.of_node;
209 struct pci_bus *bus; 209 struct pci_bus *bus;
210 const u32 *busrange, *ranges; 210 const __be32 *busrange, *ranges;
211 int len, i, mode; 211 int len, i, mode;
212 struct pci_bus_region region; 212 struct pci_bus_region region;
213 struct resource *res; 213 struct resource *res;
@@ -230,9 +230,11 @@ void of_scan_pci_bridge(struct pci_dev *dev)
230 return; 230 return;
231 } 231 }
232 232
233 bus = pci_find_bus(pci_domain_nr(dev->bus), busrange[0]); 233 bus = pci_find_bus(pci_domain_nr(dev->bus),
234 of_read_number(busrange, 1));
234 if (!bus) { 235 if (!bus) {
235 bus = pci_add_new_bus(dev->bus, dev, busrange[0]); 236 bus = pci_add_new_bus(dev->bus, dev,
237 of_read_number(busrange, 1));
236 if (!bus) { 238 if (!bus) {
237 printk(KERN_ERR "Failed to create pci bus for %s\n", 239 printk(KERN_ERR "Failed to create pci bus for %s\n",
238 node->full_name); 240 node->full_name);
@@ -241,7 +243,8 @@ void of_scan_pci_bridge(struct pci_dev *dev)
241 } 243 }
242 244
243 bus->primary = dev->bus->number; 245 bus->primary = dev->bus->number;
244 pci_bus_insert_busn_res(bus, busrange[0], busrange[1]); 246 pci_bus_insert_busn_res(bus, of_read_number(busrange, 1),
247 of_read_number(busrange+1, 1));
245 bus->bridge_ctl = 0; 248 bus->bridge_ctl = 0;
246 249
247 /* parse ranges property */ 250 /* parse ranges property */
@@ -254,7 +257,7 @@ void of_scan_pci_bridge(struct pci_dev *dev)
254 } 257 }
255 i = 1; 258 i = 1;
256 for (; len >= 32; len -= 32, ranges += 8) { 259 for (; len >= 32; len -= 32, ranges += 8) {
257 flags = pci_parse_of_flags(ranges[0], 1); 260 flags = pci_parse_of_flags(of_read_number(ranges, 1), 1);
258 size = of_read_number(&ranges[6], 2); 261 size = of_read_number(&ranges[6], 2);
259 if (flags == 0 || size == 0) 262 if (flags == 0 || size == 0)
260 continue; 263 continue;