~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to hw/ppc/spapr.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include "sysemu/device_tree.h"
37
37
#include "sysemu/block-backend.h"
38
38
#include "sysemu/cpus.h"
39
 
#include "sysemu/kvm.h"
 
39
#include "sysemu/hw_accel.h"
40
40
#include "kvm_ppc.h"
41
41
#include "migration/migration.h"
42
42
#include "mmu-hash64.h"
63
63
#include "qemu/error-report.h"
64
64
#include "trace.h"
65
65
#include "hw/nmi.h"
 
66
#include "hw/intc/intc.h"
66
67
 
67
68
#include "hw/compat.h"
68
69
#include "qemu/cutils.h"
95
96
 
96
97
#define HTAB_SIZE(spapr)        (1ULL << ((spapr)->htab_shift))
97
98
 
98
 
static XICSState *try_create_xics(const char *type, int nr_servers,
99
 
                                  int nr_irqs, Error **errp)
 
99
static int try_create_xics(sPAPRMachineState *spapr, const char *type_ics,
 
100
                           const char *type_icp, int nr_servers,
 
101
                           int nr_irqs, Error **errp)
100
102
{
101
 
    Error *err = NULL;
102
 
    DeviceState *dev;
 
103
    XICSFabric *xi = XICS_FABRIC(spapr);
 
104
    Error *err = NULL, *local_err = NULL;
 
105
    ICSState *ics = NULL;
 
106
    int i;
103
107
 
104
 
    dev = qdev_create(NULL, type);
105
 
    qdev_prop_set_uint32(dev, "nr_servers", nr_servers);
106
 
    qdev_prop_set_uint32(dev, "nr_irqs", nr_irqs);
107
 
    object_property_set_bool(OBJECT(dev), true, "realized", &err);
 
108
    ics = ICS_SIMPLE(object_new(type_ics));
 
109
    object_property_add_child(OBJECT(spapr), "ics", OBJECT(ics), NULL);
 
110
    object_property_set_int(OBJECT(ics), nr_irqs, "nr-irqs", &err);
 
111
    object_property_add_const_link(OBJECT(ics), "xics", OBJECT(xi), NULL);
 
112
    object_property_set_bool(OBJECT(ics), true, "realized", &local_err);
 
113
    error_propagate(&err, local_err);
108
114
    if (err) {
109
 
        error_propagate(errp, err);
110
 
        object_unparent(OBJECT(dev));
111
 
        return NULL;
112
 
    }
113
 
    return XICS_COMMON(dev);
 
115
        goto error;
 
116
    }
 
117
 
 
118
    spapr->icps = g_malloc0(nr_servers * sizeof(ICPState));
 
119
    spapr->nr_servers = nr_servers;
 
120
 
 
121
    for (i = 0; i < nr_servers; i++) {
 
122
        ICPState *icp = &spapr->icps[i];
 
123
 
 
124
        object_initialize(icp, sizeof(*icp), type_icp);
 
125
        object_property_add_child(OBJECT(spapr), "icp[*]", OBJECT(icp), NULL);
 
126
        object_property_add_const_link(OBJECT(icp), "xics", OBJECT(xi), NULL);
 
127
        object_property_set_bool(OBJECT(icp), true, "realized", &err);
 
128
        if (err) {
 
129
            goto error;
 
130
        }
 
131
        object_unref(OBJECT(icp));
 
132
    }
 
133
 
 
134
    spapr->ics = ics;
 
135
    return 0;
 
136
 
 
137
error:
 
138
    error_propagate(errp, err);
 
139
    if (ics) {
 
140
        object_unparent(OBJECT(ics));
 
141
    }
 
142
    return -1;
114
143
}
115
144
 
116
 
static XICSState *xics_system_init(MachineState *machine,
117
 
                                   int nr_servers, int nr_irqs, Error **errp)
 
145
static int xics_system_init(MachineState *machine,
 
146
                            int nr_servers, int nr_irqs, Error **errp)
118
147
{
119
 
    XICSState *xics = NULL;
 
148
    int rc = -1;
120
149
 
121
150
    if (kvm_enabled()) {
122
151
        Error *err = NULL;
123
152
 
124
 
        if (machine_kernel_irqchip_allowed(machine)) {
125
 
            xics = try_create_xics(TYPE_XICS_SPAPR_KVM, nr_servers, nr_irqs,
126
 
                                   &err);
 
153
        if (machine_kernel_irqchip_allowed(machine) &&
 
154
            !xics_kvm_init(SPAPR_MACHINE(machine), errp)) {
 
155
            rc = try_create_xics(SPAPR_MACHINE(machine), TYPE_ICS_KVM,
 
156
                                 TYPE_KVM_ICP, nr_servers, nr_irqs, &err);
127
157
        }
128
 
        if (machine_kernel_irqchip_required(machine) && !xics) {
 
158
        if (machine_kernel_irqchip_required(machine) && rc < 0) {
129
159
            error_reportf_err(err,
130
160
                              "kernel_irqchip requested but unavailable: ");
131
161
        } else {
133
163
        }
134
164
    }
135
165
 
136
 
    if (!xics) {
137
 
        xics = try_create_xics(TYPE_XICS_SPAPR, nr_servers, nr_irqs, errp);
 
166
    if (rc < 0) {
 
167
        xics_spapr_init(SPAPR_MACHINE(machine), errp);
 
168
        rc = try_create_xics(SPAPR_MACHINE(machine), TYPE_ICS_SIMPLE,
 
169
                               TYPE_ICP, nr_servers, nr_irqs, errp);
138
170
    }
139
171
 
140
 
    return xics;
 
172
    return rc;
141
173
}
142
174
 
143
175
static int spapr_fixup_cpu_smt_dt(void *fdt, int offset, PowerPCCPU *cpu,
148
180
    uint32_t gservers_prop[smt_threads * 2];
149
181
    int index = ppc_get_vcpu_dt_id(cpu);
150
182
 
151
 
    if (cpu->cpu_version) {
152
 
        ret = fdt_setprop_cell(fdt, offset, "cpu-version", cpu->cpu_version);
 
183
    if (cpu->compat_pvr) {
 
184
        ret = fdt_setprop_cell(fdt, offset, "cpu-version", cpu->compat_pvr);
153
185
        if (ret < 0) {
154
186
            return ret;
155
187
        }
206
238
        PowerPCCPU *cpu = POWERPC_CPU(cs);
207
239
        DeviceClass *dc = DEVICE_GET_CLASS(cs);
208
240
        int index = ppc_get_vcpu_dt_id(cpu);
 
241
        int compat_smt = MIN(smp_threads, ppc_compat_max_threads(cpu));
209
242
 
210
243
        if ((index % smt) != 0) {
211
244
            continue;
240
273
            return ret;
241
274
        }
242
275
 
243
 
        ret = spapr_fixup_cpu_smt_dt(fdt, offset, cpu,
244
 
                                     ppc_get_compat_smt_threads(cpu));
 
276
        ret = spapr_fixup_cpu_smt_dt(fdt, offset, cpu, compat_smt);
245
277
        if (ret < 0) {
246
278
            return ret;
247
279
        }
356
388
        0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
357
389
        0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
358
390
        0x80, 0x00, 0x80, 0x00, 0x00, 0x00 };
 
391
    /* Currently we don't advertise any of the "new" ISAv3.00 functionality */
 
392
    uint8_t pa_features_300[] = { 64, 0,
 
393
        0xf6, 0x1f, 0xc7, 0xc0, 0x80, 0xf0, /*  0 -  5 */
 
394
        0x80, 0x00, 0x00, 0x00, 0x00, 0x00, /*  6 - 11 */
 
395
        0x00, 0x00, 0x00, 0x00, 0x80, 0x00, /* 12 - 17 */
 
396
        0x80, 0x00, 0x80, 0x00, 0x00, 0x00, /* 18 - 23 */
 
397
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 24 - 29 */
 
398
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 30 - 35 */
 
399
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 36 - 41 */
 
400
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 42 - 47 */
 
401
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 48 - 53 */
 
402
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 54 - 59 */
 
403
        0x00, 0x00, 0x00, 0x00           }; /* 60 - 63 */
 
404
 
359
405
    uint8_t *pa_features;
360
406
    size_t pa_size;
361
407
 
362
 
    switch (env->mmu_model) {
363
 
    case POWERPC_MMU_2_06:
364
 
    case POWERPC_MMU_2_06a:
 
408
    switch (POWERPC_MMU_VER(env->mmu_model)) {
 
409
    case POWERPC_MMU_VER_2_06:
365
410
        pa_features = pa_features_206;
366
411
        pa_size = sizeof(pa_features_206);
367
412
        break;
368
 
    case POWERPC_MMU_2_07:
369
 
    case POWERPC_MMU_2_07a:
 
413
    case POWERPC_MMU_VER_2_07:
370
414
        pa_features = pa_features_207;
371
415
        pa_size = sizeof(pa_features_207);
372
416
        break;
 
417
    case POWERPC_MMU_VER_3_00:
 
418
        pa_features = pa_features_300;
 
419
        pa_size = sizeof(pa_features_300);
 
420
        break;
373
421
    default:
374
422
        return;
375
423
    }
407
455
    size_t page_sizes_prop_size;
408
456
    uint32_t vcpus_per_socket = smp_threads * smp_cores;
409
457
    uint32_t pft_size_prop[] = {0, cpu_to_be32(spapr->htab_shift)};
 
458
    int compat_smt = MIN(smp_threads, ppc_compat_max_threads(cpu));
410
459
    sPAPRDRConnector *drc;
411
460
    sPAPRDRConnectorClass *drck;
412
461
    int drc_index;
494
543
 
495
544
    _FDT(spapr_fixup_cpu_numa_dt(fdt, offset, cs));
496
545
 
497
 
    _FDT(spapr_fixup_cpu_smt_dt(fdt, offset, cpu,
498
 
                                ppc_get_compat_smt_threads(cpu)));
 
546
    _FDT(spapr_fixup_cpu_smt_dt(fdt, offset, cpu, compat_smt));
499
547
}
500
548
 
501
549
static void spapr_populate_cpus_dt_node(void *fdt, sPAPRMachineState *spapr)
685
733
 
686
734
int spapr_h_cas_compose_response(sPAPRMachineState *spapr,
687
735
                                 target_ulong addr, target_ulong size,
688
 
                                 bool cpu_update,
689
736
                                 sPAPROptionVector *ov5_updates)
690
737
{
691
738
    void *fdt, *fdt_skel;
704
751
    g_free(fdt_skel);
705
752
 
706
753
    /* Fixup cpu nodes */
707
 
    if (cpu_update) {
708
 
        _FDT((spapr_fixup_cpu_dt(fdt, spapr)));
709
 
    }
 
754
    _FDT((spapr_fixup_cpu_dt(fdt, spapr)));
710
755
 
711
756
    if (spapr_dt_cas_updates(spapr, fdt, ov5_updates)) {
712
757
        return -1;
927
972
    _FDT(fdt_setprop_cell(fdt, 0, "#size-cells", 2));
928
973
 
929
974
    /* /interrupt controller */
930
 
    spapr_dt_xics(spapr->xics, fdt, PHANDLE_XICP);
 
975
    spapr_dt_xics(spapr->nr_servers, fdt, PHANDLE_XICP);
931
976
 
932
977
    ret = spapr_populate_memory(spapr, fdt);
933
978
    if (ret < 0) {
961
1006
        _FDT(spapr_drc_populate_dt(fdt, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB));
962
1007
    }
963
1008
 
964
 
    if (mc->query_hotpluggable_cpus) {
 
1009
    if (mc->has_hotpluggable_cpus) {
965
1010
        int offset = fdt_path_offset(fdt, "/cpus");
966
1011
        ret = spapr_drc_populate_dt(fdt, offset, NULL,
967
1012
                                    SPAPR_DR_CONNECTOR_TYPE_CPU);
1008
1053
    return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR;
1009
1054
}
1010
1055
 
1011
 
static void emulate_spapr_hypercall(PowerPCCPU *cpu)
 
1056
static void emulate_spapr_hypercall(PPCVirtualHypervisor *vhyp,
 
1057
                                    PowerPCCPU *cpu)
1012
1058
{
1013
1059
    CPUPPCState *env = &cpu->env;
1014
1060
 
 
1061
    /* The TCG path should also be holding the BQL at this point */
 
1062
    g_assert(qemu_mutex_iothread_locked());
 
1063
 
1015
1064
    if (msr_pr) {
1016
1065
        hcall_dprintf("Hypercall made with MSR[PR]=1\n");
1017
1066
        env->gpr[3] = H_PRIVILEGE;
1020
1069
    }
1021
1070
}
1022
1071
 
 
1072
static uint64_t spapr_get_patbe(PPCVirtualHypervisor *vhyp)
 
1073
{
 
1074
    sPAPRMachineState *spapr = SPAPR_MACHINE(vhyp);
 
1075
 
 
1076
    return spapr->patb_entry;
 
1077
}
 
1078
 
1023
1079
#define HPTE(_table, _i)   (void *)(((uint64_t *)(_table)) + ((_i) * 2))
1024
1080
#define HPTE_VALID(_hpte)  (tswap64(*((uint64_t *)(_hpte))) & HPTE64_V_VALID)
1025
1081
#define HPTE_DIRTY(_hpte)  (tswap64(*((uint64_t *)(_hpte))) & HPTE64_V_HPTE_DIRTY)
1052
1108
    spapr->htab_fd = -1;
1053
1109
}
1054
1110
 
 
1111
static hwaddr spapr_hpt_mask(PPCVirtualHypervisor *vhyp)
 
1112
{
 
1113
    sPAPRMachineState *spapr = SPAPR_MACHINE(vhyp);
 
1114
 
 
1115
    return HTAB_SIZE(spapr) / HASH_PTEG_SIZE_64 - 1;
 
1116
}
 
1117
 
 
1118
static const ppc_hash_pte64_t *spapr_map_hptes(PPCVirtualHypervisor *vhyp,
 
1119
                                                hwaddr ptex, int n)
 
1120
{
 
1121
    sPAPRMachineState *spapr = SPAPR_MACHINE(vhyp);
 
1122
    hwaddr pte_offset = ptex * HASH_PTE_SIZE_64;
 
1123
 
 
1124
    if (!spapr->htab) {
 
1125
        /*
 
1126
         * HTAB is controlled by KVM. Fetch into temporary buffer
 
1127
         */
 
1128
        ppc_hash_pte64_t *hptes = g_malloc(n * HASH_PTE_SIZE_64);
 
1129
        kvmppc_read_hptes(hptes, ptex, n);
 
1130
        return hptes;
 
1131
    }
 
1132
 
 
1133
    /*
 
1134
     * HTAB is controlled by QEMU. Just point to the internally
 
1135
     * accessible PTEG.
 
1136
     */
 
1137
    return (const ppc_hash_pte64_t *)(spapr->htab + pte_offset);
 
1138
}
 
1139
 
 
1140
static void spapr_unmap_hptes(PPCVirtualHypervisor *vhyp,
 
1141
                              const ppc_hash_pte64_t *hptes,
 
1142
                              hwaddr ptex, int n)
 
1143
{
 
1144
    sPAPRMachineState *spapr = SPAPR_MACHINE(vhyp);
 
1145
 
 
1146
    if (!spapr->htab) {
 
1147
        g_free((void *)hptes);
 
1148
    }
 
1149
 
 
1150
    /* Nothing to do for qemu managed HPT */
 
1151
}
 
1152
 
 
1153
static void spapr_store_hpte(PPCVirtualHypervisor *vhyp, hwaddr ptex,
 
1154
                             uint64_t pte0, uint64_t pte1)
 
1155
{
 
1156
    sPAPRMachineState *spapr = SPAPR_MACHINE(vhyp);
 
1157
    hwaddr offset = ptex * HASH_PTE_SIZE_64;
 
1158
 
 
1159
    if (!spapr->htab) {
 
1160
        kvmppc_write_hpte(ptex, pte0, pte1);
 
1161
    } else {
 
1162
        stq_p(spapr->htab + offset, pte0);
 
1163
        stq_p(spapr->htab + offset + HASH_PTE_SIZE_64 / 2, pte1);
 
1164
    }
 
1165
}
 
1166
 
1055
1167
static int spapr_hpt_shift_for_ramsize(uint64_t ramsize)
1056
1168
{
1057
1169
    int shift;
1143
1255
    /* Check for unknown sysbus devices */
1144
1256
    foreach_dynamic_sysbus_device(find_unknown_sysbus_device, NULL);
1145
1257
 
 
1258
    spapr->patb_entry = 0;
 
1259
 
1146
1260
    /* Allocate and/or reset the hash page table */
1147
1261
    spapr_reallocate_hpt(spapr,
1148
1262
                         spapr_hpt_shift_for_ramsize(machine->maxram_size),
1251
1365
    sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
1252
1366
    int err = 0;
1253
1367
 
 
1368
    if (!object_dynamic_cast(OBJECT(spapr->ics), TYPE_ICS_KVM)) {
 
1369
        int i;
 
1370
        for (i = 0; i < spapr->nr_servers; i++) {
 
1371
            icp_resend(&spapr->icps[i]);
 
1372
        }
 
1373
    }
 
1374
 
1254
1375
    /* In earlier versions, there was no separate qdev for the PAPR
1255
1376
     * RTC, so the RTC offset was stored directly in sPAPREnvironment.
1256
1377
     * So when migrating from those versions, poke the incoming offset
1329
1450
    },
1330
1451
};
1331
1452
 
 
1453
static bool spapr_patb_entry_needed(void *opaque)
 
1454
{
 
1455
    sPAPRMachineState *spapr = opaque;
 
1456
 
 
1457
    return !!spapr->patb_entry;
 
1458
}
 
1459
 
 
1460
static const VMStateDescription vmstate_spapr_patb_entry = {
 
1461
    .name = "spapr_patb_entry",
 
1462
    .version_id = 1,
 
1463
    .minimum_version_id = 1,
 
1464
    .needed = spapr_patb_entry_needed,
 
1465
    .fields = (VMStateField[]) {
 
1466
        VMSTATE_UINT64(patb_entry, sPAPRMachineState),
 
1467
        VMSTATE_END_OF_LIST()
 
1468
    },
 
1469
};
 
1470
 
1332
1471
static const VMStateDescription vmstate_spapr = {
1333
1472
    .name = "spapr",
1334
1473
    .version_id = 3,
1346
1485
    },
1347
1486
    .subsections = (const VMStateDescription*[]) {
1348
1487
        &vmstate_spapr_ov5_cas,
 
1488
        &vmstate_spapr_patb_entry,
1349
1489
        NULL
1350
1490
    }
1351
1491
};
1384
1524
        /* Consume invalid HPTEs */
1385
1525
        while ((index < htabslots)
1386
1526
               && !HPTE_VALID(HPTE(spapr->htab, index))) {
 
1527
            CLEAN_HPTE(HPTE(spapr->htab, index));
1387
1528
            index++;
1388
 
            CLEAN_HPTE(HPTE(spapr->htab, index));
1389
1529
        }
1390
1530
 
1391
1531
        /* Consume valid HPTEs */
1392
1532
        chunkstart = index;
1393
1533
        while ((index < htabslots) && (index - chunkstart < USHRT_MAX)
1394
1534
               && HPTE_VALID(HPTE(spapr->htab, index))) {
 
1535
            CLEAN_HPTE(HPTE(spapr->htab, index));
1395
1536
            index++;
1396
 
            CLEAN_HPTE(HPTE(spapr->htab, index));
1397
1537
        }
1398
1538
 
1399
1539
        if (index > chunkstart) {
1753
1893
    }
1754
1894
}
1755
1895
 
 
1896
/* find cpu slot in machine->possible_cpus by core_id */
 
1897
static CPUArchId *spapr_find_cpu_slot(MachineState *ms, uint32_t id, int *idx)
 
1898
{
 
1899
    int index = id / smp_threads;
 
1900
 
 
1901
    if (index >= ms->possible_cpus->len) {
 
1902
        return NULL;
 
1903
    }
 
1904
    if (idx) {
 
1905
        *idx = index;
 
1906
    }
 
1907
    return &ms->possible_cpus->cpus[index];
 
1908
}
 
1909
 
 
1910
static void spapr_init_cpus(sPAPRMachineState *spapr)
 
1911
{
 
1912
    MachineState *machine = MACHINE(spapr);
 
1913
    MachineClass *mc = MACHINE_GET_CLASS(machine);
 
1914
    char *type = spapr_get_cpu_core_type(machine->cpu_model);
 
1915
    int smt = kvmppc_smt_threads();
 
1916
    const CPUArchIdList *possible_cpus;
 
1917
    int boot_cores_nr = smp_cpus / smp_threads;
 
1918
    int i;
 
1919
 
 
1920
    if (!type) {
 
1921
        error_report("Unable to find sPAPR CPU Core definition");
 
1922
        exit(1);
 
1923
    }
 
1924
 
 
1925
    possible_cpus = mc->possible_cpu_arch_ids(machine);
 
1926
    if (mc->has_hotpluggable_cpus) {
 
1927
        if (smp_cpus % smp_threads) {
 
1928
            error_report("smp_cpus (%u) must be multiple of threads (%u)",
 
1929
                         smp_cpus, smp_threads);
 
1930
            exit(1);
 
1931
        }
 
1932
        if (max_cpus % smp_threads) {
 
1933
            error_report("max_cpus (%u) must be multiple of threads (%u)",
 
1934
                         max_cpus, smp_threads);
 
1935
            exit(1);
 
1936
        }
 
1937
    } else {
 
1938
        if (max_cpus != smp_cpus) {
 
1939
            error_report("This machine version does not support CPU hotplug");
 
1940
            exit(1);
 
1941
        }
 
1942
        boot_cores_nr = possible_cpus->len;
 
1943
    }
 
1944
 
 
1945
    for (i = 0; i < possible_cpus->len; i++) {
 
1946
        int core_id = i * smp_threads;
 
1947
 
 
1948
        if (mc->has_hotpluggable_cpus) {
 
1949
            sPAPRDRConnector *drc =
 
1950
                spapr_dr_connector_new(OBJECT(spapr),
 
1951
                                       SPAPR_DR_CONNECTOR_TYPE_CPU,
 
1952
                                       (core_id / smp_threads) * smt);
 
1953
 
 
1954
            qemu_register_reset(spapr_drc_reset, drc);
 
1955
        }
 
1956
 
 
1957
        if (i < boot_cores_nr) {
 
1958
            Object *core  = object_new(type);
 
1959
            int nr_threads = smp_threads;
 
1960
 
 
1961
            /* Handle the partially filled core for older machine types */
 
1962
            if ((i + 1) * smp_threads >= smp_cpus) {
 
1963
                nr_threads = smp_cpus - i * smp_threads;
 
1964
            }
 
1965
 
 
1966
            object_property_set_int(core, nr_threads, "nr-threads",
 
1967
                                    &error_fatal);
 
1968
            object_property_set_int(core, core_id, CPU_CORE_PROP_CORE_ID,
 
1969
                                    &error_fatal);
 
1970
            object_property_set_bool(core, true, "realized", &error_fatal);
 
1971
        }
 
1972
    }
 
1973
    g_free(type);
 
1974
}
 
1975
 
1756
1976
/* pSeries LPAR / sPAPR hardware init */
1757
1977
static void ppc_spapr_init(MachineState *machine)
1758
1978
{
1759
1979
    sPAPRMachineState *spapr = SPAPR_MACHINE(machine);
1760
 
    MachineClass *mc = MACHINE_GET_CLASS(machine);
1761
1980
    sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);
1762
1981
    const char *kernel_filename = machine->kernel_filename;
1763
1982
    const char *initrd_filename = machine->initrd_filename;
1772
1991
    long load_limit, fw_size;
1773
1992
    char *filename;
1774
1993
    int smt = kvmppc_smt_threads();
1775
 
    int spapr_cores = smp_cpus / smp_threads;
1776
 
    int spapr_max_cores = max_cpus / smp_threads;
1777
 
 
1778
 
    if (mc->query_hotpluggable_cpus) {
1779
 
        if (smp_cpus % smp_threads) {
1780
 
            error_report("smp_cpus (%u) must be multiple of threads (%u)",
1781
 
                         smp_cpus, smp_threads);
1782
 
            exit(1);
1783
 
        }
1784
 
        if (max_cpus % smp_threads) {
1785
 
            error_report("max_cpus (%u) must be multiple of threads (%u)",
1786
 
                         max_cpus, smp_threads);
1787
 
            exit(1);
1788
 
        }
1789
 
    }
1790
1994
 
1791
1995
    msi_nonbroken = true;
1792
1996
 
1793
1997
    QLIST_INIT(&spapr->phbs);
1794
1998
 
1795
 
    cpu_ppc_hypercall = emulate_spapr_hypercall;
1796
 
 
1797
1999
    /* Allocate RMA if necessary */
1798
2000
    rma_alloc_size = kvmppc_alloc_rma(&rma);
1799
2001
 
1839
2041
    load_limit = MIN(spapr->rma_size, RTAS_MAX_ADDR) - FW_OVERHEAD;
1840
2042
 
1841
2043
    /* Set up Interrupt Controller before we create the VCPUs */
1842
 
    spapr->xics = xics_system_init(machine,
1843
 
                                   DIV_ROUND_UP(max_cpus * smt, smp_threads),
1844
 
                                   XICS_IRQS_SPAPR, &error_fatal);
 
2044
    xics_system_init(machine, DIV_ROUND_UP(max_cpus * smt, smp_threads),
 
2045
                     XICS_IRQS_SPAPR, &error_fatal);
1845
2046
 
1846
2047
    /* Set up containers for ibm,client-set-architecture negotiated options */
1847
2048
    spapr->ov5 = spapr_ovec_new();
1866
2067
 
1867
2068
    ppc_cpu_parse_features(machine->cpu_model);
1868
2069
 
1869
 
    if (mc->query_hotpluggable_cpus) {
1870
 
        char *type = spapr_get_cpu_core_type(machine->cpu_model);
1871
 
 
1872
 
        if (type == NULL) {
1873
 
            error_report("Unable to find sPAPR CPU Core definition");
1874
 
            exit(1);
1875
 
        }
1876
 
 
1877
 
        spapr->cores = g_new0(Object *, spapr_max_cores);
1878
 
        for (i = 0; i < spapr_max_cores; i++) {
1879
 
            int core_id = i * smp_threads;
1880
 
            sPAPRDRConnector *drc =
1881
 
                spapr_dr_connector_new(OBJECT(spapr),
1882
 
                                       SPAPR_DR_CONNECTOR_TYPE_CPU,
1883
 
                                       (core_id / smp_threads) * smt);
1884
 
 
1885
 
            qemu_register_reset(spapr_drc_reset, drc);
1886
 
 
1887
 
            if (i < spapr_cores) {
1888
 
                Object *core  = object_new(type);
1889
 
                object_property_set_int(core, smp_threads, "nr-threads",
1890
 
                                        &error_fatal);
1891
 
                object_property_set_int(core, core_id, CPU_CORE_PROP_CORE_ID,
1892
 
                                        &error_fatal);
1893
 
                object_property_set_bool(core, true, "realized", &error_fatal);
1894
 
            }
1895
 
        }
1896
 
        g_free(type);
1897
 
    } else {
1898
 
        for (i = 0; i < smp_cpus; i++) {
1899
 
            PowerPCCPU *cpu = cpu_ppc_init(machine->cpu_model);
1900
 
            if (cpu == NULL) {
1901
 
                error_report("Unable to find PowerPC CPU definition");
1902
 
                exit(1);
1903
 
            }
1904
 
            spapr_cpu_init(spapr, cpu, &error_fatal);
1905
 
       }
1906
 
    }
 
2070
    spapr_init_cpus(spapr);
1907
2071
 
1908
2072
    if (kvm_enabled()) {
1909
2073
        /* Enable H_LOGICAL_CI_* so SLOF can talk to in-kernel devices */
2116
2280
    qemu_register_reset(spapr_ccs_reset_hook, spapr);
2117
2281
 
2118
2282
    qemu_register_boot_set(spapr_boot_set, spapr);
 
2283
 
 
2284
    /* to stop and start vmclock */
 
2285
    if (kvm_enabled()) {
 
2286
        qemu_add_vm_change_state_handler(cpu_ppc_clock_vm_state_change,
 
2287
                                         &spapr->tb);
 
2288
    }
2119
2289
}
2120
2290
 
2121
2291
static int spapr_kvm_type(const char *vm_type)
2185
2355
        }
2186
2356
    }
2187
2357
 
 
2358
    /*
 
2359
     * SLOF probes the USB devices, and if it recognizes that the device is a
 
2360
     * storage device, it changes its name to "storage" instead of "usb-host",
 
2361
     * and additionally adds a child node for the SCSI LUN, so the correct
 
2362
     * boot path in SLOF is something like .../storage@1/disk@xxx" instead.
 
2363
     */
 
2364
    if (strcmp("usb-host", qdev_fw_name(dev)) == 0) {
 
2365
        USBDevice *usbdev = CAST(USBDevice, dev, TYPE_USB_DEVICE);
 
2366
        if (usb_host_dev_is_scsi_storage(usbdev)) {
 
2367
            return g_strdup_printf("storage@%s/disk", usbdev->port->path);
 
2368
        }
 
2369
    }
 
2370
 
2188
2371
    if (phb) {
2189
2372
        /* Replace "pci" with "pci@800000020000000" */
2190
2373
        return g_strdup_printf("pci@%"PRIX64, phb->buid);
2252
2435
    g_free(spapr->kvm_type);
2253
2436
}
2254
2437
 
2255
 
static void ppc_cpu_do_nmi_on_cpu(CPUState *cs, run_on_cpu_data arg)
 
2438
void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg)
2256
2439
{
2257
2440
    cpu_synchronize_state(cs);
2258
2441
    ppc_cpu_do_system_reset(cs);
2263
2446
    CPUState *cs;
2264
2447
 
2265
2448
    CPU_FOREACH(cs) {
2266
 
        async_run_on_cpu(cs, ppc_cpu_do_nmi_on_cpu, RUN_ON_CPU_NULL);
 
2449
        async_run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL);
2267
2450
    }
2268
2451
}
2269
2452
 
2325
2508
    uint64_t align = memory_region_get_alignment(mr);
2326
2509
    uint64_t size = memory_region_size(mr);
2327
2510
    uint64_t addr;
 
2511
    char *mem_dev;
2328
2512
 
2329
2513
    if (size % SPAPR_MEMORY_BLOCK_SIZE) {
2330
2514
        error_setg(&local_err, "Hotplugged memory size must be a multiple of "
2332
2516
        goto out;
2333
2517
    }
2334
2518
 
 
2519
    mem_dev = object_property_get_str(OBJECT(dimm), PC_DIMM_MEMDEV_PROP, NULL);
 
2520
    if (mem_dev && !kvmppc_is_mem_backend_page_size_ok(mem_dev)) {
 
2521
        error_setg(&local_err, "Memory backend has bad page size. "
 
2522
                   "Use 'memory-backend-file' with correct mem-path.");
 
2523
        goto out;
 
2524
    }
 
2525
 
2335
2526
    pc_dimm_memory_plug(dev, &ms->hotplug_memory, mr, align, &local_err);
2336
2527
    if (local_err) {
2337
2528
        goto out;
2456
2647
    return fdt;
2457
2648
}
2458
2649
 
 
2650
static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
 
2651
                              Error **errp)
 
2652
{
 
2653
    MachineState *ms = MACHINE(qdev_get_machine());
 
2654
    CPUCore *cc = CPU_CORE(dev);
 
2655
    CPUArchId *core_slot = spapr_find_cpu_slot(ms, cc->core_id, NULL);
 
2656
 
 
2657
    core_slot->cpu = NULL;
 
2658
    object_unparent(OBJECT(dev));
 
2659
}
 
2660
 
 
2661
static void spapr_core_release(DeviceState *dev, void *opaque)
 
2662
{
 
2663
    HotplugHandler *hotplug_ctrl;
 
2664
 
 
2665
    hotplug_ctrl = qdev_get_hotplug_handler(dev);
 
2666
    hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort);
 
2667
}
 
2668
 
 
2669
static
 
2670
void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,
 
2671
                               Error **errp)
 
2672
{
 
2673
    int index;
 
2674
    sPAPRDRConnector *drc;
 
2675
    sPAPRDRConnectorClass *drck;
 
2676
    Error *local_err = NULL;
 
2677
    CPUCore *cc = CPU_CORE(dev);
 
2678
    int smt = kvmppc_smt_threads();
 
2679
 
 
2680
    if (!spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &index)) {
 
2681
        error_setg(errp, "Unable to find CPU core with core-id: %d",
 
2682
                   cc->core_id);
 
2683
        return;
 
2684
    }
 
2685
    if (index == 0) {
 
2686
        error_setg(errp, "Boot CPU core may not be unplugged");
 
2687
        return;
 
2688
    }
 
2689
 
 
2690
    drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, index * smt);
 
2691
    g_assert(drc);
 
2692
 
 
2693
    drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
 
2694
    drck->detach(drc, dev, spapr_core_release, NULL, &local_err);
 
2695
    if (local_err) {
 
2696
        error_propagate(errp, local_err);
 
2697
        return;
 
2698
    }
 
2699
 
 
2700
    spapr_hotplug_req_remove_by_index(drc);
 
2701
}
 
