uvtd: vt: implement VT_GETMODE/SETMODE ioctl state-tracking
[platform/upstream/kmscon.git] / src / uvt_internal.h
1 /*
2  * UVT - Userspace Virtual Terminals
3  *
4  * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@gmail.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files
8  * (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 /*
27  * Userspace Virtual Terminals Internals
28  * Internal header of the UVT implementation.
29  */
30
31 #ifndef UVT_INTERNAL_H
32 #define UVT_INTERNAL_H
33
34 #include <eloop.h>
35 #include <stdlib.h>
36 #include <uvt.h>
37 #include "shl_array.h"
38 #include "shl_dlist.h"
39 #include "shl_hook.h"
40 #include "shl_llog.h"
41
42 #include <fuse/fuse.h>
43 #include <fuse/fuse_common.h>
44 #include <fuse/fuse_lowlevel.h>
45 #include <fuse/fuse_opt.h>
46 #include <fuse/cuse_lowlevel.h>
47
48 /* contexts */
49
50 struct uvt_ctx {
51         unsigned long ref;
52         llog_submit_t llog;
53         void *llog_data;
54         struct ev_eloop *eloop;
55
56         char *cuse_file;
57         unsigned int major;
58         unsigned int minor_offset;
59         struct shl_array *minors;
60 };
61
62 /* character devices */
63
64 struct uvt_cdev {
65         unsigned long ref;
66         struct uvt_ctx *ctx;
67         llog_submit_t llog;
68         void *llog_data;
69
70         int error;
71         struct shl_hook *hook;
72
73         struct fuse_session *session;
74         int fd;
75         struct fuse_chan *channel;
76         struct ev_fd *efd;
77
78         size_t bufsize;
79         char *buf;
80
81         struct shl_dlist clients;
82 };
83
84 /* client sessions */
85
86 struct uvt_client {
87         unsigned long ref;
88         struct shl_dlist list;
89         struct uvt_cdev *cdev;
90         llog_submit_t llog;
91         void *llog_data;
92
93         struct fuse_pollhandle *ph;
94         struct shl_dlist waiters;
95
96         const struct uvt_vt_ops *vt;
97         void *vt_data;
98         bool vt_locked;
99         bool vt_in_unlock;
100         unsigned int vt_retry;
101 };
102
103 void uvt_client_cleanup(struct uvt_client *client);
104
105 int uvt_client_ll_open(struct uvt_client **out, struct uvt_cdev *cdev,
106                        fuse_req_t req, struct fuse_file_info *fi);
107 void uvt_client_ll_release(fuse_req_t req, struct fuse_file_info *fi);
108 void uvt_client_ll_read(fuse_req_t req, size_t size, off_t off,
109                         struct fuse_file_info *fi);
110 void uvt_client_ll_write(fuse_req_t req, const char *buf, size_t size,
111                          off_t off, struct fuse_file_info *fi);
112 void uvt_client_ll_poll(fuse_req_t req, struct fuse_file_info *fi,
113                         struct fuse_pollhandle *ph);
114 void uvt_client_ll_ioctl(fuse_req_t req, int cmd, void *arg,
115                          struct fuse_file_info *fi, unsigned int flags,
116                          const void *in_buf, size_t in_bufsz, size_t out_bufsz);
117
118 #endif /* UVT_INTERNAL_H */