All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	agraf@suse.de, stefanha@redhat.com, mst@redhat.com,
	aik@ozlabs.ru, mdroth@linux.vnet.ibm.com, groug@kaod.org,
	thuth@redhat.com
Subject: Re: [Qemu-devel] [PATCH 3/8] libqos: Move BAR assignment to common code
Date: Wed, 19 Oct 2016 14:07:15 +1100	[thread overview]
Message-ID: <20161019030715.GG11140@umbus.fritz.box> (raw)
In-Reply-To: <1dc5eb87-ebc5-40db-25ef-5e61bd488a7e@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 9487 bytes --]

On Tue, Oct 18, 2016 at 05:00:08PM +0200, Laurent Vivier wrote:
> 
> 
> On 18/10/2016 12:52, David Gibson wrote:
> > The PCI backends in libqos each supply an iomap() and iounmap() function
> > which is used to set up a specified PCI BAR.  But PCI BAR allocation takes
> > place entirely within PCI space, so doesn't really need per-backend
> > versions.  For example, Linux includes generic BAR allocation code used on
> > platforms where that isn't done by firmware.
> > 
> > This patch merges the BAR allocation from the two existing backends into a
> > single simplified copy.  The back ends just need to set up some parameters
> > describing the window of PCI IO and PCI memory addresses which are
> > available for allocation.  Like both the existing versions the new one uses
> > a simple bump allocator.
> > 
> > Note that (again like the existing versions) this doesn't really handle
> > 64-bit memory BARs properly.  It is actually used for such a BAR by the
> > ivshmem test, and apparently the 32-bit MMIO BAR logic is close enough to
> > work, as long as the BAR isn't too big.  Fixing that to properly handle
> > 64-bit BAR allocation is a problem for another time.
> > 
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> >  tests/libqos/pci-pc.c    | 79 ++--------------------------------------------
> >  tests/libqos/pci-spapr.c | 81 ++----------------------------------------------
> >  tests/libqos/pci.c       | 56 +++++++++++++++++++++++++++++++--
> >  tests/libqos/pci.h       |  7 ++---
> >  4 files changed, 63 insertions(+), 160 deletions(-)
> > 
> > diff --git a/tests/libqos/pci-pc.c b/tests/libqos/pci-pc.c
> > index 51dff8a..b087d13 100644
> > --- a/tests/libqos/pci-pc.c
> > +++ b/tests/libqos/pci-pc.c
> > @@ -17,7 +17,6 @@
> >  #include "hw/pci/pci_regs.h"
> >  
> >  #include "qemu-common.h"
> > -#include "qemu/host-utils.h"
> >  
> >  
> >  #define ACPI_PCIHP_ADDR         0xae00
> > @@ -132,71 +131,6 @@ static void qpci_pc_config_writel(QPCIBus *bus, int devfn, uint8_t offset, uint3
> >      outl(0xcfc, value);
> >  }
> >  
> > -static void *qpci_pc_iomap(QPCIBus *bus, QPCIDevice *dev, int barno, uint64_t *sizeptr)
> > -{
> > -    QPCIBusPC *s = container_of(bus, QPCIBusPC, bus);
> > -    static const int bar_reg_map[] = {
> > -        PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
> > -        PCI_BASE_ADDRESS_3, PCI_BASE_ADDRESS_4, PCI_BASE_ADDRESS_5,
> > -    };
> > -    int bar_reg;
> > -    uint32_t addr;
> > -    uint64_t size;
> > -    uint32_t io_type;
> > -
> > -    g_assert(barno >= 0 && barno <= 5);
> > -    bar_reg = bar_reg_map[barno];
> > -
> > -    qpci_config_writel(dev, bar_reg, 0xFFFFFFFF);
> > -    addr = qpci_config_readl(dev, bar_reg);
> > -
> > -    io_type = addr & PCI_BASE_ADDRESS_SPACE;
> > -    if (io_type == PCI_BASE_ADDRESS_SPACE_IO) {
> > -        addr &= PCI_BASE_ADDRESS_IO_MASK;
> > -    } else {
> > -        addr &= PCI_BASE_ADDRESS_MEM_MASK;
> > -    }
> > -
> > -    size = (1ULL << ctzl(addr));
> > -    if (size == 0) {
> > -        return NULL;
> > -    }
> > -    if (sizeptr) {
> > -        *sizeptr = size;
> > -    }
> > -
> > -    if (io_type == PCI_BASE_ADDRESS_SPACE_IO) {
> > -        uint16_t loc;
> > -
> > -        g_assert(QEMU_ALIGN_UP(s->pci_iohole_alloc, size) + size
> > -                 <= s->pci_iohole_size);
> > -        s->pci_iohole_alloc = QEMU_ALIGN_UP(s->pci_iohole_alloc, size);
> > -        loc = s->pci_iohole_start + s->pci_iohole_alloc;
> > -        s->pci_iohole_alloc += size;
> > -
> > -        qpci_config_writel(dev, bar_reg, loc | PCI_BASE_ADDRESS_SPACE_IO);
> > -
> > -        return (void *)(intptr_t)loc;
> > -    } else {
> > -        uint64_t loc;
> > -
> > -        g_assert(QEMU_ALIGN_UP(s->pci_hole_alloc, size) + size
> > -                 <= s->pci_hole_size);
> > -        s->pci_hole_alloc = QEMU_ALIGN_UP(s->pci_hole_alloc, size);
> > -        loc = s->pci_hole_start + s->pci_hole_alloc;
> > -        s->pci_hole_alloc += size;
> > -
> > -        qpci_config_writel(dev, bar_reg, loc);
> > -
> > -        return (void *)(intptr_t)loc;
> > -    }
> > -}
> > -
> > -static void qpci_pc_iounmap(QPCIBus *bus, void *data)
> > -{
> > -    /* FIXME */
> > -}
> > -
> >  QPCIBus *qpci_init_pc(QGuestAllocator *alloc)
> >  {
> >      QPCIBusPC *ret;
> > @@ -227,16 +161,9 @@ QPCIBus *qpci_init_pc(QGuestAllocator *alloc)
> >      ret->bus.config_writew = qpci_pc_config_writew;
> >      ret->bus.config_writel = qpci_pc_config_writel;
> >  
> > -    ret->bus.iomap = qpci_pc_iomap;
> > -    ret->bus.iounmap = qpci_pc_iounmap;
> > -
> > -    ret->pci_hole_start = 0xE0000000;
> > -    ret->pci_hole_size = 0x20000000;
> > -    ret->pci_hole_alloc = 0;
> > -
> > -    ret->pci_iohole_start = 0xc000;
> > -    ret->pci_iohole_size = 0x4000;
> > -    ret->pci_iohole_alloc = 0;
> 
> I think you can remove all these fields (pci_hole_.., pci_iohole_...)
> from QPCIBusPC.
> 
> > +    ret->bus.pio_alloc_ptr = 0xc000;
> > +    ret->bus.mmio_alloc_ptr = 0xE0000000;
> > +    ret->bus.mmio_limit = 0x100000000ULL;
> >  
> >      return &ret->bus;
> >  }
> > diff --git a/tests/libqos/pci-spapr.c b/tests/libqos/pci-spapr.c
> > index 2d26a94..9a18d8a 100644
> > --- a/tests/libqos/pci-spapr.c
> > +++ b/tests/libqos/pci-spapr.c
> > @@ -167,72 +167,6 @@ static void qpci_spapr_config_writel(QPCIBus *bus, int devfn, uint8_t offset,
> >      qrtas_ibm_write_pci_config(s->alloc, s->buid, config_addr, 4, value);
> >  }
> >  
> > -static void *qpci_spapr_iomap(QPCIBus *bus, QPCIDevice *dev, int barno,
> > -                              uint64_t *sizeptr)
> > -{
> > -    QPCIBusSPAPR *s = container_of(bus, QPCIBusSPAPR, bus);
> > -    static const int bar_reg_map[] = {
> > -        PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
> > -        PCI_BASE_ADDRESS_3, PCI_BASE_ADDRESS_4, PCI_BASE_ADDRESS_5,
> > -    };
> > -    int bar_reg;
> > -    uint32_t addr;
> > -    uint64_t size;
> > -    uint32_t io_type;
> > -
> > -    g_assert(barno >= 0 && barno <= 5);
> > -    bar_reg = bar_reg_map[barno];
> > -
> > -    qpci_config_writel(dev, bar_reg, 0xFFFFFFFF);
> > -    addr = qpci_config_readl(dev, bar_reg);
> > -
> > -    io_type = addr & PCI_BASE_ADDRESS_SPACE;
> > -    if (io_type == PCI_BASE_ADDRESS_SPACE_IO) {
> > -        addr &= PCI_BASE_ADDRESS_IO_MASK;
> > -    } else {
> > -        addr &= PCI_BASE_ADDRESS_MEM_MASK;
> > -    }
> > -
> > -    size = (1ULL << ctzl(addr));
> > -    if (size == 0) {
> > -        return NULL;
> > -    }
> > -    if (sizeptr) {
> > -        *sizeptr = size;
> > -    }
> > -
> > -    if (io_type == PCI_BASE_ADDRESS_SPACE_IO) {
> > -        uint16_t loc;
> > -
> > -        g_assert(QEMU_ALIGN_UP(s->pci_iohole_alloc, size) + size
> > -                 <= s->pci_iohole_size);
> > -        s->pci_iohole_alloc = QEMU_ALIGN_UP(s->pci_iohole_alloc, size);
> > -        loc = s->pci_iohole_start + s->pci_iohole_alloc;
> > -        s->pci_iohole_alloc += size;
> > -
> > -        qpci_config_writel(dev, bar_reg, loc | PCI_BASE_ADDRESS_SPACE_IO);
> > -
> > -        return (void *)(unsigned long)loc;
> > -    } else {
> > -        uint64_t loc;
> > -
> > -        g_assert(QEMU_ALIGN_UP(s->pci_hole_alloc, size) + size
> > -                 <= s->pci_hole_size);
> > -        s->pci_hole_alloc = QEMU_ALIGN_UP(s->pci_hole_alloc, size);
> > -        loc = s->pci_hole_start + s->pci_hole_alloc;
> > -        s->pci_hole_alloc += size;
> > -
> > -        qpci_config_writel(dev, bar_reg, loc);
> > -
> > -        return (void *)(unsigned long)loc;
> > -    }
> > -}
> > -
> > -static void qpci_spapr_iounmap(QPCIBus *bus, void *data)
> > -{
> > -    /* FIXME */
> > -}
> > -
> >  #define SPAPR_PCI_BASE               (1ULL << 45)
> >  
> >  #define SPAPR_PCI_MMIO32_WIN_SIZE    0x80000000 /* 2 GiB */
> > @@ -270,9 +204,6 @@ QPCIBus *qpci_init_spapr(QGuestAllocator *alloc)
> >      ret->bus.config_writew = qpci_spapr_config_writew;
> >      ret->bus.config_writel = qpci_spapr_config_writel;
> >  
> > -    ret->bus.iomap = qpci_spapr_iomap;
> > -    ret->bus.iounmap = qpci_spapr_iounmap;
> > -
> >      /* FIXME: We assume the default location of the PHB for now.
> >       * Ideally we'd parse the device tree deposited in the guest to
> >       * get the window locations */
> > @@ -287,15 +218,9 @@ QPCIBus *qpci_init_spapr(QGuestAllocator *alloc)
> >      ret->mmio32.pci_base = 0x80000000; /* 2 GiB */
> >      ret->mmio32.size = SPAPR_PCI_MMIO32_WIN_SIZE;
> >  
> > -    ret->pci_hole_start = 0xC0000000;
> > -    ret->pci_hole_size =
> > -        ret->mmio32.pci_base + ret->mmio32.size - ret->pci_hole_start;
> > -    ret->pci_hole_alloc = 0;
> > -
> > -    ret->pci_iohole_start = 0xc000;
> > -    ret->pci_iohole_size =
> > -        ret->pio.pci_base + ret->pio.size - ret->pci_iohole_start;
> > -    ret->pci_iohole_alloc = 0;
> 
> I think you can remove all these fields (pci_hole_.., pci_iohole_...)
> from QPCIBusSPAPR.

