Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1604626rwn; Fri, 9 Sep 2022 00:40:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR4fmERRuU0H6gg5rtMKZ7wb30drRutmk+xO5TMkAd42OJayA7q6mELHnGZBlddm1+lWMBCh X-Received: by 2002:a63:24c:0:b0:430:7ec9:c6d3 with SMTP id 73-20020a63024c000000b004307ec9c6d3mr11019928pgc.334.1662709200185; Fri, 09 Sep 2022 00:40:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662709200; cv=none; d=google.com; s=arc-20160816; b=Rr5sRcI6c3Whtpez43sLvtYnBIg3tPIY922IXAMtk+Zr0o81ruR/SuYpjm4uoWA6ds CBnH+cWvRCzDEH1LW6BpzvGR3kdn/bdmKRiY9cQ2cB7hoqXEaddGL7/52ZwG731MANos TnRlNrHd5XTU4jbPCKJnx9wUDBMv8/+VRUEE7sTy1O9gNQBEXneSvI7PHIIDfHvcKkgn L3IDQShHCGVjEuzmWcnFZ8Fuy93eSdDo8mztz87uy5yCBSasUyx+8pxnP8NV8YNqVgv6 XFbcpbgtkaPjwP/WTPIBVlWS4wseajT8uh4cuyoDZgR29pSubKXBz5xj8nOUxbSAKMjP chnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=XLqg6V7Tdr/L8/3lQsYC81qoeoMQM07Mlbgp3RhuJqc=; b=u7Wdr/CnJ4oGxU9i6zBd4K5txYo6913/TnxxuAqDxji2a1iU9EOC0rchfGUJ1vnIm4 2mcDp7aDDCtTcfg0DaHKfFQ1/nIq6z57h7W+rBb5kSZ5BEz3DjVH8jEJgP2Aqp2FsnWn vXB8Vcp5IzvFavhOhZrTY+9c15vWjiXDlI/+cG1vbRH5l+j23m+2+QnjEruwnTFFeudU EUJ3YUDMV4N6Ptzz6GyEdDmFrnGZUJNgV3zYoXYf+mr0Ou7qvsViA1vRwosa/q26dda8 TTZCDxZcuatR1lW2VvrR9+rv0sOrD/qrH0vs6I6xHmd68OU4kQq9qmJEnbnbzhsdrcL8 TqKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=XG4Izvn+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i24-20020a633c58000000b004340446009csi782383pgn.226.2022.09.09.00.39.48; Fri, 09 Sep 2022 00:40:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=XG4Izvn+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230368AbiIIHiB (ORCPT + 99 others); Fri, 9 Sep 2022 03:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230509AbiIIHgl (ORCPT ); Fri, 9 Sep 2022 03:36:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A39AC125B2D for ; Fri, 9 Sep 2022 00:35:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4BF33B82381 for ; Fri, 9 Sep 2022 07:34:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D400C4FF16; Fri, 9 Sep 2022 07:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662708895; bh=SeKZxIQ5VkdtxzfjOKhOpZ42imwNIzgYsVny6L1AXAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XG4Izvn+FigonIdcos5S7LcXxgjeOQnIDGYLCW4gxfLQ375Rhl9vv5XBroLGKwEm7 dxqA7pMZKBCLdQMSdctRgbs2Xbf6sKU2j+d5ScLogC4Agno+itiAxxo5wf5vcfz2zB 6fTVODhUv+LGltIQpJurMxkA/jP5Jle621Hh5wtGGR22XicMbYoAdyKn3Yj+bSJ9/j 2PJhJ9YZXOzOzdjxv59CmAWaVJ3VeQQVOLKv6qJSEUsgrKwTSSvNIW5CMxTjazfaAU zr9eEG5cUuV8sk+T+kFDBnVjrMEIi3zu6f1cz2RJX3uxALGnYRdj6aRyOjNPtPXiB2 RcBzQOtvQukCw== Received: from mchehab by mail.kernel.org with local (Exim 4.95) (envelope-from ) id 1oWYXH-007FHn-Ja; Fri, 09 Sep 2022 09:34:47 +0200 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , "Rodrigo Vivi" , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Chris Wilson , Daniel Vetter , David Airlie , Jani Nikula , Joonas Lahtinen , Matthew Auld , Tvrtko Ursulin , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 34/37] drm/i915: document struct drm_i915_gem_object Date: Fri, 9 Sep 2022 09:34:41 +0200 Message-Id: <5172513593291c5cbcaccd455a1eee6dd32eac90.1662708705.git.mchehab@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a large struct used to describe gem objects. It is currently partially documented. Finish its documentation, filling the gaps from git logs. Reviewed-by: Rodrigo Vivi Signed-off-by: Mauro Carvalho Chehab --- To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH v3 00/37] at: https://lore.kernel.org/all/cover.1662708705.git.mchehab@kernel.org/ .../gpu/drm/i915/gem/i915_gem_object_types.h | 200 ++++++++++++++---- 1 file changed, 158 insertions(+), 42 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h index 35746cf268ea..577f02b16b23 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h @@ -233,6 +233,9 @@ struct i915_gem_object_page_iter { struct mutex lock; /* protects this cache */ }; +/** + * struct drm_i915_gem_object - describes an i915 GEM object + */ struct drm_i915_gem_object { /* * We might have reason to revisit the below since it wastes @@ -241,12 +244,16 @@ struct drm_i915_gem_object { * when accessing it. */ union { + /** @base: GEM base object */ struct drm_gem_object base; + /** @__do_not_access: TTM buffer object */ struct ttm_buffer_object __do_not_access; }; + /** @ops: pointer to GEM object ops */ const struct drm_i915_gem_object_ops *ops; + /** @vma: struct containing VMA list, tree and lock */ struct { /** * @vma.lock: protect the list/tree of vmas @@ -280,10 +287,12 @@ struct drm_i915_gem_object { * * If this object is closed, we need to remove all of its VMA from * the fast lookup index in associated contexts; @lut_list provides - * this translation from object to context->handles_vma. + * this translation from object to ``context->handles_vma``. */ struct list_head lut_list; - spinlock_t lut_lock; /* guards lut_list */ + + /** @lut_lock: guards @lut_list */ + spinlock_t lut_lock; /** * @obj_link: Link into @i915_gem_ww_ctx.obj_list @@ -294,42 +303,88 @@ struct drm_i915_gem_object { */ struct list_head obj_link; /** - * @shared_resv_from: The object shares the resv from this vm. + * @shares_resv_from: The object shares the resv from this vm. */ struct i915_address_space *shares_resv_from; union { + /** @rcu: head used when freeing objects with RCU */ struct rcu_head rcu; + /** @freed: list of GEM freed objects */ struct llist_node freed; }; /** - * Whether the object is currently in the GGTT mmap. + * @userfault_count: a value bigger than zero means that the object + * was mmapped into userspace. + * + * Used when the object is currently in the GGTT mmap. */ unsigned int userfault_count; + /** + * @userfault_link: list of all objects that were + * mmapped into userspace. + * + * Used when the object is currently in the GGTT mmap. + */ struct list_head userfault_link; + /** @mmo: struct containing mmo offsets and lock */ struct { - spinlock_t lock; /* Protects access to mmo offsets */ + /** @mmo.lock: protects access to @mmo.offsets */ + spinlock_t lock; + /** @mmo.offsets: rbtree list of mmo offsets */ struct rb_root offsets; } mmo; + /* private: used on selftest only */ I915_SELFTEST_DECLARE(struct list_head st_link); + /* public: */ + /** + * @flags: object flags. Current flags are: + * + * %I915_BO_ALLOC_CONTIGUOUS: + * Object requires to be allocated as a contiguous block + * %I915_BO_ALLOC_VOLATILE: + * Volatile objects are marked as %DONTNEED while pinned, therefore + * once unpinned the backing store can be discarded. + * This is limited to kernel internal objects. + * %I915_BO_ALLOC_CPU_CLEAR: + * Some internal device local-memory objects may have an option + * to CPU clear the pages upon gathering the backing store. + * Note that this might be before the blitter is usable, which + * is the case for some internal GuC objects. + * %I915_BO_ALLOC_USER: + * Make sure the object is cleared before any user access. + * %I915_BO_ALLOC_PM_VOLATILE: + * Object is allowed to lose its contents on suspend / resume, + * even if pinned + * %I915_BO_ALLOC_PM_EARLY: + * Object needs to be restored early using memcpy during resume + * %I915_BO_ALLOC_GPU_ONLY: + * Object is likely never accessed by the CPU. This will + * prioritise the BO to be allocated in the non-mappable portion + * of lmem. This is merely a hint, and if dealing with userspace + * objects the CPU fault handler is free to ignore this. + * %I915_BO_READONLY: + * User has created object as read-only + * %I915_BO_PROTECTED: + * User has created protected. All protected objects and + * contexts will be considered invalid when the PXP session + * is destroyed and all new submissions using them will be + * rejected. All intel contexts within the invalidated gem + * contexts will be marked banned. Userspace can detect that + * an invalidation has occurred via the %RESET_STATS ioctl, + * where we report it the same way as a ban due to a hang. + */ unsigned long flags; #define I915_BO_ALLOC_CONTIGUOUS BIT(0) #define I915_BO_ALLOC_VOLATILE BIT(1) #define I915_BO_ALLOC_CPU_CLEAR BIT(2) #define I915_BO_ALLOC_USER BIT(3) -/* Object is allowed to lose its contents on suspend / resume, even if pinned */ #define I915_BO_ALLOC_PM_VOLATILE BIT(4) -/* Object needs to be restored early using memcpy during resume */ #define I915_BO_ALLOC_PM_EARLY BIT(5) -/* - * Object is likely never accessed by the CPU. This will prioritise the BO to be - * allocated in the non-mappable portion of lmem. This is merely a hint, and if - * dealing with userspace objects the CPU fault handler is free to ignore this. - */ #define I915_BO_ALLOC_GPU_ONLY BIT(6) #define I915_BO_ALLOC_FLAGS (I915_BO_ALLOC_CONTIGUOUS | \ I915_BO_ALLOC_VOLATILE | \ @@ -342,15 +397,21 @@ struct drm_i915_gem_object { #define I915_TILING_QUIRK_BIT 8 /* unknown swizzling; do not release! */ #define I915_BO_PROTECTED BIT(9) /** - * @mem_flags - Mutable placement-related flags + * @mem_flags: Mutable placement-related flags * * These are flags that indicate specifics of the memory region * the object is currently in. As such they are only stable * either under the object lock or if the object is pinned. + * There are two flags: + * + * %I915_BO_FLAG_STRUCT_PAGE: + * Object backed by struct pages + * %I915_BO_FLAG_IOMEM: + * Object backed by IO memory */ unsigned int mem_flags; -#define I915_BO_FLAG_STRUCT_PAGE BIT(0) /* Object backed by struct pages */ -#define I915_BO_FLAG_IOMEM BIT(1) /* Object backed by IO memory */ +#define I915_BO_FLAG_STRUCT_PAGE BIT(0) +#define I915_BO_FLAG_IOMEM BIT(1) /** * @cache_level: The desired GTT caching level. * @@ -399,7 +460,7 @@ struct drm_i915_gem_object { * * Supported values: * - * I915_BO_CACHE_COHERENT_FOR_READ: + * %I915_BO_CACHE_COHERENT_FOR_READ: * * On shared LLC platforms, we use this for special scanout surfaces, * where the display engine is not coherent with the CPU cache. As such @@ -422,7 +483,7 @@ struct drm_i915_gem_object { * * cache_coherent = 0 * - * I915_BO_CACHE_COHERENT_FOR_WRITE: + * %I915_BO_CACHE_COHERENT_FOR_WRITE: * * When writing through the CPU cache, the GPU is still coherent. Note * that this also implies I915_BO_CACHE_COHERENT_FOR_READ. @@ -508,23 +569,29 @@ struct drm_i915_gem_object { */ u16 write_domain; + /** @frontbuffer: pointer to the object's frontbuffer */ struct intel_frontbuffer __rcu *frontbuffer; - /** Current tiling stride for the object, if it's tiled. */ + /** + * @tiling_and_stride: current tiling stride for the object, + * if it's tiled. + */ unsigned int tiling_and_stride; #define FENCE_MINIMUM_STRIDE 128 /* See i915_tiling_ok() */ #define TILING_MASK (FENCE_MINIMUM_STRIDE - 1) #define STRIDE_MASK (~TILING_MASK) + /** @mm: struct containing mm-specific fields */ struct { - /* - * Protects the pages and their use. Do not use directly, but - * instead go through the pin/unpin interfaces. + /** + * @mm.pages_pin_count: protects the pages and their use. Do + * not use directly, but instead go through the pin/unpin + * interfaces. */ atomic_t pages_pin_count; /** - * @shrink_pin: Prevents the pages from being made visible to + * @mm.shrink_pin: Prevents the pages from being made visible to * the shrinker, while the shrink_pin is non-zero. Most users * should pretty much never have to care about this, outside of * some special use cases. @@ -535,7 +602,7 @@ struct drm_i915_gem_object { * __i915_gem_object_set_pages(). They will then be removed the * shrinker list once the pages are released. * - * The @shrink_pin is incremented by calling + * The @mm.shrink_pin is incremented by calling * i915_gem_object_make_unshrinkable(), which will also remove * the object from the shrinker list, if the pin count was zero. * @@ -547,13 +614,13 @@ struct drm_i915_gem_object { atomic_t shrink_pin; /** - * @ttm_shrinkable: True when the object is using shmem pages + * @mm.ttm_shrinkable: True when the object is using shmem pages * underneath. Protected by the object lock. */ bool ttm_shrinkable; /** - * @unknown_state: Indicate that the object is effectively + * @mm.unknown_state: Indicate that the object is effectively * borked. This is write-once and set if we somehow encounter a * fatal error when moving/clearing the pages, and we are not * able to fallback to memcpy/memset, like on small-BAR systems. @@ -571,96 +638,145 @@ struct drm_i915_gem_object { bool unknown_state; /** - * Priority list of potential placements for this object. + * @mm.placements: priority list of potential placements for + * this object. */ struct intel_memory_region **placements; + /** + * @mm.n_placements: Size of @mm.placements. + */ int n_placements; /** - * Memory region for this object. + * @mm.region: memory region for this object. */ struct intel_memory_region *region; /** - * Memory manager resource allocated for this object. Only - * needed for the mock region. + * @mm.res: Memory manager resource allocated for this object. + * Only needed for the mock region. */ struct ttm_resource *res; /** - * Element within memory_region->objects or region->purgeable - * if the object is marked as DONTNEED. Access is protected by - * region->obj_lock. + * @mm.region_link: element within memory_region->objects or + * ``region->purgeable`` if the object is marked as %DONTNEED. + * Access is protected by ``region->obj_lock``. */ struct list_head region_link; + /** @mm.rsgt: refcounted sg-tables */ struct i915_refct_sgt *rsgt; + /** @mm.pages: pages pointer for GGTT entries */ struct sg_table *pages; + /** + * @mm.mapping: mapped pages of the object into kernel space. + * can be %NULL if unmapped. + */ void *mapping; + /** + * @mm.page_sizes: Page sizes of the pages. + */ struct i915_page_sizes page_sizes; + /* private: used on selftest only */ I915_SELFTEST_DECLARE(unsigned int page_mask); + /* public: */ + /** @mm.get_page: */ struct i915_gem_object_page_iter get_page; + /** @mm.get_dma_page: */ struct i915_gem_object_page_iter get_dma_page; /** - * Element within i915->mm.shrink_list or i915->mm.purge_list, - * locked by i915->mm.obj_lock. + * @mm.link: element within ``i915->mm.shrink_list`` or + * ``i915->mm.purge_list``, locked by ``i915->mm.obj_lock``. */ struct list_head link; /** - * Advice: are the backing pages purgeable? + * @mm.madv: Advice: are the backing pages purgeable? */ unsigned int madv:2; /** - * This is set if the object has been written to since the - * pages were last acquired. + * @mm.dirty: this is set if the object has been written to + * since the pages were last acquired. */ bool dirty:1; u32 tlb; } mm; + /** @ttm: struct containing TTM specific fields */ struct { + /** @ttm.cached_io_rsgt: cached refcounted sg-tables */ struct i915_refct_sgt *cached_io_rsgt; + /** @ttm.get_io_page: rbtree iterator to get IO pages */ struct i915_gem_object_page_iter get_io_page; + /** @ttm.backup: list of LMEM objects backed up at suspend */ struct drm_i915_gem_object *backup; + /** @ttm.created: indicate that object as created with TTM */ bool created:1; } ttm; - /* - * Record which PXP key instance this object was created against (if - * any), so we can use it to determine if the encryption is valid by - * comparing against the current key instance. + /** + * @pxp_key_instance: rRecord which PXP key instance this object was + * created against (if any), so we can use it to determine if the + * encryption is valid by comparing against the current key instance. */ u32 pxp_key_instance; - /** Record of address bit 17 of each page at last unbind. */ + /** @bit_17: Record of address bit 17 of each page at last unbind. */ unsigned long *bit_17; union { #ifdef CONFIG_MMU_NOTIFIER + /** + * @userptr: Struct which supports userptr data + * Only used when %CONFIG_MMU_NOTIFIER is enabled + */ struct i915_gem_userptr { + /** @userptr.ptr: pointer to the user-mapped ptr */ uintptr_t ptr; + /** @userptr.notifier_seq: */ unsigned long notifier_seq; + /** @userptr.notifier: data used by MMU notifier */ struct mmu_interval_notifier notifier; + /** @userptr.pvec: S/G pages used by userptr */ struct page **pvec; + /** + * @userptr.page_ref: number of page references + * incremented when pages are in usage. + * + */ int page_ref; } userptr; #endif + /** + * @stolen: Used to identify an object allocated from + * stolen memory. + */ struct drm_mm_node *stolen; + /** + * @bo_offset: The range start. + * Used only by TTM. + */ resource_size_t bo_offset; + /** @scratch: physical size of huge gem object */ unsigned long scratch; + /** @encode: gen8 PDE encode address */ u64 encode; + /** + * @gvt_info: contains a pointer to ``dmabuf_obj->info`` + * Used only by gvt. + */ void *gvt_info; }; }; -- 2.37.3