@@ -12,6 +12,12 @@ else()
set(DMABUF_ALLOC dmabuf_alloc_stub.c)
endif()
+if (HAVE_COHERENT_DMA)
+ set(DMA_UTIL dma_util.pyx)
+else()
+ set(DMA_UTIL "")
+endif()
+
rdma_cython_module(pyverbs ""
addr.pyx
base.pyx
@@ -19,6 +25,7 @@ rdma_cython_module(pyverbs ""
cmid.pyx
cq.pyx
device.pyx
+ ${DMA_UTIL}
dmabuf.pyx
${DMABUF_ALLOC}
enums.pyx
new file mode 100644
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
+# Copyright (c) 2021 Nvidia, Inc. All rights reserved. See COPYING file
+
+#cython: language_level=3
+
+from libc.stdint cimport uintptr_t, uint64_t
+
+cdef extern from 'util/udma_barrier.h':
+ cdef void udma_to_device_barrier()
+ cdef void udma_from_device_barrier()
+
+cdef extern from 'util/mmio.h':
+ cdef void mmio_write64_be(void *addr, uint64_t val)
+
+
+def udma_to_dev_barrier():
+ udma_to_device_barrier()
+
+
+def udma_from_dev_barrier():
+ udma_from_device_barrier()
+
+
+def mmio_write64_as_be(addr, val):
+ mmio_write64_be(<void*><uintptr_t> addr, val)
@@ -6,13 +6,17 @@
from posix.stdlib cimport posix_memalign as c_posix_memalign
from libc.stdlib cimport malloc as c_malloc, free as c_free
from posix.mman cimport mmap as c_mmap, munmap as c_munmap
-from libc.stdint cimport uintptr_t
+from libc.stdint cimport uintptr_t, uint32_t, uint64_t
from libc.string cimport memset
cimport posix.mman as mm
cdef extern from 'sys/mman.h':
cdef void* MAP_FAILED
+cdef extern from 'endian.h':
+ unsigned long htobe32(unsigned long host_32bits)
+ unsigned long htobe64(unsigned long host_64bits)
+
def mmap(addr=0, length=100, prot=mm.PROT_READ | mm.PROT_WRITE,
flags=mm.MAP_PRIVATE | mm.MAP_ANONYMOUS, fd=0, offset=0):
@@ -82,6 +86,46 @@ def free(ptr):
c_free(<void*><uintptr_t>ptr)
+def writebe32(addr, val, offset=0):
+ """
+ Write 32-bit value <val> as Big Endian to address <addr> and offset <offset>
+ :param addr: The start of the address to write the value to
+ :param val: Value to write
+ :param offset: Offset of the address to write the value to (in 4-bytes)
+ """
+ (<uint32_t*><void*><uintptr_t>addr)[offset] = htobe32(val)
+
+
+def writebe64(addr, val, offset=0):
+ """
+ Write 64-bit value <val> as Big Endian to address <addr> and offset <offset>
+ :param addr: The start of the address to write the value to
+ :param val: Value to write
+ :param offset: Offset of the address to write the value to (in 8-bytes)
+ """
+ (<uint64_t*><void*><uintptr_t>addr)[offset] = htobe64(val)
+
+
+def read32(addr, offset=0):
+ """
+ Read 32-bit value from address <addr> and offset <offset>
+ :param addr: The start of the address to read from
+ :param offset: Offset of the address to read from (in 4-bytes)
+ :return: The read value
+ """
+ return (<uint32_t*><uintptr_t>addr)[offset]
+
+
+def read64(addr, offset=0):
+ """
+ Read 64-bit value from address <addr> and offset <offset>
+ :param addr: The start of the address to read from
+ :param offset: Offset of the address to read from (in 8-bytes)
+ :return: The read value
+ """
+ return (<uint64_t*><uintptr_t>addr)[offset]
+
+
# protection bits for mmap/mprotect
PROT_EXEC_ = mm.PROT_EXEC
PROT_READ_ = mm.PROT_READ