xen: add pinned page flag
[linux-2.6-block.git] / arch / i386 / xen / enlighten.c
CommitLineData
5ead97c8
JF
1/*
2 * Core of Xen paravirt_ops implementation.
3 *
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
10 *
11 * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
12 */
13
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
25#include <xen/interface/xen.h>
26#include <xen/interface/physdev.h>
27#include <xen/interface/vcpu.h>
28#include <xen/features.h>
29#include <xen/page.h>
30
31#include <asm/paravirt.h>
32#include <asm/page.h>
33#include <asm/xen/hypercall.h>
34#include <asm/xen/hypervisor.h>
35#include <asm/fixmap.h>
36#include <asm/processor.h>
37#include <asm/setup.h>
38#include <asm/desc.h>
39#include <asm/pgtable.h>
40
41#include "xen-ops.h"
3b827c1b 42#include "mmu.h"
5ead97c8
JF
43#include "multicalls.h"
44
45EXPORT_SYMBOL_GPL(hypercall_page);
46
47DEFINE_PER_CPU(enum paravirt_lazy_mode, xen_lazy_mode);
48
49DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
50DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info);
51DEFINE_PER_CPU(unsigned long, xen_cr3);
52
53struct start_info *xen_start_info;
54EXPORT_SYMBOL_GPL(xen_start_info);
55
56static void xen_vcpu_setup(int cpu)
57{
58 per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu];
59}
60
61static void __init xen_banner(void)
62{
63 printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
64 paravirt_ops.name);
65 printk(KERN_INFO "Hypervisor signature: %s\n", xen_start_info->magic);
66}
67
68static void xen_cpuid(unsigned int *eax, unsigned int *ebx,
69 unsigned int *ecx, unsigned int *edx)
70{
71 unsigned maskedx = ~0;
72
73 /*
74 * Mask out inconvenient features, to try and disable as many
75 * unsupported kernel subsystems as possible.
76 */
77 if (*eax == 1)
78 maskedx = ~((1 << X86_FEATURE_APIC) | /* disable APIC */
79 (1 << X86_FEATURE_ACPI) | /* disable ACPI */
80 (1 << X86_FEATURE_ACC)); /* thermal monitoring */
81
82 asm(XEN_EMULATE_PREFIX "cpuid"
83 : "=a" (*eax),
84 "=b" (*ebx),
85 "=c" (*ecx),
86 "=d" (*edx)
87 : "0" (*eax), "2" (*ecx));
88 *edx &= maskedx;
89}
90
91static void xen_set_debugreg(int reg, unsigned long val)
92{
93 HYPERVISOR_set_debugreg(reg, val);
94}
95
96static unsigned long xen_get_debugreg(int reg)
97{
98 return HYPERVISOR_get_debugreg(reg);
99}
100
101static unsigned long xen_save_fl(void)
102{
103 struct vcpu_info *vcpu;
104 unsigned long flags;
105
106 preempt_disable();
107 vcpu = x86_read_percpu(xen_vcpu);
108 /* flag has opposite sense of mask */
109 flags = !vcpu->evtchn_upcall_mask;
110 preempt_enable();
111
112 /* convert to IF type flag
113 -0 -> 0x00000000
114 -1 -> 0xffffffff
115 */
116 return (-flags) & X86_EFLAGS_IF;
117}
118
119static void xen_restore_fl(unsigned long flags)
120{
121 struct vcpu_info *vcpu;
122
123 preempt_disable();
124
125 /* convert from IF type flag */
126 flags = !(flags & X86_EFLAGS_IF);
127 vcpu = x86_read_percpu(xen_vcpu);
128 vcpu->evtchn_upcall_mask = flags;
129
130 if (flags == 0) {
131 /* Unmask then check (avoid races). We're only protecting
132 against updates by this CPU, so there's no need for
133 anything stronger. */
134 barrier();
135
136 if (unlikely(vcpu->evtchn_upcall_pending))
137 force_evtchn_callback();
138 preempt_enable();
139 } else
140 preempt_enable_no_resched();
141}
142
143static void xen_irq_disable(void)
144{
145 struct vcpu_info *vcpu;
146 preempt_disable();
147 vcpu = x86_read_percpu(xen_vcpu);
148 vcpu->evtchn_upcall_mask = 1;
149 preempt_enable_no_resched();
150}
151
152static void xen_irq_enable(void)
153{
154 struct vcpu_info *vcpu;
155
156 preempt_disable();
157 vcpu = x86_read_percpu(xen_vcpu);
158 vcpu->evtchn_upcall_mask = 0;
159
160 /* Unmask then check (avoid races). We're only protecting
161 against updates by this CPU, so there's no need for
162 anything stronger. */
163 barrier();
164
165 if (unlikely(vcpu->evtchn_upcall_pending))
166 force_evtchn_callback();
167 preempt_enable();
168}
169
170static void xen_safe_halt(void)
171{
172 /* Blocking includes an implicit local_irq_enable(). */
173 if (HYPERVISOR_sched_op(SCHEDOP_block, 0) != 0)
174 BUG();
175}
176
177static void xen_halt(void)
178{
179 if (irqs_disabled())
180 HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
181 else
182 xen_safe_halt();
183}
184
185static void xen_set_lazy_mode(enum paravirt_lazy_mode mode)
186{
187 switch (mode) {
188 case PARAVIRT_LAZY_NONE:
189 BUG_ON(x86_read_percpu(xen_lazy_mode) == PARAVIRT_LAZY_NONE);
190 break;
191
192 case PARAVIRT_LAZY_MMU:
193 case PARAVIRT_LAZY_CPU:
194 BUG_ON(x86_read_percpu(xen_lazy_mode) != PARAVIRT_LAZY_NONE);
195 break;
196
197 case PARAVIRT_LAZY_FLUSH:
198 /* flush if necessary, but don't change state */
199 if (x86_read_percpu(xen_lazy_mode) != PARAVIRT_LAZY_NONE)
200 xen_mc_flush();
201 return;
202 }
203
204 xen_mc_flush();
205 x86_write_percpu(xen_lazy_mode, mode);
206}
207
208static unsigned long xen_store_tr(void)
209{
210 return 0;
211}
212
213static void xen_set_ldt(const void *addr, unsigned entries)
214{
215 unsigned long linear_addr = (unsigned long)addr;
216 struct mmuext_op *op;
217 struct multicall_space mcs = xen_mc_entry(sizeof(*op));
218
219 op = mcs.args;
220 op->cmd = MMUEXT_SET_LDT;
221 if (linear_addr) {
222 /* ldt my be vmalloced, use arbitrary_virt_to_machine */
223 xmaddr_t maddr;
224 maddr = arbitrary_virt_to_machine((unsigned long)addr);
225 linear_addr = (unsigned long)maddr.maddr;
226 }
227 op->arg1.linear_addr = linear_addr;
228 op->arg2.nr_ents = entries;
229
230 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
231
232 xen_mc_issue(PARAVIRT_LAZY_CPU);
233}
234
235static void xen_load_gdt(const struct Xgt_desc_struct *dtr)
236{
237 unsigned long *frames;
238 unsigned long va = dtr->address;
239 unsigned int size = dtr->size + 1;
240 unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
241 int f;
242 struct multicall_space mcs;
243
244 /* A GDT can be up to 64k in size, which corresponds to 8192
245 8-byte entries, or 16 4k pages.. */
246
247 BUG_ON(size > 65536);
248 BUG_ON(va & ~PAGE_MASK);
249
250 mcs = xen_mc_entry(sizeof(*frames) * pages);
251 frames = mcs.args;
252
253 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
254 frames[f] = virt_to_mfn(va);
255 make_lowmem_page_readonly((void *)va);
256 }
257
258 MULTI_set_gdt(mcs.mc, frames, size / sizeof(struct desc_struct));
259
260 xen_mc_issue(PARAVIRT_LAZY_CPU);
261}
262
263static void load_TLS_descriptor(struct thread_struct *t,
264 unsigned int cpu, unsigned int i)
265{
266 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
267 xmaddr_t maddr = virt_to_machine(&gdt[GDT_ENTRY_TLS_MIN+i]);
268 struct multicall_space mc = __xen_mc_entry(0);
269
270 MULTI_update_descriptor(mc.mc, maddr.maddr, t->tls_array[i]);
271}
272
273static void xen_load_tls(struct thread_struct *t, unsigned int cpu)
274{
275 xen_mc_batch();
276
277 load_TLS_descriptor(t, cpu, 0);
278 load_TLS_descriptor(t, cpu, 1);
279 load_TLS_descriptor(t, cpu, 2);
280
281 xen_mc_issue(PARAVIRT_LAZY_CPU);
282}
283
284static void xen_write_ldt_entry(struct desc_struct *dt, int entrynum,
285 u32 low, u32 high)
286{
287 unsigned long lp = (unsigned long)&dt[entrynum];
288 xmaddr_t mach_lp = virt_to_machine(lp);
289 u64 entry = (u64)high << 32 | low;
290
291 xen_mc_flush();
292 if (HYPERVISOR_update_descriptor(mach_lp.maddr, entry))
293 BUG();
294}
295
296static int cvt_gate_to_trap(int vector, u32 low, u32 high,
297 struct trap_info *info)
298{
299 u8 type, dpl;
300
301 type = (high >> 8) & 0x1f;
302 dpl = (high >> 13) & 3;
303
304 if (type != 0xf && type != 0xe)
305 return 0;
306
307 info->vector = vector;
308 info->address = (high & 0xffff0000) | (low & 0x0000ffff);
309 info->cs = low >> 16;
310 info->flags = dpl;
311 /* interrupt gates clear IF */
312 if (type == 0xe)
313 info->flags |= 4;
314
315 return 1;
316}
317
318/* Locations of each CPU's IDT */
319static DEFINE_PER_CPU(struct Xgt_desc_struct, idt_desc);
320
321/* Set an IDT entry. If the entry is part of the current IDT, then
322 also update Xen. */
323static void xen_write_idt_entry(struct desc_struct *dt, int entrynum,
324 u32 low, u32 high)
325{
326
327 int cpu = smp_processor_id();
328 unsigned long p = (unsigned long)&dt[entrynum];
329 unsigned long start = per_cpu(idt_desc, cpu).address;
330 unsigned long end = start + per_cpu(idt_desc, cpu).size + 1;
331
332 xen_mc_flush();
333
334 write_dt_entry(dt, entrynum, low, high);
335
336 if (p >= start && (p + 8) <= end) {
337 struct trap_info info[2];
338
339 info[1].address = 0;
340
341 if (cvt_gate_to_trap(entrynum, low, high, &info[0]))
342 if (HYPERVISOR_set_trap_table(info))
343 BUG();
344 }
345}
346
347/* Load a new IDT into Xen. In principle this can be per-CPU, so we
348 hold a spinlock to protect the static traps[] array (static because
349 it avoids allocation, and saves stack space). */
350static void xen_load_idt(const struct Xgt_desc_struct *desc)
351{
352 static DEFINE_SPINLOCK(lock);
353 static struct trap_info traps[257];
354
355 int cpu = smp_processor_id();
356 unsigned in, out, count;
357
358 per_cpu(idt_desc, cpu) = *desc;
359
360 count = (desc->size+1) / 8;
361 BUG_ON(count > 256);
362
363 spin_lock(&lock);
364 for (in = out = 0; in < count; in++) {
365 const u32 *entry = (u32 *)(desc->address + in * 8);
366
367 if (cvt_gate_to_trap(in, entry[0], entry[1], &traps[out]))
368 out++;
369 }
370 traps[out].address = 0;
371
372 xen_mc_flush();
373 if (HYPERVISOR_set_trap_table(traps))
374 BUG();
375
376 spin_unlock(&lock);
377}
378
379/* Write a GDT descriptor entry. Ignore LDT descriptors, since
380 they're handled differently. */
381static void xen_write_gdt_entry(struct desc_struct *dt, int entry,
382 u32 low, u32 high)
383{
384 switch ((high >> 8) & 0xff) {
385 case DESCTYPE_LDT:
386 case DESCTYPE_TSS:
387 /* ignore */
388 break;
389
390 default: {
391 xmaddr_t maddr = virt_to_machine(&dt[entry]);
392 u64 desc = (u64)high << 32 | low;
393
394 xen_mc_flush();
395 if (HYPERVISOR_update_descriptor(maddr.maddr, desc))
396 BUG();
397 }
398
399 }
400}
401
402static void xen_load_esp0(struct tss_struct *tss,
403 struct thread_struct *thread)
404{
405 struct multicall_space mcs = xen_mc_entry(0);
406 MULTI_stack_switch(mcs.mc, __KERNEL_DS, thread->esp0);
407 xen_mc_issue(PARAVIRT_LAZY_CPU);
408}
409
410static void xen_set_iopl_mask(unsigned mask)
411{
412 struct physdev_set_iopl set_iopl;
413
414 /* Force the change at ring 0. */
415 set_iopl.iopl = (mask == 0) ? 1 : (mask >> 12) & 3;
416 HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
417}
418
419static void xen_io_delay(void)
420{
421}
422
423#ifdef CONFIG_X86_LOCAL_APIC
424static unsigned long xen_apic_read(unsigned long reg)
425{
426 return 0;
427}
428#endif
429
430static void xen_flush_tlb(void)
431{
432 struct mmuext_op op;
433
434 op.cmd = MMUEXT_TLB_FLUSH_LOCAL;
435 if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
436 BUG();
437}
438
439static void xen_flush_tlb_single(unsigned long addr)
440{
441 struct mmuext_op op;
442
443 op.cmd = MMUEXT_INVLPG_LOCAL;
444 op.arg1.linear_addr = addr & PAGE_MASK;
445 if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
446 BUG();
447}
448
449static unsigned long xen_read_cr2(void)
450{
451 return x86_read_percpu(xen_vcpu)->arch.cr2;
452}
453
454static void xen_write_cr4(unsigned long cr4)
455{
456 /* never allow TSC to be disabled */
457 native_write_cr4(cr4 & ~X86_CR4_TSD);
458}
459
460/*
461 * Page-directory addresses above 4GB do not fit into architectural %cr3.
462 * When accessing %cr3, or equivalent field in vcpu_guest_context, guests
463 * must use the following accessor macros to pack/unpack valid MFNs.
464 *
465 * Note that Xen is using the fact that the pagetable base is always
466 * page-aligned, and putting the 12 MSB of the address into the 12 LSB
467 * of cr3.
468 */
469#define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
470#define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
471
472static unsigned long xen_read_cr3(void)
473{
474 return x86_read_percpu(xen_cr3);
475}
476
477static void xen_write_cr3(unsigned long cr3)
478{
479 if (cr3 == x86_read_percpu(xen_cr3)) {
480 /* just a simple tlb flush */
481 xen_flush_tlb();
482 return;
483 }
484
485 x86_write_percpu(xen_cr3, cr3);
486
487
488 {
489 struct mmuext_op *op;
490 struct multicall_space mcs = xen_mc_entry(sizeof(*op));
491 unsigned long mfn = pfn_to_mfn(PFN_DOWN(cr3));
492
493 op = mcs.args;
494 op->cmd = MMUEXT_NEW_BASEPTR;
495 op->arg1.mfn = mfn;
496
497 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
498
499 xen_mc_issue(PARAVIRT_LAZY_CPU);
500 }
501}
502
503static void xen_alloc_pt(struct mm_struct *mm, u32 pfn)
504{
505 /* XXX pfn isn't necessarily a lowmem page */
506 make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
507}
508
509static void xen_alloc_pd(u32 pfn)
510{
511 make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
512}
513
514static void xen_release_pd(u32 pfn)
515{
516 make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
517}
518
519static void xen_release_pt(u32 pfn)
520{
521 make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
522}
523
524static void xen_alloc_pd_clone(u32 pfn, u32 clonepfn,
525 u32 start, u32 count)
526{
527 xen_alloc_pd(pfn);
528}
529
530static __init void xen_pagetable_setup_start(pgd_t *base)
531{
532 pgd_t *xen_pgd = (pgd_t *)xen_start_info->pt_base;
533
534 init_mm.pgd = base;
535 /*
536 * copy top-level of Xen-supplied pagetable into place. For
537 * !PAE we can use this as-is, but for PAE it is a stand-in
538 * while we copy the pmd pages.
539 */
540 memcpy(base, xen_pgd, PTRS_PER_PGD * sizeof(pgd_t));
541
542 if (PTRS_PER_PMD > 1) {
543 int i;
544 /*
545 * For PAE, need to allocate new pmds, rather than
546 * share Xen's, since Xen doesn't like pmd's being
547 * shared between address spaces.
548 */
549 for (i = 0; i < PTRS_PER_PGD; i++) {
550 if (pgd_val_ma(xen_pgd[i]) & _PAGE_PRESENT) {
551 pmd_t *pmd = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
552
553 memcpy(pmd, (void *)pgd_page_vaddr(xen_pgd[i]),
554 PAGE_SIZE);
555
556 xen_alloc_pd(PFN_DOWN(__pa(pmd)));
557
558 set_pgd(&base[i], __pgd(1 + __pa(pmd)));
559 } else
560 pgd_clear(&base[i]);
561 }
562 }
563
564 /* make sure zero_page is mapped RO so we can use it in pagetables */
565 make_lowmem_page_readonly(empty_zero_page);
566 make_lowmem_page_readonly(base);
567 /*
568 * Switch to new pagetable. This is done before
569 * pagetable_init has done anything so that the new pages
570 * added to the table can be prepared properly for Xen.
571 */
572 xen_write_cr3(__pa(base));
573}
574
575static __init void xen_pagetable_setup_done(pgd_t *base)
576{
577 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
578 /*
579 * Create a mapping for the shared info page.
580 * Should be set_fixmap(), but shared_info is a machine
581 * address with no corresponding pseudo-phys address.
582 */
5ead97c8
JF
583 set_pte_mfn(fix_to_virt(FIX_PARAVIRT_BOOTMAP),
584 PFN_DOWN(xen_start_info->shared_info),
585 PAGE_KERNEL);
5ead97c8
JF
586
587 HYPERVISOR_shared_info =
588 (struct shared_info *)fix_to_virt(FIX_PARAVIRT_BOOTMAP);
589
590 } else
591 HYPERVISOR_shared_info =
592 (struct shared_info *)__va(xen_start_info->shared_info);
593
5ead97c8 594 xen_pgd_pin(base);
5ead97c8
JF
595
596 xen_vcpu_setup(smp_processor_id());
597}
598
599static const struct paravirt_ops xen_paravirt_ops __initdata = {
600 .paravirt_enabled = 1,
601 .shared_kernel_pmd = 0,
602
603 .name = "Xen",
604 .banner = xen_banner,
605
606 .patch = paravirt_patch_default,
607
608 .memory_setup = xen_memory_setup,
609 .arch_setup = xen_arch_setup,
e46cdb66 610 .init_IRQ = xen_init_IRQ,
5ead97c8 611
15c84731
JF
612 .time_init = xen_time_init,
613 .set_wallclock = xen_set_wallclock,
614 .get_wallclock = xen_get_wallclock,
615 .get_cpu_khz = xen_cpu_khz,
616 .sched_clock = xen_clocksource_read,
617
5ead97c8
JF
618 .cpuid = xen_cpuid,
619
620 .set_debugreg = xen_set_debugreg,
621 .get_debugreg = xen_get_debugreg,
622
623 .clts = native_clts,
624
625 .read_cr0 = native_read_cr0,
626 .write_cr0 = native_write_cr0,
627
628 .read_cr2 = xen_read_cr2,
629 .write_cr2 = native_write_cr2,
630
631 .read_cr3 = xen_read_cr3,
632 .write_cr3 = xen_write_cr3,
633
634 .read_cr4 = native_read_cr4,
635 .read_cr4_safe = native_read_cr4_safe,
636 .write_cr4 = xen_write_cr4,
637
638 .save_fl = xen_save_fl,
639 .restore_fl = xen_restore_fl,
640 .irq_disable = xen_irq_disable,
641 .irq_enable = xen_irq_enable,
642 .safe_halt = xen_safe_halt,
643 .halt = xen_halt,
644 .wbinvd = native_wbinvd,
645
646 .read_msr = native_read_msr_safe,
647 .write_msr = native_write_msr_safe,
648 .read_tsc = native_read_tsc,
649 .read_pmc = native_read_pmc,
650
651 .iret = (void *)&hypercall_page[__HYPERVISOR_iret],
652 .irq_enable_sysexit = NULL, /* never called */
653
654 .load_tr_desc = paravirt_nop,
655 .set_ldt = xen_set_ldt,
656 .load_gdt = xen_load_gdt,
657 .load_idt = xen_load_idt,
658 .load_tls = xen_load_tls,
659
660 .store_gdt = native_store_gdt,
661 .store_idt = native_store_idt,
662 .store_tr = xen_store_tr,
663
664 .write_ldt_entry = xen_write_ldt_entry,
665 .write_gdt_entry = xen_write_gdt_entry,
666 .write_idt_entry = xen_write_idt_entry,
667 .load_esp0 = xen_load_esp0,
668
669 .set_iopl_mask = xen_set_iopl_mask,
670 .io_delay = xen_io_delay,
671
672#ifdef CONFIG_X86_LOCAL_APIC
673 .apic_write = paravirt_nop,
674 .apic_write_atomic = paravirt_nop,
675 .apic_read = xen_apic_read,
676 .setup_boot_clock = paravirt_nop,
677 .setup_secondary_clock = paravirt_nop,
678 .startup_ipi_hook = paravirt_nop,
679#endif
680
681 .flush_tlb_user = xen_flush_tlb,
682 .flush_tlb_kernel = xen_flush_tlb,
683 .flush_tlb_single = xen_flush_tlb_single,
684
685 .pte_update = paravirt_nop,
686 .pte_update_defer = paravirt_nop,
687
688 .pagetable_setup_start = xen_pagetable_setup_start,
689 .pagetable_setup_done = xen_pagetable_setup_done,
690
691 .alloc_pt = xen_alloc_pt,
692 .alloc_pd = xen_alloc_pd,
693 .alloc_pd_clone = xen_alloc_pd_clone,
694 .release_pd = xen_release_pd,
695 .release_pt = xen_release_pt,
696
3b827c1b
JF
697 .set_pte = xen_set_pte,
698 .set_pte_at = xen_set_pte_at,
699 .set_pmd = xen_set_pmd,
700
701 .pte_val = xen_pte_val,
702 .pgd_val = xen_pgd_val,
703
704 .make_pte = xen_make_pte,
705 .make_pgd = xen_make_pgd,
706
707#ifdef CONFIG_X86_PAE
708 .set_pte_atomic = xen_set_pte_atomic,
709 .set_pte_present = xen_set_pte_at,
710 .set_pud = xen_set_pud,
711 .pte_clear = xen_pte_clear,
712 .pmd_clear = xen_pmd_clear,
713
714 .make_pmd = xen_make_pmd,
715 .pmd_val = xen_pmd_val,
716#endif /* PAE */
717
718 .activate_mm = xen_activate_mm,
719 .dup_mmap = xen_dup_mmap,
720 .exit_mmap = xen_exit_mmap,
721
5ead97c8
JF
722 .set_lazy_mode = xen_set_lazy_mode,
723};
724
725/* First C function to be called on Xen boot */
726asmlinkage void __init xen_start_kernel(void)
727{
728 pgd_t *pgd;
729
730 if (!xen_start_info)
731 return;
732
733 BUG_ON(memcmp(xen_start_info->magic, "xen-3.0", 7) != 0);
734
735 /* Install Xen paravirt ops */
736 paravirt_ops = xen_paravirt_ops;
737
738 xen_setup_features();
739
740 /* Get mfn list */
741 if (!xen_feature(XENFEAT_auto_translated_physmap))
742 phys_to_machine_mapping = (unsigned long *)xen_start_info->mfn_list;
743
744 pgd = (pgd_t *)xen_start_info->pt_base;
745
746 init_pg_tables_end = __pa(pgd) + xen_start_info->nr_pt_frames*PAGE_SIZE;
747
748 init_mm.pgd = pgd; /* use the Xen pagetables to start */
749
750 /* keep using Xen gdt for now; no urgent need to change it */
751
752 x86_write_percpu(xen_cr3, __pa(pgd));
753 xen_vcpu_setup(0);
754
755 paravirt_ops.kernel_rpl = 1;
756 if (xen_feature(XENFEAT_supervisor_mode_kernel))
757 paravirt_ops.kernel_rpl = 0;
758
759 /* set the limit of our address space */
760 reserve_top_address(-HYPERVISOR_VIRT_START + 2 * PAGE_SIZE);
761
762 /* set up basic CPUID stuff */
763 cpu_detect(&new_cpu_data);
764 new_cpu_data.hard_math = 1;
765 new_cpu_data.x86_capability[0] = cpuid_edx(1);
766
767 /* Poke various useful things into boot_params */
768 LOADER_TYPE = (9 << 4) | 0;
769 INITRD_START = xen_start_info->mod_start ? __pa(xen_start_info->mod_start) : 0;
770 INITRD_SIZE = xen_start_info->mod_len;
771
772 /* Start the world */
773 start_kernel();
774}