From: Alex Williamson <alex.williamson@redhat.com>
To: kvm@vger.kernel.org
Cc: alex.williamson@redhat.com, avi@redhat.com, mst@redhat.com,
jan.kiszka@siemens.com, shashidhar.patil@gmail.com
Subject: [PATCH v2 3/8] pci-assign: Use struct for MSI-X table
Date: Tue, 31 Jan 2012 22:32:37 -0700 [thread overview]
Message-ID: <20120201053237.9843.24674.stgit@bling.home> (raw)
In-Reply-To: <20120201052203.9843.80792.stgit@bling.home>
This makes access much easier.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
hw/device-assignment.c | 55 ++++++++++++++++++++++--------------------------
hw/device-assignment.h | 9 +++++++-
2 files changed, 33 insertions(+), 31 deletions(-)
diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 67c417b..53c843e 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -966,10 +966,9 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)
AssignedDevice *adev = DO_UPCAST(AssignedDevice, dev, pci_dev);
uint16_t entries_nr = 0, entries_max_nr;
int pos = 0, i, r = 0;
- uint32_t msg_addr, msg_upper_addr, msg_data, msg_ctrl;
struct kvm_assigned_msix_nr msix_nr;
struct kvm_assigned_msix_entry msix_entry;
- void *va = adev->msix_table_page;
+ MSIXTableEntry *entry = adev->msix_table;
pos = pci_find_capability(pci_dev, PCI_CAP_ID_MSIX);
@@ -978,12 +977,11 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)
entries_max_nr += 1;
/* Get the usable entry number for allocating */
- for (i = 0; i < entries_max_nr; i++) {
- memcpy(&msg_ctrl, va + i * 16 + 12, 4);
- memcpy(&msg_data, va + i * 16 + 8, 4);
+ for (i = 0; i < entries_max_nr; i++, entry++) {
/* Ignore unused entry even it's unmasked */
- if (msg_data == 0)
+ if (entry->data == 0) {
continue;
+ }
entries_nr ++;
}
@@ -1006,16 +1004,13 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)
msix_entry.assigned_dev_id = msix_nr.assigned_dev_id;
entries_nr = 0;
- for (i = 0; i < entries_max_nr; i++) {
+ entry = adev->msix_table;
+ for (i = 0; i < entries_max_nr; i++, entry++) {
if (entries_nr >= msix_nr.entry_nr)
break;
- memcpy(&msg_ctrl, va + i * 16 + 12, 4);
- memcpy(&msg_data, va + i * 16 + 8, 4);
- if (msg_data == 0)
+ if (entry->data == 0) {
continue;
-
- memcpy(&msg_addr, va + i * 16, 4);
- memcpy(&msg_upper_addr, va + i * 16 + 4, 4);
+ }
r = kvm_get_irq_route_gsi();
if (r < 0)
@@ -1024,10 +1019,11 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)
adev->entry[entries_nr].gsi = r;
adev->entry[entries_nr].type = KVM_IRQ_ROUTING_MSI;
adev->entry[entries_nr].flags = 0;
- adev->entry[entries_nr].u.msi.address_lo = msg_addr;
- adev->entry[entries_nr].u.msi.address_hi = msg_upper_addr;
- adev->entry[entries_nr].u.msi.data = msg_data;
- DEBUG("MSI-X data 0x%x, MSI-X addr_lo 0x%x\n!", msg_data, msg_addr);
+ adev->entry[entries_nr].u.msi.address_lo = entry->addr_lo;
+ adev->entry[entries_nr].u.msi.address_hi = entry->addr_hi;
+ adev->entry[entries_nr].u.msi.data = entry->data;
+ DEBUG("MSI-X data 0x%x, MSI-X addr_lo 0x%x\n!",
+ entry->data, entry->addr_lo);
kvm_add_routing_entry(&adev->entry[entries_nr]);
msix_entry.gsi = adev->entry[entries_nr].gsi;
@@ -1436,7 +1432,7 @@ static uint64_t msix_mmio_read(void *opaque, target_phys_addr_t addr,
AssignedDevice *adev = opaque;
uint64_t val;
- memcpy(&val, (void *)((uint8_t *)adev->msix_table_page + addr), size);
+ memcpy(&val, (void *)((uint8_t *)adev->msix_table + addr), size);
return val;
}
@@ -1449,7 +1445,7 @@ static void msix_mmio_write(void *opaque, target_phys_addr_t addr,
DEBUG("write to MSI-X entry table mmio offset 0x%lx, val 0x%lx\n",
addr, val);
- memcpy((void *)((uint8_t *)adev->msix_table_page + addr), &val, size);
+ memcpy((void *)((uint8_t *)adev->msix_table + addr), &val, size);
}
static const MemoryRegionOps msix_mmio_ops = {
@@ -1468,15 +1464,13 @@ static const MemoryRegionOps msix_mmio_ops = {
static int assigned_dev_register_msix_mmio(AssignedDevice *dev)
{
- dev->msix_table_page = mmap(NULL, 0x1000,
- PROT_READ|PROT_WRITE,
- MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
- if (dev->msix_table_page == MAP_FAILED) {
- fprintf(stderr, "fail allocate msix_table_page! %s\n",
- strerror(errno));
+ dev->msix_table = mmap(NULL, 0x1000, PROT_READ|PROT_WRITE,
+ MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+ if (dev->msix_table == MAP_FAILED) {
+ fprintf(stderr, "fail allocate msix_table! %s\n", strerror(errno));
return -EFAULT;
}
- memset(dev->msix_table_page, 0, 0x1000);
+ memset(dev->msix_table, 0, 0x1000);
memory_region_init_io(&dev->mmio, &msix_mmio_ops, dev,
"assigned-dev-msix", MSIX_PAGE_SIZE);
return 0;
@@ -1484,16 +1478,17 @@ static int assigned_dev_register_msix_mmio(AssignedDevice *dev)
static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev)
{
- if (!dev->msix_table_page)
+ if (!dev->msix_table) {
return;
+ }
memory_region_destroy(&dev->mmio);
- if (munmap(dev->msix_table_page, 0x1000) == -1) {
- fprintf(stderr, "error unmapping msix_table_page! %s\n",
+ if (munmap(dev->msix_table, 0x1000) == -1) {
+ fprintf(stderr, "error unmapping msix_table! %s\n",
strerror(errno));
}
- dev->msix_table_page = NULL;
+ dev->msix_table = NULL;
}
static const VMStateDescription vmstate_assigned_device = {
diff --git a/hw/device-assignment.h b/hw/device-assignment.h
index 1b4aecc..2e06ebb 100644
--- a/hw/device-assignment.h
+++ b/hw/device-assignment.h
@@ -80,6 +80,13 @@ typedef struct {
#define ASSIGNED_DEVICE_USE_IOMMU_MASK (1 << ASSIGNED_DEVICE_USE_IOMMU_BIT)
#define ASSIGNED_DEVICE_PREFER_MSI_MASK (1 << ASSIGNED_DEVICE_PREFER_MSI_BIT)
+typedef struct {
+ uint32_t addr_lo;
+ uint32_t addr_hi;
+ uint32_t data;
+ uint32_t ctrl;
+} MSIXTableEntry;
+
typedef struct AssignedDevice {
PCIDevice dev;
PCIHostDevice host;
@@ -108,7 +115,7 @@ typedef struct AssignedDevice {
uint8_t emulate_config_write[PCI_CONFIG_SPACE_SIZE];
int irq_entries_nr;
struct kvm_irq_routing_entry *entry;
- void *msix_table_page;
+ MSIXTableEntry *msix_table;
target_phys_addr_t msix_table_addr;
MemoryRegion mmio;
char *configfd_name;
next prev parent reply other threads:[~2012-02-01 5:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-01 5:32 [PATCH v2 0/8] pci-assign: better MSI-X table support Alex Williamson
2012-02-01 5:32 ` [PATCH v2 1/8] pci-assign: Fix warnings with DEBUG enabled Alex Williamson
2012-02-01 5:32 ` [PATCH v2 2/8] pci-assign: Update MSI-X MMIO to Memory API Alex Williamson
2012-02-01 5:32 ` Alex Williamson [this message]
2012-02-01 5:32 ` [PATCH v2 4/8] pci-assign: Only calculate maximum MSI-X vector entries once Alex Williamson
2012-02-01 5:32 ` [PATCH v2 5/8] pci-assign: Proper initialization for MSI-X table Alex Williamson
2012-02-01 5:32 ` [PATCH v2 6/8] pci-assign: Allocate entries for all MSI-X vectors Alex Williamson
2012-02-01 5:33 ` [PATCH v2 7/8] pci-assign: Use MSIX_PAGE_SIZE Alex Williamson
2012-02-01 5:33 ` [PATCH v2 8/8] pci-assign: Update MSI-X config based on table writes Alex Williamson
2012-02-01 7:22 ` Michael S. Tsirkin
2012-02-01 13:48 ` Alex Williamson
2012-02-01 14:13 ` Jan Kiszka
2012-02-01 15:13 ` Michael S. Tsirkin
2012-02-01 7:25 ` Michael S. Tsirkin
2012-02-01 13:51 ` Alex Williamson
2012-02-07 20:04 ` [PATCH v2 0/8] pci-assign: better MSI-X table support Marcelo Tosatti
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=20120201053237.9843.24674.stgit@bling.home \
--to=alex.williamson@redhat.com \
--cc=avi@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=shashidhar.patil@gmail.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.