[libdrm,2/4] drm: add drmSyncobjWait wrapper

Submitted by Marek Olšák on Sept. 28, 2017, 10:10 p.m.

Details

Message ID 1506636659-24517-2-git-send-email-maraeo@gmail.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in AMD X.Org drivers

Not browsing as part of any series.

Commit Message

Marek Olšák Sept. 28, 2017, 10:10 p.m.
From: Marek Olšák <marek.olsak@amd.com>

---
 include/drm/drm.h | 24 ++++++++++++++++++++++++
 xf86drm.c         | 22 ++++++++++++++++++++++
 xf86drm.h         |  3 +++
 3 files changed, 49 insertions(+)

Patch hide | download patch | download mbox

diff --git a/include/drm/drm.h b/include/drm/drm.h
index bf3674a..4da1667 100644
--- a/include/drm/drm.h
+++ b/include/drm/drm.h
@@ -687,38 +687,57 @@  struct drm_prime_handle {
 
 	/** Flags.. only applicable for handle->fd */
 	__u32 flags;
 
 	/** Returned dmabuf file descriptor */
 	__s32 fd;
 };
 
 struct drm_syncobj_create {
 	__u32 handle;
+#define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0)
 	__u32 flags;
 };
 
 struct drm_syncobj_destroy {
 	__u32 handle;
 	__u32 pad;
 };
 
 #define DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE (1 << 0)
 #define DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE (1 << 0)
 struct drm_syncobj_handle {
 	__u32 handle;
 	__u32 flags;
 
 	__s32 fd;
 	__u32 pad;
 };
 
