From patchwork Wed Jul 21 09:45:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Carmody X-Patchwork-Id: 113323 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6L9jjHg019913 for ; Wed, 21 Jul 2010 09:45:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750765Ab0GUJpo (ORCPT ); Wed, 21 Jul 2010 05:45:44 -0400 Received: from smtp.nokia.com ([192.100.122.233]:26659 "EHLO mgw-mx06.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750712Ab0GUJpo convert rfc822-to-8bit (ORCPT ); Wed, 21 Jul 2010 05:45:44 -0400 Received: from esebh105.NOE.Nokia.com (esebh105.ntc.nokia.com [172.21.138.211]) by mgw-mx06.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id o6L9jbgx006131; Wed, 21 Jul 2010 12:45:38 +0300 Received: from vaebh102.NOE.Nokia.com ([10.160.244.23]) by esebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 21 Jul 2010 12:45:37 +0300 Received: from smtp.mgd.nokia.com ([65.54.30.7]) by vaebh102.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Wed, 21 Jul 2010 12:45:32 +0300 Received: from NOK-EUMSG-01.mgdnok.nokia.com ([65.54.30.86]) by nok-am1mhub-03.mgdnok.nokia.com ([65.54.30.7]) with mapi; Wed, 21 Jul 2010 11:45:31 +0200 From: To: , , , CC: Date: Wed, 21 Jul 2010 11:45:30 +0200 Subject: RE: [PATCH 2/2] omap:mailbox-provide multiple reader support Thread-Topic: [PATCH 2/2] omap:mailbox-provide multiple reader support Thread-Index: AcsoUy+WuFRkTH1JR1CTKCj3At5I1gAZSLiE Message-ID: <702744BC498BAE41B3AA631D95EC463058B3CFD799@NOK-EUMSG-01.mgdnok.nokia.com> References: <1279662096-3121-1-git-send-email-h-kanigeri2@ti.com>, <1279662096-3121-3-git-send-email-h-kanigeri2@ti.com> In-Reply-To: <1279662096-3121-3-git-send-email-h-kanigeri2@ti.com> Accept-Language: en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 X-OriginalArrivalTime: 21 Jul 2010 09:45:32.0240 (UTC) FILETIME=[75E82500:01CB28B9] X-Nokia-AV: Clean Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 21 Jul 2010 09:45:46 +0000 (UTC) diff --git a/arch/arm/plat-omap/include/plat/mailbox.h b/arch/arm/plat-omap/include/plat/mailbox.h index 0486d64..c8e47d8 100644 --- a/arch/arm/plat-omap/include/plat/mailbox.h +++ b/arch/arm/plat-omap/include/plat/mailbox.h @@ -68,13 +68,15 @@ struct omap_mbox { void *priv; void (*err_notify)(void); + atomic_t 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 *, struct notifier_block *nb); int omap_mbox_register(struct device *parent, struct omap_mbox *); int omap_mbox_unregister(struct omap_mbox *); diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c index baac315..f9f2af4 100644 --- a/arch/arm/plat-omap/mailbox.c +++ b/arch/arm/plat-omap/mailbox.c @@ -149,8 +149,8 @@ static void mbox_rx_work(struct work_struct *work) if (unlikely(len != sizeof(msg))) pr_err("%s: kfifo_out anomaly detected\n", __func__); - if (mq->callback) - mq->callback((void *)msg); + blocking_notifier_call_chain(&mq->mbox->notifier, len, + (void *)msg); } } @@ -252,28 +252,30 @@ static int omap_mbox_startup(struct omap_mbox *mbox) } } - ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED, - mbox->name, mbox); - if (unlikely(ret)) { - printk(KERN_ERR - "failed to register mailbox interrupt:%d\n", ret); - goto fail_request_irq; - } + if (atomic_inc_return(&mbox->use_count) == 1) { + ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED, + mbox->name, mbox); + if (unlikely(ret)) { + printk(KERN_ERR "failed to register mailbox interrupt:" + "%d\n", ret); + goto fail_request_irq; + } - 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, NULL, mbox_tx_tasklet); + if (!mq) { + ret = -ENOMEM; + goto fail_alloc_txq; + } + mbox->txq = mq; - mq = mbox_queue_alloc(mbox, mbox_rx_work, NULL); - if (!mq) { - ret = -ENOMEM; - goto fail_alloc_rxq; + mq = mbox_queue_alloc(mbox, mbox_rx_work, NULL); + if (!mq) { + ret = -ENOMEM; + goto fail_alloc_rxq; + } + mbox->rxq = mq; + mq->mbox = mbox; } - mbox->rxq = mq; - return 0; fail_alloc_rxq: @@ -281,6 +283,7 @@ static int omap_mbox_startup(struct omap_mbox *mbox) fail_alloc_txq: free_irq(mbox->irq, mbox); fail_request_irq: + atomic_dec(&mbox->use_count); if (likely(mbox->ops->shutdown)) { if (atomic_dec_return(&mbox_refcount) == 0) mbox->ops->shutdown(mbox); @@ -291,10 +294,12 @@ static int omap_mbox_startup(struct omap_mbox *mbox) static void omap_mbox_fini(struct omap_mbox *mbox) { - mbox_queue_free(mbox->txq); - mbox_queue_free(mbox->rxq); - free_irq(mbox->irq, mbox); + if (atomic_dec_return(&mbox->use_count) == 0) { + mbox_queue_free(mbox->txq); + mbox_queue_free(mbox->rxq); + free_irq(mbox->irq, mbox); + } if (likely(mbox->ops->shutdown)) { if (atomic_dec_return(&mbox_refcount) == 0) @@ -314,7 +319,7 @@ static struct omap_mbox **find_mboxes(const char *name) return p; } -struct omap_mbox *omap_mbox_get(const char *name) +struct omap_mbox *omap_mbox_get(const char *name, struct notifier_block *nb) { struct omap_mbox *mbox; int ret; @@ -325,19 +330,21 @@ struct omap_mbox *omap_mbox_get(const char *name) spin_unlock(&mboxes_lock); return ERR_PTR(-ENOENT); } - spin_unlock(&mboxes_lock); ret = omap_mbox_startup(mbox); if (ret) return ERR_PTR(-ENODEV); + if (nb) + blocking_notifier_chain_register(&mbox->notifier, nb); return mbox; } EXPORT_SYMBOL(omap_mbox_get); -void omap_mbox_put(struct omap_mbox *mbox) +void omap_mbox_put(struct omap_mbox *mbox, struct notifier_block *nb) { + blocking_notifier_chain_unregister(&mbox->notifier, nb); omap_mbox_fini(mbox); } EXPORT_SYMBOL(omap_mbox_put); @@ -361,6 +368,8 @@ int omap_mbox_register(struct device *parent, struct omap_mbox *mbox) } *tmp = mbox; spin_unlock(&mboxes_lock); + BLOCKING_INIT_NOTIFIER_HEAD(&mbox->notifier); + atomic_set(&mbox->use_count, 0); return 0;