integratorcp.c 19.3 KB
Newer Older
1
/*
B
bellard 已提交
2 3
 * ARM Integrator CP System emulation.
 *
4
 * Copyright (c) 2005-2007 CodeSourcery.
B
bellard 已提交
5 6
 * Written by Paul Brook
 *
M
Matthew Fernandez 已提交
7
 * This code is licensed under the GPL
B
bellard 已提交
8 9
 */

P
Peter Maydell 已提交
10
#include "qemu/osdep.h"
11
#include "qapi/error.h"
12 13
#include "qemu-common.h"
#include "cpu.h"
14
#include "hw/sysbus.h"
15
#include "hw/devices.h"
16
#include "hw/boards.h"
17
#include "hw/arm/arm.h"
18
#include "hw/misc/arm_integrator_debug.h"
P
Paolo Bonzini 已提交
19
#include "net/net.h"
20
#include "exec/address-spaces.h"
21
#include "sysemu/sysemu.h"
22
#include "qemu/error-report.h"
X
xiaoqiang zhao 已提交
23
#include "hw/char/pl011.h"
B
bellard 已提交
24

25 26 27 28 29 30 31 32 33
#define TYPE_INTEGRATOR_CM "integrator_core"
#define INTEGRATOR_CM(obj) \
    OBJECT_CHECK(IntegratorCMState, (obj), TYPE_INTEGRATOR_CM)

typedef struct IntegratorCMState {
    /*< private >*/
    SysBusDevice parent_obj;
    /*< public >*/

34
    MemoryRegion iomem;
G
Gerd Hoffmann 已提交
35
    uint32_t memsz;
36
    MemoryRegion flash;
B
bellard 已提交
37 38 39 40 41 42 43 44
    uint32_t cm_osc;
    uint32_t cm_ctrl;
    uint32_t cm_lock;
    uint32_t cm_auxosc;
    uint32_t cm_sdram;
    uint32_t cm_init;
    uint32_t cm_flags;
    uint32_t cm_nvflags;
45
    uint32_t cm_refcnt_offset;
B
bellard 已提交
46 47 48
    uint32_t int_level;
    uint32_t irq_enabled;
    uint32_t fiq_enabled;
49
} IntegratorCMState;
B
bellard 已提交
50 51 52 53 54 55

static uint8_t integrator_spd[128] = {
   128, 8, 4, 11, 9, 1, 64, 0,  2, 0xa0, 0xa0, 0, 0, 8, 0, 1,
   0xe, 4, 0x1c, 1, 2, 0x20, 0xc0, 0, 0, 0, 0, 0x30, 0x28, 0x30, 0x28, 0x40
};

A
Avi Kivity 已提交
56
static uint64_t integratorcm_read(void *opaque, hwaddr offset,
57
                                  unsigned size)
B
bellard 已提交
58
{
59
    IntegratorCMState *s = opaque;
B
bellard 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    if (offset >= 0x100 && offset < 0x200) {
        /* CM_SPD */
        if (offset >= 0x180)
            return 0;
        return integrator_spd[offset >> 2];
    }
    switch (offset >> 2) {
    case 0: /* CM_ID */
        return 0x411a3001;
    case 1: /* CM_PROC */
        return 0;
    case 2: /* CM_OSC */
        return s->cm_osc;
    case 3: /* CM_CTRL */
        return s->cm_ctrl;
    case 4: /* CM_STAT */
        return 0x00100000;
    case 5: /* CM_LOCK */
        if (s->cm_lock == 0xa05f) {
            return 0x1a05f;
        } else {
            return s->cm_lock;
        }
    case 6: /* CM_LMBUSCNT */
        /* ??? High frequency timer.  */
P
Paul Brook 已提交
85
        hw_error("integratorcm_read: CM_LMBUSCNT");
B
bellard 已提交
86 87 88 89 90 91
    case 7: /* CM_AUXOSC */
        return s->cm_auxosc;
    case 8: /* CM_SDRAM */
        return s->cm_sdram;
    case 9: /* CM_INIT */
        return s->cm_init;
92 93 94 95 96 97 98
    case 10: /* CM_REFCNT */
        /* This register, CM_REFCNT, provides a 32-bit count value.
         * The count increments at the fixed reference clock frequency of 24MHz
         * and can be used as a real-time counter.
         */
        return (uint32_t)muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), 24,
                                  1000) - s->cm_refcnt_offset;
