acpi_numa.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * ACPI 5.1 based NUMA setup for ARM64
  4. * Lots of code was borrowed from arch/x86/mm/srat.c
  5. *
  6. * Copyright 2004 Andi Kleen, SuSE Labs.
  7. * Copyright (C) 2013-2016, Linaro Ltd.
  8. * Author: Hanjun Guo <[email protected]>
  9. *
  10. * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
  11. *
  12. * Called from acpi_numa_init while reading the SRAT and SLIT tables.
  13. * Assumes all memory regions belonging to a single proximity domain
  14. * are in one chunk. Holes between them will be included in the node.
  15. */
  16. #define pr_fmt(fmt) "ACPI: NUMA: " fmt
  17. #include <linux/acpi.h>
  18. #include <linux/bitmap.h>
  19. #include <linux/kernel.h>
  20. #include <linux/mm.h>
  21. #include <linux/memblock.h>
  22. #include <linux/mmzone.h>
  23. #include <linux/module.h>
  24. #include <linux/topology.h>
  25. #include <asm/numa.h>
  26. static int acpi_early_node_map[NR_CPUS] __initdata = { NUMA_NO_NODE };
  27. int __init acpi_numa_get_nid(unsigned int cpu)
  28. {
  29. return acpi_early_node_map[cpu];
  30. }
  31. static inline int get_cpu_for_acpi_id(u32 uid)
  32. {
  33. int cpu;
  34. for (cpu = 0; cpu < nr_cpu_ids; cpu++)
  35. if (uid == get_acpi_id_for_cpu(cpu))
  36. return cpu;
  37. return -EINVAL;
  38. }
  39. static int __init acpi_parse_gicc_pxm(union acpi_subtable_headers *header,
  40. const unsigned long end)
  41. {
  42. struct acpi_srat_gicc_affinity *pa;
  43. int cpu, pxm, node;
  44. if (srat_disabled())
  45. return -EINVAL;
  46. pa = (struct acpi_srat_gicc_affinity *)header;
  47. if (!pa)
  48. return -EINVAL;
  49. if (!(pa->flags & ACPI_SRAT_GICC_ENABLED))
  50. return 0;
  51. pxm = pa->proximity_domain;
  52. node = pxm_to_node(pxm);
  53. /*
  54. * If we can't map the UID to a logical cpu this
  55. * means that the UID is not part of possible cpus
  56. * so we do not need a NUMA mapping for it, skip
  57. * the SRAT entry and keep parsing.
  58. */
  59. cpu = get_cpu_for_acpi_id(pa->acpi_processor_uid);
  60. if (cpu < 0)
  61. return 0;
  62. acpi_early_node_map[cpu] = node;
  63. pr_info("SRAT: PXM %d -> MPIDR 0x%llx -> Node %d\n", pxm,
  64. cpu_logical_map(cpu), node);
  65. return 0;
  66. }
  67. void __init acpi_map_cpus_to_nodes(void)
  68. {
  69. acpi_table_parse_entries(ACPI_SIG_SRAT, sizeof(struct acpi_table_srat),
  70. ACPI_SRAT_TYPE_GICC_AFFINITY,
  71. acpi_parse_gicc_pxm, 0);
  72. }
  73. /* Callback for Proximity Domain -> ACPI processor UID mapping */
  74. void __init acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa)
  75. {
  76. int pxm, node;
  77. if (srat_disabled())
  78. return;
  79. if (pa->header.length < sizeof(struct acpi_srat_gicc_affinity)) {
  80. pr_err("SRAT: Invalid SRAT header length: %d\n",
  81. pa->header.length);
  82. bad_srat();
  83. return;
  84. }
  85. if (!(pa->flags & ACPI_SRAT_GICC_ENABLED))
  86. return;
  87. pxm = pa->proximity_domain;
  88. node = acpi_map_pxm_to_node(pxm);
  89. if (node == NUMA_NO_NODE) {
  90. pr_err("SRAT: Too many proximity domains %d\n", pxm);
  91. bad_srat();
  92. return;
  93. }
  94. node_set(node, numa_nodes_parsed);
  95. }