powerpc/pseries: Flush lazy kernel mappings after unplug operations
[safe/jmp/linux-2.6] / drivers / char / mwave / mwavedd.c
index d37625d..a4ec50c 100644 (file)
@@ -56,7 +56,9 @@
 #include <linux/serial.h>
 #include <linux/sched.h>
 #include <linux/spinlock.h>
+#include <linux/smp_lock.h>
 #include <linux/delay.h>
+#include <linux/serial_8250.h>
 #include "smapi.h"
 #include "mwavedd.h"
 #include "3780i.h"
@@ -84,8 +86,8 @@ module_param(mwave_uart_io, int, 0);
 
 static int mwave_open(struct inode *inode, struct file *file);
 static int mwave_close(struct inode *inode, struct file *file);
-static int mwave_ioctl(struct inode *inode, struct file *filp,
-                       unsigned int iocmd, unsigned long ioarg);
+static long mwave_ioctl(struct file *filp, unsigned int iocmd,
+                                                       unsigned long ioarg);
 
 MWAVE_DEVICE_DATA mwave_s_mdd;
 
@@ -99,6 +101,7 @@ static int mwave_open(struct inode *inode, struct file *file)
        PRINTK_2(TRACE_MWAVE,
                "mwavedd::mwave_open, exit return retval %x\n", retval);
 
+       cycle_kernel_lock();
        return retval;
 }
 
@@ -116,16 +119,16 @@ static int mwave_close(struct inode *inode, struct file *file)
        return retval;
 }
 
-static int mwave_ioctl(struct inode *inode, struct file *file,
-                       unsigned int iocmd, unsigned long ioarg)
+static long mwave_ioctl(struct file *file, unsigned int iocmd,
+                                                       unsigned long ioarg)
 {
        unsigned int retval = 0;
        pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;
        void __user *arg = (void __user *)ioarg;
 
-       PRINTK_5(TRACE_MWAVE,
-               "mwavedd::mwave_ioctl, entry inode %p file %p cmd %x arg %x\n",
-                inode,  file, iocmd, (int) ioarg);
+       PRINTK_4(TRACE_MWAVE,
+               "mwavedd::mwave_ioctl, entry file %p cmd %x arg %x\n",
+               file, iocmd, (int) ioarg);
 
        switch (iocmd) {
 
@@ -133,7 +136,9 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                        PRINTK_1(TRACE_MWAVE,
                                "mwavedd::mwave_ioctl, IOCTL_MW_RESET"
                                " calling tp3780I_ResetDSP\n");
+                       lock_kernel();
                        retval = tp3780I_ResetDSP(&pDrvData->rBDData);
+                       unlock_kernel();
                        PRINTK_2(TRACE_MWAVE,
                                "mwavedd::mwave_ioctl, IOCTL_MW_RESET"
                                " retval %x from tp3780I_ResetDSP\n",
@@ -144,7 +149,9 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                        PRINTK_1(TRACE_MWAVE,
                                "mwavedd::mwave_ioctl, IOCTL_MW_RUN"
                                " calling tp3780I_StartDSP\n");
+                       lock_kernel();
                        retval = tp3780I_StartDSP(&pDrvData->rBDData);
+                       unlock_kernel();
                        PRINTK_2(TRACE_MWAVE,
                                "mwavedd::mwave_ioctl, IOCTL_MW_RUN"
                                " retval %x from tp3780I_StartDSP\n",
@@ -158,8 +165,10 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                                "mwavedd::mwave_ioctl,"
                                " IOCTL_MW_DSP_ABILITIES calling"
                                " tp3780I_QueryAbilities\n");
+                       lock_kernel();
                        retval = tp3780I_QueryAbilities(&pDrvData->rBDData,
                                        &rAbilities);
+                       unlock_kernel();
                        PRINTK_2(TRACE_MWAVE,
                                "mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES"
                                " retval %x from tp3780I_QueryAbilities\n",
@@ -190,11 +199,13 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                                "mwavedd::mwave_ioctl IOCTL_MW_READ_DATA,"
                                " size %lx, ioarg %lx pusBuffer %p\n",
                                rReadData.ulDataLength, ioarg, pusBuffer);
+                       lock_kernel();
                        retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
                                        iocmd,
                                        pusBuffer,
                                        rReadData.ulDataLength,
                                        rReadData.usDspAddress);
+                       unlock_kernel();
                }
                        break;
        
@@ -212,10 +223,12 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                                " size %lx, ioarg %lx pusBuffer %p\n",
                                rReadData.ulDataLength / 2, ioarg,
                                pusBuffer);
