Debian Codegraph @

common/dev_c2691.c

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