change rga mmu remap index method
authorzsq <zsq@rock-chips.com>
Sun, 30 Dec 2012 02:36:44 +0000 (10:36 +0800)
committerzsq <zsq@rock-chips.com>
Sun, 30 Dec 2012 02:36:44 +0000 (10:36 +0800)
drivers/video/rockchip/rga/rga.h
drivers/video/rockchip/rga/rga_drv.c
drivers/video/rockchip/rga/rga_mmu_info.c

index bbf5fa94833deb0a7f57ca3096dc6273a68fbb5b..241d28bc120ca0edcdb738707aaece110ff2e9ba 100755 (executable)
@@ -354,10 +354,11 @@ struct rga_reg {
        struct list_head        status_link;            /* link to register set list */\r
        uint32_t  sys_reg[RGA_REG_CTRL_LEN];\r
     uint32_t  cmd_reg[RGA_REG_CMD_LEN];\r
+    \r
     uint32_t *MMU_base;\r
-    //atomic_t int_enable;\r
-        \r
-    //struct rga_req req;\r
+    //atomic_t int_enable;   \r
+\r
+    //struct rga_req      req;\r
 };\r
 \r
 \r
@@ -372,6 +373,7 @@ typedef struct rga_service_info {
     atomic_t           total_running;\r
     \r
     struct rga_reg        *reg;\r
+    \r
     uint32_t            cmd_buff[28*8];/* cmd_buff for rga */\r
     uint32_t            *pre_scale_buf;\r
     atomic_t            int_disable;     /* 0 int enable 1 int disable  */\r
@@ -381,6 +383,8 @@ typedef struct rga_service_info {
     atomic_t            rga_working;\r
     bool                enable;\r
 \r
+    //struct rga_req      req[10];\r
+\r
     struct mutex       mutex;  // mutex\r
 } rga_service_info;\r
 \r
index 38d0683a4ee0f3b4d41e230385f4496ca5cc4a67..64fe0ce4a4968fd41ece9c54d0bf68c17029d04d 100755 (executable)
@@ -115,6 +115,30 @@ static void rga_try_set_reg(void);
 #define INFO(format, args...)\r
 #endif\r
 \r
+#if RGA_TEST\r
+static void print_info(struct rga_req *req)\r
+{\r
+    printk("src : yrgb_addr = %.8x, src.uv_addr = %.8x, src.v_addr = %.8x, format = %d\n",\r
+            req->src.yrgb_addr, req->src.uv_addr, req->src.v_addr, req->src.format);\r
+    printk("src : act_w = %d, act_h = %d, vir_w = %d, vir_h = %d\n",\r
+        req->src.act_w, req->src.act_h, req->src.vir_w, req->src.vir_h);\r
+    printk("src : x_offset = %.8x y_offset = %.8x\n", req->src.x_offset, req->src.y_offset);\r
+\r
+    printk("dst : yrgb_addr = %.8x, dst.uv_addr = %.8x, dst.v_addr = %.8x\n",\r
+            req->dst.yrgb_addr, req->dst.uv_addr, req->dst.v_addr);\r
+    printk("dst : x_offset = %.8x y_offset = %.8x\n", req->dst.x_offset, req->dst.y_offset);\r
+    printk("dst : act_w = %d, act_h = %d, vir_w = %d, vir_h = %d\n",\r
+        req->dst.act_w, req->dst.act_h, req->dst.vir_w, req->dst.vir_h);\r
+\r
+    printk("clip.xmin = %d, clip.xmax = %d. clip.ymin = %d, clip.ymax = %d\n",\r
+        req->clip.xmin, req->clip.xmax, req->clip.ymin, req->clip.ymax);\r
+\r
+    printk("alpha_rop_flag = %.8x\n", req->alpha_rop_flag);\r
+    printk("alpha_rop_mode = %.8x\n", req->alpha_rop_mode);\r
+    printk("PD_mode = %.8x\n", req->PD_mode);\r
+}\r
+#endif\r
+\r
 \r
 static inline void rga_write(u32 b, u32 r)\r
 {\r
@@ -418,9 +442,7 @@ static struct rga_reg * rga_reg_init(rga_session *session, struct rga_req *req)
     reg->session = session;\r
        INIT_LIST_HEAD(&reg->session_link);\r
        INIT_LIST_HEAD(&reg->status_link);\r
-\r
-    //memcpy(&reg->req, req, sizeof(struct rga_req));\r
-\r
+   \r
     reg->MMU_base = NULL;\r
 \r
     if (req->mmu_info.mmu_en)\r
@@ -631,29 +653,7 @@ static void rga_try_set_reg(void)
 }\r
 \r
 \r
-#if RGA_TEST\r
-static void print_info(struct rga_req *req)\r
-{\r
-    printk("src.yrgb_addr = %.8x, src.uv_addr = %.8x, src.v_addr = %.8x\n",\r
-            req->src.yrgb_addr, req->src.uv_addr, req->src.v_addr);\r
-    printk("src : act_w = %d, act_h = %d, vir_w = %d, vir_h = %d\n",\r
-        req->src.act_w, req->src.act_h, req->src.vir_w, req->src.vir_h);\r
-    printk("src : x_offset = %.8x y_offset = %.8x\n", req->src.x_offset, req->src.y_offset);\r
 \r
-    printk("dst.yrgb_addr = %.8x, dst.uv_addr = %.8x, dst.v_addr = %.8x\n",\r
-            req->dst.yrgb_addr, req->dst.uv_addr, req->dst.v_addr);\r
-    printk("dst : x_offset = %.8x y_offset = %.8x\n", req->dst.x_offset, req->dst.y_offset);\r
-    printk("dst : act_w = %d, act_h = %d, vir_w = %d, vir_h = %d\n",\r
-        req->dst.act_w, req->dst.act_h, req->dst.vir_w, req->dst.vir_h);\r
-\r
-    printk("clip.xmin = %d, clip.xmax = %d. clip.ymin = %d, clip.ymax = %d\n",\r
-        req->clip.xmin, req->clip.xmax, req->clip.ymin, req->clip.ymax);\r
-\r
-    printk("alpha_rop_flag = %.8x\n", req->alpha_rop_flag);\r
-    printk("alpha_rop_mode = %.8x\n", req->alpha_rop_mode);\r
-    printk("PD_mode = %.8x\n", req->PD_mode);\r
-}\r
-#endif\r
 \r
 /* Caller must hold rga_service.lock */\r
 static void rga_del_running_list(void)\r
@@ -663,7 +663,7 @@ static void rga_del_running_list(void)
     while(!list_empty(&rga_service.running))\r
     {\r
         reg = list_entry(rga_service.running.next, struct rga_reg, status_link);\r
-\r
+        \r
         if(reg->MMU_base != NULL)\r
         {\r
             kfree(reg->MMU_base);\r
@@ -917,23 +917,27 @@ static long rga_ioctl(struct file *file, uint32_t cmd, unsigned long arg)
 {\r
     struct rga_req *req;\r
        int ret = 0;\r
-    rga_session *session = (rga_session *)file->private_data;\r
+    rga_session *session;\r
+\r
+    mutex_lock(&rga_service.mutex);\r
+    \r
+    session = (rga_session *)file->private_data;\r
 \r
        if (NULL == session)\r
     {\r
         printk("%s [%d] rga thread session is null\n",__FUNCTION__,__LINE__);\r
+        mutex_unlock(&rga_service.mutex);\r
                return -EINVAL;\r
        }\r
-\r
+    \r
     req = kzalloc(sizeof(struct rga_req), GFP_KERNEL);\r
     if(req == NULL)\r
     {\r
         printk("%s [%d] get rga_req mem failed\n",__FUNCTION__,__LINE__);\r
+        mutex_unlock(&rga_service.mutex);\r
         return -EINVAL;\r
     }\r
-\r
-       mutex_lock(&rga_service.mutex);\r
-\r
+       \r
        switch (cmd)\r
        {\r
                case RGA_BLIT_SYNC:\r
@@ -978,10 +982,10 @@ static long rga_ioctl(struct file *file, uint32_t cmd, unsigned long arg)
                        break;\r
        }\r
 \r
-       mutex_unlock(&rga_service.mutex);\r
-\r
-        kfree(req);\r
+    kfree(req);\r
 \r
+       mutex_unlock(&rga_service.mutex);\r
+    \r
        return ret;\r
 }\r
 \r
@@ -1355,295 +1359,7 @@ void rga_test_0(void)
     req.mmu_info.mmu_en = 1;\r
 \r
     rga_blit_sync(&session, &req);\r
-\r
-    dmac_inv_range(&dst_buf[0], &dst_buf[320*240]);\r
-    outer_inv_range(virt_to_phys(&dst_buf[0]),virt_to_phys(&dst_buf[320*240]));\r
-\r
-    for(j=0; j<17; j++)\r
-    {\r
-        for(i=0; i<8; i++)\r
-        {\r
-            printk("%.8x, ", dst_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-\r
-        for(i=8; i<16; i++)\r
-        {\r
-            printk("%.8x, ", dst_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-    }\r
-\r
-    p = (uint8_t *)src_buf;\r
-    p = p + 16 * 4;\r
-\r
-    for(i=0; i<16; i++)\r
-        src_buf[i] = 0;\r
-\r
-    for(j=0; j<16; j++)\r
-    {\r
-        for(i=0; i<16; i++)\r
-        {\r
-            t = j*16 + i;\r
-            src_buf[(j+1)*16 + i] = (t<<24)|(t<<16)|(t<<8)|t;\r
-        }\r
-    }\r
-\r
-    dmac_flush_range(&src_buf[0], &src_buf[320*240]);\r
-    outer_flush_range(virt_to_phys(&src_buf[0]),virt_to_phys(&src_buf[320*240]));\r
-\r
-    dmac_inv_range(&src_buf[0], &src_buf[320*240]);\r
-    outer_inv_range(virt_to_phys(&src_buf[0]),virt_to_phys(&src_buf[320*240]));\r
-\r
-    printk("SRC DATA \n");\r
-    for(j=0; j<17; j++)\r
-    {\r
-        for(i=0; i<8; i++)\r
-        {\r
-            printk("%.8x, ", src_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-\r
-        for(i=8; i<16; i++)\r
-        {\r
-            printk("%.8x, ", src_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-    }    \r
-\r
-    req.src.act_w = 320;\r
-    req.src.act_h = 240;\r
-\r
-    req.src.vir_w = 320;\r
-    req.src.vir_h = 240;\r
-    req.src.yrgb_addr = (uint32_t)src;\r
-    req.src.uv_addr = (uint32_t)virt_to_phys(src);\r
-    req.src.v_addr = (uint32_t)virt_to_phys(src);\r
-    req.src.format = 0;\r
-\r
-    req.dst.act_w = 320;\r
-    req.dst.act_h = 240;\r
-\r
-    req.dst.vir_w = 1024;\r
-    req.dst.vir_h = 768;\r
-    req.dst.x_offset = 0;\r
-    req.dst.y_offset = 0;\r
-    req.dst.yrgb_addr = (uint32_t)(dst);\r
-\r
-    //req.dst.format = RK_FORMAT_RGB_565;\r
-\r
-    req.clip.xmin = 0;\r
-    req.clip.xmax = 1023;\r
-    req.clip.ymin = 0;\r
-    req.clip.ymax = 767;\r
-\r
-    //req.render_mode = color_fill_mode;\r
-    //req.fg_color = 0x80ffffff;\r
-\r
-    //req.rotate_mode = 1;\r
-    //req.scale_mode = 2;\r
-\r
-    req.alpha_rop_flag = 0x19;\r
-    req.alpha_rop_mode = 0x1;\r
-    req.PD_mode = 3;\r
-\r
-    req.sina = 0;\r
-    req.cosa = 65536;\r
-\r
-    req.mmu_info.mmu_flag = 0x21;\r
-    req.mmu_info.mmu_en = 1;\r
     \r
-    rga_blit_sync(&session, &req);\r
-\r
-    dmac_inv_range(&dst_buf[0], &dst_buf[320*240]);\r
-    outer_inv_range(virt_to_phys(&dst_buf[0]),virt_to_phys(&dst_buf[320*240]));\r
-\r
-    for(j=0; j<17; j++)\r
-    {\r
-        for(i=0; i<8; i++)\r
-        {\r
-            printk("%.8x, ", dst_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-        for(i=8; i<16; i++)\r
-        {\r
-            printk("%.8x, ", dst_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-    }\r
-\r
-    memset(src_buf, 0x80, 320*240*4);\r
-\r
-    dmac_flush_range(&src_buf[0], &src_buf[320*240]);\r
-    outer_flush_range(virt_to_phys(&src_buf[0]),virt_to_phys(&src_buf[320*240]));\r
-\r
-   \r
-    #if 0\r
-    memset(src_buf, 0x80, 800*480*4);\r
-    memset(dst_buf, 0xcc, 800*480*4);\r
-\r
-    dmac_flush_range(&dst_buf[0], &dst_buf[800*480]);\r
-    outer_flush_range(virt_to_phys(&dst_buf[0]),virt_to_phys(&dst_buf[800*480]));\r
-    #endif\r
-\r
-    req.src.act_w = 320;\r
-    req.src.act_h = 240;\r
-\r
-    req.src.vir_w = 320;\r
-    req.src.vir_h = 240;\r
-    req.src.yrgb_addr = (uint32_t)(src);\r
-    req.src.uv_addr = (uint32_t)virt_to_phys(src);\r
-    req.src.v_addr = (uint32_t)virt_to_phys(src);\r
-    req.src.format = 0;\r
-\r
-    req.dst.act_w = 320;\r
-    req.dst.act_h = 240;\r
-\r
-    req.dst.vir_w = 1024;\r
-    req.dst.vir_h = 768;\r
-    req.dst.x_offset = 0;\r
-    req.dst.y_offset = 0;\r
-    req.dst.yrgb_addr = (uint32_t)(dst);\r
-\r
-    //req.dst.format = RK_FORMAT_RGB_565;\r
-\r
-    req.clip.xmin = 0;\r
-    req.clip.xmax = 1023;\r
-    req.clip.ymin = 0;\r
-    req.clip.ymax = 767;\r
-\r
-    //req.render_mode = color_fill_mode;\r
-    //req.fg_color = 0x80ffffff;\r
-\r
-    //req.rotate_mode = 1;\r
-    //req.scale_mode = 2;\r
-\r
-    req.alpha_rop_flag = 0;\r
-    req.alpha_rop_mode = 0x0;\r
-\r
-    req.sina = 0;\r
-    req.cosa = 65536;\r
-\r
-    req.mmu_info.mmu_flag = 0x21;\r
-    req.mmu_info.mmu_en = 1;\r
-\r
-    rga_blit_sync(&session, &req);\r
-\r
-    dmac_inv_range(&dst_buf[0], &dst_buf[320*240]);\r
-    outer_inv_range(virt_to_phys(&dst_buf[0]),virt_to_phys(&dst_buf[320*240]));\r
-\r
-    for(j=0; j<17; j++)\r
-    {\r
-        for(i=0; i<8; i++)\r
-        {\r
-            printk("%.8x, ", dst_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-\r
-        for(i=8; i<16; i++)\r
-        {\r
-            printk("%.8x, ", dst_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-    }\r
-\r
-    p = (uint8_t *)src_buf;\r
-    p = p + 16 * 4;\r
-\r
-    for(i=0; i<16; i++)\r
-        src_buf[i] = 0;\r
-\r
-    for(j=0; j<16; j++)\r
-    {\r
-        for(i=0; i<16; i++)\r
-        {\r
-            t = j*16 + i;\r
-            src_buf[(j+1)*16 + i] = (t<<24)|(t<<16)|(t<<8)|t;\r
-        }\r
-    }\r
-\r
-    dmac_inv_range(&src_buf[0], &src_buf[320*240]);\r
-    outer_inv_range(virt_to_phys(&src_buf[0]),virt_to_phys(&src_buf[320*240]));\r
-    printk("SRC DATA \n");\r
-    for(j=0; j<17; j++)\r
-    {\r
-        for(i=0; i<8; i++)\r
-        {\r
-            printk("%.8x, ", src_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-\r
-        for(i=8; i<16; i++)\r
-        {\r
-            printk("%.8x, ", src_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-    }\r
-\r
-    dmac_flush_range(&src_buf[0], &src_buf[320*240]);\r
-    outer_flush_range(virt_to_phys(&src_buf[0]),virt_to_phys(&src_buf[320*240]));\r
-\r
-    req.src.act_w = 320;\r
-    req.src.act_h = 240;\r
-\r
-    req.src.vir_w = 320;\r
-    req.src.vir_h = 240;\r
-    req.src.yrgb_addr = (uint32_t)(src);\r
-    req.src.uv_addr = (uint32_t)virt_to_phys(src);\r
-    req.src.v_addr = (uint32_t)virt_to_phys(src);\r
-    req.src.format = 0;\r
-\r
-    req.dst.act_w = 320;\r
-    req.dst.act_h = 240;\r
-\r
-    req.dst.vir_w = 1024;\r
-    req.dst.vir_h = 768;\r
-    req.dst.x_offset = 0;\r
-    req.dst.y_offset = 0;\r
-    req.dst.yrgb_addr = (uint32_t)(dst);\r
-\r
-    //req.dst.format = RK_FORMAT_RGB_565;\r
-\r
-    req.clip.xmin = 0;\r
-    req.clip.xmax = 1023;\r
-    req.clip.ymin = 0;\r
-    req.clip.ymax = 767;\r
-\r
-    //req.render_mode = color_fill_mode;\r
-    //req.fg_color = 0x80ffffff;\r
-\r
-    //req.rotate_mode = 1;\r
-    //req.scale_mode = 2;\r
-\r
-    req.alpha_rop_flag = 0x19;\r
-    req.alpha_rop_mode = 0x1;\r
-    req.PD_mode = 3;\r
-\r
-    req.sina = 0;\r
-    req.cosa = 65536;\r
-\r
-    req.mmu_info.mmu_flag = 0x21;\r
-    req.mmu_info.mmu_en = 1;\r
-    \r
-    rga_blit_sync(&session, &req);\r
-\r
-    dmac_inv_range(&dst_buf[0], &dst_buf[320*240]);\r
-    outer_inv_range(virt_to_phys(&dst_buf[0]),virt_to_phys(&dst_buf[320*240]));\r
-\r
-    for(j=0; j<17; j++)\r
-    {\r
-        for(i=0; i<8; i++)\r
-        {\r
-            printk("%.8x, ", dst_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-        for(i=8; i<16; i++)\r
-        {\r
-            printk("%.8x, ", dst_buf[j*16 + i]);            \r
-        }\r
-        printk("\n");\r
-    }\r
-\r
     #if 1\r
     fb->var.bits_per_pixel = 32;\r
     \r
index e8167d7fc5305fe0cdb34bd70ba6878306bfa8fc..8a1f5fd67ee2ca9b3fcd3cadafbed3c7b092556c 100755 (executable)
@@ -248,7 +248,7 @@ static int rga_MapUserMemory(struct page **pages,
     uint32_t temp;\r
     status = 0;\r
     Address = 0;\r
-\r
+    \r
     do\r
     {    \r
         down_read(&current->mm->mmap_sem);\r
@@ -262,7 +262,8 @@ static int rga_MapUserMemory(struct page **pages,
                 NULL\r
                 );\r
         up_read(&current->mm->mmap_sem);\r
-                        \r
+\r
+        #if 0                \r
         if(result <= 0 || result < pageCount) \r
         {\r
             status = 0;\r
@@ -282,6 +283,73 @@ static int rga_MapUserMemory(struct page **pages,
 \r
             return status;\r
         }\r
+        #else\r
+        if(result <= 0 || result < pageCount) \r
+        {\r
+            struct vm_area_struct *vma;\r
+\r
+            for(i=0; i<pageCount; i++)\r
+            {                \r
+                vma = find_vma(current->mm, (Memory + i) << PAGE_SHIFT);\r
+\r
+                if (vma && (vma->vm_flags & VM_PFNMAP) )\r
+                {\r
+                    do\r
+                    {\r
+                        pte_t       * pte;\r
+                        spinlock_t  * ptl;\r
+                        unsigned long pfn;                                                                        \r
+                        pgd_t * pgd;\r
+                        pud_t * pud;\r
+                        \r
+                        pgd = pgd_offset(current->mm, (Memory + i) << PAGE_SHIFT);\r
+\r
+                        if(pgd_val(*pgd) == 0)\r
+                        {\r
+                            printk("rga pgd value is zero \n");\r
+                            break;\r
+                        }\r
+                        \r
+                        pud = pud_offset(pgd, (Memory + i) << PAGE_SHIFT);\r
+                        if (pud)\r
+                        {\r
+                            pmd_t * pmd = pmd_offset(pud, (Memory + i) << PAGE_SHIFT);\r
+                            if (pmd)\r
+                            {\r
+                                pte = pte_offset_map_lock(current->mm, pmd, (Memory + i) << PAGE_SHIFT, &ptl);\r
+                                if (!pte)\r
+                                {\r
+                                    break;\r
+                                }\r
+                            }\r
+                            else\r
+                            {\r
+                                break;\r
+                            }\r
+                        }\r
+                        else\r
+                        {\r
+                            break;\r
+                        }\r
+\r
+                        pfn = pte_pfn(*pte);\r
+                        Address = ((pfn << PAGE_SHIFT) | (((unsigned long)((Memory + i) << PAGE_SHIFT)) & ~PAGE_MASK));                        \r
+                        pte_unmap_unlock(pte, ptl);                                                                        \r
+                    }\r
+                    while (0);\r
+\r
+                    pageTable[i] = Address;\r
+                }\r
+                else\r
+                {\r
+                    status = RGA_OUT_OF_RESOURCES;\r
+                    break;\r
+                }     \r
+            }\r
+            \r
+            return 0;\r
+        }\r
+        #endif\r
 \r
         for (i = 0; i < pageCount; i++)\r
         {\r
@@ -370,14 +438,14 @@ static int rga_mmu_info_BitBlt_mode(struct rga_reg *reg, struct rga_req *req)
         /* Cal out the needed mem size */\r
         AllSize = SrcMemSize + DstMemSize;\r
                            \r
-        pages = kmalloc((AllSize + 1)* sizeof(struct page *), GFP_KERNEL);\r
+        pages = kzalloc((AllSize + 1)* sizeof(struct page *), GFP_KERNEL);\r
         if(pages == NULL) {\r
             pr_err("RGA MMU malloc pages mem failed\n");\r
             status = RGA_MALLOC_ERROR;\r
             break;                \r
         }\r
         \r
-        MMU_Base = kmalloc((AllSize + 1) * sizeof(uint32_t), GFP_KERNEL);\r
+        MMU_Base = kzalloc((AllSize + 1) * sizeof(uint32_t), GFP_KERNEL);\r
         if(MMU_Base == NULL) {\r
             pr_err("RGA MMU malloc MMU_Base point failed\n");\r
             status = RGA_MALLOC_ERROR;\r
@@ -385,7 +453,7 @@ static int rga_mmu_info_BitBlt_mode(struct rga_reg *reg, struct rga_req *req)
         }\r
 \r
         if(req->src.yrgb_addr < KERNEL_SPACE_VALID)\r
-        {            \r
+        {               \r
             ret = rga_MapUserMemory(&pages[0], &MMU_Base[0], SrcStart, SrcMemSize);\r
             if (ret < 0) {\r
                 pr_err("rga map src memory failed\n");\r
@@ -421,7 +489,7 @@ static int rga_mmu_info_BitBlt_mode(struct rga_reg *reg, struct rga_req *req)
             #if 0\r
             ktime_t start, end;\r
             start = ktime_get();\r
-            #endif\r
+            #endif            \r
             ret = rga_MapUserMemory(&pages[SrcMemSize], &MMU_Base[SrcMemSize], DstStart, DstMemSize);\r
             if (ret < 0) {\r
                 pr_err("rga map dst memory failed\n");\r