setup.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_X86_32
  50. /*
  51. * Great future not-so-futuristic plan: make i386 and x86_64 do it
  52. * the same way
  53. */
  54. unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
  55. EXPORT_SYMBOL(__per_cpu_offset);
  56. #endif
  57. /*
  58. * Great future plan:
  59. * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
  60. * Always point %gs to its beginning
  61. */
  62. void __init setup_per_cpu_areas(void)
  63. {
  64. int i;
  65. unsigned long size;
  66. #ifdef CONFIG_HOTPLUG_CPU
  67. prefill_possible_map();
  68. #endif
  69. /* Copy section for each CPU (we discard the original) */
  70. size = PERCPU_ENOUGH_ROOM;
  71. printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n",
  72. size);
  73. for_each_possible_cpu(i) {
  74. char *ptr;
  75. #ifndef CONFIG_NEED_MULTIPLE_NODES
  76. ptr = alloc_bootmem_pages(size);
  77. #else
  78. int node = early_cpu_to_node(i);
  79. if (!node_online(node) || !NODE_DATA(node)) {
  80. ptr = alloc_bootmem_pages(size);
  81. printk(KERN_INFO
  82. "cpu %d has no node or node-local memory\n", i);
  83. }
  84. else
  85. ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
  86. #endif
  87. if (!ptr)
  88. panic("Cannot allocate cpu data for CPU %d\n", i);
  89. #ifdef CONFIG_X86_64
  90. cpu_pda(i)->data_offset = ptr - __per_cpu_start;
  91. #else
  92. __per_cpu_offset[i] = ptr - __per_cpu_start;
  93. #endif
  94. memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
  95. }
  96. /* Setup percpu data maps */
  97. setup_per_cpu_maps();
  98. }
  99. #endif