7d37435bd5
Most files that have TABs only contain a handful of them. Change them to spaces so that we don't confuse people. disas, standard-headers, linux-headers and libdecnumber are imported from other projects and probably should be exempted from the check. Outside those, after this patch the following files still contain both 8-space and TAB sequences at the beginning of the line. Many of them have a majority of TABs, or were initially committed with all tabs. bsd-user/i386/target_syscall.h bsd-user/x86_64/target_syscall.h crypto/aes.c hw/audio/fmopl.c hw/audio/fmopl.h hw/block/tc58128.c hw/display/cirrus_vga.c hw/display/xenfb.c hw/dma/etraxfs_dma.c hw/intc/sh_intc.c hw/misc/mst_fpga.c hw/net/pcnet.c hw/sh4/sh7750.c hw/timer/m48t59.c hw/timer/sh_timer.c include/crypto/aes.h include/disas/bfd.h include/hw/sh4/sh.h libdecnumber/decNumber.c linux-headers/asm-generic/unistd.h linux-headers/linux/kvm.h linux-user/alpha/target_syscall.h linux-user/arm/nwfpe/double_cpdo.c linux-user/arm/nwfpe/fpa11_cpdt.c linux-user/arm/nwfpe/fpa11_cprt.c linux-user/arm/nwfpe/fpa11.h linux-user/flat.h linux-user/flatload.c linux-user/i386/target_syscall.h linux-user/ppc/target_syscall.h linux-user/sparc/target_syscall.h linux-user/syscall.c linux-user/syscall_defs.h linux-user/x86_64/target_syscall.h slirp/cksum.c slirp/if.c slirp/ip.h slirp/ip_icmp.c slirp/ip_icmp.h slirp/ip_input.c slirp/ip_output.c slirp/mbuf.c slirp/misc.c slirp/sbuf.c slirp/socket.c slirp/socket.h slirp/tcp_input.c slirp/tcpip.h slirp/tcp_output.c slirp/tcp_subr.c slirp/tcp_timer.c slirp/tftp.c slirp/udp.c slirp/udp.h target/cris/cpu.h target/cris/mmu.c target/cris/op_helper.c target/sh4/helper.c target/sh4/op_helper.c target/sh4/translate.c tcg/sparc/tcg-target.inc.c tests/tcg/cris/check_addo.c tests/tcg/cris/check_moveq.c tests/tcg/cris/check_swap.c tests/tcg/multiarch/test-mmap.c ui/vnc-enc-hextile-template.h ui/vnc-enc-zywrle.h util/envlist.c util/readline.c The following have only TABs: bsd-user/i386/target_signal.h bsd-user/sparc64/target_signal.h bsd-user/sparc64/target_syscall.h bsd-user/sparc/target_signal.h bsd-user/sparc/target_syscall.h bsd-user/x86_64/target_signal.h crypto/desrfb.c hw/audio/intel-hda-defs.h hw/core/uboot_image.h hw/sh4/sh7750_regnames.c hw/sh4/sh7750_regs.h include/hw/cris/etraxfs_dma.h linux-user/alpha/termbits.h linux-user/arm/nwfpe/fpopcode.h linux-user/arm/nwfpe/fpsr.h linux-user/arm/syscall_nr.h linux-user/arm/target_signal.h linux-user/cris/target_signal.h linux-user/i386/target_signal.h linux-user/linux_loop.h linux-user/m68k/target_signal.h linux-user/microblaze/target_signal.h linux-user/mips64/target_signal.h linux-user/mips/target_signal.h linux-user/mips/target_syscall.h linux-user/mips/termbits.h linux-user/ppc/target_signal.h linux-user/sh4/target_signal.h linux-user/sh4/termbits.h linux-user/sparc64/target_syscall.h linux-user/sparc/target_signal.h linux-user/x86_64/target_signal.h linux-user/x86_64/termbits.h pc-bios/optionrom/optionrom.h slirp/mbuf.h slirp/misc.h slirp/sbuf.h slirp/tcp.h slirp/tcp_timer.h slirp/tcp_var.h target/i386/svm.h target/sparc/asi.h target/xtensa/core-dc232b/xtensa-modules.inc.c target/xtensa/core-dc233c/xtensa-modules.inc.c target/xtensa/core-de212/core-isa.h target/xtensa/core-de212/xtensa-modules.inc.c target/xtensa/core-fsf/xtensa-modules.inc.c target/xtensa/core-sample_controller/core-isa.h target/xtensa/core-sample_controller/xtensa-modules.inc.c target/xtensa/core-test_kc705_be/core-isa.h target/xtensa/core-test_kc705_be/xtensa-modules.inc.c tests/tcg/cris/check_abs.c tests/tcg/cris/check_addc.c tests/tcg/cris/check_addcm.c tests/tcg/cris/check_addoq.c tests/tcg/cris/check_bound.c tests/tcg/cris/check_ftag.c tests/tcg/cris/check_int64.c tests/tcg/cris/check_lz.c tests/tcg/cris/check_openpf5.c tests/tcg/cris/check_sigalrm.c tests/tcg/cris/crisutils.h tests/tcg/cris/sys.c tests/tcg/i386/test-i386-ssse3.c ui/vgafont.h Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20181213223737.11793-3-pbonzini@redhat.com> Reviewed-by: Aleksandar Markovic <amarkovic@wavecomp.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> Acked-by: Richard Henderson <richard.henderson@linaro.org> Acked-by: Eric Blake <eblake@redhat.com> Acked-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Stefan Markovic <smarkovic@wavecomp.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
298 lines
8.5 KiB
C
298 lines
8.5 KiB
C
/*
|
|
* Copyright (C) International Business Machines Corp., 2005
|
|
* Author(s): Anthony Liguori <aliguori@us.ibm.com>
|
|
*
|
|
* Copyright (C) Red Hat 2007
|
|
*
|
|
* Xen Console
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; under version 2 of the License.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include <sys/select.h>
|
|
#include <termios.h>
|
|
|
|
#include "qapi/error.h"
|
|
#include "hw/hw.h"
|
|
#include "chardev/char-fe.h"
|
|
#include "hw/xen/xen_backend.h"
|
|
|
|
#include <xen/io/console.h>
|
|
|
|
struct buffer {
|
|
uint8_t *data;
|
|
size_t consumed;
|
|
size_t size;
|
|
size_t capacity;
|
|
size_t max_capacity;
|
|
};
|
|
|
|
struct XenConsole {
|
|
struct XenDevice xendev; /* must be first */
|
|
struct buffer buffer;
|
|
char console[XEN_BUFSIZE];
|
|
int ring_ref;
|
|
void *sring;
|
|
CharBackend chr;
|
|
int backlog;
|
|
};
|
|
|
|
static void buffer_append(struct XenConsole *con)
|
|
{
|
|
struct buffer *buffer = &con->buffer;
|
|
XENCONS_RING_IDX cons, prod, size;
|
|
struct xencons_interface *intf = con->sring;
|
|
|
|
cons = intf->out_cons;
|
|
prod = intf->out_prod;
|
|
xen_mb();
|
|
|
|
size = prod - cons;
|
|
if ((size == 0) || (size > sizeof(intf->out)))
|
|
return;
|
|
|
|
if ((buffer->capacity - buffer->size) < size) {
|
|
buffer->capacity += (size + 1024);
|
|
buffer->data = g_realloc(buffer->data, buffer->capacity);
|
|
}
|
|
|
|
while (cons != prod)
|
|
buffer->data[buffer->size++] = intf->out[
|
|
MASK_XENCONS_IDX(cons++, intf->out)];
|
|
|
|
xen_mb();
|
|
intf->out_cons = cons;
|
|
xen_pv_send_notify(&con->xendev);
|
|
|
|
if (buffer->max_capacity &&
|
|
buffer->size > buffer->max_capacity) {
|
|
/* Discard the middle of the data. */
|
|
|
|
size_t over = buffer->size - buffer->max_capacity;
|
|
uint8_t *maxpos = buffer->data + buffer->max_capacity;
|
|
|
|
memmove(maxpos - over, maxpos, over);
|
|
buffer->data = g_realloc(buffer->data, buffer->max_capacity);
|
|
buffer->size = buffer->capacity = buffer->max_capacity;
|
|
|
|
if (buffer->consumed > buffer->max_capacity - over)
|
|
buffer->consumed = buffer->max_capacity - over;
|
|
}
|
|
}
|
|
|
|
static void buffer_advance(struct buffer *buffer, size_t len)
|
|
{
|
|
buffer->consumed += len;
|
|
if (buffer->consumed == buffer->size) {
|
|
buffer->consumed = 0;
|
|
buffer->size = 0;
|
|
}
|
|
}
|
|
|
|
static int ring_free_bytes(struct XenConsole *con)
|
|
{
|
|
struct xencons_interface *intf = con->sring;
|
|
XENCONS_RING_IDX cons, prod, space;
|
|
|
|
cons = intf->in_cons;
|
|
prod = intf->in_prod;
|
|
xen_mb();
|
|
|
|
space = prod - cons;
|
|
if (space > sizeof(intf->in))
|
|
return 0; /* ring is screwed: ignore it */
|
|
|
|
return (sizeof(intf->in) - space);
|
|
}
|
|
|
|
static int xencons_can_receive(void *opaque)
|
|
{
|
|
struct XenConsole *con = opaque;
|
|
return ring_free_bytes(con);
|
|
}
|
|
|
|
static void xencons_receive(void *opaque, const uint8_t *buf, int len)
|
|
{
|
|
struct XenConsole *con = opaque;
|
|
struct xencons_interface *intf = con->sring;
|
|
XENCONS_RING_IDX prod;
|
|
int i, max;
|
|
|
|
max = ring_free_bytes(con);
|
|
/* The can_receive() func limits this, but check again anyway */
|
|
if (max < len)
|
|
len = max;
|
|
|
|
prod = intf->in_prod;
|
|
for (i = 0; i < len; i++) {
|
|
intf->in[MASK_XENCONS_IDX(prod++, intf->in)] =
|
|
buf[i];
|
|
}
|
|
xen_wmb();
|
|
intf->in_prod = prod;
|
|
xen_pv_send_notify(&con->xendev);
|
|
}
|
|
|
|
static void xencons_send(struct XenConsole *con)
|
|
{
|
|
ssize_t len, size;
|
|
|
|
size = con->buffer.size - con->buffer.consumed;
|
|
if (qemu_chr_fe_backend_connected(&con->chr)) {
|
|
len = qemu_chr_fe_write(&con->chr,
|
|
con->buffer.data + con->buffer.consumed,
|
|
size);
|
|
} else {
|
|
len = size;
|
|
}
|
|
if (len < 1) {
|
|
if (!con->backlog) {
|
|
con->backlog = 1;
|
|
xen_pv_printf(&con->xendev, 1,
|
|
"backlog piling up, nobody listening?\n");
|
|
}
|
|
} else {
|
|
buffer_advance(&con->buffer, len);
|
|
if (con->backlog && len == size) {
|
|
con->backlog = 0;
|
|
xen_pv_printf(&con->xendev, 1, "backlog is gone\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
static int con_init(struct XenDevice *xendev)
|
|
{
|
|
struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
|
|
char *type, *dom, label[32];
|
|
int ret = 0;
|
|
const char *output;
|
|
|
|
/* setup */
|
|
dom = xs_get_domain_path(xenstore, con->xendev.dom);
|
|
if (!xendev->dev) {
|
|
snprintf(con->console, sizeof(con->console), "%s/console", dom);
|
|
} else {
|
|
snprintf(con->console, sizeof(con->console), "%s/device/console/%d", dom, xendev->dev);
|
|
}
|
|
free(dom);
|
|
|
|
type = xenstore_read_str(con->console, "type");
|
|
if (!type || strcmp(type, "ioemu") != 0) {
|
|
xen_pv_printf(xendev, 1, "not for me (type=%s)\n", type);
|
|
ret = -1;
|
|
goto out;
|
|
}
|
|
|
|
output = xenstore_read_str(con->console, "output");
|
|
|
|
/* no Xen override, use qemu output device */
|
|
if (output == NULL) {
|
|
if (con->xendev.dev) {
|
|
qemu_chr_fe_init(&con->chr, serial_hd(con->xendev.dev),
|
|
&error_abort);
|
|
}
|
|
} else {
|
|
snprintf(label, sizeof(label), "xencons%d", con->xendev.dev);
|
|
qemu_chr_fe_init(&con->chr,
|
|
/*
|
|
* FIXME: sure we want to support implicit
|
|
* muxed monitors here?
|
|
*/
|
|
qemu_chr_new_mux_mon(label, output), &error_abort);
|
|
}
|
|
|
|
xenstore_store_pv_console_info(con->xendev.dev,
|
|
qemu_chr_fe_get_driver(&con->chr));
|
|
|
|
out:
|
|
g_free(type);
|
|
return ret;
|
|
}
|
|
|
|
static int con_initialise(struct XenDevice *xendev)
|
|
{
|
|
struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
|
|
int limit;
|
|
|
|
if (xenstore_read_int(con->console, "ring-ref", &con->ring_ref) == -1)
|
|
return -1;
|
|
if (xenstore_read_int(con->console, "port", &con->xendev.remote_port) == -1)
|
|
return -1;
|
|
if (xenstore_read_int(con->console, "limit", &limit) == 0)
|
|
con->buffer.max_capacity = limit;
|
|
|
|
if (!xendev->dev) {
|
|
xen_pfn_t mfn = con->ring_ref;
|
|
con->sring = xenforeignmemory_map(xen_fmem, con->xendev.dom,
|
|
PROT_READ | PROT_WRITE,
|
|
1, &mfn, NULL);
|
|
} else {
|
|
con->sring = xen_be_map_grant_ref(xendev, con->ring_ref,
|
|
PROT_READ | PROT_WRITE);
|
|
}
|
|
if (!con->sring)
|
|
return -1;
|
|
|
|
xen_be_bind_evtchn(&con->xendev);
|
|
qemu_chr_fe_set_handlers(&con->chr, xencons_can_receive,
|
|
xencons_receive, NULL, NULL, con, NULL, true);
|
|
|
|
xen_pv_printf(xendev, 1,
|
|
"ring mfn %d, remote port %d, local port %d, limit %zd\n",
|
|
con->ring_ref,
|
|
con->xendev.remote_port,
|
|
con->xendev.local_port,
|
|
con->buffer.max_capacity);
|
|
return 0;
|
|
}
|
|
|
|
static void con_disconnect(struct XenDevice *xendev)
|
|
{
|
|
struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
|
|
|
|
qemu_chr_fe_deinit(&con->chr, false);
|
|
xen_pv_unbind_evtchn(&con->xendev);
|
|
|
|
if (con->sring) {
|
|
if (!xendev->dev) {
|
|
xenforeignmemory_unmap(xen_fmem, con->sring, 1);
|
|
} else {
|
|
xen_be_unmap_grant_ref(xendev, con->sring);
|
|
}
|
|
con->sring = NULL;
|
|
}
|
|
}
|
|
|
|
static void con_event(struct XenDevice *xendev)
|
|
{
|
|
struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
|
|
|
|
buffer_append(con);
|
|
if (con->buffer.size - con->buffer.consumed)
|
|
xencons_send(con);
|
|
}
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
struct XenDevOps xen_console_ops = {
|
|
.size = sizeof(struct XenConsole),
|
|
.flags = DEVOPS_FLAG_IGNORE_STATE|DEVOPS_FLAG_NEED_GNTDEV,
|
|
.init = con_init,
|
|
.initialise = con_initialise,
|
|
.event = con_event,
|
|
.disconnect = con_disconnect,
|
|
};
|