From: "Michel Dänzer" <michel-otUistvHUpPR7s880joybQ@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: Emil Velikov
<emil.l.velikov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH libdrm 1/9] amdgpu: Pass file descriptor directly to amdgpu_close_kms_handle
Date: Mon, 24 Jun 2019 18:53:58 +0200 [thread overview]
Message-ID: <20190624165406.13682-2-michel@daenzer.net> (raw)
In-Reply-To: <20190624165406.13682-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org>
From: Michel Dänzer <michel.daenzer@amd.com>
And propagate drmIoctl's return value.
This allows replacing all remaining open-coded DRM_IOCTL_GEM_CLOSE
ioctl calls with amdgpu_close_kms_handle calls.
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
---
amdgpu/amdgpu_bo.c | 35 +++++++++++++++--------------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index 32ee358f..6c0b8517 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -39,13 +39,12 @@
#include "amdgpu_internal.h"
#include "util_math.h"
-static void amdgpu_close_kms_handle(amdgpu_device_handle dev,
- uint32_t handle)
+static int amdgpu_close_kms_handle(int fd, uint32_t handle)
{
struct drm_gem_close args = {};
args.handle = handle;
- drmIoctl(dev->fd, DRM_IOCTL_GEM_CLOSE, &args);
+ return drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &args);
}
static int amdgpu_bo_create(amdgpu_device_handle dev,
@@ -93,7 +92,7 @@ drm_public int amdgpu_bo_alloc(amdgpu_device_handle dev,
r = amdgpu_bo_create(dev, alloc_buffer->alloc_size, args.out.handle,
buf_handle);
if (r) {
- amdgpu_close_kms_handle(dev, args.out.handle);
+ amdgpu_close_kms_handle(dev->fd, args.out.handle);
goto out;
}
@@ -214,11 +213,8 @@ static int amdgpu_bo_export_flink(amdgpu_bo_handle bo)
bo->flink_name = flink.name;
- if (bo->dev->flink_fd != bo->dev->fd) {
- struct drm_gem_close args = {};
- args.handle = handle;
- drmIoctl(bo->dev->flink_fd, DRM_IOCTL_GEM_CLOSE, &args);
- }
+ if (bo->dev->flink_fd != bo->dev->fd)
+ amdgpu_close_kms_handle(bo->dev->flink_fd, handle);
pthread_mutex_lock(&bo->dev->bo_table_mutex);
r = handle_table_insert(&bo->dev->bo_flink_names, bo->flink_name, bo);
@@ -261,7 +257,6 @@ drm_public int amdgpu_bo_import(amdgpu_device_handle dev,
struct amdgpu_bo_import_result *output)
{
struct drm_gem_open open_arg = {};
- struct drm_gem_close close_arg = {};
struct amdgpu_bo *bo = NULL;
uint32_t handle = 0, flink_name = 0;
uint64_t alloc_size = 0;
@@ -345,12 +340,12 @@ drm_public int amdgpu_bo_import(amdgpu_device_handle dev,
close(dma_fd);
if (r)
goto free_bo_handle;
- close_arg.handle = open_arg.handle;
- r = drmIoctl(dev->flink_fd, DRM_IOCTL_GEM_CLOSE,
- &close_arg);
+ r = amdgpu_close_kms_handle(dev->flink_fd,
+ open_arg.handle);
if (r)
goto free_bo_handle;
}
+ open_arg.handle = 0;
break;
case amdgpu_bo_handle_type_dma_buf_fd:
@@ -388,14 +383,13 @@ drm_public int amdgpu_bo_import(amdgpu_device_handle dev,
remove_handle:
handle_table_remove(&dev->bo_handles, bo->handle);
free_bo_handle:
- if (flink_name && !close_arg.handle && open_arg.handle) {
- close_arg.handle = open_arg.handle;
- drmIoctl(dev->flink_fd, DRM_IOCTL_GEM_CLOSE, &close_arg);
- }
+ if (flink_name && open_arg.handle)
+ amdgpu_close_kms_handle(dev->flink_fd, open_arg.handle);
+
if (bo)
amdgpu_bo_free(bo);
else
- amdgpu_close_kms_handle(dev, handle);
+ amdgpu_close_kms_handle(dev->fd, handle);
unlock:
pthread_mutex_unlock(&dev->bo_table_mutex);
return r;
@@ -424,12 +418,13 @@ drm_public int amdgpu_bo_free(amdgpu_bo_handle buf_handle)
amdgpu_bo_cpu_unmap(bo);
}
- amdgpu_close_kms_handle(dev, bo->handle);
+ amdgpu_close_kms_handle(dev->fd, bo->handle);
pthread_mutex_destroy(&bo->cpu_access_mutex);
free(bo);
}
pthread_mutex_unlock(&dev->bo_table_mutex);
+
return 0;
}
@@ -604,7 +599,7 @@ drm_public int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
r = amdgpu_bo_create(dev, size, args.handle, buf_handle);
if (r) {
- amdgpu_close_kms_handle(dev, args.handle);
+ amdgpu_close_kms_handle(dev->fd, args.handle);
goto out;
}
--
2.20.1
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2019-06-24 16:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-24 16:53 [PATCH libdrm 0/9] amdgpu: Michel Dänzer
[not found] ` <20190624165406.13682-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org>
2019-06-24 16:53 ` Michel Dänzer [this message]
2019-06-28 17:11 ` [PATCH libdrm 1/9] amdgpu: Pass file descriptor directly to amdgpu_close_kms_handle Emil Velikov
2019-06-24 16:53 ` [PATCH libdrm 2/9] amdgpu: Add BO handle to table in amdgpu_bo_create Michel Dänzer
2019-06-24 16:54 ` [PATCH libdrm 3/9] amdgpu: Rename fd_mutex/list to dev_mutex/list Michel Dänzer
2019-06-24 16:54 ` [PATCH libdrm 8/9] amdgpu: Drop refcount member from struct amdgpu_core_bo/device Michel Dänzer
2019-06-24 16:54 ` [PATCH mesa 9/9] winsys/amdgpu: Use amdgpu_bo_handle_type_kms_user for API KMS handles Michel Dänzer
2019-06-24 16:54 ` [PATCH libdrm 4/9] amdgpu: Add struct amdgpu_core_device and amdgpu_core_bo Michel Dänzer
2019-06-24 16:54 ` [PATCH libdrm 5/9] amdgpu: Add amdgpu_bo_handle_type_kms_user Michel Dänzer
2019-06-24 16:54 ` [PATCH libdrm 6/9] amdgpu: Re-use an existing amdgpu_device when possible Michel Dänzer
2019-06-24 16:54 ` [PATCH libdrm 7/9] amdgpu: Use normal integers for device / core BO reference counting Michel Dänzer
2019-06-24 17:31 ` [PATCH libdrm 0/9] amdgpu: Christian König
[not found] ` <b48aae10-c1db-b76b-ddde-9c0a47028633-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-06-25 8:02 ` Michel Dänzer
2019-06-25 9:44 ` Koenig, Christian
[not found] ` <78d5a7c1-8534-7917-58bc-1827dff106c8-5C7GfCeVMHo@public.gmane.org>
2019-06-25 10:07 ` Michel Dänzer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190624165406.13682-2-michel@daenzer.net \
--to=michel-otuistvhuppr7s880joybq@public.gmane.org \
--cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=emil.l.velikov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox