From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: Simon Glass <sjg@chromium.org>
Cc: kettenis@openbsd.org, u-boot@lists.denx.de, bmeng.cn@gmail.com,
marex@denx.de
Subject: Re: [PATCH 1/7] iommu: Add DMA mapping operations
Date: Sat, 21 Jan 2023 20:28:40 +0100 [thread overview]
Message-ID: <87o7qroffb.fsf@bloch.sibelius.xs4all.nl> (raw)
In-Reply-To: <CAPnjgZ2HgQ=4+55_UKMzfCve4CkkUagWDg9F7MQyvai6Cb15=g@mail.gmail.com> (message from Simon Glass on Wed, 18 Jan 2023 12:42:19 -0700)
> From: Simon Glass <sjg@chromium.org>
> Date: Wed, 18 Jan 2023 12:42:19 -0700
>
> Hi Mark,
>
> On Tue, 17 Jan 2023 at 15:04, Mark Kettenis <kettenis@openbsd.org> wrote:
> >
> > In order to support IOMMUs in non-bypass mode we need device ops
> > to map and unmap DMA memory. The map operation enters a mapping
> > for a region specified by CPU address and size into the translation
> > table of the IOMMU and returns a DMA address suitable for
> > programming the device to do DMA. The unmap operation removes
> > this mapping from the translation table of the IOMMU.
> >
> > Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
> > ---
> > drivers/iommu/iommu-uclass.c | 28 ++++++++++++++++++++++++++++
> > include/dm/device.h | 3 +++
> > include/iommu.h | 24 ++++++++++++++++++++++++
> > 3 files changed, 55 insertions(+)
> >
> > diff --git a/drivers/iommu/iommu-uclass.c b/drivers/iommu/iommu-uclass.c
> > index ed917b3c3e..f6b1457736 100644
> > --- a/drivers/iommu/iommu-uclass.c
> > +++ b/drivers/iommu/iommu-uclass.c
> > @@ -7,6 +7,9 @@
> >
> > #include <common.h>
> > #include <dm.h>
> > +#include <iommu.h>
> > +#include <phys2bus.h>
> > +#include <asm/io.h>
> >
> > #if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA))
> > int dev_iommu_enable(struct udevice *dev)
> > @@ -33,12 +36,37 @@ int dev_iommu_enable(struct udevice *dev)
> > __func__, ret);
> > return ret;
> > }
> > + dev->iommu = dev_iommu;
> > }
> >
> > return 0;
> > }
> > #endif
> >
> > +dma_addr_t dev_iommu_dma_map(struct udevice *dev, void *addr, size_t size)
> > +{
> > + const struct iommu_ops *ops;
> > +
> > + if (dev->iommu) {
> > + ops = device_get_ops(dev->iommu);
> > + if (ops && ops->map)
> > + return ops->map(dev->iommu, addr, size);
> > + }
> > +
> > + return dev_phys_to_bus(dev, virt_to_phys(addr));
> > +}
> > +
> > +void dev_iommu_dma_unmap(struct udevice *dev, dma_addr_t addr, size_t size)
> > +{
> > + const struct iommu_ops *ops;
> > +
> > + if (dev->iommu) {
> > + ops = device_get_ops(dev->iommu);
> > + if (ops && ops->unmap)
> > + ops->unmap(dev->iommu, addr, size);
> > + }
> > +}
> > +
> > UCLASS_DRIVER(iommu) = {
> > .id = UCLASS_IOMMU,
> > .name = "iommu",
> > diff --git a/include/dm/device.h b/include/dm/device.h
> > index f3f953c9af..abe1927ecd 100644
> > --- a/include/dm/device.h
> > +++ b/include/dm/device.h
> > @@ -194,6 +194,9 @@ struct udevice {
> > #if CONFIG_IS_ENABLED(DM_DMA)
> > ulong dma_offset;
> > #endif
> > +#if CONFIG_IS_ENABLED(IOMMU)
> > + struct udevice *iommu;
> > +#endif
> > };
> >
> > static inline int dm_udevice_size(void)
> > diff --git a/include/iommu.h b/include/iommu.h
> > index 6c46adf449..cf9719c5e9 100644
> > --- a/include/iommu.h
> > +++ b/include/iommu.h
> > @@ -3,6 +3,27 @@
> >
> > struct udevice;
> >
> > +struct iommu_ops {
> > + /**
> > + * map() - map DMA memory
> > + *
> > + * @dev: device for which to map DMA memory
> > + * @addr: CPU address of the memory
> > + * @size: size of the memory
> > + * @return DMA address for the device
> > + */
> > + dma_addr_t (*map)(struct udevice *dev, void *addr, size_t size);
> > +
> > + /**
> > + * unmap() - unmap DMA memory
> > + *
> > + * @dev: device for which to unmap DMA memory
> > + * @addr: DMA address of the memory
> > + * @size: size of the memory
> > + */
> > + void (*unmap)(struct udevice *dev, dma_addr_t addr, size_t size);
> > +};
> > +
> > #if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) && \
> > CONFIG_IS_ENABLED(IOMMU)
> > int dev_iommu_enable(struct udevice *dev);
> > @@ -13,4 +34,7 @@ static inline int dev_iommu_enable(struct udevice *dev)
> > }
> > #endif
> >
> > +dma_addr_t dev_iommu_dma_map(struct udevice *dev, void *addr, size_t size);
> > +void dev_iommu_dma_unmap(struct udevice *dev, dma_addr_t addr, size_t size);
> > +
> > #endif
>
> Please add some tests for these operations to test/dm/iommc.c
Sure; just sent v2 with some tests added.
next prev parent reply other threads:[~2023-01-21 19:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-17 22:03 [PATCH 0/7] Apple PCIe/XHCI support Mark Kettenis
2023-01-17 22:03 ` [PATCH 1/7] iommu: Add DMA mapping operations Mark Kettenis
2023-01-18 19:42 ` Simon Glass
2023-01-21 19:28 ` Mark Kettenis [this message]
2023-01-17 22:03 ` [PATCH 2/7] iommu: apple: Implement DMA mapping operations for Apple DART Mark Kettenis
2023-01-17 22:04 ` [PATCH 3/7] usb: xhci: Implement DMA mapping Mark Kettenis
2023-01-17 22:51 ` Marek Vasut
2023-01-17 22:04 ` [PATCH 4/7] iommu: Implement mapping IOMMUs for PCI devices Mark Kettenis
2023-01-17 22:04 ` [PATCH 5/7] pci: Add Apple PCIe controller driver Mark Kettenis
2023-01-17 22:04 ` [PATCH 6/7] arm: apple: Enable PCIe USB controller Mark Kettenis
2023-01-17 22:04 ` [PATCH 7/7] usb: xhci: Fix root hub descriptor Mark Kettenis
2023-01-17 22:51 ` Marek Vasut
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o7qroffb.fsf@bloch.sibelius.xs4all.nl \
--to=mark.kettenis@xs4all.nl \
--cc=bmeng.cn@gmail.com \
--cc=kettenis@openbsd.org \
--cc=marex@denx.de \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox