Commit cb8b8ef4 authored by Peter Maydell's avatar Peter Maydell

Merge remote-tracking branch 'remotes/elmarco/tags/chrfe-pull-request' into staging

# gpg: Signature made Fri 02 Jun 2017 20:12:48 BST
# gpg:                using RSA key 0xDAE8E10975969CE5
# gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>"
# gpg:                 aka "Marc-André Lureau <marcandre.lureau@gmail.com>"
# gpg: WARNING: This key is not certified with sufficiently trusted signatures!
# gpg:          It is not certain that the signature belongs to the owner.
# Primary key fingerprint: 87A9 BD93 3F87 C606 D276  F62D DAE8 E109 7596 9CE5

* remotes/elmarco/tags/chrfe-pull-request:
  char: move char devices to chardev/
  char: make chr_fe_deinit() optionaly delete backend
  char: rename functions that are not part of fe
  char: move CharBackend handling in char-fe unit
  char: generalize qemu_chr_write_all()
  be-hci: use backend functions
  chardev: serial & parallel declaration to own headers
  chardev: move headers to include/chardev
  Remove/replace sysemu/char.h inclusion
  char-win: close file handle except with console
  char-win: rename hcom->file
  char-win: rename win_chr_init/poll win_chr_serial_init/poll
  char-win: remove WinChardev.len
  char-win: simplify win_chr_read()
  char: cast ARRAY_SIZE() as signed to silent warning on empty array
