aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/hotplug/ibmphp_hpc.c
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2018-12-10 16:49:10 -0500
committerBjorn Helgaas <bhelgaas@google.com>2019-01-29 18:15:36 -0500
commit2a727f6091372231281efaa8a5f56ee79509fd83 (patch)
tree8b4b8cf9043cb82cb0b1363d676d4d45708be7a8 /drivers/pci/hotplug/ibmphp_hpc.c
parent25bd879ec16ad3b83a5b1c3f16faa55e696bfccb (diff)
PCI: ibmphp: Turn semaphores into completions or mutexes
The sem_exit variable is conceptually a completion, so it should be called that. Similarly, the semOperations semaphore is a simple mutex, and can be changed into that, respectively. With both converted, the ibmphp_hpc_initvars() function is no longer used and can be removed. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/hotplug/ibmphp_hpc.c')
-rw-r--r--drivers/pci/hotplug/ibmphp_hpc.c47
1 files changed, 14 insertions, 33 deletions
diff --git a/drivers/pci/hotplug/ibmphp_hpc.c b/drivers/pci/hotplug/ibmphp_hpc.c
index 752c384cbd4c..508a62a6b5f9 100644
--- a/drivers/pci/hotplug/ibmphp_hpc.c
+++ b/drivers/pci/hotplug/ibmphp_hpc.c
@@ -15,13 +15,13 @@
15 15
16#include <linux/wait.h> 16#include <linux/wait.h>
17#include <linux/time.h> 17#include <linux/time.h>
18#include <linux/completion.h>
18#include <linux/delay.h> 19#include <linux/delay.h>
19#include <linux/module.h> 20#include <linux/module.h>
20#include <linux/pci.h> 21#include <linux/pci.h>
21#include <linux/init.h> 22#include <linux/init.h>
22#include <linux/mutex.h> 23#include <linux/mutex.h>
23#include <linux/sched.h> 24#include <linux/sched.h>
24#include <linux/semaphore.h>
25#include <linux/kthread.h> 25#include <linux/kthread.h>
26#include "ibmphp.h" 26#include "ibmphp.h"
27 27
@@ -88,10 +88,10 @@ static int to_debug = 0;
88//---------------------------------------------------------------------------- 88//----------------------------------------------------------------------------
89// global variables 89// global variables
90//---------------------------------------------------------------------------- 90//----------------------------------------------------------------------------
91static struct mutex sem_hpcaccess; // lock access to HPC 91static DEFINE_MUTEX(sem_hpcaccess); // lock access to HPC
92static struct semaphore semOperations; // lock all operations and 92static DEFINE_MUTEX(operations_mutex); // lock all operations and
93 // access to data structures 93 // access to data structures
94static struct semaphore sem_exit; // make sure polling thread goes away 94static DECLARE_COMPLETION(exit_complete); // make sure polling thread goes away
95static struct task_struct *ibmphp_poll_thread; 95static struct task_struct *ibmphp_poll_thread;
96//---------------------------------------------------------------------------- 96//----------------------------------------------------------------------------
97// local function prototypes 97// local function prototypes
@@ -110,23 +110,6 @@ static int hpc_wait_ctlr_notworking(int, struct controller *, void __iomem *, u8
110 110
111 111
112/*---------------------------------------------------------------------- 112/*----------------------------------------------------------------------
113* Name: ibmphp_hpc_initvars
114*
115* Action: initialize semaphores and variables
116*---------------------------------------------------------------------*/
117void __init ibmphp_hpc_initvars(void)
118{
119 debug("%s - Entry\n", __func__);
120
121 mutex_init(&sem_hpcaccess);
122 sema_init(&semOperations, 1);
123 sema_init(&sem_exit, 0);
124 to_debug = 0;
125
126 debug("%s - Exit\n", __func__);
127}
128
129/*----------------------------------------------------------------------
130* Name: i2c_ctrl_read 113* Name: i2c_ctrl_read
131* 114*
132* Action: read from HPC over I2C 115* Action: read from HPC over I2C
@@ -780,7 +763,7 @@ void free_hpc_access(void)
780*---------------------------------------------------------------------*/ 763*---------------------------------------------------------------------*/
781void ibmphp_lock_operations(void) 764void ibmphp_lock_operations(void)
782{ 765{
783 down(&semOperations); 766 mutex_lock(&operations_mutex);
784 to_debug = 1; 767 to_debug = 1;
785} 768}
786 769
@@ -790,7 +773,7 @@ void ibmphp_lock_operations(void)
790void ibmphp_unlock_operations(void) 773void ibmphp_unlock_operations(void)
791{ 774{
792 debug("%s - Entry\n", __func__); 775 debug("%s - Entry\n", __func__);
793 up(&semOperations); 776 mutex_unlock(&operations_mutex);
794 to_debug = 0; 777 to_debug = 0;
795 debug("%s - Exit\n", __func__); 778 debug("%s - Exit\n", __func__);
796} 779}
@@ -816,7 +799,7 @@ static int poll_hpc(void *data)
816 799
817 while (!kthread_should_stop()) { 800 while (!kthread_should_stop()) {
818 /* try to get the lock to do some kind of hardware access */ 801 /* try to get the lock to do some kind of hardware access */
819 down(&semOperations); 802 mutex_lock(&operations_mutex);
820 803
821 switch (poll_state) { 804 switch (poll_state) {
822 case POLL_LATCH_REGISTER: 805 case POLL_LATCH_REGISTER:
@@ -871,13 +854,13 @@ static int poll_hpc(void *data)
871 break; 854 break;
872 case POLL_SLEEP: 855 case POLL_SLEEP:
873 /* don't sleep with a lock on the hardware */ 856 /* don't sleep with a lock on the hardware */
874 up(&semOperations); 857 mutex_unlock(&operations_mutex);
875 msleep(POLL_INTERVAL_SEC * 1000); 858 msleep(POLL_INTERVAL_SEC * 1000);
876 859
877 if (kthread_should_stop()) 860 if (kthread_should_stop())
878 goto out_sleep; 861 goto out_sleep;
879 862
880 down(&semOperations); 863 mutex_lock(&operations_mutex);
881 864
882 if (poll_count >= POLL_LATCH_CNT) { 865 if (poll_count >= POLL_LATCH_CNT) {
883 poll_count = 0; 866 poll_count = 0;
@@ -887,12 +870,12 @@ static int poll_hpc(void *data)
887 break; 870 break;
888 } 871 }
889 /* give up the hardware semaphore */ 872 /* give up the hardware semaphore */
890 up(&semOperations); 873 mutex_unlock(&operations_mutex);
891 /* sleep for a short time just for good measure */ 874 /* sleep for a short time just for good measure */
892out_sleep: 875out_sleep:
893 msleep(100); 876 msleep(100);
894 } 877 }
895 up(&sem_exit); 878 complete(&exit_complete);
896 debug("%s - Exit\n", __func__); 879 debug("%s - Exit\n", __func__);
897 return 0; 880 return 0;
898} 881}
@@ -1060,9 +1043,9 @@ void __exit ibmphp_hpc_stop_poll_thread(void)
1060 debug("after locking operations\n"); 1043 debug("after locking operations\n");
1061 1044
1062 // wait for poll thread to exit 1045 // wait for poll thread to exit
1063 debug("before sem_exit down\n"); 1046 debug("before exit_complete down\n");
1064 down(&sem_exit); 1047 wait_for_completion(&exit_complete);
1065 debug("after sem_exit down\n"); 1048 debug("after exit_completion down\n");
1066 1049
1067 // cleanup 1050 // cleanup
1068 debug("before free_hpc_access\n"); 1051 debug("before free_hpc_access\n");
@@ -1070,8 +1053,6 @@ void __exit ibmphp_hpc_stop_poll_thread(void)
1070 debug("after free_hpc_access\n"); 1053 debug("after free_hpc_access\n");
1071 ibmphp_unlock_operations(); 1054 ibmphp_unlock_operations();
1072 debug("after unlock operations\n"); 1055 debug("after unlock operations\n");
1073 up(&sem_exit);
1074 debug("after sem exit up\n");
1075 1056
1076 debug("%s - Exit\n", __func__); 1057 debug("%s - Exit\n", __func__);
1077} 1058}