All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Gerd Hoffmann <kraxel@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 1/9] serial: split serial.c
Date: Mon, 15 Oct 2012 09:16:00 -0500	[thread overview]
Message-ID: <877gqrg6sf.fsf@codemonkey.ws> (raw)
In-Reply-To: <1350288417-24350-2-git-send-email-kraxel@redhat.com>

Gerd Hoffmann <kraxel@redhat.com> writes:

> Split serial.c into serial.c, serial.h and serial-isa.c.  While being at
> creating a serial.h header file move the serial prototypes from pc.h to
> the new serial.h.  The latter leads to s/pc.h/serial.h/ in tons of
> boards which just want the serial bits from pc.h
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/Makefile.objs         |    2 +-
>  hw/alpha_dp264.c         |    1 +
>  hw/kzm.c                 |    2 +-
>  hw/mips_fulong2e.c       |    1 +
>  hw/mips_jazz.c           |    1 +
>  hw/mips_malta.c          |    1 +
>  hw/mips_mipssim.c        |    2 +-
>  hw/mips_r4k.c            |    1 +
>  hw/musicpal.c            |    2 +-
>  hw/omap_uart.c           |    3 +-
>  hw/openrisc_sim.c        |    3 +-
>  hw/pc.c                  |    1 +
>  hw/pc.h                  |   27 ---------
>  hw/petalogix_ml605_mmu.c |    2 +-
>  hw/ppc/e500.c            |    2 +-
>  hw/ppc405_uc.c           |    2 +-
>  hw/ppc440_bamboo.c       |    2 +-
>  hw/ppc_prep.c            |    1 +
>  hw/pxa2xx.c              |    2 +-
>  hw/serial-isa.c          |  130 +++++++++++++++++++++++++++++++++++++++++
>  hw/serial.c              |  143 ++--------------------------------------------
>  hw/serial.h              |   73 +++++++++++++++++++++++
>  hw/sm501.c               |    2 +-
>  hw/sun4u.c               |    1 +
>  hw/virtex_ml507.c        |    2 +-
>  hw/xtensa_lx60.c         |    3 +-
>  26 files changed, 232 insertions(+), 180 deletions(-)
>  create mode 100644 hw/serial-isa.c
>  create mode 100644 hw/serial.h
>
> diff --git a/hw/Makefile.objs b/hw/Makefile.objs
> index 854faa9..16e7a1e 100644
> --- a/hw/Makefile.objs
> +++ b/hw/Makefile.objs
> @@ -20,7 +20,7 @@ common-obj-$(CONFIG_M48T59) += m48t59.o
>  common-obj-$(CONFIG_ESCC) += escc.o
>  common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
>  
> -common-obj-$(CONFIG_SERIAL) += serial.o
> +common-obj-$(CONFIG_SERIAL) += serial.o serial-isa.o
>  common-obj-$(CONFIG_PARALLEL) += parallel.o
>  common-obj-$(CONFIG_I8254) += i8254_common.o i8254.o
>  common-obj-$(CONFIG_PCSPK) += pcspk.o
> diff --git a/hw/alpha_dp264.c b/hw/alpha_dp264.c
> index 5ea04c7..8ce04e5 100644
> --- a/hw/alpha_dp264.c
> +++ b/hw/alpha_dp264.c
> @@ -15,6 +15,7 @@
>  #include "mc146818rtc.h"
>  #include "ide.h"
>  #include "i8254.h"
> +#include "serial.h"
>  
>  #define MAX_IDE_BUS 2
>  
> diff --git a/hw/kzm.c b/hw/kzm.c
> index 68cd1b4..1f3082b 100644
> --- a/hw/kzm.c
> +++ b/hw/kzm.c
> @@ -21,7 +21,7 @@
>  #include "net.h"
>  #include "sysemu.h"
>  #include "boards.h"
> -#include "pc.h" /* for the FPGA UART that emulates a 16550 */
> +#include "serial.h"
>  #include "imx.h"
>  
>      /* Memory map for Kzm Emulation Baseboard:
> diff --git a/hw/mips_fulong2e.c b/hw/mips_fulong2e.c
> index d4a8672..a3cb3ab 100644
> --- a/hw/mips_fulong2e.c
> +++ b/hw/mips_fulong2e.c
> @@ -20,6 +20,7 @@
>  
>  #include "hw.h"
>  #include "pc.h"
> +#include "serial.h"
>  #include "fdc.h"
>  #include "net.h"
>  #include "boards.h"
> diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
> index db927f1..d35cd54 100644
> --- a/hw/mips_jazz.c
> +++ b/hw/mips_jazz.c
> @@ -26,6 +26,7 @@
>  #include "mips.h"
>  #include "mips_cpudevs.h"
>  #include "pc.h"
> +#include "serial.h"
>  #include "isa.h"
>  #include "fdc.h"
>  #include "sysemu.h"
> diff --git a/hw/mips_malta.c b/hw/mips_malta.c
> index 632b466..8f73b1b 100644
> --- a/hw/mips_malta.c
> +++ b/hw/mips_malta.c
> @@ -24,6 +24,7 @@
>  
>  #include "hw.h"
>  #include "pc.h"
> +#include "serial.h"
>  #include "fdc.h"
>  #include "net.h"
>  #include "boards.h"
> diff --git a/hw/mips_mipssim.c b/hw/mips_mipssim.c
> index 830f635..0ee6756 100644
> --- a/hw/mips_mipssim.c
> +++ b/hw/mips_mipssim.c
> @@ -27,7 +27,7 @@
>  #include "hw.h"
>  #include "mips.h"
>  #include "mips_cpudevs.h"
> -#include "pc.h"
> +#include "serial.h"
>  #include "isa.h"
>  #include "net.h"
>  #include "sysemu.h"
> diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
> index 967a76e..b3be80b 100644
> --- a/hw/mips_r4k.c
> +++ b/hw/mips_r4k.c
> @@ -11,6 +11,7 @@
>  #include "mips.h"
>  #include "mips_cpudevs.h"
>  #include "pc.h"
> +#include "serial.h"
>  #include "isa.h"
>  #include "net.h"
>  #include "sysemu.h"
> diff --git a/hw/musicpal.c b/hw/musicpal.c
> index f305e21..346fe41 100644
> --- a/hw/musicpal.c
> +++ b/hw/musicpal.c
> @@ -15,7 +15,7 @@
>  #include "net.h"
>  #include "sysemu.h"
>  #include "boards.h"
> -#include "pc.h"
> +#include "serial.h"
>  #include "qemu-timer.h"
>  #include "ptimer.h"
>  #include "block.h"
> diff --git a/hw/omap_uart.c b/hw/omap_uart.c
> index 167d5c4..1c16a54 100644
> --- a/hw/omap_uart.c
> +++ b/hw/omap_uart.c
> @@ -20,8 +20,7 @@
>  #include "qemu-char.h"
>  #include "hw.h"
>  #include "omap.h"
> -/* We use pc-style serial ports.  */
> -#include "pc.h"
> +#include "serial.h"
>  #include "exec-memory.h"
>  
>  /* UARTs */
> diff --git a/hw/openrisc_sim.c b/hw/openrisc_sim.c
> index 55e97f0..e484613 100644
> --- a/hw/openrisc_sim.c
> +++ b/hw/openrisc_sim.c
> @@ -21,7 +21,8 @@
>  #include "hw.h"
>  #include "boards.h"
>  #include "elf.h"
> -#include "pc.h"
> +#include "serial.h"
> +#include "net.h"
>  #include "loader.h"
>  #include "exec-memory.h"
>  #include "sysemu.h"
> diff --git a/hw/pc.c b/hw/pc.c
> index 6c0722d..805e8ca 100644
> --- a/hw/pc.c
> +++ b/hw/pc.c
> @@ -23,6 +23,7 @@
>   */
>  #include "hw.h"
>  #include "pc.h"
> +#include "serial.h"
>  #include "apic.h"
>  #include "fdc.h"
>  #include "ide.h"
> diff --git a/hw/pc.h b/hw/pc.h
> index 9923d96..6cba7ce 100644
> --- a/hw/pc.h
> +++ b/hw/pc.h
> @@ -12,33 +12,6 @@
>  
>  /* PC-style peripherals (also used by other machines).  */
>  
> -/* serial.c */
> -
> -SerialState *serial_init(int base, qemu_irq irq, int baudbase,
> -                         CharDriverState *chr);
> -SerialState *serial_mm_init(MemoryRegion *address_space,
> -                            target_phys_addr_t base, int it_shift,
> -                            qemu_irq irq, int baudbase,
> -                            CharDriverState *chr, enum device_endian);
> -static inline bool serial_isa_init(ISABus *bus, int index,
> -                                   CharDriverState *chr)
> -{
> -    ISADevice *dev;
> -
> -    dev = isa_try_create(bus, "isa-serial");
> -    if (!dev) {
> -        return false;
> -    }
> -    qdev_prop_set_uint32(&dev->qdev, "index", index);
> -    qdev_prop_set_chr(&dev->qdev, "chardev", chr);
> -    if (qdev_init(&dev->qdev) < 0) {
> -        return false;
> -    }
> -    return true;
> -}
> -
> -void serial_set_frequency(SerialState *s, uint32_t frequency);
> -
>  /* parallel.c */
>  static inline bool parallel_init(ISABus *bus, int index, CharDriverState *chr)
>  {
> diff --git a/hw/petalogix_ml605_mmu.c b/hw/petalogix_ml605_mmu.c
> index b9bfbed..1c12c5b 100644
> --- a/hw/petalogix_ml605_mmu.c
> +++ b/hw/petalogix_ml605_mmu.c
> @@ -34,7 +34,7 @@
>  #include "boards.h"
>  #include "xilinx.h"
>  #include "blockdev.h"
> -#include "pc.h"
> +#include "serial.h"
>  #include "exec-memory.h"
>  #include "ssi.h"
>  
> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
> index d23f9b2..846f53a 100644
> --- a/hw/ppc/e500.c
> +++ b/hw/ppc/e500.c
> @@ -19,7 +19,7 @@
>  #include "e500.h"
>  #include "net.h"
>  #include "hw/hw.h"
> -#include "hw/pc.h"
> +#include "hw/serial.h"
>  #include "hw/pci.h"
>  #include "hw/boards.h"
>  #include "sysemu.h"
> diff --git a/hw/ppc405_uc.c b/hw/ppc405_uc.c
> index b52ab2f..e81409d 100644
> --- a/hw/ppc405_uc.c
> +++ b/hw/ppc405_uc.c
> @@ -24,7 +24,7 @@
>  #include "hw.h"
>  #include "ppc.h"
>  #include "ppc405.h"
> -#include "pc.h"
> +#include "serial.h"
>  #include "qemu-timer.h"
>  #include "sysemu.h"
>  #include "qemu-log.h"
> diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
> index c198071..7e6fa85 100644
> --- a/hw/ppc440_bamboo.c
> +++ b/hw/ppc440_bamboo.c
> @@ -23,7 +23,7 @@
>  #include "loader.h"
>  #include "elf.h"
>  #include "exec-memory.h"
> -#include "pc.h"
> +#include "serial.h"
>  #include "ppc.h"
>  #include "ppc405.h"
>  #include "sysemu.h"
> diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
> index 1544430..50fd567 100644
> --- a/hw/ppc_prep.c
> +++ b/hw/ppc_prep.c
> @@ -24,6 +24,7 @@
>  #include "hw.h"
>  #include "nvram.h"
>  #include "pc.h"
> +#include "serial.h"
>  #include "fdc.h"
>  #include "net.h"
>  #include "sysemu.h"
> diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
> index d5f1420..4ec904f 100644
> --- a/hw/pxa2xx.c
> +++ b/hw/pxa2xx.c
> @@ -10,7 +10,7 @@
>  #include "sysbus.h"
>  #include "pxa.h"
>  #include "sysemu.h"
> -#include "pc.h"
> +#include "serial.h"
>  #include "i2c.h"
>  #include "ssi.h"
>  #include "qemu-char.h"
> diff --git a/hw/serial-isa.c b/hw/serial-isa.c
> new file mode 100644
> index 0000000..96c78f7
> --- /dev/null
> +++ b/hw/serial-isa.c
> @@ -0,0 +1,130 @@
> +/*
> + * QEMU 16550A UART emulation
> + *
> + * Copyright (c) 2003-2004 Fabrice Bellard
> + * Copyright (c) 2008 Citrix Systems, Inc.
> + *
> + * 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 "serial.h"
> +#include "isa.h"
> +
> +typedef struct ISASerialState {
> +    ISADevice dev;
> +    uint32_t index;
> +    uint32_t iobase;
> +    uint32_t isairq;
> +    SerialState state;
> +} ISASerialState;
> +
> +static const int isa_serial_io[MAX_SERIAL_PORTS] = {
> +    0x3f8, 0x2f8, 0x3e8, 0x2e8
> +};
> +static const int isa_serial_irq[MAX_SERIAL_PORTS] = {
> +    4, 3, 4, 3
> +};
> +
> +static int serial_isa_initfn(ISADevice *dev)
> +{
> +    static int index;
> +    ISASerialState *isa = DO_UPCAST(ISASerialState, dev, dev);
> +    SerialState *s = &isa->state;
> +
> +    if (isa->index == -1) {
> +        isa->index = index;
> +    }
> +    if (isa->index >= MAX_SERIAL_PORTS) {
> +        return -1;
> +    }
> +    if (isa->iobase == -1) {
> +        isa->iobase = isa_serial_io[isa->index];
> +    }
> +    if (isa->isairq == -1) {
> +        isa->isairq = isa_serial_irq[isa->index];
> +    }
> +    index++;
> +
> +    s->baudbase = 115200;
> +    isa_init_irq(dev, &s->irq, isa->isairq);
> +    serial_init_core(s);
> +    qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 3);
> +
> +    memory_region_init_io(&s->io, &serial_io_ops, s, "serial", 8);
> +    isa_register_ioport(dev, &s->io, isa->iobase);
> +    return 0;
> +}
> +
> +static const VMStateDescription vmstate_isa_serial = {
> +    .name = "serial",
> +    .version_id = 3,
> +    .minimum_version_id = 2,
> +    .fields = (VMStateField[]) {
> +        VMSTATE_STRUCT(state, ISASerialState, 0, vmstate_serial, SerialState),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> +
> +static Property serial_isa_properties[] = {
> +    DEFINE_PROP_UINT32("index",  ISASerialState, index,   -1),
> +    DEFINE_PROP_HEX32("iobase",  ISASerialState, iobase,  -1),
> +    DEFINE_PROP_UINT32("irq",    ISASerialState, isairq,  -1),
> +    DEFINE_PROP_CHR("chardev",   ISASerialState, state.chr),
> +    DEFINE_PROP_UINT32("wakeup", ISASerialState, state.wakeup, 0),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static void serial_isa_class_initfn(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
> +    ic->init = serial_isa_initfn;
> +    dc->vmsd = &vmstate_isa_serial;
> +    dc->props = serial_isa_properties;
> +}
> +
> +static TypeInfo serial_isa_info = {
> +    .name          = "isa-serial",
> +    .parent        = TYPE_ISA_DEVICE,
> +    .instance_size = sizeof(ISASerialState),
> +    .class_init    = serial_isa_class_initfn,
> +};
> +
> +static void serial_register_types(void)
> +{
> +    type_register_static(&serial_isa_info);
> +}
> +
> +type_init(serial_register_types)
> +
> +bool serial_isa_init(ISABus *bus, int index, CharDriverState *chr)
> +{
> +    ISADevice *dev;
> +
> +    dev = isa_try_create(bus, "isa-serial");
> +    if (!dev) {
> +        return false;
> +    }
> +    qdev_prop_set_uint32(&dev->qdev, "index", index);
> +    qdev_prop_set_chr(&dev->qdev, "chardev", chr);
> +    if (qdev_init(&dev->qdev) < 0) {
> +        return false;
> +    }
> +    return true;
> +}
> diff --git a/hw/serial.c b/hw/serial.c
> index a421d1e..78e219d 100644
> --- a/hw/serial.c
> +++ b/hw/serial.c
> @@ -22,12 +22,10 @@
>   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
>   * THE SOFTWARE.
>   */
> -#include "hw.h"
> +
> +#include "serial.h"
>  #include "qemu-char.h"
> -#include "isa.h"
> -#include "pc.h"
>  #include "qemu-timer.h"
> -#include "sysemu.h"
>  
>  //#define DEBUG_SERIAL
>  
> @@ -93,8 +91,6 @@
>  #define UART_FCR_RFR        0x02    /* RCVR Fifo Reset */
>  #define UART_FCR_FE         0x01    /* FIFO Enable */
>  
> -#define UART_FIFO_LENGTH    16      /* 16550A Fifo Length */
> -
>  #define XMIT_FIFO           0
>  #define RECV_FIFO           1
>  #define MAX_XMIT_RETRY      4
> @@ -107,64 +103,6 @@ do { fprintf(stderr, "serial: " fmt , ## __VA_ARGS__); } while (0)
>  do {} while (0)
>  #endif
>  
> -typedef struct SerialFIFO {
> -    uint8_t data[UART_FIFO_LENGTH];
> -    uint8_t count;
> -    uint8_t itl;                        /* Interrupt Trigger Level */
> -    uint8_t tail;
> -    uint8_t head;
> -} SerialFIFO;
> -
> -struct SerialState {
> -    uint16_t divider;
> -    uint8_t rbr; /* receive register */
> -    uint8_t thr; /* transmit holding register */
> -    uint8_t tsr; /* transmit shift register */
> -    uint8_t ier;
> -    uint8_t iir; /* read only */
> -    uint8_t lcr;
> -    uint8_t mcr;
> -    uint8_t lsr; /* read only */
> -    uint8_t msr; /* read only */
> -    uint8_t scr;
> -    uint8_t fcr;
> -    uint8_t fcr_vmstate; /* we can't write directly this value
> -                            it has side effects */
> -    /* NOTE: this hidden state is necessary for tx irq generation as
> -       it can be reset while reading iir */
> -    int thr_ipending;
> -    qemu_irq irq;
> -    CharDriverState *chr;
> -    int last_break_enable;
> -    int it_shift;
> -    int baudbase;
> -    int tsr_retry;
> -    uint32_t wakeup;
> -
> -    uint64_t last_xmit_ts;              /* Time when the last byte was successfully sent out of the tsr */
> -    SerialFIFO recv_fifo;
> -    SerialFIFO xmit_fifo;
> -
> -    struct QEMUTimer *fifo_timeout_timer;
> -    int timeout_ipending;                   /* timeout interrupt pending state */
> -    struct QEMUTimer *transmit_timer;
> -
> -
> -    uint64_t char_transmit_time;               /* time to transmit a char in ticks*/
> -    int poll_msl;
> -
> -    struct QEMUTimer *modem_status_poll;
> -    MemoryRegion io;
> -};
> -
> -typedef struct ISASerialState {
> -    ISADevice dev;
> -    uint32_t index;
> -    uint32_t iobase;
> -    uint32_t isairq;
> -    SerialState state;
> -} ISASerialState;
> -
>  static void serial_receive1(void *opaque, const uint8_t *buf, int size);
>  
>  static void fifo_clear(SerialState *s, int fifo)
> @@ -687,7 +625,7 @@ static int serial_post_load(void *opaque, int version_id)
>      return 0;
>  }
>  
> -static const VMStateDescription vmstate_serial = {
> +const VMStateDescription vmstate_serial = {
>      .name = "serial",
>      .version_id = 3,
>      .minimum_version_id = 2,
> @@ -736,7 +674,7 @@ static void serial_reset(void *opaque)
>      qemu_irq_lower(s->irq);
>  }
>  
> -static void serial_init_core(SerialState *s)
> +void serial_init_core(SerialState *s)
>  {
>      if (!s->chr) {
>          fprintf(stderr, "Can't create serial device, empty char device\n");
> @@ -761,54 +699,15 @@ void serial_set_frequency(SerialState *s, uint32_t frequency)
>      serial_update_parameters(s);
>  }
>  
> -static const int isa_serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
> -static const int isa_serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
> -
>  static const MemoryRegionPortio serial_portio[] = {
>      { 0, 8, 1, .read = serial_ioport_read, .write = serial_ioport_write },
>      PORTIO_END_OF_LIST()
>  };
>  
> -static const MemoryRegionOps serial_io_ops = {
> +const MemoryRegionOps serial_io_ops = {
>      .old_portio = serial_portio
>  };
>  
> -static int serial_isa_initfn(ISADevice *dev)
> -{
> -    static int index;
> -    ISASerialState *isa = DO_UPCAST(ISASerialState, dev, dev);
> -    SerialState *s = &isa->state;
> -
> -    if (isa->index == -1)
> -        isa->index = index;
> -    if (isa->index >= MAX_SERIAL_PORTS)
> -        return -1;
> -    if (isa->iobase == -1)
> -        isa->iobase = isa_serial_io[isa->index];
> -    if (isa->isairq == -1)
> -        isa->isairq = isa_serial_irq[isa->index];
> -    index++;
> -
> -    s->baudbase = 115200;
> -    isa_init_irq(dev, &s->irq, isa->isairq);
> -    serial_init_core(s);
> -    qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 3);
> -
> -    memory_region_init_io(&s->io, &serial_io_ops, s, "serial", 8);
> -    isa_register_ioport(dev, &s->io, isa->iobase);
> -    return 0;
> -}
> -
> -static const VMStateDescription vmstate_isa_serial = {
> -    .name = "serial",
> -    .version_id = 3,
> -    .minimum_version_id = 2,
> -    .fields      = (VMStateField []) {
> -        VMSTATE_STRUCT(state, ISASerialState, 0, vmstate_serial, SerialState),
> -        VMSTATE_END_OF_LIST()
> -    }
> -};
> -
>  SerialState *serial_init(int base, qemu_irq irq, int baudbase,
>                           CharDriverState *chr)
>  {
> @@ -886,35 +785,3 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
>      serial_update_msl(s);
>      return s;
>  }
> -
> -static Property serial_isa_properties[] = {
> -    DEFINE_PROP_UINT32("index", ISASerialState, index,   -1),
> -    DEFINE_PROP_HEX32("iobase", ISASerialState, iobase,  -1),
> -    DEFINE_PROP_UINT32("irq",   ISASerialState, isairq,  -1),
> -    DEFINE_PROP_CHR("chardev",  ISASerialState, state.chr),
> -    DEFINE_PROP_UINT32("wakeup", ISASerialState, state.wakeup, 0),
> -    DEFINE_PROP_END_OF_LIST(),
> -};
> -
> -static void serial_isa_class_initfn(ObjectClass *klass, void *data)
> -{
> -    DeviceClass *dc = DEVICE_CLASS(klass);
> -    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
> -    ic->init = serial_isa_initfn;
> -    dc->vmsd = &vmstate_isa_serial;
> -    dc->props = serial_isa_properties;
> -}
> -
> -static TypeInfo serial_isa_info = {
> -    .name          = "isa-serial",
> -    .parent        = TYPE_ISA_DEVICE,
> -    .instance_size = sizeof(ISASerialState),
> -    .class_init    = serial_isa_class_initfn,
> -};
> -
> -static void serial_register_types(void)
> -{
> -    type_register_static(&serial_isa_info);
> -}
> -
> -type_init(serial_register_types)
> diff --git a/hw/serial.h b/hw/serial.h
> new file mode 100644
> index 0000000..004a050
> --- /dev/null
> +++ b/hw/serial.h
> @@ -0,0 +1,73 @@

Please make sure to include a license in all new files.

> +#include "hw.h"
> +#include "sysemu.h"
> +#include "memory.h"
> +
> +#define UART_FIFO_LENGTH    16      /* 16550A Fifo Length */
> +
> +typedef struct SerialFIFO {
> +    uint8_t data[UART_FIFO_LENGTH];
> +    uint8_t count;
> +    uint8_t itl;                        /* Interrupt Trigger Level */
> +    uint8_t tail;
> +    uint8_t head;
> +} SerialFIFO;
> +
> +struct SerialState {
> +    uint16_t divider;
> +    uint8_t rbr; /* receive register */
> +    uint8_t thr; /* transmit holding register */
> +    uint8_t tsr; /* transmit shift register */
> +    uint8_t ier;
> +    uint8_t iir; /* read only */
> +    uint8_t lcr;
> +    uint8_t mcr;
> +    uint8_t lsr; /* read only */
> +    uint8_t msr; /* read only */
> +    uint8_t scr;
> +    uint8_t fcr;
> +    uint8_t fcr_vmstate; /* we can't write directly this value
> +                            it has side effects */
> +    /* NOTE: this hidden state is necessary for tx irq generation as
> +       it can be reset while reading iir */
> +    int thr_ipending;
> +    qemu_irq irq;
> +    CharDriverState *chr;
> +    int last_break_enable;
> +    int it_shift;
> +    int baudbase;
> +    int tsr_retry;
> +    uint32_t wakeup;
> +
> +    /* Time when the last byte was successfully sent out of the tsr */
> +    uint64_t last_xmit_ts;
> +    SerialFIFO recv_fifo;
> +    SerialFIFO xmit_fifo;
> +
> +    struct QEMUTimer *fifo_timeout_timer;
> +    int timeout_ipending;           /* timeout interrupt pending state */
> +    struct QEMUTimer *transmit_timer;
> +
> +
> +    uint64_t char_transmit_time;    /* time to transmit a char in ticks */
> +    int poll_msl;
> +
> +    struct QEMUTimer *modem_status_poll;
> +    MemoryRegion io;
> +};
> +
> +extern const VMStateDescription vmstate_serial;
> +extern const MemoryRegionOps serial_io_ops;
> +
> +void serial_init_core(SerialState *s);

Instead of exposing all of this, another option would be to QOM-ify
SerialState such that it can be created by doing object_init() as a
proper child device.

Not a pre-req for this series (it can be done as a follow up).

Regards,

Anthony Liguori

  reply	other threads:[~2012-10-15 14:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-15  8:06 [Qemu-devel] [PATCH v3 0/9] serial device hotplug patch series Gerd Hoffmann
2012-10-15  8:06 ` [Qemu-devel] [PATCH v3 1/9] serial: split serial.c Gerd Hoffmann
2012-10-15 14:16   ` Anthony Liguori [this message]
2012-10-15  8:06 ` [Qemu-devel] [PATCH v3 2/9] serial: add pci variant Gerd Hoffmann
2012-10-15  8:06 ` [Qemu-devel] [PATCH v3 3/9] serial: add windows inf file for the pci card to docs Gerd Hoffmann
2012-10-15  8:06 ` [Qemu-devel] [PATCH v3 4/9] serial: add 2x + 4x pci variant Gerd Hoffmann
2012-10-15 14:18   ` Anthony Liguori
2012-10-15  8:06 ` [Qemu-devel] [PATCH v3 5/9] usb-serial: don't magically zap chardev on umplug Gerd Hoffmann
2012-10-15  8:06 ` [Qemu-devel] [PATCH v3 6/9] usb-serial: only expose device in guest when the chardev is open Gerd Hoffmann
2012-10-15  8:06 ` [Qemu-devel] [PATCH v3 7/9] chardev: add error reporting for qemu_chr_new_from_opts Gerd Hoffmann
2012-10-17  1:12   ` Luiz Capitulino
2012-10-17  1:13     ` Luiz Capitulino
2012-10-15  8:06 ` [Qemu-devel] [PATCH v3 8/9] chardev: fix QemuOpts lifecycle Gerd Hoffmann
2012-10-17  1:18   ` Luiz Capitulino
2012-10-15  8:06 ` [Qemu-devel] [PATCH v3 9/9] chardev: add hotplug support Gerd Hoffmann
2012-10-15 14:22   ` Anthony Liguori
2012-10-15 18:04   ` Eric Blake
2012-10-17  1:49     ` Luiz Capitulino
2012-10-16  9:13   ` Lei Li
2012-10-17  9:27     ` Gerd Hoffmann
2012-10-17  1:28   ` Luiz Capitulino
2012-10-17  1:52 ` [Qemu-devel] [PATCH v3 0/9] serial device hotplug patch series Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877gqrg6sf.fsf@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.