2702
 
 
2703
static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
 
2704
                            Error **errp)
 
2705
{
 
2706
    sPAPRMachineState *spapr = SPAPR_MACHINE(OBJECT(hotplug_dev));
 
2707
    MachineClass *mc = MACHINE_GET_CLASS(spapr);
 
2708
    sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev));
 
2709
    CPUCore *cc = CPU_CORE(dev);
 
2710
    CPUState *cs = CPU(core->threads);
 
2711
    sPAPRDRConnector *drc;
 
2712
    Error *local_err = NULL;
 
2713
    void *fdt = NULL;
 
2714
    int fdt_offset = 0;
 
2715
    int smt = kvmppc_smt_threads();
 
2716
    CPUArchId *core_slot;
 
2717
    int index;
 
2718
 
 
2719
    core_slot = spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &index);
 
2720
    if (!core_slot) {
 
2721
        error_setg(errp, "Unable to find CPU core with core-id: %d",
 
2722
                   cc->core_id);
 
2723
        return;
 
2724
    }
 
2725
    drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, index * smt);
 
2726
 
 
2727
    g_assert(drc || !mc->has_hotpluggable_cpus);
 
2728
 
 
2729
    /*
 
2730
     * Setup CPU DT entries only for hotplugged CPUs. For boot time or
 
2731
     * coldplugged CPUs DT entries are setup in spapr_build_fdt().
 
2732
     */
 
