Commit 727bf2dc authored by Dave Airlie's avatar Dave Airlie
Browse files

Merge tag 'drm-xe-next-2025-11-14' of https://gitlab.freedesktop.org/drm/xe/kernel into drm-next



Driver Changes:

Avoid TOCTOU when montoring throttle reasons (Lucas)
Add/extend workaround (Nitin)
SRIOV migration work / plumbing (Michal Wajdeczko, Michal Winiarski, Lukasz)
Drop debug flag requirement for VF resource fixup
Fix MTL vm_max_level (Rodrigo)
Changes around TILE_ADDR_RANGE for platform compatibility
(Fei, Lucas)
Add runtime registers for GFX ver >= 35 (Piotr)
Kerneldoc fix (Kriish)
Rework pcode error mapping (Lucas)
Allow lockdown the PF (Michal)
Eliminate GUC code caching of some frequency values (Sk)
Improvements around forcewake referencing (Matt Roper)

Signed-off-by: default avatarDave Airlie <airlied@redhat.com>

From: Thomas Hellstrom <thomas.hellstrom@linux.intel.com>
Link: https://patch.msgid.link/aRcJOrisG2qPbucE@fedora
parents 61926c91 6bcb180f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -174,9 +174,11 @@ xe-$(CONFIG_PCI_IOV) += \
	xe_lmtt_2l.o \
	xe_lmtt_ml.o \
	xe_pci_sriov.o \
	xe_sriov_packet.o \
	xe_sriov_pf.o \
	xe_sriov_pf_control.o \
	xe_sriov_pf_debugfs.o \
	xe_sriov_pf_migration.o \
	xe_sriov_pf_provision.o \
	xe_sriov_pf_service.o \
	xe_sriov_pf_sysfs.o \
+0 −1
Original line number Diff line number Diff line
@@ -101,7 +101,6 @@

#define XE2_LMEM_CFG				XE_REG(0x48b0)

#define XEHP_TILE_ADDR_RANGE(_idx)		XE_REG_MCR(0x4900 + (_idx) * 4)
#define XEHP_FLAT_CCS_BASE_ADDR			XE_REG_MCR(0x4910)
#define XEHP_FLAT_CCS_PTR			REG_GENMASK(31, 8)

+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@
#define STOLEN_RESERVED				XE_REG(0x1082c0)
#define   WOPCM_SIZE_MASK			REG_GENMASK64(9, 7)

#define SG_TILE_ADDR_RANGE(_idx)		XE_REG(0x1083a0 + (_idx) * 4)

#define MTL_RP_STATE_CAP			XE_REG(0x138000)

#define MTL_GT_RPA_FREQUENCY			XE_REG(0x138008)
+208 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0 AND MIT
/*
 * Copyright © 2025 Intel Corporation
 */

#include <kunit/static_stub.h>
#include <kunit/test.h>
#include <kunit/test-bug.h>

#include "xe_kunit_helpers.h"
#include "xe_pci_test.h"

#define TEST_MAX_VFS	63

static void pf_set_admin_mode(struct xe_device *xe, bool enable)
{
	/* should match logic of xe_sriov_pf_admin_only() */
	xe->info.probe_display = !enable;
	KUNIT_EXPECT_EQ(kunit_get_current_test(), enable, xe_sriov_pf_admin_only(xe));
}

static const void *num_vfs_gen_param(struct kunit *test, const void *prev, char *desc)
{
	unsigned long next = 1 + (unsigned long)prev;

	if (next > TEST_MAX_VFS)
		return NULL;
	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%lu VF%s",
		 next, str_plural(next));
	return (void *)next;
}

static int pf_gt_config_test_init(struct kunit *test)
{
	struct xe_pci_fake_data fake = {
		.sriov_mode = XE_SRIOV_MODE_PF,
		.platform = XE_TIGERLAKE, /* any random platform with SR-IOV */
		.subplatform = XE_SUBPLATFORM_NONE,
	};
	struct xe_device *xe;
	struct xe_gt *gt;

	test->priv = &fake;
	xe_kunit_helper_xe_device_test_init(test);

	xe = test->priv;
	KUNIT_ASSERT_TRUE(test, IS_SRIOV_PF(xe));

	gt = xe_root_mmio_gt(xe);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, gt);
	test->priv = gt;

	/* pretend it can support up to 63 VFs */
	xe->sriov.pf.device_total_vfs = TEST_MAX_VFS;
	xe->sriov.pf.driver_max_vfs = TEST_MAX_VFS;
	KUNIT_ASSERT_EQ(test, xe_sriov_pf_get_totalvfs(xe), 63);

	pf_set_admin_mode(xe, false);
	KUNIT_ASSERT_EQ(test, xe_sriov_init(xe), 0);

	/* more sanity checks */
	KUNIT_EXPECT_EQ(test, GUC_ID_MAX + 1, SZ_64K);
	KUNIT_EXPECT_EQ(test, GUC_NUM_DOORBELLS, SZ_256);

	return 0;
}

