xen_pv_ops.c 8.5 KB

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