From owner-svn-soc-all@freebsd.org Wed Jun 24 21:55:55 2015 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 451BF91688A for ; Wed, 24 Jun 2015 21:55:55 +0000 (UTC) (envelope-from mihai@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 357B211E6 for ; Wed, 24 Jun 2015 21:55:55 +0000 (UTC) (envelope-from mihai@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id t5OLttgH020488 for ; Wed, 24 Jun 2015 21:55:55 GMT (envelope-from mihai@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id t5OLtrtA020483 for svn-soc-all@FreeBSD.org; Wed, 24 Jun 2015 21:55:53 GMT (envelope-from mihai@FreeBSD.org) Date: Wed, 24 Jun 2015 21:55:53 GMT Message-Id: <201506242155.t5OLtrtA020483@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mihai@FreeBSD.org using -f From: mihai@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r287552 - in soc2015/mihai/bhyve-on-arm-head/sys: arm/vmm modules/vmm-arm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Jun 2015 21:55:55 -0000 Author: mihai Date: Wed Jun 24 21:55:52 2015 New Revision: 287552 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=287552 Log: soc2015: mihai: bhyve-on-arm-head: sys: arm: vmm: complete initialization part Added: soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/hyp.S Deleted: soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/init.S Modified: soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/arm.c soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/arm.h soc2015/mihai/bhyve-on-arm-head/sys/modules/vmm-arm/Makefile Modified: soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/arm.c ============================================================================== --- soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/arm.c Wed Jun 24 20:51:48 2015 (r287551) +++ soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/arm.c Wed Jun 24 21:55:52 2015 (r287552) @@ -21,29 +21,69 @@ lpae_pd_entry_t hyp_l1pd[2 * LPAE_L1_ENTRIES]; extern void _hypervisor_stub_trap(void *vect_addr); -char *stack = NULL; +extern void* _init_hyp_vector; + +char *stack; +char *hyp_code; static int arm_init(int ipinum) { - char *stack_top, *hyp_code; + char *stack_top; + size_t hyp_code_size; + uint64_t *phys_hyp_l1pd; stack = malloc(PAGE_SIZE, M_HYP); stack_top = stack + PAGE_SIZE; - lpae_vmmmap_set(NULL, stack, ptophys(stack), PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE); + lpae_vmmmap_set(NULL, stack, ptophys(stack), PAGE_SIZE, + VM_PROT_READ | VM_PROT_WRITE); + + /* + * Allocate a PAGE for the HYP code to be sure it's PAGE_SIZE + * aligned and doesn't cross a page boundary. + */ + hyp_code_size = _hyp_code_stop - _hyp_code_start; + hyp_code_size = (hyp_code_size + PAGE_SIZE) & PAGE_SIZE; + hyp_code = contigmalloc(hyp_code_size, M_HYP, 0, 0x0, + 0xffffffff, PAGE_SIZE, 0); + memcpy(hyp_code, _hyp_code_start, hyp_code_size); - /* Allocate a PAGE for the HYP code to be sure it's PAGE_SIZE aligned and doesn't cross a page boundary */ - hyp_code = malloc(PAGE_SIZE, M_HYP); - memcpy(hyp_code, _hyp_code_start, _hyp_code_stop - _hyp_code_start); + printf("%s hyp_code_size: %p, _hyp_code_start: %p, hyp_code: %p\n", __func__, (void*) _hyp_code_start, (void*) hyp_code); /* Create two mappings: * - one identity - VA == PA - * - one normal mappings to HYP pagetable */ - lpae_vmmmap_set(NULL, hyp_code, ptophys(hyp_code), PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE); - lpae_vmmmap_set(NULL, ptophys(hyp_code), ptophys(hyp_code), PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE); + * - one normal mappings to HYP pagetable + */ + lpae_vmmmap_set(NULL, hyp_code, ptophys(hyp_code), hyp_code_size, + VM_PROT_READ | VM_PROT_WRITE); + lpae_vmmmap_set(NULL, ptophys(hyp_code), ptophys(hyp_code), hyp_code_size, + VM_PROT_READ | VM_PROT_WRITE); + + /* + * Flush all caches to be sure we have the + * code and tables in physical memory + */ + cpu_idcache_wbinv_all(); + cpu_l2cache_wbinv_all(); + + /* + * Install the temporary vector from which + * will do the initialization part of VMM + */ + _hypervisor_stub_trap(vtophys(_init_hyp_vector)); + + /* + * Special init call to activate the MMU + * and change the exception vector. + * - r0 - first parameter unused + * - r1 - stack pointer + * - r2 - lower 32 bits for the HTTBR + * - r3 - upper 32 bits for the HTTBR + */ + phys_hyp_l1pd = vtophys(&hyp_l1pd[0]); + vmm_call_hyp(NULL, stack_top, LOW(phys_hyp_l1pd), HIGH(phys_hyp_l1pd); - vmm_call_hyp(NULL, stack_top, &hyp_l1pd[0], &hyp_l1pd[0]); return 0; } Modified: soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/arm.h ============================================================================== --- soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/arm.h Wed Jun 24 20:51:48 2015 (r287551) +++ soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/arm.h Wed Jun 24 21:55:52 2015 (r287552) @@ -7,3 +7,5 @@ uint64_t vmm_call_hyp(void *hyp_func_addr, ...); +#define HIGH(x) (x >> 32) +#define LOW(x) (x & ((1 << 32) - 1)) Added: soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/hyp.S ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2015/mihai/bhyve-on-arm-head/sys/arm/vmm/hyp.S Wed Jun 24 21:55:52 2015 (r287552) @@ -0,0 +1,134 @@ +#include "assym.s" +#include +#include +#include +#include +#include +#include + +#define SYS_WRITE0 4 + +.text + .globl _hyp_code_start + .globl _hyp_code_end + .globl _hyp_vector + .globl _init_hyp_vector + +_hyp_code_start: + +__semi_call: + svc 0x123456 + mov pc, lr + +ASENTRY_NP(kvm_call_hyp) + hvc #0 + bx lr +END(kvm_call_hyp) + + .align 5 +_init_hyp_vector: + .word 0 /* Reset */ + .word 0 /* undev */ + .word 0 /* SVC */ + .word 0 /* PABT */ + .word 0 /* DABT */ + b hyp_init_hvc /* HYP-Mode */ + .word 0 /* FIQ */ + .word 0 /* IRQ */ + +hyp_init_hvc: + mov sp, r1 /* r1 contains the stack pointer */ + + /* Find the offset between the two vectors */ + adr r0, _init_hyp_vector + adr r1, _hyp_vector + sub r1, r1, r0 + + mrc p15, 4, r0, c12, c0, 0 @ get current HVBAR + add r0, r0, r1 @ find the address of the _hyp_vector + mcr p15, 4, r0, c12, c0, 0 @ set HVBAR to the new vector + + mcrr p15, 4, r2, r3, c2 @ set the HTTBR (r2 is the low word, r3 is the low word) + isb + + @ Flush the TLB of this page + adr r1, _hyp_code_start + mcr p15, 4, r0, c8, c7, 0 @ TLBIALLH + dsb ish + + eret + + .align 5 +_hyp_vector: + b hyp_reset /* Reset */ + b hyp_undef /* undef */ + b hyp_svc /* SVC */ + b hyp_pabt /* PABT */ + b hyp_dabt /* DABT */ + b hyp_hvc /* HYP-Mode */ + b hyp_fiq /* FIQ */ + b hyp_irq /* IRQ */ + + .align +hyp_reset: + b loop + + .align +hyp_undef: + mov r0, #SYS_WRITE0 + adr r1, und_die_str + bl __semi_call + mrs r0, ELR_hyp + b loop + + .align +hyp_svc: + mov r0, #SYS_WRITE0 + adr r1, svc_die_str + bl __semi_call + mrs r0, ELR_hyp + b loop + .align + +hyp_pabt: + mov r0, #SYS_WRITE0 + adr r1, pabt_die_str + bl __semi_call + mrs r0, ELR_hyp + mrc p15, 4, r1, c5, c2, 0 @ HSR (syndrome register) + mrc p15, 4, r2, c6, c0, 2 @ HIFAR (hyp instruction fault address) + b loop + + .align +hyp_dabt: + mov r0, #SYS_WRITE0 + adr r1, dabt_die_str + bl __semi_call + mrs r0, ELR_hyp + mrc p15, 4, r1, c5, c2, 0 @ HSR (syndrome register) + mrc p15, 4, r2, c6, c0, 0 @ HDFAR (hyp data fault address) + b loop + + .align +hyp_hvc: + + .align +hyp_fiq: + b loop + .align +hyp_irq: + b loop + .align +loop: + b loop + +und_die_str: + .ascii "unexpected undefined exception in Hyp mode at r0: %#08x\n" +pabt_die_str: + .ascii "unexpected prefetch abort in Hyp mode at r0: %#08x\n" +dabt_die_str: + .ascii "unexpected data abort in Hyp mode at r0: %#08x\n" +svc_die_str: + .ascii "unexpected HVC/SVC trap in Hyp mode at r0: %#08x\n" + +_hyp_code_end: Modified: soc2015/mihai/bhyve-on-arm-head/sys/modules/vmm-arm/Makefile ============================================================================== --- soc2015/mihai/bhyve-on-arm-head/sys/modules/vmm-arm/Makefile Wed Jun 24 20:51:48 2015 (r287551) +++ soc2015/mihai/bhyve-on-arm-head/sys/modules/vmm-arm/Makefile Wed Jun 24 21:55:52 2015 (r287552) @@ -11,7 +11,7 @@ vmm_dev.c \ mmu.c \ vmm_stat.c \ - init.S + hyp.S .include