|
@@ -46,6 +46,7 @@
|
|
|
#include "qapi/qapi-events-misc.h"
|
|
|
#include "qemu/notify.h"
|
|
|
#include "qemu/thread.h"
|
|
|
+#include "qemu/main-loop.h"
|
|
|
#include "sysemu/sysemu.h"
|
|
|
#include "libvfio-user.h"
|
|
|
#include "hw/qdev-core.h"
|
|
@@ -244,6 +245,45 @@ retry_attach:
|
|
|
qemu_set_fd_handler(o->vfu_poll_fd, vfu_object_ctx_run, NULL, o);
|
|
|
}
|
|
|
|
|
|
+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;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Writes to the BAR registers would trigger an update to the
|
|
|
+ * global Memory and IO AddressSpaces. But the remote device
|
|
|
+ * never uses the global AddressSpaces, therefore overlapping
|
|
|
+ * memory regions are not a problem
|
|
|
+ */
|
|
|
+ while (bytes > 0) {
|
|
|
+ len = (bytes > pci_access_width) ? pci_access_width : bytes;
|
|
|
+ if (is_write) {
|
|
|
+ memcpy(&val, ptr, len);
|
|
|
+ pci_host_config_write_common(o->pci_dev, offset,
|
|
|
+ pci_config_size(o->pci_dev),
|
|
|
+ val, len);
|
|
|
+ trace_vfu_cfg_write(offset, val);
|
|
|
+ } else {
|
|
|
+ val = pci_host_config_read_common(o->pci_dev, offset,
|
|
|
+ pci_config_size(o->pci_dev), len);
|
|
|
+ memcpy(ptr, &val, len);
|
|
|
+ trace_vfu_cfg_read(offset, val);
|
|
|
+ }
|
|
|
+ offset += len;
|
|
|
+ ptr += len;
|
|
|
+ bytes -= len;
|
|
|
+ }
|
|
|
+
|
|
|
+ return count;
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
* TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
|
|
|
* properties. It also depends on devices instantiated in QEMU. These
|
|
@@ -336,6 +376,17 @@ static void vfu_object_init_ctx(VfuObject *o, Error **errp)
|
|
|
TYPE_VFU_OBJECT, o->device);
|
|
|
qdev_add_unplug_blocker(DEVICE(o->pci_dev), o->unplug_blocker);
|
|
|
|
|
|
+ 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(errp,
|
|
|
+ "vfu: Failed to setup config space handlers for %s- %s",
|
|
|
+ o->device, strerror(errno));
|
|
|
+ goto fail;
|
|
|
+ }
|
|
|
+
|
|
|
ret = vfu_realize_ctx(o->vfu_ctx);
|
|
|
if (ret < 0) {
|
|
|
error_setg(errp, "vfu: Failed to realize device %s- %s",
|