1 #include "nv_include.h"
3 NVAllocRec *NVAllocateMemory(NVPtr pNv, int type, int size)
5 struct drm_nouveau_mem_alloc memalloc;
8 mem = malloc(sizeof(NVAllocRec));
12 memalloc.flags = type | NOUVEAU_MEM_MAPPED;
14 memalloc.alignment = 0;
15 if (drmCommandWriteRead(pNv->drm_fd, DRM_NOUVEAU_MEM_ALLOC, &memalloc,
17 ErrorF("NOUVEAU_MEM_ALLOC failed. "
18 "flags=0x%08x, size=%lld (%d)\n",
19 memalloc.flags, memalloc.size, errno);
23 mem->type = memalloc.flags;
24 mem->size = memalloc.size;
25 mem->offset = memalloc.offset;
27 if (drmMap(pNv->drm_fd, memalloc.map_handle, mem->size, &mem->map)) {
28 ErrorF("drmMap() failed. handle=0x%x, size=%lld (%d)\n",
29 memalloc.map_handle, mem->size, errno);
31 NVFreeMemory(pNv, mem);
38 void NVFreeMemory(NVPtr pNv, NVAllocRec *mem)
40 struct drm_nouveau_mem_free memfree;
44 if (drmUnmap(mem->map, mem->size))
45 ErrorF("drmUnmap() failed. "
46 "map=%p, size=%lld\n",
50 memfree.flags = mem->type;
51 memfree.offset = mem->offset;
53 if (drmCommandWriteRead(pNv->drm_fd,
54 DRM_NOUVEAU_MEM_FREE, &memfree,
56 ErrorF("NOUVEAU_MEM_FREE failed. "
57 "flags=0x%08x, offset=0x%llx (%d)\n",
58 mem->type, mem->size, errno);