setup.c 4.0 KB

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