Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1532343 > unrolled thread

[PATCH 1/2] mailbox: mailbox-test: add support for fasync/poll

Started bySudeep Holla <sudeep.holla@arm.com>
First post2016-11-29 15:40 +0100
Last post2016-12-10 16:30 +0100
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/2] mailbox: mailbox-test: add support for fasync/poll Sudeep Holla <sudeep.holla@arm.com> - 2016-11-29 15:40 +0100
    [PATCH 2/2] mailbox: mailbox-test: allow reserved areas in SRAM Sudeep Holla <sudeep.holla@arm.com> - 2016-11-29 15:40 +0100
    Re: [PATCH 1/2] mailbox: mailbox-test: add support for fasync/poll Sudeep Holla <sudeep.holla@arm.com> - 2016-12-08 20:00 +0100
      Re: [PATCH 1/2] mailbox: mailbox-test: add support for fasync/poll Jassi Brar <jassisinghbrar@gmail.com> - 2016-12-10 16:30 +0100

#1532343 — [PATCH 1/2] mailbox: mailbox-test: add support for fasync/poll

FromSudeep Holla <sudeep.holla@arm.com>
Date2016-11-29 15:40 +0100
Subject[PATCH 1/2] mailbox: mailbox-test: add support for fasync/poll
Message-ID<sIRJD-1es-5@gated-at.bofh.it>
Currently the read operation on the message debug file returns error if
there's no data ready to be read. It expects the userspace to retry if
it fails. Since the mailbox response could be asynchronous, it would be
good to add support to block the read until the data is available.

We can also implement poll file operations so that the userspace can
wait to become ready to perform any I/O.

This patch implements the poll and fasync file operation callback for
the test mailbox device.

Cc: Lee Jones <lee.jones@linaro.org>
Cc: Jassi Brar <jaswinder.singh@linaro.org>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/mailbox/mailbox-test.c | 79 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 71 insertions(+), 8 deletions(-)

diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c
index 9ca96e9db6bf..d13f4f8a1ecf 100644
--- a/drivers/mailbox/mailbox-test.c
+++ b/drivers/mailbox/mailbox-test.c
@@ -11,12 +11,14 @@

 #include <linux/debugfs.h>
 #include <linux/err.h>
+#include <linux/fs.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/mailbox_client.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/poll.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>

@@ -39,6 +41,8 @@ struct mbox_test_device {
 	char			*signal;
 	char			*message;
 	spinlock_t		lock;
+	wait_queue_head_t	waitq;
+	struct fasync_struct	*async_queue;
 };

 static ssize_t mbox_test_signal_write(struct file *filp,
@@ -81,6 +85,13 @@ static const struct file_operations mbox_test_signal_ops = {
 	.llseek	= generic_file_llseek,
 };

+static int mbox_test_message_fasync(int fd, struct file *filp, int on)
+{
+	struct mbox_test_device *tdev = filp->private_data;
+
+	return fasync_helper(fd, filp, on, &tdev->async_queue);
+}
+
 static ssize_t mbox_test_message_write(struct file *filp,
 				       const char __user *userbuf,
 				       size_t count, loff_t *ppos)
@@ -138,6 +149,20 @@ static ssize_t mbox_test_message_write(struct file *filp,
 	return ret < 0 ? ret : count;
 }

+static bool mbox_test_message_data_ready(struct mbox_test_device *tdev)
+{
+	unsigned char data;
+	unsigned long flags;
+
+	spin_lock_irqsave(&tdev->lock, flags);
+	data = tdev->rx_buffer[0];
+	spin_unlock_irqrestore(&tdev->lock, flags);
+
+	if (data != '\0')
+		return true;
+	return false;
+}
+
 static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf,
 				      size_t count, loff_t *ppos)
 {
@@ -147,6 +172,8 @@ static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf,
 	int l = 0;
 	int ret;

+	DECLARE_WAITQUEUE(wait, current);
+
 	touser = kzalloc(MBOX_HEXDUMP_MAX_LEN + 1, GFP_KERNEL);
 	if (!touser)
 		return -ENOMEM;
@@ -155,15 +182,29 @@ static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf,
 		ret = snprintf(touser, 20, "<NO RX CAPABILITY>\n");
 		ret = simple_read_from_buffer(userbuf, count, ppos,
 					      touser, ret);
-		goto out;
+		goto kfree_err;
 	}

