Unverified Commit 866d8b3f authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!13849 intel: backport Intel SST TPMI update from 6.10

Merge Pull Request from: @jiayingbao 
 
backport sst driver update and fix from 6.10
including version change, feature update and fix.

Test:
intel-speed-select tool function ok 
 
Link:https://gitee.com/openeuler/kernel/pulls/13849

 

Reviewed-by: default avatarJason Zeng <jason.zeng@intel.com>
Signed-off-by: default avatarZhang Peng <zhangpeng362@huawei.com>
parents 2aa1596c db55e4c3
Loading
Loading
Loading
Loading
+60 −56
Original line number Diff line number Diff line
@@ -653,10 +653,6 @@ static long isst_if_def_ioctl(struct file *file, unsigned int cmd,

/* Lock to prevent module registration when already opened by user space */
static DEFINE_MUTEX(punit_misc_dev_open_lock);
/* Lock to allow one shared misc device for all ISST interfaces */
static DEFINE_MUTEX(punit_misc_dev_reg_lock);
static int misc_usage_count;
static int misc_device_ret;
static int misc_device_open;

static int isst_if_open(struct inode *inode, struct file *file)
@@ -720,56 +716,26 @@ static struct miscdevice isst_if_char_driver = {
	.fops		= &isst_if_char_driver_ops,
};

static const struct x86_cpu_id hpm_cpu_ids[] = {
	X86_MATCH_INTEL_FAM6_MODEL(GRANITERAPIDS_D,	NULL),
	X86_MATCH_INTEL_FAM6_MODEL(GRANITERAPIDS_X,	NULL),
	X86_MATCH_INTEL_FAM6_MODEL(ATOM_CRESTMONT,	NULL),
	X86_MATCH_INTEL_FAM6_MODEL(ATOM_CRESTMONT_X,	NULL),
	{}
};

static int isst_misc_reg(void)
{
	mutex_lock(&punit_misc_dev_reg_lock);
	if (misc_device_ret)
		goto unlock_exit;

	if (!misc_usage_count) {
		const struct x86_cpu_id *id;

		id = x86_match_cpu(hpm_cpu_ids);
		if (id)
			isst_hpm_support = true;
	int ret;

		misc_device_ret = isst_if_cpu_info_init();
		if (misc_device_ret)
			goto unlock_exit;
	ret = isst_if_cpu_info_init();
	if (ret)
		return ret;

		misc_device_ret = misc_register(&isst_if_char_driver);
		if (misc_device_ret) {
	ret = misc_register(&isst_if_char_driver);
	if (ret)
		isst_if_cpu_info_exit();
			goto unlock_exit;
		}
	}
	misc_usage_count++;

unlock_exit:
	mutex_unlock(&punit_misc_dev_reg_lock);

	return misc_device_ret;
	return ret;
}

static void isst_misc_unreg(void)
{
	mutex_lock(&punit_misc_dev_reg_lock);
	if (misc_usage_count)
		misc_usage_count--;
	if (!misc_usage_count && !misc_device_ret) {
	misc_deregister(&isst_if_char_driver);
	isst_if_cpu_info_exit();
}
	mutex_unlock(&punit_misc_dev_reg_lock);
}

/**
 * isst_if_cdev_register() - Register callback for IOCTL
@@ -788,11 +754,12 @@ static void isst_misc_unreg(void)
 */
int isst_if_cdev_register(int device_type, struct isst_if_cmd_cb *cb)
{
	int ret;

	if (device_type >= ISST_IF_DEV_MAX)
		return -EINVAL;

	if (device_type < ISST_IF_DEV_TPMI && isst_hpm_support)
		return -ENODEV;

	mutex_lock(&punit_misc_dev_open_lock);
	/* Device is already open, we don't want to add new callbacks */
	if (misc_device_open) {
@@ -807,15 +774,6 @@ int isst_if_cdev_register(int device_type, struct isst_if_cmd_cb *cb)
	punit_callbacks[device_type].registered = 1;
	mutex_unlock(&punit_misc_dev_open_lock);

	ret = isst_misc_reg();
	if (ret) {
		/*
		 * No need of mutex as the misc device register failed
		 * as no one can open device yet. Hence no contention.
		 */
		punit_callbacks[device_type].registered = 0;
		return ret;
	}
	return 0;
}
EXPORT_SYMBOL_GPL(isst_if_cdev_register);
@@ -831,7 +789,6 @@ EXPORT_SYMBOL_GPL(isst_if_cdev_register);
 */
void isst_if_cdev_unregister(int device_type)
{
	isst_misc_unreg();
	mutex_lock(&punit_misc_dev_open_lock);
	punit_callbacks[device_type].def_ioctl = NULL;
	punit_callbacks[device_type].registered = 0;
@@ -841,4 +798,51 @@ void isst_if_cdev_unregister(int device_type)
}
EXPORT_SYMBOL_GPL(isst_if_cdev_unregister);

#define SST_HPM_SUPPORTED	0x01
#define SST_MBOX_SUPPORTED	0x02

static const struct x86_cpu_id isst_cpu_ids[] = {
	X86_MATCH_INTEL_FAM6_MODEL(ATOM_CRESTMONT,	SST_HPM_SUPPORTED),
	X86_MATCH_INTEL_FAM6_MODEL(ATOM_CRESTMONT_X,	SST_HPM_SUPPORTED),
	X86_MATCH_INTEL_FAM6_MODEL(EMERALDRAPIDS_X,	0),
	X86_MATCH_INTEL_FAM6_MODEL(GRANITERAPIDS_D,	SST_HPM_SUPPORTED),
	X86_MATCH_INTEL_FAM6_MODEL(GRANITERAPIDS_X,	SST_HPM_SUPPORTED),
	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D,		0),
	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X,		0),
	X86_MATCH_INTEL_FAM6_MODEL(SAPPHIRERAPIDS_X,	0),
	X86_MATCH_INTEL_FAM6_MODEL(SKYLAKE_X,		SST_MBOX_SUPPORTED),
	{}
};
MODULE_DEVICE_TABLE(x86cpu, isst_cpu_ids);

