| 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 3725 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_c3725.h" |
| 26 |
#include "dev_c3725_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 3725 mainboard EEPROM */ |
| 36 |
static m_uint16_t eeprom_c3725_mainboard_data[] = { |
| 37 |
0x04FF, 0xC18B, 0x5858, 0x5858, 0x5858, 0x5858, 0x5858, 0x5809, |
| 38 |
0x6140, 0x0259, 0xC046, 0x0320, 0x003F, 0x1302, 0x4244, 0x3085, |
| 39 |
0x1C10, 0x8206, 0x80FF, 0xFFFF, 0xFFC4, 0x08FF, 0xFFFF, 0xFFFF, |
| 40 |
0xFFFF, 0xFF81, 0xFFFF, 0xFFFF, 0x03FF, 0x04FF, 0xC28B, 0x4654, |
| 41 |
0x5830, 0x3934, 0x3557, 0x304D, 0x59C3, 0x0600, 0x1319, 0x5C6F, |
| 42 |
0x7043, 0x0030, 0xC508, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x4100, |
| 43 |
0x0101, 0x02FF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 44 |
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 45 |
}; |
| 46 |
|
| 47 |
struct cisco_eeprom eeprom_c3725_mainboard = { |
| 48 |
"C3725 Backplane", |
| 49 |
eeprom_c3725_mainboard_data, |
| 50 |
sizeof(eeprom_c3725_mainboard_data)/2, |
| 51 |
}; |
| 52 |
|
| 53 |
/* ======================================================================== */ |
| 54 |
/* Network Module Drivers */ |
| 55 |
/* ======================================================================== */ |
| 56 |
static struct cisco_card_driver *nm_drivers[] = { |
| 57 |
&dev_c3725_nm_1fe_tx_driver, |
| 58 |
&dev_c3725_nm_16esw_driver, |
| 59 |
&dev_c3725_gt96100_fe_driver, |
| 60 |
&dev_c3725_nm_4t_driver, |
| 61 |
&dev_c3725_nm_nam_driver, |
| 62 |
&dev_c3725_nm_cids_driver, |
| 63 |
NULL, |
| 64 |
}; |
| 65 |
|
| 66 |
/* ======================================================================== */ |
| 67 |
/* Cisco 3725 router instances */ |
| 68 |
/* ======================================================================== */ |
| 69 |
|
| 70 |
/* Initialize default parameters for a C3725 */ |
| 71 |
static void c3725_init_defaults(c3725_t *router); |
| 72 |
|
| 73 |
/* Directly extract the configuration from the NVRAM device */ |
| 74 |
static int c3725_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", C3725_NVRAM_OFFSET, C3725_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 c3725_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, C3725_NVRAM_OFFSET, C3725_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 |
static int c3725_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 + C3725_NVRAM_OFFSET; |
| 104 |
len = C3725_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 c3725_create_instance(vm_instance_t *vm) |
| 122 |
{ |
| 123 |
c3725_t *router; |
| 124 |
|
| 125 |
if (!(router = malloc(sizeof(*router)))) { |
| 126 |
fprintf(stderr,"C3725 '%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 |
c3725_init_defaults(router); |
| 135 |
return(0); |
| 136 |
} |
| 137 |
|
| 138 |
/* Free resources used by a router instance */ |
| 139 |
static int c3725_delete_instance(vm_instance_t *vm) |
| 140 |
{ |
| 141 |
c3725_t *router = VM_C3725(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 c3725_get_onboard_wic_addr(u_int slot,m_uint64_t *phys_addr) |
| 174 |
{ |
| 175 |
if (slot >= C3725_MAX_WIC_BAYS) |
| 176 |
return(-1); |
| 177 |
|
| 178 |
*phys_addr = C3725_WIC_ADDR + (slot * C3725_WIC_SIZE); |
| 179 |
return(0); |
| 180 |
} |
| 181 |
|
| 182 |
/* Set EEPROM for the specified slot */ |
| 183 |
int c3725_set_slot_eeprom(c3725_t *router,u_int slot, |
| 184 |
struct cisco_eeprom *eeprom) |
| 185 |
{ |
| 186 |
if ((slot < 1) || (slot >= C3725_MAX_NM_BAYS)) |
| 187 |
return(-1); |
| 188 |
|
| 189 |
router->nm_eeprom_group[slot-1].eeprom[0] = eeprom; |
| 190 |
return(0); |
| 191 |
} |
| 192 |
|
| 193 |
/* Get slot/port corresponding to specified network IRQ */ |
| 194 |
static inline void |
| 195 |
c3725_net_irq_get_slot_port(u_int irq,u_int *slot,u_int *port) |
| 196 |
{ |
| 197 |
irq -= C3725_NETIO_IRQ_BASE; |
| 198 |
*port = irq & C3725_NETIO_IRQ_PORT_MASK; |
| 199 |
*slot = irq >> C3725_NETIO_IRQ_PORT_BITS; |
| 200 |
} |
| 201 |
|
| 202 |
/* Get network IRQ for specified slot/port */ |
| 203 |
u_int c3725_net_irq_for_slot_port(u_int slot,u_int port) |
| 204 |
{ |
| 205 |
u_int irq; |
| 206 |
|
| 207 |
irq = (slot << C3725_NETIO_IRQ_PORT_BITS) + port; |
| 208 |
irq += C3725_NETIO_IRQ_BASE; |
| 209 |
|
| 210 |
return(irq); |
| 211 |
} |
| 212 |
|
| 213 |
/* Get PCI device for the specified NM bay */ |
| 214 |
int c3725_nm_get_pci_device(u_int nm_bay) |
| 215 |
{ |
| 216 |
switch(nm_bay) { |
| 217 |
case 1: |
| 218 |
return(0x06); |
| 219 |
case 2: |
| 220 |
return(0x0A); |
| 221 |
default: |
| 222 |
return(-1); |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
/* Set the system id or processor board id in the eeprom */ |
| 227 |
int c3725_set_system_id(c3725_t *router,char *id) |
| 228 |
{ |
| 229 |
/* 11 characters is enough. Array is 20 long */ |
| 230 |
strncpy(router->board_id,id,13); |
| 231 |
/* Make sure it is null terminated */ |
| 232 |
router->board_id[13] = 0x00; |
| 233 |
c3725_refresh_systemid(router); |
| 234 |
return 0; |
| 235 |
} |
| 236 |
|
| 237 |
int c3725_refresh_systemid(c3725_t *router) |
| 238 |
{ |
| 239 |
if (router->board_id[0] == 0x00) return(0); |
| 240 |
m_uint8_t buf[11]; |
| 241 |
|
| 242 |
parse_board_id(buf,router->board_id,11); |
| 243 |
cisco_eeprom_set_region(&router->mb_eeprom ,62,buf,11); |
| 244 |
return (0); |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
/* Set the base MAC address of the chassis */ |
| 249 |
static int c3725_burn_mac_addr(c3725_t *router,n_eth_addr_t *addr) |
| 250 |
{ |
| 251 |
m_uint8_t eeprom_ver; |
| 252 |
size_t offset; |
| 253 |
|
| 254 |
/* Read EEPROM format version */ |
| 255 |
cisco_eeprom_get_byte(&router->mb_eeprom,0,&eeprom_ver); |
| 256 |
|
| 257 |
switch(eeprom_ver) { |
| 258 |
case 0: |
| 259 |
cisco_eeprom_set_region(&router->mb_eeprom,2,addr->eth_addr_byte,6); |
| 260 |
break; |
| 261 |
|
| 262 |
case 4: |
| 263 |
if (!cisco_eeprom_v4_find_field(&router->mb_eeprom,0xC3,&offset)) { |
| 264 |
cisco_eeprom_set_region(&router->mb_eeprom,offset, |
| 265 |
addr->eth_addr_byte,6); |
| 266 |
} |
| 267 |
break; |
| 268 |
|
| 269 |
default: |
| 270 |
vm_error(router->vm,"c3725_burn_mac_addr: unable to handle " |
| 271 |
"EEPROM version %u\n",eeprom_ver); |
| 272 |
return(-1); |
| 273 |
} |
| 274 |
|
| 275 |
return(0); |
| 276 |
} |
| 277 |
|
| 278 |
/* Set chassis MAC address */ |
| 279 |
int c3725_chassis_set_mac_addr(c3725_t *router,char *mac_addr) |
| 280 |
{ |
| 281 |
if (parse_mac_addr(&router->mac_addr,mac_addr) == -1) { |
| 282 |
vm_error(router->vm,"unable to parse MAC address '%s'.\n",mac_addr); |
| 283 |
return(-1); |
| 284 |
} |
| 285 |
|
| 286 |
/* Set the chassis base MAC address */ |
| 287 |
c3725_burn_mac_addr(router,&router->mac_addr); |
| 288 |
return(0); |
| 289 |
} |
| 290 |
|
| 291 |
/* Create the two main PCI busses for a GT64120 based system */ |
| 292 |
static int c3725_init_gt96100(c3725_t *router) |
| 293 |
{ |
| 294 |
vm_instance_t *vm = router->vm; |
| 295 |
vm_obj_t *obj; |
| 296 |
|
| 297 |
vm->pci_bus[0] = pci_bus_create("PCI bus #0",0); |
| 298 |
vm->pci_bus[1] = pci_bus_create("PCI bus #1",0); |
| 299 |
|
| 300 |
if (!vm->pci_bus[0] || !vm->pci_bus[1]) { |
| 301 |
vm_error(router->vm,"unable to create PCI data.\n"); |
| 302 |
return(-1); |
| 303 |
} |
| 304 |
|
| 305 |
if (dev_gt96100_init(vm,"gt96100",C3725_GT96K_ADDR,0x200000, |
| 306 |
C3725_GT96K_IRQ, |
| 307 |
C3725_EXT_IRQ, |
| 308 |
c3725_net_irq_for_slot_port(0,0), |
| 309 |
255) == -1) |
| 310 |
return(-1); |
| 311 |
|
| 312 |
if (!(obj = vm_object_find(router->vm,"gt96100"))) |
| 313 |
return(-1); |
| 314 |
|
| 315 |
router->gt_data = obj->data; |
| 316 |
return(0); |
| 317 |
} |
| 318 |
|
| 319 |
/* Initialize a Cisco 3725 */ |
| 320 |
static int c3725_init(c3725_t *router) |
| 321 |
{ |
| 322 |
vm_instance_t *vm = router->vm; |
| 323 |
|
| 324 |
/* Set the processor type: R7000 */ |
| 325 |
mips64_set_prid(CPU_MIPS64(vm->boot_cpu),MIPS_PRID_R7000); |
| 326 |
|
| 327 |
/* Initialize the Galileo GT-96100 PCI controller */ |
| 328 |
if (c3725_init_gt96100(router) == -1) |
| 329 |
return(-1); |
| 330 |
|
| 331 |
/* Initialize PCI map (NM slots 1 & 2) */ |
| 332 |
vm->slots_pci_bus[1] = vm->pci_bus[1]; |
| 333 |
vm->slots_pci_bus[2] = vm->pci_bus[1]; |
| 334 |
|
| 335 |
vm->elf_machine_id = C3725_ELF_MACHINE_ID; |
| 336 |
return(0); |
| 337 |
} |
| 338 |
|
| 339 |
/* Show C3725 hardware info */ |
| 340 |
void c3725_show_hardware(c3725_t *router) |
| 341 |
{ |
| 342 |
vm_instance_t *vm = router->vm; |
| 343 |
|
| 344 |
printf("C3725 instance '%s' (id %d):\n",vm->name,vm->instance_id); |
| 345 |
|
| 346 |
printf(" VM Status : %d\n",vm->status); |
| 347 |
printf(" RAM size : %u Mb\n",vm->ram_size); |
| 348 |
printf(" NVRAM size : %u Kb\n",vm->nvram_size); |
| 349 |
printf(" IOS image : %s\n\n",vm->ios_image); |
| 350 |
|
| 351 |
if (vm->debug_level > 0) { |
| 352 |
dev_show_list(vm); |
| 353 |
pci_dev_show_list(vm->pci_bus[0]); |
| 354 |
pci_dev_show_list(vm->pci_bus[1]); |
| 355 |
printf("\n"); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
/* Initialize default parameters for a C3725 */ |
| 360 |
static void c3725_init_defaults(c3725_t *router) |
| 361 |
{ |
| 362 |
vm_instance_t *vm = router->vm; |
| 363 |
n_eth_addr_t *m; |
| 364 |
m_uint16_t pid; |
| 365 |
|
| 366 |
/* Set platform slots characteristics */ |
| 367 |
vm->nr_slots = C3725_MAX_NM_BAYS; |
| 368 |
vm->slots_type = CISCO_CARD_TYPE_NM; |
| 369 |
vm->slots_drivers = nm_drivers; |
| 370 |
|
| 371 |
pid = (m_uint16_t)getpid(); |
| 372 |
|
| 373 |
/* Generate a chassis MAC address based on the instance ID */ |
| 374 |
m = &router->mac_addr; |
| 375 |
m->eth_addr_byte[0] = vm_get_mac_addr_msb(vm); |
| 376 |
m->eth_addr_byte[1] = vm->instance_id & 0xFF; |
| 377 |
m->eth_addr_byte[2] = pid >> 8; |
| 378 |
m->eth_addr_byte[3] = pid & 0xFF; |
| 379 |
m->eth_addr_byte[4] = 0x00; |
| 380 |
m->eth_addr_byte[5] = 0x00; |
| 381 |
|
| 382 |
router->board_id[0] = 0x00; |
| 383 |
|
| 384 |
c3725_init_eeprom_groups(router); |
| 385 |
cisco_eeprom_copy(&router->mb_eeprom,&eeprom_c3725_mainboard); |
| 386 |
c3725_burn_mac_addr(router,&router->mac_addr); |
| 387 |
|
| 388 |
/* The GT96100 system controller has 2 integrated FastEthernet ports */ |
| 389 |
vm_slot_add_binding(vm,"GT96100-FE",0,0); |
| 390 |
|
| 391 |
vm->ram_mmap = C3725_DEFAULT_RAM_MMAP; |
| 392 |
vm->ram_size = C3725_DEFAULT_RAM_SIZE; |
| 393 |
vm->rom_size = C3725_DEFAULT_ROM_SIZE; |
| 394 |
vm->nvram_size = C3725_DEFAULT_NVRAM_SIZE; |
| 395 |
vm->conf_reg_setup = C3725_DEFAULT_CONF_REG; |
| 396 |
vm->clock_divisor = C3725_DEFAULT_CLOCK_DIV; |
| 397 |
vm->nvram_rom_space = C3725_NVRAM_ROM_RES_SIZE; |
| 398 |
vm->nm_iomem_size = C3725_DEFAULT_IOMEM_SIZE; |
| 399 |
|
| 400 |
vm->pcmcia_disk_size[0] = C3725_DEFAULT_DISK0_SIZE; |
| 401 |
vm->pcmcia_disk_size[1] = C3725_DEFAULT_DISK1_SIZE; |
| 402 |
} |
| 403 |
|
| 404 |
/* Initialize the C3725 Platform */ |
| 405 |
static int c3725_init_platform(c3725_t *router) |
| 406 |
{ |
| 407 |
vm_instance_t *vm = router->vm; |
| 408 |
cpu_mips_t *cpu; |
| 409 |
cpu_gen_t *gen; |
| 410 |
vm_obj_t *obj; |
| 411 |
|
| 412 |
/* Copy config register setup into "active" config register */ |
| 413 |
vm->conf_reg = vm->conf_reg_setup; |
| 414 |
|
| 415 |
/* Create Console and AUX ports */ |
| 416 |
vm_init_vtty(vm); |
| 417 |
|
| 418 |
/* Create a CPU group */ |
| 419 |
vm->cpu_group = cpu_group_create("System CPU"); |
| 420 |
|
| 421 |
/* Initialize the virtual MIPS processor */ |
| 422 |
if (!(gen = cpu_create(vm,CPU_TYPE_MIPS64,0))) { |
| 423 |
vm_error(vm,"unable to create CPU!\n"); |
| 424 |
return(-1); |
| 425 |
} |
| 426 |
|
| 427 |
cpu = CPU_MIPS64(gen); |
| 428 |
|
| 429 |
/* Add this CPU to the system CPU group */ |
| 430 |
cpu_group_add(vm->cpu_group,gen); |
| 431 |
vm->boot_cpu = gen; |
| 432 |
|
| 433 |
/* Initialize the IRQ routing vectors */ |
| 434 |
vm->set_irq = mips64_vm_set_irq; |
| 435 |
vm->clear_irq = mips64_vm_clear_irq; |
| 436 |
|
| 437 |
/* Mark the Network IO interrupt as high priority */ |
| 438 |
cpu->irq_idle_preempt[C3725_NETIO_IRQ] = TRUE; |
| 439 |
cpu->irq_idle_preempt[C3725_GT96K_IRQ] = TRUE; |
| 440 |
cpu->irq_idle_preempt[C3725_DUART_IRQ] = TRUE; |
| 441 |
|
| 442 |
/* Copy some parameters from VM to CPU (idle PC, ...) */ |
| 443 |
cpu->idle_pc = vm->idle_pc; |
| 444 |
|
| 445 |
if (vm->timer_irq_check_itv) |
| 446 |
cpu->timer_irq_check_itv = vm->timer_irq_check_itv; |
| 447 |
|
| 448 |
/* Remote emulator control */ |
| 449 |
dev_remote_control_init(vm,0x16000000,0x1000); |
| 450 |
|
| 451 |
/* Specific Storage Area (SSA) */ |
| 452 |
dev_ram_init(vm,"ssa",TRUE,FALSE,NULL,FALSE,0x16001000ULL,0x7000); |
| 453 |
|
| 454 |
/* IO FPGA */ |
| 455 |
if (dev_c3725_iofpga_init(router,C3725_IOFPGA_ADDR,0x40000) == -1) |
| 456 |
return(-1); |
| 457 |
|
| 458 |
if (!(obj = vm_object_find(router->vm,"io_fpga"))) |
| 459 |
return(-1); |
| 460 |
|
| 461 |
router->iofpga_data = obj->data; |
| 462 |
|
| 463 |
#if 0 |
| 464 |
/* PCI IO space */ |
| 465 |
if (!(vm->pci_io_space = pci_io_data_init(vm,C3725_PCI_IO_ADDR))) |
| 466 |
return(-1); |
| 467 |
#endif |
| 468 |
|
| 469 |
/* Initialize the chassis */ |
| 470 |
if (c3725_init(router) == -1) |
| 471 |
return(-1); |
| 472 |
|
| 473 |
/* Initialize RAM */ |
| 474 |
vm_ram_init(vm,0x00000000ULL); |
| 475 |
|
| 476 |
/* Initialize ROM (as a Flash) */ |
| 477 |
if (!(obj = dev_flash_init(vm,"rom",C3725_ROM_ADDR,vm->rom_size*1048576))) |
| 478 |
return(-1); |
| 479 |
|
| 480 |
dev_flash_copy_data(obj,0,mips64_microcode,mips64_microcode_len); |
| 481 |
c3725_nvram_check_empty_config(vm); |
| 482 |
|
| 483 |
/* Byte swapping */ |
| 484 |
dev_bswap_init(vm,"mem_bswap",C3725_BSWAP_ADDR,1024*1048576,0x00000000ULL); |
| 485 |
|
| 486 |
/* Initialize the NS16552 DUART */ |
| 487 |
dev_ns16552_init(vm,C3725_DUART_ADDR,0x1000,3,C3725_DUART_IRQ, |
| 488 |
vm->vtty_con,vm->vtty_aux); |
| 489 |
|
| 490 |
/* PCMCIA Slot 0 */ |
| 491 |
dev_pcmcia_disk_init(vm,"slot0",C3725_SLOT0_ADDR,0x200000, |
| 492 |
vm->pcmcia_disk_size[0],1); |
| 493 |
|
| 494 |
/* PCMCIA Slot 1 */ |
| 495 |
dev_pcmcia_disk_init(vm,"slot1",C3725_SLOT1_ADDR,0x200000, |
| 496 |
vm->pcmcia_disk_size[1],1); |
| 497 |
|
| 498 |
/* Initialize Network Modules */ |
| 499 |
if (vm_slot_init_all(vm) == -1) |
| 500 |
return(-1); |
| 501 |
|
| 502 |
/* Show device list */ |
| 503 |
c3725_show_hardware(router); |
| 504 |
return(0); |
| 505 |
} |
| 506 |
|
| 507 |
/* Boot the IOS image */ |
| 508 |
static int c3725_boot_ios(c3725_t *router) |
| 509 |
{ |
| 510 |
vm_instance_t *vm = router->vm; |
| 511 |
cpu_mips_t *cpu; |
| 512 |
|
| 513 |
if (!vm->boot_cpu) |
| 514 |
return(-1); |
| 515 |
|
| 516 |
/* Suspend CPU activity since we will restart directly from ROM */ |
| 517 |
vm_suspend(vm); |
| 518 |
|
| 519 |
/* Check that CPU activity is really suspended */ |
| 520 |
if (cpu_group_sync_state(vm->cpu_group) == -1) { |
| 521 |
vm_error(vm,"unable to sync with system CPUs.\n"); |
| 522 |
return(-1); |
| 523 |
} |
| 524 |
|
| 525 |
/* Reset the boot CPU */ |
| 526 |
cpu = CPU_MIPS64(vm->boot_cpu); |
| 527 |
mips64_reset(cpu); |
| 528 |
|
| 529 |
/* Load IOS image */ |
| 530 |
if (mips64_load_elf_image(cpu,vm->ios_image, |
| 531 |
(vm->ghost_status == VM_GHOST_RAM_USE), |
| 532 |
&vm->ios_entry_point) < 0) |
| 533 |
{ |
| 534 |
vm_error(vm,"failed to load Cisco IOS image '%s'.\n",vm->ios_image); |
| 535 |
return(-1); |
| 536 |
} |
| 537 |
|
| 538 |
/* Launch the simulation */ |
| 539 |
printf("\nC3725 '%s': starting simulation (CPU0 PC=0x%llx), " |
| 540 |
"JIT %sabled.\n", |
| 541 |
vm->name,cpu->pc,vm->jit_use ? "en":"dis"); |
| 542 |
|
| 543 |
vm_log(vm,"C3725_BOOT", |
| 544 |
"starting instance (CPU0 PC=0x%llx,idle_pc=0x%llx,JIT %s)\n", |
| 545 |
cpu->pc,cpu->idle_pc,vm->jit_use ? "on":"off"); |
| 546 |
|
| 547 |
/* Start main CPU */ |
| 548 |
if (vm->ghost_status != VM_GHOST_RAM_GENERATE) { |
| 549 |
vm->status = VM_STATUS_RUNNING; |
| 550 |
cpu_start(vm->boot_cpu); |
| 551 |
} else { |
| 552 |
vm->status = VM_STATUS_SHUTDOWN; |
| 553 |
} |
| 554 |
return(0); |
| 555 |
} |
| 556 |
|
| 557 |
/* Set an IRQ */ |
| 558 |
static void c3725_set_irq(vm_instance_t *vm,u_int irq) |
| 559 |
{ |
| 560 |
c3725_t *router = VM_C3725(vm); |
| 561 |
cpu_mips_t *cpu0 = CPU_MIPS64(vm->boot_cpu); |
| 562 |
u_int slot,port; |
| 563 |
|
| 564 |
switch(irq) { |
| 565 |
case 0 ... 7: |
| 566 |
mips64_set_irq(cpu0,irq); |
| 567 |
|
| 568 |
if (cpu0->irq_idle_preempt[irq]) |
| 569 |
cpu_idle_break_wait(cpu0->gen); |
| 570 |
break; |
| 571 |
|
| 572 |
case C3725_NETIO_IRQ_BASE ... C3725_NETIO_IRQ_END: |
| 573 |
c3725_net_irq_get_slot_port(irq,&slot,&port); |
| 574 |
dev_c3725_iofpga_net_set_irq(router->iofpga_data,slot,port); |
| 575 |
break; |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
/* Clear an IRQ */ |
| 580 |
static void c3725_clear_irq(vm_instance_t *vm,u_int irq) |
| 581 |
{ |
| 582 |
c3725_t *router = VM_C3725(vm); |
| 583 |
cpu_mips_t *cpu0 = CPU_MIPS64(vm->boot_cpu); |
| 584 |
u_int slot,port; |
| 585 |
|
| 586 |
switch(irq) { |
| 587 |
case 0 ... 7: |
| 588 |
mips64_clear_irq(cpu0,irq); |
| 589 |
break; |
| 590 |
|
| 591 |
case C3725_NETIO_IRQ_BASE ... C3725_NETIO_IRQ_END: |
| 592 |
c3725_net_irq_get_slot_port(irq,&slot,&port); |
| 593 |
dev_c3725_iofpga_net_clear_irq(router->iofpga_data,slot,port); |
| 594 |
break; |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
/* Initialize a Cisco 3725 instance */ |
| 599 |
static int c3725_init_instance(vm_instance_t *vm) |
| 600 |
{ |
| 601 |
c3725_t *router = VM_C3725(vm); |
| 602 |
m_uint32_t rom_entry_point; |
| 603 |
cpu_mips_t *cpu0; |
| 604 |
|
| 605 |
if (!vm->ios_image) { |
| 606 |
vm_error(vm,"no Cisco IOS image defined."); |
| 607 |
return(-1); |
| 608 |
} |
| 609 |
|
| 610 |
/* Initialize the C3725 platform */ |
| 611 |
if (c3725_init_platform(router) == -1) { |
| 612 |
vm_error(vm,"unable to initialize the platform hardware.\n"); |
| 613 |
return(-1); |
| 614 |
} |
| 615 |
|
| 616 |
/* IRQ routing */ |
| 617 |
vm->set_irq = c3725_set_irq; |
| 618 |
vm->clear_irq = c3725_clear_irq; |
| 619 |
|
| 620 |
/* Load IOS configuration files */ |
| 621 |
if (vm->ios_startup_config != NULL || vm->ios_private_config != NULL) { |
| 622 |
vm_nvram_push_config(vm,vm->ios_startup_config,vm->ios_private_config); |
| 623 |
vm->conf_reg &= ~0x40; |
| 624 |
} |
| 625 |
|
| 626 |
/* Load ROM (ELF image or embedded) */ |
| 627 |
cpu0 = CPU_MIPS64(vm->boot_cpu); |
| 628 |
rom_entry_point = (m_uint32_t)MIPS_ROM_PC; |
| 629 |
|
| 630 |
if ((vm->rom_filename != NULL) && |
| 631 |
(mips64_load_elf_image(cpu0,vm->rom_filename,0,&rom_entry_point) < 0)) |
| 632 |
{ |
| 633 |
vm_error(vm,"unable to load alternate ROM '%s', " |
| 634 |
"fallback to embedded ROM.\n\n",vm->rom_filename); |
| 635 |
vm->rom_filename = NULL; |
| 636 |
} |
| 637 |
|
| 638 |
/* Load symbol file */ |
| 639 |
if (vm->sym_filename) { |
| 640 |
mips64_sym_load_file(cpu0,vm->sym_filename); |
| 641 |
cpu0->sym_trace = 1; |
| 642 |
} |
| 643 |
|
| 644 |
return(c3725_boot_ios(router)); |
| 645 |
} |
| 646 |
|
| 647 |
/* Stop a Cisco 3725 instance */ |
| 648 |
static int c3725_stop_instance(vm_instance_t *vm) |
| 649 |
{ |
| 650 |
printf("\nC3725 '%s': stopping simulation.\n",vm->name); |
| 651 |
vm_log(vm,"C3725_STOP","stopping simulation.\n"); |
| 652 |
|
| 653 |
/* Stop all CPUs */ |
| 654 |
if (vm->cpu_group != NULL) { |
| 655 |
vm_stop(vm); |
| 656 |
|
| 657 |
if (cpu_group_sync_state(vm->cpu_group) == -1) { |
| 658 |
vm_error(vm,"unable to sync with system CPUs.\n"); |
| 659 |
return(-1); |
| 660 |
} |
| 661 |
} |
| 662 |
|
| 663 |
/* Free resources that were used during execution to emulate hardware */ |
| 664 |
vm_slot_shutdown_all(vm); |
| 665 |
vm_hardware_shutdown(vm); |
| 666 |
|
| 667 |
/* Cleanup */ |
| 668 |
VM_C3725(vm)->iofpga_data = NULL; |
| 669 |
VM_C3725(vm)->gt_data = NULL; |
| 670 |
return(0); |
| 671 |
} |
| 672 |
|
| 673 |
/* Get MAC address MSB */ |
| 674 |
static u_int c3725_get_mac_addr_msb(void) |
| 675 |
{ |
| 676 |
return(0xC2); |
| 677 |
} |
| 678 |
|
| 679 |
/* Parse specific options for the Cisco 3725 platform */ |
| 680 |
static int c3725_cli_parse_options(vm_instance_t *vm,int option) |
| 681 |
{ |
| 682 |
c3725_t *router = VM_C3725(vm); |
| 683 |
|
| 684 |
switch(option) { |
| 685 |
/* IO memory reserved for NMs (in percents!) */ |
| 686 |
case OPT_IOMEM_SIZE: |
| 687 |
vm->nm_iomem_size = 0x8000 | atoi(optarg); |
| 688 |
break; |
| 689 |
|
| 690 |
/* Set the base MAC address */ |
| 691 |
case 'm': |
| 692 |
if (!c3725_chassis_set_mac_addr(router,optarg)) |
| 693 |
printf("MAC address set to '%s'.\n",optarg); |
| 694 |
break; |
| 695 |
|
| 696 |
/* Set the System ID */ |
| 697 |
case 'I': |
| 698 |
if (!c3725_set_system_id(router,optarg)) |
| 699 |
printf("System ID set to '%s'.\n",optarg); |
| 700 |
break; |
| 701 |
|
| 702 |
/* Unknown option */ |
| 703 |
default: |
| 704 |
return(-1); |
| 705 |
} |
| 706 |
|
| 707 |
return(0); |
| 708 |
} |
| 709 |
|
| 710 |
/* Show specific CLI options */ |
| 711 |
static void c3725_cli_show_options(vm_instance_t *vm) |
| 712 |
{ |
| 713 |
printf(" --iomem-size <val> : IO memory (in percents, default: %u)\n" |
| 714 |
" -p <nm_desc> : Define a Network Module\n" |
| 715 |
" -I <serialno> : Set Processor Board Serial Number\n" |
| 716 |
" -s <nm_nio> : Bind a Network IO interface to a " |
| 717 |
"Network Module\n", |
| 718 |
vm->nm_iomem_size); |
| 719 |
} |
| 720 |
|
| 721 |
/* Platform definition */ |
| 722 |
static vm_platform_t c3725_platform = { |
| 723 |
"c3725", "C3725", "3725", |
| 724 |
c3725_create_instance, |
| 725 |
c3725_delete_instance, |
| 726 |
c3725_init_instance, |
| 727 |
c3725_stop_instance, |
| 728 |
NULL, |
| 729 |
NULL, |
| 730 |
c3725_nvram_extract_config, |
| 731 |
c3725_nvram_push_config, |
| 732 |
c3725_get_mac_addr_msb, |
| 733 |
NULL, |
| 734 |
c3725_cli_parse_options, |
| 735 |
c3725_cli_show_options, |
| 736 |
NULL, |
| 737 |
}; |
| 738 |
|
| 739 |
/* Register the c3725 platform */ |
| 740 |
int c3725_platform_register(void) |
| 741 |
{ |
| 742 |
if (vm_platform_register(&c3725_platform) == -1) |
| 743 |
return(-1); |
| 744 |
|
| 745 |
return(hypervisor_c3725_init(&c3725_platform)); |
| 746 |
} |