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