smp.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef __ASM_SMP_H
  2. #define __ASM_SMP_H
  3. /*
  4. * We need the APIC definitions automatically as part of 'smp.h'
  5. */
  6. #include <linux/threads.h>
  7. #include <linux/cpumask.h>
  8. #include <linux/bitops.h>
  9. extern int disable_apic;
  10. #ifdef CONFIG_X86_LOCAL_APIC
  11. #include <asm/fixmap.h>
  12. #include <asm/mpspec.h>
  13. #ifdef CONFIG_X86_IO_APIC
  14. #include <asm/io_apic.h>
  15. #endif
  16. #include <asm/apic.h>
  17. #include <asm/thread_info.h>
  18. #endif
  19. #ifdef CONFIG_SMP
  20. #include <asm/pda.h>
  21. struct pt_regs;
  22. extern cpumask_t cpu_present_mask;
  23. extern cpumask_t cpu_possible_map;
  24. extern cpumask_t cpu_online_map;
  25. extern cpumask_t cpu_callout_map;
  26. extern cpumask_t cpu_initialized;
  27. /*
  28. * Private routines/data
  29. */
  30. extern void smp_alloc_memory(void);
  31. extern volatile unsigned long smp_invalidate_needed;
  32. extern int pic_mode;
  33. extern void lock_ipi_call_lock(void);
  34. extern void unlock_ipi_call_lock(void);
  35. extern int smp_num_siblings;
  36. extern void smp_send_reschedule(int cpu);
  37. void smp_stop_cpu(void);
  38. extern int smp_call_function_single(int cpuid, void (*func) (void *info),
  39. void *info, int retry, int wait);
  40. extern cpumask_t cpu_sibling_map[NR_CPUS];
  41. extern cpumask_t cpu_core_map[NR_CPUS];
  42. extern u8 cpu_llc_id[NR_CPUS];
  43. #define SMP_TRAMPOLINE_BASE 0x6000
  44. /*
  45. * On x86 all CPUs are mapped 1:1 to the APIC space.
  46. * This simplifies scheduling and IPI sending and
  47. * compresses data structures.
  48. */
  49. static inline int num_booting_cpus(void)
  50. {
  51. return cpus_weight(cpu_callout_map);
  52. }
  53. #define raw_smp_processor_id() read_pda(cpunumber)
  54. static inline int hard_smp_processor_id(void)
  55. {
  56. /* we don't want to mark this access volatile - bad code generation */
  57. return GET_APIC_ID(*(unsigned int *)(APIC_BASE+APIC_ID));
  58. }
  59. extern int safe_smp_processor_id(void);
  60. extern int __cpu_disable(void);
  61. extern void __cpu_die(unsigned int cpu);
  62. extern void prefill_possible_map(void);
  63. extern unsigned num_processors;
  64. extern unsigned disabled_cpus;
  65. #define NO_PROC_ID 0xFF /* No processor magic marker */
  66. #endif
  67. /*
  68. * Some lowlevel functions might want to know about
  69. * the real APIC ID <-> CPU # mapping.
  70. */
  71. extern u8 x86_cpu_to_apicid[NR_CPUS]; /* physical ID */
  72. extern u8 x86_cpu_to_log_apicid[NR_CPUS];
  73. extern u8 bios_cpu_apicid[];
  74. static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
  75. {
  76. return cpus_addr(cpumask)[0];
  77. }
  78. static inline int cpu_present_to_apicid(int mps_cpu)
  79. {
  80. if (mps_cpu < NR_CPUS)
  81. return (int)bios_cpu_apicid[mps_cpu];
  82. else
  83. return BAD_APICID;
  84. }
  85. #ifndef CONFIG_SMP
  86. #define stack_smp_processor_id() 0
  87. #define safe_smp_processor_id() 0
  88. #define cpu_logical_map(x) (x)
  89. #else
  90. #include <asm/thread_info.h>
  91. #define stack_smp_processor_id() \
  92. ({ \
  93. struct thread_info *ti; \
  94. __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
  95. ti->cpu; \
  96. })
  97. #endif
  98. static __inline int logical_smp_processor_id(void)
  99. {
  100. /* we don't want to mark this access volatile - bad code generation */
  101. return GET_APIC_LOGICAL_ID(*(unsigned long *)(APIC_BASE+APIC_LDR));
  102. }
  103. #ifdef CONFIG_SMP
  104. #define cpu_physical_id(cpu) x86_cpu_to_apicid[cpu]
  105. #else
  106. #define cpu_physical_id(cpu) boot_cpu_id
  107. static inline int smp_call_function_single(int cpuid, void (*func) (void *info),
  108. void *info, int retry, int wait)
  109. {
  110. /* Disable interrupts here? */
  111. func(info);
  112. return 0;
  113. }
  114. #endif /* !CONFIG_SMP */
  115. #endif