mach_apic.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef _ASM_X86_MACH_DEFAULT_MACH_APIC_H
  2. #define _ASM_X86_MACH_DEFAULT_MACH_APIC_H
  3. #ifdef CONFIG_X86_LOCAL_APIC
  4. #include <asm/smp.h>
  5. #define APIC_DFR_VALUE (APIC_DFR_FLAT)
  6. static inline const struct cpumask *default_target_cpus(void)
  7. {
  8. #ifdef CONFIG_SMP
  9. return cpu_online_mask;
  10. #else
  11. return cpumask_of(0);
  12. #endif
  13. }
  14. #ifdef CONFIG_X86_64
  15. #include <asm/genapic.h>
  16. #define read_apic_id() (apic->get_apic_id(apic_read(APIC_ID)))
  17. extern void default_setup_apic_routing(void);
  18. #else
  19. /*
  20. * Set up the logical destination ID.
  21. *
  22. * Intel recommends to set DFR, LDR and TPR before enabling
  23. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  24. * document number 292116). So here it goes...
  25. */
  26. static inline void default_init_apic_ldr(void)
  27. {
  28. unsigned long val;
  29. apic_write(APIC_DFR, APIC_DFR_VALUE);
  30. val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
  31. val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
  32. apic_write(APIC_LDR, val);
  33. }
  34. static inline int default_apic_id_registered(void)
  35. {
  36. return physid_isset(read_apic_id(), phys_cpu_present_map);
  37. }
  38. static inline unsigned int
  39. default_cpu_mask_to_apicid(const struct cpumask *cpumask)
  40. {
  41. return cpumask_bits(cpumask)[0];
  42. }
  43. static inline unsigned int
  44. default_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  45. const struct cpumask *andmask)
  46. {
  47. unsigned long mask1 = cpumask_bits(cpumask)[0];
  48. unsigned long mask2 = cpumask_bits(andmask)[0];
  49. unsigned long mask3 = cpumask_bits(cpu_online_mask)[0];
  50. return (unsigned int)(mask1 & mask2 & mask3);
  51. }
  52. static inline int default_phys_pkg_id(int cpuid_apic, int index_msb)
  53. {
  54. return cpuid_apic >> index_msb;
  55. }
  56. static inline void default_setup_apic_routing(void)
  57. {
  58. #ifdef CONFIG_X86_IO_APIC
  59. printk("Enabling APIC mode: %s. Using %d I/O APICs\n",
  60. "Flat", nr_ioapics);
  61. #endif
  62. }
  63. static inline int default_apicid_to_node(int logical_apicid)
  64. {
  65. #ifdef CONFIG_SMP
  66. return apicid_2_node[hard_smp_processor_id()];
  67. #else
  68. return 0;
  69. #endif
  70. }
  71. #endif
  72. static inline unsigned long default_check_apicid_used(physid_mask_t bitmap, int apicid)
  73. {
  74. return physid_isset(apicid, bitmap);
  75. }
  76. static inline unsigned long default_check_apicid_present(int bit)
  77. {
  78. return physid_isset(bit, phys_cpu_present_map);
  79. }
  80. static inline physid_mask_t default_ioapic_phys_id_map(physid_mask_t phys_map)
  81. {
  82. return phys_map;
  83. }
  84. /* Mapping from cpu number to logical apicid */
  85. static inline int default_cpu_to_logical_apicid(int cpu)
  86. {
  87. return 1 << cpu;
  88. }
  89. static inline int __default_cpu_present_to_apicid(int mps_cpu)
  90. {
  91. if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu))
  92. return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
  93. else
  94. return BAD_APICID;
  95. }
  96. static inline int
  97. __default_check_phys_apicid_present(int boot_cpu_physical_apicid)
  98. {
  99. return physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map);
  100. }
  101. #ifdef CONFIG_X86_32
  102. static inline int default_cpu_present_to_apicid(int mps_cpu)
  103. {
  104. return __default_cpu_present_to_apicid(mps_cpu);
  105. }
  106. static inline int
  107. default_check_phys_apicid_present(int boot_cpu_physical_apicid)
  108. {
  109. return __default_check_phys_apicid_present(boot_cpu_physical_apicid);
  110. }
  111. #else
  112. extern int default_cpu_present_to_apicid(int mps_cpu);
  113. extern int default_check_phys_apicid_present(int boot_cpu_physical_apicid);
  114. #endif
  115. static inline physid_mask_t default_apicid_to_cpu_present(int phys_apicid)
  116. {
  117. return physid_mask_of_physid(phys_apicid);
  118. }
  119. #endif /* CONFIG_X86_LOCAL_APIC */
  120. #endif /* _ASM_X86_MACH_DEFAULT_MACH_APIC_H */