setup.c 3.5 KB

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