Re: [Qemu-devel] [PATCH v4] hw/char: remove legacy interface escc_init()

2018-02-14 Thread David Gibson
On Wed, Feb 14, 2018 at 07:35:58AM +0100, Laurent Vivier wrote:
> Move necessary stuff in escc.h and update type names.
> Remove slavio_serial_ms_kbd_init().
> Fix code style problems reported by checkpatch.pl
> Update mac_newworld, mac_oldworld and sun4m to use directly the
> QDEV interface.
> 
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Philippe Mathieu-Daudé 
> Reviewed-by: Mark Cave-Ayland 

Applied, thanks.

> ---
> 
> Notes:
> v4: rebase and add Mark's R-b
> v3: in sun4m, move comments about Slavio TTY
> above both qdev_create().
> v2: in sun4m, move comments about Slavio TTY close to
> their qdev_prop_set_chr()²
> 
>  hw/char/escc.c | 209 
> ++---
>  hw/ppc/mac_newworld.c  |  19 -
>  hw/ppc/mac_oldworld.c  |  19 -
>  hw/sparc/sun4m.c   |  34 +++-
>  include/hw/char/escc.h |  54 +++--
>  5 files changed, 170 insertions(+), 165 deletions(-)
> 
> diff --git a/hw/char/escc.c b/hw/char/escc.c
> index 449bf2fc63..628f5f81f7 100644
> --- a/hw/char/escc.c
> +++ b/hw/char/escc.c
> @@ -26,10 +26,7 @@
>  #include "hw/hw.h"
>  #include "hw/sysbus.h"
>  #include "hw/char/escc.h"
> -#include "chardev/char-fe.h"
> -#include "chardev/char-serial.h"
>  #include "ui/console.h"
> -#include "ui/input.h"
>  #include "trace.h"
>  
>  /*
> @@ -64,53 +61,7 @@
>   *  2010-May-23  Artyom Tarasenko:  Reworked IUS logic
>   */
>  
> -typedef enum {
> -chn_a, chn_b,
> -} ChnID;
> -
> -#define CHN_C(s) ((s)->chn == chn_b? 'b' : 'a')
> -
> -typedef enum {
> -ser, kbd, mouse,
> -} ChnType;
> -
> -#define SERIO_QUEUE_SIZE 256
> -
> -typedef struct {
> -uint8_t data[SERIO_QUEUE_SIZE];
> -int rptr, wptr, count;
> -} SERIOQueue;
> -
> -#define SERIAL_REGS 16
> -typedef struct ChannelState {
> -qemu_irq irq;
> -uint32_t rxint, txint, rxint_under_svc, txint_under_svc;
> -struct ChannelState *otherchn;
> -uint32_t reg;
> -uint8_t wregs[SERIAL_REGS], rregs[SERIAL_REGS];
> -SERIOQueue queue;
> -CharBackend chr;
> -int e0_mode, led_mode, caps_lock_mode, num_lock_mode;
> -int disabled;
> -int clock;
> -uint32_t vmstate_dummy;
> -ChnID chn; // this channel, A (base+4) or B (base+0)
> -ChnType type;
> -uint8_t rx, tx;
> -QemuInputHandlerState *hs;
> -} ChannelState;
> -
> -#define ESCC(obj) OBJECT_CHECK(ESCCState, (obj), TYPE_ESCC)
> -
> -typedef struct ESCCState {
> -SysBusDevice parent_obj;
> -
> -struct ChannelState chn[2];
> -uint32_t it_shift;
> -MemoryRegion mmio;
> -uint32_t disabled;
> -uint32_t frequency;
> -} ESCCState;
> +#define CHN_C(s) ((s)->chn == escc_chn_b ? 'b' : 'a')
>  
>  #define SERIAL_CTRL 0
>  #define SERIAL_DATA 1
> @@ -214,44 +165,47 @@ typedef struct ESCCState {
>  #define R_MISC1I 14
>  #define R_EXTINT 15
>  
> -static void handle_kbd_command(ChannelState *s, int val);
> +static void handle_kbd_command(ESCCChannelState *s, int val);
>  static int serial_can_receive(void *opaque);
> -static void serial_receive_byte(ChannelState *s, int ch);
> +static void serial_receive_byte(ESCCChannelState *s, int ch);
>  
>  static void clear_queue(void *opaque)
>  {
> -ChannelState *s = opaque;
> -SERIOQueue *q = >queue;
> +ESCCChannelState *s = opaque;
> +ESCCSERIOQueue *q = >queue;
>  q->rptr = q->wptr = q->count = 0;
>  }
>  
>  static void put_queue(void *opaque, int b)
>  {
> -ChannelState *s = opaque;
> -SERIOQueue *q = >queue;
> +ESCCChannelState *s = opaque;
> +ESCCSERIOQueue *q = >queue;
>  
>  trace_escc_put_queue(CHN_C(s), b);
> -if (q->count >= SERIO_QUEUE_SIZE)
> +if (q->count >= ESCC_SERIO_QUEUE_SIZE) {
>  return;
> +}
>  q->data[q->wptr] = b;
> -if (++q->wptr == SERIO_QUEUE_SIZE)
> +if (++q->wptr == ESCC_SERIO_QUEUE_SIZE) {
>  q->wptr = 0;
> +}
>  q->count++;
>  serial_receive_byte(s, 0);
>  }
>  
>  static uint32_t get_queue(void *opaque)
>  {
> -ChannelState *s = opaque;
> -SERIOQueue *q = >queue;
> +ESCCChannelState *s = opaque;
> +ESCCSERIOQueue *q = >queue;
>  int val;
>  
>  if (q->count == 0) {
>  return 0;
>  } else {
>  val = q->data[q->rptr];
> -if (++q->rptr == SERIO_QUEUE_SIZE)
> +if (++q->rptr == ESCC_SERIO_QUEUE_SIZE) {
>  q->rptr = 0;
> +}
>  q->count--;
>  }
>  trace_escc_get_queue(CHN_C(s), val);
> @@ -260,7 +214,7 @@ static uint32_t get_queue(void *opaque)
>  return val;
>  }
>  
> -static int escc_update_irq_chn(ChannelState *s)
> +static int escc_update_irq_chn(ESCCChannelState *s)
>  {
>  if s->wregs[W_INTR] & INTR_TXINT) && (s->txint == 1)) ||
>   // tx ints enabled, pending
> @@ -274,7 +228,7 @@ static int escc_update_irq_chn(ChannelState *s)
>  return 0;
>  }
>  
> -static void escc_update_irq(ChannelState *s)

