root / hw / versatilepb.c @ 4487fd34
History | View | Annotate | Download (9.2 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | 16406950 | pbrook | * ARM Versatile Platform/Application Baseboard System emulation.
|
3 | cdbdb648 | pbrook | *
|
4 | a1bb27b1 | pbrook | * Copyright (c) 2005-2007 CodeSourcery.
|
5 | cdbdb648 | pbrook | * Written by Paul Brook
|
6 | cdbdb648 | pbrook | *
|
7 | cdbdb648 | pbrook | * This code is licenced under the GPL.
|
8 | cdbdb648 | pbrook | */
|
9 | cdbdb648 | pbrook | |
10 | 87ecb68b | pbrook | #include "hw.h" |
11 | 87ecb68b | pbrook | #include "arm-misc.h" |
12 | 87ecb68b | pbrook | #include "primecell.h" |
13 | 87ecb68b | pbrook | #include "devices.h" |
14 | 87ecb68b | pbrook | #include "net.h" |
15 | 87ecb68b | pbrook | #include "sysemu.h" |
16 | 87ecb68b | pbrook | #include "pci.h" |
17 | 87ecb68b | pbrook | #include "boards.h" |
18 | cdbdb648 | pbrook | |
19 | cdbdb648 | pbrook | /* Primary interrupt controller. */
|
20 | cdbdb648 | pbrook | |
21 | cdbdb648 | pbrook | typedef struct vpb_sic_state |
22 | cdbdb648 | pbrook | { |
23 | cdbdb648 | pbrook | uint32_t base; |
24 | cdbdb648 | pbrook | uint32_t level; |
25 | cdbdb648 | pbrook | uint32_t mask; |
26 | cdbdb648 | pbrook | uint32_t pic_enable; |
27 | d537cf6c | pbrook | qemu_irq *parent; |
28 | cdbdb648 | pbrook | int irq;
|
29 | cdbdb648 | pbrook | } vpb_sic_state; |
30 | cdbdb648 | pbrook | |
31 | cdbdb648 | pbrook | static void vpb_sic_update(vpb_sic_state *s) |
32 | cdbdb648 | pbrook | { |
33 | cdbdb648 | pbrook | uint32_t flags; |
34 | cdbdb648 | pbrook | |
35 | cdbdb648 | pbrook | flags = s->level & s->mask; |
36 | d537cf6c | pbrook | qemu_set_irq(s->parent[s->irq], flags != 0);
|
37 | cdbdb648 | pbrook | } |
38 | cdbdb648 | pbrook | |
39 | cdbdb648 | pbrook | static void vpb_sic_update_pic(vpb_sic_state *s) |
40 | cdbdb648 | pbrook | { |
41 | cdbdb648 | pbrook | int i;
|
42 | cdbdb648 | pbrook | uint32_t mask; |
43 | cdbdb648 | pbrook | |
44 | cdbdb648 | pbrook | for (i = 21; i <= 30; i++) { |
45 | cdbdb648 | pbrook | mask = 1u << i;
|
46 | cdbdb648 | pbrook | if (!(s->pic_enable & mask))
|
47 | cdbdb648 | pbrook | continue;
|
48 | d537cf6c | pbrook | qemu_set_irq(s->parent[i], (s->level & mask) != 0);
|
49 | cdbdb648 | pbrook | } |
50 | cdbdb648 | pbrook | } |
51 | cdbdb648 | pbrook | |
52 | cdbdb648 | pbrook | static void vpb_sic_set_irq(void *opaque, int irq, int level) |
53 | cdbdb648 | pbrook | { |
54 | cdbdb648 | pbrook | vpb_sic_state *s = (vpb_sic_state *)opaque; |
55 | cdbdb648 | pbrook | if (level)
|
56 | cdbdb648 | pbrook | s->level |= 1u << irq;
|
57 | cdbdb648 | pbrook | else
|
58 | cdbdb648 | pbrook | s->level &= ~(1u << irq);
|
59 | cdbdb648 | pbrook | if (s->pic_enable & (1u << irq)) |
60 | d537cf6c | pbrook | qemu_set_irq(s->parent[irq], level); |
61 | cdbdb648 | pbrook | vpb_sic_update(s); |
62 | cdbdb648 | pbrook | } |
63 | cdbdb648 | pbrook | |
64 | cdbdb648 | pbrook | static uint32_t vpb_sic_read(void *opaque, target_phys_addr_t offset) |
65 | cdbdb648 | pbrook | { |
66 | cdbdb648 | pbrook | vpb_sic_state *s = (vpb_sic_state *)opaque; |
67 | cdbdb648 | pbrook | |
68 | cdbdb648 | pbrook | offset -= s->base; |
69 | cdbdb648 | pbrook | switch (offset >> 2) { |
70 | cdbdb648 | pbrook | case 0: /* STATUS */ |
71 | cdbdb648 | pbrook | return s->level & s->mask;
|
72 | cdbdb648 | pbrook | case 1: /* RAWSTAT */ |
73 | cdbdb648 | pbrook | return s->level;
|
74 | cdbdb648 | pbrook | case 2: /* ENABLE */ |
75 | cdbdb648 | pbrook | return s->mask;
|
76 | cdbdb648 | pbrook | case 4: /* SOFTINT */ |
77 | cdbdb648 | pbrook | return s->level & 1; |
78 | cdbdb648 | pbrook | case 8: /* PICENABLE */ |
79 | cdbdb648 | pbrook | return s->pic_enable;
|
80 | cdbdb648 | pbrook | default:
|
81 | e69954b9 | pbrook | printf ("vpb_sic_read: Bad register offset 0x%x\n", (int)offset); |
82 | cdbdb648 | pbrook | return 0; |
83 | cdbdb648 | pbrook | } |
84 | cdbdb648 | pbrook | } |
85 | cdbdb648 | pbrook | |
86 | cdbdb648 | pbrook | static void vpb_sic_write(void *opaque, target_phys_addr_t offset, |
87 | cdbdb648 | pbrook | uint32_t value) |
88 | cdbdb648 | pbrook | { |
89 | cdbdb648 | pbrook | vpb_sic_state *s = (vpb_sic_state *)opaque; |
90 | cdbdb648 | pbrook | offset -= s->base; |
91 | cdbdb648 | pbrook | |
92 | cdbdb648 | pbrook | switch (offset >> 2) { |
93 | cdbdb648 | pbrook | case 2: /* ENSET */ |
94 | cdbdb648 | pbrook | s->mask |= value; |
95 | cdbdb648 | pbrook | break;
|
96 | cdbdb648 | pbrook | case 3: /* ENCLR */ |
97 | cdbdb648 | pbrook | s->mask &= ~value; |
98 | cdbdb648 | pbrook | break;
|
99 | cdbdb648 | pbrook | case 4: /* SOFTINTSET */ |
100 | cdbdb648 | pbrook | if (value)
|
101 | cdbdb648 | pbrook | s->mask |= 1;
|
102 | cdbdb648 | pbrook | break;
|
103 | cdbdb648 | pbrook | case 5: /* SOFTINTCLR */ |
104 | cdbdb648 | pbrook | if (value)
|
105 | cdbdb648 | pbrook | s->mask &= ~1u;
|
106 | cdbdb648 | pbrook | break;
|
107 | cdbdb648 | pbrook | case 8: /* PICENSET */ |
108 | cdbdb648 | pbrook | s->pic_enable |= (value & 0x7fe00000);
|
109 | cdbdb648 | pbrook | vpb_sic_update_pic(s); |
110 | cdbdb648 | pbrook | break;
|
111 | cdbdb648 | pbrook | case 9: /* PICENCLR */ |
112 | cdbdb648 | pbrook | s->pic_enable &= ~value; |
113 | cdbdb648 | pbrook | vpb_sic_update_pic(s); |
114 | cdbdb648 | pbrook | break;
|
115 | cdbdb648 | pbrook | default:
|
116 | e69954b9 | pbrook | printf ("vpb_sic_write: Bad register offset 0x%x\n", (int)offset); |
117 | cdbdb648 | pbrook | return;
|
118 | cdbdb648 | pbrook | } |
119 | cdbdb648 | pbrook | vpb_sic_update(s); |
120 | cdbdb648 | pbrook | } |
121 | cdbdb648 | pbrook | |
122 | cdbdb648 | pbrook | static CPUReadMemoryFunc *vpb_sic_readfn[] = {
|
123 | cdbdb648 | pbrook | vpb_sic_read, |
124 | cdbdb648 | pbrook | vpb_sic_read, |
125 | cdbdb648 | pbrook | vpb_sic_read |
126 | cdbdb648 | pbrook | }; |
127 | cdbdb648 | pbrook | |
128 | cdbdb648 | pbrook | static CPUWriteMemoryFunc *vpb_sic_writefn[] = {
|
129 | cdbdb648 | pbrook | vpb_sic_write, |
130 | cdbdb648 | pbrook | vpb_sic_write, |
131 | cdbdb648 | pbrook | vpb_sic_write |
132 | cdbdb648 | pbrook | }; |
133 | cdbdb648 | pbrook | |
134 | d537cf6c | pbrook | static qemu_irq *vpb_sic_init(uint32_t base, qemu_irq *parent, int irq) |
135 | cdbdb648 | pbrook | { |
136 | cdbdb648 | pbrook | vpb_sic_state *s; |
137 | d537cf6c | pbrook | qemu_irq *qi; |
138 | cdbdb648 | pbrook | int iomemtype;
|
139 | cdbdb648 | pbrook | |
140 | cdbdb648 | pbrook | s = (vpb_sic_state *)qemu_mallocz(sizeof(vpb_sic_state));
|
141 | cdbdb648 | pbrook | if (!s)
|
142 | cdbdb648 | pbrook | return NULL; |
143 | d537cf6c | pbrook | qi = qemu_allocate_irqs(vpb_sic_set_irq, s, 32);
|
144 | cdbdb648 | pbrook | s->base = base; |
145 | cdbdb648 | pbrook | s->parent = parent; |
146 | cdbdb648 | pbrook | s->irq = irq; |
147 | cdbdb648 | pbrook | iomemtype = cpu_register_io_memory(0, vpb_sic_readfn,
|
148 | cdbdb648 | pbrook | vpb_sic_writefn, s); |
149 | 187337f8 | pbrook | cpu_register_physical_memory(base, 0x00001000, iomemtype);
|
150 | cdbdb648 | pbrook | /* ??? Save/restore. */
|
151 | d537cf6c | pbrook | return qi;
|
152 | cdbdb648 | pbrook | } |
153 | cdbdb648 | pbrook | |
154 | cdbdb648 | pbrook | /* Board init. */
|
155 | cdbdb648 | pbrook | |
156 | 16406950 | pbrook | /* The AB and PB boards both use the same core, just with different
|
157 | 16406950 | pbrook | peripherans and expansion busses. For now we emulate a subset of the
|
158 | 16406950 | pbrook | PB peripherals and just change the board ID. */
|
159 | cdbdb648 | pbrook | |
160 | f93eb9ff | balrog | static struct arm_boot_info versatile_binfo; |
161 | f93eb9ff | balrog | |
162 | 00f82b8a | aurel32 | static void versatile_init(ram_addr_t ram_size, int vga_ram_size, |
163 | 6ac0e82d | balrog | const char *boot_device, DisplayState *ds, |
164 | cdbdb648 | pbrook | const char *kernel_filename, const char *kernel_cmdline, |
165 | 3371d272 | pbrook | const char *initrd_filename, const char *cpu_model, |
166 | 3371d272 | pbrook | int board_id)
|
167 | cdbdb648 | pbrook | { |
168 | cdbdb648 | pbrook | CPUState *env; |
169 | d537cf6c | pbrook | qemu_irq *pic; |
170 | d537cf6c | pbrook | qemu_irq *sic; |
171 | 7d8406be | pbrook | void *scsi_hba;
|
172 | 502a5395 | pbrook | PCIBus *pci_bus; |
173 | 502a5395 | pbrook | NICInfo *nd; |
174 | 502a5395 | pbrook | int n;
|
175 | 502a5395 | pbrook | int done_smc = 0; |
176 | e4bcb14c | ths | int index;
|
177 | cdbdb648 | pbrook | |
178 | 3371d272 | pbrook | if (!cpu_model)
|
179 | 3371d272 | pbrook | cpu_model = "arm926";
|
180 | aaed909a | bellard | env = cpu_init(cpu_model); |
181 | aaed909a | bellard | if (!env) {
|
182 | aaed909a | bellard | fprintf(stderr, "Unable to find CPU definition\n");
|
183 | aaed909a | bellard | exit(1);
|
184 | aaed909a | bellard | } |
185 | 1235fc06 | ths | /* ??? RAM should repeat to fill physical memory space. */
|
186 | cdbdb648 | pbrook | /* SDRAM at address zero. */
|
187 | cdbdb648 | pbrook | cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
|
188 | cdbdb648 | pbrook | |
189 | e69954b9 | pbrook | arm_sysctl_init(0x10000000, 0x41007004); |
190 | cdbdb648 | pbrook | pic = arm_pic_init_cpu(env); |
191 | d537cf6c | pbrook | pic = pl190_init(0x10140000, pic[0], pic[1]); |
192 | cdbdb648 | pbrook | sic = vpb_sic_init(0x10003000, pic, 31); |
193 | d537cf6c | pbrook | pl050_init(0x10006000, sic[3], 0); |
194 | d537cf6c | pbrook | pl050_init(0x10007000, sic[4], 1); |
195 | cdbdb648 | pbrook | |
196 | e69954b9 | pbrook | pci_bus = pci_vpb_init(sic, 27, 0); |
197 | 502a5395 | pbrook | /* The Versatile PCI bridge does not provide access to PCI IO space,
|
198 | 502a5395 | pbrook | so many of the qemu PCI devices are not useable. */
|
199 | 502a5395 | pbrook | for(n = 0; n < nb_nics; n++) { |
200 | 502a5395 | pbrook | nd = &nd_table[n]; |
201 | 502a5395 | pbrook | if (!nd->model)
|
202 | 502a5395 | pbrook | nd->model = done_smc ? "rtl8139" : "smc91c111"; |
203 | 502a5395 | pbrook | if (strcmp(nd->model, "smc91c111") == 0) { |
204 | d537cf6c | pbrook | smc91c111_init(nd, 0x10010000, sic[25]); |
205 | cdbdb648 | pbrook | } else {
|
206 | abcebc7e | ths | pci_nic_init(pci_bus, nd, -1);
|
207 | cdbdb648 | pbrook | } |
208 | cdbdb648 | pbrook | } |
209 | 0d92ed30 | pbrook | if (usb_enabled) {
|
210 | e24ad6f1 | pbrook | usb_ohci_init_pci(pci_bus, 3, -1); |
211 | 0d92ed30 | pbrook | } |
212 | e4bcb14c | ths | if (drive_get_max_bus(IF_SCSI) > 0) { |
213 | e4bcb14c | ths | fprintf(stderr, "qemu: too many SCSI bus\n");
|
214 | e4bcb14c | ths | exit(1);
|
215 | e4bcb14c | ths | } |
216 | 7d8406be | pbrook | scsi_hba = lsi_scsi_init(pci_bus, -1);
|
217 | e4bcb14c | ths | for (n = 0; n < LSI_MAX_DEVS; n++) { |
218 | e4bcb14c | ths | index = drive_get_index(IF_SCSI, 0, n);
|
219 | e4bcb14c | ths | if (index == -1) |
220 | e4bcb14c | ths | continue;
|
221 | e4bcb14c | ths | lsi_scsi_attach(scsi_hba, drives_table[index].bdrv, n); |
222 | 7d8406be | pbrook | } |
223 | cdbdb648 | pbrook | |
224 | 9ee6e8bb | pbrook | pl011_init(0x101f1000, pic[12], serial_hds[0], PL011_ARM); |
225 | 9ee6e8bb | pbrook | pl011_init(0x101f2000, pic[13], serial_hds[1], PL011_ARM); |
226 | 9ee6e8bb | pbrook | pl011_init(0x101f3000, pic[14], serial_hds[2], PL011_ARM); |
227 | 9ee6e8bb | pbrook | pl011_init(0x10009000, sic[6], serial_hds[3], PL011_ARM); |
228 | cdbdb648 | pbrook | |
229 | d537cf6c | pbrook | pl080_init(0x10130000, pic[17], 8); |
230 | d537cf6c | pbrook | sp804_init(0x101e2000, pic[4]); |
231 | d537cf6c | pbrook | sp804_init(0x101e3000, pic[5]); |
232 | cdbdb648 | pbrook | |
233 | cdbdb648 | pbrook | /* The versatile/PB actually has a modified Color LCD controller
|
234 | cdbdb648 | pbrook | that includes hardware cursor support from the PL111. */
|
235 | d537cf6c | pbrook | pl110_init(ds, 0x10120000, pic[16], 1); |
236 | cdbdb648 | pbrook | |
237 | e4bcb14c | ths | index = drive_get_index(IF_SD, 0, 0); |
238 | e4bcb14c | ths | if (index == -1) { |
239 | e4bcb14c | ths | fprintf(stderr, "qemu: missing SecureDigital card\n");
|
240 | e4bcb14c | ths | exit(1);
|
241 | e4bcb14c | ths | } |
242 | e4bcb14c | ths | |
243 | e4bcb14c | ths | pl181_init(0x10005000, drives_table[index].bdrv, sic[22], sic[1]); |
244 | a1bb27b1 | pbrook | #if 0
|
245 | a1bb27b1 | pbrook | /* Disabled because there's no way of specifying a block device. */
|
246 | a1bb27b1 | pbrook | pl181_init(0x1000b000, NULL, sic, 23, 2);
|
247 | a1bb27b1 | pbrook | #endif
|
248 | a1bb27b1 | pbrook | |
249 | 7e1543c2 | pbrook | /* Add PL031 Real Time Clock. */
|
250 | 7e1543c2 | pbrook | pl031_init(0x101e8000,pic[10]); |
251 | 7e1543c2 | pbrook | |
252 | 16406950 | pbrook | /* Memory map for Versatile/PB: */
|
253 | cdbdb648 | pbrook | /* 0x10000000 System registers. */
|
254 | cdbdb648 | pbrook | /* 0x10001000 PCI controller config registers. */
|
255 | cdbdb648 | pbrook | /* 0x10002000 Serial bus interface. */
|
256 | cdbdb648 | pbrook | /* 0x10003000 Secondary interrupt controller. */
|
257 | cdbdb648 | pbrook | /* 0x10004000 AACI (audio). */
|
258 | a1bb27b1 | pbrook | /* 0x10005000 MMCI0. */
|
259 | cdbdb648 | pbrook | /* 0x10006000 KMI0 (keyboard). */
|
260 | cdbdb648 | pbrook | /* 0x10007000 KMI1 (mouse). */
|
261 | cdbdb648 | pbrook | /* 0x10008000 Character LCD Interface. */
|
262 | cdbdb648 | pbrook | /* 0x10009000 UART3. */
|
263 | cdbdb648 | pbrook | /* 0x1000a000 Smart card 1. */
|
264 | a1bb27b1 | pbrook | /* 0x1000b000 MMCI1. */
|
265 | cdbdb648 | pbrook | /* 0x10010000 Ethernet. */
|
266 | cdbdb648 | pbrook | /* 0x10020000 USB. */
|
267 | cdbdb648 | pbrook | /* 0x10100000 SSMC. */
|
268 | cdbdb648 | pbrook | /* 0x10110000 MPMC. */
|
269 | cdbdb648 | pbrook | /* 0x10120000 CLCD Controller. */
|
270 | cdbdb648 | pbrook | /* 0x10130000 DMA Controller. */
|
271 | cdbdb648 | pbrook | /* 0x10140000 Vectored interrupt controller. */
|
272 | cdbdb648 | pbrook | /* 0x101d0000 AHB Monitor Interface. */
|
273 | cdbdb648 | pbrook | /* 0x101e0000 System Controller. */
|
274 | cdbdb648 | pbrook | /* 0x101e1000 Watchdog Interface. */
|
275 | cdbdb648 | pbrook | /* 0x101e2000 Timer 0/1. */
|
276 | cdbdb648 | pbrook | /* 0x101e3000 Timer 2/3. */
|
277 | cdbdb648 | pbrook | /* 0x101e4000 GPIO port 0. */
|
278 | cdbdb648 | pbrook | /* 0x101e5000 GPIO port 1. */
|
279 | cdbdb648 | pbrook | /* 0x101e6000 GPIO port 2. */
|
280 | cdbdb648 | pbrook | /* 0x101e7000 GPIO port 3. */
|
281 | cdbdb648 | pbrook | /* 0x101e8000 RTC. */
|
282 | cdbdb648 | pbrook | /* 0x101f0000 Smart card 0. */
|
283 | cdbdb648 | pbrook | /* 0x101f1000 UART0. */
|
284 | cdbdb648 | pbrook | /* 0x101f2000 UART1. */
|
285 | cdbdb648 | pbrook | /* 0x101f3000 UART2. */
|
286 | cdbdb648 | pbrook | /* 0x101f4000 SSPI. */
|
287 | cdbdb648 | pbrook | |
288 | f93eb9ff | balrog | versatile_binfo.ram_size = ram_size; |
289 | f93eb9ff | balrog | versatile_binfo.kernel_filename = kernel_filename; |
290 | f93eb9ff | balrog | versatile_binfo.kernel_cmdline = kernel_cmdline; |
291 | f93eb9ff | balrog | versatile_binfo.initrd_filename = initrd_filename; |
292 | f93eb9ff | balrog | versatile_binfo.board_id = board_id; |
293 | f93eb9ff | balrog | arm_load_kernel(env, &versatile_binfo); |
294 | 16406950 | pbrook | } |
295 | 16406950 | pbrook | |
296 | 00f82b8a | aurel32 | static void vpb_init(ram_addr_t ram_size, int vga_ram_size, |
297 | b881c2c6 | blueswir1 | const char *boot_device, DisplayState *ds, |
298 | 16406950 | pbrook | const char *kernel_filename, const char *kernel_cmdline, |
299 | 94fc95cd | j_mayer | const char *initrd_filename, const char *cpu_model) |
300 | 16406950 | pbrook | { |
301 | b881c2c6 | blueswir1 | versatile_init(ram_size, vga_ram_size, |
302 | b881c2c6 | blueswir1 | boot_device, ds, |
303 | 16406950 | pbrook | kernel_filename, kernel_cmdline, |
304 | 3371d272 | pbrook | initrd_filename, cpu_model, 0x183);
|
305 | 16406950 | pbrook | } |
306 | 16406950 | pbrook | |
307 | 00f82b8a | aurel32 | static void vab_init(ram_addr_t ram_size, int vga_ram_size, |
308 | b881c2c6 | blueswir1 | const char *boot_device, DisplayState *ds, |
309 | 16406950 | pbrook | const char *kernel_filename, const char *kernel_cmdline, |
310 | 94fc95cd | j_mayer | const char *initrd_filename, const char *cpu_model) |
311 | 16406950 | pbrook | { |
312 | b881c2c6 | blueswir1 | versatile_init(ram_size, vga_ram_size, |
313 | b881c2c6 | blueswir1 | boot_device, ds, |
314 | 16406950 | pbrook | kernel_filename, kernel_cmdline, |
315 | 3371d272 | pbrook | initrd_filename, cpu_model, 0x25e);
|
316 | cdbdb648 | pbrook | } |
317 | cdbdb648 | pbrook | |
318 | cdbdb648 | pbrook | QEMUMachine versatilepb_machine = { |
319 | cdbdb648 | pbrook | "versatilepb",
|
320 | cdbdb648 | pbrook | "ARM Versatile/PB (ARM926EJ-S)",
|
321 | cdbdb648 | pbrook | vpb_init, |
322 | cdbdb648 | pbrook | }; |
323 | 16406950 | pbrook | |
324 | 16406950 | pbrook | QEMUMachine versatileab_machine = { |
325 | 16406950 | pbrook | "versatileab",
|
326 | 16406950 | pbrook | "ARM Versatile/AB (ARM926EJ-S)",
|
327 | 16406950 | pbrook | vab_init, |
328 | 16406950 | pbrook | }; |