hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/pci/hotplug/ibmphp_hpc.c
....@@ -15,13 +15,13 @@
1515
1616 #include <linux/wait.h>
1717 #include <linux/time.h>
18
+#include <linux/completion.h>
1819 #include <linux/delay.h>
1920 #include <linux/module.h>
2021 #include <linux/pci.h>
2122 #include <linux/init.h>
2223 #include <linux/mutex.h>
2324 #include <linux/sched.h>
24
-#include <linux/semaphore.h>
2525 #include <linux/kthread.h>
2626 #include "ibmphp.h"
2727
....@@ -88,10 +88,10 @@
8888 //----------------------------------------------------------------------------
8989 // global variables
9090 //----------------------------------------------------------------------------
91
-static struct mutex sem_hpcaccess; // lock access to HPC
92
-static struct semaphore semOperations; // lock all operations and
91
+static DEFINE_MUTEX(sem_hpcaccess); // lock access to HPC
92
+static DEFINE_MUTEX(operations_mutex); // lock all operations and
9393 // access to data structures
94
-static struct semaphore sem_exit; // make sure polling thread goes away
94
+static DECLARE_COMPLETION(exit_complete); // make sure polling thread goes away
9595 static struct task_struct *ibmphp_poll_thread;
9696 //----------------------------------------------------------------------------
9797 // local function prototypes
....@@ -108,23 +108,6 @@
108108 static int hpc_wait_ctlr_notworking(int, struct controller *, void __iomem *, u8 *);
109109 //----------------------------------------------------------------------------
110110
111
-
112
-/*----------------------------------------------------------------------
113
-* Name: ibmphp_hpc_initvars
114
-*
115
-* Action: initialize semaphores and variables
116
-*---------------------------------------------------------------------*/
117
-void __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
-}
128111
129112 /*----------------------------------------------------------------------
130113 * Name: i2c_ctrl_read
....@@ -780,7 +763,7 @@
780763 *---------------------------------------------------------------------*/
781764 void ibmphp_lock_operations(void)
782765 {
783
- down(&semOperations);
766
+ mutex_lock(&operations_mutex);
784767 to_debug = 1;
785768 }
786769
....@@ -790,7 +773,7 @@
790773 void ibmphp_unlock_operations(void)
791774 {
792775 debug("%s - Entry\n", __func__);
793
- up(&semOperations);
776
+ mutex_unlock(&operations_mutex);
794777 to_debug = 0;
795778 debug("%s - Exit\n", __func__);
796779 }
....@@ -816,7 +799,7 @@
816799
817800 while (!kthread_should_stop()) {
818801 /* try to get the lock to do some kind of hardware access */
819
- down(&semOperations);
802
+ mutex_lock(&operations_mutex);
820803
821804 switch (poll_state) {
822805 case POLL_LATCH_REGISTER:
....@@ -871,13 +854,13 @@
871854 break;
872855 case POLL_SLEEP:
873856 /* don't sleep with a lock on the hardware */
874
- up(&semOperations);
857
+ mutex_unlock(&operations_mutex);
875858 msleep(POLL_INTERVAL_SEC * 1000);
876859
877860 if (kthread_should_stop())
878861 goto out_sleep;
879862
880
- down(&semOperations);
863
+ mutex_lock(&operations_mutex);
881864
882865 if (poll_count >= POLL_LATCH_CNT) {
883866 poll_count = 0;
....@@ -887,12 +870,12 @@
887870 break;
888871 }
889872 /* give up the hardware semaphore */
890
- up(&semOperations);
873
+ mutex_unlock(&operations_mutex);
891874 /* sleep for a short time just for good measure */
892875 out_sleep:
893876 msleep(100);
894877 }
895
- up(&sem_exit);
878
+ complete(&exit_complete);
896879 debug("%s - Exit\n", __func__);
897880 return 0;
898881 }
....@@ -1060,9 +1043,9 @@
10601043 debug("after locking operations\n");
10611044
10621045 // wait for poll thread to exit
1063
- debug("before sem_exit down\n");
1064
- down(&sem_exit);
1065
- debug("after sem_exit down\n");
1046
+ debug("before exit_complete down\n");
1047
+ wait_for_completion(&exit_complete);
1048
+ debug("after exit_completion down\n");
10661049
10671050 // cleanup
10681051 debug("before free_hpc_access\n");
....@@ -1070,8 +1053,6 @@
10701053 debug("after free_hpc_access\n");
10711054 ibmphp_unlock_operations();
10721055 debug("after unlock operations\n");
1073
- up(&sem_exit);
1074
- debug("after sem exit up\n");
10751056
10761057 debug("%s - Exit\n", __func__);
10771058 }