+#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0)
+#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1)
+struct drm_syncobj_wait {
+	__u64 handles;
+	/* absolute timeout */
+	__s64 timeout_nsec;
+	__u32 count_handles;
+	__u32 flags;
+	__u32 first_signaled; /* only valid when not waiting all */
+	__u32 pad;
+};
+
+struct drm_syncobj_array {
+	__u64 handles;
+	__u32 count_handles;
+	__u32 pad;
+};
+
 #if defined(__cplusplus)
 }
 #endif
 
 #include "drm_mode.h"
 
 #if defined(__cplusplus)
 extern "C" {
 #endif
 
@@ -827,20 +846,23 @@  extern "C" {
 #define DRM_IOCTL_MODE_OBJ_SETPROPERTY	DRM_IOWR(0xBA, struct drm_mode_obj_set_property)
 #define DRM_IOCTL_MODE_CURSOR2		DRM_IOWR(0xBB, struct drm_mode_cursor2)
 #define DRM_IOCTL_MODE_ATOMIC		DRM_IOWR(0xBC, struct drm_mode_atomic)
 #define DRM_IOCTL_MODE_CREATEPROPBLOB	DRM_IOWR(0xBD, struct drm_mode_create_blob)
 #define DRM_IOCTL_MODE_DESTROYPROPBLOB	DRM_IOWR(0xBE, struct drm_mode_destroy_blob)
 
 #define DRM_IOCTL_SYNCOBJ_CREATE	DRM_IOWR(0xBF, struct drm_syncobj_create)
 #define DRM_IOCTL_SYNCOBJ_DESTROY	DRM_IOWR(0xC0, struct drm_syncobj_destroy)
 #define DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD	DRM_IOWR(0xC1, struct drm_syncobj_handle)
 #define DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE	DRM_IOWR(0xC2, struct drm_syncobj_handle)
+#define DRM_IOCTL_SYNCOBJ_WAIT		DRM_IOWR(0xC3, struct drm_syncobj_wait)
+#define DRM_IOCTL_SYNCOBJ_RESET		DRM_IOWR(0xC4, struct drm_syncobj_array)
+#define DRM_IOCTL_SYNCOBJ_SIGNAL	DRM_IOWR(0xC5, struct drm_syncobj_array)
 
 /**
  * Device specific ioctls should only be in their respective headers
  * The device specific ioctl range is from 0x40 to 0x9f.
  * Generic IOCTLS restart at 0xA0.
  *
  * \sa drmCommandNone(), drmCommandRead(), drmCommandWrite(), and
  * drmCommandReadWrite().
  */
 #define DRM_COMMAND_BASE                0x40
@@ -869,20 +891,21 @@  struct drm_event {
 struct drm_event_vblank {
 	struct drm_event base;
 	__u64 user_data;
 	__u32 tv_sec;
 	__u32 tv_usec;
 	__u32 sequence;
 	__u32 crtc_id; /* 0 on older kernels that do not support this */
 };
 
 /* typedef area */
+#ifndef __KERNEL__
 typedef struct drm_clip_rect drm_clip_rect_t;
 typedef struct drm_drawable_info drm_drawable_info_t;
 typedef struct drm_tex_region drm_tex_region_t;
 typedef struct drm_hw_lock drm_hw_lock_t;
 typedef struct drm_version drm_version_t;
 typedef struct drm_unique drm_unique_t;
 typedef struct drm_list drm_list_t;
 typedef struct drm_block drm_block_t;
 typedef struct drm_control drm_control_t;
 typedef enum drm_map_type drm_map_type_t;
@@ -910,16 +933,17 @@  typedef struct drm_draw drm_draw_t;
 typedef struct drm_update_draw drm_update_draw_t;
 typedef struct drm_auth drm_auth_t;
 typedef struct drm_irq_busid drm_irq_busid_t;
 typedef enum drm_vblank_seq_type drm_vblank_seq_type_t;
 
 typedef struct drm_agp_buffer drm_agp_buffer_t;
 typedef struct drm_agp_binding drm_agp_binding_t;
 typedef struct drm_agp_info drm_agp_info_t;
 typedef struct drm_scatter_gather drm_scatter_gather_t;
 typedef struct drm_set_version drm_set_version_t;
+#endif
 
 #if defined(__cplusplus)
 }
 #endif
 
 #endif
diff --git a/xf86drm.c b/xf86drm.c
index 6ea0112..8a32717 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -4218,10 +4218,32 @@  int drmSyncobjExportSyncFile(int fd, uint32_t handle, int *sync_file_fd)
     memclear(args);
     args.fd = -1;
     args.handle = handle;
     args.flags = DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE;
     ret = drmIoctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &args);
     if (ret)
 	return ret;
     *sync_file_fd = args.fd;
     return 0;
 }
+
+int drmSyncobjWait(int fd, uint32_t *handles, unsigned num_handles,
+		   int64_t timeout_nsec, unsigned flags,
+		   uint32_t *first_signaled)
+{
+	struct drm_syncobj_wait args;
+	int ret;
+
+	memclear(args);
+	args.handles = (intptr_t)handles;
+	args.timeout_nsec = timeout_nsec;
+	args.count_handles = num_handles;
+	args.flags = flags;
+
+	ret = drmIoctl(fd, DRM_IOCTL_SYNCOBJ_WAIT, &args);
+	if (ret < 0)
+		return ret;
+
+	if (first_signaled)
+		*first_signaled = args.first_signaled;
+	return ret;
+}
diff --git a/xf86drm.h b/xf86drm.h
index 2855a3e..ea650ef 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -853,16 +853,19 @@  extern int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_device
 
 extern int drmDevicesEqual(drmDevicePtr a, drmDevicePtr b);
 
 extern int drmSyncobjCreate(int fd, uint32_t flags, uint32_t *handle);
 extern int drmSyncobjDestroy(int fd, uint32_t handle);
 extern int drmSyncobjHandleToFD(int fd, uint32_t handle, int *obj_fd);
 extern int drmSyncobjFDToHandle(int fd, int obj_fd, uint32_t *handle);
 
 extern int drmSyncobjImportSyncFile(int fd, uint32_t handle, int sync_file_fd);
 extern int drmSyncobjExportSyncFile(int fd, uint32_t handle, int *sync_file_fd);
