ppc/pnv: Link "chip" property to PnvCore::chip pointer
[qemu/ar7.git] / hw / rdma / rdma_utils.c
blob73f279104c37d10630b360ec7405faf691deb438
1 /*
2 * QEMU paravirtual RDMA - Generic RDMA backend
4 * Copyright (C) 2018 Oracle
5 * Copyright (C) 2018 Red Hat Inc
7 * Authors:
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"
19 #include "trace.h"
20 #include "rdma_utils.h"
22 void *rdma_pci_dma_map(PCIDevice *dev, dma_addr_t addr, dma_addr_t plen)
24 void *p;
25 hwaddr len = plen;
27 if (!addr) {
28 rdma_error_report("addr is NULL");
29 return NULL;
32 p = pci_dma_map(dev, addr, &len, DMA_DIRECTION_TO_DEVICE);
33 if (!p) {
34 rdma_error_report("pci_dma_map fail, addr=0x%"PRIx64", len=%"PRId64,
35 addr, len);
36 return NULL;
39 if (len != plen) {
40 rdma_pci_dma_unmap(dev, p, len);
41 return NULL;
44 trace_rdma_pci_dma_map(addr, p, len);
46 return p;
49 void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len)
51 trace_rdma_pci_dma_unmap(buffer);
52 if (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)
65 if (list->list) {
66 qlist_destroy_obj(QOBJECT(list->list));
67 qemu_mutex_destroy(&list->lock);
68 list->list = NULL;
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)
81 QObject *obj;
83 qemu_mutex_lock(&list->lock);
84 obj = qlist_pop(list->list);
85 qemu_mutex_unlock(&list->lock);
87 if (!obj) {
88 return -ENOENT;
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)
101 if (list->list) {
102 g_slist_free(list->list);
103 list->list = NULL;
107 void rdma_protected_gslist_append_int32(RdmaProtectedGSList *list,
108 int32_t value)
110 qemu_mutex_lock(&list->lock);
111 list->list = g_slist_prepend(list->list, GINT_TO_POINTER(value));
112 qemu_mutex_unlock(&list->lock);
115 void rdma_protected_gslist_remove_int32(RdmaProtectedGSList *list,
116 int32_t value)
118 qemu_mutex_lock(&list->lock);
119 list->list = g_slist_remove(list->list, GINT_TO_POINTER(value));
120 qemu_mutex_unlock(&list->lock);