/[dynamips]/trunk/dev_c7200_bri.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

Diff of /trunk/dev_c7200_bri.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

upstream/dynamips-0.2.6-RC3/dev_c7200_bri.c revision 4 by dpavlin, Sat Oct 6 16:06:49 2007 UTC upstream/dynamips-0.2.8-RC1/dev_c7200_bri.c revision 11 by dpavlin, Sat Oct 6 16:33:40 2007 UTC
# Line 1  Line 1 
1  /*    /*  
2   * Cisco C7200 (Predator) Simulation Platform.   * Cisco router Simulation Platform.
3   * Copyright (C) 2005-2006 Christophe Fillot.  All rights reserved.   * Copyright (C) 2005-2006 Christophe Fillot.  All rights reserved.
4   *   *
5   * EEPROM types:   * EEPROM types:
# Line 22  Line 22 
22  #include <pthread.h>  #include <pthread.h>
23  #include <assert.h>  #include <assert.h>
24    
25  #include "mips64.h"  #include "cpu.h"
26    #include "vm.h"
27  #include "dynamips.h"  #include "dynamips.h"
28  #include "memory.h"  #include "memory.h"
29  #include "device.h"  #include "device.h"
# Line 490  static inline int m32_tx_scan(struct m32 Line 491  static inline int m32_tx_scan(struct m32
491           printf("M32: data_ptr=0x%x, len=%u\n",txd.tdp,pkt_len);           printf("M32: data_ptr=0x%x, len=%u\n",txd.tdp,pkt_len);
492           mem_dump(stdout,pkt,pkt_len);           mem_dump(stdout,pkt,pkt_len);
493    
494           /* Poll the next descriptor (wait for HOLD bit to be reset */           /* Poll the next descriptor (wait for HOLD bit to be reset) */
495           chan->poll_mode = 1;             chan->poll_mode = 1;  
496    
497           if (txd.params & M32_TXDESC_FE) {           if (txd.params & M32_TXDESC_FE) {
# Line 578  static int m32_action_req(struct m32_dat Line 579  static int m32_action_req(struct m32_dat
579  }  }
580    
581  /* Munich32 general access function */  /* Munich32 general access function */
582  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,
583                              m_uint32_t offset,u_int op_size,u_int op_type,                              m_uint32_t offset,u_int op_size,u_int op_type,
584                              m_uint64_t *data)                              m_uint64_t *data)
585  {  {
# Line 641  static void *m32_gen_access(struct m32_d Line 642  static void *m32_gen_access(struct m32_d
642  /*  /*
643   *  pa_4b_access()   *  pa_4b_access()
644   */   */
645  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,
646                     u_int op_size,u_int op_type,m_uint64_t *data)                     u_int op_size,u_int op_type,m_uint64_t *data)
647  {  {
648     struct pa_4b_data *d = dev->priv_data;     struct pa_4b_data *d = dev->priv_data;
# Line 654  void *pa_4b_access(cpu_mips_t *cpu,struc Line 655  void *pa_4b_access(cpu_mips_t *cpu,struc
655     if (offset >= MUNICH32_MEM_SIZE) {     if (offset >= MUNICH32_MEM_SIZE) {
656        if (op_type == MTS_READ) {        if (op_type == MTS_READ) {
657           cpu_log(cpu,d->name,"read  access to offset = 0x%x, pc = 0x%llx "           cpu_log(cpu,d->name,"read  access to offset = 0x%x, pc = 0x%llx "
658                   "(op_size=%u)\n",offset,cpu->pc,op_size);                   "(op_size=%u)\n",offset,cpu_get_pc(cpu),op_size);
659        } else {        } else {
660           cpu_log(cpu,d->name,"write access to vaddr = 0x%x, pc = 0x%llx, "           cpu_log(cpu,d->name,"write access to vaddr = 0x%x, pc = 0x%llx, "
661                   "val = 0x%llx (op_size=%u)\n",offset,cpu->pc,*data,op_size);                   "val = 0x%llx (op_size=%u)\n",
662                     offset,cpu_get_pc(cpu),*data,op_size);
663        }        }
664     }     }
665  #endif  #endif
# Line 741  void *pa_4b_access(cpu_mips_t *cpu,struc Line 743  void *pa_4b_access(cpu_mips_t *cpu,struc
743  /*  /*
744   * pci_munich32_read()   * pci_munich32_read()
745   */   */
746  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,
747                                      int reg)                                      int reg)
748  {    {  
749     struct pa_4b_data *d = dev->priv_data;     struct pa_4b_data *d = dev->priv_data;
# Line 760  static m_uint32_t pci_munich32_read(cpu_ Line 762  static m_uint32_t pci_munich32_read(cpu_
762  /*  /*
763   * pci_munich32_write()   * pci_munich32_write()
764   */   */
765  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,
766                                 int reg,m_uint32_t value)                                 int reg,m_uint32_t value)
767  {  {
768     struct pa_4b_data *d = dev->priv_data;     struct pa_4b_data *d = dev->priv_data;
# Line 782  static void pci_munich32_write(cpu_mips_ Line 784  static void pci_munich32_write(cpu_mips_
784   *   *
785   * Add a PA-4B/PA-8B port adapter into specified slot.   * Add a PA-4B/PA-8B port adapter into specified slot.
786   */   */
787  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)
788  {  {
789       u_int slot = card->slot_id;
790     struct pci_device *pci_dev;     struct pci_device *pci_dev;
791     struct pa_4b_data *d;     struct pa_4b_data *d;
792     struct vdevice *dev;     struct vdevice *dev;
793    
794     /* Allocate the private data structure for PA-4B chip */     /* Allocate the private data structure for PA-4B chip */
795     if (!(d = malloc(sizeof(*d)))) {     if (!(d = malloc(sizeof(*d)))) {
796        fprintf(stderr,"%s (PA-4B): out of memory\n",name);        vm_error(vm,"%s: out of memory\n",card->dev_name);
797        return(-1);        return(-1);
798     }     }
799    
800     memset(d,0,sizeof(*d));     memset(d,0,sizeof(*d));
801     d->m32_offset = 0x08;     d->m32_offset = 0x08;
802     d->m32_data.vm = router->vm;     d->m32_data.vm = vm;
803    
804       /* Set the PCI bus */
805       card->pci_bus = vm->slots_pci_bus[slot];
806    
807     /* Set the EEPROM */     /* Set the EEPROM */
808     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"));
809       c7200_set_slot_eeprom(VM_C7200(vm),slot,&card->eeprom);
810    
811     /* Add as PCI device PA-4B */     /* Add as PCI device PA-4B */
812     pci_dev = pci_dev_add(router->pa_bay[pa_bay].pci_map,name,     pci_dev = pci_dev_add(card->pci_bus,card->dev_name,
813                           BRI_PCI_VENDOR_ID,BRI_PCI_PRODUCT_ID,                           BRI_PCI_VENDOR_ID,BRI_PCI_PRODUCT_ID,
814                           0,0,C7200_NETIO_IRQ,d,                           0,0,C7200_NETIO_IRQ,d,
815                           NULL,pci_munich32_read,pci_munich32_write);                           NULL,pci_munich32_read,pci_munich32_write);
816    
817     if (!pci_dev) {     if (!pci_dev) {
818        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);
819        return(-1);        return(-1);
820     }     }
821    
822     /* Create the PA-4B structure */     /* Create the PA-4B structure */
823     d->name        = name;     d->name    = card->dev_name;
824     d->pci_dev     = pci_dev;     d->pci_dev = pci_dev;
825     d->vm          = router->vm;     d->vm      = vm;
826    
827     /* Create the device itself */     /* Create the device itself */
828     if (!(dev = dev_create(name))) {     if (!(dev = dev_create(card->dev_name))) {
829        fprintf(stderr,"%s (PA-4B): unable to create device.\n",name);        vm_error(vm,"%s: unable to create device.\n",card->dev_name);
830        return(-1);        return(-1);
831     }     }
832    
833     dev->phys_len  = 0x800000;     dev->phys_len = 0x800000;
834     dev->handler   = pa_4b_access;     dev->handler  = pa_4b_access;
835    
836     /* Store device info */     /* Store device info */
837     dev->priv_data = d;     dev->priv_data = d;
838     d->dev = dev;     d->dev = dev;
839    
    /* Map this device to the VM */  
    vm_bind_device(router->vm,dev);  
   
840     /* Store device info into the router structure */     /* Store device info into the router structure */
841     return(c7200_pa_set_drvinfo(router,pa_bay,d));     card->drv_info = d;
842       return(0);
843  }  }
844    
845  /* Remove a PA-4B from the specified slot */  /* Remove a PA-4B from the specified slot */
846  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)
847  {  {
848     struct c7200_pa_bay *bay;     struct pa_4b_data *d = card->drv_info;
    struct pa_4b_data *d;  
   
    if (!(bay = c7200_pa_get_info(router,pa_bay)))  
       return(-1);  
   
    d = bay->drv_info;  
849    
850     /* Remove the PA EEPROM */     /* Remove the PA EEPROM */
851     c7200_pa_unset_eeprom(router,pa_bay);     cisco_card_unset_eeprom(card);
852       c7200_set_slot_eeprom(VM_C7200(vm),card->slot_id,NULL);
853    
854     /* Remove the PCI device */     /* Remove the PCI device */
855     pci_dev_remove(d->pci_dev);     pci_dev_remove(d->pci_dev);
856    
857     /* Remove the device from the CPU address space */     /* Remove the device from the CPU address space */
858     vm_unbind_device(router->vm,d->dev);     vm_unbind_device(vm,d->dev);
859     cpu_group_rebuild_mts(router->vm->cpu_group);     cpu_group_rebuild_mts(vm->cpu_group);
860    
861     /* Free the device structure itself */     /* Free the device structure itself */
862     free(d->dev);     free(d->dev);
# Line 865  int dev_c7200_pa_bri_shutdown(c7200_t *r Line 865  int dev_c7200_pa_bri_shutdown(c7200_t *r
865  }  }
866    
867  /* Bind a Network IO descriptor to a specific port */  /* Bind a Network IO descriptor to a specific port */
868  int dev_c7200_pa_bri_set_nio(c7200_t *router,u_int pa_bay,u_int port_id,  int dev_c7200_pa_bri_set_nio(vm_instance_t *vm,struct cisco_card *card,
869                               netio_desc_t *nio)                               u_int port_id,netio_desc_t *nio)
870  {  {
871     struct pa_4b_data *d;     struct pa_4b_data *d = card->drv_info;
872    
873     if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay)))     if (!d || (port_id > 0))
874        return(-1);        return(-1);
875    
876     if (d->nio != NULL)     if (d->nio != NULL)
# Line 879  int dev_c7200_pa_bri_set_nio(c7200_t *ro Line 879  int dev_c7200_pa_bri_set_nio(c7200_t *ro
879     d->nio = nio;     d->nio = nio;
880    
881     /* TEST */     /* TEST */
882     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,
883                                      &d->m32_data,NULL);
884    
885     //netio_rxl_add(nio,(netio_rx_handler_t)dev_pa_4b_handle_rxring,d,NULL);     //netio_rxl_add(nio,(netio_rx_handler_t)dev_pa_4b_handle_rxring,d,NULL);
886     return(0);     return(0);
887  }  }
888    
889  /* Bind a Network IO descriptor to a specific port */  /* Bind a Network IO descriptor to a specific port */
890  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,
891                                   u_int port_id)
892  {  {
893     struct pa_4b_data *d;     struct pa_4b_data *d = card->drv_info;
894    
895     if ((port_id > 0) || !(d = c7200_pa_get_drvinfo(router,pa_bay)))     if (!d || (port_id > 0))
896        return(-1);        return(-1);
897    
898     if (d->nio) {     if (d->nio) {
# Line 904  int dev_c7200_pa_bri_unset_nio(c7200_t * Line 906  int dev_c7200_pa_bri_unset_nio(c7200_t *
906  }  }
907    
908  /* PA-4B driver */  /* PA-4B driver */
909  struct c7200_pa_driver dev_c7200_pa_4b_driver = {  struct cisco_card_driver dev_c7200_pa_4b_driver = {
910     "PA-4B", 0,     "PA-4B", 0, 0,
911     dev_c7200_pa_bri_init,     dev_c7200_pa_bri_init,
912     dev_c7200_pa_bri_shutdown,     dev_c7200_pa_bri_shutdown,
913       NULL,
914     dev_c7200_pa_bri_set_nio,     dev_c7200_pa_bri_set_nio,
915     dev_c7200_pa_bri_unset_nio,     dev_c7200_pa_bri_unset_nio,
916     NULL,     NULL,

Legend:
Removed from v.4  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26