From patchwork Mon Dec 31 13:06:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Bedia X-Patchwork-Id: 1945581 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 9E608DF23A for ; Tue, 8 Jan 2013 13:23:32 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TsZ5K-0003G0-B9; Tue, 08 Jan 2013 13:19:20 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tpf60-0004K8-OC for linux-arm-kernel@lists.infradead.org; Mon, 31 Dec 2012 13:08:02 +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 qBVD7xg7006355; Mon, 31 Dec 2012 07:07:59 -0600 Received: from DQHE72.ent.ti.com (dqhe72.ent.ti.com [172.16.34.79]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id qBVD7wXS032012; Mon, 31 Dec 2012 07:07:58 -0600 Received: from dbdp32.itg.ti.com (172.24.170.251) by DQHE72.ent.ti.com (172.16.34.79) with Microsoft SMTP Server id 14.1.323.3; Mon, 31 Dec 2012 21:07:54 +0800 Received: from localhost.localdomain (dbdp20.itg.ti.com [172.24.170.38]) by dbdp32.itg.ti.com (8.13.8/8.13.8) with ESMTP id qBVD7dBU030716; Mon, 31 Dec 2012 18:37:54 +0530 From: Vaibhav Bedia To: , , , Subject: [RFC v2 02/18] mailbox: Add an API for flushing the FIFO Date: Mon, 31 Dec 2012 18:36:55 +0530 Message-ID: <1356959231-17335-3-git-send-email-vaibhav.bedia@ti.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1356959231-17335-1-git-send-email-vaibhav.bedia@ti.com> References: <1356959231-17335-1-git-send-email-vaibhav.bedia@ti.com> MIME-Version: 1.0 X-Bad-Reply: References and In-Reply-To but no 'Re:' in Subject. X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121231_080801_001943_F3DDDA50 X-CRM114-Status: GOOD ( 16.59 ) X-Spam-Score: -7.6 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.6 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 -0.7 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] X-Mailman-Approved-At: Tue, 08 Jan 2013 08:12:36 -0500 Cc: Santosh Shilimkar , Vaibhav Bedia X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org On AM33XX, the mailbox module between the MPU and the WKUP-M3 co-processor facilitates a one-way communication. MPU uses the assigned mailbox sub-module to issue the interrupt to the WKUP-M3 co-processor which then goes and reads the the IPC data from registers in the control module. WKUP-M3 is in the L4_WKUP and does not have any access to the mailbox module. Due to this limitation, the MPU is completely responsible for FIFO maintenance and interrupt generation. MPU needs to ensure that the FIFO does not overflow by reading back the assigned mailbox sub-module. This patch adds an API in the mailbox code which the MPU can use to empty the FIFO by issuing a readback command. Signed-off-by: Vaibhav Bedia Cc: Santosh Shilimkar --- Note: This patch which will be slightly reworked once the mailbox driver changes are finalized. drivers/mailbox/mailbox-omap2.c | 19 +++++++++++++++++++ drivers/mailbox/mailbox.c | 36 ++++++++++++++++++++++++++++++++++++ drivers/mailbox/mailbox.h | 3 +++ include/linux/mailbox.h | 1 + 4 files changed, 59 insertions(+), 0 deletions(-) diff --git a/drivers/mailbox/mailbox-omap2.c b/drivers/mailbox/mailbox-omap2.c index 6d61159..c732be1 100644 --- a/drivers/mailbox/mailbox-omap2.c +++ b/drivers/mailbox/mailbox-omap2.c @@ -125,6 +125,23 @@ static int omap2_mbox_fifo_full(struct mailbox *mbox) return mbox_read_reg(fifo->fifo_stat); } +static int omap2_mbox_fifo_needs_flush(struct mailbox *mbox) +{ + struct omap_mbox2_priv *p = mbox->priv; + struct omap_mbox2_fifo *fifo = &p->tx_fifo; + + return mbox_read_reg(fifo->msg_stat); +} + +static void omap2_mbox_fifo_readback(struct mailbox *mbox, + struct mailbox_msg *msg) +{ + struct omap_mbox2_priv *p = mbox->priv; + struct omap_mbox2_fifo *fifo = &p->tx_fifo; + + msg->header = mbox_read_reg(fifo->msg); +} + static int ompa2_mbox_poll_for_space(struct mailbox *mbox) { if (omap2_mbox_fifo_full(mbox)) @@ -221,6 +238,8 @@ static struct mailbox_ops omap2_mbox_ops = { .read = omap2_mbox_fifo_read, .write = omap2_mbox_fifo_write, .empty = omap2_mbox_fifo_empty, + .fifo_needs_flush = omap2_mbox_fifo_needs_flush, + .fifo_readback = omap2_mbox_fifo_readback, .poll_for_space = ompa2_mbox_poll_for_space, .enable_irq = omap2_mbox_enable_irq, .disable_irq = omap2_mbox_disable_irq, diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 2f50226..92c9f68 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -57,6 +57,15 @@ static inline int mbox_empty(struct mailbox *mbox) { return mbox->ops->empty(mbox); } +static inline int mbox_fifo_needs_flush(struct mailbox *mbox) +{ + return mbox->ops->fifo_needs_flush(mbox); +} +static inline void mbox_fifo_readback(struct mailbox *mbox, + struct mailbox_msg *msg) +{ + mbox->ops->fifo_readback(mbox, msg); +} /* Mailbox IRQ handle functions */ static inline void ack_mbox_irq(struct mailbox *mbox, mailbox_irq_t irq) @@ -110,6 +119,33 @@ out: } EXPORT_SYMBOL(mailbox_msg_send); +/* + * Flush the Rx FIFO by reading back the messages + * Since the normal expectation is that the Rx will do the + * reading, add a debug message to indicate if we really flush + * + * Returns the no. of messages read back + */ +int mailbox_rx_flush(struct mailbox *mbox) +{ + int ret = 0; + struct mailbox_msg readback_msg; + + while (mbox_fifo_needs_flush(mbox)) { + mbox_fifo_readback(mbox, &readback_msg); + ret++; + } + + if (ret) { + /* no more messages in the fifo. clear IRQ source. */ + ack_mbox_irq(mbox, IRQ_RX); + pr_debug("Flushed %s Rx FIFO by reading back\n", mbox->name); + } + + return ret; +} +EXPORT_SYMBOL(mailbox_rx_flush); + #define TRANSFER_TIMEOUT 30000 /* Becomes ~3s timeout */ static struct mailbox_msg no_irq_msg_res; diff --git a/drivers/mailbox/mailbox.h b/drivers/mailbox/mailbox.h index f103194..b841ae1 100644 --- a/drivers/mailbox/mailbox.h +++ b/drivers/mailbox/mailbox.h @@ -24,6 +24,9 @@ struct mailbox_ops { int (*write)(struct mailbox *mbox, struct mailbox_msg *msg); int (*empty)(struct mailbox *mbox); int (*poll_for_space)(struct mailbox *mbox); + int (*fifo_needs_flush)(struct mailbox *mbox); + void (*fifo_readback)(struct mailbox *mbox, + struct mailbox_msg *msg); /* irq */ void (*enable_irq)(struct mailbox *mbox, mailbox_irq_t irq); diff --git a/include/linux/mailbox.h b/include/linux/mailbox.h index 3f9ec1e..705def9 100644 --- a/include/linux/mailbox.h +++ b/include/linux/mailbox.h @@ -22,6 +22,7 @@ struct mailbox_msg { #define MAILBOX_FILL_HEADER_MSG(_msg, _header) \ MAILBOX_FILL_MSG(_msg, _header, NULL, 0); +int mailbox_rx_flush(struct mailbox *); int mailbox_msg_send(struct mailbox *, struct mailbox_msg *msg); struct mailbox_msg *mailbox_msg_send_receive_no_irq(struct mailbox *, struct mailbox_msg *msg);