smp.h 3.2 KB

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