Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Arnd Bergmann and committed by
Bjorn Helgaas
2a727f60 25bd879e

+14 -36
-1
drivers/pci/hotplug/ibmphp.h
··· 378 378 struct bus_node *ibmphp_find_res_bus(u8); 379 379 void ibmphp_print_test(void); /* for debugging purposes */ 380 380 381 - void ibmphp_hpc_initvars(void); 382 381 int ibmphp_hpc_readslot(struct slot *, u8, u8 *); 383 382 int ibmphp_hpc_writeslot(struct slot *, u8); 384 383 void ibmphp_lock_operations(void);
-2
drivers/pci/hotplug/ibmphp_core.c
··· 1277 1277 1278 1278 ibmphp_debug = debug; 1279 1279 1280 - ibmphp_hpc_initvars(); 1281 - 1282 1280 for (i = 0; i < 16; i++) 1283 1281 irqs[i] = 0; 1284 1282
+14 -33
drivers/pci/hotplug/ibmphp_hpc.c
··· 15 15 16 16 #include <linux/wait.h> 17 17 #include <linux/time.h> 18 + #include <linux/completion.h> 18 19 #include <linux/delay.h> 19 20 #include <linux/module.h> 20 21 #include <linux/pci.h> 21 22 #include <linux/init.h> 22 23 #include <linux/mutex.h> 23 24 #include <linux/sched.h> 24 - #include <linux/semaphore.h> 25 25 #include <linux/kthread.h> 26 26 #include "ibmphp.h" 27 27 ··· 88 88 //---------------------------------------------------------------------------- 89 89 // global variables 90 90 //---------------------------------------------------------------------------- 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 93 93 // 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 95 95 static struct task_struct *ibmphp_poll_thread; 96 96 //---------------------------------------------------------------------------- 97 97 // local function prototypes ··· 108 108 static int hpc_wait_ctlr_notworking(int, struct controller *, void __iomem *, u8 *); 109 109 //---------------------------------------------------------------------------- 110 110 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 - } 128 111 129 112 /*---------------------------------------------------------------------- 130 113 * Name: i2c_ctrl_read ··· 763 780 *---------------------------------------------------------------------*/ 764 781 void ibmphp_lock_operations(void) 765 782 { 766 - down(&semOperations); 783 + mutex_lock(&operations_mutex); 767 784 to_debug = 1; 768 785 } 769 786 ··· 773 790 void ibmphp_unlock_operations(void) 774 791 { 775 792 debug("%s - Entry\n", __func__); 776 - up(&semOperations); 793 + mutex_unlock(&operations_mutex); 777 794 to_debug = 0; 778 795 debug("%s - Exit\n", __func__); 779 796 } ··· 799 816 800 817 while (!kthread_should_stop()) { 801 818 /* try to get the lock to do some kind of hardware access */ 802 - down(&semOperations); 819 + mutex_lock(&operations_mutex); 803 820 804 821 switch (poll_state) { 805 822 case POLL_LATCH_REGISTER: ··· 854 871 break; 855 872 case POLL_SLEEP: 856 873 /* don't sleep with a lock on the hardware */ 857 - up(&semOperations); 874 + mutex_unlock(&operations_mutex); 858 875 msleep(POLL_INTERVAL_SEC * 1000); 859 876 860 877 if (kthread_should_stop()) 861 878 goto out_sleep; 862 879 863 - down(&semOperations); 880 + mutex_lock(&operations_mutex); 864 881 865 882 if (poll_count >= POLL_LATCH_CNT) { 866 883 poll_count = 0; ··· 870 887 break; 871 888 } 872 889 /* give up the hardware semaphore */ 873 - up(&semOperations); 890 + mutex_unlock(&operations_mutex); 874 891 /* sleep for a short time just for good measure */ 875 892 out_sleep: 876 893 msleep(100); 877 894 } 878 - up(&sem_exit); 895 + complete(&exit_complete); 879 896 debug("%s - Exit\n", __func__); 880 897 return 0; 881 898 } ··· 1043 1060 debug("after locking operations\n"); 1044 1061 1045 1062 // wait for poll thread to exit 1046 - debug("before sem_exit down\n"); 1047 - down(&sem_exit); 1048 - debug("after sem_exit down\n"); 1063 + debug("before exit_complete down\n"); 1064 + wait_for_completion(&exit_complete); 1065 + debug("after exit_completion down\n"); 1049 1066 1050 1067 // cleanup 1051 1068 debug("before free_hpc_access\n"); ··· 1053 1070 debug("after free_hpc_access\n"); 1054 1071 ibmphp_unlock_operations(); 1055 1072 debug("after unlock operations\n"); 1056 - up(&sem_exit); 1057 - debug("after sem exit up\n"); 1058 1073 1059 1074 debug("%s - Exit\n", __func__); 1060 1075 }