B
bellard 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    case 12: /* CM_FLAGS */
        return s->cm_flags;
    case 14: /* CM_NVFLAGS */
        return s->cm_nvflags;
    case 16: /* CM_IRQ_STAT */
        return s->int_level & s->irq_enabled;
    case 17: /* CM_IRQ_RSTAT */
        return s->int_level;
    case 18: /* CM_IRQ_ENSET */
        return s->irq_enabled;
    case 20: /* CM_SOFT_INTSET */
        return s->int_level & 1;
    case 24: /* CM_FIQ_STAT */
        return s->int_level & s->fiq_enabled;
    case 25: /* CM_FIQ_RSTAT */
        return s->int_level;
    case 26: /* CM_FIQ_ENSET */
        return s->fiq_enabled;
    case 32: /* CM_VOLTAGE_CTL0 */
    case 33: /* CM_VOLTAGE_CTL1 */
    case 34: /* CM_VOLTAGE_CTL2 */
    case 35: /* CM_VOLTAGE_CTL3 */
        /* ??? Voltage control unimplemented.  */
        return 0;
    default:
P
Paul Brook 已提交
124 125
        hw_error("integratorcm_read: Unimplemented offset 0x%x\n",
                 (int)offset);
B
bellard 已提交
126 127 128 129
        return 0;
    }
}

130
static void integratorcm_do_remap(IntegratorCMState *s)
B
bellard 已提交
131
{
132 133 134 135
    /* Sync memory region state with CM_CTRL REMAP bit:
     * bit 0 => flash at address 0; bit 1 => RAM
     */
    memory_region_set_enabled(&s->flash, !(s->cm_ctrl & 4));
B
bellard 已提交
136 137
}

138
static void integratorcm_set_ctrl(IntegratorCMState *s, uint32_t value)
B
bellard 已提交
139 140
{
    if (value & 8) {
141
        qemu_system_reset_request();
B
bellard 已提交
142
    }
143 144 145 146 147 148
    if ((s->cm_ctrl ^ value) & 1) {
        /* (value & 1) != 0 means the green "MISC LED" is lit.
         * We don't have any nice place to display LEDs. printf is a bad
         * idea because Linux uses the LED as a heartbeat and the output
         * will swamp anything else on the terminal.
         */
B
bellard 已提交
149
    }
150 151
    /* Note that the RESET bit [3] always reads as zero */
    s->cm_ctrl = (s->cm_ctrl & ~5) | (value & 5);
152
    integratorcm_do_remap(s);
B
bellard 已提交
153 154
}

155
static void integratorcm_update(IntegratorCMState *s)
B
bellard 已提交
156 157 158 159
{
    /* ??? The CPU irq/fiq is raised when either the core module or base PIC
       are active.  */
    if (s->int_level & (s->irq_enabled | s->fiq_enabled))
P
Paul Brook 已提交
160
        hw_error("Core module interrupt\n");
B
bellard 已提交
161 162
}

A
Avi Kivity 已提交
163
static void integratorcm_write(void *opaque, hwaddr offset,
164
                               uint64_t value, unsigned size)
