Skip to content

Commit

Permalink
char: add backend hotswap handler
Browse files Browse the repository at this point in the history
Frontends should have an interface to setup the handler of a backend change.
The interface will be used in the next commits

Signed-off-by: Anton Nefedov <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
xantnef authored and bonzini committed Jul 14, 2017
1 parent 313e45b commit 81517ba
Show file tree
Hide file tree
Showing 48 changed files with 77 additions and 58 deletions.
2 changes: 1 addition & 1 deletion backends/rng-egd.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static void rng_egd_opened(RngBackend *b, Error **errp)

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

static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
Expand Down
4 changes: 3 additions & 1 deletion chardev/char-fe.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ 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);
qemu_chr_fe_set_handlers(b, NULL, NULL, NULL, NULL, NULL, NULL, true);
if (b->chr->be == b) {
b->chr->be = NULL;
}
Expand All @@ -235,6 +235,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
IOCanReadHandler *fd_can_read,
IOReadHandler *fd_read,
IOEventHandler *fd_event,
BackendChangeHandler *be_change,
void *opaque,
GMainContext *context,
bool set_open)
Expand All @@ -258,6 +259,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
b->chr_can_read = fd_can_read;
b->chr_read = fd_read;
b->chr_event = fd_event;
b->chr_be_change = be_change;
b->opaque = opaque;
if (cc->chr_update_read_handler) {
cc->chr_update_read_handler(s, context);
Expand Down
1 change: 1 addition & 0 deletions chardev/char-mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ void mux_chr_set_handlers(Chardev *chr, GMainContext *context)
mux_chr_can_read,
mux_chr_read,
mux_chr_event,
NULL,
chr,
context, true);
}
Expand Down
2 changes: 1 addition & 1 deletion gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ int gdbserver_start(const char *device)
if (chr) {
qemu_chr_fe_init(&s->chr, chr, &error_abort);
qemu_chr_fe_set_handlers(&s->chr, gdb_chr_can_receive, gdb_chr_receive,
gdb_chr_event, NULL, NULL, true);
gdb_chr_event, NULL, NULL, NULL, true);
}
s->state = chr ? RS_IDLE : RS_INACTIVE;
s->mon_chr = mon_chr;
Expand Down
3 changes: 2 additions & 1 deletion hw/arm/pxa2xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1970,7 +1970,8 @@ static void pxa2xx_fir_realize(DeviceState *dev, Error **errp)
PXA2xxFIrState *s = PXA2XX_FIR(dev);

qemu_chr_fe_set_handlers(&s->chr, pxa2xx_fir_is_empty,
pxa2xx_fir_rx, pxa2xx_fir_event, s, NULL, true);
pxa2xx_fir_rx, pxa2xx_fir_event, NULL, s, NULL,
true);
}

static bool pxa2xx_fir_vmstate_validate(void *opaque, int version_id)
Expand Down
2 changes: 1 addition & 1 deletion hw/arm/strongarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ static void strongarm_uart_realize(DeviceState *dev, Error **errp)
strongarm_uart_can_receive,
strongarm_uart_receive,
strongarm_uart_event,
s, NULL, true);
NULL, s, NULL, true);
}

static void strongarm_uart_reset(DeviceState *dev)
Expand Down
2 changes: 1 addition & 1 deletion hw/char/bcm2835_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static void bcm2835_aux_realize(DeviceState *dev, Error **errp)
BCM2835AuxState *s = BCM2835_AUX(dev);

qemu_chr_fe_set_handlers(&s->chr, bcm2835_aux_can_receive,
bcm2835_aux_receive, NULL, s, NULL, true);
bcm2835_aux_receive, NULL, NULL, s, NULL, true);
}

static Property bcm2835_aux_props[] = {
Expand Down
2 changes: 1 addition & 1 deletion hw/char/cadence_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ static void cadence_uart_realize(DeviceState *dev, Error **errp)
fifo_trigger_update, s);

