Skip to contentSkip to conversation

powerpc/powernv: Enhance opal message read interface

PATCH Superseded Vasant Hegde 2 participants 5 messages Aug 21, 2019 – Aug 23, 2019 PowerPC

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 powerpc/powernv: Enhance opal message read interface

Use "opal-msg-size" device tree property to allocate memory for "opal_msg".

Cc Mahesh Salgaonkar <[email protected]>
Cc Jeremy Kerr <[email protected]>

---
Changes in v3:
- Call BUG_ON, if we fail to allocate memory during init.

-Vasant

 arch/powerpc/platforms/powernv/opal.c | 29 ++++++++++++++++++---------
 1 file changed, 19 insertions(+), 10 deletions(-)
arch/powerpc/platforms/powernv/opal.c +19 -10
index aba443be7daa..4f1f68f568bf 100644
@@ -58,6 +58,8 @@ static DEFINE_SPINLOCK(opal_write_lock);
 static struct atomic_notifier_head opal_msg_notifier_head[OPAL_MSG_TYPE_MAX];
 static uint32_t opal_heartbeat;
 static struct task_struct *kopald_tsk;
+static struct opal_msg *opal_msg;
+static uint64_t opal_msg_size;
 
 void opal_configure_cores(void)
 {
@@ -271,14 +273,9 @@ static void opal_message_do_notify(uint32_t msg_type, void *msg)
 static void opal_handle_message(void)
 {
 	s64 ret;
-	/*
-	 * TODO: pre-allocate a message buffer depending on opal-msg-size
-	 * value in /proc/device-tree.
-	 */
-	static struct opal_msg msg;
 	u32 type;
 
-	ret = opal_get_msg(__pa(&msg), sizeof(msg));
+	ret = opal_get_msg(__pa(opal_msg), opal_msg_size);
 	/* No opal message pending. */
 	if (ret == OPAL_RESOURCE)
 		return;
@@ -290,14 +287,14 @@ static void opal_handle_message(void)
 		return;
 	}
 
-	type = be32_to_cpu(msg.msg_type);
+	type = be32_to_cpu(opal_msg->msg_type);
 
 	/* Sanity check */
 	if (type >= OPAL_MSG_TYPE_MAX) {
 		pr_warn_once("%s: Unknown message type: %u\n", __func__, type);
 		return;
 	}
-	opal_message_do_notify(type, (void *)&msg);
+	opal_message_do_notify(type, (void *)opal_msg);
 }
 
 static irqreturn_t opal_message_notify(int irq, void *data)
