root / hw / petalogix_s3adsp1800_mmu.c @ 28366c3a
History | View | Annotate | Download (6.8 kB)
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" |
35 |
#include "loader.h" |
36 |
#include "elf.h" |
37 |
|
38 |
#define LMB_BRAM_SIZE (128 * 1024) |
39 |
#define FLASH_SIZE (16 * 1024 * 1024) |
40 |
|
41 |
static uint32_t bootstrap_pc;
|
42 |
|
43 |
static void main_cpu_reset(void *opaque) |
44 |
{ |
45 |
CPUState *env = opaque; |
46 |
cpu_reset(env); |
47 |
env->sregs[SR_PC] = bootstrap_pc; |
48 |
} |
49 |
|
50 |
#define BINARY_DEVICE_TREE_FILE "petalogix-s3adsp1800.dtb" |
51 |
static int petalogix_load_device_tree(target_phys_addr_t addr, |
52 |
uint32_t ramsize, |
53 |
target_phys_addr_t initrd_base, |
54 |
target_phys_addr_t initrd_size, |
55 |
const char *kernel_cmdline) |
56 |
{ |
57 |
char *path;
|
58 |
int fdt_size;
|
59 |
#ifdef CONFIG_FDT
|
60 |
void *fdt;
|
61 |
int r;
|
62 |
|
63 |
/* Try the local "mb.dtb" override. */
|
64 |
fdt = load_device_tree("mb.dtb", &fdt_size);
|
65 |
if (!fdt) {
|
66 |
path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE); |
67 |
if (path) {
|
68 |
fdt = load_device_tree(path, &fdt_size); |
69 |
qemu_free(path); |
70 |
} |
71 |
if (!fdt)
|
72 |
return 0; |
73 |
} |
74 |
|
75 |
r = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", kernel_cmdline); |
76 |
if (r < 0) |
77 |
fprintf(stderr, "couldn't set /chosen/bootargs\n");
|
78 |
cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
|
79 |
#else
|
80 |
/* We lack libfdt so we cannot manipulate the fdt. Just pass on the blob
|
81 |
to the kernel. */
|
82 |
fdt_size = load_image_targphys("mb.dtb", addr, 0x10000); |
83 |
if (fdt_size < 0) { |
84 |
path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE); |
85 |
if (path) {
|
86 |
fdt_size = load_image_targphys(path, addr, 0x10000);
|
87 |
qemu_free(path); |
88 |
} |
89 |
} |
90 |
|
91 |
if (kernel_cmdline) {
|
92 |
fprintf(stderr, |
93 |
"Warning: missing libfdt, cannot pass cmdline to kernel!\n");
|
94 |
} |
95 |
#endif
|
96 |
return fdt_size;
|
97 |
} |
98 |
|
99 |
static void |
100 |
petalogix_s3adsp1800_init(ram_addr_t ram_size, |
101 |
const char *boot_device, |
102 |
const char *kernel_filename, |
103 |
const char *kernel_cmdline, |
104 |
const char *initrd_filename, const char *cpu_model) |
105 |
{ |
106 |
DeviceState *dev; |
107 |
CPUState *env; |
108 |
int kernel_size;
|
109 |
DriveInfo *dinfo; |
110 |
int i;
|
111 |
target_phys_addr_t ddr_base = 0x90000000;
|
112 |
ram_addr_t phys_lmb_bram; |
113 |
ram_addr_t phys_ram; |
114 |
ram_addr_t phys_flash; |
115 |
qemu_irq irq[32], *cpu_irq;
|
116 |
|
117 |
/* init CPUs */
|
118 |
if (cpu_model == NULL) { |
119 |
cpu_model = "microblaze";
|
120 |
} |
121 |
env = cpu_init(cpu_model); |
122 |
|
123 |
env->pvr.regs[10] = 0x0c000000; /* spartan 3a dsp family. */ |
124 |
qemu_register_reset(main_cpu_reset, env); |
125 |
|
126 |
/* Attach emulated BRAM through the LMB. */
|
127 |
phys_lmb_bram = qemu_ram_alloc(LMB_BRAM_SIZE); |
128 |
cpu_register_physical_memory(0x00000000, LMB_BRAM_SIZE,
|
129 |
phys_lmb_bram | IO_MEM_RAM); |
130 |
|
131 |
phys_ram = qemu_ram_alloc(ram_size); |
132 |
cpu_register_physical_memory(ddr_base, ram_size, phys_ram | IO_MEM_RAM); |
133 |
|
134 |
phys_flash = qemu_ram_alloc(FLASH_SIZE); |
135 |
dinfo = drive_get(IF_PFLASH, 0, 0); |
136 |
pflash_cfi02_register(0xa0000000, phys_flash,
|
137 |
dinfo ? dinfo->bdrv : NULL, (64 * 1024), |
138 |
FLASH_SIZE >> 16,
|
139 |
1, 1, 0x0000, 0x0000, 0x0000, 0x0000, |
140 |
0x555, 0x2aa); |
141 |
|
142 |
cpu_irq = microblaze_pic_init_cpu(env); |
143 |
dev = xilinx_intc_create(0x81800000, cpu_irq[0], 2); |
144 |
for (i = 0; i < 32; i++) { |
145 |
irq[i] = qdev_get_gpio_in(dev, i); |
146 |
} |
147 |
|
148 |
sysbus_create_simple("xilinx,uartlite", 0x84000000, irq[3]); |
149 |
/* 2 timers at irq 2 @ 62 Mhz. */
|
150 |
xilinx_timer_create(0x83c00000, irq[0], 2, 62 * 1000000); |
151 |
xilinx_ethlite_create(&nd_table[0], 0x81000000, irq[1], 0, 0); |
152 |
|
153 |
if (kernel_filename) {
|
154 |
uint64_t entry, low, high; |
155 |
int kcmdline_len;
|
156 |
uint32_t base32; |
157 |
|
158 |
/* Boots a kernel elf binary. */
|
159 |
kernel_size = load_elf(kernel_filename, 0,
|
160 |
&entry, &low, &high, |
161 |
1, ELF_MACHINE, 0); |
162 |
base32 = entry; |
163 |
if (base32 == 0xc0000000) { |
164 |
kernel_size = load_elf(kernel_filename, -0x30000000LL,
|
165 |
&entry, NULL, NULL, |
166 |
1, ELF_MACHINE, 0); |
167 |
} |
168 |
/* Always boot into physical ram. */
|
169 |
bootstrap_pc = ddr_base + (entry & 0x0fffffff);
|
170 |
if (kernel_size < 0) { |
171 |
/* If we failed loading ELF's try a raw image. */
|
172 |
kernel_size = load_image_targphys(kernel_filename, ddr_base, |
173 |
ram_size); |
174 |
bootstrap_pc = ddr_base; |
175 |
} |
176 |
|
177 |
env->regs[5] = ddr_base + kernel_size;
|
178 |
if (kernel_cmdline && (kcmdline_len = strlen(kernel_cmdline))) {
|
179 |
pstrcpy_targphys("cmdline", env->regs[5], 256, kernel_cmdline); |
180 |
} |
181 |
env->regs[6] = 0; |
182 |
/* Provide a device-tree. */
|
183 |
env->regs[7] = ddr_base + kernel_size + 256; |
184 |
petalogix_load_device_tree(env->regs[7], ram_size,
|
185 |
env->regs[6], 0, |
186 |
kernel_cmdline); |
187 |
} |
188 |
|
189 |
env->sregs[SR_PC] = bootstrap_pc; |
190 |
} |
191 |
|
192 |
static QEMUMachine petalogix_s3adsp1800_machine = {
|
193 |
.name = "petalogix-s3adsp1800",
|
194 |
.desc = "Petalogix linux refdesign for xilinx Spartan 3ADSP1800",
|
195 |
.init = petalogix_s3adsp1800_init, |
196 |
.is_default = 1
|
197 |
}; |
198 |
|
199 |
static void petalogix_s3adsp1800_machine_init(void) |
200 |
{ |
201 |
qemu_register_machine(&petalogix_s3adsp1800_machine); |
202 |
} |
203 |
|
204 |
machine_init(petalogix_s3adsp1800_machine_init); |