setup.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
  13. /*
  14. * Copy data used in early init routines from the initial arrays to the
  15. * per cpu data areas. These arrays then become expendable and the
  16. * *_early_ptr's are zeroed indicating that the static arrays are gone.
  17. */
  18. static void __init setup_per_cpu_maps(void)
  19. {
  20. int cpu;
  21. for_each_possible_cpu(cpu) {
  22. #ifdef CONFIG_SMP
  23. if (per_cpu_offset(cpu)) {
  24. #endif
  25. per_cpu(x86_cpu_to_apicid, cpu) =
  26. x86_cpu_to_apicid_init[cpu];
  27. per_cpu(x86_bios_cpu_apicid, cpu) =
  28. x86_bios_cpu_apicid_init[cpu];
  29. #ifdef CONFIG_NUMA
  30. per_cpu(x86_cpu_to_node_map, cpu) =
  31. x86_cpu_to_node_map_init[cpu];
  32. #endif
  33. #ifdef CONFIG_SMP
  34. } else
  35. printk(KERN_NOTICE "per_cpu_offset zero for cpu %d\n",
  36. cpu);
  37. #endif
  38. }
  39. /* indicate the early static arrays will soon be gone */
  40. x86_cpu_to_apicid_early_ptr = NULL;
  41. x86_bios_cpu_apicid_early_ptr = NULL;
  42. #ifdef CONFIG_NUMA
  43. x86_cpu_to_node_map_early_ptr = NULL;
  44. #endif
  45. }
  46. #ifdef CONFIG_X86_32
  47. /*
  48. * Great future not-so-futuristic plan: make i386 and x86_64 do it
  49. * the same way
  50. */
  51. unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
  52. EXPORT_SYMBOL(__per_cpu_offset);
  53. #endif
  54. /*
  55. * Great future plan:
  56. * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
  57. * Always point %gs to its beginning
  58. */
  59. void __init setup_per_cpu_areas(void)
  60. {
  61. int i;
  62. unsigned long size;
  63. #ifdef CONFIG_HOTPLUG_CPU
  64. prefill_possible_map();
  65. #endif
  66. /* Copy section for each CPU (we discard the original) */
  67. size = PERCPU_ENOUGH_ROOM;
  68. printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n",
  69. size);
  70. for_each_cpu_mask(i, cpu_possible_map) {
  71. char *ptr;
  72. #ifndef CONFIG_NEED_MULTIPLE_NODES
  73. ptr = alloc_bootmem_pages(size);
  74. #else
  75. int node = early_cpu_to_node(i);
  76. if (!node_online(node) || !NODE_DATA(node))
  77. ptr = alloc_bootmem_pages(size);
  78. else
  79. ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
  80. #endif
  81. if (!ptr)
  82. panic("Cannot allocate cpu data for CPU %d\n", i);
  83. #ifdef CONFIG_X86_64
  84. cpu_pda(i)->data_offset = ptr - __per_cpu_start;
  85. #else
  86. __per_cpu_offset[i] = ptr - __per_cpu_start;
  87. #endif
  88. memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
  89. }
  90. /* setup percpu data maps early */
  91. setup_per_cpu_maps();
  92. }
  93. #endif