From: "Michael S. Tsirkin" <mst@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: joerg.roedel@amd.com, agraf@suse.de, qemu-devel@nongnu.org,
avi@redhat.com, eduard.munteanu@linux360.ro, rth@twiddle.net
Subject: Re: [Qemu-devel] [PATCH 03/14] Add stub functions for PCI device models to do PCI DMA
Date: Wed, 2 Nov 2011 09:17:37 +0200 [thread overview]
Message-ID: <20111102071737.GB5613@redhat.com> (raw)
In-Reply-To: <1320041218-30487-4-git-send-email-david@gibson.dropbear.id.au>
On Mon, Oct 31, 2011 at 05:06:47PM +1100, David Gibson wrote:
> This patch adds functions to pci.[ch] to perform PCI DMA operations.
> At present, these are just stubs which perform directly cpu physical
> memory accesses. Stubs are included which are analogous to
> cpu_physical_memory_{read,write}(), the stX_phys() and ldX_phys()
> functions and cpu_physical_memory_{map,unmap}().
>
> In addition, a wrapper around qemu_sglist_init() is provided, which
> also takes a PCIDevice *. It's assumed that _init() is the only
> sglist function which will need wrapping, the idea being that once we
> have IOMMU support whatever IOMMU context handle the wrapper derives
> from the PCI device will be stored within the sglist structure for
> later use.
>
> Using these stubs, however, distinguishes PCI device DMA transactions from
> other accesses to physical memory, which will allow PCI IOMMU support to
> be added in one place, rather than updating every PCI driver at that time.
>
> That is, it allows us to update individual PCI drivers to support an IOMMU
> without having yet determined the details of how the IOMMU emulation will
> operate. This will let us remove the most bitrot-sensitive part of an
> IOMMU patch in advance.
>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
> hw/pci.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 67 insertions(+), 0 deletions(-)
>
> diff --git a/hw/pci.h b/hw/pci.h
> index 86a81c8..c449a90 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -6,6 +6,7 @@
>
> #include "qdev.h"
> #include "memory.h"
> +#include "dma.h"
>
> /* PCI includes legacy ISA access. */
> #include "isa.h"
> @@ -487,4 +488,70 @@ static inline uint32_t pci_config_size(const PCIDevice *d)
> return pci_is_express(d) ? PCIE_CONFIG_SPACE_SIZE : PCI_CONFIG_SPACE_SIZE;
> }
>
> +/* DMA access functions */
> +static inline int pci_dma_rw(PCIDevice *dev, dma_addr_t addr,
> + void *buf, dma_addr_t len, DMADirection dir)
> +{
> + cpu_physical_memory_rw(addr, buf, len, dir == DMA_DIRECTION_FROM_DEVICE);
> + return 0;
> +}
> +
> +static inline int pci_dma_read(PCIDevice *dev, dma_addr_t addr,
> + void *buf, dma_addr_t len)
> +{
> + return pci_dma_rw(dev, addr, buf, len, DMA_DIRECTION_TO_DEVICE);
> +}
> +
> +static inline int pci_dma_write(PCIDevice *dev, dma_addr_t addr,
> + const void *buf, dma_addr_t len)
> +{
> + return pci_dma_rw(dev, addr, (void *) buf, len, DMA_DIRECTION_FROM_DEVICE);
> +}
> +
> +#define PCI_DMA_DEFINE_LDST(_l, _s, _bits) \
> + static inline uint##_bits##_t ld##_l##_pci_dma(PCIDevice *dev, \
> + dma_addr_t addr) \
> + { \
> + return ld##_l##_phys(addr); \
> + } \
> + static inline void st##_s##_pci_dma(PCIDevice *dev, \
> + dma_addr_t addr, uint##_bits##_t val) \
> + { \
> + st##_s##_phys(addr, val); \
> + }
> +
I'd much rather name APIs pci_dma_XXX.
why use a suffix and not a prefix?
> +PCI_DMA_DEFINE_LDST(ub, b, 8);
> +PCI_DMA_DEFINE_LDST(uw_le, w_le, 16)
> +PCI_DMA_DEFINE_LDST(l_le, l_le, 32);
> +PCI_DMA_DEFINE_LDST(q_le, q_le, 64);
> +PCI_DMA_DEFINE_LDST(uw_be, w_be, 16)
> +PCI_DMA_DEFINE_LDST(l_be, l_be, 32);
> +PCI_DMA_DEFINE_LDST(q_be, q_be, 64);
> +
> +#undef PCI_DMA_DEFINE_LDST
> +
> +static inline void *pci_dma_map(PCIDevice *dev, dma_addr_t addr,
> + dma_addr_t *plen, DMADirection dir)
> +{
> + target_phys_addr_t len = *plen;
> + void *buf;
> +
> + buf = cpu_physical_memory_map(addr, &len, dir == DMA_DIRECTION_FROM_DEVICE);
> + *plen = len;
> + return buf;
> +}
> +
> +static inline void pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len,
> + DMADirection dir, dma_addr_t access_len)
> +{
> + cpu_physical_memory_unmap(buffer, len, dir == DMA_DIRECTION_FROM_DEVICE,
> + access_len);
> +}
> +
> +static inline void pci_dma_sglist_init(QEMUSGList *qsg, PCIDevice *dev,
> + int alloc_hint)
> +{
> + qemu_sglist_init(qsg, alloc_hint);
> +}
> +
> #endif
> --
> 1.7.7
next prev parent reply other threads:[~2011-11-02 7:16 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-31 6:06 [Qemu-devel] [0/14] Preliminary work for IOMMU emulation support (v3) David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 01/14] Define DMA address and direction types David Gibson
2011-11-01 22:21 ` Anthony Liguori
2011-10-31 6:06 ` [Qemu-devel] [PATCH 02/14] Use dma_addr_t type for scatter/gather code David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 03/14] Add stub functions for PCI device models to do PCI DMA David Gibson
2011-11-02 7:17 ` Michael S. Tsirkin [this message]
2011-11-02 11:47 ` David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 04/14] rtl8139: Use PCI DMA stub functions David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 05/14] eepro100: " David Gibson
2011-10-31 16:45 ` Stefan Weil
2011-11-01 20:24 ` Anthony Liguori
2011-11-02 7:40 ` Michael S. Tsirkin
2011-11-02 12:46 ` Anthony Liguori
2011-11-02 17:56 ` Alexander Graf
2011-11-02 17:19 ` Anthony Liguori
2011-11-02 17:28 ` Alexander Graf
2011-11-02 19:11 ` Michael S. Tsirkin
2011-11-03 0:52 ` David Gibson
2011-11-02 11:01 ` Michael S. Tsirkin
2011-11-02 7:16 ` Michael S. Tsirkin
2011-11-03 5:16 ` David Gibson
2011-11-03 12:25 ` Michael S. Tsirkin
2011-11-04 0:28 ` David Gibson
2011-11-05 8:32 ` Stefan Weil
2011-10-31 6:06 ` [Qemu-devel] [PATCH 06/14] ac97: " David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 07/14] es1370: " David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 08/14] e1000: " David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 09/14] lsi53c895a: " David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 10/14] pcnet-pci: " David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 11/14] intel-hda: " David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 12/14] PCI IDE: " David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 13/14] usb-ehci: " David Gibson
2011-10-31 6:06 ` [Qemu-devel] [PATCH 14/14] usb-uhci: " David Gibson
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=20111102071737.GB5613@redhat.com \
--to=mst@redhat.com \
--cc=agraf@suse.de \
--cc=avi@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=eduard.munteanu@linux360.ro \
--cc=joerg.roedel@amd.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.