2 * QEMU paravirtual RDMA - Generic RDMA backend
4 * Copyright (C) 2018 Oracle
5 * Copyright (C) 2018 Red Hat Inc
8 * Yuval Shaia <yuval.shaia@oracle.com>
9 * Marcel Apfelbaum <marcel@redhat.com>
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"
17 #include "hw/pci/pci_device.h"
19 #include "rdma_utils.h"
21 void *rdma_pci_dma_map(PCIDevice
*dev
, dma_addr_t addr
, dma_addr_t len
)
24 dma_addr_t pci_len
= len
;
27 rdma_error_report("addr is NULL");
31 p
= pci_dma_map(dev
, addr
, &pci_len
, DMA_DIRECTION_TO_DEVICE
);
33 rdma_error_report("pci_dma_map fail, addr=0x%"PRIx64
", len=%"PRId64
,
39 rdma_pci_dma_unmap(dev
, p
, pci_len
);
43 trace_rdma_pci_dma_map(addr
, p
, pci_len
);
48 void rdma_pci_dma_unmap(PCIDevice
*dev
, void *buffer
, dma_addr_t len
)
50 trace_rdma_pci_dma_unmap(buffer
);
52 pci_dma_unmap(dev
, buffer
, len
, DMA_DIRECTION_TO_DEVICE
, 0);
56 void rdma_protected_gqueue_init(RdmaProtectedGQueue
*list
)
58 qemu_mutex_init(&list
->lock
);
59 list
->list
= g_queue_new();
62 void rdma_protected_gqueue_destroy(RdmaProtectedGQueue
*list
)
65 g_queue_free_full(list
->list
, g_free
);
66 qemu_mutex_destroy(&list
->lock
);
71 void rdma_protected_gqueue_append_int64(RdmaProtectedGQueue
*list
,
74 qemu_mutex_lock(&list
->lock
);
75 g_queue_push_tail(list
->list
, g_memdup(&value
, sizeof(value
)));
76 qemu_mutex_unlock(&list
->lock
);
79 int64_t rdma_protected_gqueue_pop_int64(RdmaProtectedGQueue
*list
)
84 qemu_mutex_lock(&list
->lock
);
86 valp
= g_queue_pop_head(list
->list
);
87 qemu_mutex_unlock(&list
->lock
);
98 void rdma_protected_gslist_init(RdmaProtectedGSList
*list
)
100 qemu_mutex_init(&list
->lock
);
103 void rdma_protected_gslist_destroy(RdmaProtectedGSList
*list
)
106 g_slist_free(list
->list
);
107 qemu_mutex_destroy(&list
->lock
);
112 void rdma_protected_gslist_append_int32(RdmaProtectedGSList
*list
,
115 qemu_mutex_lock(&list
->lock
);
116 list
->list
= g_slist_prepend(list
->list
, GINT_TO_POINTER(value
));
117 qemu_mutex_unlock(&list
->lock
);
120 void rdma_protected_gslist_remove_int32(RdmaProtectedGSList
*list
,
123 qemu_mutex_lock(&list
->lock
);
124 list
->list
= g_slist_remove(list
->list
, GINT_TO_POINTER(value
));
125 qemu_mutex_unlock(&list
->lock
);