platform/x86/amd/hsmp: Make hsmp_pdev static instead of global

Instead of making hsmp_pdev global and exporting this symbol from hsmp.c,
make it static and create a wrapper function get_hsmp_pdev() to access
hsmp_pdev from plat.c and acpi.c.

Signed-off-by: Suma Hegde <suma.hegde@amd.com>
Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
Link: https://lore.kernel.org/r/20241021111428.2676884-11-suma.hegde@amd.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
This commit is contained in:
Suma Hegde 2024-10-21 11:14:28 +00:00 committed by Ilpo Järvinen
parent c1691730d9
commit 1349dd7dc2
No known key found for this signature in database
GPG Key ID: 59AC4F6153E5CE31
4 changed files with 48 additions and 32 deletions

View File

@ -35,6 +35,8 @@
#define MSG_ARGOFF_STR "MsgArgOffset" #define MSG_ARGOFF_STR "MsgArgOffset"
#define MSG_RESPOFF_STR "MsgRspOffset" #define MSG_RESPOFF_STR "MsgRspOffset"
static struct hsmp_plat_device *hsmp_pdev;
static int amd_hsmp_acpi_rdwr(struct hsmp_socket *sock, u32 offset, static int amd_hsmp_acpi_rdwr(struct hsmp_socket *sock, u32 offset,
u32 *value, bool write) u32 *value, bool write)
{ {
@ -203,7 +205,7 @@ static int hsmp_read_acpi_crs(struct hsmp_socket *sock)
/* Parse the ACPI table to read the data */ /* Parse the ACPI table to read the data */
static int hsmp_parse_acpi_table(struct device *dev, u16 sock_ind) static int hsmp_parse_acpi_table(struct device *dev, u16 sock_ind)
{ {
struct hsmp_socket *sock = &hsmp_pdev.sock[sock_ind]; struct hsmp_socket *sock = &hsmp_pdev->sock[sock_ind];
int ret; int ret;
sock->sock_ind = sock_ind; sock->sock_ind = sock_ind;
@ -236,7 +238,7 @@ static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj
static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj, static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
struct bin_attribute *battr, int id) struct bin_attribute *battr, int id)
{ {
if (hsmp_pdev.proto_ver == HSMP_PROTO_VER6) if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6)
return battr->attr.mode; return battr->attr.mode;
return 0; return 0;
@ -250,7 +252,7 @@ static int init_acpi(struct device *dev)
ret = hsmp_get_uid(dev, &sock_ind); ret = hsmp_get_uid(dev, &sock_ind);
if (ret) if (ret)
return ret; return ret;
if (sock_ind >= hsmp_pdev.num_sockets) if (sock_ind >= hsmp_pdev->num_sockets)
return -EINVAL; return -EINVAL;
ret = hsmp_parse_acpi_table(dev, sock_ind); ret = hsmp_parse_acpi_table(dev, sock_ind);
@ -274,7 +276,7 @@ static int init_acpi(struct device *dev)
return ret; return ret;
} }
if (hsmp_pdev.proto_ver == HSMP_PROTO_VER6) { if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6) {
ret = hsmp_get_tbl_dram_base(sock_ind); ret = hsmp_get_tbl_dram_base(sock_ind);
if (ret) if (ret)
dev_err(dev, "Failed to init metric table\n"); dev_err(dev, "Failed to init metric table\n");
@ -314,15 +316,19 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
{ {
int ret; int ret;
if (!hsmp_pdev.is_probed) { hsmp_pdev = get_hsmp_pdev();
hsmp_pdev.num_sockets = amd_nb_num(); if (!hsmp_pdev)
if (hsmp_pdev.num_sockets == 0 || hsmp_pdev.num_sockets > MAX_AMD_SOCKETS) return -ENOMEM;
if (!hsmp_pdev->is_probed) {
hsmp_pdev->num_sockets = amd_nb_num();
if (hsmp_pdev->num_sockets == 0 || hsmp_pdev->num_sockets > MAX_AMD_SOCKETS)
return -ENODEV; return -ENODEV;
hsmp_pdev.sock = devm_kcalloc(&pdev->dev, hsmp_pdev.num_sockets, hsmp_pdev->sock = devm_kcalloc(&pdev->dev, hsmp_pdev->num_sockets,
sizeof(*hsmp_pdev.sock), sizeof(*hsmp_pdev->sock),
GFP_KERNEL); GFP_KERNEL);
if (!hsmp_pdev.sock) if (!hsmp_pdev->sock)
return -ENOMEM; return -ENOMEM;
} }
@ -332,11 +338,11 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
return ret; return ret;
} }
if (!hsmp_pdev.is_probed) { if (!hsmp_pdev->is_probed) {
ret = hsmp_misc_register(&pdev->dev); ret = hsmp_misc_register(&pdev->dev);
if (ret) if (ret)
return ret; return ret;
hsmp_pdev.is_probed = true; hsmp_pdev->is_probed = true;
} }
return 0; return 0;
@ -348,9 +354,9 @@ static void hsmp_acpi_remove(struct platform_device *pdev)
* We register only one misc_device even on multi-socket system. * We register only one misc_device even on multi-socket system.
* So, deregister should happen only once. * So, deregister should happen only once.
*/ */
if (hsmp_pdev.is_probed) { if (hsmp_pdev->is_probed) {
hsmp_misc_deregister(); hsmp_misc_deregister();
hsmp_pdev.is_probed = false; hsmp_pdev->is_probed = false;
} }
} }