2733
    if (dev->hotplugged) {
 
2734
        fdt = spapr_populate_hotplug_cpu_dt(cs, &fdt_offset, spapr);
 
2735
    }
 
2736
 
 
2737
    if (drc) {
 
2738
        sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
 
2739
        drck->attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, &local_err);
 
2740
        if (local_err) {
 
2741
            g_free(fdt);
 
2742
            error_propagate(errp, local_err);
 
2743
            return;
 
2744
        }
 
2745
    }
 
2746
 
 
2747
    if (dev->hotplugged) {
 
2748
        /*
 
2749
         * Send hotplug notification interrupt to the guest only in case
 
2750
         * of hotplugged CPUs.
 
2751
         */
 
2752
        spapr_hotplug_req_add_by_index(drc);
 
2753
    } else {
 
2754
        /*
 
2755
         * Set the right DRC states for cold plugged CPU.
 
2756
         */
 
2757
        if (drc) {
 
2758
            sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
 
2759
            drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USABLE);
 
2760
            drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_UNISOLATED);
 
2761
        }
 
2762
    }
 
2763
    core_slot->cpu = OBJECT(dev);
 
2764
}
 
2765
 
 
2766
static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
 
2767
                                Error **errp)
 
2768
{
 
2769
    MachineState *machine = MACHINE(OBJECT(hotplug_dev));
 
2770
    MachineClass *mc = MACHINE_GET_CLASS(hotplug_dev);
 
2771
    Error *local_err = NULL;
 
2772
    CPUCore *cc = CPU_CORE(dev);
 
2773
    char *base_core_type = spapr_get_cpu_core_type(machine->cpu_model);
 
2774
    const char *type = object_get_typename(OBJECT(dev));
 
2775
    CPUArchId *core_slot;
 
2776
    int index;
 
2777
 
 
2778
    if (dev->hotplugged && !mc->has_hotpluggable_cpus) {
 
2779
        error_setg(&local_err, "CPU hotplug not supported for this machine");
 
2780
        goto out;
 
2781
    }
 
2782
 
 
2783
    if (strcmp(base_core_type, type)) {
 
2784
        error_setg(&local_err, "CPU core type should be %s", base_core_type);
 
2785
        goto out;
 
2786
    }
 
2787
 
 
2788
    if (cc->core_id % smp_threads) {
 
2789
        error_setg(&local_err, "invalid core id %d", cc->core_id);
 
2790
        goto out;
 
2791
    }
 
2792
 
 
2793
    if (cc->nr_threads != smp_threads) {
 
2794
        error_setg(errp, "invalid nr-threads %d, must be %d",
 
2795
                   cc->nr_threads, smp_threads);
 
2796
        return;
 
2797
    }
 
2798
 
 
2799
    core_slot = spapr_find_cpu_slot(MACHINE(hotplug_dev), cc->core_id, &index);
 
2800
    if (!core_slot) {
 
2801
        error_setg(&local_err, "core id %d out of range", cc->core_id);
 
2802
        goto out;
 
2803
    }
 
2804
 
 
2805
    if (core_slot->cpu) {
 
2806
        error_setg(&local_err, "core %d already populated", cc->core_id);
 
2807
        goto out;
 
2808
    }
 
2809
 
 
2810
out:
 
2811
    g_free(base_core_type);
 
2812
    error_propagate(errp, local_err);
 
2813
}
 