-	if (tdev->rx_buffer[0] == '\0') {
-		ret = snprintf(touser, 9, "<EMPTY>\n");
-		ret = simple_read_from_buffer(userbuf, count, ppos,
-					      touser, ret);
-		goto out;
-	}
+	add_wait_queue(&tdev->waitq, &wait);
+
+	do {
+		__set_current_state(TASK_INTERRUPTIBLE);
+
+		if (mbox_test_message_data_ready(tdev))
+			break;
+
+		if (filp->f_flags & O_NONBLOCK) {
+			ret = -EAGAIN;
+			goto waitq_err;
+		}
+
+		if (signal_pending(current)) {
+			ret = -ERESTARTSYS;
+			goto waitq_err;
+		}
+		schedule();
+
+	} while (1);

 	spin_lock_irqsave(&tdev->lock, flags);

@@ -185,14 +226,31 @@ static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf,
 	spin_unlock_irqrestore(&tdev->lock, flags);

 	ret = simple_read_from_buffer(userbuf, count, ppos, touser, MBOX_HEXDUMP_MAX_LEN);
-out:
+waitq_err:
+	__set_current_state(TASK_RUNNING);
+	remove_wait_queue(&tdev->waitq, &wait);
+kfree_err:
 	kfree(touser);
 	return ret;
 }

+static unsigned int
+mbox_test_message_poll(struct file *filp, struct poll_table_struct *wait)
+{
+	struct mbox_test_device *tdev = filp->private_data;
+
+	poll_wait(filp, &tdev->waitq, wait);
+
+	if (mbox_test_message_data_ready(tdev))
+		return POLLIN | POLLRDNORM;
+	return 0;
+}
+
 static const struct file_operations mbox_test_message_ops = {
 	.write	= mbox_test_message_write,
 	.read	= mbox_test_message_read,
+	.fasync	= mbox_test_message_fasync,
+	.poll	= mbox_test_message_poll,
 	.open	= simple_open,
 	.llseek	= generic_file_llseek,
 };
@@ -234,6 +292,10 @@ static void mbox_test_receive_message(struct mbox_client *client, void *message)
 		memcpy(tdev->rx_buffer, message, MBOX_MAX_MSG_LEN);
 	}
 	spin_unlock_irqrestore(&tdev->lock, flags);
+
+	wake_up_interruptible(&tdev->waitq);
+
+	kill_fasync(&tdev->async_queue, SIGIO, POLL_IN);
 }

 static void mbox_test_prepare_message(struct mbox_client *client, void *message)
@@ -334,6 +396,7 @@ static int mbox_test_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;

+	init_waitqueue_head(&tdev->waitq);
 	dev_info(&pdev->dev, "Successfully registered\n");

 	return 0;
--
2.7.4

[toc] | [next] | [standalone]


#1532346 — [PATCH 2/2] mailbox: mailbox-test: allow reserved areas in SRAM

FromSudeep Holla <sudeep.holla@arm.com>
Date2016-11-29 15:40 +0100
Subject[PATCH 2/2] mailbox: mailbox-test: allow reserved areas in SRAM
Message-ID<sIRJE-1es-23@gated-at.bofh.it>
In reply to#1532343
When CONFIG_SRAM is enable and the SRAM region is found, the entire SRAM
region resource is requested and marked as occupied by SRAM driver even
if certain parts of regions is marked reserved.

It's quite possible that a small region of the SRAM is reserved for all
the mailbox communication and hence it may fail to request the region
as it's already marked busy region.

