diff --git a/include/_zvm/vm.h b/include/_zvm/vm.h index a47dd3d251008668398dbd6e97bbd089eb0d428f..290a55f3272b6386ba7f8474ba3f624ee4932ea6 100644 --- a/include/_zvm/vm.h +++ b/include/_zvm/vm.h @@ -69,6 +69,8 @@ #define vcpu_need_switch(tid1, tid2) ((VCPU_THREAD(tid1)) || (VCPU_THREAD(tid2))) +#define PAGE_ALIGN(addr) ((addr + CONFIG_MMU_PAGE_SIZE - 1) & ~(CONFIG_MMU_PAGE_SIZE - 1)) + struct vcpu_work; struct z_vm_info; struct os; diff --git a/subsys/_zvm/vm.c b/subsys/_zvm/vm.c index 2fcf3a900b34c6ab1a5e502503d6ccfd1866c6e4..1855fecc23d0cd5e92a3bfcafb12c43488f9e0a0 100644 --- a/subsys/_zvm/vm.c +++ b/subsys/_zvm/vm.c @@ -135,11 +135,32 @@ int vm_mem_init(struct vm *vm) { int ret = 0; struct vm_mem_domain *vmem_dm = vm->vmem_domain; + struct _dnode *d_node,*ds_node; + struct vm_mem_partition *vpart; + uint64_t hpa_base; + if (vmem_dm->is_init) { ZVM_LOG_WARN("Vm mem has been init before! \n"); return -EMMAO; } + + /* Create a new address space using kmalloc + to store Linux and Zephyr images. */ + + SYS_DLIST_FOR_EACH_NODE_SAFE(&vmem_dm->idle_vpart_list,d_node,ds_node){ + vpart = CONTAINER_OF(d_node,struct vm_mem_partition,vpart_node); + + // if(vpart->part_hpa_size != LINUX_VM_MEM_SIZE && vpart->part_hpa_size != ZEPHYR_VM_MEM_SIZE) + // continue; + + hpa_base = (uint64_t) k_malloc(vpart->part_hpa_size+CONFIG_MMU_PAGE_SIZE-1); + hpa_base = PAGE_ALIGN(hpa_base); + vpart->part_hpa_base = hpa_base; + } + + + #ifndef CONFIG_VM_DYNAMIC_MEMORY ret = vm_mem_apart_add(vmem_dm); if (ret) {