Statistics
| Branch: | Revision:

root / hw / mpc8544_guts.c @ 1129714f

History | View | Annotate | Download (3.7 kB)

1 b0fb8423 Alexander Graf
/*
2 b0fb8423 Alexander Graf
 * QEMU PowerPC MPC8544 global util pseudo-device
3 b0fb8423 Alexander Graf
 *
4 b0fb8423 Alexander Graf
 * Copyright (C) 2011 Freescale Semiconductor, Inc. All rights reserved.
5 b0fb8423 Alexander Graf
 *
6 b0fb8423 Alexander Graf
 * Author: Alexander Graf, <alex@csgraf.de>
7 b0fb8423 Alexander Graf
 *
8 b0fb8423 Alexander Graf
 * This is free software; you can redistribute it and/or modify
9 b0fb8423 Alexander Graf
 * it under the terms of  the GNU General  Public License as published by
10 b0fb8423 Alexander Graf
 * the Free Software Foundation;  either version 2 of the  License, or
11 b0fb8423 Alexander Graf
 * (at your option) any later version.
12 b0fb8423 Alexander Graf
 *
13 b0fb8423 Alexander Graf
 * *****************************************************************
14 b0fb8423 Alexander Graf
 *
15 b0fb8423 Alexander Graf
 * The documentation for this device is noted in the MPC8544 documentation,
16 b0fb8423 Alexander Graf
 * file name "MPC8544ERM.pdf". You can easily find it on the web.
17 b0fb8423 Alexander Graf
 *
18 b0fb8423 Alexander Graf
 */
19 b0fb8423 Alexander Graf
20 b0fb8423 Alexander Graf
#include "hw.h"
21 b0fb8423 Alexander Graf
#include "sysemu.h"
22 b0fb8423 Alexander Graf
#include "sysbus.h"
23 b0fb8423 Alexander Graf
24 b0fb8423 Alexander Graf
#define MPC8544_GUTS_MMIO_SIZE        0x1000
25 b0fb8423 Alexander Graf
#define MPC8544_GUTS_RSTCR_RESET      0x02
26 b0fb8423 Alexander Graf
27 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_PORPLLSR    0x00
28 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_PORBMSR     0x04
29 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_PORIMPSCR   0x08
30 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_PORDEVSR    0x0C
31 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_PORDBGMSR   0x10
32 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_PORDEVSR2   0x14
33 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_GPPORCR     0x20
34 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_GPIOCR      0x30
35 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_GPOUTDR     0x40
36 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_GPINDR      0x50
37 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_PMUXCR      0x60
38 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_DEVDISR     0x70
39 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_POWMGTCSR   0x80
40 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_MCPSUMR     0x90
41 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_RSTRSCR     0x94
42 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_PVR         0xA0
43 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_SVR         0xA4
44 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_RSTCR       0xB0
45 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_IOVSELSR    0xC0
46 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_DDRCSR      0xB20
47 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_DDRCDR      0xB24
48 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_DDRCLKDR    0xB28
49 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_CLKOCR      0xE00
50 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_SRDS1CR1    0xF04
51 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_SRDS2CR1    0xF10
52 b0fb8423 Alexander Graf
#define MPC8544_GUTS_ADDR_SRDS2CR3    0xF18
53 b0fb8423 Alexander Graf
54 b0fb8423 Alexander Graf
struct GutsState {
55 b0fb8423 Alexander Graf
    SysBusDevice busdev;
56 b0fb8423 Alexander Graf
};
57 b0fb8423 Alexander Graf
58 b0fb8423 Alexander Graf
typedef struct GutsState GutsState;
59 b0fb8423 Alexander Graf
60 b0fb8423 Alexander Graf
static uint32_t mpc8544_guts_read32(void *opaque, target_phys_addr_t addr)
61 b0fb8423 Alexander Graf
{
62 b0fb8423 Alexander Graf
    uint32_t value = 0;
63 b0fb8423 Alexander Graf
    CPUState *env = cpu_single_env;
64 b0fb8423 Alexander Graf
65 b0fb8423 Alexander Graf
    addr &= MPC8544_GUTS_MMIO_SIZE - 1;
66 b0fb8423 Alexander Graf
    switch (addr) {
67 b0fb8423 Alexander Graf
    case MPC8544_GUTS_ADDR_PVR:
68 b0fb8423 Alexander Graf
        value = env->spr[SPR_PVR];
69 b0fb8423 Alexander Graf
        break;
70 b0fb8423 Alexander Graf
    case MPC8544_GUTS_ADDR_SVR:
71 b0fb8423 Alexander Graf
        value = env->spr[SPR_E500_SVR];
72 b0fb8423 Alexander Graf
        break;
73 b0fb8423 Alexander Graf
    default:
74 b0fb8423 Alexander Graf
        fprintf(stderr, "guts: Unknown register read: %x\n", (int)addr);
75 b0fb8423 Alexander Graf
        break;
76 b0fb8423 Alexander Graf
    }
77 b0fb8423 Alexander Graf
78 b0fb8423 Alexander Graf
    return value;
79 b0fb8423 Alexander Graf
}
80 b0fb8423 Alexander Graf
81 b0fb8423 Alexander Graf
static CPUReadMemoryFunc * const mpc8544_guts_read[] = {
82 b0fb8423 Alexander Graf
    NULL,
83 b0fb8423 Alexander Graf
    NULL,
84 b0fb8423 Alexander Graf
    &mpc8544_guts_read32,
85 b0fb8423 Alexander Graf
};
86 b0fb8423 Alexander Graf
87 b0fb8423 Alexander Graf
static void mpc8544_guts_write32(void *opaque, target_phys_addr_t addr,
88 b0fb8423 Alexander Graf
                              uint32_t value)