B
bellard 已提交
165
{
166
    IntegratorCMState *s = opaque;
B
bellard 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
    switch (offset >> 2) {
    case 2: /* CM_OSC */
        if (s->cm_lock == 0xa05f)
            s->cm_osc = value;
        break;
    case 3: /* CM_CTRL */
        integratorcm_set_ctrl(s, value);
        break;
    case 5: /* CM_LOCK */
        s->cm_lock = value & 0xffff;
        break;
    case 7: /* CM_AUXOSC */
        if (s->cm_lock == 0xa05f)
            s->cm_auxosc = value;
        break;
    case 8: /* CM_SDRAM */
        s->cm_sdram = value;
        break;
    case 9: /* CM_INIT */
        /* ??? This can change the memory bus frequency.  */
        s->cm_init = value;
        break;
    case 12: /* CM_FLAGSS */
        s->cm_flags |= value;
        break;
    case 13: /* CM_FLAGSC */
        s->cm_flags &= ~value;
        break;
    case 14: /* CM_NVFLAGSS */
        s->cm_nvflags |= value;
        break;
    case 15: /* CM_NVFLAGSS */
        s->cm_nvflags &= ~value;
        break;
    case 18: /* CM_IRQ_ENSET */
        s->irq_enabled |= value;
        integratorcm_update(s);
        break;
    case 19: /* CM_IRQ_ENCLR */
        s->irq_enabled &= ~value;
        integratorcm_update(s);
        break;
    case 20: /* CM_SOFT_INTSET */
        s->int_level |= (value & 1);
        integratorcm_update(s);
        break;
    case 21: /* CM_SOFT_INTCLR */
        s->int_level &= ~(value & 1);
        integratorcm_update(s);
        break;
    case 26: /* CM_FIQ_ENSET */
        s->fiq_enabled |= value;
        integratorcm_update(s);
        break;
    case 27: /* CM_FIQ_ENCLR */
        s->fiq_enabled &= ~value;
        integratorcm_update(s);
        break;
    case 32: /* CM_VOLTAGE_CTL0 */
    case 33: /* CM_VOLTAGE_CTL1 */
    case 34: /* CM_VOLTAGE_CTL2 */
    case 35: /* CM_VOLTAGE_CTL3 */
        /* ??? Voltage control unimplemented.  */
        break;
    default:
P
Paul Brook 已提交
232 233
        hw_error("integratorcm_write: Unimplemented offset 0x%x\n",
                 (int)offset);
B
bellard 已提交
234 235 236 237 238 239
        break;
    }
}

/* Integrator/CM control registers.  */

240 241 242 243
static const MemoryRegionOps integratorcm_ops = {
    .read = integratorcm_read,
    .write = integratorcm_write,
    .endianness = DEVICE_NATIVE_ENDIAN,
B
bellard 已提交
244 245
};

X
xiaoqiang.zhao 已提交
246
static void integratorcm_init(Object *obj)
B
bellard 已提交
247
{
X
xiaoqiang.zhao 已提交
248 249
    IntegratorCMState *s = INTEGRATOR_CM(obj);
    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
B
bellard 已提交
250 251 252 253 254

    s->cm_osc = 0x01000048;
    /* ??? What should the high bits of this value be?  */
    s->cm_auxosc = 0x0007feff;
    s->cm_sdram = 0x00011122;
G
Gerd Hoffmann 已提交
255
    if (s->memsz >= 256) {
B
bellard 已提交
256 257
        integrator_spd[31] = 64;
        s->cm_sdram |= 0x10;
G
Gerd Hoffmann 已提交
258
    } else if (s->memsz >= 128) {
B
bellard 已提交
259 260
        integrator_spd[31] = 32;
        s->cm_sdram |= 0x0c;
G
Gerd Hoffmann 已提交
261
    } else if (s->memsz >= 64) {
B
bellard 已提交
262 263
        integrator_spd[31] = 16;
        s->cm_sdram |= 0x08;
G
Gerd Hoffmann 已提交
264
    } else if (s->memsz >= 32) {
B
bellard 已提交
265 266 267 268 269 270 271
        integrator_spd[31] = 4;
        s->cm_sdram |= 0x04;
    } else {
        integrator_spd[31] = 2;
    }
    memcpy(integrator_spd + 73, "QEMU-MEMORY", 11);
    s->cm_init = 0x00000112;
272 273
    s->cm_refcnt_offset = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), 24,
                                   1000);
X
xiaoqiang.zhao 已提交
274
    memory_region_init_ram(&s->flash, obj, "integrator.flash", 0x100000,
275
                           &error_fatal);
276
    vmstate_register_ram_global(&s->flash);
B
bellard 已提交
277

X
xiaoqiang.zhao 已提交
278
    memory_region_init_io(&s->iomem, obj, &integratorcm_ops, s,
279
                          "integratorcm", 0x00800000);
280
    sysbus_init_mmio(dev, &s->iomem);
281

282
    integratorcm_do_remap(s);
B
bellard 已提交
283 284 285 286 287 288
    /* ??? Save/restore.  */
}

/* Integrator/CP hardware emulation.  */
/* Primary interrupt controller.  */

289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
#define TYPE_INTEGRATOR_PIC "integrator_pic"
#define INTEGRATOR_PIC(obj) \
   OBJECT_CHECK(icp_pic_state, (obj), TYPE_INTEGRATOR_PIC)

typedef struct icp_pic_state {
    /*< private >*/
    SysBusDevice parent_obj;
    /*< public >*/

    MemoryRegion iomem;
    uint32_t level;
    uint32_t irq_enabled;
    uint32_t fiq_enabled;
    qemu_irq parent_irq;
    qemu_irq parent_fiq;
B
bellard 已提交
304 305 306 307
} icp_pic_state;

