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

drm/xe/pf: Access VF's register using dedicated MMIO view

Instead of creating ad-hoc new register definitions with altered
register addresses to mimic the VF's access to these registers,
prepare new MMIO instance per required VF, with shifted internal
location of the register map. This will allow to use unmodified
register definitions in all calls to xe_mmio() functions.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: Matt Roper <matthew.d.roper@intel.com>
Link: https://patch.msgid.link/20251024205826.4652-1-michal.wajdeczko@intel.com

+41 -28
+8 -28
drivers/gpu/drm/xe/xe_gt_sriov_pf.c
··· 158 158 xe_gt_sriov_pf_service_update(gt); 159 159 } 160 160 161 - static u32 pf_get_vf_regs_stride(struct xe_device *xe) 162 - { 163 - return GRAPHICS_VERx100(xe) > 1200 ? 0x400 : 0x1000; 164 - } 165 - 166 - static struct xe_reg xe_reg_vf_to_pf(struct xe_reg vf_reg, unsigned int vfid, u32 stride) 167 - { 168 - struct xe_reg pf_reg = vf_reg; 169 - 170 - pf_reg.vf = 0; 171 - pf_reg.addr += stride * vfid; 172 - 173 - return pf_reg; 174 - } 175 - 176 161 static void pf_clear_vf_scratch_regs(struct xe_gt *gt, unsigned int vfid) 177 162 { 178 - u32 stride = pf_get_vf_regs_stride(gt_to_xe(gt)); 179 - struct xe_reg scratch; 180 - int n, count; 163 + struct xe_mmio mmio; 164 + int n; 165 + 166 + xe_mmio_init_vf_view(&mmio, &gt->mmio, vfid); 181 167 182 168 if (xe_gt_is_media_type(gt)) { 183 - count = MED_VF_SW_FLAG_COUNT; 184 - for (n = 0; n < count; n++) { 185 - scratch = xe_reg_vf_to_pf(MED_VF_SW_FLAG(n), vfid, stride); 186 - xe_mmio_write32(&gt->mmio, scratch, 0); 187 - } 169 + for (n = 0; n < MED_VF_SW_FLAG_COUNT; n++) 170 + xe_mmio_write32(&mmio, MED_VF_SW_FLAG(n), 0); 188 171 } else { 189 - count = VF_SW_FLAG_COUNT; 190 - for (n = 0; n < count; n++) { 191 - scratch = xe_reg_vf_to_pf(VF_SW_FLAG(n), vfid, stride); 192 - xe_mmio_write32(&gt->mmio, scratch, 0); 193 - } 172 + for (n = 0; n < VF_SW_FLAG_COUNT; n++) 173 + xe_mmio_write32(&mmio, VF_SW_FLAG(n), 0); 194 174 } 195 175 } 196 176
+29
drivers/gpu/drm/xe/xe_mmio.c
··· 379 379 { 380 380 return __xe_mmio_wait32(mmio, reg, mask, val, timeout_us, out_val, atomic, false); 381 381 } 382 + 383 + #ifdef CONFIG_PCI_IOV 384 + static size_t vf_regs_stride(struct xe_device *xe) 385 + { 386 + return GRAPHICS_VERx100(xe) > 1200 ? 0x400 : 0x1000; 387 + } 388 + 389 + /** 390 + * xe_mmio_init_vf_view() - Initialize an MMIO instance for accesses like the VF 391 + * @mmio: the target &xe_mmio to initialize as VF's view 392 + * @base: the source &xe_mmio to initialize from 393 + * @vfid: the VF identifier 394 + */ 395 + void xe_mmio_init_vf_view(struct xe_mmio *mmio, const struct xe_mmio *base, unsigned int vfid) 396 + { 397 + struct xe_tile *tile = base->tile; 398 + struct xe_device *xe = tile->xe; 399 + size_t offset = vf_regs_stride(xe) * vfid; 400 + 401 + xe_assert(xe, IS_SRIOV_PF(xe)); 402 + xe_assert(xe, vfid); 403 + xe_assert(xe, !base->sriov_vf_gt); 404 + xe_assert(xe, base->regs_size > offset); 405 + 406 + *mmio = *base; 407 + mmio->regs += offset; 408 + mmio->regs_size -= offset; 409 + } 410 + #endif
+4
drivers/gpu/drm/xe/xe_mmio.h
··· 42 42 return &xe->tiles[0].mmio; 43 43 } 44 44 45 + #ifdef CONFIG_PCI_IOV 46 + void xe_mmio_init_vf_view(struct xe_mmio *mmio, const struct xe_mmio *base, unsigned int vfid); 47 + #endif 48 + 45 49 #endif