]> Pileus Git - ~andy/linux/blobdiff - drivers/staging/sep/sep_driver.c
staging/comedi/me4000: fix sparse warning "obsolete struct initializer"
[~andy/linux] / drivers / staging / sep / sep_driver.c
index ebe7a90aec0ec5634aa03f503af841df49d9f18e..ee234547c87781713627cf9200399fd756efe24e 100644 (file)
@@ -29,7 +29,6 @@
  *  2010.09.14  Upgrade to Medfield
  *
  */
-#define DEBUG
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/miscdevice.h>
@@ -53,6 +52,7 @@
 #include <asm/cacheflush.h>
 #include <linux/sched.h>
 #include <linux/delay.h>
+#include <linux/jiffies.h>
 #include <linux/rar_register.h>
 
 #include "../memrar/memrar.h"
@@ -90,7 +90,7 @@ static int sep_load_firmware(struct sep_device *sep)
        char *res_name = "resident.image.bin";
        char *extapp_name = "extapp.image.bin";
        int error ;
-       unsigned int work1, work2, work3;
+       unsigned long work1, work2, work3;
 
        /* Set addresses and load resident */
        sep->resident_bus = sep->rar_bus;
@@ -106,21 +106,17 @@ static int sep_load_firmware(struct sep_device *sep)
        sep->resident_size = fw->size;
        release_firmware(fw);
 
-       dev_dbg(&sep->pdev->dev, "resident virtual is %p\n",
-               sep->resident_addr);
        dev_dbg(&sep->pdev->dev, "resident bus is %lx\n",
                (unsigned long)sep->resident_bus);
-       dev_dbg(&sep->pdev->dev, "resident size is %08x\n",
-               sep->resident_size);
 
        /* Set addresses for dcache (no loading needed) */
-       work1 = (unsigned int)sep->resident_bus;
-       work2 = (unsigned int)sep->resident_size;
+       work1 = (unsigned long)sep->resident_bus;
+       work2 = (unsigned long)sep->resident_size;
        work3 = (work1 + work2 + (1024 * 4)) & 0xfffff000;
        sep->dcache_bus = (dma_addr_t)work3;
 
-       work1 = (unsigned int)sep->resident_addr;
-       work2 = (unsigned int)sep->resident_size;
+       work1 = (unsigned long)sep->resident_addr;
+       work2 = (unsigned long)sep->resident_size;
        work3 = (work1 + work2 + (1024 * 4)) & 0xfffff000;
        sep->dcache_addr = (void *)work3;
 
@@ -140,12 +136,8 @@ static int sep_load_firmware(struct sep_device *sep)
        sep->cache_size = fw->size;
        release_firmware(fw);
 
-       dev_dbg(&sep->pdev->dev, "cache virtual is %p\n",
-               sep->cache_addr);
        dev_dbg(&sep->pdev->dev, "cache bus is %08lx\n",
                (unsigned long)sep->cache_bus);
-       dev_dbg(&sep->pdev->dev, "cache size is %08x\n",
-               sep->cache_size);
 
        /* Set addresses and load extapp */
        sep->extapp_bus = sep->cache_bus + (1024 * 370);
@@ -161,12 +153,8 @@ static int sep_load_firmware(struct sep_device *sep)
        sep->extapp_size = fw->size;
        release_firmware(fw);
 
-       dev_dbg(&sep->pdev->dev, "extapp virtual is %p\n",
-               sep->extapp_addr);
        dev_dbg(&sep->pdev->dev, "extapp bus is %08llx\n",
                (unsigned long long)sep->extapp_bus);
-       dev_dbg(&sep->pdev->dev, "extapp size is %08x\n",
-               sep->extapp_size);
 
        return error;
 }
@@ -205,7 +193,7 @@ static int sep_map_and_alloc_shared_area(struct sep_device *sep)
                return -ENOMEM;
        }
        dev_dbg(&sep->pdev->dev,
-               "shared_addr %x bytes @%p (bus %llx)\n",
+               "shared_addr %zx bytes @%p (bus %llx)\n",
                                sep->shared_size, sep->shared_addr,
                                (unsigned long long)sep->shared_bus);
        return 0;
@@ -217,7 +205,6 @@ static int sep_map_and_alloc_shared_area(struct sep_device *sep)
  */
 static void sep_unmap_and_free_shared_area(struct sep_device *sep)
 {
-       dev_dbg(&sep->pdev->dev, "shared area unmap and free\n");
        dma_free_coherent(&sep->pdev->dev, sep->shared_size,
                                sep->shared_addr, sep->shared_bus);
 }
@@ -256,19 +243,12 @@ static int sep_singleton_open(struct inode *inode_ptr, struct file *file_ptr)
 
        file_ptr->private_data = sep;
 
-       dev_dbg(&sep->pdev->dev, "Singleton open for pid %d\n",
-               current->pid);
-
-       dev_dbg(&sep->pdev->dev, "calling test and set for singleton 0\n");
        if (test_and_set_bit(0, &sep->singleton_access_flag)) {
                error = -EBUSY;
                goto end_function;
        }
 
-       dev_dbg(&sep->pdev->dev,
-               "sep_singleton_open end\n");
 end_function:
-
        return error;
 }
 
@@ -278,7 +258,7 @@ end_function:
  *     @filp: file handle to SEP device
  *
  *     Open method for the SEP device. Called when userspace opens
- *     the SEP device node. 
+ *     the SEP device node.
  *
  *     Returns zero on success otherwise an error code.
  */
@@ -312,8 +292,6 @@ static int sep_singleton_release(struct inode *inode, struct file *filp)
 {
        struct sep_device *sep = filp->private_data;
 
-       dev_dbg(&sep->pdev->dev, "Singleton release for pid %d\n",
-                                                       current->pid);
        clear_bit(0, &sep->singleton_access_flag);
        return 0;
 }
@@ -339,7 +317,6 @@ static int sep_request_daemon_open(struct inode *inode, struct file *filp)
                current->pid);
 
        /* There is supposed to be only one request daemon */
-       dev_dbg(&sep->pdev->dev, "calling test and set for req_dmon open 0\n");
        if (test_and_set_bit(0, &sep->request_daemon_open))
                error = -EBUSY;
        return error;
@@ -356,7 +333,7 @@ static int sep_request_daemon_release(struct inode *inode, struct file *filp)
 {
        struct sep_device *sep = filp->private_data;
 
-       dev_dbg(&sep->pdev->dev, "Reques daemon release for pid %d\n",
+       dev_dbg(&sep->pdev->dev, "Request daemon release for pid %d\n",
                current->pid);
 
        /* Clear the request_daemon_open flag */
@@ -375,9 +352,6 @@ static int sep_req_daemon_send_reply_command_handler(struct sep_device *sep)
 {
        unsigned long lck_flags;
 
-       dev_dbg(&sep->pdev->dev,
-               "sep_req_daemon_send_reply_command_handler start\n");
-
        sep_dump_message(sep);
 
        /* Counters are lockable region */
@@ -386,9 +360,7 @@ static int sep_req_daemon_send_reply_command_handler(struct sep_device *sep)
        sep->reply_ct++;
 
        /* Send the interrupt to SEP */
-       sep_write_reg(sep, HW_HOST_HOST_SEP_GPR2_REG_ADDR,
-               sep->send_ct);
-
+       sep_write_reg(sep, HW_HOST_HOST_SEP_GPR2_REG_ADDR, sep->send_ct);
        sep->send_ct++;
 
        spin_unlock_irqrestore(&sep->snd_rply_lck, lck_flags);
@@ -397,9 +369,6 @@ static int sep_req_daemon_send_reply_command_handler(struct sep_device *sep)
                "sep_req_daemon_send_reply send_ct %lx reply_ct %lx\n",
                sep->send_ct, sep->reply_ct);
 
-       dev_dbg(&sep->pdev->dev,
-               "sep_req_daemon_send_reply_command_handler end\n");
-
        return 0;
 }
 
@@ -417,8 +386,6 @@ static int sep_free_dma_table_data_handler(struct sep_device *sep)
        /* Pointer to the current dma_resource struct */
        struct sep_dma_resource *dma;
 
-       dev_dbg(&sep->pdev->dev, "sep_free_dma_table_data_handler start\n");
-
        for (dcb_counter = 0; dcb_counter < sep->nr_dcb_creat; dcb_counter++) {
                dma = &sep->dma_res_arr[dcb_counter];
 
@@ -464,12 +431,12 @@ static int sep_free_dma_table_data_handler(struct sep_device *sep)
                }
 
                /* Reset all the values */
-               dma->in_page_array = 0;
-               dma->out_page_array = 0;
+               dma->in_page_array = NULL;
+               dma->out_page_array = NULL;
                dma->in_num_pages = 0;
                dma->out_num_pages = 0;
-               dma->in_map_array = 0;
-               dma->out_map_array = 0;
+               dma->in_map_array = NULL;
+               dma->out_map_array = NULL;
                dma->in_map_num_entries = 0;
                dma->out_map_num_entries = 0;
        }
@@ -477,7 +444,6 @@ static int sep_free_dma_table_data_handler(struct sep_device *sep)
        sep->nr_dcb_creat = 0;
        sep->num_lli_tables_created = 0;
 
-       dev_dbg(&sep->pdev->dev, "sep_free_dma_table_data_handler end\n");
        return 0;
 }
 
