Browse Source

Linux_SDK_V1.0.2

thead_admin 1 year ago
parent
commit
bf06161d3c

+ 1 - 1
driver/xrp-kernel/xrp_hw_comm.c

@@ -97,7 +97,7 @@ int xrp_set_reset_reg(int dsp_id)
 	uint32_t old_value = __raw_readl(hw_drvdata->sys_regs+XRP_REG_RESET);
 	pr_debug("%s,reset reg:%x\n",__func__,old_value);
 	__raw_writel(old_value^bit_mask,hw_drvdata->sys_regs+XRP_REG_RESET);
-	udelay(10000);
+	udelay(100);
 	__raw_writel(old_value,hw_drvdata->sys_regs+XRP_REG_RESET);
 	mutex_unlock(&hw_drvdata->lock);
 

+ 1 - 2
driver/xrp-kernel/xrp_hw_simple.c

@@ -525,10 +525,9 @@ static irqreturn_t irq_handler(int irq, void *dev_id)
 
 	if(is_expect_irq(hw))
 	{
+		ack_irq(hw);
 		ret = xrp_irq_handler(irq, hw->xrp);
 
-		if (ret == IRQ_HANDLED)
-			ack_irq(hw);
 
 	}
 	else{

+ 5 - 0
driver/xrp-kernel/xrp_kernel_defs.h

@@ -45,6 +45,11 @@
 #define XRP_IOCTL_DMABUF_RELEASE   _IO(XRP_IOCTL_MAGIC, 9)
 
 #define XRP_IOCTL_DMABUF_SYNC  _IO(XRP_IOCTL_MAGIC, 10)
+
+#define XRP_IOCTL_POP_NEW_REPORT  _IO(XRP_IOCTL_MAGIC, 11)
+
+
+#define  SIG_REPORT    (SIGRTMIN+5)
 struct xrp_ioctl_alloc {
 	__u32 size;
 	__u32 align;

+ 14 - 2
driver/xrp-kernel/xrp_kernel_report.h

@@ -29,14 +29,26 @@
 
 // #include "xrp_alloc.h"
 #include <linux/interrupt.h>
+#include "xrp_kernel_defs.h"
+
+#define REPORT_QUEUE_NUM   8
+
+struct xrp_report_ring_buffer{
+    volatile __u32 WR;
+    volatile __u32 RD;
+    volatile bool is_full;
+    __u32  max_item;
+    __u8   data[1];
+};
+
 struct xrp_reporter {
 
     struct fasync_struct *fasync;
 	struct tasklet_struct  report_task;
-	__u64 buffer_virt;
-
+	__u64 buffer_virt; 
 	phys_addr_t buffer_phys;
 	size_t buffer_size;
+    struct xrp_report_ring_buffer  *buffer_list;
 
 };
 

+ 144 - 133
driver/xrp-kernel/xvp_main.c

@@ -56,6 +56,8 @@
 #include <linux/slab.h>
 #include <linux/sort.h>
 #include <linux/timer.h>
+#include <linux/time.h>
+#include <linux/timex.h>
 #include <linux/dma-mapping.h>
 #include <linux/dma-buf.h>
 #include <asm/mman.h>
@@ -704,55 +706,92 @@ static long xrp_ioctl_alloc(struct file *filp,
 	}
 	return 0;
 }
+
+static int report_cnt=0;
 static void xrp_report_tasklet(unsigned long arg)
 {
 	struct xvp *xvp=(struct xvp *)arg;
-		struct xrp_dsp_cmd __iomem *cmd=xvp->comm;
+    struct xrp_dsp_cmd __iomem *cmd=xvp->comm;
 	struct xrp_report_buffer *p_buf = xvp->reporter->buffer_virt;
-	// pr_debug("%s,addr:%lx\n",__func__,arg);
+    struct xrp_report_ring_buffer  *ring_buffer = xvp->reporter->buffer_list;
+    __u32  report_id;
+
 	if(!xvp->reporter->fasync)
 	{
 		pr_debug("%s:fasync is not register in user space\n",__func__);
 		return;
 	}
-	// pr_debug("%s,%d\n",__func__,xvp->reporter->fasync->magic);
-	// if(!xvp->reporter->user_buffer_virt &&
-	// 	!xvp->reporter->buffer_size)
-	// {
-	// 	pr_debug("%s:user_buffer_virt and buffer size is invalid\n",__func__);
-	// 	return;
-	// }
-	// size_t s= xrp_comm_read32(&cmd->report_paylad_size);
+	
+    if((ring_buffer->WR+1)%ring_buffer->max_item == ring_buffer->RD)
+    {
+        /*****if before this flag set ,pop comming, and finish the all sig handler lead no one clear ?? **/
+        // xvp->reporter->buffer_list->is_full =true;
+        pr_err("%s,report queue is full,block the reprot,WR:%d,RD:%d\n",__func__,ring_buffer->WR,ring_buffer->RD);
+        return ;
+    }
 
-	// unsigned int id = xrp_comm_read32(&cmd->report_id);
-	// if(copy_to_user(&p_buf_user->report_id,&id,sizeof(p_buf_user->report_id)));
-	// {
-	// 	pr_debug("%s:copy report id to user fail\n",__func__);
-	// 	return;
-	// }
+    report_id = xrp_comm_read32(&cmd->report_id)&0xffff;
+    // int fd;
+    // fd = xrp_comm_read32(&p_buf->data[8]);
 
-    // if(xvp->reporter->buffer_size>XRP_DSP_CMD_INLINE_DATA_SIZE)
-	// {
-	// 	if(xrp_copy_user_from_phys(xvp,&p_buf_user->data[0],s,xvp->reporter->buffer_phys,XRP_FLAG_READ_WRITE))
-	// 		return;			 
-	// }
-	// else
-	// {
-	// 	char temp_buf[XRP_DSP_CMD_INLINE_DATA_SIZE];
-	// 	xrp_comm_read(&cmd->report_data,temp_buf,s);
-	// 	if(copy_to_user(&p_buf_user->data[0],temp_buf,s))
-	// 	{
-	// 		pr_debug("%s:copy report data to user fail\n",__func__);
-	// 		return;
-	// 	}
-	// }
-	/*****clear report*********************/
-	p_buf->report_id = xrp_comm_read32(&cmd->report_id)&0xffff;
 
-	//xrp_dma_sync_for_cpu(xvp,xvp->reporter->buffer_virt,xvp->reporter->buffer_phys,xvp->reporter->buffer_size,XRP_FLAG_WRITE);	
-	kill_fasync(&(xvp->reporter->fasync), SIGIO, POLL_IN);
-	xrp_comm_write32(&cmd->report_id,0x0);
-    // pr_debug("%s,report_id:%d,report_data:%x\n",__func__,p_buf->report_id,p_buf->data[0]);
+    xrp_comm_write32(&p_buf->report_id,report_id);
+    xrp_comm_read(p_buf,&ring_buffer->data[ring_buffer->WR*xvp->reporter->buffer_size],xvp->reporter->buffer_size);
+    ring_buffer->WR = (ring_buffer->WR+1)%ring_buffer->max_item;
+
+	kill_fasync(&(xvp->reporter->fasync), SIG_REPORT, POLL_IN);
+
+
+    /*******************if  report queue is full block new report************************************************/
+    // if(ring_buffer->WR == ring_buffer->RD)
+    // {
+    //     /*****if before this flag set ,pop comming, and finish the all sig handler lead no one clear ?? **/
+    //     xvp->reporter->buffer_list->is_full =true;
+    //     pr_err("%s,report queue is full,block the reprot\n",__func__);
+    // }else
+    {
+        /*****clear report*********************/
+        xrp_comm_write32(&cmd->report_id,0x0);
+    }
+
+    pr_debug("%s,report_id:%d,report_cnt:%d,WR:%d,RD:%d\n",__func__,p_buf->report_id,++report_cnt,ring_buffer->WR,ring_buffer->RD);
+}
+
+
+static long xrp_pop_report(struct file *filp,
+			                struct xrp_report_buffer __user *p)
+{
+    	struct xvp_file *xvp_file = filp->private_data;
+        struct xvp *xvp = xvp_file->xvp;
+        struct xrp_dsp_cmd __iomem *cmd=xvp->comm;
+        struct xrp_report_ring_buffer  *ring_buffer = xvp->reporter->buffer_list;
+        void* report_buf;
+
+ /*******************if  report queue is empty ,return************************************************/
+        if((ring_buffer->WR == ring_buffer->RD))
+            return -EFAULT;
+
+
+        report_buf = &ring_buffer->data[ring_buffer->RD*xvp->reporter->buffer_size];
+        if(copy_to_user(p, report_buf, xvp->reporter->buffer_size))
+        {
+            pr_debug("%s: copy to user fail\n", __func__);
+            return -EFAULT;
+        }
+ /*******************if  report queue is full ,unblock************************************************/
+        if((ring_buffer->WR+1)%ring_buffer->max_item==ring_buffer->RD)
+        {
+            ring_buffer->RD=(ring_buffer->RD+1)%ring_buffer->max_item;
+            ring_buffer->is_full==false;
+            xrp_comm_write32(&cmd->report_id,0x0);
+            pr_debug("%s: unblock the report,RD:%d\n", __func__,ring_buffer->RD);
+        }
+        else
+        {
+            ring_buffer->RD=(ring_buffer->RD+1)%ring_buffer->max_item;
+        }
+
+        return 0;
 }
 static long xrp_map_phy_to_virt(phys_addr_t paddr,unsigned long size,__u64 *vaddr)
 {
@@ -786,7 +825,6 @@ static long xrp_map_phy_to_virt(phys_addr_t paddr,unsigned long size,__u64 *vadd
 		// else
         {
 				void __iomem *p = ioremap(paddr, size);
-				unsigned long rc;
 
 				if (!p) {
 					pr_debug("%s,couldn't ioremap %pap x 0x%08x\n",__func__,&paddr, (u32)size);
@@ -815,6 +853,7 @@ static long xrp_unmap_phy_to_virt(unsigned long *vaddr,phys_addr_t paddr,unsigne
 		*vaddr=NULL;
 		return 0;
 }
+
 static long xrp_ioctl_alloc_report(struct file *filp,
 			    struct xrp_ioctl_alloc __user *p)
 {
@@ -824,88 +863,77 @@ static long xrp_ioctl_alloc_report(struct file *filp,
 		struct xrp_ioctl_alloc xrp_ioctl_alloc;
 		struct xrp_dsp_cmd __iomem *cmd=xvp->comm;
 		unsigned long vaddr;
+        int  size;
 		long err;
 
-		pr_debug("%s: %p\n", __func__, p);
 		if (copy_from_user(&xrp_ioctl_alloc, p, sizeof(*p)))
 			return -EFAULT;
+
 		pr_debug("%s: virtAddr = %lx.size = %d, align = %x\n", __func__,
 		 		xrp_ioctl_alloc.addr,xrp_ioctl_alloc.size, 
 				xrp_ioctl_alloc.align);
-		// if(NULL == xrp_ioctl_alloc.addr)
-		// {
-		// 	return -EFAULT;
-		// }
+
 		xvp->reporter= kmalloc(sizeof(*(xvp->reporter)), GFP_KERNEL);
 		if (!xvp->reporter)
 			return -EFAULT;
 		xvp->reporter->fasync=NULL;
-		err = xrp_allocate(xvp_file->xvp->pool,
-			xrp_ioctl_alloc.size,
-			xrp_ioctl_alloc.align,
-			&xrp_allocation);
-
-		if (err)
-			return err;
-		xrp_allocation_queue(xvp_file, xrp_allocation);
-
-		vaddr = vm_mmap(filp, 0, xrp_allocation->size,
-							PROT_READ | PROT_WRITE, MAP_SHARED,
-							xrp_allocation_offset(xrp_allocation));
-		xrp_ioctl_alloc.addr=vaddr;		
-		xvp->reporter->buffer_phys = xrp_allocation->start;
-
-		if(xrp_map_phy_to_virt(xvp->reporter->buffer_phys,sizeof(__u32),&xvp->reporter->buffer_virt))
+
+		if (xrp_allocate(xvp_file->xvp->pool,xrp_ioctl_alloc.size,
+                            xrp_ioctl_alloc.align,&xrp_allocation))
+        {
+            goto One_Err;
+        }
+	    xrp_allocation_queue(xvp_file, xrp_allocation);
+        xvp->reporter->buffer_phys = xrp_allocation->start;
+        xvp->reporter->buffer_size = xrp_ioctl_alloc.size;
+		if(xrp_map_phy_to_virt(xvp->reporter->buffer_phys,xrp_ioctl_alloc.size,&xvp->reporter->buffer_virt))
 		{
-			pr_debug("%s: map to kernel virt fail\n", __func__);
-			kfree(xvp->reporter);
-			return -EFAULT;
+			pr_err("%s: map to kernel virt fail\n", __func__);
+			goto Two_Err;
 		}
 
+
+        size = sizeof(struct xrp_report_ring_buffer)+ xrp_ioctl_alloc.size*REPORT_QUEUE_NUM;
+        xvp->reporter->buffer_list = kmalloc(size, GFP_KERNEL);
+
+        if (xvp->reporter->buffer_list == NULL)
+			goto Two_Err;
+
+
+        xvp->reporter->buffer_list->WR=0;
+        xvp->reporter->buffer_list->RD=0;
+        xvp->reporter->buffer_list->is_full = false;
+        xvp->reporter->buffer_list->max_item = REPORT_QUEUE_NUM;
+        report_cnt =0;
 		xrp_comm_write32(&cmd->report_addr, 
 					xrp_translate_to_dsp(&xvp->address_map,xvp->reporter->buffer_phys+sizeof(__u32)));
+
 		unsigned int dsp_addr = xrp_comm_read32(&cmd->report_addr);		
 		pr_debug("%s: alloc_report buffer user virt:%llx,kernel virt:%lx, phys:%llx,dsp_addr:%x,size:%d\n", __func__,
 					vaddr,xvp->reporter->buffer_virt,xvp->reporter->buffer_phys,dsp_addr,xrp_allocation->size);
-		/*alloc report memory for DSP , alloc kernel memory for user get*/
-		// if(xrp_ioctl_alloc.size>XRP_DSP_CMD_INLINE_DATA_SIZE)
-		// {
-
-		// 	err = xrp_allocate(xvp_file->xvp->pool,
-		// 			xrp_ioctl_alloc.size,
-		// 			xrp_ioctl_alloc.align,
-		// 			&xrp_allocation);
-		// 	if (err)
-		// 		return err;
-
-		// 	// xrp_allocation_queue(xvp_file, xrp_allocation);
-		// 	xvp->reporter->buffer_phys = xrp_allocation->start;
-		// 	xrp_comm_write32(&cmd->report_addr, 
-		// 				xrp_translate_to_dsp(&xvp->address_map,xvp->reporter->buffer_phys));
-		// 	// vaddr = vm_mmap(filp, 0, xrp_allocation->size,
-		// 	// PROT_READ | PROT_WRITE, MAP_SHARED,
-		// 	// xrp_allocation_offset(xrp_allocation));
-		// 	// xrp_ioctl_alloc.addr=vaddr;
-		// 	pr_debug("%s: kernel bufdfer:%lx\n", __func__, xvp->reporter->buffer_phys);
-		// }
-		// else{
-		// 	xvp->reporter->buffer_phys = NULL;
-		// }
-        /*save the user addr ,which kernel copy the report to */
-		// xvp->reporter->user_buffer_virt = xrp_ioctl_alloc.addr;	
-		xvp->reporter->buffer_size = xrp_ioctl_alloc.size;
+
+
 		xrp_comm_write32(&cmd->report_buffer_size,xvp->reporter->buffer_size);
+		xrp_comm_write32(&cmd->report_paylad_size,xvp->reporter->buffer_size);
 		xrp_comm_write32(&cmd->report_status,XRP_DSP_REPORT_WORKING);
 		xrp_comm_write32(&cmd->report_id,0);
 		tasklet_init(&xvp->reporter->report_task,xrp_report_tasklet,(unsigned long)xvp);
 		if (copy_to_user(p, &xrp_ioctl_alloc, sizeof(*p))) {
-			vm_munmap(vaddr, xrp_ioctl_alloc.size);
-			kfree(xvp->reporter);
 			pr_debug("%s: copy to user fail\n", __func__);
-			return -EFAULT;
+			goto Thr_Err;
 		}
-		pr_debug("%s: alloc_report %lx end\n", __func__,xvp);
+
 	return 0;
+Thr_Err:
+    kfree(xvp->reporter->buffer_list);
+    xvp->reporter->buffer_list = NULL;
+Two_Err:
+    xrp_allocation_put(xrp_allocation);
+
+One_Err:
+    kfree(xvp->reporter);
+    xvp->reporter == NULL;
+    return -EFAULT;
 }
 
 static int xrp_report_fasync(int fd, struct file *filp, int on){
@@ -942,47 +970,22 @@ static long xrp_ioctl_release_report(struct file *filp,
 	struct vm_area_struct *vma;
 	unsigned long start;
 	struct xrp_dsp_cmd __iomem *cmd=xvp->comm;
+	struct xrp_allocation *xrp_allocation;
+
+    if(xvp->reporter==NULL)
+        return 0;
 
 	tasklet_kill(&xvp->reporter->report_task);
 	xrp_comm_write32(&cmd->report_status,XRP_DSP_REPORT_INVALID);
 
 	if (copy_from_user(&xrp_ioctl_alloc, p, sizeof(*p)))
-	return -EFAULT;
-
-	start = xrp_ioctl_alloc.addr;
-	pr_debug("%s: virt_addr = 0x%08lx\n", __func__, start);
+	    return -EFAULT;
 
-    #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
-	down_read(&mm->mmap_sem);
-	#else
-	down_read(&mm->mmap_lock);
-	#endif
-	vma = find_vma(mm, start);
-
-	if (vma && vma->vm_file == filp &&
-		vma->vm_start <= start && start < vma->vm_end) {
-		size_t size;
-
-		start = vma->vm_start;
-		size = vma->vm_end - vma->vm_start;
-        #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
-		up_read(&mm->mmap_sem);
-		#else
-		up_read(&mm->mmap_lock);		
-		#endif
-		pr_debug("%s: 0x%lx x %zu\n", __func__, start, size);
-		vm_munmap(start, size);
-	}
-	else{
-		pr_debug("%s: no vma/bad vma for vaddr = 0x%08lx\n", __func__, start);
-        #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
-		up_read(&mm->mmap_sem);
-		#else
-		up_read(&mm->mmap_lock);		
-		#endif
-		return -EINVAL;
-	}
+    xrp_allocation = xrp_allocation_dequeue(xvp_file,xvp->reporter->buffer_phys,xvp->reporter->buffer_size);
 
+    xrp_allocation_put(xrp_allocation);
+    if(xvp->reporter->buffer_list)
+        kfree(xvp->reporter->buffer_list);
 	xrp_report_fasync_release(filp);	
 	kfree(xvp->reporter);
 	xvp->reporter =NULL;
@@ -2402,20 +2405,21 @@ static struct xrp_dma_buf_item * xrp_search_dma_buf( struct list_head *list,int
 }
 
 static long xrp_ioctl_dma_buf_release(struct file *filp,
-			                        int __user *p)
+			                       struct xrp_dma_buf __user *p)
 {
     int fd;
     struct xvp_file *xvp_file = filp->private_data;
 	struct xvp *xvp = xvp_file->xvp;
     struct dma_buf *dmabuf = NULL;
+    struct xrp_dma_buf  user_param;
     struct xrp_dma_buf_item *dma_buf_item=NULL;
     struct xrp_dma_buf_item *loop,*temp;
     
-    if (copy_from_user(&fd, p, sizeof(*p)))
+    if (copy_from_user(&user_param, p, sizeof(*p)))
     {
 		return -EFAULT;
     }
-
+    fd = user_param.fd;
     // dmabuf = dma_buf_get(fd);
     // spin_lock(&xrp_dma_buf_lock);
     // list_for_each_entry_safe(loop, temp, &xvp->dma_buf_list, link)
@@ -2436,7 +2440,7 @@ static long xrp_ioctl_dma_buf_release(struct file *filp,
     {
         return -EFAULT;
     }
-    
+    vm_munmap(user_param.addr , user_param.size);
     dma_buf_unmap_attachment(dma_buf_item->attachment, dma_buf_item->sgt, DMA_BIDIRECTIONAL);
     dma_buf_detach(dma_buf_item->dmabuf, dma_buf_item->attachment);
     dma_buf_put(dma_buf_item->dmabuf);
@@ -2520,12 +2524,16 @@ static long xvp_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
         break;
     case XRP_IOCTL_DMABUF_RELEASE:
         retval = xrp_ioctl_dma_buf_release(filp,
-                                    (int __user *)arg);
+                    ( struct xrp_dma_buf  __user *)arg);
         break;
     case XRP_IOCTL_DMABUF_SYNC:
         retval = xrp_ioctl_dma_buf_sync(filp,
                     (struct xrp_dma_buf __user *)arg);
         break;
+    case XRP_IOCTL_POP_NEW_REPORT:
+         retval = xrp_pop_report(filp,
+                    (struct xrp_report_buffer __user *)arg);
+        break;
 	default:
 		retval = -EINVAL;
 		break;
@@ -2716,9 +2724,10 @@ static int xrp_boot_firmware(struct xvp *xvp)
             }
         }
         xrp_reset_dsp(xvp);
+
+	    xrp_release_dsp(xvp);
     }
 
-	xrp_release_dsp(xvp);
 //#endif
 	if (loopback < LOOPBACK_NOIO) {
 		ret = xrp_synchronize(xvp);
@@ -2754,6 +2763,8 @@ int xrp_runtime_suspend(struct device *dev)
 	struct xvp *xvp = dev_get_drvdata(dev);
 
 	xrp_halt_dsp(xvp);
+    /*****WR to make sure DSP is in idle*****/
+    udelay(1000);
     xrp_reset_dsp(xvp);
 	xvp_disable_dsp(xvp);
     // release_firmware(xvp->firmware);

+ 14 - 12
driver/xrp-user/dsp-ps/csi_dsp_core.c

@@ -892,7 +892,9 @@ int csi_dsp_task_release_request(struct csi_sw_task_req*  req)
         {
             for(plane_idx =0 ;plane_idx<req->buffers[buf_idx].plane_count;plane_idx++)
             {
-                 xrp_release_dma_buf(task->instance->device,req->buffers[buf_idx].planes[plane_idx].fd,&status);
+                 xrp_release_dma_buf(task->instance->device,req->buffers[buf_idx].planes[plane_idx].fd,
+                                                            req->buffers[buf_idx].planes[plane_idx].buf_vir,
+                                                            req->buffers[buf_idx].planes[plane_idx].size,&status);
             }
         }
         else
@@ -1030,7 +1032,7 @@ int csi_dsp_task_create_buffer(void * task_ctx,struct csi_dsp_buffer * buffer)
                 err_2:
                     for(j=0;j<i;j++)
                     {
-                            xrp_release_dma_buf(task->instance->device,buffer->planes[i].fd,&status);
+                            xrp_release_dma_buf(task->instance->device,buffer->planes[i].fd,buffer->planes[i].buf_vir,buffer->planes[i].size,&status);
                     }
                     return -1;
          default:
@@ -1078,7 +1080,7 @@ int csi_dsp_task_free_buffer(void * task_ctx,struct csi_dsp_buffer * buffer)
          case CSI_DSP_BUF_TYPE_DMA_BUF_IMPORT:
                 for(i=0;i<buffer->plane_count;i++)
                 {
-                    xrp_release_dma_buf(task->instance->device,buffer->planes[i].fd,&status);
+                    xrp_release_dma_buf(task->instance->device,buffer->planes[i].fd,buffer->planes[i].buf_vir,buffer->planes[i].size,&status);
                     if(status != XRP_STATUS_SUCCESS)
                     {
                         DSP_PRINT(WARNING,"ERR DMA Buffrs(%d) Release fail\n",buffer->planes[i].fd);
@@ -1180,7 +1182,7 @@ int csi_dsp_request_add_buffer(struct csi_sw_task_req* req,struct csi_dsp_buffer
                 err_2:
                     for(j=0;j<i;j++)
                     {
-                        xrp_release_dma_buf(task->instance->device,buffer->planes[i].fd,&status);
+                        xrp_release_dma_buf(task->instance->device,buffer->planes[i].fd,buffer->planes[i].buf_vir,buffer->planes[i].size,&status);
                     }
                     return -1;
          case CSI_DSP_BUF_ALLOC_APP:
@@ -1267,10 +1269,10 @@ int csi_dsp_request_enqueue(struct csi_sw_task_req* req)
 		return -1;
     }
 
-    for(loop =0;loop<req->buffer_num;loop++)
-    {
-        csi_dsp_buf_flush(task->instance->device,&req->buffers[loop]);
-    }
+    // for(loop =0;loop<req->buffer_num;loop++)
+    // {
+    //     csi_dsp_buf_flush(task->instance->device,&req->buffers[loop]);
+    // }
 
 	xrp_enqueue_command(task->queue, req, sizeof(struct csi_sw_task_req),
 			    &event_item->req_status, sizeof(event_item->req_status),
@@ -1334,10 +1336,10 @@ struct csi_sw_task_req*  csi_dsp_request_dequeue(void *task_ctx)
     free(evts);
     free(item);
 
-    for(loop =0;loop<req->buffer_num;loop++)
-    {
-        csi_dsp_buf_flush(task->instance->device,&req->buffers[loop]);
-    }
+    // for(loop =0;loop<req->buffer_num;loop++)
+    // {
+    //     csi_dsp_buf_flush(task->instance->device,&req->buffers[loop]);
+    // }
 
     DSP_PRINT(DEBUG,"Req %d is deuque \n",req->request_id);
     return req;

+ 2 - 2
driver/xrp-user/dsp-ps/dsp_common.c

@@ -18,7 +18,7 @@
 
 #include "dsp_common.h"
 
-int log_level = CSI_DSP_LOG_INFO;
+int dsp_log_level = CSI_DSP_LOG_INFO;
 int pid = 0;
 
 
@@ -41,6 +41,6 @@ static int getLogLevel()
 
 void dsp_InitEnv()
 {
-    log_level = getLogLevel();
+    dsp_log_level = getLogLevel();
 
 }

+ 1 - 1
driver/xrp-user/include/csi_dsp_api.h

@@ -224,7 +224,7 @@ int csi_dsp_task_release_request(struct csi_sw_task_req* req);
 
 
 int csi_dsp_task_update_backend_buf(void *task_ctx,struct csi_dsp_task_be_para* config_para);
-int csi_dsp_test_config(void* dsp ,struct csi_dsp_ip_test_par* config_para,void* buf);
+// int csi_dsp_test_config(void* dsp ,struct csi_dsp_ip_test_par* config_para,void* buf);
 #ifdef __cplusplus
 }
 #endif

+ 6 - 0
driver/xrp-user/include/csi_dsp_task_defs.h

@@ -92,6 +92,12 @@ typedef enum{
   CSI_DSP_REPORT_HEARTBEAT_ERR,
   CSI_DSP_HW_FRAME_DROP,
   CSI_DSP_REPORT_EXRA_PARAM,
+  CSI_DSP_REPORT_HW_ERROR,
+  CSI_DSP_REPORT_HW_VIPRE_NM_OVERFLOW_FLOW,
+  CSI_DSP_REPORT_HW_VIPRE_FIFO_ERROR,
+  CSI_DSP_REPORT_HW_VIPRE_BUS_ERROR,
+  CSI_DSP_REPORT_HW_ERROR_END,
+  CSI_DSP_REPORT_MAX
 }csi_dsp_report_e;
 
 typedef struct dsp_frame{

+ 5 - 3
driver/xrp-user/include/dsp_common.h

@@ -50,9 +50,11 @@
 
 #define DSP_PRINT(level, ...) \
     { \
-        if (log_level >= CSI_DSP_LOG_##level) \
+        if (dsp_log_level >= CSI_DSP_LOG_##level) \
         { \
-            printf("CSI_DSP[%d] %s,(%s,%d): ", pid, #level,__FUNCTION__,__LINE__);  \
+            struct timeval ts; \
+            gettimeofday(&ts, 0); \
+            printf("[%ld.%06ld] CSI_DSP[%d] %s,(%s,%d): ",ts.tv_sec, ts.tv_usec,pid, #level,__FUNCTION__,__LINE__);  \
             printf(__VA_ARGS__); \
         } \
     }
@@ -83,7 +85,7 @@ typedef enum log_level
     CSI_DSP_LOG_MAX
 } csi_dsp_log_level;
 
-extern int log_level;
+extern int dsp_log_level;
 extern int pid;
 
 void dsp_InitEnv();

+ 1 - 1
driver/xrp-user/include/xrp_api.h

@@ -490,7 +490,7 @@ int xrp_release_reporter(struct xrp_device *device,struct xrp_report *report);
 void xrp_import_dma_buf(struct xrp_device *device, int fd,enum xrp_access_flags flag ,uint64_t *phy_addr,
                                 uint64_t *user_addr,size_t* size,enum xrp_status *status);
 
-void xrp_release_dma_buf(struct xrp_device *device, int fd,enum xrp_status *status);
+void xrp_release_dma_buf(struct xrp_device *device, int fd,uint64_t user_addr,size_t size,enum xrp_status *status);
 
 void xrp_flush_dma_buf(struct xrp_device *device, int fd,enum xrp_access_flags flag ,enum xrp_status *status);
 /*!

+ 95 - 32
driver/xrp-user/xrp-host/hosted/xrp_linux.c

@@ -20,7 +20,7 @@
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-
+#define _GNU_SOURCE
 #include <fcntl.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -38,6 +38,7 @@
 #include "xrp_kernel_defs.h"
 #include "xrp_report.h"
 #include "dsp_common.h"
+// #include "csi_dsp_task_defs.h"
 struct xrp_request {
 	struct xrp_queue_item q;
 	void *in_data;
@@ -257,19 +258,81 @@ void xrp_enqueue_command(struct xrp_queue *queue,
 }
 
 static struct xrp_report *reporter;
+static int report_cnt =0;
 
-void xrp_reporter_sig_handler()
+static void xrp_prcoess_report(struct xrp_report *reporter)
 {
-	// printf("%s\n",__func__);
+
 	struct xrp_report_buffer *report_buffer;
+    // struct timeval start_time,mid_time,current_time;
 	if(!reporter || !reporter->report_buf)
 	{
 		return;
 	}
-	report_buffer = (struct xrp_report_buffer *)reporter->report_buf;
-	// printf("buffer:%lx,id:%d,data:%x,%x,%x,%x\n",report_buffer,report_buffer->report_id,report_buffer->data[0],report_buffer->data[1],report_buffer->data[2],report_buffer->data[3]);
 
-	xrp_process_report(&reporter->list,report_buffer->data,report_buffer->report_id);
+	report_buffer = (struct xrp_report_buffer  *)reporter->report_buf;
+    // gettimeofday(&start_time, 0);
+    while(ioctl(reporter->device->impl.fd, XRP_IOCTL_POP_NEW_REPORT,report_buffer)==0)
+    {
+    
+        // csi_dsp_report_item_t * item = (csi_dsp_report_item_t *)report_buffer->data;
+        // gettimeofday(&mid_time, 0);
+        xrp_process_report(&reporter->list,report_buffer->data,report_buffer->report_id);
+        // gettimeofday(&current_time, 0);
+        report_cnt++;
+        // printf("report_cnt:%d,report %d,process time:(%ld s,%ld us,delta:%ldus),callback:%ldus\n",report_cnt,report_buffer->report_id,
+        //                                start_time.tv_sec,start_time.tv_usec,
+        //                                (current_time.tv_sec-start_time.tv_sec)*1000000+(current_time.tv_usec-start_time.tv_usec),
+        //                                (current_time.tv_sec-mid_time.tv_sec)*1000000+(current_time.tv_usec-mid_time.tv_usec));
+        DSP_PRINT(DEBUG,"report_cnt:%d,report %d\n",report_cnt,report_buffer->report_id);
+    }
+}
+static void xrp_reporter_sig_handler()
+{
+   if(!reporter)
+   {
+        return;
+   }
+   reporter->process_sig =1;
+
+}
+static void *xrp_report_thread(void *p)
+{
+    sigset_t   waitset,oldset;
+
+    struct xrp_report * report_handler =(struct xrp_report *) p;
+    if(report_handler == NULL)
+    {
+        DSP_PRINT(WARNING,"report is not created\n");
+        return NULL;
+    }
+    report_cnt =0;
+    sigemptyset(&waitset);
+    sigaddset(&waitset, SIG_REPORT);
+
+	signal(SIG_REPORT, xrp_reporter_sig_handler); /* sigaction() is better */
+    struct f_owner_ex  owner_ex;
+    owner_ex.pid = gettid();//syscall(SYS_gettid);
+    owner_ex.type = F_OWNER_TID;
+	fcntl(report_handler->device->impl.fd,F_SETOWN_EX, &owner_ex);
+	int oflags = fcntl(report_handler->device->impl.fd, F_GETFL);
+	fcntl(report_handler->device->impl.fd, F_SETFL, oflags | FASYNC);
+    fcntl(report_handler->device->impl.fd, F_SETSIG, SIG_REPORT);
+    DSP_PRINT(INFO,"report thread runing....\n");
+    while(1)
+    {
+        sigprocmask(SIG_BLOCK, &waitset,&oldset);
+        if(report_handler->process_sig)
+        {
+            xrp_prcoess_report(report_handler);
+            report_handler->process_sig = 0;
+        }
+        sigsuspend(&oldset);
+        sigprocmask(SIG_UNBLOCK, &waitset,NULL); 
+
+    }
+     DSP_PRINT(INFO,"report thread exit\n");
+     return NULL;
 }
 
 
@@ -279,17 +342,14 @@ int xrp_add_report_item_with_id(struct xrp_report *report,
 								void* context,
 								size_t data_size)
 {
-	// int id;
-	// // set_status(status, XRP_STATUS_SUCCESS);
-	// id =xrp_alloc_report_id(&report->list);
+
 	if(report_id<0 || !report)
 	{
-		// set_status(status, XRP_STATUS_FAILURE);
 		return -1;
 	}
 	if(data_size>report->buf_size)
 	{
-		//realloc()
+
 		DSP_PRINT(WARNING,"report instance size %d is exceed limit %d\n",data_size,report->buf_size);
 		// set_status(status, XRP_STATUS_FAILURE);
 		return -1;
@@ -333,8 +393,6 @@ int xrp_add_report_item(struct xrp_report *report,
 }
 
 
-
-
 void xrp_remove_report_item(struct xrp_report *report,int report_id)
 {
 	int id;
@@ -348,13 +406,7 @@ void xrp_impl_create_report(struct xrp_device *device,
 				size_t size,
 			    enum xrp_status *status)
 {
-	// char *report_buf = malloc(size+4);
-	// if(!report_buf)
-	// {
-	// 	set_status(status, XRP_STATUS_FAILURE);
-	// 	return;
-	// }
-	
+    sigset_t bset,oset;
 	struct xrp_ioctl_alloc ioctl_alloc = {
 		.addr = (uintptr_t)NULL,
 		.size = size,
@@ -369,21 +421,22 @@ void xrp_impl_create_report(struct xrp_device *device,
 		set_status(status, XRP_STATUS_FAILURE);
 		return;
 	}
-	if(ioctl_alloc.addr ==NULL)
-	{
-		DSP_PRINT(INFO,"alloc report buffer fail\n");
+
+	report->report_buf = malloc(size);
+    if(report->report_buf ==NULL)
+    {
         set_status(status, XRP_STATUS_FAILURE);
-        return ;
-	}
-	report->report_buf = (void *)(uintptr_t)ioctl_alloc.addr;
+		return;
+    }
 	// printf("buf:%lx,report:x\n",ioctl_alloc.addr,report);
 	report->buf_size = size;
 	report->list.queue.head=NULL;
+    report->process_sig =0;
+
 	reporter=report;
-	signal(SIGIO, xrp_reporter_sig_handler); /* sigaction() is better */
-	fcntl(report->device->impl.fd, F_SETOWN, getpid());
-	int oflags = fcntl(report->device->impl.fd, F_GETFL);
-	fcntl(report->device->impl.fd, F_SETFL, oflags | FASYNC);
+
+    xrp_thread_create(&report->report_thread, NULL, xrp_report_thread, report);
+
 	set_status(status, XRP_STATUS_SUCCESS);
 	DSP_PRINT(INFO,"buf:%lx,user space report create\n",ioctl_alloc.addr);
 }
@@ -400,6 +453,12 @@ void xrp_impl_release_report(struct xrp_device *device,
 		set_status(status, XRP_STATUS_FAILURE);
 		return;
 	}
+    xrp_thread_cancel(&report->report_thread);
+    if(!xrp_thread_join(&report->report_thread))
+    {
+        DSP_PRINT(INFO,"report_thread release done\n");
+    }
+    free(report->report_buf);
 	report->report_buf=NULL;
     xrp_release_device(device);
 	set_status(status, XRP_STATUS_SUCCESS);
@@ -435,14 +494,18 @@ void xrp_import_dma_buf(struct xrp_device *device, int fd,enum xrp_access_flags
         return;
 }
 
-void xrp_release_dma_buf(struct xrp_device *device, int fd,enum xrp_status *status)
+void xrp_release_dma_buf(struct xrp_device *device, int fd,uint64_t user_addr,size_t size,enum xrp_status *status)
 {
+        struct xrp_dma_buf dma_buf;
         if(fd < 0)
         {
             set_status(status, XRP_STATUS_FAILURE);
             return;
         }
-        int ret = ioctl(device->impl.fd, XRP_IOCTL_DMABUF_RELEASE,&fd);
+        dma_buf.fd = fd;
+        dma_buf.addr = user_addr;
+        dma_buf.size = size;
+        int ret = ioctl(device->impl.fd, XRP_IOCTL_DMABUF_RELEASE,&dma_buf);
 
         if (ret < 0) {
             set_status(status, XRP_STATUS_FAILURE);

+ 4 - 0
driver/xrp-user/xrp-host/thread-pthread/xrp_thread_impl.h

@@ -104,4 +104,8 @@ static inline int xrp_thread_detach(xrp_thread *thread)
 	return pthread_detach(*thread) == 0;
 }
 
+static inline int xrp_thread_cancel(xrp_thread *thread)
+{
+    return pthread_cancel(*thread) == 0;
+}
 #endif

+ 3 - 2
driver/xrp-user/xrp-host/xrp_host_common.h

@@ -95,11 +95,12 @@ struct xrp_report{
 
 	struct xrp_refcounted ref;
 	struct xrp_device *device;
-	struct xrp_report_list list;
-	
+	struct xrp_report_list list;	
 	void *report_buf;
 
 	int  buf_size;
+    xrp_thread report_thread;
+    int  process_sig;
 
 };
 

+ 2 - 3
driver/xrp-user/xrp-host/xrp_report.c

@@ -45,10 +45,9 @@ void xrp_process_report(struct xrp_report_list *list,void* data,unsigned int id)
 		(report_item->size&&!report_item->buf)){
 		return;
 	}
-	memcpy(report_item->buf,data,report_item->size);
-    int *ptr=report_item->buf;
+	// memcpy(report_item->buf,data,report_item->size);
   
-	report_item->fn(report_item->context,report_item->buf);
+	report_item->fn(report_item->context,data);
 }
 
 int xrp_add_report(struct xrp_report_list *list,

BIN
firmware/xrp0.elf


BIN
firmware/xrp0_fl.elf


BIN
firmware/xrp0_pil.elf


BIN
firmware/xrp1.elf


BIN
firmware/xrp1_fl.elf


BIN
firmware/xrp1_pil.elf


+ 1 - 5
test/drv_test/test_post_process_dma_buf.cpp

@@ -72,14 +72,10 @@ TEST_GROUP(DspPostProcessTestDmaBuf)
         return -1;
     }
     printf("%s,export dma buf @fd:%x\n",__FUNCTION__,params->fd);
-    // if(VMEM_mmap(mem_allocor,params))
-    // {
-    //     return -1;
-    // }
-    // printf("%s,mmap dma buf addr:%lx\n",__FUNCTION__,params->vir_address);
     return 0;
 
   }  
+  
   int releaseDmaBuffer(VmemParams *params)
   {
       VMEM_free(mem_allocor, params);