smp.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/kernel.h>
  8. #include <linux/threads.h>
  9. #include <linux/cpumask.h>
  10. #include <asm/pda.h>
  11. #endif
  12. #if defined(CONFIG_X86_LOCAL_APIC) && !defined(__ASSEMBLY__)
  13. #include <asm/bitops.h>
  14. #include <asm/mpspec.h>
  15. #include <asm/apic.h>
  16. #ifdef CONFIG_X86_IO_APIC
  17. #include <asm/io_apic.h>
  18. #endif
  19. #endif
  20. #define BAD_APICID 0xFFu
  21. #ifdef CONFIG_SMP
  22. #ifndef __ASSEMBLY__
  23. /*
  24. * Private routines/data
  25. */
  26. extern void smp_alloc_memory(void);
  27. extern int pic_mode;
  28. extern int smp_num_siblings;
  29. extern cpumask_t cpu_sibling_map[];
  30. extern cpumask_t cpu_core_map[];
  31. extern void (*mtrr_hook) (void);
  32. extern void zap_low_mappings (void);
  33. extern void lock_ipi_call_lock(void);
  34. extern void unlock_ipi_call_lock(void);
  35. #define MAX_APICID 256
  36. extern u8 x86_cpu_to_apicid[];
  37. #define cpu_physical_id(cpu) x86_cpu_to_apicid[cpu]
  38. #ifdef CONFIG_HOTPLUG_CPU
  39. extern void cpu_exit_clear(void);
  40. extern void cpu_uninit(void);
  41. #endif
  42. struct smp_ops
  43. {
  44. void (*smp_prepare_boot_cpu)(void);
  45. void (*smp_prepare_cpus)(unsigned max_cpus);
  46. int (*cpu_up)(unsigned cpu);
  47. void (*smp_cpus_done)(unsigned max_cpus);
  48. void (*smp_send_stop)(void);
  49. void (*smp_send_reschedule)(int cpu);
  50. int (*smp_call_function_mask)(cpumask_t mask,
  51. void (*func)(void *info), void *info,
  52. int wait);
  53. };
  54. extern struct smp_ops smp_ops;
  55. static inline void smp_prepare_boot_cpu(void)
  56. {
  57. smp_ops.smp_prepare_boot_cpu();
  58. }
  59. static inline void smp_prepare_cpus(unsigned int max_cpus)
  60. {
  61. smp_ops.smp_prepare_cpus(max_cpus);
  62. }
  63. static inline int __cpu_up(unsigned int cpu)
  64. {
  65. return smp_ops.cpu_up(cpu);
  66. }
  67. static inline void smp_cpus_done(unsigned int max_cpus)
  68. {
  69. smp_ops.smp_cpus_done(max_cpus);
  70. }
  71. static inline void smp_send_stop(void)
  72. {
  73. smp_ops.smp_send_stop();
  74. }
  75. static inline void smp_send_reschedule(int cpu)
  76. {
  77. smp_ops.smp_send_reschedule(cpu);
  78. }
  79. static inline int smp_call_function_mask(cpumask_t mask,
  80. void (*func) (void *info), void *info,
  81. int wait)
  82. {
  83. return smp_ops.smp_call_function_mask(mask, func, info, wait);
  84. }
  85. void native_smp_prepare_boot_cpu(void);
  86. void native_smp_prepare_cpus(unsigned int max_cpus);
  87. int native_cpu_up(unsigned int cpunum);
  88. void native_smp_cpus_done(unsigned int max_cpus);
  89. #ifndef CONFIG_PARAVIRT
  90. #define startup_ipi_hook(phys_apicid, start_eip, start_esp) \
  91. do { } while (0)
  92. #endif
  93. /*
  94. * This function is needed by all SMP systems. It must _always_ be valid
  95. * from the initial startup. We map APIC_BASE very early in page_setup(),
  96. * so this is correct in the x86 case.
  97. */
  98. #define raw_smp_processor_id() (read_pda(cpu_number))
  99. extern cpumask_t cpu_callout_map;
  100. extern cpumask_t cpu_callin_map;
  101. extern cpumask_t cpu_possible_map;
  102. /* We don't mark CPUs online until __cpu_up(), so we need another measure */
  103. static inline int num_booting_cpus(void)
  104. {
  105. return cpus_weight(cpu_callout_map);
  106. }
  107. #ifdef CONFIG_X86_LOCAL_APIC
  108. #ifdef APIC_DEFINITION
  109. extern int hard_smp_processor_id(void);
  110. #else
  111. #include <mach_apicdef.h>
  112. static inline int hard_smp_processor_id(void)
  113. {
  114. /* we don't want to mark this access volatile - bad code generation */
  115. return GET_APIC_ID(*(unsigned long *)(APIC_BASE+APIC_ID));
  116. }
  117. #endif
  118. #endif
  119. extern int safe_smp_processor_id(void);
  120. extern int __cpu_disable(void);
  121. extern void __cpu_die(unsigned int cpu);
  122. extern unsigned int num_processors;
  123. #endif /* !__ASSEMBLY__ */
  124. #else /* CONFIG_SMP */
  125. #define safe_smp_processor_id() 0
  126. #define cpu_physical_id(cpu) boot_cpu_physical_apicid
  127. #define NO_PROC_ID 0xFF /* No processor magic marker */
  128. #endif
  129. #ifndef __ASSEMBLY__
  130. extern u8 apicid_2_node[];
  131. #ifdef CONFIG_X86_LOCAL_APIC
  132. static __inline int logical_smp_processor_id(void)
  133. {
  134. /* we don't want to mark this access volatile - bad code generation */
  135. return GET_APIC_LOGICAL_ID(*(unsigned long *)(APIC_BASE+APIC_LDR));
  136. }
  137. #endif
  138. #endif
  139. #endif