+extern int drmSyncobjWait(int fd, uint32_t *handles, unsigned num_handles,
+			  int64_t timeout_nsec, unsigned flags,
+			  uint32_t *first_signaled);
 
 #if defined(__cplusplus)
 }
 #endif
 
 #endif

Comments

On 2017年09月29日 06:10, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak@amd.com>
>
> ---
>   include/drm/drm.h | 24 ++++++++++++++++++++++++
>   xf86drm.c         | 22 ++++++++++++++++++++++
>   xf86drm.h         |  3 +++
>   3 files changed, 49 insertions(+)
>
> diff --git a/include/drm/drm.h b/include/drm/drm.h
> index bf3674a..4da1667 100644
> --- a/include/drm/drm.h
> +++ b/include/drm/drm.h
> @@ -687,38 +687,57 @@ struct drm_prime_handle {
>   
>   	/** Flags.. only applicable for handle->fd */
>   	__u32 flags;
>   
>   	/** Returned dmabuf file descriptor */
>   	__s32 fd;
>   };
>   
>   struct drm_syncobj_create {
>   	__u32 handle;
> +#define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0)
>   	__u32 flags;
>   };
>   
>   struct drm_syncobj_destroy {
>   	__u32 handle;
>   	__u32 pad;
>   };
>   
>   #define DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE (1 << 0)
>   #define DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE (1 << 0)
Typo for '(1 << 1)' ?

With that fixes, the set is Reviewed-by: Chunming Zhou <david1.zhou@amd.com>

