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>
34 /***************************************************************************
37 static struct pv_info xen_info __initdata = {
38 .kernel_rpl = 2, /* or 1: determin at runtime */
39 .paravirt_enabled = 1,
43 #define IA64_RSC_PL_SHIFT 2
44 #define IA64_RSC_PL_BIT_SIZE 2
45 #define IA64_RSC_PL_MASK \
46 (((1UL << IA64_RSC_PL_BIT_SIZE) - 1) << IA64_RSC_PL_SHIFT)
51 /* Xenified Linux/ia64 may run on pl = 1 or 2.
52 * determin at run time. */
53 unsigned long rsc = ia64_getreg(_IA64_REG_AR_RSC);
54 unsigned int rpl = (rsc & IA64_RSC_PL_MASK) >> IA64_RSC_PL_SHIFT;
55 xen_info.kernel_rpl = rpl;
58 /***************************************************************************
60 * initialization hooks.
64 xen_panic_hypercall(struct unw_frame_info *info, void *arg)
66 current->thread.ksp = (__u64)info->sw - 16;
67 HYPERVISOR_shutdown(SHUTDOWN_crash);
68 /* we're never actually going to get here... */
72 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
74 unw_init_running(xen_panic_hypercall, NULL);
75 /* we're never actually going to get here... */
79 static struct notifier_block xen_panic_block = {
80 xen_panic_event, NULL, 0 /* try to go last */
83 static void xen_pm_power_off(void)
86 HYPERVISOR_shutdown(SHUTDOWN_poweroff);
93 "Running on Xen! pl = %d start_info_pfn=0x%lx nr_pages=%ld "
96 HYPERVISOR_shared_info->arch.start_info_pfn,
97 xen_start_info->nr_pages, xen_start_info->flags);
101 xen_reserve_memory(struct rsvd_region *region)
103 region->start = (unsigned long)__va(
104 (HYPERVISOR_shared_info->arch.start_info_pfn << PAGE_SHIFT));
105 region->end = region->start + PAGE_SIZE;
110 xen_arch_setup_early(void)
112 struct shared_info *s;
113 BUG_ON(!xen_pv_domain());
115 s = HYPERVISOR_shared_info;
116 xen_start_info = __va(s->arch.start_info_pfn << PAGE_SHIFT);
118 /* Must be done before any hypercall. */
119 xencomm_initialize();
121 xen_setup_features();
122 /* Register a call for panic conditions. */
123 atomic_notifier_chain_register(&panic_notifier_list,
125 pm_power_off = xen_pm_power_off;
127 xen_ia64_enable_opt_feature();
131 xen_arch_setup_console(char **cmdline_p)
133 add_preferred_console("xenboot", 0, NULL);
134 add_preferred_console("tty", 0, NULL);
136 add_preferred_console("hvc", 0, NULL);
138 #if !defined(CONFIG_VT) || !defined(CONFIG_DUMMY_CONSOLE)
144 xen_arch_setup_nomca(void)
150 xen_post_smp_prepare_boot_cpu(void)
152 xen_setup_vcpu_info_placement();
155 static const struct pv_init_ops xen_init_ops __initdata = {
156 .banner = xen_banner,
158 .reserve_memory = xen_reserve_memory,
160 .arch_setup_early = xen_arch_setup_early,
161 .arch_setup_console = xen_arch_setup_console,
162 .arch_setup_nomca = xen_arch_setup_nomca,
164 .post_smp_prepare_boot_cpu = xen_post_smp_prepare_boot_cpu,
167 /***************************************************************************
172 static void xen_setreg(int regnum, unsigned long val)
175 case _IA64_REG_AR_KR0 ... _IA64_REG_AR_KR7:
176 xen_set_kr(regnum - _IA64_REG_AR_KR0, val);
178 #ifdef CONFIG_IA32_SUPPORT
179 case _IA64_REG_AR_EFLAG:
183 case _IA64_REG_CR_TPR:
186 case _IA64_REG_CR_ITM:
189 case _IA64_REG_CR_EOI:
193 ia64_native_setreg_func(regnum, val);
198 static unsigned long xen_getreg(int regnum)
206 #ifdef CONFIG_IA32_SUPPORT
207 case _IA64_REG_AR_EFLAG:
208 res = xen_get_eflag();
211 case _IA64_REG_CR_IVR:
214 case _IA64_REG_CR_TPR:
218 res = ia64_native_getreg_func(regnum);
224 /* turning on interrupts is a bit more complicated.. write to the
225 * memory-mapped virtual psr.i bit first (to avoid race condition),
226 * then if any interrupts were pending, we have to execute a hyperprivop
227 * to ensure the pending interrupt gets delivered; else we're done! */
231 int old = xen_get_virtual_psr_i();
232 xen_set_virtual_psr_i(1);
234 if (!old && xen_get_virtual_pend())
238 /* turning off interrupts can be paravirtualized simply by writing
239 * to a memory-mapped virtual psr.i bit (implemented as a 16-bit bool) */
243 xen_set_virtual_psr_i(0);
250 return xen_get_virtual_psr_i() ? IA64_PSR_I : 0;
254 xen_intrin_local_irq_restore(unsigned long mask)
256 if (mask & IA64_PSR_I)
262 static const struct pv_cpu_ops xen_cpu_ops __initdata = {
265 .get_cpuid = xen_get_cpuid,
266 .get_pmd = xen_get_pmd,
267 .getreg = xen_getreg,
268 .setreg = xen_setreg,
270 .get_rr = xen_get_rr,
271 .set_rr = xen_set_rr,
272 .set_rr0_to_rr4 = xen_set_rr0_to_rr4,
275 .get_psr_i = xen_get_psr_i,
276 .intrin_local_irq_restore
277 = xen_intrin_local_irq_restore,
280 /******************************************************************************
281 * replacement of hand written assembly codes.
284 extern char xen_switch_to;
285 extern char xen_leave_syscall;
286 extern char xen_work_processed_syscall;
287 extern char xen_leave_kernel;
289 const struct pv_cpu_asm_switch xen_cpu_asm_switch = {
290 .switch_to = (unsigned long)&xen_switch_to,
291 .leave_syscall = (unsigned long)&xen_leave_syscall,
292 .work_processed_syscall = (unsigned long)&xen_work_processed_syscall,
293 .leave_kernel = (unsigned long)&xen_leave_kernel,
296 /***************************************************************************
298 * iosapic read/write hooks.
301 xen_pcat_compat_init(void)
306 static struct irq_chip*
307 xen_iosapic_get_irq_chip(unsigned long trigger)
313 xen_iosapic_read(char __iomem *iosapic, unsigned int reg)
315 struct physdev_apic apic_op;
318 apic_op.apic_physbase = (unsigned long)iosapic -
319 __IA64_UNCACHED_OFFSET;
321 ret = HYPERVISOR_physdev_op(PHYSDEVOP_apic_read, &apic_op);
324 return apic_op.value;
328 xen_iosapic_write(char __iomem *iosapic, unsigned int reg, u32 val)
330 struct physdev_apic apic_op;
332 apic_op.apic_physbase = (unsigned long)iosapic -
333 __IA64_UNCACHED_OFFSET;
336 HYPERVISOR_physdev_op(PHYSDEVOP_apic_write, &apic_op);
339 static const struct pv_iosapic_ops xen_iosapic_ops __initdata = {
340 .pcat_compat_init = xen_pcat_compat_init,
341 .__get_irq_chip = xen_iosapic_get_irq_chip,
343 .__read = xen_iosapic_read,
344 .__write = xen_iosapic_write,
347 /***************************************************************************
348 * pv_ops initialization
352 xen_setup_pv_ops(void)
356 pv_init_ops = xen_init_ops;
357 pv_cpu_ops = xen_cpu_ops;
358 pv_iosapic_ops = xen_iosapic_ops;
359 pv_irq_ops = xen_irq_ops;
361 paravirt_cpu_asm_init(&xen_cpu_asm_switch);