From patchwork Wed Mar 13 03:24:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suman Anna X-Patchwork-Id: 2261151 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 9A0ED3FD8C for ; Wed, 13 Mar 2013 03:34:59 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UFcPa-0005Fm-Kx; Wed, 13 Mar 2013 03:31:30 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UFcNR-0004NM-03 for linux-arm-kernel@lists.infradead.org; Wed, 13 Mar 2013 03:29:26 +0000 Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id r2D3TAxh030882; Tue, 12 Mar 2013 22:29:10 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id r2D3TAJv006977; Tue, 12 Mar 2013 22:29:10 -0500 Received: from dlelxv22.itg.ti.com (172.17.1.197) by dfle73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.1.323.3; Tue, 12 Mar 2013 22:29:10 -0500 Received: from localhost (irmo.am.dhcp.ti.com [128.247.74.241]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id r2D3TAMZ011084; Tue, 12 Mar 2013 22:29:10 -0500 From: Suman Anna To: Greg Kroah-Hartman Subject: [PATCHv3 08/14] mailbox: add shared memory mailbox type Date: Tue, 12 Mar 2013 22:24:22 -0500 Message-ID: <1363145062-14612-1-git-send-email-s-anna@ti.com> X-Mailer: git-send-email 1.8.1.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130312_232917_367624_6D4476FE X-CRM114-Status: GOOD ( 15.67 ) X-Spam-Score: -9.5 (---------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-9.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [198.47.26.153 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -2.6 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Ohad Ben-Cohen , Suman Anna , Russell King , Loic Pallardy , Arnd Bergmann , Tony Lindgren , Linus Walleij , linux-kernel@vger.kernel.org, Omar Ramirez Luna , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Loic Pallardy Some mailboxes are made up of cross interrupts and associated shared memory. Shared memory mapping is fixed and cross interrupt/shared memory relation make impossible the use of virtio. Mailbox framework must be enough opened to support any kind of mailbox. Signed-off-by: Loic Pallardy Signed-off-by: Linus Walleij --- drivers/mailbox/mailbox-omap1.c | 34 +++++++++++++++++++++++++++++----- drivers/mailbox/mailbox-omap2.c | 16 ++++++++++++---- drivers/mailbox/mailbox.c | 38 +++++++++++--------------------------- drivers/mailbox/mailbox_internal.h | 18 +++++++++--------- 4 files changed, 61 insertions(+), 45 deletions(-) diff --git a/drivers/mailbox/mailbox-omap1.c b/drivers/mailbox/mailbox-omap1.c index 9268f98..7b30157 100644 --- a/drivers/mailbox/mailbox-omap1.c +++ b/drivers/mailbox/mailbox-omap1.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "mailbox_internal.h" @@ -38,6 +39,7 @@ struct omap_mbox1_priv { struct omap_mbox1_fifo tx_fifo; struct omap_mbox1_fifo rx_fifo; u32 data; + bool empty_flag; }; static inline int mbox_read_reg(size_t ofs) @@ -59,6 +61,7 @@ static void omap1_mbox_fifo_read(struct mailbox *mbox, struct mailbox_msg *msg) priv->data = mbox_read_reg(fifo->data); priv->data |= ((u32) mbox_read_reg(fifo->cmd)) << 16; MAILBOX_FILL_MSG((*msg), 0, priv->data, 0); + priv->empty_flag = false; } static int @@ -76,7 +79,11 @@ omap1_mbox_fifo_write(struct mailbox *mbox, struct mailbox_msg *msg) static int omap1_mbox_fifo_empty(struct mailbox *mbox) { - return 0; + struct omap_mbox1_priv *priv = (struct omap_mbox1_priv *)mbox->priv; + if (priv->empty_flag) + return 0; + else + return 1; } static int omap1_mbox_fifo_full(struct mailbox *mbox) @@ -87,6 +94,18 @@ static int omap1_mbox_fifo_full(struct mailbox *mbox) return mbox_read_reg(fifo->flag); } +static int omap1_mbox_poll_for_space(struct mailbox *mbox) +{ + int ret = 0, i = 1000; + + while (omap1_mbox_fifo_full(mbox)) { + if (--i == 0) + return -1; + udelay(1); + } + return ret; +} + /* irq */ static void omap1_mbox_enable_irq(struct mailbox *mbox, mailbox_type_t irq) @@ -105,17 +124,22 @@ omap1_mbox_disable_irq(struct mailbox *mbox, mailbox_type_t irq) static int omap1_mbox_is_irq(struct mailbox *mbox, mailbox_type_t irq) { + struct omap_mbox1_priv *priv = (struct omap_mbox1_priv *)mbox->priv; + if (irq == IRQ_TX) return 0; + if (irq == IRQ_RX) + priv->empty_flag = true; + return 1; } static struct mailbox_ops omap1_mbox_ops = { .type = MBOX_HW_FIFO1_TYPE, - .fifo_read = omap1_mbox_fifo_read, - .fifo_write = omap1_mbox_fifo_write, - .fifo_empty = omap1_mbox_fifo_empty, - .fifo_full = omap1_mbox_fifo_full, + .read = omap1_mbox_fifo_read, + .write = omap1_mbox_fifo_write, + .empty = omap1_mbox_fifo_empty, + .poll_for_space = omap1_mbox_poll_for_space, .enable_irq = omap1_mbox_enable_irq, .disable_irq = omap1_mbox_disable_irq, .is_irq = omap1_mbox_is_irq, diff --git a/drivers/mailbox/mailbox-omap2.c b/drivers/mailbox/mailbox-omap2.c index 43704fd..72f8368 100644 --- a/drivers/mailbox/mailbox-omap2.c +++ b/drivers/mailbox/mailbox-omap2.c @@ -129,6 +129,14 @@ static int omap2_mbox_fifo_full(struct mailbox *mbox) return mbox_read_reg(fifo->fifo_stat); } +static int omap2_mbox_poll_for_space(struct mailbox *mbox) +{ + if (omap2_mbox_fifo_full(mbox)) + return -1; + + return 0; +} + /* Mailbox IRQ handle functions */ static void omap2_mbox_enable_irq(struct mailbox *mbox, mailbox_type_t irq) @@ -216,10 +224,10 @@ static struct mailbox_ops omap2_mbox_ops = { .type = MBOX_HW_FIFO2_TYPE, .startup = omap2_mbox_startup, .shutdown = omap2_mbox_shutdown, - .fifo_read = omap2_mbox_fifo_read, - .fifo_write = omap2_mbox_fifo_write, - .fifo_empty = omap2_mbox_fifo_empty, - .fifo_full = omap2_mbox_fifo_full, + .read = omap2_mbox_fifo_read, + .write = omap2_mbox_fifo_write, + .empty = omap2_mbox_fifo_empty, + .poll_for_space = omap2_mbox_poll_for_space, .enable_irq = omap2_mbox_enable_irq, .disable_irq = omap2_mbox_disable_irq, .ack_irq = omap2_mbox_ack_irq, diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index ff6595a..08da5b0 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -44,21 +44,17 @@ module_param(mbox_kfifo_size, uint, S_IRUGO); MODULE_PARM_DESC(mbox_kfifo_size, "Size of mailbox kfifo (bytes)"); /* Mailbox FIFO handle functions */ -static inline void mbox_fifo_read(struct mailbox *mbox, struct mailbox_msg *msg) +static inline void mbox_read(struct mailbox *mbox, struct mailbox_msg *msg) { - mbox->ops->fifo_read(mbox, msg); + mbox->ops->read(mbox, msg); } -static inline int mbox_fifo_write(struct mailbox *mbox, struct mailbox_msg *msg) +static inline int mbox_write(struct mailbox *mbox, struct mailbox_msg *msg) { - return mbox->ops->fifo_write(mbox, msg); + return mbox->ops->write(mbox, msg); } -static inline int mbox_fifo_empty(struct mailbox *mbox) +static inline int mbox_empty(struct mailbox *mbox) { - return mbox->ops->fifo_empty(mbox); -} -static inline int mbox_fifo_full(struct mailbox *mbox) -{ - return mbox->ops->fifo_full(mbox); + return mbox->ops->empty(mbox); } /* Mailbox IRQ handle functions */ @@ -77,16 +73,7 @@ static inline int is_mbox_irq(struct mailbox *mbox, mailbox_irq_t irq) */ static int __mbox_poll_for_space(struct mailbox *mbox) { - int ret = 0, i = 1000; - - while (mbox_fifo_full(mbox)) { - if (mbox->ops->type == MBOX_HW_FIFO2_TYPE) - return -1; - if (--i == 0) - return -1; - udelay(1); - } - return ret; + return mbox->ops->poll_for_space(mbox); } int mailbox_msg_send(struct mailbox *mbox, struct mailbox_msg *msg) @@ -102,7 +89,7 @@ int mailbox_msg_send(struct mailbox *mbox, struct mailbox_msg *msg) } if (kfifo_is_empty(&mq->fifo) && !__mbox_poll_for_space(mbox)) { - ret = mbox_fifo_write(mbox, msg); + ret = mbox_write(mbox, msg); goto out; } @@ -181,7 +168,7 @@ static void mbox_tx_tasklet(unsigned long tx_data) msg.pdata = tx_data_buf; } - ret = mbox_fifo_write(mbox, &msg); + ret = mbox_write(mbox, &msg); WARN_ON(ret); } } @@ -236,7 +223,7 @@ static void __mbox_rx_interrupt(struct mailbox *mbox) struct mailbox_msg msg; int len; - while (!mbox_fifo_empty(mbox)) { + while (!mbox_empty(mbox)) { if (unlikely(kfifo_avail(&mq->fifo) < (sizeof(msg) + CONFIG_MBOX_DATA_SIZE))) { mailbox_disable_irq(mbox, IRQ_RX); @@ -244,7 +231,7 @@ static void __mbox_rx_interrupt(struct mailbox *mbox) goto nomem; } - mbox_fifo_read(mbox, &msg); + mbox_read(mbox, &msg); len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg)); WARN_ON(len != sizeof(msg)); @@ -254,9 +241,6 @@ static void __mbox_rx_interrupt(struct mailbox *mbox) msg.size); WARN_ON(len != msg.size); } - - if (mbox->ops->type == MBOX_HW_FIFO1_TYPE) - break; } /* no more messages in the fifo. clear IRQ source. */ diff --git a/drivers/mailbox/mailbox_internal.h b/drivers/mailbox/mailbox_internal.h index 7ac8bb8..8aded95 100644 --- a/drivers/mailbox/mailbox_internal.h +++ b/drivers/mailbox/mailbox_internal.h @@ -17,20 +17,19 @@ #include typedef int __bitwise mailbox_type_t; -#define MBOX_HW_FIFO1_TYPE ((__force mailbox_type_t) 1) -#define MBOX_HW_FIFO2_TYPE ((__force mailbox_type_t) 2) +#define MBOX_HW_FIFO1_TYPE ((__force mailbox_type_t) 1) +#define MBOX_HW_FIFO2_TYPE ((__force mailbox_type_t) 2) +#define MBOX_SHARED_MEM_TYPE ((__force mailbox_type_t) 3) struct mailbox_ops { mailbox_type_t type; int (*startup)(struct mailbox *mbox); void (*shutdown)(struct mailbox *mbox); - /* fifo */ - void (*fifo_read)(struct mailbox *mbox, - struct mailbox_msg *msg); - int (*fifo_write)(struct mailbox *mbox, - struct mailbox_msg *msg); - int (*fifo_empty)(struct mailbox *mbox); - int (*fifo_full)(struct mailbox *mbox); + /* mailbox access */ + void (*read)(struct mailbox *mbox, struct mailbox_msg *msg); + int (*write)(struct mailbox *mbox, struct mailbox_msg *msg); + int (*empty)(struct mailbox *mbox); + int (*poll_for_space)(struct mailbox *mbox); /* irq */ void (*enable_irq)(struct mailbox *mbox, mailbox_irq_t irq); void (*disable_irq)(struct mailbox *mbox, mailbox_irq_t irq); @@ -53,6 +52,7 @@ struct mailbox_queue { struct mailbox { const char *name; + unsigned int id; unsigned int irq; struct mailbox_queue *txq, *rxq; struct mailbox_ops *ops;