[Qemu-devel] [PATCH v4] hw/char: remove legacy interface escc_init()

2018-02-13 Thread Laurent Vivier
Move necessary stuff in escc.h and update type names.
Remove slavio_serial_ms_kbd_init().
Fix code style problems reported by checkpatch.pl
Update mac_newworld, mac_oldworld and sun4m to use directly the
QDEV interface.

Signed-off-by: Laurent Vivier 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Mark Cave-Ayland 
---

Notes:
v4: rebase and add Mark's R-b
v3: in sun4m, move comments about Slavio TTY
above both qdev_create().
v2: in sun4m, move comments about Slavio TTY close to
their qdev_prop_set_chr()²

 hw/char/escc.c | 209 ++---
 hw/ppc/mac_newworld.c  |  19 -
 hw/ppc/mac_oldworld.c  |  19 -
 hw/sparc/sun4m.c   |  34 +++-
 include/hw/char/escc.h |  54 +++--
 5 files changed, 170 insertions(+), 165 deletions(-)

diff --git a/hw/char/escc.c b/hw/char/escc.c
index 449bf2fc63..628f5f81f7 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -26,10 +26,7 @@
 #include "hw/hw.h"
 #include "hw/sysbus.h"
 #include "hw/char/escc.h"
-#include "chardev/char-fe.h"
-#include "chardev/char-serial.h"
 #include "ui/console.h"
-#include "ui/input.h"
 #include "trace.h"
 
 /*
@@ -64,53 +61,7 @@
  *  2010-May-23  Artyom Tarasenko:  Reworked IUS logic
  */
 