2814
 
2459
2815
static void spapr_machine_device_plug(HotplugHandler *hotplug_dev,
2460
2816
                                      DeviceState *dev, Error **errp)
2461
2817
{
2518
2874
            error_setg(errp, "Memory hot unplug not supported for this guest");
2519
2875
        }
2520
2876
    } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) {
2521
 
        if (!mc->query_hotpluggable_cpus) {
 
2877
        if (!mc->has_hotpluggable_cpus) {
2522
2878
            error_setg(errp, "CPU hot unplug not supported on this machine");
2523
2879
            return;
2524
2880
        }
2545
2901
            error_setg(errp, "Memory hot unplug not supported for this guest");
2546
2902
        }
2547
2903
    } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) {
2548
 
        if (!mc->query_hotpluggable_cpus) {
 
2904
        if (!mc->has_hotpluggable_cpus) {
2549
2905
            error_setg(errp, "CPU hot unplug not supported on this machine");
2550
2906
            return;
2551
2907
        }
2552
 
        spapr_core_unplug(hotplug_dev, dev, errp);
 
2908
        spapr_core_unplug_request(hotplug_dev, dev, errp);
2553
2909
    }
2554
2910
}
2555
2911
 
2578
2934
    return cpu_index / smp_threads / smp_cores;
2579
2935
}
2580
2936
 
