From patchwork Sun May 20 13:48:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 10413427 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 BE9FF6032C for ; Sun, 20 May 2018 13:49:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFA9F28653 for ; Sun, 20 May 2018 13:49:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3A5F2872F; Sun, 20 May 2018 13:49:58 +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=unavailable 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 2965328714 for ; Sun, 20 May 2018 13:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751725AbeETNto (ORCPT ); Sun, 20 May 2018 09:49:44 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:45589 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751162AbeETNtP (ORCPT ); Sun, 20 May 2018 09:49:15 -0400 Received: by mail-wr0-f196.google.com with SMTP id w3-v6so5754767wrl.12; Sun, 20 May 2018 06:49:14 -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:in-reply-to:references; bh=+w5ibtcxSXD2/H7ACOoT5H6ZTSX8DxlPN5X/tJ8rSLw=; b=aGyBJ4znrA7Fmx1bdTy0W/NU2bWNt90DkSsPjkjArxIX6rLayqxA004iK2KLA+FoIP TpJqTcdKJNx5gv2xHppX3AAI//x+sqU4BEbQMoXJ42X+Qt4xU8nMBVAt5qAw+OQmMhmJ R80KvuBvC+yyvKIRxOAgrA36BZZksm31OsHyDVOj6aoT2Zq/mMIOKXrc67DMiEkCUWyu dYDNspGnZigOm09Y13mJv+bTbtvciThwHXGNSINNq67bsMweBm/KKzCl5UBbwmzm0cM2 7ORslg9xdZ7OLCsL8v6rMwCtoYeMI+nfXLJkuyTPnkVDM5m/PjPbLf8ALRFrIII0RZE3 27Ww== 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; bh=+w5ibtcxSXD2/H7ACOoT5H6ZTSX8DxlPN5X/tJ8rSLw=; b=Gb0mIn10DXGbYYgHRrJXeUhxyxqSvO59UEd7tVKbljfzIOvkaRQh1A6u+YkVkfQzIF oPtHXFGT9nFA7LYXZaeWGCHAMJgaA5CzF0eHLWrCO3VySzrGc/HHGS67LbtvG9VidNuX ctXTPDyrg5QjxxzQ82sdgiaxlzXwE2+mkHPHIWXpRgV/BGpPcZyTKTMt5IvuLVkNFLkF wkmbEpA7lt0pIHM6MfTgDpR8iT6XK0I9CNFc69KbIObeCFolPPkHabgwP3Nk2BK/rrk9 nld0ubiRXAaor0JelsIQnYnaIbIlcGTcpXOsZ9Hog4yrSV6QkBESNFqlPnj0fRHEQoNG OHtQ== X-Gm-Message-State: ALKqPwfac934CFfNL88TpIhPIzcbttniQsQPrGkz4NkwwdCLGHvAornM G0u98SQ0lULXVliRy04T8nHd3zHm X-Google-Smtp-Source: AB8JxZqhyvieD2B6tvIXfvTvaN36iNLlcY8ZoC9ewaFFlc8V6h5/exGh5he5Z207N+0YCYoPG2b07Q== X-Received: by 2002:adf:d1cc:: with SMTP id m12-v6mr3605929wri.198.1526824154251; Sun, 20 May 2018 06:49:14 -0700 (PDT) Received: from localhost.localdomain ([109.252.91.60]) by smtp.gmail.com with ESMTPSA id 2-v6sm28540300wrb.22.2018.05.20.06.49.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 May 2018 06:49:13 -0700 (PDT) From: Dmitry Osipenko To: Hans Verkuil , Mauro Carvalho Chehab , Thierry Reding , Jonathan Hunter Cc: linux-tegra@vger.kernel.org, linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] media: staging: tegra-vde: Reset memory client Date: Sun, 20 May 2018 16:48:45 +0300 Message-Id: <20180520134846.31046-2-digetx@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180520134846.31046-1-digetx@gmail.com> References: <20180520134846.31046-1-digetx@gmail.com> 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 --- drivers/staging/media/tegra-vde/tegra-vde.c | 42 +++++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/tegra-vde/tegra-vde.c b/drivers/staging/media/tegra-vde/tegra-vde.c index 90177a59b97c..6dd3bf4481be 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,21 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, ret = timeout; } - err = reset_control_assert(vde->rst); - if (err) - dev_err(dev, "Failed to assert HW reset: %d\n", err); + /* + * 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) { + err = reset_control_assert(vde->rst); + if (err) + dev_err(dev, + "DEC end: Failed to assert HW reset: %d\n", + err); + } else { + dev_err(dev, "DEC end: Failed to assert MC reset: %d\n", err); + } put_runtime_pm: pm_runtime_mark_last_busy(dev); @@ -1074,6 +1101,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;