Skip to content

Commit 2a727f6

Browse files
arndbbjorn-helgaas
authored andcommitted
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>
1 parent 25bd879 commit 2a727f6

3 files changed

Lines changed: 14 additions & 36 deletions

File tree

‎drivers/pci/hotplug/ibmphp.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ int ibmphp_add_pfmem_from_mem(struct resource_node *);
378378
struct bus_node *ibmphp_find_res_bus(u8);
379379
void ibmphp_print_test(void); /* for debugging purposes */
380380

381-
void ibmphp_hpc_initvars(void);
382381
int ibmphp_hpc_readslot(struct slot *, u8, u8 *);
383382
int ibmphp_hpc_writeslot(struct slot *, u8);
384383
void ibmphp_lock_operations(void);

‎drivers/pci/hotplug/ibmphp_core.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,6 @@ static int __init ibmphp_init(void)
12771277

12781278
ibmphp_debug = debug;
12791279

1280-
ibmphp_hpc_initvars();
1281-
12821280
for (i = 0; i < 16; i++)
12831281
irqs[i] = 0;
12841282

‎drivers/pci/hotplug/ibmphp_hpc.c‎

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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 @@ static int to_debug = 0;
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
@@ -109,23 +109,6 @@ static int hpc_wait_ctlr_notworking(int, struct controller *, void __iomem *, u8
109109
//----------------------------------------------------------------------------
110110

111111

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-
}
128-
129112
/*----------------------------------------------------------------------
130113
* Name: i2c_ctrl_read
131114
*
@@ -780,7 +763,7 @@ void free_hpc_access(void)
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 @@ void ibmphp_lock_operations(void)
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 @@ static int poll_hpc(void *data)
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 @@ static int poll_hpc(void *data)
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 @@ static int poll_hpc(void *data)
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,18 +1043,16 @@ void __exit ibmphp_hpc_stop_poll_thread(void)
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");
10691052
free_hpc_access();
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
}

0 commit comments

Comments
 (0)