-typedef enum {
-chn_a, chn_b,
-} ChnID;
-
-#define CHN_C(s) ((s)->chn == chn_b? 'b' : 'a')
-
-typedef enum {
-ser, kbd, mouse,
-} ChnType;
-
-#define SERIO_QUEUE_SIZE 256
-
-typedef struct {
-uint8_t data[SERIO_QUEUE_SIZE];
-int rptr, wptr, count;
-} SERIOQueue;
-
-#define SERIAL_REGS 16
-typedef struct ChannelState {
-qemu_irq irq;
-uint32_t rxint, txint, rxint_under_svc, txint_under_svc;
-struct ChannelState *otherchn;
-uint32_t reg;
-uint8_t wregs[SERIAL_REGS], rregs[SERIAL_REGS];
-SERIOQueue queue;
-CharBackend chr;
-int e0_mode, led_mode, caps_lock_mode, num_lock_mode;
-int disabled;
-int clock;
-uint32_t vmstate_dummy;
-ChnID chn; // this channel, A (base+4) or B (base+0)
-ChnType type;
-uint8_t rx, tx;
-QemuInputHandlerState *hs;
-} ChannelState;
-
-#define ESCC(obj) OBJECT_CHECK(ESCCState, (obj), TYPE_ESCC)
-
-typedef struct ESCCState {
-SysBusDevice parent_obj;
-
-struct ChannelState chn[2];
-uint32_t it_shift;
-MemoryRegion mmio;
-uint32_t disabled;
-uint32_t frequency;
-} ESCCState;
+#define CHN_C(s) ((s)->chn == escc_chn_b ? 'b' : 'a')
 
 #define SERIAL_CTRL 0
 #define SERIAL_DATA 1
@@ -214,44 +165,47 @@ typedef struct ESCCState {
 #define R_MISC1I 14
 #define R_EXTINT 15
 
-static void handle_kbd_command(ChannelState *s, int val);
+static void handle_kbd_command(ESCCChannelState *s, int val);
 static int serial_can_receive(void *opaque);
-static void serial_receive_byte(ChannelState *s, int ch);
+static void serial_receive_byte(ESCCChannelState *s, int ch);
 
 static void clear_queue(void *opaque)
 {
-ChannelState *s = opaque;
-SERIOQueue *q = >queue;
+ESCCChannelState *s = opaque;
+ESCCSERIOQueue *q = >queue;
 q->rptr = q->wptr = q->count = 0;
 }
 
 static void put_queue(void *opaque, int b)
 {
-ChannelState *s = opaque;
-SERIOQueue *q = >queue;
+ESCCChannelState *s = opaque;
+ESCCSERIOQueue *q = >queue;
 
 trace_escc_put_queue(CHN_C(s), b);
-if (q->count >= SERIO_QUEUE_SIZE)
+if (q->count >= ESCC_SERIO_QUEUE_SIZE) {
 return;
+}
 q->data[q->wptr] = b;
-if (++q->wptr == SERIO_QUEUE_SIZE)
+if (++q->wptr == ESCC_SERIO_QUEUE_SIZE) {
 q->wptr = 0;
+}
 q->count++;
 serial_receive_byte(s, 0);
 }
 
 static uint32_t get_queue(void *opaque)
 {
-ChannelState *s = opaque;
-SERIOQueue *q = >queue;
+ESCCChannelState *s = opaque;
+ESCCSERIOQueue *q = >queue;
 int val;
 
 if (q->count == 0) {
 return 0;
 } else {
 val = q->data[q->rptr];
-if (++q->rptr == SERIO_QUEUE_SIZE)
+if (++q->rptr == ESCC_SERIO_QUEUE_SIZE) {
 q->rptr = 0;
+}
 q->count--;
 }
 trace_escc_get_queue(CHN_C(s), val);
@@ -260,7 +214,7 @@ static uint32_t get_queue(void *opaque)
 return val;
 }
 
-static int escc_update_irq_chn(ChannelState *s)
+static int escc_update_irq_chn(ESCCChannelState *s)
 {
 if s->wregs[W_INTR] & INTR_TXINT) && (s->txint == 1)) ||
  // tx ints enabled, pending
@@ -274,7 +228,7 @@ static int escc_update_irq_chn(ChannelState *s)
 return 0;
 }
 
-static void escc_update_irq(ChannelState *s)
+static void escc_update_irq(ESCCChannelState *s)
 {
 int irq;
 
@@ -285,12 +239,12 @@ static void escc_update_irq(ChannelState *s)
 qemu_set_irq(s->irq, irq);
 }
 
-static void escc_reset_chn(ChannelState *s)
+static void escc_reset_chn(ESCCChannelState *s)
 {
 int i;
 
 s->reg = 0;
-for (i = 0; i < SERIAL_REGS; i++) {
+for (i = 0; i < ESCC_SERIAL_REGS; i++) {
 s->rregs[i] = 0;