[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC server v2 06/11] vfio-user: handle PCI config space accesses
From: |
Jagannathan Raman |
Subject: |
[PATCH RFC server v2 06/11] vfio-user: handle PCI config space accesses |
Date: |
Fri, 27 Aug 2021 13:53:25 -0400 |
Define and register handlers for PCI config space accesses
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
hw/remote/vfio-user-obj.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
hw/remote/trace-events | 2 ++
2 files changed, 46 insertions(+)
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index 0726eb9..13011ce 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -36,6 +36,7 @@
#include "sysemu/runstate.h"
#include "qemu/notify.h"
#include "qemu/thread.h"
+#include "qemu/main-loop.h"
#include "qapi/error.h"
#include "sysemu/sysemu.h"
#include "libvfio-user.h"
@@ -144,6 +145,38 @@ retry_attach:
return NULL;
}
+static ssize_t vfu_object_cfg_access(vfu_ctx_t *vfu_ctx, char * const buf,
+ size_t count, loff_t offset,
+ const bool is_write)
+{
+ VfuObject *o = vfu_get_private(vfu_ctx);
+ uint32_t pci_access_width = sizeof(uint32_t);
+ size_t bytes = count;
+ uint32_t val = 0;
+ char *ptr = buf;
+ int len;
+
+ while (bytes > 0) {
+ len = (bytes > pci_access_width) ? pci_access_width : bytes;
+ if (is_write) {
+ memcpy(&val, ptr, len);
+ pci_default_write_config(PCI_DEVICE(o->pci_dev),
+ offset, val, len);
+ trace_vfu_cfg_write(offset, val);
+ } else {
+ val = pci_default_read_config(PCI_DEVICE(o->pci_dev),
+ offset, len);
+ memcpy(ptr, &val, len);
+ trace_vfu_cfg_read(offset, val);
+ }
+ offset += len;
+ ptr += len;
+ bytes -= len;
+ }
+
+ return count;
+}
+
static void vfu_object_machine_done(Notifier *notifier, void *data)
{
VfuObject *o = container_of(notifier, VfuObject, machine_done);
@@ -182,6 +215,17 @@ static void vfu_object_machine_done(Notifier *notifier,
void *data)
return;
}
+ ret = vfu_setup_region(o->vfu_ctx, VFU_PCI_DEV_CFG_REGION_IDX,
+ pci_config_size(o->pci_dev), &vfu_object_cfg_access,
+ VFU_REGION_FLAG_RW | VFU_REGION_FLAG_ALWAYS_CB,
+ NULL, 0, -1, 0);
+ if (ret < 0) {
+ error_setg(&error_abort,
+ "vfu: Failed to setup config space handlers for %s- %s",
+ o->devid, strerror(errno));
+ return;
+ }
+
ret = vfu_realize_ctx(o->vfu_ctx);
if (ret < 0) {
error_setg(&error_abort, "vfu: Failed to realize device %s- %s",
diff --git a/hw/remote/trace-events b/hw/remote/trace-events
index 7da12f0..2ef7884 100644
--- a/hw/remote/trace-events
+++ b/hw/remote/trace-events
@@ -5,3 +5,5 @@ mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to
receive %d size %d,
# vfio-user-obj.c
vfu_prop(const char *prop, const char *val) "vfu: setting %s as %s"
+vfu_cfg_read(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u -> 0x%x"
+vfu_cfg_write(uint32_t offset, uint32_t val) "vfu: cfg: 0x%u <- 0x%x"
--
1.8.3.1
- Re: [PATCH RFC v2 01/16] vfio-user: introduce vfio-user protocol specification, (continued)
- [PATCH RFC v2 13/16] vfio-user: dma map/unmap operations, Elena Ufimtseva, 2021/08/16
- [PATCH RFC v2 16/16] vfio-user: migration support, Elena Ufimtseva, 2021/08/16
- [PATCH RFC server v2 00/11] vfio-user server in QEMU, Jagannathan Raman, 2021/08/27
- [PATCH RFC server v2 01/11] vfio-user: build library, Jagannathan Raman, 2021/08/27
- [PATCH RFC server v2 02/11] vfio-user: define vfio-user object, Jagannathan Raman, 2021/08/27
- [PATCH RFC server v2 03/11] vfio-user: instantiate vfio-user context, Jagannathan Raman, 2021/08/27
- [PATCH RFC server v2 04/11] vfio-user: find and init PCI device, Jagannathan Raman, 2021/08/27
- [PATCH RFC server v2 05/11] vfio-user: run vfio-user context, Jagannathan Raman, 2021/08/27
- [PATCH RFC server v2 07/11] vfio-user: handle DMA mappings, Jagannathan Raman, 2021/08/27
- [PATCH RFC server v2 06/11] vfio-user: handle PCI config space accesses,
Jagannathan Raman <=
- [PATCH RFC server v2 08/11] vfio-user: handle PCI BAR accesses, Jagannathan Raman, 2021/08/27
- [PATCH RFC server v2 09/11] vfio-user: handle device interrupts, Jagannathan Raman, 2021/08/27
- [PATCH RFC server v2 10/11] vfio-user: register handlers to facilitate migration, Jagannathan Raman, 2021/08/27
- [PATCH RFC server v2 11/11] vfio-user: acceptance test, Jagannathan Raman, 2021/08/27