Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1780040rwo; Wed, 2 Aug 2023 22:23:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlHw8bbepqVZOUS8Km9EYxT+uKlyNVcXcj4Rd7xW20br0XmQgGRRiqWsh4Lnq2Mz5iycmXk1 X-Received: by 2002:a05:6512:3c83:b0:4fd:da95:6f39 with SMTP id h3-20020a0565123c8300b004fdda956f39mr7381793lfv.68.1691040219883; Wed, 02 Aug 2023 22:23:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691040219; cv=none; d=google.com; s=arc-20160816; b=a49E2RlmyEv4eVpDhWmxgYJ9So0gBFtawuM0/y5m04nYjXCKqWuhzRnL1atX6hcObR vVnpcPDpqGTosQQWUPtGvBJUxua9yiSf6Oxq+M5N/MiN6kqp5J2ryzv0f6UHSxiWFhZE 7Jq81b0G3QGeTqg6CWruf+Vqv29iRW1Rr/5ESXTF6idlofJbwchXivxnCZ1PQyoJQTmz +ciz1yJ02c5CTFNHTuVMzProqX9R7F++k22QG79Mv1uB2yQ5wv+lfRYXaKJT68Q1Nahu 3ofW1kl+OyccUIlPzLW4+xcF+P2EEwxFDRS5QfTIyheN4OfWjhWcf4eJr7kSyYFfU76j +t4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5XezimV1as/cKuTMyLJfYIpzABwFXYSrbRVNfnuICdU=; fh=mKfyWPDLNt63b4x10yZlJ3I4atEj/UBaPo0F9StBEvQ=; b=o4nphIKIjkGKlDT6DPQBsYafTn+Wn6i5lfSTp+fldRdD0MkNV01kVO5spj5gHDrRWw FRXOf6fhN0WweZQtp3BYUjqMgSLODToSPMvoJVAiciP63ypn2tOrkCxSdfnMld0IsXwi ygHERvWS+E9fDsf1eS9TTLZ90dDB09x2/g9Ue+iX/PzlyFIpgSFtNBnqXEulEEs8A0WY WHQzwPYjYWC4Zx4SxJlr/tR2xAcD/hYB+mGAJE3xYI52wcoP3FDT36tsfVAX3wVoQ0hP Q2puFJXXtVwY6LBPaioiwSVGameSKQiDczfOtCCw28t/DLoC6tEuJom3Cr7Rwl1sdUPy 0gkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=giOWK51D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a05640202cc00b0051dd30d53a5si3499884edx.386.2023.08.02.22.23.16; Wed, 02 Aug 2023 22:23:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=giOWK51D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231591AbjHCDha (ORCPT + 99 others); Wed, 2 Aug 2023 23:37:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231204AbjHCDh3 (ORCPT ); Wed, 2 Aug 2023 23:37:29 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E51626B2 for ; Wed, 2 Aug 2023 20:37:28 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-34941081235so1892655ab.1 for ; Wed, 02 Aug 2023 20:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1691033847; x=1691638647; 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=5XezimV1as/cKuTMyLJfYIpzABwFXYSrbRVNfnuICdU=; b=giOWK51Dhn9vReA6OJfd8zvKnuve/uokt8ax23zbCVAwmmR36s9yVrixUyaVE4JA7D oWS+jn9gNn+g8OAAVMQNVW+gzShA5OHjUhoJhM7ZkkoKfPI8kT643pso7Dn7dXLQ0fD8 MtD+unY09yWthQYKv4JKiELGU9AbHbs7CIQJUeYXurtQyg3KeSegehAPAiIjicbya9Wu btmRsfa0OtDeg99VO+jVo3Cp2FbYCph1ACEm7RB+66jKoVJzhqe0itR5GEp/LrE9Vqzy ccuMlaOKScPTnpuspxvUA/6DSzjmypFuCndoiTNyhItlnwGtVoz7lisoyGaokTQLk79b PaqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691033847; x=1691638647; 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=5XezimV1as/cKuTMyLJfYIpzABwFXYSrbRVNfnuICdU=; b=kf/3de8eKnF+ud2ZGRIAF074zqRjEcv+FL61BEHIJEoSgPGPXxVD3eTFaFwuQ+twBM NAwq+psw1NZ632DMN6eB5FFiLdAtMLw1PpjlRH/OvwYLYg/cB8kXVaWtRgAW/owqlG3t jMS2QFswqEOEczQgdXpdTNvqRztcsUB4orK1MsING5OTIHueZtqrIFOVlgYyrwS9H9Ec Si2RORviBCtpdkIJ9pp0dX8YaL+r4mIPnsDaFRGqJKrH4dM+xMetuYz6gYvXdkGlDRLR LbQ21DXLDGQcbPJ8Mv/RzYzMcal4OIR2yn+DTslwe1wUNshomXqoWh/k7eTKk6zmqaaH 7yVw== X-Gm-Message-State: ABy/qLZ/2cGTFNGxXrcxPUndFf/w/VMHkc+oQIH5SkrDuARyVCqBsxZR vCZxh+66G5mBafRbKg+oMaU7Tc04Z2SvLstQgZmPVg== X-Received: by 2002:a05:6e02:2163:b0:345:dcc1:a1c4 with SMTP id s3-20020a056e02216300b00345dcc1a1c4mr18872255ilv.4.1691033847682; Wed, 02 Aug 2023 20:37:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Zong Li Date: Thu, 3 Aug 2023 11:37:16 +0800 Message-ID: Subject: Re: [PATCH 01/11] RISC-V: drivers/iommu: Add RISC-V IOMMU - Ziommu support. To: Tomasz Jeznach Cc: Joerg Roedel , Will Deacon , Robin Murphy , Paul Walmsley , Anup Patel , Albert Ou , linux@rivosinc.com, linux-kernel@vger.kernel.org, Sebastien Boeuf , iommu@lists.linux.dev, Palmer Dabbelt , Nick Kossifidis , linux-riscv@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 3, 2023 at 4:15=E2=80=AFAM Tomasz Jeznach wrote: > > On Thu, Jul 27, 2023 at 7:42=E2=80=AFPM Zong Li wrot= e: > > > > On Thu, Jul 20, 2023 at 3:34=E2=80=AFAM Tomasz Jeznach wrote: > > > > > > +static int riscv_iommu_platform_probe(struct platform_device *pdev) > > > +{ > > > + struct device *dev =3D &pdev->dev; > > > + struct riscv_iommu_device *iommu =3D NULL; > > > + struct resource *res =3D NULL; > > > + int ret =3D 0; > > > + > > > + iommu =3D devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL); > > > + if (!iommu) > > > + return -ENOMEM; > > > + > > > + iommu->dev =3D dev; > > > + dev_set_drvdata(dev, iommu); > > > + > > > + res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); > > > + if (!res) { > > > + dev_err(dev, "could not find resource for register re= gion\n"); > > > + return -EINVAL; > > > + } > > > + > > > + iommu->reg =3D devm_platform_get_and_ioremap_resource(pdev, 0= , &res); > > > + if (IS_ERR(iommu->reg)) { > > > + ret =3D dev_err_probe(dev, PTR_ERR(iommu->reg), > > > + "could not map register region\n"= ); > > > + goto fail; > > > + }; > > > + > > > + iommu->reg_phys =3D res->start; > > > + > > > + ret =3D -ENODEV; > > > + > > > + /* Sanity check: Did we get the whole register space ? */ > > > + if ((res->end - res->start + 1) < RISCV_IOMMU_REG_SIZE) { > > > + dev_err(dev, "device region smaller than register fil= e (0x%llx)\n", > > > + res->end - res->start); > > > + goto fail; > > > + } > > > > Could we assume that DT should be responsible for specifying the right = size? > > > > This only to validate DT provided info and driver expected register > file size. Expectation is that DT will provide right size. > > > > > +static struct iommu_domain *riscv_iommu_domain_alloc(unsigned type) > > > +{ > > > + struct riscv_iommu_domain *domain; > > > + > > > + if (type !=3D IOMMU_DOMAIN_IDENTITY && > > > + type !=3D IOMMU_DOMAIN_BLOCKED) > > > + return NULL; > > > + > > > + domain =3D kzalloc(sizeof(*domain), GFP_KERNEL); > > > + if (!domain) > > > + return NULL; > > > + > > > + mutex_init(&domain->lock); > > > + INIT_LIST_HEAD(&domain->endpoints); > > > + > > > + domain->domain.ops =3D &riscv_iommu_domain_ops; > > > + domain->mode =3D RISCV_IOMMU_DC_FSC_MODE_BARE; > > > + domain->pscid =3D ida_alloc_range(&riscv_iommu_pscids, 1, > > > + RISCV_IOMMU_MAX_PSCID, GFP_KE= RNEL); > > > + > > > + printk("domain type %x alloc %u\n", type, domain->pscid); > > > + > > > > Could it uses pr_xxx instead of printk? > > > > Absolutely, fixed here and elsewhere. Also, used dev_dbg wherever applica= ble. > > > > + > > > +static int riscv_iommu_enable(struct riscv_iommu_device *iommu, unsi= gned requested_mode) > > > +{ > > > + struct device *dev =3D iommu->dev; > > > + u64 ddtp =3D 0; > > > + u64 ddtp_paddr =3D 0; > > > + unsigned mode =3D requested_mode; > > > + unsigned mode_readback =3D 0; > > > + > > > + ddtp =3D riscv_iommu_get_ddtp(iommu); > > > + if (ddtp & RISCV_IOMMU_DDTP_BUSY) > > > + return -EBUSY; > > > + > > > + /* Disallow state transtion from xLVL to xLVL. */ > > > + switch (FIELD_GET(RISCV_IOMMU_DDTP_MODE, ddtp)) { > > > + case RISCV_IOMMU_DDTP_MODE_BARE: > > > + case RISCV_IOMMU_DDTP_MODE_OFF: > > > + break; > > > + default: > > > + if ((mode !=3D RISCV_IOMMU_DDTP_MODE_BARE) > > > + && (mode !=3D RISCV_IOMMU_DDTP_MODE_OFF)) > > > + return -EINVAL; > > > + break; > > > + } > > > + > > > + retry: > > > > We need to consider the `iommu.passthrough` before we set up the mode > > in switch case, something like > > > > This function is only to execute configuration and set device directory m= ode. > Handling global iommu.passthrough policy is implemented in > riscv_iommu_init() call (patch #7). Thanks. I saw that in patch #7. > > Best, > - Tomasz