Skip to contentSkip to conversation

OMAP: mailbox: fixes and enhancements

PATCH New Hari Kanigeri 1 participant 5 messages Nov 29, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v5 cover OMAP: mailbox: fixes and enhancements

Here is the revised set taking into account comments received on previous patch set
========================

- Dropped the "OMAP: mailbox: fix rx interrupt disable in omap4" patch. This patch will be sent along with mailbox hwmod changes.
- Fixed the typo kifo to kfifo in "OMAP: mailbox: send message in process context" patch.

References:
http://marc.info/?l=linux-omap&m=129069379825760&w=2
http://marc.info/?l=linux-omap&m=129060518315342&w=2

The previous versions of this patch set can be found here
=======================
http://www.spinics.net/lists/linux-omap/msg40714.html
http://www.spinics.net/lists/arm-kernel/msg104544.html
http://www.spinics.net/lists/linux-omap/msg39988.html
http://www.spinics.net/lists/linux-omap/msg39931.html
http://www.mail-archive.com/[email protected]/msg37278.html

Fernando Guzman Lugo (1):
OMAP: mailbox: change full flag per mailbox queue instead of global

Hari Kanigeri (3):
OMAP: mailbox: fix checkpatch warnings
OMAP: mailbox: send message in process context
OMAP: mailbox: add notification support for multiple readers

 arch/arm/plat-omap/include/plat/mailbox.h |    8 +-
 arch/arm/plat-omap/mailbox.c              |  130 +++++++++++++++++------------
 2 files changed, 81 insertions(+), 57 deletions(-)
#1 lore raw

PATCH v5 1/4 OMAP: mailbox: change full flag per mailbox queue instead of global

From: Fernando Guzman Lugo <[email protected]>

The variable rq_full flag is a global variable, so if there are multiple mailbox users there will be conflicts. Now there is a full flag per mailbox queue.

---
 arch/arm/plat-omap/include/plat/mailbox.h |    1 +
 arch/arm/plat-omap/mailbox.c              |    9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)
arch/arm/plat-omap/include/plat/mailbox.h +1 -0
index 9976565..13f2ef3 100644
@@ -48,6 +48,7 @@ struct omap_mbox_queue {
 	struct tasklet_struct	tasklet;
 	int	(*callback)(void *);
 	struct omap_mbox	*mbox;
+	bool full;
 };
 
 struct omap_mbox {
arch/arm/plat-omap/mailbox.c +7 -2
index d2fafb8..48e161c 100644
@@ -33,7 +33,6 @@
 
 static struct workqueue_struct *mboxd;
 static struct omap_mbox **mboxes;
-static bool rq_full;
 
 static int mbox_configured;
 static DEFINE_MUTEX(mbox_configured_lock);
@@ -148,6 +147,12 @@ static void mbox_rx_work(struct work_struct *work)
 
 		if (mq->callback)
 			mq->callback((void *)msg);
+		spin_lock_irq(&mq->lock);
+		if (mq->full) {
+			mq->full = false;
+			omap_mbox_enable_irq(mq->mbox, IRQ_RX);
+		}
+		spin_unlock_irq(&mq->lock);
 	}
 }
 
@@ -170,7 +175,7 @@ static void __mbox_rx_interrupt(struct omap_mbox *mbox)
 	while (!mbox_fifo_empty(mbox)) {
 		if (unlikely(kfifo_avail(&mq->fifo) < sizeof(msg))) {
 			omap_mbox_disable_irq(mbox, IRQ_RX);
-			rq_full = true;
+			mq->full = true;
 			goto nomem;
 		}
 
Signature · 1 line
1.7.0
#2 lore raw

PATCH v5 2/4 OMAP: mailbox: fix checkpatch warnings

In reply to Hari Kanigeri

Fix the following checkpatch warnings observed in mailbox module.

WARNING: please, no space for starting a line,
excluding comments
+ fail_alloc_rxq:$

WARNING: please, no space for starting a line,
excluding comments
+ fail_alloc_txq:$

WARNING: please, no space for starting a line,
excluding comments
+ fail_request_irq:$

WARNING: line over 80 characters
+ mbox_kfifo_size = max_t(unsigned int, mbox_kfifo_size, sizeof(mbox_msg_t));

---
 arch/arm/plat-omap/mailbox.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
arch/arm/plat-omap/mailbox.c +5 -4
index 48e161c..d9aa87c 100644
@@ -281,11 +281,11 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
 
 	return 0;
 
- fail_alloc_rxq:
+fail_alloc_rxq:
 	mbox_queue_free(mbox->txq);
- fail_alloc_txq:
+fail_alloc_txq:
 	free_irq(mbox->irq, mbox);
- fail_request_irq:
+fail_request_irq:
 	if (mbox->ops->shutdown)
 		mbox->ops->shutdown(mbox);
 
@@ -396,7 +396,8 @@ static int __init omap_mbox_init(void)
 
 	/* kfifo size sanity check: alignment and minimal size */
 	mbox_kfifo_size = ALIGN(mbox_kfifo_size, sizeof(mbox_msg_t));
-	mbox_kfifo_size = max_t(unsigned int, mbox_kfifo_size, sizeof(mbox_msg_t));
+	mbox_kfifo_size = max_t(unsigned int, mbox_kfifo_size,
+							sizeof(mbox_msg_t));
 
 	return 0;
 }
