root / hw / petalogix_s3adsp1800_mmu.c @ 0c3271c5
History | View | Annotate | Download (6.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 | 6a8b1ae2 | Edgar E. Iglesias | |
36 | 6a8b1ae2 | Edgar E. Iglesias | #define LMB_BRAM_SIZE (128 * 1024) |
37 | 6a8b1ae2 | Edgar E. Iglesias | #define FLASH_SIZE (16 * 1024 * 1024) |
38 | 6a8b1ae2 | Edgar E. Iglesias | |
39 | 6a8b1ae2 | Edgar E. Iglesias | static uint32_t bootstrap_pc;
|
40 | 6a8b1ae2 | Edgar E. Iglesias | |
41 | 6a8b1ae2 | Edgar E. Iglesias | static void main_cpu_reset(void *opaque) |
42 | 6a8b1ae2 | Edgar E. Iglesias | { |
43 | 6a8b1ae2 | Edgar E. Iglesias | CPUState *env = opaque; |
44 | 6a8b1ae2 | Edgar E. Iglesias | cpu_reset(env); |
45 | 6a8b1ae2 | Edgar E. Iglesias | env->sregs[SR_PC] = bootstrap_pc; |
46 | 6a8b1ae2 | Edgar E. Iglesias | } |
47 | 6a8b1ae2 | Edgar E. Iglesias | |
48 | 6a8b1ae2 | Edgar E. Iglesias | #define BINARY_DEVICE_TREE_FILE "petalogix-s3adsp1800.dtb" |
49 | 6a8b1ae2 | Edgar E. Iglesias | static int petalogix_load_device_tree(target_phys_addr_t addr, |
50 | 6a8b1ae2 | Edgar E. Iglesias | uint32_t ramsize, |
51 | 6a8b1ae2 | Edgar E. Iglesias | target_phys_addr_t initrd_base, |
52 | 6a8b1ae2 | Edgar E. Iglesias | target_phys_addr_t initrd_size, |
53 | 6a8b1ae2 | Edgar E. Iglesias | const char *kernel_cmdline) |
54 | 6a8b1ae2 | Edgar E. Iglesias | { |
55 | 7696d1ec | Edgar E. Iglesias | #ifdef HAVE_FDT
|
56 | 6a8b1ae2 | Edgar E. Iglesias | void *fdt;
|
57 | 6a8b1ae2 | Edgar E. Iglesias | int r;
|
58 | 7696d1ec | Edgar E. Iglesias | #endif
|
59 | 4b0c7aa3 | Edgar E. Iglesias | char *path;
|
60 | 7696d1ec | Edgar E. Iglesias | int fdt_size;
|
61 | 6a8b1ae2 | Edgar E. Iglesias | |
62 | 7696d1ec | Edgar E. Iglesias | #ifdef HAVE_FDT
|
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 | 6a8b1ae2 | Edgar E. Iglesias | 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 | 6a8b1ae2 | Edgar E. Iglesias | int i;
|
110 | 6a8b1ae2 | Edgar E. Iglesias | target_phys_addr_t ddr_base = 0x90000000;
|
111 | 6a8b1ae2 | Edgar E. Iglesias | ram_addr_t phys_lmb_bram; |
112 | 6a8b1ae2 | Edgar E. Iglesias | ram_addr_t phys_ram; |
113 | 6a8b1ae2 | Edgar E. Iglesias | ram_addr_t phys_flash; |
114 | 6a8b1ae2 | Edgar E. Iglesias | qemu_irq irq[32], *cpu_irq;
|
115 | 6a8b1ae2 | Edgar E. Iglesias | |
116 | 6a8b1ae2 | Edgar E. Iglesias | /* init CPUs */
|
117 | 6a8b1ae2 | Edgar E. Iglesias | if (cpu_model == NULL) { |
118 | 6a8b1ae2 | Edgar E. Iglesias | cpu_model = "microblaze";
|
119 | 6a8b1ae2 | Edgar E. Iglesias | } |
120 | 6a8b1ae2 | Edgar E. Iglesias | env = cpu_init(cpu_model); |
121 | 6a8b1ae2 | Edgar E. Iglesias | |
122 | 6a8b1ae2 | Edgar E. Iglesias | env->pvr.regs[10] = 0x0c000000; /* spartan 3a dsp family. */ |
123 | a08d4367 | Jan Kiszka | qemu_register_reset(main_cpu_reset, env); |
124 | 6a8b1ae2 | Edgar E. Iglesias | |
125 | 6a8b1ae2 | Edgar E. Iglesias | /* Attach emulated BRAM through the LMB. */
|
126 | 6a8b1ae2 | Edgar E. Iglesias | phys_lmb_bram = qemu_ram_alloc(LMB_BRAM_SIZE); |
127 | 6a8b1ae2 | Edgar E. Iglesias | cpu_register_physical_memory(0x00000000, LMB_BRAM_SIZE,
|
128 | 6a8b1ae2 | Edgar E. Iglesias | phys_lmb_bram | IO_MEM_RAM); |
129 | 6a8b1ae2 | Edgar E. Iglesias | |
130 | 6a8b1ae2 | Edgar E. Iglesias | phys_ram = qemu_ram_alloc(ram_size); |
131 | 6a8b1ae2 | Edgar E. Iglesias | cpu_register_physical_memory(ddr_base, ram_size, phys_ram | IO_MEM_RAM); |
132 | 6a8b1ae2 | Edgar E. Iglesias | |
133 | 6a8b1ae2 | Edgar E. Iglesias | phys_flash = qemu_ram_alloc(FLASH_SIZE); |
134 | 6a8b1ae2 | Edgar E. Iglesias | i = drive_get_index(IF_PFLASH, 0, 0); |
135 | 6a8b1ae2 | Edgar E. Iglesias | pflash_cfi02_register(0xa0000000, phys_flash,
|
136 | 6a8b1ae2 | Edgar E. Iglesias | i != -1 ? drives_table[i].bdrv : NULL, (64 * 1024), |
137 | 6a8b1ae2 | Edgar E. Iglesias | FLASH_SIZE >> 16,
|
138 | 6a8b1ae2 | Edgar E. Iglesias | 1, 1, 0x0000, 0x0000, 0x0000, 0x0000, |
139 | 6a8b1ae2 | Edgar E. Iglesias | 0x555, 0x2aa); |
140 | 6a8b1ae2 | Edgar E. Iglesias | |
141 | 6a8b1ae2 | Edgar E. Iglesias | cpu_irq = microblaze_pic_init_cpu(env); |
142 | 6a8b1ae2 | Edgar E. Iglesias | dev = xilinx_intc_create(0x81800000, cpu_irq[0], 2); |
143 | 6a8b1ae2 | Edgar E. Iglesias | for (i = 0; i < 32; i++) { |
144 | 6a8b1ae2 | Edgar E. Iglesias | irq[i] = qdev_get_gpio_in(dev, i); |
145 | 6a8b1ae2 | Edgar E. Iglesias | } |
146 | 6a8b1ae2 | Edgar E. Iglesias | |
147 | 6a8b1ae2 | Edgar E. Iglesias | sysbus_create_simple("xilinx,uartlite", 0x84000000, irq[3]); |
148 | 6a8b1ae2 | Edgar E. Iglesias | /* 2 timers at irq 2 @ 62 Mhz. */
|
149 | 6a8b1ae2 | Edgar E. Iglesias | xilinx_timer_create(0x83c00000, irq[0], 2, 62 * 1000000); |
150 | 6a8b1ae2 | Edgar E. Iglesias | xilinx_ethlite_create(&nd_table[0], 0x81000000, irq[1], 0, 0); |
151 | 6a8b1ae2 | Edgar E. Iglesias | |
152 | 6a8b1ae2 | Edgar E. Iglesias | if (kernel_filename) {
|
153 | 6a8b1ae2 | Edgar E. Iglesias | uint64_t entry, low, high; |
154 | 6a8b1ae2 | Edgar E. Iglesias | int kcmdline_len;
|
155 | 6a8b1ae2 | Edgar E. Iglesias | uint32_t base32; |
156 | 6a8b1ae2 | Edgar E. Iglesias | |
157 | 6a8b1ae2 | Edgar E. Iglesias | /* Boots a kernel elf binary. */
|
158 | 6a8b1ae2 | Edgar E. Iglesias | kernel_size = load_elf(kernel_filename, 0,
|
159 | 6a8b1ae2 | Edgar E. Iglesias | &entry, &low, &high); |
160 | 6a8b1ae2 | Edgar E. Iglesias | base32 = entry; |
161 | 6a8b1ae2 | Edgar E. Iglesias | if (base32 == 0xc0000000) { |
162 | 6a8b1ae2 | Edgar E. Iglesias | kernel_size = load_elf(kernel_filename, -0x30000000LL,
|
163 | 6a8b1ae2 | Edgar E. Iglesias | &entry, NULL, NULL); |
164 | 6a8b1ae2 | Edgar E. Iglesias | } |
165 | 6a8b1ae2 | Edgar E. Iglesias | /* Always boot into physical ram. */
|
166 | 6a8b1ae2 | Edgar E. Iglesias | bootstrap_pc = ddr_base + (entry & 0x0fffffff);
|
167 | 6a8b1ae2 | Edgar E. Iglesias | if (kernel_size < 0) { |
168 | 6a8b1ae2 | Edgar E. Iglesias | /* If we failed loading ELF's try a raw image. */
|
169 | 6a8b1ae2 | Edgar E. Iglesias | kernel_size = load_image_targphys(kernel_filename, ddr_base, |
170 | 6a8b1ae2 | Edgar E. Iglesias | ram_size); |
171 | 6a8b1ae2 | Edgar E. Iglesias | bootstrap_pc = ddr_base; |
172 | 6a8b1ae2 | Edgar E. Iglesias | } |
173 | 6a8b1ae2 | Edgar E. Iglesias | |
174 | 6a8b1ae2 | Edgar E. Iglesias | env->regs[5] = ddr_base + kernel_size;
|
175 | 6a8b1ae2 | Edgar E. Iglesias | if (kernel_cmdline && (kcmdline_len = strlen(kernel_cmdline))) {
|
176 | 6a8b1ae2 | Edgar E. Iglesias | pstrcpy_targphys(env->regs[5], 256, kernel_cmdline); |
177 | 6a8b1ae2 | Edgar E. Iglesias | } |
178 | 6a8b1ae2 | Edgar E. Iglesias | env->regs[6] = 0; |
179 | 6a8b1ae2 | Edgar E. Iglesias | /* Provide a device-tree. */
|
180 | 6a8b1ae2 | Edgar E. Iglesias | env->regs[7] = ddr_base + kernel_size + 256; |
181 | 6a8b1ae2 | Edgar E. Iglesias | petalogix_load_device_tree(env->regs[7], ram_size,
|
182 | 6a8b1ae2 | Edgar E. Iglesias | env->regs[6], 0, |
183 | 6a8b1ae2 | Edgar E. Iglesias | kernel_cmdline); |
184 | 6a8b1ae2 | Edgar E. Iglesias | } |
185 | 6a8b1ae2 | Edgar E. Iglesias | |
186 | 6a8b1ae2 | Edgar E. Iglesias | env->sregs[SR_PC] = bootstrap_pc; |
187 | 6a8b1ae2 | Edgar E. Iglesias | } |
188 | 6a8b1ae2 | Edgar E. Iglesias | |
189 | 6a8b1ae2 | Edgar E. Iglesias | static QEMUMachine petalogix_s3adsp1800_machine = {
|
190 | 6a8b1ae2 | Edgar E. Iglesias | .name = "petalogix-s3adsp1800",
|
191 | 6a8b1ae2 | Edgar E. Iglesias | .desc = "Petalogix linux refdesign for xilinx Spartan 3ADSP1800",
|
192 | 6a8b1ae2 | Edgar E. Iglesias | .init = petalogix_s3adsp1800_init, |
193 | 6a8b1ae2 | Edgar E. Iglesias | .is_default = 1
|
194 | 6a8b1ae2 | Edgar E. Iglesias | }; |
195 | 6a8b1ae2 | Edgar E. Iglesias | |
196 | 6a8b1ae2 | Edgar E. Iglesias | static void petalogix_s3adsp1800_machine_init(void) |
197 | 6a8b1ae2 | Edgar E. Iglesias | { |
198 | 6a8b1ae2 | Edgar E. Iglesias | qemu_register_machine(&petalogix_s3adsp1800_machine); |
199 | 6a8b1ae2 | Edgar E. Iglesias | } |
200 | 6a8b1ae2 | Edgar E. Iglesias | |
201 | 6a8b1ae2 | Edgar E. Iglesias | machine_init(petalogix_s3adsp1800_machine_init); |