From: "Michael S. Tsirkin" <mst@redhat.com>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCHv2] qemu: target library, use it in msix
Date: Wed, 23 Sep 2009 23:06:35 +0300 [thread overview]
Message-ID: <20090923200635.GA21246@redhat.com> (raw)
This creates target.c, which builds per-target, and makes it possible
for devices to become target-independent. Use it in msix, reverting
part of 5e520a7d500ec2569d22d80f9ef4272a34cb3c80, as we no longer have
to pass target page around.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
Makefile.target | 3 +++
hw/msix.c | 51 ++++++++++++++++++++++++++-------------------------
hw/msix.h | 5 ++---
hw/pci.h | 6 ------
hw/virtio-pci.c | 3 +--
target.c | 17 +++++++++++++++++
target.h | 6 ++++++
7 files changed, 55 insertions(+), 36 deletions(-)
create mode 100644 target.c
create mode 100644 target.h
diff --git a/Makefile.target b/Makefile.target
index 0ebef17..c0f143a 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -55,6 +55,9 @@ libobj-$(CONFIG_S390_DIS) += s390-dis.o
libobj-$(CONFIG_SH4_DIS) += sh4-dis.o
libobj-$(CONFIG_SPARC_DIS) += sparc-dis.o
+# Target library: makes devices target-independent
+libobj-y += target.o
+
# libqemu
libqemu.a: $(libobj-y)
diff --git a/hw/msix.c b/hw/msix.c
index 3782994..af820ec 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -14,6 +14,7 @@
#include "hw.h"
#include "msix.h"
#include "pci.h"
+#include "target.h"
/* Declaration from linux/pci_regs.h */
#define PCI_CAP_ID_MSIX 0x11 /* MSI-X */
@@ -38,6 +39,15 @@
#define MSIX_VECTOR_CTRL 12
#define MSIX_ENTRY_SIZE 16
#define MSIX_VECTOR_MASK 0x1
+
+/* How much space does an MSIX table need. */
+/* The spec requires giving the table structure
+ * a 4K aligned region all by itself. Align it to
+ * target pages so that drivers can do passthrough
+ * on the rest of the region. */
+#define MSIX_PAGE_SIZE target_page_align(0x1000)
+/* Reserve second half of the page for pending bits */
+#define MSIX_PAGE_PENDING (MSIX_PAGE_SIZE / 2)
#define MSIX_MAX_ENTRIES 32
@@ -53,12 +63,6 @@
/* Flag for interrupt controller to declare MSI-X support */
int msix_supported;
-/* Reserve second half of the page for pending bits */
-static int msix_page_pending(PCIDevice *d)
-{
- return (d->msix_page_size / 2);
-}
-
/* Add MSI-X capability to the config space for the device. */
/* Given a bar and its size, add MSI-X table on top of it
* and fill MSI-X capability in the config space.
@@ -77,11 +81,11 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
return -ENOSPC;
/* Add space for MSI-X structures */
- if (!bar_size) {
- new_size = pdev->msix_page_size;
- } else if (bar_size < pdev->msix_page_size) {
- bar_size = pdev->msix_page_size;
- new_size = pdev->msix_page_size * 2;
+ if (!bar_size)
+ new_size = MSIX_PAGE_SIZE;
+ else if (bar_size < MSIX_PAGE_SIZE) {
+ bar_size = MSIX_PAGE_SIZE;
+ new_size = MSIX_PAGE_SIZE * 2;
} else
new_size = bar_size * 2;
@@ -95,8 +99,8 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
/* Table on top of BAR */
pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
/* Pending bits on top of that */
- pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + msix_page_pending(pdev))
- | bar_nr);
+ pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + MSIX_PAGE_PENDING) |
+ bar_nr);
pdev->msix_cap = config_offset;
/* Make flags bit writeable. */
pdev->wmask[config_offset + MSIX_ENABLE_OFFSET] |= MSIX_ENABLE_MASK;
@@ -126,7 +130,7 @@ void msix_write_config(PCIDevice *dev, uint32_t addr,
static uint32_t msix_mmio_readl(void *opaque, target_phys_addr_t addr)
{
PCIDevice *dev = opaque;
- unsigned int offset = addr & (dev->msix_page_size - 1);
+ unsigned int offset = addr & (MSIX_PAGE_SIZE - 1);
void *page = dev->msix_table_page;
uint32_t val = 0;
@@ -148,7 +152,7 @@ static uint8_t msix_pending_mask(int vector)
static uint8_t *msix_pending_byte(PCIDevice *dev, int vector)
{
- return dev->msix_table_page + msix_page_pending(dev) + vector / 8;
+ return dev->msix_table_page + MSIX_PAGE_PENDING + vector / 8;
}
static int msix_is_pending(PCIDevice *dev, int vector)
@@ -176,7 +180,7 @@ static void msix_mmio_writel(void *opaque, target_phys_addr_t addr,
uint32_t val)
{
PCIDevice *dev = opaque;
- unsigned int offset = addr & (dev->msix_page_size - 1);
+ unsigned int offset = addr & (MSIX_PAGE_SIZE - 1);
int vector = offset / MSIX_ENTRY_SIZE;
memcpy(dev->msix_table_page + offset, &val, 4);
if (!msix_is_masked(dev, vector) && msix_is_pending(dev, vector)) {
@@ -205,7 +209,7 @@ void msix_mmio_map(PCIDevice *d, int region_num,
{
uint8_t *config = d->config + d->msix_cap;
uint32_t table = pci_get_long(config + MSIX_TABLE_OFFSET);
- uint32_t offset = table & ~(d->msix_page_size - 1);
+ uint32_t offset = table & ~(MSIX_PAGE_SIZE - 1);
/* TODO: for assigned devices, we'll want to make it possible to map
* pending bits separately in case they are in a separate bar. */
int table_bir = table & PCI_MSIX_FLAGS_BIRMASK;
@@ -221,7 +225,7 @@ void msix_mmio_map(PCIDevice *d, int region_num,
/* Initialize the MSI-X structures. Note: if MSI-X is supported, BAR size is
* modified, it should be retrieved with msix_bar_size. */
int msix_init(struct PCIDevice *dev, unsigned short nentries,
- unsigned bar_nr, unsigned bar_size, target_phys_addr_t page_size)
+ unsigned bar_nr, unsigned bar_size)
{
int ret;
/* Nothing to do if MSI is not supported by interrupt controller */
@@ -234,8 +238,7 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
sizeof *dev->msix_entry_used);
- dev->msix_page_size = page_size;
- dev->msix_table_page = qemu_mallocz(dev->msix_page_size);
+ dev->msix_table_page = qemu_mallocz(MSIX_PAGE_SIZE);
dev->msix_mmio_index = cpu_register_io_memory(msix_mmio_read,
msix_mmio_write, dev);
@@ -290,8 +293,7 @@ void msix_save(PCIDevice *dev, QEMUFile *f)
}
qemu_put_buffer(f, dev->msix_table_page, n * MSIX_ENTRY_SIZE);
- qemu_put_buffer(f, dev->msix_table_page + msix_page_pending(dev),
- (n + 7) / 8);
+ qemu_put_buffer(f, dev->msix_table_page + MSIX_PAGE_PENDING, (n + 7) / 8);
}
/* Should be called after restoring the config space. */
@@ -305,8 +307,7 @@ void msix_load(PCIDevice *dev, QEMUFile *f)
msix_free_irq_entries(dev);
qemu_get_buffer(f, dev->msix_table_page, n * MSIX_ENTRY_SIZE);
- qemu_get_buffer(f, dev->msix_table_page + msix_page_pending(dev),
- (n + 7) / 8);
+ qemu_get_buffer(f, dev->msix_table_page + MSIX_PAGE_PENDING, (n + 7) / 8);
}
/* Does device support MSI-X? */
@@ -356,7 +357,7 @@ void msix_reset(PCIDevice *dev)
return;
msix_free_irq_entries(dev);
dev->config[dev->msix_cap + MSIX_ENABLE_OFFSET] &= MSIX_ENABLE_MASK;
- memset(dev->msix_table_page, 0, dev->msix_page_size);
+ memset(dev->msix_table_page, 0, MSIX_PAGE_SIZE);
}
/* PCI spec suggests that devices make it possible for software to configure
diff --git a/hw/msix.h b/hw/msix.h
index 9367ba3..3427778 100644
--- a/hw/msix.h
+++ b/hw/msix.h
@@ -3,9 +3,8 @@
#include "qemu-common.h"
-int msix_init(struct PCIDevice *dev, unsigned short nentries,
- unsigned bar_nr, unsigned bar_size,
- target_phys_addr_t page_size);
+int msix_init(PCIDevice *pdev, unsigned short nentries,
+ unsigned bar_nr, unsigned bar_size);
void msix_write_config(PCIDevice *pci_dev, uint32_t address,
uint32_t val, int len);
diff --git a/hw/pci.h b/hw/pci.h
index dddd599..8cfc38d 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -214,12 +214,6 @@ struct PCIDevice {
uint32_t msix_bar_size;
/* Version id needed for VMState */
int32_t version_id;
- /* How much space does an MSIX table need. */
- /* The spec requires giving the table structure
- * a 4K aligned region all by itself. Align it to
- * target pages so that drivers can do passthrough
- * on the rest of the region. */
- target_phys_addr_t msix_page_size;
};
PCIDevice *pci_register_device(PCIBus *bus, const char *name,
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 1f14c5e..3a0231e 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -410,8 +410,7 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
config[0x3d] = 1;
- if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0,
- TARGET_PAGE_SIZE)) {
+ if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0)) {
pci_register_bar(&proxy->pci_dev, 1,
msix_bar_size(&proxy->pci_dev),
PCI_ADDRESS_SPACE_MEM,
diff --git a/target.c b/target.c
new file mode 100644
index 0000000..3287eea
--- /dev/null
+++ b/target.c
@@ -0,0 +1,17 @@
+/*
+ * Target definitions for use by devices.
+ *
+ * Author: Michael S. Tsirkin <mst@redhat.com>
+ *
+ * Copyright (c) 2009, Red Hat Inc, Michael S. Tsirkin (mst@redhat.com)
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#include "qemu-common.h"
+#include "target.h"
+
+unsigned target_page_align(unsigned value)
+{
+ return TARGET_PAGE_ALIGN(value);
+}
diff --git a/target.h b/target.h
new file mode 100644
index 0000000..0e01e47
--- /dev/null
+++ b/target.h
@@ -0,0 +1,6 @@
+#ifndef QEMU_TARGET_H
+#define QEMU_TARGET_H
+
+unsigned target_page_align(unsigned value);
+
+#endif
--
1.6.5.rc2
next reply other threads:[~2009-09-23 20:08 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-23 20:06 Michael S. Tsirkin [this message]
2009-09-24 17:50 ` [Qemu-devel] Re: [PATCHv2] qemu: target library, use it in msix Blue Swirl
2009-09-24 19:11 ` Michael S. Tsirkin
2009-09-24 20:13 ` Blue Swirl
2009-09-29 16:11 ` [Qemu-devel] CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix) Michael S. Tsirkin
2009-09-29 18:15 ` [Qemu-devel] " Blue Swirl
2009-09-30 13:51 ` Michael S. Tsirkin
2009-09-30 16:50 ` malc
2009-09-30 17:00 ` Avi Kivity
2009-09-30 17:29 ` Michael S. Tsirkin
2009-09-30 17:29 ` Blue Swirl
2009-09-30 21:01 ` Anthony Liguori
2009-10-01 6:17 ` Michael S. Tsirkin
2009-10-01 8:43 ` Kevin Wolf
2009-10-01 8:58 ` Michael S. Tsirkin
2009-10-01 9:10 ` Kevin Wolf
2009-10-01 9:17 ` Michael S. Tsirkin
2009-10-01 6:31 ` Avi Kivity
2009-10-01 6:47 ` Michael S. Tsirkin
2009-10-01 7:08 ` Paolo Bonzini
2009-09-30 17:00 ` [Qemu-devel] Re: CODING_STYLE Juan Quintela
2009-10-01 1:25 ` Edgar E. Iglesias
2009-10-01 6:41 ` Michael S. Tsirkin
2009-10-01 9:01 ` Gleb Natapov
2009-10-01 8:56 ` Kevin Wolf
2009-10-01 9:02 ` Michael S. Tsirkin
2009-10-01 9:46 ` Gleb Natapov
2009-10-01 10:02 ` Michael S. Tsirkin
2009-10-01 9:01 ` Gleb Natapov
2009-09-30 17:02 ` Markus Armbruster
2009-10-01 6:37 ` Amit Shah
2009-09-30 17:31 ` [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix) Paolo Bonzini
2009-09-30 17:32 ` Michael S. Tsirkin
2009-09-30 17:48 ` Michael S. Tsirkin
2009-09-30 18:32 ` Paolo Bonzini
2009-10-01 6:00 ` Michael S. Tsirkin
2009-09-30 20:11 ` [Qemu-devel] Re: CODING_STYLE Markus Armbruster
2009-09-30 21:00 ` [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix) Anthony Liguori
2009-09-30 23:01 ` [Qemu-devel] Re: CODING_STYLE Markus Armbruster
2009-09-30 23:24 ` Anthony Liguori
2009-09-30 16:06 ` [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix) Christoph Hellwig
2009-09-30 16:14 ` Michael S. Tsirkin
2009-09-30 21:04 ` Anthony Liguori
2009-09-27 8:20 ` [Qemu-devel] Re: [PATCHv2] qemu: target library, use it in msix Michael S. Tsirkin
2009-09-27 10:40 ` Avi Kivity
2009-09-27 11:45 ` Michael S. Tsirkin
2009-09-27 11:55 ` Avi Kivity
2009-09-27 12:00 ` Michael S. Tsirkin
2009-09-27 12:19 ` Avi Kivity
2009-09-27 14:08 ` Michael S. Tsirkin
2009-09-27 14:14 ` Avi Kivity
2009-09-27 14:21 ` Michael S. Tsirkin
2009-09-27 14:24 ` Michael S. Tsirkin
2009-09-27 15:19 ` Blue Swirl
2009-09-29 14:50 ` Michael S. Tsirkin
2009-09-29 15:15 ` Blue Swirl
2009-09-29 15:57 ` Michael S. Tsirkin
2009-09-29 16:26 ` Avi Kivity
2009-09-29 16:38 ` Michael S. Tsirkin
2009-09-29 19:34 ` Blue Swirl
2009-09-29 21:09 ` Michael S. Tsirkin
2009-09-27 14:26 ` Avi Kivity
2009-09-29 7:19 ` 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=20090923200635.GA21246@redhat.com \
--to=mst@redhat.com \
--cc=blauwirbel@gmail.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 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.