Statistics
| Branch: | Revision:

root / hw / mpc8544_guts.c @ 3871481c

History | View | Annotate | Download (4 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 1c7af35f Avi Kivity
    MemoryRegion iomem;
57 b0fb8423 Alexander Graf
};
58 b0fb8423 Alexander Graf
59 b0fb8423 Alexander Graf
typedef struct GutsState GutsState;
60 b0fb8423 Alexander Graf
61 1c7af35f Avi Kivity
static uint64_t mpc8544_guts_read(void *opaque, target_phys_addr_t addr,
62 1c7af35f Avi Kivity
                                  unsigned size)
63 b0fb8423 Alexander Graf
{
64 b0fb8423 Alexander Graf
    uint32_t value = 0;
65 e2684c0b Andreas Färber
    CPUPPCState *env = cpu_single_env;
66 b0fb8423 Alexander Graf
67 b0fb8423 Alexander Graf
    addr &= MPC8544_GUTS_MMIO_SIZE - 1;
68 b0fb8423 Alexander Graf
    switch (addr) {
69 b0fb8423 Alexander Graf
    case MPC8544_GUTS_ADDR_PVR:
70 b0fb8423 Alexander Graf
        value = env->spr[SPR_PVR];
71 b0fb8423 Alexander Graf
        break;
72 b0fb8423 Alexander Graf
    case MPC8544_GUTS_ADDR_SVR:
73 b0fb8423 Alexander Graf
        value = env->spr[SPR_E500_SVR];
74 b0fb8423 Alexander Graf
        break;
75 b0fb8423 Alexander Graf
    default:
76 b0fb8423 Alexander Graf
        fprintf(stderr, "guts: Unknown register read: %x\n", (int)addr);
77 b0fb8423 Alexander Graf
        break;
78 b0fb8423 Alexander Graf
    }
79 b0fb8423 Alexander Graf
80 b0fb8423 Alexander Graf
    return value;
81 b0fb8423 Alexander Graf
}
82 b0fb8423 Alexander Graf
83 1c7af35f Avi Kivity
static void mpc8544_guts_write(void *opaque, target_phys_addr_t addr,
84 1c7af35f Avi Kivity
                               uint64_t value, unsigned size)
85 b0fb8423 Alexander Graf
{
86 b0fb8423 Alexander Graf
    addr &= MPC8544_GUTS_MMIO_SIZE - 1;
87 b0fb8423 Alexander Graf
88 b0fb8423 Alexander Graf
    switch (addr) {
89 b0fb8423 Alexander Graf
    case MPC8544_GUTS_ADDR_RSTCR:
90 b0fb8423 Alexander Graf
        if (value & MPC8544_GUTS_RSTCR_RESET) {
91 b0fb8423 Alexander Graf
            qemu_system_reset_request();
92 b0fb8423 Alexander Graf
        }
93 b0fb8423 Alexander Graf
        break;
94 b0fb8423 Alexander Graf
    default:
95 b0fb8423 Alexander Graf
        fprintf(stderr, "guts: Unknown register write: %x = %x\n",
96 1c7af35f Avi Kivity
                (int)addr, (unsigned)value);
97 b0fb8423 Alexander Graf
        break;
98 b0fb8423 Alexander Graf
    }
99 b0fb8423 Alexander Graf
}
100 b0fb8423 Alexander Graf
101 1c7af35f Avi Kivity
static const MemoryRegionOps mpc8544_guts_ops = {
102 1c7af35f Avi Kivity
    .read = mpc8544_guts_read,
103 1c7af35f Avi Kivity
    .write = mpc8544_guts_write,
104 1c7af35f Avi Kivity
    .endianness = DEVICE_BIG_ENDIAN,
105 1c7af35f Avi Kivity
    .valid = {
106 1c7af35f Avi Kivity
        .min_access_size = 4,
107 1c7af35f Avi Kivity
        .max_access_size = 4,
108 1c7af35f Avi Kivity
    },
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
115 b0fb8423 Alexander Graf
    s = FROM_SYSBUS(GutsState, sysbus_from_qdev(dev));
116 b0fb8423 Alexander Graf
117 1c7af35f Avi Kivity
    memory_region_init_io(&s->iomem, &mpc8544_guts_ops, s,
118 1c7af35f Avi Kivity
                          "mpc6544.guts", MPC8544_GUTS_MMIO_SIZE);
119 750ecd44 Avi Kivity
    sysbus_init_mmio(dev, &s->iomem);
120 b0fb8423 Alexander Graf
121 b0fb8423 Alexander Graf
    return 0;
122 b0fb8423 Alexander Graf
}
123 b0fb8423 Alexander Graf
124 999e12bb Anthony Liguori
static void mpc8544_guts_class_init(ObjectClass *klass, void *data)
125 999e12bb Anthony Liguori
{
126 999e12bb Anthony Liguori
    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
127 999e12bb Anthony Liguori
128 999e12bb Anthony Liguori
    k->init = mpc8544_guts_initfn;
129 999e12bb Anthony Liguori
}
130 999e12bb Anthony Liguori
131 39bffca2 Anthony Liguori
static TypeInfo mpc8544_guts_info = {
132 39bffca2 Anthony Liguori
    .name          = "mpc8544-guts",
133 39bffca2 Anthony Liguori
    .parent        = TYPE_SYS_BUS_DEVICE,
134 39bffca2 Anthony Liguori
    .instance_size = sizeof(GutsState),
135 39bffca2 Anthony Liguori
    .class_init    = mpc8544_guts_class_init,
136 b0fb8423 Alexander Graf
};
137 b0fb8423 Alexander Graf
138 83f7d43a Andreas Färber
static void mpc8544_guts_register_types(void)
139 b0fb8423 Alexander Graf
{
140 39bffca2 Anthony Liguori
    type_register_static(&mpc8544_guts_info);
141 b0fb8423 Alexander Graf
}
142 83f7d43a Andreas Färber
143 83f7d43a Andreas Färber
type_init(mpc8544_guts_register_types)