1 /******************************************************************************
2 * arch/ia64/xen/xen_pv_ops.c
4 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
5 * VA Linux Systems Japan K.K.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/console.h>
24 #include <linux/irq.h>
25 #include <linux/kernel.h>
28 #include <asm/xen/hypervisor.h>
29 #include <asm/xen/xencomm.h>
30 #include <asm/xen/privop.h>
32 /***************************************************************************
35 static struct pv_info xen_info __initdata = {
36 .kernel_rpl = 2, /* or 1: determin at runtime */
37 .paravirt_enabled = 1,
41 #define IA64_RSC_PL_SHIFT 2
42 #define IA64_RSC_PL_BIT_SIZE 2
43 #define IA64_RSC_PL_MASK \
44 (((1UL << IA64_RSC_PL_BIT_SIZE) - 1) << IA64_RSC_PL_SHIFT)
49 /* Xenified Linux/ia64 may run on pl = 1 or 2.
50 * determin at run time. */
51 unsigned long rsc = ia64_getreg(_IA64_REG_AR_RSC);
52 unsigned int rpl = (rsc & IA64_RSC_PL_MASK) >> IA64_RSC_PL_SHIFT;
53 xen_info.kernel_rpl = rpl;
56 /***************************************************************************
58 * initialization hooks.
62 xen_panic_hypercall(struct unw_frame_info *info, void *arg)
64 current->thread.ksp = (__u64)info->sw - 16;
65 HYPERVISOR_shutdown(SHUTDOWN_crash);
66 /* we're never actually going to get here... */
70 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
72 unw_init_running(xen_panic_hypercall, NULL);
73 /* we're never actually going to get here... */
77 static struct notifier_block xen_panic_block = {
78 xen_panic_event, NULL, 0 /* try to go last */
81 static void xen_pm_power_off(void)
84 HYPERVISOR_shutdown(SHUTDOWN_poweroff);
91 "Running on Xen! pl = %d start_info_pfn=0x%lx nr_pages=%ld "
94 HYPERVISOR_shared_info->arch.start_info_pfn,
95 xen_start_info->nr_pages, xen_start_info->flags);
99 xen_reserve_memory(struct rsvd_region *region)
101 region->start = (unsigned long)__va(
102 (HYPERVISOR_shared_info->arch.start_info_pfn << PAGE_SHIFT));
103 region->end = region->start + PAGE_SIZE;
108 xen_arch_setup_early(void)
110 struct shared_info *s;
111 BUG_ON(!xen_pv_domain());
113 s = HYPERVISOR_shared_info;
114 xen_start_info = __va(s->arch.start_info_pfn << PAGE_SHIFT);
116 /* Must be done before any hypercall. */
117 xencomm_initialize();
119 xen_setup_features();
120 /* Register a call for panic conditions. */
121 atomic_notifier_chain_register(&panic_notifier_list,
123 pm_power_off = xen_pm_power_off;
125 xen_ia64_enable_opt_feature();
129 xen_arch_setup_console(char **cmdline_p)
131 add_preferred_console("xenboot", 0, NULL);
132 add_preferred_console("tty", 0, NULL);
134 add_preferred_console("hvc", 0, NULL);
136 #if !defined(CONFIG_VT) || !defined(CONFIG_DUMMY_CONSOLE)
142 xen_arch_setup_nomca(void)
148 xen_post_smp_prepare_boot_cpu(void)
150 xen_setup_vcpu_info_placement();
153 static const struct pv_init_ops xen_init_ops __initdata = {
154 .banner = xen_banner,
156 .reserve_memory = xen_reserve_memory,
158 .arch_setup_early = xen_arch_setup_early,
159 .arch_setup_console = xen_arch_setup_console,
160 .arch_setup_nomca = xen_arch_setup_nomca,
162 .post_smp_prepare_boot_cpu = xen_post_smp_prepare_boot_cpu,
165 /***************************************************************************
170 static void xen_setreg(int regnum, unsigned long val)
173 case _IA64_REG_AR_KR0 ... _IA64_REG_AR_KR7:
174 xen_set_kr(regnum - _IA64_REG_AR_KR0, val);
176 #ifdef CONFIG_IA32_SUPPORT
177 case _IA64_REG_AR_EFLAG:
181 case _IA64_REG_CR_TPR:
184 case _IA64_REG_CR_ITM:
187 case _IA64_REG_CR_EOI:
191 ia64_native_setreg_func(regnum, val);
196 static unsigned long xen_getreg(int regnum)
204 #ifdef CONFIG_IA32_SUPPORT
205 case _IA64_REG_AR_EFLAG:
206 res = xen_get_eflag();
209 case _IA64_REG_CR_IVR:
212 case _IA64_REG_CR_TPR:
216 res = ia64_native_getreg_func(regnum);
222 /* turning on interrupts is a bit more complicated.. write to the
223 * memory-mapped virtual psr.i bit first (to avoid race condition),
224 * then if any interrupts were pending, we have to execute a hyperprivop
225 * to ensure the pending interrupt gets delivered; else we're done! */
229 int old = xen_get_virtual_psr_i();
230 xen_set_virtual_psr_i(1);
232 if (!old && xen_get_virtual_pend())
236 /* turning off interrupts can be paravirtualized simply by writing
237 * to a memory-mapped virtual psr.i bit (implemented as a 16-bit bool) */
241 xen_set_virtual_psr_i(0);
248 return xen_get_virtual_psr_i() ? IA64_PSR_I : 0;
252 xen_intrin_local_irq_restore(unsigned long mask)
254 if (mask & IA64_PSR_I)
260 static const struct pv_cpu_ops xen_cpu_ops __initdata = {
263 .get_cpuid = xen_get_cpuid,
264 .get_pmd = xen_get_pmd,
265 .getreg = xen_getreg,
266 .setreg = xen_setreg,
268 .get_rr = xen_get_rr,
269 .set_rr = xen_set_rr,
270 .set_rr0_to_rr4 = xen_set_rr0_to_rr4,
273 .get_psr_i = xen_get_psr_i,
274 .intrin_local_irq_restore
275 = xen_intrin_local_irq_restore,
278 /******************************************************************************
279 * replacement of hand written assembly codes.
282 extern char xen_switch_to;
283 extern char xen_leave_syscall;
284 extern char xen_work_processed_syscall;
285 extern char xen_leave_kernel;
287 const struct pv_cpu_asm_switch xen_cpu_asm_switch = {
288 .switch_to = (unsigned long)&xen_switch_to,
289 .leave_syscall = (unsigned long)&xen_leave_syscall,
290 .work_processed_syscall = (unsigned long)&xen_work_processed_syscall,
291 .leave_kernel = (unsigned long)&xen_leave_kernel,
294 /***************************************************************************
296 * iosapic read/write hooks.
299 xen_pcat_compat_init(void)
304 static struct irq_chip*
305 xen_iosapic_get_irq_chip(unsigned long trigger)
311 xen_iosapic_read(char __iomem *iosapic, unsigned int reg)
313 struct physdev_apic apic_op;
316 apic_op.apic_physbase = (unsigned long)iosapic -
317 __IA64_UNCACHED_OFFSET;
319 ret = HYPERVISOR_physdev_op(PHYSDEVOP_apic_read, &apic_op);
322 return apic_op.value;
326 xen_iosapic_write(char __iomem *iosapic, unsigned int reg, u32 val)
328 struct physdev_apic apic_op;
330 apic_op.apic_physbase = (unsigned long)iosapic -
331 __IA64_UNCACHED_OFFSET;
334 HYPERVISOR_physdev_op(PHYSDEVOP_apic_write, &apic_op);
337 static const struct pv_iosapic_ops xen_iosapic_ops __initdata = {
338 .pcat_compat_init = xen_pcat_compat_init,
339 .__get_irq_chip = xen_iosapic_get_irq_chip,
341 .__read = xen_iosapic_read,
342 .__write = xen_iosapic_write,
345 /***************************************************************************
346 * pv_ops initialization
350 xen_setup_pv_ops(void)
354 pv_init_ops = xen_init_ops;
355 pv_cpu_ops = xen_cpu_ops;
356 pv_iosapic_ops = xen_iosapic_ops;
358 paravirt_cpu_asm_init(&xen_cpu_asm_switch);