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_RESPOFF_STR "MsgRspOffset"
static struct hsmp_plat_device *hsmp_pdev;
static int amd_hsmp_acpi_rdwr(struct hsmp_socket *sock, u32 offset,
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 */
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;
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,
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 0;
@ -250,7 +252,7 @@ static int init_acpi(struct device *dev)
ret = hsmp_get_uid(dev, &sock_ind);
if (ret)
return ret;
if (sock_ind >= hsmp_pdev.num_sockets)
if (sock_ind >= hsmp_pdev->num_sockets)
return -EINVAL;
ret = hsmp_parse_acpi_table(dev, sock_ind);
@ -274,7 +276,7 @@ static int init_acpi(struct device *dev)
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);
if (ret)
dev_err(dev, "Failed to init metric table\n");
@ -314,15 +316,19 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
{
int ret;
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)
hsmp_pdev = get_hsmp_pdev();
if (!hsmp_pdev)
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;
hsmp_pdev.sock = devm_kcalloc(&pdev->dev, hsmp_pdev.num_sockets,
sizeof(*hsmp_pdev.sock),
GFP_KERNEL);
if (!hsmp_pdev.sock)
hsmp_pdev->sock = devm_kcalloc(&pdev->dev, hsmp_pdev->num_sockets,
sizeof(*hsmp_pdev->sock),
GFP_KERNEL);
if (!hsmp_pdev->sock)
return -ENOMEM;
}
@ -332,11 +338,11 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
return ret;
}
if (!hsmp_pdev.is_probed) {
if (!hsmp_pdev->is_probed) {
ret = hsmp_misc_register(&pdev->dev);
if (ret)
return ret;
hsmp_pdev.is_probed = true;
hsmp_pdev->is_probed = true;
}
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.
* So, deregister should happen only once.
*/
if (hsmp_pdev.is_probed) {
if (hsmp_pdev->is_probed) {
hsmp_misc_deregister();
hsmp_pdev.is_probed = false;
hsmp_pdev->is_probed = false;
}
}

View File

@ -35,8 +35,7 @@
#define DRIVER_VERSION "2.3"
struct hsmp_plat_device hsmp_pdev;
EXPORT_SYMBOL_NS_GPL(hsmp_pdev, AMD_HSMP);
static struct hsmp_plat_device hsmp_pdev;
/*
* 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);
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_VERSION(DRIVER_VERSION);
MODULE_LICENSE("GPL");

View File

@ -55,8 +55,6 @@ struct hsmp_plat_device {
bool is_probed;
};
extern struct hsmp_plat_device hsmp_pdev;
int hsmp_cache_proto_ver(u16 sock_ind);
int hsmp_test(u16 sock_ind, u32 value);
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_get_tbl_dram_base(u16 sock_ind);
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 */

View File

@ -37,6 +37,8 @@
#define HSMP_INDEX_REG 0xc4
#define HSMP_DATA_REG 0xc8
static struct hsmp_plat_device *hsmp_pdev;
static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset,
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;
sock_ind = (uintptr_t)bin_attr->private;
if (sock_ind >= hsmp_pdev.num_sockets)
if (sock_ind >= hsmp_pdev->num_sockets)
return -EINVAL;
sock = &hsmp_pdev.sock[sock_ind];
sock = &hsmp_pdev->sock[sock_ind];
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;
if (id == 0 && sock_ind >= hsmp_pdev.num_sockets)
if (id == 0 && sock_ind >= hsmp_pdev->num_sockets)
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 0;
@ -156,10 +158,10 @@ static int init_platform_device(struct device *dev)
struct hsmp_socket *sock;
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))
return -ENODEV;
sock = &hsmp_pdev.sock[i];
sock = &hsmp_pdev->sock[i];
sock->root = node_to_amd_nb(i)->root;
sock->sock_ind = i;
sock->dev = dev;
@ -194,7 +196,7 @@ static int init_platform_device(struct device *dev)
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);
if (ret)
dev_err(dev, "Failed to init metric table\n");
@ -208,10 +210,10 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev)
{
int ret;
hsmp_pdev.sock = devm_kcalloc(&pdev->dev, hsmp_pdev.num_sockets,
sizeof(*hsmp_pdev.sock),
GFP_KERNEL);
if (!hsmp_pdev.sock)
hsmp_pdev->sock = devm_kcalloc(&pdev->dev, hsmp_pdev->num_sockets,
sizeof(*hsmp_pdev->sock),
GFP_KERNEL);
if (!hsmp_pdev->sock)
return -ENOMEM;
ret = init_platform_device(&pdev->dev);
@ -298,12 +300,16 @@ static int __init hsmp_plt_init(void)
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
* if we have N SMN/DF interfaces that ideally means N sockets
*/
hsmp_pdev.num_sockets = amd_nb_num();
if (hsmp_pdev.num_sockets == 0 || hsmp_pdev.num_sockets > MAX_AMD_SOCKETS)
hsmp_pdev->num_sockets = amd_nb_num();
if (hsmp_pdev->num_sockets == 0 || hsmp_pdev->num_sockets > MAX_AMD_SOCKETS)
return ret;
ret = platform_driver_register(&amd_hsmp_driver);