Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 May 2022 09:37:36 -0700
From:      Kyle Evans <kevans@freebsd.org>
To:        Ravi Pokala <rpokala@freebsd.org>
Cc:        Ruslan Bukin <br@freebsd.org>, src-committers <src-committers@freebsd.org>,  "<dev-commits-src-all@freebsd.org>" <dev-commits-src-all@freebsd.org>, dev-commits-src-main@freebsd.org
Subject:   Re: 0b6bacc7874f - main - Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU specifier based on "iommu-map" DTS property.
Message-ID:  <CACNAnaEw8wbnvRjEyLC6caOw4=yVEuWceM8JYYGninKyemCaew@mail.gmail.com>
In-Reply-To: <450C9313-CB5A-4DCA-97FB-40FC87886F00@panasas.com>
References:  <202205061551.246FpO6o060060@gitrepo.freebsd.org> <450C9313-CB5A-4DCA-97FB-40FC87886F00@panasas.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, May 6, 2022 at 9:25 AM Ravi Pokala <rpokala@freebsd.org> wrote:
>
> -----Original Message-----
> From: <owner-src-committers@freebsd.org> on behalf of Ruslan Bukin <br@Fr=
eeBSD.org>
> Date: 2022-05-06, Friday at 08:51
> To: <src-committers@FreeBSD.org>, <dev-commits-src-all@FreeBSD.org>, <dev=
-commits-src-main@FreeBSD.org>
> 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 <br@FreeBSD.org>
>     AuthorDate: 2022-05-06 15:41:11 +0000
>     Commit:     Ruslan Bukin <br@FreeBSD.org>
>     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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACNAnaEw8wbnvRjEyLC6caOw4=yVEuWceM8JYYGninKyemCaew>