4747#define HSMP_INDEX_REG 0xc4
4848#define HSMP_DATA_REG 0xc8
4949
50- static struct semaphore * hsmp_sem ;
50+ #define HSMP_CDEV_NAME "hsmp_cdev"
51+ #define HSMP_DEVNODE_NAME "hsmp"
5152
52- static struct miscdevice hsmp_device ;
53+ struct hsmp_socket {
54+ struct semaphore hsmp_sem ;
55+ u16 sock_ind ;
56+ };
57+
58+ struct hsmp_plat_device {
59+ struct miscdevice hsmp_device ;
60+ struct hsmp_socket * sock ;
61+ struct device * dev ;
62+ u16 num_sockets ;
63+ };
64+
65+ static struct hsmp_plat_device plat_dev ;
5366
5467static int amd_hsmp_rdwr (struct pci_dev * root , u32 address ,
5568 u32 * value , bool write )
@@ -188,6 +201,7 @@ static int validate_message(struct hsmp_message *msg)
188201
189202int hsmp_send_message (struct hsmp_message * msg )
190203{
204+ struct hsmp_socket * sock = & plat_dev .sock [msg -> sock_ind ];
191205 struct amd_northbridge * nb ;
192206 int ret ;
193207
@@ -208,14 +222,13 @@ int hsmp_send_message(struct hsmp_message *msg)
208222 * In SMP system timeout of 100 millisecs should
209223 * be enough for the previous thread to finish the operation
210224 */
211- ret = down_timeout (& hsmp_sem [msg -> sock_ind ],
212- msecs_to_jiffies (HSMP_MSG_TIMEOUT ));
225+ ret = down_timeout (& sock -> hsmp_sem , msecs_to_jiffies (HSMP_MSG_TIMEOUT ));
213226 if (ret < 0 )
214227 return ret ;
215228
216229 ret = __hsmp_send_message (nb -> root , msg );
217230
218- up (& hsmp_sem [ msg -> sock_ind ] );
231+ up (& sock -> hsmp_sem );
219232
220233 return ret ;
221234}
@@ -321,28 +334,31 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev)
321334{
322335 int i ;
323336
324- hsmp_sem = devm_kzalloc (& pdev -> dev ,
325- ( amd_nb_num () * sizeof (struct semaphore )),
326- GFP_KERNEL );
327- if (!hsmp_sem )
337+ plat_dev . sock = devm_kzalloc (& pdev -> dev ,
338+ ( plat_dev . num_sockets * sizeof (struct hsmp_socket )),
339+ GFP_KERNEL );
340+ if (!plat_dev . sock )
328341 return - ENOMEM ;
342+ plat_dev .dev = & pdev -> dev ;
329343
330- for (i = 0 ; i < amd_nb_num (); i ++ )
331- sema_init (& hsmp_sem [i ], 1 );
344+ for (i = 0 ; i < plat_dev .num_sockets ; i ++ ) {
345+ sema_init (& plat_dev .sock [i ].hsmp_sem , 1 );
346+ plat_dev .sock [i ].sock_ind = i ;
347+ }
332348
333- hsmp_device .name = "hsmp_cdev" ;
334- hsmp_device .minor = MISC_DYNAMIC_MINOR ;
335- hsmp_device .fops = & hsmp_fops ;
336- hsmp_device .parent = & pdev -> dev ;
337- hsmp_device .nodename = "hsmp" ;
338- hsmp_device .mode = 0644 ;
349+ plat_dev . hsmp_device .name = HSMP_CDEV_NAME ;
350+ plat_dev . hsmp_device .minor = MISC_DYNAMIC_MINOR ;
351+ plat_dev . hsmp_device .fops = & hsmp_fops ;
352+ plat_dev . hsmp_device .parent = & pdev -> dev ;
353+ plat_dev . hsmp_device .nodename = HSMP_DEVNODE_NAME ;
354+ plat_dev . hsmp_device .mode = 0644 ;
339355
340- return misc_register (& hsmp_device );
356+ return misc_register (& plat_dev . hsmp_device );
341357}
342358
343359static void hsmp_pltdrv_remove (struct platform_device * pdev )
344360{
345- misc_deregister (& hsmp_device );
361+ misc_deregister (& plat_dev . hsmp_device );
346362}
347363
348364static struct platform_driver amd_hsmp_driver = {
@@ -358,7 +374,6 @@ static struct platform_device *amd_hsmp_platdev;
358374static int __init hsmp_plt_init (void )
359375{
360376 int ret = - ENODEV ;
361- u16 num_sockets ;
362377 int i ;
363378
364379 if (boot_cpu_data .x86_vendor != X86_VENDOR_AMD || boot_cpu_data .x86 < 0x19 ) {
@@ -371,12 +386,12 @@ static int __init hsmp_plt_init(void)
371386 * amd_nb_num() returns number of SMN/DF interfaces present in the system
372387 * if we have N SMN/DF interfaces that ideally means N sockets
373388 */
374- num_sockets = amd_nb_num ();
375- if (num_sockets == 0 )
389+ plat_dev . num_sockets = amd_nb_num ();
390+ if (plat_dev . num_sockets == 0 )
376391 return ret ;
377392
378393 /* Test the hsmp interface on each socket */
379- for (i = 0 ; i < num_sockets ; i ++ ) {
394+ for (i = 0 ; i < plat_dev . num_sockets ; i ++ ) {
380395 ret = hsmp_test (i , 0xDEADBEEF );
381396 if (ret ) {
382397 pr_err ("HSMP is not supported on Fam:%x model:%x\n" ,
0 commit comments