root / hw / ppc440_bamboo.c @ 9a3e12c8
History | View | Annotate | Download (5.8 kB)
1 | 2c9fade2 | aurel32 | /*
|
---|---|---|---|
2 | 2c9fade2 | aurel32 | * Qemu PowerPC 440 Bamboo board emulation
|
3 | 2c9fade2 | aurel32 | *
|
4 | 2c9fade2 | aurel32 | * Copyright 2007 IBM Corporation.
|
5 | 2c9fade2 | aurel32 | * Authors:
|
6 | 2c9fade2 | aurel32 | * Jerone Young <jyoung5@us.ibm.com>
|
7 | 2c9fade2 | aurel32 | * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
|
8 | 2c9fade2 | aurel32 | * Hollis Blanchard <hollisb@us.ibm.com>
|
9 | 2c9fade2 | aurel32 | *
|
10 | 2c9fade2 | aurel32 | * This work is licensed under the GNU GPL license version 2 or later.
|
11 | 2c9fade2 | aurel32 | *
|
12 | 2c9fade2 | aurel32 | */
|
13 | 2c9fade2 | aurel32 | |
14 | 2c9fade2 | aurel32 | #include "config.h" |
15 | 2c9fade2 | aurel32 | #include "qemu-common.h" |
16 | 2c9fade2 | aurel32 | #include "net.h" |
17 | 2c9fade2 | aurel32 | #include "hw.h" |
18 | 2c9fade2 | aurel32 | #include "pci.h" |
19 | 2c9fade2 | aurel32 | #include "boards.h" |
20 | 2c9fade2 | aurel32 | #include "sysemu.h" |
21 | 2c9fade2 | aurel32 | #include "ppc440.h" |
22 | 2c9fade2 | aurel32 | #include "kvm.h" |
23 | 2c9fade2 | aurel32 | #include "kvm_ppc.h" |
24 | 2c9fade2 | aurel32 | #include "device_tree.h" |
25 | 2c9fade2 | aurel32 | |
26 | 2c9fade2 | aurel32 | #define BINARY_DEVICE_TREE_FILE "bamboo.dtb" |
27 | 2c9fade2 | aurel32 | |
28 | 7ec632b4 | pbrook | static void *bamboo_load_device_tree(target_phys_addr_t addr, |
29 | 2c9fade2 | aurel32 | uint32_t ramsize, |
30 | 2c9fade2 | aurel32 | target_phys_addr_t initrd_base, |
31 | 2c9fade2 | aurel32 | target_phys_addr_t initrd_size, |
32 | 2c9fade2 | aurel32 | const char *kernel_cmdline) |
33 | 2c9fade2 | aurel32 | { |
34 | 2c9fade2 | aurel32 | void *fdt = NULL; |
35 | 2c9fade2 | aurel32 | #ifdef HAVE_FDT
|
36 | 2c9fade2 | aurel32 | uint32_t mem_reg_property[] = { 0, 0, ramsize }; |
37 | 5cea8590 | Paul Brook | char *filename;
|
38 | 7ec632b4 | pbrook | int fdt_size;
|
39 | 2c9fade2 | aurel32 | int ret;
|
40 | 2c9fade2 | aurel32 | |
41 | 5cea8590 | Paul Brook | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE); |
42 | 5cea8590 | Paul Brook | if (!filename) {
|
43 | 5cea8590 | Paul Brook | goto out;
|
44 | 5cea8590 | Paul Brook | } |
45 | 5cea8590 | Paul Brook | fdt = load_device_tree(filename, &fdt_size); |
46 | 5cea8590 | Paul Brook | qemu_free(filename); |
47 | 5cea8590 | Paul Brook | if (fdt == NULL) { |
48 | 2c9fade2 | aurel32 | goto out;
|
49 | 5cea8590 | Paul Brook | } |
50 | 2c9fade2 | aurel32 | |
51 | 2c9fade2 | aurel32 | /* Manipulate device tree in memory. */
|
52 | 2c9fade2 | aurel32 | |
53 | 2c9fade2 | aurel32 | ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property, |
54 | 2c9fade2 | aurel32 | sizeof(mem_reg_property));
|
55 | 2c9fade2 | aurel32 | if (ret < 0) |
56 | 2c9fade2 | aurel32 | fprintf(stderr, "couldn't set /memory/reg\n");
|
57 | 2c9fade2 | aurel32 | |
58 | 2c9fade2 | aurel32 | ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start", |
59 | 2c9fade2 | aurel32 | initrd_base); |
60 | 2c9fade2 | aurel32 | if (ret < 0) |
61 | 2c9fade2 | aurel32 | fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
|
62 | 2c9fade2 | aurel32 | |
63 | 2c9fade2 | aurel32 | ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end", |
64 | 2c9fade2 | aurel32 | (initrd_base + initrd_size)); |
65 | 2c9fade2 | aurel32 | if (ret < 0) |
66 | 2c9fade2 | aurel32 | fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
|
67 | 2c9fade2 | aurel32 | |
68 | 2c9fade2 | aurel32 | ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", |
69 | 2c9fade2 | aurel32 | kernel_cmdline); |
70 | 2c9fade2 | aurel32 | if (ret < 0) |
71 | 2c9fade2 | aurel32 | fprintf(stderr, "couldn't set /chosen/bootargs\n");
|
72 | 2c9fade2 | aurel32 | |
73 | 2c9fade2 | aurel32 | if (kvm_enabled())
|
74 | 2c9fade2 | aurel32 | kvmppc_fdt_update(fdt); |
75 | 2c9fade2 | aurel32 | |
76 | 7ec632b4 | pbrook | cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
|
77 | 7ec632b4 | pbrook | |
78 | 2c9fade2 | aurel32 | out:
|
79 | 2c9fade2 | aurel32 | #endif
|
80 | 2c9fade2 | aurel32 | |
81 | 2c9fade2 | aurel32 | return fdt;
|
82 | 2c9fade2 | aurel32 | } |
83 | 2c9fade2 | aurel32 | |
84 | fbe1b595 | Paul Brook | static void bamboo_init(ram_addr_t ram_size, |
85 | a147d62b | blueswir1 | const char *boot_device, |
86 | 2c9fade2 | aurel32 | const char *kernel_filename, |
87 | 2c9fade2 | aurel32 | const char *kernel_cmdline, |
88 | 2c9fade2 | aurel32 | const char *initrd_filename, |
89 | 2c9fade2 | aurel32 | const char *cpu_model) |
90 | 2c9fade2 | aurel32 | { |
91 | 2c9fade2 | aurel32 | unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 }; |
92 | 2c9fade2 | aurel32 | PCIBus *pcibus; |
93 | c2cc47a4 | Markus Armbruster | PCIDevice *pci_dev; |
94 | 2c9fade2 | aurel32 | CPUState *env; |
95 | 2c9fade2 | aurel32 | uint64_t elf_entry; |
96 | 2c9fade2 | aurel32 | uint64_t elf_lowaddr; |
97 | 2c9fade2 | aurel32 | target_ulong entry = 0;
|
98 | 2c9fade2 | aurel32 | target_ulong loadaddr = 0;
|
99 | 2c9fade2 | aurel32 | target_long kernel_size = 0;
|
100 | 2c9fade2 | aurel32 | target_ulong initrd_base = 0;
|
101 | 2c9fade2 | aurel32 | target_long initrd_size = 0;
|
102 | 2c9fade2 | aurel32 | target_ulong dt_base = 0;
|
103 | 2c9fade2 | aurel32 | void *fdt;
|
104 | 2c9fade2 | aurel32 | int i;
|
105 | 2c9fade2 | aurel32 | |
106 | 2c9fade2 | aurel32 | /* Setup CPU. */
|
107 | 727170b6 | Blue Swirl | env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);
|
108 | 2c9fade2 | aurel32 | |
109 | 2c9fade2 | aurel32 | if (pcibus) {
|
110 | 2c9fade2 | aurel32 | int unit_id = 0; |
111 | 2c9fade2 | aurel32 | |
112 | 2c9fade2 | aurel32 | /* Add virtio block devices. */
|
113 | 2c9fade2 | aurel32 | while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) { |
114 | c2cc47a4 | Markus Armbruster | pci_dev = pci_create("virtio-blk-pci", drives_table[i].devaddr);
|
115 | c2cc47a4 | Markus Armbruster | qdev_init(&pci_dev->qdev); |
116 | 2c9fade2 | aurel32 | unit_id++; |
117 | 2c9fade2 | aurel32 | } |
118 | 2c9fade2 | aurel32 | |
119 | 5fc1503e | aliguori | /* Add virtio console devices */
|
120 | 5fc1503e | aliguori | for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) { |
121 | 0e058a8a | Paul Brook | if (virtcon_hds[i]) {
|
122 | 53c25cea | Paul Brook | pci_create_simple(pcibus, -1, "virtio-console-pci"); |
123 | 0e058a8a | Paul Brook | } |
124 | 5fc1503e | aliguori | } |
125 | 5fc1503e | aliguori | |
126 | 2c9fade2 | aurel32 | /* Register network interfaces. */
|
127 | 2c9fade2 | aurel32 | for (i = 0; i < nb_nics; i++) { |
128 | cb457d76 | aliguori | /* There are no PCI NICs on the Bamboo board, but there are
|
129 | cb457d76 | aliguori | * PCI slots, so we can pick whatever default model we want. */
|
130 | 5607c388 | Markus Armbruster | pci_nic_init(&nd_table[i], "e1000", NULL); |
131 | 2c9fade2 | aurel32 | } |
132 | 2c9fade2 | aurel32 | } |
133 | 2c9fade2 | aurel32 | |
134 | 2c9fade2 | aurel32 | /* Load kernel. */
|
135 | 2c9fade2 | aurel32 | if (kernel_filename) {
|
136 | 2c9fade2 | aurel32 | kernel_size = load_uimage(kernel_filename, &entry, &loadaddr, NULL);
|
137 | 2c9fade2 | aurel32 | if (kernel_size < 0) { |
138 | 2c9fade2 | aurel32 | kernel_size = load_elf(kernel_filename, 0, &elf_entry, &elf_lowaddr,
|
139 | 2c9fade2 | aurel32 | NULL);
|
140 | 2c9fade2 | aurel32 | entry = elf_entry; |
141 | 2c9fade2 | aurel32 | loadaddr = elf_lowaddr; |
142 | 2c9fade2 | aurel32 | } |
143 | 2c9fade2 | aurel32 | /* XXX try again as binary */
|
144 | 2c9fade2 | aurel32 | if (kernel_size < 0) { |
145 | 2c9fade2 | aurel32 | fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
146 | 2c9fade2 | aurel32 | kernel_filename); |
147 | 2c9fade2 | aurel32 | exit(1);
|
148 | 2c9fade2 | aurel32 | } |
149 | 2c9fade2 | aurel32 | } |
150 | 2c9fade2 | aurel32 | |
151 | 2c9fade2 | aurel32 | /* Load initrd. */
|
152 | 2c9fade2 | aurel32 | if (initrd_filename) {
|
153 | 2c9fade2 | aurel32 | initrd_base = kernel_size + loadaddr; |
154 | dcac9679 | pbrook | initrd_size = load_image_targphys(initrd_filename, initrd_base, |
155 | dcac9679 | pbrook | ram_size - initrd_base); |
156 | 2c9fade2 | aurel32 | |
157 | 2c9fade2 | aurel32 | if (initrd_size < 0) { |
158 | 2c9fade2 | aurel32 | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
|
159 | 2c9fade2 | aurel32 | initrd_filename); |
160 | 2c9fade2 | aurel32 | exit(1);
|
161 | 2c9fade2 | aurel32 | } |
162 | 2c9fade2 | aurel32 | } |
163 | 2c9fade2 | aurel32 | |
164 | 2c9fade2 | aurel32 | /* If we're loading a kernel directly, we must load the device tree too. */
|
165 | 2c9fade2 | aurel32 | if (kernel_filename) {
|
166 | 2c9fade2 | aurel32 | if (initrd_base)
|
167 | 2c9fade2 | aurel32 | dt_base = initrd_base + initrd_size; |
168 | 2c9fade2 | aurel32 | else
|
169 | 2c9fade2 | aurel32 | dt_base = kernel_size + loadaddr; |
170 | 2c9fade2 | aurel32 | |
171 | 7ec632b4 | pbrook | fdt = bamboo_load_device_tree(dt_base, ram_size, |
172 | 2c9fade2 | aurel32 | initrd_base, initrd_size, kernel_cmdline); |
173 | 2c9fade2 | aurel32 | if (fdt == NULL) { |
174 | 2c9fade2 | aurel32 | fprintf(stderr, "couldn't load device tree\n");
|
175 | 2c9fade2 | aurel32 | exit(1);
|
176 | 2c9fade2 | aurel32 | } |
177 | 2c9fade2 | aurel32 | |
178 | 2c9fade2 | aurel32 | /* Set initial guest state. */
|
179 | 2c9fade2 | aurel32 | env->gpr[1] = (16<<20) - 8; |
180 | 2c9fade2 | aurel32 | env->gpr[3] = dt_base;
|
181 | 2c9fade2 | aurel32 | env->nip = entry; |
182 | 2c9fade2 | aurel32 | /* XXX we currently depend on KVM to create some initial TLB entries. */
|
183 | 2c9fade2 | aurel32 | } |
184 | 2c9fade2 | aurel32 | |
185 | 2c9fade2 | aurel32 | if (kvm_enabled())
|
186 | 2c9fade2 | aurel32 | kvmppc_init(); |
187 | 2c9fade2 | aurel32 | } |
188 | 2c9fade2 | aurel32 | |
189 | f80f9ec9 | Anthony Liguori | static QEMUMachine bamboo_machine = {
|
190 | 2c9fade2 | aurel32 | .name = "bamboo",
|
191 | 2c9fade2 | aurel32 | .desc = "bamboo",
|
192 | 2c9fade2 | aurel32 | .init = bamboo_init, |
193 | 2c9fade2 | aurel32 | }; |
194 | f80f9ec9 | Anthony Liguori | |
195 | f80f9ec9 | Anthony Liguori | static void bamboo_machine_init(void) |
196 | f80f9ec9 | Anthony Liguori | { |
197 | f80f9ec9 | Anthony Liguori | qemu_register_machine(&bamboo_machine); |
198 | f80f9ec9 | Anthony Liguori | } |
199 | f80f9ec9 | Anthony Liguori | |
200 | f80f9ec9 | Anthony Liguori | machine_init(bamboo_machine_init); |