static void icp_pic_update(icp_pic_state *s)
{
308
    uint32_t flags;
B
bellard 已提交
309

P
pbrook 已提交
310 311 312 313
    flags = (s->level & s->irq_enabled);
    qemu_set_irq(s->parent_irq, flags != 0);
    flags = (s->level & s->fiq_enabled);
    qemu_set_irq(s->parent_fiq, flags != 0);
B
bellard 已提交
314 315
}

316
static void icp_pic_set_irq(void *opaque, int irq, int level)
B
bellard 已提交
317
{
318
    icp_pic_state *s = (icp_pic_state *)opaque;
B
bellard 已提交
319
    if (level)
320
        s->level |= 1 << irq;
B
bellard 已提交
321
    else
322
        s->level &= ~(1 << irq);
B
bellard 已提交
323 324 325
    icp_pic_update(s);
}

A
Avi Kivity 已提交
326
static uint64_t icp_pic_read(void *opaque, hwaddr offset,
327
                             unsigned size)
B
bellard 已提交
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
{
    icp_pic_state *s = (icp_pic_state *)opaque;

    switch (offset >> 2) {
    case 0: /* IRQ_STATUS */
        return s->level & s->irq_enabled;
    case 1: /* IRQ_RAWSTAT */
        return s->level;
    case 2: /* IRQ_ENABLESET */
        return s->irq_enabled;
    case 4: /* INT_SOFTSET */
        return s->level & 1;
    case 8: /* FRQ_STATUS */
        return s->level & s->fiq_enabled;
    case 9: /* FRQ_RAWSTAT */
        return s->level;
    case 10: /* FRQ_ENABLESET */
        return s->fiq_enabled;
    case 3: /* IRQ_ENABLECLR */
    case 5: /* INT_SOFTCLR */
    case 11: /* FRQ_ENABLECLR */
    default:
P
pbrook 已提交
350
        printf ("icp_pic_read: Bad register offset 0x%x\n", (int)offset);
B
bellard 已提交
351 352 353 354
        return 0;
    }
}

A
Avi Kivity 已提交
355
static void icp_pic_write(void *opaque, hwaddr offset,
356
                          uint64_t value, unsigned size)
B
bellard 已提交
357 358 359 360 361 362 363 364 365 366 367 368
{
    icp_pic_state *s = (icp_pic_state *)opaque;

    switch (offset >> 2) {
    case 2: /* IRQ_ENABLESET */
        s->irq_enabled |= value;
        break;
    case 3: /* IRQ_ENABLECLR */
        s->irq_enabled &= ~value;
        break;
    case 4: /* INT_SOFTSET */
        if (value & 1)
P
pbrook 已提交
369
            icp_pic_set_irq(s, 0, 1);
B
bellard 已提交
370 371 372
        break;
    case 5: /* INT_SOFTCLR */
        if (value & 1)
P
pbrook 已提交
373
            icp_pic_set_irq(s, 0, 0);
B
bellard 已提交
374 375 376 377 378 379 380 381 382 383 384 385
        break;
    case 10: /* FRQ_ENABLESET */
        s->fiq_enabled |= value;
        break;
    case 11: /* FRQ_ENABLECLR */
        s->fiq_enabled &= ~value;
        break;
    case 0: /* IRQ_STATUS */
    case 1: /* IRQ_RAWSTAT */
    case 8: /* FRQ_STATUS */
    case 9: /* FRQ_RAWSTAT */
    default:
P
pbrook 已提交
386
        printf ("icp_pic_write: Bad register offset 0x%x\n", (int)offset);
B
bellard 已提交
387 388 389 390 391
        return;
    }
    icp_pic_update(s);
}

392 393 394 395
static const MemoryRegionOps icp_pic_ops = {
    .read = icp_pic_read,
    .write = icp_pic_write,
    .endianness = DEVICE_NATIVE_ENDIAN,
B
bellard 已提交
396 397
};