qemu_chr_fe_set_handlers(&s->chr, uart_can_receive, uart_receive,
uart_event, s, NULL, true);
uart_event, NULL, s, NULL, true);
}

static void cadence_uart_init(Object *obj)
Expand Down
2 changes: 1 addition & 1 deletion hw/char/debugcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static void debugcon_realize_core(DebugconState *s, Error **errp)
return;
}

qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, NULL, s, NULL, true);
qemu_chr_fe_set_handlers(&s->chr, NULL, NULL, NULL, NULL, s, NULL, true);
}

static void debugcon_isa_realizefn(DeviceState *dev, Error **errp)
Expand Down
2 changes: 1 addition & 1 deletion hw/char/digic-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static void digic_uart_realize(DeviceState *dev, Error **errp)
DigicUartState *s = DIGIC_UART(dev);

qemu_chr_fe_set_handlers(&s->chr, uart_can_rx, uart_rx,
uart_event, s, NULL, true);
uart_event, NULL, s, NULL, true);
}

static void digic_uart_init(Object *obj)
Expand Down
2 changes: 1 addition & 1 deletion hw/char/escc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ static void escc_realize(DeviceState *dev, Error **errp)
if (qemu_chr_fe_get_driver(&s->chn[i].chr)) {
s->chn[i].clock = s->frequency / 2;
qemu_chr_fe_set_handlers(&s->chn[i].chr, serial_can_receive,
serial_receive1, serial_event,
serial_receive1, serial_event, NULL,
&s->chn[i], NULL, true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion hw/char/etraxfs_ser.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static void etraxfs_ser_realize(DeviceState *dev, Error **errp)

qemu_chr_fe_set_handlers(&s->chr,
serial_can_receive, serial_receive,
serial_event, s, NULL, true);
serial_event, NULL, s, NULL, true);
}

static void etraxfs_ser_class_init(ObjectClass *klass, void *data)
Expand Down
2 changes: 1 addition & 1 deletion hw/char/exynos4210_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ static void exynos4210_uart_realize(DeviceState *dev, Error **errp)

qemu_chr_fe_set_handlers(&s->chr, exynos4210_uart_can_receive,
exynos4210_uart_receive, exynos4210_uart_event,
s, NULL, true);
NULL, s, NULL, true);
}

static Property exynos4210_uart_properties[] = {
Expand Down
2 changes: 1 addition & 1 deletion hw/char/grlib_apbuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static int grlib_apbuart_init(SysBusDevice *dev)
grlib_apbuart_can_receive,
grlib_apbuart_receive,
grlib_apbuart_event,
uart, NULL, true);
NULL, uart, NULL, true);

sysbus_init_irq(dev, &uart->irq);

Expand Down
2 changes: 1 addition & 1 deletion hw/char/imx_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ static void imx_serial_realize(DeviceState *dev, Error **errp)
DPRINTF("char dev for uart: %p\n", qemu_chr_fe_get_driver(&s->chr));

qemu_chr_fe_set_handlers(&s->chr, imx_can_receive, imx_receive,
imx_event, s, NULL, true);
imx_event, NULL, s, NULL, true);
}

static void imx_serial_init(Object *obj)
Expand Down
2 changes: 1 addition & 1 deletion hw/char/ipoctal232.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ static void ipoctal_realize(DeviceState *dev, Error **errp)
if (qemu_chr_fe_get_driver(&ch->dev)) {
qemu_chr_fe_set_handlers(&ch->dev, hostdev_can_receive,
hostdev_receive, hostdev_event,
ch, NULL, true);
NULL, ch, NULL, true);
DPRINTF("Redirecting channel %u to %s\n", i, ch->dev->label);
} else {
DPRINTF("Could not redirect channel %u, no chardev set\n", i);
Expand Down
2 changes: 1 addition & 1 deletion hw/char/lm32_juart.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static void lm32_juart_realize(DeviceState *dev, Error **errp)
LM32JuartState *s = LM32_JUART(dev);

qemu_chr_fe_set_handlers(&s->chr, juart_can_rx, juart_rx,
juart_event, s, NULL, true);
juart_event, NULL, s, NULL, true);
}