static int __init isst_if_common_init(void)
{
	const struct x86_cpu_id *id;

	id = x86_match_cpu(isst_cpu_ids);
	if (!id)
		return -ENODEV;

	if (id->driver_data == SST_HPM_SUPPORTED) {
		isst_hpm_support = true;
	} else if (id->driver_data == SST_MBOX_SUPPORTED) {
		u64 data;

		/* Can fail only on some Skylake-X generations */
		if (rdmsrl_safe(MSR_OS_MAILBOX_INTERFACE, &data) ||
		    rdmsrl_safe(MSR_OS_MAILBOX_DATA, &data))
			return -ENODEV;
	}

	return isst_misc_reg();
}
module_init(isst_if_common_init)

static void __exit isst_if_common_exit(void)
{
	isst_misc_unreg();
}
module_exit(isst_if_common_exit)

MODULE_DESCRIPTION("ISST common interface module");
MODULE_LICENSE("GPL v2");
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@
#define PCI_DEVICE_ID_INTEL_RAPL_PRIO_DEVID_1	0x3251
#define PCI_DEVICE_ID_INTEL_CFG_MBOX_DEVID_1	0x3259

#define MSR_OS_MAILBOX_INTERFACE		0xB0
#define MSR_OS_MAILBOX_DATA			0xB1

/*
 * Validate maximum commands in a single request.
 * This is enough to handle command to every core in one ioctl, or all
+0 −2
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@

#include "isst_if_common.h"

#define MSR_OS_MAILBOX_INTERFACE	0xB0
#define MSR_OS_MAILBOX_DATA		0xB1
#define MSR_OS_MAILBOX_BUSY_BIT		31

/*
+13 −8
Original line number Diff line number Diff line
@@ -18,16 +18,17 @@
struct isst_mmio_range {
	int beg;
	int end;
	int size;
};

static struct isst_mmio_range mmio_range_devid_0[] = {
	{0x04, 0x14},
	{0x20, 0xD0},
	{0x04, 0x14, 0x18},
	{0x20, 0xD0, 0xD4},
};

static struct isst_mmio_range mmio_range_devid_1[] = {
	{0x04, 0x14},
	{0x20, 0x11C},
	{0x04, 0x14, 0x18},
	{0x20, 0x11C, 0x120},
};

struct isst_if_device {
@@ -93,6 +94,7 @@ static int isst_if_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
	struct isst_if_device *punit_dev;
	struct isst_if_cmd_cb cb;
	u32 mmio_base, pcu_base;
	struct resource r;
	u64 base_addr;
	int ret;

@@ -114,13 +116,16 @@ static int isst_if_probe(struct pci_dev *pdev, const struct pci_device_id *ent)

	pcu_base &= GENMASK(10, 0);
	base_addr = (u64)mmio_base << 23 | (u64) pcu_base << 12;
	punit_dev->punit_mmio = devm_ioremap(&pdev->dev, base_addr, 256);
	if (!punit_dev->punit_mmio)
		return -ENOMEM;

	punit_dev->mmio_range = (struct isst_mmio_range *) ent->driver_data;

	r = DEFINE_RES_MEM(base_addr, punit_dev->mmio_range[1].size);
	punit_dev->punit_mmio = devm_ioremap_resource(&pdev->dev, &r);
	if (IS_ERR(punit_dev->punit_mmio))
		return PTR_ERR(punit_dev->punit_mmio);

	mutex_init(&punit_dev->mutex);
	pci_set_drvdata(pdev, punit_dev);
	punit_dev->mmio_range = (struct isst_mmio_range *) ent->driver_data;

	memset(&cb, 0, sizeof(cb));
	cb.cmd_size = sizeof(struct isst_if_io_reg);
+358 −68

File changed.

Preview size limit exceeded, changes collapsed.