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.


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