s390x: upgrade status of KVM cores to "supported"
[qemu/ar7.git] / hw / riscv / riscv_hart.c
blobe34a26a0ef25c6f1897ff8b19472dfcf8f27f157
1 /*
2 * QEMU RISCV Hart Array
4 * Copyright (c) 2017 SiFive, Inc.
6 * Holds the state of a heterogenous array of RISC-V harts
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2 or later, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
23 #include "hw/sysbus.h"
24 #include "target/riscv/cpu.h"
25 #include "hw/riscv/riscv_hart.h"
27 static Property riscv_harts_props[] = {
28 DEFINE_PROP_UINT32("num-harts", RISCVHartArrayState, num_harts, 1),
29 DEFINE_PROP_STRING("cpu-type", RISCVHartArrayState, cpu_type),
30 DEFINE_PROP_END_OF_LIST(),
33 static void riscv_harts_cpu_reset(void *opaque)
35 RISCVCPU *cpu = opaque;
36 cpu_reset(CPU(cpu));
39 static void riscv_harts_realize(DeviceState *dev, Error **errp)
41 RISCVHartArrayState *s = RISCV_HART_ARRAY(dev);
42 Error *err = NULL;
43 int n;
45 s->harts = g_new0(RISCVCPU, s->num_harts);
47 for (n = 0; n < s->num_harts; n++) {
48 object_initialize_child(OBJECT(s), "harts[*]", &s->harts[n],
49 sizeof(RISCVCPU), s->cpu_type,
50 &error_abort, NULL);
51 s->harts[n].env.mhartid = n;
52 qemu_register_reset(riscv_harts_cpu_reset, &s->harts[n]);
53 object_property_set_bool(OBJECT(&s->harts[n]), true,
54 "realized", &err);
55 if (err) {
56 error_propagate(errp, err);
57 return;
62 static void riscv_harts_class_init(ObjectClass *klass, void *data)
64 DeviceClass *dc = DEVICE_CLASS(klass);
66 dc->props = riscv_harts_props;
67 dc->realize = riscv_harts_realize;
70 static const TypeInfo riscv_harts_info = {
71 .name = TYPE_RISCV_HART_ARRAY,
72 .parent = TYPE_SYS_BUS_DEVICE,
73 .instance_size = sizeof(RISCVHartArrayState),
74 .class_init = riscv_harts_class_init,
77 static void riscv_harts_register_types(void)
79 type_register_static(&riscv_harts_info);
82 type_init(riscv_harts_register_types)