Skip to content

Commit 2cbd924

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

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;
@@ -550,12 +545,12 @@ static void apple_rtkit_rx_work(struct work_struct *work)
550545
kfree(rtk_work);
551546
}
552547

553-
static void apple_rtkit_rx(struct mbox_client *cl, void *mssg)
548+
static void apple_rtkit_rx(struct apple_mbox *mbox, struct apple_mbox_msg msg,
549+
void *cookie)
554550
{
555-
struct apple_rtkit *rtk = container_of(cl, struct apple_rtkit, mbox_cl);
556-
struct apple_mbox_msg *msg = mssg;
551+
struct apple_rtkit *rtk = cookie;
557552
struct apple_rtkit_rx_work *work;
558-
u8 ep = msg->msg1;
553+
u8 ep = msg.msg1;
559554

560555
/*
561556
* The message was read from a MMIO FIFO and we have to make
@@ -571,7 +566,7 @@ static void apple_rtkit_rx(struct mbox_client *cl, void *mssg)
571566

572567
if (ep >= APPLE_RTKIT_APP_ENDPOINT_START &&
573568
rtk->ops->recv_message_early &&
574-
rtk->ops->recv_message_early(rtk->cookie, ep, msg->msg0))
569+
rtk->ops->recv_message_early(rtk->cookie, ep, msg.msg0))
575570
return;
576571

577572
work = kzalloc(sizeof(*work), GFP_ATOMIC);
@@ -580,30 +575,18 @@ static void apple_rtkit_rx(struct mbox_client *cl, void *mssg)
580575

581576
work->rtk = rtk;
582577
work->ep = ep;
583-
work->msg = msg->msg0;
578+
work->msg = msg.msg0;
584579
INIT_WORK(&work->work, apple_rtkit_rx_work);
585580
queue_work(rtk->wq, &work->work);
586581
}
587582

588-
static void apple_rtkit_tx_done(struct mbox_client *cl, void *mssg, int r)
589-
{
590-
struct apple_rtkit_msg *msg =
591-
container_of(mssg, struct apple_rtkit_msg, mbox_msg);
592-
593-
if (r == -ETIME)
594-
return;
595-
596-
if (msg->completion)
597-
complete(msg->completion);
598-
kfree(msg);
599-
}
600-
601583
int apple_rtkit_send_message(struct apple_rtkit *rtk, u8 ep, u64 message,
602584
struct completion *completion, bool atomic)
603585
{
604-
struct apple_rtkit_msg *msg;
605-
int ret;
606-
gfp_t flags;
586+
struct apple_mbox_msg msg = {
587+
.msg0 = message,
588+
.msg1 = ep,
589+
};
607590

608591
if (rtk->crashed) {
609592
dev_warn(rtk->dev,
@@ -618,33 +601,14 @@ int apple_rtkit_send_message(struct apple_rtkit *rtk, u8 ep, u64 message,
618601
return -EINVAL;
619602
}
620603

621-
if (atomic)
622-
flags = GFP_ATOMIC;
623-
else
624-
flags = GFP_KERNEL;
625-
626-
msg = kzalloc(sizeof(*msg), flags);
627-
if (!msg)
628-
return -ENOMEM;
629-
630-
msg->mbox_msg.msg0 = message;
631-
msg->mbox_msg.msg1 = ep;
632-
msg->completion = completion;
633-
634604
/*
635605
* The message will be sent with a MMIO write. We need the barrier
636606
* here to ensure any previous writes to buffers are visible to the
637607
* device before that MMIO write happens.
638608
*/
639609
dma_wmb();
640610

641-
ret = mbox_send_message(rtk->mbox_chan, &msg->mbox_msg);
642-
if (ret < 0) {
643-
kfree(msg);
644-
return ret;
645-
}
646-
647-
return 0;
611+
return apple_mbox_send(rtk->mbox, msg, atomic);
648612
}
649613
EXPORT_SYMBOL_GPL(apple_rtkit_send_message);
650614

@@ -682,7 +646,7 @@ EXPORT_SYMBOL_GPL(apple_rtkit_send_message_wait);
682646

683647
int apple_rtkit_poll(struct apple_rtkit *rtk)
684648
{
685-
return mbox_client_peek_data(rtk->mbox_chan);
649+
return apple_mbox_poll(rtk->mbox);
686650
}
687651
EXPORT_SYMBOL_GPL(apple_rtkit_poll);
688652