@@ -306,9 +303,21 @@ static irqreturn_t opal_message_notify(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-static int __init opal_message_init(void)
+static int __init opal_message_init(struct device_node *opal_node)
 {
 	int ret, i, irq;
+	const __be32 *val;
+
+	val = of_get_property(opal_node, "opal-msg-size", NULL);
+	if (val)
+		opal_msg_size = be32_to_cpup(val);
+
+	/* If opal-msg-size property is not available then use default size */
+	if (!opal_msg_size)
+		opal_msg_size = sizeof(struct opal_msg);
+
+	opal_msg = kmalloc(opal_msg_size, GFP_KERNEL);
+	BUG_ON(opal_msg == NULL);
 
 	for (i = 0; i < OPAL_MSG_TYPE_MAX; i++)
 		ATOMIC_INIT_NOTIFIER_HEAD(&opal_msg_notifier_head[i]);
@@ -910,7 +919,7 @@ static int __init opal_init(void)
 	}
 
 	/* Initialise OPAL messaging system */
-	opal_message_init();
+	opal_message_init(opal_node);
 
 	/* Initialise OPAL asynchronous completion interface */
 	opal_async_comp_init();
Signature · 1 line
2.21.0
#1 lore raw

PATCH v3 2/2 powerpc/powernv: Add new opal message type

We have OPAL_MSG_PRD message type to pass prd related messages from OPAL to opal-prd. It can handle messages upto 64 bytes. We have a requirement to send bigger than 64 bytes of data from OPAL to opal-prd. Lets add new message type (OPAL_MSG_PRD2) to pass bigger data.

---
 arch/powerpc/include/asm/opal-api.h       | 1 +
 arch/powerpc/platforms/powernv/opal-prd.c | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/opal-api.h +1 -0
index 383242eb0dea..1cad413e1e0e 100644
@@ -453,6 +453,7 @@ enum opal_msg_type {
 	OPAL_MSG_DPO		= 5,
 	OPAL_MSG_PRD		= 6,
 	OPAL_MSG_OCC		= 7,
+	OPAL_MSG_PRD2		= 8,
 	OPAL_MSG_TYPE_MAX,
 };
 
arch/powerpc/platforms/powernv/opal-prd.c +8 -1
index e072bf157d62..50a735d77192 100644
@@ -342,7 +342,7 @@ static int opal_prd_msg_notifier(struct notifier_block *nb,
 	int msg_size, item_size;
 	unsigned long flags;
 
-	if (msg_type != OPAL_MSG_PRD)
+	if (msg_type != OPAL_MSG_PRD && msg_type != OPAL_MSG_PRD2)
 		return 0;
 
 	/* Calculate total size of the message and item we need to store. The
@@ -393,6 +393,13 @@ static int opal_prd_probe(struct platform_device *pdev)
 		return rc;
 	}
 
+	rc = opal_message_notifier_register(OPAL_MSG_PRD2, &opal_prd_event_nb);
+	if (rc) {
+		pr_err("%s: Couldn't register event notifier (%d)\n",
+		       __func__, OPAL_MSG_PRD2);
+		return rc;
+	}
+
 	rc = misc_register(&opal_prd_dev);
 	if (rc) {
 		pr_err("failed to register miscdev\n");
Signature · 1 line
2.21.0
#2 lore raw
In reply to Vasant Hegde
Quoted 64 lines · Vasant Hegde

Use "opal-msg-size" device tree property to allocate memory for "opal_msg".

Cc Mahesh Salgaonkar <[email protected]>
Cc Jeremy Kerr <[email protected]>

---
Changes in v3:
- Call BUG_ON, if we fail to allocate memory during init.

(quoted diff) +0 -1
-Vasant
 
 arch/powerpc/platforms/powernv/opal.c | 29 ++++++++++++++++++---------
 1 file changed, 19 insertions(+), 10 deletions(-)
arch/powerpc/platforms/powernv/opal.c +5 -8
index aba443be7daa..4f1f68f568bf 100644
@@ -58,6 +58,8 @@ static DEFINE_SPINLOCK(opal_write_lock);
 static struct atomic_notifier_head opal_msg_notifier_head[OPAL_MSG_TYPE_MAX];
 static uint32_t opal_heartbeat;
 static struct task_struct *kopald_tsk;
+static struct opal_msg *opal_msg;
+static uint64_t opal_msg_size;
 
 void opal_configure_cores(void)
 {
@@ -271,14 +273,9 @@ static void opal_message_do_notify(uint32_t msg_type, void *msg)
 static void opal_handle_message(void)
 {
 	s64 ret;
-	/*
-	 * TODO: pre-allocate a message buffer depending on opal-msg-size
-	 * value in /proc/device-tree.
-	 */
-	static struct opal_msg msg;
 	u32 type;
 
-	ret = opal_get_msg(__pa(&msg), sizeof(msg));
+	ret = opal_get_msg(__pa(opal_msg), opal_msg_size);
 	/* No opal message pending. */
 	if (ret == OPAL_RESOURCE)
 		return;
@@ -290,14 +287,14 @@ static void opal_handle_message(void)
 		return;
 	}
 
-	type = be32_to_cpu(msg.msg_type);
+	type = be32_to_cpu(opal_msg->msg_type);
 
 	/* Sanity check */
 	if (type >= OPAL_MSG_TYPE_MAX) {
 		pr_warn_once("%s: Unknown message type: %u\n", __func__, type);
 		return;
 	}
-	opal_message_do_notify(type, (void *)&msg);
+	opal_message_do_notify(type, (void *)opal_msg);
 }
 
 static irqreturn_t opal_message_notify(int irq, void *data)
