Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael J. Ruhl" <michael.j.ruhl@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: david.e.box@linux.intel.com,
	"Michael J. Ruhl" <michael.j.ruhl@intel.com>
Subject: [PATCH 5/6] drm/xe/vsec: Add support for DG2
Date: Fri, 10 May 2024 16:59:37 -0400	[thread overview]
Message-ID: <20240510205948.904409-6-michael.j.ruhl@intel.com> (raw)
In-Reply-To: <20240510205948.904409-1-michael.j.ruhl@intel.com>

DG2 needs to adjust the discovery offset WRT the GT BAR
not the P2SB bar so utilize the P2SB quirk.

Add support by registering via the intel_vsec_register()
API.

Signed-off-by: Michael J. Ruhl <michael.j.ruhl@intel.com>
---
 drivers/gpu/drm/xe/Makefile    |   1 +
 drivers/gpu/drm/xe/xe_device.c |   3 +
 drivers/gpu/drm/xe/xe_vsec.c   | 110 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_vsec.h   |  13 ++++
 4 files changed, 127 insertions(+)
 create mode 100644 drivers/gpu/drm/xe/xe_vsec.c
 create mode 100644 drivers/gpu/drm/xe/xe_vsec.h

diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile
index a67977edff5b..805b27201e1a 100644
--- a/drivers/gpu/drm/xe/Makefile
+++ b/drivers/gpu/drm/xe/Makefile
@@ -143,6 +143,7 @@ xe-y += xe_bb.o \
 	xe_uc_debugfs.o \
 	xe_uc_fw.o \
 	xe_vm.o \
+	xe_vsec.o \
 	xe_vram_freq.o \
 	xe_wait_user_fence.o \
 	xe_wa.o \
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 4165e1347371..e77768bc4471 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -46,6 +46,7 @@
 #include "xe_ttm_stolen_mgr.h"
 #include "xe_ttm_sys_mgr.h"
 #include "xe_vm.h"
+#include "xe_vsec.h"
 #include "xe_wait_user_fence.h"
 
 static int xe_file_open(struct drm_device *dev, struct drm_file *file)
@@ -662,6 +663,8 @@ int xe_device_probe(struct xe_device *xe)
 
 	xe_hwmon_register(xe);
 
+	xe_vsec_init(xe);
+
 	return drmm_add_action_or_reset(&xe->drm, xe_device_sanitize, xe);
 
 err_fini_display:
