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>
24 #include <asm/paravirt.h>
26 #include <asm/setup.h>
27 #include <asm/arch_hooks.h>
30 #include <asm/delay.h>
33 static void native_nop(void)
37 static void __init default_banner(void)
39 printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
43 char *memory_setup(void)
45 return paravirt_ops.memory_setup();
48 static fastcall unsigned long native_get_debugreg(int regno)
50 unsigned long val = 0; /* Damn you, gcc! */
54 asm("movl %%db0, %0" :"=r" (val)); break;
56 asm("movl %%db1, %0" :"=r" (val)); break;
58 asm("movl %%db2, %0" :"=r" (val)); break;
60 asm("movl %%db3, %0" :"=r" (val)); break;
62 asm("movl %%db6, %0" :"=r" (val)); break;
64 asm("movl %%db7, %0" :"=r" (val)); break;
71 static fastcall void native_set_debugreg(int regno, unsigned long value)
75 asm("movl %0,%%db0" : /* no output */ :"r" (value));
78 asm("movl %0,%%db1" : /* no output */ :"r" (value));
81 asm("movl %0,%%db2" : /* no output */ :"r" (value));
84 asm("movl %0,%%db3" : /* no output */ :"r" (value));
87 asm("movl %0,%%db6" : /* no output */ :"r" (value));
90 asm("movl %0,%%db7" : /* no output */ :"r" (value));
99 paravirt_ops.init_IRQ();
102 static fastcall void native_clts(void)
104 asm volatile ("clts");
107 static fastcall unsigned long native_read_cr0(void)
110 asm volatile("movl %%cr0,%0\n\t" :"=r" (val));
114 static fastcall void native_write_cr0(unsigned long val)
116 asm volatile("movl %0,%%cr0": :"r" (val));
119 static fastcall unsigned long native_read_cr2(void)
122 asm volatile("movl %%cr2,%0\n\t" :"=r" (val));
126 static fastcall void native_write_cr2(unsigned long val)
128 asm volatile("movl %0,%%cr2": :"r" (val));
131 static fastcall unsigned long native_read_cr3(void)
134 asm volatile("movl %%cr3,%0\n\t" :"=r" (val));
138 static fastcall void native_write_cr3(unsigned long val)
140 asm volatile("movl %0,%%cr3": :"r" (val));
143 static fastcall unsigned long native_read_cr4(void)
146 asm volatile("movl %%cr4,%0\n\t" :"=r" (val));
150 static fastcall unsigned long native_read_cr4_safe(void)
153 /* This could fault if %cr4 does not exist */
154 asm("1: movl %%cr4, %0 \n"
156 ".section __ex_table,\"a\" \n"
159 : "=r" (val): "0" (0));
163 static fastcall void native_write_cr4(unsigned long val)
165 asm volatile("movl %0,%%cr4": :"r" (val));
168 static fastcall unsigned long native_save_fl(void)
171 asm volatile("pushfl ; popl %0":"=g" (f): /* no input */);
175 static fastcall void native_restore_fl(unsigned long f)
177 asm volatile("pushl %0 ; popfl": /* no output */
182 static fastcall void native_irq_disable(void)
184 asm volatile("cli": : :"memory");
187 static fastcall void native_irq_enable(void)
189 asm volatile("sti": : :"memory");
192 static fastcall void native_safe_halt(void)
194 asm volatile("sti; hlt": : :"memory");
197 static fastcall void native_halt(void)
199 asm volatile("hlt": : :"memory");
202 static fastcall void native_wbinvd(void)
204 asm volatile("wbinvd": : :"memory");
207 static fastcall unsigned long long native_read_msr(unsigned int msr, int *err)
209 unsigned long long val;
211 asm volatile("2: rdmsr ; xorl %0,%0\n"
213 ".section .fixup,\"ax\"\n\t"
214 "3: movl %3,%0 ; jmp 1b\n\t"
216 ".section __ex_table,\"a\"\n"
220 : "=r" (*err), "=A" (val)
221 : "c" (msr), "i" (-EFAULT));
226 static fastcall int native_write_msr(unsigned int msr, unsigned long long val)
229 asm volatile("2: wrmsr ; xorl %0,%0\n"
231 ".section .fixup,\"ax\"\n\t"
232 "3: movl %4,%0 ; jmp 1b\n\t"
234 ".section __ex_table,\"a\"\n"
239 : "c" (msr), "0" ((u32)val), "d" ((u32)(val>>32)),
244 static fastcall unsigned long long native_read_tsc(void)
246 unsigned long long val;
247 asm volatile("rdtsc" : "=A" (val));
251 static fastcall unsigned long long native_read_pmc(void)
253 unsigned long long val;
254 asm volatile("rdpmc" : "=A" (val));
258 static fastcall void native_load_tr_desc(void)
260 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
263 static fastcall void native_load_gdt(const struct Xgt_desc_struct *dtr)
265 asm volatile("lgdt %0"::"m" (*dtr));
268 static fastcall void native_load_idt(const struct Xgt_desc_struct *dtr)
270 asm volatile("lidt %0"::"m" (*dtr));
273 static fastcall void native_store_gdt(struct Xgt_desc_struct *dtr)
275 asm ("sgdt %0":"=m" (*dtr));
278 static fastcall void native_store_idt(struct Xgt_desc_struct *dtr)
280 asm ("sidt %0":"=m" (*dtr));
283 static fastcall unsigned long native_store_tr(void)
286 asm ("str %0":"=r" (tr));
290 static fastcall void native_load_tls(struct thread_struct *t, unsigned int cpu)
292 #define C(i) get_cpu_gdt_table(cpu)[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i]
297 static inline void native_write_dt_entry(void *dt, int entry, u32 entry_low, u32 entry_high)
299 u32 *lp = (u32 *)((char *)dt + entry*8);
304 static fastcall void native_write_ldt_entry(void *dt, int entrynum, u32 low, u32 high)
306 native_write_dt_entry(dt, entrynum, low, high);
309 static fastcall void native_write_gdt_entry(void *dt, int entrynum, u32 low, u32 high)
311 native_write_dt_entry(dt, entrynum, low, high);
314 static fastcall void native_write_idt_entry(void *dt, int entrynum, u32 low, u32 high)
316 native_write_dt_entry(dt, entrynum, low, high);
319 static fastcall void native_load_esp0(struct tss_struct *tss,
320 struct thread_struct *thread)
322 tss->esp0 = thread->esp0;
324 /* This can only happen when SEP is enabled, no need to test "SEP"arately */
325 if (unlikely(tss->ss1 != thread->sysenter_cs)) {
326 tss->ss1 = thread->sysenter_cs;
327 wrmsr(MSR_IA32_SYSENTER_CS, thread->sysenter_cs, 0);
331 static fastcall void native_io_delay(void)
333 asm volatile("outb %al,$0x80");
336 /* These are in entry.S */
337 extern fastcall void native_iret(void);
338 extern fastcall void native_irq_enable_sysexit(void);
340 static int __init print_banner(void)
342 paravirt_ops.banner();
345 core_initcall(print_banner);
347 struct paravirt_ops paravirt_ops = {
348 .name = "bare hardware",
349 .paravirt_enabled = 0,
352 .banner = default_banner,
353 .arch_setup = native_nop,
354 .memory_setup = machine_specific_memory_setup,
355 .get_wallclock = native_get_wallclock,
356 .set_wallclock = native_set_wallclock,
357 .time_init = time_init_hook,
358 .init_IRQ = native_init_IRQ,
360 .cpuid = native_cpuid,
361 .get_debugreg = native_get_debugreg,
362 .set_debugreg = native_set_debugreg,
364 .read_cr0 = native_read_cr0,
365 .write_cr0 = native_write_cr0,
366 .read_cr2 = native_read_cr2,
367 .write_cr2 = native_write_cr2,
368 .read_cr3 = native_read_cr3,
369 .write_cr3 = native_write_cr3,
370 .read_cr4 = native_read_cr4,
371 .read_cr4_safe = native_read_cr4_safe,
372 .write_cr4 = native_write_cr4,
373 .save_fl = native_save_fl,
374 .restore_fl = native_restore_fl,
375 .irq_disable = native_irq_disable,
376 .irq_enable = native_irq_enable,
377 .safe_halt = native_safe_halt,
379 .wbinvd = native_wbinvd,
380 .read_msr = native_read_msr,
381 .write_msr = native_write_msr,
382 .read_tsc = native_read_tsc,
383 .read_pmc = native_read_pmc,
384 .load_tr_desc = native_load_tr_desc,
385 .set_ldt = native_set_ldt,
386 .load_gdt = native_load_gdt,
387 .load_idt = native_load_idt,
388 .store_gdt = native_store_gdt,
389 .store_idt = native_store_idt,
390 .store_tr = native_store_tr,
391 .load_tls = native_load_tls,
392 .write_ldt_entry = native_write_ldt_entry,
393 .write_gdt_entry = native_write_gdt_entry,
394 .write_idt_entry = native_write_idt_entry,
395 .load_esp0 = native_load_esp0,
397 .set_iopl_mask = native_set_iopl_mask,
398 .io_delay = native_io_delay,
399 .const_udelay = __const_udelay,
401 .irq_enable_sysexit = native_irq_enable_sysexit,
404 EXPORT_SYMBOL(paravirt_ops);