From ce08d3570ae0ef3e8b011d8bd4722b7b413c476b Mon Sep 17 00:00:00 2001 From: Suma Hegde Date: Sat, 6 Jan 2024 02:25:26 +0000 Subject: platform/x86/amd/hsmp: Move dev from platdev to hsmp_socket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On an ACPI enabled platforms the probe is called for each socket and the struct dev is different for each socket. This change will help in handling both ACPI and non-ACPI platforms. Also change pr_err() to dev_err() API. Signed-off-by: Suma Hegde Signed-off-by: Naveen Krishna Chatradhi Reviewed-by: Hans de Goede Reviewed-by: Ilpo Järvinen Link: https://lore.kernel.org/r/20240106022532.1746932-5-suma.hegde@amd.com Signed-off-by: Ilpo Järvinen --- drivers/platform/x86/amd/hsmp.c | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'drivers/platform/x86/amd') diff --git a/drivers/platform/x86/amd/hsmp.c b/drivers/platform/x86/amd/hsmp.c index 287eaa9b0dda..6347aafb81e7 100644 --- a/drivers/platform/x86/amd/hsmp.c +++ b/drivers/platform/x86/amd/hsmp.c @@ -69,13 +69,13 @@ struct hsmp_socket { struct semaphore hsmp_sem; char name[HSMP_ATTR_GRP_NAME_SIZE]; struct pci_dev *root; + struct device *dev; u16 sock_ind; }; struct hsmp_plat_device { struct miscdevice hsmp_device; struct hsmp_socket *sock; - struct device *dev; u32 proto_ver; u16 num_sockets; }; @@ -278,8 +278,9 @@ static int hsmp_test(u16 sock_ind, u32 value) /* Check the response value */ if (msg.args[0] != (value + 1)) { - pr_err("Socket %d test message failed, Expected 0x%08X, received 0x%08X\n", - sock_ind, (value + 1), msg.args[0]); + dev_err(plat_dev.sock[sock_ind].dev, + "Socket %d test message failed, Expected 0x%08X, received 0x%08X\n", + sock_ind, (value + 1), msg.args[0]); return -EBADE; } @@ -356,14 +357,12 @@ static ssize_t hsmp_metric_tbl_read(struct file *filp, struct kobject *kobj, struct hsmp_message msg = { 0 }; int ret; - /* Do not support lseek(), reads entire metric table */ - if (count < bin_attr->size) { - dev_err(plat_dev.dev, "Wrong buffer size\n"); + if (!sock) return -EINVAL; - } - if (!sock) { - dev_err(plat_dev.dev, "Failed to read attribute private data\n"); + /* Do not support lseek(), reads entire metric table */ + if (count < bin_attr->size) { + dev_err(sock->dev, "Wrong buffer size\n"); return -EINVAL; } @@ -399,13 +398,13 @@ static int hsmp_get_tbl_dram_base(u16 sock_ind) */ dram_addr = msg.args[0] | ((u64)(msg.args[1]) << 32); if (!dram_addr) { - dev_err(plat_dev.dev, "Invalid DRAM address for metric table\n"); + dev_err(sock->dev, "Invalid DRAM address for metric table\n"); return -ENOMEM; } - sock->metric_tbl_addr = devm_ioremap(plat_dev.dev, dram_addr, + sock->metric_tbl_addr = devm_ioremap(sock->dev, dram_addr, sizeof(struct hsmp_metric_table)); if (!sock->metric_tbl_addr) { - dev_err(plat_dev.dev, "Failed to ioremap metric table addr\n"); + dev_err(sock->dev, "Failed to ioremap metric table addr\n"); return -ENOMEM; } return 0; @@ -453,14 +452,15 @@ static int hsmp_create_sysfs_interface(void) if (WARN_ON(plat_dev.num_sockets > U8_MAX)) return -ERANGE; - hsmp_attr_grps = devm_kzalloc(plat_dev.dev, sizeof(struct attribute_group *) * + hsmp_attr_grps = devm_kzalloc(plat_dev.sock[0].dev, sizeof(struct attribute_group *) * (plat_dev.num_sockets + 1), GFP_KERNEL); if (!hsmp_attr_grps) return -ENOMEM; /* Create a sysfs directory for each socket */ for (i = 0; i < plat_dev.num_sockets; i++) { - attr_grp = devm_kzalloc(plat_dev.dev, sizeof(struct attribute_group), GFP_KERNEL); + attr_grp = devm_kzalloc(plat_dev.sock[i].dev, sizeof(struct attribute_group), + GFP_KERNEL); if (!attr_grp) return -ENOMEM; @@ -468,7 +468,7 @@ static int hsmp_create_sysfs_interface(void) attr_grp->name = plat_dev.sock[i].name; /* Null terminated list of attributes */ - hsmp_bin_attrs = devm_kzalloc(plat_dev.dev, sizeof(struct bin_attribute *) * + hsmp_bin_attrs = devm_kzalloc(plat_dev.sock[i].dev, sizeof(struct bin_attribute *) * (NUM_HSMP_ATTRS + 1), GFP_KERNEL); if (!hsmp_bin_attrs) return -ENOMEM; @@ -482,7 +482,7 @@ static int hsmp_create_sysfs_interface(void) if (ret) return ret; } - return devm_device_add_groups(plat_dev.dev, hsmp_attr_grps); + return devm_device_add_groups(plat_dev.sock[0].dev, hsmp_attr_grps); } static int hsmp_cache_proto_ver(void) @@ -501,7 +501,7 @@ static int hsmp_cache_proto_ver(void) return ret; } -static int init_platform_device(void) +static int init_platform_device(struct device *dev) { struct hsmp_socket *sock; int ret, i; @@ -512,6 +512,7 @@ static int init_platform_device(void) sock = &plat_dev.sock[i]; sock->root = node_to_amd_nb(i)->root; sock->sock_ind = i; + sock->dev = dev; sock->mbinfo.base_addr = SMN_HSMP_BASE; sock->mbinfo.msg_id_off = SMN_HSMP_MSG_ID; sock->mbinfo.msg_resp_off = SMN_HSMP_MSG_RESP; @@ -521,9 +522,9 @@ static int init_platform_device(void) /* Test the hsmp interface on each socket */ ret = hsmp_test(i, 0xDEADBEEF); if (ret) { - pr_err("HSMP test message failed on Fam:%x model:%x\n", - boot_cpu_data.x86, boot_cpu_data.x86_model); - pr_err("Is HSMP disabled in BIOS ?\n"); + dev_err(dev, "HSMP test message failed on Fam:%x model:%x\n", + boot_cpu_data.x86, boot_cpu_data.x86_model); + dev_err(dev, "Is HSMP disabled in BIOS ?\n"); return ret; } } @@ -540,9 +541,8 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev) GFP_KERNEL); if (!plat_dev.sock) return -ENOMEM; - plat_dev.dev = &pdev->dev; - ret = init_platform_device(); + ret = init_platform_device(&pdev->dev); if (ret) return ret; @@ -555,13 +555,13 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev) ret = hsmp_cache_proto_ver(); if (ret) { - dev_err(plat_dev.dev, "Failed to read HSMP protocol version\n"); + dev_err(&pdev->dev, "Failed to read HSMP protocol version\n"); return ret; } ret = hsmp_create_sysfs_interface(); if (ret) - dev_err(plat_dev.dev, "Failed to create HSMP sysfs interface\n"); + dev_err(&pdev->dev, "Failed to create HSMP sysfs interface\n"); return misc_register(&plat_dev.hsmp_device); } -- cgit v1.2.3-58-ga151