static const VMStateDescription vmstate_lm32_juart = {
Expand Down
2 changes: 1 addition & 1 deletion hw/char/lm32_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static void lm32_uart_realize(DeviceState *dev, Error **errp)
LM32UartState *s = LM32_UART(dev);

qemu_chr_fe_set_handlers(&s->chr, uart_can_rx, uart_rx,
uart_event, s, NULL, true);
uart_event, NULL, s, NULL, true);
}

static const VMStateDescription vmstate_lm32_uart = {
Expand Down
2 changes: 1 addition & 1 deletion hw/char/mcf_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static void mcf_uart_realize(DeviceState *dev, Error **errp)
mcf_uart_state *s = MCF_UART(dev);

qemu_chr_fe_set_handlers(&s->chr, mcf_uart_can_receive, mcf_uart_receive,
mcf_uart_event, s, NULL, true);
mcf_uart_event, NULL, s, NULL, true);
}

static Property mcf_uart_properties[] = {
Expand Down
2 changes: 1 addition & 1 deletion hw/char/milkymist-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static void milkymist_uart_realize(DeviceState *dev, Error **errp)
MilkymistUartState *s = MILKYMIST_UART(dev);

qemu_chr_fe_set_handlers(&s->chr, uart_can_rx, uart_rx,
uart_event, s, NULL, true);
uart_event, NULL, s, NULL, true);
}

static void milkymist_uart_init(Object *obj)
Expand Down
2 changes: 1 addition & 1 deletion hw/char/pl011.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ static void pl011_realize(DeviceState *dev, Error **errp)
PL011State *s = PL011(dev);

qemu_chr_fe_set_handlers(&s->chr, pl011_can_receive, pl011_receive,
pl011_event, s, NULL, true);
pl011_event, NULL, s, NULL, true);
}

static void pl011_class_init(ObjectClass *oc, void *data)
Expand Down
2 changes: 1 addition & 1 deletion hw/char/sclpconsole-lm.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static int console_init(SCLPEvent *event)
console_available = true;

qemu_chr_fe_set_handlers(&scon->chr, chr_can_read,
chr_read, NULL, scon, NULL, true);
chr_read, NULL, NULL, scon, NULL, true);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion hw/char/sclpconsole.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static int console_init(SCLPEvent *event)
}
console_available = true;
qemu_chr_fe_set_handlers(&scon->chr, chr_can_read,
chr_read, NULL, scon, NULL, true);
chr_read, NULL, NULL, scon, NULL, true);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion hw/char/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ void serial_realize_core(SerialState *s, Error **errp)
qemu_register_reset(serial_reset, s);

qemu_chr_fe_set_handlers(&s->chr, serial_can_receive1, serial_receive1,
serial_event, s, NULL, true);
serial_event, NULL, s, NULL, true);
fifo8_create(&s->recv_fifo, UART_FIFO_LENGTH);
fifo8_create(&s->xmit_fifo, UART_FIFO_LENGTH);
serial_reset(s);
Expand Down
2 changes: 1 addition & 1 deletion hw/char/sh_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ void sh_serial_init(MemoryRegion *sysmem,
qemu_chr_fe_init(&s->chr, chr, &error_abort);
qemu_chr_fe_set_handlers(&s->chr, sh_serial_can_receive1,
sh_serial_receive1,
sh_serial_event, s, NULL, true);
sh_serial_event, NULL, s, NULL, true);
}

s->eri = eri_source;
Expand Down
2 changes: 1 addition & 1 deletion hw/char/spapr_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static void spapr_vty_realize(VIOsPAPRDevice *sdev, Error **errp)
}