Ah, yes, meant to remove them from both PC and spapr, but forgot.
Done for the next spin.

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2016-10-19  4:49 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18 10:52 [Qemu-devel] [PATCH 0/8] Cleanups to qtest PCI handling David Gibson
2016-10-18 10:52 ` [Qemu-devel] [PATCH 1/8] libqos: Give qvirtio_config_read*() consistent semantics David Gibson
2016-10-18 12:41   ` Laurent Vivier
2016-10-18 13:27   ` Greg Kurz
2016-10-19  2:41     ` David Gibson
2016-10-18 10:52 ` [Qemu-devel] [PATCH 2/8] libqos: Handle PCI IO de-multiplexing in common code David Gibson
2016-10-18 13:28   ` Laurent Vivier
2016-10-19  2:59     ` David Gibson
2016-10-18 10:52 ` [Qemu-devel] [PATCH 3/8] libqos: Move BAR assignment to " David Gibson
2016-10-18 15:00   ` Laurent Vivier
2016-10-19  3:07     ` David Gibson [this message]
2016-10-18 10:52 ` [Qemu-devel] [PATCH 4/8] tests: Better handle legacy IO addresses in tco-test David Gibson
2016-10-18 15:14   ` Laurent Vivier
2016-10-18 16:28     ` Laurent Vivier
2016-10-19  3:19       ` David Gibson
2016-10-19  3:09     ` David Gibson
2016-10-18 10:52 ` [Qemu-devel] [PATCH 5/8] libqos: Add streaming accessors for PCI MMIO David Gibson
2016-10-18 15:17   ` Laurent Vivier
2016-10-18 10:52 ` [Qemu-devel] [PATCH 6/8] libqos: Implement mmio accessors in terms of mem{read, write} David Gibson
2016-10-18 16:04   ` Laurent Vivier
2016-10-18 10:52 ` [Qemu-devel] [PATCH 7/8] tests: Use qpci_mem{read, write} in ivshmem-test David Gibson
2016-10-18 16:14   ` Laurent Vivier
2016-10-19  4:13     ` David Gibson
2016-10-18 10:52 ` [Qemu-devel] [PATCH 8/8] libqos: Change PCI accessors to take opaque BAR handle David Gibson
2016-10-18 16:48   ` Laurent Vivier
2016-10-19  4:06     ` David Gibson
2016-10-18 11:56 ` [Qemu-devel] [PATCH 0/8] Cleanups to qtest PCI handling Laurent Vivier
2016-10-19  1:11   ` 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=20161019030715.GG11140@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=aik@ozlabs.ru \
    --cc=groug@kaod.org \
    --cc=lvivier@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    /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.