Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1652726pxa; Thu, 20 Aug 2020 17:27:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHZSILSoU50wcvcvIkCUyFJkgHq2z5whSuegiObZYybKeVrgIiYC9ce2vINIw19jOgWIr6 X-Received: by 2002:a50:ec90:: with SMTP id e16mr469186edr.234.1597969674565; Thu, 20 Aug 2020 17:27:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597969674; cv=none; d=google.com; s=arc-20160816; b=zfhfLq0Z/+0AmXOEkBGxeoM5E/QSQp1jBfvjevAJMU2XFBtxsbj81m8ymEA3iIuTgV S1MxGDSS2n4u+7xqswHifmqBD0OLSCK5ZQw1DxSEvQI5Ews+tu8mj1bpIvpWAtQlP0qq x6HtMnhH5H9uEJ27uy7dRxOXx6zmyZRW8mfuLs+wFu3l3OmHQiysmCiZJPbl9fzxmBFe r1IkJnO4KikktYWEoAjfIXQcRgc+vY6bm8/RxaSizNVG2bJL4heEugzb60C4GKDGBOk7 4QN8eV7fH98+T4Dqy0+AdQh7W0oRL4s9j757q6Loxdylou6g/1aRoZsZObjt9fMpSvTi Y/0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:date:to:cc:from :subject:references:in-reply-to:content-transfer-encoding :mime-version:dkim-signature; bh=JaBnFv8JsCcvYIQ4zapld4yeibcuyrja8X9nWizMp1c=; b=vKXX4B02zWAX2CvwCPlCo45AifO5Ej7HThm6PuC0aAyyGUzvLb4dF2YJ+KaSDzHkW+ QUeb9198CjC82jh6SclAoxFx77fcudmuwEiWO6+/OAGHS6jyGKpoWAA3PAnHoW9vtWJD clirMfXkuTDQ6umII5vsM5MXK5bI4Ea9LoPJBfj9wWiPiAJqELgku1jZyXzdmnSoiBCw S9hLjFjL+dPcfBvMAppA0nd2y6dI5FhWjidJXFVJ/TTChH+ieYdnUJyAZpvz8Ny6n3rI jUIui9++C1I4SmJlHZM8yReyZzReM0E8ykbBYXDMmGZu6LWGxBImYUTfv0kmApjClY4j R7WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BZjKFFxJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si59611ejg.108.2020.08.20.17.27.30; Thu, 20 Aug 2020 17:27:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BZjKFFxJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726918AbgHUAWq (ORCPT + 99 others); Thu, 20 Aug 2020 20:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726718AbgHUAWm (ORCPT ); Thu, 20 Aug 2020 20:22:42 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72CF7C061386 for ; Thu, 20 Aug 2020 17:22:42 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id m8so199436pfh.3 for ; Thu, 20 Aug 2020 17:22:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:content-transfer-encoding:in-reply-to:references :subject:from:cc:to:date:message-id:user-agent; bh=JaBnFv8JsCcvYIQ4zapld4yeibcuyrja8X9nWizMp1c=; b=BZjKFFxJrYWLpgWAWQWZDBKLRAci51Q0Su8FjO3iUEFzlyOhqLFNPsvuxixamwrRLs lKZGGf7rLwn47tLUO42ClFCzMBDXdfLXL78W50n+2ZlXdKXDTdRlU5lXHXAw4nbEdKSF UHZOlE43W/n9/caF6jnniuToGVFUgwElEfn7A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding :in-reply-to:references:subject:from:cc:to:date:message-id :user-agent; bh=JaBnFv8JsCcvYIQ4zapld4yeibcuyrja8X9nWizMp1c=; b=PrVG50qVPCVcK1RIfPZF3cZ/iKiug6NgUnEtWkJ5I+P3//mNGYZM4c92mZD7Mx5zHp PYlGRmnv3Rc5YR/U4PBi4pXm+wenHaLwCKSs9E4pItzIVRNP2dAHT9sJnYyeY7scaQoa nKW8470kGC7NXbLMThFufIQW6gu5BFf2k7piVcYEg7SvcncMlLEMYpA/MzezUWniyMLV IjUVZ9KqYjGAdofasU65hB1LazcbNh89yOsRujMKqGIAF1Y0csEHzNUYptCs/ajfbBm/ z9yxfxhVZpZyKyqxObxX8TM+dF52JucIEg648+bjKCQ5ep0OSon0b2Cpvcvnjwbx/k25 6ibg== X-Gm-Message-State: AOAM533M05P2kSx8LmvyS/OkE4j5JV8jOixDYyU5fS88bySoey++TUNT 6AcSQk0H72TucbHqFOjTcSmcuA== X-Received: by 2002:a63:925d:: with SMTP id s29mr449060pgn.423.1597969361170; Thu, 20 Aug 2020 17:22:41 -0700 (PDT) Received: from chromium.org ([2620:15c:202:1:3e52:82ff:fe6c:83ab]) by smtp.gmail.com with ESMTPSA id x127sm249376pfd.86.2020.08.20.17.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 17:22:40 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20200820103522.26242-3-rojay@codeaurora.org> References: <20200820103522.26242-1-rojay@codeaurora.org> <20200820103522.26242-3-rojay@codeaurora.org> Subject: Re: [PATCH V2 2/2] i2c: i2c-qcom-geni: Add shutdown callback for i2c From: Stephen Boyd Cc: dianders@chromium.org, saiprakash.ranjan@codeaurora.org, gregkh@linuxfoundation.org, mka@chromium.org, akashast@codeaurora.org, msavaliy@qti.qualcomm.com, skakit@codeaurora.org, rnayak@codeaurora.org, agross@kernel.org, bjorn.andersson@linaro.org, linux-arm-msm@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, sumit.semwal@linaro.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Roja Rani Yarubandi To: Roja Rani Yarubandi , wsa@kernel.org Date: Thu, 20 Aug 2020 17:22:39 -0700 Message-ID: <159796935923.334488.7479152222902825306@swboyd.mtv.corp.google.com> User-Agent: alot/0.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Roja Rani Yarubandi (2020-08-20 03:35:22) > If the hardware is still accessing memory after SMMU translation > is disabled (as part of smmu shutdown callback), then the > IOVAs (I/O virtual address) which it was using will go on the bus > as the physical addresses which will result in unknown crashes > like NoC/interconnect errors. >=20 > So, implement shutdown callback to i2c driver to unmap DMA mappings > during system "reboot" or "shutdown". >=20 > Signed-off-by: Roja Rani Yarubandi > --- I'd still put a Fixes tag because it's fixing the driver when someone runs shutdown. > Changes in V2: > - As per Stephen's comments added seperate function for stop transfer, > fixed minor nitpicks. >=20 > drivers/i2c/busses/i2c-qcom-geni.c | 43 ++++++++++++++++++++++++++++++ > include/linux/qcom-geni-se.h | 5 ++++ > 2 files changed, 48 insertions(+) >=20 > diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-= qcom-geni.c > index 1fda5c7c2cfc..d07f2f33bb75 100644 > --- a/drivers/i2c/busses/i2c-qcom-geni.c > +++ b/drivers/i2c/busses/i2c-qcom-geni.c > @@ -486,6 +486,28 @@ static int geni_i2c_xfer(struct i2c_adapter *adap, > return ret; > } > =20 > +static void geni_i2c_stop_xfer(struct geni_i2c_dev *gi2c) > +{ > + u32 val; > + struct geni_se *se =3D &gi2c->se; > + > + val =3D readl_relaxed(gi2c->se.base + SE_DMA_DEBUG_REG0); > + if (val & DMA_TX_ACTIVE) { > + geni_i2c_abort_xfer(gi2c); > + gi2c->cur_wr =3D 0; > + if (gi2c->err) > + geni_i2c_tx_fsm_rst(gi2c); > + geni_se_tx_dma_unprep(se, gi2c->tx_dma, gi2c->xfer_len); > + } > + if (val & DMA_RX_ACTIVE) { > + geni_i2c_abort_xfer(gi2c); > + gi2c->cur_rd =3D 0; > + if (gi2c->err) > + geni_i2c_rx_fsm_rst(gi2c); > + geni_se_rx_dma_unprep(se, gi2c->rx_dma, gi2c->xfer_len); > + } > +} > + > static u32 geni_i2c_func(struct i2c_adapter *adap) > { > return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUIC= K); > @@ -617,6 +639,26 @@ static int geni_i2c_remove(struct platform_device *p= dev) > return 0; > } > =20 > +static void geni_i2c_shutdown(struct platform_device *pdev) > +{ > + int ret; > + u32 dma; > + struct geni_i2c_dev *gi2c =3D platform_get_drvdata(pdev); > + struct geni_se *se =3D &gi2c->se; > + > + ret =3D pm_runtime_get_sync(gi2c->se.dev); > + if (ret < 0) { > + dev_err(gi2c->se.dev, "Failed to resume device: %d\n", re= t); > + return; > + } > + > + dma =3D readl_relaxed(se->base + SE_GENI_DMA_MODE_EN); > + if (dma) > + geni_i2c_stop_xfer(gi2c); Any reason the if (dma) check isn't inside geni_i2c_stop_xfer()? Checking for dma and then bailing out early should work and keep the logic in one function. Then the pm_runtime_sync() call could go in there too and if (!dma) goto out. This assumes that we're going to call geni_i2c_stop_xfer() from somewhere else, like if a transfer times out or something? > + > + pm_runtime_put_sync_suspend(gi2c->se.dev); > +} > + > static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev) > { > int ret;