Skip to content

Commit

Permalink
char: remaining switch to CharBackend in frontend
Browse files Browse the repository at this point in the history
Similar to previous change, for the remaining CharDriverState front ends
users.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20161022095318.17775-13-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
elmarco authored and bonzini committed Oct 24, 2016
1 parent becdfa0 commit 32a6ebe
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 164 deletions.
29 changes: 16 additions & 13 deletions backends/rng-egd.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef struct RngEgd
{
RngBackend parent;

CharDriverState *chr;
CharBackend chr;
char *chr_name;
} RngEgd;

Expand All @@ -42,7 +42,7 @@ static void rng_egd_request_entropy(RngBackend *b, RngRequest *req)

/* XXX this blocks entire thread. Rewrite to use
* qemu_chr_fe_write and background I/O callbacks */
qemu_chr_fe_write_all(s->chr, header, sizeof(header));
qemu_chr_fe_write_all(s->chr.chr, header, sizeof(header));

size -= len;
}
Expand Down Expand Up @@ -86,28 +86,31 @@ static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size)
static void rng_egd_opened(RngBackend *b, Error **errp)
{
RngEgd *s = RNG_EGD(b);
CharDriverState *chr;

if (s->chr_name == NULL) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"chardev", "a valid character device");
return;
}

s->chr = qemu_chr_find(s->chr_name);
if (s->chr == NULL) {
chr = qemu_chr_find(s->chr_name);
if (chr == NULL) {
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", s->chr_name);
return;
}

if (qemu_chr_fe_claim(s->chr) != 0) {
if (qemu_chr_fe_claim(chr) != 0) {
error_setg(errp, QERR_DEVICE_IN_USE, s->chr_name);
return;
}
if (!qemu_chr_fe_init(&s->chr, chr, errp)) {
return;
}

/* FIXME we should resubmit pending requests when the CDS reconnects. */
qemu_chr_add_handlers(s->chr, rng_egd_chr_can_read, rng_egd_chr_read,
NULL, s);
qemu_chr_add_handlers(s->chr.chr, rng_egd_chr_can_read,
rng_egd_chr_read, NULL, s);
}

static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
Expand All @@ -127,8 +130,8 @@ static char *rng_egd_get_chardev(Object *obj, Error **errp)
{
RngEgd *s = RNG_EGD(obj);

if (s->chr && s->chr->label) {
return g_strdup(s->chr->label);
if (s->chr.chr && s->chr.chr->label) {
return g_strdup(s->chr.chr->label);
}

return NULL;
Expand All @@ -145,9 +148,9 @@ static void rng_egd_finalize(Object *obj)
{
RngEgd *s = RNG_EGD(obj);

if (s->chr) {
qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, NULL);
qemu_chr_fe_release(s->chr);
if (s->chr.chr) {
qemu_chr_add_handlers(s->chr.chr, NULL, NULL, NULL, NULL);
qemu_chr_fe_release(s->chr.chr);
}

g_free(s->chr_name);
Expand Down
22 changes: 13 additions & 9 deletions gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ typedef struct GDBState {
int fd;
int running_state;
#else
CharDriverState *chr;
CharBackend chr;
CharDriverState *mon_chr;
#endif
char syscall_buf[256];
Expand Down Expand Up @@ -404,7 +404,7 @@ static void put_buffer(GDBState *s, const uint8_t *buf, int len)
#else
/* XXX this blocks entire thread. Rewrite to use
* qemu_chr_fe_write and background I/O callbacks */
qemu_chr_fe_write_all(s->chr, buf, len);
qemu_chr_fe_write_all(s->chr.chr, buf, len);
#endif
}

Expand Down Expand Up @@ -1481,7 +1481,7 @@ void gdb_exit(CPUArchState *env, int code)
return;
}
#else
if (!s->chr) {
if (!s->chr.chr) {
return;
}
#endif
Expand All @@ -1490,7 +1490,7 @@ void gdb_exit(CPUArchState *env, int code)
put_packet(s, buf);

#ifndef CONFIG_USER_ONLY
qemu_chr_delete(s->chr);
qemu_chr_delete(s->chr.chr);
#endif
}

Expand Down Expand Up @@ -1750,8 +1750,6 @@ int gdbserver_start(const char *device)
return -1;

qemu_chr_fe_claim_no_fail(chr);
qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive,
gdb_chr_event, NULL);
}

s = gdbserver_state;
Expand All @@ -1766,14 +1764,20 @@ int gdbserver_start(const char *device)
mon_chr->chr_write = gdb_monitor_write;
monitor_init(mon_chr, 0);
} else {
if (s->chr)
qemu_chr_delete(s->chr);
if (s->chr.chr) {
qemu_chr_delete(s->chr.chr);
}
mon_chr = s->mon_chr;
memset(s, 0, sizeof(GDBState));
s->mon_chr = mon_chr;
}
s->c_cpu = first_cpu;
s->g_cpu = first_cpu;
s->chr = chr;
if (chr) {
qemu_chr_fe_init(&s->chr, chr, &error_abort);
qemu_chr_add_handlers(s->chr.chr, gdb_chr_can_receive, gdb_chr_receive,
gdb_chr_event, NULL);
}
s->state = chr ? RS_IDLE : RS_INACTIVE;
s->mon_chr = mon_chr;
s->current_syscall_cb = NULL;
Expand Down
11 changes: 6 additions & 5 deletions hw/arm/omap2.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ struct omap_sti_s {
qemu_irq irq;
MemoryRegion iomem;
MemoryRegion iomem_fifo;
CharDriverState *chr;
CharBackend chr;

uint32_t sysconfig;
uint32_t systest;
Expand Down Expand Up @@ -771,14 +771,14 @@ static void omap_sti_fifo_write(void *opaque, hwaddr addr,
/* Flush channel <i>value</i>. */
/* XXX this blocks entire thread. Rewrite to use
* qemu_chr_fe_write and background I/O callbacks */
qemu_chr_fe_write_all(s->chr, (const uint8_t *) "\r", 1);
qemu_chr_fe_write_all(s->chr.chr, (const uint8_t *) "\r", 1);
} else if (ch == STI_TRACE_CONSOLE_CHANNEL || 1) {
if (value == 0xc0 || value == 0xc3) {
/* Open channel <i>ch</i>. */
} else if (value == 0x00)
qemu_chr_fe_write_all(s->chr, (const uint8_t *) "\n", 1);
qemu_chr_fe_write_all(s->chr.chr, (const uint8_t *) "\n", 1);
else
qemu_chr_fe_write_all(s->chr, &byte, 1);
qemu_chr_fe_write_all(s->chr.chr, &byte, 1);
}
}

