setup.c 2.4 KB

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