@@ -704,20 +668,6 @@ int apple_rtkit_start_ep(struct apple_rtkit *rtk, u8 endpoint)
704668
}
705669
EXPORT_SYMBOL_GPL(apple_rtkit_start_ep);
706670

707-
static int apple_rtkit_request_mbox_chan(struct apple_rtkit *rtk)
708-
{
709-
if (rtk->mbox_name)
710-
rtk->mbox_chan = mbox_request_channel_byname(&rtk->mbox_cl,
711-
rtk->mbox_name);
712-
else
713-
rtk->mbox_chan =
714-
mbox_request_channel(&rtk->mbox_cl, rtk->mbox_idx);
715-
716-
if (IS_ERR(rtk->mbox_chan))
717-
return PTR_ERR(rtk->mbox_chan);
718-
return 0;
719-
}
720-
721671
struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
722672
const char *mbox_name, int mbox_idx,
723673
const struct apple_rtkit_ops *ops)
@@ -743,13 +693,18 @@ struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
743693
bitmap_zero(rtk->endpoints, APPLE_RTKIT_MAX_ENDPOINTS);
744694
set_bit(APPLE_RTKIT_EP_MGMT, rtk->endpoints);
745695

746-
rtk->mbox_name = mbox_name;
747-
rtk->mbox_idx = mbox_idx;
748-
rtk->mbox_cl.dev = dev;
749-
rtk->mbox_cl.tx_block = false;
750-
rtk->mbox_cl.knows_txdone = false;
751-
rtk->mbox_cl.rx_callback = &apple_rtkit_rx;
752-
rtk->mbox_cl.tx_done = &apple_rtkit_tx_done;
696+
if (mbox_name)
697+
rtk->mbox = apple_mbox_get_byname(dev, mbox_name);
698+
else
699+
rtk->mbox = apple_mbox_get(dev, mbox_idx);
700+
701+
if (IS_ERR(rtk->mbox)) {
702+
ret = PTR_ERR(rtk->mbox);
703+
goto free_rtk;
704+
}
705+
706+
rtk->mbox->rx = apple_rtkit_rx;
707+
rtk->mbox->cookie = rtk;
753708

754709
rtk->wq = alloc_ordered_workqueue("rtkit-%s", WQ_MEM_RECLAIM,
755710
dev_name(rtk->dev));
@@ -758,7 +713,7 @@ struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie,
758713
goto free_rtk;
759714
}
760715

761-
ret = apple_rtkit_request_mbox_chan(rtk);
716+
ret = apple_mbox_start(rtk->mbox);
762717
if (ret)
763718
goto destroy_wq;
764719

@@ -789,7 +744,7 @@ static int apple_rtkit_wait_for_completion(struct completion *c)
789744
int apple_rtkit_reinit(struct apple_rtkit *rtk)
790745
{
791746
/* make sure we don't handle any messages while reinitializing */
792-
mbox_free_channel(rtk->mbox_chan);
747+
apple_mbox_stop(rtk->mbox);
793748
flush_workqueue(rtk->wq);
794749

795750
apple_rtkit_free_buffer(rtk, &rtk->ioreport_buffer);
@@ -813,7 +768,7 @@ int apple_rtkit_reinit(struct apple_rtkit *rtk)
813768
rtk->iop_power_state = APPLE_RTKIT_PWR_STATE_OFF;
814769
rtk->ap_power_state = APPLE_RTKIT_PWR_STATE_OFF;
815770

816-
return apple_rtkit_request_mbox_chan(rtk);
771+
return apple_mbox_start(rtk->mbox);
817772
}
818773
EXPORT_SYMBOL_GPL(apple_rtkit_reinit);
819774

@@ -976,7 +931,7 @@ EXPORT_SYMBOL_GPL(apple_rtkit_wake);
976931

977932
void apple_rtkit_free(struct apple_rtkit *rtk)
978933
{
979-
mbox_free_channel(rtk->mbox_chan);
934+
apple_mbox_stop(rtk->mbox);
980935
destroy_workqueue(rtk->wq);
981936

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

0 commit comments

Comments
 (0)