Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp528903lqr; Wed, 5 Jun 2024 12:59:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWZY25WgujZi0W2voi1W10YltpM8EMyk0FURBpkPWQVl0HCGZz/tin1uxTGkm4mjbTiXCjPwRQD84aBUbtbcsRjdHvQIrWKZU7PneeE7Q== X-Google-Smtp-Source: AGHT+IHND+yL7gb6mjh+21XieoTqk2aQhXPSe9Hy9mLr8Ts2MyE1sIXaZW7+DOxMMjB+fm8/MAgo X-Received: by 2002:a17:903:228d:b0:1f6:2623:7077 with SMTP id d9443c01a7336-1f6a59041d4mr37626635ad.12.1717617559952; Wed, 05 Jun 2024 12:59:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717617559; cv=pass; d=google.com; s=arc-20160816; b=lIs/z1nP9AO6Qy7zIZm0poU0Q3RsFcXJJRyOfVhsVEnZxwxtTNIUiSVvV74n2yyOiH 2+Lm60DPbl0j/X35OKWNJIIiAWYhu8LbSVugldWwm9HYrM3qgjgB14+LhAICqE4oER7L W1PpJsvGmfJaJFKTFYyVZh8Ma/NyHhHbklxLRlqSsRyvb7LHk82WZnu/s8IK2kv2viag WXPkc0y8kxgNnMWMyPCIKQmOczKsHExBzlSbry0ZKT/d8z80/fyDzfk7XUborCKqUoi2 553J9BU3yHD2lm6pCfB+/Lr7lKIpm12X5aBnFHanSFP7HZMXbt+U2uPfgq1GS3G7DnP0 CDYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=ISuOcjK6nJKqnAu/IEdqzzoElkUOKEX7y0pHx2W7vds=; fh=ac5EG4L4V6kQW1CtFYMhyrzBps8J8lrUNGB4u+kf1xE=; b=VitA0bHvgdF+qKCrVc8+UlSXDRMEo0IeqB3sewx8sX4y4tgjrgy60zPV7Uluie3pZ2 i/2r+MYIPR/ChaO8IRX1TKV3ASGuzVXqPALHDBbrG+5HtYPW3D8KYUFALOwFtz6WrGWi 9w+bR7hpCU5lICYLTpLvpsELNpmW8ADxRsMghiGJjATEf7eK2Uqe4vTsKZmLq4KrrVuQ QvylnSsNcULTIOvLwQt2+krBJ+HB2D+n/AoiMGWX/e7qLo5nNbMr8904tyB53Vpy73ik qPR+2xIFepVBbfmDvQXkUG5Q/Nwr4rWBf1yDIX2FQHxLkHcnebHRxxKmC6qTutGY1XhT GRjQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=R0DrYBez; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-203131-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203131-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f671fb03e8si6678565ad.592.2024.06.05.12.59.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 12:59:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203131-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=R0DrYBez; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-203131-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203131-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 65D6A28727B for ; Wed, 5 Jun 2024 19:58:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3A3915535F; Wed, 5 Jun 2024 19:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="R0DrYBez" Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 239EB282FE for ; Wed, 5 Jun 2024 19:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717617478; cv=none; b=TfE1AN6aKiav9E+1hQC9R+AwOysbsNhrEi36UKYCFU7LJnW6C7LHyQxQMhiWiuLEKCq9wuluArK4imUOSu1WLbPL4F/TikVIlizkoZNHdQV5eseAgkuYYRp/vHV4c7H8zoQ34Wb8LrUEPNBpxrULO91sJ3QT2+S1V4r84d9sAsE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717617478; c=relaxed/simple; bh=fYJBLJlZl9zT4F1JeeL+BHFvL4WZ1tU5L3j8W45umK0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=jil5bZ5lEfsR4CJTGree6OxKkIcijLwy5yKhbEYYply0zewaTyDQqcu4Ca53/Sqwh4wYOH+nCck0/bvkTotEx9bi4E7Kb/BzCn4wqvBosF8kmEW5+n5duk2cuaKgELEi1kZcYPLoNliiEku0YXvMaX/ArK5Cs5mhUT4E3pKeyd4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=R0DrYBez; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-702555eb23bso147841b3a.1 for ; Wed, 05 Jun 2024 12:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1717617476; x=1718222276; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ISuOcjK6nJKqnAu/IEdqzzoElkUOKEX7y0pHx2W7vds=; b=R0DrYBezj1DrCUZivcdEiMqYKArw/kREkiKTGJk28xvWf2PNLzMFhzb6W92Z4peH77 SqSDYfEr4yN8gyxwJ1v9dpOusnvL2yjD6TGf0fpcff5Y+po8kxQ8o7kLXnTK0A9mIxh4 2CrTkmXV5npUp46Fo3jfbqicrANmUupltoh9VeWwhstSvbGwRqlRDSbU5npT1GVBFzWM HnJpQQg/3HSjNfJ3smhpZA4B4eqTSTEMS8et1L3ZIsq1YxVnoTsECIvIg8PNVLwI5hja 1YXDTZYP6cj/0RXmJCnTlGDjd1zlZdbYBjlPrOENQxSkPZnNAlyy2kbfAp8S2TA0W0W5 8YFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717617476; x=1718222276; 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=ISuOcjK6nJKqnAu/IEdqzzoElkUOKEX7y0pHx2W7vds=; b=LesW8C368bmQ1lTxOUBSPNCOWdkR3QMa1+MooJuI9LxLpLPRxryuo1C4wOlTY3v3m9 +4alGne6HsUh7rWCuVXcAkbTITcqSnzhXxfr2Wa6sKhFM738DQlJQHsDVoQokSAptP20 RkgPhZg0Mpn/FEER/O9x7MCQ6VQhsVxO0SlgSdQjFURr7BY7w6X4blko6fD/YVmVPgsX 64dQy3KtKA1vC9KgIgvOoYl4KQvhAxj096Sg0KRAs/4XLmxHMz8ADG1l87XaaHMm607q ticwNNRmj2g70rjLxTKULoN8VS1RKCJFQdIbG+LjB6OqyHp8wsWjMj8j56G0XKLDcSQf ObmQ== X-Forwarded-Encrypted: i=1; AJvYcCXrOF1dEPfAHiqe0C6/K6GEc+X3JbLqTq1SBushWNX6QsLR65cHvwngqii0IPbrmaJQWr8DexOQsKJUFmVjRvdmWTlyZw42knlRJuTQ X-Gm-Message-State: AOJu0Yx88toeFUJ8V9W3+ddnO/VohcHwcsno0A4rDAyTZDUyde6e6zjP EA/I5evdv6ymIJO09AiLR/5iKbsosKRKC3mT7XuaIQy3+SXfMTN18fXJedvoDgY= X-Received: by 2002:a05:6a20:9492:b0:1b1:f0d4:71b6 with SMTP id adf61e73a8af0-1b2b7186cf0mr3529279637.54.1717617476365; Wed, 05 Jun 2024 12:57:56 -0700 (PDT) Received: from tjeznach.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70244900ee9sm8664209b3a.124.2024.06.05.12.57.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 12:57:55 -0700 (PDT) From: Tomasz Jeznach To: Joerg Roedel , Will Deacon , Robin Murphy , Paul Walmsley Cc: Palmer Dabbelt , Albert Ou , Anup Patel , Sunil V L , Nick Kossifidis , Sebastien Boeuf , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, iommu@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux@rivosinc.com, Tomasz Jeznach Subject: [PATCH v7 0/7] Linux RISC-V IOMMU Support Date: Wed, 5 Jun 2024 12:57:42 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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, using highest page-table mode advertised by the hardware. This 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]. Changes from v6: - rebase on v6.10-rc2 - editorial changes in iommu-bits.h addressing Drew's comments - fix IOVA length check in riscv_iommu_iotlb_inval() Best regards, Tomasz Jeznach [1] link: https://github.com/riscv-non-isa/riscv-iommu [2] link: https://github.com/tjeznach/linux v6 link: https://lore.kernel.org/linux-iommu/cover.1716578450.git.tjeznach@rivosinc.com/ v5 link: https://lore.kernel.org/linux-iommu/cover.1715708679.git.tjeznach@rivosinc.com/ v4 link: https://lore.kernel.org/linux-iommu/cover.1714752293.git.tjeznach@rivosinc.com/ v3 link: https://lore.kernel.org/linux-iommu/cover.1714494653.git.tjeznach@rivosinc.com/ v2 link: https://lore.kernel.org/linux-iommu/cover.1713456597.git.tjeznach@rivosinc.com/ 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 | 147 ++ MAINTAINERS | 8 + drivers/iommu/Kconfig | 1 + drivers/iommu/Makefile | 2 +- drivers/iommu/riscv/Kconfig | 20 + drivers/iommu/riscv/Makefile | 3 + drivers/iommu/riscv/iommu-bits.h | 784 ++++++++ drivers/iommu/riscv/iommu-pci.c | 119 ++ drivers/iommu/riscv/iommu-platform.c | 92 + drivers/iommu/riscv/iommu.c | 1677 +++++++++++++++++ drivers/iommu/riscv/iommu.h | 88 + 11 files changed, 2940 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: c3f38fa61af77b49866b006939479069cd451173 -- 2.34.1