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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
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>
26 #define TX_HYPERCALL 0x300
27 #define RX_HYPERCALL 0x301
28 #define MACADDR_HYPERCALL 0x302
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);
43 PrintDebug("Transmitting Packet\n");
45 if (read_guest_pa_memory(info, pkt_gpa, pkt_len, pkt) != -1) {
54 static int rx_call(struct guest_info * info, uint_t call_no, void * priv_data) {
55 // struct nic_state * nic = (struct nic_state *)priv_data;
56 addr_t pkt_gpa = info->vm_regs.rbx;
60 PrintDebug("Receiving Packet\n");
63 if (write_guest_pa_memory(info, pkt_gpa, pkt_len, pkt) != -1) {
71 static int macaddr_call(struct guest_info * info, uint_t call_no, void * priv_data) {
72 struct nic_state * nic = (struct nic_state *)priv_data;
73 addr_t mac_gpa = info->vm_regs.rbx;
76 PrintDebug("Returning MAC ADDR\n");
78 if (write_guest_pa_memory(info, mac_gpa, 6, nic->mac_addr) != 6) {
79 PrintError("Could not write mac address\n");
87 static int net_free(struct vm_device * dev) {
93 static struct v3_device_ops dev_ops = {
103 static int net_init(struct guest_info * vm, v3_cfg_tree_t * cfg) {
104 struct nic_state * state = NULL;
105 char * dev_id = v3_cfg_val(cfg, "ID");
107 state = (struct nic_state *)V3_Malloc(sizeof(struct nic_state));
109 PrintDebug("Creating VMNet Device\n");
111 struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, state);
113 if (v3_attach_device(vm, dev) == -1) {
114 PrintError("Could not attach device %s\n", dev_id);
119 v3_register_hypercall(vm, TX_HYPERCALL, tx_call, state);
120 v3_register_hypercall(vm, RX_HYPERCALL, rx_call, state);
121 v3_register_hypercall(vm, MACADDR_HYPERCALL, macaddr_call, state);
123 state->mac_addr[0] = 0x52;
124 state->mac_addr[1] = 0x54;
125 state->mac_addr[2] = 0x00;
126 state->mac_addr[3] = 0x12;
127 state->mac_addr[4] = 0x34;
128 state->mac_addr[5] = 0x56;
134 device_register("VMNET", net_init)