Skip to content

Commit 9e56d02

Browse files
committed
drm/xe: Allow to assign GGTT region to the VF
VF's drivers can't modify GGTT PTEs except the range explicitly assigned by the PF driver. To allow hardware enforcement of this requirement, each GGTT PTE has a field with the VF number that identifies which VF can modify that particular GGTT PTE entry. Only PF driver can modify this field and PF driver shall do that before VF drivers will be loaded. Add function to prepare PTEs. Since it will be used only by the PF driver, make it available only for CONFIG_PCI_IOV=y. Bspec: 45015, 52395 Reviewed-by: Piotr Piórkowski <piotr.piorkowski@intel.com> Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240415173937.1287-3-michal.wajdeczko@intel.com
1 parent c720172 commit 9e56d02

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

drivers/gpu/drm/xe/regs/xe_gtt_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#define XELPG_GGTT_PTE_PAT0 BIT_ULL(52)
1010
#define XELPG_GGTT_PTE_PAT1 BIT_ULL(53)
1111

12+
#define GGTT_PTE_VFID GENMASK_ULL(11, 2)
13+
1214
#define GUC_GGTT_TOP 0xFEE00000
1315

1416
#define XELPG_PPGTT_PTE_PAT3 BIT_ULL(62)

drivers/gpu/drm/xe/xe_ggtt.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,50 @@ void xe_ggtt_remove_bo(struct xe_ggtt *ggtt, struct xe_bo *bo)
460460
bo->flags & XE_BO_FLAG_GGTT_INVALIDATE);
461461
}
462462

463+
#ifdef CONFIG_PCI_IOV
464+
static u64 xe_encode_vfid_pte(u16 vfid)
465+
{
466+
return FIELD_PREP(GGTT_PTE_VFID, vfid) | XE_PAGE_PRESENT;
467+
}
468+
469+
static void xe_ggtt_assign_locked(struct xe_ggtt *ggtt, const struct drm_mm_node *node, u16 vfid)
470+
{
471+
u64 start = node->start;
472+
u64 size = node->size;
473+
u64 end = start + size - 1;
474+
u64 pte = xe_encode_vfid_pte(vfid);
475+
476+
lockdep_assert_held(&ggtt->lock);
477+
478+
if (!drm_mm_node_allocated(node))
479+
return;
480+
481+
while (start < end) {
482+
xe_ggtt_set_pte(ggtt, start, pte);
483+
start += XE_PAGE_SIZE;
484+
}
485+
486+
xe_ggtt_invalidate(ggtt);
487+
}
488+
489+
/**
490+
* xe_ggtt_assign - assign a GGTT region to the VF
491+
* @ggtt: the &xe_ggtt where the node belongs
492+
* @node: the &drm_mm_node to update
493+
* @vfid: the VF identifier
494+
*
495+
* This function is used by the PF driver to assign a GGTT region to the VF.
496+
* In addition to PTE's VFID bits 11:2 also PRESENT bit 0 is set as on some
497+
* platforms VFs can't modify that either.
498+
*/
499+
void xe_ggtt_assign(struct xe_ggtt *ggtt, const struct drm_mm_node *node, u16 vfid)
500+
{
501+
mutex_lock(&ggtt->lock);
502+
xe_ggtt_assign_locked(ggtt, node, vfid);
503+
mutex_unlock(&ggtt->lock);
504+
}
505+
#endif
506+
463507
int xe_ggtt_dump(struct xe_ggtt *ggtt, struct drm_printer *p)
464508
{
465509
int err;

drivers/gpu/drm/xe/xe_ggtt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ void xe_ggtt_remove_bo(struct xe_ggtt *ggtt, struct xe_bo *bo);
3333

3434
int xe_ggtt_dump(struct xe_ggtt *ggtt, struct drm_printer *p);
3535

36+
#ifdef CONFIG_PCI_IOV
37+
void xe_ggtt_assign(struct xe_ggtt *ggtt, const struct drm_mm_node *node, u16 vfid);
38+
#endif
39+
3640
#endif

0 commit comments

Comments
 (0)