xref: /linux/drivers/gpu/drm/xe/xe_bo_types.h (revision 48eb42245fea7b004634c406a3ce92e020a78a05)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5 
6 #ifndef _XE_BO_TYPES_H_
7 #define _XE_BO_TYPES_H_
8 
9 #include <linux/iosys-map.h>
10 
11 #include <drm/drm_gpusvm.h>
12 #include <drm/drm_pagemap.h>
13 #include <drm/ttm/ttm_bo.h>
14 #include <drm/ttm/ttm_device.h>
15 #include <drm/ttm/ttm_placement.h>
16 
17 #include "xe_device_types.h"
18 #include "xe_ggtt_types.h"
19 
20 struct xe_device;
21 struct xe_mem_pool_node;
22 struct xe_vm;
23 struct xe_exec_queue;
24 
25 #define XE_BO_MAX_PLACEMENTS	3
26 
27 /* TODO: To be selected with VM_MADVISE */
28 #define	XE_BO_PRIORITY_NORMAL	1
29 
30 /**
31  * struct xe_bo - Xe buffer object
32  */
33 struct xe_bo {
34 	/** @ttm: TTM base buffer object */
35 	struct ttm_buffer_object ttm;
36 	/** @backup_obj: The backup object when pinned and suspended (vram only) */
37 	struct xe_bo *backup_obj;
38 	/** @parent_obj: Ref to parent bo if this a backup_obj */
39 	struct xe_bo *parent_obj;
40 	/** @dma_buf: Imported dma-buf ref to keep its resv alive. */
41 	struct dma_buf *dma_buf;
42 	/** @flags: flags for this buffer object */
43 	u32 flags;
44 	/** @vm: VM this BO is attached to, for extobj this will be NULL */
45 	struct xe_vm *vm;
46 	/**
47 	 * @q: Queue this BO is attached to, mostly for LRC BO, NULL otherwise.
48 	 * Protected by the BO dma_resv: readers must hold it across both the
49 	 * read and xe_exec_queue_get_unless_zero(). The BO holds no reference
50 	 * on the queue.
51 	 */
52 	struct xe_exec_queue *q;
53 	/** @tile: Tile this BO is attached to (kernel BO only) */
54 	struct xe_tile *tile;
55 	/** @placements: valid placements for this BO */
56 	struct ttm_place placements[XE_BO_MAX_PLACEMENTS];
57 	/** @placement: current placement for this BO */
58 	struct ttm_placement placement;
59 	/** @ggtt_node: Array of GGTT nodes if this BO is mapped in the GGTTs */
60 	struct xe_ggtt_node *ggtt_node[XE_MAX_TILES_PER_DEVICE];
61 	/** @vmap: iosys map of this buffer */
62 	struct iosys_map vmap;
63 	/** @kmap: TTM bo kmap object for internal use only. Keep off. */
64 	struct ttm_bo_kmap_obj kmap;
65 	/** @pinned_link: link to present / evicted list of pinned BO */
66 	struct list_head pinned_link;
67 #ifdef CONFIG_PROC_FS
68 	/**
69 	 * @client: @xe_drm_client which created the bo
70 	 */
71 	struct xe_drm_client *client;
72 	/**
73 	 * @client_link: Link into @xe_drm_client.objects_list
74 	 */
75 	struct list_head client_link;
76 #endif
77 	/** @attr: User controlled attributes for bo */
78 	struct {
79 		/**
80 		 * @attr.atomic_access: type of atomic access bo needs
81 		 * protected by bo dma-resv lock
82 		 */
83 		u32 atomic_access;
84 	} attr;
85 	/**
86 	 * @pxp_key_instance: PXP key instance this BO was created against. A
87 	 * 0 in this variable indicates that the BO does not use PXP encryption.
88 	 */
89 	u32 pxp_key_instance;
90 
91 	/** @freed: List node for delayed put. */
92 	struct llist_node freed;
93 	/** @created: Whether the bo has passed initial creation */
94 	bool created;
95 
96 	/** @ccs_cleared: true means that CCS region of BO is already cleared */
97 	bool ccs_cleared;
98 
99 	/** @bb_ccs: BB instructions of CCS read/write. Valid only for VF */
100 	struct xe_mem_pool_node *bb_ccs[XE_SRIOV_VF_CCS_CTX_COUNT];
101 
102 	/**
103 	 * @cpu_caching: CPU caching mode. Currently only used for userspace
104 	 * objects. Exceptions are system memory on DGFX, which is always
105 	 * WB.
106 	 */
107 	u16 cpu_caching;
108 
109 	/** @devmem_allocation: SVM device memory allocation */
110 	struct drm_pagemap_devmem devmem_allocation;
111 
112 	/** @vram_userfault_link: Link into @mem_access.vram_userfault.list */
113 	struct list_head vram_userfault_link;
114 
115 	/**
116 	 * @min_align: minimum alignment needed for this BO if different
117 	 * from default
118 	 */
119 	u64 min_align;
120 
121 	/**
122 	 * @purgeable: Purgeability state and accounting.
123 	 *
124 	 * All fields are protected by the BO's dma-resv lock.
125 	 */
126 	struct {
127 		/**
128 		 * @purgeable.state: BO purgeability state
129 		 *                   (WILLNEED/DONTNEED/PURGED).
130 		 */
131 		u32 state;
132 
133 		/**
134 		 * @purgeable.vma_count: Number of VMAs currently mapping this BO.
135 		 */
136 		u32 vma_count;
137 
138 		/**
139 		 * @purgeable.willneed_count: Number of active WILLNEED holders.
140 		 *
141 		 * Counts WILLNEED VMAs plus active dma-buf exports for
142 		 * non-imported BOs. The BO flips to DONTNEED on a 1->0
143 		 * transition only when VMAs still exist; if the last VMA is
144 		 * removed, the previous BO state is preserved.
145 		 */
146 		u32 willneed_count;
147 	} purgeable;
148 };
149 
150 #endif
151