From patchwork Sat May 26 14:27:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 10428979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7331260225 for ; Sat, 26 May 2018 14:29:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EAC42950A for ; Sat, 26 May 2018 14:29:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C9DC2950E; Sat, 26 May 2018 14:29:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B90262950A for ; Sat, 26 May 2018 14:29:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754954AbeEZO25 (ORCPT ); Sat, 26 May 2018 10:28:57 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:43193 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752095AbeEZO24 (ORCPT ); Sat, 26 May 2018 10:28:56 -0400 Received: by mail-wr0-f194.google.com with SMTP id r13-v6so13601876wrj.10; Sat, 26 May 2018 07:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rBGSqMvKzwm96y8fSxdbCK/7Fn2Byz9we2eK17fV4O0=; b=Su6poX+fVouqhDoLNnmYrmOJyFGbzvkrQQ7Sg8Pt1spAzuXEFSnygFRJ7GAijpzw3n 1Iphue136y/N7N16iCbZjPfwOtU41ZDkBI/G8E9pyUZHk+kCF2J4UfWSq4yk632tjK/t tq7iYwg1bMu4F8are7IBS+I0EXlpSSCpXQcvF7z5xw7xX5ws+IFl4Ay8pUoEjOTXT0el Fa5meyKY1Bm4bcIxfhEaZBh1Z8Go+2R5lxTuun99Yob78zrFlPzYAgP/tj62EIyBGMaY 1M1QGthrShnRimCgUEi0YDOaspwmQ/vvmImIdQfW7JtNlfdhdcfaU4HYknajWSljpULI KiBQ== 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; bh=rBGSqMvKzwm96y8fSxdbCK/7Fn2Byz9we2eK17fV4O0=; b=Q/hXq1qjDjIadrGHh9bCjiRc0HI+bmJ8U75RShNNEW8puht645LkAYX5DAZzIA9CJE RFOpMSf+KrYl7DZlNTkBk3Qr+B0ltw791+67ciVELXqBM+Wgdc817pDh6CYjoNrNRltg EYlC9FjKkD7tBy24nbNtiAH9/X4Y7zQ/4WO4o3smVZaJ27BuOqBW4xu8jxkvs/UvwByJ 6THAj9I+lJIWC+30/oWVuehuSubkh0BkRDcBkLsTaGtw4lx0Z9j6u09uTxXCIL4GvFJs iS7/801x+h2jzHMIHZ0E8QlD+CG4NNaN7pMcZxiD0sNL/tb8eq7C1zirqknbsRbtn+jD EPvA== X-Gm-Message-State: ALKqPwfHP5P/7+5W+yTbBE86Aog9qENKWdsam/czmkId/wLzQTK3zl23 Qjn6LGYky2f7JmQJJQbse7vsEWeQ X-Google-Smtp-Source: AB8JxZqF+OhLlxj5c+NygbI/APOtirvXgBnjH8wcwl+WH+vUgI5GTUU1m0RJpdeu2+r0BNs9etgt1Q== X-Received: by 2002:adf:c32b:: with SMTP id n40-v6mr5797369wrf.91.1527344935053; Sat, 26 May 2018 07:28:55 -0700 (PDT) Received: from localhost.localdomain (109-252-91-41.nat.spd-mgts.ru. [109.252.91.41]) by smtp.gmail.com with ESMTPSA id g28-v6sm9278263wmc.38.2018.05.26.07.28.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 May 2018 07:28:54 -0700 (PDT) From: Dmitry Osipenko To: Hans Verkuil , Mauro Carvalho Chehab , Thierry Reding Cc: linux-tegra@vger.kernel.org, linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] media: staging: tegra-vde: Reset memory client Date: Sat, 26 May 2018 17:27:55 +0300 Message-Id: <20180526142755.22966-1-digetx@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP DMA requests must be blocked before resetting VDE HW, otherwise it is possible to get a memory corruption or a machine hang. Use the reset control provided by the Memory Controller to block DMA before resetting the VDE HW. Signed-off-by: Dmitry Osipenko --- Changelog: v2: - Reset HW even if Memory Client resetting fails. drivers/staging/media/tegra-vde/tegra-vde.c | 35 +++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/tegra-vde/tegra-vde.c b/drivers/staging/media/tegra-vde/tegra-vde.c index 90177a59b97c..6f06061a40d9 100644 --- a/drivers/staging/media/tegra-vde/tegra-vde.c +++ b/drivers/staging/media/tegra-vde/tegra-vde.c @@ -73,6 +73,7 @@ struct tegra_vde { struct mutex lock; struct miscdevice miscdev; struct reset_control *rst; + struct reset_control *rst_mc; struct gen_pool *iram_pool; struct completion decode_completion; struct clk *clk; @@ -850,9 +851,23 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, * We rely on the VDE registers reset value, otherwise VDE * causes bus lockup. */ + ret = reset_control_assert(vde->rst_mc); + if (ret) { + dev_err(dev, "DEC start: Failed to assert MC reset: %d\n", + ret); + goto put_runtime_pm; + } + ret = reset_control_reset(vde->rst); if (ret) { - dev_err(dev, "Failed to reset HW: %d\n", ret); + dev_err(dev, "DEC start: Failed to reset HW: %d\n", ret); + goto put_runtime_pm; + } + + ret = reset_control_deassert(vde->rst_mc); + if (ret) { + dev_err(dev, "DEC start: Failed to deassert MC reset: %d\n", + ret); goto put_runtime_pm; } @@ -880,9 +895,18 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, ret = timeout; } + /* + * At first reset memory client to avoid resetting VDE HW in the + * middle of DMA which could result into memory corruption or hang + * the whole system. + */ + err = reset_control_assert(vde->rst_mc); + if (err) + dev_err(dev, "DEC end: Failed to assert MC reset: %d\n", err); + err = reset_control_assert(vde->rst); if (err) - dev_err(dev, "Failed to assert HW reset: %d\n", err); + dev_err(dev, "DEC end: Failed to assert HW reset: %d\n", err); put_runtime_pm: pm_runtime_mark_last_busy(dev); @@ -1074,6 +1098,13 @@ static int tegra_vde_probe(struct platform_device *pdev) return err; } + vde->rst_mc = devm_reset_control_get_optional(dev, "mc"); + if (IS_ERR(vde->rst_mc)) { + err = PTR_ERR(vde->rst_mc); + dev_err(dev, "Could not get MC reset %d\n", err); + return err; + } + irq = platform_get_irq_byname(pdev, "sync-token"); if (irq < 0) return irq;