X
xiaoqiang.zhao 已提交
398
static void icp_pic_init(Object *obj)
B
bellard 已提交
399
{
X
xiaoqiang.zhao 已提交
400 401 402
    DeviceState *dev = DEVICE(obj);
    icp_pic_state *s = INTEGRATOR_PIC(obj);
    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
B
bellard 已提交
403

404 405 406
    qdev_init_gpio_in(dev, icp_pic_set_irq, 32);
    sysbus_init_irq(sbd, &s->parent_irq);
    sysbus_init_irq(sbd, &s->parent_fiq);
X
xiaoqiang.zhao 已提交
407
    memory_region_init_io(&s->iomem, obj, &icp_pic_ops, s,
408
                          "icp-pic", 0x00800000);
409
    sysbus_init_mmio(sbd, &s->iomem);
B
bellard 已提交
410 411 412
}

/* CP control registers.  */
413

414 415 416 417 418 419 420 421 422 423
#define TYPE_ICP_CONTROL_REGS "icp-ctrl-regs"
#define ICP_CONTROL_REGS(obj) \
    OBJECT_CHECK(ICPCtrlRegsState, (obj), TYPE_ICP_CONTROL_REGS)

typedef struct ICPCtrlRegsState {
    /*< private >*/
    SysBusDevice parent_obj;
    /*< public >*/

    MemoryRegion iomem;
424 425 426

    qemu_irq mmc_irq;
    uint32_t intreg_state;
427 428
} ICPCtrlRegsState;

429 430 431 432 433 434
#define ICP_GPIO_MMC_WPROT      "mmc-wprot"
#define ICP_GPIO_MMC_CARDIN     "mmc-cardin"

#define ICP_INTREG_WPROT        (1 << 0)
#define ICP_INTREG_CARDIN       (1 << 3)

A
Avi Kivity 已提交
435
static uint64_t icp_control_read(void *opaque, hwaddr offset,
436
                                 unsigned size)
B
bellard 已提交
437
{
438 439
    ICPCtrlRegsState *s = opaque;

B
bellard 已提交
440 441 442 443 444 445
    switch (offset >> 2) {
    case 0: /* CP_IDFIELD */
        return 0x41034003;
    case 1: /* CP_FLASHPROG */
        return 0;
    case 2: /* CP_INTREG */
446
        return s->intreg_state;
B
bellard 已提交
447 448 449
    case 3: /* CP_DECODE */
        return 0x11;
    default:
P
Paul Brook 已提交
450
        hw_error("icp_control_read: Bad offset %x\n", (int)offset);
B
bellard 已提交
451 452 453 454
        return 0;
    }
}

A
Avi Kivity 已提交
455
static void icp_control_write(void *opaque, hwaddr offset,
456
                          uint64_t value, unsigned size)
B
bellard 已提交
457
{
458 459
    ICPCtrlRegsState *s = opaque;

B
bellard 已提交
460 461
    switch (offset >> 2) {
    case 2: /* CP_INTREG */
462 463 464 465
        s->intreg_state &= ~(value & ICP_INTREG_CARDIN);
        qemu_set_irq(s->mmc_irq, !!(s->intreg_state & ICP_INTREG_CARDIN));
        break;
    case 1: /* CP_FLASHPROG */
B
bellard 已提交
466 467 468 469
    case 3: /* CP_DECODE */
        /* Nothing interesting implemented yet.  */
        break;
    default:
P
Paul Brook 已提交
470
        hw_error("icp_control_write: Bad offset %x\n", (int)offset);
B
bellard 已提交
471 472 473
    }
}

474 475 476 477
static const MemoryRegionOps icp_control_ops = {
    .read = icp_control_read,
    .write = icp_control_write,
    .endianness = DEVICE_NATIVE_ENDIAN,
B
bellard 已提交
478 479
};

480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
static void icp_control_mmc_wprot(void *opaque, int line, int level)
{
    ICPCtrlRegsState *s = opaque;

    s->intreg_state &= ~ICP_INTREG_WPROT;
    if (level) {
        s->intreg_state |= ICP_INTREG_WPROT;
    }
}

static void icp_control_mmc_cardin(void *opaque, int line, int level)
{
    ICPCtrlRegsState *s = opaque;

    /* line is released by writing to CP_INTREG */
    if (level) {
        s->intreg_state |= ICP_INTREG_CARDIN;
        qemu_set_irq(s->mmc_irq, 1);
    }
}