Signed-off-by: 's avatarPeter Maydell <peter.maydell@linaro.org>
parents c6e84fbd 6b10e573
......@@ -1238,13 +1238,12 @@ M: Paolo Bonzini <pbonzini@redhat.com>
M: Marc-André Lureau <marcandre.lureau@redhat.com>
S: Maintained
F: chardev/
F: backends/msmouse.c
F: backends/testdev.c
F: include/chardev/
Character Devices (Braille)
M: Samuel Thibault <samuel.thibault@ens-lyon.org>
S: Maintained
F: backends/baum.c
F: chardev/baum.c
Command line option argument parsing
M: Markus Armbruster <armbru@redhat.com>
......
......@@ -50,8 +50,6 @@ common-obj-$(CONFIG_LINUX) += fsdev/
common-obj-y += migration/
common-obj-$(CONFIG_SPICE) += spice-qemu-char.o
common-obj-y += audio/
common-obj-y += hw/
common-obj-y += accel.o
......@@ -70,6 +68,7 @@ common-obj-y += tpm.o
common-obj-$(CONFIG_SLIRP) += slirp/
common-obj-y += backends/
common-obj-y += chardev/
common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o
......@@ -121,6 +120,7 @@ trace-events-subdirs += io
trace-events-subdirs += migration
trace-events-subdirs += block
trace-events-subdirs += backends
trace-events-subdirs += chardev
trace-events-subdirs += hw/block
trace-events-subdirs += hw/block/dataplane
trace-events-subdirs += hw/char
......
common-obj-y += rng.o rng-egd.o
common-obj-$(CONFIG_POSIX) += rng-random.o
common-obj-y += msmouse.o wctablet.o testdev.o
common-obj-$(CONFIG_BRLAPI) += baum.o
baum.o-cflags := $(SDL_CFLAGS)
common-obj-$(CONFIG_TPM) += tpm.o
common-obj-y += hostmem.o hostmem-ram.o
......
......@@ -12,7 +12,7 @@
#include "qemu/osdep.h"
#include "sysemu/rng.h"
#include "sysemu/char.h"
#include "chardev/char-fe.h"
#include "qapi/error.h"
#include "qapi/qmp/qerror.h"
......@@ -145,7 +145,7 @@ static void rng_egd_finalize(Object *obj)
{
RngEgd *s = RNG_EGD(obj);
qemu_chr_fe_deinit(&s->chr);
qemu_chr_fe_deinit(&s->chr, false);
g_free(s->chr_name);
}
......
# See docs/tracing.txt for syntax documentation.
# backends/wctablet.c
wct_init(void) ""
wct_cmd_re(void) ""
wct_cmd_st(void) ""
wct_cmd_sp(void) ""
wct_cmd_ts(int input) "0x%02x"
wct_cmd_other(const char *cmd) "%s"
wct_speed(int speed) "%d"
chardev-obj-y += char.o
chardev-obj-$(CONFIG_WIN32) += char-console.o
chardev-obj-$(CONFIG_POSIX) += char-fd.o
chardev-obj-y += char-fe.o
chardev-obj-y += char-file.o
chardev-obj-y += char-io.o
chardev-obj-y += char-mux.o
......@@ -15,3 +16,9 @@ chardev-obj-y += char-stdio.o
chardev-obj-y += char-udp.o
chardev-obj-$(CONFIG_WIN32) += char-win.o
chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
common-obj-y += msmouse.o wctablet.o testdev.o
common-obj-$(CONFIG_BRLAPI) += baum.o
baum.o-cflags := $(SDL_CFLAGS)
common-obj-$(CONFIG_SPICE) += spice.o
......@@ -24,7 +24,7 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qemu-common.h"
#include "sysemu/char.h"
#include "chardev/char.h"
#include "qemu/timer.h"
#include "hw/usb.h"
#include "ui/console.h"
......
......@@ -22,14 +22,14 @@
* THE SOFTWARE.
*/
#include "qemu/osdep.h"
#include "char-win.h"
#include "chardev/char-win.h"
static void qemu_chr_open_win_con(Chardev *chr,
ChardevBackend *backend,
bool *be_opened,
Error **errp)
{
qemu_chr_open_win_file(chr, GetStdHandle(STD_OUTPUT_HANDLE));
win_chr_set_file(chr, GetStdHandle(STD_OUTPUT_HANDLE), true);
}
static void char_console_class_init(ObjectClass *oc, void *data)
......
......@@ -25,11 +25,11 @@
#include "qemu/sockets.h"
#include "qapi/error.h"
#include "qemu-common.h"
#include "sysemu/char.h"
#include "chardev/char.h"
#include "io/channel-file.h"
#include "char-fd.h"
#include "char-io.h"
#include "chardev/char-fd.h"
#include "chardev/char-io.h"
/* Called with chr_write_lock held. */
static int fd_chr_write(Chardev *chr, const uint8_t *buf, int len)
......
/*
* QEMU System Emulator
*
* Copyright (c) 2003-2008 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "qemu/osdep.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
#include "qapi-visit.h"
#include "sysemu/replay.h"
#include "chardev/char-fe.h"
#include "chardev/char-io.h"
#include "chardev/char-mux.h"
int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len)
{
Chardev *s = be->chr;
if (!s) {
return 0;
}
return qemu_chr_write(s, buf, len, false);
}
int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len)
{
Chardev *s = be->chr;
if (!s) {
return 0;
}
return qemu_chr_write(s, buf, len, true);
}
int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len)
{
Chardev *s = be->chr;
int offset = 0, counter = 10;
int res;
if (!s || !CHARDEV_GET_CLASS(s)->chr_sync_read) {
return 0;
}
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) {
return replay_char_read_all_load(buf);
}
while (offset < len) {
retry:
res = CHARDEV_GET_CLASS(s)->chr_sync_read(s, buf + offset,
len - offset);
if (res == -1 && errno == EAGAIN) {
g_usleep(100);
goto retry;
}
if (res == 0) {
break;
}
if (res < 0) {
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
replay_char_read_all_save_error(res);
}
return res;
}
offset += res;
if (!counter--) {
break;
}
}
if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) {
replay_char_read_all_save_buf(buf, offset);
}
return offset;
}
int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg)
{
Chardev *s = be->chr;
int res;
if (!s || !CHARDEV_GET_CLASS(s)->chr_ioctl || qemu_chr_replay(s)) {
res = -ENOTSUP;
} else {
res = CHARDEV_GET_CLASS(s)->chr_ioctl(s, cmd, arg);
}
return res;
}
int qemu_chr_fe_get_msgfd(CharBackend *be)
{
Chardev *s = be->chr;
int fd;
int res = (qemu_chr_fe_get_msgfds(be, &fd, 1) == 1) ? fd : -1;
if (s && qemu_chr_replay(s)) {
error_report("Replay: get msgfd is not supported "
"for serial devices yet");
exit(1);
}
return res;
}
int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int len)
{
Chardev *s = be->chr;
if (!s) {
return -1;
}
return CHARDEV_GET_CLASS(s)->get_msgfds ?
CHARDEV_GET_CLASS(s)->get_msgfds(s, fds, len) : -1;
}
int qemu_chr_fe_set_msgfds(CharBackend *be, int *fds, int num)
{
Chardev *s = be->chr;
if (!s) {
return -1;
}
return CHARDEV_GET_CLASS(s)->set_msgfds ?
CHARDEV_GET_CLASS(s)->set_msgfds(s, fds, num) : -1;
}
void qemu_chr_fe_accept_input(CharBackend *be)
{
Chardev *s = be->chr;
if (!s) {
return;
}
if (CHARDEV_GET_CLASS(s)->chr_accept_input) {
CHARDEV_GET_CLASS(s)->chr_accept_input(s);
}
qemu_notify_event();
}
void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...)
{
char buf[CHR_READ_BUF_LEN];
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
/* XXX this blocks entire thread. Rewrite to use
* qemu_chr_fe_write and background I/O callbacks */
qemu_chr_fe_write_all(be, (uint8_t *)buf, strlen(buf));
va_end(ap);
}
Chardev *qemu_chr_fe_get_driver(CharBackend *be)
{
return be->chr;
}
bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
{
int tag = 0;
if (CHARDEV_IS_MUX(s)) {
MuxChardev *d = MUX_CHARDEV(s);
if (d->mux_cnt >= MAX_MUX) {
goto unavailable;
}
d->backends[d->mux_cnt] = b;
tag = d->mux_cnt++;
} else if (s->be) {
goto unavailable;
} else {
s->be = b;
}
b->fe_open = false;
b->tag = tag;
b->chr = s;
return true;
unavailable:
error_setg(errp, QERR_DEVICE_IN_USE, s->label);
return false;
}
void qemu_chr_fe_deinit(CharBackend *b, bool del)
{
assert(b);
if (b->chr) {
qemu_chr_fe_set_handlers(b, NULL, NULL, NULL, NULL, NULL, true);
if (b->chr->be == b) {
b->chr->be = NULL;
}
if (CHARDEV_IS_MUX(b->chr)) {
MuxChardev *d = MUX_CHARDEV(b->chr);
d->backends[b->tag] = NULL;
}
if (del) {
object_unparent(OBJECT(b->chr));
}
b->chr = NULL;
}
}
void qemu_chr_fe_set_handlers(CharBackend *b,
IOCanReadHandler *fd_can_read,
IOReadHandler *fd_read,
IOEventHandler *fd_event,
void *opaque,
GMainContext *context,
bool set_open)
{
Chardev *s;
ChardevClass *cc;
int fe_open;
s = b->chr;
if (!s) {
return;
}
cc = CHARDEV_GET_CLASS(s);
if (!opaque && !fd_can_read && !fd_read && !fd_event) {
fe_open = 0;
remove_fd_in_watch(s);
} else {
fe_open = 1;
}
b->chr_can_read = fd_can_read;
b->chr_read = fd_read;
b->chr_event = fd_event;
b->opaque = opaque;
if (cc->chr_update_read_handler) {
cc->chr_update_read_handler(s, context);
}
if (set_open) {
qemu_chr_fe_set_open(b, fe_open);
}
if (fe_open) {
qemu_chr_fe_take_focus(b);
/* We're connecting to an already opened device, so let's make sure we
also get the open event */
if (s->be_open) {
qemu_chr_be_event(s, CHR_EVENT_OPENED);
}
}
if (CHARDEV_IS_MUX(s)) {
mux_chr_set_handlers(s, context);
}
}
void qemu_chr_fe_take_focus(CharBackend *b)
{
if (!b->chr) {
return;
}
if (CHARDEV_IS_MUX(b->chr)) {
mux_set_focus(b->chr, b->tag);
}
}
int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp)
{
if (!be->chr) {
error_setg(errp, "missing associated backend");
return -1;
}
return qemu_chr_wait_connected(be->chr, errp);
}
void qemu_chr_fe_set_echo(CharBackend *be, bool echo)
{
Chardev *chr = be->chr;
if (chr && CHARDEV_GET_CLASS(chr)->chr_set_echo) {
CHARDEV_GET_CLASS(chr)->chr_set_echo(chr, echo);
}
}
void qemu_chr_fe_set_open(CharBackend *be, int fe_open)
{
Chardev *chr = be->chr;
if (!chr) {
return;
}
if (be->fe_open == fe_open) {
return;
}
be->fe_open = fe_open;
if (CHARDEV_GET_CLASS(chr)->chr_set_fe_open) {
CHARDEV_GET_CLASS(chr)->chr_set_fe_open(chr, fe_open);
}
}
guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond,
GIOFunc func, void *user_data)
{
Chardev *s = be->chr;
GSource *src;
guint tag;
if (!s || CHARDEV_GET_CLASS(s)->chr_add_watch == NULL) {
return 0;
}
src = CHARDEV_GET_CLASS(s)->chr_add_watch(s, cond);
if (!src) {
return 0;
}
g_source_set_callback(src, (GSourceFunc)func, user_data, NULL);
tag = g_source_attach(src, NULL);
g_source_unref(src);
return tag;
}
void qemu_chr_fe_disconnect(CharBackend *be)
{
Chardev *chr = be->chr;
if (chr && CHARDEV_GET_CLASS(chr)->chr_disconnect) {
CHARDEV_GET_CLASS(chr)->chr_disconnect(chr);
}
}
......@@ -24,12 +24,12 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qemu-common.h"
#include "sysemu/char.h"
#include "chardev/char.h"
#ifdef _WIN32
#include "char-win.h"
#include "chardev/char-win.h"
#else
#include "char-fd.h"
#include "chardev/char-fd.h"
#endif
static void qmp_chardev_open_file(Chardev *chr,
......@@ -65,7 +65,7 @@ static void qmp_chardev_open_file(Chardev *chr,
return;
}
qemu_chr_open_win_file(chr, out);
win_chr_set_file(chr, out, false);
#else
int flags, in = -1, out;
......
......@@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
#include "qemu/osdep.h"
#include "char-io.h"
#include "chardev/char-io.h"
typedef struct IOWatchPoll {
GSource parent;
......
......@@ -24,9 +24,9 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qemu-common.h"
#include "sysemu/char.h"
#include "chardev/char.h"
#include "sysemu/block-backend.h"
#include "char-mux.h"
#include "chardev/char-mux.h"
/* MUX driver for serial I/O splitting */
......@@ -266,7 +266,7 @@ static void char_mux_finalize(Object *obj)
be->chr = NULL;
}
}
qemu_chr_fe_deinit(&d->chr);
qemu_chr_fe_deinit(&d->chr, false);
}
void mux_chr_set_handlers(Chardev *chr, GMainContext *context)
......
......@@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
#include "qemu/osdep.h"
#include "sysemu/char.h"
#include "chardev/char.h"
static void null_chr_open(Chardev *chr,
ChardevBackend *backend,
......
......@@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
#include "qemu/osdep.h"
#include "sysemu/char.h"
#include "chardev/char.h"
#include "qapi/error.h"
#include <sys/ioctl.h>
......@@ -41,8 +41,8 @@
#endif
#endif
#include "char-fd.h"
#include "char-parallel.h"
#include "chardev/char-fd.h"
#include "chardev/char-parallel.h"
#if defined(__linux__)
......
......@@ -23,12 +23,12 @@
*/
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "sysemu/char.h"
#include "chardev/char.h"
#ifdef _WIN32
#include "char-win.h"
#include "chardev/char-win.h"
#else
#include "char-fd.h"
#include "chardev/char-fd.h"
#endif
#ifdef _WIN32
......@@ -58,27 +58,27 @@ static int win_chr_pipe_init(Chardev *chr, const char *filename,
}
openname = g_strdup_printf("\\\\.\\pipe\\%s", filename);
s->hcom = CreateNamedPipe(openname,
s->file = CreateNamedPipe(openname,
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE |
PIPE_WAIT,
MAXCONNECT, NSENDBUF, NRECVBUF, NTIMEOUT, NULL);
g_free(openname);
if (s->hcom == INVALID_HANDLE_VALUE) {
if (s->file == INVALID_HANDLE_VALUE) {
error_setg(errp, "Failed CreateNamedPipe (%lu)", GetLastError());
s->hcom = NULL;
s->file = NULL;
goto fail;
}
ZeroMemory(&ov, sizeof(ov));
ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
ret = ConnectNamedPipe(s->hcom, &ov);
ret = ConnectNamedPipe(s->file, &ov);
if (ret) {
error_setg(errp, "Failed ConnectNamedPipe");
goto fail;
}
ret = GetOverlappedResult(s->hcom, &ov, &size, TRUE);
ret = GetOverlappedResult(s->file, &ov, &size, TRUE);
if (!ret) {
error_setg(errp, "Failed GetOverlappedResult");
if (ov.hEvent) {
......
......@@ -24,12 +24,12 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
#include "qemu-common.h"
#include "sysemu/char.h"
#include "chardev/char.h"
#include "io/channel-file.h"
#include "qemu/sockets.h"
#include "qemu/error-report.h"
#include "char-io.h"
#include "chardev/char-io.h"
#if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \
|| defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) \
......
......@@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
#include "qemu/osdep.h"
#include "sysemu/char.h"
#include "chardev/char.h"
#include "qmp-commands.h"
#include "qemu/base64.h"
......
......@@ -27,14 +27,14 @@
#include "qapi/error.h"
#ifdef _WIN32
#include "char-win.h"
#include "chardev/char-win.h"
#else
#include <sys/ioctl.h>
#include <termios.h>
#include "char-fd.h"
#include "chardev/char-fd.h"
#endif
#include "char-serial.h"
#include "chardev/char-serial.h"
#ifdef _WIN32
......@@ -45,7 +45,7 @@ static void qmp_chardev_open_serial(Chardev *chr,
{
ChardevHostdev *serial = backend->u.serial.data;
win_chr_init(chr, serial->device, errp);
win_chr_serial_init(chr, serial->device, errp);
}
#elif defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \
......
......@@ -22,14 +22,14 @@
* THE SOFTWARE.
*/
#include "qemu/osdep.h"
#include "sysemu/char.h"
#include "chardev/char.h"
#include "io/channel-socket.h"
#include "io/channel-tls.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
#include "qapi/clone-visitor.h"
#include "char-io.h"
#include "chardev/char-io.h"
/***********************************************************/