summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormonk.liu <monk.liu@amd.com>2015-04-23 13:18:59 +0800
committerAlex Deucher <alexander.deucher@amd.com>2015-07-30 00:11:09 -0400
commit6c87df22dcb5e8f0628eca0ecc6131c9638c2078 (patch)
tree79a476ebd1e3ecf45905d6f18f5575aa2a94f535
parentdda3b2bb7c591b8494ca09ca9b5a1cbf2d2baa72 (diff)
amdgpu: support non-page-aligned userptr
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>
-rw-r--r--amdgpu/amdgpu_bo.c12
-rw-r--r--amdgpu/amdgpu_internal.h3
2 files changed, 14 insertions, 1 deletions
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index 8ba45929..cbc4cd6c 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -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;
}
diff --git a/amdgpu/amdgpu_internal.h b/amdgpu/amdgpu_internal.h
index 8346f16b..19bc7e18 100644
--- a/amdgpu/amdgpu_internal.h
+++ b/amdgpu/amdgpu_internal.h
@@ -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;