Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp11245992rwl; Mon, 2 Jan 2023 17:24:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXvLYe6IVBdOX2Euxbk5OAm1EPQS+8pud1EOi6V1XRWq6SMn+491wRyGhip5VO6r3DIToy5i X-Received: by 2002:a17:902:ee55:b0:192:dbc3:6b79 with SMTP id 21-20020a170902ee5500b00192dbc36b79mr927379plo.12.1672709065646; Mon, 02 Jan 2023 17:24:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672709065; cv=none; d=google.com; s=arc-20160816; b=a+3lqGuY03nLIq8IOSpplgUwcSKYf3T+cdBraLM97+XBZN2yk6j2YkAWS5LBkh2Fxi AFIAziOJsMHBdWO7hElD9srPjyG3mNurArFYpkMBzrDjVzaZlQ06o7/oUOmNXnweQ4R4 mXqdccGbMNq3Fc/RmnPbD/zJBtiWeqi8yNsuf8gZO4PiwAv4r514aeFCEVtFGAvlz8Kj 4c7uP5XVKXinqH8gr2OesubdJxHtWMUyAGBXK/kcLiEfuBg+7Hn6jXCJdjulrwD6uIjo OyckZGAKBdgiC5JgAS/L8AnAw7fctfY/Dsb69+evDcRqifMa7EByXN3ash3oEtKb9M/b LAJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=l33byjN96tAFT91WzVSv7uBqAlUyhhwrwVPAOp/DxlI=; b=rGaQ7dXgsyOl1iXuit0f3Qya+q5PzPxfboghYgrqFbe+BeUA1ycPa3w8E0+9vSdQv7 Zj06HMTgmdwbQwmO97YWKh0sywbuumG/YLT+Ejf+28wt7SlHXTm8VGnZbM4hXULzW3kc bnkgg9A4p87TrC3EoK+r4c57TspfBCZu0YCpYXJn0bnWC/+RW62wJstLejiWjRgKMJak yuvUpewb3MU0vgSuIVCDlrYBRj6eyuwyu0/RpoDMhfgHDj3Pdb6saSCvqcHJJJzzOBNv RKkAh3+fe5cCbkPNLtk1iiEEeZQCSr+kymmBvc37vPo28zh8bFEbD9uYVvi2+bmD5+VR mDcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=cUBLPZjz; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=o4pb0s46; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sholland.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n12-20020a170902e54c00b00174ea015ee8si32061913plf.592.2023.01.02.17.24.18; Mon, 02 Jan 2023 17:24:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=cUBLPZjz; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=o4pb0s46; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sholland.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236634AbjACBJ6 (ORCPT + 62 others); Mon, 2 Jan 2023 20:09:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236475AbjACBJU (ORCPT ); Mon, 2 Jan 2023 20:09:20 -0500 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79E7FAE72; Mon, 2 Jan 2023 17:09:16 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 07CFF3200919; Mon, 2 Jan 2023 20:09:14 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 02 Jan 2023 20:09:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672708154; x=1672794554; bh=l3 3byjN96tAFT91WzVSv7uBqAlUyhhwrwVPAOp/DxlI=; b=cUBLPZjztaJPEF/tEF eXnYxSk3QYC4X9Z7BNWWtKNjLeMXIICX3Z0F8srYK52u98ILXKIAd8ey6+qiX+2/ CCjS38MZ8Oe+mD2bKi4MAGhwnVkT3B9toQo1K9iJowu5tTZG2k97iHSKAnbB5/Jr ke2GtIwXCgCdTv3mcZAC5/B0XRLjz3OJvSCueGp7HtFYI5nJzW1M+rEgNePKjwt+ 1JpAKKyNSlpHCfgUifkjt+vrUsCE8D9ExCMld5D4SiccVrOLbsjmmIlCmYP/1n/a oJkSowd45RKHw7EOYQcZgaLe7UgxoBTS6CEczexSaGjrIbnpgcpS3XgRVgeskRTc ZPFQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672708154; x=1672794554; bh=l33byjN96tAFT 91WzVSv7uBqAlUyhhwrwVPAOp/DxlI=; b=o4pb0s46K9RCUY30Fk6zVEKZDK0lT JnqzFQvbGCV95Q4cwbpolMY8oC7geSKBCkCT/zx1IY5on+go50zWThlMBK6iUhha mo850IGtZegHv5RvI74j/eHf38uCTQRfnU3wJy6Bcl/BTiLoZBmzmGnLFFdm1zTn Ogx4W7OaNakzafipaZcj0y2ttLazg6HwIFGJioYA75B3ywDWBepeEQWH6PqAXjyJ 2SDLMjvaa6rw7jliJ3nJsUraewPELG4b6UnNIKLYaeKIC4pXj4jNpSsiEOqdi8mM 73ZnvyMUw7evkNB+jW1rsWE3mlVf7C8suf7LVlBRcHw6jvdfF2zuJG7bw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrjeefgdeffecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpedukeetueduhedtleetvefguddvvdejhfefudelgfduveeggeehgfdu feeitdevteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 2 Jan 2023 20:09:13 -0500 (EST) From: Samuel Holland To: Joerg Roedel , Will Deacon , Robin Murphy , Chen-Yu Tsai , Jernej Skrabec , Krzysztof Kozlowski , Rob Herring Cc: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Maxime Ripard , Samuel Holland Subject: [PATCH v2 3/6] iommu/sun50i: Keep the bypass register up to date Date: Mon, 2 Jan 2023 19:09:00 -0600 Message-Id: <20230103010903.11181-4-samuel@sholland.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20230103010903.11181-1-samuel@sholland.org> References: <20230103010903.11181-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the IOMMU driver leaves the bypass register at its default value. The H6 variant of the hardware disables bypass by default. So once the first device is attached to the IOMMU, translation is enabled for all masters, even those not attached to an IOMMU group/domain. On the other hand, the D1 hardware variant enables bypass by default, so keeping the default value prevents the IOMMU from functioning entirely. Fixes: 4100b8c229b3 ("iommu: Add Allwinner H6 IOMMU driver") Signed-off-by: Samuel Holland --- Changes in v2: - Set bypass based on attached devices instead of using a fixed value drivers/iommu/sun50i-iommu.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index 3757d5a18318..a3a462933c62 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -441,6 +441,9 @@ static int sun50i_iommu_enable(struct sun50i_iommu *iommu) spin_lock_irqsave(&iommu->iommu_lock, flags); + iommu_write(iommu, IOMMU_BYPASS_REG, + ~atomic_read(&sun50i_domain->masters)); + iommu_write(iommu, IOMMU_TTB_REG, sun50i_domain->dt_dma); iommu_write(iommu, IOMMU_TLB_PREFETCH_REG, IOMMU_TLB_PREFETCH_MASTER_ENABLE(0) | @@ -755,6 +758,17 @@ static void sun50i_iommu_detach_domain(struct sun50i_iommu *iommu, iommu->domain = NULL; } +static void sun50i_iommu_update_masters(struct sun50i_iommu *iommu, + struct sun50i_iommu_domain *sun50i_domain) +{ + unsigned long flags; + + spin_lock_irqsave(&iommu->iommu_lock, flags); + iommu_write(iommu, IOMMU_BYPASS_REG, + ~atomic_read(&sun50i_domain->masters)); + spin_unlock_irqrestore(&iommu->iommu_lock, flags); +} + static void sun50i_iommu_detach_device(struct iommu_domain *domain, struct device *dev) { @@ -770,6 +784,8 @@ static void sun50i_iommu_detach_device(struct iommu_domain *domain, if (atomic_fetch_andnot(masters, &sun50i_domain->masters) == masters) sun50i_iommu_detach_domain(iommu, sun50i_domain); + else + sun50i_iommu_update_masters(iommu, sun50i_domain); } static int sun50i_iommu_attach_device(struct iommu_domain *domain, @@ -791,6 +807,8 @@ static int sun50i_iommu_attach_device(struct iommu_domain *domain, if (atomic_fetch_or(masters, &sun50i_domain->masters) == 0) sun50i_iommu_attach_domain(iommu, sun50i_domain); + else + sun50i_iommu_update_masters(iommu, sun50i_domain); return 0; } -- 2.37.4