+                       lock_kernel();
                        retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
                                iocmd, pusBuffer,
                                rReadData.ulDataLength / 2,
                                rReadData.usDspAddress);
+                       unlock_kernel();
                }
                        break;
        
@@ -233,10 +246,12 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                                " size %lx, ioarg %lx pusBuffer %p\n",
                                rWriteData.ulDataLength, ioarg,
                                pusBuffer);
+                       lock_kernel();
                        retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
                                        iocmd, pusBuffer,
                                        rWriteData.ulDataLength,
                                        rWriteData.usDspAddress);
+                       unlock_kernel();
                }
                        break;
        
@@ -254,23 +269,19 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                                " size %lx, ioarg %lx pusBuffer %p\n",
                                rWriteData.ulDataLength, ioarg,
                                pusBuffer);
+                       lock_kernel();
                        retval = tp3780I_ReadWriteDspIStore(&pDrvData->rBDData,
                                        iocmd, pusBuffer,
                                        rWriteData.ulDataLength,
                                        rWriteData.usDspAddress);
+                       unlock_kernel();
                }
                        break;
        
                case IOCTL_MW_REGISTER_IPC: {
                        unsigned int ipcnum = (unsigned int) ioarg;
        
-                       PRINTK_3(TRACE_MWAVE,
-                               "mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC"
-                               " ipcnum %x entry usIntCount %x\n",
-                               ipcnum,
-                               pDrvData->IPCs[ipcnum].usIntCount);
-       
-                       if (ipcnum > ARRAY_SIZE(pDrvData->IPCs)) {
+                       if (ipcnum >= ARRAY_SIZE(pDrvData->IPCs)) {
                                PRINTK_ERROR(KERN_ERR_MWAVE
                                                "mwavedd::mwave_ioctl:"
                                                " IOCTL_MW_REGISTER_IPC:"
@@ -278,8 +289,16 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                                                ipcnum);
                                return -EINVAL;
                        }
+                       PRINTK_3(TRACE_MWAVE,
+                               "mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC"
+                               " ipcnum %x entry usIntCount %x\n",
+                               ipcnum,
+                               pDrvData->IPCs[ipcnum].usIntCount);
+
+                       lock_kernel();
                        pDrvData->IPCs[ipcnum].bIsHere = FALSE;
                        pDrvData->IPCs[ipcnum].bIsEnabled = TRUE;
+                       unlock_kernel();
        
                        PRINTK_2(TRACE_MWAVE,
                                "mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC"
@@ -291,19 +310,20 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                case IOCTL_MW_GET_IPC: {
                        unsigned int ipcnum = (unsigned int) ioarg;
        
-                       PRINTK_3(TRACE_MWAVE,
-                               "mwavedd::mwave_ioctl IOCTL_MW_GET_IPC"
-                               " ipcnum %x, usIntCount %x\n",
-                               ipcnum,
-                               pDrvData->IPCs[ipcnum].usIntCount);
-                       if (ipcnum > ARRAY_SIZE(pDrvData->IPCs)) {
+                       if (ipcnum >= ARRAY_SIZE(pDrvData->IPCs)) {
                                PRINTK_ERROR(KERN_ERR_MWAVE
                                                "mwavedd::mwave_ioctl:"
                                                " IOCTL_MW_GET_IPC: Error:"
                                                " Invalid ipcnum %x\n", ipcnum);
                                return -EINVAL;
                        }
+                       PRINTK_3(TRACE_MWAVE,
+                               "mwavedd::mwave_ioctl IOCTL_MW_GET_IPC"
+                               " ipcnum %x, usIntCount %x\n",
+                               ipcnum,
+                               pDrvData->IPCs[ipcnum].usIntCount);
        
+                       lock_kernel();
                        if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
                                DECLARE_WAITQUEUE(wait, current);
 
@@ -344,6 +364,7 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                                        " processing\n",
                                        ipcnum);
                        }
+                       unlock_kernel();
                }
                        break;
        
@@ -354,7 +375,7 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                                "mwavedd::mwave_ioctl IOCTL_MW_UNREGISTER_IPC"
                                " ipcnum %x\n",
                                ipcnum);
-                       if (ipcnum > ARRAY_SIZE(pDrvData->IPCs)) {
+                       if (ipcnum >= ARRAY_SIZE(pDrvData->IPCs)) {
                                PRINTK_ERROR(KERN_ERR_MWAVE
                                                "mwavedd::mwave_ioctl:"
                                                " IOCTL_MW_UNREGISTER_IPC:"
@@ -362,19 +383,18 @@ static int mwave_ioctl(struct inode *inode, struct file *file,
                                                ipcnum);
                                return -EINVAL;
                        }
+                       lock_kernel();
                        if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
                                pDrvData->IPCs[ipcnum].bIsEnabled = FALSE;
                                if (pDrvData->IPCs[ipcnum].bIsHere == TRUE) {
                                        wake_up_interruptible(&pDrvData->IPCs[ipcnum].ipc_wait_queue);
                                }
                        }
+                       unlock_kernel();
                }
                        break;
        
                default:
-                       PRINTK_ERROR(KERN_ERR_MWAVE "mwavedd::mwave_ioctl:"
-                                       " Error: Unrecognized iocmd %x\n",
-                                       iocmd);
                        return -ENOTTY;
                        break;
        } /* switch */
