apic.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #ifndef __ASM_ES7000_APIC_H
  2. #define __ASM_ES7000_APIC_H
  3. #define xapic_phys_to_log_apicid(cpu) per_cpu(x86_bios_cpu_apicid, cpu)
  4. #define esr_disable (1)
  5. static inline int apic_id_registered(void)
  6. {
  7. return (1);
  8. }
  9. static inline cpumask_t target_cpus(void)
  10. {
  11. #if defined CONFIG_ES7000_CLUSTERED_APIC
  12. return CPU_MASK_ALL;
  13. #else
  14. return cpumask_of_cpu(smp_processor_id());
  15. #endif
  16. }
  17. #if defined CONFIG_ES7000_CLUSTERED_APIC
  18. #define APIC_DFR_VALUE (APIC_DFR_CLUSTER)
  19. #define INT_DELIVERY_MODE (dest_LowestPrio)
  20. #define INT_DEST_MODE (1) /* logical delivery broadcast to all procs */
  21. #define NO_BALANCE_IRQ (1)
  22. #else
  23. #define APIC_DFR_VALUE (APIC_DFR_FLAT)
  24. #define INT_DELIVERY_MODE (dest_Fixed)
  25. #define INT_DEST_MODE (0) /* phys delivery to target procs */
  26. #define NO_BALANCE_IRQ (0)
  27. #undef APIC_DEST_LOGICAL
  28. #define APIC_DEST_LOGICAL 0x0
  29. #endif
  30. static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
  31. {
  32. return 0;
  33. }
  34. static inline unsigned long check_apicid_present(int bit)
  35. {
  36. return physid_isset(bit, phys_cpu_present_map);
  37. }
  38. #define apicid_cluster(apicid) (apicid & 0xF0)
  39. static inline unsigned long calculate_ldr(int cpu)
  40. {
  41. unsigned long id;
  42. id = xapic_phys_to_log_apicid(cpu);
  43. return (SET_APIC_LOGICAL_ID(id));
  44. }
  45. /*
  46. * Set up the logical destination ID.
  47. *
  48. * Intel recommends to set DFR, LdR and TPR before enabling
  49. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  50. * document number 292116). So here it goes...
  51. */
  52. static inline void init_apic_ldr(void)
  53. {
  54. unsigned long val;
  55. int cpu = smp_processor_id();
  56. apic_write(APIC_DFR, APIC_DFR_VALUE);
  57. val = calculate_ldr(cpu);
  58. apic_write(APIC_LDR, val);
  59. }
  60. #ifndef CONFIG_X86_GENERICARCH
  61. extern void enable_apic_mode(void);
  62. #endif
  63. extern int apic_version [MAX_APICS];
  64. static inline void setup_apic_routing(void)
  65. {
  66. int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id());
  67. printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
  68. (apic_version[apic] == 0x14) ?
  69. "Physical Cluster" : "Logical Cluster", nr_ioapics, cpus_addr(target_cpus())[0]);
  70. }
  71. static inline int multi_timer_check(int apic, int irq)
  72. {
  73. return 0;
  74. }
  75. static inline int apicid_to_node(int logical_apicid)
  76. {
  77. return 0;
  78. }
  79. static inline int cpu_present_to_apicid(int mps_cpu)
  80. {
  81. if (!mps_cpu)
  82. return boot_cpu_physical_apicid;
  83. else if (mps_cpu < NR_CPUS)
  84. return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
  85. else
  86. return BAD_APICID;
  87. }
  88. static inline physid_mask_t apicid_to_cpu_present(int phys_apicid)
  89. {
  90. static int id = 0;
  91. physid_mask_t mask;
  92. mask = physid_mask_of_physid(id);
  93. ++id;
  94. return mask;
  95. }
  96. extern u8 cpu_2_logical_apicid[];
  97. /* Mapping from cpu number to logical apicid */
  98. static inline int cpu_to_logical_apicid(int cpu)
  99. {
  100. #ifdef CONFIG_SMP
  101. if (cpu >= NR_CPUS)
  102. return BAD_APICID;
  103. return (int)cpu_2_logical_apicid[cpu];
  104. #else
  105. return logical_smp_processor_id();
  106. #endif
  107. }
  108. static inline physid_mask_t ioapic_phys_id_map(physid_mask_t phys_map)
  109. {
  110. /* For clustered we don't have a good way to do this yet - hack */
  111. return physids_promote(0xff);
  112. }
  113. static inline void setup_portio_remap(void)
  114. {
  115. }
  116. extern unsigned int boot_cpu_physical_apicid;
  117. static inline int check_phys_apicid_present(int cpu_physical_apicid)
  118. {
  119. boot_cpu_physical_apicid = read_apic_id();
  120. return (1);
  121. }
  122. static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
  123. {
  124. int num_bits_set;
  125. int cpus_found = 0;
  126. int cpu;
  127. int apicid;
  128. num_bits_set = cpus_weight(cpumask);
  129. /* Return id to all */
  130. if (num_bits_set == NR_CPUS)
  131. #if defined CONFIG_ES7000_CLUSTERED_APIC
  132. return 0xFF;
  133. #else
  134. return cpu_to_logical_apicid(0);
  135. #endif
  136. /*
  137. * The cpus in the mask must all be on the apic cluster. If are not
  138. * on the same apicid cluster return default value of TARGET_CPUS.
  139. */
  140. cpu = first_cpu(cpumask);
  141. apicid = cpu_to_logical_apicid(cpu);
  142. while (cpus_found < num_bits_set) {
  143. if (cpu_isset(cpu, cpumask)) {
  144. int new_apicid = cpu_to_logical_apicid(cpu);
  145. if (apicid_cluster(apicid) !=
  146. apicid_cluster(new_apicid)){
  147. printk ("%s: Not a valid mask!\n", __func__);
  148. #if defined CONFIG_ES7000_CLUSTERED_APIC
  149. return 0xFF;
  150. #else
  151. return cpu_to_logical_apicid(0);
  152. #endif
  153. }
  154. apicid = new_apicid;
  155. cpus_found++;
  156. }
  157. cpu++;
  158. }
  159. return apicid;
  160. }
  161. static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
  162. {
  163. return cpuid_apic >> index_msb;
  164. }
  165. #endif /* __ASM_ES7000_APIC_H */