setup.c 2.5 KB

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