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