12 |
#include <sys/types.h> |
#include <sys/types.h> |
13 |
#include <assert.h> |
#include <assert.h> |
14 |
|
|
15 |
#include "mips64.h" |
#include "cpu.h" |
16 |
|
#include "vm.h" |
17 |
#include "dynamips.h" |
#include "dynamips.h" |
18 |
#include "memory.h" |
#include "memory.h" |
19 |
#include "device.h" |
#include "device.h" |
20 |
#include "pci_io.h" |
#include "pci_io.h" |
21 |
#include "dev_gt.h" |
#include "dev_gt.h" |
22 |
#include "cisco_eeprom.h" |
#include "cisco_eeprom.h" |
23 |
|
#include "dev_rom.h" |
24 |
#include "dev_c3745.h" |
#include "dev_c3745.h" |
25 |
|
#include "dev_c3745_iofpga.h" |
26 |
#include "dev_vtty.h" |
#include "dev_vtty.h" |
27 |
#include "registry.h" |
#include "registry.h" |
28 |
|
|
369 |
registry_foreach_type(OBJ_TYPE_VM,c3745_reg_save_config,fd,NULL); |
registry_foreach_type(OBJ_TYPE_VM,c3745_reg_save_config,fd,NULL); |
370 |
} |
} |
371 |
|
|
372 |
|
/* Get slot/port corresponding to specified network IRQ */ |
373 |
|
static inline void |
374 |
|
c3745_net_irq_get_slot_port(u_int irq,u_int *slot,u_int *port) |
375 |
|
{ |
376 |
|
irq -= C3745_NETIO_IRQ_BASE; |
377 |
|
*port = irq & C3745_NETIO_IRQ_PORT_MASK; |
378 |
|
*slot = irq >> C3745_NETIO_IRQ_PORT_BITS; |
379 |
|
} |
380 |
|
|
381 |
|
/* Get network IRQ for specified slot/port */ |
382 |
|
u_int c3745_net_irq_for_slot_port(u_int slot,u_int port) |
383 |
|
{ |
384 |
|
u_int irq; |
385 |
|
|
386 |
|
irq = (slot << C3745_NETIO_IRQ_PORT_BITS) + port; |
387 |
|
irq += C3745_NETIO_IRQ_BASE; |
388 |
|
|
389 |
|
return(irq); |
390 |
|
} |
391 |
|
|
392 |
/* Set NM EEPROM definition */ |
/* Set NM EEPROM definition */ |
393 |
int c3745_nm_set_eeprom(c3745_t *router,u_int nm_bay, |
int c3745_nm_set_eeprom(c3745_t *router,u_int nm_bay, |
394 |
const struct cisco_eeprom *eeprom) |
const struct cisco_eeprom *eeprom) |
745 |
snprintf(bay->dev_name,len,"%s(%u)",bay->dev_type,nm_bay); |
snprintf(bay->dev_name,len,"%s(%u)",bay->dev_type,nm_bay); |
746 |
|
|
747 |
/* Initialize NM driver */ |
/* Initialize NM driver */ |
748 |
if (bay->nm_driver->nm_init(router,bay->dev_name,nm_bay) == 1) { |
if (bay->nm_driver->nm_init(router,bay->dev_name,nm_bay) == -1) { |
749 |
vm_error(router->vm,"unable to initialize NM %u.\n",nm_bay); |
vm_error(router->vm,"unable to initialize NM %u.\n",nm_bay); |
750 |
return(-1); |
return(-1); |
751 |
} |
} |
1070 |
} |
} |
1071 |
|
|
1072 |
return(dev_gt96100_init(vm,"gt96100",C3745_GT96K_ADDR,0x200000, |
return(dev_gt96100_init(vm,"gt96100",C3745_GT96K_ADDR,0x200000, |
1073 |
C3745_GT96K_IRQ,C3745_NETIO_IRQ)); |
C3745_GT96K_IRQ,c3745_net_irq_for_slot_port(0,0))); |
1074 |
} |
} |
1075 |
|
|
1076 |
/* Initialize a Cisco 3745 */ |
/* Initialize a Cisco 3745 */ |
1081 |
int i; |
int i; |
1082 |
|
|
1083 |
/* Set the processor type: R7000 */ |
/* Set the processor type: R7000 */ |
1084 |
mips64_set_prid(vm->boot_cpu,MIPS_PRID_R7000); |
mips64_set_prid(CPU_MIPS64(vm->boot_cpu),MIPS_PRID_R7000); |
1085 |
|
|
1086 |
/* Initialize the Galileo GT-96100 PCI controller */ |
/* Initialize the Galileo GT-96100 PCI controller */ |
1087 |
if (c3745_init_gt96100(router) == -1) |
if (c3745_init_gt96100(router) == -1) |
1168 |
/* Initialize the C3745 Platform */ |
/* Initialize the C3745 Platform */ |
1169 |
int c3745_init_platform(c3745_t *router) |
int c3745_init_platform(c3745_t *router) |
1170 |
{ |
{ |
|
extern m_uint8_t microcode[]; |
|
|
extern ssize_t microcode_len; |
|
1171 |
vm_instance_t *vm = router->vm; |
vm_instance_t *vm = router->vm; |
1172 |
struct c3745_nm_bay *nm_bay; |
struct c3745_nm_bay *nm_bay; |
1173 |
cpu_mips_t *cpu; |
cpu_mips_t *cpu; |
1174 |
|
cpu_gen_t *gen; |
1175 |
vm_obj_t *obj; |
vm_obj_t *obj; |
1176 |
int i; |
int i; |
1177 |
|
|
1185 |
vm->cpu_group = cpu_group_create("System CPU"); |
vm->cpu_group = cpu_group_create("System CPU"); |
1186 |
|
|
1187 |
/* Initialize the virtual MIPS processor */ |
/* Initialize the virtual MIPS processor */ |
1188 |
if (!(cpu = cpu_create(vm,0))) { |
if (!(gen = cpu_create(vm,CPU_TYPE_MIPS64,0))) { |
1189 |
vm_error(vm,"unable to create CPU!\n"); |
vm_error(vm,"unable to create CPU!\n"); |
1190 |
return(-1); |
return(-1); |
1191 |
} |
} |
1192 |
|
|
1193 |
|
cpu = CPU_MIPS64(gen); |
1194 |
|
|
1195 |
/* Add this CPU to the system CPU group */ |
/* Add this CPU to the system CPU group */ |
1196 |
cpu_group_add(vm->cpu_group,cpu); |
cpu_group_add(vm->cpu_group,gen); |
1197 |
vm->boot_cpu = cpu; |
vm->boot_cpu = gen; |
1198 |
|
|
1199 |
|
/* Initialize the IRQ routing vectors */ |
1200 |
|
vm->set_irq = mips64_vm_set_irq; |
1201 |
|
vm->clear_irq = mips64_vm_clear_irq; |
1202 |
|
|
1203 |
/* Mark the Network IO interrupt as high priority */ |
/* Mark the Network IO interrupt as high priority */ |
1204 |
cpu->irq_idle_preempt[C3745_NETIO_IRQ] = TRUE; |
cpu->irq_idle_preempt[C3745_NETIO_IRQ] = TRUE; |
1215 |
dev_remote_control_init(vm,0x16000000,0x1000); |
dev_remote_control_init(vm,0x16000000,0x1000); |
1216 |
|
|
1217 |
/* Specific Storage Area (SSA) */ |
/* Specific Storage Area (SSA) */ |
1218 |
dev_ram_init(vm,"ssa",TRUE,FALSE,NULL,0x16001000ULL,0x7000); |
dev_ram_init(vm,"ssa",TRUE,FALSE,NULL,FALSE,0x16001000ULL,0x7000); |
1219 |
|
|
1220 |
/* IO FPGA */ |
/* IO FPGA */ |
1221 |
if (dev_c3745_iofpga_init(router,C3745_IOFPGA_ADDR,0x200000) == -1) |
if (dev_c3745_iofpga_init(router,C3745_IOFPGA_ADDR,0x200000) == -1) |
1222 |
return(-1); |
return(-1); |
1223 |
|
|
1224 |
|
if (!(obj = vm_object_find(router->vm,"io_fpga"))) |
1225 |
|
return(-1); |
1226 |
|
|
1227 |
|
router->iofpga_data = obj->data; |
1228 |
|
|
1229 |
#if 0 |
#if 0 |
1230 |
/* PCI IO space */ |
/* PCI IO space */ |
1231 |
if (!(vm->pci_io_space = pci_io_data_init(vm,C3745_PCI_IO_ADDR))) |
if (!(vm->pci_io_space = pci_io_data_init(vm,C3745_PCI_IO_ADDR))) |
1243 |
if (!(obj = dev_flash_init(vm,"rom",C3745_ROM_ADDR,vm->rom_size*1048576))) |
if (!(obj = dev_flash_init(vm,"rom",C3745_ROM_ADDR,vm->rom_size*1048576))) |
1244 |
return(-1); |
return(-1); |
1245 |
|
|
1246 |
dev_flash_copy_data(obj,0,microcode,microcode_len); |
dev_flash_copy_data(obj,0,mips64_microcode,mips64_microcode_len); |
1247 |
c3745_nvram_check_empty_config(vm); |
c3745_nvram_check_empty_config(vm); |
1248 |
|
|
1249 |
/* Initialize the NS16552 DUART */ |
/* Initialize the NS16552 DUART */ |
1284 |
int c3745_boot_ios(c3745_t *router) |
int c3745_boot_ios(c3745_t *router) |
1285 |
{ |
{ |
1286 |
vm_instance_t *vm = router->vm; |
vm_instance_t *vm = router->vm; |
1287 |
|
cpu_mips_t *cpu; |
1288 |
|
|
1289 |
if (!vm->boot_cpu) |
if (!vm->boot_cpu) |
1290 |
return(-1); |
return(-1); |
1299 |
} |
} |
1300 |
|
|
1301 |
/* Reset the boot CPU */ |
/* Reset the boot CPU */ |
1302 |
mips64_reset(vm->boot_cpu); |
cpu = CPU_MIPS64(vm->boot_cpu); |
1303 |
|
mips64_reset(cpu); |
1304 |
|
|
1305 |
/* Load IOS image */ |
/* Load IOS image */ |
1306 |
if (mips64_load_elf_image(vm->boot_cpu,vm->ios_image, |
if (mips64_load_elf_image(cpu,vm->ios_image, |
1307 |
(vm->ghost_status == VM_GHOST_RAM_USE), |
(vm->ghost_status == VM_GHOST_RAM_USE), |
1308 |
&vm->ios_entry_point) < 0) |
&vm->ios_entry_point) < 0) |
1309 |
{ |
{ |
1314 |
/* Launch the simulation */ |
/* Launch the simulation */ |
1315 |
printf("\nC3745 '%s': starting simulation (CPU0 PC=0x%llx), " |
printf("\nC3745 '%s': starting simulation (CPU0 PC=0x%llx), " |
1316 |
"JIT %sabled.\n", |
"JIT %sabled.\n", |
1317 |
vm->name,vm->boot_cpu->pc,vm->jit_use ? "en":"dis"); |
vm->name,cpu->pc,vm->jit_use ? "en":"dis"); |
1318 |
|
|
1319 |
vm_log(vm,"C3745_BOOT", |
vm_log(vm,"C3745_BOOT", |
1320 |
"starting instance (CPU0 PC=0x%llx,idle_pc=0x%llx,JIT %s)\n", |
"starting instance (CPU0 PC=0x%llx,idle_pc=0x%llx,JIT %s)\n", |
1321 |
vm->boot_cpu->pc,vm->boot_cpu->idle_pc,vm->jit_use ? "on":"off"); |
cpu->pc,cpu->idle_pc,vm->jit_use ? "on":"off"); |
1322 |
|
|
1323 |
/* Start main CPU */ |
/* Start main CPU */ |
1324 |
if (vm->ghost_status != VM_GHOST_RAM_GENERATE) { |
if (vm->ghost_status != VM_GHOST_RAM_GENERATE) { |
1330 |
return(0); |
return(0); |
1331 |
} |
} |
1332 |
|
|
1333 |
|
/* Set an IRQ */ |
1334 |
|
static void c3745_set_irq(vm_instance_t *vm,u_int irq) |
1335 |
|
{ |
1336 |
|
c3745_t *router = VM_C3745(vm); |
1337 |
|
cpu_mips_t *cpu0 = CPU_MIPS64(vm->boot_cpu); |
1338 |
|
u_int slot,port; |
1339 |
|
|
1340 |
|
switch(irq) { |
1341 |
|
case 0 ... 7: |
1342 |
|
mips64_set_irq(cpu0,irq); |
1343 |
|
|
1344 |
|
if (cpu0->irq_idle_preempt[irq]) |
1345 |
|
cpu_idle_break_wait(cpu0->gen); |
1346 |
|
break; |
1347 |
|
|
1348 |
|
case C3745_NETIO_IRQ_BASE ... C3745_NETIO_IRQ_END: |
1349 |
|
c3745_net_irq_get_slot_port(irq,&slot,&port); |
1350 |
|
dev_c3745_iofpga_net_set_irq(router->iofpga_data,slot,port); |
1351 |
|
break; |
1352 |
|
} |
1353 |
|
} |
1354 |
|
|
1355 |
|
/* Clear an IRQ */ |
1356 |
|
static void c3745_clear_irq(vm_instance_t *vm,u_int irq) |
1357 |
|
{ |
1358 |
|
c3745_t *router = VM_C3745(vm); |
1359 |
|
cpu_mips_t *cpu0 = CPU_MIPS64(vm->boot_cpu); |
1360 |
|
u_int slot,port; |
1361 |
|
|
1362 |
|
switch(irq) { |
1363 |
|
case 0 ... 7: |
1364 |
|
mips64_clear_irq(cpu0,irq); |
1365 |
|
break; |
1366 |
|
|
1367 |
|
case C3745_NETIO_IRQ_BASE ... C3745_NETIO_IRQ_END: |
1368 |
|
c3745_net_irq_get_slot_port(irq,&slot,&port); |
1369 |
|
dev_c3745_iofpga_net_clear_irq(router->iofpga_data,slot,port); |
1370 |
|
break; |
1371 |
|
} |
1372 |
|
} |
1373 |
|
|
1374 |
/* Initialize a Cisco 3745 instance */ |
/* Initialize a Cisco 3745 instance */ |
1375 |
int c3745_init_instance(c3745_t *router) |
int c3745_init_instance(c3745_t *router) |
1376 |
{ |
{ |
1389 |
return(-1); |
return(-1); |
1390 |
} |
} |
1391 |
|
|
1392 |
|
/* IRQ routing */ |
1393 |
|
vm->set_irq = c3745_set_irq; |
1394 |
|
vm->clear_irq = c3745_clear_irq; |
1395 |
|
|
1396 |
/* Load IOS configuration file */ |
/* Load IOS configuration file */ |
1397 |
if (vm->ios_config != NULL) { |
if (vm->ios_config != NULL) { |
1398 |
vm_nvram_push_config(vm,vm->ios_config); |
vm_nvram_push_config(vm,vm->ios_config); |
1400 |
} |
} |
1401 |
|
|
1402 |
/* Load ROM (ELF image or embedded) */ |
/* Load ROM (ELF image or embedded) */ |
1403 |
cpu0 = vm->boot_cpu; |
cpu0 = CPU_MIPS64(vm->boot_cpu); |
1404 |
rom_entry_point = (m_uint32_t)MIPS_ROM_PC; |
rom_entry_point = (m_uint32_t)MIPS_ROM_PC; |
1405 |
|
|
1406 |
if ((vm->rom_filename != NULL) && |
if ((vm->rom_filename != NULL) && |