2 * QEMU paravirtual RDMA - Generic RDMA backend
4 * Copyright (C) 2018 Oracle
5 * Copyright (C) 2018 Red Hat Inc
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
16 #include "qemu/osdep.h"
18 #include "rdma_utils.h"
20 void *rdma_pci_dma_map(PCIDevice *dev, dma_addr_t addr, dma_addr_t plen)
26 rdma_error_report("addr is NULL");
30 p = pci_dma_map(dev, addr, &len, DMA_DIRECTION_TO_DEVICE);
32 rdma_error_report("pci_dma_map fail, addr=0x%"PRIx64", len=%"PRId64,
38 rdma_pci_dma_unmap(dev, p, len);
42 trace_rdma_pci_dma_map(addr, p, len);
47 void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len)
49 trace_rdma_pci_dma_unmap(buffer);
51 pci_dma_unmap(dev, buffer, len, DMA_DIRECTION_TO_DEVICE, 0);
55 void rdma_protected_gqueue_init(RdmaProtectedGQueue *list)
57 qemu_mutex_init(&list->lock);
58 list->list = g_queue_new();
61 void rdma_protected_gqueue_destroy(RdmaProtectedGQueue *list)
64 g_queue_free_full(list->list, g_free);
65 qemu_mutex_destroy(&list->lock);
70 void rdma_protected_gqueue_append_int64(RdmaProtectedGQueue *list,
73 qemu_mutex_lock(&list->lock);
74 g_queue_push_tail(list->list, g_memdup(&value, sizeof(value)));
75 qemu_mutex_unlock(&list->lock);
78 int64_t rdma_protected_gqueue_pop_int64(RdmaProtectedGQueue *list)
83 qemu_mutex_lock(&list->lock);
85 valp = g_queue_pop_head(list->list);
86 qemu_mutex_unlock(&list->lock);
97 void rdma_protected_gslist_init(RdmaProtectedGSList *list)
99 qemu_mutex_init(&list->lock);
102 void rdma_protected_gslist_destroy(RdmaProtectedGSList *list)
105 g_slist_free(list->list);
106 qemu_mutex_destroy(&list->lock);
111 void rdma_protected_gslist_append_int32(RdmaProtectedGSList *list,
114 qemu_mutex_lock(&list->lock);
115 list->list = g_slist_prepend(list->list, GINT_TO_POINTER(value));
116 qemu_mutex_unlock(&list->lock);
119 void rdma_protected_gslist_remove_int32(RdmaProtectedGSList *list,
122 qemu_mutex_lock(&list->lock);
123 list->list = g_slist_remove(list->list, GINT_TO_POINTER(value));
124 qemu_mutex_unlock(&list->lock);