2 * Model of Petalogix linux reference design targeting Xilinx Spartan 3ADSP-1800
5 * Copyright (c) 2009 Edgar E. Iglesias.
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
33 #include "device_tree.h"
36 #define LMB_BRAM_SIZE (128 * 1024)
37 #define FLASH_SIZE (16 * 1024 * 1024)
39 static uint32_t bootstrap_pc
;
41 static void main_cpu_reset(void *opaque
)
43 CPUState
*env
= opaque
;
45 env
->sregs
[SR_PC
] = bootstrap_pc
;
48 #define BINARY_DEVICE_TREE_FILE "petalogix-s3adsp1800.dtb"
49 static int petalogix_load_device_tree(target_phys_addr_t addr
,
51 target_phys_addr_t initrd_base
,
52 target_phys_addr_t initrd_size
,
53 const char *kernel_cmdline
)
64 /* Try the local "mb.dtb" override. */
65 fdt
= load_device_tree("mb.dtb", &fdt_size
);
67 pathlen
= snprintf(NULL
, 0, "%s/%s",
68 bios_dir
, BINARY_DEVICE_TREE_FILE
) + 1;
69 path
= qemu_malloc(pathlen
);
70 snprintf(path
, pathlen
, "%s/%s", bios_dir
, BINARY_DEVICE_TREE_FILE
);
71 fdt
= load_device_tree(BINARY_DEVICE_TREE_FILE
, &fdt_size
);
77 r
= qemu_devtree_setprop_string(fdt
, "/chosen", "bootargs", kernel_cmdline
);
79 fprintf(stderr
, "couldn't set /chosen/bootargs\n");
80 cpu_physical_memory_write (addr
, (void *)fdt
, fdt_size
);
82 /* We lack libfdt so we cannot manipulate the fdt. Just pass on the blob
84 fdt_size
= load_image_targphys("mb.dtb", addr
, 0x10000);
86 fdt_size
= load_image_targphys(BINARY_DEVICE_TREE_FILE
, addr
, 0x10000);
91 "Warning: missing libfdt, cannot pass cmdline to kernel!\n");
98 petalogix_s3adsp1800_init(ram_addr_t ram_size
,
99 const char *boot_device
,
100 const char *kernel_filename
,
101 const char *kernel_cmdline
,
102 const char *initrd_filename
, const char *cpu_model
)
108 target_phys_addr_t ddr_base
= 0x90000000;
109 ram_addr_t phys_lmb_bram
;
111 ram_addr_t phys_flash
;
112 qemu_irq irq
[32], *cpu_irq
;
115 if (cpu_model
== NULL
) {
116 cpu_model
= "microblaze";
118 env
= cpu_init(cpu_model
);
120 env
->pvr
.regs
[10] = 0x0c000000; /* spartan 3a dsp family. */
121 qemu_register_reset(main_cpu_reset
, 0, env
);
123 /* Attach emulated BRAM through the LMB. */
124 phys_lmb_bram
= qemu_ram_alloc(LMB_BRAM_SIZE
);
125 cpu_register_physical_memory(0x00000000, LMB_BRAM_SIZE
,
126 phys_lmb_bram
| IO_MEM_RAM
);
128 phys_ram
= qemu_ram_alloc(ram_size
);
129 cpu_register_physical_memory(ddr_base
, ram_size
, phys_ram
| IO_MEM_RAM
);
131 phys_flash
= qemu_ram_alloc(FLASH_SIZE
);
132 i
= drive_get_index(IF_PFLASH
, 0, 0);
133 pflash_cfi02_register(0xa0000000, phys_flash
,
134 i
!= -1 ? drives_table
[i
].bdrv
: NULL
, (64 * 1024),
136 1, 1, 0x0000, 0x0000, 0x0000, 0x0000,
139 cpu_irq
= microblaze_pic_init_cpu(env
);
140 dev
= xilinx_intc_create(0x81800000, cpu_irq
[0], 2);
141 for (i
= 0; i
< 32; i
++) {
142 irq
[i
] = qdev_get_gpio_in(dev
, i
);
145 sysbus_create_simple("xilinx,uartlite", 0x84000000, irq
[3]);
146 /* 2 timers at irq 2 @ 62 Mhz. */
147 xilinx_timer_create(0x83c00000, irq
[0], 2, 62 * 1000000);
148 xilinx_ethlite_create(&nd_table
[0], 0x81000000, irq
[1], 0, 0);
150 if (kernel_filename
) {
151 uint64_t entry
, low
, high
;
155 /* Boots a kernel elf binary. */
156 kernel_size
= load_elf(kernel_filename
, 0,
157 &entry
, &low
, &high
);
159 if (base32
== 0xc0000000) {
160 kernel_size
= load_elf(kernel_filename
, -0x30000000LL
,
163 /* Always boot into physical ram. */
164 bootstrap_pc
= ddr_base
+ (entry
& 0x0fffffff);
165 if (kernel_size
< 0) {
166 /* If we failed loading ELF's try a raw image. */
167 kernel_size
= load_image_targphys(kernel_filename
, ddr_base
,
169 bootstrap_pc
= ddr_base
;
172 env
->regs
[5] = ddr_base
+ kernel_size
;
173 if (kernel_cmdline
&& (kcmdline_len
= strlen(kernel_cmdline
))) {
174 pstrcpy_targphys(env
->regs
[5], 256, kernel_cmdline
);
177 /* Provide a device-tree. */
178 env
->regs
[7] = ddr_base
+ kernel_size
+ 256;
179 petalogix_load_device_tree(env
->regs
[7], ram_size
,
184 env
->sregs
[SR_PC
] = bootstrap_pc
;
187 static QEMUMachine petalogix_s3adsp1800_machine
= {
188 .name
= "petalogix-s3adsp1800",
189 .desc
= "Petalogix linux refdesign for xilinx Spartan 3ADSP1800",
190 .init
= petalogix_s3adsp1800_init
,
194 static void petalogix_s3adsp1800_machine_init(void)
196 qemu_register_machine(&petalogix_s3adsp1800_machine
);
199 machine_init(petalogix_s3adsp1800_machine_init
);