static void fair_contexts_1vf(struct kunit *test)
{
	struct xe_gt *gt = test->priv;
	struct xe_device *xe = gt_to_xe(gt);

	pf_set_admin_mode(xe, false);
	KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe));
	KUNIT_EXPECT_EQ(test, SZ_32K, pf_profile_fair_ctxs(gt, 1));

	pf_set_admin_mode(xe, true);
	KUNIT_ASSERT_TRUE(test, xe_sriov_pf_admin_only(xe));
	KUNIT_EXPECT_EQ(test, SZ_64K - SZ_1K, pf_profile_fair_ctxs(gt, 1));
}

static void fair_contexts(struct kunit *test)
{
	unsigned int num_vfs = (unsigned long)test->param_value;
	struct xe_gt *gt = test->priv;
	struct xe_device *xe = gt_to_xe(gt);

	pf_set_admin_mode(xe, false);
	KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe));

	KUNIT_EXPECT_TRUE(test, is_power_of_2(pf_profile_fair_ctxs(gt, num_vfs)));
	KUNIT_EXPECT_GT(test, GUC_ID_MAX, num_vfs * pf_profile_fair_ctxs(gt, num_vfs));

	if (num_vfs > 31)
		KUNIT_ASSERT_EQ(test, SZ_1K, pf_profile_fair_ctxs(gt, num_vfs));
	else if (num_vfs > 15)
		KUNIT_ASSERT_EQ(test, SZ_2K, pf_profile_fair_ctxs(gt, num_vfs));
	else if (num_vfs > 7)
		KUNIT_ASSERT_EQ(test, SZ_4K, pf_profile_fair_ctxs(gt, num_vfs));
	else if (num_vfs > 3)
		KUNIT_ASSERT_EQ(test, SZ_8K, pf_profile_fair_ctxs(gt, num_vfs));
	else if (num_vfs > 1)
		KUNIT_ASSERT_EQ(test, SZ_16K, pf_profile_fair_ctxs(gt, num_vfs));
	else
		KUNIT_ASSERT_EQ(test, SZ_32K, pf_profile_fair_ctxs(gt, num_vfs));
}

static void fair_doorbells_1vf(struct kunit *test)
{
	struct xe_gt *gt = test->priv;
	struct xe_device *xe = gt_to_xe(gt);

	pf_set_admin_mode(xe, false);
	KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe));
	KUNIT_EXPECT_EQ(test, 128, pf_profile_fair_dbs(gt, 1));

	pf_set_admin_mode(xe, true);
	KUNIT_ASSERT_TRUE(test, xe_sriov_pf_admin_only(xe));
	KUNIT_EXPECT_EQ(test, 240, pf_profile_fair_dbs(gt, 1));
}

static void fair_doorbells(struct kunit *test)
{
	unsigned int num_vfs = (unsigned long)test->param_value;
	struct xe_gt *gt = test->priv;
	struct xe_device *xe = gt_to_xe(gt);

	pf_set_admin_mode(xe, false);
	KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe));

	KUNIT_EXPECT_TRUE(test, is_power_of_2(pf_profile_fair_dbs(gt, num_vfs)));
	KUNIT_EXPECT_GE(test, GUC_NUM_DOORBELLS, (num_vfs + 1) * pf_profile_fair_dbs(gt, num_vfs));

	if (num_vfs > 31)
		KUNIT_ASSERT_EQ(test, SZ_4, pf_profile_fair_dbs(gt, num_vfs));
	else if (num_vfs > 15)
		KUNIT_ASSERT_EQ(test, SZ_8, pf_profile_fair_dbs(gt, num_vfs));
	else if (num_vfs > 7)
		KUNIT_ASSERT_EQ(test, SZ_16, pf_profile_fair_dbs(gt, num_vfs));
	else if (num_vfs > 3)
		KUNIT_ASSERT_EQ(test, SZ_32, pf_profile_fair_dbs(gt, num_vfs));
	else if (num_vfs > 1)
		KUNIT_ASSERT_EQ(test, SZ_64, pf_profile_fair_dbs(gt, num_vfs));
	else
		KUNIT_ASSERT_EQ(test, SZ_128, pf_profile_fair_dbs(gt, num_vfs));
}

