platform/x86/amd/hsmp: create plat specific struct
Subsystems (4)
PATCH v2 1/4 platform/x86/amd/hsmp: create plat specific struct
From: Suma Hegde <[email protected]>
Having a separate platform device structure helps in future, to contain platform specific variables and other data.
---
Changes since v1:
1. defined HSMP_CDEV_NAME and HSMP_DEVNODE_NAME macros
drivers/platform/x86/amd/hsmp.c | 56 +++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 20 deletions(-)
drivers/platform/x86/amd/hsmp.c +36 -20
@@ -47,9 +47,23 @@#define HSMP_INDEX_REG 0xc4#define HSMP_DATA_REG 0xc8 -static struct semaphore *hsmp_sem; +#define HSMP_CDEV_NAME "hsmp_cdev" +#define HSMP_DEVNODE_NAME "hsmp" -static struct miscdevice hsmp_device; +struct hsmp_socket { +struct semaphore hsmp_sem; +u16 sock_ind; +}; + +struct hsmp_plat_device { +struct miscdevice hsmp_device; +struct hsmp_socket *sock; +struct device *dev; +}; + +static u16 num_sockets; + +static struct hsmp_plat_device plat_dev;static int amd_hsmp_rdwr (struct pci_dev *root,u32 address,u32 *value,bool write)
@@ -188,6 +202,7 @@ static int validate_message(struct hsmp_message *msg)int hsmp_send_message (struct hsmp_message *msg) { +struct hsmp_socket *sock = &plat_dev.sock[msg->sock_ind];struct amd_northbridge *nb;int ret;
@@ -208,14 +223,13 @@ int hsmp_send_message(struct hsmp_message *msg)* In SMP system timeout of 100 millisecs should * be enough for the previous thread to finish the operation */ - ret =down_timeout (&hsmp_sem[msg->sock_ind], -msecs_to_jiffies (HSMP_MSG_TIMEOUT )); + ret =down_timeout (&sock->hsmp_sem,msecs_to_jiffies (HSMP_MSG_TIMEOUT ));if (ret <0 )return ret; ret =__hsmp_send_message (nb->root, msg); -up (&hsmp_sem[msg->sock_ind]); +up (&sock->hsmp_sem);return ret; }
@@ -321,28 +335,31 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev) {int i; - hsmp_sem =devm_kzalloc (&pdev->dev, - (amd_nb_num () *sizeof (struct semaphore )), -GFP_KERNEL ); -if (!hsmp_sem) + plat_dev.sock =devm_kzalloc (&pdev->dev, + (num_sockets *sizeof (struct hsmp_socket )), +GFP_KERNEL ); +if (!plat_dev.sock)return -ENOMEM ; + plat_dev.dev = &pdev->dev; -for (i =0 ; i <amd_nb_num (); i++) -sema_init (&hsmp_sem[i],1 ); +for (i =0 ; i < num_sockets; i++) { +sema_init (&plat_dev.sock[i].hsmp_sem,1 ); + plat_dev.sock[i].sock_ind = i; + } - hsmp_device.name ="hsmp_cdev" ; - hsmp_device.minor =MISC_DYNAMIC_MINOR ; - hsmp_device.fops = &hsmp_fops; - hsmp_device.parent = &pdev->dev; - hsmp_device.nodename ="hsmp" ; - hsmp_device.mode =0644 ; + plat_dev.hsmp_device.name =HSMP_CDEV_NAME ; + plat_dev.hsmp_device.minor =MISC_DYNAMIC_MINOR ; + plat_dev.hsmp_device.fops = &hsmp_fops; + plat_dev.hsmp_device.parent = &pdev->dev; + plat_dev.hsmp_device.nodename =HSMP_DEVNODE_NAME ; + plat_dev.hsmp_device.mode =0644 ; -return misc_register (&hsmp_device); +return misc_register (&plat_dev.hsmp_device); }static void hsmp_pltdrv_remove (struct platform_device *pdev) { -misc_deregister (&hsmp_device); +misc_deregister (&plat_dev.hsmp_device); }static struct platform_driver amd_hsmp_driver = {
@@ -358,7 +375,6 @@ static struct platform_device *amd_hsmp_platdev;static int __init hsmp_plt_init (void ) {int ret = -ENODEV ; -u16 num_sockets;int i;if (boot_cpu_data.x86_vendor !=X86_VENDOR_AMD || boot_cpu_data.x86 <0x19 ) {
Signature · 1 line
2.25.1
PATCH v2 2/4 platform/x86/amd/hsmp: add support for metrics tbl
From: Suma Hegde <[email protected]>
AMD MI300 MCM provides GET_METRICS_TABLE message to retrieve all the system management information from SMU.
The metrics table is made available as hexadecimal sysfs binary file under per socket sysfs directory created at /sys/devices/platform/amd_hsmp/socket%d/metrics_bin
Metrics table definitions will be documented as part of Public PPR. The same is defined in the amd_hsmp.h header.
---
Changes since v1:
1. Remove HSMP_DEVNODE_NAME and HSMP_CDEV_NAME macro definitions in this patch
2. Remove extra space in comments for HSMP_GET_METRIC_TABLE_VER, HSMP_GET_METRIC_TABLE and HSMP_GET_METRIC_TABLE_DRAM_ADDR enum definition in amd_hsmp.h files
3. Change check, count == 0 to !count in hsmp_metric_tbl_read() function
4. Add hsmp_metric_table_visible() function
5. hsmp_create_metric_tbl_sysfs_file() is renamed as hsmp_init_metric_tbl_bin_attr() and code is also modified slightly
6. Modify hsmp_create_sysfs_file() to use devm_device_add_groups()
7. Change from cleanup label to deregister label
8. Add dev_err print in hsmp_get_tbl_dram_base()
9. Reword "Unable to Failed" in hsmp_get_tbl_dram_base()
10. Add HSMP_GRP_NAME_SIZE and NUM_ATTRS macros
11. Remove sysfs cleanup code in hsmp_pltdrv_remove()
12. Correct ATRR typo error
13. Change sprintf to snprintf
14. Check metrics table support only against HSMP_PROTO_VER6
arch/x86/include/uapi/asm/amd_hsmp.h | 109 ++++++++++++++++ drivers/platform/x86/amd/hsmp.c | 180 ++++++++++++++++++++++++++- 2 files changed, 286 insertions(+), 3 deletions(-)
arch/x86/include/uapi/asm/amd_hsmp.h +109 -0
@@ -47,6 +47,9 @@ enum hsmp_message_ids {HSMP_SET_PCI_RATE ,/* 20h Control link rate on PCIe devices */ HSMP_SET_POWER_MODE ,/* 21h Select power efficiency profile policy */ HSMP_SET_PSTATE_MAX_MIN ,/* 22h Set the max and min DF P-State */ +HSMP_GET_METRIC_TABLE_VER ,/* 23h Get metrics table version */ +HSMP_GET_METRIC_TABLE ,/* 24h Get metrics table */ +HSMP_GET_METRIC_TABLE_DRAM_ADDR ,/* 25h Get metrics table dram address */ HSMP_MSG_ID_MAX, };
@@ -64,6 +67,14 @@ enum hsmp_msg_type { HSMP_GET = 1, }; +enum hsmp_proto_versions { +HSMP_PROTO_VER2 =2 , +HSMP_PROTO_VER3 , +HSMP_PROTO_VER4 , +HSMP_PROTO_VER5 , +HSMP_PROTO_VER6 +}; +struct hsmp_msg_desc {int num_args;int response_sz;
@@ -295,6 +306,104 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table[] = {* input: args[0] = min df pstate[15:8] + max df pstate[7:0] */ {1, 0, HSMP_SET}, + +/* +* HSMP_GET_METRIC_TABLE_VER, num_args = 0, response_sz = 1 +* output: args[0] = metrics table version +*/ + {0, 1, HSMP_GET}, + +/* +* HSMP_GET_METRIC_TABLE, num_args = 0, response_sz = 0 +*/ + {0, 0, HSMP_GET}, + +/* +* HSMP_GET_METRIC_TABLE_DRAM_ADDR, num_args = 0, response_sz = 2 +* output: args[0] = lower 32 bits of the address +* output: args[1] = upper 32 bits of the address +*/ + {0, 2, HSMP_GET}, +}; + +/* Metrics table for EPYC socket(supported only from proto version 6) */ +struct hsmp_metric_table { +__u32 accumulation_counter; + +//TEMPERATURE +__u32 max_socket_temperature; +__u32 max_vr_temperature; +__u32 max_hbm_temperature; +__u64 max_socket_temperature_acc; +__u64 max_vr_temperature_acc; +__u64 max_hbm_temperature_acc; + +//POWER +__u32 socket_power_limit; +__u32 max_socket_power_limit; +__u32 socket_power; + +//ENERGY +__u64 timestamp; +__u64 socket_energy_acc; +__u64 ccd_energy_acc; +__u64 xcd_energy_acc; +__u64 aid_energy_acc; +__u64 hbm_energy_acc; + +//FREQUENCY +__u32 cclk_frequency_limit; +__u32 gfxclk_frequency_limit; +__u32 fclk_frequency; +__u32 uclk_frequency; +__u32 socclk_frequency[4 ]; +__u32 vclk_frequency[4 ]; +__u32 dclk_frequency[4 ]; +__u32 lclk_frequency[4 ]; +__u64 gfxclk_frequency_acc[8 ]; +__u64 cclk_frequency_acc[96 ]; + +//FREQUENCY RANGE +__u32 max_cclk_frequency; +__u32 min_cclk_frequency; +__u32 max_gfxclk_frequency; +__u32 min_gfxclk_frequency; +__u32 fclk_frequency_table[4 ]; +__u32 uclk_frequency_table[4 ]; +__u32 socclk_frequency_table[4 ]; +__u32 vclk_frequency_table[4 ]; +__u32 dclk_frequency_table[4 ]; +__u32 lclk_frequency_table[4 ]; +__u32 max_lclk_dpm_range; +__u32 min_lclk_dpm_range; + +//XGMI +__u32 xgmi_width; +__u32 xgmi_bitrate; +__u64 xgmi_read_bandwidth_acc[8 ]; +__u64 xgmi_write_bandwidth_acc[8 ]; + +//ACTIVITY +__u32 socket_c0_residency; +__u32 socket_gfx_busy; +__u32 dram_bandwidth_utilization; +__u64 socket_c0_residency_acc; +__u64 socket_gfx_busy_acc; +__u64 dram_bandwidth_acc; +__u32 max_dram_bandwidth; +__u64 dram_bandwidth_utilization_acc; +__u64 pcie_bandwidth_acc[4 ]; + +//THROTTLERS +__u32 prochot_residency_acc; +__u32 ppt_residency_acc; +__u32 socket_thm_residency_acc; +__u32 vr_thm_residency_acc; +__u32 hbm_thm_residency_acc; +__u32 spare; + +// New Items at end to maintain driver compatibility +__u32 gfxclk_frequency[8 ]; };/* Reset to default packing */
drivers/platform/x86/amd/hsmp.c +177 -3
212 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 3/4 platform/x86/amd/hsmp: improve the error log
In reply to Suma HegdeFrom: Suma Hegde <[email protected]>
1. Change print message during platform init to a more meaningful clear message.
2. Return the error code returned by hsmp_test() itself, rather then returning a common EOPNOTSUPP error.
---
Changes since v1:
1. New patch.
drivers/platform/x86/amd/hsmp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/x86/amd/hsmp.c +3 -3
@@ -569,10 +569,10 @@ static int __init hsmp_plt_init(void)for (i =0 ; i < num_sockets; i++) { ret =hsmp_test (i,0xDEADBEEF );if (ret) { -pr_err ("HSMP is not supported on Fam:%x model:%x\n" , +pr_err ("HSMP test message failed on Fam:%x model:%x\n" , boot_cpu_data.x86, boot_cpu_data.x86_model); -pr_err ("Or Is HSMP disabled in BIOS ?\n" ); -return -EOPNOTSUPP ; +pr_err ("Is HSMP disabled in BIOS ?\n" ); +return ret; } }
Signature · 1 line
2.25.1
PATCH v2 4/4 Documentation: Add amd_hsmp sysfs file info
In reply to Suma Hegdesysfs bin file is added for metrics table information
---
Changes since v1:
New patch
Documentation/arch/x86/amd_hsmp.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Documentation/arch/x86/amd_hsmp.rst +16 -0
@@ -41,6 +41,22 @@ In-kernel integration: * Locking across callers is taken care by the driver. +HSMP sysfs interface +==================== + +1. Metrics table bin sysfs + +AMD MI300A MCM provides GET_METRICS_TABLE message to retrieve +all the system management information from SMU. + +The metrics table is made available as hexadecimal sysfs binary file +under per socket sysfs directory created at +/sys/devices/platform/amd_hsmp/socket%d/metrics_bin + +Metrics table definitions will be documented as part of Public PPR. +The same is defined in the amd_hsmp.h header. + + An example ==========
Signature · 1 line
2.25.1
Re: [PATCH v2 4/4] Documentation: Add amd_hsmp sysfs file info
Hi Suma,
Quoted 4 lines · Suma Hegde
sysfs bin file is added for metrics table information
Signed-off-by Suma Hegde <[email protected]>Reviewed-by Naveen Krishna Chatradhi <[email protected]>
Please squash this patch into patch 2/4 (since this documents the metrics_bin sysfs attr added there).
Regards,
Hans
Quoted 34 lines
---
Changes since v1:
New patchDocumentation/arch/x86/amd_hsmp.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)Documentation/arch/x86/amd_hsmp.rst +16
-0@@ -41,6 +41,22 @@ In-kernel integration: * Locking across callers is taken care by the driver. +HSMP sysfs interface +==================== + +1. Metrics table bin sysfs + +AMD MI300A MCM provides GET_METRICS_TABLE message to retrieve +all the system management information from SMU. + +The metrics table is made available as hexadecimal sysfs binary file +under per socket sysfs directory created at +/sys/devices/platform/amd_hsmp/socket%d/metrics_bin + +Metrics table definitions will be documented as part of Public PPR. +The same is defined in the amd_hsmp.h header. + + An example ==========
Hi Suma,
Thank you for the patch.
Quoted 29 lines · Suma Hegde
From: Suma Hegde <[email protected]>
Having a separate platform device structure helps in future, to contain platform specific variables and other data.
Signed-off-by Suma Hegde <[email protected]>Reviewed-by Naveen Krishna Chatradhi <[email protected]>---
Changes since v1:
1. definedHSMP_CDEV_NAMEandHSMP_DEVNODE_NAMEmacrosdrivers/platform/x86/amd/hsmp.c | 56 +++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 20 deletions(-)drivers/platform/x86/amd/hsmp.c +4
-2@@ -47,9 +47,23 @@#define HSMP_INDEX_REG 0xc4#define HSMP_DATA_REG 0xc8 -static struct semaphore *hsmp_sem; +#define HSMP_CDEV_NAME "hsmp_cdev" +#define HSMP_DEVNODE_NAME "hsmp" -static struct miscdevice hsmp_device; +struct hsmp_socket { +struct semaphore hsmp_sem;
drivers/platform/x86/amd/hsmp.c line 64
Quoted 10 lines
drivers/platform/x86/amd/hsmp.c +10
-0+u16 sock_ind; +}; + +struct hsmp_plat_device { +struct miscdevice hsmp_device; +struct hsmp_socket *sock; +struct device *dev; +}; + +static u16 num_sockets;
Overall this patch looks good to me, but since num_sockets indicates the size of the plat_dev.sock array, num_sockets should IMHO itself also be part of struct hsmp_plat_device.
(and all usages of "num_sockets" should then be replaced by "plat_dev.num_sockets")
Other then that this looks good to me.
Regards,
Hans
Quoted 84 lines
drivers/platform/x86/amd/hsmp.c +22
-18+ +static struct hsmp_plat_device plat_dev;static int amd_hsmp_rdwr (struct pci_dev *root,u32 address,u32 *value,bool write)@@ -188,6 +202,7 @@ static int validate_message(struct hsmp_message *msg)int hsmp_send_message (struct hsmp_message *msg) { +struct hsmp_socket *sock = &plat_dev.sock[msg->sock_ind];struct amd_northbridge *nb;int ret;@@ -208,14 +223,13 @@ int hsmp_send_message(struct hsmp_message *msg)* In SMP system timeout of 100 millisecs should * be enough for the previous thread to finish the operation */ - ret =down_timeout (&hsmp_sem[msg->sock_ind], -msecs_to_jiffies (HSMP_MSG_TIMEOUT )); + ret =down_timeout (&sock->hsmp_sem,msecs_to_jiffies (HSMP_MSG_TIMEOUT ));if (ret <0 )return ret; ret =__hsmp_send_message (nb->root, msg); -up (&hsmp_sem[msg->sock_ind]); +up (&sock->hsmp_sem);return ret; }@@ -321,28 +335,31 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev) {int i; - hsmp_sem =devm_kzalloc (&pdev->dev, - (amd_nb_num () *sizeof (struct semaphore )), -GFP_KERNEL ); -if (!hsmp_sem) + plat_dev.sock =devm_kzalloc (&pdev->dev, + (num_sockets *sizeof (struct hsmp_socket )), +GFP_KERNEL ); +if (!plat_dev.sock)return -ENOMEM ; + plat_dev.dev = &pdev->dev; -for (i =0 ; i <amd_nb_num (); i++) -sema_init (&hsmp_sem[i],1 ); +for (i =0 ; i < num_sockets; i++) { +sema_init (&plat_dev.sock[i].hsmp_sem,1 ); + plat_dev.sock[i].sock_ind = i; + } - hsmp_device.name ="hsmp_cdev" ; - hsmp_device.minor =MISC_DYNAMIC_MINOR ; - hsmp_device.fops = &hsmp_fops; - hsmp_device.parent = &pdev->dev; - hsmp_device.nodename ="hsmp" ; - hsmp_device.mode =0644 ; + plat_dev.hsmp_device.name =HSMP_CDEV_NAME ; + plat_dev.hsmp_device.minor =MISC_DYNAMIC_MINOR ; + plat_dev.hsmp_device.fops = &hsmp_fops; + plat_dev.hsmp_device.parent = &pdev->dev; + plat_dev.hsmp_device.nodename =HSMP_DEVNODE_NAME ; + plat_dev.hsmp_device.mode =0644 ; -return misc_register (&hsmp_device); +return misc_register (&plat_dev.hsmp_device); }static void hsmp_pltdrv_remove (struct platform_device *pdev) { -misc_deregister (&hsmp_device); +misc_deregister (&plat_dev.hsmp_device); }static struct platform_driver amd_hsmp_driver = {@@ -358,7 +375,6 @@ static struct platform_device *amd_hsmp_platdev;static int __init hsmp_plt_init (void ) {int ret = -ENODEV ; -u16 num_sockets;int i;if (boot_cpu_data.x86_vendor !=X86_VENDOR_AMD || boot_cpu_data.x86 <0x19 ) {
Hi Hans de,
Thank you for your review. I will wait till Monday and respin v3 patches addressing your feedback.
Thanks and Regards,
Suma
Quoted 149 lines · Hans de Goede
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Hi Suma,
Thank you for the patch.
Quoted 29 lines · Suma Hegde
From: Suma Hegde <[email protected]>
Having a separate platform device structure helps in future, to contain platform specific variables and other data.
Signed-off-by Suma Hegde <[email protected]>Reviewed-by Naveen Krishna Chatradhi <[email protected]>---
Changes since v1:
1. definedHSMP_CDEV_NAMEandHSMP_DEVNODE_NAMEmacrosdrivers/platform/x86/amd/hsmp.c | 56 +++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 20 deletions(-)drivers/platform/x86/amd/hsmp.c +4
-2@@ -47,9 +47,23 @@#define HSMP_INDEX_REG 0xc4#define HSMP_DATA_REG 0xc8 -static struct semaphore *hsmp_sem; +#define HSMP_CDEV_NAME "hsmp_cdev" +#define HSMP_DEVNODE_NAME "hsmp" -static struct miscdevice hsmp_device; +struct hsmp_socket { +struct semaphore hsmp_sem;drivers/platform/x86/amd/hsmp.c line 64
Quoted 10 lines
drivers/platform/x86/amd/hsmp.c +10
-0+u16 sock_ind; +}; + +struct hsmp_plat_device { +struct miscdevice hsmp_device; +struct hsmp_socket *sock; +struct device *dev; +}; + +static u16 num_sockets;Overall this patch looks good to me, but since
num_socketsindicates the size of the plat_dev.sock array,num_socketsshould IMHO itself also be part of structhsmp_plat_device.(and all usages of "
num_sockets" should then be replaced by "plat_dev.num_sockets")Other then that this looks good to me.
Regards,
Hans
Quoted 84 lines
drivers/platform/x86/amd/hsmp.c +22
-18+ +static struct hsmp_plat_device plat_dev;static int amd_hsmp_rdwr (struct pci_dev *root,u32 address,u32 *value,bool write)@@ -188,6 +202,7 @@ static int validate_message(struct hsmp_message *msg)int hsmp_send_message (struct hsmp_message *msg) { +struct hsmp_socket *sock = &plat_dev.sock[msg->sock_ind];struct amd_northbridge *nb;int ret;@@ -208,14 +223,13 @@ int hsmp_send_message(struct hsmp_message *msg)* In SMP system timeout of 100 millisecs should * be enough for the previous thread to finish the operation */ - ret =down_timeout (&hsmp_sem[msg->sock_ind], -msecs_to_jiffies (HSMP_MSG_TIMEOUT )); + ret =down_timeout (&sock->hsmp_sem,msecs_to_jiffies (HSMP_MSG_TIMEOUT ));if (ret <0 )return ret; ret =__hsmp_send_message (nb->root, msg); -up (&hsmp_sem[msg->sock_ind]); +up (&sock->hsmp_sem);return ret; }@@ -321,28 +335,31 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev) {int i; - hsmp_sem =devm_kzalloc (&pdev->dev, - (amd_nb_num () *sizeof (struct semaphore )), -GFP_KERNEL ); -if (!hsmp_sem) + plat_dev.sock =devm_kzalloc (&pdev->dev, + (num_sockets *sizeof (struct hsmp_socket )), +GFP_KERNEL ); +if (!plat_dev.sock)return -ENOMEM ; + plat_dev.dev = &pdev->dev; -for (i =0 ; i <amd_nb_num (); i++) -sema_init (&hsmp_sem[i],1 ); +for (i =0 ; i < num_sockets; i++) { +sema_init (&plat_dev.sock[i].hsmp_sem,1 ); + plat_dev.sock[i].sock_ind = i; + } - hsmp_device.name ="hsmp_cdev" ; - hsmp_device.minor =MISC_DYNAMIC_MINOR ; - hsmp_device.fops = &hsmp_fops; - hsmp_device.parent = &pdev->dev; - hsmp_device.nodename ="hsmp" ; - hsmp_device.mode =0644 ; + plat_dev.hsmp_device.name =HSMP_CDEV_NAME ; + plat_dev.hsmp_device.minor =MISC_DYNAMIC_MINOR ; + plat_dev.hsmp_device.fops = &hsmp_fops; + plat_dev.hsmp_device.parent = &pdev->dev; + plat_dev.hsmp_device.nodename =HSMP_DEVNODE_NAME ; + plat_dev.hsmp_device.mode =0644 ; -return misc_register (&hsmp_device); +return misc_register (&plat_dev.hsmp_device); }static void hsmp_pltdrv_remove (struct platform_device *pdev) { -misc_deregister (&hsmp_device); +misc_deregister (&plat_dev.hsmp_device); }static struct platform_driver amd_hsmp_driver = {@@ -358,7 +375,6 @@ static struct platform_device *amd_hsmp_platdev;static int __init hsmp_plt_init (void ) {int ret = -ENODEV ; -u16 num_sockets;int i;if (boot_cpu_data.x86_vendor !=X86_VENDOR_AMD || boot_cpu_data.x86 <0x19 ) {
Hi Suma,
Thank you for the patch.
Quoted 29 lines · Suma Hegde
From: Suma Hegde <[email protected]>
Having a separate platform device structure helps in future, to contain platform specific variables and other data.
Signed-off-by Suma Hegde <[email protected]>Reviewed-by Naveen Krishna Chatradhi <[email protected]>---
Changes since v1:
1. definedHSMP_CDEV_NAMEandHSMP_DEVNODE_NAMEmacrosdrivers/platform/x86/amd/hsmp.c | 56 +++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 20 deletions(-)drivers/platform/x86/amd/hsmp.c +4
-2@@ -47,9 +47,23 @@#define HSMP_INDEX_REG 0xc4#define HSMP_DATA_REG 0xc8 -static struct semaphore *hsmp_sem; +#define HSMP_CDEV_NAME "hsmp_cdev" +#define HSMP_DEVNODE_NAME "hsmp" -static struct miscdevice hsmp_device; +struct hsmp_socket { +struct semaphore hsmp_sem;
drivers/platform/x86/amd/hsmp.c line 64
Quoted 10 lines
drivers/platform/x86/amd/hsmp.c +10
-0+u16 sock_ind; +}; + +struct hsmp_plat_device { +struct miscdevice hsmp_device; +struct hsmp_socket *sock; +struct device *dev; +}; + +static u16 num_sockets;
Overall this patch looks good to me, but since num_sockets indicates the size of the plat_dev.sock array, num_sockets should IMHO itself also be part of struct hsmp_plat_device.
(and all usages of "num_sockets" should then be replaced by "plat_dev.num_sockets")
Other then that this looks good to me.
Regards,
Hans
Quoted 84 lines
drivers/platform/x86/amd/hsmp.c +22
-18+ +static struct hsmp_plat_device plat_dev;static int amd_hsmp_rdwr (struct pci_dev *root,u32 address,u32 *value,bool write)@@ -188,6 +202,7 @@ static int validate_message(struct hsmp_message *msg)int hsmp_send_message (struct hsmp_message *msg) { +struct hsmp_socket *sock = &plat_dev.sock[msg->sock_ind];struct amd_northbridge *nb;int ret;@@ -208,14 +223,13 @@ int hsmp_send_message(struct hsmp_message *msg)* In SMP system timeout of 100 millisecs should * be enough for the previous thread to finish the operation */ - ret =down_timeout (&hsmp_sem[msg->sock_ind], -msecs_to_jiffies (HSMP_MSG_TIMEOUT )); + ret =down_timeout (&sock->hsmp_sem,msecs_to_jiffies (HSMP_MSG_TIMEOUT ));if (ret <0 )return ret; ret =__hsmp_send_message (nb->root, msg); -up (&hsmp_sem[msg->sock_ind]); +up (&sock->hsmp_sem);return ret; }@@ -321,28 +335,31 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev) {int i; - hsmp_sem =devm_kzalloc (&pdev->dev, - (amd_nb_num () *sizeof (struct semaphore )), -GFP_KERNEL ); -if (!hsmp_sem) + plat_dev.sock =devm_kzalloc (&pdev->dev, + (num_sockets *sizeof (struct hsmp_socket )), +GFP_KERNEL ); +if (!plat_dev.sock)return -ENOMEM ; + plat_dev.dev = &pdev->dev; -for (i =0 ; i <amd_nb_num (); i++) -sema_init (&hsmp_sem[i],1 ); +for (i =0 ; i < num_sockets; i++) { +sema_init (&plat_dev.sock[i].hsmp_sem,1 ); + plat_dev.sock[i].sock_ind = i; + } - hsmp_device.name ="hsmp_cdev" ; - hsmp_device.minor =MISC_DYNAMIC_MINOR ; - hsmp_device.fops = &hsmp_fops; - hsmp_device.parent = &pdev->dev; - hsmp_device.nodename ="hsmp" ; - hsmp_device.mode =0644 ; + plat_dev.hsmp_device.name =HSMP_CDEV_NAME ; + plat_dev.hsmp_device.minor =MISC_DYNAMIC_MINOR ; + plat_dev.hsmp_device.fops = &hsmp_fops; + plat_dev.hsmp_device.parent = &pdev->dev; + plat_dev.hsmp_device.nodename =HSMP_DEVNODE_NAME ; + plat_dev.hsmp_device.mode =0644 ; -return misc_register (&hsmp_device); +return misc_register (&plat_dev.hsmp_device); }static void hsmp_pltdrv_remove (struct platform_device *pdev) { -misc_deregister (&hsmp_device); +misc_deregister (&plat_dev.hsmp_device); }static struct platform_driver amd_hsmp_driver = {@@ -358,7 +375,6 @@ static struct platform_device *amd_hsmp_platdev;static int __init hsmp_plt_init (void ) {int ret = -ENODEV ; -u16 num_sockets;int i;if (boot_cpu_data.x86_vendor !=X86_VENDOR_AMD || boot_cpu_data.x86 <0x19 ) {