root / hw / arm_sysctl.c @ d8ed79ae
History | View | Annotate | Download (6 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | e69954b9 | pbrook | * Status and system control registers for ARM RealView/Versatile boards.
|
3 | e69954b9 | pbrook | *
|
4 | 9ee6e8bb | pbrook | * Copyright (c) 2006-2007 CodeSourcery.
|
5 | e69954b9 | pbrook | * Written by Paul Brook
|
6 | e69954b9 | pbrook | *
|
7 | e69954b9 | pbrook | * This code is licenced under the GPL.
|
8 | e69954b9 | pbrook | */
|
9 | e69954b9 | pbrook | |
10 | 042eb37a | Daniel Jacobowitz | #include "hw.h" |
11 | 042eb37a | Daniel Jacobowitz | #include "qemu-timer.h" |
12 | 82634c2d | Paul Brook | #include "sysbus.h" |
13 | 9596ebb7 | pbrook | #include "primecell.h" |
14 | 87ecb68b | pbrook | #include "sysemu.h" |
15 | e69954b9 | pbrook | |
16 | e69954b9 | pbrook | #define LOCK_VALUE 0xa05f |
17 | e69954b9 | pbrook | |
18 | e69954b9 | pbrook | typedef struct { |
19 | 82634c2d | Paul Brook | SysBusDevice busdev; |
20 | e69954b9 | pbrook | uint32_t sys_id; |
21 | e69954b9 | pbrook | uint32_t leds; |
22 | e69954b9 | pbrook | uint16_t lockval; |
23 | e69954b9 | pbrook | uint32_t cfgdata1; |
24 | e69954b9 | pbrook | uint32_t cfgdata2; |
25 | e69954b9 | pbrook | uint32_t flags; |
26 | e69954b9 | pbrook | uint32_t nvflags; |
27 | e69954b9 | pbrook | uint32_t resetlevel; |
28 | e69954b9 | pbrook | } arm_sysctl_state; |
29 | e69954b9 | pbrook | |
30 | c227f099 | Anthony Liguori | static uint32_t arm_sysctl_read(void *opaque, target_phys_addr_t offset) |
31 | e69954b9 | pbrook | { |
32 | e69954b9 | pbrook | arm_sysctl_state *s = (arm_sysctl_state *)opaque; |
33 | e69954b9 | pbrook | |
34 | e69954b9 | pbrook | switch (offset) {
|
35 | e69954b9 | pbrook | case 0x00: /* ID */ |
36 | e69954b9 | pbrook | return s->sys_id;
|
37 | e69954b9 | pbrook | case 0x04: /* SW */ |
38 | e69954b9 | pbrook | /* General purpose hardware switches.
|
39 | e69954b9 | pbrook | We don't have a useful way of exposing these to the user. */
|
40 | e69954b9 | pbrook | return 0; |
41 | e69954b9 | pbrook | case 0x08: /* LED */ |
42 | e69954b9 | pbrook | return s->leds;
|
43 | e69954b9 | pbrook | case 0x20: /* LOCK */ |
44 | e69954b9 | pbrook | return s->lockval;
|
45 | e69954b9 | pbrook | case 0x0c: /* OSC0 */ |
46 | e69954b9 | pbrook | case 0x10: /* OSC1 */ |
47 | e69954b9 | pbrook | case 0x14: /* OSC2 */ |
48 | e69954b9 | pbrook | case 0x18: /* OSC3 */ |
49 | e69954b9 | pbrook | case 0x1c: /* OSC4 */ |
50 | e69954b9 | pbrook | case 0x24: /* 100HZ */ |
51 | e69954b9 | pbrook | /* ??? Implement these. */
|
52 | e69954b9 | pbrook | return 0; |
53 | e69954b9 | pbrook | case 0x28: /* CFGDATA1 */ |
54 | e69954b9 | pbrook | return s->cfgdata1;
|
55 | e69954b9 | pbrook | case 0x2c: /* CFGDATA2 */ |
56 | e69954b9 | pbrook | return s->cfgdata2;
|
57 | e69954b9 | pbrook | case 0x30: /* FLAGS */ |
58 | e69954b9 | pbrook | return s->flags;
|
59 | e69954b9 | pbrook | case 0x38: /* NVFLAGS */ |
60 | e69954b9 | pbrook | return s->nvflags;
|
61 | e69954b9 | pbrook | case 0x40: /* RESETCTL */ |
62 | e69954b9 | pbrook | return s->resetlevel;
|
63 | e69954b9 | pbrook | case 0x44: /* PCICTL */ |
64 | e69954b9 | pbrook | return 1; |
65 | e69954b9 | pbrook | case 0x48: /* MCI */ |
66 | e69954b9 | pbrook | return 0; |
67 | e69954b9 | pbrook | case 0x4c: /* FLASH */ |
68 | e69954b9 | pbrook | return 0; |
69 | e69954b9 | pbrook | case 0x50: /* CLCD */ |
70 | e69954b9 | pbrook | return 0x1000; |
71 | e69954b9 | pbrook | case 0x54: /* CLCDSER */ |
72 | e69954b9 | pbrook | return 0; |
73 | e69954b9 | pbrook | case 0x58: /* BOOTCS */ |
74 | e69954b9 | pbrook | return 0; |
75 | e69954b9 | pbrook | case 0x5c: /* 24MHz */ |
76 | 042eb37a | Daniel Jacobowitz | return muldiv64(qemu_get_clock(vm_clock), 24000000, get_ticks_per_sec()); |
77 | e69954b9 | pbrook | case 0x60: /* MISC */ |
78 | e69954b9 | pbrook | return 0; |
79 | e69954b9 | pbrook | case 0x84: /* PROCID0 */ |
80 | e69954b9 | pbrook | /* ??? Don't know what the proper value for the core tile ID is. */
|
81 | e69954b9 | pbrook | return 0x02000000; |
82 | e69954b9 | pbrook | case 0x88: /* PROCID1 */ |
83 | e69954b9 | pbrook | return 0xff000000; |
84 | e69954b9 | pbrook | case 0x64: /* DMAPSR0 */ |
85 | e69954b9 | pbrook | case 0x68: /* DMAPSR1 */ |
86 | e69954b9 | pbrook | case 0x6c: /* DMAPSR2 */ |
87 | e69954b9 | pbrook | case 0x70: /* IOSEL */ |
88 | e69954b9 | pbrook | case 0x74: /* PLDCTL */ |
89 | e69954b9 | pbrook | case 0x80: /* BUSID */ |
90 | e69954b9 | pbrook | case 0x8c: /* OSCRESET0 */ |
91 | e69954b9 | pbrook | case 0x90: /* OSCRESET1 */ |
92 | e69954b9 | pbrook | case 0x94: /* OSCRESET2 */ |
93 | e69954b9 | pbrook | case 0x98: /* OSCRESET3 */ |
94 | e69954b9 | pbrook | case 0x9c: /* OSCRESET4 */ |
95 | e69954b9 | pbrook | case 0xc0: /* SYS_TEST_OSC0 */ |
96 | e69954b9 | pbrook | case 0xc4: /* SYS_TEST_OSC1 */ |
97 | e69954b9 | pbrook | case 0xc8: /* SYS_TEST_OSC2 */ |
98 | e69954b9 | pbrook | case 0xcc: /* SYS_TEST_OSC3 */ |
99 | e69954b9 | pbrook | case 0xd0: /* SYS_TEST_OSC4 */ |
100 | e69954b9 | pbrook | return 0; |
101 | e69954b9 | pbrook | default:
|
102 | e69954b9 | pbrook | printf ("arm_sysctl_read: Bad register offset 0x%x\n", (int)offset); |
103 | e69954b9 | pbrook | return 0; |
104 | e69954b9 | pbrook | } |
105 | e69954b9 | pbrook | } |
106 | e69954b9 | pbrook | |
107 | c227f099 | Anthony Liguori | static void arm_sysctl_write(void *opaque, target_phys_addr_t offset, |
108 | e69954b9 | pbrook | uint32_t val) |
109 | e69954b9 | pbrook | { |
110 | e69954b9 | pbrook | arm_sysctl_state *s = (arm_sysctl_state *)opaque; |
111 | e69954b9 | pbrook | |
112 | e69954b9 | pbrook | switch (offset) {
|
113 | e69954b9 | pbrook | case 0x08: /* LED */ |
114 | e69954b9 | pbrook | s->leds = val; |
115 | e69954b9 | pbrook | case 0x0c: /* OSC0 */ |
116 | e69954b9 | pbrook | case 0x10: /* OSC1 */ |
117 | e69954b9 | pbrook | case 0x14: /* OSC2 */ |
118 | e69954b9 | pbrook | case 0x18: /* OSC3 */ |
119 | e69954b9 | pbrook | case 0x1c: /* OSC4 */ |
120 | e69954b9 | pbrook | /* ??? */
|
121 | e69954b9 | pbrook | break;
|
122 | e69954b9 | pbrook | case 0x20: /* LOCK */ |
123 | e69954b9 | pbrook | if (val == LOCK_VALUE)
|
124 | e69954b9 | pbrook | s->lockval = val; |
125 | e69954b9 | pbrook | else
|
126 | e69954b9 | pbrook | s->lockval = val & 0x7fff;
|
127 | e69954b9 | pbrook | break;
|
128 | e69954b9 | pbrook | case 0x28: /* CFGDATA1 */ |
129 | e69954b9 | pbrook | /* ??? Need to implement this. */
|
130 | e69954b9 | pbrook | s->cfgdata1 = val; |
131 | e69954b9 | pbrook | break;
|
132 | e69954b9 | pbrook | case 0x2c: /* CFGDATA2 */ |
133 | e69954b9 | pbrook | /* ??? Need to implement this. */
|
134 | e69954b9 | pbrook | s->cfgdata2 = val; |
135 | e69954b9 | pbrook | break;
|
136 | e69954b9 | pbrook | case 0x30: /* FLAGSSET */ |
137 | e69954b9 | pbrook | s->flags |= val; |
138 | e69954b9 | pbrook | break;
|
139 | e69954b9 | pbrook | case 0x34: /* FLAGSCLR */ |
140 | e69954b9 | pbrook | s->flags &= ~val; |
141 | e69954b9 | pbrook | break;
|
142 | e69954b9 | pbrook | case 0x38: /* NVFLAGSSET */ |
143 | e69954b9 | pbrook | s->nvflags |= val; |
144 | e69954b9 | pbrook | break;
|
145 | e69954b9 | pbrook | case 0x3c: /* NVFLAGSCLR */ |
146 | e69954b9 | pbrook | s->nvflags &= ~val; |
147 | e69954b9 | pbrook | break;
|
148 | e69954b9 | pbrook | case 0x40: /* RESETCTL */ |
149 | e69954b9 | pbrook | if (s->lockval == LOCK_VALUE) {
|
150 | e69954b9 | pbrook | s->resetlevel = val; |
151 | e69954b9 | pbrook | if (val & 0x100) |
152 | f3d6b95e | pbrook | qemu_system_reset_request (); |
153 | e69954b9 | pbrook | } |
154 | e69954b9 | pbrook | break;
|
155 | e69954b9 | pbrook | case 0x44: /* PCICTL */ |
156 | e69954b9 | pbrook | /* nothing to do. */
|
157 | e69954b9 | pbrook | break;
|
158 | e69954b9 | pbrook | case 0x4c: /* FLASH */ |
159 | e69954b9 | pbrook | case 0x50: /* CLCD */ |
160 | e69954b9 | pbrook | case 0x54: /* CLCDSER */ |
161 | e69954b9 | pbrook | case 0x64: /* DMAPSR0 */ |
162 | e69954b9 | pbrook | case 0x68: /* DMAPSR1 */ |
163 | e69954b9 | pbrook | case 0x6c: /* DMAPSR2 */ |
164 | e69954b9 | pbrook | case 0x70: /* IOSEL */ |
165 | e69954b9 | pbrook | case 0x74: /* PLDCTL */ |
166 | e69954b9 | pbrook | case 0x80: /* BUSID */ |
167 | e69954b9 | pbrook | case 0x84: /* PROCID0 */ |
168 | e69954b9 | pbrook | case 0x88: /* PROCID1 */ |
169 | e69954b9 | pbrook | case 0x8c: /* OSCRESET0 */ |
170 | e69954b9 | pbrook | case 0x90: /* OSCRESET1 */ |
171 | e69954b9 | pbrook | case 0x94: /* OSCRESET2 */ |
172 | e69954b9 | pbrook | case 0x98: /* OSCRESET3 */ |
173 | e69954b9 | pbrook | case 0x9c: /* OSCRESET4 */ |
174 | e69954b9 | pbrook | break;
|
175 | e69954b9 | pbrook | default:
|
176 | e69954b9 | pbrook | printf ("arm_sysctl_write: Bad register offset 0x%x\n", (int)offset); |
177 | e69954b9 | pbrook | return;
|
178 | e69954b9 | pbrook | } |
179 | e69954b9 | pbrook | } |
180 | e69954b9 | pbrook | |
181 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const arm_sysctl_readfn[] = { |
182 | e69954b9 | pbrook | arm_sysctl_read, |
183 | e69954b9 | pbrook | arm_sysctl_read, |
184 | e69954b9 | pbrook | arm_sysctl_read |
185 | e69954b9 | pbrook | }; |
186 | e69954b9 | pbrook | |
187 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const arm_sysctl_writefn[] = { |
188 | e69954b9 | pbrook | arm_sysctl_write, |
189 | e69954b9 | pbrook | arm_sysctl_write, |
190 | e69954b9 | pbrook | arm_sysctl_write |
191 | e69954b9 | pbrook | }; |
192 | e69954b9 | pbrook | |
193 | 81a322d4 | Gerd Hoffmann | static int arm_sysctl_init1(SysBusDevice *dev) |
194 | e69954b9 | pbrook | { |
195 | 82634c2d | Paul Brook | arm_sysctl_state *s = FROM_SYSBUS(arm_sysctl_state, dev); |
196 | e69954b9 | pbrook | int iomemtype;
|
197 | e69954b9 | pbrook | |
198 | 9ee6e8bb | pbrook | /* The MPcore bootloader uses these flags to start secondary CPUs.
|
199 | 9ee6e8bb | pbrook | We don't use a bootloader, so do this here. */
|
200 | 9ee6e8bb | pbrook | s->flags = 3;
|
201 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(arm_sysctl_readfn, |
202 | e69954b9 | pbrook | arm_sysctl_writefn, s); |
203 | 82634c2d | Paul Brook | sysbus_init_mmio(dev, 0x1000, iomemtype);
|
204 | e69954b9 | pbrook | /* ??? Save/restore. */
|
205 | 81a322d4 | Gerd Hoffmann | return 0; |
206 | e69954b9 | pbrook | } |
207 | 82634c2d | Paul Brook | |
208 | 82634c2d | Paul Brook | /* Legacy helper function. */
|
209 | 82634c2d | Paul Brook | void arm_sysctl_init(uint32_t base, uint32_t sys_id)
|
210 | 82634c2d | Paul Brook | { |
211 | 82634c2d | Paul Brook | DeviceState *dev; |
212 | 82634c2d | Paul Brook | |
213 | 82634c2d | Paul Brook | dev = qdev_create(NULL, "realview_sysctl"); |
214 | ee6847d1 | Gerd Hoffmann | qdev_prop_set_uint32(dev, "sys_id", sys_id);
|
215 | e23a1b33 | Markus Armbruster | qdev_init_nofail(dev); |
216 | 82634c2d | Paul Brook | sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
|
217 | 82634c2d | Paul Brook | } |
218 | 82634c2d | Paul Brook | |
219 | ee6847d1 | Gerd Hoffmann | static SysBusDeviceInfo arm_sysctl_info = {
|
220 | ee6847d1 | Gerd Hoffmann | .init = arm_sysctl_init1, |
221 | ee6847d1 | Gerd Hoffmann | .qdev.name = "realview_sysctl",
|
222 | ee6847d1 | Gerd Hoffmann | .qdev.size = sizeof(arm_sysctl_state),
|
223 | ee6847d1 | Gerd Hoffmann | .qdev.props = (Property[]) { |
224 | e325775b | Gerd Hoffmann | DEFINE_PROP_UINT32("sys_id", arm_sysctl_state, sys_id, 0), |
225 | e325775b | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
226 | ee6847d1 | Gerd Hoffmann | } |
227 | ee6847d1 | Gerd Hoffmann | }; |
228 | ee6847d1 | Gerd Hoffmann | |
229 | 82634c2d | Paul Brook | static void arm_sysctl_register_devices(void) |
230 | 82634c2d | Paul Brook | { |
231 | ee6847d1 | Gerd Hoffmann | sysbus_register_withprop(&arm_sysctl_info); |
232 | 82634c2d | Paul Brook | } |
233 | 82634c2d | Paul Brook | |
234 | 82634c2d | Paul Brook | device_init(arm_sysctl_register_devices) |