smp.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. /*
  29. * Private routines/data
  30. */
  31. extern void smp_alloc_memory(void);
  32. extern cpumask_t cpu_online_map;
  33. extern volatile unsigned long smp_invalidate_needed;
  34. extern int pic_mode;
  35. extern int smp_num_siblings;
  36. extern void smp_flush_tlb(void);
  37. extern void smp_message_irq(int cpl, void *dev_id, struct pt_regs *regs);
  38. extern void smp_send_reschedule(int cpu);
  39. extern void smp_invalidate_rcv(void); /* Process an NMI */
  40. extern void (*mtrr_hook) (void);
  41. extern void zap_low_mappings(void);
  42. void smp_stop_cpu(void);
  43. extern cpumask_t cpu_sibling_map[NR_CPUS];
  44. extern cpumask_t cpu_core_map[NR_CPUS];
  45. extern u8 phys_proc_id[NR_CPUS];
  46. extern u8 cpu_core_id[NR_CPUS];
  47. #define SMP_TRAMPOLINE_BASE 0x6000
  48. /*
  49. * On x86 all CPUs are mapped 1:1 to the APIC space.
  50. * This simplifies scheduling and IPI sending and
  51. * compresses data structures.
  52. */
  53. extern cpumask_t cpu_callout_map;
  54. extern cpumask_t cpu_callin_map;
  55. #define cpu_possible_map cpu_callout_map
  56. static inline int num_booting_cpus(void)
  57. {
  58. return cpus_weight(cpu_callout_map);
  59. }
  60. #define __smp_processor_id() read_pda(cpunumber)
  61. extern __inline int hard_smp_processor_id(void)
  62. {
  63. /* we don't want to mark this access volatile - bad code generation */
  64. return GET_APIC_ID(*(unsigned int *)(APIC_BASE+APIC_ID));
  65. }
  66. #define safe_smp_processor_id() (disable_apic ? 0 : x86_apicid_to_cpu(hard_smp_processor_id()))
  67. #endif /* !ASSEMBLY */
  68. #define NO_PROC_ID 0xFF /* No processor magic marker */
  69. #endif
  70. #ifndef ASSEMBLY
  71. /*
  72. * Some lowlevel functions might want to know about
  73. * the real APIC ID <-> CPU # mapping.
  74. */
  75. extern u8 x86_cpu_to_apicid[NR_CPUS]; /* physical ID */
  76. extern u8 x86_cpu_to_log_apicid[NR_CPUS];
  77. extern u8 bios_cpu_apicid[];
  78. static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask)
  79. {
  80. return cpus_addr(cpumask)[0];
  81. }
  82. static inline int x86_apicid_to_cpu(u8 apicid)
  83. {
  84. int i;
  85. for (i = 0; i < NR_CPUS; ++i)
  86. if (x86_cpu_to_apicid[i] == apicid)
  87. return i;
  88. /* No entries in x86_cpu_to_apicid? Either no MPS|ACPI,
  89. * or called too early. Either way, we must be CPU 0. */
  90. if (x86_cpu_to_apicid[0] == BAD_APICID)
  91. return 0;
  92. return -1;
  93. }
  94. static inline int cpu_present_to_apicid(int mps_cpu)
  95. {
  96. if (mps_cpu < NR_CPUS)
  97. return (int)bios_cpu_apicid[mps_cpu];
  98. else
  99. return BAD_APICID;
  100. }
  101. #endif /* !ASSEMBLY */
  102. #ifndef CONFIG_SMP
  103. #define stack_smp_processor_id() 0
  104. #define safe_smp_processor_id() 0
  105. #define cpu_logical_map(x) (x)
  106. #else
  107. #include <asm/thread_info.h>
  108. #define stack_smp_processor_id() \
  109. ({ \
  110. struct thread_info *ti; \
  111. __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
  112. ti->cpu; \
  113. })
  114. #endif
  115. #ifndef __ASSEMBLY__
  116. static __inline int logical_smp_processor_id(void)
  117. {
  118. /* we don't want to mark this access volatile - bad code generation */
  119. return GET_APIC_LOGICAL_ID(*(unsigned long *)(APIC_BASE+APIC_LDR));
  120. }
  121. #endif
  122. #endif