x86: PAT use reserve free memtype in mmap of /dev/mem
[linux-2.6] / arch / x86 / kernel / paravirt_patch_64.c
1 #include <asm/paravirt.h>
2 #include <asm/asm-offsets.h>
3 #include <linux/stringify.h>
4
5 DEF_NATIVE(pv_irq_ops, irq_disable, "cli");
6 DEF_NATIVE(pv_irq_ops, irq_enable, "sti");
7 DEF_NATIVE(pv_irq_ops, restore_fl, "pushq %rdi; popfq");
8 DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
9 DEF_NATIVE(pv_cpu_ops, iret, "iretq");
10 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
11 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
12 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
13 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
14 DEF_NATIVE(pv_cpu_ops, clts, "clts");
15 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
16
17 /* the three commands give us more control to how to return from a syscall */
18 DEF_NATIVE(pv_cpu_ops, irq_enable_syscall_ret, "movq %gs:" __stringify(pda_oldrsp) ", %rsp; swapgs; sysretq;");
19 DEF_NATIVE(pv_cpu_ops, swapgs, "swapgs");
20
21 unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
22                       unsigned long addr, unsigned len)
23 {
24         const unsigned char *start, *end;
25         unsigned ret;
26
27 #define PATCH_SITE(ops, x)                                      \
28                 case PARAVIRT_PATCH(ops.x):                     \
29                         start = start_##ops##_##x;              \
30                         end = end_##ops##_##x;                  \
31                         goto patch_site
32         switch(type) {
33                 PATCH_SITE(pv_irq_ops, restore_fl);
34                 PATCH_SITE(pv_irq_ops, save_fl);
35                 PATCH_SITE(pv_irq_ops, irq_enable);
36                 PATCH_SITE(pv_irq_ops, irq_disable);
37                 PATCH_SITE(pv_cpu_ops, iret);
38                 PATCH_SITE(pv_cpu_ops, irq_enable_syscall_ret);
39                 PATCH_SITE(pv_cpu_ops, swapgs);
40                 PATCH_SITE(pv_mmu_ops, read_cr2);
41                 PATCH_SITE(pv_mmu_ops, read_cr3);
42                 PATCH_SITE(pv_mmu_ops, write_cr3);
43                 PATCH_SITE(pv_cpu_ops, clts);
44                 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
45                 PATCH_SITE(pv_cpu_ops, wbinvd);
46
47         patch_site:
48                 ret = paravirt_patch_insns(ibuf, len, start, end);
49                 break;
50
51         default:
52                 ret = paravirt_patch_default(type, clobbers, ibuf, addr, len);
53                 break;
54         }
55 #undef PATCH_SITE
56         return ret;
57 }