topology.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * This file contains NUMA specific variables and functions which can
  7. * be split away from DISCONTIGMEM and are used on NUMA machines with
  8. * contiguous memory.
  9. * 2002/08/07 Erich Focht <efocht@ess.nec.de>
  10. * Populate cpu entries in sysfs for non-numa systems as well
  11. * Intel Corporation - Ashok Raj
  12. */
  13. #include <linux/config.h>
  14. #include <linux/cpu.h>
  15. #include <linux/kernel.h>
  16. #include <linux/mm.h>
  17. #include <linux/node.h>
  18. #include <linux/init.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/nodemask.h>
  21. #include <asm/mmzone.h>
  22. #include <asm/numa.h>
  23. #include <asm/cpu.h>
  24. #ifdef CONFIG_NUMA
  25. static struct node *sysfs_nodes;
  26. #endif
  27. static struct ia64_cpu *sysfs_cpus;
  28. int arch_register_cpu(int num)
  29. {
  30. struct node *parent = NULL;
  31. #ifdef CONFIG_NUMA
  32. parent = &sysfs_nodes[cpu_to_node(num)];
  33. #endif /* CONFIG_NUMA */
  34. #ifdef CONFIG_ACPI
  35. /*
  36. * If CPEI cannot be re-targetted, and this is
  37. * CPEI target, then dont create the control file
  38. */
  39. if (!can_cpei_retarget() && is_cpu_cpei_target(num))
  40. sysfs_cpus[num].cpu.no_control = 1;
  41. #endif
  42. return register_cpu(&sysfs_cpus[num].cpu, num, parent);
  43. }
  44. #ifdef CONFIG_HOTPLUG_CPU
  45. void arch_unregister_cpu(int num)
  46. {
  47. struct node *parent = NULL;
  48. #ifdef CONFIG_NUMA
  49. int node = cpu_to_node(num);
  50. parent = &sysfs_nodes[node];
  51. #endif /* CONFIG_NUMA */
  52. return unregister_cpu(&sysfs_cpus[num].cpu, parent);
  53. }
  54. EXPORT_SYMBOL(arch_register_cpu);
  55. EXPORT_SYMBOL(arch_unregister_cpu);
  56. #endif /*CONFIG_HOTPLUG_CPU*/
  57. static int __init topology_init(void)
  58. {
  59. int i, err = 0;
  60. #ifdef CONFIG_NUMA
  61. sysfs_nodes = kzalloc(sizeof(struct node) * MAX_NUMNODES, GFP_KERNEL);
  62. if (!sysfs_nodes) {
  63. err = -ENOMEM;
  64. goto out;
  65. }
  66. /*
  67. * MCD - Do we want to register all ONLINE nodes, or all POSSIBLE nodes?
  68. */
  69. for_each_online_node(i) {
  70. if ((err = register_node(&sysfs_nodes[i], i, 0)))
  71. goto out;
  72. }
  73. #endif
  74. sysfs_cpus = kzalloc(sizeof(struct ia64_cpu) * NR_CPUS, GFP_KERNEL);
  75. if (!sysfs_cpus) {
  76. err = -ENOMEM;
  77. goto out;
  78. }
  79. for_each_present_cpu(i) {
  80. if((err = arch_register_cpu(i)))
  81. goto out;
  82. }
  83. out:
  84. return err;
  85. }
  86. subsys_initcall(topology_init);