From: "Michael S. Tsirkin" <mst@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org, Anthony Liguori <aliguori@amazon.com>
Subject: Re: [Qemu-devel] [PATCH] virtio-pci: make pci bar layout more flexible.
Date: Tue, 3 Mar 2015 18:42:01 +0100 [thread overview]
Message-ID: <20150303174201.GD21824@redhat.com> (raw)
In-Reply-To: <1425390913-17726-1-git-send-email-kraxel@redhat.com>
On Tue, Mar 03, 2015 at 02:55:13PM +0100, Gerd Hoffmann wrote:
> This patch makes the bar layout for virtio pci devices configurable.
> This is used to
> (a) create different layouts for legacy/transitional vs. modern
> devices.
> (b) make sure we use unused pci bars, by checking
> PCIDevice->io_regions
>
> VirtIOPCIProxy subclasses which need additional pci bars, such as
> virtio-vga, just need to make sure they register the additinal bars
> before initializing virtio-pci, so the superclass can see the registered
> bars and shuffle around the virtio bars accordingly.
I think I prefer we just DTRT and keep same layouts for everyone by
default: isn't there a layout that is good for everybody?
Maybe you could give two examples that require two
incompatible layouts?
I know this means we'll leave BAR0 unused for modern devices but that
does not seem too bad.
> The patch also makes sure the modern bar is properly aligned so it can
> be a 64bit bar, and the prefetchable + 64bit attributes are enabled.
This can be a separate patch?
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> hw/virtio/virtio-pci.c | 36 +++++++++++++++++++++++++++++++-----
> 1 file changed, 31 insertions(+), 5 deletions(-)
>
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 6b1f422..a2cfb1f 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -965,8 +965,6 @@ static void virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,
> PCIDevice *dev = &proxy->pci_dev;
> int offset;
>
> - cap->bar = 2;
> -
> offset = pci_add_capability(dev, PCI_CAP_ID_VNDR, 0, cap->cap_len);
> assert(offset > 0);
>
> @@ -1232,9 +1230,12 @@ static void virtio_pci_device_write(void *opaque, hwaddr addr,
> static void virtio_pci_device_plugged(DeviceState *d)
> {
> VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
> + PCIDevice *pci = PCI_DEVICE(d);
> VirtioBusState *bus = &proxy->bus;
> bool legacy = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_LEGACY);
> bool modern = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN);
> + uint32_t modern_mem_bar; /* 64bit bar */
> + uint32_t msix_bar; /* 32bit bar */
> uint8_t *config;
> uint32_t size;
>
> @@ -1248,6 +1249,12 @@ static void virtio_pci_device_plugged(DeviceState *d)
> pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
> pci_get_word(config + PCI_VENDOR_ID));
> pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_bus_get_vdev_id(bus));
> + msix_bar = 1;
> + modern_mem_bar = 2;
> + while (pci->io_regions[modern_mem_bar].size ||
> + pci->io_regions[modern_mem_bar+1].size) {
> + modern_mem_bar += 2;
> + }
> } else {
> /* pure virtio-1.0 */
> pci_set_word(config + PCI_VENDOR_ID,
> @@ -1255,7 +1262,18 @@ static void virtio_pci_device_plugged(DeviceState *d)
> pci_set_word(config + PCI_DEVICE_ID,
> 0x1040 + virtio_bus_get_vdev_id(bus));
> pci_config_set_revision(config, 1);
> + modern_mem_bar = 0;
> + while (pci->io_regions[modern_mem_bar].size ||
> + pci->io_regions[modern_mem_bar+1].size) {
> + modern_mem_bar += 2;
> + }
> + msix_bar = modern_mem_bar + 2;
> + while (pci->io_regions[msix_bar].size) {
> + msix_bar++;
> + }
> }
> + assert(modern_mem_bar <= 4);
> + assert(msix_bar <= 5);
> config[PCI_INTERRUPT_PIN] = 1;
>
>
> @@ -1263,29 +1281,34 @@ static void virtio_pci_device_plugged(DeviceState *d)
> struct virtio_pci_cap common = {
> .cfg_type = VIRTIO_PCI_CAP_COMMON_CFG,
> .cap_len = sizeof common,
> + .bar = modern_mem_bar,
> .offset = cpu_to_le32(0x0),
> .length = cpu_to_le32(0x1000),
> };
> struct virtio_pci_cap isr = {
> .cfg_type = VIRTIO_PCI_CAP_ISR_CFG,
> .cap_len = sizeof isr,
> + .bar = modern_mem_bar,
> .offset = cpu_to_le32(0x1000),
> .length = cpu_to_le32(0x1000),
> };
> struct virtio_pci_cap device = {
> .cfg_type = VIRTIO_PCI_CAP_DEVICE_CFG,
> .cap_len = sizeof device,
> + .bar = modern_mem_bar,
> .offset = cpu_to_le32(0x2000),
> .length = cpu_to_le32(0x1000),
> };
> struct virtio_pci_notify_cap notify = {
> .cap.cfg_type = VIRTIO_PCI_CAP_NOTIFY_CFG,
> .cap.cap_len = sizeof notify,
> + .cap.bar = modern_mem_bar,
> .cap.offset = cpu_to_le32(0x3000),
> .cap.length = cpu_to_le32(QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *
> VIRTIO_PCI_QUEUE_MAX),
> .notify_off_multiplier = cpu_to_le32(QEMU_VIRTIO_PCI_QUEUE_MEM_MULT),
> };
> + uint32_t modern_mem_attr;
>
> static const MemoryRegionOps common_ops = {
> .read = virtio_pci_common_read,
> @@ -1359,12 +1382,15 @@ static void virtio_pci_device_plugged(DeviceState *d)
> QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *
> VIRTIO_PCI_QUEUE_MAX);
> memory_region_add_subregion(&proxy->modern_bar, 0x3000, &proxy->notify);
> - pci_register_bar(&proxy->pci_dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY,
> - &proxy->modern_bar);
> + modern_mem_attr = (PCI_BASE_ADDRESS_SPACE_MEMORY |
> + PCI_BASE_ADDRESS_MEM_PREFETCH |
> + PCI_BASE_ADDRESS_MEM_TYPE_64);
> + pci_register_bar(&proxy->pci_dev, modern_mem_bar,
> + modern_mem_attr, &proxy->modern_bar);
> }
>
> if (proxy->nvectors &&
> - msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors, 1)) {
> + msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors, msix_bar)) {
> error_report("unable to init msix vectors to %" PRIu32,
> proxy->nvectors);
> proxy->nvectors = 0;
> --
> 1.8.3.1
next prev parent reply other threads:[~2015-03-03 17:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-03 13:55 [Qemu-devel] [PATCH] virtio-pci: make pci bar layout more flexible Gerd Hoffmann
2015-03-03 17:42 ` Michael S. Tsirkin [this message]
2015-03-04 10:55 ` Gerd Hoffmann
2015-03-04 11:04 ` Michael S. Tsirkin
2015-03-04 11:46 ` Gerd Hoffmann
2015-03-04 11:51 ` Michael S. Tsirkin
2015-03-04 12:04 ` Michael S. Tsirkin
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=20150303174201.GD21824@redhat.com \
--to=mst@redhat.com \
--cc=aliguori@amazon.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).