Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Francois Dugast <francois.dugast@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Francois Dugast <francois.dugast@intel.com>
Subject: [PATCH v1 12/14] drm/xe/uapi: Add examples of user space code
Date: Thu,  7 Dec 2023 13:50:07 +0000	[thread overview]
Message-ID: <20231207135009.7-13-francois.dugast@intel.com> (raw)
In-Reply-To: <20231207135009.7-1-francois.dugast@intel.com>

Complete the documentation of some structs by adding functional
examples of user space code. Those examples are intentionally kept
very simple. Put together, they provide a foundation for a minimal
application that executes a job using the Xe driver.

Signed-off-by: Francois Dugast <francois.dugast@intel.com>
---
 include/uapi/drm/xe_drm.h | 84 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h
index b5117bc1f13c..6811a1c96078 100644
--- a/include/uapi/drm/xe_drm.h
+++ b/include/uapi/drm/xe_drm.h
@@ -962,6 +962,30 @@ struct drm_xe_vm_bind_op {
 
 /**
  * struct drm_xe_vm_bind - Input of &DRM_IOCTL_XE_VM_BIND
+ *
+ * Below is an example of a minimal use of @drm_xe_vm_bind to
+ * asynchronously bind the buffer `data` at address `BIND_ADDRESS` to
+ * illustrate `userptr`. It can be synchronized by using the example
+ * provided for @drm_xe_sync.
+ *
+ * .. code-block:: C
+ *
+ *     data = aligned_alloc(ALIGNMENT, BO_SIZE);
+ *     struct drm_xe_vm_bind bind = {
+ *         .vm_id = vm,
+ *         .num_binds = 1,
+ *         .bind.obj = 0,
+ *         .bind.obj_offset = to_user_pointer(data),
+ *         .bind.range = BO_SIZE,
+ *         .bind.addr = BIND_ADDRESS,
+ *         .bind.op = DRM_XE_VM_BIND_OP_MAP_USERPTR,
+ *         .bind.flags = DRM_XE_VM_BIND_FLAG_ASYNC,
+ *         .num_syncs = 1,
+ *         .syncs = &sync,
+ *         .exec_queue_id = 0,
+ *     };
+ *     ioctl(fd, DRM_IOCTL_XE_VM_BIND, &bind);
+ *
  */
 struct drm_xe_vm_bind {
 	/** @extensions: Pointer to the first extension struct, if any */
@@ -1023,6 +1047,25 @@ struct drm_xe_vm_bind {
 
 /**
  * struct drm_xe_exec_queue_create - Input of &DRM_IOCTL_XE_EXEC_QUEUE_CREATE
+ *
+ * The example below shows how to use @drm_xe_exec_queue_create to create
+ * a simple exec_queue (no parallel submission) of class
+ * &DRM_XE_ENGINE_CLASS_RENDER.
+ *
+ * .. code-block:: C
+ *
+ *     struct drm_xe_engine_class_instance instance = {
+ *         .engine_class = DRM_XE_ENGINE_CLASS_RENDER,
+ *     };
+ *     struct drm_xe_exec_queue_create exec_queue_create = {
+ *          .extensions = 0,
+ *          .vm_id = vm,
+ *          .num_bb_per_exec = 1,
+ *          .num_eng_per_bb = 1,
+ *          .instances = to_user_pointer(&instance),
+ *     };
+ *     ioctl(fd, DRM_IOCTL_XE_EXEC_QUEUE_CREATE, &exec_queue_create);
+ *
  */
 struct drm_xe_exec_queue_create {
 #define DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY		0
@@ -1114,6 +1157,30 @@ struct drm_xe_exec_queue_get_property {
  *
  * and the @flags can be:
  *  - %DRM_XE_SYNC_FLAG_SIGNAL
+ *
+ * A minimal use of @drm_xe_sync looks like this:
+ *
+ * .. code-block:: C
+ *
+ *     struct drm_xe_sync sync = {
+ *         .flags = DRM_XE_SYNC_FLAG_SIGNAL,
+ *         .type = DRM_XE_SYNC_TYPE_SYNCOBJ,
+ *     };
+ *     struct drm_syncobj_create syncobj_create = { 0 };
+ *     ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &syncobj_create);
+ *     sync.handle = syncobj_create.handle;
+ *         ...
+ *         use of &sync in drm_xe_exec or drm_xe_vm_bind
+ *         ...
+ *     struct drm_syncobj_wait wait = {
+ *         .handles = &sync.handle,
+ *         .timeout_nsec = INT64_MAX,
+ *         .count_handles = 1,
+ *         .flags = 0,
+ *         .first_signaled = 0,
+ *         .pad = 0,
+ *     };
+ *     ioctl(fd, DRM_IOCTL_SYNCOBJ_WAIT, &wait);
  */
 struct drm_xe_sync {
 	/** @extensions: Pointer to the first extension struct, if any */
@@ -1156,6 +1223,23 @@ struct drm_xe_sync {
 
 /**
  * struct drm_xe_exec - Input of &DRM_IOCTL_XE_EXEC
+ *
+ * This is an example to use @drm_xe_exec for execution of the object
+ * at BIND_ADDRESS (see example in @drm_xe_vm_bind) by an exec_queue
+ * (see example in @drm_xe_exec_queue_create). It can be synchronized
+ * by using the example provided for @drm_xe_sync.
+ *
+ * .. code-block:: C
+ *
+ *     struct drm_xe_exec exec = {
+ *         .exec_queue_id = exec_queue,
+ *         .syncs = &sync,
+ *         .num_syncs = 1,
+ *         .address = BIND_ADDRESS,
+ *         .num_batch_buffer = 1,
+ *     };
+ *     ioctl(fd, DRM_IOCTL_XE_EXEC, &exec);
+ *
  */
 struct drm_xe_exec {
 	/** @extensions: Pointer to the first extension struct, if any */
-- 
2.34.1


  parent reply	other threads:[~2023-12-07 13:50 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-07 13:49 [PATCH v1 00/14] uAPI Alignment - Documentation Francois Dugast
2023-12-07 13:49 ` [PATCH v1 01/14] drm/xe/uapi: Add a comment to each struct Francois Dugast
2023-12-14 14:17   ` Rodrigo Vivi
2023-12-07 13:49 ` [PATCH v1 02/14] drm/xe/uapi: Add missing documentation for struct members Francois Dugast
2023-12-14 14:17   ` Rodrigo Vivi
2023-12-07 13:49 ` [PATCH v1 03/14] drm/xe/uapi: Document use of size in drm_xe_device_query Francois Dugast
2023-12-13 18:16   ` Rodrigo Vivi
2023-12-07 13:49 ` [PATCH v1 04/14] drm/xe/uapi: Document drm_xe_query_config keys Francois Dugast
2023-12-13 18:14   ` Rodrigo Vivi
2023-12-07 13:50 ` [PATCH v1 05/14] drm/xe/uapi: Document DRM_XE_DEVICE_QUERY_HWCONFIG Francois Dugast
2023-12-13 18:14   ` Rodrigo Vivi
2023-12-07 13:50 ` [PATCH v1 06/14] drm/xe/uapi: Make constant comments visible in kernel doc Francois Dugast
2023-12-13 18:16   ` Rodrigo Vivi
2023-12-07 13:50 ` [PATCH v1 07/14] drm/xe/uapi: Replace BO with GEM in documentation Francois Dugast
2023-12-07 14:49   ` Matthew Auld
2023-12-13 18:27     ` Rodrigo Vivi
2023-12-07 13:50 ` [PATCH v1 08/14] drm/xe/uapi: Order sections Francois Dugast
2023-12-14 20:57   ` Lucas De Marchi
2023-12-15  4:06     ` Aravind Iddamsetty
2023-12-07 13:50 ` [PATCH v1 09/14] drm/xe/uapi: More uAPI documentation additions and cosmetic updates Francois Dugast
2023-12-14 16:45   ` Lucas De Marchi
2023-12-14 19:40     ` Francois Dugast
2023-12-07 13:50 ` [PATCH v1 10/14] drm/xe/uapi: Document the memory_region bitmask Francois Dugast
2023-12-14 21:23   ` Lucas De Marchi
2023-12-07 13:50 ` [PATCH v1 11/14] drm/xe/uapi: Add block diagram of a device Francois Dugast
2023-12-07 14:01   ` Souza, Jose
2023-12-07 13:50 ` Francois Dugast [this message]
2023-12-13 18:26   ` [PATCH v1 12/14] drm/xe/uapi: Add examples of user space code Rodrigo Vivi
2023-12-07 13:50 ` [PATCH v1 13/14] drm/xe/uapi: Move CPU_CACHING defines before doc Francois Dugast
2023-12-13 18:18   ` Rodrigo Vivi
2023-12-07 13:50 ` [PATCH v1 14/14] drm/xe/uapi: Move DRM_XE_ACC_GRANULARITY_* where they are used Francois Dugast
2023-12-13 18:17   ` Rodrigo Vivi
2023-12-07 16:42 ` ✓ CI.Patch_applied: success for uAPI Alignment - Documentation Patchwork
2023-12-07 16:42 ` ✗ CI.checkpatch: warning " Patchwork
2023-12-07 16:44 ` ✓ CI.KUnit: success " Patchwork
2023-12-07 16:51 ` ✓ CI.Build: " Patchwork
2023-12-07 16:51 ` ✓ CI.Hooks: " Patchwork
2023-12-07 16:53 ` ✓ CI.checksparse: " Patchwork
2023-12-07 17:28 ` ✓ CI.BAT: " Patchwork

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=20231207135009.7-13-francois.dugast@intel.com \
    --to=francois.dugast@intel.com \
    --cc=intel-xe@lists.freedesktop.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