From ad6d962735eb48dde1851269bdeaa042fdb39172 Mon Sep 17 00:00:00 2001 From: Fernando Guzman Lugo Date: Fri, 12 Feb 2010 19:02:32 -0600 Subject: Mailbox: free mailbox interrupt before freeing blk queue Free interrupt before freeing blk_queue to avoid any attempt of access to blk_queue after it was freed. Signed-off-by: Fernando Guzman Lugo Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/mailbox.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index 08a2df766289..252a58698ef7 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -298,11 +298,10 @@ static int omap_mbox_startup(struct omap_mbox *mbox) static void omap_mbox_fini(struct omap_mbox *mbox) { + free_irq(mbox->irq, mbox); mbox_queue_free(mbox->txq); mbox_queue_free(mbox->rxq); - free_irq(mbox->irq, mbox); - if (unlikely(mbox->ops->shutdown)) { write_lock(&mboxes_lock); if (mbox_configured > 0) -- cgit v1.2.1 From 0e828e8c2bab6d30649447eea68686413c92d340 Mon Sep 17 00:00:00 2001 From: Fernando Guzman Lugo Date: Fri, 12 Feb 2010 19:07:14 -0600 Subject: Mailbox: flush pending deferred works before freeing blk queue flush pending deferred works before freeing blk_queue to prevent any attempt of access to blk_queue after it was freed Signed-off-by: Fernando Guzman Lugo Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/mailbox.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index 252a58698ef7..77c23f5a0037 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -299,6 +299,8 @@ static int omap_mbox_startup(struct omap_mbox *mbox) static void omap_mbox_fini(struct omap_mbox *mbox) { free_irq(mbox->irq, mbox); + tasklet_kill(&mbox->txq->tasklet); + flush_work(&mbox->rxq->work); mbox_queue_free(mbox->txq); mbox_queue_free(mbox->rxq); -- cgit v1.2.1 From 9caae4d87ca0087edd6c02efd674f13fe0419ee9 Mon Sep 17 00:00:00 2001 From: Fernando Guzman Lugo Date: Wed, 27 Jan 2010 20:04:02 -0600 Subject: Mailbox: Check valid registered callback before calling This patch checks if the mailbox user has assinged a valid callback fuction before calling it. Signed-off-by: Fernando Guzman Lugo Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/mailbox.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index 77c23f5a0037..72efbe5be578 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -146,7 +146,8 @@ static void mbox_rx_work(struct work_struct *work) msg = (mbox_msg_t)rq->special; blk_end_request_all(rq, 0); - mbox->rxq->callback((void *)msg); + if (mbox->rxq->callback) + mbox->rxq->callback((void *)msg); } } -- cgit v1.2.1 From 72b917ef90084885ffcc5adb69095af02d2b6996 Mon Sep 17 00:00:00 2001 From: Hiroshi DOYU Date: Thu, 18 Feb 2010 00:48:55 -0600 Subject: Mailbox: new mutext lock for h/w mailbox configuration mailbox startup and shutdown are being executed against a single H/W module, and a mailbox H/W module is totally __independent__ of the registration of logical mailboxes. So, an independent mutext should be used for startup and shutdown. Signed-off-by: Fernando Guzman Lugo Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/mailbox.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index 72efbe5be578..986002b089fd 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -34,6 +34,7 @@ static struct omap_mbox *mboxes; static DEFINE_RWLOCK(mboxes_lock); static int mbox_configured; +static DEFINE_MUTEX(mbox_configured_lock); /* Mailbox FIFO handle functions */ static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox) @@ -250,16 +251,16 @@ static int omap_mbox_startup(struct omap_mbox *mbox) struct omap_mbox_queue *mq; if (likely(mbox->ops->startup)) { - write_lock(&mboxes_lock); + mutex_lock(&mbox_configured_lock); if (!mbox_configured) ret = mbox->ops->startup(mbox); if (unlikely(ret)) { - write_unlock(&mboxes_lock); + mutex_unlock(&mbox_configured_lock); return ret; } mbox_configured++; - write_unlock(&mboxes_lock); + mutex_unlock(&mbox_configured_lock); } ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED, @@ -306,12 +307,12 @@ static void omap_mbox_fini(struct omap_mbox *mbox) mbox_queue_free(mbox->rxq); if (unlikely(mbox->ops->shutdown)) { - write_lock(&mboxes_lock); + mutex_lock(&mbox_configured_lock); if (mbox_configured > 0) mbox_configured--; if (!mbox_configured) mbox->ops->shutdown(mbox); - write_unlock(&mboxes_lock); + mutex_unlock(&mbox_configured_lock); } } -- cgit v1.2.1 From 1ea5d6d18bf1d528ae1081b9176d69c00bd51fa2 Mon Sep 17 00:00:00 2001 From: Fernando Guzman Lugo Date: Mon, 8 Feb 2010 13:35:40 -0600 Subject: Mailbox: disable mailbox interrupt when request queue when blk_get_request fails to get the request it is returning without read the message from the mailbox fifo, then when it leaves the isr and interruption is trigger again and again and the workqueue which get elements from the request queue is never executed and the kernel is stuck and shows a softlockup message. Now the mailbox interrupt is disabled when request queue is full and enabled when it pop a elememt form the request queue. Signed-off-by: Fernando Guzman Lugo Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/mailbox.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index 986002b089fd..c3402165488d 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -32,6 +32,7 @@ static struct workqueue_struct *mboxd; static struct omap_mbox *mboxes; static DEFINE_RWLOCK(mboxes_lock); +static bool rq_full; static int mbox_configured; static DEFINE_MUTEX(mbox_configured_lock); @@ -141,6 +142,10 @@ static void mbox_rx_work(struct work_struct *work) while (1) { spin_lock_irqsave(q->queue_lock, flags); rq = blk_fetch_request(q); + if (rq_full) { + omap_mbox_enable_irq(mbox, IRQ_RX); + rq_full = false; + } spin_unlock_irqrestore(q->queue_lock, flags); if (!rq) break; @@ -178,8 +183,11 @@ static void __mbox_rx_interrupt(struct omap_mbox *mbox) while (!mbox_fifo_empty(mbox)) { rq = blk_get_request(q, WRITE, GFP_ATOMIC); - if (unlikely(!rq)) + if (unlikely(!rq)) { + omap_mbox_disable_irq(mbox, IRQ_RX); + rq_full = true; goto nomem; + } msg = mbox_fifo_read(mbox); -- cgit v1.2.1 From 10d1a0028dc4549bd8e887641cc283f5f184f819 Mon Sep 17 00:00:00 2001 From: Ohad Ben-Cohen Date: Wed, 5 May 2010 15:33:06 +0000 Subject: omap: mailbox: convert rwlocks to spinlock rwlocks are slower and have potential starvation issues therefore spinlocks are generally preferred. see also: http://lwn.net/Articles/364583/ Signed-off-by: Ohad Ben-Cohen Signed-off-by: Kanigeri Hari Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/mailbox.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index c3402165488d..fafe47bf2f55 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -31,7 +31,7 @@ static struct workqueue_struct *mboxd; static struct omap_mbox *mboxes; -static DEFINE_RWLOCK(mboxes_lock); +static DEFINE_SPINLOCK(mboxes_lock); static bool rq_full; static int mbox_configured; @@ -341,14 +341,14 @@ struct omap_mbox *omap_mbox_get(const char *name) struct omap_mbox *mbox; int ret; - read_lock(&mboxes_lock); + spin_lock(&mboxes_lock); mbox = *(find_mboxes(name)); if (mbox == NULL) { - read_unlock(&mboxes_lock); + spin_unlock(&mboxes_lock); return ERR_PTR(-ENOENT); } - read_unlock(&mboxes_lock); + spin_unlock(&mboxes_lock); ret = omap_mbox_startup(mbox); if (ret) @@ -374,15 +374,15 @@ int omap_mbox_register(struct device *parent, struct omap_mbox *mbox) if (mbox->next) return -EBUSY; - write_lock(&mboxes_lock); + spin_lock(&mboxes_lock); tmp = find_mboxes(mbox->name); if (*tmp) { ret = -EBUSY; - write_unlock(&mboxes_lock); + spin_unlock(&mboxes_lock); goto err_find; } *tmp = mbox; - write_unlock(&mboxes_lock); + spin_unlock(&mboxes_lock); return 0; @@ -395,18 +395,18 @@ int omap_mbox_unregister(struct omap_mbox *mbox) { struct omap_mbox **tmp; - write_lock(&mboxes_lock); + spin_lock(&mboxes_lock); tmp = &mboxes; while (*tmp) { if (mbox == *tmp) { *tmp = mbox->next; mbox->next = NULL; - write_unlock(&mboxes_lock); + spin_unlock(&mboxes_lock); return 0; } tmp = &(*tmp)->next; } - write_unlock(&mboxes_lock); + spin_unlock(&mboxes_lock); return -EINVAL; } -- cgit v1.2.1 From f375325a040d03e2c620394ebc8bcaf0bdba01da Mon Sep 17 00:00:00 2001 From: Ohad Ben-Cohen Date: Wed, 5 May 2010 15:33:07 +0000 Subject: omap: mailbox cleanup: split MODULE_AUTHOR line use multiple MODULE_AUTHOR lines for multiple authors Signed-off-by: Ohad Ben-Cohen Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/mailbox.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index fafe47bf2f55..66c6e87fa3ec 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -430,4 +430,5 @@ module_exit(omap_mbox_exit); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("omap mailbox: interrupt driven messaging"); -MODULE_AUTHOR("Toshihiro Kobayashi and Hiroshi DOYU"); +MODULE_AUTHOR("Toshihiro Kobayashi"); +MODULE_AUTHOR("Hiroshi DOYU"); -- cgit v1.2.1 From 01072d8f4b9911047ef435a807cfd7223c94d94d Mon Sep 17 00:00:00 2001 From: Ohad Ben-Cohen Date: Wed, 5 May 2010 15:33:08 +0000 Subject: omap: mailbox: remove (un)likely macros from cold paths Signed-off-by: Ohad Ben-Cohen Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/mailbox.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index 66c6e87fa3ec..81076b54d37b 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -258,12 +258,12 @@ static int omap_mbox_startup(struct omap_mbox *mbox) int ret = 0; struct omap_mbox_queue *mq; - if (likely(mbox->ops->startup)) { + if (mbox->ops->startup) { mutex_lock(&mbox_configured_lock); if (!mbox_configured) ret = mbox->ops->startup(mbox); - if (unlikely(ret)) { + if (ret) { mutex_unlock(&mbox_configured_lock); return ret; } @@ -273,7 +273,7 @@ static int omap_mbox_startup(struct omap_mbox *mbox) ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED, mbox->name, mbox); - if (unlikely(ret)) { + if (ret) { printk(KERN_ERR "failed to register mailbox interrupt:%d\n", ret); goto fail_request_irq; @@ -300,7 +300,7 @@ static int omap_mbox_startup(struct omap_mbox *mbox) fail_alloc_txq: free_irq(mbox->irq, mbox); fail_request_irq: - if (unlikely(mbox->ops->shutdown)) + if (mbox->ops->shutdown) mbox->ops->shutdown(mbox); return ret; @@ -314,7 +314,7 @@ static void omap_mbox_fini(struct omap_mbox *mbox) mbox_queue_free(mbox->txq); mbox_queue_free(mbox->rxq); - if (unlikely(mbox->ops->shutdown)) { + if (mbox->ops->shutdown) { mutex_lock(&mbox_configured_lock); if (mbox_configured > 0) mbox_configured--; -- cgit v1.2.1 From b5bebe410204cf84337b54c372cceda2d6b27de6 Mon Sep 17 00:00:00 2001 From: Ohad Ben-Cohen Date: Wed, 5 May 2010 15:33:09 +0000 Subject: omap: mailbox: convert block api to kfifo The underlying buffering implementation of mailbox is converted from block API to kfifo due to the simplicity and speed of kfifo. The default size of the kfifo buffer is set to 256 bytes. This value is configurable at compile time (via CONFIG_OMAP_MBOX_KFIFO_SIZE), and can be changed at runtime (via the mbox_kfifo_size module parameter). Signed-off-by: Ohad Ben-Cohen Signed-off-by: Hari Kanigeri Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/Kconfig | 9 +++ arch/arm/plat-omap/include/plat/mailbox.h | 4 +- arch/arm/plat-omap/mailbox.c | 119 +++++++++++++----------------- 3 files changed, 64 insertions(+), 68 deletions(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/Kconfig b/arch/arm/plat-omap/Kconfig index 78b49a626d06..111d39a47ad1 100644 --- a/arch/arm/plat-omap/Kconfig +++ b/arch/arm/plat-omap/Kconfig @@ -106,6 +106,15 @@ config OMAP_MBOX_FWK Say Y here if you want to use OMAP Mailbox framework support for DSP, IVA1.0 and IVA2 in OMAP1/2/3. +config OMAP_MBOX_KFIFO_SIZE + int "Mailbox kfifo default buffer size (bytes)" + depends on OMAP_MBOX_FWK + default 256 + help + Specify the default size of mailbox's kfifo buffers (bytes). + This can also be changed at runtime (via the mbox_kfifo_size + module parameter). + config OMAP_IOMMU tristate diff --git a/arch/arm/plat-omap/include/plat/mailbox.h b/arch/arm/plat-omap/include/plat/mailbox.h index 729166b76a7c..0c3c4a5f4b42 100644 --- a/arch/arm/plat-omap/include/plat/mailbox.h +++ b/arch/arm/plat-omap/include/plat/mailbox.h @@ -5,8 +5,8 @@ #include #include -#include #include +#include typedef u32 mbox_msg_t; struct omap_mbox; @@ -42,7 +42,7 @@ struct omap_mbox_ops { struct omap_mbox_queue { spinlock_t lock; - struct request_queue *queue; + struct kfifo fifo; struct work_struct work; struct tasklet_struct tasklet; int (*callback)(void *); diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index 81076b54d37b..ec0e1596b4f3 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -21,11 +21,14 @@ * */ +#include #include #include #include #include #include +#include +#include #include @@ -37,6 +40,10 @@ static bool rq_full; static int mbox_configured; static DEFINE_MUTEX(mbox_configured_lock); +static unsigned int mbox_kfifo_size = CONFIG_OMAP_MBOX_KFIFO_SIZE; +module_param(mbox_kfifo_size, uint, S_IRUGO); +MODULE_PARM_DESC(mbox_kfifo_size, "Size of omap's mailbox kfifo (bytes)"); + /* Mailbox FIFO handle functions */ static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox) { @@ -69,7 +76,7 @@ static inline int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq) /* * message sender */ -static int __mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg) +static int __mbox_poll_for_space(struct omap_mbox *mbox) { int ret = 0, i = 1000; @@ -80,49 +87,50 @@ static int __mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg) return -1; udelay(1); } - mbox_fifo_write(mbox, msg); return ret; } - int omap_mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg) { + struct omap_mbox_queue *mq = mbox->txq; + int ret = 0, len; - struct request *rq; - struct request_queue *q = mbox->txq->queue; + spin_lock(&mq->lock); - rq = blk_get_request(q, WRITE, GFP_ATOMIC); - if (unlikely(!rq)) - return -ENOMEM; + if (kfifo_avail(&mq->fifo) < sizeof(msg)) { + ret = -ENOMEM; + goto out; + } + + len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg)); + WARN_ON(len != sizeof(msg)); - blk_insert_request(q, rq, 0, (void *) msg); tasklet_schedule(&mbox->txq->tasklet); - return 0; +out: + spin_unlock(&mq->lock); + return ret; } EXPORT_SYMBOL(omap_mbox_msg_send); static void mbox_tx_tasklet(unsigned long tx_data) { - int ret; - struct request *rq; struct omap_mbox *mbox = (struct omap_mbox *)tx_data; - struct request_queue *q = mbox->txq->queue; - - while (1) { - - rq = blk_fetch_request(q); - - if (!rq) - break; + struct omap_mbox_queue *mq = mbox->txq; + mbox_msg_t msg; + int ret; - ret = __mbox_msg_send(mbox, (mbox_msg_t)rq->special); - if (ret) { + while (kfifo_len(&mq->fifo)) { + if (__mbox_poll_for_space(mbox)) { omap_mbox_enable_irq(mbox, IRQ_TX); - blk_requeue_request(q, rq); - return; + break; } - blk_end_request_all(rq, 0); + + ret = kfifo_out(&mq->fifo, (unsigned char *)&msg, + sizeof(msg)); + WARN_ON(ret != sizeof(msg)); + + mbox_fifo_write(mbox, msg); } } @@ -133,41 +141,21 @@ static void mbox_rx_work(struct work_struct *work) { struct omap_mbox_queue *mq = container_of(work, struct omap_mbox_queue, work); - struct omap_mbox *mbox = mq->queue->queuedata; - struct request_queue *q = mbox->rxq->queue; - struct request *rq; mbox_msg_t msg; - unsigned long flags; - - while (1) { - spin_lock_irqsave(q->queue_lock, flags); - rq = blk_fetch_request(q); - if (rq_full) { - omap_mbox_enable_irq(mbox, IRQ_RX); - rq_full = false; - } - spin_unlock_irqrestore(q->queue_lock, flags); - if (!rq) - break; + int len; + + while (kfifo_len(&mq->fifo) >= sizeof(msg)) { + len = kfifo_out(&mq->fifo, (unsigned char *)&msg, sizeof(msg)); + WARN_ON(len != sizeof(msg)); - msg = (mbox_msg_t)rq->special; - blk_end_request_all(rq, 0); - if (mbox->rxq->callback) - mbox->rxq->callback((void *)msg); + if (mq->callback) + mq->callback((void *)msg); } } /* * Mailbox interrupt handler */ -static void mbox_txq_fn(struct request_queue *q) -{ -} - -static void mbox_rxq_fn(struct request_queue *q) -{ -} - static void __mbox_tx_interrupt(struct omap_mbox *mbox) { omap_mbox_disable_irq(mbox, IRQ_TX); @@ -177,13 +165,12 @@ static void __mbox_tx_interrupt(struct omap_mbox *mbox) static void __mbox_rx_interrupt(struct omap_mbox *mbox) { - struct request *rq; + struct omap_mbox_queue *mq = mbox->rxq; mbox_msg_t msg; - struct request_queue *q = mbox->rxq->queue; + int len; while (!mbox_fifo_empty(mbox)) { - rq = blk_get_request(q, WRITE, GFP_ATOMIC); - if (unlikely(!rq)) { + if (unlikely(kfifo_avail(&mq->fifo) < sizeof(msg))) { omap_mbox_disable_irq(mbox, IRQ_RX); rq_full = true; goto nomem; @@ -191,8 +178,9 @@ static void __mbox_rx_interrupt(struct omap_mbox *mbox) msg = mbox_fifo_read(mbox); + len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg)); + WARN_ON(len != sizeof(msg)); - blk_insert_request(q, rq, 0, (void *)msg); if (mbox->ops->type == OMAP_MBOX_TYPE1) break; } @@ -217,11 +205,9 @@ static irqreturn_t mbox_interrupt(int irq, void *p) } static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox, - request_fn_proc *proc, void (*work) (struct work_struct *), void (*tasklet)(unsigned long)) { - struct request_queue *q; struct omap_mbox_queue *mq; mq = kzalloc(sizeof(struct omap_mbox_queue), GFP_KERNEL); @@ -230,11 +216,8 @@ static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox, spin_lock_init(&mq->lock); - q = blk_init_queue(proc, &mq->lock); - if (!q) + if (kfifo_alloc(&mq->fifo, mbox_kfifo_size, GFP_KERNEL)) goto error; - q->queuedata = mbox; - mq->queue = q; if (work) INIT_WORK(&mq->work, work); @@ -249,7 +232,7 @@ error: static void mbox_queue_free(struct omap_mbox_queue *q) { - blk_cleanup_queue(q->queue); + kfifo_free(&q->fifo); kfree(q); } @@ -279,14 +262,14 @@ static int omap_mbox_startup(struct omap_mbox *mbox) goto fail_request_irq; } - mq = mbox_queue_alloc(mbox, mbox_txq_fn, NULL, mbox_tx_tasklet); + mq = mbox_queue_alloc(mbox, NULL, mbox_tx_tasklet); if (!mq) { ret = -ENOMEM; goto fail_alloc_txq; } mbox->txq = mq; - mq = mbox_queue_alloc(mbox, mbox_rxq_fn, mbox_rx_work, NULL); + mq = mbox_queue_alloc(mbox, mbox_rx_work, NULL); if (!mq) { ret = -ENOMEM; goto fail_alloc_rxq; @@ -418,6 +401,10 @@ static int __init omap_mbox_init(void) if (!mboxd) return -ENOMEM; + /* 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)); + return 0; } module_init(omap_mbox_init); -- cgit v1.2.1 From 6b23398591a51943dbf08f30cfc2475a895cb1b4 Mon Sep 17 00:00:00 2001 From: Hiroshi DOYU Date: Tue, 18 May 2010 16:15:32 +0300 Subject: omap mailbox: Set a device in logical mbox instance for traceability With this patch, you'll get the following sysfs directories. This structure implies that a single platform device, "omap2-mailbox" holds multiple logical mbox instances. This could be the base to add sysfs files for each logical mboxes. Then userland application can access a mbox through sysfs entries if necessary(ex: setting kfifo size dynamically) ~# tree -d -L 2 /sys/devices/platform/omap2-mailbox/ /sys/devices/platform/omap2-mailbox/ |-- driver -> ../../../bus/platform/drivers/omap2-mailbox |-- mbox | |-- dsp <- they are each instances of logical mailbox. | |-- ducati | |-- iva2 | |-- mbox01 | |-- mbox02 | |-- mbox03 | |-- ..... | `-- tesla |-- power `-- subsystem -> ../../../bus/platform This was wrongly dropped by: commit c7c158e57bce6220644f2bcd65d82e1468aa40ec Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/mailbox.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index ec0e1596b4f3..87e0cde8d0db 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -347,6 +347,8 @@ void omap_mbox_put(struct omap_mbox *mbox) } EXPORT_SYMBOL(omap_mbox_put); +static struct class omap_mbox_class = { .name = "mbox", }; + int omap_mbox_register(struct device *parent, struct omap_mbox *mbox) { int ret = 0; @@ -357,6 +359,11 @@ int omap_mbox_register(struct device *parent, struct omap_mbox *mbox) if (mbox->next) return -EBUSY; + mbox->dev = device_create(&omap_mbox_class, + parent, 0, mbox, "%s", mbox->name); + if (IS_ERR(mbox->dev)) + return PTR_ERR(mbox->dev); + spin_lock(&mboxes_lock); tmp = find_mboxes(mbox->name); if (*tmp) { @@ -385,6 +392,7 @@ int omap_mbox_unregister(struct omap_mbox *mbox) *tmp = mbox->next; mbox->next = NULL; spin_unlock(&mboxes_lock); + device_unregister(mbox->dev); return 0; } tmp = &(*tmp)->next; @@ -397,6 +405,12 @@ EXPORT_SYMBOL(omap_mbox_unregister); static int __init omap_mbox_init(void) { + int err; + + err = class_register(&omap_mbox_class); + if (err) + return err; + mboxd = create_workqueue("mboxd"); if (!mboxd) return -ENOMEM; @@ -407,11 +421,12 @@ static int __init omap_mbox_init(void) return 0; } -module_init(omap_mbox_init); +subsys_initcall(omap_mbox_init); static void __exit omap_mbox_exit(void) { destroy_workqueue(mboxd); + class_unregister(&omap_mbox_class); } module_exit(omap_mbox_exit); -- cgit v1.2.1 From fc9960b2823d581ab8a1541fc8b9f2748ee3e5f2 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Fri, 11 Jun 2010 15:51:43 +0000 Subject: omap: mailbox: remove unecessary fields Nobody is using them. Signed-off-by: Felipe Contreras Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/include/plat/mailbox.h | 8 -------- 1 file changed, 8 deletions(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/include/plat/mailbox.h b/arch/arm/plat-omap/include/plat/mailbox.h index 0c3c4a5f4b42..aad8bf80c224 100644 --- a/arch/arm/plat-omap/include/plat/mailbox.h +++ b/arch/arm/plat-omap/include/plat/mailbox.h @@ -52,19 +52,11 @@ struct omap_mbox_queue { struct omap_mbox { char *name; unsigned int irq; - struct omap_mbox_queue *txq, *rxq; - struct omap_mbox_ops *ops; - - mbox_msg_t seq_snd, seq_rcv; - struct device *dev; - struct omap_mbox *next; void *priv; - - void (*err_notify)(void); }; int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg); -- cgit v1.2.1 From 9c80c8cd740f802eed27ed1c1334262b205bb8f5 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Fri, 11 Jun 2010 15:51:46 +0000 Subject: omap: mailbox: simplify omap_mbox_register() No need to dynamically register mailboxes one by one. Signed-off-by: Felipe Contreras Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/include/plat/mailbox.h | 5 +- arch/arm/plat-omap/mailbox.c | 95 ++++++++++++------------------- 2 files changed, 37 insertions(+), 63 deletions(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/include/plat/mailbox.h b/arch/arm/plat-omap/include/plat/mailbox.h index aad8bf80c224..c44fde30c7c1 100644 --- a/arch/arm/plat-omap/include/plat/mailbox.h +++ b/arch/arm/plat-omap/include/plat/mailbox.h @@ -55,7 +55,6 @@ struct omap_mbox { struct omap_mbox_queue *txq, *rxq; struct omap_mbox_ops *ops; struct device *dev; - struct omap_mbox *next; void *priv; }; @@ -65,8 +64,8 @@ void omap_mbox_init_seq(struct omap_mbox *); struct omap_mbox *omap_mbox_get(const char *); void omap_mbox_put(struct omap_mbox *); -int omap_mbox_register(struct device *parent, struct omap_mbox *); -int omap_mbox_unregister(struct omap_mbox *); +int omap_mbox_register(struct device *parent, struct omap_mbox **); +int omap_mbox_unregister(void); static inline void omap_mbox_save_ctx(struct omap_mbox *mbox) { diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index 87e0cde8d0db..fe0882130852 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -33,8 +33,7 @@ #include static struct workqueue_struct *mboxd; -static struct omap_mbox *mboxes; -static DEFINE_SPINLOCK(mboxes_lock); +static struct omap_mbox **mboxes; static bool rq_full; static int mbox_configured; @@ -307,31 +306,20 @@ static void omap_mbox_fini(struct omap_mbox *mbox) } } -static struct omap_mbox **find_mboxes(const char *name) -{ - struct omap_mbox **p; - - for (p = &mboxes; *p; p = &(*p)->next) { - if (strcmp((*p)->name, name) == 0) - break; - } - - return p; -} - struct omap_mbox *omap_mbox_get(const char *name) { struct omap_mbox *mbox; int ret; - spin_lock(&mboxes_lock); - mbox = *(find_mboxes(name)); - if (mbox == NULL) { - spin_unlock(&mboxes_lock); - return ERR_PTR(-ENOENT); - } + if (!mboxes) + return ERR_PTR(-EINVAL); - spin_unlock(&mboxes_lock); + for (mbox = *mboxes; mbox; mbox++) + if (!strcmp(mbox->name, name)) + break; + + if (!mbox) + return ERR_PTR(-ENOENT); ret = omap_mbox_startup(mbox); if (ret) @@ -349,57 +337,44 @@ EXPORT_SYMBOL(omap_mbox_put); static struct class omap_mbox_class = { .name = "mbox", }; -int omap_mbox_register(struct device *parent, struct omap_mbox *mbox) +int omap_mbox_register(struct device *parent, struct omap_mbox **list) { - int ret = 0; - struct omap_mbox **tmp; + int ret; + int i; - if (!mbox) + mboxes = list; + if (!mboxes) return -EINVAL; - if (mbox->next) - return -EBUSY; - - mbox->dev = device_create(&omap_mbox_class, - parent, 0, mbox, "%s", mbox->name); - if (IS_ERR(mbox->dev)) - return PTR_ERR(mbox->dev); - - spin_lock(&mboxes_lock); - tmp = find_mboxes(mbox->name); - if (*tmp) { - ret = -EBUSY; - spin_unlock(&mboxes_lock); - goto err_find; - } - *tmp = mbox; - spin_unlock(&mboxes_lock); + for (i = 0; mboxes[i]; i++) { + struct omap_mbox *mbox = mboxes[i]; + mbox->dev = device_create(&omap_mbox_class, + parent, 0, mbox, "%s", mbox->name); + if (IS_ERR(mbox->dev)) { + ret = PTR_ERR(mbox->dev); + goto err_out; + } + } return 0; -err_find: +err_out: + while (i--) + device_unregister(mboxes[i]->dev); return ret; } EXPORT_SYMBOL(omap_mbox_register); -int omap_mbox_unregister(struct omap_mbox *mbox) +int omap_mbox_unregister(void) { - struct omap_mbox **tmp; - - spin_lock(&mboxes_lock); - tmp = &mboxes; - while (*tmp) { - if (mbox == *tmp) { - *tmp = mbox->next; - mbox->next = NULL; - spin_unlock(&mboxes_lock); - device_unregister(mbox->dev); - return 0; - } - tmp = &(*tmp)->next; - } - spin_unlock(&mboxes_lock); + int i; - return -EINVAL; + if (!mboxes) + return -EINVAL; + + for (i = 0; mboxes[i]; i++) + device_unregister(mboxes[i]->dev); + mboxes = NULL; + return 0; } EXPORT_SYMBOL(omap_mbox_unregister); -- cgit v1.2.1 From b3e69146f43fa351aa3cdffe2e76ec42174da612 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Fri, 11 Jun 2010 15:51:49 +0000 Subject: omap: mailbox: reorganize headers Remove kernel.h and module.h since they are not used correctly anyway. Also, remove device.h since it comes along with platform_device.h (always will I guess). Signed-off-by: Felipe Contreras Signed-off-by: Hiroshi DOYU --- arch/arm/plat-omap/include/plat/mailbox.h | 3 ++- arch/arm/plat-omap/mailbox.c | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'arch/arm/plat-omap') diff --git a/arch/arm/plat-omap/include/plat/mailbox.h b/arch/arm/plat-omap/include/plat/mailbox.h index c44fde30c7c1..997656552109 100644 --- a/arch/arm/plat-omap/include/plat/mailbox.h +++ b/arch/arm/plat-omap/include/plat/mailbox.h @@ -3,9 +3,10 @@ #ifndef MAILBOX_H #define MAILBOX_H -#include +#include #include #include +#include #include typedef u32 mbox_msg_t; diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index fe0882130852..d2fafb892f7f 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -21,10 +21,9 @@ * */ -#include -#include #include -#include +#include +#include #include #include #include -- cgit v1.2.1