1 /* 2 * QEMU PowerPC pSeries Logical Partition NUMA associativity handling 3 * 4 * Copyright IBM Corp. 2020 5 * 6 * Authors: 7 * Daniel Henrique Barboza <danielhb413@gmail.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or later. 10 * See the COPYING file in the top-level directory. 11 */ 12 13 #include "qemu/osdep.h" 14 #include "qemu-common.h" 15 #include "hw/ppc/spapr_numa.h" 16 #include "hw/ppc/fdt.h" 17 18 19 void spapr_numa_associativity_init(SpaprMachineState *spapr, 20 MachineState *machine) 21 { 22 int nb_numa_nodes = machine->numa_state->num_nodes; 23 int i; 24 25 /* 26 * For all associativity arrays: first position is the size, 27 * position MAX_DISTANCE_REF_POINTS is always the numa_id, 28 * represented by the index 'i'. 29 * 30 * This will break on sparse NUMA setups, when/if QEMU starts 31 * to support it, because there will be no more guarantee that 32 * 'i' will be a valid node_id set by the user. 33 */ 34 for (i = 0; i < nb_numa_nodes; i++) { 35 spapr->numa_assoc_array[i][0] = cpu_to_be32(MAX_DISTANCE_REF_POINTS); 36 spapr->numa_assoc_array[i][MAX_DISTANCE_REF_POINTS] = cpu_to_be32(i); 37 } 38 } 39 40 void spapr_numa_write_associativity_dt(SpaprMachineState *spapr, void *fdt, 41 int offset, int nodeid) 42 { 43 _FDT((fdt_setprop(fdt, offset, "ibm,associativity", 44 spapr->numa_assoc_array[nodeid], 45 sizeof(spapr->numa_assoc_array[nodeid])))); 46 } 47 48 /* 49 * Helper that writes ibm,associativity-reference-points and 50 * max-associativity-domains in the RTAS pointed by @rtas 51 * in the DT @fdt. 52 */ 53 void spapr_numa_write_rtas_dt(SpaprMachineState *spapr, void *fdt, int rtas) 54 { 55 SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr); 56 uint32_t refpoints[] = { 57 cpu_to_be32(0x4), 58 cpu_to_be32(0x4), 59 cpu_to_be32(0x2), 60 }; 61 uint32_t nr_refpoints = ARRAY_SIZE(refpoints); 62 uint32_t maxdomain = cpu_to_be32(spapr->gpu_numa_id > 1 ? 1 : 0); 63 uint32_t maxdomains[] = { 64 cpu_to_be32(4), 65 maxdomain, 66 maxdomain, 67 maxdomain, 68 cpu_to_be32(spapr->gpu_numa_id), 69 }; 70 71 if (smc->pre_5_1_assoc_refpoints) { 72 nr_refpoints = 2; 73 } 74 75 _FDT(fdt_setprop(fdt, rtas, "ibm,associativity-reference-points", 76 refpoints, nr_refpoints * sizeof(refpoints[0]))); 77 78 _FDT(fdt_setprop(fdt, rtas, "ibm,max-associativity-domains", 79 maxdomains, sizeof(maxdomains))); 80 } 81