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.


path fixes
[palacios.git] / linux_module / palacios-serial.c
1 /* 
2  * VM Serial Controls
3  * (c) Lei Xia, 2010
4  */
5
6 #include <linux/device.h>
7 #include <linux/cdev.h>
8 #include <linux/errno.h>
9 #include <linux/fs.h>
10 #include <linux/uaccess.h>
11 #include <linux/poll.h>
12 #include <linux/anon_inodes.h>
13 #include <linux/file.h>
14
15 #include <palacios/vmm.h>
16 #include <palacios/vmm_host_events.h>
17
18 #include "palacios.h"
19 #include "palacios-stream.h"
20
21
22 void
23 send_serial_input_to_palacios( unsigned char *input,
24                                unsigned int len,
25                                struct v3_vm_info * vm ) {
26     struct v3_serial_event event;
27
28     if (len > 128) {
29         len = 128;
30     }
31
32     memcpy(event.data, input, len);
33     event.len = len;
34         
35     v3_deliver_serial_event(vm, &event);
36 }
37
38 static ssize_t 
39 serial_read(struct file * filp, char __user * buf, size_t size, loff_t * offset) {
40
41     int len = 0;
42     char temp[128];
43     struct stream_buffer * stream = filp->private_data;
44         
45     memset(temp, 0, 128);
46
47     if (size > 128) {
48         size = 128;
49     }
50         
51     len =  stream_dequeue(stream, temp, size);
52         
53     if (copy_to_user(buf, temp, len)) {
54         printk("Read fault\n");
55         return -EFAULT;
56     }
57
58     printk("Returning %d bytes\n", len);
59
60     return len;
61 }
62
63 static ssize_t 
64 serial_write(struct file * filp, const char __user * buf, size_t size, loff_t * offset) {
65     char temp[128];
66     struct stream_buffer * stream = filp->private_data;
67     struct v3_vm_info * vm;
68
69     memset(temp, 0, 128);
70
71     if (size > 128) {
72         size = 128;
73     }
74
75     if (copy_from_user(temp, buf, size)) {
76         printk("Write fault\n");
77         return -EFAULT;
78     }
79
80     vm = stream->guest->v3_ctx;
81     send_serial_input_to_palacios(temp, size, vm);
82    
83     return size;
84 }
85
86
87 static unsigned int 
88 serial_poll(struct file * filp, struct poll_table_struct * poll_tb) {
89     unsigned int mask = 0;
90     struct stream_buffer *stream = filp->private_data;
91   
92     poll_wait(filp, &(stream->intr_queue), poll_tb);
93
94     if(stream_datalen(stream) > 0){
95         mask = POLLIN | POLLRDNORM;
96     }
97         
98     printk("polling v3 serial\n");
99
100     return mask;
101 }
102
103 static struct file_operations v3_cons_fops = {
104     .read     = serial_read,
105     .write    = serial_write,
106     .poll     = serial_poll,
107 };
108
109
110 int open_serial(char * name) {
111     int cons_fd;
112     void *stream;
113
114     printk("open path: %s\n", name);
115
116     stream = find_stream_by_name(NULL, name);
117
118     if (stream == NULL) {
119         return -1;
120     }
121
122     cons_fd = anon_inode_getfd("v3-cons", &v3_cons_fops, stream, 0);
123     
124     if (cons_fd < 0) {
125         printk("Error creating serial inode\n");
126         return cons_fd;
127     }
128
129     printk("Returning new serial fd\n");
130             
131     return cons_fd;
132 }