Expand All @@ -798,7 +798,8 @@ static struct omap_sti_s *omap_sti_init(struct omap_target_agent_s *ta,
s->irq = irq;
omap_sti_reset(s);

s->chr = chr ?: qemu_chr_new("null", "null");
qemu_chr_fe_init(&s->chr, chr ?: qemu_chr_new("null", "null"),
&error_abort);

memory_region_init_io(&s->iomem, NULL, &omap_sti_ops, s, "omap.sti",
omap_l4_region_size(ta, 0));
Expand Down
12 changes: 7 additions & 5 deletions hw/char/mcf_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "hw/m68k/mcf.h"
#include "sysemu/char.h"
#include "exec/address-spaces.h"
#include "qapi/error.h"

typedef struct {
MemoryRegion iomem;
Expand All @@ -26,7 +27,7 @@ typedef struct {
int tx_enabled;
int rx_enabled;
qemu_irq irq;
CharDriverState *chr;
CharBackend chr;
} mcf_uart_state;

/* UART Status Register bits. */
Expand Down Expand Up @@ -92,7 +93,7 @@ uint64_t mcf_uart_read(void *opaque, hwaddr addr,
if (s->fifo_len == 0)
s->sr &= ~MCF_UART_RxRDY;
mcf_uart_update(s);
qemu_chr_accept_input(s->chr);
qemu_chr_accept_input(s->chr.chr);
return val;
}
case 0x10:
Expand All @@ -113,10 +114,11 @@ uint64_t mcf_uart_read(void *opaque, hwaddr addr,
static void mcf_uart_do_tx(mcf_uart_state *s)
{
if (s->tx_enabled && (s->sr & MCF_UART_TxEMP) == 0) {
if (s->chr)
if (s->chr.chr) {
/* XXX this blocks entire thread. Rewrite to use
* qemu_chr_fe_write and background I/O callbacks */
qemu_chr_fe_write_all(s->chr, (unsigned char *)&s->tb, 1);
qemu_chr_fe_write_all(s->chr.chr, (unsigned char *)&s->tb, 1);
}
s->sr |= MCF_UART_TxEMP;
}
if (s->tx_enabled) {
Expand Down Expand Up @@ -280,9 +282,9 @@ void *mcf_uart_init(qemu_irq irq, CharDriverState *chr)
mcf_uart_state *s;

s = g_malloc0(sizeof(mcf_uart_state));
s->chr = chr;
s->irq = irq;
if (chr) {
qemu_chr_fe_init(&s->chr, chr, &error_abort);
qemu_chr_fe_claim_no_fail(chr);
qemu_chr_add_handlers(chr, mcf_uart_can_receive, mcf_uart_receive,
mcf_uart_event, s);
Expand Down
10 changes: 5 additions & 5 deletions hw/char/sh_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "hw/sh4/sh.h"
#include "sysemu/char.h"
#include "exec/address-spaces.h"
#include "qapi/error.h"

//#define DEBUG_SERIAL

Expand Down Expand Up @@ -62,7 +63,7 @@ typedef struct {
int flags;
int rtrg;

CharDriverState *chr;
CharBackend chr;

qemu_irq eri;
qemu_irq rxi;
Expand Down Expand Up @@ -109,11 +110,11 @@ static void sh_serial_write(void *opaque, hwaddr offs,
}
return;
case 0x0c: /* FTDR / TDR */
if (s->chr) {
if (s->chr.chr) {
ch = val;
/* XXX this blocks entire thread. Rewrite to use
* qemu_chr_fe_write and background I/O callbacks */
qemu_chr_fe_write_all(s->chr, &ch, 1);
qemu_chr_fe_write_all(s->chr.chr, &ch, 1);
}
s->dr = val;
s->flags &= ~SH_SERIAL_FLAG_TDE;
Expand Down Expand Up @@ -395,10 +396,9 @@ void sh_serial_init(MemoryRegion *sysmem,
0, 0x28);
memory_region_add_subregion(sysmem, A7ADDR(base), &s->iomem_a7);

s->chr = chr;

if (chr) {
qemu_chr_fe_claim_no_fail(chr);
qemu_chr_fe_init(&s->chr, chr, &error_abort);
qemu_chr_add_handlers(chr, sh_serial_can_receive1, sh_serial_receive1,
sh_serial_event, s);
}
Expand Down
39 changes: 23 additions & 16 deletions hw/char/xen_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "hw/hw.h"
#include "sysemu/char.h"
#include "hw/xen/xen_backend.h"
#include "qapi/error.h"

#include <xen/io/console.h>

Expand All @@ -43,7 +44,7 @@ struct XenConsole {
char console[XEN_BUFSIZE];
int ring_ref;
void *sring;
CharDriverState *chr;
CharBackend chr;
int backlog;
};

Expand Down Expand Up @@ -148,11 +149,13 @@ static void xencons_send(struct XenConsole *con)
ssize_t len, size;

size = con->buffer.size - con->buffer.consumed;
if (con->chr)
len = qemu_chr_fe_write(con->chr, con->buffer.data + con->buffer.consumed,
size);
else
if (con->chr.chr) {
len = qemu_chr_fe_write(con->chr.chr,
con->buffer.data + con->buffer.consumed,
size);
} else {
len = size;
}
if (len < 1) {
if (!con->backlog) {
con->backlog = 1;
Expand Down Expand Up @@ -196,13 +199,17 @@ static int con_init(struct XenDevice *xendev)

/* no Xen override, use qemu output device */
if (output == NULL) {
con->chr = serial_hds[con->xendev.dev];
if (con->xendev.dev) {
qemu_chr_fe_init(&con->chr, serial_hds[con->xendev.dev],
&error_abort);
}
} else {
snprintf(label, sizeof(label), "xencons%d", con->xendev.dev);
con->chr = qemu_chr_new(label, output);
qemu_chr_fe_init(&con->chr,
qemu_chr_new(label, output), &error_abort);
}

xenstore_store_pv_console_info(con->xendev.dev, con->chr);
xenstore_store_pv_console_info(con->xendev.dev, con->chr.chr);

out:
g_free(type);
Expand Down Expand Up @@ -235,15 +242,15 @@ static int con_initialise(struct XenDevice *xendev)
return -1;

xen_be_bind_evtchn(&con->xendev);
if (con->chr) {
if (qemu_chr_fe_claim(con->chr) == 0) {
qemu_chr_add_handlers(con->chr, xencons_can_receive,
if (con->chr.chr) {
if (qemu_chr_fe_claim(con->chr.chr) == 0) {
qemu_chr_add_handlers(con->chr.chr, xencons_can_receive,
xencons_receive, NULL, con);
} else {
xen_be_printf(xendev, 0,
"xen_console_init error chardev %s already used\n",
con->chr->label);
con->chr = NULL;
con->chr.chr->label);
con->chr.chr = NULL;
}
}

Expand All @@ -259,9 +266,9 @@ static void con_disconnect(struct XenDevice *xendev)
{
struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);

if (con->chr) {
qemu_chr_add_handlers(con->chr, NULL, NULL, NULL, NULL);
qemu_chr_fe_release(con->chr);
if (con->chr.chr) {
qemu_chr_add_handlers(con->chr.chr, NULL, NULL, NULL, NULL);
qemu_chr_fe_release(con->chr.chr);
}
xen_be_unbind_evtchn(&con->xendev);

Expand Down
Loading

0 comments on commit 32a6ebe

Please sign in to comment.