From nobody Fri May 6 16:37:36 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 734101AD40E9; Fri, 6 May 2022 16:37:43 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kvx7W2hXkz3v6L; Fri, 6 May 2022 16:37:43 +0000 (UTC) (envelope-from kevans@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651855063; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4+rY6WxEtsNs1cT1Av8Pg3hHqmUdRhN2rcib7bt3BEw=; b=Ul1JBV8cB/Uil/jKrgGFNAYUXlFASzivVyyzZG+Nf4H1aZJ+kHe9bfmg9/wFXrp+Bx9Q++ TJUQ34LIbAm+7MSLEqzJClU01d8mdhVEBjqB9XkQ1l5aRbY8Qw5kHoSDK2igxDaQtiiTg8 Fy6bOo1JRL5snwL0JDuhpnAzEPatfIEGK+JghQsQ34PZnIGxlJ3OGo8iLt7Fz4B3b8pQja uUAjEoG6zzlf+eto6UB41B6NklfHfpGDhrtsG0e1BCT+wVr6eLTpH+r/VI/zM1CP7k437J nOC9M8pOnvZSfnsL0W/0U2MWY0eqcHxnVIYzCCtCzswkNO9SQl16AfpGCE/g3Q== Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) (Authenticated sender: kevans) by smtp.freebsd.org (Postfix) with ESMTPSA id 362AB2EA6D; Fri, 6 May 2022 16:37:43 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: by mail-lf1-f49.google.com with SMTP id u23so7818480lfc.1; Fri, 06 May 2022 09:37:43 -0700 (PDT) X-Gm-Message-State: AOAM531rcpWZYbPToxdDeKgAMCMEhGu07Ett1vn+A3ylJRoSy3mVos0i 21Q8BlcBwWNWJl0pcKPKtccJyhgVKXiE0lLe7sA= X-Google-Smtp-Source: ABdhPJzIyDOrWGEC6G7Z7BRI1NC8XEYqpiGMZVnJVokdRylwWuyM87Uth18uqXGDLvxVxiKn/apaTQNx36AIuuS5I+o= X-Received: by 2002:a05:6512:400e:b0:450:e09d:c9a6 with SMTP id br14-20020a056512400e00b00450e09dc9a6mr3172621lfb.243.1651855061648; Fri, 06 May 2022 09:37:41 -0700 (PDT) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 References: <202205061551.246FpO6o060060@gitrepo.freebsd.org> <450C9313-CB5A-4DCA-97FB-40FC87886F00@panasas.com> In-Reply-To: <450C9313-CB5A-4DCA-97FB-40FC87886F00@panasas.com> From: Kyle Evans Date: Fri, 6 May 2022 09:37:36 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: 0b6bacc7874f - main - Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU specifier based on "iommu-map" DTS property. To: Ravi Pokala Cc: Ruslan Bukin , src-committers , "" , dev-commits-src-main@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651855063; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4+rY6WxEtsNs1cT1Av8Pg3hHqmUdRhN2rcib7bt3BEw=; b=V4lTWp7nQmzXVLs380FZQwS21wb2PkGz1UOYCKg2i6/J6inDTEEzGabDfUc/0HwqMs/IFL UkZhvN4qXI6whbuhKPL4Mh/KrAAVzK18gjOSTaVApLICvkVJ5DY2CyHEuYUiHmoF+2cvUl qet6BB48akdZ+OH2eVwOAKmlwxwvqiX7ezrz/Pqt1LgZefDbC5kps1TCQ9nBZBVv7TUNN5 h39n/f3FsMWpcvptgo0eG5azOJ1SxOOowEB91tqoM8kK0RPMxToYAYxpejkxu4JriVPXRl +ITJabUpYswmKNmr7sVMxpF7CniVRe0FnwIxePYiboBHvhsQO3Te8a6Y7OJg/g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651855063; a=rsa-sha256; cv=none; b=eK+48J++a9FhapG3dRyHX5D/yOX5z9CNB1NUr/y0DRJtOD1tzwfxTbXxx7VZqW18x9b0oQ ugE83LDIOmBXHOZ5TrBFTDt0EMuhjD9WSPB82cVD/VqYy8FE/leQjmZf028TkupNsqafTK lynTGMOMOFOswmHd9U+zqHv9viOFQgQY1wmCLDyhIElp+BfX7jmNnr6Dq2aiJA/SFeddHa DTPlCa+O21R5EEBsNbN+PRX9Q2Q8ayXek/ecuXa3adveL8MUisZtQCoTwG2tp2FJ+NfPoK rhnOkBJM+iA0L9ZT/9PCo7TxwVPz2H6566GFMPtryM3APoxK9i2SKEmCaTCnBQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N On Fri, May 6, 2022 at 9:25 AM Ravi Pokala wrote: > > -----Original Message----- > From: on behalf of Ruslan Bukin > Date: 2022-05-06, Friday at 08:51 > To: , , > Subject: git: 0b6bacc7874f - main - Add ofw_bus_iommu_map() that maps PCI= requester ID to an IOMMU specifier based on "iommu-map" DTS property. > > The branch main has been updated by br: > > URL: https://cgit.FreeBSD.org/src/commit/?id=3D0b6bacc7874f9c68ad35b0= 6f1a7614171eb9ab10 > > commit 0b6bacc7874f9c68ad35b06f1a7614171eb9ab10 > Author: Ruslan Bukin > AuthorDate: 2022-05-06 15:41:11 +0000 > Commit: Ruslan Bukin > CommitDate: 2022-05-06 15:48:04 +0000 > > Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU > specifier based on "iommu-map" DTS property. > > Sponsored by: UKRI > --- > sys/dev/ofw/ofw_bus_subr.c | 44 ++++++++++++++++++++++++++++++++++++= ++++++++ > sys/dev/ofw/ofw_bus_subr.h | 3 ++- > 2 files changed, 46 insertions(+), 1 deletion(-) > > diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c > index ea57d1086779..408d554b3c7f 100644 > --- a/sys/dev/ofw/ofw_bus_subr.c > +++ b/sys/dev/ofw/ofw_bus_subr.c > @@ -491,6 +491,50 @@ ofw_bus_msimap(phandle_t node, uint16_t pci_rid,= phandle_t *msi_parent, > return (err); > } > > +int > +ofw_bus_iommu_map(phandle_t node, uint16_t pci_rid, phandle_t *iommu= _parent, > + uint32_t *iommu_rid) > +{ > + pcell_t mask, iommu_base, rid_base, rid_length; > + uint32_t masked_rid; > + pcell_t map[4]; > + ssize_t len; > + int err, i; > + > + len =3D OF_getproplen(node, "iommu-map"); > + if (len <=3D 0) > + return (ENOENT); > + if (len > sizeof(map)) > + return (ENOMEM); > + > + len =3D OF_getencprop(node, "iommu-map", map, 16); > + > + err =3D ENOENT; > + mask =3D 0xffffffff; > + OF_getencprop(node, "iommu-map-mask", &mask, sizeof(mask)); > + > + masked_rid =3D pci_rid & mask; > + for (i =3D 0; i < len; i +=3D 4) { > + rid_base =3D map[i + 0]; > + rid_length =3D map[i + 3]; > > Hi Ruslan, > > I'm confused by this. 'map' is declared as a 4-element array, which means= 'map[i + 0]' and 'map[i + 3]' are both only valid when 'i' is 0. But 'i' i= s the loop iterator; doesn't that mean you're accessing outside the array a= fter the 0th time through the loop? > The comparison looks like it's wrong and inherited from ofw_bus_msimap() -- i is in terms of # cells, OF_getencprop returns size in bytes, This version only holds one mapping (four cells) at a time, so the intention is just one iteration through the loop. We'll need to extend this at some point, the M1 FDT has 3 4-cell mappings here. ofw_bus_msimap() was almost an exact fit, and an adapted version is what I use in my m1 branch.