Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/xe/bo: refactor try_add_vram

Get rid of some of the duplication here. In a future patch we need to
also consider [fpfn, lpfn], so better adjust in only one place.

Suggested-by: José Roberto de Souza <jose.souza@intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

authored by

Matthew Auld and committed by
Rodrigo Vivi
e7dc1341 8deba79f

+31 -55
+31 -55
drivers/gpu/drm/xe/xe_bo.c
··· 106 106 } 107 107 } 108 108 109 - static void try_add_vram0(struct xe_device *xe, struct xe_bo *bo, 110 - struct ttm_place *places, u32 bo_flags, u32 *c) 109 + static void add_vram(struct xe_device *xe, struct xe_bo *bo, 110 + struct ttm_place *places, u32 bo_flags, u32 mem_type, u32 *c) 111 111 { 112 - struct xe_gt *gt; 112 + struct xe_gt *gt = mem_type_to_gt(xe, mem_type); 113 113 114 - if (bo_flags & XE_BO_CREATE_VRAM0_BIT) { 115 - gt = mem_type_to_gt(xe, XE_PL_VRAM0); 116 - XE_BUG_ON(!gt->mem.vram.size); 114 + XE_BUG_ON(!gt->mem.vram.size); 117 115 118 - places[*c] = (struct ttm_place) { 119 - .mem_type = XE_PL_VRAM0, 120 - /* 121 - * For eviction / restore on suspend / resume objects 122 - * pinned in VRAM must be contiguous 123 - */ 124 - .flags = bo_flags & (XE_BO_CREATE_PINNED_BIT | 125 - XE_BO_CREATE_GGTT_BIT) ? 126 - TTM_PL_FLAG_CONTIGUOUS : 0, 127 - }; 128 - *c += 1; 116 + places[*c] = (struct ttm_place) { 117 + .mem_type = mem_type, 118 + /* 119 + * For eviction / restore on suspend / resume objects 120 + * pinned in VRAM must be contiguous 121 + */ 122 + .flags = bo_flags & (XE_BO_CREATE_PINNED_BIT | 123 + XE_BO_CREATE_GGTT_BIT) ? 124 + TTM_PL_FLAG_CONTIGUOUS : 0, 125 + }; 126 + *c += 1; 129 127 130 - if (bo->props.preferred_mem_type == XE_BO_PROPS_INVALID) 131 - bo->props.preferred_mem_type = XE_PL_VRAM0; 132 - } 128 + if (bo->props.preferred_mem_type == XE_BO_PROPS_INVALID) 129 + bo->props.preferred_mem_type = mem_type; 133 130 } 134 131 135 - static void try_add_vram1(struct xe_device *xe, struct xe_bo *bo, 136 - struct ttm_place *places, u32 bo_flags, u32 *c) 132 + static void try_add_vram(struct xe_device *xe, struct xe_bo *bo, 133 + struct ttm_place *places, u32 bo_flags, u32 *c) 137 134 { 138 - struct xe_gt *gt; 139 - 140 - if (bo_flags & XE_BO_CREATE_VRAM1_BIT) { 141 - gt = mem_type_to_gt(xe, XE_PL_VRAM1); 142 - XE_BUG_ON(!gt->mem.vram.size); 143 - 144 - places[*c] = (struct ttm_place) { 145 - .mem_type = XE_PL_VRAM1, 146 - /* 147 - * For eviction / restore on suspend / resume objects 148 - * pinned in VRAM must be contiguous 149 - */ 150 - .flags = bo_flags & (XE_BO_CREATE_PINNED_BIT | 151 - XE_BO_CREATE_GGTT_BIT) ? 152 - TTM_PL_FLAG_CONTIGUOUS : 0, 153 - }; 154 - *c += 1; 155 - 156 - if (bo->props.preferred_mem_type == XE_BO_PROPS_INVALID) 157 - bo->props.preferred_mem_type = XE_PL_VRAM1; 135 + if (bo->props.preferred_gt == XE_GT1) { 136 + if (bo_flags & XE_BO_CREATE_VRAM1_BIT) 137 + add_vram(xe, bo, places, bo_flags, XE_PL_VRAM1, c); 138 + if (bo_flags & XE_BO_CREATE_VRAM0_BIT) 139 + add_vram(xe, bo, places, bo_flags, XE_PL_VRAM0, c); 140 + } else { 141 + if (bo_flags & XE_BO_CREATE_VRAM0_BIT) 142 + add_vram(xe, bo, places, bo_flags, XE_PL_VRAM0, c); 143 + if (bo_flags & XE_BO_CREATE_VRAM1_BIT) 144 + add_vram(xe, bo, places, bo_flags, XE_PL_VRAM1, c); 158 145 } 159 146 } 160 147 ··· 171 184 172 185 if (bo->props.preferred_mem_class == XE_MEM_REGION_CLASS_SYSMEM) { 173 186 try_add_system(bo, places, bo_flags, &c); 174 - if (bo->props.preferred_gt == XE_GT1) { 175 - try_add_vram1(xe, bo, places, bo_flags, &c); 176 - try_add_vram0(xe, bo, places, bo_flags, &c); 177 - } else { 178 - try_add_vram0(xe, bo, places, bo_flags, &c); 179 - try_add_vram1(xe, bo, places, bo_flags, &c); 180 - } 181 - } else if (bo->props.preferred_gt == XE_GT1) { 182 - try_add_vram1(xe, bo, places, bo_flags, &c); 183 - try_add_vram0(xe, bo, places, bo_flags, &c); 184 - try_add_system(bo, places, bo_flags, &c); 187 + try_add_vram(xe, bo, places, bo_flags, &c); 185 188 } else { 186 - try_add_vram0(xe, bo, places, bo_flags, &c); 187 - try_add_vram1(xe, bo, places, bo_flags, &c); 189 + try_add_vram(xe, bo, places, bo_flags, &c); 188 190 try_add_system(bo, places, bo_flags, &c); 189 191 } 190 192 try_add_stolen(xe, bo, places, bo_flags, &c);