@@ -410,8 +430,8 @@ static ssize_t mwave_write(struct file *file, const char __user *buf,
 
 static int register_serial_portandirq(unsigned int port, int irq)
 {
-       struct serial_struct serial;
-
+       struct uart_port uart;
+       
        switch ( port ) {
                case 0x3f8:
                case 0x2f8:
@@ -442,20 +462,22 @@ static int register_serial_portandirq(unsigned int port, int irq)
        } /* switch */
        /* irq is okay */
 
-       memset(&serial, 0, sizeof(serial));
-       serial.port = port;
-       serial.irq = irq;
-       serial.flags = ASYNC_SHARE_IRQ;
-
-       return register_serial(&serial);
+       memset(&uart, 0, sizeof(struct uart_port));
+       
+       uart.uartclk =  1843200;
+       uart.iobase = port;
+       uart.irq = irq;
+       uart.iotype = UPIO_PORT;
+       uart.flags =  UPF_SHARE_IRQ;
+       return serial8250_register_port(&uart);
 }
 
 
-static struct file_operations mwave_fops = {
+static const struct file_operations mwave_fops = {
        .owner          = THIS_MODULE,
        .read           = mwave_read,
        .write          = mwave_write,
-       .ioctl          = mwave_ioctl,
+       .unlocked_ioctl = mwave_ioctl,
        .open           = mwave_open,
        .release        = mwave_close
 };
@@ -472,7 +494,7 @@ struct device mwave_device;
 
 /* Prevent code redundancy, create a macro for mwave_show_* functions. */
 #define mwave_show_function(attr_name, format_string, field)           \
-static ssize_t mwave_show_##attr_name(struct device *dev, char *buf)   \
+static ssize_t mwave_show_##attr_name(struct device *dev, struct device_attribute *attr, char *buf)    \
 {                                                                      \
        DSP_3780I_CONFIG_SETTINGS *pSettings =                          \
                &mwave_s_mdd.rBDData.rDspSettings;                      \
@@ -523,7 +545,7 @@ static void mwave_exit(void)
 #endif
 
        if ( pDrvData->sLine >= 0 ) {
-               unregister_serial(pDrvData->sLine);
+               serial8250_unregister_port(pDrvData->sLine);
        }
        if (pDrvData->bMwaveDevRegistered) {
                misc_deregister(&mwave_misc_dev);
@@ -641,7 +663,7 @@ static int __init mwave_init(void)
 #if 0
        /* sysfs */
        memset(&mwave_device, 0, sizeof (struct device));
-       snprintf(mwave_device.bus_id, BUS_ID_SIZE, "mwave");
+       dev_set_name(&mwave_device, "mwave");
 
        if (device_register(&mwave_device))
                goto cleanup_error;