2581
 
static HotpluggableCPUList *spapr_query_hotpluggable_cpus(MachineState *machine)
 
2937
static const CPUArchIdList *spapr_possible_cpu_arch_ids(MachineState *machine)
2582
2938
{
2583
2939
    int i;
2584
 
    HotpluggableCPUList *head = NULL;
2585
 
    sPAPRMachineState *spapr = SPAPR_MACHINE(machine);
2586
2940
    int spapr_max_cores = max_cpus / smp_threads;
2587
 
 
2588
 
    for (i = 0; i < spapr_max_cores; i++) {
2589
 
        HotpluggableCPUList *list_item = g_new0(typeof(*list_item), 1);
2590
 
        HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1);
2591
 
        CpuInstanceProperties *cpu_props = g_new0(typeof(*cpu_props), 1);
2592
 
 
2593
 
        cpu_item->type = spapr_get_cpu_core_type(machine->cpu_model);
2594
 
        cpu_item->vcpus_count = smp_threads;
2595
 
        cpu_props->has_core_id = true;
2596
 
        cpu_props->core_id = i * smp_threads;
 
2941
    MachineClass *mc = MACHINE_GET_CLASS(machine);
 
2942
 
 
2943
    if (!mc->has_hotpluggable_cpus) {
 
2944
        spapr_max_cores = QEMU_ALIGN_UP(smp_cpus, smp_threads) / smp_threads;
 
2945
    }
 
2946
    if (machine->possible_cpus) {
 
2947
        assert(machine->possible_cpus->len == spapr_max_cores);
 
2948
        return machine->possible_cpus;
 
2949
    }
 
2950
 
 
2951
    machine->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
 
2952
                             sizeof(CPUArchId) * spapr_max_cores);
 