diff --git a/drivers/gpu/drm/xe/xe_vsec.c b/drivers/gpu/drm/xe/xe_vsec.c
new file mode 100644
index 000000000000..a91aec49d04a
--- /dev/null
+++ b/drivers/gpu/drm/xe/xe_vsec.c
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright © 2022 - 2024 Intel Corporation
+ */
+#include <linux/intel_vsec.h>
+#include <linux/pci.h>
+
+#include "xe_device_types.h"
+#include "xe_drv.h"
+#include "xe_platform_types.h"
+#include "xe_vsec.h"
+
+#define SOC_BASE		0x280000
+
+/* from drivers/platform/x86/intel/pmt/telemetry.c */
+#define TELEM_BASE_OFFSET	0x8
+
+#define DG2_PMT_BASE		0xE8000
+#define DG2_DISCOVERY_START	0x6000
+#define DG2_TELEM_START		0x4000
+
+#define DG2_DISCOVERY_OFFSET	(SOC_BASE + DG2_PMT_BASE + DG2_DISCOVERY_START)
+#define DG2_TELEM_OFFSET	(SOC_BASE + DG2_PMT_BASE + DG2_TELEM_START)
+
+#define GFX_BAR			0
+
+static struct intel_vsec_header dg2_telemetry = {
+	.length = 0x10,
+	.id = VSEC_ID_TELEMETRY,
+	.num_entries = 1,
+	.entry_size = 3,
+	.tbir = GFX_BAR,
+	.offset = DG2_DISCOVERY_OFFSET,
+};
+
+static struct intel_vsec_header *dg2_capabilities[] = {
+	&dg2_telemetry,
+	NULL
+};
+
+static struct intel_vsec_platform_info dg2_vsec_info = {
+	.caps = VSEC_CAP_TELEMETRY,
+	.headers = dg2_capabilities,
+	.quirks = VSEC_QUIRK_EARLY_HW | VSEC_QUIRK_P2SB_OFFSET,
+};
+
+/*
+ * Access the DG2 PMT MMIO discovery table
+ *
+ * The intel_vsec driver does not typically access the discovery table.
+ * Instead, it creates a memory resource for the table and passes it
+ * to the PMT telemetry driver. Each discovery table contains 3 items,
+ *    - GUID
+ *    - Telemetry size
+ *    - Telemetry offset (offset from P2SB BAR, not GT)
+ *
+ * For DG2 we know what the telemetry offset is, but we still need to
+ * use the discovery table to pass the GUID and the size. So figure
+ * out the difference between the P2SB offset and the GT offset and
+ * save this so that the telemetry driver can use it to adjust the
+ * value.
+ */
+static int dg2_adjust_offset(struct pci_dev *pdev, struct device *dev,
+			     struct intel_vsec_platform_info *info)
+{
+	void __iomem *base;
+	u32 telem_offset;
+	u64 addr;
+
+	addr = pci_resource_start(pdev, GFX_BAR) + info->headers[0]->offset;
+	base = ioremap_wc(addr, 16);
+	if (!base)
+		return -ENOMEM;
+
+	telem_offset = readl(base + TELEM_BASE_OFFSET);
+
+	/* Use the base_addr + P2SB quirk to pass this info */
+	if (telem_offset < DG2_TELEM_OFFSET)
+		info->base_addr = -(DG2_TELEM_OFFSET - telem_offset);
+	else
+		info->base_addr = -(telem_offset - DG2_TELEM_OFFSET);
+
+	iounmap(base);
+
+	return 0;
+}
+
+/**
+ * intel_vsec_init - Initialize resources and add intel_vsec auxiliary
+ * interface
+ * @xe: valid xe instance
+ */
+void xe_vsec_init(struct xe_device *xe)
+{
+	struct intel_vsec_platform_info *info = &dg2_vsec_info;
+	struct device *dev = xe->drm.dev;
+	struct pci_dev *pdev = to_pci_dev(dev);
+	u32 ret;
+
+	ret = dg2_adjust_offset(pdev, dev, info);
+	if (ret)
+		return;
+
+	/*
+	 * Register a VSEC. Cleanup is handled using device managed
+	 * resources.
+	 */
+	intel_vsec_register(pdev, info);
+}
+MODULE_IMPORT_NS(INTEL_VSEC);
diff --git a/drivers/gpu/drm/xe/xe_vsec.h b/drivers/gpu/drm/xe/xe_vsec.h
new file mode 100644
index 000000000000..3fd29a21cad6
--- /dev/null
+++ b/drivers/gpu/drm/xe/xe_vsec.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright © 2022 - 2024 Intel Corporation
+ */
+
+#ifndef _XE_VSEC_H_
+#define _XE_VSEC_H_
+
+struct xe_device;
+
+void xe_vsec_init(struct xe_device *xe);
+
+#endif
-- 
2.44.0


  parent reply	other threads:[~2024-05-10 21:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-10 20:59 [PATCH 0/6] Support PMT features in Xe Michael J. Ruhl
2024-05-10 20:59 ` [PATCH 1/6] platform/x86/intel/vsec.h: Move to include/linux Michael J. Ruhl
2024-05-28 15:43   ` Ruhl, Michael J
2024-05-30 21:07     ` David E. Box
2024-05-10 20:59 ` [PATCH 2/6] platform/x86/intel/vsec: Add PMT read callbacks Michael J. Ruhl
2024-05-10 20:59 ` [PATCH 3/6] platform/x86/intel/pmt: Add support to use provided " Michael J. Ruhl
2024-05-13 17:15   ` Rodrigo Vivi
2024-05-10 20:59 ` [PATCH 4/6] platform/x86/intel/pmt: Add quirk for BAR0 offset adjustment Michael J. Ruhl
2024-05-30 20:59   ` David E. Box
2024-05-31 15:40     ` Ruhl, Michael J
2024-05-10 20:59 ` Michael J. Ruhl [this message]
2024-05-10 20:59 ` [PATCH 6/6] drm/xe/vsec: Support BMG devices Michael J. Ruhl
2024-05-30 21:06   ` David E. Box
2024-05-31 15:42     ` Ruhl, Michael J
2024-05-10 21:48 ` ✓ CI.Patch_applied: success for Support PMT features in Xe Patchwork
2024-05-10 21:48 ` ✗ CI.checkpatch: warning " Patchwork
2024-05-10 21:49 ` ✗ CI.KUnit: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240510205948.904409-6-michael.j.ruhl@intel.com \
    --to=michael.j.ruhl@intel.com \
    --cc=david.e.box@linux.intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox