xen_pv_ops.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /******************************************************************************
  2. * arch/ia64/xen/xen_pv_ops.c
  3. *
  4. * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
  5. * VA Linux Systems Japan K.K.
  6. *
  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.
  11. *
  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.
  16. *
  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
  20. *
  21. */
  22. #include <linux/console.h>
  23. #include <linux/irq.h>
  24. #include <linux/kernel.h>
  25. #include <linux/pm.h>
  26. #include <linux/unistd.h>
  27. #include <asm/xen/hypervisor.h>
  28. #include <asm/xen/xencomm.h>
  29. #include <asm/xen/privop.h>
  30. #include "irq_xen.h"
  31. #include "time.h"
  32. /***************************************************************************
  33. * general info
  34. */
  35. static struct pv_info xen_info __initdata = {
  36. .kernel_rpl = 2, /* or 1: determin at runtime */
  37. .paravirt_enabled = 1,
  38. .name = "Xen/ia64",
  39. };
  40. #define IA64_RSC_PL_SHIFT 2
  41. #define IA64_RSC_PL_BIT_SIZE 2
  42. #define IA64_RSC_PL_MASK \
  43. (((1UL << IA64_RSC_PL_BIT_SIZE) - 1) << IA64_RSC_PL_SHIFT)
  44. static void __init
  45. xen_info_init(void)
  46. {
  47. /* Xenified Linux/ia64 may run on pl = 1 or 2.
  48. * determin at run time. */
  49. unsigned long rsc = ia64_getreg(_IA64_REG_AR_RSC);
  50. unsigned int rpl = (rsc & IA64_RSC_PL_MASK) >> IA64_RSC_PL_SHIFT;
  51. xen_info.kernel_rpl = rpl;
  52. }
  53. /***************************************************************************
  54. * pv_init_ops
  55. * initialization hooks.
  56. */
  57. static void
  58. xen_panic_hypercall(struct unw_frame_info *info, void *arg)
  59. {
  60. current->thread.ksp = (__u64)info->sw - 16;
  61. HYPERVISOR_shutdown(SHUTDOWN_crash);
  62. /* we're never actually going to get here... */
  63. }
  64. static int
  65. xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
  66. {
  67. unw_init_running(xen_panic_hypercall, NULL);
  68. /* we're never actually going to get here... */
  69. return NOTIFY_DONE;
  70. }
  71. static struct notifier_block xen_panic_block = {
  72. xen_panic_event, NULL, 0 /* try to go last */
  73. };
  74. static void xen_pm_power_off(void)
  75. {
  76. local_irq_disable();
  77. HYPERVISOR_shutdown(SHUTDOWN_poweroff);
  78. }
  79. static void __init
  80. xen_banner(void)
  81. {
  82. printk(KERN_INFO
  83. "Running on Xen! pl = %d start_info_pfn=0x%lx nr_pages=%ld "
  84. "flags=0x%x\n",
  85. xen_info.kernel_rpl,
  86. HYPERVISOR_shared_info->arch.start_info_pfn,
  87. xen_start_info->nr_pages, xen_start_info->flags);
  88. }
  89. static int __init
  90. xen_reserve_memory(struct rsvd_region *region)
  91. {
  92. region->start = (unsigned long)__va(
  93. (HYPERVISOR_shared_info->arch.start_info_pfn << PAGE_SHIFT));
  94. region->end = region->start + PAGE_SIZE;
  95. return 1;
  96. }
  97. static void __init
  98. xen_arch_setup_early(void)
  99. {
  100. struct shared_info *s;
  101. BUG_ON(!xen_pv_domain());
  102. s = HYPERVISOR_shared_info;
  103. xen_start_info = __va(s->arch.start_info_pfn << PAGE_SHIFT);
  104. /* Must be done before any hypercall. */
  105. xencomm_initialize();
  106. xen_setup_features();
  107. /* Register a call for panic conditions. */
  108. atomic_notifier_chain_register(&panic_notifier_list,
  109. &xen_panic_block);
  110. pm_power_off = xen_pm_power_off;
  111. xen_ia64_enable_opt_feature();
  112. }
  113. static void __init
  114. xen_arch_setup_console(char **cmdline_p)
  115. {
  116. add_preferred_console("xenboot", 0, NULL);
  117. add_preferred_console("tty", 0, NULL);
  118. /* use hvc_xen */
  119. add_preferred_console("hvc", 0, NULL);
  120. #if !defined(CONFIG_VT) || !defined(CONFIG_DUMMY_CONSOLE)
  121. conswitchp = NULL;
  122. #endif
  123. }
  124. static int __init
  125. xen_arch_setup_nomca(void)
  126. {
  127. return 1;
  128. }
  129. static void __init
  130. xen_post_smp_prepare_boot_cpu(void)
  131. {
  132. xen_setup_vcpu_info_placement();
  133. }
  134. static const struct pv_init_ops xen_init_ops __initconst = {
  135. .banner = xen_banner,
  136. .reserve_memory = xen_reserve_memory,
  137. .arch_setup_early = xen_arch_setup_early,
  138. .arch_setup_console = xen_arch_setup_console,
  139. .arch_setup_nomca = xen_arch_setup_nomca,
  140. .post_smp_prepare_boot_cpu = xen_post_smp_prepare_boot_cpu,
  141. };
  142. /***************************************************************************
  143. * pv_fsys_data
  144. * addresses for fsys
  145. */
  146. extern unsigned long xen_fsyscall_table[NR_syscalls];
  147. extern char xen_fsys_bubble_down[];
  148. struct pv_fsys_data xen_fsys_data __initdata = {
  149. .fsyscall_table = (unsigned long *)xen_fsyscall_table,
  150. .fsys_bubble_down = (void *)xen_fsys_bubble_down,
  151. };
  152. /***************************************************************************
  153. * pv_cpu_ops
  154. * intrinsics hooks.
  155. */
  156. static void xen_setreg(int regnum, unsigned long val)
  157. {
  158. switch (regnum) {
  159. case _IA64_REG_AR_KR0 ... _IA64_REG_AR_KR7:
  160. xen_set_kr(regnum - _IA64_REG_AR_KR0, val);
  161. break;
  162. #ifdef CONFIG_IA32_SUPPORT
  163. case _IA64_REG_AR_EFLAG:
  164. xen_set_eflag(val);
  165. break;
  166. #endif
  167. case _IA64_REG_CR_TPR:
  168. xen_set_tpr(val);
  169. break;
  170. case _IA64_REG_CR_ITM:
  171. xen_set_itm(val);
  172. break;
  173. case _IA64_REG_CR_EOI:
  174. xen_eoi(val);
  175. break;
  176. default:
  177. ia64_native_setreg_func(regnum, val);
  178. break;
  179. }
  180. }
  181. static unsigned long xen_getreg(int regnum)
  182. {
  183. unsigned long res;
  184. switch (regnum) {
  185. case _IA64_REG_PSR:
  186. res = xen_get_psr();
  187. break;
  188. #ifdef CONFIG_IA32_SUPPORT
  189. case _IA64_REG_AR_EFLAG:
  190. res = xen_get_eflag();
  191. break;
  192. #endif
  193. case _IA64_REG_CR_IVR:
  194. res = xen_get_ivr();
  195. break;
  196. case _IA64_REG_CR_TPR:
  197. res = xen_get_tpr();
  198. break;
  199. default:
  200. res = ia64_native_getreg_func(regnum);
  201. break;
  202. }
  203. return res;
  204. }
  205. /* turning on interrupts is a bit more complicated.. write to the
  206. * memory-mapped virtual psr.i bit first (to avoid race condition),
  207. * then if any interrupts were pending, we have to execute a hyperprivop
  208. * to ensure the pending interrupt gets delivered; else we're done! */
  209. static void
  210. xen_ssm_i(void)
  211. {
  212. int old = xen_get_virtual_psr_i();
  213. xen_set_virtual_psr_i(1);
  214. barrier();
  215. if (!old && xen_get_virtual_pend())
  216. xen_hyper_ssm_i();
  217. }
  218. /* turning off interrupts can be paravirtualized simply by writing
  219. * to a memory-mapped virtual psr.i bit (implemented as a 16-bit bool) */
  220. static void
  221. xen_rsm_i(void)
  222. {
  223. xen_set_virtual_psr_i(0);
  224. barrier();
  225. }
  226. static unsigned long
  227. xen_get_psr_i(void)
  228. {
  229. return xen_get_virtual_psr_i() ? IA64_PSR_I : 0;
  230. }
  231. static void
  232. xen_intrin_local_irq_restore(unsigned long mask)
  233. {
  234. if (mask & IA64_PSR_I)
  235. xen_ssm_i();
  236. else
  237. xen_rsm_i();
  238. }
  239. static const struct pv_cpu_ops xen_cpu_ops __initconst = {
  240. .fc = xen_fc,
  241. .thash = xen_thash,
  242. .get_cpuid = xen_get_cpuid,
  243. .get_pmd = xen_get_pmd,
  244. .getreg = xen_getreg,
  245. .setreg = xen_setreg,
  246. .ptcga = xen_ptcga,
  247. .get_rr = xen_get_rr,
  248. .set_rr = xen_set_rr,
  249. .set_rr0_to_rr4 = xen_set_rr0_to_rr4,
  250. .ssm_i = xen_ssm_i,
  251. .rsm_i = xen_rsm_i,
  252. .get_psr_i = xen_get_psr_i,
  253. .intrin_local_irq_restore
  254. = xen_intrin_local_irq_restore,
  255. };
  256. /******************************************************************************
  257. * replacement of hand written assembly codes.
  258. */
  259. extern char xen_switch_to;
  260. extern char xen_leave_syscall;
  261. extern char xen_work_processed_syscall;
  262. extern char xen_leave_kernel;
  263. const struct pv_cpu_asm_switch xen_cpu_asm_switch = {
  264. .switch_to = (unsigned long)&xen_switch_to,
  265. .leave_syscall = (unsigned long)&xen_leave_syscall,
  266. .work_processed_syscall = (unsigned long)&xen_work_processed_syscall,
  267. .leave_kernel = (unsigned long)&xen_leave_kernel,
  268. };
  269. /***************************************************************************
  270. * pv_iosapic_ops
  271. * iosapic read/write hooks.
  272. */
  273. static void
  274. xen_pcat_compat_init(void)
  275. {
  276. /* nothing */
  277. }
  278. static struct irq_chip*
  279. xen_iosapic_get_irq_chip(unsigned long trigger)
  280. {
  281. return NULL;
  282. }
  283. static unsigned int
  284. xen_iosapic_read(char __iomem *iosapic, unsigned int reg)
  285. {
  286. struct physdev_apic apic_op;
  287. int ret;
  288. apic_op.apic_physbase = (unsigned long)iosapic -
  289. __IA64_UNCACHED_OFFSET;
  290. apic_op.reg = reg;
  291. ret = HYPERVISOR_physdev_op(PHYSDEVOP_apic_read, &apic_op);
  292. if (ret)
  293. return ret;
  294. return apic_op.value;
  295. }
  296. static void
  297. xen_iosapic_write(char __iomem *iosapic, unsigned int reg, u32 val)
  298. {
  299. struct physdev_apic apic_op;
  300. apic_op.apic_physbase = (unsigned long)iosapic -
  301. __IA64_UNCACHED_OFFSET;
  302. apic_op.reg = reg;
  303. apic_op.value = val;
  304. HYPERVISOR_physdev_op(PHYSDEVOP_apic_write, &apic_op);
  305. }
  306. static const struct pv_iosapic_ops xen_iosapic_ops __initconst = {
  307. .pcat_compat_init = xen_pcat_compat_init,
  308. .__get_irq_chip = xen_iosapic_get_irq_chip,
  309. .__read = xen_iosapic_read,
  310. .__write = xen_iosapic_write,
  311. };
  312. /***************************************************************************
  313. * pv_ops initialization
  314. */
  315. void __init
  316. xen_setup_pv_ops(void)
  317. {
  318. xen_info_init();
  319. pv_info = xen_info;
  320. pv_init_ops = xen_init_ops;
  321. pv_fsys_data = xen_fsys_data;
  322. pv_cpu_ops = xen_cpu_ops;
  323. pv_iosapic_ops = xen_iosapic_ops;
  324. pv_irq_ops = xen_irq_ops;
  325. pv_time_ops = xen_time_ops;
  326. paravirt_cpu_asm_init(&xen_cpu_asm_switch);
  327. }