Skip to content

Commit c354dae

Browse files
committed
soc: apple: rtkit: Port to the internal mailbox driver
Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent 9e9a004 commit c354dae

3 files changed

Lines changed: 31 additions & 80 deletions

File tree

drivers/soc/apple/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ config APPLE_MBOX
3333

3434
config APPLE_RTKIT
3535
tristate "Apple RTKit co-processor IPC protocol"
36-
depends on MAILBOX
36+
depends on APPLE_MBOX
3737
depends on ARCH_APPLE || COMPILE_TEST
3838
default ARCH_APPLE
3939
help

drivers/soc/apple/rtkit-internal.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
#ifndef _APPLE_RTKIT_INTERAL_H
88
#define _APPLE_RTKIT_INTERAL_H
99

10-
#include <linux/apple-mailbox.h>
1110
#include <linux/bitfield.h>
1211
#include <linux/bitmap.h>
1312
#include <linux/completion.h>
1413
#include <linux/dma-mapping.h>
1514
#include <linux/io.h>
1615
#include <linux/kernel.h>
17-
#include <linux/mailbox_client.h>
1816
#include <linux/module.h>
1917
#include <linux/slab.h>
2018
#include <linux/soc/apple/rtkit.h>
2119
#include <linux/workqueue.h>
20+
#include "mailbox.h"
2221

2322
#define APPLE_RTKIT_APP_ENDPOINT_START 0x20
2423
#define APPLE_RTKIT_MAX_ENDPOINTS 0x100
@@ -28,10 +27,7 @@ struct apple_rtkit {
2827
const struct apple_rtkit_ops *ops;
2928
struct device *dev;
3029

31-
const char *mbox_name;
32-
int mbox_idx;
33-
struct mbox_client mbox_cl;
34-
struct mbox_chan *mbox_chan;
30+
struct apple_mbox *mbox;
3531

3632
struct completion epmap_completion;
3733
struct completion iop_pwr_ack_completion;

drivers/soc/apple/rtkit.c

Lines changed: 28 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ enum {
7373
#define APPLE_RTKIT_MIN_SUPPORTED_VERSION 11
7474
#define APPLE_RTKIT_MAX_SUPPORTED_VERSION 12
7575

76-
struct apple_rtkit_msg {
77-
struct completion *completion;
78-
struct apple_mbox_msg mbox_msg;
79-
};
80-
8176
struct apple_rtkit_rx_work {
8277
struct apple_rtkit *rtk;
8378
u8 ep;
@@ -562,12 +557,12 @@ static void apple_rtkit_rx_work(struct work_struct *work)
562557
kfree(rtk_work);
563558
}
564559

565-
static void apple_rtkit_rx(struct mbox_client *cl, void *mssg)
560+
static void apple_rtkit_rx(struct apple_mbox *mbox, struct apple_mbox_msg msg,
561+
void *cookie)
566562
{
567-
struct apple_rtkit *rtk = container_of(cl, struct apple_rtkit, mbox_cl);
568-
struct apple_mbox_msg *msg = mssg;
563+
struct apple_rtkit *rtk = cookie;
569564
struct apple_rtkit_rx_work *work;
570-
u8 ep = msg->msg1;
565+
u8 ep = msg.msg1;
571566

572567
/*
573568
* The message was read from a MMIO FIFO and we have to make
@@ -583,7 +578,7 @@ static void apple_rtkit_rx(struct mbox_client *cl, void *mssg)
583578

584579
if (ep >= APPLE_RTKIT_APP_ENDPOINT_START &&
585580
rtk->ops->recv_message_early &&
586-
rtk->ops->recv_message_early(rtk->cookie, ep, msg->msg0))
581+
rtk->ops->recv_message_early(rtk->cookie, ep, msg.msg0))
587582
return;
588583

589584
work = kzalloc(sizeof(*work), GFP_ATOMIC);
@@ -592,30 +587,18 @@ static void apple_rtkit_rx(struct mbox_client *cl, void *mssg)
592587

593588
work->rtk = rtk;
594589
work->ep = ep;
595-
work->msg = msg->msg0;
590+
work->msg = msg.msg0;
596591
INIT_WORK(&work->work, apple_rtkit_rx_work);
597592
queue_work(rtk->wq, &work->work);
598593
}
599594

600-
static void apple_rtkit_tx_done(struct mbox_client *cl, void *mssg, int r)
601-
{
602-
struct apple_rtkit_msg *msg =
603-
container_of(mssg, struct apple_rtkit_msg, mbox_msg);
604-
605-
if (r == -ETIME)
606-
return;
607-
608-
if (msg->completion)
609-
complete(msg->completion);
610-
kfree(msg);
611-
}
612-
613595
int apple_rtkit_send_message(struct apple_rtkit *rtk, u8 ep, u64 message,
614596
struct completion *completion, bool atomic)
615597
{
616-
struct apple_rtkit_msg *msg;
617-
int ret;
618-
gfp_t flags;
598+
struct apple_mbox_msg msg = {
599+
.msg0 = message,
600+
.msg1 = ep,
601+
};
619602

620603
if (rtk->crashed) {
621604
dev_warn(rtk->dev,
@@ -630,33 +613,14 @@ int apple_rtkit_send_message(struct apple_rtkit *rtk, u8 ep, u64 message,
630613
return -EINVAL;
631614
}
632615

633-
if (atomic)
634-
flags = GFP_ATOMIC;
635-
else
636-
flags = GFP_KERNEL;
637-
638-
msg = kzalloc(sizeof(*msg), flags);
639-
if (!msg)
640-
return -ENOMEM;
641-
642-
msg->mbox_msg.msg0 = message;
643-
msg->mbox_msg.msg1 = ep;
644-
msg->completion = completion;
645-
646616
/*
647617
* The message will be sent with a MMIO write. We need the barrier
648618
* here to ensure any previous writes to buffers are visible to the
649619
* device before that MMIO write happens.
650620
*/
651621
dma_wmb();
652622

653-
ret = mbox_send_message(rtk->mbox_chan, &msg->mbox_msg);
654-
if (ret < 0) {
655-
kfree(msg);
656-
return ret;
657-
}
658-
659-
return 0;
623+
return apple_mbox_send(rtk->mbox, msg, atomic);
660624
}
661625
EXPORT_SYMBOL_GPL(apple_rtkit_send_message);
662626

@@ -694,7 +658,7 @@ EXPORT_SYMBOL_GPL(apple_rtkit_send_message_wait);
694658

695659
int apple_rtkit_poll(struct apple_rtkit *rtk)
696660
{
697-
return mbox_client_peek_data(rtk->mbox_chan);
661+
return apple_mbox_poll(rtk->mbox);
698662
}
699663
EXPORT_SYMBOL_GPL(apple_rtkit_poll);
700664

@@ -716,20 +680,6 @@ int apple_rtkit_start_ep(struct apple_rtkit *rtk, u8 endpoint)
716680
}
717681
EXPORT_SYMBOL_GPL(apple_rtkit_start_ep);
718682

719-
static int apple_rtkit_request_mbox_chan(struct apple_rtkit *rtk)
720-
{
721-
if (rtk->mbox_name)
722-
rtk->mbox_chan = mbox_request_channel_byname(&rtk->mbox_cl,
723-
rtk->mbox_name);
724-
else
725-
rtk->mbox_chan =
726-
mbox_request_channel(&rtk->mbox_cl, rtk->mbox_idx);
727-
728-
if (IS_ERR(rtk->mbox_chan))
729-
return PTR_ERR(rtk->mbox_chan);
730-
return 0;
731-
}
732-
733683
struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
734684
const char *mbox_name, int mbox_idx,
735685
const struct apple_rtkit_ops *ops)
@@ -755,13 +705,18 @@ struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
755705
bitmap_zero(rtk->endpoints, APPLE_RTKIT_MAX_ENDPOINTS);
756706
set_bit(APPLE_RTKIT_EP_MGMT, rtk->endpoints);
757707

758-
rtk->mbox_name = mbox_name;
759-
rtk->mbox_idx = mbox_idx;
760-
rtk->mbox_cl.dev = dev;
761-
rtk->mbox_cl.tx_block = false;
762-
rtk->mbox_cl.knows_txdone = false;
763-
rtk->mbox_cl.rx_callback = &apple_rtkit_rx;
764-
rtk->mbox_cl.tx_done = &apple_rtkit_tx_done;
708+
if (mbox_name)
709+
rtk->mbox = apple_mbox_get_byname(dev, mbox_name);
710+
else
711+
rtk->mbox = apple_mbox_get(dev, mbox_idx);
712+
713+
if (IS_ERR(rtk->mbox)) {
714+
ret = PTR_ERR(rtk->mbox);
715+
goto free_rtk;
716+
}
717+
718+
rtk->mbox->rx = apple_rtkit_rx;
719+
rtk->mbox->cookie = rtk;
765720

766721
rtk->wq = alloc_ordered_workqueue("rtkit-%s", WQ_MEM_RECLAIM,
767722
dev_name(rtk->dev));
@@ -770,7 +725,7 @@ struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
770725
goto free_rtk;
771726
}
772727

773-
ret = apple_rtkit_request_mbox_chan(rtk);
728+
ret = apple_mbox_start(rtk->mbox);
774729
if (ret)
775730
goto destroy_wq;
776731

@@ -801,7 +756,7 @@ static int apple_rtkit_wait_for_completion(struct completion *c)
801756
int apple_rtkit_reinit(struct apple_rtkit *rtk)
802757
{
803758
/* make sure we don't handle any messages while reinitializing */
804-
mbox_free_channel(rtk->mbox_chan);
759+
apple_mbox_stop(rtk->mbox);
805760
flush_workqueue(rtk->wq);
806761

807762
apple_rtkit_free_buffer(rtk, &rtk->ioreport_buffer);
@@ -825,7 +780,7 @@ int apple_rtkit_reinit(struct apple_rtkit *rtk)
825780
rtk->iop_power_state = APPLE_RTKIT_PWR_STATE_OFF;
826781
rtk->ap_power_state = APPLE_RTKIT_PWR_STATE_OFF;
827782

828-
return apple_rtkit_request_mbox_chan(rtk);
783+
return apple_mbox_start(rtk->mbox);
829784
}
830785
EXPORT_SYMBOL_GPL(apple_rtkit_reinit);
831786

@@ -988,7 +943,7 @@ EXPORT_SYMBOL_GPL(apple_rtkit_wake);
988943

989944
void apple_rtkit_free(struct apple_rtkit *rtk)
990945
{
991-
mbox_free_channel(rtk->mbox_chan);
946+
apple_mbox_stop(rtk->mbox);
992947
destroy_workqueue(rtk->wq);
993948

994949
apple_rtkit_free_buffer(rtk, &rtk->ioreport_buffer);

0 commit comments

Comments
 (0)