Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ACC45C41535 for ; Thu, 9 Nov 2023 15:46:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 606DB10E8E2; Thu, 9 Nov 2023 15:46:36 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by gabe.freedesktop.org (Postfix) with ESMTPS id 79A4D10E8E5 for ; Thu, 9 Nov 2023 15:46:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699544773; x=1731080773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eTaTq0sP3PxnEILzXXvLWgeWq9ivrcrxhFKSAdHyZvM=; b=YlH3iICJRWRTxjSCqRmbk9eeFgJeC4qCSdg3s5Ui0PC3OhnNz56gpi5x DlZi5ymVGHpHMfIVjgb8LzoNuk78/LW0oUybZSPXZRTrBv/wLh57yTKbM cWU8Dk+E+9IdfiftvC3IY/6R0XyeRvbgjEIhy1rT7WHljbIv43y4Dr7qT Tna7MRheg2ny0MpV6pW22bUQDd6T3G2VNnOZPwsOV74Yv0s/FE57zb/9a pSeZIblbbENPr2oClY4lq1fsPZA3bgAGxfHVIbcCtOLtzRQVcUgjZCZUx ZUSIg00fmhoeGVYWDawngzgqjI3YdKA3IUbmKJE/qHlzeCbvKPIrrODp4 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10889"; a="11556873" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="11556873" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2023 07:46:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10889"; a="936886115" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="936886115" Received: from hschreib-mobl.ger.corp.intel.com (HELO ac699de916ef.intel.com) ([10.249.42.184]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2023 07:46:08 -0800 From: Francois Dugast To: intel-xe@lists.freedesktop.org Date: Thu, 9 Nov 2023 15:44:57 +0000 Message-Id: <20231109154457.7-44-francois.dugast@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231109154457.7-1-francois.dugast@intel.com> References: <20231109154457.7-1-francois.dugast@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Intel-xe] [PATCH v3 43/43] drm/xe/uapi: Add examples of user space code X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Francois Dugast Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" 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 --- 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 4339e6fe47e4..089d05b69da5 100644 --- a/include/uapi/drm/xe_drm.h +++ b/include/uapi/drm/xe_drm.h @@ -958,6 +958,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 */ @@ -1030,6 +1054,30 @@ struct drm_xe_vm_bind { * 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 */ @@ -1134,6 +1182,25 @@ struct drm_xe_sync { /** * 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 @@ -1256,6 +1323,23 @@ struct drm_xe_exec_queue_get_property { /** * 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