qemu_chr_fe_set_handlers(&dev->chardev, vty_can_receive,
vty_receive, NULL, dev, NULL, true);
vty_receive, NULL, NULL, dev, NULL, true);
}

/* Forward declaration */
Expand Down
3 changes: 2 additions & 1 deletion hw/char/stm32f2xx_usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ static void stm32f2xx_usart_realize(DeviceState *dev, Error **errp)
STM32F2XXUsartState *s = STM32F2XX_USART(dev);

qemu_chr_fe_set_handlers(&s->chr, stm32f2xx_usart_can_receive,
stm32f2xx_usart_receive, NULL, s, NULL, true);
stm32f2xx_usart_receive, NULL, NULL,
s, NULL, true);
}

static void stm32f2xx_usart_class_init(ObjectClass *klass, void *data)
Expand Down
2 changes: 1 addition & 1 deletion hw/char/terminal3270.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static void terminal_init(EmulatedCcw3270Device *dev, Error **errp)
}
terminal_available = true;
qemu_chr_fe_set_handlers(&t->chr, terminal_can_read,
terminal_read, chr_event, t, NULL, true);
terminal_read, chr_event, NULL, t, NULL, true);
}

static int read_payload_3270(EmulatedCcw3270Device *dev, uint32_t cda,
Expand Down
4 changes: 2 additions & 2 deletions hw/char/virtio-console.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ static void virtconsole_realize(DeviceState *dev, Error **errp)
*/
if (k->is_console) {
qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read,
NULL, vcon, NULL, true);
NULL, NULL, vcon, NULL, true);
virtio_serial_open(port);
} else {
qemu_chr_fe_set_handlers(&vcon->chr, chr_can_read, chr_read,
chr_event, vcon, NULL, false);
chr_event, NULL, vcon, NULL, false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion hw/char/xen_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static int con_initialise(struct XenDevice *xendev)

xen_be_bind_evtchn(&con->xendev);
qemu_chr_fe_set_handlers(&con->chr, xencons_can_receive,
xencons_receive, NULL, con, NULL, true);
xencons_receive, NULL, NULL, con, NULL, true);

xen_pv_printf(xendev, 1,
"ring mfn %d, remote port %d, local port %d, limit %zd\n",
Expand Down
2 changes: 1 addition & 1 deletion hw/char/xilinx_uartlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static void xilinx_uartlite_realize(DeviceState *dev, Error **errp)
XilinxUARTLite *s = XILINX_UARTLITE(dev);

qemu_chr_fe_set_handlers(&s->chr, uart_can_rx, uart_rx,
uart_event, s, NULL, true);
uart_event, NULL, s, NULL, true);
}

static void xilinx_uartlite_init(Object *obj)
Expand Down
2 changes: 1 addition & 1 deletion hw/ipmi/ipmi_bmc_extern.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ static void ipmi_bmc_extern_realize(DeviceState *dev, Error **errp)
}

qemu_chr_fe_set_handlers(&ibe->chr, can_receive, receive,
chr_event, ibe, NULL, true);
chr_event, NULL, ibe, NULL, true);
}

static int ipmi_bmc_extern_post_migrate(void *opaque, int version_id)
Expand Down
2 changes: 1 addition & 1 deletion hw/mips/boston.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ static void boston_mach_init(MachineState *machine)
chr = qemu_chr_new("lcd", "vc:320x240");
qemu_chr_fe_init(&s->lcd_display, chr, NULL);
qemu_chr_fe_set_handlers(&s->lcd_display, NULL, NULL,
boston_lcd_event, s, NULL, true);
boston_lcd_event, NULL, s, NULL, true);

