diff options
| author | Arnd Bergmann <arnd@arndb.de> | 2018-12-10 16:49:10 -0500 |
|---|---|---|
| committer | Bjorn Helgaas <bhelgaas@google.com> | 2019-01-29 18:15:36 -0500 |
| commit | 2a727f6091372231281efaa8a5f56ee79509fd83 (patch) | |
| tree | 8b4b8cf9043cb82cb0b1363d676d4d45708be7a8 /drivers/pci/hotplug | |
| parent | 25bd879ec16ad3b83a5b1c3f16faa55e696bfccb (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')
| -rw-r--r-- | drivers/pci/hotplug/ibmphp.h | 1 | ||||
| -rw-r--r-- | drivers/pci/hotplug/ibmphp_core.c | 2 | ||||
| -rw-r--r-- | drivers/pci/hotplug/ibmphp_hpc.c | 47 |
3 files changed, 14 insertions, 36 deletions
diff --git a/drivers/pci/hotplug/ibmphp.h b/drivers/pci/hotplug/ibmphp.h index b89f850c3a4e..e90a4ebf6550 100644 --- a/drivers/pci/hotplug/ibmphp.h +++ b/drivers/pci/hotplug/ibmphp.h | |||
| @@ -378,7 +378,6 @@ int ibmphp_add_pfmem_from_mem(struct resource_node *); | |||
| 378 | struct bus_node *ibmphp_find_res_bus(u8); | 378 | struct bus_node *ibmphp_find_res_bus(u8); |
| 379 | void ibmphp_print_test(void); /* for debugging purposes */ | 379 | void ibmphp_print_test(void); /* for debugging purposes */ |
| 380 | 380 | ||
| 381 | void ibmphp_hpc_initvars(void); | ||
| 382 | int ibmphp_hpc_readslot(struct slot *, u8, u8 *); | 381 | int ibmphp_hpc_readslot(struct slot *, u8, u8 *); |
| 383 | int ibmphp_hpc_writeslot(struct slot *, u8); | 382 | int ibmphp_hpc_writeslot(struct slot *, u8); |
| 384 | void ibmphp_lock_operations(void); | 383 | void ibmphp_lock_operations(void); |
diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c index 08a58e911fc2..17124254d897 100644 --- a/drivers/pci/hotplug/ibmphp_core.c +++ b/drivers/pci/hotplug/ibmphp_core.c | |||
| @@ -1277,8 +1277,6 @@ static int __init ibmphp_init(void) | |||
| 1277 | 1277 | ||
| 1278 | ibmphp_debug = debug; | 1278 | ibmphp_debug = debug; |
| 1279 | 1279 | ||
| 1280 | ibmphp_hpc_initvars(); | ||
| 1281 | |||
| 1282 | for (i = 0; i < 16; i++) | 1280 | for (i = 0; i < 16; i++) |
| 1283 | irqs[i] = 0; | 1281 | irqs[i] = 0; |
| 1284 | 1282 | ||
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 | //---------------------------------------------------------------------------- |
| 91 | static struct mutex sem_hpcaccess; // lock access to HPC | 91 | static DEFINE_MUTEX(sem_hpcaccess); // lock access to HPC |
| 92 | static struct semaphore semOperations; // lock all operations and | 92 | static DEFINE_MUTEX(operations_mutex); // lock all operations and |
| 93 | // access to data structures | 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 | static struct task_struct *ibmphp_poll_thread; | 95 | static 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 | *---------------------------------------------------------------------*/ | ||
| 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 | |||
| 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 | *---------------------------------------------------------------------*/ |
| 781 | void ibmphp_lock_operations(void) | 764 | void 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) | |||
| 790 | void ibmphp_unlock_operations(void) | 773 | void 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 */ |
| 892 | out_sleep: | 875 | out_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 | } |
