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 "qapi/qmp/qlist.h"
18 #include "qapi/qmp/qnum.h"
20 #include "rdma_utils.h"
22 void *rdma_pci_dma_map(PCIDevice
*dev
, dma_addr_t addr
, dma_addr_t plen
)
28 rdma_error_report("addr is NULL");
32 p
= pci_dma_map(dev
, addr
, &len
, DMA_DIRECTION_TO_DEVICE
);
34 rdma_error_report("pci_dma_map fail, addr=0x%"PRIx64
", len=%"PRId64
,
40 rdma_pci_dma_unmap(dev
, p
, len
);
44 trace_rdma_pci_dma_map(addr
, p
, len
);
49 void rdma_pci_dma_unmap(PCIDevice
*dev
, void *buffer
, dma_addr_t len
)
51 trace_rdma_pci_dma_unmap(buffer
);
53 pci_dma_unmap(dev
, buffer
, len
, DMA_DIRECTION_TO_DEVICE
, 0);
57 void rdma_protected_qlist_init(RdmaProtectedQList
*list
)
59 qemu_mutex_init(&list
->lock
);
60 list
->list
= qlist_new();
63 void rdma_protected_qlist_destroy(RdmaProtectedQList
*list
)
66 qlist_destroy_obj(QOBJECT(list
->list
));
67 qemu_mutex_destroy(&list
->lock
);
72 void rdma_protected_qlist_append_int64(RdmaProtectedQList
*list
, int64_t value
)
74 qemu_mutex_lock(&list
->lock
);
75 qlist_append_int(list
->list
, value
);
76 qemu_mutex_unlock(&list
->lock
);
79 int64_t rdma_protected_qlist_pop_int64(RdmaProtectedQList
*list
)
83 qemu_mutex_lock(&list
->lock
);
84 obj
= qlist_pop(list
->list
);
85 qemu_mutex_unlock(&list
->lock
);
91 return qnum_get_uint(qobject_to(QNum
, obj
));
94 void rdma_protected_gslist_init(RdmaProtectedGSList
*list
)
96 qemu_mutex_init(&list
->lock
);
99 void rdma_protected_gslist_destroy(RdmaProtectedGSList
*list
)
102 g_slist_free(list
->list
);
103 qemu_mutex_destroy(&list
->lock
);
108 void rdma_protected_gslist_append_int32(RdmaProtectedGSList
*list
,
111 qemu_mutex_lock(&list
->lock
);
112 list
->list
= g_slist_prepend(list
->list
, GINT_TO_POINTER(value
));
113 qemu_mutex_unlock(&list
->lock
);
116 void rdma_protected_gslist_remove_int32(RdmaProtectedGSList
*list
,
119 qemu_mutex_lock(&list
->lock
);
120 list
->list
= g_slist_remove(list
->list
, GINT_TO_POINTER(value
));
121 qemu_mutex_unlock(&list
->lock
);