[Skiboot] [PATCH v10 05/31] opal-msg: endian fixes for opal-msg.c and opal_queue_msg callers

Nicholas Piggin npiggin at gmail.com
Sun Dec 8 23:22:46 AEDT 2019


Reported-by: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>
Reviewed-by: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
 core/flash.c          |  5 ++++-
 core/i2c.c            |  4 +++-
 core/opal-msg.c       |  2 +-
 core/pci-opal.c       | 25 ++++++++++++++++---------
 hw/dts.c              |  4 +++-
 hw/fsp/fsp-leds.c     |  4 +++-
 hw/fsp/fsp-mem-err.c  |  9 +++++----
 hw/fsp/fsp-op-panel.c |  4 +++-
 hw/fsp/fsp-rtc.c      |  3 ++-
 hw/fsp/fsp-sensor.c   |  3 ++-
 hw/fsp/fsp-sysparam.c |  6 ++++--
 hw/ipmi/ipmi-sel.c    |  6 ++++--
 hw/occ.c              |  6 ++++--
 include/opal-msg.h    |  4 ++--
 14 files changed, 56 insertions(+), 29 deletions(-)

diff --git a/core/flash.c b/core/flash.c
index 7fbfca22b..4e10229d5 100644
--- a/core/flash.c
+++ b/core/flash.c
@@ -470,7 +470,10 @@ static int64_t opal_flash_op(enum flash_op op, uint64_t id, uint64_t offset,
 
 	unlock(&flash_lock);
 
-	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, token, rc);
+	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
+			cpu_to_be64(token),
+			cpu_to_be64(rc));
+
 	return OPAL_ASYNC_COMPLETION;
 
 err:
diff --git a/core/i2c.c b/core/i2c.c
index 6bae83b42..f33028743 100644
--- a/core/i2c.c
+++ b/core/i2c.c
@@ -42,7 +42,9 @@ static void opal_i2c_request_complete(int rc, struct i2c_request *req)
 {
 	uint64_t token = (uint64_t)(unsigned long)req->user_data;
 
-	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, token, rc);
+	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
+			cpu_to_be64(token),
+			cpu_to_be64(rc));
 	free(req);
 }
 
diff --git a/core/opal-msg.c b/core/opal-msg.c
index c393be7ef..dbe75e14a 100644
--- a/core/opal-msg.c
+++ b/core/opal-msg.c
@@ -143,7 +143,7 @@ static int64_t opal_check_completion(uint64_t *buffer, uint64_t size,
 
 	lock(&opal_msg_lock);
 	list_for_each_safe(&msg_pending_list, entry, next_entry, link) {
-		if (entry->msg.msg_type == OPAL_MSG_ASYNC_COMP &&
+		if (be32_to_cpu(entry->msg.msg_type) == OPAL_MSG_ASYNC_COMP &&
 		    be64_to_cpu(entry->msg.params[0]) == token) {
 			list_del(&entry->link);
 			callback = entry->consumed;
diff --git a/core/pci-opal.c b/core/pci-opal.c
index 4dc5237cc..292f1006e 100644
--- a/core/pci-opal.c
+++ b/core/pci-opal.c
@@ -804,8 +804,10 @@ static void link_up_timer(struct timer *t, void *data,
 	rescan_slot_devices(slot);
 out:
 	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
-		       slot->async_token, get_slot_phandle(slot),
-		       slot->power_state, rc <= 0 ? rc : OPAL_BUSY);
+		       cpu_to_be64(slot->async_token),
+		       cpu_to_be64(get_slot_phandle(slot)),
+		       cpu_to_be64(slot->power_state),
+		       rc <= 0 ? cpu_to_be64(rc) : cpu_to_be64(OPAL_BUSY));
 	phb_unlock(phb);
 }
 
@@ -834,9 +836,10 @@ static void wait_for_link_up_and_rescan(struct pci_slot *slot)
 		rc = slot->ops.freset(slot);
 		if (rc < 0) {
 			opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
-				       slot->async_token,
-				       get_slot_phandle(slot),
-				       slot->power_state, rc);
+				       cpu_to_be64(slot->async_token),
+				       cpu_to_be64(get_slot_phandle(slot)),
+				       cpu_to_be64(slot->power_state),
+				       cpu_to_be64(rc))
 			return;
 		}
 	} else {
@@ -863,8 +866,10 @@ static void set_power_timer(struct timer *t __unused, void *data,
 		if (slot->retries-- == 0) {
 			pci_slot_set_state(slot, PCI_SLOT_STATE_NORMAL);
 			opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
-				       slot->async_token, get_slot_phandle(slot),
-				       slot->power_state, OPAL_BUSY);
+				       cpu_to_be64(slot->async_token),
+				       cpu_to_be64(get_slot_phandle(slot)),
+				       cpu_to_be64(slot->power_state),
+				       cpu_to_be64(OPAL_BUSY));
 		} else {
 			schedule_timer(&slot->timer, msecs_to_tb(10));
 		}
