From: Alyssa Rosenzweig <alyssa@rosenzweig.io>
To: sven@svenpeter.dev
Cc: Janne Grunau <j@jannau.net>,
asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Hector Martin <marcan@marcan.st>
Subject: Re: [PATCH v2 2/4] soc: apple: rtkit: Implement OSLog buffers properly
Date: Wed, 26 Feb 2025 14:07:14 -0500 [thread overview]
Message-ID: <Z79mYrxWDSpaRPyX@blossom> (raw)
In-Reply-To: <20250226-apple-soc-misc-v2-2-c3ec37f9021b@svenpeter.dev>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Le Wed , Feb 26, 2025 at 07:00:04PM +0000, Sven Peter via B4 Relay a écrit :
> From: Hector Martin <marcan@marcan.st>
>
> 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>
> Signed-off-by: Sven Peter <sven@svenpeter.dev>
> ---
> drivers/soc/apple/rtkit-internal.h | 1 +
> drivers/soc/apple/rtkit.c | 56 +++++++++++++++++++++++---------------
> 2 files changed, 35 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/soc/apple/rtkit-internal.h b/drivers/soc/apple/rtkit-internal.h
> index 27c9fa745fd5..b8d5244678f0 100644
> --- a/drivers/soc/apple/rtkit-internal.h
> +++ b/drivers/soc/apple/rtkit-internal.h
> @@ -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;
> diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c
> index be0d08861168..7e7b4f64ab17 100644
> --- a/drivers/soc/apple/rtkit.c
> +++ b/drivers/soc/apple/rtkit.c
> @@ -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, 36)
> +#define APPLE_RTKIT_OSLOG_IOVA GENMASK_ULL(35, 0)
>
> #define APPLE_RTKIT_MIN_SUPPORTED_VERSION 11
> #define APPLE_RTKIT_MAX_SUPPORTED_VERSION 12
> @@ -259,15 +260,21 @@ 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);
> u64 reply;
> int err;
>
> + /* The different size vs. IOVA shifts look odd but are indeed correct this way */
> + if (ep == APPLE_RTKIT_EP_OSLOG) {
> + buffer->size = FIELD_GET(APPLE_RTKIT_OSLOG_SIZE, msg);
> + buffer->iova = FIELD_GET(APPLE_RTKIT_OSLOG_IOVA, msg) << 12;
> + } else {
> + buffer->size = FIELD_GET(APPLE_RTKIT_BUFFER_REQUEST_SIZE, msg) << 12;
> + buffer->iova = FIELD_GET(APPLE_RTKIT_BUFFER_REQUEST_IOVA, msg);
> + }
> +
> buffer->buffer = NULL;
> buffer->iomem = NULL;
> buffer->is_mapped = false;
> - buffer->iova = FIELD_GET(APPLE_RTKIT_BUFFER_REQUEST_IOVA, msg);
> - buffer->size = n_4kpages << 12;
>
> dev_dbg(rtk->dev, "RTKit: buffer request for 0x%zx bytes at %pad\n",
> buffer->size, &buffer->iova);
> @@ -292,11 +299,21 @@ 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 and needs a shifted IOVA instead of size */
> + 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, buffer->size);
> + 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,
> + buffer->size >> 12);
> + reply |= FIELD_PREP(APPLE_RTKIT_BUFFER_REQUEST_IOVA,
> + buffer->iova);
> + }
> apple_rtkit_send_message(rtk, ep, reply, NULL, false);
> }
>
> @@ -494,25 +511,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);
> }
> }
>
> @@ -729,6 +739,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);
> @@ -916,6 +927,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);
>
> --
> 2.34.1
>
>
next prev parent reply other threads:[~2025-02-26 19:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-26 19:00 [PATCH v2 0/4] Miscellaneous Apple RTKit fixes Sven Peter via B4 Relay
2025-02-26 19:00 ` Sven Peter
2025-02-26 19:00 ` [PATCH v2 1/4] soc: apple: rtkit: Add and use PWR_STATE_INIT instead of _ON Sven Peter via B4 Relay
2025-02-26 19:00 ` Sven Peter
2025-02-26 19:06 ` Alyssa Rosenzweig
2025-02-26 19:00 ` [PATCH v2 2/4] soc: apple: rtkit: Implement OSLog buffers properly Sven Peter via B4 Relay
2025-02-26 19:00 ` Sven Peter
2025-02-26 19:07 ` Alyssa Rosenzweig [this message]
2025-02-26 19:00 ` [PATCH v2 3/4] soc: apple: rtkit: Use high prio work queue Sven Peter via B4 Relay
2025-02-26 19:00 ` Sven Peter
2025-02-26 19:00 ` [PATCH v2 4/4] soc: apple: rtkit: Cut syslog messages after the first '\0' Sven Peter via B4 Relay
2025-02-26 19:00 ` Sven Peter
2025-02-28 21:46 ` [PATCH v2 0/4] Miscellaneous Apple RTKit fixes Sven Peter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z79mYrxWDSpaRPyX@blossom \
--to=alyssa@rosenzweig.io \
--cc=asahi@lists.linux.dev \
--cc=j@jannau.net \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcan@marcan.st \
--cc=sven@svenpeter.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.