Commit 5345fdb4 authored by Marc-André Lureau's avatar Marc-André Lureau Committed by Paolo Bonzini
Browse files

char: use qemu_chr_fe* functions with CharBackend argument



This also switches from qemu_chr_add_handlers() to
qemu_chr_fe_set_handlers(). Note that qemu_chr_fe_set_handlers() now
takes the focus when fe_open (qemu_chr_add_handlers() did take the
focus)

Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20161022095318.17775-16-marcandre.lureau@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent fbf3cc3a
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -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.chr, header, sizeof(header));
        qemu_chr_fe_write_all(&s->chr, header, sizeof(header));

        size -= len;
    }
@@ -109,8 +109,8 @@ static void rng_egd_opened(RngBackend *b, Error **errp)
    }

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

static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
@@ -129,9 +129,10 @@ static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
static char *rng_egd_get_chardev(Object *obj, Error **errp)
{
    RngEgd *s = RNG_EGD(obj);
    CharDriverState *chr = qemu_chr_fe_get_driver(&s->chr);

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

    return NULL;
@@ -149,7 +150,7 @@ static void rng_egd_finalize(Object *obj)
    RngEgd *s = RNG_EGD(obj);

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

+11 −7
Original line number Diff line number Diff line
@@ -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.chr, buf, len);
    qemu_chr_fe_write_all(&s->chr, buf, len);
#endif
}

@@ -1471,6 +1471,9 @@ void gdb_exit(CPUArchState *env, int code)
{
  GDBState *s;
  char buf[4];
#ifndef CONFIG_USER_ONLY
  CharDriverState *chr;
#endif

  s = gdbserver_state;
  if (!s) {
@@ -1481,7 +1484,8 @@ void gdb_exit(CPUArchState *env, int code)
      return;
  }
#else
  if (!s->chr.chr) {
  chr = qemu_chr_fe_get_driver(&s->chr);
  if (!chr) {
      return;
  }
#endif
@@ -1490,7 +1494,7 @@ void gdb_exit(CPUArchState *env, int code)
  put_packet(s, buf);

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

@@ -1764,8 +1768,8 @@ int gdbserver_start(const char *device)
        mon_chr->chr_write = gdb_monitor_write;
        monitor_init(mon_chr, 0);
    } else {
        if (s->chr.chr) {
            qemu_chr_delete(s->chr.chr);
        if (qemu_chr_fe_get_driver(&s->chr)) {
            qemu_chr_delete(qemu_chr_fe_get_driver(&s->chr));
        }
        mon_chr = s->mon_chr;
        memset(s, 0, sizeof(GDBState));
@@ -1775,8 +1779,8 @@ int gdbserver_start(const char *device)
    s->g_cpu = first_cpu;
    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);
        qemu_chr_fe_set_handlers(&s->chr, gdb_chr_can_receive, gdb_chr_receive,
                                 gdb_chr_event, NULL, NULL);
    }
    s->state = chr ? RS_IDLE : RS_INACTIVE;
    s->mon_chr = mon_chr;
+6 −5
Original line number Diff line number Diff line
@@ -771,14 +771,15 @@ 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.chr, (const uint8_t *) "\r", 1);
        qemu_chr_fe_write_all(&s->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.chr, (const uint8_t *) "\n", 1);
        else
            qemu_chr_fe_write_all(s->chr.chr, &byte, 1);
        } else if (value == 0x00) {
            qemu_chr_fe_write_all(&s->chr, (const uint8_t *) "\n", 1);
        } else {
            qemu_chr_fe_write_all(&s->chr, &byte, 1);
        }
    }
}

+3 −3
Original line number Diff line number Diff line
@@ -1906,7 +1906,7 @@ static void pxa2xx_fir_write(void *opaque, hwaddr addr,
        if (s->chr.chr && s->enable && (s->control[0] & (1 << 3))) { /* TXE */
            /* XXX this blocks entire thread. Rewrite to use
             * qemu_chr_fe_write and background I/O callbacks */
            qemu_chr_fe_write_all(s->chr.chr, &ch, 1);
            qemu_chr_fe_write_all(&s->chr, &ch, 1);
        }
        break;
    case ICSR0:
@@ -1977,8 +1977,8 @@ static void pxa2xx_fir_realize(DeviceState *dev, Error **errp)

    if (s->chr.chr) {
        qemu_chr_fe_claim_no_fail(s->chr.chr);
        qemu_chr_add_handlers(s->chr.chr, pxa2xx_fir_is_empty,
                        pxa2xx_fir_rx, pxa2xx_fir_event, s);
        qemu_chr_fe_set_handlers(&s->chr, pxa2xx_fir_is_empty,
                                 pxa2xx_fir_rx, pxa2xx_fir_event, s, NULL);
    }
}

+8 −8
Original line number Diff line number Diff line
@@ -1021,7 +1021,7 @@ static void strongarm_uart_update_parameters(StrongARMUARTState *s)
    ssp.stop_bits = stop_bits;
    s->char_transmit_time =  (NANOSECONDS_PER_SECOND / speed) * frame_size;
    if (s->chr.chr) {
        qemu_chr_fe_ioctl(s->chr.chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
        qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
    }

    DPRINTF(stderr, "%s speed=%d parity=%c data=%d stop=%d\n", s->chr->label,
@@ -1107,10 +1107,10 @@ static void strongarm_uart_tx(void *opaque)

    if (s->utcr3 & UTCR3_LBM) /* loopback */ {
        strongarm_uart_receive(s, &s->tx_fifo[s->tx_start], 1);
    } else if (s->chr.chr) {
    } else if (qemu_chr_fe_get_driver(&s->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.chr, &s->tx_fifo[s->tx_start], 1);
        qemu_chr_fe_write_all(&s->chr, &s->tx_fifo[s->tx_start], 1);
    }

    s->tx_start = (s->tx_start + 1) % 8;
@@ -1240,11 +1240,11 @@ static void strongarm_uart_init(Object *obj)
    s->tx_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, strongarm_uart_tx, s);

    if (s->chr.chr) {
        qemu_chr_add_handlers(s->chr.chr,
        qemu_chr_fe_set_handlers(&s->chr,
                                 strongarm_uart_can_receive,
                                 strongarm_uart_receive,
                                 strongarm_uart_event,
                        s);
                                 s, NULL);
    }
}

Loading