@@ -875,8 +880,10 @@ static void set_power_timer(struct timer *t __unused, void *data,
 			remove_slot_devices(slot);
 			pci_slot_set_state(slot, PCI_SLOT_STATE_NORMAL);
 			opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
-				       slot->async_token, get_slot_phandle(slot),
-				       OPAL_PCI_SLOT_POWER_OFF, OPAL_SUCCESS);
+				       cpu_to_be64(slot->async_token),
+				       cpu_to_be64(get_slot_phandle(slot)),
+				       cpu_to_be64(OPAL_PCI_SLOT_POWER_OFF),
+				       cpu_to_be64(OPAL_SUCCESS));
 			break;
 		}
 
diff --git a/hw/dts.c b/hw/dts.c
index c21c5c779..b72516ab2 100644
--- a/hw/dts.c
+++ b/hw/dts.c
@@ -183,7 +183,9 @@ static void dts_async_read_temp(struct timer *t __unused, void *data,
 		dctl_clear_special_wakeup(cpu);
 
 	check_sensor_read(cpu->token);
-	rc = opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, cpu->token, rc);
+	rc = opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
+			cpu_to_be64(cpu->token),
+			cpu_to_be64(rc));
 	if (rc)
 		prerror("Failed to queue async message\n");
 
diff --git a/hw/fsp/fsp-leds.c b/hw/fsp/fsp-leds.c
index 7d234a81c..9e89f20d0 100644
--- a/hw/fsp/fsp-leds.c
+++ b/hw/fsp/fsp-leds.c
@@ -186,7 +186,9 @@ static bool is_enclosure_led(char *loc_code)
 
 static inline void opal_led_update_complete(u64 async_token, u64 result)
 {
-	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, async_token, result);
+	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
+			cpu_to_be64(async_token),
+			cpu_to_be64(result));
 }
 
 static inline bool is_sai_loc_code(const char *loc_code)
diff --git a/hw/fsp/fsp-mem-err.c b/hw/fsp/fsp-mem-err.c
index ffafb96b9..01b1e55ab 100644
--- a/hw/fsp/fsp-mem-err.c
+++ b/hw/fsp/fsp-mem-err.c
@@ -96,10 +96,11 @@ static void queue_event_for_delivery(void *data __unused, int staus __unused)
 	merr_data = (uint64_t *)&entry->data;
 
 	/* queue up for delivery */