>   struct drm_syncobj_handle {
>   	__u32 handle;
>   	__u32 flags;
>   
>   	__s32 fd;
>   	__u32 pad;
>   };
>   
> +#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0)
> +#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1)
> +struct drm_syncobj_wait {
> +	__u64 handles;
> +	/* absolute timeout */
> +	__s64 timeout_nsec;
> +	__u32 count_handles;
> +	__u32 flags;
> +	__u32 first_signaled; /* only valid when not waiting all */
> +	__u32 pad;
> +};
> +
> +struct drm_syncobj_array {
> +	__u64 handles;
> +	__u32 count_handles;
> +	__u32 pad;
> +};
> +
>   #if defined(__cplusplus)
>   }
>   #endif
>   
>   #include "drm_mode.h"
>   
>   #if defined(__cplusplus)
>   extern "C" {
>   #endif
>   
> @@ -827,20 +846,23 @@ extern "C" {
>   #define DRM_IOCTL_MODE_OBJ_SETPROPERTY	DRM_IOWR(0xBA, struct drm_mode_obj_set_property)
>   #define DRM_IOCTL_MODE_CURSOR2		DRM_IOWR(0xBB, struct drm_mode_cursor2)
>   #define DRM_IOCTL_MODE_ATOMIC		DRM_IOWR(0xBC, struct drm_mode_atomic)
>   #define DRM_IOCTL_MODE_CREATEPROPBLOB	DRM_IOWR(0xBD, struct drm_mode_create_blob)
>   #define DRM_IOCTL_MODE_DESTROYPROPBLOB	DRM_IOWR(0xBE, struct drm_mode_destroy_blob)
>   
>   #define DRM_IOCTL_SYNCOBJ_CREATE	DRM_IOWR(0xBF, struct drm_syncobj_create)
>   #define DRM_IOCTL_SYNCOBJ_DESTROY	DRM_IOWR(0xC0, struct drm_syncobj_destroy)
>   #define DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD	DRM_IOWR(0xC1, struct drm_syncobj_handle)
>   #define DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE	DRM_IOWR(0xC2, struct drm_syncobj_handle)
> +#define DRM_IOCTL_SYNCOBJ_WAIT		DRM_IOWR(0xC3, struct drm_syncobj_wait)
> +#define DRM_IOCTL_SYNCOBJ_RESET		DRM_IOWR(0xC4, struct drm_syncobj_array)
> +#define DRM_IOCTL_SYNCOBJ_SIGNAL	DRM_IOWR(0xC5, struct drm_syncobj_array)
>   
>   /**
>    * Device specific ioctls should only be in their respective headers
>    * The device specific ioctl range is from 0x40 to 0x9f.
>    * Generic IOCTLS restart at 0xA0.
>    *
>    * \sa drmCommandNone(), drmCommandRead(), drmCommandWrite(), and
>    * drmCommandReadWrite().
>    */
>   #define DRM_COMMAND_BASE                0x40
> @@ -869,20 +891,21 @@ struct drm_event {
>   struct drm_event_vblank {
>   	struct drm_event base;
>   	__u64 user_data;
>   	__u32 tv_sec;
>   	__u32 tv_usec;
>   	__u32 sequence;
>   	__u32 crtc_id; /* 0 on older kernels that do not support this */
>   };
>   
>   /* typedef area */
> +#ifndef __KERNEL__
>   typedef struct drm_clip_rect drm_clip_rect_t;
>   typedef struct drm_drawable_info drm_drawable_info_t;
>   typedef struct drm_tex_region drm_tex_region_t;
>   typedef struct drm_hw_lock drm_hw_lock_t;
>   typedef struct drm_version drm_version_t;
>   typedef struct drm_unique drm_unique_t;
>   typedef struct drm_list drm_list_t;
>   typedef struct drm_block drm_block_t;
>   typedef struct drm_control drm_control_t;
>   typedef enum drm_map_type drm_map_type_t;
> @@ -910,16 +933,17 @@ typedef struct drm_draw drm_draw_t;
>   typedef struct drm_update_draw drm_update_draw_t;
>   typedef struct drm_auth drm_auth_t;
>   typedef struct drm_irq_busid drm_irq_busid_t;
>   typedef enum drm_vblank_seq_type drm_vblank_seq_type_t;
>   
>   typedef struct drm_agp_buffer drm_agp_buffer_t;
>   typedef struct drm_agp_binding drm_agp_binding_t;
>   typedef struct drm_agp_info drm_agp_info_t;
>   typedef struct drm_scatter_gather drm_scatter_gather_t;
>   typedef struct drm_set_version drm_set_version_t;
> +#endif
>   
>   #if defined(__cplusplus)
>   }
>   #endif
>   
>   #endif
> diff --git a/xf86drm.c b/xf86drm.c
> index 6ea0112..8a32717 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -4218,10 +4218,32 @@ int drmSyncobjExportSyncFile(int fd, uint32_t handle, int *sync_file_fd)
>       memclear(args);
>       args.fd = -1;
>       args.handle = handle;
>       args.flags = DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE;
>       ret = drmIoctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, &args);
>       if (ret)
>   	return ret;
>       *sync_file_fd = args.fd;
>       return 0;
>   }
> +
> +int drmSyncobjWait(int fd, uint32_t *handles, unsigned num_handles,
> +		   int64_t timeout_nsec, unsigned flags,
> +		   uint32_t *first_signaled)
> +{
> +	struct drm_syncobj_wait args;
> +	int ret;
> +
> +	memclear(args);
> +	args.handles = (intptr_t)handles;
> +	args.timeout_nsec = timeout_nsec;
> +	args.count_handles = num_handles;
> +	args.flags = flags;
> +
> +	ret = drmIoctl(fd, DRM_IOCTL_SYNCOBJ_WAIT, &args);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (first_signaled)
> +		*first_signaled = args.first_signaled;
> +	return ret;
> +}
> diff --git a/xf86drm.h b/xf86drm.h
> index 2855a3e..ea650ef 100644
> --- a/xf86drm.h
> +++ b/xf86drm.h
> @@ -853,16 +853,19 @@ extern int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_device
>   
>   extern int drmDevicesEqual(drmDevicePtr a, drmDevicePtr b);
>   
>   extern int drmSyncobjCreate(int fd, uint32_t flags, uint32_t *handle);
>   extern int drmSyncobjDestroy(int fd, uint32_t handle);
>   extern int drmSyncobjHandleToFD(int fd, uint32_t handle, int *obj_fd);
>   extern int drmSyncobjFDToHandle(int fd, int obj_fd, uint32_t *handle);
>   
>   extern int drmSyncobjImportSyncFile(int fd, uint32_t handle, int sync_file_fd);
>   extern int drmSyncobjExportSyncFile(int fd, uint32_t handle, int *sync_file_fd);
> +extern int drmSyncobjWait(int fd, uint32_t *handles, unsigned num_handles,
> +			  int64_t timeout_nsec, unsigned flags,
> +			  uint32_t *first_signaled);
>   
>   #if defined(__cplusplus)
>   }
>   #endif
>   
>   #endif
On Fri, Sep 29, 2017 at 4:12 AM, Chunming Zhou <zhoucm1@amd.com> wrote:
>
>
> On 2017年09月29日 06:10, Marek Olšák wrote:
>>
>> From: Marek Olšák <marek.olsak@amd.com>
>>
>> ---
>>   include/drm/drm.h | 24 ++++++++++++++++++++++++
>>   xf86drm.c         | 22 ++++++++++++++++++++++
>>   xf86drm.h         |  3 +++
>>   3 files changed, 49 insertions(+)
>>
>> diff --git a/include/drm/drm.h b/include/drm/drm.h
>> index bf3674a..4da1667 100644
>> --- a/include/drm/drm.h
>> +++ b/include/drm/drm.h
>> @@ -687,38 +687,57 @@ struct drm_prime_handle {
>>         /** Flags.. only applicable for handle->fd */
>>         __u32 flags;
>>         /** Returned dmabuf file descriptor */
>>         __s32 fd;
>>   };
>>     struct drm_syncobj_create {
>>         __u32 handle;
>> +#define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0)
>>         __u32 flags;
>>   };
>>     struct drm_syncobj_destroy {
>>         __u32 handle;
>>         __u32 pad;
>>   };
>>     #define DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE (1 << 0)
>>   #define DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE (1 << 0)
>
> Typo for '(1 << 1)' ?

