[Skiboot] [PATCH v2 2/9] opal-msg: Pass return value to callback handler

Vasant Hegde hegdevasant at linux.vnet.ibm.com
Tue Apr 9 21:49:22 AEST 2019


Kernel calls opal_get_msg() API to read OPAL message. In this path OPAL
calls "callback" handler to intimate caller that kernel read the opal
message. It assumes that read is always success. This assumption was
fine as message was always fixed size.

Next patch introduces variable size opal message. In that situation
opal_get_msg() may fail due to insufficient buffer size (ex: old kernel
and new OPAL combination). So lets add `return value` parameter to "callback"
handler. So that caller knows kernel didn't read the message and take
appropriate action.

Cc: Jeremy Kerr <jk at ozlabs.org>
Cc: Mahesh Salgaonkar <mahesh at linux.vnet.ibm.com>
Cc: Oliver O'Halloran <oohall at gmail.com>
Signed-off-by: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>
---
 core/opal-msg.c      | 16 ++++++++--------
 core/test/run-msg.c  |  5 +++--
 hw/fsp/fsp-mem-err.c |  6 +++---
 hw/occ.c             |  4 ++--
 hw/prd.c             |  4 ++--
 include/opal-msg.h   |  6 +++---
 6 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/core/opal-msg.c b/core/opal-msg.c
index 19714670e..d3dd2ae3c 100644
--- a/core/opal-msg.c
+++ b/core/opal-msg.c
@@ -1,4 +1,4 @@
-/* Copyright 2013-2014 IBM Corp.
+/* Copyright 2013-2019 IBM Corp.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
 
 struct opal_msg_entry {
 	struct list_node link;
-	void (*consumed)(void *data);
+	void (*consumed)(void *data, int status);
 	void *data;
 	struct opal_msg msg;
 };
@@ -35,8 +35,8 @@ static LIST_HEAD(msg_pending_list);
 static struct lock opal_msg_lock = LOCK_UNLOCKED;
 
 int _opal_queue_msg(enum opal_msg_type msg_type, void *data,
-		    void (*consumed)(void *data), size_t num_params,
-		    const u64 *params)
+		    void (*consumed)(void *data, int status),
+		    size_t num_params, const u64 *params)
 {
 	struct opal_msg_entry *entry;
 
@@ -75,7 +75,7 @@ int _opal_queue_msg(enum opal_msg_type msg_type, void *data,
 static int64_t opal_get_msg(uint64_t *buffer, uint64_t size)
 {
 	struct opal_msg_entry *entry;
-	void (*callback)(void *data);
+	void (*callback)(void *data, int status);
 	void *data;
 
 	if (size < sizeof(struct opal_msg) || !buffer)
@@ -103,7 +103,7 @@ static int64_t opal_get_msg(uint64_t *buffer, uint64_t size)
 	unlock(&opal_msg_lock);
 
 	if (callback)
-		callback(data);
+		callback(data, OPAL_SUCCESS);
 
 	return OPAL_SUCCESS;
 }
@@ -113,7 +113,7 @@ static int64_t opal_check_completion(uint64_t *buffer, uint64_t size,
 				     uint64_t token)
 {
 	struct opal_msg_entry *entry, *next_entry;
-	void (*callback)(void *data) = NULL;
+	void (*callback)(void *data, int status) = NULL;
 	int rc = OPAL_BUSY;
 	void *data = NULL;
 
@@ -142,7 +142,7 @@ static int64_t opal_check_completion(uint64_t *buffer, uint64_t size,
 	unlock(&opal_msg_lock);
 
 	if (callback)
-		callback(data);
+		callback(data, OPAL_SUCCESS);
 
 	return rc;
 
diff --git a/core/test/run-msg.c b/core/test/run-msg.c
index 67418a917..08e1a019b 100644
--- a/core/test/run-msg.c
+++ b/core/test/run-msg.c
@@ -1,4 +1,4 @@
-/* Copyright 2013-2014 IBM Corp.
+/* Copyright 2013-2019 IBM Corp.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -61,8 +61,9 @@ void opal_update_pending_evt(uint64_t evt_mask, uint64_t evt_values)
 }
 
 static long magic = 8097883813087437089UL;
-static void callback(void *data)
+static void callback(void *data, int status)
 {
+	assert(status == OPAL_SUCCESS);
         assert(*(uint64_t *)data == magic);
 }
 
diff --git a/hw/fsp/fsp-mem-err.c b/hw/fsp/fsp-mem-err.c
index a2b0619ff..7f01c5834 100644
--- a/hw/fsp/fsp-mem-err.c
+++ b/hw/fsp/fsp-mem-err.c
@@ -1,4 +1,4 @@
-/* Copyright 2013-2014 IBM Corp.
+/* Copyright 2013-2019 IBM Corp.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -84,7 +84,7 @@ static bool send_response_to_fsp(u32 cmd_sub_mod)
  *            in that case, at least until we clarify a bit better how
  *            we want to handle things.
  */
