Statistics
| Branch: | Revision:

root / hw / etraxfs.c @ 8217606e

History | View | Annotate | Download (6 kB)

1 83fa1010 ths
/*
2 83fa1010 ths
 * QEMU ETRAX System Emulator
3 83fa1010 ths
 *
4 83fa1010 ths
 * Copyright (c) 2007 Edgar E. Iglesias, Axis Communications AB.
5 83fa1010 ths
 *
6 83fa1010 ths
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 83fa1010 ths
 * of this software and associated documentation files (the "Software"), to deal
8 83fa1010 ths
 * in the Software without restriction, including without limitation the rights
9 83fa1010 ths
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 83fa1010 ths
 * copies of the Software, and to permit persons to whom the Software is
11 83fa1010 ths
 * furnished to do so, subject to the following conditions:
12 83fa1010 ths
 *
13 83fa1010 ths
 * The above copyright notice and this permission notice shall be included in
14 83fa1010 ths
 * all copies or substantial portions of the Software.
15 83fa1010 ths
 *
16 83fa1010 ths
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 83fa1010 ths
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 83fa1010 ths
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 83fa1010 ths
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 83fa1010 ths
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 83fa1010 ths
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 83fa1010 ths
 * THE SOFTWARE.
23 83fa1010 ths
 */
24 83fa1010 ths
25 4b816985 Edgar E. Iglesias
#include "sysbus.h"
26 4b816985 Edgar E. Iglesias
#include "boards.h"
27 4b816985 Edgar E. Iglesias
#include "sysemu.h"
28 4b816985 Edgar E. Iglesias
#include "net.h"
29 3b1fd90e Edgar E. Iglesias
#include "flash.h"
30 5ef98b47 edgar_igl
#include "etraxfs.h"
31 b01cde7b edgar_igl
32 b01cde7b edgar_igl
#define FLASH_SIZE 0x2000000
33 b01cde7b edgar_igl
#define INTMEM_SIZE (128 * 1024)
34 83fa1010 ths
35 5439779e edgar_igl
static uint32_t bootstrap_pc;
36 5439779e edgar_igl
37 5439779e edgar_igl
static void main_cpu_reset(void *opaque)
38 5439779e edgar_igl
{
39 5439779e edgar_igl
    CPUState *env = opaque;
40 5439779e edgar_igl
    cpu_reset(env);
41 5439779e edgar_igl
42 5439779e edgar_igl
    env->pc = bootstrap_pc;
43 5439779e edgar_igl
}
44 48318011 edgar_igl
45 83fa1010 ths
static
46 fbe1b595 Paul Brook
void bareetraxfs_init (ram_addr_t ram_size,
47 3023f332 aliguori
                       const char *boot_device,
48 83fa1010 ths
                       const char *kernel_filename, const char *kernel_cmdline,
49 83fa1010 ths
                       const char *initrd_filename, const char *cpu_model)
