summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compote.c13
-rw-r--r--compote.h9
2 files changed, 22 insertions, 0 deletions
diff --git a/compote.c b/compote.c
index 190aff6..49a3ea9 100644
--- a/compote.c
+++ b/compote.c
@@ -20,6 +20,7 @@
#include <strings.h>
#include <unistd.h>
#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
@@ -96,6 +97,17 @@ int compote_mo_new(compote_context_t *ctx, compote_mo_t **mop, uint64_t nbytes)
mo->foffset = arg.foffset;
mo->nbytes = nbytes;
+
+ mo->ptr = mmap(NULL, mo->nbytes, PROT_READ | PROT_WRITE,
+ MAP_SHARED, ctx->fd, mo->foffset);
+ if (mo->ptr == MAP_FAILED) {
+ mo->ptr = NULL;
+ compote_mo_del(ctx, &mo);
+ return -errno;
+ }
+
+ memset(mo->ptr, 0, mo->nbytes);
+
*mop = mo;
return 0;
}
@@ -111,6 +123,7 @@ void compote_mo_del(compote_context_t *ctx, compote_mo_t **mop)
}
arg.foffset = mo->foffset;
+ munmap(mo->ptr, mo->nbytes);
compote_context_ioctl(ctx, COMPOTE_IOCTL_MEM_FREE, &arg);
free(mo);
}
diff --git a/compote.h b/compote.h
index 4c5bb18..b7811fb 100644
--- a/compote.h
+++ b/compote.h
@@ -35,4 +35,13 @@ int compote_context_ioctl(compote_context_t *ctx, int command, void *arg);
int compote_mo_new(compote_context_t *ctx, compote_mo_t **mop, uint64_t nbytes);
void compote_mo_del(compote_context_t *ctx, compote_mo_t **mop);
+static inline uint64_t compote_mo_gpu_addr(compote_mo_t *mo)
+{
+ if (mo == NULL || mo->ptr == NULL) {
+ return -1UL;
+ }
+
+ return (unsigned long)mo->ptr;
+}
+
#endif // COMPOTE_H