2953
    machine->possible_cpus->len = spapr_max_cores;
 
2954
    for (i = 0; i < machine->possible_cpus->len; i++) {
 
2955
        int core_id = i * smp_threads;
 
2956
 
 
2957
        machine->possible_cpus->cpus[i].vcpus_count = smp_threads;
 
2958
        machine->possible_cpus->cpus[i].arch_id = core_id;
 
2959
        machine->possible_cpus->cpus[i].props.has_core_id = true;
 
2960
        machine->possible_cpus->cpus[i].props.core_id = core_id;
2597
2961
        /* TODO: add 'has_node/node' here to describe
2598
2962
           to which node core belongs */
2599
 
 
2600
 
        cpu_item->props = cpu_props;
2601
 
        if (spapr->cores[i]) {
2602
 
            cpu_item->has_qom_path = true;
2603
 
            cpu_item->qom_path = object_get_canonical_path(spapr->cores[i]);
2604
 
        }
2605
 
        list_item->value = cpu_item;
2606
 
        list_item->next = head;
2607
 
        head = list_item;
2608
2963
    }
2609
 
    return head;
 
2964
    return machine->possible_cpus;
2610
2965
}
2611
2966
 
2612
2967
static void spapr_phb_placement(sPAPRMachineState *spapr, uint32_t index,
2630
2985
     * 1TiB 64-bit MMIO windows for each PHB.
2631
2986
     */
2632
2987
    const uint64_t base_buid = 0x800000020000000ULL;
2633
 
    const int max_phbs =
2634
 
        (SPAPR_PCI_LIMIT - SPAPR_PCI_BASE) / SPAPR_PCI_MEM64_WIN_SIZE - 1;
 
2988
#define SPAPR_MAX_PHBS ((SPAPR_PCI_LIMIT - SPAPR_PCI_BASE) / \
 
2989
                        SPAPR_PCI_MEM64_WIN_SIZE - 1)
2635
2990
    int i;
2636
2991
 
2637
2992
    /* Sanity check natural alignments */
2640
2995
    QEMU_BUILD_BUG_ON((SPAPR_PCI_MEM64_WIN_SIZE % SPAPR_PCI_MEM32_WIN_SIZE) != 0);
2641
2996
    QEMU_BUILD_BUG_ON((SPAPR_PCI_MEM32_WIN_SIZE % SPAPR_PCI_IO_WIN_SIZE) != 0);
2642
2997
    /* Sanity check bounds */
2643
 
    QEMU_BUILD_BUG_ON((max_phbs * SPAPR_PCI_IO_WIN_SIZE) > SPAPR_PCI_MEM32_WIN_SIZE);
2644
 
    QEMU_BUILD_BUG_ON((max_phbs * SPAPR_PCI_MEM32_WIN_SIZE) > SPAPR_PCI_MEM64_WIN_SIZE);
 
2998
    QEMU_BUILD_BUG_ON((SPAPR_MAX_PHBS * SPAPR_PCI_IO_WIN_SIZE) >
 
2999
                      SPAPR_PCI_MEM32_WIN_SIZE);
 
3000
    QEMU_BUILD_BUG_ON((SPAPR_MAX_PHBS * SPAPR_PCI_MEM32_WIN_SIZE) >
 
3001
                      SPAPR_PCI_MEM64_WIN_SIZE);
2645
3002
 
2646
 
    if (index >= max_phbs) {
2647
 
        error_setg(errp, "\"index\" for PAPR PHB is too large (max %u)",
2648
 
                   max_phbs - 1);
 
3003
    if (index >= SPAPR_MAX_PHBS) {
 
3004
        error_setg(errp, "\"index\" for PAPR PHB is too large (max %llu)",
 
3005
                   SPAPR_MAX_PHBS - 1);
2649
3006
        return;
2650
3007
    }
2651
3008
 
2659
3016
    *mmio64 = SPAPR_PCI_BASE + (index + 1) * SPAPR_PCI_MEM64_WIN_SIZE;
2660
3017
}
2661
3018
 
 
3019
static ICSState *spapr_ics_get(XICSFabric *dev, int irq)
 
3020
{
 
3021
    sPAPRMachineState *spapr = SPAPR_MACHINE(dev);
 
3022
 
 
3023
    return ics_valid_irq(spapr->ics, irq) ? spapr->ics : NULL;
 
3024
}
 
3025
 
 
3026
static void spapr_ics_resend(XICSFabric *dev)
 
3027
{
 
3028
    sPAPRMachineState *spapr = SPAPR_MACHINE(dev);
 
3029
 
 
3030
    ics_resend(spapr->ics);
 
3031
}
 
3032
 
 
3033
static ICPState *spapr_icp_get(XICSFabric *xi, int server)
 
