Skip to content

Commit f8aab60

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 <[email protected]> Signed-off-by: Andrey Grodzovsky <[email protected]> Reviewed-by: Alex Deucher <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 3001867 commit f8aab60

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

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

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

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

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

482486
dma_resv_unlock(resv);
483-
return &bo->tbo.base;
487+
return gobj;
484488

485489
error:
486490
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
@@ -69,26 +69,12 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
6969
bp.type = type;
7070
bp.resv = resv;
7171
bp.preferred_domain = initial_domain;
72-
retry:
7372
bp.flags = flags;
7473
bp.domain = initial_domain;
7574
r = amdgpu_bo_create(adev, &bp, &bo);
76-
if (r) {
77-
if (r != -ERESTARTSYS) {
78-
if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
79-
flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
80-
goto retry;
81-
}
82-
83-
if (initial_domain == AMDGPU_GEM_DOMAIN_VRAM) {
84-
initial_domain |= AMDGPU_GEM_DOMAIN_GTT;
85-
goto retry;
86-
}
87-
DRM_DEBUG("Failed to allocate GEM object (%ld, %d, %u, %d)\n",
88-
size, initial_domain, alignment, r);
89-
}
75+
if (r)
9076
return r;
91-
}
77+
9278
*obj = &bo->tbo.base;
9379
(*obj)->funcs = &amdgpu_gem_object_funcs;
9480

@@ -238,7 +224,7 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
238224
uint64_t size = args->in.bo_size;
239225
struct dma_resv *resv = NULL;
240226
struct drm_gem_object *gobj;
241-
uint32_t handle;
227+
uint32_t handle, initial_domain;
242228
int r;
243229

244230
/* reject invalid gem flags */
@@ -282,9 +268,28 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
282268
resv = vm->root.base.bo->tbo.base.resv;
283269
}
284270

271+
retry:
272+
initial_domain = (u32)(0xffffffff & args->in.domains);
285273
r = amdgpu_gem_object_create(adev, size, args->in.alignment,
286-
(u32)(0xffffffff & args->in.domains),
274+
initial_domain,
287275
flags, ttm_bo_type_device, resv, &gobj);
276+
if (r) {
277+
if (r != -ERESTARTSYS) {
278+
if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
279+
flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
280+
goto retry;
281+
}
282+
283+
if (initial_domain == AMDGPU_GEM_DOMAIN_VRAM) {
284+
initial_domain |= AMDGPU_GEM_DOMAIN_GTT;
285+
goto retry;
286+
}
287+
DRM_DEBUG("Failed to allocate GEM object (%llu, %d, %llu, %d)\n",
288+
size, initial_domain, args->in.alignment, r);
289+
}
290+
return r;
291+
}
292+
288293
if (flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID) {
289294
if (!r) {
290295
struct amdgpu_bo *abo = gem_to_amdgpu_bo(gobj);

0 commit comments

Comments
 (0)