paravirt.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /******************************************************************************
  2. * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
  3. * VA Linux Systems Japan K.K.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. #ifndef __ASM_PARAVIRT_H
  21. #define __ASM_PARAVIRT_H
  22. #ifdef CONFIG_PARAVIRT_GUEST
  23. #define PARAVIRT_HYPERVISOR_TYPE_DEFAULT 0
  24. #define PARAVIRT_HYPERVISOR_TYPE_XEN 1
  25. #ifndef __ASSEMBLY__
  26. #include <asm/hw_irq.h>
  27. #include <asm/meminit.h>
  28. /******************************************************************************
  29. * general info
  30. */
  31. struct pv_info {
  32. unsigned int kernel_rpl;
  33. int paravirt_enabled;
  34. const char *name;
  35. };
  36. extern struct pv_info pv_info;
  37. static inline int paravirt_enabled(void)
  38. {
  39. return pv_info.paravirt_enabled;
  40. }
  41. static inline unsigned int get_kernel_rpl(void)
  42. {
  43. return pv_info.kernel_rpl;
  44. }
  45. /******************************************************************************
  46. * initialization hooks.
  47. */
  48. struct rsvd_region;
  49. struct pv_init_ops {
  50. void (*banner)(void);
  51. int (*reserve_memory)(struct rsvd_region *region);
  52. void (*arch_setup_early)(void);
  53. void (*arch_setup_console)(char **cmdline_p);
  54. int (*arch_setup_nomca)(void);
  55. void (*post_smp_prepare_boot_cpu)(void);
  56. };
  57. extern struct pv_init_ops pv_init_ops;
  58. static inline void paravirt_banner(void)
  59. {
  60. if (pv_init_ops.banner)
  61. pv_init_ops.banner();
  62. }
  63. static inline int paravirt_reserve_memory(struct rsvd_region *region)
  64. {
  65. if (pv_init_ops.reserve_memory)
  66. return pv_init_ops.reserve_memory(region);
  67. return 0;
  68. }
  69. static inline void paravirt_arch_setup_early(void)
  70. {
  71. if (pv_init_ops.arch_setup_early)
  72. pv_init_ops.arch_setup_early();
  73. }
  74. static inline void paravirt_arch_setup_console(char **cmdline_p)
  75. {
  76. if (pv_init_ops.arch_setup_console)
  77. pv_init_ops.arch_setup_console(cmdline_p);
  78. }
  79. static inline int paravirt_arch_setup_nomca(void)
  80. {
  81. if (pv_init_ops.arch_setup_nomca)
  82. return pv_init_ops.arch_setup_nomca();
  83. return 0;
  84. }
  85. static inline void paravirt_post_smp_prepare_boot_cpu(void)
  86. {
  87. if (pv_init_ops.post_smp_prepare_boot_cpu)
  88. pv_init_ops.post_smp_prepare_boot_cpu();
  89. }
  90. /******************************************************************************
  91. * replacement of iosapic operations.
  92. */
  93. struct pv_iosapic_ops {
  94. void (*pcat_compat_init)(void);
  95. struct irq_chip *(*get_irq_chip)(unsigned long trigger);
  96. unsigned int (*__read)(char __iomem *iosapic, unsigned int reg);
  97. void (*__write)(char __iomem *iosapic, unsigned int reg, u32 val);
  98. };
  99. extern struct pv_iosapic_ops pv_iosapic_ops;
  100. static inline void
  101. iosapic_pcat_compat_init(void)
  102. {
  103. if (pv_iosapic_ops.pcat_compat_init)
  104. pv_iosapic_ops.pcat_compat_init();
  105. }
  106. static inline struct irq_chip*
  107. iosapic_get_irq_chip(unsigned long trigger)
  108. {
  109. return pv_iosapic_ops.get_irq_chip(trigger);
  110. }
  111. static inline unsigned int
  112. __iosapic_read(char __iomem *iosapic, unsigned int reg)
  113. {
  114. return pv_iosapic_ops.__read(iosapic, reg);
  115. }
  116. static inline void
  117. __iosapic_write(char __iomem *iosapic, unsigned int reg, u32 val)
  118. {
  119. return pv_iosapic_ops.__write(iosapic, reg, val);
  120. }
  121. /******************************************************************************
  122. * replacement of irq operations.
  123. */
  124. struct pv_irq_ops {
  125. void (*register_ipi)(void);
  126. int (*assign_irq_vector)(int irq);
  127. void (*free_irq_vector)(int vector);
  128. void (*register_percpu_irq)(ia64_vector vec,
  129. struct irqaction *action);
  130. void (*resend_irq)(unsigned int vector);
  131. };
  132. extern struct pv_irq_ops pv_irq_ops;
  133. static inline void
  134. ia64_register_ipi(void)
  135. {
  136. pv_irq_ops.register_ipi();
  137. }
  138. static inline int
  139. assign_irq_vector(int irq)
  140. {
  141. return pv_irq_ops.assign_irq_vector(irq);
  142. }
  143. static inline void
  144. free_irq_vector(int vector)
  145. {
  146. return pv_irq_ops.free_irq_vector(vector);
  147. }
  148. static inline void
  149. register_percpu_irq(ia64_vector vec, struct irqaction *action)
  150. {
  151. pv_irq_ops.register_percpu_irq(vec, action);
  152. }
  153. static inline void
  154. ia64_resend_irq(unsigned int vector)
  155. {
  156. pv_irq_ops.resend_irq(vector);
  157. }
  158. /******************************************************************************
  159. * replacement of time operations.
  160. */
  161. extern struct itc_jitter_data_t itc_jitter_data;
  162. extern volatile int time_keeper_id;
  163. struct pv_time_ops {
  164. void (*init_missing_ticks_accounting)(int cpu);
  165. int (*do_steal_accounting)(unsigned long *new_itm);
  166. void (*clocksource_resume)(void);
  167. };
  168. extern struct pv_time_ops pv_time_ops;
  169. static inline void
  170. paravirt_init_missing_ticks_accounting(int cpu)
  171. {
  172. if (pv_time_ops.init_missing_ticks_accounting)
  173. pv_time_ops.init_missing_ticks_accounting(cpu);
  174. }
  175. static inline int
  176. paravirt_do_steal_accounting(unsigned long *new_itm)
  177. {
  178. return pv_time_ops.do_steal_accounting(new_itm);
  179. }
  180. #endif /* !__ASSEMBLY__ */
  181. #else
  182. /* fallback for native case */
  183. #ifndef __ASSEMBLY__
  184. #define paravirt_banner() do { } while (0)
  185. #define paravirt_reserve_memory(region) 0
  186. #define paravirt_arch_setup_early() do { } while (0)
  187. #define paravirt_arch_setup_console(cmdline_p) do { } while (0)
  188. #define paravirt_arch_setup_nomca() 0
  189. #define paravirt_post_smp_prepare_boot_cpu() do { } while (0)
  190. #define paravirt_init_missing_ticks_accounting(cpu) do { } while (0)
  191. #define paravirt_do_steal_accounting(new_itm) 0
  192. #endif /* __ASSEMBLY__ */
  193. #endif /* CONFIG_PARAVIRT_GUEST */
  194. #endif /* __ASM_PARAVIRT_H */