summaryrefslogtreecommitdiff
path: root/screen.c
diff options
context:
space:
mode:
Diffstat (limited to 'screen.c')
-rw-r--r--screen.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/screen.c b/screen.c
index ffd2efc..40323fe 100644
--- a/screen.c
+++ b/screen.c
@@ -92,3 +92,30 @@ static uint64_t get_param(unsigned int param)
drmCommandWriteRead(drm_fd, DRM_NOUVEAU_GETPARAM, &getp, sizeof(getp));
return getp.value;
}
+
+void *screen_allocmem(int agp, int size, uint64_t *ofs)
+{
+ struct drm_nouveau_mem_alloc mema;
+ void *map;
+ int ret;
+
+ mema.flags = NOUVEAU_MEM_MAPPED;
+ mema.flags |= (agp ? NOUVEAU_MEM_AGP : NOUVEAU_MEM_FB);
+
+ mema.alignment = 0x1000;
+ mema.size = size;
+ ret = drmCommandWriteRead(drm_fd, DRM_NOUVEAU_MEM_ALLOC, &mema, sizeof(mema));
+ if (ret) {
+ fprintf(stderr, "Failed to alloc memory\n");
+ return NULL;
+ }
+ *ofs = mema.offset;
+
+ /* instead of mema.map_handle, originally we were passing in ofs */
+ if (drmMap(drm_fd, mema.map_handle, mema.size, &map)) {
+ fprintf(stderr, "Failed to map memory\n");
+ return NULL;
+ }
+
+ return map;
+}