xref: /openbmc/qemu/hw/mips/fuloong2e.c (revision 08ae519ab8eb6c9abbd97156cb3678f372521501)
1c3a09ff6SPhilippe Mathieu-Daudé /*
2c3a09ff6SPhilippe Mathieu-Daudé  * QEMU fuloong 2e mini pc support
3c3a09ff6SPhilippe Mathieu-Daudé  *
4c3a09ff6SPhilippe Mathieu-Daudé  * Copyright (c) 2008 yajin (yajin@vm-kernel.org)
5c3a09ff6SPhilippe Mathieu-Daudé  * Copyright (c) 2009 chenming (chenming@rdc.faw.com.cn)
6c3a09ff6SPhilippe Mathieu-Daudé  * Copyright (c) 2010 Huacai Chen (zltjiangshi@gmail.com)
7c3a09ff6SPhilippe Mathieu-Daudé  * This code is licensed under the GNU GPL v2.
8c3a09ff6SPhilippe Mathieu-Daudé  *
9c3a09ff6SPhilippe Mathieu-Daudé  * Contributions after 2012-01-13 are licensed under the terms of the
10c3a09ff6SPhilippe Mathieu-Daudé  * GNU GPL, version 2 or (at your option) any later version.
11c3a09ff6SPhilippe Mathieu-Daudé  */
12c3a09ff6SPhilippe Mathieu-Daudé 
13c3a09ff6SPhilippe Mathieu-Daudé /*
14c3a09ff6SPhilippe Mathieu-Daudé  * Fuloong 2e mini pc is based on ICT/ST Loongson 2e CPU (MIPS III like, 800MHz)
15c3a09ff6SPhilippe Mathieu-Daudé  * https://www.linux-mips.org/wiki/Fuloong_2E
16c3a09ff6SPhilippe Mathieu-Daudé  *
1794a37806SJiaxun Yang  * Loongson 2e manuals:
1894a37806SJiaxun Yang  * https://github.com/loongson-community/docs/tree/master/2E
19c3a09ff6SPhilippe Mathieu-Daudé  */
20c3a09ff6SPhilippe Mathieu-Daudé 
21c3a09ff6SPhilippe Mathieu-Daudé #include "qemu/osdep.h"
222c65db5eSPaolo Bonzini #include "qemu/datadir.h"
23c3a09ff6SPhilippe Mathieu-Daudé #include "qemu/units.h"
24c3a09ff6SPhilippe Mathieu-Daudé #include "qapi/error.h"
25c3a09ff6SPhilippe Mathieu-Daudé #include "cpu.h"
263ca7639fSPhilippe Mathieu-Daudé #include "hw/clock.h"
27c3a09ff6SPhilippe Mathieu-Daudé #include "net/net.h"
28c3a09ff6SPhilippe Mathieu-Daudé #include "hw/boards.h"
29c3a09ff6SPhilippe Mathieu-Daudé #include "hw/i2c/smbus_eeprom.h"
30c3a09ff6SPhilippe Mathieu-Daudé #include "hw/block/flash.h"
31c3a09ff6SPhilippe Mathieu-Daudé #include "hw/mips/mips.h"
324d0c59faSJiaxun Yang #include "hw/mips/bootloader.h"
33c3a09ff6SPhilippe Mathieu-Daudé #include "hw/pci/pci.h"
34c3a09ff6SPhilippe Mathieu-Daudé #include "hw/loader.h"
35c3a09ff6SPhilippe Mathieu-Daudé #include "hw/ide/pci.h"
363dc31cb8SBALATON Zoltan #include "hw/qdev-properties.h"
37c3a09ff6SPhilippe Mathieu-Daudé #include "elf.h"
38c3a09ff6SPhilippe Mathieu-Daudé #include "hw/isa/vt82c686.h"
39c3a09ff6SPhilippe Mathieu-Daudé #include "sysemu/qtest.h"
40c3a09ff6SPhilippe Mathieu-Daudé #include "sysemu/reset.h"
413dc31cb8SBALATON Zoltan #include "sysemu/sysemu.h"
42c3a09ff6SPhilippe Mathieu-Daudé #include "qemu/error-report.h"
43c3a09ff6SPhilippe Mathieu-Daudé 
44df055c65SJiaxun Yang #define ENVP_PADDR              0x2000
45df055c65SJiaxun Yang #define ENVP_VADDR              cpu_mips_phys_to_kseg0(NULL, ENVP_PADDR)
46c3a09ff6SPhilippe Mathieu-Daudé #define ENVP_NB_ENTRIES         16
47c3a09ff6SPhilippe Mathieu-Daudé #define ENVP_ENTRY_SIZE         256
48c3a09ff6SPhilippe Mathieu-Daudé 
49c3a09ff6SPhilippe Mathieu-Daudé /* Fuloong 2e has a 512k flash: Winbond W39L040AP70Z */
50c3a09ff6SPhilippe Mathieu-Daudé #define BIOS_SIZE               (512 * KiB)
51c3a09ff6SPhilippe Mathieu-Daudé 
52c3a09ff6SPhilippe Mathieu-Daudé /*
53c3a09ff6SPhilippe Mathieu-Daudé  * PMON is not part of qemu and released with BSD license, anyone
54c3a09ff6SPhilippe Mathieu-Daudé  * who want to build a pmon binary please first git-clone the source
55c3a09ff6SPhilippe Mathieu-Daudé  * from the git repository at:
5694a37806SJiaxun Yang  * https://github.com/loongson-community/pmon
57c3a09ff6SPhilippe Mathieu-Daudé  */
58c3a09ff6SPhilippe Mathieu-Daudé #define FULOONG_BIOSNAME "pmon_2e.bin"
59c3a09ff6SPhilippe Mathieu-Daudé 
60c3a09ff6SPhilippe Mathieu-Daudé /* PCI SLOT in Fuloong 2e */
61c3a09ff6SPhilippe Mathieu-Daudé #define FULOONG2E_VIA_SLOT        5
62c3a09ff6SPhilippe Mathieu-Daudé #define FULOONG2E_ATI_SLOT        6
63c3a09ff6SPhilippe Mathieu-Daudé #define FULOONG2E_RTL8139_SLOT    7
64c3a09ff6SPhilippe Mathieu-Daudé 
65c3a09ff6SPhilippe Mathieu-Daudé static struct _loaderparams {
66c3a09ff6SPhilippe Mathieu-Daudé     int ram_size;
67c3a09ff6SPhilippe Mathieu-Daudé     const char *kernel_filename;
68c3a09ff6SPhilippe Mathieu-Daudé     const char *kernel_cmdline;
69c3a09ff6SPhilippe Mathieu-Daudé     const char *initrd_filename;
70c3a09ff6SPhilippe Mathieu-Daudé } loaderparams;
71c3a09ff6SPhilippe Mathieu-Daudé 
prom_set(uint32_t * prom_buf,int index,const char * string,...)729edc6313SMarc-André Lureau static void G_GNUC_PRINTF(3, 4) prom_set(uint32_t *prom_buf, int index,
73c3a09ff6SPhilippe Mathieu-Daudé                                         const char *string, ...)
74c3a09ff6SPhilippe Mathieu-Daudé {
75c3a09ff6SPhilippe Mathieu-Daudé     va_list ap;
76c3a09ff6SPhilippe Mathieu-Daudé     int32_t table_addr;
77c3a09ff6SPhilippe Mathieu-Daudé 
78c3a09ff6SPhilippe Mathieu-Daudé     if (index >= ENVP_NB_ENTRIES) {
79c3a09ff6SPhilippe Mathieu-Daudé         return;
80c3a09ff6SPhilippe Mathieu-Daudé     }
81c3a09ff6SPhilippe Mathieu-Daudé 
82c3a09ff6SPhilippe Mathieu-Daudé     if (string == NULL) {
83c3a09ff6SPhilippe Mathieu-Daudé         prom_buf[index] = 0;
84c3a09ff6SPhilippe Mathieu-Daudé         return;
85c3a09ff6SPhilippe Mathieu-Daudé     }
86c3a09ff6SPhilippe Mathieu-Daudé 
87c3a09ff6SPhilippe Mathieu-Daudé     table_addr = sizeof(int32_t) * ENVP_NB_ENTRIES + index * ENVP_ENTRY_SIZE;
88df055c65SJiaxun Yang     prom_buf[index] = tswap32(ENVP_VADDR + table_addr);
89c3a09ff6SPhilippe Mathieu-Daudé 
90c3a09ff6SPhilippe Mathieu-Daudé     va_start(ap, string);
91c3a09ff6SPhilippe Mathieu-Daudé     vsnprintf((char *)prom_buf + table_addr, ENVP_ENTRY_SIZE, string, ap);
92c3a09ff6SPhilippe Mathieu-Daudé     va_end(ap);
93c3a09ff6SPhilippe Mathieu-Daudé }
94c3a09ff6SPhilippe Mathieu-Daudé 
load_kernel(MIPSCPU * cpu)95e41f27ecSJiaxun Yang static uint64_t load_kernel(MIPSCPU *cpu)
96c3a09ff6SPhilippe Mathieu-Daudé {
97dde98994SJiaxun Yang     uint64_t kernel_entry, kernel_high, initrd_size;
98c3a09ff6SPhilippe Mathieu-Daudé     int index = 0;
99c3a09ff6SPhilippe Mathieu-Daudé     long kernel_size;
100c3a09ff6SPhilippe Mathieu-Daudé     ram_addr_t initrd_offset;
101c3a09ff6SPhilippe Mathieu-Daudé     uint32_t *prom_buf;
102c3a09ff6SPhilippe Mathieu-Daudé     long prom_size;
103c3a09ff6SPhilippe Mathieu-Daudé 
104c3a09ff6SPhilippe Mathieu-Daudé     kernel_size = load_elf(loaderparams.kernel_filename, NULL,
105c3a09ff6SPhilippe Mathieu-Daudé                            cpu_mips_kseg0_to_phys, NULL,
106dde98994SJiaxun Yang                            &kernel_entry, NULL,
107dde98994SJiaxun Yang                            &kernel_high, NULL,
108617160c9SBALATON Zoltan                            0, EM_MIPS, 1, 0);
109c3a09ff6SPhilippe Mathieu-Daudé     if (kernel_size < 0) {
110c3a09ff6SPhilippe Mathieu-Daudé         error_report("could not load kernel '%s': %s",
111c3a09ff6SPhilippe Mathieu-Daudé                      loaderparams.kernel_filename,
112c3a09ff6SPhilippe Mathieu-Daudé                      load_elf_strerror(kernel_size));
113c3a09ff6SPhilippe Mathieu-Daudé         exit(1);
114c3a09ff6SPhilippe Mathieu-Daudé     }
115c3a09ff6SPhilippe Mathieu-Daudé 
116c3a09ff6SPhilippe Mathieu-Daudé     /* load initrd */
117c3a09ff6SPhilippe Mathieu-Daudé     initrd_size = 0;
118c3a09ff6SPhilippe Mathieu-Daudé     initrd_offset = 0;
119c3a09ff6SPhilippe Mathieu-Daudé     if (loaderparams.initrd_filename) {
120c3a09ff6SPhilippe Mathieu-Daudé         initrd_size = get_image_size(loaderparams.initrd_filename);
121c3a09ff6SPhilippe Mathieu-Daudé         if (initrd_size > 0) {
122acab36caSPhilippe Mathieu-Daudé             initrd_offset = ROUND_UP(kernel_high, INITRD_PAGE_SIZE);
12374d6bf85SPaolo Bonzini             if (initrd_offset + initrd_size > loaderparams.ram_size) {
124c3a09ff6SPhilippe Mathieu-Daudé                 error_report("memory too small for initial ram disk '%s'",
125c3a09ff6SPhilippe Mathieu-Daudé                              loaderparams.initrd_filename);
126c3a09ff6SPhilippe Mathieu-Daudé                 exit(1);
127c3a09ff6SPhilippe Mathieu-Daudé             }
128c3a09ff6SPhilippe Mathieu-Daudé             initrd_size = load_image_targphys(loaderparams.initrd_filename,
129c3a09ff6SPhilippe Mathieu-Daudé                                               initrd_offset,
13074d6bf85SPaolo Bonzini                                               loaderparams.ram_size - initrd_offset);
131c3a09ff6SPhilippe Mathieu-Daudé         }
132c3a09ff6SPhilippe Mathieu-Daudé         if (initrd_size == (target_ulong) -1) {
133c3a09ff6SPhilippe Mathieu-Daudé             error_report("could not load initial ram disk '%s'",
134c3a09ff6SPhilippe Mathieu-Daudé                          loaderparams.initrd_filename);
135c3a09ff6SPhilippe Mathieu-Daudé             exit(1);
136c3a09ff6SPhilippe Mathieu-Daudé         }
137c3a09ff6SPhilippe Mathieu-Daudé     }
138c3a09ff6SPhilippe Mathieu-Daudé 
139c3a09ff6SPhilippe Mathieu-Daudé     /* Setup prom parameters. */
140c3a09ff6SPhilippe Mathieu-Daudé     prom_size = ENVP_NB_ENTRIES * (sizeof(int32_t) + ENVP_ENTRY_SIZE);
141c3a09ff6SPhilippe Mathieu-Daudé     prom_buf = g_malloc(prom_size);
142c3a09ff6SPhilippe Mathieu-Daudé 
143c3a09ff6SPhilippe Mathieu-Daudé     prom_set(prom_buf, index++, "%s", loaderparams.kernel_filename);
144c3a09ff6SPhilippe Mathieu-Daudé     if (initrd_size > 0) {
145c3a09ff6SPhilippe Mathieu-Daudé         prom_set(prom_buf, index++,
146c3a09ff6SPhilippe Mathieu-Daudé                  "rd_start=0x%" PRIx64 " rd_size=%" PRId64 " %s",
147c3a09ff6SPhilippe Mathieu-Daudé                  cpu_mips_phys_to_kseg0(NULL, initrd_offset),
148c3a09ff6SPhilippe Mathieu-Daudé                  initrd_size, loaderparams.kernel_cmdline);
149c3a09ff6SPhilippe Mathieu-Daudé     } else {
150c3a09ff6SPhilippe Mathieu-Daudé         prom_set(prom_buf, index++, "%s", loaderparams.kernel_cmdline);
151c3a09ff6SPhilippe Mathieu-Daudé     }
152c3a09ff6SPhilippe Mathieu-Daudé 
153c3a09ff6SPhilippe Mathieu-Daudé     /* Setup minimum environment variables */
154c3a09ff6SPhilippe Mathieu-Daudé     prom_set(prom_buf, index++, "busclock=33000000");
155e41f27ecSJiaxun Yang     prom_set(prom_buf, index++, "cpuclock=%u", clock_get_hz(cpu->clock));
156c3a09ff6SPhilippe Mathieu-Daudé     prom_set(prom_buf, index++, "memsize=%"PRIi64, loaderparams.ram_size / MiB);
157c3a09ff6SPhilippe Mathieu-Daudé     prom_set(prom_buf, index++, NULL);
158c3a09ff6SPhilippe Mathieu-Daudé 
159df055c65SJiaxun Yang     rom_add_blob_fixed("prom", prom_buf, prom_size, ENVP_PADDR);
160c3a09ff6SPhilippe Mathieu-Daudé 
161c3a09ff6SPhilippe Mathieu-Daudé     g_free(prom_buf);
162c3a09ff6SPhilippe Mathieu-Daudé     return kernel_entry;
163c3a09ff6SPhilippe Mathieu-Daudé }
164c3a09ff6SPhilippe Mathieu-Daudé 
write_bootloader(CPUMIPSState * env,uint8_t * base,uint64_t kernel_addr)165c3a09ff6SPhilippe Mathieu-Daudé static void write_bootloader(CPUMIPSState *env, uint8_t *base,
166dde98994SJiaxun Yang                              uint64_t kernel_addr)
167c3a09ff6SPhilippe Mathieu-Daudé {
168c3a09ff6SPhilippe Mathieu-Daudé     uint32_t *p;
169c3a09ff6SPhilippe Mathieu-Daudé 
170c3a09ff6SPhilippe Mathieu-Daudé     /* Small bootloader */
171c3a09ff6SPhilippe Mathieu-Daudé     p = (uint32_t *)base;
172c3a09ff6SPhilippe Mathieu-Daudé 
173c3a09ff6SPhilippe Mathieu-Daudé     /* j 0x1fc00040 */
174c3a09ff6SPhilippe Mathieu-Daudé     stl_p(p++, 0x0bf00010);
175c3a09ff6SPhilippe Mathieu-Daudé     /* nop */
176c3a09ff6SPhilippe Mathieu-Daudé     stl_p(p++, 0x00000000);
177c3a09ff6SPhilippe Mathieu-Daudé 
178c3a09ff6SPhilippe Mathieu-Daudé     /* Second part of the bootloader */
179c3a09ff6SPhilippe Mathieu-Daudé     p = (uint32_t *)(base + 0x040);
180c3a09ff6SPhilippe Mathieu-Daudé 
181cd5066f8SPhilippe Mathieu-Daudé     bl_gen_jump_kernel((void **)&p,
18236d7487bSPhilippe Mathieu-Daudé                        true, ENVP_VADDR - 64,
18336d7487bSPhilippe Mathieu-Daudé                        true, 2, true, ENVP_VADDR,
18436d7487bSPhilippe Mathieu-Daudé                        true, ENVP_VADDR + 8,
18536d7487bSPhilippe Mathieu-Daudé                        true, loaderparams.ram_size,
18636d7487bSPhilippe Mathieu-Daudé                        kernel_addr);
187c3a09ff6SPhilippe Mathieu-Daudé }
188c3a09ff6SPhilippe Mathieu-Daudé 
main_cpu_reset(void * opaque)189c3a09ff6SPhilippe Mathieu-Daudé static void main_cpu_reset(void *opaque)
190c3a09ff6SPhilippe Mathieu-Daudé {
191c3a09ff6SPhilippe Mathieu-Daudé     MIPSCPU *cpu = opaque;
192c3a09ff6SPhilippe Mathieu-Daudé     CPUMIPSState *env = &cpu->env;
193c3a09ff6SPhilippe Mathieu-Daudé 
194c3a09ff6SPhilippe Mathieu-Daudé     cpu_reset(CPU(cpu));
195c3a09ff6SPhilippe Mathieu-Daudé     /* TODO: 2E reset stuff */
196c3a09ff6SPhilippe Mathieu-Daudé     if (loaderparams.kernel_filename) {
197c3a09ff6SPhilippe Mathieu-Daudé         env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL));
198c3a09ff6SPhilippe Mathieu-Daudé     }
199c3a09ff6SPhilippe Mathieu-Daudé }
200c3a09ff6SPhilippe Mathieu-Daudé 
201c3a09ff6SPhilippe Mathieu-Daudé /* Network support */
network_init(PCIBus * pci_bus)202c3a09ff6SPhilippe Mathieu-Daudé static void network_init(PCIBus *pci_bus)
203c3a09ff6SPhilippe Mathieu-Daudé {
204c3a09ff6SPhilippe Mathieu-Daudé     /* The Fuloong board has a RTL8139 card using PCI SLOT 7 */
2058e437561SDavid Woodhouse     pci_init_nic_in_slot(pci_bus, "rtl8139", NULL, "07");
2068e437561SDavid Woodhouse     pci_init_nic_devices(pci_bus, "rtl8139");
207c3a09ff6SPhilippe Mathieu-Daudé }
208c3a09ff6SPhilippe Mathieu-Daudé 
mips_fuloong2e_init(MachineState * machine)209c3a09ff6SPhilippe Mathieu-Daudé static void mips_fuloong2e_init(MachineState *machine)
210c3a09ff6SPhilippe Mathieu-Daudé {
211c3a09ff6SPhilippe Mathieu-Daudé     const char *kernel_filename = machine->kernel_filename;
212c3a09ff6SPhilippe Mathieu-Daudé     const char *kernel_cmdline = machine->kernel_cmdline;
213c3a09ff6SPhilippe Mathieu-Daudé     const char *initrd_filename = machine->initrd_filename;
214c3a09ff6SPhilippe Mathieu-Daudé     char *filename;
215c3a09ff6SPhilippe Mathieu-Daudé     MemoryRegion *address_space_mem = get_system_memory();
216c3a09ff6SPhilippe Mathieu-Daudé     MemoryRegion *bios = g_new(MemoryRegion, 1);
217c3a09ff6SPhilippe Mathieu-Daudé     long bios_size;
218c3a09ff6SPhilippe Mathieu-Daudé     uint8_t *spd_data;
219dde98994SJiaxun Yang     uint64_t kernel_entry;
2209307d06dSMarkus Armbruster     PCIDevice *pci_dev;
221c3a09ff6SPhilippe Mathieu-Daudé     PCIBus *pci_bus;
222c3a09ff6SPhilippe Mathieu-Daudé     I2CBus *smbus;
2233ca7639fSPhilippe Mathieu-Daudé     Clock *cpuclk;
224c3a09ff6SPhilippe Mathieu-Daudé     MIPSCPU *cpu;
225c3a09ff6SPhilippe Mathieu-Daudé     CPUMIPSState *env;
226c3a09ff6SPhilippe Mathieu-Daudé     DeviceState *dev;
227c3a09ff6SPhilippe Mathieu-Daudé 
2283ca7639fSPhilippe Mathieu-Daudé     cpuclk = clock_new(OBJECT(machine), "cpu-refclk");
2293ca7639fSPhilippe Mathieu-Daudé     clock_set_hz(cpuclk, 533080000); /* ~533 MHz */
2303ca7639fSPhilippe Mathieu-Daudé 
231c3a09ff6SPhilippe Mathieu-Daudé     /* init CPUs */
232*3e8f019bSPhilippe Mathieu-Daudé     cpu = mips_cpu_create_with_clock(machine->cpu_type, cpuclk, false);
233c3a09ff6SPhilippe Mathieu-Daudé     env = &cpu->env;
234c3a09ff6SPhilippe Mathieu-Daudé 
235c3a09ff6SPhilippe Mathieu-Daudé     qemu_register_reset(main_cpu_reset, cpu);
236c3a09ff6SPhilippe Mathieu-Daudé 
237c3a09ff6SPhilippe Mathieu-Daudé     /* TODO: support more than 256M RAM as highmem */
238c3a09ff6SPhilippe Mathieu-Daudé     if (machine->ram_size != 256 * MiB) {
239c3a09ff6SPhilippe Mathieu-Daudé         error_report("Invalid RAM size, should be 256MB");
240c3a09ff6SPhilippe Mathieu-Daudé         exit(EXIT_FAILURE);
241c3a09ff6SPhilippe Mathieu-Daudé     }
242c3a09ff6SPhilippe Mathieu-Daudé     memory_region_add_subregion(address_space_mem, 0, machine->ram);
243c3a09ff6SPhilippe Mathieu-Daudé 
244c3a09ff6SPhilippe Mathieu-Daudé     /* Boot ROM */
245c3a09ff6SPhilippe Mathieu-Daudé     memory_region_init_rom(bios, NULL, "fuloong2e.bios", BIOS_SIZE,
246c3a09ff6SPhilippe Mathieu-Daudé                            &error_fatal);
247c3a09ff6SPhilippe Mathieu-Daudé     memory_region_add_subregion(address_space_mem, 0x1fc00000LL, bios);
248c3a09ff6SPhilippe Mathieu-Daudé 
249c3a09ff6SPhilippe Mathieu-Daudé     /*
250c3a09ff6SPhilippe Mathieu-Daudé      * We do not support flash operation, just loading pmon.bin as raw BIOS.
251c3a09ff6SPhilippe Mathieu-Daudé      * Please use -L to set the BIOS path and -bios to set bios name.
252c3a09ff6SPhilippe Mathieu-Daudé      */
253c3a09ff6SPhilippe Mathieu-Daudé 
254c3a09ff6SPhilippe Mathieu-Daudé     if (kernel_filename) {
255c3a09ff6SPhilippe Mathieu-Daudé         loaderparams.ram_size = machine->ram_size;
256c3a09ff6SPhilippe Mathieu-Daudé         loaderparams.kernel_filename = kernel_filename;
257c3a09ff6SPhilippe Mathieu-Daudé         loaderparams.kernel_cmdline = kernel_cmdline;
258c3a09ff6SPhilippe Mathieu-Daudé         loaderparams.initrd_filename = initrd_filename;
259e41f27ecSJiaxun Yang         kernel_entry = load_kernel(cpu);
260c3a09ff6SPhilippe Mathieu-Daudé         write_bootloader(env, memory_region_get_ram_ptr(bios), kernel_entry);
261c3a09ff6SPhilippe Mathieu-Daudé     } else {
262a4374f86SPavel Dovgalyuk         filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
26359588beaSPaolo Bonzini                                   machine->firmware ?: FULOONG_BIOSNAME);
264c3a09ff6SPhilippe Mathieu-Daudé         if (filename) {
265c3a09ff6SPhilippe Mathieu-Daudé             bios_size = load_image_targphys(filename, 0x1fc00000LL,
266c3a09ff6SPhilippe Mathieu-Daudé                                             BIOS_SIZE);
267c3a09ff6SPhilippe Mathieu-Daudé             g_free(filename);
268c3a09ff6SPhilippe Mathieu-Daudé         } else {
269c3a09ff6SPhilippe Mathieu-Daudé             bios_size = -1;
270c3a09ff6SPhilippe Mathieu-Daudé         }
271c3a09ff6SPhilippe Mathieu-Daudé 
272c3a09ff6SPhilippe Mathieu-Daudé         if ((bios_size < 0 || bios_size > BIOS_SIZE) &&
27359588beaSPaolo Bonzini             machine->firmware && !qtest_enabled()) {
27459588beaSPaolo Bonzini             error_report("Could not load MIPS bios '%s'", machine->firmware);
275c3a09ff6SPhilippe Mathieu-Daudé             exit(1);
276c3a09ff6SPhilippe Mathieu-Daudé         }
277c3a09ff6SPhilippe Mathieu-Daudé     }
278c3a09ff6SPhilippe Mathieu-Daudé 
279c3a09ff6SPhilippe Mathieu-Daudé     /* Init internal devices */
280c3a09ff6SPhilippe Mathieu-Daudé     cpu_mips_irq_init_cpu(cpu);
281c3a09ff6SPhilippe Mathieu-Daudé     cpu_mips_clock_init(cpu);
282c3a09ff6SPhilippe Mathieu-Daudé 
283c3a09ff6SPhilippe Mathieu-Daudé     /* North bridge, Bonito --> IP2 */
284c3a09ff6SPhilippe Mathieu-Daudé     pci_bus = bonito_init((qemu_irq *)&(env->irq[2]));
285c3a09ff6SPhilippe Mathieu-Daudé 
286c3a09ff6SPhilippe Mathieu-Daudé     /* South bridge -> IP5 */
2879dcb64c9SPaolo Bonzini     pci_dev = pci_new_multifunction(PCI_DEVFN(FULOONG2E_VIA_SLOT, 0),
288e052944aSBernhard Beschow                                     TYPE_VT82C686B_ISA);
2899dcb64c9SPaolo Bonzini 
2909dcb64c9SPaolo Bonzini     /* Set properties on individual devices before realizing the south bridge */
2919dcb64c9SPaolo Bonzini     if (machine->audiodev) {
2929dcb64c9SPaolo Bonzini         dev = DEVICE(object_resolve_path_component(OBJECT(pci_dev), "ac97"));
2939dcb64c9SPaolo Bonzini         qdev_prop_set_string(dev, "audiodev", machine->audiodev);
2949dcb64c9SPaolo Bonzini     }
2959dcb64c9SPaolo Bonzini 
2969dcb64c9SPaolo Bonzini     pci_realize_and_unref(pci_dev, pci_bus, &error_abort);
2979dcb64c9SPaolo Bonzini 
298ff9105daSBernhard Beschow     object_property_add_alias(OBJECT(machine), "rtc-time",
299ff9105daSBernhard Beschow                               object_resolve_path_component(OBJECT(pci_dev),
300ff9105daSBernhard Beschow                                                             "rtc"),
301ff9105daSBernhard Beschow                               "date");
3029a365c25SBernhard Beschow     qdev_connect_gpio_out_named(DEVICE(pci_dev), "intr", 0, env->irq[5]);
3034ff5328bSBernhard Beschow 
3044ff5328bSBernhard Beschow     dev = DEVICE(object_resolve_path_component(OBJECT(pci_dev), "ide"));
3054ff5328bSBernhard Beschow     pci_ide_create_devs(PCI_DEVICE(dev));
3064ff5328bSBernhard Beschow 
3074ff5328bSBernhard Beschow     dev = DEVICE(object_resolve_path_component(OBJECT(pci_dev), "pm"));
3084ff5328bSBernhard Beschow     smbus = I2C_BUS(qdev_get_child_bus(dev, "i2c"));
309c3a09ff6SPhilippe Mathieu-Daudé 
310c3a09ff6SPhilippe Mathieu-Daudé     /* GPU */
311c3a09ff6SPhilippe Mathieu-Daudé     if (vga_interface_type != VGA_NONE) {
312f9bcb2d6SGautam Agrawal         vga_interface_created = true;
3139307d06dSMarkus Armbruster         pci_dev = pci_new(-1, "ati-vga");
3149307d06dSMarkus Armbruster         dev = DEVICE(pci_dev);
315c3a09ff6SPhilippe Mathieu-Daudé         qdev_prop_set_uint32(dev, "vgamem_mb", 16);
316c3a09ff6SPhilippe Mathieu-Daudé         qdev_prop_set_uint16(dev, "x-device-id", 0x5159);
3179307d06dSMarkus Armbruster         pci_realize_and_unref(pci_dev, pci_bus, &error_fatal);
318c3a09ff6SPhilippe Mathieu-Daudé     }
319c3a09ff6SPhilippe Mathieu-Daudé 
320c3a09ff6SPhilippe Mathieu-Daudé     /* Populate SPD eeprom data */
321c3a09ff6SPhilippe Mathieu-Daudé     spd_data = spd_data_generate(DDR, machine->ram_size);
322c3a09ff6SPhilippe Mathieu-Daudé     smbus_eeprom_init_one(smbus, 0x50, spd_data);
323c3a09ff6SPhilippe Mathieu-Daudé 
324c3a09ff6SPhilippe Mathieu-Daudé     /* Network card: RTL8139D */
325c3a09ff6SPhilippe Mathieu-Daudé     network_init(pci_bus);
326c3a09ff6SPhilippe Mathieu-Daudé }
327c3a09ff6SPhilippe Mathieu-Daudé 
mips_fuloong2e_machine_init(MachineClass * mc)328c3a09ff6SPhilippe Mathieu-Daudé static void mips_fuloong2e_machine_init(MachineClass *mc)
329c3a09ff6SPhilippe Mathieu-Daudé {
330c3a09ff6SPhilippe Mathieu-Daudé     mc->desc = "Fuloong 2e mini pc";
331c3a09ff6SPhilippe Mathieu-Daudé     mc->init = mips_fuloong2e_init;
332c3a09ff6SPhilippe Mathieu-Daudé     mc->block_default_type = IF_IDE;
333c3a09ff6SPhilippe Mathieu-Daudé     mc->default_cpu_type = MIPS_CPU_TYPE_NAME("Loongson-2E");
334c3a09ff6SPhilippe Mathieu-Daudé     mc->default_ram_size = 256 * MiB;
335c3a09ff6SPhilippe Mathieu-Daudé     mc->default_ram_id = "fuloong2e.ram";
336a08d60bcSHuacai Chen     mc->minimum_page_bits = 14;
3379dcb64c9SPaolo Bonzini     machine_add_audiodev_property(mc);
338c3a09ff6SPhilippe Mathieu-Daudé }
339c3a09ff6SPhilippe Mathieu-Daudé 
340c3a09ff6SPhilippe Mathieu-Daudé DEFINE_MACHINE("fuloong2e", mips_fuloong2e_machine_init)
341