--- upstream/dynamips-0.2.6-RC2/dev_c7200_bri.c 2007/10/06 16:05:34 3 +++ upstream/dynamips-0.2.8-RC1/dev_c7200_bri.c 2007/10/06 16:33:40 11 @@ -1,5 +1,5 @@ /* - * Cisco C7200 (Predator) Simulation Platform. + * Cisco router Simulation Platform. * Copyright (C) 2005-2006 Christophe Fillot. All rights reserved. * * EEPROM types: @@ -22,7 +22,8 @@ #include #include -#include "mips64.h" +#include "cpu.h" +#include "vm.h" #include "dynamips.h" #include "memory.h" #include "device.h" @@ -490,7 +491,7 @@ printf("M32: data_ptr=0x%x, len=%u\n",txd.tdp,pkt_len); mem_dump(stdout,pkt,pkt_len); - /* Poll the next descriptor (wait for HOLD bit to be reset */ + /* Poll the next descriptor (wait for HOLD bit to be reset) */ chan->poll_mode = 1; if (txd.params & M32_TXDESC_FE) { @@ -578,7 +579,7 @@ } /* Munich32 general access function */ -static void *m32_gen_access(struct m32_data *d,cpu_mips_t *cpu, +static void *m32_gen_access(struct m32_data *d,cpu_gen_t *cpu, m_uint32_t offset,u_int op_size,u_int op_type, m_uint64_t *data) { @@ -641,7 +642,7 @@ /* * pa_4b_access() */ -void *pa_4b_access(cpu_mips_t *cpu,struct vdevice *dev,m_uint32_t offset, +void *pa_4b_access(cpu_gen_t *cpu,struct vdevice *dev,m_uint32_t offset, u_int op_size,u_int op_type,m_uint64_t *data) { struct pa_4b_data *d = dev->priv_data; @@ -654,10 +655,11 @@ if (offset >= MUNICH32_MEM_SIZE) { if (op_type == MTS_READ) { cpu_log(cpu,d->name,"read access to offset = 0x%x, pc = 0x%llx " - "(op_size=%u)\n",offset,cpu->pc,op_size); + "(op_size=%u)\n",offset,cpu_get_pc(cpu),op_size); } else { cpu_log(cpu,d->name,"write access to vaddr = 0x%x, pc = 0x%llx, " - "val = 0x%llx (op_size=%u)\n",offset,cpu->pc,*data,op_size); + "val = 0x%llx (op_size=%u)\n", + offset,cpu_get_pc(cpu),*data,op_size); } } #endif @@ -741,7 +743,7 @@ /* * pci_munich32_read() */ -static m_uint32_t pci_munich32_read(cpu_mips_t *cpu,struct pci_device *dev, +static m_uint32_t pci_munich32_read(cpu_gen_t *cpu,struct pci_device *dev, int reg) { struct pa_4b_data *d = dev->priv_data; @@ -760,7 +762,7 @@ /* * pci_munich32_write() */ -static void pci_munich32_write(cpu_mips_t *cpu,struct pci_device *dev, +static void pci_munich32_write(cpu_gen_t *cpu,struct pci_device *dev, int reg,m_uint32_t value) { struct pa_4b_data *d = dev->priv_data; @@ -782,81 +784,79 @@ * * Add a PA-4B/PA-8B port adapter into specified slot. */ -int dev_c7200_pa_bri_init(c7200_t *router,char *name,u_int pa_bay) +int dev_c7200_pa_bri_init(vm_instance_t *vm,struct cisco_card *card) { + u_int slot = card->slot_id; struct pci_device *pci_dev; struct pa_4b_data *d; struct vdevice *dev; /* Allocate the private data structure for PA-4B chip */ if (!(d = malloc(sizeof(*d)))) { - fprintf(stderr,"%s (PA-4B): out of memory\n",name); + vm_error(vm,"%s: out of memory\n",card->dev_name); return(-1); } memset(d,0,sizeof(*d)); d->m32_offset = 0x08; - d->m32_data.vm = router->vm; + d->m32_data.vm = vm; + + /* Set the PCI bus */ + card->pci_bus = vm->slots_pci_bus[slot]; /* Set the EEPROM */ - c7200_pa_set_eeprom(router,pa_bay,cisco_eeprom_find_pa("PA-4B")); + cisco_card_set_eeprom(vm,card,cisco_eeprom_find_pa("PA-4B")); + c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom); /* Add as PCI device PA-4B */ - pci_dev = pci_dev_add(router->pa_bay[pa_bay].pci_map,name, + pci_dev = pci_dev_add(card->pci_bus,card->dev_name, BRI_PCI_VENDOR_ID,BRI_PCI_PRODUCT_ID, 0,0,C7200_NETIO_IRQ,d, NULL,pci_munich32_read,pci_munich32_write); if (!pci_dev) { - fprintf(stderr,"%s (PA-4B): unable to create PCI device.\n",name); + vm_error(vm,"%s: unable to create PCI device.\n",card->dev_name); return(-1); } /* Create the PA-4B structure */ - d->name = name; - d->pci_dev = pci_dev; - d->vm = router->vm; + d->name = card->dev_name; + d->pci_dev = pci_dev; + d->vm = vm; /* Create the device itself */ - if (!(dev = dev_create(name))) { - fprintf(stderr,"%s (PA-4B): unable to create device.\n",name); + if (!(dev = dev_create(card->dev_name))) { + vm_error(vm,"%s: unable to create device.\n",card->dev_name); return(-1); } - dev->phys_len = 0x800000; - dev->handler = pa_4b_access; + dev->phys_len = 0x800000; + dev->handler = pa_4b_access; /* Store device info */ dev->priv_data = d; d->dev = dev; - /* Map this device to the VM */ - vm_bind_device(router->vm,dev); - /* Store device info into the router structure */ - return(c7200_pa_set_drvinfo(router,pa_bay,d)); + card->drv_info = d; + return(0); } /* Remove a PA-4B from the specified slot */ -int dev_c7200_pa_bri_shutdown(c7200_t *router,u_int pa_bay) +int dev_c7200_pa_bri_shutdown(vm_instance_t *vm,struct cisco_card *card) { - struct c7200_pa_bay *bay; - struct pa_4b_data *d; - - if (!(bay = c7200_pa_get_info(router,pa_bay))) - return(-1); - - d = bay->drv_info; + struct pa_4b_data *d = card->drv_info; /* Remove the PA EEPROM */ - c7200_pa_unset_eeprom(router,pa_bay); + cisco_card_unset_eeprom(card); + c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL); /* Remove the PCI device */ pci_dev_remove(d->pci_dev); /* Remove the device from the CPU address space */ - vm_unbind_device(router->vm,d->dev); - cpu_group_rebuild_mts(router->vm->cpu_group); + vm_unbind_device(vm,d->dev); + cpu_group_rebuild_mts(vm->cpu_group); /* Free the device structure itself */ free(d->dev); @@ -865,12 +865,12 @@ } /* Bind a Network IO descriptor to a specific port */ -int dev_c7200_pa_bri_set_nio(c7200_t *router,u_int pa_bay,u_int port_id, - netio_desc_t *nio) +int dev_c7200_pa_bri_set_nio(vm_instance_t *vm,struct cisco_card *card, + u_int port_id,netio_desc_t *nio) { - struct pa_4b_data *d; + struct pa_4b_data *d = card->drv_info; - if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay))) + if (!d || (port_id > 0)) return(-1); if (d->nio != NULL) @@ -879,18 +879,20 @@ d->nio = nio; /* TEST */ - d->m32_data.tx_tid = ptask_add((ptask_callback)m32_tx_scan_all_channels,&d->m32_data,NULL); + d->m32_data.tx_tid = ptask_add((ptask_callback)m32_tx_scan_all_channels, + &d->m32_data,NULL); //netio_rxl_add(nio,(netio_rx_handler_t)dev_pa_4b_handle_rxring,d,NULL); return(0); } /* Bind a Network IO descriptor to a specific port */ -int dev_c7200_pa_bri_unset_nio(c7200_t *router,u_int pa_bay,u_int port_id) +int dev_c7200_pa_bri_unset_nio(vm_instance_t *vm,struct cisco_card *card, + u_int port_id) { - struct pa_4b_data *d; + struct pa_4b_data *d = card->drv_info; - if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay))) + if (!d || (port_id > 0)) return(-1); if (d->nio) { @@ -904,10 +906,11 @@ } /* PA-4B driver */ -struct c7200_pa_driver dev_c7200_pa_4b_driver = { - "PA-4B", 0, +struct cisco_card_driver dev_c7200_pa_4b_driver = { + "PA-4B", 0, 0, dev_c7200_pa_bri_init, dev_c7200_pa_bri_shutdown, + NULL, dev_c7200_pa_bri_set_nio, dev_c7200_pa_bri_unset_nio, NULL,