Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp766309lqo; Fri, 17 May 2024 00:20:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVRA/zaHef9+LkwE2/2j3tMMdVDSiQcZpnAvGJaE+9B3va4C5a0n+IxT87dVTB3T6HRuNcofGxKSrj25KtweaLIxf1QJ70wKBUS+yxU9w== X-Google-Smtp-Source: AGHT+IFJwAZNfZLxn03kmgWXNqwPMwpO86hjrSbtcEIoUdo1Q9rxfipzXUPheYbi99F12jPAGW7/ X-Received: by 2002:a05:6870:1182:b0:229:e422:4ff9 with SMTP id 586e51a60fabf-24172a77948mr17912395fac.18.1715930410140; Fri, 17 May 2024 00:20:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715930410; cv=pass; d=google.com; s=arc-20160816; b=tB9NsEG5jJBrjhRP9H4hphh63a0Y3o0jyNtCwLAPW2FjCld1ninMSohm9M8oithvW5 X90kfPxvtlkdALT1A9rATnKobBTuWMMiwPKt3Nvp6VUmX7DDbmoBqVcNxKjTnbZJ9XoV bce/TiiscdVNGdvEkMY6IjUVOEXasmI7Joi1t8HvXqbtXJ2HbvzOTY8rETCBqQz0Hb/i KeFuStqZ1KWBDCPC7oDP0M2YUkwEfObKAkJpjjjdl0Nxlz4IzXGnDTpAveHdGoJcB0Zs guIBSelxtAIqIU+1WEpdtkKMkuC3A/85PzXdXxDWxl0yz7+CI8EVNkrAykwGtW2HyVeG dsZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=DARwQ7xcLW9SgOpwsz1tepc/1IVi/5Qc1nde5sSyF/U=; fh=3a8U1uqdibIoY77rgVuSrKY8+he7ctVAMNpIQUSczCg=; b=jkaUj0KuesCk+r160/ktNbm4EvRnc5OK97X0M92Z5R8dVJ9csRfgAvIidpeOdHOdB/ S3Rl0eBu5FUYh8oZaQevQODN+QgyrwM47mq2DDJqnpeCWTwFq40it+gFqBw59D9NOuSk PG8iREHiBWGCHac1O8L+YRR11xJxaZ6KzT0Ajm0V4DOTEhtFPmST42lmRAPkMKSkRLBb vOCAWjXt0wyS8JD90mYwTxC16y5ZzFpeQ8suzJ0K1+Oab706u2cc6c1beedjOXVCc8Mk HNbC/TUARK6ZnZpdorYEpi2GGkNwz3+QcirBgRTNZrC8TTnriS+4GqYOTIlBGvK1Ptz3 lJ8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=JiHkGtGC; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-181786-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181786-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2b42180si13307657b3a.338.2024.05.17.00.20.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 00:20:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181786-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=JiHkGtGC; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-181786-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181786-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com 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 6762EB210F2 for ; Fri, 17 May 2024 07:20:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1BD017552; Fri, 17 May 2024 07:20:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="JiHkGtGC" Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (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 6C887168C4 for ; Fri, 17 May 2024 07:19:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715930400; cv=none; b=c/u8dz417smx8goCyeAxFGzbK0szDD7Tr58qUphpoHmPSnBG/4O2QotfuDSr81algJ8M80kRyh2xbfb2Qakb9jfJwXu8zvM8p1+dZRTy1zG/Zn3fgX5pDwPJfS+oq5EAhJGRUR0tRk06g85mrQ33530PO8uVxI7KXmZROFDeLXs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715930400; c=relaxed/simple; bh=VPdVtsCdvH0FWtAzjEnwbG4aKW0bLBPevKsTmJFxsLQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=YR/MqaJlHeHkAXINmEbiPPLszj6BoH03XLsFp/dHGkSMyAlhozkj0R7py5WV8afEgVsJfaTD2y+nMr1eF1XZOoO4VWC8mB4JGgD5YuxVLg79bfQcfMNstRsEPFMGD2iuGu6zGkMdgQtxozvLe1tPcpXJBLMkIBRyli4LWQFO2uU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=JiHkGtGC; arc=none smtp.client-ip=209.85.166.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-7da04b08b82so5246439f.0 for ; Fri, 17 May 2024 00:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1715930398; x=1716535198; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DARwQ7xcLW9SgOpwsz1tepc/1IVi/5Qc1nde5sSyF/U=; b=JiHkGtGCwSU1Vz/XfBPZPfzwKoadUiYN9oZG9igGduOUDhkcGOy/+Wv6ikiiL8TPYu e6qcY7KwiU7bH/bqpRCygjoMu2+FHh5RVLghvtb4XbZlJBHgtFc1IbOB+0ZLkd/PfT/k +1eQTY2AfMQPzIlWwjqM8KTX2Y8cr2fbASPC0keVnCJNCXT3+Q71jjRznpbhzwmoxwn1 1fv1EV4c9v/4HE7EH0CQFORDNK9dBJtk2WX5wqidfqmMPMrlVAess3/eJAWMh6qhKFVp c+C1kreFBbavigdD95j6w6T7ON/prBGmuhADmawd4mlLkJqsBJ66e0uOMr7JyNqA9VmX KjdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715930398; x=1716535198; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DARwQ7xcLW9SgOpwsz1tepc/1IVi/5Qc1nde5sSyF/U=; b=s52A1ULUQy6cyhiXLEs0C3E28sXpBSiCfY7VsChm9cS1sIldZJNe4cMQAhOXVFITdX zKskuxNo4Z0FUXDu95b22mc1TQDPro5xdarrZY0i3HGS4XjbQTFEA32KzrrhgI9SY3iw 0M4ogwuwYnYQxm+ns8AYVvTR0ULO7wh1tabhE0mgMVFZBXVy1WXIvYnkpPbOEybfYdgc mknrdiLAkNOCTNXDY2J7nxAFcnajyYyWHj1IKT8JKkwTXzPbes9NV4EAuTXDYL9CsuNK rX0NNvuqaAgunRwz6a1TJpoV2pHwBhbIrnpQoUVV1+/zxR5UiCc5SsQsFgR2J0RwhoHx BGSw== X-Forwarded-Encrypted: i=1; AJvYcCWl7E5t67k5Xn03OGyVEt0+vUojA0aUApp1i18KeRoJC+p0LjglHD5f11STNnaQVKBMXFiTDRbPgho7pyapCowYePHNOsV1CfIe/OIB X-Gm-Message-State: AOJu0Yw/tzYsNRi7AkVMhe40OeqqT966UlEQe3dmuudu5syWGszxg3Ax BKO1pYyplAc2eUG+tMCWS6e6aTDn6er5M+zhs5ekkCMVBXa2rJXUVDMDatLmpbfk5REER4q6zF2 N35RIC0aeuBYt0ZUJheCcW/v4ykmox2yEhWbXCA== X-Received: by 2002:a6b:7f42:0:b0:7e1:839e:5ab3 with SMTP id ca18e2360f4ac-7e1b51ba8a6mr2350130739f.6.1715930398577; Fri, 17 May 2024 00:19:58 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <518a4b0bf651707a9508c169fe3868e669ec2c6d.1715708679.git.tjeznach@rivosinc.com> In-Reply-To: <518a4b0bf651707a9508c169fe3868e669ec2c6d.1715708679.git.tjeznach@rivosinc.com> From: Zong Li Date: Fri, 17 May 2024 15:19:48 +0800 Message-ID: Subject: Re: [PATCH v5 4/7] iommu/riscv: Enable IOMMU registration and device probe. To: Tomasz Jeznach Cc: Joerg Roedel , Will Deacon , Robin Murphy , Paul Walmsley , Anup Patel , devicetree@vger.kernel.org, Conor Dooley , Albert Ou , 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, Lu Baolu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 15, 2024 at 2:17=E2=80=AFAM Tomasz Jeznach wrote: > > Advertise IOMMU device and its core API. > Only minimal implementation for single identity domain type, without > per-group domain protection. > > Reviewed-by: Lu Baolu > 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 3c5a6b49669d..b8e0e4b62585 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_dev= ice *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 =3D { > + .type =3D IOMMU_DOMAIN_IDENTITY, > + .ops =3D &(const struct iommu_domain_ops) { > + .attach_dev =3D 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_phan= dle_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 =3D dev_iommu_fwspec_get(dev); > + struct riscv_iommu_device *iommu; > + > + if (!fwspec || !fwspec->iommu_fwnode->dev || !fwspec->num_ids) > + return ERR_PTR(-ENODEV); > + > + iommu =3D dev_get_drvdata(fwspec->iommu_fwnode->dev); > + if (!iommu) > + return ERR_PTR(-ENODEV); > + > + return &iommu->iommu; > +} > + > +static const struct iommu_ops riscv_iommu_ops =3D { > + .of_xlate =3D riscv_iommu_of_xlate, > + .identity_domain =3D &riscv_iommu_identity_domain, > + .def_domain_type =3D riscv_iommu_device_domain_type, > + .device_group =3D riscv_iommu_device_group, > + .probe_device =3D 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_d= evice *iommu) > > void riscv_iommu_remove(struct riscv_iommu_device *iommu) > { > + iommu_device_unregister(&iommu->iommu); > iommu_device_sysfs_remove(&iommu->iommu); > } > > @@ -95,5 +151,15 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu= ) > return dev_err_probe(iommu->dev, rc, > "cannot register sysfs interface\n")= ; > > + rc =3D iommu_device_register(&iommu->iommu, &riscv_iommu_ops, iom= mu->dev); > + if (rc) { > + dev_err_probe(iommu->dev, rc, "cannot register iommu inte= rface\n"); > + goto err_remove_sysfs; > + } > + > return 0; > + > +err_remove_sysfs: > + iommu_device_sysfs_remove(&iommu->iommu); > + return rc; > } Reviewed-by: Zong Li Thanks > -- > 2.34.1 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv