xen_pv_ops.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  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. #ifdef ASM_SUPPORTED
  135. static unsigned long __init_or_module
  136. xen_patch_bundle(void *sbundle, void *ebundle, unsigned long type);
  137. #endif
  138. static void __init
  139. xen_patch_branch(unsigned long tag, unsigned long type);
  140. static const struct pv_init_ops xen_init_ops __initconst = {
  141. .banner = xen_banner,
  142. .reserve_memory = xen_reserve_memory,
  143. .arch_setup_early = xen_arch_setup_early,
  144. .arch_setup_console = xen_arch_setup_console,
  145. .arch_setup_nomca = xen_arch_setup_nomca,
  146. .post_smp_prepare_boot_cpu = xen_post_smp_prepare_boot_cpu,
  147. #ifdef ASM_SUPPORTED
  148. .patch_bundle = xen_patch_bundle,
  149. #endif
  150. .patch_branch = xen_patch_branch,
  151. };
  152. /***************************************************************************
  153. * pv_fsys_data
  154. * addresses for fsys
  155. */
  156. extern unsigned long xen_fsyscall_table[NR_syscalls];
  157. extern char xen_fsys_bubble_down[];
  158. struct pv_fsys_data xen_fsys_data __initdata = {
  159. .fsyscall_table = (unsigned long *)xen_fsyscall_table,
  160. .fsys_bubble_down = (void *)xen_fsys_bubble_down,
  161. };
  162. /***************************************************************************
  163. * pv_patchdata
  164. * patchdata addresses
  165. */
  166. #define DECLARE(name) \
  167. extern unsigned long __xen_start_gate_##name##_patchlist[]; \
  168. extern unsigned long __xen_end_gate_##name##_patchlist[]
  169. DECLARE(fsyscall);
  170. DECLARE(brl_fsys_bubble_down);
  171. DECLARE(vtop);
  172. DECLARE(mckinley_e9);
  173. extern unsigned long __xen_start_gate_section[];
  174. #define ASSIGN(name) \
  175. .start_##name##_patchlist = \
  176. (unsigned long)__xen_start_gate_##name##_patchlist, \
  177. .end_##name##_patchlist = \
  178. (unsigned long)__xen_end_gate_##name##_patchlist
  179. static struct pv_patchdata xen_patchdata __initdata = {
  180. ASSIGN(fsyscall),
  181. ASSIGN(brl_fsys_bubble_down),
  182. ASSIGN(vtop),
  183. ASSIGN(mckinley_e9),
  184. .gate_section = (void*)__xen_start_gate_section,
  185. };
  186. /***************************************************************************
  187. * pv_cpu_ops
  188. * intrinsics hooks.
  189. */
  190. #ifndef ASM_SUPPORTED
  191. static void
  192. xen_set_itm_with_offset(unsigned long val)
  193. {
  194. /* ia64_cpu_local_tick() calls this with interrupt enabled. */
  195. /* WARN_ON(!irqs_disabled()); */
  196. xen_set_itm(val - XEN_MAPPEDREGS->itc_offset);
  197. }
  198. static unsigned long
  199. xen_get_itm_with_offset(void)
  200. {
  201. /* unused at this moment */
  202. printk(KERN_DEBUG "%s is called.\n", __func__);
  203. WARN_ON(!irqs_disabled());
  204. return ia64_native_getreg(_IA64_REG_CR_ITM) +
  205. XEN_MAPPEDREGS->itc_offset;
  206. }
  207. /* ia64_set_itc() is only called by
  208. * cpu_init() with ia64_set_itc(0) and ia64_sync_itc().
  209. * So XEN_MAPPEDRESG->itc_offset cal be considered as almost constant.
  210. */
  211. static void
  212. xen_set_itc(unsigned long val)
  213. {
  214. unsigned long mitc;
  215. WARN_ON(!irqs_disabled());
  216. mitc = ia64_native_getreg(_IA64_REG_AR_ITC);
  217. XEN_MAPPEDREGS->itc_offset = val - mitc;
  218. XEN_MAPPEDREGS->itc_last = val;
  219. }
  220. static unsigned long
  221. xen_get_itc(void)
  222. {
  223. unsigned long res;
  224. unsigned long itc_offset;
  225. unsigned long itc_last;
  226. unsigned long ret_itc_last;
  227. itc_offset = XEN_MAPPEDREGS->itc_offset;
  228. do {
  229. itc_last = XEN_MAPPEDREGS->itc_last;
  230. res = ia64_native_getreg(_IA64_REG_AR_ITC);
  231. res += itc_offset;
  232. if (itc_last >= res)
  233. res = itc_last + 1;
  234. ret_itc_last = cmpxchg(&XEN_MAPPEDREGS->itc_last,
  235. itc_last, res);
  236. } while (unlikely(ret_itc_last != itc_last));
  237. return res;
  238. #if 0
  239. /* ia64_itc_udelay() calls ia64_get_itc() with interrupt enabled.
  240. Should it be paravirtualized instead? */
  241. WARN_ON(!irqs_disabled());
  242. itc_offset = XEN_MAPPEDREGS->itc_offset;
  243. itc_last = XEN_MAPPEDREGS->itc_last;
  244. res = ia64_native_getreg(_IA64_REG_AR_ITC);
  245. res += itc_offset;
  246. if (itc_last >= res)
  247. res = itc_last + 1;
  248. XEN_MAPPEDREGS->itc_last = res;
  249. return res;
  250. #endif
  251. }
  252. static void xen_setreg(int regnum, unsigned long val)
  253. {
  254. switch (regnum) {
  255. case _IA64_REG_AR_KR0 ... _IA64_REG_AR_KR7:
  256. xen_set_kr(regnum - _IA64_REG_AR_KR0, val);
  257. break;
  258. #ifdef CONFIG_IA32_SUPPORT
  259. case _IA64_REG_AR_EFLAG:
  260. xen_set_eflag(val);
  261. break;
  262. #endif
  263. case _IA64_REG_AR_ITC:
  264. xen_set_itc(val);
  265. break;
  266. case _IA64_REG_CR_TPR:
  267. xen_set_tpr(val);
  268. break;
  269. case _IA64_REG_CR_ITM:
  270. xen_set_itm_with_offset(val);
  271. break;
  272. case _IA64_REG_CR_EOI:
  273. xen_eoi(val);
  274. break;
  275. default:
  276. ia64_native_setreg_func(regnum, val);
  277. break;
  278. }
  279. }
  280. static unsigned long xen_getreg(int regnum)
  281. {
  282. unsigned long res;
  283. switch (regnum) {
  284. case _IA64_REG_PSR:
  285. res = xen_get_psr();
  286. break;
  287. #ifdef CONFIG_IA32_SUPPORT
  288. case _IA64_REG_AR_EFLAG:
  289. res = xen_get_eflag();
  290. break;
  291. #endif
  292. case _IA64_REG_AR_ITC:
  293. res = xen_get_itc();
  294. break;
  295. case _IA64_REG_CR_ITM:
  296. res = xen_get_itm_with_offset();
  297. break;
  298. case _IA64_REG_CR_IVR:
  299. res = xen_get_ivr();
  300. break;
  301. case _IA64_REG_CR_TPR:
  302. res = xen_get_tpr();
  303. break;
  304. default:
  305. res = ia64_native_getreg_func(regnum);
  306. break;
  307. }
  308. return res;
  309. }
  310. /* turning on interrupts is a bit more complicated.. write to the
  311. * memory-mapped virtual psr.i bit first (to avoid race condition),
  312. * then if any interrupts were pending, we have to execute a hyperprivop
  313. * to ensure the pending interrupt gets delivered; else we're done! */
  314. static void
  315. xen_ssm_i(void)
  316. {
  317. int old = xen_get_virtual_psr_i();
  318. xen_set_virtual_psr_i(1);
  319. barrier();
  320. if (!old && xen_get_virtual_pend())
  321. xen_hyper_ssm_i();
  322. }
  323. /* turning off interrupts can be paravirtualized simply by writing
  324. * to a memory-mapped virtual psr.i bit (implemented as a 16-bit bool) */
  325. static void
  326. xen_rsm_i(void)
  327. {
  328. xen_set_virtual_psr_i(0);
  329. barrier();
  330. }
  331. static unsigned long
  332. xen_get_psr_i(void)
  333. {
  334. return xen_get_virtual_psr_i() ? IA64_PSR_I : 0;
  335. }
  336. static void
  337. xen_intrin_local_irq_restore(unsigned long mask)
  338. {
  339. if (mask & IA64_PSR_I)
  340. xen_ssm_i();
  341. else
  342. xen_rsm_i();
  343. }
  344. #else
  345. #define __DEFINE_FUNC(name, code) \
  346. extern const char xen_ ## name ## _direct_start[]; \
  347. extern const char xen_ ## name ## _direct_end[]; \
  348. asm (".align 32\n" \
  349. ".proc xen_" #name "\n" \
  350. "xen_" #name ":\n" \
  351. "xen_" #name "_direct_start:\n" \
  352. code \
  353. "xen_" #name "_direct_end:\n" \
  354. "br.cond.sptk.many b6\n" \
  355. ".endp xen_" #name "\n")
  356. #define DEFINE_VOID_FUNC0(name, code) \
  357. extern void \
  358. xen_ ## name (void); \
  359. __DEFINE_FUNC(name, code)
  360. #define DEFINE_VOID_FUNC1(name, code) \
  361. extern void \
  362. xen_ ## name (unsigned long arg); \
  363. __DEFINE_FUNC(name, code)
  364. #define DEFINE_VOID_FUNC2(name, code) \
  365. extern void \
  366. xen_ ## name (unsigned long arg0, \
  367. unsigned long arg1); \
  368. __DEFINE_FUNC(name, code)
  369. #define DEFINE_FUNC0(name, code) \
  370. extern unsigned long \
  371. xen_ ## name (void); \
  372. __DEFINE_FUNC(name, code)
  373. #define DEFINE_FUNC1(name, type, code) \
  374. extern unsigned long \
  375. xen_ ## name (type arg); \
  376. __DEFINE_FUNC(name, code)
  377. #define XEN_PSR_I_ADDR_ADDR (XSI_BASE + XSI_PSR_I_ADDR_OFS)
  378. /*
  379. * static void xen_set_itm_with_offset(unsigned long val)
  380. * xen_set_itm(val - XEN_MAPPEDREGS->itc_offset);
  381. */
  382. /* 2 bundles */
  383. DEFINE_VOID_FUNC1(set_itm_with_offset,
  384. "mov r2 = " __stringify(XSI_BASE) " + "
  385. __stringify(XSI_ITC_OFFSET_OFS) "\n"
  386. ";;\n"
  387. "ld8 r3 = [r2]\n"
  388. ";;\n"
  389. "sub r8 = r8, r3\n"
  390. "break " __stringify(HYPERPRIVOP_SET_ITM) "\n");
  391. /*
  392. * static unsigned long xen_get_itm_with_offset(void)
  393. * return ia64_native_getreg(_IA64_REG_CR_ITM) + XEN_MAPPEDREGS->itc_offset;
  394. */
  395. /* 2 bundles */
  396. DEFINE_FUNC0(get_itm_with_offset,
  397. "mov r2 = " __stringify(XSI_BASE) " + "
  398. __stringify(XSI_ITC_OFFSET_OFS) "\n"
  399. ";;\n"
  400. "ld8 r3 = [r2]\n"
  401. "mov r8 = cr.itm\n"
  402. ";;\n"
  403. "add r8 = r8, r2\n");
  404. /*
  405. * static void xen_set_itc(unsigned long val)
  406. * unsigned long mitc;
  407. *
  408. * WARN_ON(!irqs_disabled());
  409. * mitc = ia64_native_getreg(_IA64_REG_AR_ITC);
  410. * XEN_MAPPEDREGS->itc_offset = val - mitc;
  411. * XEN_MAPPEDREGS->itc_last = val;
  412. */
  413. /* 2 bundles */
  414. DEFINE_VOID_FUNC1(set_itc,
  415. "mov r2 = " __stringify(XSI_BASE) " + "
  416. __stringify(XSI_ITC_LAST_OFS) "\n"
  417. "mov r3 = ar.itc\n"
  418. ";;\n"
  419. "sub r3 = r8, r3\n"
  420. "st8 [r2] = r8, "
  421. __stringify(XSI_ITC_LAST_OFS) " - "
  422. __stringify(XSI_ITC_OFFSET_OFS) "\n"
  423. ";;\n"
  424. "st8 [r2] = r3\n");
  425. /*
  426. * static unsigned long xen_get_itc(void)
  427. * unsigned long res;
  428. * unsigned long itc_offset;
  429. * unsigned long itc_last;
  430. * unsigned long ret_itc_last;
  431. *
  432. * itc_offset = XEN_MAPPEDREGS->itc_offset;
  433. * do {
  434. * itc_last = XEN_MAPPEDREGS->itc_last;
  435. * res = ia64_native_getreg(_IA64_REG_AR_ITC);
  436. * res += itc_offset;
  437. * if (itc_last >= res)
  438. * res = itc_last + 1;
  439. * ret_itc_last = cmpxchg(&XEN_MAPPEDREGS->itc_last,
  440. * itc_last, res);
  441. * } while (unlikely(ret_itc_last != itc_last));
  442. * return res;
  443. */
  444. /* 5 bundles */
  445. DEFINE_FUNC0(get_itc,
  446. "mov r2 = " __stringify(XSI_BASE) " + "
  447. __stringify(XSI_ITC_OFFSET_OFS) "\n"
  448. ";;\n"
  449. "ld8 r9 = [r2], " __stringify(XSI_ITC_LAST_OFS) " - "
  450. __stringify(XSI_ITC_OFFSET_OFS) "\n"
  451. /* r9 = itc_offset */
  452. /* r2 = XSI_ITC_OFFSET */
  453. "888:\n"
  454. "mov r8 = ar.itc\n" /* res = ar.itc */
  455. ";;\n"
  456. "ld8 r3 = [r2]\n" /* r3 = itc_last */
  457. "add r8 = r8, r9\n" /* res = ar.itc + itc_offset */
  458. ";;\n"
  459. "cmp.gtu p6, p0 = r3, r8\n"
  460. ";;\n"
  461. "(p6) add r8 = 1, r3\n" /* if (itc_last > res) itc_last + 1 */
  462. ";;\n"
  463. "mov ar.ccv = r8\n"
  464. ";;\n"
  465. "cmpxchg8.acq r10 = [r2], r8, ar.ccv\n"
  466. ";;\n"
  467. "cmp.ne p6, p0 = r10, r3\n"
  468. "(p6) hint @pause\n"
  469. "(p6) br.cond.spnt 888b\n");
  470. DEFINE_VOID_FUNC1(fc,
  471. "break " __stringify(HYPERPRIVOP_FC) "\n");
  472. /*
  473. * psr_i_addr_addr = XEN_PSR_I_ADDR_ADDR
  474. * masked_addr = *psr_i_addr_addr
  475. * pending_intr_addr = masked_addr - 1
  476. * if (val & IA64_PSR_I) {
  477. * masked = *masked_addr
  478. * *masked_addr = 0:xen_set_virtual_psr_i(1)
  479. * compiler barrier
  480. * if (masked) {
  481. * uint8_t pending = *pending_intr_addr;
  482. * if (pending)
  483. * XEN_HYPER_SSM_I
  484. * }
  485. * } else {
  486. * *masked_addr = 1:xen_set_virtual_psr_i(0)
  487. * }
  488. */
  489. /* 6 bundles */
  490. DEFINE_VOID_FUNC1(intrin_local_irq_restore,
  491. /* r8 = input value: 0 or IA64_PSR_I
  492. * p6 = (flags & IA64_PSR_I)
  493. * = if clause
  494. * p7 = !(flags & IA64_PSR_I)
  495. * = else clause
  496. */
  497. "cmp.ne p6, p7 = r8, r0\n"
  498. "mov r9 = " __stringify(XEN_PSR_I_ADDR_ADDR) "\n"
  499. ";;\n"
  500. /* r9 = XEN_PSR_I_ADDR */
  501. "ld8 r9 = [r9]\n"
  502. ";;\n"
  503. /* r10 = masked previous value */
  504. "(p6) ld1.acq r10 = [r9]\n"
  505. ";;\n"
  506. /* p8 = !masked interrupt masked previously? */
  507. "(p6) cmp.ne.unc p8, p0 = r10, r0\n"
  508. /* p7 = else clause */
  509. "(p7) mov r11 = 1\n"
  510. ";;\n"
  511. /* masked = 1 */
  512. "(p7) st1.rel [r9] = r11\n"
  513. /* p6 = if clause */
  514. /* masked = 0
  515. * r9 = masked_addr - 1
  516. * = pending_intr_addr
  517. */
  518. "(p8) st1.rel [r9] = r0, -1\n"
  519. ";;\n"
  520. /* r8 = pending_intr */
  521. "(p8) ld1.acq r11 = [r9]\n"
  522. ";;\n"
  523. /* p9 = interrupt pending? */
  524. "(p8) cmp.ne.unc p9, p10 = r11, r0\n"
  525. ";;\n"
  526. "(p10) mf\n"
  527. /* issue hypercall to trigger interrupt */
  528. "(p9) break " __stringify(HYPERPRIVOP_SSM_I) "\n");
  529. DEFINE_VOID_FUNC2(ptcga,
  530. "break " __stringify(HYPERPRIVOP_PTC_GA) "\n");
  531. DEFINE_VOID_FUNC2(set_rr,
  532. "break " __stringify(HYPERPRIVOP_SET_RR) "\n");
  533. /*
  534. * tmp = XEN_MAPPEDREGS->interrupt_mask_addr = XEN_PSR_I_ADDR_ADDR;
  535. * tmp = *tmp
  536. * tmp = *tmp;
  537. * psr_i = tmp? 0: IA64_PSR_I;
  538. */
  539. /* 4 bundles */
  540. DEFINE_FUNC0(get_psr_i,
  541. "mov r9 = " __stringify(XEN_PSR_I_ADDR_ADDR) "\n"
  542. ";;\n"
  543. "ld8 r9 = [r9]\n" /* r9 = XEN_PSR_I_ADDR */
  544. "mov r8 = 0\n" /* psr_i = 0 */
  545. ";;\n"
  546. "ld1.acq r9 = [r9]\n" /* r9 = XEN_PSR_I */
  547. ";;\n"
  548. "cmp.eq.unc p6, p0 = r9, r0\n" /* p6 = (XEN_PSR_I != 0) */
  549. ";;\n"
  550. "(p6) mov r8 = " __stringify(1 << IA64_PSR_I_BIT) "\n");
  551. DEFINE_FUNC1(thash, unsigned long,
  552. "break " __stringify(HYPERPRIVOP_THASH) "\n");
  553. DEFINE_FUNC1(get_cpuid, int,
  554. "break " __stringify(HYPERPRIVOP_GET_CPUID) "\n");
  555. DEFINE_FUNC1(get_pmd, int,
  556. "break " __stringify(HYPERPRIVOP_GET_PMD) "\n");
  557. DEFINE_FUNC1(get_rr, unsigned long,
  558. "break " __stringify(HYPERPRIVOP_GET_RR) "\n");
  559. /*
  560. * void xen_privop_ssm_i(void)
  561. *
  562. * int masked = !xen_get_virtual_psr_i();
  563. * // masked = *(*XEN_MAPPEDREGS->interrupt_mask_addr)
  564. * xen_set_virtual_psr_i(1)
  565. * // *(*XEN_MAPPEDREGS->interrupt_mask_addr) = 0
  566. * // compiler barrier
  567. * if (masked) {
  568. * uint8_t* pend_int_addr =
  569. * (uint8_t*)(*XEN_MAPPEDREGS->interrupt_mask_addr) - 1;
  570. * uint8_t pending = *pend_int_addr;
  571. * if (pending)
  572. * XEN_HYPER_SSM_I
  573. * }
  574. */
  575. /* 4 bundles */
  576. DEFINE_VOID_FUNC0(ssm_i,
  577. "mov r8 = " __stringify(XEN_PSR_I_ADDR_ADDR) "\n"
  578. ";;\n"
  579. "ld8 r8 = [r8]\n" /* r8 = XEN_PSR_I_ADDR */
  580. ";;\n"
  581. "ld1.acq r9 = [r8]\n" /* r9 = XEN_PSR_I */
  582. ";;\n"
  583. "st1.rel [r8] = r0, -1\n" /* psr_i = 0. enable interrupt
  584. * r8 = XEN_PSR_I_ADDR - 1
  585. * = pend_int_addr
  586. */
  587. "cmp.eq.unc p0, p6 = r9, r0\n"/* p6 = !XEN_PSR_I
  588. * previously interrupt
  589. * masked?
  590. */
  591. ";;\n"
  592. "(p6) ld1.acq r8 = [r8]\n" /* r8 = xen_pend_int */
  593. ";;\n"
  594. "(p6) cmp.eq.unc p6, p7 = r8, r0\n" /*interrupt pending?*/
  595. ";;\n"
  596. /* issue hypercall to get interrupt */
  597. "(p7) break " __stringify(HYPERPRIVOP_SSM_I) "\n"
  598. ";;\n");
  599. /*
  600. * psr_i_addr_addr = XEN_MAPPEDREGS->interrupt_mask_addr
  601. * = XEN_PSR_I_ADDR_ADDR;
  602. * psr_i_addr = *psr_i_addr_addr;
  603. * *psr_i_addr = 1;
  604. */
  605. /* 2 bundles */
  606. DEFINE_VOID_FUNC0(rsm_i,
  607. "mov r8 = " __stringify(XEN_PSR_I_ADDR_ADDR) "\n"
  608. /* r8 = XEN_PSR_I_ADDR */
  609. "mov r9 = 1\n"
  610. ";;\n"
  611. "ld8 r8 = [r8]\n" /* r8 = XEN_PSR_I */
  612. ";;\n"
  613. "st1.rel [r8] = r9\n"); /* XEN_PSR_I = 1 */
  614. extern void
  615. xen_set_rr0_to_rr4(unsigned long val0, unsigned long val1,
  616. unsigned long val2, unsigned long val3,
  617. unsigned long val4);
  618. __DEFINE_FUNC(set_rr0_to_rr4,
  619. "break " __stringify(HYPERPRIVOP_SET_RR0_TO_RR4) "\n");
  620. extern unsigned long xen_getreg(int regnum);
  621. #define __DEFINE_GET_REG(id, privop) \
  622. "mov r2 = " __stringify(_IA64_REG_ ## id) "\n" \
  623. ";;\n" \
  624. "cmp.eq p6, p0 = r2, r8\n" \
  625. ";;\n" \
  626. "(p6) break " __stringify(HYPERPRIVOP_GET_ ## privop) "\n" \
  627. "(p6) br.cond.sptk.many b6\n" \
  628. ";;\n"
  629. __DEFINE_FUNC(getreg,
  630. __DEFINE_GET_REG(PSR, PSR)
  631. #ifdef CONFIG_IA32_SUPPORT
  632. __DEFINE_GET_REG(AR_EFLAG, EFLAG)
  633. #endif
  634. /* get_itc */
  635. "mov r2 = " __stringify(_IA64_REG_AR_ITC) "\n"
  636. ";;\n"
  637. "cmp.eq p6, p0 = r2, r8\n"
  638. ";;\n"
  639. "(p6) br.cond.spnt xen_get_itc\n"
  640. ";;\n"
  641. /* get itm */
  642. "mov r2 = " __stringify(_IA64_REG_CR_ITM) "\n"
  643. ";;\n"
  644. "cmp.eq p6, p0 = r2, r8\n"
  645. ";;\n"
  646. "(p6) br.cond.spnt xen_get_itm_with_offset\n"
  647. ";;\n"
  648. __DEFINE_GET_REG(CR_IVR, IVR)
  649. __DEFINE_GET_REG(CR_TPR, TPR)
  650. /* fall back */
  651. "movl r2 = ia64_native_getreg_func\n"
  652. ";;\n"
  653. "mov b7 = r2\n"
  654. ";;\n"
  655. "br.cond.sptk.many b7\n");
  656. extern void xen_setreg(int regnum, unsigned long val);
  657. #define __DEFINE_SET_REG(id, privop) \
  658. "mov r2 = " __stringify(_IA64_REG_ ## id) "\n" \
  659. ";;\n" \
  660. "cmp.eq p6, p0 = r2, r9\n" \
  661. ";;\n" \
  662. "(p6) break " __stringify(HYPERPRIVOP_ ## privop) "\n" \
  663. "(p6) br.cond.sptk.many b6\n" \
  664. ";;\n"
  665. __DEFINE_FUNC(setreg,
  666. /* kr0 .. kr 7*/
  667. /*
  668. * if (_IA64_REG_AR_KR0 <= regnum &&
  669. * regnum <= _IA64_REG_AR_KR7) {
  670. * register __index asm ("r8") = regnum - _IA64_REG_AR_KR0
  671. * register __val asm ("r9") = val
  672. * "break HYPERPRIVOP_SET_KR"
  673. * }
  674. */
  675. "mov r17 = r9\n"
  676. "mov r2 = " __stringify(_IA64_REG_AR_KR0) "\n"
  677. ";;\n"
  678. "cmp.ge p6, p0 = r9, r2\n"
  679. "sub r17 = r17, r2\n"
  680. ";;\n"
  681. "(p6) cmp.ge.unc p7, p0 = "
  682. __stringify(_IA64_REG_AR_KR7) " - " __stringify(_IA64_REG_AR_KR0)
  683. ", r17\n"
  684. ";;\n"
  685. "(p7) mov r9 = r8\n"
  686. ";;\n"
  687. "(p7) mov r8 = r17\n"
  688. "(p7) break " __stringify(HYPERPRIVOP_SET_KR) "\n"
  689. /* set itm */
  690. "mov r2 = " __stringify(_IA64_REG_CR_ITM) "\n"
  691. ";;\n"
  692. "cmp.eq p6, p0 = r2, r8\n"
  693. ";;\n"
  694. "(p6) br.cond.spnt xen_set_itm_with_offset\n"
  695. /* set itc */
  696. "mov r2 = " __stringify(_IA64_REG_AR_ITC) "\n"
  697. ";;\n"
  698. "cmp.eq p6, p0 = r2, r8\n"
  699. ";;\n"
  700. "(p6) br.cond.spnt xen_set_itc\n"
  701. #ifdef CONFIG_IA32_SUPPORT
  702. __DEFINE_SET_REG(AR_EFLAG, SET_EFLAG)
  703. #endif
  704. __DEFINE_SET_REG(CR_TPR, SET_TPR)
  705. __DEFINE_SET_REG(CR_EOI, EOI)
  706. /* fall back */
  707. "movl r2 = ia64_native_setreg_func\n"
  708. ";;\n"
  709. "mov b7 = r2\n"
  710. ";;\n"
  711. "br.cond.sptk.many b7\n");
  712. #endif
  713. static const struct pv_cpu_ops xen_cpu_ops __initconst = {
  714. .fc = xen_fc,
  715. .thash = xen_thash,
  716. .get_cpuid = xen_get_cpuid,
  717. .get_pmd = xen_get_pmd,
  718. .getreg = xen_getreg,
  719. .setreg = xen_setreg,
  720. .ptcga = xen_ptcga,
  721. .get_rr = xen_get_rr,
  722. .set_rr = xen_set_rr,
  723. .set_rr0_to_rr4 = xen_set_rr0_to_rr4,
  724. .ssm_i = xen_ssm_i,
  725. .rsm_i = xen_rsm_i,
  726. .get_psr_i = xen_get_psr_i,
  727. .intrin_local_irq_restore
  728. = xen_intrin_local_irq_restore,
  729. };
  730. /******************************************************************************
  731. * replacement of hand written assembly codes.
  732. */
  733. extern char xen_switch_to;
  734. extern char xen_leave_syscall;
  735. extern char xen_work_processed_syscall;
  736. extern char xen_leave_kernel;
  737. const struct pv_cpu_asm_switch xen_cpu_asm_switch = {
  738. .switch_to = (unsigned long)&xen_switch_to,
  739. .leave_syscall = (unsigned long)&xen_leave_syscall,
  740. .work_processed_syscall = (unsigned long)&xen_work_processed_syscall,
  741. .leave_kernel = (unsigned long)&xen_leave_kernel,
  742. };
  743. /***************************************************************************
  744. * pv_iosapic_ops
  745. * iosapic read/write hooks.
  746. */
  747. static void
  748. xen_pcat_compat_init(void)
  749. {
  750. /* nothing */
  751. }
  752. static struct irq_chip*
  753. xen_iosapic_get_irq_chip(unsigned long trigger)
  754. {
  755. return NULL;
  756. }
  757. static unsigned int
  758. xen_iosapic_read(char __iomem *iosapic, unsigned int reg)
  759. {
  760. struct physdev_apic apic_op;
  761. int ret;
  762. apic_op.apic_physbase = (unsigned long)iosapic -
  763. __IA64_UNCACHED_OFFSET;
  764. apic_op.reg = reg;
  765. ret = HYPERVISOR_physdev_op(PHYSDEVOP_apic_read, &apic_op);
  766. if (ret)
  767. return ret;
  768. return apic_op.value;
  769. }
  770. static void
  771. xen_iosapic_write(char __iomem *iosapic, unsigned int reg, u32 val)
  772. {
  773. struct physdev_apic apic_op;
  774. apic_op.apic_physbase = (unsigned long)iosapic -
  775. __IA64_UNCACHED_OFFSET;
  776. apic_op.reg = reg;
  777. apic_op.value = val;
  778. HYPERVISOR_physdev_op(PHYSDEVOP_apic_write, &apic_op);
  779. }
  780. static struct pv_iosapic_ops xen_iosapic_ops __initdata = {
  781. .pcat_compat_init = xen_pcat_compat_init,
  782. .__get_irq_chip = xen_iosapic_get_irq_chip,
  783. .__read = xen_iosapic_read,
  784. .__write = xen_iosapic_write,
  785. };
  786. /***************************************************************************
  787. * pv_ops initialization
  788. */
  789. void __init
  790. xen_setup_pv_ops(void)
  791. {
  792. xen_info_init();
  793. pv_info = xen_info;
  794. pv_init_ops = xen_init_ops;
  795. pv_fsys_data = xen_fsys_data;
  796. pv_patchdata = xen_patchdata;
  797. pv_cpu_ops = xen_cpu_ops;
  798. pv_iosapic_ops = xen_iosapic_ops;
  799. pv_irq_ops = xen_irq_ops;
  800. pv_time_ops = xen_time_ops;
  801. paravirt_cpu_asm_init(&xen_cpu_asm_switch);
  802. }
  803. #ifdef ASM_SUPPORTED
  804. /***************************************************************************
  805. * binary pacthing
  806. * pv_init_ops.patch_bundle
  807. */
  808. #define DEFINE_FUNC_GETREG(name, privop) \
  809. DEFINE_FUNC0(get_ ## name, \
  810. "break "__stringify(HYPERPRIVOP_GET_ ## privop) "\n")
  811. DEFINE_FUNC_GETREG(psr, PSR);
  812. DEFINE_FUNC_GETREG(eflag, EFLAG);
  813. DEFINE_FUNC_GETREG(ivr, IVR);
  814. DEFINE_FUNC_GETREG(tpr, TPR);
  815. #define DEFINE_FUNC_SET_KR(n) \
  816. DEFINE_VOID_FUNC0(set_kr ## n, \
  817. ";;\n" \
  818. "mov r9 = r8\n" \
  819. "mov r8 = " #n "\n" \
  820. "break " __stringify(HYPERPRIVOP_SET_KR) "\n")
  821. DEFINE_FUNC_SET_KR(0);
  822. DEFINE_FUNC_SET_KR(1);
  823. DEFINE_FUNC_SET_KR(2);
  824. DEFINE_FUNC_SET_KR(3);
  825. DEFINE_FUNC_SET_KR(4);
  826. DEFINE_FUNC_SET_KR(5);
  827. DEFINE_FUNC_SET_KR(6);
  828. DEFINE_FUNC_SET_KR(7);
  829. #define __DEFINE_FUNC_SETREG(name, privop) \
  830. DEFINE_VOID_FUNC0(name, \
  831. "break "__stringify(HYPERPRIVOP_ ## privop) "\n")
  832. #define DEFINE_FUNC_SETREG(name, privop) \
  833. __DEFINE_FUNC_SETREG(set_ ## name, SET_ ## privop)
  834. DEFINE_FUNC_SETREG(eflag, EFLAG);
  835. DEFINE_FUNC_SETREG(tpr, TPR);
  836. __DEFINE_FUNC_SETREG(eoi, EOI);
  837. extern const char xen_check_events[];
  838. extern const char __xen_intrin_local_irq_restore_direct_start[];
  839. extern const char __xen_intrin_local_irq_restore_direct_end[];
  840. extern const unsigned long __xen_intrin_local_irq_restore_direct_reloc;
  841. asm (
  842. ".align 32\n"
  843. ".proc xen_check_events\n"
  844. "xen_check_events:\n"
  845. /* masked = 0
  846. * r9 = masked_addr - 1
  847. * = pending_intr_addr
  848. */
  849. "st1.rel [r9] = r0, -1\n"
  850. ";;\n"
  851. /* r8 = pending_intr */
  852. "ld1.acq r11 = [r9]\n"
  853. ";;\n"
  854. /* p9 = interrupt pending? */
  855. "cmp.ne p9, p10 = r11, r0\n"
  856. ";;\n"
  857. "(p10) mf\n"
  858. /* issue hypercall to trigger interrupt */
  859. "(p9) break " __stringify(HYPERPRIVOP_SSM_I) "\n"
  860. "br.cond.sptk.many b6\n"
  861. ".endp xen_check_events\n"
  862. "\n"
  863. ".align 32\n"
  864. ".proc __xen_intrin_local_irq_restore_direct\n"
  865. "__xen_intrin_local_irq_restore_direct:\n"
  866. "__xen_intrin_local_irq_restore_direct_start:\n"
  867. "1:\n"
  868. "{\n"
  869. "cmp.ne p6, p7 = r8, r0\n"
  870. "mov r17 = ip\n" /* get ip to calc return address */
  871. "mov r9 = "__stringify(XEN_PSR_I_ADDR_ADDR) "\n"
  872. ";;\n"
  873. "}\n"
  874. "{\n"
  875. /* r9 = XEN_PSR_I_ADDR */
  876. "ld8 r9 = [r9]\n"
  877. ";;\n"
  878. /* r10 = masked previous value */
  879. "(p6) ld1.acq r10 = [r9]\n"
  880. "adds r17 = 1f - 1b, r17\n" /* calculate return address */
  881. ";;\n"
  882. "}\n"
  883. "{\n"
  884. /* p8 = !masked interrupt masked previously? */
  885. "(p6) cmp.ne.unc p8, p0 = r10, r0\n"
  886. "\n"
  887. /* p7 = else clause */
  888. "(p7) mov r11 = 1\n"
  889. ";;\n"
  890. "(p8) mov b6 = r17\n" /* set return address */
  891. "}\n"
  892. "{\n"
  893. /* masked = 1 */
  894. "(p7) st1.rel [r9] = r11\n"
  895. "\n"
  896. "[99:]\n"
  897. "(p8) brl.cond.dptk.few xen_check_events\n"
  898. "}\n"
  899. /* pv calling stub is 5 bundles. fill nop to adjust return address */
  900. "{\n"
  901. "nop 0\n"
  902. "nop 0\n"
  903. "nop 0\n"
  904. "}\n"
  905. "1:\n"
  906. "__xen_intrin_local_irq_restore_direct_end:\n"
  907. ".endp __xen_intrin_local_irq_restore_direct\n"
  908. "\n"
  909. ".align 8\n"
  910. "__xen_intrin_local_irq_restore_direct_reloc:\n"
  911. "data8 99b\n"
  912. );
  913. static struct paravirt_patch_bundle_elem xen_patch_bundle_elems[]
  914. __initdata_or_module =
  915. {
  916. #define XEN_PATCH_BUNDLE_ELEM(name, type) \
  917. { \
  918. (void*)xen_ ## name ## _direct_start, \
  919. (void*)xen_ ## name ## _direct_end, \
  920. PARAVIRT_PATCH_TYPE_ ## type, \
  921. }
  922. XEN_PATCH_BUNDLE_ELEM(fc, FC),
  923. XEN_PATCH_BUNDLE_ELEM(thash, THASH),
  924. XEN_PATCH_BUNDLE_ELEM(get_cpuid, GET_CPUID),
  925. XEN_PATCH_BUNDLE_ELEM(get_pmd, GET_PMD),
  926. XEN_PATCH_BUNDLE_ELEM(ptcga, PTCGA),
  927. XEN_PATCH_BUNDLE_ELEM(get_rr, GET_RR),
  928. XEN_PATCH_BUNDLE_ELEM(set_rr, SET_RR),
  929. XEN_PATCH_BUNDLE_ELEM(set_rr0_to_rr4, SET_RR0_TO_RR4),
  930. XEN_PATCH_BUNDLE_ELEM(ssm_i, SSM_I),
  931. XEN_PATCH_BUNDLE_ELEM(rsm_i, RSM_I),
  932. XEN_PATCH_BUNDLE_ELEM(get_psr_i, GET_PSR_I),
  933. {
  934. (void*)__xen_intrin_local_irq_restore_direct_start,
  935. (void*)__xen_intrin_local_irq_restore_direct_end,
  936. PARAVIRT_PATCH_TYPE_INTRIN_LOCAL_IRQ_RESTORE,
  937. },
  938. #define XEN_PATCH_BUNDLE_ELEM_GETREG(name, reg) \
  939. { \
  940. xen_get_ ## name ## _direct_start, \
  941. xen_get_ ## name ## _direct_end, \
  942. PARAVIRT_PATCH_TYPE_GETREG + _IA64_REG_ ## reg, \
  943. }
  944. XEN_PATCH_BUNDLE_ELEM_GETREG(psr, PSR),
  945. XEN_PATCH_BUNDLE_ELEM_GETREG(eflag, AR_EFLAG),
  946. XEN_PATCH_BUNDLE_ELEM_GETREG(ivr, CR_IVR),
  947. XEN_PATCH_BUNDLE_ELEM_GETREG(tpr, CR_TPR),
  948. XEN_PATCH_BUNDLE_ELEM_GETREG(itc, AR_ITC),
  949. XEN_PATCH_BUNDLE_ELEM_GETREG(itm_with_offset, CR_ITM),
  950. #define __XEN_PATCH_BUNDLE_ELEM_SETREG(name, reg) \
  951. { \
  952. xen_ ## name ## _direct_start, \
  953. xen_ ## name ## _direct_end, \
  954. PARAVIRT_PATCH_TYPE_SETREG + _IA64_REG_ ## reg, \
  955. }
  956. #define XEN_PATCH_BUNDLE_ELEM_SETREG(name, reg) \
  957. __XEN_PATCH_BUNDLE_ELEM_SETREG(set_ ## name, reg)
  958. XEN_PATCH_BUNDLE_ELEM_SETREG(kr0, AR_KR0),
  959. XEN_PATCH_BUNDLE_ELEM_SETREG(kr1, AR_KR1),
  960. XEN_PATCH_BUNDLE_ELEM_SETREG(kr2, AR_KR2),
  961. XEN_PATCH_BUNDLE_ELEM_SETREG(kr3, AR_KR3),
  962. XEN_PATCH_BUNDLE_ELEM_SETREG(kr4, AR_KR4),
  963. XEN_PATCH_BUNDLE_ELEM_SETREG(kr5, AR_KR5),
  964. XEN_PATCH_BUNDLE_ELEM_SETREG(kr6, AR_KR6),
  965. XEN_PATCH_BUNDLE_ELEM_SETREG(kr7, AR_KR7),
  966. XEN_PATCH_BUNDLE_ELEM_SETREG(eflag, AR_EFLAG),
  967. XEN_PATCH_BUNDLE_ELEM_SETREG(tpr, CR_TPR),
  968. __XEN_PATCH_BUNDLE_ELEM_SETREG(eoi, CR_EOI),
  969. XEN_PATCH_BUNDLE_ELEM_SETREG(itc, AR_ITC),
  970. XEN_PATCH_BUNDLE_ELEM_SETREG(itm_with_offset, CR_ITM),
  971. };
  972. static unsigned long __init_or_module
  973. xen_patch_bundle(void *sbundle, void *ebundle, unsigned long type)
  974. {
  975. const unsigned long nelems = sizeof(xen_patch_bundle_elems) /
  976. sizeof(xen_patch_bundle_elems[0]);
  977. unsigned long used;
  978. const struct paravirt_patch_bundle_elem *found;
  979. used = __paravirt_patch_apply_bundle(sbundle, ebundle, type,
  980. xen_patch_bundle_elems, nelems,
  981. &found);
  982. if (found == NULL)
  983. /* fallback */
  984. return ia64_native_patch_bundle(sbundle, ebundle, type);
  985. if (used == 0)
  986. return used;
  987. /* relocation */
  988. switch (type) {
  989. case PARAVIRT_PATCH_TYPE_INTRIN_LOCAL_IRQ_RESTORE: {
  990. unsigned long reloc =
  991. __xen_intrin_local_irq_restore_direct_reloc;
  992. unsigned long reloc_offset = reloc - (unsigned long)
  993. __xen_intrin_local_irq_restore_direct_start;
  994. unsigned long tag = (unsigned long)sbundle + reloc_offset;
  995. paravirt_patch_reloc_brl(tag, xen_check_events);
  996. break;
  997. }
  998. default:
  999. /* nothing */
  1000. break;
  1001. }
  1002. return used;
  1003. }
  1004. #endif /* ASM_SUPPOTED */
  1005. const struct paravirt_patch_branch_target xen_branch_target[]
  1006. __initconst = {
  1007. #define PARAVIRT_BR_TARGET(name, type) \
  1008. { \
  1009. &xen_ ## name, \
  1010. PARAVIRT_PATCH_TYPE_BR_ ## type, \
  1011. }
  1012. PARAVIRT_BR_TARGET(switch_to, SWITCH_TO),
  1013. PARAVIRT_BR_TARGET(leave_syscall, LEAVE_SYSCALL),
  1014. PARAVIRT_BR_TARGET(work_processed_syscall, WORK_PROCESSED_SYSCALL),
  1015. PARAVIRT_BR_TARGET(leave_kernel, LEAVE_KERNEL),
  1016. };
  1017. static void __init
  1018. xen_patch_branch(unsigned long tag, unsigned long type)
  1019. {
  1020. const unsigned long nelem =
  1021. sizeof(xen_branch_target) / sizeof(xen_branch_target[0]);
  1022. __paravirt_patch_apply_branch(tag, type, xen_branch_target, nelem);
  1023. }