Skip to content

Commit

Permalink
soc: apple: rtkit: Implement OSLog buffers properly
Browse files Browse the repository at this point in the history
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 <marcan@marcan.st>
  • Loading branch information
marcan committed Apr 16, 2023
1 parent af31cf4 commit ea40aa1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions drivers/soc/apple/rtkit-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct apple_rtkit {

struct apple_rtkit_shmem ioreport_buffer;
struct apple_rtkit_shmem crashlog_buffer;
struct apple_rtkit_shmem oslog_buffer;

struct apple_rtkit_shmem syslog_buffer;
char *syslog_msg_buffer;
Expand Down
50 changes: 30 additions & 20 deletions drivers/soc/apple/rtkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ enum {
#define APPLE_RTKIT_SYSLOG_MSG_SIZE GENMASK_ULL(31, 24)

#define APPLE_RTKIT_OSLOG_TYPE GENMASK_ULL(63, 56)
#define APPLE_RTKIT_OSLOG_INIT 1
#define APPLE_RTKIT_OSLOG_ACK 3
#define APPLE_RTKIT_OSLOG_BUFFER_REQUEST 1
#define APPLE_RTKIT_OSLOG_SIZE GENMASK_ULL(55, 48)
#define APPLE_RTKIT_OSLOG_IOVA GENMASK_ULL(47, 0)

#define APPLE_RTKIT_MIN_SUPPORTED_VERSION 11
#define APPLE_RTKIT_MAX_SUPPORTED_VERSION 12
Expand Down Expand Up @@ -260,10 +261,15 @@ static int apple_rtkit_common_rx_get_buffer(struct apple_rtkit *rtk,
struct apple_rtkit_shmem *buffer,
u8 ep, u64 msg)
{
size_t n_4kpages = FIELD_GET(APPLE_RTKIT_BUFFER_REQUEST_SIZE, msg);
size_t n_4kpages;
u64 reply;
int err;

if (ep == APPLE_RTKIT_EP_OSLOG)
n_4kpages = FIELD_GET(APPLE_RTKIT_OSLOG_SIZE, msg);
else
n_4kpages = FIELD_GET(APPLE_RTKIT_BUFFER_REQUEST_SIZE, msg);

buffer->buffer = NULL;
buffer->iomem = NULL;
buffer->is_mapped = false;
Expand Down Expand Up @@ -293,11 +299,20 @@ static int apple_rtkit_common_rx_get_buffer(struct apple_rtkit *rtk,
}

if (!buffer->is_mapped) {
reply = FIELD_PREP(APPLE_RTKIT_SYSLOG_TYPE,
APPLE_RTKIT_BUFFER_REQUEST);
reply |= FIELD_PREP(APPLE_RTKIT_BUFFER_REQUEST_SIZE, n_4kpages);
reply |= FIELD_PREP(APPLE_RTKIT_BUFFER_REQUEST_IOVA,
buffer->iova);
/* oslog uses different fields */
if (ep == APPLE_RTKIT_EP_OSLOG) {
reply = FIELD_PREP(APPLE_RTKIT_OSLOG_TYPE,
APPLE_RTKIT_OSLOG_BUFFER_REQUEST);
reply |= FIELD_PREP(APPLE_RTKIT_OSLOG_SIZE, n_4kpages);
reply |= FIELD_PREP(APPLE_RTKIT_OSLOG_IOVA,
buffer->iova >> 12);
} else {
reply = FIELD_PREP(APPLE_RTKIT_SYSLOG_TYPE,
APPLE_RTKIT_BUFFER_REQUEST);
reply |= FIELD_PREP(APPLE_RTKIT_BUFFER_REQUEST_SIZE, n_4kpages);
reply |= FIELD_PREP(APPLE_RTKIT_BUFFER_REQUEST_IOVA,
buffer->iova);
}
apple_rtkit_send_message(rtk, ep, reply, NULL, false);
}

Expand Down Expand Up @@ -482,25 +497,18 @@ static void apple_rtkit_syslog_rx(struct apple_rtkit *rtk, u64 msg)
}
}

static void apple_rtkit_oslog_rx_init(struct apple_rtkit *rtk, u64 msg)
{
u64 ack;

dev_dbg(rtk->dev, "RTKit: oslog init: msg: 0x%llx\n", msg);
ack = FIELD_PREP(APPLE_RTKIT_OSLOG_TYPE, APPLE_RTKIT_OSLOG_ACK);
apple_rtkit_send_message(rtk, APPLE_RTKIT_EP_OSLOG, ack, NULL, false);
}

static void apple_rtkit_oslog_rx(struct apple_rtkit *rtk, u64 msg)
{
u8 type = FIELD_GET(APPLE_RTKIT_OSLOG_TYPE, msg);

switch (type) {
case APPLE_RTKIT_OSLOG_INIT:
apple_rtkit_oslog_rx_init(rtk, msg);
case APPLE_RTKIT_OSLOG_BUFFER_REQUEST:
apple_rtkit_common_rx_get_buffer(rtk, &rtk->oslog_buffer,
APPLE_RTKIT_EP_OSLOG, msg);
break;
default:
dev_warn(rtk->dev, "RTKit: Unknown oslog message: %llx\n", msg);
dev_warn(rtk->dev, "RTKit: Unknown oslog message: %llx\n",
msg);
}
}

Expand Down Expand Up @@ -717,6 +725,7 @@ int apple_rtkit_reinit(struct apple_rtkit *rtk)

apple_rtkit_free_buffer(rtk, &rtk->ioreport_buffer);
apple_rtkit_free_buffer(rtk, &rtk->crashlog_buffer);
apple_rtkit_free_buffer(rtk, &rtk->oslog_buffer);
apple_rtkit_free_buffer(rtk, &rtk->syslog_buffer);

kfree(rtk->syslog_msg_buffer);
Expand Down Expand Up @@ -904,6 +913,7 @@ void apple_rtkit_free(struct apple_rtkit *rtk)

apple_rtkit_free_buffer(rtk, &rtk->ioreport_buffer);
apple_rtkit_free_buffer(rtk, &rtk->crashlog_buffer);
apple_rtkit_free_buffer(rtk, &rtk->oslog_buffer);
apple_rtkit_free_buffer(rtk, &rtk->syslog_buffer);

kfree(rtk->syslog_msg_buffer);
Expand Down

0 comments on commit ea40aa1

Please sign in to comment.