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