drm/xe/pf: Add SR-IOV PF specific early GT initialization
authorMichal Wajdeczko <michal.wajdeczko@intel.com>
Mon, 15 Apr 2024 17:39:36 +0000 (19:39 +0200)
committerMichal Wajdeczko <michal.wajdeczko@intel.com>
Tue, 16 Apr 2024 10:37:34 +0000 (12:37 +0200)
The PF driver must maintain additional GT level data per each VF.
This additional per-VF data will be added in upcoming patches and
will include: provisioning configuration (like GGTT space or LMEM
allocation sizes or scheduling parameters), monitoring thresholds
and counters, and more.

As number of supported VFs varies across platforms use flexible
array where first entry will contain metadata for the PF itself
(if such configuration parameter is applicable for the PF) and
all remaining entries will contain data for potential VFs.

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-6-michal.wajdeczko@intel.com
drivers/gpu/drm/xe/Makefile
drivers/gpu/drm/xe/xe_gt.c
drivers/gpu/drm/xe/xe_gt_sriov_pf.c [new file with mode: 0644]
drivers/gpu/drm/xe/xe_gt_sriov_pf.h [new file with mode: 0644]
drivers/gpu/drm/xe/xe_gt_sriov_pf_types.h

index 522bffa5c4e1af265ffc40956692bb07babf5a17..39f47909b466fc80715ec056b54980cb7d32e562 100644 (file)
@@ -160,6 +160,7 @@ xe-y += \
        xe_sriov.o
 
 xe-$(CONFIG_PCI_IOV) += \
+       xe_gt_sriov_pf.o \
        xe_gt_sriov_pf_control.o \
        xe_gt_sriov_pf_policy.o \
        xe_lmtt.o \
index cfa5da9004612780349c1933f6b5ae5db6e243c5..38956b60e084036d03c22e5ea2d060bdbcd39a09 100644 (file)
@@ -29,6 +29,7 @@
 #include "xe_gt_mcr.h"
 #include "xe_gt_pagefault.h"
 #include "xe_gt_printk.h"
+#include "xe_gt_sriov_pf.h"
 #include "xe_gt_sysfs.h"
 #include "xe_gt_tlb_invalidation.h"
 #include "xe_gt_topology.h"
@@ -311,6 +312,12 @@ int xe_gt_init_early(struct xe_gt *gt)
 {
        int err;
 
+       if (IS_SRIOV_PF(gt_to_xe(gt))) {
+               err = xe_gt_sriov_pf_init_early(gt);
+               if (err)
+                       return err;
+       }
+
        err = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
        if (err)
                return err;
diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf.c b/drivers/gpu/drm/xe/xe_gt_sriov_pf.c
new file mode 100644 (file)
index 0000000..791dcdd
--- /dev/null
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2023-2024 Intel Corporation
+ */
+
+#include <drm/drm_managed.h>
+
+#include "xe_gt_sriov_pf.h"
+#include "xe_gt_sriov_pf_helpers.h"
+
+/*
+ * VF's metadata is maintained in the flexible array where:
+ *   - entry [0] contains metadata for the PF (only if applicable),
+ *   - entries [1..n] contain metadata for VF1..VFn::
+ *
+ *       <--------------------------- 1 + total_vfs ----------->
+ *      +-------+-------+-------+-----------------------+-------+
+ *      |   0   |   1   |   2   |                       |   n   |
+ *      +-------+-------+-------+-----------------------+-------+
+ *      |  PF   |  VF1  |  VF2  |      ...     ...      |  VFn  |
+ *      +-------+-------+-------+-----------------------+-------+
+ */
+static int pf_alloc_metadata(struct xe_gt *gt)
+{
+       unsigned int num_vfs = xe_gt_sriov_pf_get_totalvfs(gt);
+
+       gt->sriov.pf.vfs = drmm_kcalloc(&gt_to_xe(gt)->drm, 1 + num_vfs,
+                                       sizeof(*gt->sriov.pf.vfs), GFP_KERNEL);
+       if (!gt->sriov.pf.vfs)
+               return -ENOMEM;
+
+       return 0;
+}
+
+/**
+ * xe_gt_sriov_pf_init_early - Prepare SR-IOV PF data structures on PF.
+ * @gt: the &xe_gt to initialize
+ *
+ * Early initialization of the PF data.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int xe_gt_sriov_pf_init_early(struct xe_gt *gt)
+{
+       int err;
+
+       err = pf_alloc_metadata(gt);
+       if (err)
+               return err;
+
+       return 0;
+}
diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf.h b/drivers/gpu/drm/xe/xe_gt_sriov_pf.h
new file mode 100644 (file)
index 0000000..05142ff
--- /dev/null
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023-2024 Intel Corporation
+ */
+
+#ifndef _XE_GT_SRIOV_PF_H_
+#define _XE_GT_SRIOV_PF_H_
+
+struct xe_gt;
+
+#ifdef CONFIG_PCI_IOV
+int xe_gt_sriov_pf_init_early(struct xe_gt *gt);
+#else
+static inline int xe_gt_sriov_pf_init_early(struct xe_gt *gt)
+{
+       return 0;
+}
+#endif
+
+#endif
index 768277b8bc95bd810e074303e06f72c5415c07b6..223f280ef7485fa49637dbc36fdbc46f5c1f9b22 100644 (file)
 
 #include "xe_gt_sriov_pf_policy_types.h"
 
+/**
+ * struct xe_gt_sriov_metadata - GT level per-VF metadata.
+ */
+struct xe_gt_sriov_metadata {
+       /* XXX: VF metadata will go here */
+};
+
 /**
  * struct xe_gt_sriov_pf - GT level PF virtualization data.
  * @policy: policy data.
+ * @vfs: metadata for all VFs.
  */
 struct xe_gt_sriov_pf {
        struct xe_gt_sriov_pf_policy policy;
+       struct xe_gt_sriov_metadata *vfs;
 };
 
 #endif