2 * Qemu PowerPC 440 Bamboo board emulation
4 * Copyright 2007 IBM Corporation.
6 * Jerone Young <jyoung5@us.ibm.com>
7 * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
8 * Hollis Blanchard <hollisb@us.ibm.com>
10 * This work is licensed under the GNU GPL license version 2 or later.
15 #include "qemu-common.h"
22 #include "device_tree.h"
25 #include "exec-memory.h"
31 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
34 #define KERNEL_ADDR 0x1000000
35 #define FDT_ADDR 0x1800000
36 #define RAMDISK_ADDR 0x1900000
38 #define PPC440EP_PCI_CONFIG 0xeec00000
39 #define PPC440EP_PCI_INTACK 0xeed00000
40 #define PPC440EP_PCI_SPECIAL 0xeed00000
41 #define PPC440EP_PCI_REGS 0xef400000
42 #define PPC440EP_PCI_IO 0xe8000000
43 #define PPC440EP_PCI_IOLEN 0x00010000
45 #define PPC440EP_SDRAM_NR_BANKS 4
47 static const unsigned int ppc440ep_sdram_bank_sizes
[] = {
48 256<<20, 128<<20, 64<<20, 32<<20, 16<<20, 8<<20, 0
51 static target_phys_addr_t entry
;
53 static PCIBus
*ppc4xx_pci_init(CPUState
*env
, qemu_irq pci_irqs
[4],
54 target_phys_addr_t config_space
,
55 target_phys_addr_t int_ack
,
56 target_phys_addr_t special_cycle
,
57 target_phys_addr_t registers
)
62 CPUState
*ppc440ep_init(MemoryRegion
*address_space_mem
, ram_addr_t
*ram_size
,
63 PCIBus
**pcip
, const unsigned int pci_irq_nrs
[4],
64 int do_init
, const char *cpu_model
)
66 MemoryRegion
*ram_memories
67 = g_malloc(PPC440EP_SDRAM_NR_BANKS
* sizeof(*ram_memories
));
68 target_phys_addr_t ram_bases
[PPC440EP_SDRAM_NR_BANKS
];
69 target_phys_addr_t ram_sizes
[PPC440EP_SDRAM_NR_BANKS
];
75 if (cpu_model
== NULL
) {
78 env
= cpu_init(cpu_model
);
80 fprintf(stderr
, "Unable to initialize CPU!\n");
84 ppc_booke_timers_init(env
, 400000000, 0);
85 ppc_dcr_init(env
, NULL
, NULL
);
87 /* interrupt controller */
88 irqs
= g_malloc0(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
89 irqs
[PPCUIC_OUTPUT_INT
] = ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
90 irqs
[PPCUIC_OUTPUT_CINT
] = ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
91 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
93 /* SDRAM controller */
94 memset(ram_bases
, 0, sizeof(ram_bases
));
95 memset(ram_sizes
, 0, sizeof(ram_sizes
));
96 *ram_size
= ppc4xx_sdram_adjust(*ram_size
, PPC440EP_SDRAM_NR_BANKS
,
99 ppc440ep_sdram_bank_sizes
);
100 /* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */
101 ppc4xx_sdram_init(env
, pic
[14], PPC440EP_SDRAM_NR_BANKS
, ram_memories
,
102 ram_bases
, ram_sizes
, do_init
);
105 pci_irqs
= g_malloc(sizeof(qemu_irq
) * 4);
106 pci_irqs
[0] = pic
[pci_irq_nrs
[0]];
107 pci_irqs
[1] = pic
[pci_irq_nrs
[1]];
108 pci_irqs
[2] = pic
[pci_irq_nrs
[2]];
109 pci_irqs
[3] = pic
[pci_irq_nrs
[3]];
110 *pcip
= ppc4xx_pci_init(env
, pci_irqs
,
113 PPC440EP_PCI_SPECIAL
,
116 printf("couldn't create PCI controller!\n");
118 isa_mmio_init(PPC440EP_PCI_IO
, PPC440EP_PCI_IOLEN
);
120 if (serial_hds
[0] != NULL
) {
121 serial_mm_init(address_space_mem
, 0xef600300, 0, pic
[0],
122 PPC_SERIAL_MM_BAUDBASE
, serial_hds
[0],
125 if (serial_hds
[1] != NULL
) {
126 serial_mm_init(address_space_mem
, 0xef600400, 0, pic
[1],
127 PPC_SERIAL_MM_BAUDBASE
, serial_hds
[1],
134 static int bamboo_load_device_tree(target_phys_addr_t addr
,
136 target_phys_addr_t initrd_base
,
137 target_phys_addr_t initrd_size
,
138 const char *kernel_cmdline
)
142 uint32_t mem_reg_property
[] = { 0, 0, ramsize
};
146 uint32_t tb_freq
= 400000000;
147 uint32_t clock_freq
= 400000000;
149 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, BINARY_DEVICE_TREE_FILE
);
153 fdt
= load_device_tree(filename
, &fdt_size
);
159 /* Manipulate device tree in memory. */
161 ret
= qemu_devtree_setprop(fdt
, "/memory", "reg", mem_reg_property
,
162 sizeof(mem_reg_property
));
164 fprintf(stderr
, "couldn't set /memory/reg\n");
166 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-start",
169 fprintf(stderr
, "couldn't set /chosen/linux,initrd-start\n");
171 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-end",
172 (initrd_base
+ initrd_size
));
174 fprintf(stderr
, "couldn't set /chosen/linux,initrd-end\n");
176 ret
= qemu_devtree_setprop_string(fdt
, "/chosen", "bootargs",
179 fprintf(stderr
, "couldn't set /chosen/bootargs\n");
181 /* Copy data from the host device tree into the guest. Since the guest can
182 * directly access the timebase without host involvement, we must expose
183 * the correct frequencies. */
185 tb_freq
= kvmppc_get_tbfreq();
186 clock_freq
= kvmppc_get_clockfreq();
189 qemu_devtree_setprop_cell(fdt
, "/cpus/cpu@0", "clock-frequency",
191 qemu_devtree_setprop_cell(fdt
, "/cpus/cpu@0", "timebase-frequency",
194 ret
= rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE
, fdt
, fdt_size
, addr
);
203 /* Create reset TLB entries for BookE, spanning the 32bit addr space. */
204 static void mmubooke_create_initial_mapping(CPUState
*env
,
206 target_phys_addr_t pa
)
208 ppcemb_tlb_t
*tlb
= &env
->tlb
.tlbe
[0];
211 tlb
->prot
= PAGE_VALID
| ((PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
) << 4);
212 tlb
->size
= 1 << 31; /* up to 0x80000000 */
213 tlb
->EPN
= va
& TARGET_PAGE_MASK
;
214 tlb
->RPN
= pa
& TARGET_PAGE_MASK
;
217 tlb
= &env
->tlb
.tlbe
[1];
219 tlb
->prot
= PAGE_VALID
| ((PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
) << 4);
220 tlb
->size
= 1 << 31; /* up to 0xffffffff */
221 tlb
->EPN
= 0x80000000 & TARGET_PAGE_MASK
;
222 tlb
->RPN
= 0x80000000 & TARGET_PAGE_MASK
;
226 static void main_cpu_reset(void *opaque
)
228 CPUState
*env
= opaque
;
231 env
->gpr
[1] = (16<<20) - 8;
232 env
->gpr
[3] = FDT_ADDR
;
235 /* Create a mapping for the kernel. */
236 mmubooke_create_initial_mapping(env
, 0, 0);
239 static void bamboo_init(ram_addr_t ram_size
,
240 const char *boot_device
,
241 const char *kernel_filename
,
242 const char *kernel_cmdline
,
243 const char *initrd_filename
,
244 const char *cpu_model
)
246 unsigned int pci_irq_nrs
[4] = { 28, 27, 26, 25 };
247 MemoryRegion
*address_space_mem
= get_system_memory();
251 uint64_t elf_lowaddr
;
252 target_phys_addr_t loadaddr
= 0;
253 target_long initrd_size
= 0;
258 env
= ppc440ep_init(address_space_mem
, &ram_size
, &pcibus
,
259 pci_irq_nrs
, 1, cpu_model
);
260 qemu_register_reset(main_cpu_reset
, env
);
263 /* Register network interfaces. */
264 for (i
= 0; i
< nb_nics
; i
++) {
265 /* There are no PCI NICs on the Bamboo board, but there are
266 * PCI slots, so we can pick whatever default model we want. */
267 pci_nic_init_nofail(&nd_table
[i
], "e1000", NULL
);
272 if (kernel_filename
) {
273 success
= load_uimage(kernel_filename
, &entry
, &loadaddr
, NULL
);
275 success
= load_elf(kernel_filename
, NULL
, NULL
, &elf_entry
,
276 &elf_lowaddr
, NULL
, 1, ELF_MACHINE
, 0);
278 loadaddr
= elf_lowaddr
;
280 /* XXX try again as binary */
282 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
289 if (initrd_filename
) {
290 initrd_size
= load_image_targphys(initrd_filename
, RAMDISK_ADDR
,
291 ram_size
- RAMDISK_ADDR
);
293 if (initrd_size
< 0) {
294 fprintf(stderr
, "qemu: could not load ram disk '%s' at %x\n",
295 initrd_filename
, RAMDISK_ADDR
);
300 /* If we're loading a kernel directly, we must load the device tree too. */
301 if (kernel_filename
) {
302 if (bamboo_load_device_tree(FDT_ADDR
, ram_size
, RAMDISK_ADDR
,
303 initrd_size
, kernel_cmdline
) < 0) {
304 fprintf(stderr
, "couldn't load device tree\n");
313 static QEMUMachine bamboo_machine
= {
319 static void bamboo_machine_init(void)
321 qemu_register_machine(&bamboo_machine
);
324 machine_init(bamboo_machine_init
);