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".
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>
27 void __udelay(unsigned long usecs);
31 struct v3_dev_blk_ops * ops;
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;
41 __udelay(model->seek_usecs);
43 return model->ops->write(buf, lba, num_bytes, model->private_data);
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;
50 __udelay(model->seek_usecs);
52 return model->ops->read(buf, lba, num_bytes, model->private_data);
56 static uint64_t model_get_capacity(void * private_data) {
57 struct disk_state * model = (struct disk_state *)private_data;
59 return model->ops->get_capacity(model->private_data);
62 static int model_free(struct vm_device * dev) {
68 static struct v3_dev_blk_ops blk_ops = {
71 .get_capacity = model_get_capacity,
76 static struct v3_device_ops dev_ops = {
84 static int connect_fn(struct v3_vm_info * vm,
86 struct v3_dev_blk_ops * ops,
88 void * private_data) {
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));
96 model->seek_usecs = seek_time;
97 model->private_data = private_data;
99 if (v3_dev_connect_blk(vm, 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"));
109 static int model_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
111 char * name = v3_cfg_val(cfg, "name");
113 struct vm_device * dev = v3_allocate_device(name, &dev_ops, NULL);
115 if (v3_attach_device(vm, dev) == -1) {
116 PrintError("Could not attach device %s\n", name);
120 if (v3_dev_add_blk_frontend(vm, name, connect_fn, NULL) == -1) {
121 PrintError("Could not register %s as block frontend\n", name);
131 device_register("DISK_MODEL", model_init)