xref: /qemu/chardev/chardev-internal.h (revision 30827bad3852fd85d86995e7ccab429679442889)
1df85a78bSMarc-André Lureau /*
2ffa0f7ebSPhilippe Mathieu-Daudé  * QEMU Character device internals
3df85a78bSMarc-André Lureau  *
4df85a78bSMarc-André Lureau  * Copyright (c) 2003-2008 Fabrice Bellard
5df85a78bSMarc-André Lureau  *
6df85a78bSMarc-André Lureau  * Permission is hereby granted, free of charge, to any person obtaining a copy
7df85a78bSMarc-André Lureau  * of this software and associated documentation files (the "Software"), to deal
8df85a78bSMarc-André Lureau  * in the Software without restriction, including without limitation the rights
9df85a78bSMarc-André Lureau  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10df85a78bSMarc-André Lureau  * copies of the Software, and to permit persons to whom the Software is
11df85a78bSMarc-André Lureau  * furnished to do so, subject to the following conditions:
12df85a78bSMarc-André Lureau  *
13df85a78bSMarc-André Lureau  * The above copyright notice and this permission notice shall be included in
14df85a78bSMarc-André Lureau  * all copies or substantial portions of the Software.
15df85a78bSMarc-André Lureau  *
16df85a78bSMarc-André Lureau  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17df85a78bSMarc-André Lureau  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18df85a78bSMarc-André Lureau  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19df85a78bSMarc-André Lureau  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20df85a78bSMarc-André Lureau  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21df85a78bSMarc-André Lureau  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22df85a78bSMarc-André Lureau  * THE SOFTWARE.
23df85a78bSMarc-André Lureau  */
24ffa0f7ebSPhilippe Mathieu-Daudé #ifndef CHARDEV_INTERNAL_H
25ffa0f7ebSPhilippe Mathieu-Daudé #define CHARDEV_INTERNAL_H
26df85a78bSMarc-André Lureau 
278228e353SMarc-André Lureau #include "chardev/char.h"
284d43a603SMarc-André Lureau #include "chardev/char-fe.h"
29*30827badSPhilippe Mathieu-Daudé #include "qom/object.h"
30df85a78bSMarc-André Lureau 
31df85a78bSMarc-André Lureau #define MAX_MUX 4
32df85a78bSMarc-André Lureau #define MUX_BUFFER_SIZE 32 /* Must be a power of 2.  */
33df85a78bSMarc-André Lureau #define MUX_BUFFER_MASK (MUX_BUFFER_SIZE - 1)
34ffa0f7ebSPhilippe Mathieu-Daudé 
35df85a78bSMarc-André Lureau typedef struct MuxChardev {
36df85a78bSMarc-André Lureau     Chardev parent;
37df85a78bSMarc-André Lureau     CharBackend *backends[MAX_MUX];
38df85a78bSMarc-André Lureau     CharBackend chr;
39df85a78bSMarc-André Lureau     int focus;
40df85a78bSMarc-André Lureau     int mux_cnt;
41df85a78bSMarc-André Lureau     int term_got_escape;
42df85a78bSMarc-André Lureau     int max_size;
43df85a78bSMarc-André Lureau     /* Intermediate input buffer catches escape sequences even if the
44df85a78bSMarc-André Lureau        currently active device is not accepting any input - but only until it
45df85a78bSMarc-André Lureau        is full as well. */
46df85a78bSMarc-André Lureau     unsigned char buffer[MAX_MUX][MUX_BUFFER_SIZE];
47df85a78bSMarc-André Lureau     int prod[MAX_MUX];
48df85a78bSMarc-André Lureau     int cons[MAX_MUX];
49df85a78bSMarc-André Lureau     int timestamps;
50df85a78bSMarc-André Lureau 
51df85a78bSMarc-André Lureau     /* Protected by the Chardev chr_write_lock.  */
52df85a78bSMarc-André Lureau     int linestart;
53df85a78bSMarc-André Lureau     int64_t timestamps_start;
54df85a78bSMarc-André Lureau } MuxChardev;
55df85a78bSMarc-André Lureau 
56df85a78bSMarc-André Lureau #define MUX_CHARDEV(obj) OBJECT_CHECK(MuxChardev, (obj), TYPE_CHARDEV_MUX)
57df85a78bSMarc-André Lureau #define CHARDEV_IS_MUX(chr)                             \
58df85a78bSMarc-André Lureau     object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_MUX)
59df85a78bSMarc-André Lureau 
60df85a78bSMarc-André Lureau void mux_set_focus(Chardev *chr, int focus);
612fa9044aSPaolo Bonzini void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event);
62df85a78bSMarc-André Lureau 
63*30827badSPhilippe Mathieu-Daudé Object *get_chardevs_root(void);
64*30827badSPhilippe Mathieu-Daudé 
65df85a78bSMarc-André Lureau #endif /* CHAR_MUX_H */
66