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 char device operations to device manager
Jack Lange [Tue, 9 Nov 2010 20:03:01 +0000 (14:03 -0600)]
palacios/include/palacios/vmm_dev_mgr.h
palacios/src/devices/stream.c
palacios/src/palacios/vmm_dev_mgr.c
palacios/src/palacios/vmm_stream.c

index 9e019b5..1dd8031 100644 (file)
@@ -62,6 +62,9 @@ struct vmm_dev_mgr {
     struct list_head net_list;
     struct hashtable * net_table;
 
+    struct list_head char_list;
+    struct hashtable * char_table;
+
     struct list_head console_list;
     struct hashtable * console_table;
 
@@ -158,25 +161,35 @@ struct v3_dev_blk_ops {
 };
 
 struct v3_dev_net_ops {
-    /* below functions are called by frontend device
-     * These will be filled in by the backend when a backend is initiated.  --Lei*/
+    /* Backend implemented functions */
     int (*send)(uint8_t * buf, uint32_t count, void * private_data, struct vm_device *dest_dev);
     void (*start_rx)(void *back_data);
     void (*stop_rx)(void *back_data);
 
-    /* below functions are called by Backend device
-     * These will be filled in by the frontend when a backend is connected. -- Lei*/
+    /* Frontend implemented functions */
     int (*recv)(uint8_t * buf, uint32_t count, void * frnt_data);
-    void (*poll)(struct v3_vm_info *vm, void* frnt_data);
+    void (*poll)(struct v3_vm_info * vm, void * frnt_data);
     void (*start_tx)(void * frnt_data);
     void (*stop_tx)(void * frnt_data);
-    void * frontend_data;
+
+    /* This is ugly... */
+    void * frontend_data; 
 };
 
 struct v3_dev_console_ops {
 
 };
 
+struct v3_dev_char_ops {
+    /* Backend implemented functions */
+    int (*write)(uint8_t * buf, uint64_t len, void * private_data);
+    //  int (*read)(uint8_t * buf, uint64_t len, void * private_data);
+
+    /* Frontend Implemented functions */
+    int (*push)(uint8_t * buf, uint64_t len, void * private_data);
+};
+
+
 int v3_dev_add_blk_frontend(struct v3_vm_info * vm, 
                            char * name, 
                            int (*connect)(struct v3_vm_info * vm, 
@@ -208,6 +221,24 @@ int v3_dev_connect_net(struct v3_vm_info * vm,
                       void * private_data);
 
 
+int v3_dev_add_char_frontend(struct v3_vm_info * vm, 
+                            char * name, 
+                            int (*connect)(struct v3_vm_info * vm, 
+                                           void * frontend_data, 
+                                           struct v3_dev_char_ops * ops, 
+                                           v3_cfg_tree_t * cfg, 
+                                           void * private_data,
+                                           void ** push_fn_arg), 
+                            void * priv_data);
+
+int v3_dev_connect_char(struct v3_vm_info * vm, 
+                       char * frontend_name, 
+                       struct v3_dev_char_ops * ops, 
+                       v3_cfg_tree_t * cfg, 
+                       void * private_data, 
+                       void ** push_fn_arg);
+
+
 #endif // ! __V3VEE__
 
 #endif
index 1b0d5c7..359b0d4 100644 (file)
 #include <palacios/vmm_host_events.h>
 #include <palacios/vmm_lock.h>
 #include <palacios/vmm_string.h>
-#include <devices/serial.h>
+
 
 struct stream_state {
-    void *stream_in;
-    void *stream_out;
-    struct vm_device *frontend_dev;
-    struct v3_stream_ops stream_ops;
+    v3_stream_t stream;
+
+    struct v3_dev_char_ops * char_ops;
 };
 
-static int stream_read(char *buf, uint_t length, void *private_data) 
-{
-    struct vm_device *dev = (struct vm_device *) private_data;
-    struct stream_state *state = (struct stream_state *) dev->private_data;
-    
-    return V3_StreamRead(state->stream_out,buf,length);
-}
 
-static int stream_write(char *buf, uint_t length, void *private_data) 
+
+static int stream_write(uint8_t * buf, uint64_t length, void * private_data) 
 {
     struct vm_device *dev = (struct vm_device *) private_data;
     struct stream_state *state = (struct stream_state *) dev->private_data;
     
-    return V3_StreamWrite(state->stream_out,buf,length);
+    return v3_stream_write(state->stream, buf, length);
 }
 
 
-static void notify(void * data){
-    struct stream_state *state = (struct stream_state *)data;
-    char temp[1024];
-    int len;   
-       
-    len = V3_StreamRead(state->stream_in, temp, 1024); 
-    state->stream_ops.input(temp, len, state->stream_ops.front_data);
-}
+
 
 static struct v3_device_ops dev_ops = {
     .free = NULL,
@@ -68,35 +54,33 @@ static struct v3_device_ops dev_ops = {
 
 static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) 
 {
-    v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend");
-    const char * frontend_tag = v3_cfg_val(frontend_cfg, "tag");
-    struct vm_device * frontend = v3_find_dev(vm, frontend_tag);
+    //   v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend");
     char * dev_id = v3_cfg_val(cfg, "ID");
-    char * stream_in = v3_cfg_val(cfg, "stream_in");
-    char * stream_out = v3_cfg_val(cfg, "stream_out");
-    struct stream_state *state;
-
+    char * stream_name = v3_cfg_val(cfg, "stream");
+    struct stream_state * state = NULL;
 
-    V3_ASSERT(frontend_cfg);
-    V3_ASSERT(frontend_tag);
-    V3_ASSERT(frontend);
-    V3_ASSERT(stream_in);
-    V3_ASSERT(stream_out);
 
     state = (struct stream_state *)V3_Malloc(sizeof(struct stream_state));
+
     V3_ASSERT(state);
-    state->frontend_dev = frontend;
 
-    state->stream_out = V3_StreamOpen(stream_out, NULL, NULL, STREAM_OPEN_MODE_READ | STREAM_OPEN_MODE_WRITE);
-    state->stream_in = V3_StreamOpen(stream_in, notify, state, STREAM_OPEN_MODE_READ | STREAM_OPEN_MODE_WRITE);
-    if (!state->stream_out || !state->stream_in) {
-       PrintError("Could not open stream %s %s\n", stream_in, stream_out);
+
+    state->stream = v3_stream_open(vm, stream_name);
+
+    if (state->stream == NULL) {
+       PrintError("Could not open stream %s\n", stream_name);
        V3_Free(state);
        return -1;
     }
+
+    state->char_ops->write = stream_write;
        
-    struct vm_device *dev = v3_allocate_device(dev_id, &dev_ops, state);
-    V3_ASSERT(dev);
+    struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, state);
+
+    if (dev == NULL) {
+       PrintError("Could not allocate device %s\n", dev_id);
+       return -1;
+    }
 
     if (v3_attach_device(vm, dev) == -1) {
        PrintError("Could not attach device %s\n", dev_id);
@@ -104,10 +88,7 @@ static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg)
        return -1;
     }
 
-    state->stream_ops.read = stream_read;
-    state->stream_ops.write = stream_write;
 
-    v3_stream_register_serial(frontend, &(state->stream_ops), dev);
 
     return 0;
 }
index 0b50c36..b538506 100644 (file)
@@ -96,10 +96,12 @@ int v3_init_dev_mgr(struct v3_vm_info * vm) {
 
     INIT_LIST_HEAD(&(mgr->blk_list));
     INIT_LIST_HEAD(&(mgr->net_list));
+    INIT_LIST_HEAD(&(mgr->char_list));
     INIT_LIST_HEAD(&(mgr->console_list));
 
     mgr->blk_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn);
     mgr->net_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn);
+    mgr->char_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn);
     mgr->console_table = v3_create_htable(0, dev_hash_fn, dev_eq_fn);
     
     return 0;
@@ -395,3 +397,70 @@ int v3_dev_connect_net(struct v3_vm_info * vm,
     return 0;
 }
 
+
+struct char_frontend {
+    int (*connect)(struct v3_vm_info * vm, 
+                  void * frontend_data, 
+                  struct v3_dev_char_ops * ops, 
+                  v3_cfg_tree_t * cfg, 
+                  void * priv_data, 
+                  void ** push_fn_arg);
+    
+
+    struct list_head char_node;
+
+    void * priv_data;
+};
+
+
+
+int v3_dev_add_char_frontend(struct v3_vm_info * vm, 
+                            char * name, 
+                            int (*connect)(struct v3_vm_info * vm, 
+                                           void * frontend_data, 
+                                           struct v3_dev_char_ops * ops, 
+                                           v3_cfg_tree_t * cfg, 
+                                           void * private_data, 
+                                           void ** push_fn_arg), 
+                            void * priv_data)
+{
+    struct char_frontend * frontend = NULL;
+
+    frontend = (struct char_frontend *)V3_Malloc(sizeof(struct char_frontend));
+    memset(frontend, 0, sizeof(struct char_frontend));
+    
+    frontend->connect = connect;
+    frontend->priv_data = priv_data;
+       
+    list_add(&(frontend->char_node), &(vm->dev_mgr.char_list));
+    v3_htable_insert(vm->dev_mgr.char_table, (addr_t)(name), (addr_t)frontend);
+
+    return 0;
+}
+
+
+int v3_dev_connect_char(struct v3_vm_info * vm, 
+                       char * frontend_name, 
+                       struct v3_dev_char_ops * ops, 
+                       v3_cfg_tree_t * cfg, 
+                       void * private_data, 
+                       void ** push_fn_arg)
+{
+    struct char_frontend * frontend = NULL;
+
+    frontend = (struct char_frontend *)v3_htable_search(vm->dev_mgr.char_table,
+                                                       (addr_t)frontend_name);
+    
+    if (frontend == NULL) {
+       PrintError("Could not find frontend char device %s\n", frontend_name);
+       return 0;
+    }
+    
+    if (frontend->connect(vm, frontend->priv_data, ops, cfg, private_data, push_fn_arg) == -1) {
+       PrintError("Error connecting to char frontend %s\n", frontend_name);
+       return -1;
+    }
+
+    return 0;
+}
+
index f9fe479..c7a2e51 100644 (file)
@@ -23,6 +23,7 @@
 #include <palacios/vmm_types.h>
 
 #include <palacios/vmm_stream.h>
+#include <palacios/vm_guest.h>
 
 static struct v3_stream_hooks * stream_hooks = NULL;
 
@@ -31,7 +32,7 @@ v3_stream_t v3_stream_open(struct v3_vm_info * vm, const char * name) {
     V3_ASSERT(stream_hooks != NULL);
     V3_ASSERT(stream_hooks->open != NULL);
 
-    return stream_hooks->open(name, vm->host_private_data);
+    return stream_hooks->open(name, vm->host_priv_data);
 }
 
 int v3_stream_write(v3_stream_t stream, uint8_t * buf, uint32_t len) {