View File

@ -35,8 +35,7 @@
#define DRIVER_VERSION "2.3" #define DRIVER_VERSION "2.3"
struct hsmp_plat_device hsmp_pdev; static struct hsmp_plat_device hsmp_pdev;
EXPORT_SYMBOL_NS_GPL(hsmp_pdev, AMD_HSMP);
/* /*
* Send a message to the HSMP port via PCI-e config space registers * Send a message to the HSMP port via PCI-e config space registers
@ -384,6 +383,12 @@ void hsmp_misc_deregister(void)
} }
EXPORT_SYMBOL_NS_GPL(hsmp_misc_deregister, AMD_HSMP); EXPORT_SYMBOL_NS_GPL(hsmp_misc_deregister, AMD_HSMP);
struct hsmp_plat_device *get_hsmp_pdev(void)
{
return &hsmp_pdev;
}
EXPORT_SYMBOL_NS_GPL(get_hsmp_pdev, AMD_HSMP);
MODULE_DESCRIPTION("AMD HSMP Common driver"); MODULE_DESCRIPTION("AMD HSMP Common driver");
MODULE_VERSION(DRIVER_VERSION); MODULE_VERSION(DRIVER_VERSION);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");

View File

@ -55,8 +55,6 @@ struct hsmp_plat_device {
bool is_probed; bool is_probed;
}; };
extern struct hsmp_plat_device hsmp_pdev;
int hsmp_cache_proto_ver(u16 sock_ind); int hsmp_cache_proto_ver(u16 sock_ind);
int hsmp_test(u16 sock_ind, u32 value); int hsmp_test(u16 sock_ind, u32 value);
long hsmp_ioctl(struct file *fp, unsigned int cmd, unsigned long arg); long hsmp_ioctl(struct file *fp, unsigned int cmd, unsigned long arg);
@ -64,4 +62,5 @@ void hsmp_misc_deregister(void);
int hsmp_misc_register(struct device *dev); int hsmp_misc_register(struct device *dev);
int hsmp_get_tbl_dram_base(u16 sock_ind); int hsmp_get_tbl_dram_base(u16 sock_ind);
ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t size); ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t size);
struct hsmp_plat_device *get_hsmp_pdev(void);
#endif /* HSMP_H */ #endif /* HSMP_H */

View File

