2 * Core of Xen paravirt_ops implementation.
4 * This file contains the xen_paravirt_ops structure itself, and the
6 * - privileged instructions
11 * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/smp.h>
17 #include <linux/preempt.h>
18 #include <linux/hardirq.h>
19 #include <linux/percpu.h>
20 #include <linux/delay.h>
21 #include <linux/start_kernel.h>
22 #include <linux/sched.h>
23 #include <linux/bootmem.h>
24 #include <linux/module.h>
26 #include <linux/page-flags.h>
27 #include <linux/highmem.h>
28 #include <linux/smp.h>
30 #include <xen/interface/xen.h>
31 #include <xen/interface/physdev.h>
32 #include <xen/interface/vcpu.h>
33 #include <xen/interface/sched.h>
34 #include <xen/features.h>
37 #include <asm/paravirt.h>
39 #include <asm/xen/hypercall.h>
40 #include <asm/xen/hypervisor.h>
41 #include <asm/fixmap.h>
42 #include <asm/processor.h>
43 #include <asm/setup.h>
45 #include <asm/pgtable.h>
46 #include <asm/tlbflush.h>
47 #include <asm/reboot.h>
51 #include "multicalls.h"
53 EXPORT_SYMBOL_GPL(hypercall_page);
55 DEFINE_PER_CPU(enum paravirt_lazy_mode, xen_lazy_mode);
57 DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
58 DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info);
59 DEFINE_PER_CPU(unsigned long, xen_cr3);
61 struct start_info *xen_start_info;
62 EXPORT_SYMBOL_GPL(xen_start_info);
64 void xen_vcpu_setup(int cpu)
66 per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu];
69 static void __init xen_banner(void)
71 printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
73 printk(KERN_INFO "Hypervisor signature: %s\n", xen_start_info->magic);
76 static void xen_cpuid(unsigned int *eax, unsigned int *ebx,
77 unsigned int *ecx, unsigned int *edx)
79 unsigned maskedx = ~0;
82 * Mask out inconvenient features, to try and disable as many
83 * unsupported kernel subsystems as possible.
86 maskedx = ~((1 << X86_FEATURE_APIC) | /* disable APIC */
87 (1 << X86_FEATURE_ACPI) | /* disable ACPI */
88 (1 << X86_FEATURE_ACC)); /* thermal monitoring */
90 asm(XEN_EMULATE_PREFIX "cpuid"
95 : "0" (*eax), "2" (*ecx));
99 static void xen_set_debugreg(int reg, unsigned long val)
101 HYPERVISOR_set_debugreg(reg, val);
104 static unsigned long xen_get_debugreg(int reg)
106 return HYPERVISOR_get_debugreg(reg);
109 static unsigned long xen_save_fl(void)
111 struct vcpu_info *vcpu;
114 vcpu = x86_read_percpu(xen_vcpu);
116 /* flag has opposite sense of mask */
117 flags = !vcpu->evtchn_upcall_mask;
119 /* convert to IF type flag
123 return (-flags) & X86_EFLAGS_IF;
126 static void xen_restore_fl(unsigned long flags)
128 struct vcpu_info *vcpu;
130 /* convert from IF type flag */
131 flags = !(flags & X86_EFLAGS_IF);
133 /* There's a one instruction preempt window here. We need to
134 make sure we're don't switch CPUs between getting the vcpu
135 pointer and updating the mask. */
137 vcpu = x86_read_percpu(xen_vcpu);
138 vcpu->evtchn_upcall_mask = flags;
139 preempt_enable_no_resched();
141 /* Doesn't matter if we get preempted here, because any
142 pending event will get dealt with anyway. */
145 preempt_check_resched();
146 barrier(); /* unmask then check (avoid races) */
147 if (unlikely(vcpu->evtchn_upcall_pending))
148 force_evtchn_callback();
152 static void xen_irq_disable(void)
154 /* There's a one instruction preempt window here. We need to
155 make sure we're don't switch CPUs between getting the vcpu
156 pointer and updating the mask. */
158 x86_read_percpu(xen_vcpu)->evtchn_upcall_mask = 1;
159 preempt_enable_no_resched();
162 static void xen_irq_enable(void)
164 struct vcpu_info *vcpu;
166 /* There's a one instruction preempt window here. We need to
167 make sure we're don't switch CPUs between getting the vcpu
168 pointer and updating the mask. */
170 vcpu = x86_read_percpu(xen_vcpu);
171 vcpu->evtchn_upcall_mask = 0;
172 preempt_enable_no_resched();
174 /* Doesn't matter if we get preempted here, because any
175 pending event will get dealt with anyway. */
177 barrier(); /* unmask then check (avoid races) */
178 if (unlikely(vcpu->evtchn_upcall_pending))
179 force_evtchn_callback();
182 static void xen_safe_halt(void)
184 /* Blocking includes an implicit local_irq_enable(). */
185 if (HYPERVISOR_sched_op(SCHEDOP_block, 0) != 0)
189 static void xen_halt(void)
192 HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
197 static void xen_set_lazy_mode(enum paravirt_lazy_mode mode)
199 BUG_ON(preemptible());
202 case PARAVIRT_LAZY_NONE:
203 BUG_ON(x86_read_percpu(xen_lazy_mode) == PARAVIRT_LAZY_NONE);
206 case PARAVIRT_LAZY_MMU:
207 case PARAVIRT_LAZY_CPU:
208 BUG_ON(x86_read_percpu(xen_lazy_mode) != PARAVIRT_LAZY_NONE);
211 case PARAVIRT_LAZY_FLUSH:
212 /* flush if necessary, but don't change state */
213 if (x86_read_percpu(xen_lazy_mode) != PARAVIRT_LAZY_NONE)
219 x86_write_percpu(xen_lazy_mode, mode);
222 static unsigned long xen_store_tr(void)
227 static void xen_set_ldt(const void *addr, unsigned entries)
229 unsigned long linear_addr = (unsigned long)addr;
230 struct mmuext_op *op;
231 struct multicall_space mcs = xen_mc_entry(sizeof(*op));
234 op->cmd = MMUEXT_SET_LDT;
236 /* ldt my be vmalloced, use arbitrary_virt_to_machine */
238 maddr = arbitrary_virt_to_machine((unsigned long)addr);
239 linear_addr = (unsigned long)maddr.maddr;
241 op->arg1.linear_addr = linear_addr;
242 op->arg2.nr_ents = entries;
244 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
246 xen_mc_issue(PARAVIRT_LAZY_CPU);
249 static void xen_load_gdt(const struct Xgt_desc_struct *dtr)
251 unsigned long *frames;
252 unsigned long va = dtr->address;
253 unsigned int size = dtr->size + 1;
254 unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
256 struct multicall_space mcs;
258 /* A GDT can be up to 64k in size, which corresponds to 8192
259 8-byte entries, or 16 4k pages.. */
261 BUG_ON(size > 65536);
262 BUG_ON(va & ~PAGE_MASK);
264 mcs = xen_mc_entry(sizeof(*frames) * pages);
267 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
268 frames[f] = virt_to_mfn(va);
269 make_lowmem_page_readonly((void *)va);
272 MULTI_set_gdt(mcs.mc, frames, size / sizeof(struct desc_struct));
274 xen_mc_issue(PARAVIRT_LAZY_CPU);
277 static void load_TLS_descriptor(struct thread_struct *t,
278 unsigned int cpu, unsigned int i)
280 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
281 xmaddr_t maddr = virt_to_machine(&gdt[GDT_ENTRY_TLS_MIN+i]);
282 struct multicall_space mc = __xen_mc_entry(0);
284 MULTI_update_descriptor(mc.mc, maddr.maddr, t->tls_array[i]);
287 static void xen_load_tls(struct thread_struct *t, unsigned int cpu)
291 load_TLS_descriptor(t, cpu, 0);
292 load_TLS_descriptor(t, cpu, 1);
293 load_TLS_descriptor(t, cpu, 2);
295 xen_mc_issue(PARAVIRT_LAZY_CPU);
298 * XXX sleazy hack: If we're being called in a lazy-cpu zone,
299 * it means we're in a context switch, and %gs has just been
300 * saved. This means we can zero it out to prevent faults on
301 * exit from the hypervisor if the next process has no %gs.
302 * Either way, it has been saved, and the new value will get
303 * loaded properly. This will go away as soon as Xen has been
304 * modified to not save/restore %gs for normal hypercalls.
306 if (xen_get_lazy_mode() == PARAVIRT_LAZY_CPU)
310 static void xen_write_ldt_entry(struct desc_struct *dt, int entrynum,
313 unsigned long lp = (unsigned long)&dt[entrynum];
314 xmaddr_t mach_lp = virt_to_machine(lp);
315 u64 entry = (u64)high << 32 | low;
320 if (HYPERVISOR_update_descriptor(mach_lp.maddr, entry))
326 static int cvt_gate_to_trap(int vector, u32 low, u32 high,
327 struct trap_info *info)
331 type = (high >> 8) & 0x1f;
332 dpl = (high >> 13) & 3;
334 if (type != 0xf && type != 0xe)
337 info->vector = vector;
338 info->address = (high & 0xffff0000) | (low & 0x0000ffff);
339 info->cs = low >> 16;
341 /* interrupt gates clear IF */
348 /* Locations of each CPU's IDT */
349 static DEFINE_PER_CPU(struct Xgt_desc_struct, idt_desc);
351 /* Set an IDT entry. If the entry is part of the current IDT, then
353 static void xen_write_idt_entry(struct desc_struct *dt, int entrynum,
356 unsigned long p = (unsigned long)&dt[entrynum];
357 unsigned long start, end;
361 start = __get_cpu_var(idt_desc).address;
362 end = start + __get_cpu_var(idt_desc).size + 1;
366 write_dt_entry(dt, entrynum, low, high);
368 if (p >= start && (p + 8) <= end) {
369 struct trap_info info[2];
373 if (cvt_gate_to_trap(entrynum, low, high, &info[0]))
374 if (HYPERVISOR_set_trap_table(info))
381 static void xen_convert_trap_info(const struct Xgt_desc_struct *desc,
382 struct trap_info *traps)
384 unsigned in, out, count;
386 count = (desc->size+1) / 8;
389 for (in = out = 0; in < count; in++) {
390 const u32 *entry = (u32 *)(desc->address + in * 8);
392 if (cvt_gate_to_trap(in, entry[0], entry[1], &traps[out]))
395 traps[out].address = 0;
398 void xen_copy_trap_info(struct trap_info *traps)
400 const struct Xgt_desc_struct *desc = &__get_cpu_var(idt_desc);
402 xen_convert_trap_info(desc, traps);
405 /* Load a new IDT into Xen. In principle this can be per-CPU, so we
406 hold a spinlock to protect the static traps[] array (static because
407 it avoids allocation, and saves stack space). */
408 static void xen_load_idt(const struct Xgt_desc_struct *desc)
410 static DEFINE_SPINLOCK(lock);
411 static struct trap_info traps[257];
415 __get_cpu_var(idt_desc) = *desc;
417 xen_convert_trap_info(desc, traps);
420 if (HYPERVISOR_set_trap_table(traps))
426 /* Write a GDT descriptor entry. Ignore LDT descriptors, since
427 they're handled differently. */
428 static void xen_write_gdt_entry(struct desc_struct *dt, int entry,
433 switch ((high >> 8) & 0xff) {
440 xmaddr_t maddr = virt_to_machine(&dt[entry]);
441 u64 desc = (u64)high << 32 | low;
444 if (HYPERVISOR_update_descriptor(maddr.maddr, desc))
453 static void xen_load_esp0(struct tss_struct *tss,
454 struct thread_struct *thread)
456 struct multicall_space mcs = xen_mc_entry(0);
457 MULTI_stack_switch(mcs.mc, __KERNEL_DS, thread->esp0);
458 xen_mc_issue(PARAVIRT_LAZY_CPU);
461 static void xen_set_iopl_mask(unsigned mask)
463 struct physdev_set_iopl set_iopl;
465 /* Force the change at ring 0. */
466 set_iopl.iopl = (mask == 0) ? 1 : (mask >> 12) & 3;
467 HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
470 static void xen_io_delay(void)
474 #ifdef CONFIG_X86_LOCAL_APIC
475 static unsigned long xen_apic_read(unsigned long reg)
480 static void xen_apic_write(unsigned long reg, unsigned long val)
482 /* Warn to see if there's any stray references */
487 static void xen_flush_tlb(void)
489 struct mmuext_op *op;
490 struct multicall_space mcs = xen_mc_entry(sizeof(*op));
493 op->cmd = MMUEXT_TLB_FLUSH_LOCAL;
494 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
496 xen_mc_issue(PARAVIRT_LAZY_MMU);
499 static void xen_flush_tlb_single(unsigned long addr)
501 struct mmuext_op *op;
502 struct multicall_space mcs = xen_mc_entry(sizeof(*op));
505 op->cmd = MMUEXT_INVLPG_LOCAL;
506 op->arg1.linear_addr = addr & PAGE_MASK;
507 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
509 xen_mc_issue(PARAVIRT_LAZY_MMU);
512 static void xen_flush_tlb_others(const cpumask_t *cpus, struct mm_struct *mm,
519 cpumask_t cpumask = *cpus;
520 struct multicall_space mcs;
523 * A couple of (to be removed) sanity checks:
525 * - current CPU must not be in mask
526 * - mask must exist :)
528 BUG_ON(cpus_empty(cpumask));
529 BUG_ON(cpu_isset(smp_processor_id(), cpumask));
532 /* If a CPU which we ran on has gone down, OK. */
533 cpus_and(cpumask, cpumask, cpu_online_map);
534 if (cpus_empty(cpumask))
537 mcs = xen_mc_entry(sizeof(*args));
539 args->mask = cpumask;
540 args->op.arg2.vcpumask = &args->mask;
542 if (va == TLB_FLUSH_ALL) {
543 args->op.cmd = MMUEXT_TLB_FLUSH_MULTI;
545 args->op.cmd = MMUEXT_INVLPG_MULTI;
546 args->op.arg1.linear_addr = va;
549 MULTI_mmuext_op(mcs.mc, &args->op, 1, NULL, DOMID_SELF);
551 xen_mc_issue(PARAVIRT_LAZY_MMU);
554 static unsigned long xen_read_cr2(void)
556 return x86_read_percpu(xen_vcpu)->arch.cr2;
559 static void xen_write_cr4(unsigned long cr4)
561 /* never allow TSC to be disabled */
562 native_write_cr4(cr4 & ~X86_CR4_TSD);
565 static unsigned long xen_read_cr3(void)
567 return x86_read_percpu(xen_cr3);
570 static void xen_write_cr3(unsigned long cr3)
572 BUG_ON(preemptible());
574 if (cr3 == x86_read_percpu(xen_cr3)) {
575 /* just a simple tlb flush */
580 x86_write_percpu(xen_cr3, cr3);
584 struct mmuext_op *op;
585 struct multicall_space mcs = xen_mc_entry(sizeof(*op));
586 unsigned long mfn = pfn_to_mfn(PFN_DOWN(cr3));
589 op->cmd = MMUEXT_NEW_BASEPTR;
592 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
594 xen_mc_issue(PARAVIRT_LAZY_CPU);
598 /* Early in boot, while setting up the initial pagetable, assume
599 everything is pinned. */
600 static __init void xen_alloc_pt_init(struct mm_struct *mm, u32 pfn)
602 BUG_ON(mem_map); /* should only be used early */
603 make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
606 /* This needs to make sure the new pte page is pinned iff its being
607 attached to a pinned pagetable. */
608 static void xen_alloc_pt(struct mm_struct *mm, u32 pfn)
610 struct page *page = pfn_to_page(pfn);
612 if (PagePinned(virt_to_page(mm->pgd))) {
615 if (!PageHighMem(page))
616 make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
618 /* make sure there are no stray mappings of
624 /* This should never happen until we're OK to use struct page */
625 static void xen_release_pt(u32 pfn)
627 struct page *page = pfn_to_page(pfn);
629 if (PagePinned(page)) {
630 if (!PageHighMem(page))
631 make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
635 #ifdef CONFIG_HIGHPTE
636 static void *xen_kmap_atomic_pte(struct page *page, enum km_type type)
638 pgprot_t prot = PAGE_KERNEL;
640 if (PagePinned(page))
641 prot = PAGE_KERNEL_RO;
643 if (0 && PageHighMem(page))
644 printk("mapping highpte %lx type %d prot %s\n",
645 page_to_pfn(page), type,
646 (unsigned long)pgprot_val(prot) & _PAGE_RW ? "WRITE" : "READ");
648 return kmap_atomic_prot(page, type, prot);
652 static __init pte_t mask_rw_pte(pte_t *ptep, pte_t pte)
654 /* If there's an existing pte, then don't allow _PAGE_RW to be set */
655 if (pte_val_ma(*ptep) & _PAGE_PRESENT)
656 pte = __pte_ma(((pte_val_ma(*ptep) & _PAGE_RW) | ~_PAGE_RW) &
662 /* Init-time set_pte while constructing initial pagetables, which
663 doesn't allow RO pagetable pages to be remapped RW */
664 static __init void xen_set_pte_init(pte_t *ptep, pte_t pte)
666 pte = mask_rw_pte(ptep, pte);
668 xen_set_pte(ptep, pte);
671 static __init void xen_pagetable_setup_start(pgd_t *base)
673 pgd_t *xen_pgd = (pgd_t *)xen_start_info->pt_base;
675 /* special set_pte for pagetable initialization */
676 paravirt_ops.set_pte = xen_set_pte_init;
680 * copy top-level of Xen-supplied pagetable into place. For
681 * !PAE we can use this as-is, but for PAE it is a stand-in
682 * while we copy the pmd pages.
684 memcpy(base, xen_pgd, PTRS_PER_PGD * sizeof(pgd_t));
686 if (PTRS_PER_PMD > 1) {
689 * For PAE, need to allocate new pmds, rather than
690 * share Xen's, since Xen doesn't like pmd's being
691 * shared between address spaces.
693 for (i = 0; i < PTRS_PER_PGD; i++) {
694 if (pgd_val_ma(xen_pgd[i]) & _PAGE_PRESENT) {
695 pmd_t *pmd = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
697 memcpy(pmd, (void *)pgd_page_vaddr(xen_pgd[i]),
700 make_lowmem_page_readonly(pmd);
702 set_pgd(&base[i], __pgd(1 + __pa(pmd)));
708 /* make sure zero_page is mapped RO so we can use it in pagetables */
709 make_lowmem_page_readonly(empty_zero_page);
710 make_lowmem_page_readonly(base);
712 * Switch to new pagetable. This is done before
713 * pagetable_init has done anything so that the new pages
714 * added to the table can be prepared properly for Xen.
716 xen_write_cr3(__pa(base));
719 static __init void xen_pagetable_setup_done(pgd_t *base)
721 /* This will work as long as patching hasn't happened yet
723 paravirt_ops.alloc_pt = xen_alloc_pt;
724 paravirt_ops.set_pte = xen_set_pte;
726 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
728 * Create a mapping for the shared info page.
729 * Should be set_fixmap(), but shared_info is a machine
730 * address with no corresponding pseudo-phys address.
732 set_pte_mfn(fix_to_virt(FIX_PARAVIRT_BOOTMAP),
733 PFN_DOWN(xen_start_info->shared_info),
736 HYPERVISOR_shared_info =
737 (struct shared_info *)fix_to_virt(FIX_PARAVIRT_BOOTMAP);
740 HYPERVISOR_shared_info =
741 (struct shared_info *)__va(xen_start_info->shared_info);
743 /* Actually pin the pagetable down, but we can't set PG_pinned
744 yet because the page structures don't exist yet. */
747 #ifdef CONFIG_X86_PAE
748 op.cmd = MMUEXT_PIN_L3_TABLE;
750 op.cmd = MMUEXT_PIN_L3_TABLE;
752 op.arg1.mfn = pfn_to_mfn(PFN_DOWN(__pa(base)));
753 if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
757 xen_vcpu_setup(smp_processor_id());
760 static const struct paravirt_ops xen_paravirt_ops __initdata = {
761 .paravirt_enabled = 1,
762 .shared_kernel_pmd = 0,
765 .banner = xen_banner,
767 .patch = paravirt_patch_default,
769 .memory_setup = xen_memory_setup,
770 .arch_setup = xen_arch_setup,
771 .init_IRQ = xen_init_IRQ,
772 .post_allocator_init = xen_mark_init_mm_pinned,
774 .time_init = xen_time_init,
775 .set_wallclock = xen_set_wallclock,
776 .get_wallclock = xen_get_wallclock,
777 .get_cpu_khz = xen_cpu_khz,
778 .sched_clock = xen_sched_clock,
782 .set_debugreg = xen_set_debugreg,
783 .get_debugreg = xen_get_debugreg,
787 .read_cr0 = native_read_cr0,
788 .write_cr0 = native_write_cr0,
790 .read_cr2 = xen_read_cr2,
791 .write_cr2 = native_write_cr2,
793 .read_cr3 = xen_read_cr3,
794 .write_cr3 = xen_write_cr3,
796 .read_cr4 = native_read_cr4,
797 .read_cr4_safe = native_read_cr4_safe,
798 .write_cr4 = xen_write_cr4,
800 .save_fl = xen_save_fl,
801 .restore_fl = xen_restore_fl,
802 .irq_disable = xen_irq_disable,
803 .irq_enable = xen_irq_enable,
804 .safe_halt = xen_safe_halt,
806 .wbinvd = native_wbinvd,
808 .read_msr = native_read_msr_safe,
809 .write_msr = native_write_msr_safe,
810 .read_tsc = native_read_tsc,
811 .read_pmc = native_read_pmc,
813 .iret = (void *)&hypercall_page[__HYPERVISOR_iret],
814 .irq_enable_sysexit = NULL, /* never called */
816 .load_tr_desc = paravirt_nop,
817 .set_ldt = xen_set_ldt,
818 .load_gdt = xen_load_gdt,
819 .load_idt = xen_load_idt,
820 .load_tls = xen_load_tls,
822 .store_gdt = native_store_gdt,
823 .store_idt = native_store_idt,
824 .store_tr = xen_store_tr,
826 .write_ldt_entry = xen_write_ldt_entry,
827 .write_gdt_entry = xen_write_gdt_entry,
828 .write_idt_entry = xen_write_idt_entry,
829 .load_esp0 = xen_load_esp0,
831 .set_iopl_mask = xen_set_iopl_mask,
832 .io_delay = xen_io_delay,
834 #ifdef CONFIG_X86_LOCAL_APIC
835 .apic_write = xen_apic_write,
836 .apic_write_atomic = xen_apic_write,
837 .apic_read = xen_apic_read,
838 .setup_boot_clock = paravirt_nop,
839 .setup_secondary_clock = paravirt_nop,
840 .startup_ipi_hook = paravirt_nop,
843 .flush_tlb_user = xen_flush_tlb,
844 .flush_tlb_kernel = xen_flush_tlb,
845 .flush_tlb_single = xen_flush_tlb_single,
846 .flush_tlb_others = xen_flush_tlb_others,
848 .pte_update = paravirt_nop,
849 .pte_update_defer = paravirt_nop,
851 .pagetable_setup_start = xen_pagetable_setup_start,
852 .pagetable_setup_done = xen_pagetable_setup_done,
854 .alloc_pt = xen_alloc_pt_init,
855 .release_pt = xen_release_pt,
856 .alloc_pd = paravirt_nop,
857 .alloc_pd_clone = paravirt_nop,
858 .release_pd = paravirt_nop,
860 #ifdef CONFIG_HIGHPTE
861 .kmap_atomic_pte = xen_kmap_atomic_pte,
864 .set_pte = NULL, /* see xen_pagetable_setup_* */
865 .set_pte_at = xen_set_pte_at,
866 .set_pmd = xen_set_pmd,
868 .pte_val = xen_pte_val,
869 .pgd_val = xen_pgd_val,
871 .make_pte = xen_make_pte,
872 .make_pgd = xen_make_pgd,
874 #ifdef CONFIG_X86_PAE
875 .set_pte_atomic = xen_set_pte_atomic,
876 .set_pte_present = xen_set_pte_at,
877 .set_pud = xen_set_pud,
878 .pte_clear = xen_pte_clear,
879 .pmd_clear = xen_pmd_clear,
881 .make_pmd = xen_make_pmd,
882 .pmd_val = xen_pmd_val,
885 .activate_mm = xen_activate_mm,
886 .dup_mmap = xen_dup_mmap,
887 .exit_mmap = xen_exit_mmap,
889 .set_lazy_mode = xen_set_lazy_mode,
893 static const struct smp_ops xen_smp_ops __initdata = {
894 .smp_prepare_boot_cpu = xen_smp_prepare_boot_cpu,
895 .smp_prepare_cpus = xen_smp_prepare_cpus,
896 .cpu_up = xen_cpu_up,
897 .smp_cpus_done = xen_smp_cpus_done,
899 .smp_send_stop = xen_smp_send_stop,
900 .smp_send_reschedule = xen_smp_send_reschedule,
901 .smp_call_function_mask = xen_smp_call_function_mask,
903 #endif /* CONFIG_SMP */
905 static void xen_reboot(int reason)
911 if (HYPERVISOR_sched_op(SCHEDOP_shutdown, reason))
915 static void xen_restart(char *msg)
917 xen_reboot(SHUTDOWN_reboot);
920 static void xen_emergency_restart(void)
922 xen_reboot(SHUTDOWN_reboot);
925 static void xen_machine_halt(void)
927 xen_reboot(SHUTDOWN_poweroff);
930 static void xen_crash_shutdown(struct pt_regs *regs)
932 xen_reboot(SHUTDOWN_crash);
935 static const struct machine_ops __initdata xen_machine_ops = {
936 .restart = xen_restart,
937 .halt = xen_machine_halt,
938 .power_off = xen_machine_halt,
939 .shutdown = xen_machine_halt,
940 .crash_shutdown = xen_crash_shutdown,
941 .emergency_restart = xen_emergency_restart,
944 /* First C function to be called on Xen boot */
945 asmlinkage void __init xen_start_kernel(void)
952 BUG_ON(memcmp(xen_start_info->magic, "xen-3.0", 7) != 0);
954 /* Install Xen paravirt ops */
955 paravirt_ops = xen_paravirt_ops;
956 machine_ops = xen_machine_ops;
959 smp_ops = xen_smp_ops;
962 xen_setup_features();
965 if (!xen_feature(XENFEAT_auto_translated_physmap))
966 phys_to_machine_mapping = (unsigned long *)xen_start_info->mfn_list;
968 pgd = (pgd_t *)xen_start_info->pt_base;
970 init_pg_tables_end = __pa(pgd) + xen_start_info->nr_pt_frames*PAGE_SIZE;
972 init_mm.pgd = pgd; /* use the Xen pagetables to start */
974 /* keep using Xen gdt for now; no urgent need to change it */
976 x86_write_percpu(xen_cr3, __pa(pgd));
979 paravirt_ops.kernel_rpl = 1;
980 if (xen_feature(XENFEAT_supervisor_mode_kernel))
981 paravirt_ops.kernel_rpl = 0;
983 /* set the limit of our address space */
984 reserve_top_address(-HYPERVISOR_VIRT_START + 2 * PAGE_SIZE);
986 /* set up basic CPUID stuff */
987 cpu_detect(&new_cpu_data);
988 new_cpu_data.hard_math = 1;
989 new_cpu_data.x86_capability[0] = cpuid_edx(1);
991 /* Poke various useful things into boot_params */
992 LOADER_TYPE = (9 << 4) | 0;
993 INITRD_START = xen_start_info->mod_start ? __pa(xen_start_info->mod_start) : 0;
994 INITRD_SIZE = xen_start_info->mod_len;
996 /* Start the world */