@@ -496,8 +462,6 @@ static int sep_request_daemon_mmap(struct file  *filp,
        dma_addr_t bus_address;
        int error = 0;
 
-       dev_dbg(&sep->pdev->dev, "daemon mmap start\n");
-
        if ((vma->vm_end - vma->vm_start) > SEP_DRIVER_MMMAP_AREA_SIZE) {
                error = -EINVAL;
                goto end_function;
@@ -506,9 +470,6 @@ static int sep_request_daemon_mmap(struct file  *filp,
        /* Get physical address */
        bus_address = sep->shared_bus;
 
-       dev_dbg(&sep->pdev->dev, "bus_address is %08lx\n",
-                                       (unsigned long)bus_address);
-
        if (remap_pfn_range(vma, vma->vm_start, bus_address >> PAGE_SHIFT,
                vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
 
@@ -518,7 +479,6 @@ static int sep_request_daemon_mmap(struct file  *filp,
        }
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "daemon mmap end\n");
        return error;
 }
 
@@ -539,8 +499,6 @@ static unsigned int sep_request_daemon_poll(struct file *filp,
        unsigned long lck_flags;
        struct sep_device *sep = filp->private_data;
 
-       dev_dbg(&sep->pdev->dev, "daemon poll: start\n");
-
        poll_wait(filp, &sep->event_request_daemon, wait);
 
        dev_dbg(&sep->pdev->dev, "daemon poll: send_ct is %lx reply ct is %lx\n",
@@ -573,7 +531,6 @@ static unsigned int sep_request_daemon_poll(struct file *filp,
                mask = 0;
        }
 end_function:
-       dev_dbg(&sep->pdev->dev, "daemon poll: exit\n");
        return mask;
 }
 
@@ -596,7 +553,6 @@ static int sep_release(struct inode *inode, struct file *filp)
         * clear the in use flags, and then wake up sep_event
         * so that other processes can do transactions
         */
-       dev_dbg(&sep->pdev->dev, "waking up event and mmap_event\n");
        if (sep->pid_doing_transaction == current->pid) {
                clear_bit(SEP_MMAP_LOCK_BIT, &sep->in_use_flags);
                clear_bit(SEP_SEND_MSG_LOCK_BIT, &sep->in_use_flags);
@@ -622,8 +578,6 @@ static int sep_mmap(struct file *filp, struct vm_area_struct *vma)
        struct sep_device *sep = filp->private_data;
        unsigned long error = 0;
 
-       dev_dbg(&sep->pdev->dev, "mmap start\n");
-
        /* Set the transaction busy (own the device) */
        wait_event_interruptible(sep->event,
                test_and_set_bit(SEP_MMAP_LOCK_BIT,
@@ -665,16 +619,12 @@ static int sep_mmap(struct file *filp, struct vm_area_struct *vma)
        /* Get bus address */
        bus_addr = sep->shared_bus;
 
-       dev_dbg(&sep->pdev->dev,
-               "bus_address is %lx\n", (unsigned long)bus_addr);
-
        if (remap_pfn_range(vma, vma->vm_start, bus_addr >> PAGE_SHIFT,
                vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
                dev_warn(&sep->pdev->dev, "remap_page_range failed\n");
                error = -EAGAIN;
                goto end_function_with_error;
        }
-       dev_dbg(&sep->pdev->dev, "mmap end\n");
        goto end_function;
 
 end_function_with_error:
@@ -686,7 +636,6 @@ end_function_with_error:
 
        /* Raise event for stuck contextes */
 
-       dev_warn(&sep->pdev->dev, "mmap error - waking up event\n");
        wake_up(&sep->event);
 
 end_function:
@@ -710,8 +659,6 @@ static unsigned int sep_poll(struct file *filp, poll_table *wait)
 
        struct sep_device *sep = filp->private_data;
 
-       dev_dbg(&sep->pdev->dev, "poll: start\n");
-
        /* Am I the process that owns the transaction? */
        mutex_lock(&sep->sep_mutex);
        if (current->pid != sep->pid_doing_transaction) {
@@ -724,7 +671,6 @@ static unsigned int sep_poll(struct file *filp, poll_table *wait)
 
        /* Check if send command or send_reply were activated previously */
        if (!test_bit(SEP_SEND_MSG_LOCK_BIT, &sep->in_use_flags)) {
-               dev_warn(&sep->pdev->dev, "poll; lock bit set\n");
                mask = POLLERR;
                goto end_function;
        }
@@ -781,7 +727,6 @@ static unsigned int sep_poll(struct file *filp, poll_table *wait)
        }
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "poll: end\n");
        return mask;
 }
 
@@ -810,8 +755,6 @@ static unsigned long sep_set_time(struct sep_device *sep)
        u32 *time_addr; /* Address of time as seen by the kernel */
 
 
-       dev_dbg(&sep->pdev->dev, "sep_set_time start\n");
-
        do_gettimeofday(&time);
 
        /* Set value in the SYSTEM MEMORY offset */
@@ -835,15 +778,13 @@ static unsigned long sep_set_time(struct sep_device *sep)
  *     Inserts the data into the caller id table. Note that this function
  *     falls under the ioctl lock
  */
-static int sep_set_caller_id_handler(struct sep_device *sep, u32 arg)
+static int sep_set_caller_id_handler(struct sep_device *sep, unsigned long arg)
 {
        void __user *hash;
        int   error = 0;
        int   i;
        struct caller_id_struct command_args;
 
-       dev_dbg(&sep->pdev->dev, "sep_set_caller_id_handler start\n");
-
        for (i = 0; i < SEP_CALLER_ID_TABLE_NUM_ENTRIES; i++) {
                if (sep->caller_id_table[i].pid == 0)
                        break;
@@ -887,7 +828,6 @@ static int sep_set_caller_id_handler(struct sep_device *sep, u32 arg)
                hash, command_args.callerIdSizeInBytes))
                error = -EFAULT;
 end_function:
-       dev_dbg(&sep->pdev->dev, "sep_set_caller_id_handler end\n");
        return error;
 }
 
@@ -901,9 +841,7 @@ end_function:
 static int sep_set_current_caller_id(struct sep_device *sep)
 {
        int i;
-
-       dev_dbg(&sep->pdev->dev, "sep_set_current_caller_id start\n");
-       dev_dbg(&sep->pdev->dev, "current process is %d\n", current->pid);
+       u32 *hash_buf_ptr;
 
        /* Zero the previous value */
        memset(sep->shared_addr + SEP_CALLER_ID_OFFSET_BYTES,
@@ -919,7 +857,13 @@ static int sep_set_current_caller_id(struct sep_device *sep)
                        break;
                }
        }
-       dev_dbg(&sep->pdev->dev, "sep_set_current_caller_id end\n");
+       /* Ensure data is in little endian */
+       hash_buf_ptr = (u32 *)sep->shared_addr +
+               SEP_CALLER_ID_OFFSET_BYTES;
+
+       for (i = 0; i < SEP_CALLER_ID_HASH_SIZE_IN_WORDS; i++)
+               hash_buf_ptr[i] = cpu_to_le32(hash_buf_ptr[i]);
+
        return 0;
 }
 
@@ -937,17 +881,13 @@ static int sep_send_command_handler(struct sep_device *sep)
        unsigned long lck_flags;
        int error = 0;
 
-       dev_dbg(&sep->pdev->dev, "sep_send_command_handler start\n");
-
        if (test_and_set_bit(SEP_SEND_MSG_LOCK_BIT, &sep->in_use_flags)) {
                error = -EPROTO;
                goto end_function;
        }
        sep_set_time(sep);
 
-       /* Only Medfield has caller id */
-       if (sep->mrst == 0)
-               sep_set_current_caller_id(sep);
+       sep_set_current_caller_id(sep);
 
        sep_dump_message(sep);
 
@@ -964,7 +904,6 @@ static int sep_send_command_handler(struct sep_device *sep)
        sep_write_reg(sep, HW_HOST_HOST_SEP_GPR0_REG_ADDR, 0x2);
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "sep_send_command_handler end\n");
        return error;
 }
 
@@ -988,9 +927,6 @@ static int sep_allocate_data_pool_memory_handler(struct sep_device *sep,
        /* Holds the allocated buffer address in the system memory pool */
        u32 *token_addr;
 
-       dev_dbg(&sep->pdev->dev,
-               "sep_allocate_data_pool_memory_handler start\n");
-
        if (copy_from_user(&command_args, (void __user *)arg,
                                        sizeof(struct alloc_struct))) {
                error = -EFAULT;
@@ -1005,40 +941,28 @@ static int sep_allocate_data_pool_memory_handler(struct sep_device *sep,
        }
 
        dev_dbg(&sep->pdev->dev,
-               "bytes_allocated: %x\n", (int)sep->data_pool_bytes_allocated);
+               "data pool bytes_allocated: %x\n", (int)sep->data_pool_bytes_allocated);
        dev_dbg(&sep->pdev->dev,
                "offset: %x\n", SEP_DRIVER_DATA_POOL_AREA_OFFSET_IN_BYTES);
        /* Set the virtual and bus address */
        command_args.offset = SEP_DRIVER_DATA_POOL_AREA_OFFSET_IN_BYTES +
                sep->data_pool_bytes_allocated;
 
-       dev_dbg(&sep->pdev->dev,
-               "command_args.offset: %x\n", command_args.offset);
-
        /* Place in the shared area that is known by the SEP */
        token_addr = (u32 *)(sep->shared_addr +
                SEP_DRIVER_DATA_POOL_ALLOCATION_OFFSET_IN_BYTES +
                (sep->num_of_data_allocations)*2*sizeof(u32));
 
-       dev_dbg(&sep->pdev->dev, "allocation offset: %x\n",
-               SEP_DRIVER_DATA_POOL_ALLOCATION_OFFSET_IN_BYTES);
-       dev_dbg(&sep->pdev->dev, "data pool token addr is %p\n", token_addr);
-
        token_addr[0] = SEP_DATA_POOL_POINTERS_VAL_TOKEN;
        token_addr[1] = (u32)sep->shared_bus +
                SEP_DRIVER_DATA_POOL_AREA_OFFSET_IN_BYTES +
                sep->data_pool_bytes_allocated;
 
-       dev_dbg(&sep->pdev->dev, "data pool token [0] %x\n", token_addr[0]);
-       dev_dbg(&sep->pdev->dev, "data pool token [1] %x\n", token_addr[1]);
-
        /* Write the memory back to the user space */
        error = copy_to_user((void *)arg, (void *)&command_args,
                sizeof(struct alloc_struct));
        if (error) {
                error = -EFAULT;
-               dev_warn(&sep->pdev->dev,
-                       "allocate data pool copy to user error\n");
                goto end_function;
        }
 
@@ -1046,11 +970,6 @@ static int sep_allocate_data_pool_memory_handler(struct sep_device *sep,
        sep->data_pool_bytes_allocated += command_args.num_bytes;
        sep->num_of_data_allocations += 1;
 
-       dev_dbg(&sep->pdev->dev, "data_allocations %d\n",
-               sep->num_of_data_allocations);
-       dev_dbg(&sep->pdev->dev, "bytes allocated  %d\n",
-               (int)sep->data_pool_bytes_allocated);
-
 end_function:
        dev_dbg(&sep->pdev->dev, "sep_allocate_data_pool_memory_handler end\n");
        return error;
@@ -1071,7 +990,7 @@ end_function:
  *     the kernel (when ioctl is not used)
  */
 static int sep_lock_kernel_pages(struct sep_device *sep,
-       u32 kernel_virt_addr,
+       unsigned long kernel_virt_addr,
        u32 data_size,
        struct sep_lli_entry **lli_array_ptr,
        int in_out_flag)
@@ -1083,13 +1002,9 @@ static int sep_lock_kernel_pages(struct sep_device *sep,
        /* Map array */
        struct sep_dma_map *map_array;
 
-       dev_dbg(&sep->pdev->dev,
-               "sep_lock_kernel_pages start\n");
-
-       dev_dbg(&sep->pdev->dev,
-               "kernel_virt_addr is %08x\n", kernel_virt_addr);
-       dev_dbg(&sep->pdev->dev,
-               "data_size is %x\n", data_size);
+       dev_dbg(&sep->pdev->dev, "lock kernel pages kernel_virt_addr is %08lx\n",
+                               (unsigned long)kernel_virt_addr);
+       dev_dbg(&sep->pdev->dev, "data_size is %x\n", data_size);
 
        lli_array = kmalloc(sizeof(struct sep_lli_entry), GFP_ATOMIC);
        if (!lli_array) {
@@ -1124,13 +1039,13 @@ static int sep_lock_kernel_pages(struct sep_device *sep,
        if (in_out_flag == SEP_DRIVER_IN_FLAG) {
                *lli_array_ptr = lli_array;
                sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages = 1;
-               sep->dma_res_arr[sep->nr_dcb_creat].in_page_array = 0;
+               sep->dma_res_arr[sep->nr_dcb_creat].in_page_array = NULL;
                sep->dma_res_arr[sep->nr_dcb_creat].in_map_array = map_array;
                sep->dma_res_arr[sep->nr_dcb_creat].in_map_num_entries = 1;
        } else {
                *lli_array_ptr = lli_array;
                sep->dma_res_arr[sep->nr_dcb_creat].out_num_pages = 1;
-               sep->dma_res_arr[sep->nr_dcb_creat].out_page_array = 0;
+               sep->dma_res_arr[sep->nr_dcb_creat].out_page_array = NULL;
                sep->dma_res_arr[sep->nr_dcb_creat].out_map_array = map_array;
                sep->dma_res_arr[sep->nr_dcb_creat].out_map_num_entries = 1;
        }
@@ -1140,7 +1055,6 @@ end_function_with_error:
        kfree(lli_array);
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "sep_lock_kernel_pages end\n");
        return error;
 }
 
@@ -1182,22 +1096,17 @@ static int sep_lock_user_pages(struct sep_device *sep,
        /* Direction of the DMA mapping for locked pages */
        enum dma_data_direction dir;
 
-       dev_dbg(&sep->pdev->dev,
-               "sep_lock_user_pages start\n");
-
        /* Set start and end pages  and num pages */
        end_page = (app_virt_addr + data_size - 1) >> PAGE_SHIFT;
        start_page = app_virt_addr >> PAGE_SHIFT;
        num_pages = end_page - start_page + 1;
 
-       dev_dbg(&sep->pdev->dev, "app_virt_addr is %x\n", app_virt_addr);
+       dev_dbg(&sep->pdev->dev, "lock user pages app_virt_addr is %x\n", app_virt_addr);
        dev_dbg(&sep->pdev->dev, "data_size is %x\n", data_size);
        dev_dbg(&sep->pdev->dev, "start_page is %x\n", start_page);
        dev_dbg(&sep->pdev->dev, "end_page is %x\n", end_page);
        dev_dbg(&sep->pdev->dev, "num_pages is %x\n", num_pages);
 
-       dev_dbg(&sep->pdev->dev, "starting page_array malloc\n");
-
        /* Allocate array of pages structure pointers */
        page_array = kmalloc(sizeof(struct page *) * num_pages, GFP_ATOMIC);
        if (!page_array) {
@@ -1220,14 +1129,12 @@ static int sep_lock_user_pages(struct sep_device *sep,
                goto end_function_with_error2;
        }
 
-       dev_dbg(&sep->pdev->dev, "starting get_user_pages\n");
-
        /* Convert the application virtual address into a set of physical */
        down_read(&current->mm->mmap_sem);
        result = get_user_pages(current, current->mm, app_virt_addr,
                num_pages,
                ((in_out_flag == SEP_DRIVER_IN_FLAG) ? 0 : 1),
-               0, page_array, 0);
+               0, page_array, NULL);
 
        up_read(&current->mm->mmap_sem);
 
@@ -1328,7 +1235,6 @@ end_function_with_error1:
        kfree(page_array);
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "sep_lock_user_pages end\n");
        return error;
 }
 
@@ -1399,8 +1305,6 @@ static u32 sep_calculate_lli_table_max_size(struct sep_device *sep,
                table_data_size -= (SEP_DRIVER_MIN_DATA_SIZE_PER_TABLE -
                        next_table_data_size);
 
-       dev_dbg(&sep->pdev->dev, "table data size is %x\n",
-                                                       table_data_size);
 end_function:
        return table_data_size;
 }
@@ -1429,14 +1333,12 @@ static void sep_build_lli_table(struct sep_device *sep,
        /* Counter of lli array entry */
        u32 array_counter;
 
-       dev_dbg(&sep->pdev->dev, "sep_build_lli_table start\n");
-
        /* Init currrent table data size and lli array entry counter */
        curr_table_data_size = 0;
        array_counter = 0;
        *num_table_entries_ptr = 1;
 
-       dev_dbg(&sep->pdev->dev, "table_data_size is %x\n", table_data_size);
+       dev_dbg(&sep->pdev->dev, "build lli table table_data_size is %x\n", table_data_size);
 
        /* Fill the table till table size reaches the needed amount */
        while (curr_table_data_size < table_data_size) {
@@ -1493,19 +1395,9 @@ static void sep_build_lli_table(struct sep_device *sep,
        lli_table_ptr->bus_address = 0xffffffff;
        lli_table_ptr->block_size = 0;
 
-       dev_dbg(&sep->pdev->dev, "lli_table_ptr is %p\n", lli_table_ptr);
-       dev_dbg(&sep->pdev->dev, "lli_table_ptr->bus_address is %08lx\n",
-                               (unsigned long)lli_table_ptr->bus_address);
-       dev_dbg(&sep->pdev->dev, "lli_table_ptr->block_size is %x\n",
-                                               lli_table_ptr->block_size);
-
        /* Set the output parameter */
        *num_processed_entries_ptr += array_counter;
 
-       dev_dbg(&sep->pdev->dev, "num_processed_entries_ptr is %x\n",
-               *num_processed_entries_ptr);
-
-       dev_dbg(&sep->pdev->dev, "sep_build_lli_table end\n");
 }
 
 /**
@@ -1542,8 +1434,8 @@ static dma_addr_t sep_shared_area_virt_to_bus(struct sep_device *sep,
 static void *sep_shared_area_bus_to_virt(struct sep_device *sep,
        dma_addr_t bus_address)
 {
-       dev_dbg(&sep->pdev->dev, "shared bus to virt b=%x v=%x\n",
-               (u32)bus_address, (u32)(sep->shared_addr +
+       dev_dbg(&sep->pdev->dev, "shared bus to virt b=%lx v=%lx\n",
+               (unsigned long)bus_address, (unsigned long)(sep->shared_addr +
                        (size_t)(bus_address - sep->shared_bus)));
 
        return sep->shared_addr + (size_t)(bus_address - sep->shared_bus);
@@ -1568,7 +1460,7 @@ static void sep_debug_print_lli_tables(struct sep_device *sep,
 
        dev_dbg(&sep->pdev->dev, "sep_debug_print_lli_tables start\n");
 
-       while ((unsigned long) lli_table_ptr != 0xffffffff) {
+       while ((unsigned long) lli_table_ptr->bus_address != 0xffffffff) {
                dev_dbg(&sep->pdev->dev,
                        "lli table %08lx, table_data_size is %lu\n",
                        table_count, table_data_size);
@@ -1602,18 +1494,16 @@ static void sep_debug_print_lli_tables(struct sep_device *sep,
 
                table_data_size = lli_table_ptr->block_size & 0xffffff;
                num_table_entries = (lli_table_ptr->block_size >> 24) & 0xff;
-               lli_table_ptr = (struct sep_lli_entry *)
-                       (lli_table_ptr->bus_address);
 
                dev_dbg(&sep->pdev->dev,
                        "phys table_data_size is %lu num_table_entries is"
-                       " %lu lli_table_ptr is%lu\n", table_data_size,
-                       num_table_entries, (unsigned long)lli_table_ptr);
+                       " %lu bus_address is%lu\n", table_data_size,
+                       num_table_entries, (unsigned long)lli_table_ptr->bus_address);
 
-               if ((unsigned long)lli_table_ptr != 0xffffffff)
+               if ((unsigned long)lli_table_ptr->bus_address != 0xffffffff)
                        lli_table_ptr = (struct sep_lli_entry *)
                                sep_shared_bus_to_virt(sep,
-                               (unsigned long)lli_table_ptr);
+                               (unsigned long)lli_table_ptr->bus_address);
 
                table_count++;
        }
@@ -1637,8 +1527,6 @@ static void sep_prepare_empty_lli_table(struct sep_device *sep,
 {
        struct sep_lli_entry *lli_table_ptr;
 
-       dev_dbg(&sep->pdev->dev, "sep_prepare_empty_lli_table start\n");
-
        /* Find the area for new table */
        lli_table_ptr =
                (struct sep_lli_entry *)(sep->shared_addr +
@@ -1666,9 +1554,6 @@ static void sep_prepare_empty_lli_table(struct sep_device *sep,
 
        /* Update the number of created tables */
        sep->num_lli_tables_created++;
-
-       dev_dbg(&sep->pdev->dev, "sep_prepare_empty_lli_table start\n");
-
 }
 
 /**
@@ -1713,18 +1598,17 @@ static int sep_prepare_input_dma_table(struct sep_device *sep,
        /* Number of entries in lli table */
        u32 num_entries_in_table = 0;
        /* Next table address */
-       u32 lli_table_alloc_addr = 0;
+       void *lli_table_alloc_addr = 0;
 
-       dev_dbg(&sep->pdev->dev, "sep_prepare_input_dma_table start\n");
-       dev_dbg(&sep->pdev->dev, "data_size is %x\n", data_size);
+       dev_dbg(&sep->pdev->dev, "prepare intput dma table data_size is %x\n", data_size);
        dev_dbg(&sep->pdev->dev, "block_size is %x\n", block_size);
 
        /* Initialize the pages pointers */
-       sep->dma_res_arr[sep->nr_dcb_creat].in_page_array = 0;
+       sep->dma_res_arr[sep->nr_dcb_creat].in_page_array = NULL;
        sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages = 0;
 
        /* Set the kernel address for first table to be allocated */
-       lli_table_alloc_addr = (u32)(sep->shared_addr +
+       lli_table_alloc_addr = (void *)(sep->shared_addr +
                SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES +
                sep->num_lli_tables_created * sizeof(struct sep_lli_entry) *
                SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP);
@@ -1756,7 +1640,7 @@ static int sep_prepare_input_dma_table(struct sep_device *sep,
                sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages);
 
        current_entry = 0;
-       info_entry_ptr = 0;
+       info_entry_ptr = NULL;
 
        sep_lli_entries = sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages;
 
@@ -1771,7 +1655,7 @@ static int sep_prepare_input_dma_table(struct sep_device *sep,
                        SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP;
 
                if (lli_table_alloc_addr >
-                       ((u32)sep->shared_addr +
+                       ((void *)sep->shared_addr +
                        SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES +
                        SYNCHRONIC_DMA_TABLES_AREA_SIZE_BYTES)) {
 
@@ -1805,7 +1689,7 @@ static int sep_prepare_input_dma_table(struct sep_device *sep,
                        in_lli_table_ptr,
                        &current_entry, &num_entries_in_table, table_data_size);
 
-               if (info_entry_ptr == 0) {
+               if (info_entry_ptr == NULL) {
 
                        /* Set the output parameters to physical addresses */
                        *lli_table_ptr = sep_shared_area_virt_to_bus(sep,
@@ -1822,7 +1706,7 @@ static int sep_prepare_input_dma_table(struct sep_device *sep,
                        info_entry_ptr->bus_address =
                                sep_shared_area_virt_to_bus(sep,
                                                        in_lli_table_ptr);
-                       info_entry_ptr->block_size = 
+                       info_entry_ptr->block_size =
                                ((num_entries_in_table) << 24) |
                                (table_data_size);
                }
@@ -1848,7 +1732,6 @@ end_function_error:
        kfree(sep->dma_res_arr[sep->nr_dcb_creat].in_page_array);
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "sep_prepare_input_dma_table end\n");
        return error;
 
 }
@@ -1886,15 +1769,15 @@ static int sep_construct_dma_tables_from_lli(
        u32     *table_data_size_ptr)
 {
        /* Points to the area where next lli table can be allocated */
-       u32 lli_table_alloc_addr = 0;
+       void *lli_table_alloc_addr = 0;
        /* Input lli table */
-       struct sep_lli_entry *in_lli_table_ptr = 0;
+       struct sep_lli_entry *in_lli_table_ptr = NULL;
        /* Output lli table */
-       struct sep_lli_entry *out_lli_table_ptr = 0;
+       struct sep_lli_entry *out_lli_table_ptr = NULL;
        /* Pointer to the info entry of the table - the last entry */
-       struct sep_lli_entry *info_in_entry_ptr = 0;
+       struct sep_lli_entry *info_in_entry_ptr = NULL;
        /* Pointer to the info entry of the table - the last entry */
-       struct sep_lli_entry *info_out_entry_ptr = 0;
+       struct sep_lli_entry *info_out_entry_ptr = NULL;
        /* Points to the first entry to be processed in the lli_in_array */
        u32 current_in_entry = 0;
        /* Points to the first entry to be processed in the lli_out_array */
@@ -1912,10 +1795,8 @@ static int sep_construct_dma_tables_from_lli(
        /* Number of etnries in the output table */
        u32 num_entries_out_table = 0;
 
-       dev_dbg(&sep->pdev->dev, "sep_construct_dma_tables_from_lli start\n");
-
        /* Initiate to point after the message area */
-       lli_table_alloc_addr = (u32)(sep->shared_addr +
+       lli_table_alloc_addr = (void *)(sep->shared_addr +
                SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES +
                (sep->num_lli_tables_created *
                (sizeof(struct sep_lli_entry) *
@@ -1937,7 +1818,7 @@ static int sep_construct_dma_tables_from_lli(
                /* Check if the DMA table area limit was overrun */
                if ((lli_table_alloc_addr + sizeof(struct sep_lli_entry) *
                        SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP) >
-                       ((u32)sep->shared_addr +
+                       ((void *)sep->shared_addr +
                        SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES +
                        SYNCHRONIC_DMA_TABLES_AREA_SIZE_BYTES)) {
 
@@ -1966,11 +1847,11 @@ static int sep_construct_dma_tables_from_lli(
                        &last_table_flag);
 
                dev_dbg(&sep->pdev->dev,
-                       "in_table_data_size is %x\n",
+                       "construct tables from lli in_table_data_size is %x\n",
                        in_table_data_size);
 
                dev_dbg(&sep->pdev->dev,
-                       "out_table_data_size is %x\n",
+                       "construct tables from lli out_table_data_size is %x\n",
                        out_table_data_size);
 
                table_data_size = in_table_data_size;
@@ -1992,9 +1873,6 @@ static int sep_construct_dma_tables_from_lli(
                                block_size;
                }
 
-               dev_dbg(&sep->pdev->dev, "table_data_size is %x\n",
-                                                       table_data_size);
-
                /* Construct input lli table */
                sep_build_lli_table(sep, &lli_in_array[current_in_entry],
                        in_lli_table_ptr,
@@ -2010,7 +1888,7 @@ static int sep_construct_dma_tables_from_lli(
                        table_data_size);
 
                /* If info entry is null - this is the first table built */
-               if (info_in_entry_ptr == 0) {
+               if (info_in_entry_ptr == NULL) {
                        /* Set the output parameters to physical addresses */
                        *lli_table_in_ptr =
                        sep_shared_area_virt_to_bus(sep, in_lli_table_ptr);
@@ -2091,7 +1969,6 @@ static int sep_construct_dma_tables_from_lli(
        *out_num_entries_ptr,
        *table_data_size_ptr);
 
-       dev_dbg(&sep->pdev->dev, "sep_construct_dma_tables_from_lli end\n");
        return 0;
 }
 
@@ -2133,8 +2010,6 @@ static int sep_prepare_input_output_dma_table(struct sep_device *sep,
        /* Array of pointers of page */
        struct sep_lli_entry *lli_out_array;
 
-       dev_dbg(&sep->pdev->dev, "sep_prepare_input_output_dma_table start\n");
-
        if (data_size == 0) {
                /* Prepare empty table for input and output */
                sep_prepare_empty_lli_table(sep, lli_table_in_ptr,
@@ -2147,8 +2022,8 @@ static int sep_prepare_input_output_dma_table(struct sep_device *sep,
        }
 
        /* Initialize the pages pointers */
-       sep->dma_res_arr[sep->nr_dcb_creat].in_page_array = 0;
-       sep->dma_res_arr[sep->nr_dcb_creat].out_page_array = 0;
+       sep->dma_res_arr[sep->nr_dcb_creat].in_page_array = NULL;
+       sep->dma_res_arr[sep->nr_dcb_creat].out_page_array = NULL;
 
        /* Lock the pages of the buffer and translate them to pages */
        if (is_kva == true) {
@@ -2175,7 +2050,7 @@ static int sep_prepare_input_output_dma_table(struct sep_device *sep,
                error = sep_lock_user_pages(sep, app_virt_in_addr,
                                data_size, &lli_in_array, SEP_DRIVER_IN_FLAG);
                if (error) {
-                       dev_warn(&sep->pdev->dev, 
+                       dev_warn(&sep->pdev->dev,
                                "sep_lock_user_pages for input virtual buffer failed\n");
                        goto end_function;
                }
@@ -2190,7 +2065,7 @@ static int sep_prepare_input_output_dma_table(struct sep_device *sep,
                }
        }
 
-       dev_dbg(&sep->pdev->dev, "sep_in_num_pages is %x\n",
+       dev_dbg(&sep->pdev->dev, "prep input output dma table sep_in_num_pages is %x\n",
                sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages);
        dev_dbg(&sep->pdev->dev, "sep_out_num_pages is %x\n",
                sep->dma_res_arr[sep->nr_dcb_creat].out_num_pages);
@@ -2217,13 +2092,6 @@ static int sep_prepare_input_output_dma_table(struct sep_device *sep,
 update_dcb_counter:
        /* Update DCB counter */
        sep->nr_dcb_creat++;
-       /* Fall through - free the lli entry arrays */
-       dev_dbg(&sep->pdev->dev, "in_num_entries_ptr is %08x\n",
-                                               *in_num_entries_ptr);
-       dev_dbg(&sep->pdev->dev, "out_num_entries_ptr is %08x\n",
-                                               *out_num_entries_ptr);
-       dev_dbg(&sep->pdev->dev, "table_data_size_ptr is %08x\n",
-                                               *table_data_size_ptr);
 
        goto end_function;
 
@@ -2239,8 +2107,6 @@ end_function_free_lli_in:
        kfree(lli_in_array);
 
 end_function:
-       dev_dbg(&sep->pdev->dev,
-               "sep_prepare_input_output_dma_table end result = %d\n", error);
 
        return error;
 
@@ -2263,19 +2129,19 @@ end_function:
  *     are in 32 bit format; the SEP is a 32 bit device
  */
 static int sep_prepare_input_output_dma_table_in_dcb(struct sep_device *sep,
-       u32  app_in_address,
-       u32  app_out_address,
-       u32              data_in_size,
-       u32              block_size,
-       u32              tail_block_size,
-       bool            isapplet,
-       bool            is_kva)
+       unsigned long  app_in_address,
+       unsigned long  app_out_address,
+       u32  data_in_size,
+       u32  block_size,
+       u32  tail_block_size,
+       bool isapplet,
+       bool    is_kva)
 {
        int error = 0;
        /* Size of tail */
        u32 tail_size = 0;
        /* Address of the created DCB table */
-       struct sep_dcblock *dcb_table_ptr = 0;
+       struct sep_dcblock *dcb_table_ptr = NULL;
        /* The physical address of the first input DMA table */
        dma_addr_t in_first_mlli_address = 0;
        /* Number of entries in the first input DMA table */
@@ -2287,8 +2153,6 @@ static int sep_prepare_input_output_dma_table_in_dcb(struct sep_device *sep,
        /* Data in the first input/output table */
        u32  first_data_size = 0;
 
-       dev_dbg(&sep->pdev->dev, "prepare_input_output_dma_table_in_dcb start\n");
-
        if (sep->nr_dcb_creat == SEP_MAX_NUM_SYNC_DMA_OPS) {
                /* No more DCBs to allocate */
                dev_warn(&sep->pdev->dev, "no more DCBs available\n");
@@ -2312,22 +2176,6 @@ static int sep_prepare_input_output_dma_table_in_dcb(struct sep_device *sep,
        dcb_table_ptr->out_vr_tail_pt = 0;
 
        if (isapplet == true) {
-               tail_size = data_in_size % block_size;
-               if (tail_size) {
-                       if (data_in_size < tail_block_size) {
-                               dev_warn(&sep->pdev->dev, "data in size smaller than tail block size\n");
-                               error = -ENOSPC;
-                               goto end_function;
-                       }
-                       if (tail_block_size)
-                               /*
-                                * Case the tail size should be
-                                * bigger than the real block size
-                                */
-                               tail_size = tail_block_size +
-                                       ((data_in_size -
-                                               tail_block_size) % block_size);
-               }
 
                /* Check if there is enough data for DMA operation */
                if (data_in_size < SEP_DRIVER_MIN_DATA_SIZE_PER_TABLE) {
@@ -2348,7 +2196,7 @@ static int sep_prepare_input_output_dma_table_in_dcb(struct sep_device *sep,
                        /* Set the output user-space address for mem2mem op */
                        if (app_out_address)
                                dcb_table_ptr->out_vr_tail_pt =
-                                                       (u32)app_out_address;
+                                                       (aligned_u64)app_out_address;
 
                        /*
                         * Update both data length parameters in order to avoid
@@ -2357,6 +2205,17 @@ static int sep_prepare_input_output_dma_table_in_dcb(struct sep_device *sep,
                         */
                        tail_size = 0x0;
                        data_in_size = 0x0;
+
+               } else {
+                       if (!app_out_address) {
+                               tail_size = data_in_size % block_size;
+                               if (!tail_size) {
+                                       if (tail_block_size == block_size)
+                                               tail_size = block_size;
+                               }
+                       } else {
+                               tail_size = 0;
+                       }
                }
                if (tail_size) {
                        if (is_kva == true) {
@@ -2378,7 +2237,7 @@ static int sep_prepare_input_output_dma_table_in_dcb(struct sep_device *sep,
                                 * according to tail data size
                                 */
                                dcb_table_ptr->out_vr_tail_pt =
-                                       app_out_address + data_in_size
+                                       (aligned_u64)app_out_address + data_in_size
                                        - tail_size;
 
                        /* Save the real tail data size */
@@ -2430,8 +2289,6 @@ static int sep_prepare_input_output_dma_table_in_dcb(struct sep_device *sep,
        dcb_table_ptr->output_mlli_data_size = first_data_size;
 
 end_function:
-       dev_dbg(&sep->pdev->dev,
-               "sep_prepare_input_output_dma_table_in_dcb end\n");
        return error;
 
 }
@@ -2454,16 +2311,13 @@ static int sep_create_sync_dma_tables_handler(struct sep_device *sep,
        /* Command arguments */
        struct bld_syn_tab_struct command_args;
 
-       dev_dbg(&sep->pdev->dev,
-               "sep_create_sync_dma_tables_handler start\n");
-
        if (copy_from_user(&command_args, (void __user *)arg,
                                        sizeof(struct bld_syn_tab_struct))) {
                error = -EFAULT;
                goto end_function;
        }
 
-       dev_dbg(&sep->pdev->dev, "app_in_address is %08llx\n",
+       dev_dbg(&sep->pdev->dev, "create dma table handler app_in_address is %08llx\n",
                                                command_args.app_in_address);
        dev_dbg(&sep->pdev->dev, "app_out_address is %08llx\n",
                                                command_args.app_out_address);
@@ -2479,8 +2333,8 @@ static int sep_create_sync_dma_tables_handler(struct sep_device *sep,
        }
 
        error = sep_prepare_input_output_dma_table_in_dcb(sep,
-               command_args.app_in_address,
-               command_args.app_out_address,
+               (unsigned long)command_args.app_in_address,
+               (unsigned long)command_args.app_out_address,
                command_args.data_in_size,
                command_args.block_size,
                0x0,
@@ -2488,7 +2342,6 @@ static int sep_create_sync_dma_tables_handler(struct sep_device *sep,
                false);
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "sep_create_sync_dma_tables_handler end\n");
        return error;
 }
 
@@ -2507,8 +2360,8 @@ static int sep_free_dma_tables_and_dcb(struct sep_device *sep, bool isapplet,
        int error = 0;
        int error_temp = 0;
        struct sep_dcblock *dcb_table_ptr;
-
-       dev_dbg(&sep->pdev->dev, "sep_free_dma_tables_and_dcb start\n");
+       unsigned long pt_hold;
+       void *tail_pt;
 
        if (isapplet == true) {
                /* Set pointer to first DCB table */
@@ -2519,13 +2372,15 @@ static int sep_free_dma_tables_and_dcb(struct sep_device *sep, bool isapplet,
                /* Go over each DCB and see if tail pointer must be updated */
                for (i = 0; i < sep->nr_dcb_creat; i++, dcb_table_ptr++) {
                        if (dcb_table_ptr->out_vr_tail_pt) {
+                               pt_hold = (unsigned long)dcb_table_ptr->out_vr_tail_pt;
+                               tail_pt = (void *)pt_hold;
                                if (is_kva == true) {
-                                       memcpy((void *)dcb_table_ptr->out_vr_tail_pt,
+                                       memcpy(tail_pt,
                                                dcb_table_ptr->tail_data,
                                                dcb_table_ptr->tail_data_size);
                                } else {
                                        error_temp = copy_to_user(
-                                               (void *)dcb_table_ptr->out_vr_tail_pt,
+                                               tail_pt,
                                                dcb_table_ptr->tail_data,
                                                dcb_table_ptr->tail_data_size);
                                }
@@ -2540,48 +2395,28 @@ static int sep_free_dma_tables_and_dcb(struct sep_device *sep, bool isapplet,
        /* Free the output pages, if any */
        sep_free_dma_table_data_handler(sep);
 
-       dev_dbg(&sep->pdev->dev, "sep_free_dma_tables_and_dcb end\n");
        return error;
 }
 
 /**
  *     sep_get_static_pool_addr_handler - get static pool address
  *     @sep: pointer to struct sep_device
- *     @arg: parameters from user space application
  *
  *     This function sets the bus and virtual addresses of the static pool
- *     and returns the virtual address
  */
-static int sep_get_static_pool_addr_handler(struct sep_device *sep,
-       unsigned long arg)
+static int sep_get_static_pool_addr_handler(struct sep_device *sep)
 {
-       struct stat_pool_addr_struct command_args;
-       u32 *static_pool_addr = 0;
-       unsigned long addr_hold;
-
-       dev_dbg(&sep->pdev->dev, "sep_get_static_pool_addr_handler start\n");
+       u32 *static_pool_addr = NULL;
 
        static_pool_addr = (u32 *)(sep->shared_addr +
                SEP_DRIVER_SYSTEM_RAR_MEMORY_OFFSET_IN_BYTES);
 
        static_pool_addr[0] = SEP_STATIC_POOL_VAL_TOKEN;
-       static_pool_addr[1] = sep->shared_bus +
+       static_pool_addr[1] = (u32)sep->shared_bus +
                SEP_DRIVER_STATIC_AREA_OFFSET_IN_BYTES;
 
-       addr_hold = (unsigned long)
-               (sep->shared_addr + SEP_DRIVER_STATIC_AREA_OFFSET_IN_BYTES);
-       command_args.static_virt_address = (aligned_u64)addr_hold;
-
-       dev_dbg(&sep->pdev->dev, "static pool: physical %x virtual %x\n",
-               (u32)static_pool_addr[1],
-               (u32)command_args.static_virt_address);
-
-       /* Send the parameters to user application */
-       if (copy_to_user((void __user *) arg, &command_args,
-               sizeof(struct stat_pool_addr_struct)))
-               return -EFAULT;
-
-       dev_dbg(&sep->pdev->dev, "sep_get_static_pool_addr_handler end\n");
+       dev_dbg(&sep->pdev->dev, "static pool segment: physical %x\n",
+               (u32)static_pool_addr[1]);
 
        return 0;
 }
@@ -2595,18 +2430,15 @@ static int sep_start_handler(struct sep_device *sep)
        unsigned long reg_val;
        unsigned long error = 0;
 
-       dev_dbg(&sep->pdev->dev, "sep_start_handler start\n");
-
        /* Wait in polling for message from SEP */
-       do
+       do {
                reg_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR3_REG_ADDR);
-       while (!reg_val);
+       while (!reg_val);
 
        /* Check the value */
        if (reg_val == 0x1)
                /* Fatal error - read error status from GPRO */
                error = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR0_REG_ADDR);
-       dev_dbg(&sep->pdev->dev, "sep_start_handler end\n");
        return error;
 }
 
@@ -2665,8 +2497,6 @@ static int sep_init_handler(struct sep_device *sep, unsigned long arg)
        unsigned long addr_hold;
        struct init_struct command_args;
 
-       dev_dbg(&sep->pdev->dev, "sep_init_handler start\n");
-
        /* Make sure that we have not initialized already */
        reg_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR3_REG_ADDR);
 
@@ -2763,11 +2593,10 @@ static int sep_init_handler(struct sep_device *sep, unsigned long arg)
        sep_write_reg(sep, HW_HOST_HOST_SEP_GPR0_REG_ADDR, 0x1);
 
        /* Wait for acknowledge */
-       dev_dbg(&sep->pdev->dev, "init; waiting for msg response\n");
 
-       do
+       do {
                reg_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR3_REG_ADDR);
-       while (!(reg_val & 0xFFFFFFFD));
+       while (!(reg_val & 0xFFFFFFFD));
 
        if (reg_val == 0x1) {
                dev_warn(&sep->pdev->dev, "init; device int failed\n");
@@ -2777,20 +2606,16 @@ static int sep_init_handler(struct sep_device *sep, unsigned long arg)
                dev_warn(&sep->pdev->dev, "init; error is %x\n", error);
                goto end_function;
        }
-       dev_dbg(&sep->pdev->dev, "init; end CC INIT, reg_val is %x\n", reg_val);
-
        /* Signal SEP to zero the GPR3 */
        sep_write_reg(sep, HW_HOST_HOST_SEP_GPR0_REG_ADDR, 0x10);
 
        /* Wait for response */
-       dev_dbg(&sep->pdev->dev, "init; waiting for zero set response\n");
 
-       do
+       do {
                reg_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR3_REG_ADDR);
-       while (reg_val != 0);
+       while (reg_val != 0);
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "init is done\n");
        return error;
 }
 
@@ -2802,8 +2627,6 @@ end_function:
  */
 static int sep_end_transaction_handler(struct sep_device *sep)
 {
-       dev_dbg(&sep->pdev->dev, "sep_end_transaction_handler start\n");
-
        /* Clear the data pool pointers Token */
        memset((void *)(sep->shared_addr +
                SEP_DRIVER_DATA_POOL_ALLOCATION_OFFSET_IN_BYTES),
@@ -2825,14 +2648,11 @@ static int sep_end_transaction_handler(struct sep_device *sep)
        /* Raise event for stuck contextes */
        wake_up(&sep->event);
 
-       dev_dbg(&sep->pdev->dev, "waking up event\n");
-       dev_dbg(&sep->pdev->dev, "sep_end_transaction_handler end\n");
-
        return 0;
 }
 
 /**
- *     sep_prepare_dcb_handler - prepare a control block 
+ *     sep_prepare_dcb_handler - prepare a control block
  *     @sep: pointer to struct sep_device
  *     @arg: pointer to user parameters
  *
@@ -2845,8 +2665,6 @@ static int sep_prepare_dcb_handler(struct sep_device *sep, unsigned long arg)
        /* Command arguments */
        struct build_dcb_struct command_args;
 
-       dev_dbg(&sep->pdev->dev, "sep_prepare_dcb_handler start\n");
-
        /* Get the command arguments */
        if (copy_from_user(&command_args, (void __user *)arg,
                                        sizeof(struct build_dcb_struct))) {
@@ -2854,7 +2672,7 @@ static int sep_prepare_dcb_handler(struct sep_device *sep, unsigned long arg)
                goto end_function;
        }
 
-       dev_dbg(&sep->pdev->dev, "app_in_address is %08llx\n",
+       dev_dbg(&sep->pdev->dev, "prep dcb handler app_in_address is %08llx\n",
                                                command_args.app_in_address);
        dev_dbg(&sep->pdev->dev, "app_out_address is %08llx\n",
                                                command_args.app_out_address);
@@ -2866,12 +2684,12 @@ static int sep_prepare_dcb_handler(struct sep_device *sep, unsigned long arg)
                                                command_args.tail_block_size);
 
        error = sep_prepare_input_output_dma_table_in_dcb(sep,
-               command_args.app_in_address, command_args.app_out_address,
+               (unsigned long)command_args.app_in_address,
+               (unsigned long)command_args.app_out_address,
                command_args.data_in_size, command_args.block_size,
                command_args.tail_block_size, true, false);
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "sep_prepare_dcb_handler end\n");
        return error;
 
 }
@@ -2887,17 +2705,15 @@ static int sep_free_dcb_handler(struct sep_device *sep)
 {
        int error ;
 
-       dev_dbg(&sep->pdev->dev, "sep_prepare_dcb_handler start\n");
-       dev_dbg(&sep->pdev->dev, "num of DCBs %x\n", sep->nr_dcb_creat);
+       dev_dbg(&sep->pdev->dev, "free dcbs num of DCBs %x\n", sep->nr_dcb_creat);
 
        error = sep_free_dma_tables_and_dcb(sep, false, false);
 
-       dev_dbg(&sep->pdev->dev, "sep_free_dcb_handler end\n");
        return error;
 }
 
 /**
- *     sep_rar_prepare_output_msg_handler - prepare an output message 
+ *     sep_rar_prepare_output_msg_handler - prepare an output message
  *     @sep: pointer to struct sep_device
  *     @arg: pointer to user parameters
  *
@@ -2916,8 +2732,6 @@ static int sep_rar_prepare_output_msg_handler(struct sep_device *sep,
        /* Holds the RAR address in the system memory offset */
        u32 *rar_addr;
 
-       dev_dbg(&sep->pdev->dev, "sep_rar_prepare_output_msg_handler start\n");
-
        /* Copy the data */
        if (copy_from_user(&command_args, (void __user *)arg,
                                                sizeof(command_args))) {
@@ -2931,7 +2745,6 @@ static int sep_rar_prepare_output_msg_handler(struct sep_device *sep,
                rar_buf.info.handle = (u32)command_args.rar_handle;
 
                if (rar_handle_to_bus(&rar_buf, 1) != 1) {
-                       dev_dbg(&sep->pdev->dev, "rar_handle_to_bus failure\n");
                        error = -EFAULT;
                        goto end_function;
                }
@@ -2948,7 +2761,6 @@ static int sep_rar_prepare_output_msg_handler(struct sep_device *sep,
        rar_addr[1] = rar_bus;
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "sep_rar_prepare_output_msg_handler start\n");
        return error;
 }
 
@@ -2971,11 +2783,7 @@ static int sep_realloc_ext_cache_handler(struct sep_device *sep,
 
        /* Copy the physical address to the System Area for the SEP */
        system_addr[0] = SEP_EXT_CACHE_ADDR_VAL_TOKEN;
-       dev_dbg(&sep->pdev->dev, "ext cache init; system addr 0 is %x\n",
-                                                       system_addr[0]);
        system_addr[1] = sep->extapp_bus;
-       dev_dbg(&sep->pdev->dev, "ext cache init; system addr 1 is %x\n",
-                                                       system_addr[1]);
 
        return 0;
 }
@@ -2993,39 +2801,13 @@ static long sep_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
        int error = 0;
        struct sep_device *sep = filp->private_data;
 
-       dev_dbg(&sep->pdev->dev, "ioctl start\n");
-
-       dev_dbg(&sep->pdev->dev, "cmd is %x\n", cmd);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCSENDSEPCOMMAND is %x\n", SEP_IOCSENDSEPCOMMAND);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCALLOCDATAPOLL is %x\n", SEP_IOCALLOCDATAPOLL);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCCREATESYMDMATABLE is %x\n", SEP_IOCCREATESYMDMATABLE);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCFREEDMATABLEDATA is %x\n", SEP_IOCFREEDMATABLEDATA);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCSEPSTART is %x\n", SEP_IOCSEPSTART);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCSEPINIT is %x\n", SEP_IOCSEPINIT);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCGETSTATICPOOLADDR is %x\n", SEP_IOCGETSTATICPOOLADDR);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCENDTRANSACTION is %x\n", SEP_IOCENDTRANSACTION);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCREALLOCEXTCACHE is %x\n", SEP_IOCREALLOCEXTCACHE);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCRARPREPAREMESSAGE is %x\n", SEP_IOCRARPREPAREMESSAGE);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCPREPAREDCB is %x\n", SEP_IOCPREPAREDCB);
-       dev_dbg(&sep->pdev->dev,
-               "SEP_IOCFREEDCB is %x\n", SEP_IOCFREEDCB);
+       dev_dbg(&sep->pdev->dev, "ioctl cmd is %x\n", cmd);
 
        /* Make sure we own this device */
        mutex_lock(&sep->sep_mutex);
        if ((current->pid != sep->pid_doing_transaction) &&
                                (sep->pid_doing_transaction != 0)) {
-               dev_dbg(&sep->pdev->dev, "ioctl pid is not owner\n");
+               dev_warn(&sep->pdev->dev, "ioctl pid is not owner\n");
                mutex_unlock(&sep->sep_mutex);
                error = -EACCES;
                goto end_function;
@@ -3074,15 +2856,13 @@ static long sep_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
                        error = -EPERM; /* Not permitted on new chip */
                break;
        case SEP_IOCGETSTATICPOOLADDR:
-               /* Get the physical and virtual addresses of the static pool */
-               error = sep_get_static_pool_addr_handler(sep, arg);
+               /* Inform the SEP the bus address of the static pool */
+               error = sep_get_static_pool_addr_handler(sep);
                break;
        case SEP_IOCENDTRANSACTION:
                error = sep_end_transaction_handler(sep);
                break;
        case SEP_IOCREALLOCEXTCACHE:
-               if (sep->mrst)
-                       error = -ENODEV;
                if (sep->pdev->revision == 0) /* Only for old chip */
                        error = sep_realloc_ext_cache_handler(sep, arg);
                else
@@ -3122,8 +2902,7 @@ static long sep_singleton_ioctl(struct file  *filp, u32 cmd, unsigned long arg)
        long error = 0;
        struct sep_device *sep = filp->private_data;
 
-       dev_dbg(&sep->pdev->dev, "singleton_ioctl start\n");
-       dev_dbg(&sep->pdev->dev, "cmd is %x\n", cmd);
+       dev_dbg(&sep->pdev->dev, "singleton ioctl cmd is %x\n", cmd);
 
        /* Check that the command is for the SEP device */
        if (_IOC_TYPE(cmd) != SEP_IOC_MAGIC_NUMBER) {
@@ -3135,7 +2914,7 @@ static long sep_singleton_ioctl(struct file  *filp, u32 cmd, unsigned long arg)
        mutex_lock(&sep->sep_mutex);
        if ((current->pid != sep->pid_doing_transaction) &&
                                (sep->pid_doing_transaction != 0)) {
-               dev_dbg(&sep->pdev->dev, "singleton ioctl pid is not owner\n");
+               dev_warn(&sep->pdev->dev, "singleton ioctl pid is not owner\n");
                mutex_unlock(&sep->sep_mutex);
                error = -EACCES;
                goto end_function;
@@ -3155,7 +2934,6 @@ static long sep_singleton_ioctl(struct file  *filp, u32 cmd, unsigned long arg)
        }
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "singleton ioctl end\n");
        return error;
 }
 
@@ -3174,7 +2952,6 @@ static long sep_request_daemon_ioctl(struct file *filp, u32 cmd,
        long error;
        struct sep_device *sep = filp->private_data;
 
-       dev_dbg(&sep->pdev->dev, "daemon ioctl: start\n");
        dev_dbg(&sep->pdev->dev, "daemon ioctl: cmd is %x\n", cmd);
 
        /* Check that the command is for SEP device */
@@ -3200,13 +2977,12 @@ static long sep_request_daemon_ioctl(struct file *filp, u32 cmd,
                error = 0;
                break;
        default:
-               dev_dbg(&sep->pdev->dev, "daemon ioctl: no such IOCTL\n");
+               dev_warn(&sep->pdev->dev, "daemon ioctl: no such IOCTL\n");
                error = -ENOTTY;
        }
        mutex_unlock(&sep->ioctl_mutex);
 
 end_function:
-       dev_dbg(&sep->pdev->dev, "daemon ioctl: end\n");
        return error;
 
 }
@@ -3225,7 +3001,6 @@ static irqreturn_t sep_inthandler(int irq, void *dev_id)
 
        /* Read the IRR register to check if this is SEP interrupt */
        reg_val = sep_read_reg(sep, HW_HOST_IRR_REG_ADDR);
-       dev_dbg(&sep->pdev->dev, "SEP Interrupt - reg is %08x\n", reg_val);
 
        if (reg_val & (0x1 << 13)) {
                /* Lock and update the counter of reply messages */
@@ -3262,54 +3037,126 @@ static irqreturn_t sep_inthandler(int irq, void *dev_id)
 }
 
 /**
- *     sep_callback - RAR callback
- *     @sep_context_pointer: pointer to struct sep_device
+ *     sep_reconfig_shared_area - reconfigure shared area
+ *     @sep: pointer to struct sep_device
  *
- *     Function that is called by rar_register when it is ready with
- *     a region (only for Moorestown)
+ *     Reconfig the shared area between HOST and SEP - needed in case
+ *     the DX_CC_Init function was called before OS loading.
  */
-static int sep_callback(unsigned long sep_context_pointer)
+static int sep_reconfig_shared_area(struct sep_device *sep)
 {
-       int error;
-       struct sep_device *sep = (struct sep_device *)sep_context_pointer;
-       dma_addr_t rar_end_address;
+       int ret_val;
 
-       dev_dbg(&sep->pdev->dev, "callback start\n");
+       /* use to limit waiting for SEP */
+       unsigned long end_time;
 
-       error = rar_get_address(RAR_TYPE_IMAGE, &sep->rar_bus,
-                                                       &rar_end_address);
+       /* Send the new SHARED MESSAGE AREA to the SEP */
+       dev_dbg(&sep->pdev->dev, "reconfig shared; sending %08llx to sep\n",
+                               (unsigned long long)sep->shared_bus);
 
-       if (error) {
-               dev_warn(&sep->pdev->dev, "mrst can't get rar region\n");
-               goto end_function;
-       }
+       sep_write_reg(sep, HW_HOST_HOST_SEP_GPR1_REG_ADDR, sep->shared_bus);
+
+       /* Poll for SEP response */
+       ret_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR1_REG_ADDR);
 
-       sep->rar_size = (size_t)(rar_end_address - sep->rar_bus + 1);
+       end_time = jiffies + (WAIT_TIME * HZ);
 
-       if (!request_mem_region(sep->rar_bus, sep->rar_size,
-                                                       "sep_sec_driver")) {
-               dev_warn(&sep->pdev->dev,
-                               "request mem region for mrst failed\n");
-               error = -1;
-               goto end_function;
+       while ((time_before(jiffies, end_time)) && (ret_val != 0xffffffff) &&
+               (ret_val != sep->shared_bus))
+               ret_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR1_REG_ADDR);
+
+       /* Check the return value (register) */
+       if (ret_val != sep->shared_bus) {
+               dev_warn(&sep->pdev->dev, "could not reconfig shared area\n");
+               dev_warn(&sep->pdev->dev, "result was %x\n", ret_val);
+               ret_val = -ENOMEM;
+       } else
+               ret_val = 0;
+
+       dev_dbg(&sep->pdev->dev, "reconfig shared area end\n");
+       return ret_val;
+}
+
+/* File operation for singleton SEP operations */
+static const struct file_operations singleton_file_operations = {
+       .owner = THIS_MODULE,
+       .unlocked_ioctl = sep_singleton_ioctl,
+       .poll = sep_poll,
+       .open = sep_singleton_open,
+       .release = sep_singleton_release,
+       .mmap = sep_mmap,
+};
+
+/* File operation for daemon operations */
+static const struct file_operations daemon_file_operations = {
+       .owner = THIS_MODULE,
+       .unlocked_ioctl = sep_request_daemon_ioctl,
+       .poll = sep_request_daemon_poll,
+       .open = sep_request_daemon_open,
+       .release = sep_request_daemon_release,
+       .mmap = sep_request_daemon_mmap,
+};
+
+/* The files operations structure of the driver */
+static const struct file_operations sep_file_operations = {
+       .owner = THIS_MODULE,
+       .unlocked_ioctl = sep_ioctl,
+       .poll = sep_poll,
+       .open = sep_open,
+       .release = sep_release,
+       .mmap = sep_mmap,
+};
+
+/**
+ *     sep_register_driver_with_fs - register misc devices
+ *     @sep: pointer to struct sep_device
+ *
+ *     This function registers the driver with the file system
+ */
+static int sep_register_driver_with_fs(struct sep_device *sep)
+{
+       int ret_val;
+
+       sep->miscdev_sep.minor = MISC_DYNAMIC_MINOR;
+       sep->miscdev_sep.name = SEP_DEV_NAME;
+       sep->miscdev_sep.fops = &sep_file_operations;
+
+       sep->miscdev_singleton.minor = MISC_DYNAMIC_MINOR;
+       sep->miscdev_singleton.name = SEP_DEV_SINGLETON;
+       sep->miscdev_singleton.fops = &singleton_file_operations;
+
+       sep->miscdev_daemon.minor = MISC_DYNAMIC_MINOR;
+       sep->miscdev_daemon.name = SEP_DEV_DAEMON;
+       sep->miscdev_daemon.fops = &daemon_file_operations;
+
+       ret_val = misc_register(&sep->miscdev_sep);
+       if (ret_val) {
+               dev_warn(&sep->pdev->dev, "misc reg fails for SEP %x\n",
+                       ret_val);
+               return ret_val;
        }
 
-       sep->rar_addr = ioremap_nocache(sep->rar_bus, sep->rar_size);
-       if (!sep->rar_addr) {
-               dev_warn(&sep->pdev->dev,
-                               "ioremap nocache for mrst rar failed\n");
-               error = -ENOMEM;
-               goto end_function;
+       ret_val = misc_register(&sep->miscdev_singleton);
+       if (ret_val) {
+               dev_warn(&sep->pdev->dev, "misc reg fails for sing %x\n",
+                       ret_val);
+               misc_deregister(&sep->miscdev_sep);
+               return ret_val;
        }
-       dev_dbg(&sep->pdev->dev, "rar start is %p, phy is %llx, size is %x\n",
-                       sep->rar_addr, (unsigned long long)sep->rar_bus,
-                       sep->rar_size);
 
-end_function:
-       dev_dbg(&sep->pdev->dev, "callback end\n");
-       return error;
+       ret_val = misc_register(&sep->miscdev_daemon);
+       if (ret_val) {
+               dev_warn(&sep->pdev->dev, "misc reg fails for dmn %x\n",
+                       ret_val);
+               misc_deregister(&sep->miscdev_sep);
+               misc_deregister(&sep->miscdev_singleton);
+
+               return ret_val;
+       }
+       return ret_val;
 }
 
+
 /**
  *     sep_probe - probe a matching PCI device
  *     @pdev: pci_device
@@ -3324,7 +3171,6 @@ static int __devinit sep_probe(struct pci_dev *pdev,
        int error = 0;
        struct sep_device *sep;
 
-       pr_debug("SEP pci probe starting\n");
        if (sep_dev != NULL) {
                dev_warn(&pdev->dev, "only one SEP supported.\n");
                return -EBUSY;
@@ -3342,7 +3188,8 @@ static int __devinit sep_probe(struct pci_dev *pdev,
        if (sep_dev == NULL) {
                dev_warn(&pdev->dev,
                        "can't kmalloc the sep_device structure\n");
-               return -ENOMEM;
+               error = -ENOMEM;
+               goto end_function_disable_device;
        }
 
        /*
@@ -3353,35 +3200,38 @@ static int __devinit sep_probe(struct pci_dev *pdev,
         */
        sep = sep_dev;
 
-       sep->pdev = pdev;
+       sep->pdev = pci_dev_get(pdev);
 
-       if (pdev->device == MRST_PCI_DEVICE_ID)
-               sep->mrst = 1;
+       init_waitqueue_head(&sep->event);
+       init_waitqueue_head(&sep->event_request_daemon);
+       spin_lock_init(&sep->snd_rply_lck);
+       mutex_init(&sep->sep_mutex);
+       mutex_init(&sep->ioctl_mutex);
 
-       dev_dbg(&sep->pdev->dev, "PCI obtained, device being prepared\n");
+       dev_dbg(&sep->pdev->dev, "sep probe: PCI obtained, device being prepared\n");
        dev_dbg(&sep->pdev->dev, "revision is %d\n", sep->pdev->revision);
 
        /* Set up our register area */
        sep->reg_physical_addr = pci_resource_start(sep->pdev, 0);
        if (!sep->reg_physical_addr) {
                dev_warn(&sep->pdev->dev, "Error getting register start\n");
-               pci_dev_put(sep->pdev);
-               return -ENODEV;
+               error = -ENODEV;
+               goto end_function_free_sep_dev;
        }
 
        sep->reg_physical_end = pci_resource_end(sep->pdev, 0);
        if (!sep->reg_physical_end) {
                dev_warn(&sep->pdev->dev, "Error getting register end\n");
-               pci_dev_put(sep->pdev);
-               return -ENODEV;
+               error = -ENODEV;
+               goto end_function_free_sep_dev;
        }
 
        sep->reg_addr = ioremap_nocache(sep->reg_physical_addr,
                (size_t)(sep->reg_physical_end - sep->reg_physical_addr + 1));
        if (!sep->reg_addr) {
                dev_warn(&sep->pdev->dev, "Error getting register virtual\n");
-               pci_dev_put(sep->pdev);
-               return -ENODEV;
+               error = -ENODEV;
+               goto end_function_free_sep_dev;
        }
 
        dev_dbg(&sep->pdev->dev,
@@ -3403,32 +3253,19 @@ static int __devinit sep_probe(struct pci_dev *pdev,
                goto end_function_error;
        }
 
-       /* The next section depends on type of unit */
-       if (sep->mrst) {
-               error = register_rar(RAR_TYPE_IMAGE, &sep_callback,
-                       (unsigned long)sep);
-               if (error) {
-                       dev_dbg(&sep->pdev->dev,
-                               "error register_rar\n");
-                       goto end_function_deallocate_sep_shared_area;
-               }
-       } else {
-               sep->rar_size = FAKE_RAR_SIZE;
-               sep->rar_addr = dma_alloc_coherent(NULL,
-                       sep->rar_size, &sep->rar_bus, GFP_KERNEL);
-               if (sep->rar_addr == NULL) {
-                       dev_warn(&sep->pdev->dev, "can't allocate mfld rar\n");
-                       error = -ENOMEM;
-                       goto end_function_deallocate_sep_shared_area;
-               }
-
-               dev_dbg(&sep->pdev->dev, "rar start is %p, phy is %llx,"
-                       " size is %x\n", sep->rar_addr,
-                       (unsigned long long)sep->rar_bus,
-                       sep->rar_size);
+       sep->rar_size = FAKE_RAR_SIZE;
+       sep->rar_addr = dma_alloc_coherent(&sep->pdev->dev,
+               sep->rar_size, &sep->rar_bus, GFP_KERNEL);
+       if (sep->rar_addr == NULL) {
+               dev_warn(&sep->pdev->dev, "can't allocate mfld rar\n");
+               error = -ENOMEM;
+               goto end_function_deallocate_sep_shared_area;
        }
 
-       dev_dbg(&sep->pdev->dev, "about to write IMR and ICR REG_ADDR\n");
+       dev_dbg(&sep->pdev->dev, "rar start is %p, phy is %llx,"
+               " size is %zx\n", sep->rar_addr,
+               (unsigned long long)sep->rar_bus,
+               sep->rar_size);
 
        /* Clear ICR register */
        sep_write_reg(sep, HW_HOST_ICR_REG_ADDR, 0xFFFFFFFF);
@@ -3436,14 +3273,35 @@ static int __devinit sep_probe(struct pci_dev *pdev,
        /* Set the IMR register - open only GPR 2 */
        sep_write_reg(sep, HW_HOST_IMR_REG_ADDR, (~(0x1 << 13)));
 
-       dev_dbg(&sep->pdev->dev, "about to call request_irq\n");
+       /* Read send/receive counters from SEP */
+       sep->reply_ct = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR2_REG_ADDR);
+       sep->reply_ct &= 0x3FFFFFFF;
+       sep->send_ct = sep->reply_ct;
+
        /* Get the interrupt line */
        error = request_irq(pdev->irq, sep_inthandler, IRQF_SHARED,
                "sep_driver", sep);
 
-       if (!error)
-               goto end_function;
+       if (error)
+               goto end_function_dealloc_rar;
+
+       /* The new chip requires ashared area reconfigure */
+       if (sep->pdev->revision == 4) { /* Only for new chip */
+               error = sep_reconfig_shared_area(sep);
+               if (error)
+                       goto end_function_free_irq;
+       }
+       /* Finally magic up the device nodes */
+       /* Register driver with the fs */
+       error = sep_register_driver_with_fs(sep);
+       if (error == 0)
+               /* Success */
+               return 0;
 
+end_function_free_irq:
+       free_irq(pdev->irq, sep);
+
+end_function_dealloc_rar:
        if (sep->rar_addr)
                dma_free_coherent(&sep->pdev->dev, sep->rar_size,
                        sep->rar_addr, sep->rar_bus);
@@ -3455,15 +3313,37 @@ end_function_deallocate_sep_shared_area:
 
 end_function_error:
        iounmap(sep->reg_addr);
+
+end_function_free_sep_dev:
+       pci_dev_put(sep_dev->pdev);
        kfree(sep_dev);
        sep_dev = NULL;
 
+end_function_disable_device:
+       pci_disable_device(pdev);
+
 end_function:
        return error;
 }
 
+static void sep_remove(struct pci_dev *pdev)
+{
+       struct sep_device *sep = sep_dev;
+
+       /* Unregister from fs */
+       misc_deregister(&sep->miscdev_sep);
+       misc_deregister(&sep->miscdev_singleton);
+       misc_deregister(&sep->miscdev_daemon);
+
+       /* Free the irq */
+       free_irq(sep->pdev->irq, sep);
+
+       /* Free the shared area  */
+       sep_unmap_and_free_shared_area(sep_dev);
+       iounmap((void *) sep_dev->reg_addr);
+}
+
 static DEFINE_PCI_DEVICE_TABLE(sep_pci_id_tbl) = {
-       {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MRST_PCI_DEVICE_ID)},
        {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MFLD_PCI_DEVICE_ID)},
        {0}
 };
@@ -3474,127 +3354,10 @@ MODULE_DEVICE_TABLE(pci, sep_pci_id_tbl);
 static struct pci_driver sep_pci_driver = {
        .name = "sep_sec_driver",
        .id_table = sep_pci_id_tbl,
-       .probe = sep_probe
-       /* FIXME: remove handler */
+       .probe = sep_probe,
+       .remove = sep_remove
 };
 
-/* File operation for singleton SEP operations */
-static const struct file_operations singleton_file_operations = {
-       .owner = THIS_MODULE,
-       .unlocked_ioctl = sep_singleton_ioctl,
-       .poll = sep_poll,
-       .open = sep_singleton_open,
-       .release = sep_singleton_release,
-       .mmap = sep_mmap,
-};
-
-/* File operation for daemon operations */
-static const struct file_operations daemon_file_operations = {
-       .owner = THIS_MODULE,
-       .unlocked_ioctl = sep_request_daemon_ioctl,
-       .poll = sep_request_daemon_poll,
-       .open = sep_request_daemon_open,
-       .release = sep_request_daemon_release,
-       .mmap = sep_request_daemon_mmap,
-};
-
-/* The files operations structure of the driver */
-static const struct file_operations sep_file_operations = {
-       .owner = THIS_MODULE,
-       .unlocked_ioctl = sep_ioctl,
-       .poll = sep_poll,
-       .open = sep_open,
-       .release = sep_release,
-       .mmap = sep_mmap,
-};
-
-/**
- *     sep_reconfig_shared_area - reconfigure shared area
- *     @sep: pointer to struct sep_device
- *
- *     Reconfig the shared area between HOST and SEP - needed in case
- *     the DX_CC_Init function was called before OS loading.
- */
-static int sep_reconfig_shared_area(struct sep_device *sep)
-{
-       int ret_val;
-
-       dev_dbg(&sep->pdev->dev, "reconfig shared area start\n");
-
-       /* Send the new SHARED MESSAGE AREA to the SEP */
-       dev_dbg(&sep->pdev->dev, "sending %08llx to sep\n",
-                               (unsigned long long)sep->shared_bus);
-
-       sep_write_reg(sep, HW_HOST_HOST_SEP_GPR1_REG_ADDR, sep->shared_bus);
-
-       /* Poll for SEP response */
-       ret_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR1_REG_ADDR);
-
-       while (ret_val != 0xffffffff && ret_val != sep->shared_bus)
-               ret_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR1_REG_ADDR);
-
-       /* Check the return value (register) */
-       if (ret_val != sep->shared_bus) {
-               dev_warn(&sep->pdev->dev, "could not reconfig shared area\n");
-               dev_warn(&sep->pdev->dev, "result was %x\n", ret_val);
-               ret_val = -ENOMEM;
-       } else
-               ret_val = 0;
-
-       dev_dbg(&sep->pdev->dev, "reconfig shared area end\n");
-       return ret_val;
-}
-
-/**
- *     sep_register_driver_to_fs - register misc devices
- *     @sep: pointer to struct sep_device
- *
- *     This function registers the driver to the file system
- */
-static int sep_register_driver_to_fs(struct sep_device *sep)
-{
-       int ret_val;
-
-       sep->miscdev_sep.minor = MISC_DYNAMIC_MINOR;
-       sep->miscdev_sep.name = SEP_DEV_NAME;
-       sep->miscdev_sep.fops = &sep_file_operations;
-
-       sep->miscdev_singleton.minor = MISC_DYNAMIC_MINOR;
-       sep->miscdev_singleton.name = SEP_DEV_SINGLETON;
-       sep->miscdev_singleton.fops = &singleton_file_operations;
-
-       sep->miscdev_daemon.minor = MISC_DYNAMIC_MINOR;
-       sep->miscdev_daemon.name = SEP_DEV_DAEMON;
-       sep->miscdev_daemon.fops = &daemon_file_operations;
-
-       ret_val = misc_register(&sep->miscdev_sep);
-       if (ret_val) {
-               dev_warn(&sep->pdev->dev, "misc reg fails for SEP %x\n",
-                       ret_val);
-               return ret_val;
-       }
-
-       ret_val = misc_register(&sep->miscdev_singleton);
-       if (ret_val) {
-               dev_warn(&sep->pdev->dev, "misc reg fails for sing %x\n",
-                       ret_val);
-               misc_deregister(&sep->miscdev_sep);
-               return ret_val;
-       }
-
-       if (!sep->mrst) {
-               ret_val = misc_register(&sep->miscdev_daemon);
-               if (ret_val) {
-                       dev_warn(&sep->pdev->dev, "misc reg fails for dmn %x\n",
-                               ret_val);
-                       misc_deregister(&sep->miscdev_sep);
-                       misc_deregister(&sep->miscdev_singleton);
-
-                       return ret_val;
-               }
-       }
-       return ret_val;
-}
 
 /**
  *     sep_init - init function
@@ -3603,85 +3366,19 @@ static int sep_register_driver_to_fs(struct sep_device *sep)
  */
 static int __init sep_init(void)
 {
-       int ret_val = 0;
-       struct sep_device *sep = NULL;
-
-       pr_debug("SEP driver: Init start\n");
-
-       ret_val = pci_register_driver(&sep_pci_driver);
-       if (ret_val) {
-               pr_debug("sep_driver:sep_driver_to_device failed, ret_val is %d\n",
-                                                               ret_val);
-               goto end_function;
-       }
-
-       sep = sep_dev;
-
-       init_waitqueue_head(&sep->event);
-       init_waitqueue_head(&sep->event_request_daemon);
-       spin_lock_init(&sep->snd_rply_lck);
-       mutex_init(&sep->sep_mutex);
-       mutex_init(&sep->ioctl_mutex);
-
-       /* The new chip requires ashared area reconfigure */
-       if (sep->pdev->revision == 4) { /* Only for new chip */
-               ret_val = sep_reconfig_shared_area(sep);
-               if (ret_val)
-                       goto end_function_unregister_pci;
-       }
-
-       /* Register driver to fs */
-       ret_val = sep_register_driver_to_fs(sep);
-       if (ret_val) {
-               dev_warn(&sep->pdev->dev, "error registering device to file\n");
-               goto end_function_unregister_pci;
-       }
-       goto end_function;
-
-end_function_unregister_pci:
-       pci_unregister_driver(&sep_pci_driver);
-
-end_function:
-       dev_dbg(&sep->pdev->dev, "Init end\n");
-       return ret_val;
+       return pci_register_driver(&sep_pci_driver);
 }
 
 
 /**
- *     sep_exit - called to unload driver 
+ *     sep_exit - called to unload driver
  *
  *     Drop the misc devices then remove and unmap the various resources
  *     that are not released by the driver remove method.
  */
 static void __exit sep_exit(void)
 {
-       struct sep_device *sep;
-
-       sep = sep_dev;
-       pr_debug("Exit start\n");
-
-       /* Unregister from fs */
-       misc_deregister(&sep->miscdev_sep);
-       misc_deregister(&sep->miscdev_singleton);
-       misc_deregister(&sep->miscdev_daemon);
-
-       /* Free the irq */
-       free_irq(sep->pdev->irq, sep);
-
-       /* Unregister the driver */
        pci_unregister_driver(&sep_pci_driver);
-
-       /* Free the shared area  */
-       if (sep_dev) {
-               sep_unmap_and_free_shared_area(sep_dev);
-               dev_dbg(&sep->pdev->dev,
-                       "free pages SEP SHARED AREA\n");
-               iounmap((void *) sep_dev->reg_addr);
-               dev_dbg(&sep->pdev->dev,
-                       "iounmap\n");
-       }
-       pr_debug("release_mem_region\n");
-       pr_debug("Exit end\n");
 }