apic.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #ifndef __ASM_ES7000_APIC_H
  2. #define __ASM_ES7000_APIC_H
  3. #include <linux/gfp.h>
  4. #define xapic_phys_to_log_apicid(cpu) per_cpu(x86_bios_cpu_apicid, cpu)
  5. static inline int es7000_apic_id_registered(void)
  6. {
  7. return 1;
  8. }
  9. static inline const cpumask_t *target_cpus_cluster(void)
  10. {
  11. return &CPU_MASK_ALL;
  12. }
  13. static inline const cpumask_t *es7000_target_cpus(void)
  14. {
  15. return &cpumask_of_cpu(smp_processor_id());
  16. }
  17. #define APIC_DFR_VALUE_CLUSTER (APIC_DFR_CLUSTER)
  18. #define INT_DELIVERY_MODE_CLUSTER (dest_LowestPrio)
  19. #define INT_DEST_MODE_CLUSTER (1) /* logical delivery broadcast to all procs */
  20. #define APIC_DFR_VALUE (APIC_DFR_FLAT)
  21. static inline unsigned long
  22. es7000_check_apicid_used(physid_mask_t bitmap, int apicid)
  23. {
  24. return 0;
  25. }
  26. static inline unsigned long es7000_check_apicid_present(int bit)
  27. {
  28. return physid_isset(bit, phys_cpu_present_map);
  29. }
  30. extern void es7000_enable_apic_mode(void);
  31. #define apicid_cluster(apicid) (apicid & 0xF0)
  32. static inline unsigned long calculate_ldr(int cpu)
  33. {
  34. unsigned long id;
  35. id = xapic_phys_to_log_apicid(cpu);
  36. return (SET_APIC_LOGICAL_ID(id));
  37. }
  38. /*
  39. * Set up the logical destination ID.
  40. *
  41. * Intel recommends to set DFR, LdR and TPR before enabling
  42. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  43. * document number 292116). So here it goes...
  44. */
  45. static inline void es7000_init_apic_ldr_cluster(void)
  46. {
  47. unsigned long val;
  48. int cpu = smp_processor_id();
  49. apic_write(APIC_DFR, APIC_DFR_VALUE_CLUSTER);
  50. val = calculate_ldr(cpu);
  51. apic_write(APIC_LDR, val);
  52. }
  53. static inline void es7000_init_apic_ldr(void)
  54. {
  55. unsigned long val;
  56. int cpu = smp_processor_id();
  57. apic_write(APIC_DFR, APIC_DFR_VALUE);
  58. val = calculate_ldr(cpu);
  59. apic_write(APIC_LDR, val);
  60. }
  61. extern int apic_version [MAX_APICS];
  62. static inline void es7000_setup_apic_routing(void)
  63. {
  64. int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id());
  65. printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
  66. (apic_version[apic] == 0x14) ?
  67. "Physical Cluster" : "Logical Cluster",
  68. nr_ioapics, cpus_addr(*es7000_target_cpus())[0]);
  69. }
  70. static inline int es7000_apicid_to_node(int logical_apicid)
  71. {
  72. return 0;
  73. }
  74. static inline int es7000_cpu_present_to_apicid(int mps_cpu)
  75. {
  76. if (!mps_cpu)
  77. return boot_cpu_physical_apicid;
  78. else if (mps_cpu < nr_cpu_ids)
  79. return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
  80. else
  81. return BAD_APICID;
  82. }
  83. static inline physid_mask_t es7000_apicid_to_cpu_present(int phys_apicid)
  84. {
  85. static int id = 0;
  86. physid_mask_t mask;
  87. mask = physid_mask_of_physid(id);
  88. ++id;
  89. return mask;
  90. }
  91. extern u8 cpu_2_logical_apicid[];
  92. /* Mapping from cpu number to logical apicid */
  93. static inline int es7000_cpu_to_logical_apicid(int cpu)
  94. {
  95. #ifdef CONFIG_SMP
  96. if (cpu >= nr_cpu_ids)
  97. return BAD_APICID;
  98. return (int)cpu_2_logical_apicid[cpu];
  99. #else
  100. return logical_smp_processor_id();
  101. #endif
  102. }
  103. static inline physid_mask_t es7000_ioapic_phys_id_map(physid_mask_t phys_map)
  104. {
  105. /* For clustered we don't have a good way to do this yet - hack */
  106. return physids_promote(0xff);
  107. }
  108. extern unsigned int boot_cpu_physical_apicid;
  109. static inline int es7000_check_phys_apicid_present(int cpu_physical_apicid)
  110. {
  111. boot_cpu_physical_apicid = read_apic_id();
  112. return (1);
  113. }
  114. static inline unsigned int
  115. cpu_mask_to_apicid_cluster(const struct cpumask *cpumask)
  116. {
  117. int num_bits_set;
  118. int cpus_found = 0;
  119. int cpu;
  120. int apicid;
  121. num_bits_set = cpumask_weight(cpumask);
  122. /* Return id to all */
  123. if (num_bits_set == nr_cpu_ids)
  124. return 0xFF;
  125. /*
  126. * The cpus in the mask must all be on the apic cluster. If are not
  127. * on the same apicid cluster return default value of target_cpus():
  128. */
  129. cpu = cpumask_first(cpumask);
  130. apicid = es7000_cpu_to_logical_apicid(cpu);
  131. while (cpus_found < num_bits_set) {
  132. if (cpumask_test_cpu(cpu, cpumask)) {
  133. int new_apicid = es7000_cpu_to_logical_apicid(cpu);
  134. if (apicid_cluster(apicid) !=
  135. apicid_cluster(new_apicid)){
  136. printk ("%s: Not a valid mask!\n", __func__);
  137. return 0xFF;
  138. }
  139. apicid = new_apicid;
  140. cpus_found++;
  141. }
  142. cpu++;
  143. }
  144. return apicid;
  145. }
  146. static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
  147. {
  148. int num_bits_set;
  149. int cpus_found = 0;
  150. int cpu;
  151. int apicid;
  152. num_bits_set = cpus_weight(*cpumask);
  153. /* Return id to all */
  154. if (num_bits_set == nr_cpu_ids)
  155. return es7000_cpu_to_logical_apicid(0);
  156. /*
  157. * The cpus in the mask must all be on the apic cluster. If are not
  158. * on the same apicid cluster return default value of target_cpus():
  159. */
  160. cpu = first_cpu(*cpumask);
  161. apicid = es7000_cpu_to_logical_apicid(cpu);
  162. while (cpus_found < num_bits_set) {
  163. if (cpu_isset(cpu, *cpumask)) {
  164. int new_apicid = es7000_cpu_to_logical_apicid(cpu);
  165. if (apicid_cluster(apicid) !=
  166. apicid_cluster(new_apicid)){
  167. printk ("%s: Not a valid mask!\n", __func__);
  168. return es7000_cpu_to_logical_apicid(0);
  169. }
  170. apicid = new_apicid;
  171. cpus_found++;
  172. }
  173. cpu++;
  174. }
  175. return apicid;
  176. }
  177. static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *inmask,
  178. const struct cpumask *andmask)
  179. {
  180. int apicid = es7000_cpu_to_logical_apicid(0);
  181. cpumask_var_t cpumask;
  182. if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))
  183. return apicid;
  184. cpumask_and(cpumask, inmask, andmask);
  185. cpumask_and(cpumask, cpumask, cpu_online_mask);
  186. apicid = cpu_mask_to_apicid(cpumask);
  187. free_cpumask_var(cpumask);
  188. return apicid;
  189. }
  190. static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
  191. {
  192. return cpuid_apic >> index_msb;
  193. }
  194. #endif /* __ASM_ES7000_APIC_H */