89 b0fb8423 Alexander Graf
{
90 b0fb8423 Alexander Graf
    addr &= MPC8544_GUTS_MMIO_SIZE - 1;
91 b0fb8423 Alexander Graf
92 b0fb8423 Alexander Graf
    switch (addr) {
93 b0fb8423 Alexander Graf
    case MPC8544_GUTS_ADDR_RSTCR:
94 b0fb8423 Alexander Graf
        if (value & MPC8544_GUTS_RSTCR_RESET) {
95 b0fb8423 Alexander Graf
            qemu_system_reset_request();
96 b0fb8423 Alexander Graf
        }
97 b0fb8423 Alexander Graf
        break;
98 b0fb8423 Alexander Graf
    default:
99 b0fb8423 Alexander Graf
        fprintf(stderr, "guts: Unknown register write: %x = %x\n",
100 b0fb8423 Alexander Graf
                (int)addr, value);
101 b0fb8423 Alexander Graf
        break;
102 b0fb8423 Alexander Graf
    }
103 b0fb8423 Alexander Graf
}
104 b0fb8423 Alexander Graf
105 b0fb8423 Alexander Graf
static CPUWriteMemoryFunc * const mpc8544_guts_write[] = {
106 b0fb8423 Alexander Graf
    NULL,
107 b0fb8423 Alexander Graf
    NULL,
108 b0fb8423 Alexander Graf
    &mpc8544_guts_write32,
109 b0fb8423 Alexander Graf
};
110 b0fb8423 Alexander Graf
111 b0fb8423 Alexander Graf
static int mpc8544_guts_initfn(SysBusDevice *dev)
112 b0fb8423 Alexander Graf
{
113 b0fb8423 Alexander Graf
    GutsState *s;
114 b0fb8423 Alexander Graf
    int iomem;
115 b0fb8423 Alexander Graf
116 b0fb8423 Alexander Graf
    s = FROM_SYSBUS(GutsState, sysbus_from_qdev(dev));
117 b0fb8423 Alexander Graf
118 b0fb8423 Alexander Graf
    iomem = cpu_register_io_memory(mpc8544_guts_read, mpc8544_guts_write, s,
119 b0fb8423 Alexander Graf
                                   DEVICE_BIG_ENDIAN);
120 b0fb8423 Alexander Graf
    sysbus_init_mmio(dev, MPC8544_GUTS_MMIO_SIZE, iomem);
121 b0fb8423 Alexander Graf
122 b0fb8423 Alexander Graf
    return 0;
123 b0fb8423 Alexander Graf
}
124 b0fb8423 Alexander Graf
125 b0fb8423 Alexander Graf
static SysBusDeviceInfo mpc8544_guts_info = {
126 b0fb8423 Alexander Graf
    .init         = mpc8544_guts_initfn,
127 b0fb8423 Alexander Graf
    .qdev.name    = "mpc8544-guts",
128 b0fb8423 Alexander Graf
    .qdev.size    = sizeof(GutsState),
129 b0fb8423 Alexander Graf
};
130 b0fb8423 Alexander Graf
131 b0fb8423 Alexander Graf
static void mpc8544_guts_register(void)
132 b0fb8423 Alexander Graf
{
133 b0fb8423 Alexander Graf
    sysbus_register_withprop(&mpc8544_guts_info);
134 b0fb8423 Alexander Graf
}
135 b0fb8423 Alexander Graf
device_init(mpc8544_guts_register);