2 * Copyright (c) 2011, Max Filippov, Open Source and Linux Lab.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the Open Source and Linux Lab nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "exec-memory.h"
37 typedef struct Lx60FpgaState
{
43 static void lx60_fpga_reset(void *opaque
)
45 Lx60FpgaState
*s
= opaque
;
51 static uint64_t lx60_fpga_read(void *opaque
, target_phys_addr_t addr
,
54 Lx60FpgaState
*s
= opaque
;
57 case 0x0: /*build date code*/
60 case 0x4: /*processor clock frequency, Hz*/
63 case 0x8: /*LEDs (off = 0, on = 1)*/
66 case 0xc: /*DIP switches (off = 0, on = 1)*/
72 static void lx60_fpga_write(void *opaque
, target_phys_addr_t addr
,
73 uint64_t val
, unsigned size
)
75 Lx60FpgaState
*s
= opaque
;
78 case 0x8: /*LEDs (off = 0, on = 1)*/
82 case 0x10: /*board reset*/
84 qemu_system_reset_request();
90 static const MemoryRegionOps lx60_fpga_ops
= {
91 .read
= lx60_fpga_read
,
92 .write
= lx60_fpga_write
,
93 .endianness
= DEVICE_NATIVE_ENDIAN
,
96 static Lx60FpgaState
*lx60_fpga_init(MemoryRegion
*address_space
,
97 target_phys_addr_t base
)
99 Lx60FpgaState
*s
= g_malloc(sizeof(Lx60FpgaState
));
101 memory_region_init_io(&s
->iomem
, &lx60_fpga_ops
, s
,
102 "lx60-fpga", 0x10000);
103 memory_region_add_subregion(address_space
, base
, &s
->iomem
);
105 qemu_register_reset(lx60_fpga_reset
, s
);
109 static void lx60_net_init(MemoryRegion
*address_space
,
110 target_phys_addr_t base
,
111 target_phys_addr_t descriptors
,
112 target_phys_addr_t buffers
,
113 qemu_irq irq
, NICInfo
*nd
)
119 dev
= qdev_create(NULL
, "open_eth");
120 qdev_set_nic_properties(dev
, nd
);
121 qdev_init_nofail(dev
);
123 s
= sysbus_from_qdev(dev
);
124 sysbus_connect_irq(s
, 0, irq
);
125 memory_region_add_subregion(address_space
, base
,
126 sysbus_mmio_get_region(s
, 0));
127 memory_region_add_subregion(address_space
, descriptors
,
128 sysbus_mmio_get_region(s
, 1));
130 ram
= g_malloc(sizeof(*ram
));
131 memory_region_init_ram(ram
, NULL
, "open_eth.ram", 16384);
132 memory_region_add_subregion(address_space
, buffers
, ram
);
135 static uint64_t translate_phys_addr(void *env
, uint64_t addr
)
137 return cpu_get_phys_page_debug(env
, addr
);
140 static void lx60_reset(void *env
)
145 static void lx60_init(ram_addr_t ram_size
,
146 const char *boot_device
,
147 const char *kernel_filename
, const char *kernel_cmdline
,
148 const char *initrd_filename
, const char *cpu_model
)
150 #ifdef TARGET_WORDS_BIGENDIAN
155 MemoryRegion
*system_memory
= get_system_memory();
156 CPUState
*env
= NULL
;
157 MemoryRegion
*ram
, *rom
, *system_io
;
160 for (n
= 0; n
< smp_cpus
; n
++) {
161 env
= cpu_init(cpu_model
);
163 fprintf(stderr
, "Unable to find CPU definition\n");
166 env
->sregs
[PRID
] = n
;
167 qemu_register_reset(lx60_reset
, env
);
168 /* Need MMU initialized prior to ELF loading,
169 * so that ELF gets loaded into virtual addresses
174 ram
= g_malloc(sizeof(*ram
));
175 memory_region_init_ram(ram
, NULL
, "xtensa.sram", ram_size
);
176 memory_region_add_subregion(system_memory
, 0, ram
);
178 rom
= g_malloc(sizeof(*rom
));
179 memory_region_init_ram(rom
, NULL
, "xtensa.rom", 0x1000);
180 memory_region_add_subregion(system_memory
, 0xfe000000, rom
);
182 system_io
= g_malloc(sizeof(*system_io
));
183 memory_region_init(system_io
, "system.io", 224 * 1024 * 1024);
184 memory_region_add_subregion(system_memory
, 0xf0000000, system_io
);
185 lx60_fpga_init(system_io
, 0x0d020000);
186 if (nd_table
[0].vlan
) {
187 lx60_net_init(system_io
, 0x0d030000, 0x0d030400, 0x0d800000,
188 xtensa_get_extint(env
, 1), nd_table
);
191 if (!serial_hds
[0]) {
192 serial_hds
[0] = qemu_chr_new("serial0", "null", NULL
);
195 serial_mm_init(system_io
, 0x0d050020, 2, xtensa_get_extint(env
, 0),
196 115200, serial_hds
[0], DEVICE_NATIVE_ENDIAN
);
198 if (kernel_filename
) {
200 uint64_t elf_lowaddr
;
201 int success
= load_elf(kernel_filename
, translate_phys_addr
, env
,
202 &elf_entry
, &elf_lowaddr
, NULL
, be
, ELF_MACHINE
, 0);
209 static void xtensa_lx60_init(ram_addr_t ram_size
,
210 const char *boot_device
,
211 const char *kernel_filename
, const char *kernel_cmdline
,
212 const char *initrd_filename
, const char *cpu_model
)
215 cpu_model
= "dc232b";
217 lx60_init(ram_size
, boot_device
, kernel_filename
, kernel_cmdline
,
218 initrd_filename
, cpu_model
);
221 static QEMUMachine xtensa_lx60_machine
= {
223 .desc
= "lx60 EVB (dc232b)",
224 .init
= xtensa_lx60_init
,
228 static void xtensa_lx60_machine_init(void)
230 qemu_register_machine(&xtensa_lx60_machine
);
233 machine_init(xtensa_lx60_machine_init
);