|
|
1.1 root 1: /*
2: * Qemu PowerPC 440 Bamboo board emulation
3: *
4: * Copyright 2007 IBM Corporation.
5: * Authors:
6: * Jerone Young <[email protected]>
7: * Christian Ehrhardt <[email protected]>
8: * Hollis Blanchard <[email protected]>
9: *
10: * This work is licensed under the GNU GPL license version 2 or later.
11: *
12: */
13:
14: #include "config.h"
15: #include "qemu-common.h"
16: #include "net.h"
17: #include "hw.h"
18: #include "pci.h"
19: #include "boards.h"
20: #include "ppc440.h"
21: #include "kvm.h"
22: #include "kvm_ppc.h"
23: #include "device_tree.h"
1.1.1.3 root 24: #include "loader.h"
25: #include "elf.h"
1.1.1.7 ! root 26: #include "exec-memory.h"
1.1 root 27:
28: #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
29:
1.1.1.5 root 30: /* from u-boot */
31: #define KERNEL_ADDR 0x1000000
32: #define FDT_ADDR 0x1800000
33: #define RAMDISK_ADDR 0x1900000
34:
1.1.1.4 root 35: static int bamboo_load_device_tree(target_phys_addr_t addr,
1.1 root 36: uint32_t ramsize,
37: target_phys_addr_t initrd_base,
38: target_phys_addr_t initrd_size,
39: const char *kernel_cmdline)
40: {
1.1.1.4 root 41: int ret = -1;
1.1.1.3 root 42: #ifdef CONFIG_FDT
1.1 root 43: uint32_t mem_reg_property[] = { 0, 0, ramsize };
1.1.1.2 root 44: char *filename;
45: int fdt_size;
1.1.1.4 root 46: void *fdt;
1.1.1.7 ! root 47: uint32_t tb_freq = 400000000;
! 48: uint32_t clock_freq = 400000000;
1.1 root 49:
1.1.1.2 root 50: filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
51: if (!filename) {
1.1 root 52: goto out;
1.1.1.2 root 53: }
54: fdt = load_device_tree(filename, &fdt_size);
1.1.1.7 ! root 55: g_free(filename);
1.1.1.2 root 56: if (fdt == NULL) {
57: goto out;
58: }
1.1 root 59:
60: /* Manipulate device tree in memory. */
61:
62: ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
63: sizeof(mem_reg_property));
64: if (ret < 0)
65: fprintf(stderr, "couldn't set /memory/reg\n");
66:
67: ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
68: initrd_base);
69: if (ret < 0)
70: fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
71:
72: ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
73: (initrd_base + initrd_size));
74: if (ret < 0)
75: fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
76:
77: ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
78: kernel_cmdline);
79: if (ret < 0)
80: fprintf(stderr, "couldn't set /chosen/bootargs\n");
81:
1.1.1.7 ! root 82: /* Copy data from the host device tree into the guest. Since the guest can
! 83: * directly access the timebase without host involvement, we must expose
! 84: * the correct frequencies. */
! 85: if (kvm_enabled()) {
! 86: tb_freq = kvmppc_get_tbfreq();
! 87: clock_freq = kvmppc_get_clockfreq();
! 88: }
! 89:
! 90: qemu_devtree_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",
! 91: clock_freq);
! 92: qemu_devtree_setprop_cell(fdt, "/cpus/cpu@0", "timebase-frequency",
! 93: tb_freq);
1.1 root 94:
1.1.1.4 root 95: ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);
1.1.1.7 ! root 96: g_free(fdt);
1.1.1.2 root 97:
1.1 root 98: out:
99: #endif
100:
1.1.1.4 root 101: return ret;
1.1 root 102: }
103:
1.1.1.2 root 104: static void bamboo_init(ram_addr_t ram_size,
1.1 root 105: const char *boot_device,
106: const char *kernel_filename,
107: const char *kernel_cmdline,
108: const char *initrd_filename,
109: const char *cpu_model)
110: {
111: unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
1.1.1.7 ! root 112: MemoryRegion *address_space_mem = get_system_memory();
1.1 root 113: PCIBus *pcibus;
114: CPUState *env;
115: uint64_t elf_entry;
116: uint64_t elf_lowaddr;
1.1.1.3 root 117: target_phys_addr_t entry = 0;
118: target_phys_addr_t loadaddr = 0;
1.1 root 119: target_long initrd_size = 0;
1.1.1.5 root 120: int success;
1.1 root 121: int i;
122:
123: /* Setup CPU. */
1.1.1.7 ! root 124: env = ppc440ep_init(address_space_mem, &ram_size, &pcibus,
! 125: pci_irq_nrs, 1, cpu_model);
1.1 root 126:
127: if (pcibus) {
128: /* Register network interfaces. */
129: for (i = 0; i < nb_nics; i++) {
130: /* There are no PCI NICs on the Bamboo board, but there are
131: * PCI slots, so we can pick whatever default model we want. */
1.1.1.3 root 132: pci_nic_init_nofail(&nd_table[i], "e1000", NULL);
1.1 root 133: }
134: }
135:
136: /* Load kernel. */
137: if (kernel_filename) {
1.1.1.5 root 138: success = load_uimage(kernel_filename, &entry, &loadaddr, NULL);
139: if (success < 0) {
140: success = load_elf(kernel_filename, NULL, NULL, &elf_entry,
141: &elf_lowaddr, NULL, 1, ELF_MACHINE, 0);
1.1 root 142: entry = elf_entry;
143: loadaddr = elf_lowaddr;
144: }
145: /* XXX try again as binary */
1.1.1.5 root 146: if (success < 0) {
1.1 root 147: fprintf(stderr, "qemu: could not load kernel '%s'\n",
148: kernel_filename);
149: exit(1);
150: }
151: }
152:
153: /* Load initrd. */
154: if (initrd_filename) {
1.1.1.5 root 155: initrd_size = load_image_targphys(initrd_filename, RAMDISK_ADDR,
156: ram_size - RAMDISK_ADDR);
1.1 root 157:
158: if (initrd_size < 0) {
1.1.1.5 root 159: fprintf(stderr, "qemu: could not load ram disk '%s' at %x\n",
160: initrd_filename, RAMDISK_ADDR);
1.1 root 161: exit(1);
162: }
163: }
164:
165: /* If we're loading a kernel directly, we must load the device tree too. */
166: if (kernel_filename) {
1.1.1.5 root 167: if (bamboo_load_device_tree(FDT_ADDR, ram_size, RAMDISK_ADDR,
168: initrd_size, kernel_cmdline) < 0) {
1.1 root 169: fprintf(stderr, "couldn't load device tree\n");
170: exit(1);
171: }
172:
173: /* Set initial guest state. */
174: env->gpr[1] = (16<<20) - 8;
1.1.1.5 root 175: env->gpr[3] = FDT_ADDR;
1.1 root 176: env->nip = entry;
177: /* XXX we currently depend on KVM to create some initial TLB entries. */
178: }
179:
180: if (kvm_enabled())
181: kvmppc_init();
182: }
183:
1.1.1.2 root 184: static QEMUMachine bamboo_machine = {
1.1.1.4 root 185: .name = "bamboo-0.13",
186: .alias = "bamboo",
187: .desc = "bamboo",
188: .init = bamboo_init,
189: };
190:
191: static QEMUMachine bamboo_machine_v0_12 = {
192: .name = "bamboo-0.12",
1.1 root 193: .desc = "bamboo",
194: .init = bamboo_init,
1.1.1.4 root 195: .compat_props = (GlobalProperty[]) {
196: {
197: .driver = "virtio-serial-pci",
198: .property = "max_ports",
199: .value = stringify(1),
200: },{
201: .driver = "virtio-serial-pci",
202: .property = "vectors",
203: .value = stringify(0),
204: },
205: { /* end of list */ }
206: },
1.1 root 207: };
1.1.1.2 root 208:
209: static void bamboo_machine_init(void)
210: {
211: qemu_register_machine(&bamboo_machine);
1.1.1.4 root 212: qemu_register_machine(&bamboo_machine_v0_12);
1.1.1.2 root 213: }
214:
215: machine_init(bamboo_machine_init);
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.