50 83fa1010 ths
{
51 fd6dc90b Edgar E. Iglesias
    DeviceState *dev;
52 83fa1010 ths
    CPUState *env;
53 fd6dc90b Edgar E. Iglesias
    qemu_irq irq[30], nmi[2], *cpu_irq; 
54 fa1bdde4 edgar_igl
    void *etraxfs_dmac;
55 4eeed608 edgar_igl
    struct etraxfs_dma_client *eth[2] = {NULL, NULL};
56 83fa1010 ths
    int kernel_size;
57 48318011 edgar_igl
    int i;
58 e62b5b13 edgar_igl
    ram_addr_t phys_ram;
59 5439779e edgar_igl
    ram_addr_t phys_flash;
60 b01cde7b edgar_igl
    ram_addr_t phys_intmem;
61 83fa1010 ths
62 83fa1010 ths
    /* init CPUs */
63 83fa1010 ths
    if (cpu_model == NULL) {
64 83fa1010 ths
        cpu_model = "crisv32";
65 83fa1010 ths
    }
66 aaed909a bellard
    env = cpu_init(cpu_model);
67 8217606e Jan Kiszka
    qemu_register_reset(main_cpu_reset, 0, env);
68 83fa1010 ths
69 83fa1010 ths
    /* allocate RAM */
70 e62b5b13 edgar_igl
    phys_ram = qemu_ram_alloc(ram_size);
71 e62b5b13 edgar_igl
    cpu_register_physical_memory(0x40000000, ram_size, phys_ram | IO_MEM_RAM);
72 e62b5b13 edgar_igl
73 b01cde7b edgar_igl
    /* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the 
74 980f8a0b edgar_igl
       internal memory.  */
75 b01cde7b edgar_igl
    phys_intmem = qemu_ram_alloc(INTMEM_SIZE);
76 5439779e edgar_igl
    cpu_register_physical_memory(0x38000000, INTMEM_SIZE,
77 5439779e edgar_igl
                                 phys_intmem | IO_MEM_RAM);
78 5439779e edgar_igl
79 e62b5b13 edgar_igl
80 5439779e edgar_igl
    phys_flash = qemu_ram_alloc(FLASH_SIZE);
81 5439779e edgar_igl
    i = drive_get_index(IF_PFLASH, 0, 0);
82 5439779e edgar_igl
    pflash_cfi02_register(0x0, phys_flash,
83 9eee9a5d edgar_igl
                          i != -1 ? drives_table[i].bdrv : NULL, (64 * 1024),
84 5439779e edgar_igl
                          FLASH_SIZE >> 16,
85 5439779e edgar_igl
                          1, 2, 0x0000, 0x0000, 0x0000, 0x0000,
86 5439779e edgar_igl
                          0x555, 0x2aa);
87 fd6dc90b Edgar E. Iglesias
    cpu_irq = cris_pic_init_cpu(env);
88 fd6dc90b Edgar E. Iglesias
    dev = sysbus_create_varargs("etraxfs,pic", 0x3001c000,
89 fd6dc90b Edgar E. Iglesias
                                cpu_irq[0], cpu_irq[1], NULL);
90 fd6dc90b Edgar E. Iglesias
    /* FIXME: Is there a proper way to signal vectors to the CPU core?  */
91 fd6dc90b Edgar E. Iglesias
    qdev_set_prop_ptr(dev, "interrupt_vector", &env->interrupt_vector);
92 fd6dc90b Edgar E. Iglesias
    for (i = 0; i < 30; i++) {
93 fd6dc90b Edgar E. Iglesias
        irq[i] = qdev_get_irq_sink(dev, i);
94 fd6dc90b Edgar E. Iglesias
    }
95 fd6dc90b Edgar E. Iglesias
    nmi[0] = qdev_get_irq_sink(dev, 30);
96 fd6dc90b Edgar E. Iglesias
    nmi[1] = qdev_get_irq_sink(dev, 31);
97 73cfd29f Edgar E. Iglesias
98 980f8a0b edgar_igl
    etraxfs_dmac = etraxfs_dmac_init(env, 0x30000000, 10);
99 48318011 edgar_igl
    for (i = 0; i < 10; i++) {
100 5439779e edgar_igl
        /* On ETRAX, odd numbered channels are inputs.  */
101 73cfd29f Edgar E. Iglesias
        etraxfs_dmac_connect(etraxfs_dmac, i, irq + 7 + i, i & 1);
102 48318011 edgar_igl
    }
103 48318011 edgar_igl
104 4eeed608 edgar_igl
    /* Add the two ethernet blocks.  */
105 678fdca8 Edgar E. Iglesias
    eth[0] = etraxfs_eth_init(&nd_table[0], env, 0x30034000, 1);
106 0ae18cee aliguori
    if (nb_nics > 1)
107 678fdca8 Edgar E. Iglesias
        eth[1] = etraxfs_eth_init(&nd_table[1], env, 0x30036000, 2);
108 5439779e edgar_igl
109 48318011 edgar_igl
    /* The DMA Connector block is missing, hardwire things for now.  */
110 4eeed608 edgar_igl
    etraxfs_dmac_connect_client(etraxfs_dmac, 0, eth[0]);
111 4eeed608 edgar_igl
    etraxfs_dmac_connect_client(etraxfs_dmac, 1, eth[0] + 1);
112 4eeed608 edgar_igl
    if (eth[1]) {
113 5439779e edgar_igl
        etraxfs_dmac_connect_client(etraxfs_dmac, 6, eth[1]);
114 5439779e edgar_igl
        etraxfs_dmac_connect_client(etraxfs_dmac, 7, eth[1] + 1);
115 4eeed608 edgar_igl
    }
116 48318011 edgar_igl
117 ca87d03b edgar_igl
    /* 2 timers.  */
118 3b1fd90e Edgar E. Iglesias
    sysbus_create_varargs("etraxfs,timer", 0x3001e000, irq[0x1b], nmi[1], NULL);
119 3b1fd90e Edgar E. Iglesias
    sysbus_create_varargs("etraxfs,timer", 0x3005e000, irq[0x1b], nmi[1], NULL);
120 48318011 edgar_igl
121 48318011 edgar_igl
    for (i = 0; i < 4; i++) {
122 4b816985 Edgar E. Iglesias
        sysbus_create_simple("etraxfs,serial", 0x30026000 + i * 0x2000,
123 4b816985 Edgar E. Iglesias
                             irq[0x14 + i]); 
124 48318011 edgar_igl
    }
125 83fa1010 ths
126 5439779e edgar_igl
    if (kernel_filename) {
127 f5a5cca3 edgar_igl
        uint64_t entry, high;
128 f5a5cca3 edgar_igl
        int kcmdline_len;
129 f5a5cca3 edgar_igl
130 5439779e edgar_igl
        /* Boots a kernel elf binary, os/linux-2.6/vmlinux from the axis 
131 5439779e edgar_igl
           devboard SDK.  */
132 8ab94444 edgar_igl
        kernel_size = load_elf(kernel_filename, -0x80000000LL,
133 f5a5cca3 edgar_igl
                               &entry, NULL, &high);
134 fa1bdde4 edgar_igl
        bootstrap_pc = entry;
135 fa1bdde4 edgar_igl
        if (kernel_size < 0) {
136 fa1bdde4 edgar_igl
            /* Takes a kimage from the axis devboard SDK.  */
137 dcac9679 pbrook
            kernel_size = load_image_targphys(kernel_filename, 0x40004000,
138 dcac9679 pbrook
                                              ram_size);
139 fa1bdde4 edgar_igl
            bootstrap_pc = 0x40004000;
140 fa1bdde4 edgar_igl
            env->regs[9] = 0x40004000 + kernel_size;
141 fa1bdde4 edgar_igl
        }
142 8ab94444 edgar_igl
        env->regs[8] = 0x56902387; /* RAM init magic.  */
143 f5a5cca3 edgar_igl
144 f5a5cca3 edgar_igl
        if (kernel_cmdline && (kcmdline_len = strlen(kernel_cmdline))) {
145 f5a5cca3 edgar_igl
            if (kcmdline_len > 256) {
146 f5a5cca3 edgar_igl
                fprintf(stderr, "Too long CRIS kernel cmdline (max 256)\n");
147 f5a5cca3 edgar_igl
                exit(1);
148 f5a5cca3 edgar_igl
            }
149 f5a5cca3 edgar_igl
            /* Let the kernel know we are modifying the cmdline.  */
150 f5a5cca3 edgar_igl
            env->regs[10] = 0x87109563;
151 d33fd9d1 Edgar E. Iglesias
            env->regs[11] = 0x40000000;
152 d33fd9d1 Edgar E. Iglesias
            pstrcpy_targphys(env->regs[11], 256, kernel_cmdline);
153 f5a5cca3 edgar_igl
        }
154 83fa1010 ths
    }
155 5439779e edgar_igl
    env->pc = bootstrap_pc;
156 83fa1010 ths
157 83fa1010 ths
    printf ("pc =%x\n", env->pc);
158 48318011 edgar_igl
    printf ("ram size =%ld\n", ram_size);
159 83fa1010 ths
}
160 83fa1010 ths
161 f80f9ec9 Anthony Liguori
static QEMUMachine bareetraxfs_machine = {
162 4b32e168 aliguori
    .name = "bareetraxfs",
163 4b32e168 aliguori
    .desc = "Bare ETRAX FS board",
164 4b32e168 aliguori
    .init = bareetraxfs_init,
165 0c257437 Anthony Liguori
    .is_default = 1,
166 83fa1010 ths
};
167 f80f9ec9 Anthony Liguori
168 f80f9ec9 Anthony Liguori
static void bareetraxfs_machine_init(void)
169 f80f9ec9 Anthony Liguori
{
170 f80f9ec9 Anthony Liguori
    qemu_register_machine(&bareetraxfs_machine);
171 f80f9ec9 Anthony Liguori
}
172 f80f9ec9 Anthony Liguori
173 f80f9ec9 Anthony Liguori
machine_init(bareetraxfs_machine_init);