| .. | .. |
|---|
| 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 |
|---|
| .. | .. |
|---|
| 780 | 763 | *---------------------------------------------------------------------*/ |
|---|
| 781 | 764 | void ibmphp_lock_operations(void) |
|---|
| 782 | 765 | { |
|---|
| 783 | | - down(&semOperations); |
|---|
| 766 | + mutex_lock(&operations_mutex); |
|---|
| 784 | 767 | to_debug = 1; |
|---|
| 785 | 768 | } |
|---|
| 786 | 769 | |
|---|
| .. | .. |
|---|
| 790 | 773 | void ibmphp_unlock_operations(void) |
|---|
| 791 | 774 | { |
|---|
| 792 | 775 | debug("%s - Entry\n", __func__); |
|---|
| 793 | | - up(&semOperations); |
|---|
| 776 | + mutex_unlock(&operations_mutex); |
|---|
| 794 | 777 | to_debug = 0; |
|---|
| 795 | 778 | debug("%s - Exit\n", __func__); |
|---|
| 796 | 779 | } |
|---|
| .. | .. |
|---|
| 816 | 799 | |
|---|
| 817 | 800 | while (!kthread_should_stop()) { |
|---|
| 818 | 801 | /* try to get the lock to do some kind of hardware access */ |
|---|
| 819 | | - down(&semOperations); |
|---|
| 802 | + mutex_lock(&operations_mutex); |
|---|
| 820 | 803 | |
|---|
| 821 | 804 | switch (poll_state) { |
|---|
| 822 | 805 | case POLL_LATCH_REGISTER: |
|---|
| .. | .. |
|---|
| 871 | 854 | break; |
|---|
| 872 | 855 | case POLL_SLEEP: |
|---|
| 873 | 856 | /* don't sleep with a lock on the hardware */ |
|---|
| 874 | | - up(&semOperations); |
|---|
| 857 | + mutex_unlock(&operations_mutex); |
|---|
| 875 | 858 | msleep(POLL_INTERVAL_SEC * 1000); |
|---|
| 876 | 859 | |
|---|
| 877 | 860 | if (kthread_should_stop()) |
|---|
| 878 | 861 | goto out_sleep; |
|---|
| 879 | 862 | |
|---|
| 880 | | - down(&semOperations); |
|---|
| 863 | + mutex_lock(&operations_mutex); |
|---|
| 881 | 864 | |
|---|
| 882 | 865 | if (poll_count >= POLL_LATCH_CNT) { |
|---|
| 883 | 866 | poll_count = 0; |
|---|
| .. | .. |
|---|
| 887 | 870 | break; |
|---|
| 888 | 871 | } |
|---|
| 889 | 872 | /* give up the hardware semaphore */ |
|---|
| 890 | | - up(&semOperations); |
|---|
| 873 | + mutex_unlock(&operations_mutex); |
|---|
| 891 | 874 | /* sleep for a short time just for good measure */ |
|---|
| 892 | 875 | out_sleep: |
|---|
| 893 | 876 | msleep(100); |
|---|
| 894 | 877 | } |
|---|
| 895 | | - up(&sem_exit); |
|---|
| 878 | + complete(&exit_complete); |
|---|
| 896 | 879 | debug("%s - Exit\n", __func__); |
|---|
| 897 | 880 | return 0; |
|---|
| 898 | 881 | } |
|---|
| .. | .. |
|---|
| 1060 | 1043 | debug("after locking operations\n"); |
|---|
| 1061 | 1044 | |
|---|
| 1062 | 1045 | // 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"); |
|---|
| 1066 | 1049 | |
|---|
| 1067 | 1050 | // cleanup |
|---|
| 1068 | 1051 | debug("before free_hpc_access\n"); |
|---|
| .. | .. |
|---|
| 1070 | 1053 | debug("after free_hpc_access\n"); |
|---|
| 1071 | 1054 | ibmphp_unlock_operations(); |
|---|
| 1072 | 1055 | debug("after unlock operations\n"); |
|---|
| 1073 | | - up(&sem_exit); |
|---|
| 1074 | | - debug("after sem exit up\n"); |
|---|
| 1075 | 1056 | |
|---|
| 1076 | 1057 | debug("%s - Exit\n", __func__); |
|---|
| 1077 | 1058 | } |
|---|