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

drm/xe: add xe_ttm_stolen_cpu_access_needs_ggtt()

xe_ttm_stolen_cpu_inaccessible() was originally meant to just cover the
case where stolen is not directly CPU accessible on some older
integrated platforms, and as such a GGTT mapping was also required for
CPU access (as per the check in xe_bo_create_pin_map_at()).

However with small-bar systems on dgfx we have one more case where
stolen is also inaccessible, however here we don't have any fallback
GGTT mode for CPU access. Fix the check in xe_bo_create_pin_map_at() to
make this distinction clear. In such a case the later vmap() will fail
anyway.

v2: fix kernel-doc warning
v3: Simplify further and remove cpu_inaccessible()

Suggested-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

authored by

Matthew Auld and committed by
Rodrigo Vivi
69db25e4 ddad061e

+14 -29
+1 -1
drivers/gpu/drm/xe/xe_bo.c
··· 1160 1160 u64 end = offset == ~0ull ? offset : start + size; 1161 1161 1162 1162 if (flags & XE_BO_CREATE_STOLEN_BIT && 1163 - xe_ttm_stolen_cpu_inaccessible(xe)) 1163 + xe_ttm_stolen_cpu_access_needs_ggtt(xe)) 1164 1164 flags |= XE_BO_CREATE_GGTT_BIT; 1165 1165 1166 1166 bo = xe_bo_create_locked_range(xe, gt, vm, size, start, end, type, flags);
+12 -27
drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c
··· 38 38 } 39 39 40 40 /** 41 - * xe_ttm_stolen_cpu_inaccessible - Can we directly CPU access stolen memory for 42 - * this device. 41 + * xe_ttm_stolen_cpu_access_needs_ggtt() - If we can't directly CPU access 42 + * stolen, can we then fallback to mapping through the GGTT. 43 43 * @xe: xe device 44 44 * 45 - * On some integrated platforms we can't directly access stolen via the CPU 46 - * (like some normal system memory). Also on small-bar systems for discrete, 47 - * since stolen is always as the end of normal VRAM, and the BAR likely doesn't 48 - * stretch that far. However CPU access of stolen is generally rare, and at 49 - * least on discrete should not be needed. 50 - * 51 - * If this is indeed inaccessible then we fallback to using the GGTT mappable 52 - * aperture for CPU access. On discrete platforms we have no such thing, so when 53 - * later attempting to CPU map the memory an error is instead thrown. 45 + * Some older integrated platforms don't support reliable CPU access for stolen, 46 + * however on such hardware we can always use the mappable part of the GGTT for 47 + * CPU access. Check if that's the case for this device. 54 48 */ 55 - bool xe_ttm_stolen_cpu_inaccessible(struct xe_device *xe) 49 + bool xe_ttm_stolen_cpu_access_needs_ggtt(struct xe_device *xe) 56 50 { 57 - struct ttm_resource_manager *ttm_mgr = 58 - ttm_manager_type(&xe->ttm, XE_PL_STOLEN); 59 - struct xe_ttm_stolen_mgr *mgr; 60 - 61 - if (!ttm_mgr) 62 - return true; 63 - 64 - mgr = to_stolen_mgr(ttm_mgr); 65 - 66 - return !mgr->io_base || GRAPHICS_VERx100(xe) < 1270; 51 + return GRAPHICS_VERx100(xe) < 1270 && !IS_DGFX(xe); 67 52 } 68 53 69 54 static s64 detect_bar2_dgfx(struct xe_device *xe, struct xe_ttm_stolen_mgr *mgr) ··· 163 178 drm_dbg_kms(&xe->drm, "Initialized stolen memory support with %llu bytes\n", 164 179 stolen_size); 165 180 166 - if (!xe_ttm_stolen_cpu_inaccessible(xe)) 181 + if (mgr->io_base && !xe_ttm_stolen_cpu_access_needs_ggtt(xe)) 167 182 mgr->mapping = devm_ioremap_wc(&pdev->dev, mgr->io_base, stolen_size); 168 183 } 169 184 ··· 176 191 177 192 XE_BUG_ON(!mgr->io_base); 178 193 179 - if (!IS_DGFX(xe) && xe_ttm_stolen_cpu_inaccessible(xe)) 194 + if (xe_ttm_stolen_cpu_access_needs_ggtt(xe)) 180 195 return mgr->io_base + xe_bo_ggtt_addr(bo) + offset; 181 196 182 197 xe_res_first(bo->ttm.resource, offset, 4096, &cur); ··· 242 257 if (!mgr || !mgr->io_base) 243 258 return -EIO; 244 259 245 - if (!xe_ttm_stolen_cpu_inaccessible(xe)) 246 - return __xe_ttm_stolen_io_mem_reserve_bar2(xe, mgr, mem); 247 - else 260 + if (xe_ttm_stolen_cpu_access_needs_ggtt(xe)) 248 261 return __xe_ttm_stolen_io_mem_reserve_stolen(xe, mgr, mem); 262 + else 263 + return __xe_ttm_stolen_io_mem_reserve_bar2(xe, mgr, mem); 249 264 } 250 265 251 266 u64 xe_ttm_stolen_gpu_offset(struct xe_device *xe)
+1 -1
drivers/gpu/drm/xe/xe_ttm_stolen_mgr.h
··· 14 14 15 15 void xe_ttm_stolen_mgr_init(struct xe_device *xe); 16 16 int xe_ttm_stolen_io_mem_reserve(struct xe_device *xe, struct ttm_resource *mem); 17 - bool xe_ttm_stolen_cpu_inaccessible(struct xe_device *xe); 17 + bool xe_ttm_stolen_cpu_access_needs_ggtt(struct xe_device *xe); 18 18 u64 xe_ttm_stolen_io_offset(struct xe_bo *bo, u32 offset); 19 19 u64 xe_ttm_stolen_gpu_offset(struct xe_device *xe); 20 20