Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Support HVM partitioning for APICs
[palacios.git] / palacios / src / devices / para_net.c
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #include <palacios/vmm.h>
22 #include <palacios/vmm_dev_mgr.h>
23 #include <palacios/vm_guest_mem.h>
24 #include <palacios/vmm_hypercall.h>
25
26 #define TX_HYPERCALL 0x300
27 #define RX_HYPERCALL 0x301
28 #define MACADDR_HYPERCALL 0x302
29
30
31 struct nic_state {    
32     uchar_t mac_addr[6];
33 };
34
35
36
37 static int tx_call(struct guest_info * info, uint_t call_no, void * priv_data) {
38     //    struct nic_state * nic = (struct nic_state *)priv_data;
39     addr_t pkt_gpa = info->vm_regs.rbx;
40     int pkt_len = info->vm_regs.rcx;
41     uchar_t * pkt = V3_Malloc(pkt_len);
42
43     if (!pkt) {
44         PrintError(info->vm_info, info, "Cannot allocate in transmit!\n");
45         return -1;
46     }
47     
48     PrintDebug(info->vm_info, info, "Transmitting Packet\n");
49     
50     if (read_guest_pa_memory(info, pkt_gpa, pkt_len, pkt) != -1) {
51         return -1;
52     }
53     
54     
55     return -1;
56 }
57
58
59 static int rx_call(struct guest_info * info, uint_t call_no, void * priv_data) {
60     //    struct nic_state * nic = (struct nic_state *)priv_data;
61     addr_t pkt_gpa = info->vm_regs.rbx;
62     uint_t pkt_len = 0;
63     uchar_t * pkt = NULL;
64
65     PrintDebug(info->vm_info, info, "Receiving Packet\n");
66     return -1;
67
68     if (write_guest_pa_memory(info, pkt_gpa, pkt_len, pkt) != -1) {
69         return -1;
70     }
71
72     return -1;
73 }
74
75
76 static int macaddr_call(struct guest_info * info, uint_t call_no, void * priv_data) {
77     struct nic_state * nic = (struct nic_state *)priv_data;
78     addr_t mac_gpa = info->vm_regs.rbx;
79
80
81     PrintDebug(info->vm_info, info, "Returning MAC ADDR\n");
82     
83     if (write_guest_pa_memory(info, mac_gpa, 6, nic->mac_addr) != 6) {
84         PrintError(info->vm_info, info, "Could not write mac address\n");
85         return -1;
86     }
87
88     return 0;
89 }
90
91
92 static int net_free(struct vm_device * dev) {
93
94     return 0;
95 }
96
97
98 static struct v3_device_ops dev_ops = {
99     .free = net_free,
100     .reset = NULL,
101     .start = NULL,
102     .stop = NULL,
103 };
104
105
106
107
108 static int net_init(struct guest_info * vm, v3_cfg_tree_t * cfg) {
109     struct nic_state * state = NULL;
110     char * dev_id = v3_cfg_val(cfg, "ID");
111
112     state = (struct nic_state *)V3_Malloc(sizeof(struct nic_state));
113
114     if (!state) {
115         PrintError(info->vm_info, info, "Cannot allocate in init\n");
116         return -1;
117     }
118
119     PrintDebug(info->vm_info, info, "Creating VMNet Device\n");
120
121     struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, state);
122
123     if (v3_attach_device(vm, dev) == -1) {
124         PrintError(info->vm_info, info, "Could not attach device %s\n", dev_id);
125         return -1;
126     }
127
128
129     v3_register_hypercall(vm, TX_HYPERCALL, tx_call, state);
130     v3_register_hypercall(vm, RX_HYPERCALL, rx_call, state);
131     v3_register_hypercall(vm, MACADDR_HYPERCALL, macaddr_call, state);
132
133     state->mac_addr[0] = 0x52;
134     state->mac_addr[1] = 0x54;
135     state->mac_addr[2] = 0x00;
136     state->mac_addr[3] = 0x12;
137     state->mac_addr[4] = 0x34;
138     state->mac_addr[5] = 0x56;
139
140     return 0;
141 }
142
143
144 device_register("VMNET", net_init)