Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp73290lqm; Tue, 30 Apr 2024 13:11:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVIgBLWqGzr4ejmKOyAKWaiJAZHt9TSmmHNC0kXjd4DFZulipI2ipiE8hQv3fPJbAFi6slZVw4pqpa0CUmRunpFC1foRrzk3It+Z9ucbg== X-Google-Smtp-Source: AGHT+IEjg9WeXYvL+zKGwt6dEcyVbPrzWQdCc3QsLBzvoljYr5Ez1px2U4oBqw7kIS1KJPY+l6kM X-Received: by 2002:a05:6a00:99d:b0:6ed:1012:9572 with SMTP id u29-20020a056a00099d00b006ed10129572mr782470pfg.29.1714507874971; Tue, 30 Apr 2024 13:11:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714507874; cv=pass; d=google.com; s=arc-20160816; b=OWuybYRK+uRxtYGBzx21ShCvwWazyGboOMGLwNB9nGk3XK3VTluugsFbTInYV+wHRw D8DGEYUSd+tnTKRiaVnJdP+BU9o+sgwDylDVPgE1dv9kTBhKe/2hHsPjLb6L7dyYdpbv NF3YQf/nIIgO4Z8Vplz2GhO/nZLyo4IP1VlrKzMQ1e2dWZQ8H7kZq8NeyRmrOeG8bhA/ yk7aCr6r34uoBzwzC9ozg50juFO8p1y5C+WmivQnvqjcGtn+U4wcI+oZDcIXKqHTSdUN 7wmjEzgDQ5oLFbQiKhwMrDgQvI/GvcGMEk7zwVGpohFNUsuVmyV4JqHt+50+aCkWwNDe bXIQ== 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=3KfkX2coDIYxHK7IeteKYtlpeAwqJsH66Gz3p82MjVU=; fh=SocJJguvlH5YpOUPs+6sv6BvjfQw5YCXjFljV9SZ9aw=; b=KZB40eCo0woG8nu/sU0/6f+nonldNO315l/IGWwGTTkHMqa0EiLguKfRh1kefR2uOO k9MCb+zGqLy3u+HNGcC0tU4tITTLuauuZBaTyiwYQCe+OJWlNaA9PFXJSqEqe1zhc72t pyTQqyuLgQxPoS+FqJgQdUnT0w3XdFirvxdydidGaN+EQnW+MoBvYydhwk72yEgrAb2G dDNJNZYQ/VLRwRa0TOQAcPI1rDwFovzbOaL7qiFiZ69ApKuTRyIimghgcouKwBLnbPXB DtTVkd/7KA1RCSvaBqj5UHNlGMqUQphA0RtluTgwUiGOHMRzam5tl1qcazaAcEz4SfEM fiig==; 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=22I8+9ov; 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-164684-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164684-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 g7-20020a056a0023c700b006ea81eb1872si23158464pfc.67.2024.04.30.13.11.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 13:11:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164684-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=22I8+9ov; 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-164684-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164684-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 65018B23F8F for ; Tue, 30 Apr 2024 20:03:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3361A1BED9C; Tue, 30 Apr 2024 20:02:49 +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="22I8+9ov" Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 B786B1A38EF for ; Tue, 30 Apr 2024 20:02:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714507368; cv=none; b=mCdInLUVmuHHcn6CJl11I9cbOBeHGdih6p92dZGonNFCxZ8rgH8HoWoj/dGoxMJDRgvUIpp2mUkxRIUoFv9zjrdevHYP+c1TRCdh9eRiIAZF4apsQdyQWVVakD50kABw4BMvamJQuEYQRXaVVJu21qeYYwZcDvQMxkvuBustmx4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714507368; c=relaxed/simple; bh=LhLhw4bea4YTAJnwj6A9BWGlpcgoGr12CUOji4lNSfg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZKnWN2oYjp/QYA/dnunTjcX6YecYoFDYRa6CJdafV8lJ0MuZNZIrMb2/E57UOonO/wq3R8mjfq2PHNBQMJjO3a0AXvQkBqNN7LSywQVpm4SSraYQ2w1hMzKuWfU4LBLfaeUQznyWxctWSJgtzz3FAMM8OCZBUtORnI1hGyhYpvI= 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=22I8+9ov; arc=none smtp.client-ip=209.85.214.181 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-pl1-f181.google.com with SMTP id d9443c01a7336-1e40042c13eso42161975ad.2 for ; Tue, 30 Apr 2024 13:02:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1714507366; x=1715112166; 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=3KfkX2coDIYxHK7IeteKYtlpeAwqJsH66Gz3p82MjVU=; b=22I8+9ove3wS/TzVkSL2pG37tYaoQfZF4BABvKq0RFpfIpl8mTgaKztQEvHjcq9Cbg /mNE+bYYpLKbGCI+016+ui7rIxFDZwqBmZkc6UkAc792Flrfx0yWUjuWUbDC0N7vrvd3 Xi3lQlR/2jj/jAVgHMHwcVPzk5mI+OHfk2XKsorKbN84NtLYk0KHKoqOlv5XNrEpp4wB DrGhWHubqv78g3kG5RW5jwpXMxednx0LTKba/kv8z6hmbdTBlZPIiLNffwmpMrxvIm0E HI8C/7F9RJn+yFNheBzJVeIwbT7Fj7xBQn16Sp4qKC2+0niZwC4+/d2RcAiDTPkxG/gX QB2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714507366; x=1715112166; 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=3KfkX2coDIYxHK7IeteKYtlpeAwqJsH66Gz3p82MjVU=; b=pGh6rfIxOUAJfFelXoIQQDDfTRkg5OSP4JsTDGelJRt2UVaAriGbLMF2u3OhnKBv3X toOiFZoQUAVJIqCmZhUYEXmDiHwFrcXj/X6ue1yt2WX8sB71obRNs4B/qR7aRiNtmNiW J6YrT/I9fDCOjdCuaw+1PtGa5X6AZldWM2Sy04euzQ9vWL6ekV3yNrggyi5K1Cz/lHAO Ap5PsPKLBgKSJY+3Dsit4gbn5YGp1qrgYH9LG0i9wrf4e8RS/07t9uo1+3ESqx7Bt88R ywTA42YrfuaBH93I76UvVmTd16hpdAvG8spcn/4awxi9E3AlKukMnM3PExOw2qVaagY4 WBcA== X-Forwarded-Encrypted: i=1; AJvYcCVMdt6ggjhg8GGlR3eTH2obxT9rye4EFG87/HlWn2UgLIOm4Eh2pu2HMYC5KWAj21wtXb2BrMDoxfsFDjfW0PRsyKPWMVKKLIwvtjb4 X-Gm-Message-State: AOJu0YxzZEO4cUd7oSZ3cKcNkwQKKkRv6VWF7QWYrVOHuQ11gWDV8XMz 9wmNGOr15030ZY0O7yZKS1V/LLJUBOtmGU05V3y5MJidQy/KD0IyT+7L4D/GsXk= X-Received: by 2002:a17:903:58d:b0:1eb:3e13:ca0b with SMTP id jv13-20020a170903058d00b001eb3e13ca0bmr448656plb.37.1714507365982; Tue, 30 Apr 2024 13:02:45 -0700 (PDT) Received: from tjeznach.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id w19-20020a1709027b9300b001e435fa2521sm22809820pll.249.2024.04.30.13.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 13:02:45 -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 v3 4/7] iommu/riscv: Enable IOMMU registration and device probe. Date: Tue, 30 Apr 2024 13:01:54 -0700 Message-Id: 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. Signed-off-by: Tomasz Jeznach --- drivers/iommu/riscv/iommu.c | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 07c2bcb08afd..17dc6431fd37 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 *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->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; @@ -71,6 +126,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); } @@ -96,8 +152,16 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu) goto err_sysfs; } + 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_iommu; + } + return 0; +err_iommu: + iommu_device_sysfs_remove(&iommu->iommu); err_sysfs: return rc; } -- 2.34.1