@ -37,6 +37,8 @@
#define HSMP_INDEX_REG 0xc4 #define HSMP_INDEX_REG 0xc4
#define HSMP_DATA_REG 0xc8 #define HSMP_DATA_REG 0xc8
static struct hsmp_plat_device *hsmp_pdev;
static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset, static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset,
u32 *value, bool write) u32 *value, bool write)
{ {
@ -64,10 +66,10 @@ static ssize_t hsmp_metric_tbl_plat_read(struct file *filp, struct kobject *kobj
u16 sock_ind; u16 sock_ind;
sock_ind = (uintptr_t)bin_attr->private; sock_ind = (uintptr_t)bin_attr->private;
if (sock_ind >= hsmp_pdev.num_sockets) if (sock_ind >= hsmp_pdev->num_sockets)
return -EINVAL; return -EINVAL;
sock = &hsmp_pdev.sock[sock_ind]; sock = &hsmp_pdev->sock[sock_ind];
return hsmp_metric_tbl_read(sock, buf, count); return hsmp_metric_tbl_read(sock, buf, count);
} }
@ -79,10 +81,10 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
sock_ind = (uintptr_t)battr->private; sock_ind = (uintptr_t)battr->private;
if (id == 0 && sock_ind >= hsmp_pdev.num_sockets) if (id == 0 && sock_ind >= hsmp_pdev->num_sockets)
return SYSFS_GROUP_INVISIBLE; return SYSFS_GROUP_INVISIBLE;
if (hsmp_pdev.proto_ver == HSMP_PROTO_VER6) if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6)
return battr->attr.mode; return battr->attr.mode;
return 0; return 0;
@ -156,10 +158,10 @@ static int init_platform_device(struct device *dev)
struct hsmp_socket *sock; struct hsmp_socket *sock;
int ret, i; int ret, i;
for (i = 0; i < hsmp_pdev.num_sockets; i++) { for (i = 0; i < hsmp_pdev->num_sockets; i++) {
if (!node_to_amd_nb(i)) if (!node_to_amd_nb(i))
return -ENODEV; return -ENODEV;
sock = &hsmp_pdev.sock[i]; sock = &hsmp_pdev->sock[i];
sock->root = node_to_amd_nb(i)->root; sock->root = node_to_amd_nb(i)->root;
sock->sock_ind = i; sock->sock_ind = i;
sock->dev = dev; sock->dev = dev;
@ -194,7 +196,7 @@ static int init_platform_device(struct device *dev)
return ret; return ret;
} }
if (hsmp_pdev.proto_ver == HSMP_PROTO_VER6) { if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6) {
ret = hsmp_get_tbl_dram_base(i); ret = hsmp_get_tbl_dram_base(i);
if (ret) if (ret)
dev_err(dev, "Failed to init metric table\n"); dev_err(dev, "Failed to init metric table\n");
@ -208,10 +210,10 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev)
{ {
int ret; int ret;
hsmp_pdev.sock = devm_kcalloc(&pdev->dev, hsmp_pdev.num_sockets, hsmp_pdev->sock = devm_kcalloc(&pdev->dev, hsmp_pdev->num_sockets,
sizeof(*hsmp_pdev.sock), sizeof(*hsmp_pdev->sock),
GFP_KERNEL); GFP_KERNEL);
if (!hsmp_pdev.sock) if (!hsmp_pdev->sock)
return -ENOMEM; return -ENOMEM;
ret = init_platform_device(&pdev->dev); ret = init_platform_device(&pdev->dev);
@ -298,12 +300,16 @@ static int __init hsmp_plt_init(void)
return ret; return ret;
} }
hsmp_pdev = get_hsmp_pdev();
if (!hsmp_pdev)
return -ENOMEM;
/* /*
* amd_nb_num() returns number of SMN/DF interfaces present in the system * amd_nb_num() returns number of SMN/DF interfaces present in the system
* if we have N SMN/DF interfaces that ideally means N sockets * if we have N SMN/DF interfaces that ideally means N sockets
*/ */
hsmp_pdev.num_sockets = amd_nb_num(); hsmp_pdev->num_sockets = amd_nb_num();
if (hsmp_pdev.num_sockets == 0 || hsmp_pdev.num_sockets > MAX_AMD_SOCKETS) if (hsmp_pdev->num_sockets == 0 || hsmp_pdev->num_sockets > MAX_AMD_SOCKETS)
return ret; return ret;
ret = platform_driver_register(&amd_hsmp_driver); ret = platform_driver_register(&amd_hsmp_driver);