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>
35 /***************************************************************************
38 static struct pv_info xen_info __initdata = {
39 .kernel_rpl = 2, /* or 1: determin at runtime */
40 .paravirt_enabled = 1,
44 #define IA64_RSC_PL_SHIFT 2
45 #define IA64_RSC_PL_BIT_SIZE 2
46 #define IA64_RSC_PL_MASK \
47 (((1UL << IA64_RSC_PL_BIT_SIZE) - 1) << IA64_RSC_PL_SHIFT)
52 /* Xenified Linux/ia64 may run on pl = 1 or 2.
53 * determin at run time. */
54 unsigned long rsc = ia64_getreg(_IA64_REG_AR_RSC);
55 unsigned int rpl = (rsc & IA64_RSC_PL_MASK) >> IA64_RSC_PL_SHIFT;
56 xen_info.kernel_rpl = rpl;
59 /***************************************************************************
61 * initialization hooks.
65 xen_panic_hypercall(struct unw_frame_info *info, void *arg)
67 current->thread.ksp = (__u64)info->sw - 16;
68 HYPERVISOR_shutdown(SHUTDOWN_crash);
69 /* we're never actually going to get here... */
73 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
75 unw_init_running(xen_panic_hypercall, NULL);
76 /* we're never actually going to get here... */
80 static struct notifier_block xen_panic_block = {
81 xen_panic_event, NULL, 0 /* try to go last */
84 static void xen_pm_power_off(void)
87 HYPERVISOR_shutdown(SHUTDOWN_poweroff);
94 "Running on Xen! pl = %d start_info_pfn=0x%lx nr_pages=%ld "
97 HYPERVISOR_shared_info->arch.start_info_pfn,
98 xen_start_info->nr_pages, xen_start_info->flags);
102 xen_reserve_memory(struct rsvd_region *region)
104 region->start = (unsigned long)__va(
105 (HYPERVISOR_shared_info->arch.start_info_pfn << PAGE_SHIFT));
106 region->end = region->start + PAGE_SIZE;
111 xen_arch_setup_early(void)
113 struct shared_info *s;
114 BUG_ON(!xen_pv_domain());
116 s = HYPERVISOR_shared_info;
117 xen_start_info = __va(s->arch.start_info_pfn << PAGE_SHIFT);
119 /* Must be done before any hypercall. */
120 xencomm_initialize();
122 xen_setup_features();
123 /* Register a call for panic conditions. */
124 atomic_notifier_chain_register(&panic_notifier_list,
126 pm_power_off = xen_pm_power_off;
128 xen_ia64_enable_opt_feature();
132 xen_arch_setup_console(char **cmdline_p)
134 add_preferred_console("xenboot", 0, NULL);
135 add_preferred_console("tty", 0, NULL);
137 add_preferred_console("hvc", 0, NULL);
139 #if !defined(CONFIG_VT) || !defined(CONFIG_DUMMY_CONSOLE)
145 xen_arch_setup_nomca(void)
151 xen_post_smp_prepare_boot_cpu(void)
153 xen_setup_vcpu_info_placement();
156 static const struct pv_init_ops xen_init_ops __initdata = {
157 .banner = xen_banner,
159 .reserve_memory = xen_reserve_memory,
161 .arch_setup_early = xen_arch_setup_early,
162 .arch_setup_console = xen_arch_setup_console,
163 .arch_setup_nomca = xen_arch_setup_nomca,
165 .post_smp_prepare_boot_cpu = xen_post_smp_prepare_boot_cpu,
168 /***************************************************************************
173 static void xen_setreg(int regnum, unsigned long val)
176 case _IA64_REG_AR_KR0 ... _IA64_REG_AR_KR7:
177 xen_set_kr(regnum - _IA64_REG_AR_KR0, val);
179 #ifdef CONFIG_IA32_SUPPORT
180 case _IA64_REG_AR_EFLAG:
184 case _IA64_REG_CR_TPR:
187 case _IA64_REG_CR_ITM:
190 case _IA64_REG_CR_EOI:
194 ia64_native_setreg_func(regnum, val);
199 static unsigned long xen_getreg(int regnum)
207 #ifdef CONFIG_IA32_SUPPORT
208 case _IA64_REG_AR_EFLAG:
209 res = xen_get_eflag();
212 case _IA64_REG_CR_IVR:
215 case _IA64_REG_CR_TPR:
219 res = ia64_native_getreg_func(regnum);
225 /* turning on interrupts is a bit more complicated.. write to the
226 * memory-mapped virtual psr.i bit first (to avoid race condition),
227 * then if any interrupts were pending, we have to execute a hyperprivop
228 * to ensure the pending interrupt gets delivered; else we're done! */
232 int old = xen_get_virtual_psr_i();
233 xen_set_virtual_psr_i(1);
235 if (!old && xen_get_virtual_pend())
239 /* turning off interrupts can be paravirtualized simply by writing
240 * to a memory-mapped virtual psr.i bit (implemented as a 16-bit bool) */
244 xen_set_virtual_psr_i(0);
251 return xen_get_virtual_psr_i() ? IA64_PSR_I : 0;
255 xen_intrin_local_irq_restore(unsigned long mask)
257 if (mask & IA64_PSR_I)
263 static const struct pv_cpu_ops xen_cpu_ops __initdata = {
266 .get_cpuid = xen_get_cpuid,
267 .get_pmd = xen_get_pmd,
268 .getreg = xen_getreg,
269 .setreg = xen_setreg,
271 .get_rr = xen_get_rr,
272 .set_rr = xen_set_rr,
273 .set_rr0_to_rr4 = xen_set_rr0_to_rr4,
276 .get_psr_i = xen_get_psr_i,
277 .intrin_local_irq_restore
278 = xen_intrin_local_irq_restore,
281 /******************************************************************************
282 * replacement of hand written assembly codes.
285 extern char xen_switch_to;
286 extern char xen_leave_syscall;
287 extern char xen_work_processed_syscall;
288 extern char xen_leave_kernel;
290 const struct pv_cpu_asm_switch xen_cpu_asm_switch = {
291 .switch_to = (unsigned long)&xen_switch_to,
292 .leave_syscall = (unsigned long)&xen_leave_syscall,
293 .work_processed_syscall = (unsigned long)&xen_work_processed_syscall,
294 .leave_kernel = (unsigned long)&xen_leave_kernel,
297 /***************************************************************************
299 * iosapic read/write hooks.
302 xen_pcat_compat_init(void)
307 static struct irq_chip*
308 xen_iosapic_get_irq_chip(unsigned long trigger)
314 xen_iosapic_read(char __iomem *iosapic, unsigned int reg)
316 struct physdev_apic apic_op;
319 apic_op.apic_physbase = (unsigned long)iosapic -
320 __IA64_UNCACHED_OFFSET;
322 ret = HYPERVISOR_physdev_op(PHYSDEVOP_apic_read, &apic_op);
325 return apic_op.value;
329 xen_iosapic_write(char __iomem *iosapic, unsigned int reg, u32 val)
331 struct physdev_apic apic_op;
333 apic_op.apic_physbase = (unsigned long)iosapic -
334 __IA64_UNCACHED_OFFSET;
337 HYPERVISOR_physdev_op(PHYSDEVOP_apic_write, &apic_op);
340 static const struct pv_iosapic_ops xen_iosapic_ops __initdata = {
341 .pcat_compat_init = xen_pcat_compat_init,
342 .__get_irq_chip = xen_iosapic_get_irq_chip,
344 .__read = xen_iosapic_read,
345 .__write = xen_iosapic_write,
348 /***************************************************************************
349 * pv_ops initialization
353 xen_setup_pv_ops(void)
357 pv_init_ops = xen_init_ops;
358 pv_cpu_ops = xen_cpu_ops;
359 pv_iosapic_ops = xen_iosapic_ops;
360 pv_irq_ops = xen_irq_ops;
361 pv_time_ops = xen_time_ops;
363 paravirt_cpu_asm_init(&xen_cpu_asm_switch);