xref: /openbmc/qemu/hw/tricore/tricore_testboard.c (revision da34e65c)
1 /*
2  * TriCore Baseboard System emulation.
3  *
4  * Copyright (c) 2013-2014 Bastian Koppelmann C-Lab/University Paderborn
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
23 #include "hw/hw.h"
24 #include "hw/devices.h"
25 #include "net/net.h"
26 #include "sysemu/sysemu.h"
27 #include "hw/boards.h"
28 #include "hw/loader.h"
29 #include "sysemu/block-backend.h"
30 #include "exec/address-spaces.h"
31 #include "hw/block/flash.h"
32 #include "elf.h"
33 #include "hw/tricore/tricore.h"
34 #include "qemu/error-report.h"
35 
36 
37 /* Board init.  */
38 
39 static struct tricore_boot_info tricoretb_binfo;
40 
41 static void tricore_load_kernel(CPUTriCoreState *env)
42 {
43     uint64_t entry;
44     long kernel_size;
45 
46     kernel_size = load_elf(tricoretb_binfo.kernel_filename, NULL,
47                            NULL, (uint64_t *)&entry, NULL,
48                            NULL, 0,
49                            EM_TRICORE, 1, 0);
50     if (kernel_size <= 0) {
51         error_report("qemu: no kernel file '%s'",
52                 tricoretb_binfo.kernel_filename);
53         exit(1);
54     }
55     env->PC = entry;
56 
57 }
58 
59 static void tricore_testboard_init(MachineState *machine, int board_id)
60 {
61     TriCoreCPU *cpu;
62     CPUTriCoreState *env;
63 
64     MemoryRegion *sysmem = get_system_memory();
65     MemoryRegion *ext_cram = g_new(MemoryRegion, 1);
66     MemoryRegion *ext_dram = g_new(MemoryRegion, 1);
67     MemoryRegion *int_cram = g_new(MemoryRegion, 1);
68     MemoryRegion *int_dram = g_new(MemoryRegion, 1);
69     MemoryRegion *pcp_data = g_new(MemoryRegion, 1);
70     MemoryRegion *pcp_text = g_new(MemoryRegion, 1);
71 
72     if (!machine->cpu_model) {
73         machine->cpu_model = "tc1796";
74     }
75     cpu = cpu_tricore_init(machine->cpu_model);
76     if (!cpu) {
77         error_report("Unable to find CPU definition");
78         exit(1);
79     }
80     env = &cpu->env;
81     memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram", 2*1024*1024,
82                            &error_fatal);
83     vmstate_register_ram_global(ext_cram);
84     memory_region_init_ram(ext_dram, NULL, "powerlink_ext_d.ram", 4*1024*1024,
85                            &error_fatal);
86     vmstate_register_ram_global(ext_dram);
87     memory_region_init_ram(int_cram, NULL, "powerlink_int_c.ram", 48*1024,
88                            &error_fatal);
89     vmstate_register_ram_global(int_cram);
90     memory_region_init_ram(int_dram, NULL, "powerlink_int_d.ram", 48*1024,
91                            &error_fatal);
92     vmstate_register_ram_global(int_dram);
93     memory_region_init_ram(pcp_data, NULL, "powerlink_pcp_data.ram", 16*1024,
94                            &error_fatal);
95     vmstate_register_ram_global(pcp_data);
96     memory_region_init_ram(pcp_text, NULL, "powerlink_pcp_text.ram", 32*1024,
97                            &error_fatal);
98     vmstate_register_ram_global(pcp_text);
99 
100     memory_region_add_subregion(sysmem, 0x80000000, ext_cram);
101     memory_region_add_subregion(sysmem, 0xa1000000, ext_dram);
102     memory_region_add_subregion(sysmem, 0xd4000000, int_cram);
103     memory_region_add_subregion(sysmem, 0xd0000000, int_dram);
104     memory_region_add_subregion(sysmem, 0xf0050000, pcp_data);
105     memory_region_add_subregion(sysmem, 0xf0060000, pcp_text);
106 
107     tricoretb_binfo.ram_size = machine->ram_size;
108     tricoretb_binfo.kernel_filename = machine->kernel_filename;
109 
110     if (machine->kernel_filename) {
111         tricore_load_kernel(env);
112     }
113 }
114 
115 static void tricoreboard_init(MachineState *machine)
116 {
117     tricore_testboard_init(machine, 0x183);
118 }
119 
120 static void ttb_machine_init(MachineClass *mc)
121 {
122     mc->desc = "a minimal TriCore board";
123     mc->init = tricoreboard_init;
124     mc->is_default = 0;
125 }
126 
127 DEFINE_MACHINE("tricore_testboard", ttb_machine_init)
128