1 /* Paravirtualization interfaces
2 Copyright (C) 2006 Rusty Russell IBM Corporation
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include <linux/errno.h>
19 #include <linux/module.h>
20 #include <linux/efi.h>
21 #include <linux/bcd.h>
22 #include <linux/start_kernel.h>
25 #include <asm/paravirt.h>
27 #include <asm/setup.h>
28 #include <asm/arch_hooks.h>
31 #include <asm/delay.h>
32 #include <asm/fixmap.h>
34 #include <asm/tlbflush.h>
35 #include <asm/timer.h>
38 void _paravirt_nop(void)
42 static void __init default_banner(void)
44 printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
48 char *memory_setup(void)
50 return paravirt_ops.memory_setup();
53 /* Simple instruction patching code. */
54 #define DEF_NATIVE(name, code) \
55 extern const char start_##name[], end_##name[]; \
56 asm("start_" #name ": " code "; end_" #name ":")
57 DEF_NATIVE(cli, "cli");
58 DEF_NATIVE(sti, "sti");
59 DEF_NATIVE(popf, "push %eax; popf");
60 DEF_NATIVE(pushf, "pushf; pop %eax");
61 DEF_NATIVE(iret, "iret");
62 DEF_NATIVE(sti_sysexit, "sti; sysexit");
64 static const struct native_insns
66 const char *start, *end;
68 [PARAVIRT_PATCH(irq_disable)] = { start_cli, end_cli },
69 [PARAVIRT_PATCH(irq_enable)] = { start_sti, end_sti },
70 [PARAVIRT_PATCH(restore_fl)] = { start_popf, end_popf },
71 [PARAVIRT_PATCH(save_fl)] = { start_pushf, end_pushf },
72 [PARAVIRT_PATCH(iret)] = { start_iret, end_iret },
73 [PARAVIRT_PATCH(irq_enable_sysexit)] = { start_sti_sysexit, end_sti_sysexit },
76 static unsigned native_patch(u8 type, u16 clobbers, void *insns, unsigned len)
78 unsigned int insn_len;
80 /* Don't touch it if we don't have a replacement */
81 if (type >= ARRAY_SIZE(native_insns) || !native_insns[type].start)
84 insn_len = native_insns[type].end - native_insns[type].start;
86 /* Similarly if we can't fit replacement. */
90 memcpy(insns, native_insns[type].start, insn_len);
96 paravirt_ops.init_IRQ();
99 static void native_flush_tlb(void)
101 __native_flush_tlb();
105 * Global pages have to be flushed a bit differently. Not a real
106 * performance problem because this does not happen often.
108 static void native_flush_tlb_global(void)
110 __native_flush_tlb_global();
113 static void native_flush_tlb_single(u32 addr)
115 __native_flush_tlb_single(addr);
118 /* These are in entry.S */
119 extern void native_iret(void);
120 extern void native_irq_enable_sysexit(void);
122 static int __init print_banner(void)
124 paravirt_ops.banner();
127 core_initcall(print_banner);
129 struct paravirt_ops paravirt_ops = {
130 .name = "bare hardware",
131 .paravirt_enabled = 0,
133 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
135 .patch = native_patch,
136 .banner = default_banner,
137 .arch_setup = paravirt_nop,
138 .memory_setup = machine_specific_memory_setup,
139 .get_wallclock = native_get_wallclock,
140 .set_wallclock = native_set_wallclock,
141 .time_init = hpet_time_init,
142 .init_IRQ = native_init_IRQ,
144 .cpuid = native_cpuid,
145 .get_debugreg = native_get_debugreg,
146 .set_debugreg = native_set_debugreg,
148 .read_cr0 = native_read_cr0,
149 .write_cr0 = native_write_cr0,
150 .read_cr2 = native_read_cr2,
151 .write_cr2 = native_write_cr2,
152 .read_cr3 = native_read_cr3,
153 .write_cr3 = native_write_cr3,
154 .read_cr4 = native_read_cr4,
155 .read_cr4_safe = native_read_cr4_safe,
156 .write_cr4 = native_write_cr4,
157 .save_fl = native_save_fl,
158 .restore_fl = native_restore_fl,
159 .irq_disable = native_irq_disable,
160 .irq_enable = native_irq_enable,
161 .safe_halt = native_safe_halt,
163 .wbinvd = native_wbinvd,
164 .read_msr = native_read_msr_safe,
165 .write_msr = native_write_msr_safe,
166 .read_tsc = native_read_tsc,
167 .read_pmc = native_read_pmc,
168 .get_scheduled_cycles = native_read_tsc,
169 .get_cpu_khz = native_calculate_cpu_khz,
170 .load_tr_desc = native_load_tr_desc,
171 .set_ldt = native_set_ldt,
172 .load_gdt = native_load_gdt,
173 .load_idt = native_load_idt,
174 .store_gdt = native_store_gdt,
175 .store_idt = native_store_idt,
176 .store_tr = native_store_tr,
177 .load_tls = native_load_tls,
178 .write_ldt_entry = write_dt_entry,
179 .write_gdt_entry = write_dt_entry,
180 .write_idt_entry = write_dt_entry,
181 .load_esp0 = native_load_esp0,
183 .set_iopl_mask = native_set_iopl_mask,
184 .io_delay = native_io_delay,
186 #ifdef CONFIG_X86_LOCAL_APIC
187 .apic_write = native_apic_write,
188 .apic_write_atomic = native_apic_write_atomic,
189 .apic_read = native_apic_read,
190 .setup_boot_clock = setup_boot_APIC_clock,
191 .setup_secondary_clock = setup_secondary_APIC_clock,
193 .set_lazy_mode = paravirt_nop,
195 .pagetable_setup_start = native_pagetable_setup_start,
196 .pagetable_setup_done = native_pagetable_setup_done,
198 .flush_tlb_user = native_flush_tlb,
199 .flush_tlb_kernel = native_flush_tlb_global,
200 .flush_tlb_single = native_flush_tlb_single,
202 .map_pt_hook = paravirt_nop,
204 .alloc_pt = paravirt_nop,
205 .alloc_pd = paravirt_nop,
206 .alloc_pd_clone = paravirt_nop,
207 .release_pt = paravirt_nop,
208 .release_pd = paravirt_nop,
210 .set_pte = native_set_pte,
211 .set_pte_at = native_set_pte_at,
212 .set_pmd = native_set_pmd,
213 .pte_update = paravirt_nop,
214 .pte_update_defer = paravirt_nop,
216 .ptep_get_and_clear = native_ptep_get_and_clear,
218 #ifdef CONFIG_X86_PAE
219 .set_pte_atomic = native_set_pte_atomic,
220 .set_pte_present = native_set_pte_present,
221 .set_pud = native_set_pud,
222 .pte_clear = native_pte_clear,
223 .pmd_clear = native_pmd_clear,
225 .pmd_val = native_pmd_val,
226 .make_pmd = native_make_pmd,
229 .pte_val = native_pte_val,
230 .pgd_val = native_pgd_val,
232 .make_pte = native_make_pte,
233 .make_pgd = native_make_pgd,
235 .irq_enable_sysexit = native_irq_enable_sysexit,
238 .dup_mmap = paravirt_nop,
239 .exit_mmap = paravirt_nop,
240 .activate_mm = paravirt_nop,
242 .startup_ipi_hook = paravirt_nop,
246 * NOTE: CONFIG_PARAVIRT is experimental and the paravirt_ops
247 * semantics are subject to change. Hence we only do this
248 * internal-only export of this, until it gets sorted out and
249 * all lowlevel CPU ops used by modules are separately exported.
251 EXPORT_SYMBOL_GPL(paravirt_ops);