xref: /qemu/hw/tricore/triboard.c (revision 513823e7521a09ed7ad1e32e6454bac3b2cbf52d)
1 /*
2  * Infineon TriBoard System emulation.
3  *
4  * Copyright (c) 2020 Andreas Konopik <andreas.konopik@efs-auto.de>
5  * Copyright (c) 2020 David Brenken <david.brenken@efs-auto.de>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "qemu/osdep.h"
22 #include "qemu/units.h"
23 #include "qapi/error.h"
24 #include "hw/qdev-properties.h"
25 #include "net/net.h"
26 #include "hw/loader.h"
27 #include "elf.h"
28 #include "hw/tricore/tricore.h"
29 #include "qemu/error-report.h"
30 
31 #include "hw/tricore/triboard.h"
32 #include "hw/tricore/tc27x_soc.h"
33 
34 static void tricore_load_kernel(TriCoreCPU *cpu, const char *kernel_filename)
35 {
36     uint64_t entry;
37     long kernel_size;
38     CPUTriCoreState *env;
39 
40     kernel_size = load_elf(kernel_filename, NULL,
41                            NULL, NULL, &entry, NULL,
42                            NULL, NULL, ELFDATA2LSB,
43                            EM_TRICORE, 1, 0);
44     if (kernel_size <= 0) {
45         error_report("no kernel file '%s'", kernel_filename);
46         exit(1);
47     }
48     env = &cpu->env;
49     env->PC = entry;
50 }
51 
52 
53 static void triboard_machine_init(MachineState *machine)
54 {
55     TriBoardMachineState *ms = TRIBOARD_MACHINE(machine);
56     TriBoardMachineClass *amc = TRIBOARD_MACHINE_GET_CLASS(machine);
57 
58     object_initialize_child(OBJECT(machine), "soc", &ms->tc27x_soc,
59             amc->soc_name);
60     sysbus_realize(SYS_BUS_DEVICE(&ms->tc27x_soc), &error_fatal);
61 
62     if (machine->kernel_filename) {
63         tricore_load_kernel(&ms->tc27x_soc.cpu, machine->kernel_filename);
64     }
65 }
66 
67 static void triboard_machine_tc277d_class_init(ObjectClass *oc,
68         void *data)
69 {
70     MachineClass *mc = MACHINE_CLASS(oc);
71     TriBoardMachineClass *amc = TRIBOARD_MACHINE_CLASS(oc);
72 
73     mc->init        = triboard_machine_init;
74     mc->desc        = "Infineon AURIX TriBoard TC277 (D-Step)";
75     mc->max_cpus    = 1;
76     amc->soc_name   = "tc277d-soc";
77 };
78 
79 static const TypeInfo triboard_machine_types[] = {
80     {
81         .name           = MACHINE_TYPE_NAME("KIT_AURIX_TC277_TRB"),
82         .parent         = TYPE_TRIBOARD_MACHINE,
83         .class_init     = triboard_machine_tc277d_class_init,
84     }, {
85         .name           = TYPE_TRIBOARD_MACHINE,
86         .parent         = TYPE_MACHINE,
87         .instance_size  = sizeof(TriBoardMachineState),
88         .class_size     = sizeof(TriBoardMachineClass),
89         .abstract       = true,
90     },
91 };
92 
93 DEFINE_TYPES(triboard_machine_types)
94