summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérôme Glisse <jglisse@redhat.com>2017-08-03 19:45:48 -0400
committerJérôme Glisse <jglisse@redhat.com>2017-08-04 17:38:40 -0400
commit5df632a124dc5d10cb8111957fd460d40f1154a8 (patch)
tree4c7223ca088670aef22de89e827bc2b3316cf8a7
parenta4e1562dfe0664bfc2254e05fc9dd1d152d8ec9d (diff)
compote: mmap memory object at creation
Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
-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