apic.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #include <linux/init.h>
  2. #include <asm/x86_init.h>
  3. #include <asm/apic.h>
  4. #include <asm/xen/hypercall.h>
  5. #include <xen/xen.h>
  6. #include <xen/interface/physdev.h>
  7. #include "xen-ops.h"
  8. #include "pmu.h"
  9. #include "smp.h"
  10. static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
  11. {
  12. struct physdev_apic apic_op;
  13. int ret;
  14. apic_op.apic_physbase = mpc_ioapic_addr(apic);
  15. apic_op.reg = reg;
  16. ret = HYPERVISOR_physdev_op(PHYSDEVOP_apic_read, &apic_op);
  17. if (!ret)
  18. return apic_op.value;
  19. /* fallback to return an emulated IO_APIC values */
  20. if (reg == 0x1)
  21. return 0x00170020;
  22. else if (reg == 0x0)
  23. return apic << 24;
  24. return 0xfd;
  25. }
  26. static unsigned long xen_set_apic_id(unsigned int x)
  27. {
  28. WARN_ON(1);
  29. return x;
  30. }
  31. static unsigned int xen_get_apic_id(unsigned long x)
  32. {
  33. return ((x)>>24) & 0xFFu;
  34. }
  35. static u32 xen_apic_read(u32 reg)
  36. {
  37. struct xen_platform_op op = {
  38. .cmd = XENPF_get_cpuinfo,
  39. .interface_version = XENPF_INTERFACE_VERSION,
  40. .u.pcpu_info.xen_cpuid = 0,
  41. };
  42. int ret = 0;
  43. /* Shouldn't need this as APIC is turned off for PV, and we only
  44. * get called on the bootup processor. But just in case. */
  45. if (!xen_initial_domain() || smp_processor_id())
  46. return 0;
  47. if (reg == APIC_LVR)
  48. return 0x10;
  49. #ifdef CONFIG_X86_32
  50. if (reg == APIC_LDR)
  51. return SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
  52. #endif
  53. if (reg != APIC_ID)
  54. return 0;
  55. ret = HYPERVISOR_dom0_op(&op);
  56. if (ret)
  57. return 0;
  58. return op.u.pcpu_info.apic_id << 24;
  59. }
  60. static void xen_apic_write(u32 reg, u32 val)
  61. {
  62. if (reg == APIC_LVTPC) {
  63. (void)pmu_apic_update(reg);
  64. return;
  65. }
  66. /* Warn to see if there's any stray references */
  67. WARN(1,"register: %x, value: %x\n", reg, val);
  68. }
  69. static u64 xen_apic_icr_read(void)
  70. {
  71. return 0;
  72. }
  73. static void xen_apic_icr_write(u32 low, u32 id)
  74. {
  75. /* Warn to see if there's any stray references */
  76. WARN_ON(1);
  77. }
  78. static u32 xen_safe_apic_wait_icr_idle(void)
  79. {
  80. return 0;
  81. }
  82. static int xen_apic_probe_pv(void)
  83. {
  84. if (xen_pv_domain())
  85. return 1;
  86. return 0;
  87. }
  88. static int xen_madt_oem_check(char *oem_id, char *oem_table_id)
  89. {
  90. return xen_pv_domain();
  91. }
  92. static int xen_id_always_valid(int apicid)
  93. {
  94. return 1;
  95. }
  96. static int xen_id_always_registered(void)
  97. {
  98. return 1;
  99. }
  100. static int xen_phys_pkg_id(int initial_apic_id, int index_msb)
  101. {
  102. return initial_apic_id >> index_msb;
  103. }
  104. #ifdef CONFIG_X86_32
  105. static int xen_x86_32_early_logical_apicid(int cpu)
  106. {
  107. /* Match with APIC_LDR read. Otherwise setup_local_APIC complains. */
  108. return 1 << cpu;
  109. }
  110. #endif
  111. static void xen_noop(void)
  112. {
  113. }
  114. static void xen_silent_inquire(int apicid)
  115. {
  116. }
  117. static struct apic xen_pv_apic = {
  118. .name = "Xen PV",
  119. .probe = xen_apic_probe_pv,
  120. .acpi_madt_oem_check = xen_madt_oem_check,
  121. .apic_id_valid = xen_id_always_valid,
  122. .apic_id_registered = xen_id_always_registered,
  123. /* .irq_delivery_mode - used in native_compose_msi_msg only */
  124. /* .irq_dest_mode - used in native_compose_msi_msg only */
  125. .target_cpus = default_target_cpus,
  126. .disable_esr = 0,
  127. /* .dest_logical - default_send_IPI_ use it but we use our own. */
  128. .check_apicid_used = default_check_apicid_used, /* Used on 32-bit */
  129. .vector_allocation_domain = flat_vector_allocation_domain,
  130. .init_apic_ldr = xen_noop, /* setup_local_APIC calls it */
  131. .ioapic_phys_id_map = default_ioapic_phys_id_map, /* Used on 32-bit */
  132. .setup_apic_routing = NULL,
  133. .cpu_present_to_apicid = default_cpu_present_to_apicid,
  134. .apicid_to_cpu_present = physid_set_mask_of_physid, /* Used on 32-bit */
  135. .check_phys_apicid_present = default_check_phys_apicid_present, /* smp_sanity_check needs it */
  136. .phys_pkg_id = xen_phys_pkg_id, /* detect_ht */
  137. .get_apic_id = xen_get_apic_id,
  138. .set_apic_id = xen_set_apic_id, /* Can be NULL on 32-bit. */
  139. .apic_id_mask = 0xFF << 24, /* Used by verify_local_APIC. Match with what xen_get_apic_id does. */
  140. .cpu_mask_to_apicid_and = flat_cpu_mask_to_apicid_and,
  141. #ifdef CONFIG_SMP
  142. .send_IPI_mask = xen_send_IPI_mask,
  143. .send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself,
  144. .send_IPI_allbutself = xen_send_IPI_allbutself,
  145. .send_IPI_all = xen_send_IPI_all,
  146. .send_IPI_self = xen_send_IPI_self,
  147. #endif
  148. /* .wait_for_init_deassert- used by AP bootup - smp_callin which we don't use */
  149. .inquire_remote_apic = xen_silent_inquire,
  150. .read = xen_apic_read,
  151. .write = xen_apic_write,
  152. .eoi_write = xen_apic_write,
  153. .icr_read = xen_apic_icr_read,
  154. .icr_write = xen_apic_icr_write,
  155. .wait_icr_idle = xen_noop,
  156. .safe_wait_icr_idle = xen_safe_apic_wait_icr_idle,
  157. #ifdef CONFIG_X86_32
  158. /* generic_processor_info and setup_local_APIC. */
  159. .x86_32_early_logical_apicid = xen_x86_32_early_logical_apicid,
  160. #endif
  161. };
  162. static void __init xen_apic_check(void)
  163. {
  164. if (apic == &xen_pv_apic)
  165. return;
  166. pr_info("Switched APIC routing from %s to %s.\n", apic->name,
  167. xen_pv_apic.name);
  168. apic = &xen_pv_apic;
  169. }
  170. void __init xen_init_apic(void)
  171. {
  172. x86_io_apic_ops.read = xen_io_apic_read;
  173. /* On PV guests the APIC CPUID bit is disabled so none of the
  174. * routines end up executing. */
  175. if (!xen_initial_domain())
  176. apic = &xen_pv_apic;
  177. x86_platform.apic_post_init = xen_apic_check;
  178. }
  179. apic_driver(xen_pv_apic);