No, this was copied from kernel headers.

>
> With that fixes, the set is Reviewed-by: Chunming Zhou <david1.zhou@amd.com>

Thanks.

Marek
On 2017年09月29日 20:37, Marek Olšák wrote:
> On Fri, Sep 29, 2017 at 4:12 AM, Chunming Zhou <zhoucm1@amd.com> wrote:
>>
>> On 2017年09月29日 06:10, Marek Olšák wrote:
>>> From: Marek Olšák <marek.olsak@amd.com>
>>>
>>> ---
>>>    include/drm/drm.h | 24 ++++++++++++++++++++++++
>>>    xf86drm.c         | 22 ++++++++++++++++++++++
>>>    xf86drm.h         |  3 +++
>>>    3 files changed, 49 insertions(+)
>>>
>>> diff --git a/include/drm/drm.h b/include/drm/drm.h
>>> index bf3674a..4da1667 100644
>>> --- a/include/drm/drm.h
>>> +++ b/include/drm/drm.h
>>> @@ -687,38 +687,57 @@ struct drm_prime_handle {
>>>          /** Flags.. only applicable for handle->fd */
>>>          __u32 flags;
>>>          /** Returned dmabuf file descriptor */
>>>          __s32 fd;
>>>    };
>>>      struct drm_syncobj_create {
>>>          __u32 handle;
>>> +#define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0)
>>>          __u32 flags;
>>>    };
>>>      struct drm_syncobj_destroy {
>>>          __u32 handle;
>>>          __u32 pad;
>>>    };
>>>      #define DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE (1 << 0)
>>>    #define DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE (1 << 0)
>> Typo for '(1 << 1)' ?
> No, this was copied from kernel headers.
Yes, I double checked just now, that's two separate ioctls use them, so 
they are safe.

Sorry for noise of this.

David Zhou
>
>> With that fixes, the set is Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
> Thanks.
>
> Marek