Skip to content

Commit 612cb28

Browse files
committed
soc: apple: rtkit: Implement OSLog buffers properly
Apparently nobody can figure out where the old logic came from, but it seems like it has never been actually used on any supported firmware to this day. OSLog buffers were apparently never requested. But starting with 13.3, we actually need this implemented properly for MTP (and later AOP) to work, so let's actually do that. Signed-off-by: Hector Martin <[email protected]>
1 parent c229f8f commit 612cb28

2 files changed

Lines changed: 31 additions & 20 deletions

File tree

drivers/soc/apple/rtkit-internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct apple_rtkit {
4444

4545
struct apple_rtkit_shmem ioreport_buffer;
4646
struct apple_rtkit_shmem crashlog_buffer;
47+
struct apple_rtkit_shmem oslog_buffer;
4748

4849
struct apple_rtkit_shmem syslog_buffer;
4950
char *syslog_msg_buffer;

drivers/soc/apple/rtkit.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ enum {
6767
#define APPLE_RTKIT_SYSLOG_MSG_SIZE GENMASK_ULL(31, 24)
6868

6969
#define APPLE_RTKIT_OSLOG_TYPE GENMASK_ULL(63, 56)
70-
#define APPLE_RTKIT_OSLOG_INIT 1
71-
#define APPLE_RTKIT_OSLOG_ACK 3
70+
#define APPLE_RTKIT_OSLOG_BUFFER_REQUEST 1
71+
#define APPLE_RTKIT_OSLOG_SIZE GENMASK_ULL(55, 48)
72+
#define APPLE_RTKIT_OSLOG_IOVA GENMASK_ULL(47, 0)
7273

7374
#define APPLE_RTKIT_MIN_SUPPORTED_VERSION 11
7475
#define APPLE_RTKIT_MAX_SUPPORTED_VERSION 12
@@ -260,10 +261,15 @@ static int apple_rtkit_common_rx_get_buffer(struct apple_rtkit *rtk,
260261
struct apple_rtkit_shmem *buffer,
261262
u8 ep, u64 msg)
262263
{
263-
size_t n_4kpages = FIELD_GET(APPLE_RTKIT_BUFFER_REQUEST_SIZE, msg);
264+
size_t n_4kpages;
264265
u64 reply;
265266
int err;
266267

268+
if (ep == APPLE_RTKIT_EP_OSLOG)
269+
n_4kpages = FIELD_GET(APPLE_RTKIT_OSLOG_SIZE, msg);
270+
else
271+
n_4kpages = FIELD_GET(APPLE_RTKIT_BUFFER_REQUEST_SIZE, msg);
272+
267273
buffer->buffer = NULL;
268274
buffer->iomem = NULL;
269275
buffer->is_mapped = false;
@@ -293,11 +299,20 @@ static int apple_rtkit_common_rx_get_buffer(struct apple_rtkit *rtk,
293299
}
294300

295301
if (!buffer->is_mapped) {
296-
reply = FIELD_PREP(APPLE_RTKIT_SYSLOG_TYPE,
297-
APPLE_RTKIT_BUFFER_REQUEST);
298-
reply |= FIELD_PREP(APPLE_RTKIT_BUFFER_REQUEST_SIZE, n_4kpages);
299-
reply |= FIELD_PREP(APPLE_RTKIT_BUFFER_REQUEST_IOVA,
300-
buffer->iova);
302+
/* oslog uses different fields */
303+
if (ep == APPLE_RTKIT_EP_OSLOG) {
304+
reply = FIELD_PREP(APPLE_RTKIT_OSLOG_TYPE,
305+
APPLE_RTKIT_OSLOG_BUFFER_REQUEST);
306+
reply |= FIELD_PREP(APPLE_RTKIT_OSLOG_SIZE, n_4kpages);
307+
reply |= FIELD_PREP(APPLE_RTKIT_OSLOG_IOVA,
308+
buffer->iova >> 12);
309+
} else {
310+
reply = FIELD_PREP(APPLE_RTKIT_SYSLOG_TYPE,
311+
APPLE_RTKIT_BUFFER_REQUEST);
312+
reply |= FIELD_PREP(APPLE_RTKIT_BUFFER_REQUEST_SIZE, n_4kpages);
313+
reply |= FIELD_PREP(APPLE_RTKIT_BUFFER_REQUEST_IOVA,
314+
buffer->iova);
315+
}
301316
apple_rtkit_send_message(rtk, ep, reply, NULL, false);
302317
}
303318

@@ -494,25 +509,18 @@ static void apple_rtkit_syslog_rx(struct apple_rtkit *rtk, u64 msg)
494509
}
495510
}
496511

497-
static void apple_rtkit_oslog_rx_init(struct apple_rtkit *rtk, u64 msg)
498-
{
499-
u64 ack;
500-
501-
dev_dbg(rtk->dev, "RTKit: oslog init: msg: 0x%llx\n", msg);
502-
ack = FIELD_PREP(APPLE_RTKIT_OSLOG_TYPE, APPLE_RTKIT_OSLOG_ACK);
503-
apple_rtkit_send_message(rtk, APPLE_RTKIT_EP_OSLOG, ack, NULL, false);
504-
}
505-
506512
static void apple_rtkit_oslog_rx(struct apple_rtkit *rtk, u64 msg)
507513
{
508514
u8 type = FIELD_GET(APPLE_RTKIT_OSLOG_TYPE, msg);
509515

510516
switch (type) {
511-
case APPLE_RTKIT_OSLOG_INIT:
512-
apple_rtkit_oslog_rx_init(rtk, msg);
517+
case APPLE_RTKIT_OSLOG_BUFFER_REQUEST:
518+
apple_rtkit_common_rx_get_buffer(rtk, &rtk->oslog_buffer,
519+
APPLE_RTKIT_EP_OSLOG, msg);
513520
break;
514521
default:
515-
dev_warn(rtk->dev, "RTKit: Unknown oslog message: %llx\n", msg);
522+
dev_warn(rtk->dev, "RTKit: Unknown oslog message: %llx\n",
523+
msg);
516524
}
517525
}
518526

@@ -761,6 +769,7 @@ int apple_rtkit_reinit(struct apple_rtkit *rtk)
761769

762770
apple_rtkit_free_buffer(rtk, &rtk->ioreport_buffer);
763771
apple_rtkit_free_buffer(rtk, &rtk->crashlog_buffer);
772+
apple_rtkit_free_buffer(rtk, &rtk->oslog_buffer);
764773
apple_rtkit_free_buffer(rtk, &rtk->syslog_buffer);
765774

766775
kfree(rtk->syslog_msg_buffer);
@@ -948,6 +957,7 @@ void apple_rtkit_free(struct apple_rtkit *rtk)
948957

949958
apple_rtkit_free_buffer(rtk, &rtk->ioreport_buffer);
950959
apple_rtkit_free_buffer(rtk, &rtk->crashlog_buffer);
960+
apple_rtkit_free_buffer(rtk, &rtk->oslog_buffer);
951961
apple_rtkit_free_buffer(rtk, &rtk->syslog_buffer);
952962

953963
kfree(rtk->syslog_msg_buffer);

0 commit comments

Comments
 (0)