aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc
diff options
context:
space:
mode:
authorCédric Le Goater <clg@fr.ibm.com>2014-04-24 03:23:28 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2014-04-28 03:35:35 -0400
commit926e6940f54313813d177b5cfb9ec31a441cd259 (patch)
tree018b48b91e6556ef7dc184ae1545d050e57719a6 /arch/powerpc
parent163bed77b97c2f1e941641f81566da8ea647deda (diff)
powerpc/boot: Add byteswapping routines in oflib
Values will need to be byte-swapped when calling prom (big endian) from a little endian boot wrapper. Signed-off-by: Cédric Le Goater <clg@fr.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r--arch/powerpc/boot/of.h3
-rw-r--r--arch/powerpc/boot/ofconsole.c6
-rw-r--r--arch/powerpc/boot/oflib.c22
3 files changed, 18 insertions, 13 deletions
diff --git a/arch/powerpc/boot/of.h b/arch/powerpc/boot/of.h
index 5da03d9b9463..40d95bf7402b 100644
--- a/arch/powerpc/boot/of.h
+++ b/arch/powerpc/boot/of.h
@@ -20,4 +20,7 @@ void of_console_init(void);
20 20
21typedef u32 __be32; 21typedef u32 __be32;
22 22
23#define cpu_to_be32(x) (x)
24#define be32_to_cpu(x) (x)
25
23#endif /* _PPC_BOOT_OF_H_ */ 26#endif /* _PPC_BOOT_OF_H_ */
diff --git a/arch/powerpc/boot/ofconsole.c b/arch/powerpc/boot/ofconsole.c
index ce0e02424453..8b754702460a 100644
--- a/arch/powerpc/boot/ofconsole.c
+++ b/arch/powerpc/boot/ofconsole.c
@@ -18,7 +18,7 @@
18 18
19#include "of.h" 19#include "of.h"
20 20
21static void *of_stdout_handle; 21static unsigned int of_stdout_handle;
22 22
23static int of_console_open(void) 23static int of_console_open(void)
24{ 24{
@@ -27,8 +27,10 @@ static int of_console_open(void)
27 if (((devp = of_finddevice("/chosen")) != NULL) 27 if (((devp = of_finddevice("/chosen")) != NULL)
28 && (of_getprop(devp, "stdout", &of_stdout_handle, 28 && (of_getprop(devp, "stdout", &of_stdout_handle,
29 sizeof(of_stdout_handle)) 29 sizeof(of_stdout_handle))
30 == sizeof(of_stdout_handle))) 30 == sizeof(of_stdout_handle))) {
31 of_stdout_handle = be32_to_cpu(of_stdout_handle);
31 return 0; 32 return 0;
33 }
32 34
33 return -1; 35 return -1;
34} 36}
diff --git a/arch/powerpc/boot/oflib.c b/arch/powerpc/boot/oflib.c
index 3b0c9458504f..0f72b1a42133 100644
--- a/arch/powerpc/boot/oflib.c
+++ b/arch/powerpc/boot/oflib.c
@@ -42,13 +42,13 @@ int of_call_prom(const char *service, int nargs, int nret, ...)
42 struct prom_args args; 42 struct prom_args args;
43 va_list list; 43 va_list list;
44 44
45 args.service = ADDR(service); 45 args.service = cpu_to_be32(ADDR(service));
46 args.nargs = nargs; 46 args.nargs = cpu_to_be32(nargs);
47 args.nret = nret; 47 args.nret = cpu_to_be32(nret);
48 48
49 va_start(list, nret); 49 va_start(list, nret);
50 for (i = 0; i < nargs; i++) 50 for (i = 0; i < nargs; i++)
51 args.args[i] = va_arg(list, prom_arg_t); 51 args.args[i] = cpu_to_be32(va_arg(list, prom_arg_t));
52 va_end(list); 52 va_end(list);
53 53
54 for (i = 0; i < nret; i++) 54 for (i = 0; i < nret; i++)
@@ -57,7 +57,7 @@ int of_call_prom(const char *service, int nargs, int nret, ...)
57 if (prom(&args) < 0) 57 if (prom(&args) < 0)
58 return -1; 58 return -1;
59 59
60 return (nret > 0)? args.args[nargs]: 0; 60 return (nret > 0) ? be32_to_cpu(args.args[nargs]) : 0;
61} 61}
62 62
63static int of_call_prom_ret(const char *service, int nargs, int nret, 63static int of_call_prom_ret(const char *service, int nargs, int nret,
@@ -67,13 +67,13 @@ static int of_call_prom_ret(const char *service, int nargs, int nret,
67 struct prom_args args; 67 struct prom_args args;
68 va_list list; 68 va_list list;
69 69
70 args.service = ADDR(service); 70 args.service = cpu_to_be32(ADDR(service));
71 args.nargs = nargs; 71 args.nargs = cpu_to_be32(nargs);
72 args.nret = nret; 72 args.nret = cpu_to_be32(nret);
73 73
74 va_start(list, rets); 74 va_start(list, rets);
75 for (i = 0; i < nargs; i++) 75 for (i = 0; i < nargs; i++)
76 args.args[i] = va_arg(list, prom_arg_t); 76 args.args[i] = cpu_to_be32(va_arg(list, prom_arg_t));
77 va_end(list); 77 va_end(list);
78 78
79 for (i = 0; i < nret; i++) 79 for (i = 0; i < nret; i++)
@@ -84,9 +84,9 @@ static int of_call_prom_ret(const char *service, int nargs, int nret,
84 84
85 if (rets != (void *) 0) 85 if (rets != (void *) 0)
86 for (i = 1; i < nret; ++i) 86 for (i = 1; i < nret; ++i)
87 rets[i-1] = args.args[nargs+i]; 87 rets[i-1] = be32_to_cpu(args.args[nargs+i]);
88 88
89 return (nret > 0)? args.args[nargs]: 0; 89 return (nret > 0) ? be32_to_cpu(args.args[nargs]) : 0;
90} 90}
91 91
92/* returns true if s2 is a prefix of s1 */ 92/* returns true if s2 is a prefix of s1 */