root / hw / arm_sysctl.c @ 50d3eeae
History | View | Annotate | Download (5.2 kB)
1 | e69954b9 | pbrook | /*
|
---|---|---|---|
2 | e69954b9 | pbrook | * Status and system control registers for ARM RealView/Versatile boards.
|
3 | e69954b9 | pbrook | *
|
4 | e69954b9 | pbrook | * Copyright (c) 2006 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 | e69954b9 | pbrook | #include "vl.h" |
11 | e69954b9 | pbrook | #include "arm_pic.h" |
12 | e69954b9 | pbrook | |
13 | e69954b9 | pbrook | #define LOCK_VALUE 0xa05f |
14 | e69954b9 | pbrook | |
15 | e69954b9 | pbrook | typedef struct { |
16 | e69954b9 | pbrook | uint32_t base; |
17 | e69954b9 | pbrook | uint32_t sys_id; |
18 | e69954b9 | pbrook | uint32_t leds; |
19 | e69954b9 | pbrook | uint16_t lockval; |
20 | e69954b9 | pbrook | uint32_t cfgdata1; |
21 | e69954b9 | pbrook | uint32_t cfgdata2; |
22 | e69954b9 | pbrook | uint32_t flags; |
23 | e69954b9 | pbrook | uint32_t nvflags; |
24 | e69954b9 | pbrook | uint32_t resetlevel; |
25 | e69954b9 | pbrook | } arm_sysctl_state; |
26 | e69954b9 | pbrook | |
27 | e69954b9 | pbrook | static uint32_t arm_sysctl_read(void *opaque, target_phys_addr_t offset) |
28 | e69954b9 | pbrook | { |
29 | e69954b9 | pbrook | arm_sysctl_state *s = (arm_sysctl_state *)opaque; |
30 | e69954b9 | pbrook | |
31 | e69954b9 | pbrook | offset -= s->base; |
32 | e69954b9 | pbrook | switch (offset) {
|
33 | e69954b9 | pbrook | case 0x00: /* ID */ |
34 | e69954b9 | pbrook | return s->sys_id;
|
35 | e69954b9 | pbrook | case 0x04: /* SW */ |
36 | e69954b9 | pbrook | /* General purpose hardware switches.
|
37 | e69954b9 | pbrook | We don't have a useful way of exposing these to the user. */
|
38 | e69954b9 | pbrook | return 0; |
39 | e69954b9 | pbrook | case 0x08: /* LED */ |
40 | e69954b9 | pbrook | return s->leds;
|
41 | e69954b9 | pbrook | case 0x20: /* LOCK */ |
42 | e69954b9 | pbrook | return s->lockval;
|
43 | e69954b9 | pbrook | case 0x0c: /* OSC0 */ |
44 | e69954b9 | pbrook | case 0x10: /* OSC1 */ |
45 | e69954b9 | pbrook | case 0x14: /* OSC2 */ |
46 | e69954b9 | pbrook | case 0x18: /* OSC3 */ |
47 | e69954b9 | pbrook | case 0x1c: /* OSC4 */ |
48 | e69954b9 | pbrook | case 0x24: /* 100HZ */ |
49 | e69954b9 | pbrook | /* ??? Implement these. */
|
50 | e69954b9 | pbrook | return 0; |
51 | e69954b9 | pbrook | case 0x28: /* CFGDATA1 */ |
52 | e69954b9 | pbrook | return s->cfgdata1;
|
53 | e69954b9 | pbrook | case 0x2c: /* CFGDATA2 */ |
54 | e69954b9 | pbrook | return s->cfgdata2;
|
55 | e69954b9 | pbrook | case 0x30: /* FLAGS */ |
56 | e69954b9 | pbrook | return s->flags;
|
57 | e69954b9 | pbrook | case 0x38: /* NVFLAGS */ |
58 | e69954b9 | pbrook | return s->nvflags;
|
59 | e69954b9 | pbrook | case 0x40: /* RESETCTL */ |
60 | e69954b9 | pbrook | return s->resetlevel;
|
61 | e69954b9 | pbrook | case 0x44: /* PCICTL */ |
62 | e69954b9 | pbrook | return 1; |
63 | e69954b9 | pbrook | case 0x48: /* MCI */ |
64 | e69954b9 | pbrook | return 0; |
65 | e69954b9 | pbrook | case 0x4c: /* FLASH */ |
66 | e69954b9 | pbrook | return 0; |
67 | e69954b9 | pbrook | case 0x50: /* CLCD */ |
68 | e69954b9 | pbrook | return 0x1000; |
69 | e69954b9 | pbrook | case 0x54: /* CLCDSER */ |
70 | e69954b9 | pbrook | return 0; |
71 | e69954b9 | pbrook | case 0x58: /* BOOTCS */ |
72 | e69954b9 | pbrook | return 0; |
73 | e69954b9 | pbrook | case 0x5c: /* 24MHz */ |
74 | e69954b9 | pbrook | /* ??? not implemented. */
|
75 | e69954b9 | pbrook | return 0; |
76 | e69954b9 | pbrook | case 0x60: /* MISC */ |
77 | e69954b9 | pbrook | return 0; |
78 | e69954b9 | pbrook | case 0x84: /* PROCID0 */ |
79 | e69954b9 | pbrook | /* ??? Don't know what the proper value for the core tile ID is. */
|
80 | e69954b9 | pbrook | return 0x02000000; |
81 | e69954b9 | pbrook | case 0x88: /* PROCID1 */ |
82 | e69954b9 | pbrook | return 0xff000000; |
83 | e69954b9 | pbrook | case 0x64: /* DMAPSR0 */ |
84 | e69954b9 | pbrook | case 0x68: /* DMAPSR1 */ |
85 | e69954b9 | pbrook | case 0x6c: /* DMAPSR2 */ |
86 | e69954b9 | pbrook | case 0x70: /* IOSEL */ |
87 | e69954b9 | pbrook | case 0x74: /* PLDCTL */ |
88 | e69954b9 | pbrook | case 0x80: /* BUSID */ |
89 | e69954b9 | pbrook | case 0x8c: /* OSCRESET0 */ |
90 | e69954b9 | pbrook | case 0x90: /* OSCRESET1 */ |
91 | e69954b9 | pbrook | case 0x94: /* OSCRESET2 */ |
92 | e69954b9 | pbrook | case 0x98: /* OSCRESET3 */ |
93 | e69954b9 | pbrook | case 0x9c: /* OSCRESET4 */ |
94 | e69954b9 | pbrook | case 0xc0: /* SYS_TEST_OSC0 */ |
95 | e69954b9 | pbrook | case 0xc4: /* SYS_TEST_OSC1 */ |
96 | e69954b9 | pbrook | case 0xc8: /* SYS_TEST_OSC2 */ |
97 | e69954b9 | pbrook | case 0xcc: /* SYS_TEST_OSC3 */ |
98 | e69954b9 | pbrook | case 0xd0: /* SYS_TEST_OSC4 */ |
99 | e69954b9 | pbrook | return 0; |
100 | e69954b9 | pbrook | default:
|
101 | e69954b9 | pbrook | printf ("arm_sysctl_read: Bad register offset 0x%x\n", (int)offset); |
102 | e69954b9 | pbrook | return 0; |
103 | e69954b9 | pbrook | } |
104 | e69954b9 | pbrook | } |
105 | e69954b9 | pbrook | |
106 | e69954b9 | pbrook | static void arm_sysctl_write(void *opaque, target_phys_addr_t offset, |
107 | e69954b9 | pbrook | uint32_t val) |
108 | e69954b9 | pbrook | { |
109 | e69954b9 | pbrook | arm_sysctl_state *s = (arm_sysctl_state *)opaque; |
110 | e69954b9 | pbrook | offset -= s->base; |
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 | e69954b9 | pbrook | static CPUReadMemoryFunc *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 | e69954b9 | pbrook | static CPUWriteMemoryFunc *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 | e69954b9 | pbrook | void arm_sysctl_init(uint32_t base, uint32_t sys_id)
|
194 | e69954b9 | pbrook | { |
195 | e69954b9 | pbrook | arm_sysctl_state *s; |
196 | e69954b9 | pbrook | int iomemtype;
|
197 | e69954b9 | pbrook | |
198 | e69954b9 | pbrook | s = (arm_sysctl_state *)qemu_mallocz(sizeof(arm_sysctl_state));
|
199 | e69954b9 | pbrook | if (!s)
|
200 | e69954b9 | pbrook | return;
|
201 | e69954b9 | pbrook | s->base = base; |
202 | e69954b9 | pbrook | s->sys_id = sys_id; |
203 | e69954b9 | pbrook | iomemtype = cpu_register_io_memory(0, arm_sysctl_readfn,
|
204 | e69954b9 | pbrook | arm_sysctl_writefn, s); |
205 | e69954b9 | pbrook | cpu_register_physical_memory(base, 0x00000fff, iomemtype);
|
206 | e69954b9 | pbrook | /* ??? Save/restore. */
|
207 | e69954b9 | pbrook | } |