xen: Complete pagetable pinning
[linux-2.6/sactl.git] / arch / i386 / xen / enlighten.c
blob86e68e680116c1950b4e4ffbfc1c83324b4fc8ba
1 /*
2 * Core of Xen paravirt_ops implementation.
4 * This file contains the xen_paravirt_ops structure itself, and the
5 * implementations for:
6 * - privileged instructions
7 * - interrupt flags
8 * - segment operations
9 * - booting and setup
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/percpu.h>
19 #include <linux/delay.h>
20 #include <linux/start_kernel.h>
21 #include <linux/sched.h>
22 #include <linux/bootmem.h>
23 #include <linux/module.h>
24 #include <linux/mm.h>
25 #include <linux/page-flags.h>
26 #include <linux/highmem.h>
28 #include <xen/interface/xen.h>
29 #include <xen/interface/physdev.h>
30 #include <xen/interface/vcpu.h>
31 #include <xen/features.h>
32 #include <xen/page.h>
34 #include <asm/paravirt.h>
35 #include <asm/page.h>
36 #include <asm/xen/hypercall.h>
37 #include <asm/xen/hypervisor.h>
38 #include <asm/fixmap.h>
39 #include <asm/processor.h>
40 #include <asm/setup.h>
41 #include <asm/desc.h>
42 #include <asm/pgtable.h>
44 #include "xen-ops.h"
45 #include "mmu.h"
46 #include "multicalls.h"
48 EXPORT_SYMBOL_GPL(hypercall_page);
50 DEFINE_PER_CPU(enum paravirt_lazy_mode, xen_lazy_mode);
52 DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
53 DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info);
54 DEFINE_PER_CPU(unsigned long, xen_cr3);
56 struct start_info *xen_start_info;
57 EXPORT_SYMBOL_GPL(xen_start_info);
59 static void xen_vcpu_setup(int cpu)
61 per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu];
64 static void __init xen_banner(void)
66 printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
67 paravirt_ops.name);
68 printk(KERN_INFO "Hypervisor signature: %s\n", xen_start_info->magic);
71 static void xen_cpuid(unsigned int *eax, unsigned int *ebx,
72 unsigned int *ecx, unsigned int *edx)
74 unsigned maskedx = ~0;
77 * Mask out inconvenient features, to try and disable as many
78 * unsupported kernel subsystems as possible.
80 if (*eax == 1)
81 maskedx = ~((1 << X86_FEATURE_APIC) | /* disable APIC */
82 (1 << X86_FEATURE_ACPI) | /* disable ACPI */
83 (1 << X86_FEATURE_ACC)); /* thermal monitoring */
85 asm(XEN_EMULATE_PREFIX "cpuid"
86 : "=a" (*eax),
87 "=b" (*ebx),
88 "=c" (*ecx),
89 "=d" (*edx)
90 : "0" (*eax), "2" (*ecx));
91 *edx &= maskedx;
94 static void xen_set_debugreg(int reg, unsigned long val)
96 HYPERVISOR_set_debugreg(reg, val);
99 static unsigned long xen_get_debugreg(int reg)
101 return HYPERVISOR_get_debugreg(reg);
104 static unsigned long xen_save_fl(void)
106 struct vcpu_info *vcpu;
107 unsigned long flags;
109 preempt_disable();
110 vcpu = x86_read_percpu(xen_vcpu);
111 /* flag has opposite sense of mask */
112 flags = !vcpu->evtchn_upcall_mask;
113 preempt_enable();
115 /* convert to IF type flag
116 -0 -> 0x00000000
117 -1 -> 0xffffffff
119 return (-flags) & X86_EFLAGS_IF;
122 static void xen_restore_fl(unsigned long flags)
124 struct vcpu_info *vcpu;
126 preempt_disable();
128 /* convert from IF type flag */
129 flags = !(flags & X86_EFLAGS_IF);
130 vcpu = x86_read_percpu(xen_vcpu);
131 vcpu->evtchn_upcall_mask = flags;
133 if (flags == 0) {
134 /* Unmask then check (avoid races). We're only protecting
135 against updates by this CPU, so there's no need for
136 anything stronger. */
137 barrier();
139 if (unlikely(vcpu->evtchn_upcall_pending))
140 force_evtchn_callback();
141 preempt_enable();
142 } else
143 preempt_enable_no_resched();
146 static void xen_irq_disable(void)
148 struct vcpu_info *vcpu;
149 preempt_disable();
150 vcpu = x86_read_percpu(xen_vcpu);
151 vcpu->evtchn_upcall_mask = 1;
152 preempt_enable_no_resched();
155 static void xen_irq_enable(void)
157 struct vcpu_info *vcpu;
159 preempt_disable();
160 vcpu = x86_read_percpu(xen_vcpu);
161 vcpu->evtchn_upcall_mask = 0;
163 /* Unmask then check (avoid races). We're only protecting
164 against updates by this CPU, so there's no need for
165 anything stronger. */
166 barrier();
168 if (unlikely(vcpu->evtchn_upcall_pending))
169 force_evtchn_callback();
170 preempt_enable();
173 static void xen_safe_halt(void)
175 /* Blocking includes an implicit local_irq_enable(). */
176 if (HYPERVISOR_sched_op(SCHEDOP_block, 0) != 0)
177 BUG();
180 static void xen_halt(void)
182 if (irqs_disabled())
183 HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
184 else
185 xen_safe_halt();
188 static void xen_set_lazy_mode(enum paravirt_lazy_mode mode)
190 switch (mode) {
191 case PARAVIRT_LAZY_NONE:
192 BUG_ON(x86_read_percpu(xen_lazy_mode) == PARAVIRT_LAZY_NONE);
193 break;
195 case PARAVIRT_LAZY_MMU:
196 case PARAVIRT_LAZY_CPU:
197 BUG_ON(x86_read_percpu(xen_lazy_mode) != PARAVIRT_LAZY_NONE);
198 break;
200 case PARAVIRT_LAZY_FLUSH:
201 /* flush if necessary, but don't change state */
202 if (x86_read_percpu(xen_lazy_mode) != PARAVIRT_LAZY_NONE)
203 xen_mc_flush();
204 return;
207 xen_mc_flush();
208 x86_write_percpu(xen_lazy_mode, mode);
211 static unsigned long xen_store_tr(void)
213 return 0;
216 static void xen_set_ldt(const void *addr, unsigned entries)
218 unsigned long linear_addr = (unsigned long)addr;
219 struct mmuext_op *op;
220 struct multicall_space mcs = xen_mc_entry(sizeof(*op));
222 op = mcs.args;
223 op->cmd = MMUEXT_SET_LDT;
224 if (linear_addr) {
225 /* ldt my be vmalloced, use arbitrary_virt_to_machine */
226 xmaddr_t maddr;
227 maddr = arbitrary_virt_to_machine((unsigned long)addr);
228 linear_addr = (unsigned long)maddr.maddr;
230 op->arg1.linear_addr = linear_addr;
231 op->arg2.nr_ents = entries;
233 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
235 xen_mc_issue(PARAVIRT_LAZY_CPU);
238 static void xen_load_gdt(const struct Xgt_desc_struct *dtr)
240 unsigned long *frames;
241 unsigned long va = dtr->address;
242 unsigned int size = dtr->size + 1;
243 unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
244 int f;
245 struct multicall_space mcs;
247 /* A GDT can be up to 64k in size, which corresponds to 8192
248 8-byte entries, or 16 4k pages.. */
250 BUG_ON(size > 65536);
251 BUG_ON(va & ~PAGE_MASK);
253 mcs = xen_mc_entry(sizeof(*frames) * pages);
254 frames = mcs.args;
256 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
257 frames[f] = virt_to_mfn(va);
258 make_lowmem_page_readonly((void *)va);
261 MULTI_set_gdt(mcs.mc, frames, size / sizeof(struct desc_struct));
263 xen_mc_issue(PARAVIRT_LAZY_CPU);
266 static void load_TLS_descriptor(struct thread_struct *t,
267 unsigned int cpu, unsigned int i)
269 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
270 xmaddr_t maddr = virt_to_machine(&gdt[GDT_ENTRY_TLS_MIN+i]);
271 struct multicall_space mc = __xen_mc_entry(0);
273 MULTI_update_descriptor(mc.mc, maddr.maddr, t->tls_array[i]);
276 static void xen_load_tls(struct thread_struct *t, unsigned int cpu)
278 xen_mc_batch();
280 load_TLS_descriptor(t, cpu, 0);
281 load_TLS_descriptor(t, cpu, 1);
282 load_TLS_descriptor(t, cpu, 2);
284 xen_mc_issue(PARAVIRT_LAZY_CPU);
287 static void xen_write_ldt_entry(struct desc_struct *dt, int entrynum,
288 u32 low, u32 high)
290 unsigned long lp = (unsigned long)&dt[entrynum];
291 xmaddr_t mach_lp = virt_to_machine(lp);
292 u64 entry = (u64)high << 32 | low;
294 xen_mc_flush();
295 if (HYPERVISOR_update_descriptor(mach_lp.maddr, entry))
296 BUG();
299 static int cvt_gate_to_trap(int vector, u32 low, u32 high,
300 struct trap_info *info)
302 u8 type, dpl;
304 type = (high >> 8) & 0x1f;
305 dpl = (high >> 13) & 3;
307 if (type != 0xf && type != 0xe)
308 return 0;
310 info->vector = vector;
311 info->address = (high & 0xffff0000) | (low & 0x0000ffff);
312 info->cs = low >> 16;
313 info->flags = dpl;
314 /* interrupt gates clear IF */
315 if (type == 0xe)
316 info->flags |= 4;
318 return 1;
321 /* Locations of each CPU's IDT */
322 static DEFINE_PER_CPU(struct Xgt_desc_struct, idt_desc);
324 /* Set an IDT entry. If the entry is part of the current IDT, then
325 also update Xen. */
326 static void xen_write_idt_entry(struct desc_struct *dt, int entrynum,
327 u32 low, u32 high)
330 int cpu = smp_processor_id();
331 unsigned long p = (unsigned long)&dt[entrynum];
332 unsigned long start = per_cpu(idt_desc, cpu).address;
333 unsigned long end = start + per_cpu(idt_desc, cpu).size + 1;
335 xen_mc_flush();
337 write_dt_entry(dt, entrynum, low, high);
339 if (p >= start && (p + 8) <= end) {
340 struct trap_info info[2];
342 info[1].address = 0;
344 if (cvt_gate_to_trap(entrynum, low, high, &info[0]))
345 if (HYPERVISOR_set_trap_table(info))
346 BUG();
350 /* Load a new IDT into Xen. In principle this can be per-CPU, so we
351 hold a spinlock to protect the static traps[] array (static because
352 it avoids allocation, and saves stack space). */
353 static void xen_load_idt(const struct Xgt_desc_struct *desc)
355 static DEFINE_SPINLOCK(lock);
356 static struct trap_info traps[257];
358 int cpu = smp_processor_id();
359 unsigned in, out, count;
361 per_cpu(idt_desc, cpu) = *desc;
363 count = (desc->size+1) / 8;
364 BUG_ON(count > 256);
366 spin_lock(&lock);
367 for (in = out = 0; in < count; in++) {
368 const u32 *entry = (u32 *)(desc->address + in * 8);
370 if (cvt_gate_to_trap(in, entry[0], entry[1], &traps[out]))
371 out++;
373 traps[out].address = 0;
375 xen_mc_flush();
376 if (HYPERVISOR_set_trap_table(traps))
377 BUG();
379 spin_unlock(&lock);
382 /* Write a GDT descriptor entry. Ignore LDT descriptors, since
383 they're handled differently. */
384 static void xen_write_gdt_entry(struct desc_struct *dt, int entry,
385 u32 low, u32 high)
387 switch ((high >> 8) & 0xff) {
388 case DESCTYPE_LDT:
389 case DESCTYPE_TSS:
390 /* ignore */
391 break;
393 default: {
394 xmaddr_t maddr = virt_to_machine(&dt[entry]);
395 u64 desc = (u64)high << 32 | low;
397 xen_mc_flush();
398 if (HYPERVISOR_update_descriptor(maddr.maddr, desc))
399 BUG();
405 static void xen_load_esp0(struct tss_struct *tss,
406 struct thread_struct *thread)
408 struct multicall_space mcs = xen_mc_entry(0);
409 MULTI_stack_switch(mcs.mc, __KERNEL_DS, thread->esp0);
410 xen_mc_issue(PARAVIRT_LAZY_CPU);
413 static void xen_set_iopl_mask(unsigned mask)
415 struct physdev_set_iopl set_iopl;
417 /* Force the change at ring 0. */
418 set_iopl.iopl = (mask == 0) ? 1 : (mask >> 12) & 3;
419 HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
422 static void xen_io_delay(void)
426 #ifdef CONFIG_X86_LOCAL_APIC
427 static unsigned long xen_apic_read(unsigned long reg)
429 return 0;
431 #endif
433 static void xen_flush_tlb(void)
435 struct mmuext_op op;
437 op.cmd = MMUEXT_TLB_FLUSH_LOCAL;
438 if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
439 BUG();
442 static void xen_flush_tlb_single(unsigned long addr)
444 struct mmuext_op op;
446 op.cmd = MMUEXT_INVLPG_LOCAL;
447 op.arg1.linear_addr = addr & PAGE_MASK;
448 if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
449 BUG();
452 static unsigned long xen_read_cr2(void)
454 return x86_read_percpu(xen_vcpu)->arch.cr2;
457 static void xen_write_cr4(unsigned long cr4)
459 /* never allow TSC to be disabled */
460 native_write_cr4(cr4 & ~X86_CR4_TSD);
464 * Page-directory addresses above 4GB do not fit into architectural %cr3.
465 * When accessing %cr3, or equivalent field in vcpu_guest_context, guests
466 * must use the following accessor macros to pack/unpack valid MFNs.
468 * Note that Xen is using the fact that the pagetable base is always
469 * page-aligned, and putting the 12 MSB of the address into the 12 LSB
470 * of cr3.
472 #define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
473 #define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
475 static unsigned long xen_read_cr3(void)
477 return x86_read_percpu(xen_cr3);
480 static void xen_write_cr3(unsigned long cr3)
482 if (cr3 == x86_read_percpu(xen_cr3)) {
483 /* just a simple tlb flush */
484 xen_flush_tlb();
485 return;
488 x86_write_percpu(xen_cr3, cr3);
492 struct mmuext_op *op;
493 struct multicall_space mcs = xen_mc_entry(sizeof(*op));
494 unsigned long mfn = pfn_to_mfn(PFN_DOWN(cr3));
496 op = mcs.args;
497 op->cmd = MMUEXT_NEW_BASEPTR;
498 op->arg1.mfn = mfn;
500 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
502 xen_mc_issue(PARAVIRT_LAZY_CPU);
506 /* Early in boot, while setting up the initial pagetable, assume
507 everything is pinned. */
508 static void xen_alloc_pt_init(struct mm_struct *mm, u32 pfn)
510 BUG_ON(mem_map); /* should only be used early */
511 make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
514 /* This needs to make sure the new pte page is pinned iff its being
515 attached to a pinned pagetable. */
516 static void xen_alloc_pt(struct mm_struct *mm, u32 pfn)
518 struct page *page = pfn_to_page(pfn);
520 if (PagePinned(virt_to_page(mm->pgd))) {
521 SetPagePinned(page);
523 if (!PageHighMem(page))
524 make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
525 else
526 /* make sure there are no stray mappings of
527 this page */
528 kmap_flush_unused();
532 /* This should never happen until we're OK to use struct page */
533 static void xen_release_pt(u32 pfn)
535 struct page *page = pfn_to_page(pfn);
537 if (PagePinned(page)) {
538 if (!PageHighMem(page))
539 make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
543 #ifdef CONFIG_HIGHPTE
544 static void *xen_kmap_atomic_pte(struct page *page, enum km_type type)
546 pgprot_t prot = PAGE_KERNEL;
548 if (PagePinned(page))
549 prot = PAGE_KERNEL_RO;
551 if (0 && PageHighMem(page))
552 printk("mapping highpte %lx type %d prot %s\n",
553 page_to_pfn(page), type,
554 (unsigned long)pgprot_val(prot) & _PAGE_RW ? "WRITE" : "READ");
556 return kmap_atomic_prot(page, type, prot);
558 #endif
560 static __init void xen_pagetable_setup_start(pgd_t *base)
562 pgd_t *xen_pgd = (pgd_t *)xen_start_info->pt_base;
564 init_mm.pgd = base;
566 * copy top-level of Xen-supplied pagetable into place. For
567 * !PAE we can use this as-is, but for PAE it is a stand-in
568 * while we copy the pmd pages.
570 memcpy(base, xen_pgd, PTRS_PER_PGD * sizeof(pgd_t));
572 if (PTRS_PER_PMD > 1) {
573 int i;
575 * For PAE, need to allocate new pmds, rather than
576 * share Xen's, since Xen doesn't like pmd's being
577 * shared between address spaces.
579 for (i = 0; i < PTRS_PER_PGD; i++) {
580 if (pgd_val_ma(xen_pgd[i]) & _PAGE_PRESENT) {
581 pmd_t *pmd = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
583 memcpy(pmd, (void *)pgd_page_vaddr(xen_pgd[i]),
584 PAGE_SIZE);
586 make_lowmem_page_readonly(pmd);
588 set_pgd(&base[i], __pgd(1 + __pa(pmd)));
589 } else
590 pgd_clear(&base[i]);
594 /* make sure zero_page is mapped RO so we can use it in pagetables */
595 make_lowmem_page_readonly(empty_zero_page);
596 make_lowmem_page_readonly(base);
598 * Switch to new pagetable. This is done before
599 * pagetable_init has done anything so that the new pages
600 * added to the table can be prepared properly for Xen.
602 xen_write_cr3(__pa(base));
605 static __init void xen_pagetable_setup_done(pgd_t *base)
607 /* This will work as long as patching hasn't happened yet
608 (which it hasn't) */
609 paravirt_ops.alloc_pt = xen_alloc_pt;
611 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
613 * Create a mapping for the shared info page.
614 * Should be set_fixmap(), but shared_info is a machine
615 * address with no corresponding pseudo-phys address.
617 set_pte_mfn(fix_to_virt(FIX_PARAVIRT_BOOTMAP),
618 PFN_DOWN(xen_start_info->shared_info),
619 PAGE_KERNEL);
621 HYPERVISOR_shared_info =
622 (struct shared_info *)fix_to_virt(FIX_PARAVIRT_BOOTMAP);
624 } else
625 HYPERVISOR_shared_info =
626 (struct shared_info *)__va(xen_start_info->shared_info);
628 /* Actually pin the pagetable down, but we can't set PG_pinned
629 yet because the page structures don't exist yet. */
631 struct mmuext_op op;
632 #ifdef CONFIG_X86_PAE
633 op.cmd = MMUEXT_PIN_L3_TABLE;
634 #else
635 op.cmd = MMUEXT_PIN_L3_TABLE;
636 #endif
637 op.arg1.mfn = pfn_to_mfn(PFN_DOWN(__pa(base)));
638 if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
639 BUG();
642 xen_vcpu_setup(smp_processor_id());
645 static const struct paravirt_ops xen_paravirt_ops __initdata = {
646 .paravirt_enabled = 1,
647 .shared_kernel_pmd = 0,
649 .name = "Xen",
650 .banner = xen_banner,
652 .patch = paravirt_patch_default,
654 .memory_setup = xen_memory_setup,
655 .arch_setup = xen_arch_setup,
656 .init_IRQ = xen_init_IRQ,
657 .post_allocator_init = xen_mark_init_mm_pinned,
659 .time_init = xen_time_init,
660 .set_wallclock = xen_set_wallclock,
661 .get_wallclock = xen_get_wallclock,
662 .get_cpu_khz = xen_cpu_khz,
663 .sched_clock = xen_clocksource_read,
665 .cpuid = xen_cpuid,
667 .set_debugreg = xen_set_debugreg,
668 .get_debugreg = xen_get_debugreg,
670 .clts = native_clts,
672 .read_cr0 = native_read_cr0,
673 .write_cr0 = native_write_cr0,
675 .read_cr2 = xen_read_cr2,
676 .write_cr2 = native_write_cr2,
678 .read_cr3 = xen_read_cr3,
679 .write_cr3 = xen_write_cr3,
681 .read_cr4 = native_read_cr4,
682 .read_cr4_safe = native_read_cr4_safe,
683 .write_cr4 = xen_write_cr4,
685 .save_fl = xen_save_fl,
686 .restore_fl = xen_restore_fl,
687 .irq_disable = xen_irq_disable,
688 .irq_enable = xen_irq_enable,
689 .safe_halt = xen_safe_halt,
690 .halt = xen_halt,
691 .wbinvd = native_wbinvd,
693 .read_msr = native_read_msr_safe,
694 .write_msr = native_write_msr_safe,
695 .read_tsc = native_read_tsc,
696 .read_pmc = native_read_pmc,
698 .iret = (void *)&hypercall_page[__HYPERVISOR_iret],
699 .irq_enable_sysexit = NULL, /* never called */
701 .load_tr_desc = paravirt_nop,
702 .set_ldt = xen_set_ldt,
703 .load_gdt = xen_load_gdt,
704 .load_idt = xen_load_idt,
705 .load_tls = xen_load_tls,
707 .store_gdt = native_store_gdt,
708 .store_idt = native_store_idt,
709 .store_tr = xen_store_tr,
711 .write_ldt_entry = xen_write_ldt_entry,
712 .write_gdt_entry = xen_write_gdt_entry,
713 .write_idt_entry = xen_write_idt_entry,
714 .load_esp0 = xen_load_esp0,
716 .set_iopl_mask = xen_set_iopl_mask,
717 .io_delay = xen_io_delay,
719 #ifdef CONFIG_X86_LOCAL_APIC
720 .apic_write = paravirt_nop,
721 .apic_write_atomic = paravirt_nop,
722 .apic_read = xen_apic_read,
723 .setup_boot_clock = paravirt_nop,
724 .setup_secondary_clock = paravirt_nop,
725 .startup_ipi_hook = paravirt_nop,
726 #endif
728 .flush_tlb_user = xen_flush_tlb,
729 .flush_tlb_kernel = xen_flush_tlb,
730 .flush_tlb_single = xen_flush_tlb_single,
732 .pte_update = paravirt_nop,
733 .pte_update_defer = paravirt_nop,
735 .pagetable_setup_start = xen_pagetable_setup_start,
736 .pagetable_setup_done = xen_pagetable_setup_done,
738 .alloc_pt = xen_alloc_pt_init,
739 .release_pt = xen_release_pt,
740 .alloc_pd = paravirt_nop,
741 .alloc_pd_clone = paravirt_nop,
742 .release_pd = paravirt_nop,
744 #ifdef CONFIG_HIGHPTE
745 .kmap_atomic_pte = xen_kmap_atomic_pte,
746 #endif
748 .set_pte = xen_set_pte,
749 .set_pte_at = xen_set_pte_at,
750 .set_pmd = xen_set_pmd,
752 .pte_val = xen_pte_val,
753 .pgd_val = xen_pgd_val,
755 .make_pte = xen_make_pte,
756 .make_pgd = xen_make_pgd,
758 #ifdef CONFIG_X86_PAE
759 .set_pte_atomic = xen_set_pte_atomic,
760 .set_pte_present = xen_set_pte_at,
761 .set_pud = xen_set_pud,
762 .pte_clear = xen_pte_clear,
763 .pmd_clear = xen_pmd_clear,
765 .make_pmd = xen_make_pmd,
766 .pmd_val = xen_pmd_val,
767 #endif /* PAE */
769 .activate_mm = xen_activate_mm,
770 .dup_mmap = xen_dup_mmap,
771 .exit_mmap = xen_exit_mmap,
773 .set_lazy_mode = xen_set_lazy_mode,
776 /* First C function to be called on Xen boot */
777 asmlinkage void __init xen_start_kernel(void)
779 pgd_t *pgd;
781 if (!xen_start_info)
782 return;
784 BUG_ON(memcmp(xen_start_info->magic, "xen-3.0", 7) != 0);
786 /* Install Xen paravirt ops */
787 paravirt_ops = xen_paravirt_ops;
789 xen_setup_features();
791 /* Get mfn list */
792 if (!xen_feature(XENFEAT_auto_translated_physmap))
793 phys_to_machine_mapping = (unsigned long *)xen_start_info->mfn_list;
795 pgd = (pgd_t *)xen_start_info->pt_base;
797 init_pg_tables_end = __pa(pgd) + xen_start_info->nr_pt_frames*PAGE_SIZE;
799 init_mm.pgd = pgd; /* use the Xen pagetables to start */
801 /* keep using Xen gdt for now; no urgent need to change it */
803 x86_write_percpu(xen_cr3, __pa(pgd));
804 xen_vcpu_setup(0);
806 paravirt_ops.kernel_rpl = 1;
807 if (xen_feature(XENFEAT_supervisor_mode_kernel))
808 paravirt_ops.kernel_rpl = 0;
810 /* set the limit of our address space */
811 reserve_top_address(-HYPERVISOR_VIRT_START + 2 * PAGE_SIZE);
813 /* set up basic CPUID stuff */
814 cpu_detect(&new_cpu_data);
815 new_cpu_data.hard_math = 1;
816 new_cpu_data.x86_capability[0] = cpuid_edx(1);
818 /* Poke various useful things into boot_params */
819 LOADER_TYPE = (9 << 4) | 0;
820 INITRD_START = xen_start_info->mod_start ? __pa(xen_start_info->mod_start) : 0;
821 INITRD_SIZE = xen_start_info->mod_len;
823 /* Start the world */
824 start_kernel();