Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * ACPI 3.0 based NUMA setup
0004  * Copyright 2004 Andi Kleen, SuSE Labs.
0005  *
0006  * Reads the ACPI SRAT table to figure out what memory belongs to which CPUs.
0007  *
0008  * Called from acpi_numa_init while reading the SRAT and SLIT tables.
0009  * Assumes all memory regions belonging to a single proximity domain
0010  * are in one chunk. Holes between them will be included in the node.
0011  */
0012 
0013 #include <linux/kernel.h>
0014 #include <linux/acpi.h>
0015 #include <linux/mmzone.h>
0016 #include <linux/bitmap.h>
0017 #include <linux/init.h>
0018 #include <linux/topology.h>
0019 #include <linux/mm.h>
0020 #include <asm/proto.h>
0021 #include <asm/numa.h>
0022 #include <asm/e820/api.h>
0023 #include <asm/apic.h>
0024 #include <asm/uv/uv.h>
0025 
0026 /* Callback for Proximity Domain -> x2APIC mapping */
0027 void __init
0028 acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
0029 {
0030     int pxm, node;
0031     int apic_id;
0032 
0033     if (srat_disabled())
0034         return;
0035     if (pa->header.length < sizeof(struct acpi_srat_x2apic_cpu_affinity)) {
0036         bad_srat();
0037         return;
0038     }
0039     if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
0040         return;
0041     pxm = pa->proximity_domain;
0042     apic_id = pa->apic_id;
0043     if (!apic->apic_id_valid(apic_id)) {
0044         printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n",
0045              pxm, apic_id);
0046         return;
0047     }
0048     node = acpi_map_pxm_to_node(pxm);
0049     if (node < 0) {
0050         printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
0051         bad_srat();
0052         return;
0053     }
0054 
0055     if (apic_id >= MAX_LOCAL_APIC) {
0056         printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
0057         return;
0058     }
0059     set_apicid_to_node(apic_id, node);
0060     node_set(node, numa_nodes_parsed);
0061     printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n",
0062            pxm, apic_id, node);
0063 }
0064 
0065 /* Callback for Proximity Domain -> LAPIC mapping */
0066 void __init
0067 acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
0068 {
0069     int pxm, node;
0070     int apic_id;
0071 
0072     if (srat_disabled())
0073         return;
0074     if (pa->header.length != sizeof(struct acpi_srat_cpu_affinity)) {
0075         bad_srat();
0076         return;
0077     }
0078     if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
0079         return;
0080     pxm = pa->proximity_domain_lo;
0081     if (acpi_srat_revision >= 2)
0082         pxm |= *((unsigned int*)pa->proximity_domain_hi) << 8;
0083     node = acpi_map_pxm_to_node(pxm);
0084     if (node < 0) {
0085         printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
0086         bad_srat();
0087         return;
0088     }
0089 
0090     if (get_uv_system_type() >= UV_X2APIC)
0091         apic_id = (pa->apic_id << 8) | pa->local_sapic_eid;
0092     else
0093         apic_id = pa->apic_id;
0094 
0095     if (apic_id >= MAX_LOCAL_APIC) {
0096         printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node);
0097         return;
0098     }
0099 
0100     set_apicid_to_node(apic_id, node);
0101     node_set(node, numa_nodes_parsed);
0102     printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u\n",
0103            pxm, apic_id, node);
0104 }
0105 
0106 int __init x86_acpi_numa_init(void)
0107 {
0108     int ret;
0109 
0110     ret = acpi_numa_init();
0111     if (ret < 0)
0112         return ret;
0113     return srat_disabled() ? -EINVAL : 0;
0114 }