Skip to content

Commit 4504e78

Browse files
committed
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
1 parent 071089a commit 4504e78

3 files changed

Lines changed: 41 additions & 28 deletions

File tree

drivers/gpu/drm/xe/xe_gt_sriov_pf.c

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -158,39 +158,19 @@ void xe_gt_sriov_pf_init_hw(struct xe_gt *gt)
158158
xe_gt_sriov_pf_service_update(gt);
159159
}
160160

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-
176161
static void pf_clear_vf_scratch_regs(struct xe_gt *gt, unsigned int vfid)
177162
{
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);
181167

182168
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);
188171
} 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);
194174
}
195175
}
196176

drivers/gpu/drm/xe/xe_mmio.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,32 @@ int xe_mmio_wait32_not(struct xe_mmio *mmio, struct xe_reg reg, u32 mask, u32 va
379379
{
380380
return __xe_mmio_wait32(mmio, reg, mask, val, timeout_us, out_val, atomic, false);
381381
}
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

drivers/gpu/drm/xe/xe_mmio.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ static inline struct xe_mmio *xe_root_tile_mmio(struct xe_device *xe)
4242
return &xe->tiles[0].mmio;
4343
}
4444

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+
4549
#endif

0 commit comments

Comments
 (0)