Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp4020607pxm; Tue, 1 Mar 2022 09:37:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzILD4C52NY3ay6cZeD3tqCByASmGvr+XhUAH5yjubsBoHU9538DrVy3YS7DFCDdvwf/Z7+ X-Received: by 2002:a17:902:7d93:b0:14d:d401:f59b with SMTP id a19-20020a1709027d9300b0014dd401f59bmr27002539plm.14.1646156245952; Tue, 01 Mar 2022 09:37:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646156245; cv=none; d=google.com; s=arc-20160816; b=LjEuiB0Rhs+ot0etG66q4/ZiP2Px0xMqMMi2++ZChz523fjbaV+RKVYOo/z+uUpExP p40/4CgzJE7va4rsrDLU9bfaJYvFwIWDP2wYae8m1WPqtQTIN4/vnQ3Izwo43uyLOhNp mceDKH3cbjdGsKMqYP1vBTBuG5Cj7k72FRCulindNUfs10MT/xWbdYjo7v5YXpoH50ki xFHdFRZTVcTHzzvExHSk7vExnnu5knC4pAvNxJHLP1Qf9yCACwuZCvjM4rbXv+E0D/B6 r+nZp3psLNyPhjYookdEBamflJPgj2JV+PndaTv+8Rw6vpyq9jwsKgkLo2eSp0HQmQhg VdZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6TpezAeFb9g9AHiww5bc22k1x+PyMf+mQ2/IdP7xRCs=; b=kkiZLd4fWWHeA33HTtCtd6wroApvLN4yE68YGCFwPllCPiNfabCOsU7Ds+zwhAQLBI +CZl2JiipcBlAQuQuUhnakzXWlBGxz7QO0HRFvuP5D2HMIp61wHi8TNI8YuZg29tXqJq II/kSut/KshEr5eWqi4WJEINQBtsbnKGsGEhVg+vkJgZiqXVCX4RO1MyuUhMF1PLsOjk 253tM97w///2Ji/y3urGhHQeHk9NzEMUkk2AtPS/XKbx9k4bUukkgKqRuDUIqUUyOCq/ /QFKa7342Aryfzseqby+1ZGD1Go5SWvOnrMQX0SsXqPd0wFLlR/M32qemYQsZyESb/2C wrkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=S29TLmBd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020a656a84000000b00378badd9c1dsi6110690pgu.121.2022.03.01.09.37.08; Tue, 01 Mar 2022 09:37:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=S29TLmBd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236109AbiCAQQ3 (ORCPT + 99 others); Tue, 1 Mar 2022 11:16:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230335AbiCAQQS (ORCPT ); Tue, 1 Mar 2022 11:16:18 -0500 Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 282D990CEF; Tue, 1 Mar 2022 08:15:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=6TpezAeFb9g9AHiww5bc22k1x+PyMf+mQ2/IdP7xRCs=; b=S29TLmBdJzh5hHidtdj1FNr9ar GDU7/g3f17LE/bFVTb9oIOHaOG0fWmX8gQKZLbZyo/WvfVlW+woMrIphRpTpT5Kh76GzfiRbiuDLi d1Z46CYkAwPGocfnSsCbZgI02xeJjcjsFChtSD4HxlZS9qQ1Bm8goYXtIRaQMKm1ihZWCSxMYVWmG eqiqMhry612GITThisyjeSiq3puDcE09ICV4sEJzyDR4hIuNyIHQDMu2huwww9XIRySznfXRThco7 jLzP+uyfgb5RDYpSU/VzwwEya5GXjBeDPZB7l8Tgs1NRhR6ixDksruSpm9Gv25V2PTJf0GkVwGFIs Z0rMmVQA==; Received: from 91-158-25-70.elisa-laajakaista.fi ([91.158.25.70] helo=toshino.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1nP59r-0003Z8-8n; Tue, 01 Mar 2022 18:15:27 +0200 From: cyndis@kapsi.fi To: thierry.reding@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, robh+dt@kernel.org, krzysztof.kozlowski@canonical.com Cc: linux-tegra@vger.kernel.org, dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mikko Perttunen Subject: [PATCH v4 8/9] drm/tegra: Support context isolation Date: Tue, 1 Mar 2022 18:14:54 +0200 Message-Id: <20220301161455.4037062-9-cyndis@kapsi.fi> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220301161455.4037062-1-cyndis@kapsi.fi> References: <20220301161455.4037062-1-cyndis@kapsi.fi> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 91.158.25.70 X-SA-Exim-Mail-From: cyndis@kapsi.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikko Perttunen For engines that support context isolation, allocate a context when opening a channel, and set up stream ID offset and context fields when submitting a job. Signed-off-by: Mikko Perttunen --- v4: * Separate error and output values in get_streamid_offset API * Improve error handling * Rename job->context to job->memory_context for clarity --- drivers/gpu/drm/tegra/drm.h | 2 ++ drivers/gpu/drm/tegra/submit.c | 21 +++++++++++++++- drivers/gpu/drm/tegra/uapi.c | 45 ++++++++++++++++++++++++++++++++-- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/tegra/drm.h b/drivers/gpu/drm/tegra/drm.h index fc0a19554eac..608daba01587 100644 --- a/drivers/gpu/drm/tegra/drm.h +++ b/drivers/gpu/drm/tegra/drm.h @@ -80,6 +80,7 @@ struct tegra_drm_context { /* Only used by new UAPI. */ struct xarray mappings; + struct host1x_context *memory_context; }; struct tegra_drm_client_ops { @@ -91,6 +92,7 @@ struct tegra_drm_client_ops { int (*submit)(struct tegra_drm_context *context, struct drm_tegra_submit *args, struct drm_device *drm, struct drm_file *file); + int (*get_streamid_offset)(struct tegra_drm_client *client, u32 *offset); }; int tegra_drm_submit(struct tegra_drm_context *context, diff --git a/drivers/gpu/drm/tegra/submit.c b/drivers/gpu/drm/tegra/submit.c index 6d6dd8c35475..fd0ba09e552a 100644 --- a/drivers/gpu/drm/tegra/submit.c +++ b/drivers/gpu/drm/tegra/submit.c @@ -498,6 +498,9 @@ static void release_job(struct host1x_job *job) struct tegra_drm_submit_data *job_data = job->user_data; u32 i; + if (job->memory_context) + host1x_context_put(job->memory_context); + for (i = 0; i < job_data->num_used_mappings; i++) tegra_drm_mapping_put(job_data->used_mappings[i].mapping); @@ -588,11 +591,24 @@ int tegra_drm_ioctl_channel_submit(struct drm_device *drm, void *data, goto put_job; } + if (context->memory_context && context->client->ops->get_streamid_offset) { + int offset; + + err = context->client->ops->get_streamid_offset(context->client, &offset); + if (!err) { + job->memory_context = context->memory_context; + job->engine_streamid_offset = offset; + host1x_context_get(job->memory_context); + } else if (err != -EOPNOTSUPP) { + goto unpin_job; + } + } + /* Boot engine. */ err = pm_runtime_resume_and_get(context->client->base.dev); if (err < 0) { SUBMIT_ERR(context, "could not power up engine: %d", err); - goto unpin_job; + goto put_memory_context; } job->user_data = job_data; @@ -627,6 +643,9 @@ int tegra_drm_ioctl_channel_submit(struct drm_device *drm, void *data, goto put_job; +put_memory_context: + if (job->memory_context) + host1x_context_put(job->memory_context); unpin_job: host1x_job_unpin(job); put_job: diff --git a/drivers/gpu/drm/tegra/uapi.c b/drivers/gpu/drm/tegra/uapi.c index 9ab9179d2026..475febb6d86b 100644 --- a/drivers/gpu/drm/tegra/uapi.c +++ b/drivers/gpu/drm/tegra/uapi.c @@ -33,6 +33,9 @@ static void tegra_drm_channel_context_close(struct tegra_drm_context *context) struct tegra_drm_mapping *mapping; unsigned long id; + if (context->memory_context) + host1x_context_put(context->memory_context); + xa_for_each(&context->mappings, id, mapping) tegra_drm_mapping_put(mapping); @@ -72,6 +75,7 @@ static struct tegra_drm_client *tegra_drm_find_client(struct tegra_drm *tegra, u int tegra_drm_ioctl_channel_open(struct drm_device *drm, void *data, struct drm_file *file) { + struct host1x *host = tegra_drm_to_host1x(drm->dev_private); struct tegra_drm_file *fpriv = file->driver_priv; struct tegra_drm *tegra = drm->dev_private; struct drm_tegra_channel_open *args = data; @@ -102,10 +106,38 @@ int tegra_drm_ioctl_channel_open(struct drm_device *drm, void *data, struct drm_ } } + /* Only allocate context if the engine supports context isolation. */ + if (client->ops->get_streamid_offset) { + u32 offset; + + err = client->ops->get_streamid_offset(client, &offset); + if (!err) { + context->memory_context = + host1x_context_alloc(host, get_task_pid(current, PIDTYPE_TGID)); + } else if (err == -EOPNOTSUPP) { + context->memory_context = NULL; + } else { + goto put_channel; + } + + if (IS_ERR(context->memory_context)) { + if (PTR_ERR(context->memory_context) != -EOPNOTSUPP) { + err = PTR_ERR(context->memory_context); + goto put_channel; + } else { + /* + * OK, HW does not support contexts or contexts + * are disabled. + */ + context->memory_context = NULL; + } + } + } + err = xa_alloc(&fpriv->contexts, &args->context, context, XA_LIMIT(1, U32_MAX), GFP_KERNEL); if (err < 0) - goto put_channel; + goto put_memctx; context->client = client; xa_init_flags(&context->mappings, XA_FLAGS_ALLOC1); @@ -118,6 +150,9 @@ int tegra_drm_ioctl_channel_open(struct drm_device *drm, void *data, struct drm_ return 0; +put_memctx: + if (context->memory_context) + host1x_context_put(context->memory_context); put_channel: host1x_channel_put(context->channel); free: @@ -156,6 +191,7 @@ int tegra_drm_ioctl_channel_map(struct drm_device *drm, void *data, struct drm_f struct tegra_drm_mapping *mapping; struct tegra_drm_context *context; enum dma_data_direction direction; + struct device *mapping_dev; int err = 0; if (args->flags & ~DRM_TEGRA_CHANNEL_MAP_READ_WRITE) @@ -177,6 +213,11 @@ int tegra_drm_ioctl_channel_map(struct drm_device *drm, void *data, struct drm_f kref_init(&mapping->ref); + if (context->memory_context) + mapping_dev = &context->memory_context->dev; + else + mapping_dev = context->client->base.dev; + mapping->bo = tegra_gem_lookup(file, args->handle); if (!mapping->bo) { err = -EINVAL; @@ -201,7 +242,7 @@ int tegra_drm_ioctl_channel_map(struct drm_device *drm, void *data, struct drm_f goto put_gem; } - mapping->map = host1x_bo_pin(context->client->base.dev, mapping->bo, direction, NULL); + mapping->map = host1x_bo_pin(mapping_dev, mapping->bo, direction, NULL); if (IS_ERR(mapping->map)) { err = PTR_ERR(mapping->map); goto put_gem; -- 2.35.0