Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp528787lqr; Wed, 5 Jun 2024 12:59:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWn98eKAyJsFDj1P3wVAaQBriMA7mltirTqTg2voXo1u+BPxw0cFo0pwkv7wrw8bS1J1OALNBAMilUu9bhG7EgcjKccMpmWANmHeaL5dQ== X-Google-Smtp-Source: AGHT+IEUkFTDcpglOkmLm09u0TD/XR7wGXVfYxgBVClV3y3cqGIQsHL2QDPFFcniqDdOWSpf+BCa X-Received: by 2002:ac2:4c19:0:b0:521:b2b5:60ea with SMTP id 2adb3069b0e04-52bab4c9bd1mr2092094e87.23.1717617544053; Wed, 05 Jun 2024 12:59:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717617544; cv=pass; d=google.com; s=arc-20160816; b=kD9NFBFoxSYBsIFFeFj16xRMsuVmoNBnxDFwPtREogyJDEr9orBfXUZT9ncNH2rTvi pYh5yo00HU3xlZydPlUlnK1p7T6CRyqeKI2K0RdnvYggB7pP39EE3vGiYKmCeiIMMaFL 0v89Sj7LQ/6AsUtJqeMmiXDphUFG9DuYWRC/SBj1TkXRqqkOnypu7dxf4jwstGokFOoh ggp7BCN+JBp0yi/SfK7m/MqE6Wf1uaLPwAB01oc7udXY6Hora3HI/KakL65v0eUALoAO HrO0mUY9pN9/1/T/O+hRBpG99RnCUDVik6jo/OsQp5JOUG9xrKIoLGxV470Gk40M+Gi7 dARQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=z4qXMlGpKFmKsrTG7a5LCbQMsXJowMadHB0xL9z/+TE=; fh=hs6jic5xjlXcIWjYLR4YQbqSptGt6a+iNGaW4f4pLdc=; b=OM4W0jcxfnXMExN9Ef+YtreSEbsMrUKMzTYb5/iaJZAXFIvqfaxKjr3cG/X/Mgb2Rx cGs8bCZ8zllb1NRvUJoKwLKgtGB4pqe1kFZJSNDuNl630GEfVwuyeON8Y8UlSygl7D9V jA2dCfbUoCaAEFux0yHYi/kuuKHWkMoueiJJcSOHKxC5rqxs/kCH6oIAWF0z4EMqvbjB BfThbWTvZY33+ou5XvLexSfbZXWdXpcik2DxXka0wFXj8InYLLbP/S6NWNFKE0BvMGCW IhhpO2ibNxvLRUuSyPiklI9k+aCaEeUurAKtJ0QTI0L7BubPIkslXWTQnxTbeXfKaqrv U7eg==; 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=DQivbzbX; 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-203135-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203135-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a690f020b53si345070666b.554.2024.06.05.12.59.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 12:59:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203135-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=DQivbzbX; 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-203135-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203135-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 88D9D1F246BC for ; Wed, 5 Jun 2024 19:59:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95A94155C99; Wed, 5 Jun 2024 19:58:07 +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="DQivbzbX" Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 1C2CB15573B for ; Wed, 5 Jun 2024 19:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717617486; cv=none; b=Ig8nRo0JI1X6+5bW5mRhhu8YIJsyTCxfL8qbqnbL+uY1ggjyYUjrQcYYwd7HSPKxepAIvFKNX4LPa6jHjseombAOk21OBqy/t+e5AP+6dfWNbzn/PVDRsc1ngIii9fO9ya6mmumvlNvXckB4LBtuLpXj5k0XZqzbVDXbUoadVhY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717617486; c=relaxed/simple; bh=AYdXzOi/+3MhvKkKsxvMYJSyqlyNTjNbRw7I9TePmTg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QuSFgq6k8T4VM9But9rVH+c1G0mWHAW5bLcHTgDioSA3pb5VTTTS7jEgUP0J72guH4G559QKhwSE8Y+y9uwuc73HPVx9I0gabywCLB1PR5uXmmCCW2nFs6CJzH8tQnqlfLVyi+nVYT+6v7I56Ir/JGxJr1MFiLaWr4zn7xHWavI= 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=DQivbzbX; arc=none smtp.client-ip=209.85.210.169 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-f169.google.com with SMTP id d2e1a72fcca58-7023b6d810bso142511b3a.3 for ; Wed, 05 Jun 2024 12:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1717617483; x=1718222283; darn=vger.kernel.org; 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=z4qXMlGpKFmKsrTG7a5LCbQMsXJowMadHB0xL9z/+TE=; b=DQivbzbX0WwmDr4VK3e9mWkOLNduiriHZIBseL74qvoWDSQyruE+UYgtQ79FgCAUkG c2+kzFLwL1e3dUvBobOFbapfX4MkxbrUN8mEoRfVYmU/zU8bj12WwiygJpgqbksLiWLE UOdhuD7sf/NtxGUrC4088Tk6xhvo/CVf23d+zuRd3+gEl/PL/YrHk+10X7UCdFrqFk+S cNt5odjig9b6O/raNVoRCDRxD87OknP+CrQuvuLPwQz89z3KkNdugjW/G6s7tVc2Sziy m0tMIcwiCl/otuSYwIKEZp5G2bIsHHIxI8P5r3Qi0ch91anLiJ7EbmnGFRhDiPbt278o 7CMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717617483; x=1718222283; 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=z4qXMlGpKFmKsrTG7a5LCbQMsXJowMadHB0xL9z/+TE=; b=VlSElDXwLJPwqJY1LMgpEnk8quoJBCIYAHmY9oQLitTv//JoenqWHkfHjNJJsFjZgz PXMfNf12bZWL/2DVojmX5MqtM3b64vvhvBFvitfacUWk4DRBqh0DUZE+GJNoRT0juYMU xw5W8vJKxXy3AqEisrLFEEhJC64ZRZ3zi/2gFMP58ZQfDYGFf7eBpfe+S3reUmql4dVS T5O3eNWJWQHCxoHPOV5Xb3ULhwqyOcQ3bHJlH1CDsINWvCcxXYclVN4sAYRINYLk4txw VDqHWWqu/BlBiKx9TomnhduKwuEq7NKf13vA1yviuLWuK0JewPNQp7rZxfibFJOh4GGL lLJw== X-Forwarded-Encrypted: i=1; AJvYcCVP+AKYYJmL4hNnb2YHTlWgeuYfQtqCpuVrBpdJ7mBZAk+cqJtdWcRjLLaov89czyqS8IXv97NO++dgCNQpmDr91SgRA3Pyc9vWdvx4 X-Gm-Message-State: AOJu0YzJYmR2qzbb78Q6CAI1Ff1kqJI9yoWmsOzvS5e4IqnYkiUwGLIb E6AWujqXqlYXeqgonMFMs4OJ66uUtWf/3QMTkE1yK0oX0A8bDUCmypAAPVw5Esk= X-Received: by 2002:a05:6a21:819f:b0:1ac:f796:963c with SMTP id adf61e73a8af0-1b2b7177e4cmr3669852637.56.1717617483430; Wed, 05 Jun 2024 12:58:03 -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.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 12:58:02 -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 , Lu Baolu , Zong Li Subject: [PATCH v7 4/7] iommu/riscv: Enable IOMMU registration and device probe. Date: Wed, 5 Jun 2024 12:57:46 -0700 Message-Id: <530cd10360e180a3b8303319ac40a998312e02b0.1717612299.git.tjeznach@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Advertise IOMMU device and its core API. Only minimal implementation for single identity domain type, without per-group domain protection. Reviewed-by: Lu Baolu Reviewed-by: Zong Li Signed-off-by: Tomasz Jeznach --- drivers/iommu/riscv/iommu.c | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 223314f7ed0a..c54088bf138f 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "iommu-bits.h" #include "iommu.h" @@ -36,6 +37,60 @@ static void riscv_iommu_disable(struct riscv_iommu_device *iommu) riscv_iommu_writel(iommu, RISCV_IOMMU_REG_PQCSR, 0); } +static int riscv_iommu_attach_identity_domain(struct iommu_domain *iommu_domain, + struct device *dev) +{ + /* Global pass-through already enabled, do nothing for now. */ + return 0; +} + +static struct iommu_domain riscv_iommu_identity_domain = { + .type = IOMMU_DOMAIN_IDENTITY, + .ops = &(const struct iommu_domain_ops) { + .attach_dev = riscv_iommu_attach_identity_domain, + } +}; + +static int riscv_iommu_device_domain_type(struct device *dev) +{ + return IOMMU_DOMAIN_IDENTITY; +} + +static struct iommu_group *riscv_iommu_device_group(struct device *dev) +{ + if (dev_is_pci(dev)) + return pci_device_group(dev); + return generic_device_group(dev); +} + +static int riscv_iommu_of_xlate(struct device *dev, const struct of_phandle_args *args) +{ + return iommu_fwspec_add_ids(dev, args->args, 1); +} + +static struct iommu_device *riscv_iommu_probe_device(struct device *dev) +{ + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct riscv_iommu_device *iommu; + + if (!fwspec || !fwspec->iommu_fwnode->dev || !fwspec->num_ids) + return ERR_PTR(-ENODEV); + + iommu = dev_get_drvdata(fwspec->iommu_fwnode->dev); + if (!iommu) + return ERR_PTR(-ENODEV); + + return &iommu->iommu; +} + +static const struct iommu_ops riscv_iommu_ops = { + .of_xlate = riscv_iommu_of_xlate, + .identity_domain = &riscv_iommu_identity_domain, + .def_domain_type = riscv_iommu_device_domain_type, + .device_group = riscv_iommu_device_group, + .probe_device = riscv_iommu_probe_device, +}; + static int riscv_iommu_init_check(struct riscv_iommu_device *iommu) { u64 ddtp; @@ -74,6 +129,7 @@ static int riscv_iommu_init_check(struct riscv_iommu_device *iommu) void riscv_iommu_remove(struct riscv_iommu_device *iommu) { + iommu_device_unregister(&iommu->iommu); iommu_device_sysfs_remove(&iommu->iommu); } @@ -99,5 +155,15 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu) return dev_err_probe(iommu->dev, rc, "cannot register sysfs interface\n"); + rc = iommu_device_register(&iommu->iommu, &riscv_iommu_ops, iommu->dev); + if (rc) { + dev_err_probe(iommu->dev, rc, "cannot register iommu interface\n"); + goto err_remove_sysfs; + } + return 0; + +err_remove_sysfs: + iommu_device_sysfs_remove(&iommu->iommu); + return rc; } -- 2.34.1