@@ -306,9 +303,21 @@ static irqreturn_t opal_message_notify(int irq, void *data)
 	return IRQ_HANDLED;
 }
 

arch/powerpc/platforms/powernv/opal.c static irqreturn_t opal_message_notify(int irq, void *data) · line 314

Quoted 10 lines
arch/powerpc/platforms/powernv/opal.c +6 -1
-static int __init opal_message_init(void)
+static int __init opal_message_init(struct device_node *opal_node)
 {
 	int ret, i, irq;
 
+	const __be32 *val;
+
+	val = of_get_property(opal_node, "opal-msg-size", NULL);
+	if (val)
+		opal_msg_size = be32_to_cpup(val);

Use of_property_read_u32()

arch/powerpc/platforms/powernv/opal.c static irqreturn_t opal_message_notify(int irq, void *data)

Quoted 8 lines
arch/powerpc/platforms/powernv/opal.c +7 -0
+
+	/* If opal-msg-size property is not available then use default size */
+	if (!opal_msg_size)
+		opal_msg_size = sizeof(struct opal_msg);
+
+	opal_msg = kmalloc(opal_msg_size, GFP_KERNEL);
 
+	BUG_ON(opal_msg == NULL);

Seems questionable. Why not fall back to using a staticly allocated struct opal_msg? Or re-try the allocation with the size limited to sizeof(struct opal_msg)?

Quoted 11 lines
arch/powerpc/platforms/powernv/opal.c +0 -0
 	for (i = 0; i < OPAL_MSG_TYPE_MAX; i++)
arch/powerpc/platforms/powernv/opal.c +1 -1
 		ATOMIC_INIT_NOTIFIER_HEAD(&opal_msg_notifier_head[i]);
@@ -910,7 +919,7 @@ static int __init opal_init(void)
 	}
 
 	/* Initialise OPAL messaging system */
-	opal_message_init();
+	opal_message_init(opal_node);
 
 	/* Initialise OPAL asynchronous completion interface */
 	opal_async_comp_init();
#3 lore raw
Quoted 70 lines · Oliver O'Halloran
Quoted 68 lines · Vasant Hegde

Use "opal-msg-size" device tree property to allocate memory for "opal_msg".

Cc Mahesh Salgaonkar <[email protected]>
Cc Jeremy Kerr <[email protected]>

---
Changes in v3:
- Call BUG_ON, if we fail to allocate memory during init.

(quoted diff) +0 -1
-Vasant
 
  arch/powerpc/platforms/powernv/opal.c | 29 ++++++++++++++++++---------
  1 file changed, 19 insertions(+), 10 deletions(-)
arch/powerpc/platforms/powernv/opal.c +6 -9
index aba443be7daa..4f1f68f568bf 100644
@@ -58,6 +58,8 @@ static DEFINE_SPINLOCK(opal_write_lock);
  static struct atomic_notifier_head opal_msg_notifier_head[OPAL_MSG_TYPE_MAX];
  static uint32_t opal_heartbeat;
  static struct task_struct *kopald_tsk;
