acpi_numa.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * ACPI 5.1 based NUMA setup for ARM64
  3. * Lots of code was borrowed from arch/x86/mm/srat.c
  4. *
  5. * Copyright 2004 Andi Kleen, SuSE Labs.
  6. * Copyright (C) 2013-2016, Linaro Ltd.
  7. * Author: Hanjun Guo <hanjun.guo@linaro.org>
  8. *
  9. * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
  10. *
  11. * Called from acpi_numa_init while reading the SRAT and SLIT tables.
  12. * Assumes all memory regions belonging to a single proximity domain
  13. * are in one chunk. Holes between them will be included in the node.
  14. */
  15. #define pr_fmt(fmt) "ACPI: NUMA: " fmt
  16. #include <linux/acpi.h>
  17. #include <linux/bitmap.h>
  18. #include <linux/bootmem.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 <acpi/processor.h>
  26. #include <asm/numa.h>
  27. static int cpus_in_srat;
  28. struct __node_cpu_hwid {
  29. u32 node_id; /* logical node containing this CPU */
  30. u64 cpu_hwid; /* MPIDR for this CPU */
  31. };
  32. static struct __node_cpu_hwid early_node_cpu_hwid[NR_CPUS] = {
  33. [0 ... NR_CPUS - 1] = {NUMA_NO_NODE, PHYS_CPUID_INVALID} };
  34. int acpi_numa_get_nid(unsigned int cpu, u64 hwid)
  35. {
  36. int i;
  37. for (i = 0; i < cpus_in_srat; i++) {
  38. if (hwid == early_node_cpu_hwid[i].cpu_hwid)
  39. return early_node_cpu_hwid[i].node_id;
  40. }
  41. return NUMA_NO_NODE;
  42. }
  43. /* Callback for Proximity Domain -> ACPI processor UID mapping */
  44. void __init acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa)
  45. {
  46. int pxm, node;
  47. phys_cpuid_t mpidr;
  48. if (srat_disabled())
  49. return;
  50. if (pa->header.length < sizeof(struct acpi_srat_gicc_affinity)) {
  51. pr_err("SRAT: Invalid SRAT header length: %d\n",
  52. pa->header.length);
  53. bad_srat();
  54. return;
  55. }
  56. if (!(pa->flags & ACPI_SRAT_GICC_ENABLED))
  57. return;
  58. if (cpus_in_srat >= NR_CPUS) {
  59. pr_warn_once("SRAT: cpu_to_node_map[%d] is too small, may not be able to use all cpus\n",
  60. NR_CPUS);
  61. return;
  62. }
  63. pxm = pa->proximity_domain;
  64. node = acpi_map_pxm_to_node(pxm);
  65. if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) {
  66. pr_err("SRAT: Too many proximity domains %d\n", pxm);
  67. bad_srat();
  68. return;
  69. }
  70. mpidr = acpi_map_madt_entry(pa->acpi_processor_uid);
  71. if (mpidr == PHYS_CPUID_INVALID) {
  72. pr_err("SRAT: PXM %d with ACPI ID %d has no valid MPIDR in MADT\n",
  73. pxm, pa->acpi_processor_uid);
  74. bad_srat();
  75. return;
  76. }
  77. early_node_cpu_hwid[cpus_in_srat].node_id = node;
  78. early_node_cpu_hwid[cpus_in_srat].cpu_hwid = mpidr;
  79. node_set(node, numa_nodes_parsed);
  80. cpus_in_srat++;
  81. pr_info("SRAT: PXM %d -> MPIDR 0x%Lx -> Node %d\n",
  82. pxm, mpidr, node);
  83. }
  84. int __init arm64_acpi_numa_init(void)
  85. {
  86. int ret;
  87. ret = acpi_numa_init();
  88. if (ret) {
  89. pr_info("Failed to initialise from firmware\n");
  90. return ret;
  91. }
  92. return srat_disabled() ? -EINVAL : 0;
  93. }