-static void queue_event_for_delivery(void *data __unused)
+static void queue_event_for_delivery(void *data __unused, int staus __unused)
 {
 	struct fsp_mem_err_node *entry;
 	uint64_t *merr_data;
@@ -144,7 +144,7 @@ static int queue_mem_err_node(struct OpalMemoryErrorData *merr_evt)
 	unlock(&mem_err_lock);
 
 	/* Queue up the event for delivery to OS. */
-	queue_event_for_delivery(NULL);
+	queue_event_for_delivery(NULL, OPAL_SUCCESS);
 	return 0;
 }
 
diff --git a/hw/occ.c b/hw/occ.c
index 5dc05d3fb..c892c905f 100644
--- a/hw/occ.c
+++ b/hw/occ.c
@@ -1,4 +1,4 @@
-/* Copyright 2013-2017 IBM Corp.
+/* Copyright 2013-2019 IBM Corp.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -852,7 +852,7 @@ static bool cpu_pstates_prepare_core(struct proc_chip *chip,
 }
 
 static bool occ_opal_msg_outstanding = false;
-static void occ_msg_consumed(void *data __unused)
+static void occ_msg_consumed(void *data __unused, int status __unused)
 {
 	lock(&occ_lock);
 	occ_opal_msg_outstanding = false;
diff --git a/hw/prd.c b/hw/prd.c
index c5220196b..da2447544 100644
--- a/hw/prd.c
+++ b/hw/prd.c
@@ -1,4 +1,4 @@
-/* Copyright 2014-2015 IBM Corp.
+/* Copyright 2014-2019 IBM Corp.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -81,7 +81,7 @@ static uint64_t prd_ipoll_mask;
 
 static void send_next_pending_event(void);
 
-static void prd_msg_consumed(void *data)
+static void prd_msg_consumed(void *data, int status __unused)
 {
 	struct opal_prd_msg *msg = data;
 	uint32_t proc;
diff --git a/include/opal-msg.h b/include/opal-msg.h
index 86b6d616e..9be70334d 100644
--- a/include/opal-msg.h
+++ b/include/opal-msg.h
@@ -1,4 +1,4 @@
-/* Copyright 2013-2014 IBM Corp.
+/* Copyright 2013-2019 IBM Corp.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,8 +31,8 @@
 #define OPAL_MSG_SIZE		(64 * 1024)
 
 int _opal_queue_msg(enum opal_msg_type msg_type, void *data,
-		    void (*consumed)(void *data), size_t num_params,
-		    const u64 *params);
+		    void (*consumed)(void *data, int status),
+		    size_t num_params, const u64 *params);
 
 #define opal_queue_msg(msg_type, data, cb, ...) \
 	_opal_queue_msg(msg_type, data, cb, \
-- 
2.14.3



More information about the Skiboot mailing list