smp.h 3.3 KB

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