-	rc = opal_queue_msg(OPAL_MSG_MEM_ERR, NULL,
-			    queue_event_for_delivery,
-			    merr_data[0], merr_data[1],
-			    merr_data[2], merr_data[3]);
+	rc = opal_queue_msg(OPAL_MSG_MEM_ERR, NULL, queue_event_for_delivery,
+			    cpu_to_be64(merr_data[0]),
+			    cpu_to_be64(merr_data[1]),
+			    cpu_to_be64(merr_data[2]),
+			    cpu_to_be64(merr_data[3]));
 	lock(&mem_err_lock);
 	if (rc) {
 		/*
diff --git a/hw/fsp/fsp-op-panel.c b/hw/fsp/fsp-op-panel.c
index 320da241f..00d275131 100644
--- a/hw/fsp/fsp-op-panel.c
+++ b/hw/fsp/fsp-op-panel.c
@@ -155,7 +155,9 @@ static void op_panel_write_complete(struct fsp_msg *msg)
 
 	__op_panel_write_complete(msg);
 
-	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, 1, op_async_token);
+	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
+			cpu_to_be64(1),
+			cpu_to_be64(op_async_token));
 }
 
 static int64_t __opal_write_oppanel(oppanel_line_t *lines, uint64_t num_lines,
diff --git a/hw/fsp/fsp-rtc.c b/hw/fsp/fsp-rtc.c
index e68836e66..ac12ddf22 100644
--- a/hw/fsp/fsp-rtc.c
+++ b/hw/fsp/fsp-rtc.c
@@ -139,7 +139,8 @@ static void fsp_tpo_req_complete(struct fsp_msg *read_resp)
 		break;
 	}
 	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
-		       attr->tpo_async_token, rc);
+		       cpu_to_be64(attr->tpo_async_token),
+		       cpu_to_be64(rc));
 	free(attr);
 	fsp_freemsg(read_resp);
 }
diff --git a/hw/fsp/fsp-sensor.c b/hw/fsp/fsp-sensor.c
index 74deac7a7..46385b0a6 100644
--- a/hw/fsp/fsp-sensor.c
+++ b/hw/fsp/fsp-sensor.c
@@ -293,7 +293,8 @@ static void queue_msg_for_delivery(int rc, struct opal_sensor_data *attr)
 	      __func__, rc, *(attr->sensor_data));
 	check_sensor_read(attr->async_token);
 	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
-			attr->async_token, rc);
+			cpu_to_be64(attr->async_token),
+			cpu_to_be64(rc));
 	spcn_mod_data[attr->mod_index].entry_count = 0;
 	free(attr);
 	prev_msg_consumed = true;
diff --git a/hw/fsp/fsp-sysparam.c b/hw/fsp/fsp-sysparam.c
index 0e1e8181f..c7ed36e43 100644
--- a/hw/fsp/fsp-sysparam.c
+++ b/hw/fsp/fsp-sysparam.c
@@ -194,7 +194,8 @@ static void fsp_opal_getparam_complete(uint32_t param_id __unused, int err_len,
 		rc = OPAL_INTERNAL_ERROR;
 
 	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
-			comp_data->async_token, rc);
+			cpu_to_be64(comp_data->async_token),
+			cpu_to_be64(rc));
 	free(comp_data);
 }
 
@@ -242,7 +243,8 @@ static void fsp_opal_setparam_complete(struct fsp_msg *msg)
 
 out:
 	opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
-			comp_data->async_token, rc);
+			cpu_to_be64(comp_data->async_token),
+			cpu_to_be64(rc));
 	free(comp_data);
 	fsp_freemsg(msg);
 }
diff --git a/hw/ipmi/ipmi-sel.c b/hw/ipmi/ipmi-sel.c
index 794aa3801..60df9d927 100644
--- a/hw/ipmi/ipmi-sel.c
+++ b/hw/ipmi/ipmi-sel.c
@@ -496,7 +496,8 @@ static void sel_power(uint8_t power, void *context __unused)
 			prlog(PR_NOTICE, "Host not up, shutting down now\n");
 			platform.cec_power_down(IPMI_CHASSIS_PWR_DOWN);
 		} else {
-			opal_queue_msg(OPAL_MSG_SHUTDOWN, NULL, NULL, SOFT_OFF);
+			opal_queue_msg(OPAL_MSG_SHUTDOWN, NULL, NULL,
+					cpu_to_be64(SOFT_OFF));
 		}
 
 		break;
@@ -506,7 +507,8 @@ static void sel_power(uint8_t power, void *context __unused)
 			prlog(PR_NOTICE, "Host not up, rebooting now\n");
 			platform.cec_reboot();
 		} else {
-			opal_queue_msg(OPAL_MSG_SHUTDOWN, NULL, NULL, SOFT_REBOOT);
+			opal_queue_msg(OPAL_MSG_SHUTDOWN, NULL, NULL,
+					cpu_to_be64(SOFT_REBOOT));
 		}
 
 		break;
diff --git a/hw/occ.c b/hw/occ.c
index 2c989a616..46210ba20 100644
--- a/hw/occ.c
+++ b/hw/occ.c
@@ -1126,7 +1126,9 @@ static inline void queue_occ_rsp_msg(int token, int rc)
 {
 	int ret;
 
-	ret = opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, token, rc);
+	ret = opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL,
+			cpu_to_be64(token),
+			cpu_to_be64(rc));
 	if (ret)
 		prerror("OCC: Failed to queue OCC response status message\n");
 }
@@ -1877,7 +1879,7 @@ int find_master_and_slave_occ(uint64_t **master, uint64_t **slave,
 
 int occ_msg_queue_occ_reset(void)
 {
-	struct opal_occ_msg occ_msg = { OCC_RESET, 0, 0 };
+	struct opal_occ_msg occ_msg = { CPU_TO_BE64(OCC_RESET), 0, 0 };
 	struct proc_chip *chip;
 	int rc;
 
diff --git a/include/opal-msg.h b/include/opal-msg.h
index 036183343..df605b3b6 100644
--- a/include/opal-msg.h
+++ b/include/opal-msg.h
@@ -27,8 +27,8 @@ int _opal_queue_msg(enum opal_msg_type msg_type, void *data,
 
 #define opal_queue_msg(msg_type, data, cb, ...) \
 	_opal_queue_msg(msg_type, data, cb, \
-			sizeof((u64[]) {__VA_ARGS__}), \
-			(u64[]) {__VA_ARGS__});
+			sizeof((__be64[]) {__VA_ARGS__}), \
+			(__be64[]) {__VA_ARGS__});
 
 void opal_init_msg(void);
 
-- 
2.23.0



More information about the Skiboot mailing list