* [PATCH 0/2] apple-mailbox: add support for atomc mailbox operations
@ 2022-09-05 16:48 Russell King (Oracle)
2022-09-05 16:48 ` [PATCH 1/2] mailbox: apple: Implement flush() operation Russell King
2022-09-05 16:48 ` [PATCH 2/2] mailbox: apple: Implement poll_data() operation Russell King
0 siblings, 2 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2022-09-05 16:48 UTC (permalink / raw)
To: Jassi Brar
Cc: Alyssa Rosenzweig, asahi, Hector Martin, linux-arm-kernel,
Sven Peter
Hi,
This series adds support for atomic mailbox operations to the Apple
mailbox driver.
drivers/mailbox/apple-mailbox.c | 64 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 61 insertions(+), 3 deletions(-)
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] mailbox: apple: Implement flush() operation
2022-09-05 16:48 [PATCH 0/2] apple-mailbox: add support for atomc mailbox operations Russell King (Oracle)
@ 2022-09-05 16:48 ` Russell King
2022-09-05 16:58 ` Sven Peter
2022-09-05 16:48 ` [PATCH 2/2] mailbox: apple: Implement poll_data() operation Russell King
1 sibling, 1 reply; 6+ messages in thread
From: Russell King @ 2022-09-05 16:48 UTC (permalink / raw)
To: Jassi Brar
Cc: Hector Martin, Sven Peter, Alyssa Rosenzweig, asahi,
linux-arm-kernel
From: Hector Martin <marcan@marcan.st>
This allows clients to use the atomic-safe mailbox API style.
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/mailbox/apple-mailbox.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/mailbox/apple-mailbox.c b/drivers/mailbox/apple-mailbox.c
index 496c4951ccb1..33e7acf71e3e 100644
--- a/drivers/mailbox/apple-mailbox.c
+++ b/drivers/mailbox/apple-mailbox.c
@@ -17,6 +17,7 @@
*/
#include <linux/apple-mailbox.h>
+#include <linux/delay.h>
#include <linux/device.h>
#include <linux/gfp.h>
#include <linux/interrupt.h>
@@ -112,6 +113,14 @@ static bool apple_mbox_hw_can_send(struct apple_mbox *apple_mbox)
return !(mbox_ctrl & apple_mbox->hw->control_full);
}
+static bool apple_mbox_hw_send_empty(struct apple_mbox *apple_mbox)
+{
+ u32 mbox_ctrl =
+ readl_relaxed(apple_mbox->regs + apple_mbox->hw->a2i_control);
+
+ return mbox_ctrl & apple_mbox->hw->control_empty;
+}
+
static int apple_mbox_hw_send(struct apple_mbox *apple_mbox,
struct apple_mbox_msg *msg)
{
@@ -219,6 +228,23 @@ static irqreturn_t apple_mbox_recv_irq(int irq, void *data)
return IRQ_HANDLED;
}
+static int apple_mbox_chan_flush(struct mbox_chan *chan, unsigned long timeout)
+{
+ struct apple_mbox *apple_mbox = chan->con_priv;
+ unsigned long deadline = jiffies + msecs_to_jiffies(timeout);
+
+ while (time_before(jiffies, deadline)) {
+ if (apple_mbox_hw_send_empty(apple_mbox)) {
+ mbox_chan_txdone(&apple_mbox->chan, 0);
+ return 0;
+ }
+
+ udelay(1);
+ }
+
+ return -ETIME;
+}
+
static int apple_mbox_chan_startup(struct mbox_chan *chan)
{
struct apple_mbox *apple_mbox = chan->con_priv;
@@ -250,6 +276,7 @@ static void apple_mbox_chan_shutdown(struct mbox_chan *chan)
static const struct mbox_chan_ops apple_mbox_ops = {
.send_data = apple_mbox_chan_send_data,
+ .flush = apple_mbox_chan_flush,
.startup = apple_mbox_chan_startup,
.shutdown = apple_mbox_chan_shutdown,
};
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] mailbox: apple: Implement poll_data() operation
2022-09-05 16:48 [PATCH 0/2] apple-mailbox: add support for atomc mailbox operations Russell King (Oracle)
2022-09-05 16:48 ` [PATCH 1/2] mailbox: apple: Implement flush() operation Russell King
@ 2022-09-05 16:48 ` Russell King
2022-09-05 17:03 ` Sven Peter
1 sibling, 1 reply; 6+ messages in thread
From: Russell King @ 2022-09-05 16:48 UTC (permalink / raw)
To: Jassi Brar
Cc: Hector Martin, Sven Peter, Alyssa Rosenzweig, asahi,
linux-arm-kernel
From: Hector Martin <marcan@marcan.st>
This allows clients running in atomic context to poll for messages to
arrive.
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/mailbox/apple-mailbox.c | 37 ++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/drivers/mailbox/apple-mailbox.c b/drivers/mailbox/apple-mailbox.c
index 33e7acf71e3e..1c14ff63f3d3 100644
--- a/drivers/mailbox/apple-mailbox.c
+++ b/drivers/mailbox/apple-mailbox.c
@@ -26,6 +26,7 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/spinlock.h>
#include <linux/types.h>
#define APPLE_ASC_MBOX_CONTROL_FULL BIT(16)
@@ -101,6 +102,7 @@ struct apple_mbox {
struct device *dev;
struct mbox_controller controller;
+ spinlock_t rx_lock;
};
static const struct of_device_id apple_mbox_of_match[];
@@ -204,13 +206,16 @@ static irqreturn_t apple_mbox_send_empty_irq(int irq, void *data)
return IRQ_HANDLED;
}
-static irqreturn_t apple_mbox_recv_irq(int irq, void *data)
+static int apple_mbox_poll(struct apple_mbox *apple_mbox)
{
- struct apple_mbox *apple_mbox = data;
+
struct apple_mbox_msg msg;
+ int ret = 0;
- while (apple_mbox_hw_recv(apple_mbox, &msg) == 0)
+ while (apple_mbox_hw_recv(apple_mbox, &msg) == 0) {
mbox_chan_received_data(&apple_mbox->chan, (void *)&msg);
+ ret++;
+ }
/*
* The interrupt will keep firing even if there are no more messages
@@ -225,9 +230,33 @@ static irqreturn_t apple_mbox_recv_irq(int irq, void *data)
apple_mbox->regs + apple_mbox->hw->irq_ack);
}
+ return ret;
+}
+
+static irqreturn_t apple_mbox_recv_irq(int irq, void *data)
+{
+ struct apple_mbox *apple_mbox = data;
+
+ spin_lock(&apple_mbox->rx_lock);
+ apple_mbox_poll(apple_mbox);
+ spin_unlock(&apple_mbox->rx_lock);
+
return IRQ_HANDLED;
}
+static bool apple_mbox_chan_peek_data(struct mbox_chan *chan)
+{
+ struct apple_mbox *apple_mbox = chan->con_priv;
+ unsigned long flags;
+ int ret;
+
+ spin_lock_irqsave(&apple_mbox->rx_lock, flags);
+ ret = apple_mbox_poll(apple_mbox);
+ spin_unlock_irqrestore(&apple_mbox->rx_lock, flags);
+
+ return ret > 0;
+}
+
static int apple_mbox_chan_flush(struct mbox_chan *chan, unsigned long timeout)
{
struct apple_mbox *apple_mbox = chan->con_priv;
@@ -276,6 +305,7 @@ static void apple_mbox_chan_shutdown(struct mbox_chan *chan)
static const struct mbox_chan_ops apple_mbox_ops = {
.send_data = apple_mbox_chan_send_data,
+ .peek_data = apple_mbox_chan_peek_data,
.flush = apple_mbox_chan_flush,
.startup = apple_mbox_chan_startup,
.shutdown = apple_mbox_chan_shutdown,
@@ -331,6 +361,7 @@ static int apple_mbox_probe(struct platform_device *pdev)
mbox->controller.txdone_irq = true;
mbox->controller.of_xlate = apple_mbox_of_xlate;
mbox->chan.con_priv = mbox;
+ spin_lock_init(&mbox->rx_lock);
irqname = devm_kasprintf(dev, GFP_KERNEL, "%s-recv", dev_name(dev));
if (!irqname)
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] mailbox: apple: Implement flush() operation
2022-09-05 16:48 ` [PATCH 1/2] mailbox: apple: Implement flush() operation Russell King
@ 2022-09-05 16:58 ` Sven Peter
0 siblings, 0 replies; 6+ messages in thread
From: Sven Peter @ 2022-09-05 16:58 UTC (permalink / raw)
To: Russell King, Jassi Brar
Cc: Hector Martin, Alyssa Rosenzweig, asahi, linux-arm-kernel
On Mon, Sep 5, 2022, at 18:48, Russell King wrote:
> From: Hector Martin <marcan@marcan.st>
>
> This allows clients to use the atomic-safe mailbox API style.
>
> Signed-off-by: Hector Martin <marcan@marcan.st>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> ---
Reviewed-by: Sven Peter <sven@svenpeter.dev>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] mailbox: apple: Implement poll_data() operation
2022-09-05 16:48 ` [PATCH 2/2] mailbox: apple: Implement poll_data() operation Russell King
@ 2022-09-05 17:03 ` Sven Peter
2022-09-06 7:58 ` Russell King (Oracle)
0 siblings, 1 reply; 6+ messages in thread
From: Sven Peter @ 2022-09-05 17:03 UTC (permalink / raw)
To: Russell King, Jassi Brar
Cc: Hector Martin, Alyssa Rosenzweig, asahi, linux-arm-kernel
On Mon, Sep 5, 2022, at 18:48, Russell King wrote:
> From: Hector Martin <marcan@marcan.st>
>
> This allows clients running in atomic context to poll for messages to
> arrive.
>
> Signed-off-by: Hector Martin <marcan@marcan.st>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Sven Peter <sven@svenpeter.dev>
with one small comment below:
> ---
> drivers/mailbox/apple-mailbox.c | 37 ++++++++++++++++++++++++++++++---
> 1 file changed, 34 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mailbox/apple-mailbox.c b/drivers/mailbox/apple-mailbox.c
> index 33e7acf71e3e..1c14ff63f3d3 100644
> --- a/drivers/mailbox/apple-mailbox.c
> +++ b/drivers/mailbox/apple-mailbox.c
> @@ -26,6 +26,7 @@
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/platform_device.h>
> +#include <linux/spinlock.h>
> #include <linux/types.h>
>
> #define APPLE_ASC_MBOX_CONTROL_FULL BIT(16)
> @@ -101,6 +102,7 @@ struct apple_mbox {
>
> struct device *dev;
> struct mbox_controller controller;
> + spinlock_t rx_lock;
> };
>
> static const struct of_device_id apple_mbox_of_match[];
> @@ -204,13 +206,16 @@ static irqreturn_t apple_mbox_send_empty_irq(int
> irq, void *data)
> return IRQ_HANDLED;
> }
>
> -static irqreturn_t apple_mbox_recv_irq(int irq, void *data)
> +static int apple_mbox_poll(struct apple_mbox *apple_mbox)
> {
> - struct apple_mbox *apple_mbox = data;
> +
small nit: there's a spurious white line here
> struct apple_mbox_msg msg;
> + int ret = 0;
>
> - while (apple_mbox_hw_recv(apple_mbox, &msg) == 0)
> + while (apple_mbox_hw_recv(apple_mbox, &msg) == 0) {
> mbox_chan_received_data(&apple_mbox->chan, (void *)&msg);
> + ret++;
> + }
>
> /*
> * The interrupt will keep firing even if there are no more messages
> @@ -225,9 +230,33 @@ static irqreturn_t apple_mbox_recv_irq(int irq, void *data)
> apple_mbox->regs + apple_mbox->hw->irq_ack);
> }
>
> + return ret;
> +}
> +
> +static irqreturn_t apple_mbox_recv_irq(int irq, void *data)
> +{
> + struct apple_mbox *apple_mbox = data;
> +
> + spin_lock(&apple_mbox->rx_lock);
> + apple_mbox_poll(apple_mbox);
> + spin_unlock(&apple_mbox->rx_lock);
> +
> return IRQ_HANDLED;
> }
>
> +static bool apple_mbox_chan_peek_data(struct mbox_chan *chan)
> +{
> + struct apple_mbox *apple_mbox = chan->con_priv;
> + unsigned long flags;
> + int ret;
> +
> + spin_lock_irqsave(&apple_mbox->rx_lock, flags);
> + ret = apple_mbox_poll(apple_mbox);
> + spin_unlock_irqrestore(&apple_mbox->rx_lock, flags);
> +
> + return ret > 0;
> +}
> +
> static int apple_mbox_chan_flush(struct mbox_chan *chan, unsigned long timeout)
> {
> struct apple_mbox *apple_mbox = chan->con_priv;
> @@ -276,6 +305,7 @@ static void apple_mbox_chan_shutdown(struct mbox_chan *chan)
>
> static const struct mbox_chan_ops apple_mbox_ops = {
> .send_data = apple_mbox_chan_send_data,
> + .peek_data = apple_mbox_chan_peek_data,
> .flush = apple_mbox_chan_flush,
> .startup = apple_mbox_chan_startup,
> .shutdown = apple_mbox_chan_shutdown,
> @@ -331,6 +361,7 @@ static int apple_mbox_probe(struct platform_device *pdev)
> mbox->controller.txdone_irq = true;
> mbox->controller.of_xlate = apple_mbox_of_xlate;
> mbox->chan.con_priv = mbox;
> + spin_lock_init(&mbox->rx_lock);
>
> irqname = devm_kasprintf(dev, GFP_KERNEL, "%s-recv", dev_name(dev));
> if (!irqname)
> --
> 2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] mailbox: apple: Implement poll_data() operation
2022-09-05 17:03 ` Sven Peter
@ 2022-09-06 7:58 ` Russell King (Oracle)
0 siblings, 0 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2022-09-06 7:58 UTC (permalink / raw)
To: Sven Peter
Cc: Jassi Brar, Hector Martin, Alyssa Rosenzweig, asahi,
linux-arm-kernel
On Mon, Sep 05, 2022 at 07:03:39PM +0200, Sven Peter wrote:
>
>
> On Mon, Sep 5, 2022, at 18:48, Russell King wrote:
> > From: Hector Martin <marcan@marcan.st>
> >
> > This allows clients running in atomic context to poll for messages to
> > arrive.
> >
> > Signed-off-by: Hector Martin <marcan@marcan.st>
> > Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
>
> Reviewed-by: Sven Peter <sven@svenpeter.dev>
>
> with one small comment below:
>
> > ---
> > drivers/mailbox/apple-mailbox.c | 37 ++++++++++++++++++++++++++++++---
> > 1 file changed, 34 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/mailbox/apple-mailbox.c b/drivers/mailbox/apple-mailbox.c
> > index 33e7acf71e3e..1c14ff63f3d3 100644
> > --- a/drivers/mailbox/apple-mailbox.c
> > +++ b/drivers/mailbox/apple-mailbox.c
> > @@ -26,6 +26,7 @@
> > #include <linux/module.h>
> > #include <linux/of.h>
> > #include <linux/platform_device.h>
> > +#include <linux/spinlock.h>
> > #include <linux/types.h>
> >
> > #define APPLE_ASC_MBOX_CONTROL_FULL BIT(16)
> > @@ -101,6 +102,7 @@ struct apple_mbox {
> >
> > struct device *dev;
> > struct mbox_controller controller;
> > + spinlock_t rx_lock;
> > };
> >
> > static const struct of_device_id apple_mbox_of_match[];
> > @@ -204,13 +206,16 @@ static irqreturn_t apple_mbox_send_empty_irq(int
> > irq, void *data)
> > return IRQ_HANDLED;
> > }
> >
> > -static irqreturn_t apple_mbox_recv_irq(int irq, void *data)
> > +static int apple_mbox_poll(struct apple_mbox *apple_mbox)
> > {
> > - struct apple_mbox *apple_mbox = data;
> > +
>
> small nit: there's a spurious white line here
Thanks, well spotted. Will fix.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-09-06 7:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-05 16:48 [PATCH 0/2] apple-mailbox: add support for atomc mailbox operations Russell King (Oracle)
2022-09-05 16:48 ` [PATCH 1/2] mailbox: apple: Implement flush() operation Russell King
2022-09-05 16:58 ` Sven Peter
2022-09-05 16:48 ` [PATCH 2/2] mailbox: apple: Implement poll_data() operation Russell King
2022-09-05 17:03 ` Sven Peter
2022-09-06 7:58 ` Russell King (Oracle)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).