File: dev_c3725_pcmod.c

package info (click to toggle)
dynamips 0.2.7-0.2.8RC2-2
  • links: PTS
  • area: non-free
  • in suites: lenny
  • size: 3,840 kB
  • ctags: 9,893
  • sloc: ansic: 69,846; makefile: 239; sh: 124; perl: 20
file content (110 lines) | stat: -rw-r--r-- 2,707 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*  
 * Cisco router simulation platform.
 * Copyright (c) 2007 Christophe Fillot (cf@utc.fr)
 *
 * PC Modules NM (NM-NAM, NM-CIDS, ...) for c3725 platforms.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <assert.h>

#include "utils.h"
#include "net.h"
#include "net_io.h"
#include "ptask.h"
#include "vm.h"
#include "dev_i8255x.h"
#include "dev_c3725.h"

/* Initialize a NM PC module in the specified slot */
static int dev_c3725_pcmod_init(vm_instance_t *vm,struct cisco_card *card)
{
 
   struct i8255x_data *data;
   u_int slot = card->slot_id;
 
   /* Set the PCI bus */
   card->pci_bus = vm->slots_pci_bus[slot];

   /* Set the EEPROM */
   cisco_card_set_eeprom(vm,card,cisco_eeprom_find_nm(card->driver->dev_type));
   c3725_set_slot_eeprom(VM_C3725(vm),slot,&card->eeprom);

   /* Create the Intel i8255x chip */
   data = dev_i8255x_init(vm,card->dev_name,0,
                          card->pci_bus,
                          c3725_nm_get_pci_device(slot),
                          c3725_net_irq_for_slot_port(slot,0));

   /* Store device info into the router structure */
   card->drv_info = data;
   return(0);
}

/* Remove a NM PC module from the specified slot */
static int dev_c3725_pcmod_shutdown(vm_instance_t *vm,struct cisco_card *card)
{
   struct i8255x_data *data = card->drv_info;

   /* Remove the NM EEPROM */
   cisco_card_unset_eeprom(card);
   c3725_set_slot_eeprom(VM_C3725(vm),card->slot_id,NULL);

   /* Remove the Intel i2855x chip */
   dev_i8255x_remove(data);
   return(0);
}

/* Bind a Network IO descriptor */
static int dev_c3725_pcmod_set_nio(vm_instance_t *vm,struct cisco_card *card,
                                   u_int port_id,netio_desc_t *nio)
{
   struct i8255x_data *d = card->drv_info;

   if (!d || (port_id != 0))
      return(-1);

   dev_i8255x_set_nio(d,nio);
   return(0);
}

/* Unbind a Network IO descriptor */
static int dev_c3725_pcmod_unset_nio(vm_instance_t *vm,struct cisco_card *card,
                                     u_int port_id)
{
   struct i8255x_data *d = card->drv_info;

   if (!d || (port_id != 0))
      return(-1);

   dev_i8255x_unset_nio(d);
   return(0);
}

/* NM-NAM driver */
struct cisco_card_driver dev_c3725_nm_nam_driver = {
   "NM-NAM", 0, 0,
   dev_c3725_pcmod_init, 
   dev_c3725_pcmod_shutdown, 
   NULL,
   dev_c3725_pcmod_set_nio,
   dev_c3725_pcmod_unset_nio,
   NULL,
};

/* NM-CIDS driver */
struct cisco_card_driver dev_c3725_nm_cids_driver = {
   "NM-CIDS", 0, 0,
   dev_c3725_pcmod_init, 
   dev_c3725_pcmod_shutdown, 
   NULL,
   dev_c3725_pcmod_set_nio,
   dev_c3725_pcmod_unset_nio,
   NULL,
};