This patch tries to just do a ioremap of this mailbox memory region if
it finds it busy.

Cc: Lee Jones <lee.jones@linaro.org>
Cc: Jassi Brar <jaswinder.singh@linaro.org>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/mailbox/mailbox-test.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c
index d13f4f8a1ecf..f152f1795c51 100644
--- a/drivers/mailbox/mailbox-test.c
+++ b/drivers/mailbox/mailbox-test.c
@@ -352,6 +352,7 @@ static int mbox_test_probe(struct platform_device *pdev)
 {
 	struct mbox_test_device *tdev;
 	struct resource *res;
+	resource_size_t size;
 	int ret;

 	tdev = devm_kzalloc(&pdev->dev, sizeof(*tdev), GFP_KERNEL);
@@ -360,14 +361,21 @@ static int mbox_test_probe(struct platform_device *pdev)

 	/* It's okay for MMIO to be NULL */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	size = resource_size(res);
 	tdev->tx_mmio = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(tdev->tx_mmio))
+	if (PTR_ERR(tdev->tx_mmio) == -EBUSY)
+		/* if reserved area in SRAM, try just ioremap */
+		tdev->tx_mmio = devm_ioremap(&pdev->dev, res->start, size);
+	else if (IS_ERR(tdev->tx_mmio))
 		tdev->tx_mmio = NULL;

 	/* If specified, second reg entry is Rx MMIO */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	size = resource_size(res);
 	tdev->rx_mmio = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(tdev->rx_mmio))
+	if (PTR_ERR(tdev->rx_mmio) == -EBUSY)
+		tdev->rx_mmio = devm_ioremap(&pdev->dev, res->start, size);
+	else if (IS_ERR(tdev->rx_mmio))
 		tdev->rx_mmio = tdev->tx_mmio;

 	tdev->tx_channel = mbox_test_request_channel(pdev, "tx");
--
2.7.4

[toc] | [prev] | [next] | [standalone]


#1538808

FromSudeep Holla <sudeep.holla@arm.com>
Date2016-12-08 20:00 +0100
Message-ID<sMc5b-1bo-19@gated-at.bofh.it>
In reply to#1532343

On 29/11/16 14:37, Sudeep Holla wrote:
> Currently the read operation on the message debug file returns error if
> there's no data ready to be read. It expects the userspace to retry if
> it fails. Since the mailbox response could be asynchronous, it would be
> good to add support to block the read until the data is available.
> 
> We can also implement poll file operations so that the userspace can
> wait to become ready to perform any I/O.
> 
> This patch implements the poll and fasync file operation callback for
> the test mailbox device.
> 
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Jassi Brar <jaswinder.singh@linaro.org>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

Gentle Ping!

-- 
Regards,
Sudeep

[toc] | [prev] | [next] | [standalone]


#1539851

FromJassi Brar <jassisinghbrar@gmail.com>
Date2016-12-10 16:30 +0100
Message-ID<sMRL4-3XZ-11@gated-at.bofh.it>
In reply to#1538808
On Fri, Dec 9, 2016 at 12:26 AM, Sudeep Holla <sudeep.holla@arm.com> wrote:
>
>
> On 29/11/16 14:37, Sudeep Holla wrote:
>> Currently the read operation on the message debug file returns error if
>> there's no data ready to be read. It expects the userspace to retry if
>> it fails. Since the mailbox response could be asynchronous, it would be
>> good to add support to block the read until the data is available.
>>
>> We can also implement poll file operations so that the userspace can
>> wait to become ready to perform any I/O.
>>
>> This patch implements the poll and fasync file operation callback for
>> the test mailbox device.
>>
>> Cc: Lee Jones <lee.jones@linaro.org>
>> Cc: Jassi Brar <jaswinder.singh@linaro.org>
>> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
>
> Gentle Ping!
>
Would be good to have Lee's ack.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web