1 /* 2 * QEMU paravirtual RDMA - Generic RDMA backend 3 * 4 * Copyright (C) 2018 Oracle 5 * Copyright (C) 2018 Red Hat Inc 6 * 7 * Authors: 8 * Yuval Shaia <yuval.shaia@oracle.com> 9 * Marcel Apfelbaum <marcel@redhat.com> 10 * 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. 13 * 14 */ 15 16 #include "qemu/osdep.h" 17 #include "rdma_utils.h" 18 19 #ifdef PVRDMA_DEBUG 20 unsigned long pr_dbg_cnt; 21 #endif 22 23 void *rdma_pci_dma_map(PCIDevice *dev, dma_addr_t addr, dma_addr_t plen) 24 { 25 void *p; 26 hwaddr len = plen; 27 28 if (!addr) { 29 pr_dbg("addr is NULL\n"); 30 return NULL; 31 } 32 33 p = pci_dma_map(dev, addr, &len, DMA_DIRECTION_TO_DEVICE); 34 if (!p) { 35 pr_dbg("Fail in pci_dma_map, addr=0x%" PRIx64 ", len=%" PRId64 "\n", 36 addr, len); 37 return NULL; 38 } 39 40 if (len != plen) { 41 rdma_pci_dma_unmap(dev, p, len); 42 return NULL; 43 } 44 45 pr_dbg("0x%" PRIx64 " -> %p (len=% " PRId64 ")\n", addr, p, len); 46 47 return p; 48 } 49 50 void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len) 51 { 52 pr_dbg("%p\n", buffer); 53 if (buffer) { 54 pci_dma_unmap(dev, buffer, len, DMA_DIRECTION_TO_DEVICE, 0); 55 } 56 } 57