setup.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/init.h>
  4. #include <linux/bootmem.h>
  5. #include <linux/percpu.h>
  6. #include <asm/smp.h>
  7. #include <asm/percpu.h>
  8. #include <asm/sections.h>
  9. #include <asm/processor.h>
  10. #include <asm/setup.h>
  11. #include <asm/topology.h>
  12. #include <asm/mpspec.h>
  13. #include <asm/apicdef.h>
  14. unsigned int num_processors;
  15. unsigned disabled_cpus __cpuinitdata;
  16. /* Processor that is doing the boot up */
  17. unsigned int boot_cpu_physical_apicid = -1U;
  18. EXPORT_SYMBOL(boot_cpu_physical_apicid);
  19. physid_mask_t phys_cpu_present_map;
  20. DEFINE_PER_CPU(u16, x86_cpu_to_apicid) = BAD_APICID;
  21. EXPORT_PER_CPU_SYMBOL(x86_cpu_to_apicid);
  22. /* Bitmask of physically existing CPUs */
  23. physid_mask_t phys_cpu_present_map;
  24. #if defined(CONFIG_HAVE_SETUP_PER_CPU_AREA) && defined(CONFIG_SMP)
  25. /*
  26. * Copy data used in early init routines from the initial arrays to the
  27. * per cpu data areas. These arrays then become expendable and the
  28. * *_early_ptr's are zeroed indicating that the static arrays are gone.
  29. */
  30. static void __init setup_per_cpu_maps(void)
  31. {
  32. int cpu;
  33. for_each_possible_cpu(cpu) {
  34. per_cpu(x86_cpu_to_apicid, cpu) = x86_cpu_to_apicid_init[cpu];
  35. per_cpu(x86_bios_cpu_apicid, cpu) =
  36. x86_bios_cpu_apicid_init[cpu];
  37. #ifdef CONFIG_NUMA
  38. per_cpu(x86_cpu_to_node_map, cpu) =
  39. x86_cpu_to_node_map_init[cpu];
  40. #endif
  41. }
  42. /* indicate the early static arrays will soon be gone */
  43. x86_cpu_to_apicid_early_ptr = NULL;
  44. x86_bios_cpu_apicid_early_ptr = NULL;
  45. #ifdef CONFIG_NUMA
  46. x86_cpu_to_node_map_early_ptr = NULL;
  47. #endif
  48. }
  49. #ifdef CONFIG_HAVE_CPUMASK_OF_CPU_MAP
  50. cpumask_t *cpumask_of_cpu_map __read_mostly;
  51. EXPORT_SYMBOL(cpumask_of_cpu_map);
  52. /* requires nr_cpu_ids to be initialized */
  53. static void __init setup_cpumask_of_cpu(void)
  54. {
  55. int i;
  56. /* alloc_bootmem zeroes memory */
  57. cpumask_of_cpu_map = alloc_bootmem_low(sizeof(cpumask_t) * nr_cpu_ids);
  58. for (i = 0; i < nr_cpu_ids; i++)
  59. cpu_set(i, cpumask_of_cpu_map[i]);
  60. }
  61. #else
  62. static inline void setup_cpumask_of_cpu(void) { }
  63. #endif
  64. #ifdef CONFIG_X86_32
  65. /*
  66. * Great future not-so-futuristic plan: make i386 and x86_64 do it
  67. * the same way
  68. */
  69. unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
  70. EXPORT_SYMBOL(__per_cpu_offset);
  71. #endif
  72. /*
  73. * Great future plan:
  74. * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
  75. * Always point %gs to its beginning
  76. */
  77. void __init setup_per_cpu_areas(void)
  78. {
  79. int i, highest_cpu = 0;
  80. unsigned long size;
  81. #ifdef CONFIG_HOTPLUG_CPU
  82. prefill_possible_map();
  83. #endif
  84. /* Copy section for each CPU (we discard the original) */
  85. size = PERCPU_ENOUGH_ROOM;
  86. printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n",
  87. size);
  88. for_each_possible_cpu(i) {
  89. char *ptr;
  90. #ifndef CONFIG_NEED_MULTIPLE_NODES
  91. ptr = alloc_bootmem_pages(size);
  92. #else
  93. int node = early_cpu_to_node(i);
  94. if (!node_online(node) || !NODE_DATA(node)) {
  95. ptr = alloc_bootmem_pages(size);
  96. printk(KERN_INFO
  97. "cpu %d has no node or node-local memory\n", i);
  98. }
  99. else
  100. ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
  101. #endif
  102. if (!ptr)
  103. panic("Cannot allocate cpu data for CPU %d\n", i);
  104. #ifdef CONFIG_X86_64
  105. cpu_pda(i)->data_offset = ptr - __per_cpu_start;
  106. #else
  107. __per_cpu_offset[i] = ptr - __per_cpu_start;
  108. #endif
  109. memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
  110. highest_cpu = i;
  111. }
  112. nr_cpu_ids = highest_cpu + 1;
  113. printk(KERN_DEBUG "NR_CPUS: %d, nr_cpu_ids: %d\n", NR_CPUS, nr_cpu_ids);
  114. /* Setup percpu data maps */
  115. setup_per_cpu_maps();
  116. /* Setup cpumask_of_cpu map */
  117. setup_cpumask_of_cpu();
  118. }
  119. #endif