powerpc/powernv: Fix endian issues with OPAL async code
authorAnton Blanchard <anton@samba.org>
Fri, 28 Mar 2014 05:33:33 +0000 (16:33 +1100)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Mon, 7 Apr 2014 00:34:27 +0000 (10:34 +1000)
OPAL defines opal_msg as a big endian struct so we have to
byte swap it on little endian builds.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/include/asm/opal.h
arch/powerpc/platforms/powernv/opal-async.c
arch/powerpc/platforms/powernv/opal-sensor.c
arch/powerpc/platforms/powernv/opal-sysparam.c
arch/powerpc/platforms/powernv/opal.c

index 6fb5f90e6464b1e40762f3b99a981d6e2a5a7b5a..fc73661c20fa384ab2966e824cd9dff81de5be5e 100644 (file)
@@ -422,9 +422,9 @@ enum OpalSysparamPerm {
 };
 
 struct opal_msg {
-       uint32_t msg_type;
-       uint32_t reserved;
-       uint64_t params[8];
+       __be32 msg_type;
+       __be32 reserved;
+       __be64 params[8];
 };
 
 struct opal_machine_check_event {
index cd0c1354d40468f5d17a8eb25f1397b071698c4a..32e2adfa532086bd107ee6c7dca5363ec78eec4f 100644 (file)
@@ -125,14 +125,15 @@ static int opal_async_comp_event(struct notifier_block *nb,
 {
        struct opal_msg *comp_msg = msg;
        unsigned long flags;
+       uint64_t token;
 
        if (msg_type != OPAL_MSG_ASYNC_COMP)
                return 0;
 
-       memcpy(&opal_async_responses[comp_msg->params[0]], comp_msg,
-                       sizeof(*comp_msg));
+       token = be64_to_cpu(comp_msg->params[0]);
+       memcpy(&opal_async_responses[token], comp_msg, sizeof(*comp_msg));
        spin_lock_irqsave(&opal_async_comp_lock, flags);
-       __set_bit(comp_msg->params[0], opal_async_complete_map);
+       __set_bit(token, opal_async_complete_map);
        spin_unlock_irqrestore(&opal_async_comp_lock, flags);
 
        wake_up(&opal_async_wait);
index 663cc9c65613f24ba0dee3b680f88cd5451c004e..7503e298c4c3798229c5f589497b45c308114dbc 100644 (file)
@@ -53,7 +53,7 @@ int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data)
                goto out_token;
        }
 
-       ret = msg.params[1];
+       ret = be64_to_cpu(msg.params[1]);
 
 out_token:
        mutex_unlock(&opal_sensor_mutex);
index 0bd249a26f307f0579625a8c1415c9c6f2e0edbd..6b614726baf2add5f95237647f128c5c7119e173 100644 (file)
@@ -64,7 +64,7 @@ static int opal_get_sys_param(u32 param_id, u32 length, void *buffer)
                goto out_token;
        }
 
-       ret = msg.params[1];
+       ret = be64_to_cpu(msg.params[1]);
 
 out_token:
        opal_async_release_token(token);
@@ -98,7 +98,7 @@ static int opal_set_sys_param(u32 param_id, u32 length, void *buffer)
                goto out_token;
        }
 
-       ret = msg.params[1];
+       ret = be64_to_cpu(msg.params[1]);
 
 out_token:
        opal_async_release_token(token);
index 7835d5bb973f765ace40e81073593439c2dedfe9..778a2793e75b019ef0dbc8e2732f5019dd7e0087 100644 (file)
@@ -281,6 +281,7 @@ static void opal_handle_message(void)
         * value in /proc/device-tree.
         */
        static struct opal_msg msg;
+       u32 type;
 
        ret = opal_get_msg(__pa(&msg), sizeof(msg));
        /* No opal message pending. */
@@ -294,13 +295,14 @@ static void opal_handle_message(void)
                return;
        }
 
+       type = be32_to_cpu(msg.msg_type);
+
        /* Sanity check */
-       if (msg.msg_type > OPAL_MSG_TYPE_MAX) {
-               pr_warning("%s: Unknown message type: %u\n",
-                               __func__, msg.msg_type);
+       if (type > OPAL_MSG_TYPE_MAX) {
+               pr_warning("%s: Unknown message type: %u\n", __func__, type);
                return;
        }
-       opal_message_do_notify(msg.msg_type, (void *)&msg);
+       opal_message_do_notify(type, (void *)&msg);
 }
 
 static int opal_message_notify(struct notifier_block *nb,