qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: "Michael S. Tsirkin" <mst@redhat.com>
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 22:47:55 +1100	[thread overview]
Message-ID: <20111102114755.GJ5379@truffala.fritz.box> (raw)
In-Reply-To: <20111102071737.GB5613@redhat.com>

On Wed, Nov 02, 2011 at 09:17:37AM +0200, Michael S. Tsirkin wrote:
> 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?

Because the analogous stX_phys/ldX_phys functions do.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

  reply	other threads:[~2011-11-02 11:52 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
2011-11-02 11:47     ` David Gibson [this message]
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=20111102114755.GJ5379@truffala.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=avi@redhat.com \
    --cc=eduard.munteanu@linux360.ro \
    --cc=joerg.roedel@amd.com \
    --cc=mst@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).