+static struct opal_msg *opal_msg;
+static uint64_t opal_msg_size;
 
  void opal_configure_cores(void)
  {
@@ -271,14 +273,9 @@ static void opal_message_do_notify(uint32_t msg_type, void *msg)
  static void opal_handle_message(void)
  {
  	s64 ret;
-	/*
-	 * TODO: pre-allocate a message buffer depending on opal-msg-size
-	 * value in /proc/device-tree.
-	 */
-	static struct opal_msg msg;
  	u32 type;
 
-	ret = opal_get_msg(__pa(&msg), sizeof(msg));
+	ret = opal_get_msg(__pa(opal_msg), opal_msg_size);
  	/* No opal message pending. */
  	if (ret == OPAL_RESOURCE)
  		return;
@@ -290,14 +287,14 @@ static void opal_handle_message(void)
  		return;
  	}
 
-	type = be32_to_cpu(msg.msg_type);
+	type = be32_to_cpu(opal_msg->msg_type);
 
  	/* Sanity check */
  	if (type >= OPAL_MSG_TYPE_MAX) {
  		pr_warn_once("%s: Unknown message type: %u\n", __func__, type);
  		return;
  	}
-	opal_message_do_notify(type, (void *)&msg);
+	opal_message_do_notify(type, (void *)opal_msg);
  }
 
  static irqreturn_t opal_message_notify(int irq, void *data)
@@ -306,9 +303,21 @@ static irqreturn_t opal_message_notify(int irq, void *data)
  	return IRQ_HANDLED;
  }
 
-static int __init opal_message_init(void)
+static int __init opal_message_init(struct device_node *opal_node)
  {
  	int ret, i, irq;
Quoted 7 lines

arch/powerpc/platforms/powernv/opal.c static irqreturn_t opal_message_notify(int irq, void *data) · line 313

Quoted 5 lines
arch/powerpc/platforms/powernv/opal.c +5 -0
+	const __be32 *val;
+
+	val = of_get_property(opal_node, "opal-msg-size", NULL);
+	if (val)
+		opal_msg_size = be32_to_cpup(val);

Use of_property_read_u32()

Yes. Will fix it.

Quoted 8 lines
Quoted 7 lines
arch/powerpc/platforms/powernv/opal.c +6 -0
+
+	/* If opal-msg-size property is not available then use default size */
+	if (!opal_msg_size)
+		opal_msg_size = sizeof(struct opal_msg);
+
+	opal_msg = kmalloc(opal_msg_size, GFP_KERNEL);
Quoted 5 lines

arch/powerpc/platforms/powernv/opal.c static irqreturn_t opal_message_notify(int irq, void *data) · line 320

Quoted 1 line
arch/powerpc/platforms/powernv/opal.c +1 -0
+	BUG_ON(opal_msg == NULL);

Seems questionable. Why not fall back to using a staticly allocated struct opal_msg? Or re-try the allocation with the size limited to sizeof(struct opal_msg)?

If we are not able to allocate memory during init then we have bigger problem. No point in continuing. Hence added BUG_ON().
May be I can retry allocation with fixed size before calling BUG_ON(). How about something like below :

+ /* If opal-msg-size property is not available then use default size */
+ if (!opal_msg_size)
+ opal_msg_size = sizeof(struct opal_msg);
+
+ opal_msg = kmalloc(opal_msg_size, GFP_KERNEL);
+ if (!opal_msg) {
+ opal_msg = kmalloc(sizeof(struct opal_msg), GFP_KERNEL);
+ BUG_ON(opal_msg == NULL);
+ }

-Vasant

#4 lore raw
Quoted 95 lines · Vasant Hegde
Quoted 65 lines · Oliver O'Halloran
Quoted 63 lines · Vasant Hegde

Use "opal-msg-size" device tree property to allocate memory for "opal_msg".

Cc Mahesh Salgaonkar <[email protected]>
Cc Jeremy Kerr <[email protected]>

---
Changes in v3:
   - Call BUG_ON, if we fail to allocate memory during init.

-Vasant

  arch/powerpc/platforms/powernv/opal.c | 29 ++++++++++++++++++---------

  1 file changed, 19 insertions(+), 10 deletions(-)
arch/powerpc/platforms/powernv/opal.c +6 -9
index aba443be7daa..4f1f68f568bf 100644
@@ -58,6 +58,8 @@ static DEFINE_SPINLOCK(opal_write_lock);
   static struct atomic_notifier_head opal_msg_notifier_head[OPAL_MSG_TYPE_MAX];
   static uint32_t opal_heartbeat;
   static struct task_struct *kopald_tsk;
+static struct opal_msg *opal_msg;
+static uint64_t opal_msg_size;
   void opal_configure_cores(void)
   {
@@ -271,14 +273,9 @@ static void opal_message_do_notify(uint32_t msg_type, 
 void *msg)
   static void opal_handle_message(void)
   {
       s64 ret;
-    /*
-     * TODO: pre-allocate a message buffer depending on opal-msg-size
-     * value in /proc/device-tree.
-     */
-    static struct opal_msg msg;
       u32 type;
-    ret = opal_get_msg(__pa(&msg), sizeof(msg));
+    ret = opal_get_msg(__pa(opal_msg), opal_msg_size);
       /* No opal message pending. */
       if (ret == OPAL_RESOURCE)
           return;
@@ -290,14 +287,14 @@ static void opal_handle_message(void)
           return;
       }
-    type = be32_to_cpu(msg.msg_type);
+    type = be32_to_cpu(opal_msg->msg_type);
       /* Sanity check */
       if (type >= OPAL_MSG_TYPE_MAX) {
           pr_warn_once("%s: Unknown message type: %u\n", __func__, type);
           return;
       }
-    opal_message_do_notify(type, (void *)&msg);
+    opal_message_do_notify(type, (void *)opal_msg);
   }
   static irqreturn_t opal_message_notify(int irq, void *data)
@@ -306,9 +303,21 @@ static irqreturn_t opal_message_notify(int irq, void *data)
       return IRQ_HANDLED;
   }
