Browse Source

rt_hw_mmu_switch不同架构接口不一致的问题。删除remove_asid函数。

ff#
chenhy0106 2 years ago
parent
commit
071511de4f

+ 9 - 11
components/lwp/arch/arm/cortex-a/lwp_arch.c

@@ -105,6 +105,12 @@ unsigned int arch_get_asid(struct rt_lwp *lwp)
         return lwp->asid;
     }
 
+    if (lwp->asid && !asid_valid_bitmap[lwp->asid])
+    {
+        asid_valid_bitmap[lwp->asid] = 1;
+        return lwp->asid;
+    }
+
     for (unsigned i = 1; i < MAX_ASID; i++)
     {
         if (asid_valid_bitmap[i] == 0)
@@ -112,7 +118,7 @@ unsigned int arch_get_asid(struct rt_lwp *lwp)
             asid_valid_bitmap[i] = 1;
             lwp->generation = global_generation;
             lwp->asid = i;
-            return i;
+            return lwp->asid;
         }
     }
 
@@ -123,17 +129,9 @@ unsigned int arch_get_asid(struct rt_lwp *lwp)
     lwp->generation = global_generation;
     lwp->asid = 1;
 
-    rt_hw_cpu_tlb_invalidate();
-
-    return 1;
-}
+    asm volatile ("mcr p15, 0, r0, c8, c7, 0\ndsb\nisb" ::: "memory");
 
-void arch_remove_asid(struct rt_lwp *lwp)
-{
-    if (lwp->generation == global_generation)
-    {
-        asid_valid_bitmap[lwp->asid] = 0;
-    }
+    return lwp->asid;
 }
 
 #endif

+ 0 - 1
components/lwp/arch/arm/cortex-a/lwp_arch.h

@@ -44,7 +44,6 @@ rt_inline void icache_invalid_all(void)
 }
 
 unsigned int arch_get_asid(struct rt_lwp *lwp);
-void arch_remove_asid(struct rt_lwp *lwp);
 
 #ifdef __cplusplus
 }

+ 2 - 4
components/lwp/lwp_pid.c

@@ -337,8 +337,10 @@ struct rt_lwp* lwp_new(void)
     lwp->pid = pid;
     lwp_pid_set_lwp(pid, lwp);
 
+#ifdef LWP_ENABLE_ASID
     lwp->generation = 0;
     lwp->asid = 0;
+#endif
 
 out:
     rt_hw_interrupt_enable(level);
@@ -415,10 +417,6 @@ void lwp_free(struct rt_lwp* lwp)
     lwp_unmap_user_space(lwp);
 #endif
 
-#ifdef LWP_ENABLE_ASID
-    arch_remove_asid(lwp);
-#endif
-
     level = rt_hw_interrupt_disable();
     /* for children */
     while (lwp->first_child)

+ 8 - 6
components/lwp/lwp_user_mm.c

@@ -29,14 +29,16 @@ int lwp_user_space_init(struct rt_lwp *lwp)
     return arch_user_space_init(lwp);
 }
 
-void rt_hw_mmu_switch(void *mtable, unsigned int pid, unsigned char asid);
+#ifdef LWP_ENABLE_ASID
+void rt_hw_mmu_switch(void *mtable, unsigned int pid, unsigned int asid);
+#else
+void rt_hw_mmu_switch(void *mtable);
+#endif
 void *rt_hw_mmu_tbl_get(void);
 void lwp_mmu_switch(struct rt_thread *thread)
 {
     struct rt_lwp *l = RT_NULL;
     void *pre_mmu_table = RT_NULL, *new_mmu_table = RT_NULL;
-    unsigned int asid = 0; 
-    pid_t pid = 0; 
 
     if (thread->lwp)
     {
@@ -52,10 +54,10 @@ void lwp_mmu_switch(struct rt_thread *thread)
     if (pre_mmu_table != new_mmu_table)
     {
 #ifdef LWP_ENABLE_ASID
-        asid = arch_get_asid(l);
+        rt_hw_mmu_switch(new_mmu_table, l ? l->pid : 0, arch_get_asid(l));
+#else
+        rt_hw_mmu_switch(new_mmu_table);
 #endif
-        pid = l ? l->pid : 0; 
-        rt_hw_mmu_switch(new_mmu_table, pid, asid);
     }
 }