From patchwork Fri Feb 1 13:28:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 1034767 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eEN8Md1l"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43rdGy6M5hz9sDX for ; Sat, 2 Feb 2019 00:28:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727907AbfBAN26 (ORCPT ); Fri, 1 Feb 2019 08:28:58 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34189 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727823AbfBAN26 (ORCPT ); Fri, 1 Feb 2019 08:28:58 -0500 Received: by mail-wr1-f68.google.com with SMTP id f7so7167763wrp.1 for ; Fri, 01 Feb 2019 05:28:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tvRwEnb1658BXmg0d7HebC9K6VaTA9OBNz8ovsbsOJU=; b=eEN8Md1lDNyXJggftkrBN2CfATb2s8uKsy4As55FqHLmxvKlUlrDmCms3eK+4InGHq +8OfDOJcRSVaMV7MtVTWuFNpjTBrddiia4CnjsX/PJapHfrXTv7CwJKwZT1qFOKm45/w Hi3bL3zoaUsdjOLEBBXWWco3hfFJU4FzBXCP93SyRXm42c+r0zotsO1SPSNzEmyLIGpk QWvZQ+sVNght9BrZsIf0Vw15Vte8C9tVWZzT/av8ZUxkZt5WHBPTOiQ7x4M9ChUOWZEk u5jxmSnoDEqU8dy/3YA1pUNndtxutH7z9CnbYa6qohMtJPuNLAZkvWChD2IOO9MQqmSG LSdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tvRwEnb1658BXmg0d7HebC9K6VaTA9OBNz8ovsbsOJU=; b=tZ1N7hZ1ayNX/nnZwIJw2Sgikgh1SNhlcTTFKnmkTRW+As/rbnWsgWWqMsVuYpwV1f inboWiNQnwdhBwCaxPAngpXUahXDEEhNTEB0+TnwrU2FNbtPVLBM/KrZrDDbIYqFyJM6 x6ckHGyQwTdqF9LvA5UabWu3D+6jqV2HAA7/rrQF1sNNzFs8yzHfzrPtvHY8VHcgDoqu YwWybEcCUBuXIp4vAPH2uT2B+QOSXc7weJ0LR2Pdt7y9a7U/h7nfH86E7nx5SB3dr3oU Ui+o2A4MmexLiuhY6NBiEkmioyXHm1VlMZW+FAGhNZCP/pu27cxcZrLHmpbE9cL82/IG 53Jg== X-Gm-Message-State: AJcUukcLIaNb91z/xZA9Y77sKAMJmriCfvgPV4w+tKzYe7xLNNX4ooYF yJ3MhRtawh1Ff6tZLeciZjcE2XGZsh8= X-Google-Smtp-Source: ALg8bN4Q36wGRdKbLoCsTtcIlX9bZXnQbyY2jKMX7Br077QRpVcoCdyBVhwo6rDGZhUvQ0N+qUNWHQ== X-Received: by 2002:adf:97d1:: with SMTP id t17mr38843625wrb.283.1549027736376; Fri, 01 Feb 2019 05:28:56 -0800 (PST) Received: from localhost (pD9E51040.dip0.t-ipconnect.de. [217.229.16.64]) by smtp.gmail.com with ESMTPSA id o16sm13320602wrn.11.2019.02.01.05.28.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Feb 2019 05:28:55 -0800 (PST) From: Thierry Reding To: Thierry Reding Cc: Mikko Perttunen , Dmitry Osipenko , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH v3 11/16] drm/tegra: vic: Load firmware on demand Date: Fri, 1 Feb 2019 14:28:32 +0100 Message-Id: <20190201132837.12327-12-thierry.reding@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190201132837.12327-1-thierry.reding@gmail.com> References: <20190201132837.12327-1-thierry.reding@gmail.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Thierry Reding Loading the firmware requires an allocation of IOVA space to make sure that the VIC's Falcon microcontroller can read the firmware if address translation via the SMMU is enabled. However, the allocation currently happens at a time where the geometry of an IOMMU domain may not have been initialized yet. This happens for example on Tegra186 and later where an ARM SMMU is used. Domains which are created by the ARM SMMU driver postpone the geometry setup until a device is attached to the domain. This is because IOMMU domains aren't attached to a specific IOMMU instance at allocation time and hence the input address space, which defines the geometry, is not known yet. Work around this by postponing the firmware load until it is needed at the time where a channel is opened to the VIC. At this time the shared IOMMU domain's geometry has been properly initialized. As a byproduct this allows the Tegra DRM to be created in the absence of VIC firmware, since the VIC initialization no longer fails if the firmware can't be found. Based on an earlier patch by Dmitry Osipenko . Signed-off-by: Thierry Reding Reviewed-by: Dmitry Osipenko --- drivers/gpu/drm/tegra/vic.c | 53 +++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/tegra/vic.c b/drivers/gpu/drm/tegra/vic.c index d47983deb1cf..739b894661ab 100644 --- a/drivers/gpu/drm/tegra/vic.c +++ b/drivers/gpu/drm/tegra/vic.c @@ -181,13 +181,6 @@ static int vic_init(struct host1x_client *client) vic->domain = tegra->domain; } - if (!vic->falcon.data) { - vic->falcon.data = tegra; - err = falcon_load_firmware(&vic->falcon); - if (err < 0) - goto detach; - } - vic->channel = host1x_channel_request(client->dev); if (!vic->channel) { err = -ENOMEM; @@ -246,6 +239,30 @@ static const struct host1x_client_ops vic_client_ops = { .exit = vic_exit, }; +static int vic_load_firmware(struct vic *vic) +{ + int err; + + if (vic->falcon.data) + return 0; + + vic->falcon.data = vic->client.drm; + + err = falcon_read_firmware(&vic->falcon, vic->config->firmware); + if (err < 0) + goto cleanup; + + err = falcon_load_firmware(&vic->falcon); + if (err < 0) + goto cleanup; + + return 0; + +cleanup: + vic->falcon.data = NULL; + return err; +} + static int vic_open_channel(struct tegra_drm_client *client, struct tegra_drm_context *context) { @@ -256,19 +273,25 @@ static int vic_open_channel(struct tegra_drm_client *client, if (err < 0) return err; + err = vic_load_firmware(vic); + if (err < 0) + goto rpm_put; + err = vic_boot(vic); - if (err < 0) { - pm_runtime_put(vic->dev); - return err; - } + if (err < 0) + goto rpm_put; context->channel = host1x_channel_get(vic->channel); if (!context->channel) { - pm_runtime_put(vic->dev); - return -ENOMEM; + err = -ENOMEM; + goto rpm_put; } return 0; + +rpm_put: + pm_runtime_put(vic->dev); + return err; } static void vic_close_channel(struct tegra_drm_context *context) @@ -372,10 +395,6 @@ static int vic_probe(struct platform_device *pdev) if (err < 0) return err; - err = falcon_read_firmware(&vic->falcon, vic->config->firmware); - if (err < 0) - goto exit_falcon; - platform_set_drvdata(pdev, vic); INIT_LIST_HEAD(&vic->client.base.list);