From patchwork Tue Oct 25 16:54:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 13019561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A8A07C04A95 for ; Tue, 25 Oct 2022 16:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pXuXncz7Sdv+9YYM/NWWG04aHmeBweZkX4eggVaVshE=; b=WjaizvXcU8S2Ia ynHEywW2yzwnCk6MdFkaq2Um99BBhxJm6E3uj+oCRwv06HzD3sVWS/pp1REwWsAPIk+YSB6WcfXlE eRO/nz93rPo77PvIihAPn8Yr4yGRgF+MGNHLpe04+PnnSFHATEQwta10OvurF1FKAAMlijAgOeAfQ JPO+nwY91j9YwH5T6VzVp1dVovnV5p2Ok+BLAJ/79So3n8PgT2x1WVXY04DbS+PgaWdgEHvvA72J/ 4Tfz0sah2ioOE3vhUse7fyw1vSgdApQsBSRrI8Ag+U/JJuhm8S5xjJ+Nx6dSc6+o4t/B71hYJVV4E 0WLr9+0EtZtd34g4ZR7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1onNCT-006M5Q-PM; Tue, 25 Oct 2022 16:54:49 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1onNCH-006Lyl-Ul for linux-arm-kernel@lists.infradead.org; Tue, 25 Oct 2022 16:54:39 +0000 Received: by mail-wr1-x42d.google.com with SMTP id g12so9354690wrs.10 for ; Tue, 25 Oct 2022 09:54:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9XVDf5CNGXohyTDwQXIUTQefWV+zveKEvdiJ0iEMiCo=; b=nWWvtDEnIFtSZIk2LCzs577LelT3TwOr923486IySggt0BodjQKLBytOshOzTgOkYW ShmNzTVUSj8yF8YpAsjkfXnqZw9wZ5Uxu9cFvPR9mPLSpXrh+BkPuGjsXfVTCZW1lhnx 0nTXG8MyhhmQg8vNm8SyUcRZLE8mXL8mUBGwSQHSBzwib4mvgtW7KuJzCIXJrps8u9xz lEykKyUDhLTep6wRxxb1huTpc2j03/jY6taCCgvFu/pOHj1NuUf4lp0rjTTClFpPNGUX f7e54GNHC3jhmlr7DPiVXmhJPTzx5nKyRS2lKAXqqXmREcNaaQYCs2/OmzZLNBHc8nHX 604Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9XVDf5CNGXohyTDwQXIUTQefWV+zveKEvdiJ0iEMiCo=; b=fpjgmoMr8HK3NmbrktCpCVXr4a3ulEv+YuHSNBLkiuDlXZ/1Si4/4wvSTpNAwVqJph qfumG9SgeijlPoMYPyIwmbtQkDz07sqmpfZR/yVbQ2UXPZQiGJRQmEzTCUbXX37XSy8e 24yAEJqS5EeONotBsKikWmPzr9iMqoHT5wxSml1Dp9kV5dSdZPUPmCsydfeYBhx9qyVY kFUlqiNHtCZbQJDrazq2GuhiOQ9WD/P58yn+eKL5lB4lAgVgtktnfqXxp6o626ah5kMc YKBrGw+mJIoFSeWMcOb7MAyZ4lQMYzhxRf13PHkoxjTGWLxZmWA6ZkHWcVpNgerjS+Lf jX5Q== X-Gm-Message-State: ACrzQf0ZzvH/0elwhItLmyY6bkzwGOfrV+458wpZa5jHUGcEA4fPw6// KQZKTxgcDMi+OBdhKqOnvWU= X-Google-Smtp-Source: AMsMyM4URGw014tILeGzQZ66S57zVWE5z6thpheFKt2ksgimTOOtljhHjSVf/MlhT/s/B/o2zDdIQA== X-Received: by 2002:a5d:6dcd:0:b0:235:f087:fec2 with SMTP id d13-20020a5d6dcd000000b00235f087fec2mr18867780wrz.444.1666716874910; Tue, 25 Oct 2022 09:54:34 -0700 (PDT) Received: from kista.localdomain (82-149-19-102.dynamic.telemach.net. [82.149.19.102]) by smtp.gmail.com with ESMTPSA id a20-20020a05600c349400b003a6a3595edasm3023989wmq.27.2022.10.25.09.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 09:54:34 -0700 (PDT) From: Jernej Skrabec To: maxime@cerno.tech, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com Cc: wens@csie.org, samuel@sholland.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec Subject: [PATCH v2 1/5] iommu/sun50i: Fix reset release Date: Tue, 25 Oct 2022 18:54:11 +0200 Message-Id: <20221025165415.307591-2-jernej.skrabec@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221025165415.307591-1-jernej.skrabec@gmail.com> References: <20221025165415.307591-1-jernej.skrabec@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221025_095438_008744_29415C03 X-CRM114-Status: GOOD ( 13.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Reset signal is asserted by writing 0 to the corresponding locations of masters we want to reset. So in order to deassert all reset signals, we should write 1's to all locations. Current code writes 1's to locations of masters which were just reset which is good. However, at the same time it also writes 0's to other locations and thus asserts reset signals of remaining masters. Fix code by writing all 1's when we want to deassert all reset signals. This bug was discovered when working with Cedrus (video decoder). When it faulted, display went blank due to reset signal assertion. Fixes: 4100b8c229b3 ("iommu: Add Allwinner H6 IOMMU driver") Signed-off-by: Jernej Skrabec --- drivers/iommu/sun50i-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index cd9b74ee24de..270204a6ec4a 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -27,6 +27,7 @@ #include #define IOMMU_RESET_REG 0x010 +#define IOMMU_RESET_RELEASE_ALL 0xffffffff #define IOMMU_ENABLE_REG 0x020 #define IOMMU_ENABLE_ENABLE BIT(0) @@ -893,7 +894,7 @@ static irqreturn_t sun50i_iommu_irq(int irq, void *dev_id) iommu_write(iommu, IOMMU_INT_CLR_REG, status); iommu_write(iommu, IOMMU_RESET_REG, ~status); - iommu_write(iommu, IOMMU_RESET_REG, status); + iommu_write(iommu, IOMMU_RESET_REG, IOMMU_RESET_RELEASE_ALL); spin_unlock(&iommu->iommu_lock); From patchwork Tue Oct 25 16:54:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 13019563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3EED7C04A95 for ; Tue, 25 Oct 2022 16:56:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IOW1qxKkIIsEkGe2sF8C9JJI7usILM8J84srbHmukA0=; b=ehgotO0dCC90xB FNNlzrext3kRd4vV/mnTZJN3Vc/305L/lpq0PLwMWNNXLZ3i1JGO0jMFZ+SeOXClCaSvXNNZ+Vi9k kaqw7GzHDCwXUYJj+alCPtNTTtjY6QLWrg50HaZlOTLBra4++sK81lGFONC8cRUKqdMjZ1pb39na/ KwIXzb4ra/UGpH1St8e8Mg+WvC3nntAYLphsyWo4QQGAWhrtxibCBvih7B1o8yJW3PtIe+oQEgLRM tYRvqZ7tzOXP3zC9Jdg53ND6IrFV2Fk+A4QGqwTvEEXUnInSNL2V2vaEPWU5Md2m6jOGDilwM2/ZJ i7r7bPNEKKc95Fxk2hbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1onNCc-006M7c-HL; Tue, 25 Oct 2022 16:54:58 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1onNCI-006Lyr-04 for linux-arm-kernel@lists.infradead.org; Tue, 25 Oct 2022 16:54:39 +0000 Received: by mail-wr1-x431.google.com with SMTP id z14so8634935wrn.7 for ; Tue, 25 Oct 2022 09:54:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fxmsLKzFVvKcS3WMj1YQZz1vx7/2bMhWnQ94H0bmWEY=; b=Nykt+sLEadPMO+cbi45gb3Ye9NF4TPpULSSO3kp+XegRbPdux6w/+ZO3CR3SXQRW8I R3TuAZZf1w7TrwlmiHAZ86B2JWU42B4iOt8JBUaz6eJeiBBy1XkUogeLCwFtGfszG9uR Z3rcrOhRdGx2cafEhzZkq8e1iQe9O7MFXbfFvujOvM5KHs0wioEYKntJ/BBvMa941RoX +hpKjDKTz1JH+yS0JdHZ4RzjqXIc5ObsolSvx7vq9a++fXRWX1RlSr6DmT9rqchhO4LG KvJzUCvEhmdpE1rxgBVZ1ozzNn44JG024aTd8a59jr+v0PkKHBZ0JwY5do5aEDVyYWDQ UwxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fxmsLKzFVvKcS3WMj1YQZz1vx7/2bMhWnQ94H0bmWEY=; b=vJ0uAm7r+Lpn4V0nPMJWgUlsA6rnAj8PptzO3H608kOAnan0xj3ADDvfcyj5/jQTBl HnLms09ZaZmH2nlCo9KwZ0vYenQB7u+5Ug5CJA1kRM6bxvJ8yVF8Lcu43PJJSPTlk0Sb pKu8JQYCqek6wV7/D2kjD9X0YuzWni2U6+9VE07SQMP4ck3cvWs+SP5SMHH+TA57n9+K CyNaC09STK0bkebt2HdVYXqa+hZbhEln5Q6H0S8qyOHFoyEiGVLX5xC0gid8rQkTCPmN GgIgqx06kMF29GziNDf0WDZIacokI9QAq3k/cdn8V2a6vntDnLXVzWGOOtiiHUhc3bL7 lN+Q== X-Gm-Message-State: ACrzQf1X2RfyacMOgW8Uqz3XjGa2/yxABYM2ErBTHP5Ka8BzGNe8aVYy sidg8EQBV1OHuc2l9YzF+j0= X-Google-Smtp-Source: AMsMyM4kPGoX2AJWIBlWQttHFd0s9iY+Inu6HTE/NlV0jO9C0/NXk1FfdKL8gAxUmJyeRSU69QkXEg== X-Received: by 2002:a5d:42c7:0:b0:236:4ddd:3576 with SMTP id t7-20020a5d42c7000000b002364ddd3576mr18079744wrr.289.1666716875926; Tue, 25 Oct 2022 09:54:35 -0700 (PDT) Received: from kista.localdomain (82-149-19-102.dynamic.telemach.net. [82.149.19.102]) by smtp.gmail.com with ESMTPSA id a20-20020a05600c349400b003a6a3595edasm3023989wmq.27.2022.10.25.09.54.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 09:54:35 -0700 (PDT) From: Jernej Skrabec To: maxime@cerno.tech, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com Cc: wens@csie.org, samuel@sholland.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec Subject: [PATCH v2 2/5] iommu/sun50i: Consider all fault sources for reset Date: Tue, 25 Oct 2022 18:54:12 +0200 Message-Id: <20221025165415.307591-3-jernej.skrabec@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221025165415.307591-1-jernej.skrabec@gmail.com> References: <20221025165415.307591-1-jernej.skrabec@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221025_095438_061916_91EDCDC5 X-CRM114-Status: GOOD ( 12.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We have to reset masters for all faults - permissions, L1 fault or L2 fault. Currently it's done only for permissions. If other type of fault happens, master is in locked up state. Fix that by really considering all fault sources. Fixes: 4100b8c229b3 ("iommu: Add Allwinner H6 IOMMU driver") Signed-off-by: Jernej Skrabec --- drivers/iommu/sun50i-iommu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index 270204a6ec4a..bbc269500800 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -869,8 +869,8 @@ static phys_addr_t sun50i_iommu_handle_perm_irq(struct sun50i_iommu *iommu) static irqreturn_t sun50i_iommu_irq(int irq, void *dev_id) { + u32 status, l1_status, l2_status, resets; struct sun50i_iommu *iommu = dev_id; - u32 status; spin_lock(&iommu->iommu_lock); @@ -880,6 +880,9 @@ static irqreturn_t sun50i_iommu_irq(int irq, void *dev_id) return IRQ_NONE; } + l1_status = iommu_read(iommu, IOMMU_L1PG_INT_REG); + l2_status = iommu_read(iommu, IOMMU_L2PG_INT_REG); + if (status & IOMMU_INT_INVALID_L2PG) sun50i_iommu_handle_pt_irq(iommu, IOMMU_INT_ERR_ADDR_L2_REG, @@ -893,7 +896,8 @@ static irqreturn_t sun50i_iommu_irq(int irq, void *dev_id) iommu_write(iommu, IOMMU_INT_CLR_REG, status); - iommu_write(iommu, IOMMU_RESET_REG, ~status); + resets = (status | l1_status | l2_status) & IOMMU_INT_MASTER_MASK; + iommu_write(iommu, IOMMU_RESET_REG, ~resets); iommu_write(iommu, IOMMU_RESET_REG, IOMMU_RESET_RELEASE_ALL); spin_unlock(&iommu->iommu_lock); From patchwork Tue Oct 25 16:54:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 13019565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB6B7FA373F for ; Tue, 25 Oct 2022 16:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=W32k+P/7yk8k0hoo9tab0XZLhh+l9gnHv1EgChhgcOg=; b=PBoQm4SJkS7f8b kMECo5ac2WlHO71jO9p/zU/hJgskJrzM7d4SRVyMyZPSZErCrO9GQH56VzxxtO5hg2vPG2J5zjHgI kIywxM8tdY6H6xiIgdUX3TxaXfucm7KUM+xd39KXs2JNmGqWfmobCcPus5HLBGN6cpnoV7Hxxt7SJ AUF7g7aZXznugKk63uFtxAWQDKbUQSdSiz6TSlzI0MQ5SzdGAdlL2OuePJZnyja9gtSiMD2McXXWQ x9Bh5rroU+x5Mbt4OCBoQXlwWzLgbh3qUI29wy+uNRx7BRN7ZAxTtzampFHZJzMpkzxUGaiOHbHPz Y3cxY6LMemZjIoq8bmwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1onNCw-006MCo-09; Tue, 25 Oct 2022 16:55:18 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1onNCK-006Lz0-Eq for linux-arm-kernel@lists.infradead.org; Tue, 25 Oct 2022 16:54:41 +0000 Received: by mail-wr1-x430.google.com with SMTP id l14so14905976wrw.2 for ; Tue, 25 Oct 2022 09:54:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q3Fgy6ar1zYHVJgyinsGrfKVrX6mZaQbt8q/dXIx19k=; b=KxaheGRKnwqkzce0a2Zgx3U/pr8SwK/9NCPKKP5oFz0u5wQGk3AnnzyNdNH1vzKhNt aS38eOd7IygJ3U6NfjWm/4uSFbulrRqvzT66xYqDXJ1C2kaZH/65eWYUyeq5/VoJk2er I8ZYKO4NQ2QVVFvqc3WEE7Cg2xbbCQ/j/kMoyQre2PvipucNkplMtMdibxfa+uN7z36i /rOnVYYfwtclXaARGXp04ftjtb/U8N9lmTzZB4B3hHLUQvFH+YlrGcmgvRZjgKk/wNLX Y5ezx5boqZGMzV/tVSb8P9hlXVS/CphlLNvdyHdjOh/7KSz3pBv32zfQCxzVrkWZzlnB B7qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q3Fgy6ar1zYHVJgyinsGrfKVrX6mZaQbt8q/dXIx19k=; b=ZdtYdWWD3GBqgt3VjI7iuB5fEiNYxN+w1in/vkYmk+7F8s3L8GVH48pjCNuVTy548i qXtad7Kwj4uaPjLgRCQjxtZP3kwfJQRIKeNqx1gc0sflPX6fbqwZXKaEvcE5XfHrbjel ZiQEsvv66hCmmlzMUujmJ2s8eBS/x/owB5WFT1EihazZosfO7vnXXFoiFLgL2f48dEgX rT2tls1iqQS+ONp73z8dEgFQ4AgZcAjgLKx7uc/hbm44enDzXv1wO495d5gfDK/QbJxP 9Q9BMTNUaS1AYu4yQntpD5pdB+lIN6+xMbJ2382MN6VFO9iysu9Kar2m02jIUJaqIjvK kEFg== X-Gm-Message-State: ACrzQf0esp9v+fUfxJzis9sLAi+fsLkLX+NnfcFkMYsmJhIPmSzNuco7 VvwJnA1cGbhxQUOgOkBVeqc= X-Google-Smtp-Source: AMsMyM4mnIoUAmW2Rq4/080WHIpzCDO/JXtDEmGAjFfYXWF/GvrKNswK4DUiHI4n8ZHXPJLxCkaG+Q== X-Received: by 2002:adf:e484:0:b0:236:6a2e:154e with SMTP id i4-20020adfe484000000b002366a2e154emr9844814wrm.664.1666716876981; Tue, 25 Oct 2022 09:54:36 -0700 (PDT) Received: from kista.localdomain (82-149-19-102.dynamic.telemach.net. [82.149.19.102]) by smtp.gmail.com with ESMTPSA id a20-20020a05600c349400b003a6a3595edasm3023989wmq.27.2022.10.25.09.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 09:54:36 -0700 (PDT) From: Jernej Skrabec To: maxime@cerno.tech, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com Cc: wens@csie.org, samuel@sholland.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec Subject: [PATCH v2 3/5] iommu/sun50i: Fix R/W permission check Date: Tue, 25 Oct 2022 18:54:13 +0200 Message-Id: <20221025165415.307591-4-jernej.skrabec@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221025165415.307591-1-jernej.skrabec@gmail.com> References: <20221025165415.307591-1-jernej.skrabec@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221025_095440_573447_D3C1725F X-CRM114-Status: GOOD ( 13.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Because driver has enum type permissions and iommu subsystem has bitmap type, we have to be careful how check for combined read and write permissions is done. In such case, we have to mask both permissions and check that both are set at the same time. Current code just masks both flags but doesn't check that both are set. In short, it always sets R/W permission, regardles if requested permissions were RO, WO or RW. Fix that. Fixes: 4100b8c229b3 ("iommu: Add Allwinner H6 IOMMU driver") Signed-off-by: Jernej Skrabec --- drivers/iommu/sun50i-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index bbc269500800..df871af04bcb 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -271,7 +271,7 @@ static u32 sun50i_mk_pte(phys_addr_t page, int prot) enum sun50i_iommu_aci aci; u32 flags = 0; - if (prot & (IOMMU_READ | IOMMU_WRITE)) + if ((prot & (IOMMU_READ | IOMMU_WRITE)) == (IOMMU_READ | IOMMU_WRITE)) aci = SUN50I_IOMMU_ACI_RD_WR; else if (prot & IOMMU_READ) aci = SUN50I_IOMMU_ACI_RD; From patchwork Tue Oct 25 16:54:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 13019564 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5BA0AC38A2D for ; Tue, 25 Oct 2022 16:56:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+gjQiNFCS/k+R+SoQdaz5sWs6Bxf4u57Q3C5uRYzJ4s=; b=RJv3Son7ER8evR MjPjJEl9/Ug79dBrC2FEFC3B77S4nmIOiJWBQbZHbf73sc8Yv+UiYj7YUhayEZ0WGCBSEVc3y3ZFZ LXRDPfrYxpEL0OY3nE2STRt2/0jvfVJCYSsxQnQvmnK31k3pr2ysEaCSfgX2z/gwzzVnec3y5BP70 Oa4xEWen6aCu0aujzopb232Il+DxwBEpLuGZD6gSVE88RW1yOlnF2wbE0W2qAEnY3JIHYQLgz9LNN Dde2bn3plspYLG/e3aj2xQH+HrqAZWV/Fb/ud+sxq+eGYhBttKMUuvGIzTqzLxlyL7BPcsCGeXDg+ cmCyTuBbbFFD3iyyfmfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1onNCl-006M9n-8U; Tue, 25 Oct 2022 16:55:07 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1onNCJ-006Lzp-8u for linux-arm-kernel@lists.infradead.org; Tue, 25 Oct 2022 16:54:40 +0000 Received: by mail-wr1-x42d.google.com with SMTP id y16so11693539wrt.12 for ; Tue, 25 Oct 2022 09:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d/ULxq2EdVWZOhwK21JX/tvDkCGf2dqu3n7qEL+lTOY=; b=gWB9UysqAbqOPf2utGCOJH9LJdHOTVvaB5IzqXJ++K/yLuCOmVzCGmTWOlhFwGnNZ0 /1dY+xVgUo+QcHKWnYnpR5lT0jOKo+LhbGfj7zACigig7IiRakyNWEOebPeyBRg9NfRa gFWh5ww9Y0Jc+XhTLLpQqIOM21QcG72QsPGe+gi5I9OSY0fVe2rKCalR6BMzhJwfZ91Q Zgmp9N7XliVwx3Ml6S9CO1NA9AbKpCiYuL+qAWLMxnMXHUnEb69TTsEaOEJ0njKBXIrq NtiigBcNGVlOe3WJ7lJgbHvYDnRr3BeFTzYElFREinnm+LCJ0/Resp8Sv5GGG8mgsqVG ANjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d/ULxq2EdVWZOhwK21JX/tvDkCGf2dqu3n7qEL+lTOY=; b=J5t9Wqbrw0HODPlbX4BJStyOjcGPvq9Lioi/sXn9ttf1V9hIpQQAz+WAqYupA19Vsc WwbkKuu1RV58eydEsMIhkmA3NMjfgVWNRx2zdE/FyTfC5yRCOCaTBi8llIazyEKkiqqL jfJaiio8PMvV2h0GaOmI93x3AxK7lE6dcgLZ7mAFKKaPwxGaWdzUdcwexbkIPv7V3mYn w2DdDXKVjD2Knyt+/AsK9hp8nFKB3OddNi5H2zT2VA89FPUdmUHOitK4+b6Mu9WUirkq raXc3cojB/zbfy4nLgnzJfnLVVGuXMAmQaxbDl+CapnSja9/4/axJPrWzl+pGCSBPsZw ABRw== X-Gm-Message-State: ACrzQf3PBTMAnqhNRco2GL4emrXwZ5a55X0iNQogZBtpE4cnEVW8R1Ef 0UrD4SsDDacvbw1hsE4wey8= X-Google-Smtp-Source: AMsMyM4V89EQvtcJaplOO/9x329iSAUjR7qxmdGlVdpsRjAzRPe8F7TxA5tDAipFjnBHO1jzESd3aA== X-Received: by 2002:a05:6000:1c0a:b0:22e:5d8a:c903 with SMTP id ba10-20020a0560001c0a00b0022e5d8ac903mr25013588wrb.182.1666716878012; Tue, 25 Oct 2022 09:54:38 -0700 (PDT) Received: from kista.localdomain (82-149-19-102.dynamic.telemach.net. [82.149.19.102]) by smtp.gmail.com with ESMTPSA id a20-20020a05600c349400b003a6a3595edasm3023989wmq.27.2022.10.25.09.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 09:54:37 -0700 (PDT) From: Jernej Skrabec To: maxime@cerno.tech, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com Cc: wens@csie.org, samuel@sholland.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec Subject: [PATCH v2 4/5] iommu/sun50i: Fix flush size Date: Tue, 25 Oct 2022 18:54:14 +0200 Message-Id: <20221025165415.307591-5-jernej.skrabec@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221025165415.307591-1-jernej.skrabec@gmail.com> References: <20221025165415.307591-1-jernej.skrabec@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221025_095439_336239_31ED9BDA X-CRM114-Status: GOOD ( 11.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Function sun50i_table_flush() takes number of entries as an argument, not number of bytes. Fix that mistake in sun50i_dte_get_page_table(). Fixes: 4100b8c229b3 ("iommu: Add Allwinner H6 IOMMU driver") Signed-off-by: Jernej Skrabec --- drivers/iommu/sun50i-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index df871af04bcb..e62e245060ac 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -512,7 +512,7 @@ static u32 *sun50i_dte_get_page_table(struct sun50i_iommu_domain *sun50i_domain, sun50i_iommu_free_page_table(iommu, drop_pt); } - sun50i_table_flush(sun50i_domain, page_table, PT_SIZE); + sun50i_table_flush(sun50i_domain, page_table, NUM_PT_ENTRIES); sun50i_table_flush(sun50i_domain, dte_addr, 1); return page_table; From patchwork Tue Oct 25 16:54:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 13019566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D168CC04A95 for ; Tue, 25 Oct 2022 16:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xEA1ssdC1p01NVnjFNSu2GKXvxfBlamFp4mu1WjFEco=; b=gS3BRypwFYpnJ6 qIx00YQIbslY90jmId8WcaEtEEs5ABOJ3TeyN2MVwFXjrDkZ6fG6kJW0fldooKvlfDV2QSJWBVx42 1i5XR6wDrNfuEWAW4GvNeeIcrZ1uTiIkIw5scwA/J6TAdS+sOxNxuTIu//CZrtPweU2MyOzyPlD1d cA/4+SyT3pLKRIGvfSXRsG0o0lyhYU65J6zBIMRr3OwPXa58YE0aCSO3CRUTXBmtRCXk9+GMRsmah srusAOnjbVKuJ06KL8Mka9WSDO0xb10ISjToUDCaX7D/hI6r+MjVeuD6RLi6f6Vi6iJj7z8INWfeh 1zmk18uTaaOoEzm8zhvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1onND5-006MGc-G2; Tue, 25 Oct 2022 16:55:27 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1onNCT-006Lz0-SO for linux-arm-kernel@lists.infradead.org; Tue, 25 Oct 2022 16:54:51 +0000 Received: by mail-wr1-x430.google.com with SMTP id l14so14906969wrw.2 for ; Tue, 25 Oct 2022 09:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Wj7FhB58uMn4h8H3wgZfmSRd9vXTbsp8lRGrOrs+X1o=; b=KoO/IFDIdAddmPIJ1BG+QvpjyIUIS+dN795VoEhPKi5wfaQcbf+E+GBzzCH6fbXB/f d9ezM6PZerO2XMyIMxsSkwcP20hElLy6CA53mi4Ad70JlUoEJZ4K5wCBfivlaTzslW/j YMhNodNgw0XA0BPiiU+0Hcacb+yulPiCGfNKmvPAuKajNPunn14TvN1/MPH986ZC67w0 zkf6rSBJMR4omsaTAkmgZQtJcYGtOFewv3K43i1E5CtMwARAPVfK5Tq/KrxUNFrk7sYb 2mv3NfngdOVyfsvD7dk7CUw6njAMR0Vg70i5toRbU7IqeLnCDaRSm4G0ppSF5+EIz4O0 73lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wj7FhB58uMn4h8H3wgZfmSRd9vXTbsp8lRGrOrs+X1o=; b=rFRjl+TmVhebRoHzIriNkfWBjNjiMGnQisRG+AWhy+jYl0Xsw3d9w0F9HnRM6wNuKy 05WWxor/pR+LReGveh0+l84BEtlIpj2+S8VudCkX9naG475Vfuu94Efjln4PVcl0l05v YG2LKGaxFVGN/5YhqzFrjI+i9o6W3Gcgvy5ayUyXk5AapJHoQzRNPKZkl6HnCN5jErzk oGmzVCLccyVfkiGPCfpIPd+Y0y8Av7T3qqjkI98X136zdIkg3aCfwDc9w9JgKwnEI2ZU JS2N9zDD6MtUCX7xOMlrLfYJuNNS2l8iOtLTRr3vNPk8811BpAgGoiVi4iuZja/NcLPz 61fw== X-Gm-Message-State: ACrzQf2e4l4sXWiTIRR010eVml5aelAvl+PAsyXdgb/qfAUvxo+ZJfwl ESnOQakCSP+NZaP7+qubYa4pWh2SA4OOhA== X-Google-Smtp-Source: AMsMyM4QbdbhgbDyi34T6qfyQKp7IPL827BhF9NwQyMqQzPbUOVWRISJYasElMB6P/tEeZYiLkd+dQ== X-Received: by 2002:a5d:64c2:0:b0:22e:41b1:faf7 with SMTP id f2-20020a5d64c2000000b0022e41b1faf7mr24834767wri.428.1666716879104; Tue, 25 Oct 2022 09:54:39 -0700 (PDT) Received: from kista.localdomain (82-149-19-102.dynamic.telemach.net. [82.149.19.102]) by smtp.gmail.com with ESMTPSA id a20-20020a05600c349400b003a6a3595edasm3023989wmq.27.2022.10.25.09.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 09:54:38 -0700 (PDT) From: Jernej Skrabec To: maxime@cerno.tech, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com Cc: wens@csie.org, samuel@sholland.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec Subject: [PATCH v2 5/5] iommu/sun50i: Implement .iotlb_sync_map Date: Tue, 25 Oct 2022 18:54:15 +0200 Message-Id: <20221025165415.307591-6-jernej.skrabec@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221025165415.307591-1-jernej.skrabec@gmail.com> References: <20221025165415.307591-1-jernej.skrabec@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221025_095449_956082_1FC19A1B X-CRM114-Status: GOOD ( 14.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Allocated iova ranges need to be invalidated immediately or otherwise they might or might not work when used by master or CPU. This was discovered when running video decoder conformity test with Cedrus. Some videos were now and then decoded incorrectly and generated page faults. According to vendor driver, it's enough to invalidate just start and end TLB and PTW cache lines. Documentation says that neighbouring lines must be invalidated too. Finally, when page fault occurs, that iova must be invalidated the same way, according to documentation. Fixes: 4100b8c229b3 ("iommu: Add Allwinner H6 IOMMU driver") Signed-off-by: Jernej Skrabec --- Changes from v1: - new patch drivers/iommu/sun50i-iommu.c | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) -- 2.38.1 diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index e62e245060ac..5cb2d44dfb92 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -93,6 +93,8 @@ #define NUM_PT_ENTRIES 256 #define PT_SIZE (NUM_PT_ENTRIES * PT_ENTRY_SIZE) +#define SPAGE_SIZE 4096 + struct sun50i_iommu { struct iommu_device iommu; @@ -295,6 +297,62 @@ static void sun50i_table_flush(struct sun50i_iommu_domain *sun50i_domain, dma_sync_single_for_device(iommu->dev, dma, size, DMA_TO_DEVICE); } +static void sun50i_iommu_zap_iova(struct sun50i_iommu *iommu, + unsigned long iova) +{ + u32 reg; + int ret; + + iommu_write(iommu, IOMMU_TLB_IVLD_ADDR_REG, iova); + iommu_write(iommu, IOMMU_TLB_IVLD_ADDR_MASK_REG, GENMASK(31, 12)); + iommu_write(iommu, IOMMU_TLB_IVLD_ENABLE_REG, + IOMMU_TLB_IVLD_ENABLE_ENABLE); + + ret = readl_poll_timeout_atomic(iommu->base + IOMMU_TLB_IVLD_ENABLE_REG, + reg, !reg, 1, 2000); + if (ret) + dev_warn(iommu->dev, "TLB invalidation timed out!\n"); +} + +static void sun50i_iommu_zap_ptw_cache(struct sun50i_iommu *iommu, + unsigned long iova) +{ + u32 reg; + int ret; + + iommu_write(iommu, IOMMU_PC_IVLD_ADDR_REG, iova); + iommu_write(iommu, IOMMU_PC_IVLD_ENABLE_REG, + IOMMU_PC_IVLD_ENABLE_ENABLE); + + ret = readl_poll_timeout_atomic(iommu->base + IOMMU_PC_IVLD_ENABLE_REG, + reg, !reg, 1, 2000); + if (ret) + dev_warn(iommu->dev, "PTW cache invalidation timed out!\n"); +} + +static void sun50i_iommu_zap_range(struct sun50i_iommu *iommu, + unsigned long iova, size_t size) +{ + assert_spin_locked(&iommu->iommu_lock); + + iommu_write(iommu, IOMMU_AUTO_GATING_REG, 0); + + sun50i_iommu_zap_iova(iommu, iova); + sun50i_iommu_zap_iova(iommu, iova + SPAGE_SIZE); + if (size > SPAGE_SIZE) { + sun50i_iommu_zap_iova(iommu, iova + size); + sun50i_iommu_zap_iova(iommu, iova + size + SPAGE_SIZE); + } + sun50i_iommu_zap_ptw_cache(iommu, iova); + sun50i_iommu_zap_ptw_cache(iommu, iova + SZ_1M); + if (size > SZ_1M) { + sun50i_iommu_zap_ptw_cache(iommu, iova + size); + sun50i_iommu_zap_ptw_cache(iommu, iova + size + SZ_1M); + } + + iommu_write(iommu, IOMMU_AUTO_GATING_REG, IOMMU_AUTO_GATING_ENABLE); +} + static int sun50i_iommu_flush_all_tlb(struct sun50i_iommu *iommu) { u32 reg; @@ -344,6 +402,18 @@ static void sun50i_iommu_flush_iotlb_all(struct iommu_domain *domain) spin_unlock_irqrestore(&iommu->iommu_lock, flags); } +static void sun50i_iommu_iotlb_sync_map(struct iommu_domain *domain, + unsigned long iova, size_t size) +{ + struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain); + struct sun50i_iommu *iommu = sun50i_domain->iommu; + unsigned long flags; + + spin_lock_irqsave(&iommu->iommu_lock, flags); + sun50i_iommu_zap_range(iommu, iova, size); + spin_unlock_irqrestore(&iommu->iommu_lock, flags); +} + static void sun50i_iommu_iotlb_sync(struct iommu_domain *domain, struct iommu_iotlb_gather *gather) { @@ -767,6 +837,7 @@ static const struct iommu_ops sun50i_iommu_ops = { .attach_dev = sun50i_iommu_attach_device, .detach_dev = sun50i_iommu_detach_device, .flush_iotlb_all = sun50i_iommu_flush_iotlb_all, + .iotlb_sync_map = sun50i_iommu_iotlb_sync_map, .iotlb_sync = sun50i_iommu_iotlb_sync, .iova_to_phys = sun50i_iommu_iova_to_phys, .map = sun50i_iommu_map, @@ -786,6 +857,8 @@ static void sun50i_iommu_report_fault(struct sun50i_iommu *iommu, report_iommu_fault(iommu->domain, iommu->dev, iova, prot); else dev_err(iommu->dev, "Page fault while iommu not attached to any domain?\n"); + + sun50i_iommu_zap_range(iommu, iova, SPAGE_SIZE); } static phys_addr_t sun50i_iommu_handle_pt_irq(struct sun50i_iommu *iommu,