501
static void icp_control_init(Object *obj)
B
bellard 已提交
502
{
503 504
    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
    ICPCtrlRegsState *s = ICP_CONTROL_REGS(obj);
505
    DeviceState *dev = DEVICE(obj);
B
bellard 已提交
506

507 508 509
    memory_region_init_io(&s->iomem, OBJECT(s), &icp_control_ops, s,
                          "icp_ctrl_regs", 0x00800000);
    sysbus_init_mmio(sbd, &s->iomem);
510 511 512 513 514

    qdev_init_gpio_in_named(dev, icp_control_mmc_wprot, ICP_GPIO_MMC_WPROT, 1);
    qdev_init_gpio_in_named(dev, icp_control_mmc_cardin,
                            ICP_GPIO_MMC_CARDIN, 1);
    sysbus_init_irq(sbd, &s->mmc_irq);
B
bellard 已提交
515 516 517 518 519
}


/* Board init.  */

520 521 522 523 524
static struct arm_boot_info integrator_binfo = {
    .loader_start = 0x0,
    .board_id = 0x113,
};

525
static void integratorcp_init(MachineState *machine)
B
bellard 已提交
526
{
527 528 529 530 531
    ram_addr_t ram_size = machine->ram_size;
    const char *cpu_model = machine->cpu_model;
    const char *kernel_filename = machine->kernel_filename;
    const char *kernel_cmdline = machine->kernel_cmdline;
    const char *initrd_filename = machine->initrd_filename;
532 533
    ObjectClass *cpu_oc;
    Object *cpuobj;
534
    ARMCPU *cpu;
535 536 537
    MemoryRegion *address_space_mem = get_system_memory();
    MemoryRegion *ram = g_new(MemoryRegion, 1);
    MemoryRegion *ram_alias = g_new(MemoryRegion, 1);
P
Paul Brook 已提交
538
    qemu_irq pic[32];
539
    DeviceState *dev, *sic, *icp;
P
Paul Brook 已提交
540
    int i;
B
bellard 已提交
541

542
    if (!cpu_model) {
P
pbrook 已提交
543
        cpu_model = "arm926";
544
    }
545 546 547

    cpu_oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
    if (!cpu_oc) {
B
bellard 已提交
548 549 550
        fprintf(stderr, "Unable to find CPU definition\n");
        exit(1);
    }
551

552 553
    cpuobj = object_new(object_class_get_name(cpu_oc));

554 555 556 557 558
    /* By default ARM1176 CPUs have EL3 enabled.  This board does not
     * currently support EL3 so the CPU EL3 property is disabled before
     * realization.
     */
    if (object_property_find(cpuobj, "has_el3", NULL)) {
559
        object_property_set_bool(cpuobj, false, "has_el3", &error_fatal);
560 561
    }

562
    object_property_set_bool(cpuobj, true, "realized", &error_fatal);
563 564 565

    cpu = ARM_CPU(cpuobj);

566 567
    memory_region_allocate_system_memory(ram, NULL, "integrator.ram",
                                         ram_size);
B
bellard 已提交
568
    /* ??? On a real system the first 1Mb is mapped as SSRAM or boot flash.  */
T
ths 已提交
569
    /* ??? RAM should repeat to fill physical memory space.  */
B
bellard 已提交
570
    /* SDRAM at address zero*/
571
    memory_region_add_subregion(address_space_mem, 0, ram);
B
bellard 已提交
572
    /* And again at address 0x80000000 */
573
    memory_region_init_alias(ram_alias, NULL, "ram.alias", ram, 0, ram_size);
574
    memory_region_add_subregion(address_space_mem, 0x80000000, ram_alias);
B
bellard 已提交
575

576
    dev = qdev_create(NULL, TYPE_INTEGRATOR_CM);
G
Gerd Hoffmann 已提交
577
    qdev_prop_set_uint32(dev, "memsz", ram_size >> 20);
M
Markus Armbruster 已提交
578
    qdev_init_nofail(dev);
P
Paul Brook 已提交
579 580
    sysbus_mmio_map((SysBusDevice *)dev, 0, 0x10000000);

581
    dev = sysbus_create_varargs(TYPE_INTEGRATOR_PIC, 0x14000000,
582 583 584
                                qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ),
                                qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_FIQ),
                                NULL);
P
Paul Brook 已提交
585
    for (i = 0; i < 32; i++) {
P
Paul Brook 已提交
586
        pic[i] = qdev_get_gpio_in(dev, i);
P
Paul Brook 已提交
587
    }
