Skip to content

Commit ab43234

Browse files
Andrey Grodzovskyalexdeucher
authored andcommitted
drm/amdgpu: Initialise drm_gem_object_funcs for imported BOs
For BOs imported from outside of amdgpu, setting of amdgpu_gem_object_funcs was missing in amdgpu_dma_buf_create_obj. Fix by refactoring BO creation and amdgpu_gem_object_funcs setting into single function called from both code paths. Fixes: d693def ("drm: Remove obsolete GEM and PRIME callbacks from struct drm_driver") v2: Use use amdgpu_gem_object_create() directly v3: fix warning Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 157fe68 commit ab43234

2 files changed

Lines changed: 29 additions & 20 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf)
459459
struct amdgpu_device *adev = drm_to_adev(dev);
460460
struct amdgpu_bo *bo;
461461
struct amdgpu_bo_param bp;
462+
struct drm_gem_object *gobj;
462463
int ret;
463464

464465
memset(&bp, 0, sizeof(bp));
@@ -469,17 +470,20 @@ amdgpu_dma_buf_create_obj(struct drm_device *dev, struct dma_buf *dma_buf)
469470
bp.type = ttm_bo_type_sg;
470471
bp.resv = resv;
471472
dma_resv_lock(resv, NULL);
472-
ret = amdgpu_bo_create(adev, &bp, &bo);
473+
ret = amdgpu_gem_object_create(adev, dma_buf->size, PAGE_SIZE,
474+
AMDGPU_GEM_DOMAIN_CPU,
475+
0, ttm_bo_type_sg, resv, &gobj);
473476
if (ret)
474477
goto error;
475478

479+
bo = gem_to_amdgpu_bo(gobj);
476480
bo->allowed_domains = AMDGPU_GEM_DOMAIN_GTT;
477481
bo->preferred_domains = AMDGPU_GEM_DOMAIN_GTT;
478482
if (dma_buf->ops != &amdgpu_dmabuf_ops)
479483
bo->prime_shared_count = 1;
480484

481485
dma_resv_unlock(resv);
482-
return &bo->tbo.base;
486+
return gobj;
483487

484488
error:
485489
dma_resv_unlock(resv);

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,12 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
6666
bp.type = type;
6767
bp.resv = resv;
6868
bp.preferred_domain = initial_domain;
69-
retry:
7069
bp.flags = flags;
7170
bp.domain = initial_domain;
7271
r = amdgpu_bo_create(adev, &bp, &bo);
73-
if (r) {
74-
if (r != -ERESTARTSYS) {
75-
if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
76-
flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
77-
goto retry;
78-
}
79-
80-
if (initial_domain == AMDGPU_GEM_DOMAIN_VRAM) {
81-
initial_domain |= AMDGPU_GEM_DOMAIN_GTT;
82-
goto retry;
83-
}
84-
DRM_DEBUG("Failed to allocate GEM object (%ld, %d, %u, %d)\n",
85-
size, initial_domain, alignment, r);
86-
}
72+
if (r)
8773
return r;
88-
}
74+
8975
*obj = &bo->tbo.base;
9076

9177
return 0;
@@ -225,7 +211,7 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
225211
uint64_t size = args->in.bo_size;
226212
struct dma_resv *resv = NULL;
227213
struct drm_gem_object *gobj;
228-
uint32_t handle;
214+
uint32_t handle, initial_domain;
229215
int r;
230216

231217
/* reject invalid gem flags */
@@ -269,9 +255,28 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
269255
resv = vm->root.base.bo->tbo.base.resv;
270256
}
271257

258+
retry:
259+
initial_domain = (u32)(0xffffffff & args->in.domains);
272260
r = amdgpu_gem_object_create(adev, size, args->in.alignment,
273-
(u32)(0xffffffff & args->in.domains),
261+
initial_domain,
274262
flags, ttm_bo_type_device, resv, &gobj);
263+
if (r) {
264+
if (r != -ERESTARTSYS) {
265+
if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
266+
flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
267+
goto retry;
268+
}
269+
270+
if (initial_domain == AMDGPU_GEM_DOMAIN_VRAM) {
271+
initial_domain |= AMDGPU_GEM_DOMAIN_GTT;
272+
goto retry;
273+
}
274+
DRM_DEBUG("Failed to allocate GEM object (%llu, %d, %llu, %d)\n",
275+
size, initial_domain, args->in.alignment, r);
276+
}
277+
return r;
278+
}
279+
275280
if (flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID) {
276281
if (!r) {
277282
struct amdgpu_bo *abo = gem_to_amdgpu_bo(gobj);

0 commit comments

Comments
 (0)