xen_machdep.c (182671) | xen_machdep.c (182902) |
---|---|
1/* 2 * 3 * Copyright (c) 2004 Christian Limpach. 4 * Copyright (c) 2004-2006 Kip Macy 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 17 unchanged lines hidden (view full) --- 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> | 1/* 2 * 3 * Copyright (c) 2004 Christian Limpach. 4 * Copyright (c) 2004-2006 Kip Macy 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 17 unchanged lines hidden (view full) --- 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/i386/xen/xen_machdep.c 182671 2008-09-02 02:55:45Z kmacy $"); | 34__FBSDID("$FreeBSD: head/sys/i386/xen/xen_machdep.c 182902 2008-09-10 07:11:08Z kmacy $"); |
35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/bus.h> 39#include <sys/mount.h> 40#include <sys/malloc.h> 41#include <sys/kernel.h> 42#include <sys/reboot.h> 43#include <sys/sysproto.h> 44 | 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/bus.h> 39#include <sys/mount.h> 40#include <sys/malloc.h> 41#include <sys/kernel.h> 42#include <sys/reboot.h> 43#include <sys/sysproto.h> 44 |
45 | |
46#include <machine/xen/xen-os.h> 47 | 45#include <machine/xen/xen-os.h> 46 |
48 | |
49#include <vm/vm.h> 50#include <vm/pmap.h> 51#include <machine/segments.h> 52#include <machine/pcb.h> 53#include <machine/stdarg.h> 54#include <machine/vmparam.h> 55#include <machine/cpu.h> 56#include <machine/intr_machdep.h> --- 617 unchanged lines hidden (view full) --- 674 balloon_unlock(flags); 675} 676 677extern unsigned long cpu0prvpage; 678extern unsigned long *SMPpt; 679extern struct user *proc0uarea; 680extern vm_offset_t proc0kstack; 681extern int vm86paddr, vm86phystk; | 47#include <vm/vm.h> 48#include <vm/pmap.h> 49#include <machine/segments.h> 50#include <machine/pcb.h> 51#include <machine/stdarg.h> 52#include <machine/vmparam.h> 53#include <machine/cpu.h> 54#include <machine/intr_machdep.h> --- 617 unchanged lines hidden (view full) --- 672 balloon_unlock(flags); 673} 674 675extern unsigned long cpu0prvpage; 676extern unsigned long *SMPpt; 677extern struct user *proc0uarea; 678extern vm_offset_t proc0kstack; 679extern int vm86paddr, vm86phystk; |
682char *bootmem_start, *bootmem_current, *bootmem_end; | 680char *bootmem_start, *bootmem_current, *bootmem_end; |
683 684pteinfo_t *pteinfo_list; 685void initvalues(start_info_t *startinfo); 686 687struct ringbuf_head *xen_store; /* XXX move me */ 688char *console_page; 689 690void * --- 117 unchanged lines hidden (view full) --- 808#ifdef PAE 809 vm_paddr_t IdlePDPTma, IdlePDPTnewma; 810 vm_paddr_t IdlePTDnewma[4]; 811 pd_entry_t *IdlePDPTnew, *IdlePTDnew; 812#else 813 vm_paddr_t pdir_shadow_ma; 814#endif 815 unsigned long i; | 681 682pteinfo_t *pteinfo_list; 683void initvalues(start_info_t *startinfo); 684 685struct ringbuf_head *xen_store; /* XXX move me */ 686char *console_page; 687 688void * --- 117 unchanged lines hidden (view full) --- 806#ifdef PAE 807 vm_paddr_t IdlePDPTma, IdlePDPTnewma; 808 vm_paddr_t IdlePTDnewma[4]; 809 pd_entry_t *IdlePDPTnew, *IdlePTDnew; 810#else 811 vm_paddr_t pdir_shadow_ma; 812#endif 813 unsigned long i; |
814 int ncpus; |
|
816 | 815 |
816#ifdef SMP 817 ncpus = MAXCPU; 818#else 819 ncpus = 1; 820#endif |
|
817 | 821 |
822#if 0 |
|
818 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables); | 823 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables); |
824#endif |
|
819 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments); 820#ifdef notyet 821 /* 822 * need to install handler 823 */ 824 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments_notify); 825#endif 826 xen_start_info = startinfo; --- 32 unchanged lines hidden (view full) --- 859 IdlePTD = (pd_entry_t *)startinfo->pt_base; 860 IdlePTDma = xpmap_ptom(VTOP(startinfo->pt_base)); 861 l3_pages = 0; 862#endif 863 l2_pages = 1; 864 l1_pages = xen_start_info->nr_pt_frames - l2_pages - l3_pages; 865 866 KPTphysoff = (l2_pages + l3_pages)*PAGE_SIZE; | 825 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments); 826#ifdef notyet 827 /* 828 * need to install handler 829 */ 830 HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments_notify); 831#endif 832 xen_start_info = startinfo; --- 32 unchanged lines hidden (view full) --- 865 IdlePTD = (pd_entry_t *)startinfo->pt_base; 866 IdlePTDma = xpmap_ptom(VTOP(startinfo->pt_base)); 867 l3_pages = 0; 868#endif 869 l2_pages = 1; 870 l1_pages = xen_start_info->nr_pt_frames - l2_pages - l3_pages; 871 872 KPTphysoff = (l2_pages + l3_pages)*PAGE_SIZE; |
867 | 873 |
868 KPTphys = xpmap_ptom(VTOP(startinfo->pt_base + KPTphysoff)); 869 XENPRINTF("IdlePTD %p\n", IdlePTD); 870 XENPRINTF("nr_pages: %ld shared_info: 0x%lx flags: 0x%lx pt_base: 0x%lx " 871 "mod_start: 0x%lx mod_len: 0x%lx\n", 872 xen_start_info->nr_pages, xen_start_info->shared_info, 873 xen_start_info->flags, xen_start_info->pt_base, 874 xen_start_info->mod_start, xen_start_info->mod_len); 875 /* Map proc0's KSTACK */ 876 877 proc0kstack = cur_space; cur_space += (KSTACK_PAGES * PAGE_SIZE); 878 printk("proc0kstack=%u\n", proc0kstack); | 874 KPTphys = xpmap_ptom(VTOP(startinfo->pt_base + KPTphysoff)); 875 XENPRINTF("IdlePTD %p\n", IdlePTD); 876 XENPRINTF("nr_pages: %ld shared_info: 0x%lx flags: 0x%lx pt_base: 0x%lx " 877 "mod_start: 0x%lx mod_len: 0x%lx\n", 878 xen_start_info->nr_pages, xen_start_info->shared_info, 879 xen_start_info->flags, xen_start_info->pt_base, 880 xen_start_info->mod_start, xen_start_info->mod_len); 881 /* Map proc0's KSTACK */ 882 883 proc0kstack = cur_space; cur_space += (KSTACK_PAGES * PAGE_SIZE); 884 printk("proc0kstack=%u\n", proc0kstack); |
879 | 885 |
880 /* vm86/bios stack */ 881 cur_space += PAGE_SIZE; 882 883 /* Map space for the vm86 region */ 884 vm86paddr = (vm_offset_t)cur_space; 885 cur_space += (PAGE_SIZE * 3); 886 887#ifdef PAE --- 61 unchanged lines hidden (view full) --- 949 memcpy((uint8_t *)IdlePTDnew + 3*PAGE_SIZE, IdlePTD, PAGE_SIZE/2); 950 printk("do remapping\n"); 951 for (i = 0; i < 4; i++) { 952 PT_SET_MA((uint8_t *)IdlePTDnew + i*PAGE_SIZE, 953 IdlePTDnewma[i] | PG_V); 954 } 955 xen_load_cr3(VTOP(IdlePDPTnew)); 956 xen_pgdpt_pin(xpmap_ptom(VTOP(IdlePDPTnew))); | 886 /* vm86/bios stack */ 887 cur_space += PAGE_SIZE; 888 889 /* Map space for the vm86 region */ 890 vm86paddr = (vm_offset_t)cur_space; 891 cur_space += (PAGE_SIZE * 3); 892 893#ifdef PAE --- 61 unchanged lines hidden (view full) --- 955 memcpy((uint8_t *)IdlePTDnew + 3*PAGE_SIZE, IdlePTD, PAGE_SIZE/2); 956 printk("do remapping\n"); 957 for (i = 0; i < 4; i++) { 958 PT_SET_MA((uint8_t *)IdlePTDnew + i*PAGE_SIZE, 959 IdlePTDnewma[i] | PG_V); 960 } 961 xen_load_cr3(VTOP(IdlePDPTnew)); 962 xen_pgdpt_pin(xpmap_ptom(VTOP(IdlePDPTnew))); |
963 |
|
957 for (i = 0; i < 4; i++) { 958 xen_queue_pt_update((vm_paddr_t)(IdlePTDnewma[2] + (PTDPTDI - 1024 + i)*sizeof(vm_paddr_t)), 959 IdlePTDnewma[i] | PG_V); 960 } 961 962 /* copy NKPT pages */ 963 for (i = 0; i < NKPT; i++) { 964 xen_queue_pt_update( 965 (vm_paddr_t)(IdlePTDnewma[3] + (i)*sizeof(vm_paddr_t)), 966 IdlePTD[i]); 967 } 968 PT_UPDATES_FLUSH(); 969 970 IdlePTD = IdlePTDnew; 971 IdlePDPT = IdlePDPTnew; 972 IdlePDPTma = IdlePDPTnewma; 973 974 /* allocate page for gdt */ | 964 for (i = 0; i < 4; i++) { 965 xen_queue_pt_update((vm_paddr_t)(IdlePTDnewma[2] + (PTDPTDI - 1024 + i)*sizeof(vm_paddr_t)), 966 IdlePTDnewma[i] | PG_V); 967 } 968 969 /* copy NKPT pages */ 970 for (i = 0; i < NKPT; i++) { 971 xen_queue_pt_update( 972 (vm_paddr_t)(IdlePTDnewma[3] + (i)*sizeof(vm_paddr_t)), 973 IdlePTD[i]); 974 } 975 PT_UPDATES_FLUSH(); 976 977 IdlePTD = IdlePTDnew; 978 IdlePDPT = IdlePDPTnew; 979 IdlePDPTma = IdlePDPTnewma; 980 981 /* allocate page for gdt */ |
975 gdt = (union descriptor *)cur_space; cur_space += PAGE_SIZE; 976 /* allocate page for ldt */ 977 ldt = (union descriptor *)cur_space; cur_space += PAGE_SIZE; | 982 gdt = (union descriptor *)cur_space; 983 cur_space += PAGE_SIZE*ncpus; |
978 | 984 |
985 /* allocate page for ldt */ 986 ldt = (union descriptor *)cur_space; cur_space += PAGE_SIZE; 987 cur_space += PAGE_SIZE; 988 |
|
979 HYPERVISOR_shared_info = (shared_info_t *)cur_space; 980 cur_space += PAGE_SIZE; 981 982 /* 983 * shared_info is an unsigned long so this will randomly break if 984 * it is allocated above 4GB - I guess people are used to that 985 * sort of thing with Xen ... sigh 986 */ --- 9 unchanged lines hidden (view full) --- 996 PT_SET_MA(xen_store, xen_store_ma | PG_KERNEL); 997 console_page = (char *)cur_space; 998 cur_space += PAGE_SIZE; 999 console_page_ma = (((vm_paddr_t)xen_start_info->console.domU.mfn) << PAGE_SHIFT); 1000 PT_SET_MA(console_page, console_page_ma | PG_KERNEL); 1001 1002 printk("#5\n"); 1003 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = (unsigned long)xen_phys_machine; | 989 HYPERVISOR_shared_info = (shared_info_t *)cur_space; 990 cur_space += PAGE_SIZE; 991 992 /* 993 * shared_info is an unsigned long so this will randomly break if 994 * it is allocated above 4GB - I guess people are used to that 995 * sort of thing with Xen ... sigh 996 */ --- 9 unchanged lines hidden (view full) --- 1006 PT_SET_MA(xen_store, xen_store_ma | PG_KERNEL); 1007 console_page = (char *)cur_space; 1008 cur_space += PAGE_SIZE; 1009 console_page_ma = (((vm_paddr_t)xen_start_info->console.domU.mfn) << PAGE_SHIFT); 1010 PT_SET_MA(console_page, console_page_ma | PG_KERNEL); 1011 1012 printk("#5\n"); 1013 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = (unsigned long)xen_phys_machine; |
1004#if 0 && defined(SMP) 1005 for (i = 0; i < ncpus; i++) { 1006 int j, npages = (sizeof(struct privatespace) + 1)/PAGE_SIZE; | |
1007 | 1014 |
1008 for (j = 0; j < npages; j++) { 1009 vm_paddr_t ma = xpmap_ptom(cur_space); 1010 cur_space += PAGE_SIZE; 1011 PT_SET_VA_MA(SMPpt + i*npages + j, ma | PG_KERNEL, FALSE); 1012 } 1013 } 1014 xen_flush_queue(); 1015#endif 1016 | |
1017 set_iopl.iopl = 1; 1018 PANIC_IF(HYPERVISOR_physdev_op(PHYSDEVOP_SET_IOPL, &set_iopl)); 1019 printk("#6\n"); 1020#if 0 1021 /* add page table for KERNBASE */ 1022 xen_queue_pt_update(IdlePTDma + KPTDI*sizeof(vm_paddr_t), 1023 xpmap_ptom(VTOP(cur_space) | PG_KERNEL)); 1024 xen_flush_queue(); --- 250 unchanged lines hidden (view full) --- 1275 1276 xencons_resume(); 1277 1278#ifdef CONFIG_SMP 1279 for_each_cpu(i) 1280 vcpu_prepare(i); 1281 1282#endif | 1015 set_iopl.iopl = 1; 1016 PANIC_IF(HYPERVISOR_physdev_op(PHYSDEVOP_SET_IOPL, &set_iopl)); 1017 printk("#6\n"); 1018#if 0 1019 /* add page table for KERNBASE */ 1020 xen_queue_pt_update(IdlePTDma + KPTDI*sizeof(vm_paddr_t), 1021 xpmap_ptom(VTOP(cur_space) | PG_KERNEL)); 1022 xen_flush_queue(); --- 250 unchanged lines hidden (view full) --- 1273 1274 xencons_resume(); 1275 1276#ifdef CONFIG_SMP 1277 for_each_cpu(i) 1278 vcpu_prepare(i); 1279 1280#endif |
1283 | |
1284 /* 1285 * Only resume xenbus /after/ we've prepared our VCPUs; otherwise 1286 * the VCPU hotplug callback can race with our vcpu_prepare 1287 */ 1288 xenbus_resume(); 1289 1290#ifdef CONFIG_SMP 1291 out_reenable_cpus: --- 62 unchanged lines hidden --- | 1281 /* 1282 * Only resume xenbus /after/ we've prepared our VCPUs; otherwise 1283 * the VCPU hotplug callback can race with our vcpu_prepare 1284 */ 1285 xenbus_resume(); 1286 1287#ifdef CONFIG_SMP 1288 out_reenable_cpus: --- 62 unchanged lines hidden --- |