apple rtkit: add support for atomic operations
Subsystems (2)
cover apple rtkit: add support for atomic operations
Hi,
This series adds support to the Apple rtkit for atomic messaging, which will be necessary for SMC support on these platforms.
SMC support requires a bit of rework after recent review comments, so I'm sending this separately in the hope that we can move forward with upstream kernels.
drivers/mailbox/apple-mailbox.c | 63 +++++++++++++++++++++++++++++++++++++++-- drivers/soc/apple/rtkit.c | 6 ++++ include/linux/soc/apple/rtkit.h | 12 ++++++++ 3 files changed, 78 insertions(+), 3 deletions(-)
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
PATCH 1/3 mailbox: apple: Implement flush() operation
From: Hector Martin <[email protected]>
This allows clients to use the atomic-safe mailbox API style.
--- drivers/mailbox/apple-mailbox.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/mailbox/apple-mailbox.c +27 -0
@@ -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, };
Signature · 1 line
2.30.2
PATCH 2/3 mailbox: apple: Implement poll_data() operation
In reply to Russell King (Oracle)From: Hector Martin <[email protected]>
This allows clients running in atomic context to poll for messages to arrive.
--- drivers/mailbox/apple-mailbox.c | 36 ++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-)
drivers/mailbox/apple-mailbox.c +33 -3
@@ -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,15 @@ 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 +229,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 +304,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 +360,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)
Signature · 1 line
2.30.2
PATCH 3/3 soc: apple: rtkit: Add apple_rtkit_poll
In reply to Russell King (Oracle)From: Hector Martin <[email protected]>
This allows a client to receive messages in atomic context, by polling.
--- drivers/soc/apple/rtkit.c | 6 ++++++ include/linux/soc/apple/rtkit.h | 12 ++++++++++++ 2 files changed, 18 insertions(+)
drivers/soc/apple/rtkit.c +6 -0
@@ -660,6 +660,12 @@ int apple_rtkit_send_message_wait(struct apple_rtkit *rtk, u8 ep, u64 message, }EXPORT_SYMBOL_GPL (apple_rtkit_send_message_wait); +int apple_rtkit_poll (struct apple_rtkit *rtk) +{ +return mbox_client_peek_data (rtk->mbox_chan); +} +EXPORT_SYMBOL_GPL (apple_rtkit_poll); +int apple_rtkit_start_ep (struct apple_rtkit *rtk,u8 endpoint) {u64 msg;
include/linux/soc/apple/rtkit.h +12 -0
@@ -152,4 +152,16 @@ int apple_rtkit_send_message(struct apple_rtkit *rtk, u8 ep, u64 message,int apple_rtkit_send_message_wait (struct apple_rtkit *rtk,u8 ep,u64 message,unsigned long timeout,bool atomic); +/* +* Process incoming messages in atomic context. +* This only guarantees that messages arrive as far as the recv_message_early +* callback; drivers expecting to handle incoming messages synchronously +* by calling this function must do it that way. +* Will return 1 if some data was processed, 0 if none was, or a +* negative error code on failure. +* +* @rtk: RTKit reference +*/ +int apple_rtkit_poll (struct apple_rtkit *rtk); +#endif /* _LINUX_APPLE_RTKIT_H_ */
Signature · 1 line
2.30.2
Hi,
Quoted 8 lines · Russell King (Oracle)
Hi,
This series adds support to the Apple rtkit for atomic messaging, which will be necessary for SMC support on these platforms.
SMC support requires a bit of rework after recent review comments, so I'm sending this separately in the hope that we can move forward with upstream kernels.
Maybe I misremember or maybe you forgot to pick up my reviewed-by tags for the mailbox commits.
Either way, for the entire series:
We'd usually take the last soc/rtkit commit through the Asahi platform and then the soc tree. Taking it through the mailbox tree will make things more complicated if SMC (which is the only driver that uses the poll API and hard depends on it) is also ready for this merge window. I don't think that's very likely so taking it through mailbox is also fine.
Best,
Sven
Quoted 8 lines · Sven Peter
Hi,
Quoted 5 lines · Russell King (Oracle)
Hi,
This series adds support to the Apple rtkit for atomic messaging, which will be necessary for SMC support on these platforms.
Quoted 6 lines
Quoted 3 lines
SMC support requires a bit of rework after recent review comments, so I'm sending this separately in the hope that we can move forward with upstream kernels.
Maybe I misremember or maybe you forgot to pick up my reviewed-by tags for the mailbox commits.
It's the first time I've sent the mailbox commits after Hector mentioned them.
Quoted 10 lines
Either way, for the entire series:
Reviewed-by Sven Peter <[email protected]>We'd usually take the last soc/rtkit commit through the Asahi platform and then the soc tree. Taking it through the mailbox tree will make things more complicated if SMC (which is the only driver that uses the poll API and hard depends on it) is also ready for this merge window. I don't think that's very likely so taking it through mailbox is also fine.
I'm sending these seperately because I don't think the platform/mfd issues will be sorted before the merge window. We've fallen into the trap where I have a load of updates to the patches in my git tree that aren't in the Asahi tree, but Lee wants some substantial changes to the way the MFD part is handled which I think Hector needs to do. So somehow I need to get my changes back to Hector (I don't do github) which basically means digging out the original patches from the Asahi kernel tree and supplying diffs to Hector for those - along with all the acks/reviewed-bys etc. This *really* isn't nice.
I didn't follow that discussion very well - with about 130 messages in total in that thread, it just became too much for me to keep track of, as I explained as the discussion drew to a close. That was the whole reason for me sending v2, which essentially mostly got ignored and discussion continued on v1.
So, basically, trying to get these patches into mainline has created a hell of a lot of extra work and difficulty - and at this point I'm wondering whether it really is a good idea to continue with this.
It's fine if the comments are all minor issues that can be quickly resolved, but a major restructuring is a completely different matter.
So, to at least get some progress, I decided to send what would be possible to hopefully merge during the remainder of this window.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Quoted 13 lines · Russell King (Oracle)
Quoted 12 lines · Sven Peter
Hi,
Quoted 8 lines · Russell King (Oracle)
Hi,
This series adds support to the Apple rtkit for atomic messaging, which will be necessary for SMC support on these platforms.
SMC support requires a bit of rework after recent review comments, so I'm sending this separately in the hope that we can move forward with upstream kernels.
Quoted 5 lines
Quoted 2 lines
Maybe I misremember or maybe you forgot to pick up my reviewed-by tags for the mailbox commits.
It's the first time I've sent the mailbox commits after Hector mentioned them.
There are just too many things in flight right now which is part of the reason I'm happy you're trying to get all this upstream!
https://lore.kernel.org/asahi/YxYoW2IZFK%[email protected]/
Quoted 32 lines
Quoted 11 lines
Either way, for the entire series:
Reviewed-by Sven Peter <[email protected]>We'd usually take the last soc/rtkit commit through the Asahi platform and then the soc tree. Taking it through the mailbox tree will make things more complicated if SMC (which is the only driver that uses the poll API and hard depends on it) is also ready for this merge window. I don't think that's very likely so taking it through mailbox is also fine.
I'm sending these seperately because I don't think the platform/mfd issues will be sorted before the merge window. We've fallen into the trap where I have a load of updates to the patches in my git tree that aren't in the Asahi tree, but Lee wants some substantial changes to the way the MFD part is handled which I think Hector needs to do. So somehow I need to get my changes back to Hector (I don't do github) which basically means digging out the original patches from the Asahi kernel tree and supplying diffs to Hector for those - along with all the acks/reviewed-bys etc. This *really* isn't nice.
I didn't follow that discussion very well - with about 130 messages in total in that thread, it just became too much for me to keep track of, as I explained as the discussion drew to a close. That was the whole reason for me sending v2, which essentially mostly got ignored and discussion continued on v1.
So, basically, trying to get these patches into mainline has created a hell of a lot of extra work and difficulty - and at this point I'm wondering whether it really is a good idea to continue with this.
Quoted 5 lines
It's fine if the comments are all minor issues that can be quickly resolved, but a major restructuring is a completely different matter.
So, to at least get some progress, I decided to send what would be possible to hopefully merge during the remainder of this window.
yeah, I'm just glad this is finally getting some momentum. there's just too many things in-flight in our downstream trees!
I didn't follow that discussion entirely either but I also don't think SMC will land in this merge window so taking this through mailbox is completely fine with me.
Sven
Quoted 16 lines · Sven Peter
Quoted 16 lines · Sven Peter
Quoted 14 lines
Hi,
Quoted 8 lines · Russell King (Oracle)
Hi,
This series adds support to the Apple rtkit for atomic messaging, which will be necessary for SMC support on these platforms.
SMC support requires a bit of rework after recent review comments, so I'm sending this separately in the hope that we can move forward with upstream kernels.
Maybe I misremember or maybe you forgot to pick up my reviewed-by tags for the mailbox commits.
Quoted 7 lines
Quoted 2 lines
It's the first time I've sent the mailbox commits after Hector mentioned them.
There are just too many things in flight right now which is part of the reason I'm happy you're trying to get all this upstream!
Hmm, I'd completely forgotten that I've posted it previously! Hmm, no response from Jassi on the previous posting despite nothing no action being required on the patches. Jassi?
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Jassi Brar
maintainerQuoted 21 lines · Russell King (Oracle)
Quoted 19 lines · Sven Peter
Quoted 18 lines · Sven Peter
Quoted 8 lines
Hi,
Quoted 5 lines · Russell King (Oracle)
Hi,
This series adds support to the Apple rtkit for atomic messaging, which will be necessary for SMC support on these platforms.
Quoted 6 lines
Quoted 3 lines
SMC support requires a bit of rework after recent review comments, so I'm sending this separately in the hope that we can move forward with upstream kernels.
Maybe I misremember or maybe you forgot to pick up my reviewed-by tags for the mailbox commits.
It's the first time I've sent the mailbox commits after Hector mentioned them.
Quoted 9 lines
Quoted 4 lines
There are just too many things in flight right now which is part of the reason I'm happy you're trying to get all this upstream!
Hmm, I'd completely forgotten that I've posted it previously! Hmm, no response from Jassi on the previous posting despite nothing no action being required on the patches. Jassi?
Usually I let patches roast in public until rc7 but I sensed other parts of apple support might depend on these.
So I picked patches 1 & 2 from this series yesterday.
https://git.linaro.org/landing-teams/working/fujitsu/integration.git/log/?h=mailbox-for-next
cheers.
Quoted 28 lines · Jassi Brar
Quoted 26 lines · Russell King (Oracle)
Quoted 23 lines · Sven Peter
Quoted 13 lines · Sven Peter
Quoted 12 lines
Hi,
Quoted 8 lines · Russell King (Oracle)
Hi,
This series adds support to the Apple rtkit for atomic messaging, which will be necessary for SMC support on these platforms.
SMC support requires a bit of rework after recent review comments, so I'm sending this separately in the hope that we can move forward with upstream kernels.
Quoted 5 lines
Quoted 2 lines
Maybe I misremember or maybe you forgot to pick up my reviewed-by tags for the mailbox commits.
It's the first time I've sent the mailbox commits after Hector mentioned them.
There are just too many things in flight right now which is part of the reason I'm happy you're trying to get all this upstream!
Quoted 8 lines
Quoted 4 lines
Hmm, I'd completely forgotten that I've posted it previously! Hmm, no response from Jassi on the previous posting despite nothing no action being required on the patches. Jassi?
Usually I let patches roast in public until rc7 but I sensed other parts of apple support might depend on these.
So I picked patches 1 & 2 from this series yesterday.
https://git.linaro.org/landing-teams/working/fujitsu/integration.git/log/?h=mailbox-for-next
Thanks!
Now I need to work out how we get patch 3 into mainline - there appears to be no maintainer for drivers/soc, so unless something happens, it's not going to be picked up...
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Jassi Brar
maintainerQuoted 39 lines · Russell King (Oracle)
Quoted 28 lines · Jassi Brar
Quoted 26 lines · Russell King (Oracle)
Quoted 23 lines · Sven Peter
Quoted 13 lines · Sven Peter
Quoted 12 lines
Hi,
Quoted 8 lines · Russell King (Oracle)
Hi,
This series adds support to the Apple rtkit for atomic messaging, which will be necessary for SMC support on these platforms.
SMC support requires a bit of rework after recent review comments, so I'm sending this separately in the hope that we can move forward with upstream kernels.
Quoted 5 lines
Quoted 2 lines
Maybe I misremember or maybe you forgot to pick up my reviewed-by tags for the mailbox commits.
It's the first time I've sent the mailbox commits after Hector mentioned them.
There are just too many things in flight right now which is part of the reason I'm happy you're trying to get all this upstream!
Quoted 8 lines
Quoted 4 lines
Hmm, I'd completely forgotten that I've posted it previously! Hmm, no response from Jassi on the previous posting despite nothing no action being required on the patches. Jassi?
Usually I let patches roast in public until rc7 but I sensed other parts of apple support might depend on these.
So I picked patches 1 & 2 from this series yesterday.
https://git.linaro.org/landing-teams/working/fujitsu/integration.git/log/?h=mailbox-for-next
Quoted 6 lines
Thanks!
Now I need to work out how we get patch 3 into mainline - there appears to be no maintainer for
drivers/soc, so unless something happens, it's not going to be picked up...
If nothing else works, I can pick it as a one off case.
cheers.
Quoted 38 lines · Russell King (Oracle)
Quoted 28 lines · Jassi Brar
Quoted 26 lines · Russell King (Oracle)
Quoted 23 lines · Sven Peter
Quoted 13 lines · Sven Peter
Quoted 12 lines
Hi,
Quoted 8 lines · Russell King (Oracle)
Hi,
This series adds support to the Apple rtkit for atomic messaging, which will be necessary for SMC support on these platforms.
SMC support requires a bit of rework after recent review comments, so I'm sending this separately in the hope that we can move forward with upstream kernels.
Quoted 5 lines
Quoted 2 lines
Maybe I misremember or maybe you forgot to pick up my reviewed-by tags for the mailbox commits.
It's the first time I've sent the mailbox commits after Hector mentioned them.
There are just too many things in flight right now which is part of the reason I'm happy you're trying to get all this upstream!
Quoted 8 lines
Quoted 4 lines
Hmm, I'd completely forgotten that I've posted it previously! Hmm, no response from Jassi on the previous posting despite nothing no action being required on the patches. Jassi?
Usually I let patches roast in public until rc7 but I sensed other parts of apple support might depend on these.
So I picked patches 1 & 2 from this series yesterday.
https://git.linaro.org/landing-teams/working/fujitsu/integration.git/log/?h=mailbox-for-next
Quoted 6 lines
Thanks!
Now I need to work out how we get patch 3 into mainline - there appears to be no maintainer for
drivers/soc, so unless something happens, it's not going to be picked up...
We own drivers/soc/apple, so I will pick that up (as long as it's reviewed by someone else, which it is) :). Same with DTs for our platforms.
Those PRs then go out via the SoC tree. Please remind me if I haven't picked it up and sent it upstream by Tuesday! (I need to get some sleep now)
- Hector