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