Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp770254lqb; Fri, 24 May 2024 12:35:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUF/ttfxrbw+8wxgZPxL7hkgji2Fs5wbM4XjgU3fnpDNRkH0d91YtHme0aIwPHMEg9imEHXJq2I1Ih71RQ/algfyHVRjOHCPnnjyc/8Ww== X-Google-Smtp-Source: AGHT+IFi9gi84fqvI+31qxS00KCyoBtNGqAdE3LShYz0EWbHVXzmL6QPatX62SqVMwjfCkAmyGuR X-Received: by 2002:a17:903:8c3:b0:1e4:c8b3:dbaf with SMTP id d9443c01a7336-1f448c24e3emr34148445ad.33.1716579314973; Fri, 24 May 2024 12:35:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716579314; cv=pass; d=google.com; s=arc-20160816; b=gccwEoywZ60/iGpf7jlQ2OXYcpW3Z089UZzn7+Hy+FDFFB+vlb6tiiWS4+/4UuCo2e zLCgs3olkDrH7T/ytGesL1v8qw2KkIdhGERyX5ZX5wkJy41V7L3hfsvJkyVnjjG69Cdi d7ecxa+PWxU8U4vZQrutLpvx813G3NhfGqiER8CCJY6p1cFgs6DCI5AHqjLQ6UTneZmG wD6U/t2x1nfq+LIJXyXVOtc3kP5b/uwyrkGyNpqrpeOZr89qvx5ebejoU9zUrGj8Us0G Li/FNs6QBaluLwk0LQc+7MrQpPuTLb90Z8ntCnJijmEzwQDfYyqh7UX1uSri/2h5wtkW jU7Q== 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=twMRxUCtZSr+seZ0b3xRB7CPy5cBgsYTAlk2ZKA97pU=; fh=4WBGQg2WmzQ0ZFXjWwaoBl/JT6mtZ3Dx8Ln5fQCua3g=; b=xF0A9Z6krUdWO4vB+Y5kYrw76KX+QN5asTSqDomGgkO0fO9IuZyRRAJsr44Xn0iESo FdfAMaryeo4NT2M51+ZNYOR7O1tw+fIykxClYyGx2xGFA5/T7hQTj4+1ULN7aMfTX75q DWsiLGg9X9OFCPTzoLUPK7xVIBqJyTUzcoVrVNwHCY/HzZUmY4rrAA2R1WCdPDi+/fwS if33BVFSJ4oVhuARawEPMURJICkZR9EVtmjapxKrfzOyIE21IG3y0fDcJ5AcTjCydQhV Y0HIqqLimPbLPP91qcDrFg0yP3FSRVwBKnxCPFPJci+og5zgD7pFAbYF0+sjhXzytK8h sngg==; 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="BrKM/aiN"; 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-189048-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189048-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c999d14si18436295ad.387.2024.05.24.12.35.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 12:35:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189048-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="BrKM/aiN"; 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-189048-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189048-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 2635DB217C4 for ; Fri, 24 May 2024 19:35:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 953B35F87D; Fri, 24 May 2024 19:35:03 +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="BrKM/aiN" Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 6F4B35BAC3 for ; Fri, 24 May 2024 19:35:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716579302; cv=none; b=OVN1GjyYh4FgdJzuxcVPRefonFJUjkyZdr8iM0axKamswltdZZ2VnNCbmz+6QHPYykgXGaXtNoYzH7Zs8ym/YOcWTrrq5z704fhDGaS1bbQirD8wfBjEJTjOVovQDtttQXQZJ5evpm4OEXbQY5fDeQSFHV4cj2B5bB17+FM/X9A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716579302; c=relaxed/simple; bh=LcaRAUpDmT9uL3/H/GEO5lBvGBVhfM/fXJ6PGiMjmGc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=ZwSBTKeDUAsSW+dXUXwM5Jycogc0wBSBpKE/pWkX6FRpvb9XL2QhH0k3cAGq5Xyl/DiHzSCMOBmmkFa6FTyFQnR5TPYehcRSwiX/5ppuBHkiXgxztDc9maN5B1WonKds0gnULNPU+zfSidLbfRPG5H7Mt3pctiVAXvag7S69sQI= 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=BrKM/aiN; arc=none smtp.client-ip=209.85.210.173 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-f173.google.com with SMTP id d2e1a72fcca58-6f966840af7so814798b3a.2 for ; Fri, 24 May 2024 12:35:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1716579300; x=1717184100; 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=twMRxUCtZSr+seZ0b3xRB7CPy5cBgsYTAlk2ZKA97pU=; b=BrKM/aiNDtMfeYYGYdcAOuudmKxVYqh6auVyu7D1KzOUlGDhda3vjdc3qx3LTQF2qY EYF3FRqyoSy0RWmhnaBzv4jWVVSJ/x2W2V5rVcxuEClUrcMnOWEi0rW/fezd8U14uu6n dngu2EAGWfcShmosdwfeYF/isIPkaPvhHjdZaF3hZ2WE625aZkN7KBTwyhe2zboNj4xX 750fMp/wKLCCkI1UGZFtzka7wTo2Y37XWtuKUJLYaKLfkDBm8n2IHeLR1tyYk3y6Qu1S 9kMCNp++M5yVfSu7wd77ZfInVnKgaOv85F05VXyi6R3IqZ+tya+De7G/kfc8+5UGdGv2 nEoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716579300; x=1717184100; 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=twMRxUCtZSr+seZ0b3xRB7CPy5cBgsYTAlk2ZKA97pU=; b=HqgCl/t/HiVaxy6QyBuVLkgwW4zDwTwhrThBQcebaXgOKl0hwKWJWbfWS08pwzJIfp X6g5KxTI9ytwtuQ5ck7Y3xR6rOUf05W+eA2g13ylYcLO/F6/PfeELw8ER075yKahqa1o vmUnzvJeIF4WgS5xK4+SZobhwBrhoyV9czYNG0wDii1aubGsVJD7oRRR4B58WAkmUxLm gpLgK3as6oy8Gfitr+eicOSxCaZEyz7svwlHLCYJsUFAYeEibp4iHmzzj8XrXEtVOlrm xUP0Q3AChcFXxyxXWxP8VZ8Sv91uWCq3fb5/6IITfnSrJFPUc6val4lz57K14yfLd0Ti 5C7Q== X-Forwarded-Encrypted: i=1; AJvYcCXkoopS33eKDKfX/kLe+OCJkKuLXjEfOvju1R91F10v16u6q0mIXbjTyd2AjJ3AzrWPXhXR445OJRAm8PH8aG1Op/xACZnQGRIAO2/k X-Gm-Message-State: AOJu0YxaHqkLIWyW+9BGwEV0PFXA8b21Wzozlij/KUPsNbJuzdnLjkr2 Jx80aPcCAc7+kk45BtwT3NzIRZ3yOKGGFYfRynRiAgzYCtmRxTPmU8rQA0sJr4o= X-Received: by 2002:a05:6a20:9485:b0:1b1:d32f:38ba with SMTP id adf61e73a8af0-1b212e17127mr2979231637.42.1716579299800; Fri, 24 May 2024 12:34:59 -0700 (PDT) Received: from tjeznach.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f8fd4d878esm1441684b3a.190.2024.05.24.12.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 12:34:59 -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 v6 0/7] Linux RISC-V IOMMU Support Date: Fri, 24 May 2024 12:34:40 -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 v5: - rebase on master - fix dc.tc.v check in riscv_iommu_iodir_update() - fix to use list_for_each_entry (without _rcu) under lock - editorial changes: comment spelling Best regards, Tomasz Jeznach [1] link: https://github.com/riscv-non-isa/riscv-iommu [2] link: https://github.com/tjeznach/linux 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 | 782 ++++++++ drivers/iommu/riscv/iommu-pci.c | 119 ++ drivers/iommu/riscv/iommu-platform.c | 92 + drivers/iommu/riscv/iommu.c | 1674 +++++++++++++++++ drivers/iommu/riscv/iommu.h | 88 + 11 files changed, 2935 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: f1f9984fdc5e37303d7180ff7a85dfecb8e57e85 -- 2.34.1