blob: cba7a15ce1b00016f702af326809b77dc0c0c5c4 [file] [log] [blame]
Rusty Russelld3561b72006-12-07 02:14:07 +01001/* Paravirtualization interfaces
2 Copyright (C) 2006 Rusty Russell IBM Corporation
3
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.
8
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.
13
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
17*/
18#include <linux/errno.h>
19#include <linux/module.h>
20#include <linux/efi.h>
21#include <linux/bcd.h>
Rusty Russellc9ccf302006-12-07 02:14:08 +010022#include <linux/start_kernel.h>
Rusty Russelld3561b72006-12-07 02:14:07 +010023
24#include <asm/bug.h>
25#include <asm/paravirt.h>
26#include <asm/desc.h>
27#include <asm/setup.h>
28#include <asm/arch_hooks.h>
29#include <asm/time.h>
30#include <asm/irq.h>
31#include <asm/delay.h>
Rusty Russell13623d72006-12-07 02:14:08 +010032#include <asm/fixmap.h>
33#include <asm/apic.h>
Rusty Russellda181a82006-12-07 02:14:08 +010034#include <asm/tlbflush.h>
Zachary Amsden6cb9a832007-03-05 00:30:35 -080035#include <asm/timer.h>
Rusty Russelld3561b72006-12-07 02:14:07 +010036
37/* nop stub */
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +020038void _paravirt_nop(void)
Rusty Russelld3561b72006-12-07 02:14:07 +010039{
40}
41
42static void __init default_banner(void)
43{
44 printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
45 paravirt_ops.name);
46}
47
48char *memory_setup(void)
49{
50 return paravirt_ops.memory_setup();
51}
52
Rusty Russell139ec7c2006-12-07 02:14:08 +010053/* 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 ":")
57DEF_NATIVE(cli, "cli");
58DEF_NATIVE(sti, "sti");
59DEF_NATIVE(popf, "push %eax; popf");
60DEF_NATIVE(pushf, "pushf; pop %eax");
61DEF_NATIVE(pushf_cli, "pushf; pop %eax; cli");
62DEF_NATIVE(iret, "iret");
63DEF_NATIVE(sti_sysexit, "sti; sysexit");
64
65static const struct native_insns
66{
67 const char *start, *end;
68} native_insns[] = {
69 [PARAVIRT_IRQ_DISABLE] = { start_cli, end_cli },
70 [PARAVIRT_IRQ_ENABLE] = { start_sti, end_sti },
71 [PARAVIRT_RESTORE_FLAGS] = { start_popf, end_popf },
72 [PARAVIRT_SAVE_FLAGS] = { start_pushf, end_pushf },
73 [PARAVIRT_SAVE_FLAGS_IRQ_DISABLE] = { start_pushf_cli, end_pushf_cli },
74 [PARAVIRT_INTERRUPT_RETURN] = { start_iret, end_iret },
75 [PARAVIRT_STI_SYSEXIT] = { start_sti_sysexit, end_sti_sysexit },
76};
77
78static unsigned native_patch(u8 type, u16 clobbers, void *insns, unsigned len)
79{
80 unsigned int insn_len;
81
82 /* Don't touch it if we don't have a replacement */
83 if (type >= ARRAY_SIZE(native_insns) || !native_insns[type].start)
84 return len;
85
86 insn_len = native_insns[type].end - native_insns[type].start;
87
88 /* Similarly if we can't fit replacement. */
89 if (len < insn_len)
90 return len;
91
92 memcpy(insns, native_insns[type].start, insn_len);
93 return insn_len;
94}
95
Rusty Russelld3561b72006-12-07 02:14:07 +010096void init_IRQ(void)
97{
98 paravirt_ops.init_IRQ();
99}
100
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100101static void native_flush_tlb(void)
Rusty Russellda181a82006-12-07 02:14:08 +0100102{
103 __native_flush_tlb();
104}
105
106/*
107 * Global pages have to be flushed a bit differently. Not a real
108 * performance problem because this does not happen often.
109 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100110static void native_flush_tlb_global(void)
Rusty Russellda181a82006-12-07 02:14:08 +0100111{
112 __native_flush_tlb_global();
113}
114
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100115static void native_flush_tlb_single(u32 addr)
Rusty Russellda181a82006-12-07 02:14:08 +0100116{
117 __native_flush_tlb_single(addr);
118}
119
Rusty Russelld3561b72006-12-07 02:14:07 +0100120/* These are in entry.S */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100121extern void native_iret(void);
122extern void native_irq_enable_sysexit(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100123
124static int __init print_banner(void)
125{
126 paravirt_ops.banner();
127 return 0;
128}
129core_initcall(print_banner);
130
131struct paravirt_ops paravirt_ops = {
132 .name = "bare hardware",
133 .paravirt_enabled = 0,
134 .kernel_rpl = 0,
135
Rusty Russell139ec7c2006-12-07 02:14:08 +0100136 .patch = native_patch,
Rusty Russelld3561b72006-12-07 02:14:07 +0100137 .banner = default_banner,
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200138 .arch_setup = paravirt_nop,
Rusty Russelld3561b72006-12-07 02:14:07 +0100139 .memory_setup = machine_specific_memory_setup,
140 .get_wallclock = native_get_wallclock,
141 .set_wallclock = native_set_wallclock,
Zachary Amsdene30fab32007-03-05 00:30:39 -0800142 .time_init = hpet_time_init,
Rusty Russelld3561b72006-12-07 02:14:07 +0100143 .init_IRQ = native_init_IRQ,
144
145 .cpuid = native_cpuid,
146 .get_debugreg = native_get_debugreg,
147 .set_debugreg = native_set_debugreg,
148 .clts = native_clts,
149 .read_cr0 = native_read_cr0,
150 .write_cr0 = native_write_cr0,
151 .read_cr2 = native_read_cr2,
152 .write_cr2 = native_write_cr2,
153 .read_cr3 = native_read_cr3,
154 .write_cr3 = native_write_cr3,
155 .read_cr4 = native_read_cr4,
156 .read_cr4_safe = native_read_cr4_safe,
157 .write_cr4 = native_write_cr4,
158 .save_fl = native_save_fl,
159 .restore_fl = native_restore_fl,
160 .irq_disable = native_irq_disable,
161 .irq_enable = native_irq_enable,
162 .safe_halt = native_safe_halt,
163 .halt = native_halt,
164 .wbinvd = native_wbinvd,
Rusty Russell90a0a062007-05-02 19:27:10 +0200165 .read_msr = native_read_msr_safe,
166 .write_msr = native_write_msr_safe,
Rusty Russelld3561b72006-12-07 02:14:07 +0100167 .read_tsc = native_read_tsc,
168 .read_pmc = native_read_pmc,
Zachary Amsden6cb9a832007-03-05 00:30:35 -0800169 .get_scheduled_cycles = native_read_tsc,
Zachary Amsden1182d852007-03-05 00:30:36 -0800170 .get_cpu_khz = native_calculate_cpu_khz,
Rusty Russelld3561b72006-12-07 02:14:07 +0100171 .load_tr_desc = native_load_tr_desc,
172 .set_ldt = native_set_ldt,
173 .load_gdt = native_load_gdt,
174 .load_idt = native_load_idt,
175 .store_gdt = native_store_gdt,
176 .store_idt = native_store_idt,
177 .store_tr = native_store_tr,
178 .load_tls = native_load_tls,
Rusty Russell90a0a062007-05-02 19:27:10 +0200179 .write_ldt_entry = write_dt_entry,
180 .write_gdt_entry = write_dt_entry,
181 .write_idt_entry = write_dt_entry,
Rusty Russelld3561b72006-12-07 02:14:07 +0100182 .load_esp0 = native_load_esp0,
183
184 .set_iopl_mask = native_set_iopl_mask,
185 .io_delay = native_io_delay,
Rusty Russelld3561b72006-12-07 02:14:07 +0100186
Rusty Russell13623d72006-12-07 02:14:08 +0100187#ifdef CONFIG_X86_LOCAL_APIC
188 .apic_write = native_apic_write,
189 .apic_write_atomic = native_apic_write_atomic,
190 .apic_read = native_apic_read,
Zachary Amsdenbbab4f32007-02-13 13:26:21 +0100191 .setup_boot_clock = setup_boot_APIC_clock,
192 .setup_secondary_clock = setup_secondary_APIC_clock,
Rusty Russell13623d72006-12-07 02:14:08 +0100193#endif
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200194 .set_lazy_mode = paravirt_nop,
Rusty Russell13623d72006-12-07 02:14:08 +0100195
Rusty Russellda181a82006-12-07 02:14:08 +0100196 .flush_tlb_user = native_flush_tlb,
197 .flush_tlb_kernel = native_flush_tlb_global,
198 .flush_tlb_single = native_flush_tlb_single,
199
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200200 .map_pt_hook = paravirt_nop,
Zachary Amsden9a1c13e2007-03-05 00:30:37 -0800201
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200202 .alloc_pt = paravirt_nop,
203 .alloc_pd = paravirt_nop,
204 .alloc_pd_clone = paravirt_nop,
205 .release_pt = paravirt_nop,
206 .release_pd = paravirt_nop,
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100207
Rusty Russellda181a82006-12-07 02:14:08 +0100208 .set_pte = native_set_pte,
209 .set_pte_at = native_set_pte_at,
210 .set_pmd = native_set_pmd,
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200211 .pte_update = paravirt_nop,
212 .pte_update_defer = paravirt_nop,
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200213
214 .ptep_get_and_clear = native_ptep_get_and_clear,
215
Rusty Russellda181a82006-12-07 02:14:08 +0100216#ifdef CONFIG_X86_PAE
217 .set_pte_atomic = native_set_pte_atomic,
218 .set_pte_present = native_set_pte_present,
219 .set_pud = native_set_pud,
220 .pte_clear = native_pte_clear,
221 .pmd_clear = native_pmd_clear,
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200222
223 .pmd_val = native_pmd_val,
224 .make_pmd = native_make_pmd,
Rusty Russellda181a82006-12-07 02:14:08 +0100225#endif
226
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200227 .pte_val = native_pte_val,
228 .pgd_val = native_pgd_val,
229
230 .make_pte = native_make_pte,
231 .make_pgd = native_make_pgd,
232
Rusty Russelld3561b72006-12-07 02:14:07 +0100233 .irq_enable_sysexit = native_irq_enable_sysexit,
234 .iret = native_iret,
Zachary Amsdenae5da272007-02-13 13:26:21 +0100235
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200236 .startup_ipi_hook = paravirt_nop,
Rusty Russelld3561b72006-12-07 02:14:07 +0100237};
Ingo Molnar0dbe5a12007-01-22 20:40:36 -0800238
239/*
240 * NOTE: CONFIG_PARAVIRT is experimental and the paravirt_ops
241 * semantics are subject to change. Hence we only do this
242 * internal-only export of this, until it gets sorted out and
243 * all lowlevel CPU ops used by modules are separately exported.
244 */
245EXPORT_SYMBOL_GPL(paravirt_ops);