]> git.proxmox.com Git - qemu.git/blame - hw/petalogix_s3adsp1800_mmu.c
user: Restore debug usage message for '-d ?' in user mode emulation
[qemu.git] / hw / petalogix_s3adsp1800_mmu.c
CommitLineData
6a8b1ae2
EI
1/*
2 * Model of Petalogix linux reference design targeting Xilinx Spartan 3ADSP-1800
3 * boards.
4 *
5 * Copyright (c) 2009 Edgar E. Iglesias.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
26#include "sysbus.h"
27#include "hw.h"
28#include "net.h"
29#include "flash.h"
30#include "sysemu.h"
31#include "devices.h"
32#include "boards.h"
33#include "device_tree.h"
34#include "xilinx.h"
ca20cf32
BS
35#include "loader.h"
36#include "elf.h"
2446333c 37#include "blockdev.h"
6a8b1ae2
EI
38
39#define LMB_BRAM_SIZE (128 * 1024)
40#define FLASH_SIZE (16 * 1024 * 1024)
41
7029a83b 42static struct
b4d34d5e
EI
43{
44 uint32_t bootstrap_pc;
45 uint32_t cmdline;
46 uint32_t fdt;
47} boot_info;
6a8b1ae2
EI
48
49static void main_cpu_reset(void *opaque)
50{
51 CPUState *env = opaque;
be5e8349
EI
52
53 cpu_reset(env);
b4d34d5e
EI
54 env->regs[5] = boot_info.cmdline;
55 env->regs[7] = boot_info.fdt;
56 env->sregs[SR_PC] = boot_info.bootstrap_pc;
6a8b1ae2
EI
57}
58
59#define BINARY_DEVICE_TREE_FILE "petalogix-s3adsp1800.dtb"
c227f099 60static int petalogix_load_device_tree(target_phys_addr_t addr,
6a8b1ae2 61 uint32_t ramsize,
c227f099
AL
62 target_phys_addr_t initrd_base,
63 target_phys_addr_t initrd_size,
6a8b1ae2
EI
64 const char *kernel_cmdline)
65{
84f15818
JQ
66 char *path;
67 int fdt_size;
3f0855b1 68#ifdef CONFIG_FDT
6a8b1ae2 69 void *fdt;
6a8b1ae2
EI
70 int r;
71
72 /* Try the local "mb.dtb" override. */
73 fdt = load_device_tree("mb.dtb", &fdt_size);
74 if (!fdt) {
4b0c7aa3
EI
75 path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
76 if (path) {
77 fdt = load_device_tree(path, &fdt_size);
78 qemu_free(path);
79 }
6a8b1ae2
EI
80 if (!fdt)
81 return 0;
82 }
83
84 r = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", kernel_cmdline);
85 if (r < 0)
86 fprintf(stderr, "couldn't set /chosen/bootargs\n");
6a8b1ae2 87 cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
7696d1ec
EI
88#else
89 /* We lack libfdt so we cannot manipulate the fdt. Just pass on the blob
90 to the kernel. */
91 fdt_size = load_image_targphys("mb.dtb", addr, 0x10000);
92 if (fdt_size < 0) {
4b0c7aa3
EI
93 path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
94 if (path) {
95 fdt_size = load_image_targphys(path, addr, 0x10000);
96 qemu_free(path);
97 }
7696d1ec
EI
98 }
99
100 if (kernel_cmdline) {
101 fprintf(stderr,
102 "Warning: missing libfdt, cannot pass cmdline to kernel!\n");
103 }
104#endif
6a8b1ae2
EI
105 return fdt_size;
106}
107
409dbce5
AJ
108static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
109{
110 return addr - 0x30000000LL;
111}
112
6a8b1ae2 113static void
c227f099 114petalogix_s3adsp1800_init(ram_addr_t ram_size,
6a8b1ae2
EI
115 const char *boot_device,
116 const char *kernel_filename,
117 const char *kernel_cmdline,
118 const char *initrd_filename, const char *cpu_model)
119{
120 DeviceState *dev;
121 CPUState *env;
122 int kernel_size;
751c6a17 123 DriveInfo *dinfo;
6a8b1ae2 124 int i;
c227f099
AL
125 target_phys_addr_t ddr_base = 0x90000000;
126 ram_addr_t phys_lmb_bram;
127 ram_addr_t phys_ram;
128 ram_addr_t phys_flash;
6a8b1ae2
EI
129 qemu_irq irq[32], *cpu_irq;
130
131 /* init CPUs */
132 if (cpu_model == NULL) {
133 cpu_model = "microblaze";
134 }
135 env = cpu_init(cpu_model);
136
137 env->pvr.regs[10] = 0x0c000000; /* spartan 3a dsp family. */
a08d4367 138 qemu_register_reset(main_cpu_reset, env);
6a8b1ae2
EI
139
140 /* Attach emulated BRAM through the LMB. */
1724f049
AW
141 phys_lmb_bram = qemu_ram_alloc(NULL, "petalogix_s3adsp1800.lmb_bram",
142 LMB_BRAM_SIZE);
6a8b1ae2
EI
143 cpu_register_physical_memory(0x00000000, LMB_BRAM_SIZE,
144 phys_lmb_bram | IO_MEM_RAM);
145
1724f049 146 phys_ram = qemu_ram_alloc(NULL, "petalogix_s3adsp1800.ram", ram_size);
6a8b1ae2
EI
147 cpu_register_physical_memory(ddr_base, ram_size, phys_ram | IO_MEM_RAM);
148
1724f049 149 phys_flash = qemu_ram_alloc(NULL, "petalogix_s3adsp1800.flash", FLASH_SIZE);
751c6a17 150 dinfo = drive_get(IF_PFLASH, 0, 0);
2548de3a 151 pflash_cfi01_register(0xa0000000, phys_flash,
751c6a17 152 dinfo ? dinfo->bdrv : NULL, (64 * 1024),
6a8b1ae2 153 FLASH_SIZE >> 16,
3d08ff69 154 1, 0x89, 0x18, 0x0000, 0x0, 1);
6a8b1ae2
EI
155
156 cpu_irq = microblaze_pic_init_cpu(env);
157 dev = xilinx_intc_create(0x81800000, cpu_irq[0], 2);
158 for (i = 0; i < 32; i++) {
159 irq[i] = qdev_get_gpio_in(dev, i);
160 }
161
162 sysbus_create_simple("xilinx,uartlite", 0x84000000, irq[3]);
163 /* 2 timers at irq 2 @ 62 Mhz. */
164 xilinx_timer_create(0x83c00000, irq[0], 2, 62 * 1000000);
165 xilinx_ethlite_create(&nd_table[0], 0x81000000, irq[1], 0, 0);
166
167 if (kernel_filename) {
168 uint64_t entry, low, high;
6a8b1ae2 169 uint32_t base32;
082e5be8
EI
170 int big_endian = 0;
171
172#ifdef TARGET_WORDS_BIGENDIAN
173 big_endian = 1;
174#endif
6a8b1ae2
EI
175
176 /* Boots a kernel elf binary. */
409dbce5 177 kernel_size = load_elf(kernel_filename, NULL, NULL,
ca20cf32 178 &entry, &low, &high,
082e5be8 179 big_endian, ELF_MACHINE, 0);
6a8b1ae2
EI
180 base32 = entry;
181 if (base32 == 0xc0000000) {
409dbce5
AJ
182 kernel_size = load_elf(kernel_filename, translate_kernel_address,
183 NULL, &entry, NULL, NULL,
082e5be8 184 big_endian, ELF_MACHINE, 0);
6a8b1ae2
EI
185 }
186 /* Always boot into physical ram. */
b4d34d5e 187 boot_info.bootstrap_pc = ddr_base + (entry & 0x0fffffff);
872a91b4
EI
188
189 /* If it wasn't an ELF image, try an u-boot image. */
190 if (kernel_size < 0) {
191 target_phys_addr_t uentry, loadaddr;
192
193 kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0);
194 boot_info.bootstrap_pc = uentry;
195 high = (loadaddr + kernel_size + 3) & ~3;
196 }
197
198 /* Not an ELF image nor an u-boot image, try a RAW image. */
6a8b1ae2 199 if (kernel_size < 0) {
6a8b1ae2
EI
200 kernel_size = load_image_targphys(kernel_filename, ddr_base,
201 ram_size);
b4d34d5e 202 boot_info.bootstrap_pc = ddr_base;
811976dc 203 high = (ddr_base + kernel_size + 3) & ~3;
6a8b1ae2
EI
204 }
205
7375c86f 206 boot_info.cmdline = high + 4096;
183aa454 207 if (kernel_cmdline && strlen(kernel_cmdline)) {
b4d34d5e 208 pstrcpy_targphys("cmdline", boot_info.cmdline, 256, kernel_cmdline);
6a8b1ae2 209 }
6a8b1ae2 210 /* Provide a device-tree. */
7375c86f 211 boot_info.fdt = boot_info.cmdline + 4096;
b4d34d5e
EI
212 petalogix_load_device_tree(boot_info.fdt, ram_size,
213 0, 0,
6a8b1ae2
EI
214 kernel_cmdline);
215 }
6a8b1ae2
EI
216}
217
218static QEMUMachine petalogix_s3adsp1800_machine = {
219 .name = "petalogix-s3adsp1800",
73ad9e62 220 .desc = "PetaLogix linux refdesign for xilinx Spartan 3ADSP1800",
6a8b1ae2
EI
221 .init = petalogix_s3adsp1800_init,
222 .is_default = 1
223};
224
225static void petalogix_s3adsp1800_machine_init(void)
226{
227 qemu_register_machine(&petalogix_s3adsp1800_machine);
228}
229
230machine_init(petalogix_s3adsp1800_machine_init);