Statistics
| Branch: | Revision:

root / hw / etraxfs.c @ e7b43f7e

History | View | Annotate | Download (5.4 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 ca20cf32 Blue Swirl
#include "loader.h"
32 ca20cf32 Blue Swirl
#include "elf.h"
33 77d4f95e Edgar E. Iglesias
#include "cris-boot.h"
34 2446333c Blue Swirl
#include "blockdev.h"
35 b01cde7b edgar_igl
36 b01cde7b edgar_igl
#define FLASH_SIZE 0x2000000
37 b01cde7b edgar_igl
#define INTMEM_SIZE (128 * 1024)
38 83fa1010 ths
39 77d4f95e Edgar E. Iglesias
static struct cris_load_info li;
40 5439779e edgar_igl
41 77d4f95e Edgar E. Iglesias
static void flash_cpu_reset(void *opaque)
42 5439779e edgar_igl
{
43 5439779e edgar_igl
    CPUState *env = opaque;
44 5439779e edgar_igl
    cpu_reset(env);
45 409dbce5 Aurelien Jarno
}
46 409dbce5 Aurelien Jarno
47 83fa1010 ths
static
48 c227f099 Anthony Liguori
void bareetraxfs_init (ram_addr_t ram_size,
49 3023f332 aliguori
                       const char *boot_device,
50 83fa1010 ths
                       const char *kernel_filename, const char *kernel_cmdline,
51 83fa1010 ths
                       const char *initrd_filename, const char *cpu_model)
52 83fa1010 ths
{
53 fd6dc90b Edgar E. Iglesias
    DeviceState *dev;
54 562183de Edgar E. Iglesias
    SysBusDevice *s;
55 83fa1010 ths
    CPUState *env;
56 fd6dc90b Edgar E. Iglesias
    qemu_irq irq[30], nmi[2], *cpu_irq; 
57 fa1bdde4 edgar_igl
    void *etraxfs_dmac;
58 4eeed608 edgar_igl
    struct etraxfs_dma_client *eth[2] = {NULL, NULL};
59 751c6a17 Gerd Hoffmann
    DriveInfo *dinfo;
60 48318011 edgar_igl
    int i;
61 c227f099 Anthony Liguori
    ram_addr_t phys_ram;
62 c227f099 Anthony Liguori
    ram_addr_t phys_flash;
63 c227f099 Anthony Liguori
    ram_addr_t phys_intmem;
64 83fa1010 ths
65 83fa1010 ths
    /* init CPUs */
66 83fa1010 ths
    if (cpu_model == NULL) {
67 83fa1010 ths
        cpu_model = "crisv32";
68 83fa1010 ths
    }
69 aaed909a bellard
    env = cpu_init(cpu_model);
70 83fa1010 ths
71 83fa1010 ths
    /* allocate RAM */
72 1724f049 Alex Williamson
    phys_ram = qemu_ram_alloc(NULL, "etraxfs.ram", ram_size);
73 e62b5b13 edgar_igl
    cpu_register_physical_memory(0x40000000, ram_size, phys_ram | IO_MEM_RAM);
74 e62b5b13 edgar_igl
75 b01cde7b edgar_igl
    /* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the 
76 980f8a0b edgar_igl
       internal memory.  */
77 1724f049 Alex Williamson
    phys_intmem = qemu_ram_alloc(NULL, "etraxfs.chipram", INTMEM_SIZE);
78 5439779e edgar_igl
    cpu_register_physical_memory(0x38000000, INTMEM_SIZE,
79 5439779e edgar_igl
                                 phys_intmem | IO_MEM_RAM);
80 5439779e edgar_igl
81 e62b5b13 edgar_igl
82 1724f049 Alex Williamson
    phys_flash = qemu_ram_alloc(NULL, "etraxfs.flash", FLASH_SIZE);
83 751c6a17 Gerd Hoffmann
    dinfo = drive_get(IF_PFLASH, 0, 0);
84 5439779e edgar_igl
    pflash_cfi02_register(0x0, phys_flash,
85 751c6a17 Gerd Hoffmann
                          dinfo ? dinfo->bdrv : NULL, (64 * 1024),
86 5439779e edgar_igl
                          FLASH_SIZE >> 16,
87 5439779e edgar_igl
                          1, 2, 0x0000, 0x0000, 0x0000, 0x0000,
88 5f9fc5ad Blue Swirl
                          0x555, 0x2aa, 0);
89 fd6dc90b Edgar E. Iglesias
    cpu_irq = cris_pic_init_cpu(env);
90 562183de Edgar E. Iglesias
    dev = qdev_create(NULL, "etraxfs,pic");
91 fd6dc90b Edgar E. Iglesias
    /* FIXME: Is there a proper way to signal vectors to the CPU core?  */
92 ee6847d1 Gerd Hoffmann
    qdev_prop_set_ptr(dev, "interrupt_vector", &env->interrupt_vector);
93 e23a1b33 Markus Armbruster
    qdev_init_nofail(dev);
94 562183de Edgar E. Iglesias
    s = sysbus_from_qdev(dev);
95 562183de Edgar E. Iglesias
    sysbus_mmio_map(s, 0, 0x3001c000);
96 562183de Edgar E. Iglesias
    sysbus_connect_irq(s, 0, cpu_irq[0]);
97 562183de Edgar E. Iglesias
    sysbus_connect_irq(s, 1, cpu_irq[1]);
98 fd6dc90b Edgar E. Iglesias
    for (i = 0; i < 30; i++) {
99 067a3ddc Paul Brook
        irq[i] = qdev_get_gpio_in(dev, i);
100 fd6dc90b Edgar E. Iglesias
    }
101 067a3ddc Paul Brook
    nmi[0] = qdev_get_gpio_in(dev, 30);
102 067a3ddc Paul Brook
    nmi[1] = qdev_get_gpio_in(dev, 31);
103 73cfd29f Edgar E. Iglesias
104 ba494313 Edgar E. Iglesias
    etraxfs_dmac = etraxfs_dmac_init(0x30000000, 10);
105 48318011 edgar_igl
    for (i = 0; i < 10; i++) {
106 5439779e edgar_igl
        /* On ETRAX, odd numbered channels are inputs.  */
107 73cfd29f Edgar E. Iglesias
        etraxfs_dmac_connect(etraxfs_dmac, i, irq + 7 + i, i & 1);
108 48318011 edgar_igl
    }
109 48318011 edgar_igl
110 4eeed608 edgar_igl
    /* Add the two ethernet blocks.  */
111 ba494313 Edgar E. Iglesias
    eth[0] = etraxfs_eth_init(&nd_table[0], 0x30034000, 1);
112 0ae18cee aliguori
    if (nb_nics > 1)
113 ba494313 Edgar E. Iglesias
        eth[1] = etraxfs_eth_init(&nd_table[1], 0x30036000, 2);
114 5439779e edgar_igl
115 48318011 edgar_igl
    /* The DMA Connector block is missing, hardwire things for now.  */
116 4eeed608 edgar_igl
    etraxfs_dmac_connect_client(etraxfs_dmac, 0, eth[0]);
117 4eeed608 edgar_igl
    etraxfs_dmac_connect_client(etraxfs_dmac, 1, eth[0] + 1);
118 4eeed608 edgar_igl
    if (eth[1]) {
119 5439779e edgar_igl
        etraxfs_dmac_connect_client(etraxfs_dmac, 6, eth[1]);
120 5439779e edgar_igl
        etraxfs_dmac_connect_client(etraxfs_dmac, 7, eth[1] + 1);
121 4eeed608 edgar_igl
    }
122 48318011 edgar_igl
123 ca87d03b edgar_igl
    /* 2 timers.  */
124 3b1fd90e Edgar E. Iglesias
    sysbus_create_varargs("etraxfs,timer", 0x3001e000, irq[0x1b], nmi[1], NULL);
125 3b1fd90e Edgar E. Iglesias
    sysbus_create_varargs("etraxfs,timer", 0x3005e000, irq[0x1b], nmi[1], NULL);
126 48318011 edgar_igl
127 48318011 edgar_igl
    for (i = 0; i < 4; i++) {
128 4b816985 Edgar E. Iglesias
        sysbus_create_simple("etraxfs,serial", 0x30026000 + i * 0x2000,
129 4b816985 Edgar E. Iglesias
                             irq[0x14 + i]); 
130 48318011 edgar_igl
    }
131 83fa1010 ths
132 5439779e edgar_igl
    if (kernel_filename) {
133 77d4f95e Edgar E. Iglesias
        li.image_filename = kernel_filename;
134 77d4f95e Edgar E. Iglesias
        li.cmdline = kernel_cmdline;
135 77d4f95e Edgar E. Iglesias
        cris_load_image(env, &li);
136 77d4f95e Edgar E. Iglesias
    } else {
137 77d4f95e Edgar E. Iglesias
        if (!dinfo) {
138 77d4f95e Edgar E. Iglesias
            fprintf(stderr,
139 77d4f95e Edgar E. Iglesias
                    "Provide a kernel image or a flash image to boot from.\n");
140 77d4f95e Edgar E. Iglesias
           exit(1);
141 fa1bdde4 edgar_igl
        }
142 83fa1010 ths
143 77d4f95e Edgar E. Iglesias
        /* Nothing more to do for flash images, those boot from addr 0.  */
144 77d4f95e Edgar E. Iglesias
        qemu_register_reset(flash_cpu_reset, env);
145 77d4f95e Edgar E. Iglesias
    }
146 83fa1010 ths
}
147 83fa1010 ths
148 f80f9ec9 Anthony Liguori
static QEMUMachine bareetraxfs_machine = {
149 4b32e168 aliguori
    .name = "bareetraxfs",
150 4b32e168 aliguori
    .desc = "Bare ETRAX FS board",
151 4b32e168 aliguori
    .init = bareetraxfs_init,
152 0c257437 Anthony Liguori
    .is_default = 1,
153 83fa1010 ths
};
154 f80f9ec9 Anthony Liguori
155 f80f9ec9 Anthony Liguori
static void bareetraxfs_machine_init(void)
156 f80f9ec9 Anthony Liguori
{
157 f80f9ec9 Anthony Liguori
    qemu_register_machine(&bareetraxfs_machine);
158 f80f9ec9 Anthony Liguori
}
159 f80f9ec9 Anthony Liguori
160 f80f9ec9 Anthony Liguori
machine_init(bareetraxfs_machine_init);