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