588
    sic = sysbus_create_simple(TYPE_INTEGRATOR_PIC, 0xca000000, pic[26]);
P
Paul Brook 已提交
589 590
    sysbus_create_varargs("integrator_pit", 0x13000000,
                          pic[5], pic[6], pic[7], NULL);
P
Paul Brook 已提交
591
    sysbus_create_simple("pl031", 0x15000000, pic[8]);
X
xiaoqiang zhao 已提交
592 593
    pl011_create(0x16000000, pic[1], serial_hds[0]);
    pl011_create(0x17000000, pic[2], serial_hds[1]);
594 595
    icp = sysbus_create_simple(TYPE_ICP_CONTROL_REGS, 0xcb000000,
                               qdev_get_gpio_in(sic, 3));
P
Paul Brook 已提交
596 597
    sysbus_create_simple("pl050_keyboard", 0x18000000, pic[3]);
    sysbus_create_simple("pl050_mouse", 0x19000000, pic[4]);
598
    sysbus_create_simple(TYPE_INTEGRATOR_DEBUG, 0x1a000000, 0);
599 600 601 602 603 604 605

    dev = sysbus_create_varargs("pl181", 0x1c000000, pic[23], pic[24], NULL);
    qdev_connect_gpio_out(dev, 0,
                          qdev_get_gpio_in_named(icp, ICP_GPIO_MMC_WPROT, 0));
    qdev_connect_gpio_out(dev, 1,
                          qdev_get_gpio_in_named(icp, ICP_GPIO_MMC_CARDIN, 0));

S
Stefan Hajnoczi 已提交
606
    if (nd_table[0].used)
607
        smc91c111_init(&nd_table[0], 0xc8000000, pic[27]);
P
Paul Brook 已提交
608 609

    sysbus_create_simple("pl110", 0xc0000000, pic[22]);
B
bellard 已提交
610

611 612 613 614
    integrator_binfo.ram_size = ram_size;
    integrator_binfo.kernel_filename = kernel_filename;
    integrator_binfo.kernel_cmdline = kernel_cmdline;
    integrator_binfo.initrd_filename = initrd_filename;
615
    arm_load_kernel(cpu, &integrator_binfo);
B
bellard 已提交
616 617
}

618
static void integratorcp_machine_init(MachineClass *mc)
619
{
620 621
    mc->desc = "ARM Integrator/CP (ARM926EJ-S)";
    mc->init = integratorcp_init;
622 623
}

624
DEFINE_MACHINE("integratorcp", integratorcp_machine_init)
625

626
static Property core_properties[] = {
627
    DEFINE_PROP_UINT32("memsz", IntegratorCMState, memsz, 0),
628 629 630 631 632
    DEFINE_PROP_END_OF_LIST(),
};

static void core_class_init(ObjectClass *klass, void *data)
{
633
    DeviceClass *dc = DEVICE_CLASS(klass);
634

635
    dc->props = core_properties;
636 637
}

638
static const TypeInfo core_info = {
639
    .name          = TYPE_INTEGRATOR_CM,
640
    .parent        = TYPE_SYS_BUS_DEVICE,
641
    .instance_size = sizeof(IntegratorCMState),
X
xiaoqiang.zhao 已提交
642
    .instance_init = integratorcm_init,
643
    .class_init    = core_class_init,
644 645
};

646
static const TypeInfo icp_pic_info = {
647
    .name          = TYPE_INTEGRATOR_PIC,
648 649
    .parent        = TYPE_SYS_BUS_DEVICE,
    .instance_size = sizeof(icp_pic_state),
X
xiaoqiang.zhao 已提交
650
    .instance_init = icp_pic_init,
G
Gerd Hoffmann 已提交
651 652
};

653 654 655 656 657 658 659
static const TypeInfo icp_ctrl_regs_info = {
    .name          = TYPE_ICP_CONTROL_REGS,
    .parent        = TYPE_SYS_BUS_DEVICE,
    .instance_size = sizeof(ICPCtrlRegsState),
    .instance_init = icp_control_init,
};

A
Andreas Färber 已提交
660
static void integratorcp_register_types(void)
P
Paul Brook 已提交
661
{
662 663
    type_register_static(&icp_pic_info);
    type_register_static(&core_info);
664
    type_register_static(&icp_ctrl_regs_info);
P
Paul Brook 已提交
665 666
}

A
Andreas Färber 已提交
667
type_init(integratorcp_register_types)