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.


0eec5bfb1673472271421461f22aad8ac72470c2
[palacios.git] / palacios / src / devices / disk_model.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 #include <palacios/vmm.h>
21 #include <palacios/vmm_dev_mgr.h>
22 #include <palacios/vm_guest.h>
23
24
25
26 void __udelay(unsigned long usecs);
27
28
29 struct disk_state {
30     struct v3_dev_blk_ops * ops;
31     uint32_t seek_usecs;
32
33     void * private_data;
34 };
35
36
37 static int model_write(uint8_t * buf,  uint64_t lba, uint64_t num_bytes, void * private_data) {
38     struct disk_state * model = (struct disk_state *)private_data;
39     
40     __udelay(model->seek_usecs);
41
42     return model->ops->write(buf, lba, num_bytes, model->private_data);
43
44 }
45
46 static int model_read(uint8_t * buf,  uint64_t lba, uint64_t num_bytes, void * private_data) {
47     struct disk_state * model = (struct disk_state *)private_data;
48     
49     __udelay(model->seek_usecs);
50
51     return model->ops->read(buf, lba, num_bytes, model->private_data);
52
53 }
54
55 static uint64_t model_get_capacity(void * private_data) {
56     struct disk_state * model = (struct disk_state *)private_data;
57
58     return model->ops->get_capacity(model->private_data);
59 }
60
61 static int model_free(struct vm_device * dev) {
62     return -1;
63 }
64
65
66
67 static struct v3_dev_blk_ops blk_ops = {
68     .read = model_read, 
69     .write = model_write, 
70     .get_capacity = model_get_capacity,
71 };
72
73
74
75 static struct v3_device_ops dev_ops = {
76     .free = model_free,
77     .reset = NULL,
78     .start = NULL,
79     .stop = NULL,
80 };
81
82
83 static int connect_fn(struct v3_vm_info * vm, 
84                       void * frontend_data, 
85                       struct v3_dev_blk_ops * ops, 
86                       v3_cfg_tree_t * cfg, 
87                       void * private_data) {
88
89   v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend");
90   uint32_t seek_time = atoi(v3_cfg_val(cfg, "seek_us"));
91   struct disk_state * model = (struct disk_state *)V3_Malloc(sizeof(struct disk_state));
92
93
94   model->ops = ops;
95   model->seek_usecs = seek_time;
96   model->private_data = private_data;
97
98   if (v3_dev_connect_blk(vm, v3_cfg_val(frontend_cfg, "tag"), 
99                          &blk_ops, frontend_cfg, model) == -1) {
100       PrintError("Could not connect  to frontend %s\n", 
101                   v3_cfg_val(frontend_cfg, "tag"));
102       return -1;
103   }
104
105   return 0;
106 }
107
108 static int model_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
109
110     char * name = v3_cfg_val(cfg, "name");
111
112     struct vm_device * dev = v3_allocate_device(name, &dev_ops, NULL);
113
114     if (v3_attach_device(vm, dev) == -1) {
115         PrintError("Could not attach device %s\n", name);
116         return -1;
117     }
118
119     if (v3_dev_add_blk_frontend(vm, name, connect_fn, NULL) == -1) {
120         PrintError("Could not register %s as block frontend\n", name);
121         return -1;
122     }
123
124
125     return 0;
126 }
127
128
129
130 device_register("DISK_MODEL", model_init)