ahci = pci_create_simple_multifunction(&PCI_BRIDGE(&pcie2->root)->sec_bus,
PCI_DEVFN(0, 0),
Expand Down
2 changes: 1 addition & 1 deletion hw/mips/mips_malta.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ static MaltaFPGAState *malta_fpga_init(MemoryRegion *address_space,
chr = qemu_chr_new("fpga", "vc:320x200");
qemu_chr_fe_init(&s->display, chr, NULL);
qemu_chr_fe_set_handlers(&s->display, NULL, NULL,
malta_fgpa_display_event, s, NULL, true);
malta_fgpa_display_event, NULL, s, NULL, true);

s->uart = serial_mm_init(address_space, base + 0x900, 3, uart_irq,
230400, uart_chr, DEVICE_NATIVE_ENDIAN);
Expand Down
2 changes: 1 addition & 1 deletion hw/misc/ivshmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp)
}

qemu_chr_fe_set_handlers(&s->server_chr, ivshmem_can_receive,
ivshmem_read, NULL, s, NULL, true);
ivshmem_read, NULL, NULL, s, NULL, true);

if (ivshmem_setup_interrupts(s, errp) < 0) {
error_prepend(errp, "Failed to initialize interrupts: ");
Expand Down
2 changes: 1 addition & 1 deletion hw/usb/ccid-card-passthru.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static int passthru_initfn(CCIDCardState *base)
qemu_chr_fe_set_handlers(&card->cs,
ccid_card_vscard_can_read,
ccid_card_vscard_read,
ccid_card_vscard_event, card, NULL, true);
ccid_card_vscard_event, NULL, card, NULL, true);
ccid_card_vscard_send_init(card);
} else {
error_report("missing chardev");
Expand Down
2 changes: 1 addition & 1 deletion hw/usb/dev-serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ static void usb_serial_realize(USBDevice *dev, Error **errp)
}

qemu_chr_fe_set_handlers(&s->cs, usb_serial_can_read, usb_serial_read,
usb_serial_event, s, NULL, true);
usb_serial_event, NULL, s, NULL, true);
usb_serial_handle_reset(dev);

if (chr->be_open && !dev->attached) {
Expand Down
2 changes: 1 addition & 1 deletion hw/usb/redirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ static void usbredir_realize(USBDevice *udev, Error **errp)
/* Let the backend know we are ready */
qemu_chr_fe_set_handlers(&dev->cs, usbredir_chardev_can_read,
usbredir_chardev_read, usbredir_chardev_event,
dev, NULL, true);
NULL, dev, NULL, true);

dev->vmstate =
qemu_add_vm_change_state_handler(usbredir_vm_state_change, dev);
Expand Down
5 changes: 5 additions & 0 deletions include/chardev/char-fe.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "chardev/char.h"

typedef void IOEventHandler(void *opaque, int event);
typedef int BackendChangeHandler(void *opaque);

/* This is the backend as seen by frontend, the actual backend is
* Chardev */
Expand All @@ -12,6 +13,7 @@ struct CharBackend {
IOEventHandler *chr_event;
IOCanReadHandler *chr_can_read;
IOReadHandler *chr_read;
BackendChangeHandler *chr_be_change;
void *opaque;
int tag;
int fe_open;
Expand Down Expand Up @@ -54,6 +56,8 @@ Chardev *qemu_chr_fe_get_driver(CharBackend *be);
* receive
* @fd_read: callback to receive data from char
* @fd_event: event callback
* @be_change: backend change callback; passing NULL means hot backend change
* is not supported and will not be attempted
* @opaque: an opaque pointer for the callbacks
* @context: a main loop context or NULL for the default
* @set_open: whether to call qemu_chr_fe_set_open() implicitely when
Expand All @@ -68,6 +72,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b,
IOCanReadHandler *fd_can_read,
IOReadHandler *fd_read,
IOEventHandler *fd_event,
BackendChangeHandler *be_change,
void *opaque,
GMainContext *context,
bool set_open);
Expand Down
Loading

0 comments on commit 81517ba

Please sign in to comment.