blob: 0c23f7940bc400d3306683faa19a9b8237ee90a2 [file] [log] [blame]
Rusty Russelld3561b72006-12-07 02:14:07 +01001#ifndef __ASM_PARAVIRT_H
2#define __ASM_PARAVIRT_H
3/* Various instructions on x86 need to be replaced for
4 * para-virtualization: those hooks are defined here. */
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +02005
6#ifdef CONFIG_PARAVIRT
Rusty Russellda181a82006-12-07 02:14:08 +01007#include <asm/page.h>
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01008#include <asm/asm.h>
Rusty Russelld3561b72006-12-07 02:14:07 +01009
Rusty Russell139ec7c2006-12-07 02:14:08 +010010/* Bitmask of what can be clobbered: usually at least eax. */
Glauber de Oliveira Costa21438f72008-01-30 13:32:09 +010011#define CLBR_NONE 0
12#define CLBR_EAX (1 << 0)
13#define CLBR_ECX (1 << 1)
14#define CLBR_EDX (1 << 2)
15
16#ifdef CONFIG_X86_64
17#define CLBR_RSI (1 << 3)
18#define CLBR_RDI (1 << 4)
19#define CLBR_R8 (1 << 5)
20#define CLBR_R9 (1 << 6)
21#define CLBR_R10 (1 << 7)
22#define CLBR_R11 (1 << 8)
23#define CLBR_ANY ((1 << 9) - 1)
24#include <asm/desc_defs.h>
25#else
26/* CLBR_ANY should match all regs platform has. For i386, that's just it */
27#define CLBR_ANY ((1 << 3) - 1)
28#endif /* X86_64 */
Rusty Russell139ec7c2006-12-07 02:14:08 +010029
Rusty Russelld3561b72006-12-07 02:14:07 +010030#ifndef __ASSEMBLY__
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020031#include <linux/types.h>
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +020032#include <linux/cpumask.h>
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +020033#include <asm/kmap_types.h>
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +010034#include <asm/desc_defs.h>
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +020035
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +020036struct page;
Rusty Russelld3561b72006-12-07 02:14:07 +010037struct thread_struct;
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +010038struct desc_ptr;
Rusty Russelld3561b72006-12-07 02:14:07 +010039struct tss_struct;
Rusty Russellda181a82006-12-07 02:14:08 +010040struct mm_struct;
Rusty Russell90a0a062007-05-02 19:27:10 +020041struct desc_struct;
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020042
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070043/* general info */
44struct pv_info {
Rusty Russelld3561b72006-12-07 02:14:07 +010045 unsigned int kernel_rpl;
Jeremy Fitzhardinge5311ab62007-05-02 19:27:13 +020046 int shared_kernel_pmd;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070047 int paravirt_enabled;
Rusty Russelld3561b72006-12-07 02:14:07 +010048 const char *name;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070049};
Rusty Russelld3561b72006-12-07 02:14:07 +010050
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070051struct pv_init_ops {
Rusty Russell139ec7c2006-12-07 02:14:08 +010052 /*
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070053 * Patch may replace one of the defined code sequences with
54 * arbitrary code, subject to the same register constraints.
55 * This generally means the code is not free to clobber any
56 * registers other than EAX. The patch function should return
57 * the number of bytes of code generated, as we nop pad the
58 * rest in generic code.
Rusty Russell139ec7c2006-12-07 02:14:08 +010059 */
Andi Kleenab144f52007-08-10 22:31:03 +020060 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
61 unsigned long addr, unsigned len);
Rusty Russell139ec7c2006-12-07 02:14:08 +010062
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020063 /* Basic arch-specific setup */
Rusty Russelld3561b72006-12-07 02:14:07 +010064 void (*arch_setup)(void);
65 char *(*memory_setup)(void);
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -070066 void (*post_allocator_init)(void);
67
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020068 /* Print a banner to identify the environment */
Rusty Russelld3561b72006-12-07 02:14:07 +010069 void (*banner)(void);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070070};
71
72
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -070073struct pv_lazy_ops {
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070074 /* Set deferred update mode, used for batching operations. */
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -070075 void (*enter)(void);
76 void (*leave)(void);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070077};
78
79struct pv_time_ops {
80 void (*time_init)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010081
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020082 /* Set and set time of day */
Rusty Russelld3561b72006-12-07 02:14:07 +010083 unsigned long (*get_wallclock)(void);
84 int (*set_wallclock)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010085
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070086 unsigned long long (*sched_clock)(void);
87 unsigned long (*get_cpu_khz)(void);
88};
Rusty Russelld3561b72006-12-07 02:14:07 +010089
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070090struct pv_cpu_ops {
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +020091 /* hooks for various privileged instructions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +010092 unsigned long (*get_debugreg)(int regno);
93 void (*set_debugreg)(int regno, unsigned long value);
Rusty Russelld3561b72006-12-07 02:14:07 +010094
Andi Kleen1a1eecd2007-02-13 13:26:25 +010095 void (*clts)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +010096
Andi Kleen1a1eecd2007-02-13 13:26:25 +010097 unsigned long (*read_cr0)(void);
98 void (*write_cr0)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +010099
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100100 unsigned long (*read_cr4_safe)(void);
101 unsigned long (*read_cr4)(void);
102 void (*write_cr4)(unsigned long);
Rusty Russelld3561b72006-12-07 02:14:07 +0100103
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +0100104#ifdef CONFIG_X86_64
105 unsigned long (*read_cr8)(void);
106 void (*write_cr8)(unsigned long);
107#endif
108
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200109 /* Segment descriptor handling */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100110 void (*load_tr_desc)(void);
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100111 void (*load_gdt)(const struct desc_ptr *);
112 void (*load_idt)(const struct desc_ptr *);
113 void (*store_gdt)(struct desc_ptr *);
114 void (*store_idt)(struct desc_ptr *);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100115 void (*set_ldt)(const void *desc, unsigned entries);
116 unsigned long (*store_tr)(void);
117 void (*load_tls)(struct thread_struct *t, unsigned int cpu);
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100118 void (*write_ldt_entry)(struct desc_struct *ldt, int entrynum,
119 const void *desc);
Rusty Russell90a0a062007-05-02 19:27:10 +0200120 void (*write_gdt_entry)(struct desc_struct *,
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100121 int entrynum, const void *desc, int size);
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100122 void (*write_idt_entry)(gate_desc *,
123 int entrynum, const gate_desc *gate);
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100124 void (*load_sp0)(struct tss_struct *tss, struct thread_struct *t);
Rusty Russelld3561b72006-12-07 02:14:07 +0100125
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100126 void (*set_iopl_mask)(unsigned mask);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700127
128 void (*wbinvd)(void);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100129 void (*io_delay)(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100130
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700131 /* cpuid emulation, mostly so that caps bits can be disabled */
132 void (*cpuid)(unsigned int *eax, unsigned int *ebx,
133 unsigned int *ecx, unsigned int *edx);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200134
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700135 /* MSR, PMC and TSR operations.
136 err = 0/-EFAULT. wrmsr returns 0/-EFAULT. */
137 u64 (*read_msr)(unsigned int msr, int *err);
Glauber de Oliveira Costac9dcda52008-01-30 13:31:07 +0100138 int (*write_msr)(unsigned int msr, unsigned low, unsigned high);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700139
140 u64 (*read_tsc)(void);
Glauber de Oliveira Costab8d1fae2008-01-30 13:31:07 +0100141 u64 (*read_pmc)(int counter);
Glauber de Oliveira Costae5aaac42008-01-30 13:32:05 +0100142 unsigned long long (*read_tscp)(unsigned int *aux);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700143
144 /* These two are jmp to, not actually called. */
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100145 void (*irq_enable_syscall_ret)(void);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700146 void (*iret)(void);
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700147
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +0100148 void (*swapgs)(void);
149
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700150 struct pv_lazy_ops lazy_mode;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700151};
152
153struct pv_irq_ops {
154 void (*init_IRQ)(void);
155
156 /*
157 * Get/set interrupt state. save_fl and restore_fl are only
158 * expected to use X86_EFLAGS_IF; all other bits
159 * returned from save_fl are undefined, and may be ignored by
160 * restore_fl.
161 */
162 unsigned long (*save_fl)(void);
163 void (*restore_fl)(unsigned long);
164 void (*irq_disable)(void);
165 void (*irq_enable)(void);
166 void (*safe_halt)(void);
167 void (*halt)(void);
168};
169
170struct pv_apic_ops {
Rusty Russell13623d72006-12-07 02:14:08 +0100171#ifdef CONFIG_X86_LOCAL_APIC
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200172 /*
173 * Direct APIC operations, principally for VMI. Ideally
174 * these shouldn't be in this interface.
175 */
Thomas Gleixner42e0a9aa2008-01-30 13:30:15 +0100176 void (*apic_write)(unsigned long reg, u32 v);
177 void (*apic_write_atomic)(unsigned long reg, u32 v);
178 u32 (*apic_read)(unsigned long reg);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100179 void (*setup_boot_clock)(void);
180 void (*setup_secondary_clock)(void);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200181
182 void (*startup_ipi_hook)(int phys_apicid,
183 unsigned long start_eip,
184 unsigned long start_esp);
Rusty Russell13623d72006-12-07 02:14:08 +0100185#endif
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700186};
187
188struct pv_mmu_ops {
189 /*
190 * Called before/after init_mm pagetable setup. setup_start
191 * may reset %cr3, and may pre-install parts of the pagetable;
192 * pagetable setup is expected to preserve any existing
193 * mapping.
194 */
195 void (*pagetable_setup_start)(pgd_t *pgd_base);
196 void (*pagetable_setup_done)(pgd_t *pgd_base);
197
198 unsigned long (*read_cr2)(void);
199 void (*write_cr2)(unsigned long);
200
201 unsigned long (*read_cr3)(void);
202 void (*write_cr3)(unsigned long);
203
204 /*
205 * Hooks for intercepting the creation/use/destruction of an
206 * mm_struct.
207 */
208 void (*activate_mm)(struct mm_struct *prev,
209 struct mm_struct *next);
210 void (*dup_mmap)(struct mm_struct *oldmm,
211 struct mm_struct *mm);
212 void (*exit_mmap)(struct mm_struct *mm);
213
Rusty Russell13623d72006-12-07 02:14:08 +0100214
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200215 /* TLB operations */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100216 void (*flush_tlb_user)(void);
217 void (*flush_tlb_kernel)(void);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200218 void (*flush_tlb_single)(unsigned long addr);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200219 void (*flush_tlb_others)(const cpumask_t *cpus, struct mm_struct *mm,
220 unsigned long va);
Rusty Russellda181a82006-12-07 02:14:08 +0100221
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200222 /* Hooks for allocating/releasing pagetable pages */
Jeremy Fitzhardingefdb4c332007-07-17 18:37:03 -0700223 void (*alloc_pt)(struct mm_struct *mm, u32 pfn);
Jeremy Fitzhardinge6c435452008-01-30 13:33:39 +0100224 void (*alloc_pd)(struct mm_struct *mm, u32 pfn);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100225 void (*alloc_pd_clone)(u32 pfn, u32 clonepfn, u32 start, u32 count);
226 void (*release_pt)(u32 pfn);
227 void (*release_pd)(u32 pfn);
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100228
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200229 /* Pagetable manipulation functions */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100230 void (*set_pte)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200231 void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
232 pte_t *ptep, pte_t pteval);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100233 void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
Joe Perches49cd7402008-03-23 01:03:00 -0700234 void (*pte_update)(struct mm_struct *mm, unsigned long addr,
235 pte_t *ptep);
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200236 void (*pte_update_defer)(struct mm_struct *mm,
237 unsigned long addr, pte_t *ptep);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200238
Jeremy Fitzhardinge5b8dd1e2008-01-30 13:33:15 +0100239 pteval_t (*pte_val)(pte_t);
240 pte_t (*make_pte)(pteval_t pte);
241
242 pgdval_t (*pgd_val)(pgd_t);
243 pgd_t (*make_pgd)(pgdval_t pgd);
244
245#if PAGETABLE_LEVELS >= 3
Rusty Russellda181a82006-12-07 02:14:08 +0100246#ifdef CONFIG_X86_PAE
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100247 void (*set_pte_atomic)(pte_t *ptep, pte_t pteval);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700248 void (*set_pte_present)(struct mm_struct *mm, unsigned long addr,
249 pte_t *ptep, pte_t pte);
Joe Perches49cd7402008-03-23 01:03:00 -0700250 void (*pte_clear)(struct mm_struct *mm, unsigned long addr,
251 pte_t *ptep);
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100252 void (*pmd_clear)(pmd_t *pmdp);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200253
Jeremy Fitzhardinge5b8dd1e2008-01-30 13:33:15 +0100254#endif /* CONFIG_X86_PAE */
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200255
Jeremy Fitzhardinge5b8dd1e2008-01-30 13:33:15 +0100256 void (*set_pud)(pud_t *pudp, pud_t pudval);
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200257
Jeremy Fitzhardinge5b8dd1e2008-01-30 13:33:15 +0100258 pmdval_t (*pmd_val)(pmd_t);
259 pmd_t (*make_pmd)(pmdval_t pmd);
260
261#if PAGETABLE_LEVELS == 4
262 pudval_t (*pud_val)(pud_t);
263 pud_t (*make_pud)(pudval_t pud);
Eduardo Habkost90422192008-01-30 13:33:20 +0100264
265 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
Jeremy Fitzhardinge5b8dd1e2008-01-30 13:33:15 +0100266#endif /* PAGETABLE_LEVELS == 4 */
267#endif /* PAGETABLE_LEVELS >= 3 */
Rusty Russellda181a82006-12-07 02:14:08 +0100268
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700269#ifdef CONFIG_HIGHPTE
270 void *(*kmap_atomic_pte)(struct page *page, enum km_type type);
271#endif
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700272
273 struct pv_lazy_ops lazy_mode;
Rusty Russelld3561b72006-12-07 02:14:07 +0100274};
275
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700276/* This contains all the paravirt structures: we get a convenient
277 * number for each function using the offset which we use to indicate
278 * what to patch. */
Joe Perches49cd7402008-03-23 01:03:00 -0700279struct paravirt_patch_template {
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700280 struct pv_init_ops pv_init_ops;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700281 struct pv_time_ops pv_time_ops;
282 struct pv_cpu_ops pv_cpu_ops;
283 struct pv_irq_ops pv_irq_ops;
284 struct pv_apic_ops pv_apic_ops;
285 struct pv_mmu_ops pv_mmu_ops;
286};
287
288extern struct pv_info pv_info;
289extern struct pv_init_ops pv_init_ops;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700290extern struct pv_time_ops pv_time_ops;
291extern struct pv_cpu_ops pv_cpu_ops;
292extern struct pv_irq_ops pv_irq_ops;
293extern struct pv_apic_ops pv_apic_ops;
294extern struct pv_mmu_ops pv_mmu_ops;
Rusty Russelld3561b72006-12-07 02:14:07 +0100295
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200296#define PARAVIRT_PATCH(x) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700297 (offsetof(struct paravirt_patch_template, x) / sizeof(void *))
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200298
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700299#define paravirt_type(op) \
300 [paravirt_typenum] "i" (PARAVIRT_PATCH(op)), \
301 [paravirt_opptr] "m" (op)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200302#define paravirt_clobber(clobber) \
303 [paravirt_clobber] "i" (clobber)
304
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200305/*
306 * Generate some code, and mark it as patchable by the
307 * apply_paravirt() alternate instruction patcher.
308 */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200309#define _paravirt_alt(insn_string, type, clobber) \
310 "771:\n\t" insn_string "\n" "772:\n" \
311 ".pushsection .parainstructions,\"a\"\n" \
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +0100312 _ASM_ALIGN "\n" \
313 _ASM_PTR " 771b\n" \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200314 " .byte " type "\n" \
315 " .byte 772b-771b\n" \
316 " .short " clobber "\n" \
317 ".popsection\n"
318
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200319/* Generate patchable code, with the default asm parameters. */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200320#define paravirt_alt(insn_string) \
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +0200321 _paravirt_alt(insn_string, "%c[paravirt_typenum]", "%c[paravirt_clobber]")
322
Glauber de Oliveira Costa2f485ef2008-01-30 13:32:10 +0100323/* Simple instruction patching code. */
324#define DEF_NATIVE(ops, name, code) \
325 extern const char start_##ops##_##name[], end_##ops##_##name[]; \
326 asm("start_" #ops "_" #name ": " code "; end_" #ops "_" #name ":")
327
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200328unsigned paravirt_patch_nop(void);
329unsigned paravirt_patch_ignore(unsigned len);
Andi Kleenab144f52007-08-10 22:31:03 +0200330unsigned paravirt_patch_call(void *insnbuf,
331 const void *target, u16 tgt_clobbers,
332 unsigned long addr, u16 site_clobbers,
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200333 unsigned len);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700334unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
Andi Kleenab144f52007-08-10 22:31:03 +0200335 unsigned long addr, unsigned len);
336unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
337 unsigned long addr, unsigned len);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200338
Andi Kleenab144f52007-08-10 22:31:03 +0200339unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200340 const char *start, const char *end);
341
Glauber de Oliveira Costa2f485ef2008-01-30 13:32:10 +0100342unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
343 unsigned long addr, unsigned len);
344
Jeremy Fitzhardinged5729292007-07-17 18:37:04 -0700345int paravirt_disable_iospace(void);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200346
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200347/*
348 * This generates an indirect call based on the operation type number.
349 * The type number, computed in PARAVIRT_PATCH, is derived from the
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700350 * offset into the paravirt_patch_template structure, and can therefore be
351 * freely converted back into a structure offset.
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200352 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700353#define PARAVIRT_CALL "call *%[paravirt_opptr];"
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200354
355/*
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700356 * These macros are intended to wrap calls through one of the paravirt
357 * ops structs, so that they can be later identified and patched at
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200358 * runtime.
359 *
360 * Normally, a call to a pv_op function is a simple indirect call:
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100361 * (pv_op_struct.operations)(args...).
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200362 *
363 * Unfortunately, this is a relatively slow operation for modern CPUs,
364 * because it cannot necessarily determine what the destination
365 * address is. In this case, the address is a runtime constant, so at
366 * the very least we can patch the call to e a simple direct call, or
367 * ideally, patch an inline implementation into the callsite. (Direct
368 * calls are essentially free, because the call and return addresses
369 * are completely predictable.)
370 *
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100371 * For i386, these macros rely on the standard gcc "regparm(3)" calling
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200372 * convention, in which the first three arguments are placed in %eax,
373 * %edx, %ecx (in that order), and the remaining arguments are placed
374 * on the stack. All caller-save registers (eax,edx,ecx) are expected
375 * to be modified (either clobbered or used for return values).
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100376 * X86_64, on the other hand, already specifies a register-based calling
377 * conventions, returning at %rax, with parameteres going on %rdi, %rsi,
378 * %rdx, and %rcx. Note that for this reason, x86_64 does not need any
379 * special handling for dealing with 4 arguments, unlike i386.
380 * However, x86_64 also have to clobber all caller saved registers, which
381 * unfortunately, are quite a bit (r8 - r11)
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200382 *
383 * The call instruction itself is marked by placing its start address
384 * and size into the .parainstructions section, so that
385 * apply_paravirt() in arch/i386/kernel/alternative.c can do the
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700386 * appropriate patching under the control of the backend pv_init_ops
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200387 * implementation.
388 *
389 * Unfortunately there's no way to get gcc to generate the args setup
390 * for the call, and then allow the call itself to be generated by an
391 * inline asm. Because of this, we must do the complete arg setup and
392 * return value handling from within these macros. This is fairly
393 * cumbersome.
394 *
395 * There are 5 sets of PVOP_* macros for dealing with 0-4 arguments.
396 * It could be extended to more arguments, but there would be little
397 * to be gained from that. For each number of arguments, there are
398 * the two VCALL and CALL variants for void and non-void functions.
399 *
400 * When there is a return value, the invoker of the macro must specify
401 * the return type. The macro then uses sizeof() on that type to
402 * determine whether its a 32 or 64 bit value, and places the return
403 * in the right register(s) (just %eax for 32-bit, and %edx:%eax for
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100404 * 64-bit). For x86_64 machines, it just returns at %rax regardless of
405 * the return value size.
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200406 *
407 * 64-bit arguments are passed as a pair of adjacent 32-bit arguments
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100408 * i386 also passes 64-bit arguments as a pair of adjacent 32-bit arguments
409 * in low,high order
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +0200410 *
411 * Small structures are passed and returned in registers. The macro
412 * calling convention can't directly deal with this, so the wrapper
413 * functions must do this.
414 *
415 * These PVOP_* macros are only defined within this header. This
416 * means that all uses must be wrapped in inline functions. This also
417 * makes sure the incoming and outgoing types are always correct.
418 */
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100419#ifdef CONFIG_X86_32
420#define PVOP_VCALL_ARGS unsigned long __eax, __edx, __ecx
421#define PVOP_CALL_ARGS PVOP_VCALL_ARGS
422#define PVOP_VCALL_CLOBBERS "=a" (__eax), "=d" (__edx), \
423 "=c" (__ecx)
424#define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS
425#define EXTRA_CLOBBERS
426#define VEXTRA_CLOBBERS
427#else
428#define PVOP_VCALL_ARGS unsigned long __edi, __esi, __edx, __ecx
429#define PVOP_CALL_ARGS PVOP_VCALL_ARGS, __eax
430#define PVOP_VCALL_CLOBBERS "=D" (__edi), \
431 "=S" (__esi), "=d" (__edx), \
432 "=c" (__ecx)
433
434#define PVOP_CALL_CLOBBERS PVOP_VCALL_CLOBBERS, "=a" (__eax)
435
436#define EXTRA_CLOBBERS , "r8", "r9", "r10", "r11"
437#define VEXTRA_CLOBBERS , "rax", "r8", "r9", "r10", "r11"
438#endif
439
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200440#define __PVOP_CALL(rettype, op, pre, post, ...) \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200441 ({ \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200442 rettype __ret; \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100443 PVOP_CALL_ARGS; \
444 /* This is 32-bit specific, but is okay in 64-bit */ \
445 /* since this condition will never hold */ \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200446 if (sizeof(rettype) > sizeof(unsigned long)) { \
447 asm volatile(pre \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200448 paravirt_alt(PARAVIRT_CALL) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200449 post \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100450 : PVOP_CALL_CLOBBERS \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200451 : paravirt_type(op), \
452 paravirt_clobber(CLBR_ANY), \
453 ##__VA_ARGS__ \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100454 : "memory", "cc" EXTRA_CLOBBERS); \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200455 __ret = (rettype)((((u64)__edx) << 32) | __eax); \
456 } else { \
457 asm volatile(pre \
458 paravirt_alt(PARAVIRT_CALL) \
459 post \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100460 : PVOP_CALL_CLOBBERS \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200461 : paravirt_type(op), \
462 paravirt_clobber(CLBR_ANY), \
463 ##__VA_ARGS__ \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100464 : "memory", "cc" EXTRA_CLOBBERS); \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200465 __ret = (rettype)__eax; \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200466 } \
467 __ret; \
468 })
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200469#define __PVOP_VCALL(op, pre, post, ...) \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200470 ({ \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100471 PVOP_VCALL_ARGS; \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200472 asm volatile(pre \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200473 paravirt_alt(PARAVIRT_CALL) \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200474 post \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100475 : PVOP_VCALL_CLOBBERS \
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200476 : paravirt_type(op), \
477 paravirt_clobber(CLBR_ANY), \
478 ##__VA_ARGS__ \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100479 : "memory", "cc" VEXTRA_CLOBBERS); \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200480 })
481
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200482#define PVOP_CALL0(rettype, op) \
483 __PVOP_CALL(rettype, op, "", "")
484#define PVOP_VCALL0(op) \
485 __PVOP_VCALL(op, "", "")
486
487#define PVOP_CALL1(rettype, op, arg1) \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100488 __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)))
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200489#define PVOP_VCALL1(op, arg1) \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100490 __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)))
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200491
492#define PVOP_CALL2(rettype, op, arg1, arg2) \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100493 __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)), \
494 "1" ((unsigned long)(arg2)))
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200495#define PVOP_VCALL2(op, arg1, arg2) \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100496 __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)), \
497 "1" ((unsigned long)(arg2)))
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200498
499#define PVOP_CALL3(rettype, op, arg1, arg2, arg3) \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100500 __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)), \
501 "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)))
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200502#define PVOP_VCALL3(op, arg1, arg2, arg3) \
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100503 __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)), \
504 "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)))
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200505
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100506/* This is the only difference in x86_64. We can make it much simpler */
507#ifdef CONFIG_X86_32
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200508#define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \
509 __PVOP_CALL(rettype, op, \
510 "push %[_arg4];", "lea 4(%%esp),%%esp;", \
511 "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
512 "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
513#define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \
514 __PVOP_VCALL(op, \
515 "push %[_arg4];", "lea 4(%%esp),%%esp;", \
516 "0" ((u32)(arg1)), "1" ((u32)(arg2)), \
517 "2" ((u32)(arg3)), [_arg4] "mr" ((u32)(arg4)))
Glauber de Oliveira Costaa4746362008-01-30 13:32:05 +0100518#else
519#define PVOP_CALL4(rettype, op, arg1, arg2, arg3, arg4) \
520 __PVOP_CALL(rettype, op, "", "", "0" ((unsigned long)(arg1)), \
521 "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)), \
522 "3"((unsigned long)(arg4)))
523#define PVOP_VCALL4(op, arg1, arg2, arg3, arg4) \
524 __PVOP_VCALL(op, "", "", "0" ((unsigned long)(arg1)), \
525 "1"((unsigned long)(arg2)), "2"((unsigned long)(arg3)), \
526 "3"((unsigned long)(arg4)))
527#endif
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +0200528
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200529static inline int paravirt_enabled(void)
530{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700531 return pv_info.paravirt_enabled;
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200532}
Rusty Russelld3561b72006-12-07 02:14:07 +0100533
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100534static inline void load_sp0(struct tss_struct *tss,
Rusty Russelld3561b72006-12-07 02:14:07 +0100535 struct thread_struct *thread)
536{
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100537 PVOP_VCALL2(pv_cpu_ops.load_sp0, tss, thread);
Rusty Russelld3561b72006-12-07 02:14:07 +0100538}
539
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700540#define ARCH_SETUP pv_init_ops.arch_setup();
Rusty Russelld3561b72006-12-07 02:14:07 +0100541static inline unsigned long get_wallclock(void)
542{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700543 return PVOP_CALL0(unsigned long, pv_time_ops.get_wallclock);
Rusty Russelld3561b72006-12-07 02:14:07 +0100544}
545
546static inline int set_wallclock(unsigned long nowtime)
547{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700548 return PVOP_CALL1(int, pv_time_ops.set_wallclock, nowtime);
Rusty Russelld3561b72006-12-07 02:14:07 +0100549}
550
Zachary Amsdene30fab32007-03-05 00:30:39 -0800551static inline void (*choose_time_init(void))(void)
Rusty Russelld3561b72006-12-07 02:14:07 +0100552{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700553 return pv_time_ops.time_init;
Rusty Russelld3561b72006-12-07 02:14:07 +0100554}
555
556/* The paravirtualized CPUID instruction. */
557static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
558 unsigned int *ecx, unsigned int *edx)
559{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700560 PVOP_VCALL4(pv_cpu_ops.cpuid, eax, ebx, ecx, edx);
Rusty Russelld3561b72006-12-07 02:14:07 +0100561}
562
563/*
564 * These special macros can be used to get or set a debugging register
565 */
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200566static inline unsigned long paravirt_get_debugreg(int reg)
567{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700568 return PVOP_CALL1(unsigned long, pv_cpu_ops.get_debugreg, reg);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200569}
570#define get_debugreg(var, reg) var = paravirt_get_debugreg(reg)
571static inline void set_debugreg(unsigned long val, int reg)
572{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700573 PVOP_VCALL2(pv_cpu_ops.set_debugreg, reg, val);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200574}
Rusty Russelld3561b72006-12-07 02:14:07 +0100575
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200576static inline void clts(void)
577{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700578 PVOP_VCALL0(pv_cpu_ops.clts);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200579}
Rusty Russelld3561b72006-12-07 02:14:07 +0100580
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200581static inline unsigned long read_cr0(void)
582{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700583 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr0);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200584}
Rusty Russelld3561b72006-12-07 02:14:07 +0100585
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200586static inline void write_cr0(unsigned long x)
587{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700588 PVOP_VCALL1(pv_cpu_ops.write_cr0, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200589}
Rusty Russelld3561b72006-12-07 02:14:07 +0100590
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200591static inline unsigned long read_cr2(void)
592{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700593 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr2);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200594}
Rusty Russelld3561b72006-12-07 02:14:07 +0100595
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200596static inline void write_cr2(unsigned long x)
597{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700598 PVOP_VCALL1(pv_mmu_ops.write_cr2, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200599}
Rusty Russelld3561b72006-12-07 02:14:07 +0100600
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200601static inline unsigned long read_cr3(void)
602{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700603 return PVOP_CALL0(unsigned long, pv_mmu_ops.read_cr3);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200604}
605
606static inline void write_cr3(unsigned long x)
607{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700608 PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200609}
610
611static inline unsigned long read_cr4(void)
612{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700613 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200614}
615static inline unsigned long read_cr4_safe(void)
616{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700617 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4_safe);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200618}
619
620static inline void write_cr4(unsigned long x)
621{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700622 PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200623}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200624
Glauber de Oliveira Costa94ea03c2008-01-30 13:33:19 +0100625#ifdef CONFIG_X86_64
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +0100626static inline unsigned long read_cr8(void)
627{
628 return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr8);
629}
630
631static inline void write_cr8(unsigned long x)
632{
633 PVOP_VCALL1(pv_cpu_ops.write_cr8, x);
634}
Glauber de Oliveira Costa94ea03c2008-01-30 13:33:19 +0100635#endif
Glauber de Oliveira Costa4c9890c2008-01-30 13:33:19 +0100636
Rusty Russelld3561b72006-12-07 02:14:07 +0100637static inline void raw_safe_halt(void)
638{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700639 PVOP_VCALL0(pv_irq_ops.safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100640}
641
642static inline void halt(void)
643{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700644 PVOP_VCALL0(pv_irq_ops.safe_halt);
Rusty Russelld3561b72006-12-07 02:14:07 +0100645}
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200646
647static inline void wbinvd(void)
648{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700649 PVOP_VCALL0(pv_cpu_ops.wbinvd);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200650}
Rusty Russelld3561b72006-12-07 02:14:07 +0100651
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700652#define get_kernel_rpl() (pv_info.kernel_rpl)
Rusty Russelld3561b72006-12-07 02:14:07 +0100653
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200654static inline u64 paravirt_read_msr(unsigned msr, int *err)
655{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700656 return PVOP_CALL2(u64, pv_cpu_ops.read_msr, msr, err);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200657}
658static inline int paravirt_write_msr(unsigned msr, unsigned low, unsigned high)
659{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700660 return PVOP_CALL3(int, pv_cpu_ops.write_msr, msr, low, high);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200661}
662
Rusty Russell90a0a062007-05-02 19:27:10 +0200663/* These should all do BUG_ON(_err), but our headers are too tangled. */
Joe Perches49cd7402008-03-23 01:03:00 -0700664#define rdmsr(msr, val1, val2) \
665do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200666 int _err; \
667 u64 _l = paravirt_read_msr(msr, &_err); \
668 val1 = (u32)_l; \
669 val2 = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700670} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100671
Joe Perches49cd7402008-03-23 01:03:00 -0700672#define wrmsr(msr, val1, val2) \
673do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200674 paravirt_write_msr(msr, val1, val2); \
Joe Perches49cd7402008-03-23 01:03:00 -0700675} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100676
Joe Perches49cd7402008-03-23 01:03:00 -0700677#define rdmsrl(msr, val) \
678do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200679 int _err; \
680 val = paravirt_read_msr(msr, &_err); \
Joe Perches49cd7402008-03-23 01:03:00 -0700681} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100682
Joe Perches49cd7402008-03-23 01:03:00 -0700683#define wrmsrl(msr, val) wrmsr(msr, (u32)((u64)(val)), ((u64)(val))>>32)
684#define wrmsr_safe(msr, a, b) paravirt_write_msr(msr, a, b)
Rusty Russelld3561b72006-12-07 02:14:07 +0100685
686/* rdmsr with exception handling */
Joe Perches49cd7402008-03-23 01:03:00 -0700687#define rdmsr_safe(msr, a, b) \
688({ \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200689 int _err; \
690 u64 _l = paravirt_read_msr(msr, &_err); \
691 (*a) = (u32)_l; \
692 (*b) = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700693 _err; \
694})
Rusty Russelld3561b72006-12-07 02:14:07 +0100695
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200696
697static inline u64 paravirt_read_tsc(void)
698{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700699 return PVOP_CALL0(u64, pv_cpu_ops.read_tsc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200700}
Rusty Russelld3561b72006-12-07 02:14:07 +0100701
Joe Perches49cd7402008-03-23 01:03:00 -0700702#define rdtscl(low) \
703do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200704 u64 _l = paravirt_read_tsc(); \
705 low = (int)_l; \
Joe Perches49cd7402008-03-23 01:03:00 -0700706} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100707
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200708#define rdtscll(val) (val = paravirt_read_tsc())
Rusty Russelld3561b72006-12-07 02:14:07 +0100709
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700710static inline unsigned long long paravirt_sched_clock(void)
711{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700712 return PVOP_CALL0(unsigned long long, pv_time_ops.sched_clock);
Jeremy Fitzhardinge688340e2007-07-17 18:37:04 -0700713}
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700714#define calculate_cpu_khz() (pv_time_ops.get_cpu_khz())
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800715
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200716static inline unsigned long long paravirt_read_pmc(int counter)
717{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700718 return PVOP_CALL1(u64, pv_cpu_ops.read_pmc, counter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200719}
720
Joe Perches49cd7402008-03-23 01:03:00 -0700721#define rdpmc(counter, low, high) \
722do { \
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200723 u64 _l = paravirt_read_pmc(counter); \
724 low = (u32)_l; \
725 high = _l >> 32; \
Joe Perches49cd7402008-03-23 01:03:00 -0700726} while (0)
Rusty Russelld3561b72006-12-07 02:14:07 +0100727
Glauber de Oliveira Costae5aaac42008-01-30 13:32:05 +0100728static inline unsigned long long paravirt_rdtscp(unsigned int *aux)
729{
730 return PVOP_CALL1(u64, pv_cpu_ops.read_tscp, aux);
731}
732
733#define rdtscp(low, high, aux) \
734do { \
735 int __aux; \
736 unsigned long __val = paravirt_rdtscp(&__aux); \
737 (low) = (u32)__val; \
738 (high) = (u32)(__val >> 32); \
739 (aux) = __aux; \
740} while (0)
741
742#define rdtscpll(val, aux) \
743do { \
744 unsigned long __aux; \
745 val = paravirt_rdtscp(&__aux); \
746 (aux) = __aux; \
747} while (0)
748
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200749static inline void load_TR_desc(void)
750{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700751 PVOP_VCALL0(pv_cpu_ops.load_tr_desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200752}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100753static inline void load_gdt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200754{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700755 PVOP_VCALL1(pv_cpu_ops.load_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200756}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100757static inline void load_idt(const struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200758{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700759 PVOP_VCALL1(pv_cpu_ops.load_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200760}
761static inline void set_ldt(const void *addr, unsigned entries)
762{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700763 PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200764}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100765static inline void store_gdt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200766{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700767 PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200768}
Glauber de Oliveira Costa6b68f012008-01-30 13:31:12 +0100769static inline void store_idt(struct desc_ptr *dtr)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200770{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700771 PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200772}
773static inline unsigned long paravirt_store_tr(void)
774{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700775 return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200776}
777#define store_tr(tr) ((tr) = paravirt_store_tr())
778static inline void load_TLS(struct thread_struct *t, unsigned cpu)
779{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700780 PVOP_VCALL2(pv_cpu_ops.load_tls, t, cpu);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200781}
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100782
783static inline void write_ldt_entry(struct desc_struct *dt, int entry,
784 const void *desc)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200785{
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100786 PVOP_VCALL3(pv_cpu_ops.write_ldt_entry, dt, entry, desc);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200787}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100788
789static inline void write_gdt_entry(struct desc_struct *dt, int entry,
790 void *desc, int type)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200791{
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100792 PVOP_VCALL4(pv_cpu_ops.write_gdt_entry, dt, entry, desc, type);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200793}
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100794
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100795static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200796{
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100797 PVOP_VCALL3(pv_cpu_ops.write_idt_entry, dt, entry, g);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200798}
799static inline void set_iopl_mask(unsigned mask)
800{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700801 PVOP_VCALL1(pv_cpu_ops.set_iopl_mask, mask);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200802}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200803
Rusty Russelld3561b72006-12-07 02:14:07 +0100804/* The paravirtualized I/O functions */
Joe Perches49cd7402008-03-23 01:03:00 -0700805static inline void slow_down_io(void)
806{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700807 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100808#ifdef REALLY_SLOW_IO
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700809 pv_cpu_ops.io_delay();
810 pv_cpu_ops.io_delay();
811 pv_cpu_ops.io_delay();
Rusty Russelld3561b72006-12-07 02:14:07 +0100812#endif
813}
814
Rusty Russell13623d72006-12-07 02:14:08 +0100815#ifdef CONFIG_X86_LOCAL_APIC
816/*
817 * Basic functions accessing APICs.
818 */
Thomas Gleixner42e0a9aa2008-01-30 13:30:15 +0100819static inline void apic_write(unsigned long reg, u32 v)
Rusty Russell13623d72006-12-07 02:14:08 +0100820{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700821 PVOP_VCALL2(pv_apic_ops.apic_write, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100822}
823
Thomas Gleixner42e0a9aa2008-01-30 13:30:15 +0100824static inline void apic_write_atomic(unsigned long reg, u32 v)
Rusty Russell13623d72006-12-07 02:14:08 +0100825{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700826 PVOP_VCALL2(pv_apic_ops.apic_write_atomic, reg, v);
Rusty Russell13623d72006-12-07 02:14:08 +0100827}
828
Thomas Gleixner42e0a9aa2008-01-30 13:30:15 +0100829static inline u32 apic_read(unsigned long reg)
Rusty Russell13623d72006-12-07 02:14:08 +0100830{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700831 return PVOP_CALL1(unsigned long, pv_apic_ops.apic_read, reg);
Rusty Russell13623d72006-12-07 02:14:08 +0100832}
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100833
834static inline void setup_boot_clock(void)
835{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700836 PVOP_VCALL0(pv_apic_ops.setup_boot_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100837}
838
839static inline void setup_secondary_clock(void)
840{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700841 PVOP_VCALL0(pv_apic_ops.setup_secondary_clock);
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100842}
Rusty Russell13623d72006-12-07 02:14:08 +0100843#endif
844
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -0700845static inline void paravirt_post_allocator_init(void)
846{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700847 if (pv_init_ops.post_allocator_init)
848 (*pv_init_ops.post_allocator_init)();
Jeremy Fitzhardinge6996d3b2007-07-17 18:37:03 -0700849}
850
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200851static inline void paravirt_pagetable_setup_start(pgd_t *base)
852{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700853 (*pv_mmu_ops.pagetable_setup_start)(base);
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200854}
855
856static inline void paravirt_pagetable_setup_done(pgd_t *base)
857{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700858 (*pv_mmu_ops.pagetable_setup_done)(base);
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200859}
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200860
Zachary Amsdenae5da272007-02-13 13:26:21 +0100861#ifdef CONFIG_SMP
862static inline void startup_ipi_hook(int phys_apicid, unsigned long start_eip,
863 unsigned long start_esp)
864{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700865 PVOP_VCALL3(pv_apic_ops.startup_ipi_hook,
866 phys_apicid, start_eip, start_esp);
Zachary Amsdenae5da272007-02-13 13:26:21 +0100867}
868#endif
Rusty Russell13623d72006-12-07 02:14:08 +0100869
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200870static inline void paravirt_activate_mm(struct mm_struct *prev,
871 struct mm_struct *next)
872{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700873 PVOP_VCALL2(pv_mmu_ops.activate_mm, prev, next);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200874}
875
876static inline void arch_dup_mmap(struct mm_struct *oldmm,
877 struct mm_struct *mm)
878{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700879 PVOP_VCALL2(pv_mmu_ops.dup_mmap, oldmm, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200880}
881
882static inline void arch_exit_mmap(struct mm_struct *mm)
883{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700884 PVOP_VCALL1(pv_mmu_ops.exit_mmap, mm);
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200885}
886
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200887static inline void __flush_tlb(void)
888{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700889 PVOP_VCALL0(pv_mmu_ops.flush_tlb_user);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200890}
891static inline void __flush_tlb_global(void)
892{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700893 PVOP_VCALL0(pv_mmu_ops.flush_tlb_kernel);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200894}
895static inline void __flush_tlb_single(unsigned long addr)
896{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700897 PVOP_VCALL1(pv_mmu_ops.flush_tlb_single, addr);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200898}
Rusty Russellda181a82006-12-07 02:14:08 +0100899
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200900static inline void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
901 unsigned long va)
902{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700903 PVOP_VCALL3(pv_mmu_ops.flush_tlb_others, &cpumask, mm, va);
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200904}
905
Jeremy Fitzhardingefdb4c332007-07-17 18:37:03 -0700906static inline void paravirt_alloc_pt(struct mm_struct *mm, unsigned pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200907{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700908 PVOP_VCALL2(pv_mmu_ops.alloc_pt, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200909}
910static inline void paravirt_release_pt(unsigned pfn)
911{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700912 PVOP_VCALL1(pv_mmu_ops.release_pt, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200913}
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100914
Jeremy Fitzhardinge6c435452008-01-30 13:33:39 +0100915static inline void paravirt_alloc_pd(struct mm_struct *mm, unsigned pfn)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200916{
Jeremy Fitzhardinge6c435452008-01-30 13:33:39 +0100917 PVOP_VCALL2(pv_mmu_ops.alloc_pd, mm, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200918}
919
920static inline void paravirt_alloc_pd_clone(unsigned pfn, unsigned clonepfn,
921 unsigned start, unsigned count)
922{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700923 PVOP_VCALL4(pv_mmu_ops.alloc_pd_clone, pfn, clonepfn, start, count);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200924}
925static inline void paravirt_release_pd(unsigned pfn)
926{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700927 PVOP_VCALL1(pv_mmu_ops.release_pd, pfn);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200928}
929
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200930#ifdef CONFIG_HIGHPTE
931static inline void *kmap_atomic_pte(struct page *page, enum km_type type)
932{
933 unsigned long ret;
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700934 ret = PVOP_CALL2(unsigned long, pv_mmu_ops.kmap_atomic_pte, page, type);
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +0200935 return (void *)ret;
936}
937#endif
938
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200939static inline void pte_update(struct mm_struct *mm, unsigned long addr,
940 pte_t *ptep)
941{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700942 PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200943}
944
945static inline void pte_update_defer(struct mm_struct *mm, unsigned long addr,
946 pte_t *ptep)
947{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700948 PVOP_VCALL3(pv_mmu_ops.pte_update_defer, mm, addr, ptep);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200949}
950
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100951static inline pte_t __pte(pteval_t val)
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200952{
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100953 pteval_t ret;
954
955 if (sizeof(pteval_t) > sizeof(long))
956 ret = PVOP_CALL2(pteval_t,
957 pv_mmu_ops.make_pte,
958 val, (u64)val >> 32);
959 else
960 ret = PVOP_CALL1(pteval_t,
961 pv_mmu_ops.make_pte,
962 val);
963
Jeremy Fitzhardingec8e53932008-01-30 13:32:57 +0100964 return (pte_t) { .pte = ret };
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +0200965}
966
Jeremy Fitzhardinge773221f2008-01-30 13:33:15 +0100967static inline pteval_t pte_val(pte_t pte)
968{
969 pteval_t ret;
970
971 if (sizeof(pteval_t) > sizeof(long))
972 ret = PVOP_CALL2(pteval_t, pv_mmu_ops.pte_val,
973 pte.pte, (u64)pte.pte >> 32);
974 else
975 ret = PVOP_CALL1(pteval_t, pv_mmu_ops.pte_val,
976 pte.pte);
977
978 return ret;
979}
980
Jeremy Fitzhardingeef385032008-01-30 13:33:15 +0100981static inline pgd_t __pgd(pgdval_t val)
982{
983 pgdval_t ret;
984
985 if (sizeof(pgdval_t) > sizeof(long))
986 ret = PVOP_CALL2(pgdval_t, pv_mmu_ops.make_pgd,
987 val, (u64)val >> 32);
988 else
989 ret = PVOP_CALL1(pgdval_t, pv_mmu_ops.make_pgd,
990 val);
991
992 return (pgd_t) { ret };
993}
994
995static inline pgdval_t pgd_val(pgd_t pgd)
996{
997 pgdval_t ret;
998
999 if (sizeof(pgdval_t) > sizeof(long))
1000 ret = PVOP_CALL2(pgdval_t, pv_mmu_ops.pgd_val,
1001 pgd.pgd, (u64)pgd.pgd >> 32);
1002 else
1003 ret = PVOP_CALL1(pgdval_t, pv_mmu_ops.pgd_val,
1004 pgd.pgd);
1005
1006 return ret;
1007}
1008
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +01001009static inline void set_pte(pte_t *ptep, pte_t pte)
1010{
1011 if (sizeof(pteval_t) > sizeof(long))
1012 PVOP_VCALL3(pv_mmu_ops.set_pte, ptep,
1013 pte.pte, (u64)pte.pte >> 32);
1014 else
1015 PVOP_VCALL2(pv_mmu_ops.set_pte, ptep,
1016 pte.pte);
1017}
1018
1019static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
1020 pte_t *ptep, pte_t pte)
1021{
1022 if (sizeof(pteval_t) > sizeof(long))
1023 /* 5 arg words */
1024 pv_mmu_ops.set_pte_at(mm, addr, ptep, pte);
1025 else
1026 PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte);
1027}
1028
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +01001029static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
1030{
1031 pmdval_t val = native_pmd_val(pmd);
1032
1033 if (sizeof(pmdval_t) > sizeof(long))
1034 PVOP_VCALL3(pv_mmu_ops.set_pmd, pmdp, val, (u64)val >> 32);
1035 else
1036 PVOP_VCALL2(pv_mmu_ops.set_pmd, pmdp, val);
1037}
1038
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +01001039#if PAGETABLE_LEVELS >= 3
1040static inline pmd_t __pmd(pmdval_t val)
1041{
1042 pmdval_t ret;
1043
1044 if (sizeof(pmdval_t) > sizeof(long))
1045 ret = PVOP_CALL2(pmdval_t, pv_mmu_ops.make_pmd,
1046 val, (u64)val >> 32);
1047 else
1048 ret = PVOP_CALL1(pmdval_t, pv_mmu_ops.make_pmd,
1049 val);
1050
1051 return (pmd_t) { ret };
1052}
1053
1054static inline pmdval_t pmd_val(pmd_t pmd)
1055{
1056 pmdval_t ret;
1057
1058 if (sizeof(pmdval_t) > sizeof(long))
1059 ret = PVOP_CALL2(pmdval_t, pv_mmu_ops.pmd_val,
1060 pmd.pmd, (u64)pmd.pmd >> 32);
1061 else
1062 ret = PVOP_CALL1(pmdval_t, pv_mmu_ops.pmd_val,
1063 pmd.pmd);
1064
1065 return ret;
1066}
1067
1068static inline void set_pud(pud_t *pudp, pud_t pud)
1069{
1070 pudval_t val = native_pud_val(pud);
1071
1072 if (sizeof(pudval_t) > sizeof(long))
1073 PVOP_VCALL3(pv_mmu_ops.set_pud, pudp,
1074 val, (u64)val >> 32);
1075 else
1076 PVOP_VCALL2(pv_mmu_ops.set_pud, pudp,
1077 val);
1078}
Eduardo Habkost90422192008-01-30 13:33:20 +01001079#if PAGETABLE_LEVELS == 4
1080static inline pud_t __pud(pudval_t val)
1081{
1082 pudval_t ret;
1083
1084 if (sizeof(pudval_t) > sizeof(long))
1085 ret = PVOP_CALL2(pudval_t, pv_mmu_ops.make_pud,
1086 val, (u64)val >> 32);
1087 else
1088 ret = PVOP_CALL1(pudval_t, pv_mmu_ops.make_pud,
1089 val);
1090
1091 return (pud_t) { ret };
1092}
1093
1094static inline pudval_t pud_val(pud_t pud)
1095{
1096 pudval_t ret;
1097
1098 if (sizeof(pudval_t) > sizeof(long))
1099 ret = PVOP_CALL2(pudval_t, pv_mmu_ops.pud_val,
1100 pud.pud, (u64)pud.pud >> 32);
1101 else
1102 ret = PVOP_CALL1(pudval_t, pv_mmu_ops.pud_val,
1103 pud.pud);
1104
1105 return ret;
1106}
1107
1108static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
1109{
1110 pgdval_t val = native_pgd_val(pgd);
1111
1112 if (sizeof(pgdval_t) > sizeof(long))
1113 PVOP_VCALL3(pv_mmu_ops.set_pgd, pgdp,
1114 val, (u64)val >> 32);
1115 else
1116 PVOP_VCALL2(pv_mmu_ops.set_pgd, pgdp,
1117 val);
1118}
1119
1120static inline void pgd_clear(pgd_t *pgdp)
1121{
1122 set_pgd(pgdp, __pgd(0));
1123}
1124
1125static inline void pud_clear(pud_t *pudp)
1126{
1127 set_pud(pudp, __pud(0));
1128}
1129
1130#endif /* PAGETABLE_LEVELS == 4 */
1131
Glauber de Oliveira Costa1fe91512008-01-30 13:33:19 +01001132#endif /* PAGETABLE_LEVELS >= 3 */
1133
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +01001134#ifdef CONFIG_X86_PAE
1135/* Special-case pte-setting operations for PAE, which can't update a
1136 64-bit pte atomically */
1137static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
1138{
1139 PVOP_VCALL3(pv_mmu_ops.set_pte_atomic, ptep,
1140 pte.pte, pte.pte >> 32);
1141}
1142
1143static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
1144 pte_t *ptep, pte_t pte)
1145{
1146 /* 5 arg words */
1147 pv_mmu_ops.set_pte_present(mm, addr, ptep, pte);
1148}
1149
1150static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
1151 pte_t *ptep)
1152{
1153 PVOP_VCALL3(pv_mmu_ops.pte_clear, mm, addr, ptep);
1154}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +01001155
1156static inline void pmd_clear(pmd_t *pmdp)
1157{
1158 PVOP_VCALL1(pv_mmu_ops.pmd_clear, pmdp);
1159}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +01001160#else /* !CONFIG_X86_PAE */
1161static inline void set_pte_atomic(pte_t *ptep, pte_t pte)
1162{
1163 set_pte(ptep, pte);
1164}
1165
1166static inline void set_pte_present(struct mm_struct *mm, unsigned long addr,
1167 pte_t *ptep, pte_t pte)
1168{
1169 set_pte(ptep, pte);
1170}
1171
1172static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
1173 pte_t *ptep)
1174{
1175 set_pte_at(mm, addr, ptep, __pte(0));
1176}
Jeremy Fitzhardinge60b3f622008-01-30 13:33:15 +01001177
1178static inline void pmd_clear(pmd_t *pmdp)
1179{
1180 set_pmd(pmdp, __pmd(0));
1181}
Jeremy Fitzhardinge4eed80c2008-01-30 13:33:15 +01001182#endif /* CONFIG_X86_PAE */
1183
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001184/* Lazy mode for batching updates / context switch */
1185enum paravirt_lazy_mode {
1186 PARAVIRT_LAZY_NONE,
1187 PARAVIRT_LAZY_MMU,
1188 PARAVIRT_LAZY_CPU,
1189};
1190
1191enum paravirt_lazy_mode paravirt_get_lazy_mode(void);
1192void paravirt_enter_lazy_cpu(void);
1193void paravirt_leave_lazy_cpu(void);
1194void paravirt_enter_lazy_mmu(void);
1195void paravirt_leave_lazy_mmu(void);
1196void paravirt_leave_lazy(enum paravirt_lazy_mode mode);
1197
Zachary Amsden9226d122007-02-13 13:26:21 +01001198#define __HAVE_ARCH_ENTER_LAZY_CPU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001199static inline void arch_enter_lazy_cpu_mode(void)
1200{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001201 PVOP_VCALL0(pv_cpu_ops.lazy_mode.enter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001202}
1203
1204static inline void arch_leave_lazy_cpu_mode(void)
1205{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001206 PVOP_VCALL0(pv_cpu_ops.lazy_mode.leave);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001207}
1208
1209static inline void arch_flush_lazy_cpu_mode(void)
1210{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001211 if (unlikely(paravirt_get_lazy_mode() == PARAVIRT_LAZY_CPU)) {
1212 arch_leave_lazy_cpu_mode();
1213 arch_enter_lazy_cpu_mode();
1214 }
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001215}
1216
Zachary Amsden9226d122007-02-13 13:26:21 +01001217
1218#define __HAVE_ARCH_ENTER_LAZY_MMU_MODE
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001219static inline void arch_enter_lazy_mmu_mode(void)
1220{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001221 PVOP_VCALL0(pv_mmu_ops.lazy_mode.enter);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001222}
1223
1224static inline void arch_leave_lazy_mmu_mode(void)
1225{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001226 PVOP_VCALL0(pv_mmu_ops.lazy_mode.leave);
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001227}
1228
1229static inline void arch_flush_lazy_mmu_mode(void)
1230{
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -07001231 if (unlikely(paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU)) {
1232 arch_leave_lazy_mmu_mode();
1233 arch_enter_lazy_mmu_mode();
1234 }
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001235}
Zachary Amsden9226d122007-02-13 13:26:21 +01001236
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +02001237void _paravirt_nop(void);
1238#define paravirt_nop ((void *)_paravirt_nop)
1239
Rusty Russell139ec7c2006-12-07 02:14:08 +01001240/* These all sit in the .parainstructions section to tell us what to patch. */
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001241struct paravirt_patch_site {
Rusty Russell139ec7c2006-12-07 02:14:08 +01001242 u8 *instr; /* original instructions */
1243 u8 instrtype; /* type of this instruction */
1244 u8 len; /* length of original instruction */
1245 u16 clobbers; /* what registers you may clobber */
1246};
1247
Jeremy Fitzhardinge98de0322007-05-02 19:27:14 +02001248extern struct paravirt_patch_site __parainstructions[],
1249 __parainstructions_end[];
1250
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001251#ifdef CONFIG_X86_32
1252#define PV_SAVE_REGS "pushl %%ecx; pushl %%edx;"
1253#define PV_RESTORE_REGS "popl %%edx; popl %%ecx"
1254#define PV_FLAGS_ARG "0"
1255#define PV_EXTRA_CLOBBERS
1256#define PV_VEXTRA_CLOBBERS
1257#else
1258/* We save some registers, but all of them, that's too much. We clobber all
1259 * caller saved registers but the argument parameter */
1260#define PV_SAVE_REGS "pushq %%rdi;"
1261#define PV_RESTORE_REGS "popq %%rdi;"
1262#define PV_EXTRA_CLOBBERS EXTRA_CLOBBERS, "rcx" , "rdx"
1263#define PV_VEXTRA_CLOBBERS EXTRA_CLOBBERS, "rdi", "rcx" , "rdx"
1264#define PV_FLAGS_ARG "D"
1265#endif
1266
Rusty Russell139ec7c2006-12-07 02:14:08 +01001267static inline unsigned long __raw_local_save_flags(void)
1268{
1269 unsigned long f;
1270
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001271 asm volatile(paravirt_alt(PV_SAVE_REGS
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001272 PARAVIRT_CALL
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001273 PV_RESTORE_REGS)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001274 : "=a"(f)
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001275 : paravirt_type(pv_irq_ops.save_fl),
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001276 paravirt_clobber(CLBR_EAX)
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001277 : "memory", "cc" PV_VEXTRA_CLOBBERS);
Rusty Russell139ec7c2006-12-07 02:14:08 +01001278 return f;
1279}
1280
1281static inline void raw_local_irq_restore(unsigned long f)
1282{
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001283 asm volatile(paravirt_alt(PV_SAVE_REGS
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001284 PARAVIRT_CALL
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001285 PV_RESTORE_REGS)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001286 : "=a"(f)
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001287 : PV_FLAGS_ARG(f),
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001288 paravirt_type(pv_irq_ops.restore_fl),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001289 paravirt_clobber(CLBR_EAX)
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001290 : "memory", "cc" PV_EXTRA_CLOBBERS);
Rusty Russell139ec7c2006-12-07 02:14:08 +01001291}
1292
1293static inline void raw_local_irq_disable(void)
1294{
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001295 asm volatile(paravirt_alt(PV_SAVE_REGS
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001296 PARAVIRT_CALL
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001297 PV_RESTORE_REGS)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001298 :
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001299 : paravirt_type(pv_irq_ops.irq_disable),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001300 paravirt_clobber(CLBR_EAX)
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001301 : "memory", "eax", "cc" PV_EXTRA_CLOBBERS);
Rusty Russell139ec7c2006-12-07 02:14:08 +01001302}
1303
1304static inline void raw_local_irq_enable(void)
1305{
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001306 asm volatile(paravirt_alt(PV_SAVE_REGS
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001307 PARAVIRT_CALL
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001308 PV_RESTORE_REGS)
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001309 :
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001310 : paravirt_type(pv_irq_ops.irq_enable),
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001311 paravirt_clobber(CLBR_EAX)
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001312 : "memory", "eax", "cc" PV_EXTRA_CLOBBERS);
Rusty Russell139ec7c2006-12-07 02:14:08 +01001313}
1314
1315static inline unsigned long __raw_local_irq_save(void)
1316{
1317 unsigned long f;
1318
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001319 f = __raw_local_save_flags();
1320 raw_local_irq_disable();
Rusty Russell139ec7c2006-12-07 02:14:08 +01001321 return f;
1322}
1323
Jeremy Fitzhardinge294688c2007-05-02 19:27:14 +02001324/* Make sure as little as possible of this mess escapes. */
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001325#undef PARAVIRT_CALL
Jeremy Fitzhardinge1a45b7a2007-05-02 19:27:15 +02001326#undef __PVOP_CALL
1327#undef __PVOP_VCALL
Jeremy Fitzhardingef8822f42007-05-02 19:27:14 +02001328#undef PVOP_VCALL0
1329#undef PVOP_CALL0
1330#undef PVOP_VCALL1
1331#undef PVOP_CALL1
1332#undef PVOP_VCALL2
1333#undef PVOP_CALL2
1334#undef PVOP_VCALL3
1335#undef PVOP_CALL3
1336#undef PVOP_VCALL4
1337#undef PVOP_CALL4
Rusty Russell139ec7c2006-12-07 02:14:08 +01001338
Rusty Russelld3561b72006-12-07 02:14:07 +01001339#else /* __ASSEMBLY__ */
1340
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001341#define _PVSITE(ptype, clobbers, ops, word, algn) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001342771:; \
1343 ops; \
1344772:; \
1345 .pushsection .parainstructions,"a"; \
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001346 .align algn; \
1347 word 771b; \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001348 .byte ptype; \
1349 .byte 772b-771b; \
1350 .short clobbers; \
1351 .popsection
1352
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001353
1354#ifdef CONFIG_X86_64
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001355#define PV_SAVE_REGS pushq %rax; pushq %rdi; pushq %rcx; pushq %rdx
1356#define PV_RESTORE_REGS popq %rdx; popq %rcx; popq %rdi; popq %rax
1357#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 8)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001358#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .quad, 8)
1359#else
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001360#define PV_SAVE_REGS pushl %eax; pushl %edi; pushl %ecx; pushl %edx
1361#define PV_RESTORE_REGS popl %edx; popl %ecx; popl %edi; popl %eax
1362#define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
Glauber de Oliveira Costa658be9d2008-01-30 13:32:06 +01001363#define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
1364#endif
1365
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001366#define INTERRUPT_RETURN \
1367 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_iret), CLBR_NONE, \
1368 jmp *%cs:pv_cpu_ops+PV_CPU_iret)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001369
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001370#define DISABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001371 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_disable), clobbers, \
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001372 PV_SAVE_REGS; \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001373 call *%cs:pv_irq_ops+PV_IRQ_irq_disable; \
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001374 PV_RESTORE_REGS;) \
Rusty Russell139ec7c2006-12-07 02:14:08 +01001375
Jeremy Fitzhardinged5822032007-05-02 19:27:14 +02001376#define ENABLE_INTERRUPTS(clobbers) \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001377 PARA_SITE(PARA_PATCH(pv_irq_ops, PV_IRQ_irq_enable), clobbers, \
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001378 PV_SAVE_REGS; \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001379 call *%cs:pv_irq_ops+PV_IRQ_irq_enable; \
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001380 PV_RESTORE_REGS;)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001381
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +01001382#define ENABLE_INTERRUPTS_SYSCALL_RET \
1383 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_syscall_ret),\
1384 CLBR_NONE, \
1385 jmp *%cs:pv_cpu_ops+PV_CPU_irq_enable_syscall_ret)
Rusty Russell139ec7c2006-12-07 02:14:08 +01001386
Glauber de Oliveira Costa2e47d3e2008-01-30 13:32:07 +01001387
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001388#ifdef CONFIG_X86_32
Rusty Russell139ec7c2006-12-07 02:14:08 +01001389#define GET_CR0_INTO_EAX \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001390 push %ecx; push %edx; \
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -07001391 call *pv_cpu_ops+PV_CPU_read_cr0; \
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +02001392 pop %edx; pop %ecx
Glauber de Oliveira Costa4a8c4c42008-01-30 13:32:07 +01001393#else
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +01001394#define SWAPGS \
1395 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_swapgs), CLBR_NONE, \
1396 PV_SAVE_REGS; \
1397 call *pv_cpu_ops+PV_CPU_swapgs; \
1398 PV_RESTORE_REGS \
1399 )
1400
Glauber de Oliveira Costa4a8c4c42008-01-30 13:32:07 +01001401#define GET_CR2_INTO_RCX \
1402 call *pv_mmu_ops+PV_MMU_read_cr2; \
1403 movq %rax, %rcx; \
1404 xorq %rax, %rax;
1405
Glauber de Oliveira Costa6057fc82008-01-30 13:32:06 +01001406#endif
Rusty Russell139ec7c2006-12-07 02:14:08 +01001407
Rusty Russelld3561b72006-12-07 02:14:07 +01001408#endif /* __ASSEMBLY__ */
1409#endif /* CONFIG_PARAVIRT */
1410#endif /* __ASM_PARAVIRT_H */