Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1136432pxa; Thu, 20 Aug 2020 03:37:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFPVuVVijlnrereAkUNL8vy8z+nYZhQ3n1miDssT+pEjuoN4whmowfL0dw4X+71IWFXOgy X-Received: by 2002:a17:906:f107:: with SMTP id gv7mr1478989ejb.519.1597919841510; Thu, 20 Aug 2020 03:37:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597919841; cv=none; d=google.com; s=arc-20160816; b=Lbp8eLhjQJEiN8Y98vZ3qkLC5xaRCQwOdzc3zZKSctxPhLXdQAfA8aormsy7IAf9La 5ncjmzIgnu+SNpM4vb5AhxPPLEN4GGnomqbpi34y0OUJgc6q6xzo4S70avO6aVSJYKLQ FCMx0trBAJKsCZpD6dqCB2QNYMja1BBGQ5yeGsUWNkFR8QvO/oIhVByzZ9LQMg+bvbfI YxJcXH8Be6sEAp68DyqNGix5zYiwGuDsY2Ft7AMLdhXbRHTi6MEEHgLYYK7e2hzl4m1M xR2dwGx1ftp7wnSl4rOegXotB3HyvFRgnpzV0oLoc/CP1kAClwkek4FSEIrNtE4OeiMy H9dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=C2VIIu0JZUkn5iFt/6SiK8/J/cPTW/j0CXq7TqJhryY=; b=L09rvPSAe8bBqqJHWwggnxujur7z5P7AeonG6t2pDhRLDl69I1rhMqXcaWploqzm01 djHBFlccStAVG6iZd3TsZx71I4v+uJhn7dbiwlL91TTMJ8lktR+lhvPI48i+lqL4qqk5 QitmWXddLLT4VIcZ6DnChG9R2Hpf/26z5bKfFUX1UTdIFQThrORnsxVaoDdyX9Dq1G4w x4D+i5Jtnu8oFFHsP+2ZjNtp9yARO1TQzOax/HcakCT1kGtpSJPPtvkaiKr3HTNd76Ln Iu7DYzKs4Od/P6i6W/1eeLbCfAe3MoMegx0X6JlHd922SqRluhv9yRsz9ilazR13cCo+ exmQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x2si1075423ejy.84.2020.08.20.03.36.57; Thu, 20 Aug 2020 03:37:21 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731299AbgHTKg2 (ORCPT + 99 others); Thu, 20 Aug 2020 06:36:28 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:62150 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731420AbgHTKgL (ORCPT ); Thu, 20 Aug 2020 06:36:11 -0400 Received: from ironmsg08-lv.qualcomm.com ([10.47.202.152]) by alexa-out.qualcomm.com with ESMTP; 20 Aug 2020 03:36:10 -0700 Received: from ironmsg01-blr.qualcomm.com ([10.86.208.130]) by ironmsg08-lv.qualcomm.com with ESMTP/TLS/AES256-SHA; 20 Aug 2020 03:36:08 -0700 Received: from c-rojay-linux.qualcomm.com ([10.206.21.80]) by ironmsg01-blr.qualcomm.com with ESMTP; 20 Aug 2020 16:05:36 +0530 Received: by c-rojay-linux.qualcomm.com (Postfix, from userid 88981) id 937791F44; Thu, 20 Aug 2020 16:05:35 +0530 (IST) From: Roja Rani Yarubandi To: wsa@kernel.org Cc: swboyd@chromium.org, 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 Subject: [PATCH V2 2/2] i2c: i2c-qcom-geni: Add shutdown callback for i2c Date: Thu, 20 Aug 2020 16:05:22 +0530 Message-Id: <20200820103522.26242-3-rojay@codeaurora.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200820103522.26242-1-rojay@codeaurora.org> References: <20200820103522.26242-1-rojay@codeaurora.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. So, implement shutdown callback to i2c driver to unmap DMA mappings during system "reboot" or "shutdown". Signed-off-by: Roja Rani Yarubandi --- Changes in V2: - As per Stephen's comments added seperate function for stop transfer, fixed minor nitpicks. drivers/i2c/busses/i2c-qcom-geni.c | 43 ++++++++++++++++++++++++++++++ include/linux/qcom-geni-se.h | 5 ++++ 2 files changed, 48 insertions(+) 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; } +static void geni_i2c_stop_xfer(struct geni_i2c_dev *gi2c) +{ + u32 val; + struct geni_se *se = &gi2c->se; + + val = readl_relaxed(gi2c->se.base + SE_DMA_DEBUG_REG0); + if (val & DMA_TX_ACTIVE) { + geni_i2c_abort_xfer(gi2c); + gi2c->cur_wr = 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 = 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_QUICK); @@ -617,6 +639,26 @@ static int geni_i2c_remove(struct platform_device *pdev) return 0; } +static void geni_i2c_shutdown(struct platform_device *pdev) +{ + int ret; + u32 dma; + struct geni_i2c_dev *gi2c = platform_get_drvdata(pdev); + struct geni_se *se = &gi2c->se; + + ret = pm_runtime_get_sync(gi2c->se.dev); + if (ret < 0) { + dev_err(gi2c->se.dev, "Failed to resume device: %d\n", ret); + return; + } + + dma = readl_relaxed(se->base + SE_GENI_DMA_MODE_EN); + if (dma) + geni_i2c_stop_xfer(gi2c); + + pm_runtime_put_sync_suspend(gi2c->se.dev); +} + static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev) { int ret; @@ -677,6 +719,7 @@ MODULE_DEVICE_TABLE(of, geni_i2c_dt_match); static struct platform_driver geni_i2c_driver = { .probe = geni_i2c_probe, .remove = geni_i2c_remove, + .shutdown = geni_i2c_shutdown, .driver = { .name = "geni_i2c", .pm = &geni_i2c_pm_ops, diff --git a/include/linux/qcom-geni-se.h b/include/linux/qcom-geni-se.h index dd464943f717..c3c016496d98 100644 --- a/include/linux/qcom-geni-se.h +++ b/include/linux/qcom-geni-se.h @@ -77,6 +77,7 @@ struct geni_se { #define SE_DMA_RX_FSM_RST 0xd58 #define SE_HW_PARAM_0 0xe24 #define SE_HW_PARAM_1 0xe28 +#define SE_DMA_DEBUG_REG0 0xe40 /* GENI_FORCE_DEFAULT_REG fields */ #define FORCE_DEFAULT BIT(0) @@ -207,6 +208,10 @@ struct geni_se { #define RX_GENI_CANCEL_IRQ BIT(11) #define RX_GENI_GP_IRQ_EXT GENMASK(13, 12) +/* SE_DMA_DEBUG_REG0 Register fields */ +#define DMA_TX_ACTIVE BIT(0) +#define DMA_RX_ACTIVE BIT(1) + /* SE_HW_PARAM_0 fields */ #define TX_FIFO_WIDTH_MSK GENMASK(29, 24) #define TX_FIFO_WIDTH_SHFT 24 -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation