/[dynamips]/trunk/dev_c2691.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/dev_c2691.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations)
Sat Oct 6 16:45:40 2007 UTC (11 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 21365 byte(s)
make working copy

1 /*
2 * Cisco router simulation platform.
3 * Copyright (c) 2006 Christophe Fillot (cf@utc.fr)
4 *
5 * Generic Cisco 2691 routines and definitions (EEPROM,...).
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <sys/types.h>
13 #include <assert.h>
14
15 #include "cpu.h"
16 #include "vm.h"
17 #include "dynamips.h"
18 #include "memory.h"
19 #include "device.h"
20 #include "pci_io.h"
21 #include "dev_gt.h"
22 #include "cisco_eeprom.h"
23 #include "dev_rom.h"
24 #include "dev_c2691.h"
25 #include "dev_c2691_iofpga.h"
26 #include "dev_vtty.h"
27 #include "registry.h"
28
29 /* ======================================================================== */
30 /* EEPROM definitions */
31 /* ======================================================================== */
32
33 /* Cisco 2691 mainboard EEPROM */
34 static m_uint16_t eeprom_c2691_mainboard_data[] = {
35 0x04FF, 0xC18B, 0x5858, 0x5858, 0x5858, 0x5858, 0x5858, 0x5809,
36 0x6640, 0x0258, 0xC046, 0x0320, 0x0025, 0x9002, 0x4246, 0x3085,
37 0x1C10, 0x8206, 0x80FF, 0xFFFF, 0xFFC4, 0x08FF, 0xFFFF, 0xFFFF,
38 0xFFFF, 0xFF81, 0xFFFF, 0xFFFF, 0x03FF, 0x04FF, 0xC28B, 0x5858,
39 0x5858, 0x5858, 0x5858, 0x5858, 0x58C3, 0x0600, 0x1280, 0xD387,
40 0xC043, 0x0020, 0xC508, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x4100,
41 0x0101, 0x01FF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
42 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
43 };
44
45 struct cisco_eeprom eeprom_c2691_mainboard = {
46 "C2691 Backplane",
47 eeprom_c2691_mainboard_data,
48 sizeof(eeprom_c2691_mainboard_data)/2,
49 };
50
51 /* ======================================================================== */
52 /* Network Module Drivers */
53 /* ======================================================================== */
54 static struct cisco_card_driver *nm_drivers[] = {
55 &dev_c2691_nm_1fe_tx_driver,
56 &dev_c2691_nm_16esw_driver,
57 &dev_c2691_gt96100_fe_driver,
58 &dev_c2691_nm_4t_driver,
59 &dev_c2691_nm_nam_driver,
60 &dev_c2691_nm_cids_driver,
61 NULL,
62 };
63
64 /* ======================================================================== */
65 /* Cisco 2691 router instances */
66 /* ======================================================================== */
67
68 /* Initialize default parameters for a C2691 */
69 static void c2691_init_defaults(c2691_t *router);
70
71 /* Directly extract the configuration from the NVRAM device */
72 ssize_t c2691_nvram_extract_config(vm_instance_t *vm,u_char **buffer)
73 {
74 u_char *base_ptr,*ios_ptr,*cfg_ptr,*end_ptr;
75 m_uint32_t start,nvlen;
76 m_uint16_t magic1,magic2;
77 struct vdevice *nvram_dev;
78 off_t nvram_size;
79 int fd;
80
81 if ((nvram_dev = dev_get_by_name(vm,"rom")))
82 dev_sync(nvram_dev);
83
84 fd = vm_mmap_open_file(vm,"rom",&base_ptr,&nvram_size);
85
86 if (fd == -1)
87 return(-1);
88
89 ios_ptr = base_ptr + C2691_NVRAM_OFFSET;
90 end_ptr = base_ptr + nvram_size;
91
92 if ((ios_ptr + 0x30) >= end_ptr) {
93 vm_error(vm,"NVRAM file too small\n");
94 return(-1);
95 }
96
97 magic1 = ntohs(*PTR_ADJUST(m_uint16_t *,ios_ptr,0x06));
98 magic2 = ntohs(*PTR_ADJUST(m_uint16_t *,ios_ptr,0x08));
99
100 if ((magic1 != 0xF0A5) || (magic2 != 0xABCD)) {
101 vm_error(vm,"unable to find IOS magic numbers (0x%x,0x%x)!\n",
102 magic1,magic2);
103 return(-1);
104 }
105
106 start = ntohl(*PTR_ADJUST(m_uint32_t *,ios_ptr,0x10)) + 1;
107 nvlen = ntohl(*PTR_ADJUST(m_uint32_t *,ios_ptr,0x18));
108
109 if (!(*buffer = malloc(nvlen+1))) {
110 vm_error(vm,"unable to allocate config buffer (%u bytes)\n",nvlen);
111 return(-1);
112 }
113
114 cfg_ptr = ios_ptr + start + 0x08;
115
116 if ((cfg_ptr + nvlen) > end_ptr) {
117 vm_error(vm,"NVRAM file too small\n");
118 return(-1);
119 }
120
121 memcpy(*buffer,cfg_ptr,nvlen-1);
122 (*buffer)[nvlen-1] = 0;
123 return(nvlen-1);
124 }
125
126 static int c2691_nvram_push_config_part(vm_instance_t *vm,
127 u_char *buffer,size_t len,
128 u_char *ios_ptr)
129 {
130 m_uint32_t cfg_offset,cklen,tmp;
131 m_uint16_t cksum;
132 u_char *cfg_ptr;
133
134 cfg_offset = 0x2c;
135 cfg_ptr = ios_ptr + cfg_offset;
136
137 /* Write IOS tag, uncompressed config... */
138 *PTR_ADJUST(m_uint16_t *,ios_ptr,0x06) = htons(0xF0A5);
139 *PTR_ADJUST(m_uint16_t *,ios_ptr,0x08) = htons(0xABCD);
140 *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0a) = htons(0x0001);
141 *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0c) = htons(0x0000);
142 *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0e) = htons(0x0c04);
143
144 /* Store file contents to NVRAM */
145 memcpy(cfg_ptr,buffer,len);
146
147 /* Write config addresses + size */
148 tmp = cfg_offset - 0x08;
149
150 *PTR_ADJUST(m_uint32_t *,ios_ptr,0x10) = htonl(tmp);
151 *PTR_ADJUST(m_uint32_t *,ios_ptr,0x14) = htonl(tmp + len);
152 *PTR_ADJUST(m_uint32_t *,ios_ptr,0x18) = htonl(len);
153
154 /* Compute the checksum */
155 cklen = C2691_NVRAM_SIZE - 0x08;
156 cksum = nvram_cksum((m_uint16_t *)(ios_ptr+0x08),cklen);
157 *PTR_ADJUST(m_uint16_t *,ios_ptr,0x0c) = htons(cksum);
158 return(0);
159 }
160
161 /* Directly push the IOS configuration to the NVRAM device */
162 int c2691_nvram_push_config(vm_instance_t *vm,u_char *buffer,size_t len)
163 {
164 u_char *base_ptr,*ios_ptr;
165 int fd;
166
167 fd = vm_mmap_create_file(vm,"rom",vm->rom_size*1048576,&base_ptr);
168
169 if (fd == -1)
170 return(-1);
171
172 ios_ptr = base_ptr + C2691_NVRAM_OFFSET;
173
174 /* Normal config */
175 c2691_nvram_push_config_part(vm,buffer,len,ios_ptr);
176
177 /* Backup config */
178 c2691_nvram_push_config_part(vm,buffer,len,ios_ptr + C2691_NVRAM_SIZE);
179
180 vm_mmap_close_file(fd,base_ptr,vm->rom_size*1048576);
181 return(0);
182 }
183
184 /* Check for empty config */
185 int c2691_nvram_check_empty_config(vm_instance_t *vm)
186 {
187 struct vdevice *rom_dev;
188 m_uint64_t addr;
189 size_t len;
190
191 if (!(rom_dev = dev_get_by_name(vm,"rom")))
192 return(-1);
193
194 addr = rom_dev->phys_addr + C2691_NVRAM_OFFSET;
195 len = C2691_NVRAM_SIZE;
196
197 while(len > 0) {
198 if (physmem_copy_u32_from_vm(vm,addr) != 0)
199 return(0);
200
201 addr += sizeof(m_uint32_t);
202 len -= sizeof(m_uint32_t);
203 }
204
205 /* Empty NVRAM */
206 vm->conf_reg |= 0x0040;
207 printf("NVRAM is empty, setting config register to 0x%x\n",vm->conf_reg);
208 return(0);
209 }
210
211 /* Create a new router instance */
212 static int c2691_create_instance(vm_instance_t *vm)
213 {
214 c2691_t *router;
215
216 if (!(router = malloc(sizeof(*router)))) {
217 fprintf(stderr,"C2691 '%s': Unable to create new instance!\n",vm->name);
218 return(-1);
219 }
220
221 memset(router,0,sizeof(*router));
222 router->vm = vm;
223 vm->hw_data = router;
224
225 c2691_init_defaults(router);
226 return(0);
227 }
228
229 /* Free resources used by a router instance */
230 static int c2691_delete_instance(vm_instance_t *vm)
231 {
232 c2691_t *router = VM_C2691(vm);
233 int i;
234
235 /* Stop all CPUs */
236 if (vm->cpu_group != NULL) {
237 vm_stop(vm);
238
239 if (cpu_group_sync_state(vm->cpu_group) == -1) {
240 vm_error(vm,"unable to sync with system CPUs.\n");
241 return(FALSE);
242 }
243 }
244
245 /* Remove NIO bindings */
246 for(i=0;i<vm->nr_slots;i++)
247 vm_slot_remove_all_nio_bindings(vm,i);
248
249 /* Shutdown all Network Modules */
250 vm_slot_shutdown_all(vm);
251
252 /* Free mainboard EEPROM */
253 cisco_eeprom_free(&router->mb_eeprom);
254
255 /* Free all resources used by VM */
256 vm_free(vm);
257
258 /* Free the router structure */
259 free(router);
260 return(TRUE);
261 }
262
263 /* Get WIC device address for the specified onboard port */
264 int c2691_get_onboard_wic_addr(u_int slot,m_uint64_t *phys_addr)
265 {
266 if (slot >= C2691_MAX_WIC_BAYS)
267 return(-1);
268
269 *phys_addr = C2691_WIC_ADDR + (slot * C2691_WIC_SIZE);
270 return(0);
271 }
272
273 /* Set EEPROM for the specified slot */
274 int c2691_set_slot_eeprom(c2691_t *router,u_int slot,
275 struct cisco_eeprom *eeprom)
276 {
277 if (slot != 1)
278 return(-1);
279
280 router->nm_eeprom_group.eeprom[0] = eeprom;
281 return(0);
282 }
283
284 /* Get slot/port corresponding to specified network IRQ */
285 static inline void
286 c2691_net_irq_get_slot_port(u_int irq,u_int *slot,u_int *port)
287 {
288 irq -= C2691_NETIO_IRQ_BASE;
289 *port = irq & C2691_NETIO_IRQ_PORT_MASK;
290 *slot = irq >> C2691_NETIO_IRQ_PORT_BITS;
291 }
292
293 /* Get network IRQ for specified slot/port */
294 u_int c2691_net_irq_for_slot_port(u_int slot,u_int port)
295 {
296 u_int irq;
297
298 irq = (slot << C2691_NETIO_IRQ_PORT_BITS) + port;
299 irq += C2691_NETIO_IRQ_BASE;
300
301 return(irq);
302 }
303
304 /* Set the base MAC address of the chassis */
305 static int c2691_burn_mac_addr(c2691_t *router,n_eth_addr_t *addr)
306 {
307 m_uint8_t eeprom_ver;
308 size_t offset;
309
310 /* Read EEPROM format version */
311 cisco_eeprom_get_byte(&router->mb_eeprom,0,&eeprom_ver);
312
313 switch(eeprom_ver) {
314 case 0:
315 cisco_eeprom_set_region(&router->mb_eeprom,2,addr->eth_addr_byte,6);
316 break;
317
318 case 4:
319 if (!cisco_eeprom_v4_find_field(&router->mb_eeprom,0xC3,&offset)) {
320 cisco_eeprom_set_region(&router->mb_eeprom,offset,
321 addr->eth_addr_byte,6);
322 }
323 break;
324
325 default:
326 vm_error(router->vm,"c2691_burn_mac_addr: unable to handle "
327 "EEPROM version %u\n",eeprom_ver);
328 return(-1);
329 }
330
331 return(0);
332 }
333
334 /* Set chassis MAC address */
335 int c2691_chassis_set_mac_addr(c2691_t *router,char *mac_addr)
336 {
337 if (parse_mac_addr(&router->mac_addr,mac_addr) == -1) {
338 vm_error(router->vm,"unable to parse MAC address '%s'.\n",mac_addr);
339 return(-1);
340 }
341
342 /* Set the chassis base MAC address */
343 c2691_burn_mac_addr(router,&router->mac_addr);
344 return(0);
345 }
346
347 /* Create the two main PCI busses for a GT64120 based system */
348 static int c2691_init_gt96100(c2691_t *router)
349 {
350 vm_instance_t *vm = router->vm;
351 vm_obj_t *obj;
352
353 vm->pci_bus[0] = pci_bus_create("PCI bus #0",0);
354 vm->pci_bus[1] = pci_bus_create("PCI bus #1",0);
355
356 if (!vm->pci_bus[0] || !vm->pci_bus[1]) {
357 vm_error(router->vm,"unable to create PCI data.\n");
358 return(-1);
359 }
360
361 if (dev_gt96100_init(vm,"gt96100",C2691_GT96K_ADDR,0x200000,
362 C2691_GT96K_IRQ,
363 C2691_EXT_IRQ,
364 c2691_net_irq_for_slot_port(0,0),
365 255) == -1)
366 return(-1);
367
368 if (!(obj = vm_object_find(router->vm,"gt96100")))
369 return(-1);
370
371 router->gt_data = obj->data;
372 return(0);
373 }
374
375 /* Initialize a Cisco 2691 */
376 static int c2691_init(c2691_t *router)
377 {
378 vm_instance_t *vm = router->vm;
379
380 /* Set the processor type: R7000 */
381 mips64_set_prid(CPU_MIPS64(vm->boot_cpu),MIPS_PRID_R7000);
382
383 /* Initialize the Galileo GT-96100 PCI controller */
384 if (c2691_init_gt96100(router) == -1)
385 return(-1);
386
387 /* Initialize PCI map (NM slot 1) */
388 vm->slots_pci_bus[1] = vm->pci_bus[1];
389
390 vm->elf_machine_id = C2691_ELF_MACHINE_ID;
391 return(0);
392 }
393
394 /* Show C2691 hardware info */
395 void c2691_show_hardware(c2691_t *router)
396 {
397 vm_instance_t *vm = router->vm;
398
399 printf("C2691 instance '%s' (id %d):\n",vm->name,vm->instance_id);
400
401 printf(" VM Status : %d\n",vm->status);
402 printf(" RAM size : %u Mb\n",vm->ram_size);
403 printf(" NVRAM size : %u Kb\n",vm->nvram_size);
404 printf(" IOS image : %s\n\n",vm->ios_image);
405
406 if (vm->debug_level > 0) {
407 dev_show_list(vm);
408 pci_dev_show_list(vm->pci_bus[0]);
409 pci_dev_show_list(vm->pci_bus[1]);
410 printf("\n");
411 }
412 }
413
414 /* Initialize default parameters for a C2691 */
415 static void c2691_init_defaults(c2691_t *router)
416 {
417 vm_instance_t *vm = router->vm;
418 n_eth_addr_t *m;
419 m_uint16_t pid;
420
421 /* Set platform slots characteristics */
422 vm->nr_slots = C2691_MAX_NM_BAYS;
423 vm->slots_type = CISCO_CARD_TYPE_NM;
424 vm->slots_drivers = nm_drivers;
425
426 pid = (m_uint16_t)getpid();
427
428 /* Generate a chassis MAC address based on the instance ID */
429 m = &router->mac_addr;
430 m->eth_addr_byte[0] = vm_get_mac_addr_msb(vm);
431 m->eth_addr_byte[1] = vm->instance_id & 0xFF;
432 m->eth_addr_byte[2] = pid >> 8;
433 m->eth_addr_byte[3] = pid & 0xFF;
434 m->eth_addr_byte[4] = 0x00;
435 m->eth_addr_byte[5] = 0x00;
436
437 c2691_init_eeprom_groups(router);
438 cisco_eeprom_copy(&router->mb_eeprom,&eeprom_c2691_mainboard);
439 c2691_burn_mac_addr(router,&router->mac_addr);
440
441 /* The GT96100 system controller has 2 integrated FastEthernet ports */
442 vm_slot_add_binding(vm,"GT96100-FE",0,0);
443
444 vm->ram_mmap = C2691_DEFAULT_RAM_MMAP;
445 vm->ram_size = C2691_DEFAULT_RAM_SIZE;
446 vm->rom_size = C2691_DEFAULT_ROM_SIZE;
447 vm->nvram_size = C2691_DEFAULT_NVRAM_SIZE;
448 vm->conf_reg_setup = C2691_DEFAULT_CONF_REG;
449 vm->clock_divisor = C2691_DEFAULT_CLOCK_DIV;
450 vm->nvram_rom_space = C2691_NVRAM_ROM_RES_SIZE;
451 vm->nm_iomem_size = C2691_DEFAULT_IOMEM_SIZE;
452
453 vm->pcmcia_disk_size[0] = C2691_DEFAULT_DISK0_SIZE;
454 vm->pcmcia_disk_size[1] = C2691_DEFAULT_DISK1_SIZE;
455 }
456
457 /* Initialize the C2691 Platform */
458 static int c2691_init_platform(c2691_t *router)
459 {
460 vm_instance_t *vm = router->vm;
461 cpu_mips_t *cpu;
462 cpu_gen_t *gen;
463 vm_obj_t *obj;
464
465 /* Copy config register setup into "active" config register */
466 vm->conf_reg = vm->conf_reg_setup;
467
468 /* Create Console and AUX ports */
469 vm_init_vtty(vm);
470
471 /* Create a CPU group */
472 vm->cpu_group = cpu_group_create("System CPU");
473
474 /* Initialize the virtual MIPS processor */
475 if (!(gen = cpu_create(vm,CPU_TYPE_MIPS64,0))) {
476 vm_error(vm,"unable to create CPU!\n");
477 return(-1);
478 }
479
480 cpu = CPU_MIPS64(gen);
481
482 /* Add this CPU to the system CPU group */
483 cpu_group_add(vm->cpu_group,gen);
484 vm->boot_cpu = gen;
485
486 /* Initialize the IRQ routing vectors */
487 vm->set_irq = mips64_vm_set_irq;
488 vm->clear_irq = mips64_vm_clear_irq;
489
490 /* Mark the Network IO interrupt as high priority */
491 cpu->irq_idle_preempt[C2691_NETIO_IRQ] = TRUE;
492 cpu->irq_idle_preempt[C2691_GT96K_IRQ] = TRUE;
493 cpu->irq_idle_preempt[C2691_DUART_IRQ] = TRUE;
494
495 /* Copy some parameters from VM to CPU (idle PC, ...) */
496 cpu->idle_pc = vm->idle_pc;
497
498 if (vm->timer_irq_check_itv)
499 cpu->timer_irq_check_itv = vm->timer_irq_check_itv;
500
501 /* Remote emulator control */
502 dev_remote_control_init(vm,0x16000000,0x1000);
503
504 /* Specific Storage Area (SSA) */
505 dev_ram_init(vm,"ssa",TRUE,FALSE,NULL,FALSE,0x16001000ULL,0x7000);
506
507 /* IO FPGA */
508 if (dev_c2691_iofpga_init(router,C2691_IOFPGA_ADDR,0x40000) == -1)
509 return(-1);
510
511 if (!(obj = vm_object_find(router->vm,"io_fpga")))
512 return(-1);
513
514 router->iofpga_data = obj->data;
515
516 #if 0
517 /* PCI IO space */
518 if (!(vm->pci_io_space = pci_io_data_init(vm,C2691_PCI_IO_ADDR)))
519 return(-1);
520 #endif
521
522 /* Initialize the chassis */
523 if (c2691_init(router) == -1)
524 return(-1);
525
526 /* Initialize RAM */
527 vm_ram_init(vm,0x00000000ULL);
528
529 /* Initialize ROM (as a Flash) */
530 if (!(obj = dev_flash_init(vm,"rom",C2691_ROM_ADDR,vm->rom_size*1048576)))
531 return(-1);
532
533 dev_flash_copy_data(obj,0,mips64_microcode,mips64_microcode_len);
534 c2691_nvram_check_empty_config(vm);
535
536 /* Byte swapping */
537 dev_bswap_init(vm,"mem_bswap",C2691_BSWAP_ADDR,1024*1048576,0x00000000ULL);
538
539 /* Initialize the NS16552 DUART */
540 dev_ns16552_init(vm,C2691_DUART_ADDR,0x1000,3,C2691_DUART_IRQ,
541 vm->vtty_con,vm->vtty_aux);
542
543 /* PCMCIA Slot 0 */
544 dev_pcmcia_disk_init(vm,"slot0",C2691_SLOT0_ADDR,0x200000,
545 vm->pcmcia_disk_size[0],1);
546
547 /* PCMCIA Slot 1 */
548 dev_pcmcia_disk_init(vm,"slot1",C2691_SLOT1_ADDR,0x200000,
549 vm->pcmcia_disk_size[1],1);
550
551 /* Initialize Network Modules */
552 if (vm_slot_init_all(vm) == -1)
553 return(-1);
554
555 /* Show device list */
556 c2691_show_hardware(router);
557 return(0);
558 }
559
560 /* Boot the IOS image */
561 static int c2691_boot_ios(c2691_t *router)
562 {
563 vm_instance_t *vm = router->vm;
564 cpu_mips_t *cpu;
565
566 if (!vm->boot_cpu)
567 return(-1);
568
569 /* Suspend CPU activity since we will restart directly from ROM */
570 vm_suspend(vm);
571
572 /* Check that CPU activity is really suspended */
573 if (cpu_group_sync_state(vm->cpu_group) == -1) {
574 vm_error(vm,"unable to sync with system CPUs.\n");
575 return(-1);
576 }
577
578 /* Reset the boot CPU */
579 cpu = CPU_MIPS64(vm->boot_cpu);
580 mips64_reset(cpu);
581
582 /* Load IOS image */
583 if (mips64_load_elf_image(cpu,vm->ios_image,
584 (vm->ghost_status == VM_GHOST_RAM_USE),
585 &vm->ios_entry_point) < 0)
586 {
587 vm_error(vm,"failed to load Cisco IOS image '%s'.\n",vm->ios_image);
588 return(-1);
589 }
590
591 /* Launch the simulation */
592 printf("\nC2691 '%s': starting simulation (CPU0 PC=0x%llx), "
593 "JIT %sabled.\n",
594 vm->name,cpu->pc,vm->jit_use ? "en":"dis");
595
596 vm_log(vm,"C2691_BOOT",
597 "starting instance (CPU0 PC=0x%llx,idle_pc=0x%llx,JIT %s)\n",
598 cpu->pc,cpu->idle_pc,vm->jit_use ? "on":"off");
599
600 /* Start main CPU */
601 if (vm->ghost_status != VM_GHOST_RAM_GENERATE) {
602 vm->status = VM_STATUS_RUNNING;
603 cpu_start(vm->boot_cpu);
604 } else {
605 vm->status = VM_STATUS_SHUTDOWN;
606 }
607 return(0);
608 }
609
610 /* Set an IRQ */
611 static void c2691_set_irq(vm_instance_t *vm,u_int irq)
612 {
613 c2691_t *router = VM_C2691(vm);
614 cpu_mips_t *cpu0 = CPU_MIPS64(vm->boot_cpu);
615 u_int slot,port;
616
617 switch(irq) {
618 case 0 ... 7:
619 mips64_set_irq(cpu0,irq);
620
621 if (cpu0->irq_idle_preempt[irq])
622 cpu_idle_break_wait(cpu0->gen);
623 break;
624
625 case C2691_NETIO_IRQ_BASE ... C2691_NETIO_IRQ_END:
626 c2691_net_irq_get_slot_port(irq,&slot,&port);
627 dev_c2691_iofpga_net_set_irq(router->iofpga_data,slot,port);
628 break;
629 }
630 }
631
632 /* Clear an IRQ */
633 static void c2691_clear_irq(vm_instance_t *vm,u_int irq)
634 {
635 c2691_t *router = VM_C2691(vm);
636 cpu_mips_t *cpu0 = CPU_MIPS64(vm->boot_cpu);
637 u_int slot,port;
638
639 switch(irq) {
640 case 0 ... 7:
641 mips64_clear_irq(cpu0,irq);
642 break;
643
644 case C2691_NETIO_IRQ_BASE ... C2691_NETIO_IRQ_END:
645 c2691_net_irq_get_slot_port(irq,&slot,&port);
646 dev_c2691_iofpga_net_clear_irq(router->iofpga_data,slot,port);
647 break;
648 }
649 }
650
651 /* Initialize a Cisco 2691 instance */
652 static int c2691_init_instance(vm_instance_t *vm)
653 {
654 c2691_t *router = VM_C2691(vm);
655 m_uint32_t rom_entry_point;
656 cpu_mips_t *cpu0;
657
658 if (!vm->ios_image) {
659 vm_error(vm,"no Cisco IOS image defined.");
660 return(-1);
661 }
662
663 /* Initialize the C2691 platform */
664 if (c2691_init_platform(router) == -1) {
665 vm_error(vm,"unable to initialize the platform hardware.\n");
666 return(-1);
667 }
668
669 /* IRQ routing */
670 vm->set_irq = c2691_set_irq;
671 vm->clear_irq = c2691_clear_irq;
672
673 /* Load IOS configuration file */
674 if (vm->ios_config != NULL) {
675 vm_nvram_push_config(vm,vm->ios_config);
676 vm->conf_reg &= ~0x40;
677 }
678
679 /* Load ROM (ELF image or embedded) */
680 cpu0 = CPU_MIPS64(vm->boot_cpu);
681 rom_entry_point = (m_uint32_t)MIPS_ROM_PC;
682
683 if ((vm->rom_filename != NULL) &&
684 (mips64_load_elf_image(cpu0,vm->rom_filename,0,&rom_entry_point) < 0))
685 {
686 vm_error(vm,"unable to load alternate ROM '%s', "
687 "fallback to embedded ROM.\n\n",vm->rom_filename);
688 vm->rom_filename = NULL;
689 }
690
691 /* Load symbol file */
692 if (vm->sym_filename) {
693 mips64_sym_load_file(cpu0,vm->sym_filename);
694 cpu0->sym_trace = 1;
695 }
696
697 return(c2691_boot_ios(router));
698 }
699
700 /* Stop a Cisco 2691 instance */
701 static int c2691_stop_instance(vm_instance_t *vm)
702 {
703 printf("\nC2691 '%s': stopping simulation.\n",vm->name);
704 vm_log(vm,"C2691_STOP","stopping simulation.\n");
705
706 /* Stop all CPUs */
707 if (vm->cpu_group != NULL) {
708 vm_stop(vm);
709
710 if (cpu_group_sync_state(vm->cpu_group) == -1) {
711 vm_error(vm,"unable to sync with system CPUs.\n");
712 return(-1);
713 }
714 }
715
716 /* Free resources that were used during execution to emulate hardware */
717 vm_slot_shutdown_all(vm);
718 vm_hardware_shutdown(vm);
719 return(0);
720 }
721
722 /* Get MAC address MSB */
723 static u_int c2691_get_mac_addr_msb(void)
724 {
725 return(0xC0);
726 }
727
728 /* Parse specific options for the Cisco 1700 platform */
729 static int c2691_cli_parse_options(vm_instance_t *vm,int option)
730 {
731 switch(option) {
732 /* IO memory reserved for NMs (in percents!) */
733 case OPT_IOMEM_SIZE:
734 vm->nm_iomem_size = 0x8000 | atoi(optarg);
735 break;
736
737 /* Unknown option */
738 default:
739 return(-1);
740 }
741
742 return(0);
743 }
744
745 /* Show specific CLI options */
746 static void c2691_cli_show_options(vm_instance_t *vm)
747 {
748 printf(" --iomem-size <val> : IO memory (in percents, default: %u)\n"
749 " -p <nm_desc> : Define a Network Module\n"
750 " -s <nm_nio> : Bind a Network IO interface to a "
751 "Network Module\n",
752 vm->nm_iomem_size);
753 }
754
755 /* Platform definition */
756 static vm_platform_t c2691_platform = {
757 "c2691", "C2691", "2691",
758 c2691_create_instance,
759 c2691_delete_instance,
760 c2691_init_instance,
761 c2691_stop_instance,
762 c2691_nvram_extract_config,
763 c2691_nvram_push_config,
764 c2691_get_mac_addr_msb,
765 NULL,
766 c2691_cli_parse_options,
767 c2691_cli_show_options,
768 NULL,
769 };
770
771 /* Register the c2691 platform */
772 int c2691_platform_register(void)
773 {
774 if (vm_platform_register(&c2691_platform) == -1)
775 return(-1);
776
777 return(hypervisor_c2691_init(&c2691_platform));
778 }

  ViewVC Help
Powered by ViewVC 1.1.26