amdgpu: support non-page-aligned userptr
authormonk.liu <monk.liu@amd.com>
Thu, 23 Apr 2015 05:18:59 +0000 (13:18 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 5 Aug 2015 17:47:48 +0000 (13:47 -0400)
Signed-off-by: monk.liu <monk.liu@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
amdgpu/amdgpu_bo.c
amdgpu/amdgpu_internal.h

index 8ba459294a1f0e928f885face104c7e020bd62f8..cbc4cd6cf1009fda857965add646aba12206e893 100644 (file)
@@ -587,9 +587,17 @@ int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
        struct amdgpu_bo *bo;
        struct drm_amdgpu_gem_userptr args;
        union drm_amdgpu_gem_va va;
+       uintptr_t cpu0;
+       uint32_t ps, off;
 
        memset(&args, 0, sizeof(args));
-       args.addr = (uint64_t)cpu;
+       ps = getpagesize();
+
+       cpu0 = ROUND_DOWN((uintptr_t)cpu, ps);
+       off = (uintptr_t)cpu - cpu0;
+       size = ROUND_UP(size + off, ps);
+
+       args.addr = cpu0;
        args.flags = AMDGPU_GEM_USERPTR_ANONONLY | AMDGPU_GEM_USERPTR_REGISTER;
        args.size = size;
        r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_GEM_USERPTR,
@@ -622,5 +630,7 @@ int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
                            (void*)(uintptr_t)bo->virtual_mc_base_address, bo);
        info->buf_handle = bo;
        info->virtual_mc_base_address = bo->virtual_mc_base_address;
+       info->virtual_mc_base_address += off;
+
        return r;
 }
index 8346f16b597107fbe9eb2f30a62dc21ab86c0772..19bc7e187cd2d2fceec568e8dfa3ae1ef0158609 100644 (file)
@@ -35,6 +35,9 @@
 #include "util_double_list.h"
 
 #define AMDGPU_CS_MAX_RINGS 8
+/* do not use below macro if b is not power of 2 aligned value */
+#define ROUND_DOWN(a,b) ((a) & (~((b)-1)))
+#define ROUND_UP(a,b) (((a)+((b)-1)) & (~((b)-1)))
 
 struct amdgpu_bo_va_hole {
        struct list_head list;