From b65c7d1edc1f26666251c8eff411ad7ff7c2dd6d Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sun, 3 Sep 2023 15:17:22 +0200 Subject: [PATCH] rtkit: Support usage with SRAM Will be used by SMC. Signed-off-by: Janne Grunau --- src/dcp.c | 2 +- src/nvme.c | 4 ++-- src/rtkit.c | 20 ++++++++++++++++++-- src/rtkit.h | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/dcp.c b/src/dcp.c index 75671680..d58fdbb5 100644 --- a/src/dcp.c +++ b/src/dcp.c @@ -49,7 +49,7 @@ dcp_dev_t *dcp_init(const char *dcp_path, const char *dcp_dart_path, const char goto out_iovad; } - dcp->rtkit = rtkit_init("dcp", dcp->asc, dcp->dart_dcp, dcp->iovad_dcp, NULL); + dcp->rtkit = rtkit_init("dcp", dcp->asc, dcp->dart_dcp, dcp->iovad_dcp, NULL, false); if (!dcp->rtkit) { printf("dcp: failed to initialize RTKit\n"); goto out_iovad; diff --git a/src/nvme.c b/src/nvme.c index e40df4db..30634cda 100644 --- a/src/nvme.c +++ b/src/nvme.c @@ -335,7 +335,7 @@ bool nvme_init(void) if (!nvme_sart) goto out_asc; - nvme_rtkit = rtkit_init("nvme", nvme_asc, NULL, NULL, nvme_sart); + nvme_rtkit = rtkit_init("nvme", nvme_asc, NULL, NULL, nvme_sart, false); if (!nvme_rtkit) goto out_sart; @@ -446,7 +446,7 @@ void nvme_ensure_shutdown(void) if (!nvme_sart) goto fail; - nvme_rtkit = rtkit_init("nvme", nvme_asc, NULL, NULL, nvme_sart); + nvme_rtkit = rtkit_init("nvme", nvme_asc, NULL, NULL, nvme_sart, false); if (!nvme_rtkit) goto fail; diff --git a/src/rtkit.c b/src/rtkit.c index 5528cebf..b31ec60b 100644 --- a/src/rtkit.c +++ b/src/rtkit.c @@ -87,6 +87,7 @@ struct rtkit_dev { dart_dev_t *dart; iova_domain_t *dart_iovad; sart_dev_t *sart; + bool sram; u64 dva_base; @@ -126,7 +127,7 @@ struct crashlog_entry { }; rtkit_dev_t *rtkit_init(const char *name, asc_dev_t *asc, dart_dev_t *dart, - iova_domain_t *dart_iovad, sart_dev_t *sart) + iova_domain_t *dart_iovad, sart_dev_t *sart, bool sram) { if (dart && sart) { printf("rtkit: Cannot use both SART and DART simultaneously\n"); @@ -138,6 +139,11 @@ rtkit_dev_t *rtkit_init(const char *name, asc_dev_t *asc, dart_dev_t *dart, return NULL; } + if (sram && (dart || sart)) { + printf("rtkit: cannot use SRAM with DART or SART \n"); + return NULL; + } + rtkit_dev_t *rtk = malloc(sizeof(*rtk)); if (!rtk) return NULL; @@ -153,6 +159,7 @@ rtkit_dev_t *rtkit_init(const char *name, asc_dev_t *asc, dart_dev_t *dart, rtk->dart = dart; rtk->dart_iovad = dart_iovad; rtk->sart = sart; + rtk->sram = sram; rtk->iop_power = RTKIT_POWER_OFF; rtk->ap_power = RTKIT_POWER_OFF; rtk->dva_base = 0; @@ -277,7 +284,16 @@ static bool rtkit_handle_buffer_request(rtkit_dev_t *rtk, struct rtkit_message * size_t sz = n_4kpages << 12; u64 addr = FIELD_GET(MSG_BUFFER_REQUEST_IOVA, msg->msg); - if (addr) { + if (rtk->sram) { + if (!addr) { + rtkit_printf("SRAM buffers needs to be provided by the IOP\n"); + return false; + } + bfr->dva = addr; + bfr->bfr = (void *)addr; + bfr->sz = sz; + return true; + } else if (addr) { bfr->dva = addr & ~rtk->dva_base; bfr->sz = sz; bfr->bfr = dart_translate(rtk->dart, bfr->dva & IOVA_MASK); diff --git a/src/rtkit.h b/src/rtkit.h index dcefcd9c..8461875c 100644 --- a/src/rtkit.h +++ b/src/rtkit.h @@ -23,7 +23,7 @@ struct rtkit_buffer { }; rtkit_dev_t *rtkit_init(const char *name, asc_dev_t *asc, dart_dev_t *dart, - iova_domain_t *dart_iovad, sart_dev_t *sart); + iova_domain_t *dart_iovad, sart_dev_t *sart, bool sram); bool rtkit_quiesce(rtkit_dev_t *rtk); bool rtkit_sleep(rtkit_dev_t *rtk); void rtkit_free(rtkit_dev_t *rtk);