genapic.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. #ifndef _ASM_X86_GENAPIC_H
  2. #define _ASM_X86_GENAPIC_H
  3. #include <linux/cpumask.h>
  4. #include <asm/mpspec.h>
  5. #include <asm/atomic.h>
  6. #include <asm/apic.h>
  7. /*
  8. * Copyright 2004 James Cleverdon, IBM.
  9. * Subject to the GNU Public License, v.2
  10. *
  11. * Generic APIC sub-arch data struct.
  12. *
  13. * Hacked for x86-64 by James Cleverdon from i386 architecture code by
  14. * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and
  15. * James Cleverdon.
  16. */
  17. struct genapic {
  18. char *name;
  19. int (*probe)(void);
  20. int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id);
  21. int (*apic_id_registered)(void);
  22. u32 irq_delivery_mode;
  23. u32 irq_dest_mode;
  24. const struct cpumask *(*target_cpus)(void);
  25. int disable_esr;
  26. int dest_logical;
  27. unsigned long (*check_apicid_used)(physid_mask_t bitmap, int apicid);
  28. unsigned long (*check_apicid_present)(int apicid);
  29. void (*vector_allocation_domain)(int cpu, struct cpumask *retmask);
  30. void (*init_apic_ldr)(void);
  31. physid_mask_t (*ioapic_phys_id_map)(physid_mask_t map);
  32. void (*setup_apic_routing)(void);
  33. int (*multi_timer_check)(int apic, int irq);
  34. int (*apicid_to_node)(int logical_apicid);
  35. int (*cpu_to_logical_apicid)(int cpu);
  36. int (*cpu_present_to_apicid)(int mps_cpu);
  37. physid_mask_t (*apicid_to_cpu_present)(int phys_apicid);
  38. void (*setup_portio_remap)(void);
  39. int (*check_phys_apicid_present)(int boot_cpu_physical_apicid);
  40. void (*enable_apic_mode)(void);
  41. int (*phys_pkg_id)(int cpuid_apic, int index_msb);
  42. /*
  43. * When one of the next two hooks returns 1 the genapic
  44. * is switched to this. Essentially they are additional
  45. * probe functions:
  46. */
  47. int (*mps_oem_check)(struct mpc_table *mpc, char *oem, char *productid);
  48. unsigned int (*get_apic_id)(unsigned long x);
  49. unsigned long (*set_apic_id)(unsigned int id);
  50. unsigned long apic_id_mask;
  51. unsigned int (*cpu_mask_to_apicid)(const struct cpumask *cpumask);
  52. unsigned int (*cpu_mask_to_apicid_and)(const struct cpumask *cpumask,
  53. const struct cpumask *andmask);
  54. /* ipi */
  55. void (*send_IPI_mask)(const struct cpumask *mask, int vector);
  56. void (*send_IPI_mask_allbutself)(const struct cpumask *mask,
  57. int vector);
  58. void (*send_IPI_allbutself)(int vector);
  59. void (*send_IPI_all)(int vector);
  60. void (*send_IPI_self)(int vector);
  61. /* wakeup_secondary_cpu */
  62. int (*wakeup_cpu)(int apicid, unsigned long start_eip);
  63. int trampoline_phys_low;
  64. int trampoline_phys_high;
  65. void (*wait_for_init_deassert)(atomic_t *deassert);
  66. void (*smp_callin_clear_local_apic)(void);
  67. void (*store_NMI_vector)(unsigned short *high, unsigned short *low);
  68. void (*inquire_remote_apic)(int apicid);
  69. /* apic ops */
  70. u32 (*read)(u32 reg);
  71. void (*write)(u32 reg, u32 v);
  72. u64 (*icr_read)(void);
  73. void (*icr_write)(u32 low, u32 high);
  74. void (*wait_icr_idle)(void);
  75. u32 (*safe_wait_icr_idle)(void);
  76. };
  77. extern struct genapic *apic;
  78. static inline u32 apic_read(u32 reg)
  79. {
  80. return apic->read(reg);
  81. }
  82. static inline void apic_write(u32 reg, u32 val)
  83. {
  84. apic->write(reg, val);
  85. }
  86. static inline u64 apic_icr_read(void)
  87. {
  88. return apic->icr_read();
  89. }
  90. static inline void apic_icr_write(u32 low, u32 high)
  91. {
  92. apic->icr_write(low, high);
  93. }
  94. static inline void apic_wait_icr_idle(void)
  95. {
  96. apic->wait_icr_idle();
  97. }
  98. static inline u32 safe_apic_wait_icr_idle(void)
  99. {
  100. return apic->safe_wait_icr_idle();
  101. }
  102. static inline void ack_APIC_irq(void)
  103. {
  104. /*
  105. * ack_APIC_irq() actually gets compiled as a single instruction
  106. * ... yummie.
  107. */
  108. /* Docs say use 0 for future compatibility */
  109. apic_write(APIC_EOI, 0);
  110. }
  111. static inline unsigned default_get_apic_id(unsigned long x)
  112. {
  113. unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR));
  114. if (APIC_XAPIC(ver))
  115. return (x >> 24) & 0xFF;
  116. else
  117. return (x >> 24) & 0x0F;
  118. }
  119. /*
  120. * Warm reset vector default position:
  121. */
  122. #define DEFAULT_TRAMPOLINE_PHYS_LOW 0x467
  123. #define DEFAULT_TRAMPOLINE_PHYS_HIGH 0x469
  124. #ifdef CONFIG_X86_32
  125. extern void es7000_update_genapic_to_cluster(void);
  126. #else
  127. extern struct genapic apic_flat;
  128. extern struct genapic apic_physflat;
  129. extern struct genapic apic_x2apic_cluster;
  130. extern struct genapic apic_x2apic_phys;
  131. extern int default_acpi_madt_oem_check(char *, char *);
  132. extern void apic_send_IPI_self(int vector);
  133. extern struct genapic apic_x2apic_uv_x;
  134. DECLARE_PER_CPU(int, x2apic_extra_bits);
  135. extern int default_cpu_present_to_apicid(int mps_cpu);
  136. extern int default_check_phys_apicid_present(int boot_cpu_physical_apicid);
  137. #endif
  138. static inline void default_wait_for_init_deassert(atomic_t *deassert)
  139. {
  140. while (!atomic_read(deassert))
  141. cpu_relax();
  142. return;
  143. }
  144. extern void generic_bigsmp_probe(void);
  145. #ifdef CONFIG_X86_LOCAL_APIC
  146. #include <asm/smp.h>
  147. #define APIC_DFR_VALUE (APIC_DFR_FLAT)
  148. static inline const struct cpumask *default_target_cpus(void)
  149. {
  150. #ifdef CONFIG_SMP
  151. return cpu_online_mask;
  152. #else
  153. return cpumask_of(0);
  154. #endif
  155. }
  156. DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
  157. static inline unsigned int read_apic_id(void)
  158. {
  159. unsigned int reg;
  160. reg = apic_read(APIC_ID);
  161. return apic->get_apic_id(reg);
  162. }
  163. extern void default_setup_apic_routing(void);
  164. #ifdef CONFIG_X86_32
  165. /*
  166. * Set up the logical destination ID.
  167. *
  168. * Intel recommends to set DFR, LDR and TPR before enabling
  169. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  170. * document number 292116). So here it goes...
  171. */
  172. extern void default_init_apic_ldr(void);
  173. static inline int default_apic_id_registered(void)
  174. {
  175. return physid_isset(read_apic_id(), phys_cpu_present_map);
  176. }
  177. static inline unsigned int
  178. default_cpu_mask_to_apicid(const struct cpumask *cpumask)
  179. {
  180. return cpumask_bits(cpumask)[0];
  181. }
  182. static inline unsigned int
  183. default_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  184. const struct cpumask *andmask)
  185. {
  186. unsigned long mask1 = cpumask_bits(cpumask)[0];
  187. unsigned long mask2 = cpumask_bits(andmask)[0];
  188. unsigned long mask3 = cpumask_bits(cpu_online_mask)[0];
  189. return (unsigned int)(mask1 & mask2 & mask3);
  190. }
  191. static inline int default_phys_pkg_id(int cpuid_apic, int index_msb)
  192. {
  193. return cpuid_apic >> index_msb;
  194. }
  195. extern int default_apicid_to_node(int logical_apicid);
  196. #endif
  197. static inline unsigned long default_check_apicid_used(physid_mask_t bitmap, int apicid)
  198. {
  199. return physid_isset(apicid, bitmap);
  200. }
  201. static inline unsigned long default_check_apicid_present(int bit)
  202. {
  203. return physid_isset(bit, phys_cpu_present_map);
  204. }
  205. static inline physid_mask_t default_ioapic_phys_id_map(physid_mask_t phys_map)
  206. {
  207. return phys_map;
  208. }
  209. /* Mapping from cpu number to logical apicid */
  210. static inline int default_cpu_to_logical_apicid(int cpu)
  211. {
  212. return 1 << cpu;
  213. }
  214. static inline int __default_cpu_present_to_apicid(int mps_cpu)
  215. {
  216. if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu))
  217. return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
  218. else
  219. return BAD_APICID;
  220. }
  221. static inline int
  222. __default_check_phys_apicid_present(int boot_cpu_physical_apicid)
  223. {
  224. return physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map);
  225. }
  226. #ifdef CONFIG_X86_32
  227. static inline int default_cpu_present_to_apicid(int mps_cpu)
  228. {
  229. return __default_cpu_present_to_apicid(mps_cpu);
  230. }
  231. static inline int
  232. default_check_phys_apicid_present(int boot_cpu_physical_apicid)
  233. {
  234. return __default_check_phys_apicid_present(boot_cpu_physical_apicid);
  235. }
  236. #else
  237. extern int default_cpu_present_to_apicid(int mps_cpu);
  238. extern int default_check_phys_apicid_present(int boot_cpu_physical_apicid);
  239. #endif
  240. static inline physid_mask_t default_apicid_to_cpu_present(int phys_apicid)
  241. {
  242. return physid_mask_of_physid(phys_apicid);
  243. }
  244. #endif /* CONFIG_X86_LOCAL_APIC */
  245. #endif /* _ASM_X86_GENAPIC_64_H */