-static int __init opal_message_init(void)
+static int __init opal_message_init(struct device_node *opal_node)
   {
       int ret, i, irq;
Quoted 7 lines

arch/powerpc/platforms/powernv/opal.c static irqreturn_t opal_message_notify(int irq, void *data) · line 313

Quoted 5 lines
arch/powerpc/platforms/powernv/opal.c +5 -0
+    const __be32 *val;
+
+    val = of_get_property(opal_node, "opal-msg-size", NULL);
+    if (val)
+        opal_msg_size = be32_to_cpup(val);

Use of_property_read_u32()

Yes. Will fix it.

Quoted 8 lines
Quoted 7 lines
arch/powerpc/platforms/powernv/opal.c +6 -0
+
+    /* If opal-msg-size property is not available then use default size */
+    if (!opal_msg_size)
+        opal_msg_size = sizeof(struct opal_msg);
+
+    opal_msg = kmalloc(opal_msg_size, GFP_KERNEL);
Quoted 5 lines

arch/powerpc/platforms/powernv/opal.c static irqreturn_t opal_message_notify(int irq, void *data) · line 320

Quoted 1 line
arch/powerpc/platforms/powernv/opal.c +1 -0
+    BUG_ON(opal_msg == NULL);

Seems questionable. Why not fall back to using a staticly allocated struct opal_msg? Or re-try the allocation with the size limited to sizeof(struct opal_msg)?

If we are not able to allocate memory during init then we have bigger problem. No point in continuing. Hence added BUG_ON().
May be I can retry allocation with fixed size before calling BUG_ON(). How about something like below :

Quoted 6 lines

+       /* If opal-msg-size property is not available then use default size */ +       if (!opal_msg_size)
+               opal_msg_size = sizeof(struct opal_msg);
+
+       opal_msg = kmalloc(opal_msg_size, GFP_KERNEL);
+       if (!opal_msg) {

Just to be clear I will adjust opal_msg_size size here.

-Vasant

Quoted 7 lines

+               opal_msg = kmalloc(sizeof(struct opal_msg), GFP_KERNEL); +               BUG_ON(opal_msg == NULL);
+       }

-Vasant