Signature · 1 line
1.7.0
#3 lore raw

PATCH v5 3/4 OMAP: mailbox: send message in process context

In reply to Hari Kanigeri

Schedule the Tasklet to send only when mailbox fifo is full and there are pending messages in kfifo, else send the message directly in the Process context. This would avoid needless scheduling of Tasklet for every message transfer

---
 arch/arm/plat-omap/mailbox.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
arch/arm/plat-omap/mailbox.c +7 -2
index d9aa87c..cc58b44 100644
@@ -92,20 +92,25 @@ int omap_mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg)
 	struct omap_mbox_queue *mq = mbox->txq;
 	int ret = 0, len;
 
-	spin_lock(&mq->lock);
+	spin_lock_bh(&mq->lock);
 
 	if (kfifo_avail(&mq->fifo) < sizeof(msg)) {
 		ret = -ENOMEM;
 		goto out;
 	}
 
+	if (kfifo_is_empty(&mq->fifo) && !__mbox_poll_for_space(mbox)) {
+		mbox_fifo_write(mbox, msg);
+		goto out;
+	}
+
 	len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
 	WARN_ON(len != sizeof(msg));
 
 	tasklet_schedule(&mbox->txq->tasklet);
 
 out:
-	spin_unlock(&mq->lock);
+	spin_unlock_bh(&mq->lock);
 	return ret;
 }
 EXPORT_SYMBOL(omap_mbox_msg_send);
Signature · 1 line
1.7.0
#4 lore raw

PATCH v5 4/4 OMAP: mailbox: add notification support for multiple readers

In reply to Hari Kanigeri

In the current mailbox driver, the mailbox internal pointer for callback can be directly manipulated by the Users, so a second User can easily corrupt the first user's callback pointer. The initial effort to correct this issue can be referred here:
https://patchwork.kernel.org/patch/107520/

Along with fixing the above stated issue, this patch adds the flexibility option to register notifications from multiple readers to the events received on a mailbox instance. The discussion regarding this can be referred here.
http://www.mail-archive.com/[email protected]/msg30671.html

---
 arch/arm/plat-omap/include/plat/mailbox.h |    7 +-
 arch/arm/plat-omap/mailbox.c              |  103 ++++++++++++++++-------------
 2 files changed, 61 insertions(+), 49 deletions(-)
arch/arm/plat-omap/include/plat/mailbox.h +4 -3
index 13f2ef3..cc3921e 100644
@@ -46,7 +46,6 @@ struct omap_mbox_queue {
 	struct kfifo		fifo;
 	struct work_struct	work;
 	struct tasklet_struct	tasklet;
-	int	(*callback)(void *);
 	struct omap_mbox	*mbox;
 	bool full;
 };
@@ -58,13 +57,15 @@ struct omap_mbox {
 	struct omap_mbox_ops	*ops;
 	struct device		*dev;
 	void			*priv;
+	int			use_count;
+	struct blocking_notifier_head   notifier;
 };
 
 int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg);
 void omap_mbox_init_seq(struct omap_mbox *);
 
-struct omap_mbox *omap_mbox_get(const char *);
-void omap_mbox_put(struct omap_mbox *);
+struct omap_mbox *omap_mbox_get(const char *, struct notifier_block *nb);
+void omap_mbox_put(struct omap_mbox *mbox, struct notifier_block *nb);
 
 int omap_mbox_register(struct device *parent, struct omap_mbox **);
 int omap_mbox_unregister(void);
arch/arm/plat-omap/mailbox.c +57 -46

159 lines not on this page · raw message

Signature · 1 line
1.7.0