Fam Zheng

util: Introduce vfio helpers

This is a library to manage the host vfio interface, which could be used
to implement userspace device driver code in QEMU such as NVMe or net
controllers.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20180116060901.17413-3-famz@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
  1 +/*
  2 + * QEMU VFIO helpers
  3 + *
  4 + * Copyright 2016 - 2018 Red Hat, Inc.
  5 + *
  6 + * Authors:
  7 + * Fam Zheng <famz@redhat.com>
  8 + *
  9 + * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10 + * See the COPYING file in the top-level directory.
  11 + */
  12 +
  13 +#ifndef QEMU_VFIO_HELPERS_H
  14 +#define QEMU_VFIO_HELPERS_H
  15 +#include "qemu/typedefs.h"
  16 +
  17 +typedef struct QEMUVFIOState QEMUVFIOState;
  18 +
  19 +QEMUVFIOState *qemu_vfio_open_pci(const char *device, Error **errp);
  20 +void qemu_vfio_close(QEMUVFIOState *s);
  21 +int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
  22 + bool temporary, uint64_t *iova_list);
  23 +int qemu_vfio_dma_reset_temporary(QEMUVFIOState *s);
  24 +void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host);
  25 +void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index,
  26 + uint64_t offset, uint64_t size,
  27 + Error **errp);
  28 +void qemu_vfio_pci_unmap_bar(QEMUVFIOState *s, int index, void *bar,
  29 + uint64_t offset, uint64_t size);
  30 +int qemu_vfio_pci_init_irq(QEMUVFIOState *s, EventNotifier *e,
  31 + int irq_type, Error **errp);
  32 +
  33 +#endif
@@ -46,3 +46,4 @@ util-obj-y += qht.o @@ -46,3 +46,4 @@ util-obj-y += qht.o
46 util-obj-y += range.o 46 util-obj-y += range.o
47 util-obj-y += stats64.o 47 util-obj-y += stats64.o
48 util-obj-y += systemd.o 48 util-obj-y += systemd.o
  49 +util-obj-$(CONFIG_LINUX) += vfio-helpers.o
@@ -60,3 +60,14 @@ lockcnt_futex_wake(const void *lockcnt) "lockcnt %p waking up one waiter" @@ -60,3 +60,14 @@ lockcnt_futex_wake(const void *lockcnt) "lockcnt %p waking up one waiter"
60 qemu_mutex_lock(void *mutex, const char *file, const int line) "waiting on mutex %p (%s:%d)" 60 qemu_mutex_lock(void *mutex, const char *file, const int line) "waiting on mutex %p (%s:%d)"
61 qemu_mutex_locked(void *mutex, const char *file, const int line) "taken mutex %p (%s:%d)" 61 qemu_mutex_locked(void *mutex, const char *file, const int line) "taken mutex %p (%s:%d)"
62 qemu_mutex_unlock(void *mutex, const char *file, const int line) "released mutex %p (%s:%d)" 62 qemu_mutex_unlock(void *mutex, const char *file, const int line) "released mutex %p (%s:%d)"
  63 +
  64 +# util/vfio-helpers.c
  65 +qemu_vfio_dma_reset_temporary(void *s) "s %p"
  66 +qemu_vfio_ram_block_added(void *s, void *p, size_t size) "s %p host %p size 0x%zx"
  67 +qemu_vfio_ram_block_removed(void *s, void *p, size_t size) "s %p host %p size 0x%zx"
  68 +qemu_vfio_find_mapping(void *s, void *p) "s %p host %p"
  69 +qemu_vfio_new_mapping(void *s, void *host, size_t size, int index, uint64_t iova) "s %p host %p size %zu index %d iova 0x%"PRIx64
  70 +qemu_vfio_do_mapping(void *s, void *host, size_t size, uint64_t iova) "s %p host %p size %zu iova 0x%"PRIx64
  71 +qemu_vfio_dma_map(void *s, void *host, size_t size, bool temporary, uint64_t *iova) "s %p host %p size %zu temporary %d iova %p"
  72 +qemu_vfio_dma_map_invalid(void *s, void *mapping_host, size_t mapping_size, void *host, size_t size) "s %p mapping %p %zu requested %p %zu"
  73 +qemu_vfio_dma_unmap(void *s, void *host) "s %p host %p"
This diff is collapsed. Click to expand it.