root / hw / etraxfs.c @ 5439779e
History | View | Annotate | Download (5.9 kB)
1 |
/*
|
---|---|
2 |
* QEMU ETRAX System Emulator
|
3 |
*
|
4 |
* Copyright (c) 2007 Edgar E. Iglesias, Axis Communications AB.
|
5 |
*
|
6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 |
* of this software and associated documentation files (the "Software"), to deal
|
8 |
* in the Software without restriction, including without limitation the rights
|
9 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 |
* copies of the Software, and to permit persons to whom the Software is
|
11 |
* furnished to do so, subject to the following conditions:
|
12 |
*
|
13 |
* The above copyright notice and this permission notice shall be included in
|
14 |
* all copies or substantial portions of the Software.
|
15 |
*
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 |
* THE SOFTWARE.
|
23 |
*/
|
24 |
#include <time.h> |
25 |
#include <sys/time.h> |
26 |
#include "hw.h" |
27 |
#include "net.h" |
28 |
#include "flash.h" |
29 |
#include "sysemu.h" |
30 |
#include "devices.h" |
31 |
#include "boards.h" |
32 |
|
33 |
#include "etraxfs_dma.h" |
34 |
|
35 |
/* Init functions for different blocks. */
|
36 |
extern qemu_irq *etraxfs_pic_init(CPUState *env, target_phys_addr_t base);
|
37 |
void etraxfs_timer_init(CPUState *env, qemu_irq *irqs,
|
38 |
target_phys_addr_t base); |
39 |
void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
|
40 |
qemu_irq *irq, target_phys_addr_t base); |
41 |
void etraxfs_ser_init(CPUState *env, qemu_irq *irq, CharDriverState *chr,
|
42 |
target_phys_addr_t base); |
43 |
|
44 |
#define FLASH_SIZE 0x2000000 |
45 |
#define INTMEM_SIZE (128 * 1024) |
46 |
|
47 |
static void *etraxfs_dmac; |
48 |
static uint32_t bootstrap_pc;
|
49 |
|
50 |
static void main_cpu_reset(void *opaque) |
51 |
{ |
52 |
CPUState *env = opaque; |
53 |
cpu_reset(env); |
54 |
|
55 |
env->pregs[PR_CCS] &= ~I_FLAG; |
56 |
env->pc = bootstrap_pc; |
57 |
} |
58 |
|
59 |
static
|
60 |
void bareetraxfs_init (ram_addr_t ram_size, int vga_ram_size, |
61 |
const char *boot_device, DisplayState *ds, |
62 |
const char *kernel_filename, const char *kernel_cmdline, |
63 |
const char *initrd_filename, const char *cpu_model) |
64 |
{ |
65 |
CPUState *env; |
66 |
qemu_irq *pic; |
67 |
struct etraxfs_dma_client *eth[2] = {NULL, NULL}; |
68 |
int kernel_size;
|
69 |
int i;
|
70 |
ram_addr_t phys_ram; |
71 |
ram_addr_t phys_flash; |
72 |
ram_addr_t phys_intmem; |
73 |
|
74 |
/* init CPUs */
|
75 |
if (cpu_model == NULL) { |
76 |
cpu_model = "crisv32";
|
77 |
} |
78 |
env = cpu_init(cpu_model); |
79 |
/* register_savevm("cpu", 0, 3, cpu_save, cpu_load, env); */
|
80 |
qemu_register_reset(main_cpu_reset, env); |
81 |
|
82 |
/* allocate RAM */
|
83 |
phys_ram = qemu_ram_alloc(ram_size); |
84 |
cpu_register_physical_memory(0x40000000, ram_size, phys_ram | IO_MEM_RAM);
|
85 |
/* Unached mapping. */
|
86 |
cpu_register_physical_memory(0xc0000000, ram_size, phys_ram | IO_MEM_RAM);
|
87 |
|
88 |
/* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the
|
89 |
internal memory. Cached and uncached mappings. */
|
90 |
phys_intmem = qemu_ram_alloc(INTMEM_SIZE); |
91 |
cpu_register_physical_memory(0xb8000000, INTMEM_SIZE,
|
92 |
phys_intmem | IO_MEM_RAM); |
93 |
cpu_register_physical_memory(0x38000000, INTMEM_SIZE,
|
94 |
phys_intmem | IO_MEM_RAM); |
95 |
|
96 |
|
97 |
phys_flash = qemu_ram_alloc(FLASH_SIZE); |
98 |
i = drive_get_index(IF_PFLASH, 0, 0); |
99 |
pflash_cfi02_register(0x80000000, phys_flash,
|
100 |
drives_table[i].bdrv, (64 * 1024), |
101 |
FLASH_SIZE >> 16,
|
102 |
1, 2, 0x0000, 0x0000, 0x0000, 0x0000, |
103 |
0x555, 0x2aa); |
104 |
pflash_cfi02_register(0x0, phys_flash,
|
105 |
drives_table[i].bdrv, (64 * 1024), |
106 |
FLASH_SIZE >> 16,
|
107 |
1, 2, 0x0000, 0x0000, 0x0000, 0x0000, |
108 |
0x555, 0x2aa); |
109 |
pic = etraxfs_pic_init(env, 0xb001c000);
|
110 |
etraxfs_dmac = etraxfs_dmac_init(env, 0xb0000000, 10); |
111 |
for (i = 0; i < 10; i++) { |
112 |
/* On ETRAX, odd numbered channels are inputs. */
|
113 |
etraxfs_dmac_connect(etraxfs_dmac, i, pic + 7 + i, i & 1); |
114 |
} |
115 |
|
116 |
/* Add the two ethernet blocks. */
|
117 |
eth[0] = etraxfs_eth_init(&nd_table[0], env, pic + 25, 0xb0034000); |
118 |
if (nb_nics > 1) |
119 |
eth[1] = etraxfs_eth_init(&nd_table[1], env, pic + 26, 0xb0036000); |
120 |
|
121 |
/* The DMA Connector block is missing, hardwire things for now. */
|
122 |
etraxfs_dmac_connect_client(etraxfs_dmac, 0, eth[0]); |
123 |
etraxfs_dmac_connect_client(etraxfs_dmac, 1, eth[0] + 1); |
124 |
if (eth[1]) { |
125 |
etraxfs_dmac_connect_client(etraxfs_dmac, 6, eth[1]); |
126 |
etraxfs_dmac_connect_client(etraxfs_dmac, 7, eth[1] + 1); |
127 |
} |
128 |
|
129 |
/* 2 timers. */
|
130 |
etraxfs_timer_init(env, pic + 0x1b, 0xb001e000); |
131 |
etraxfs_timer_init(env, pic + 0x1b, 0xb005e000); |
132 |
|
133 |
for (i = 0; i < 4; i++) { |
134 |
if (serial_hds[i]) {
|
135 |
etraxfs_ser_init(env, pic + 0x14 + i,
|
136 |
serial_hds[i], 0xb0026000 + i * 0x2000); |
137 |
} |
138 |
} |
139 |
|
140 |
if (kernel_filename) {
|
141 |
#if 1 |
142 |
/* Boots a kernel elf binary, os/linux-2.6/vmlinux from the axis
|
143 |
devboard SDK. */
|
144 |
kernel_size = load_elf(kernel_filename, 0,
|
145 |
&bootstrap_pc, NULL, NULL); |
146 |
#else
|
147 |
/* Takes a kimage from the axis devboard SDK. */
|
148 |
kernel_size = load_image(kernel_filename, phys_ram_base + 0x4000);
|
149 |
bootstrap_pc = 0x40004000;
|
150 |
/* magic for boot. */
|
151 |
env->regs[8] = 0x56902387; |
152 |
env->regs[9] = 0x40004000 + kernel_size; |
153 |
#endif
|
154 |
} |
155 |
env->pc = bootstrap_pc; |
156 |
|
157 |
printf ("pc =%x\n", env->pc);
|
158 |
printf ("ram size =%ld\n", ram_size);
|
159 |
} |
160 |
|
161 |
void DMA_run(void) |
162 |
{ |
163 |
etraxfs_dmac_run(etraxfs_dmac); |
164 |
} |
165 |
|
166 |
QEMUMachine bareetraxfs_machine = { |
167 |
"bareetraxfs",
|
168 |
"Bare ETRAX FS board",
|
169 |
bareetraxfs_init, |
170 |
0x8000000,
|
171 |
}; |