3034
{
 
3035
    sPAPRMachineState *spapr = SPAPR_MACHINE(xi);
 
3036
 
 
3037
    return (server < spapr->nr_servers) ? &spapr->icps[server] : NULL;
 
3038
}
 
3039
 
 
3040
static void spapr_pic_print_info(InterruptStatsProvider *obj,
 
3041
                                 Monitor *mon)
 
3042
{
 
3043
    sPAPRMachineState *spapr = SPAPR_MACHINE(obj);
 
3044
    int i;
 
3045
 
 
3046
    for (i = 0; i < spapr->nr_servers; i++) {
 
3047
        icp_pic_print_info(&spapr->icps[i], mon);
 
3048
    }
 
3049
 
 
3050
    ics_pic_print_info(spapr->ics, mon);
 
3051
}
 
3052
 
2662
3053
static void spapr_machine_class_init(ObjectClass *oc, void *data)
2663
3054
{
2664
3055
    MachineClass *mc = MACHINE_CLASS(oc);
2666
3057
    FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc);
2667
3058
    NMIClass *nc = NMI_CLASS(oc);
2668
3059
    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
 
3060
    PPCVirtualHypervisorClass *vhc = PPC_VIRTUAL_HYPERVISOR_CLASS(oc);
 
3061
    XICSFabricClass *xic = XICS_FABRIC_CLASS(oc);
 
3062
    InterruptStatsProviderClass *ispc = INTERRUPT_STATS_PROVIDER_CLASS(oc);
2669
3063
 
2670
3064
    mc->desc = "pSeries Logical Partition (PAPR compliant)";
2671
3065
 
2677
3071
    mc->init = ppc_spapr_init;
2678
3072
    mc->reset = ppc_spapr_reset;
2679
3073
    mc->block_default_type = IF_SCSI;
2680
 
    mc->max_cpus = 255;
 
3074
    mc->max_cpus = 1024;
2681
3075
    mc->no_parallel = 1;
2682
3076
    mc->default_boot_order = "";
2683
3077
    mc->default_ram_size = 512 * M_BYTE;
2689
3083
    hc->plug = spapr_machine_device_plug;
2690
3084
    hc->unplug = spapr_machine_device_unplug;
2691
3085
    mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id;
 
3086
    mc->possible_cpu_arch_ids = spapr_possible_cpu_arch_ids;
2692
3087
    hc->unplug_request = spapr_machine_device_unplug_request;
2693
3088
 
2694
3089
    smc->dr_lmb_enabled = true;
2695
3090
    smc->tcg_default_cpu = "POWER8";
2696
 
    mc->query_hotpluggable_cpus = spapr_query_hotpluggable_cpus;
 
3091
    mc->has_hotpluggable_cpus = true;
2697
3092
    fwc->get_dev_path = spapr_get_fw_dev_path;
2698
3093
    nc->nmi_monitor_handler = spapr_nmi;
2699
3094
    smc->phb_placement = spapr_phb_placement;
 
3095
    vhc->hypercall = emulate_spapr_hypercall;
 
3096
    vhc->hpt_mask = spapr_hpt_mask;
 
3097
    vhc->map_hptes = spapr_map_hptes;
 
3098
    vhc->unmap_hptes = spapr_unmap_hptes;
 
3099
    vhc->store_hpte = spapr_store_hpte;
 
3100
    vhc->get_patbe = spapr_get_patbe;
 
3101
    xic->ics_get = spapr_ics_get;
 
3102
    xic->ics_resend = spapr_ics_resend;
 
3103
    xic->icp_get = spapr_icp_get;
 
3104
    ispc->print_info = spapr_pic_print_info;
 
3105
    /* Force NUMA node memory size to be a multiple of
 
3106
     * SPAPR_MEMORY_BLOCK_SIZE (256M) since that's the granularity
 
3107
     * in which LMBs are represented and hot-added
 
3108
     */
 
3109
    mc->numa_mem_align_shift = 28;
2700
3110
}
2701
3111
 
2702
3112
static const TypeInfo spapr_machine_info = {
2712
3122
        { TYPE_FW_PATH_PROVIDER },
2713
3123
        { TYPE_NMI },
2714
3124
        { TYPE_HOTPLUG_HANDLER },
 
3125
        { TYPE_PPC_VIRTUAL_HYPERVISOR },
 
3126
        { TYPE_XICS_FABRIC },
 
3127
        { TYPE_INTERRUPT_STATS_PROVIDER },
2715
3128
        { }
2716
3129
    },
2717
3130
};
2745
3158
    type_init(spapr_machine_register_##suffix)
2746
3159
 
2747
3160
/*
 
3161
 * pseries-2.9
 
3162
 */
 
3163
static void spapr_machine_2_9_instance_options(MachineState *machine)
 
3164
{
 
3165
}
 
3166
 
 
3167
static void spapr_machine_2_9_class_options(MachineClass *mc)
 
3168
{
 
3169
    /* Defaults for the latest behaviour inherited from the base class */
 
3170
}
 
3171
 
 
3172
DEFINE_SPAPR_MACHINE(2_9, "2.9", true);
 
3173
 
 
3174
/*
2748
3175
 * pseries-2.8
2749
3176
 */
 
3177
#define SPAPR_COMPAT_2_8                                        \
 
3178
    HW_COMPAT_2_8                                               \
 
3179
    {                                                           \
 
3180
        .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,                 \
 
3181
        .property = "pcie-extended-configuration-space",        \
 
3182
        .value    = "off",                                      \
 
3183
    },
 
3184
 
2750
3185
static void spapr_machine_2_8_instance_options(MachineState *machine)
2751
3186
{
 
3187
    spapr_machine_2_9_instance_options(machine);
2752
3188
}
2753
3189
 
2754
3190
static void spapr_machine_2_8_class_options(MachineClass *mc)
2755
3191
{
2756
 
    /* Defaults for the latest behaviour inherited from the base class */
 
3192
    spapr_machine_2_9_class_options(mc);
 
3193
    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_8);
 
3194
    mc->numa_mem_align_shift = 23;
2757
3195
}
2758
3196
 
2759
 
DEFINE_SPAPR_MACHINE(2_8, "2.8", true);
 
3197
DEFINE_SPAPR_MACHINE(2_8, "2.8", false);
2760
3198
 
2761
3199
/*
2762
3200
 * pseries-2.7
2872
3310
static void spapr_machine_2_6_class_options(MachineClass *mc)
2873
3311
{
2874
3312
    spapr_machine_2_7_class_options(mc);
2875
 
    mc->query_hotpluggable_cpus = NULL;
 
3313
    mc->has_hotpluggable_cpus = false;
2876
3314
    SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_6);
2877
3315
}
2878
3316