From patchwork Thu Apr 18 16:32:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tomasz Jeznach X-Patchwork-Id: 13635170 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 64889C4345F for ; Thu, 18 Apr 2024 17:46:27 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=5tbZo3RgYjr9HJag5YS40EEN1nKlFc2k5oj82Q+UVLw=; b=o8nL/5YJVzphUi VVHdVQHzbjSKAOfrzKujYntmu5EisuA+sd8MSbGarmv3VWB8EN8vSZOC5WxhaySXX9bvqz17+5i7n qXHb0OtsCMzQh39kAq9aFlsROaYnSZzCV7jqIyfAII5ZOPNvFo1yuzN8BEhDIln/dlT72KXSM2mPK ZIs0MOPB2lc7jvDKMB+UJ4Gftnn4wLal+fN5ACrGRLkQwgKbP8oV19LaSXzDHjx61TemxQwGmS76x yM8ngvrYslamyjtwLn9f1qfzp8wwzxrgk9aEtvkUtwY5UUc/GvUYJsZoUN4jnSfcnrgpbaHna6rBf FCYq5nr2zI/8GerYWHAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxVq3-00000003Ew0-04qi; Thu, 18 Apr 2024 17:46:23 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxUge-000000031Rd-04rn for linux-riscv@lists.infradead.org; Thu, 18 Apr 2024 16:32:43 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6f074520c8cso1085056b3a.0 for ; Thu, 18 Apr 2024 09:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713457952; x=1714062752; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6qw41A+dZx7I8Diykai2FpeK5mNXOqfbEJEaS+qGnKM=; b=Mvm284FNP0l1tRhQOT8YXevJyEAjzgM5J9UV/9cgxCWJMzES7fuEga/5hnl1A+JAfK 5O68wqgR6N+cGErjC1k5XSIIJLms9UVlOt7nbdtjCcbVnefosZLc94OotdrpcubWpIx8 7lNMjgTbwR1F6Lp26sqC9ulZbU5VQGArHyjXtuFEIwYCXeQObAmGRrDs6xgPdG3wRKqn R05Jgl4qy74Ycb+ESL1sHHJcWzmXup6dR8sJt1X/xeoSH2qcJhFcV8h7qzLWTiu8LB2G 3jLJEiYSZw7g6Pr/fgVNt1WGxFhGxfUClpSMpf0NSwP6YhZ+u7VzLP8Gsbchz+Ggz5vQ y3zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713457952; x=1714062752; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6qw41A+dZx7I8Diykai2FpeK5mNXOqfbEJEaS+qGnKM=; b=rtKL5e4Q0VxVDQ073ijX0lJuZWhdoJo7i3OtJ8UAEBz5mJ/SyRPY41vCJJQkAxAA2H 6fK6JnAyD45N8Jz9y8b5EiBjPMGAxdAvcF1mFsh3FXB/ZzXB4jemY50o43JdKoNhSBhi Zo4twOUh1eWsOLFfqXcgA0rBvQW4ak6JM+BddY8/VKDwlmWUj56pWfcU/3W185iDnXTW c2VhADYnNzJ2euuKN9qG8W0yOkfpmtTN/3fD/TlRRlw/amW5JOt7u8p3M7gkOTmsIP+W gmg894gSQZaI9/eX5n+cIa4yYp8M/jFfOfAC8M+iLlPvJ4/hrLaWCHHpin3LpL2+uQrg D67w== X-Forwarded-Encrypted: i=1; AJvYcCUrQ0l8K99PVIzAJfPvfbBCqi4MfF2IQ3ukjTgnjl3T9G+CUdbi2EHhyfUO/Hgo4avX+y1FmnDWAD4Cz+lzsUn72NMqMj+JeMpNTCphP3g3 X-Gm-Message-State: AOJu0YxA9lxa9R7v3EUoHSvZfB6lzXLk+BC+CWicmcbDUb5IZQdjvtWF uO/4DjTYGPGzIjKbMhBSdMuQcksjSw3hxYYjPEOufxuLswaKz6oM4vwXvZX9QLA= X-Google-Smtp-Source: AGHT+IGrx2JZaOHUbHgOAjjqs5+H2ptnSIVhy93nY5s3x5VPcvniqdkm0SstG8X7B934i3pyGqk/Hg== X-Received: by 2002:a05:6a00:3a1d:b0:6e6:9af4:409a with SMTP id fj29-20020a056a003a1d00b006e69af4409amr3933457pfb.33.1713457952604; Thu, 18 Apr 2024 09:32:32 -0700 (PDT) Received: from tjeznach.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id b19-20020a056a000a9300b006eae3aac040sm1674755pfl.31.2024.04.18.09.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:32:32 -0700 (PDT) From: Tomasz Jeznach To: Joerg Roedel , Will Deacon , Robin Murphy , Paul Walmsley Subject: [PATCH v2 0/7] Linux RISC-V IOMMU Support Date: Thu, 18 Apr 2024 09:32:18 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240418_093236_390229_C1FA147A X-CRM114-Status: GOOD ( 17.55 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , devicetree@vger.kernel.org, Conor Dooley , Albert Ou , Tomasz Jeznach , linux@rivosinc.com, linux-kernel@vger.kernel.org, Rob Herring , Sebastien Boeuf , iommu@lists.linux.dev, Palmer Dabbelt , Nick Kossifidis , Krzysztof Kozlowski , linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This patch series introduces support for RISC-V IOMMU architected hardware into the Linux kernel. The RISC-V IOMMU specification, which this series is based on, is ratified and available at GitHub/riscv-non-isa [1]. At a high level, the RISC-V IOMMU specification defines: 1) Data structures: - Device-context: Associates devices with address spaces and holds per-device parameters for address translations. - Process-contexts: Associates different virtual address spaces based on device-provided process identification numbers. - MSI page table configuration used to direct an MSI to a guest interrupt file in an IMSIC. 2) In-memory queue interface: - Command-queue for issuing commands to the IOMMU. - Fault/event queue for reporting faults and events. - Page-request queue for reporting "Page Request" messages received from PCIe devices. - Message-signaled and wire-signaled interrupt mechanisms. 3) Memory-mapped programming interface: - Mandatory and optional register layout and description. - Software guidelines for device initialization and capabilities discovery. This series introduces RISC-V IOMMU hardware initialization and complete single-stage translation with paging domain support. The patches are organized as follows: Patch 1: Introduces minimal required device tree bindings for the driver. Patch 2: Defines RISC-V IOMMU data structures, hardware programming interface registers layout, and minimal initialization code for enabling global pass-through for all connected masters. Patch 3: Implements the device driver for PCIe implementation of RISC-V IOMMU architected hardware. Patch 4: Introduces IOMMU interfaces to the kernel subsystem. Patch 5: Implements device directory management with discovery sequences for I/O mapped or in-memory device directory table location, hardware capabilities discovery, and device to domain attach implementation. Patch 6: Implements command and fault queue, and introduces directory cache invalidation sequences. Patch 7: Implements paging domain, with page table using the same format as the CPU’s MMU. This patch series enables only 4K mappings; complete support for large page mappings will be introduced in follow-up patch series. Follow-up patch series, providing large page support and updated walk cache management based on the revised specification, and complete ATS/PRI/SVA support, will be posted to GitHub [2] in the next few days. Changes from v1: This version includes major reorganization of the code related to queue and page table management, removal of all ATS/PRI/SVA features to be addressed in follow-up patch series, removal of unnecessary checks, and adoption of new interfaces for identity and paging domain allocations. Apologies for the delay in sending v2 series, and thank you for valuable feedback and patience with last patch series. Best regards, Tomasz Jeznach [1] link: https://github.com/riscv-non-isa/riscv-iommu [2] link: https://github.com/tjeznach/linux v1 link: https://lore.kernel.org/linux-iommu/cover.1689792825.git.tjeznach@rivosinc.com/ Tomasz Jeznach (7): dt-bindings: iommu: riscv: Add bindings for RISC-V IOMMU iommu/riscv: Add RISC-V IOMMU platform device driver iommu/riscv: Add RISC-V IOMMU PCIe device driver iommu/riscv: Enable IOMMU registration and device probe. iommu/riscv: Device directory management. iommu/riscv: Command and fault queue support iommu/riscv: Paging domain support .../bindings/iommu/riscv,iommu.yaml | 149 ++ MAINTAINERS | 14 + drivers/iommu/Kconfig | 1 + drivers/iommu/Makefile | 2 +- drivers/iommu/riscv/Kconfig | 23 + drivers/iommu/riscv/Makefile | 3 + drivers/iommu/riscv/iommu-bits.h | 782 +++++++++ drivers/iommu/riscv/iommu-pci.c | 154 ++ drivers/iommu/riscv/iommu-platform.c | 94 ++ drivers/iommu/riscv/iommu.c | 1441 +++++++++++++++++ drivers/iommu/riscv/iommu.h | 88 + 11 files changed, 2750 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/iommu/riscv,iommu.yaml create mode 100644 drivers/iommu/riscv/Kconfig create mode 100644 drivers/iommu/riscv/Makefile create mode 100644 drivers/iommu/riscv/iommu-bits.h create mode 100644 drivers/iommu/riscv/iommu-pci.c create mode 100644 drivers/iommu/riscv/iommu-platform.c create mode 100644 drivers/iommu/riscv/iommu.c create mode 100644 drivers/iommu/riscv/iommu.h base-commit: 0bbac3facb5d6cc0171c45c9873a2dc96bea9680