static void fair_ggtt_1vf(struct kunit *test)
{
	struct xe_gt *gt = test->priv;
	struct xe_device *xe = gt_to_xe(gt);

	pf_set_admin_mode(xe, false);
	KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe));
	KUNIT_EXPECT_EQ(test, SZ_2G, pf_profile_fair_ggtt(gt, 1));

	pf_set_admin_mode(xe, true);
	KUNIT_ASSERT_TRUE(test, xe_sriov_pf_admin_only(xe));
	KUNIT_EXPECT_EQ(test, SZ_2G + SZ_1G + SZ_512M, pf_profile_fair_ggtt(gt, 1));
}

static void fair_ggtt(struct kunit *test)
{
	unsigned int num_vfs = (unsigned long)test->param_value;
	struct xe_gt *gt = test->priv;
	struct xe_device *xe = gt_to_xe(gt);
	u64 alignment = pf_get_ggtt_alignment(gt);
	u64 shareable = SZ_2G + SZ_1G + SZ_512M;

	pf_set_admin_mode(xe, false);
	KUNIT_ASSERT_FALSE(test, xe_sriov_pf_admin_only(xe));

	KUNIT_EXPECT_TRUE(test, IS_ALIGNED(pf_profile_fair_ggtt(gt, num_vfs), alignment));
	KUNIT_EXPECT_GE(test, shareable, num_vfs * pf_profile_fair_ggtt(gt, num_vfs));

	if (num_vfs > 56)
		KUNIT_ASSERT_EQ(test, SZ_64M - SZ_8M, pf_profile_fair_ggtt(gt, num_vfs));
	else if (num_vfs > 28)
		KUNIT_ASSERT_EQ(test, SZ_64M, pf_profile_fair_ggtt(gt, num_vfs));
	else if (num_vfs > 14)
		KUNIT_ASSERT_EQ(test, SZ_128M, pf_profile_fair_ggtt(gt, num_vfs));
	else if (num_vfs > 7)
		KUNIT_ASSERT_EQ(test, SZ_256M, pf_profile_fair_ggtt(gt, num_vfs));
	else if (num_vfs > 3)
		KUNIT_ASSERT_EQ(test, SZ_512M, pf_profile_fair_ggtt(gt, num_vfs));
	else if (num_vfs > 1)
		KUNIT_ASSERT_EQ(test, SZ_1G, pf_profile_fair_ggtt(gt, num_vfs));
	else
		KUNIT_ASSERT_EQ(test, SZ_2G, pf_profile_fair_ggtt(gt, num_vfs));
}

static struct kunit_case pf_gt_config_test_cases[] = {
	KUNIT_CASE(fair_contexts_1vf),
	KUNIT_CASE(fair_doorbells_1vf),
	KUNIT_CASE(fair_ggtt_1vf),
	KUNIT_CASE_PARAM(fair_contexts, num_vfs_gen_param),
	KUNIT_CASE_PARAM(fair_doorbells, num_vfs_gen_param),
	KUNIT_CASE_PARAM(fair_ggtt, num_vfs_gen_param),
	{}
};

static struct kunit_suite pf_gt_config_suite = {
	.name = "pf_gt_config",
	.test_cases = pf_gt_config_test_cases,
	.init = pf_gt_config_test_init,
};

kunit_test_suite(pf_gt_config_suite);
+4 −4
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ struct xe_eu_stall_data_stream {
	wait_queue_head_t poll_wq;
	size_t data_record_size;
	size_t per_xecore_buf_size;
	unsigned int fw_ref;

	struct xe_gt *gt;
	struct xe_bo *bo;
@@ -660,13 +661,12 @@ static int xe_eu_stall_stream_enable(struct xe_eu_stall_data_stream *stream)
	struct per_xecore_buf *xecore_buf;
	struct xe_gt *gt = stream->gt;
	u16 group, instance;
	unsigned int fw_ref;
	int xecore;

	/* Take runtime pm ref and forcewake to disable RC6 */
	xe_pm_runtime_get(gt_to_xe(gt));
	fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_RENDER);
	if (!xe_force_wake_ref_has_domain(fw_ref, XE_FW_RENDER)) {
	stream->fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_RENDER);
	if (!xe_force_wake_ref_has_domain(stream->fw_ref, XE_FW_RENDER)) {
		xe_gt_err(gt, "Failed to get RENDER forcewake\n");
		xe_pm_runtime_put(gt_to_xe(gt));
		return -ETIMEDOUT;
@@ -832,7 +832,7 @@ static int xe_eu_stall_disable_locked(struct xe_eu_stall_data_stream *stream)
		xe_gt_mcr_multicast_write(gt, ROW_CHICKEN2,
					  _MASKED_BIT_DISABLE(DISABLE_DOP_GATING));

	xe_force_wake_put(gt_to_fw(gt), XE_FW_RENDER);
	xe_force_wake_put(gt_to_fw(gt), stream->fw_ref);
	xe_pm_runtime_put(gt_to_xe(gt));

	return 0;
Loading