diff mbox series

[05/14] hw/char/pl011: Allow use as an embedded-struct device

Message ID 20190214125107.22178-6-peter.maydell@linaro.org
State Superseded
Headers show
Series Add model of the Arm Musca devboards | expand

Commit Message

Peter Maydell Feb. 14, 2019, 12:50 p.m. UTC
Create a new include file for the pl011's device struct,
type macros, etc, so that it can be instantiated using
the "embedded struct" coding style.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

---
 include/hw/char/pl011.h | 34 ++++++++++++++++++++++++++++++++++
 hw/char/pl011.c         | 31 ++-----------------------------
 2 files changed, 36 insertions(+), 29 deletions(-)

-- 
2.20.1

Comments

Richard Henderson Feb. 17, 2019, 5:57 p.m. UTC | #1
On 2/14/19 4:50 AM, Peter Maydell wrote:
> Create a new include file for the pl011's device struct,

> type macros, etc, so that it can be instantiated using

> the "embedded struct" coding style.

> 

> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

> ---

>  include/hw/char/pl011.h | 34 ++++++++++++++++++++++++++++++++++

>  hw/char/pl011.c         | 31 ++-----------------------------

>  2 files changed, 36 insertions(+), 29 deletions(-)


Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
Philippe Mathieu-Daudé Feb. 18, 2019, 9:59 p.m. UTC | #2
On 2/14/19 1:50 PM, Peter Maydell wrote:
> Create a new include file for the pl011's device struct,

> type macros, etc, so that it can be instantiated using

> the "embedded struct" coding style.

> 

> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>


Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>


> ---

>  include/hw/char/pl011.h | 34 ++++++++++++++++++++++++++++++++++

>  hw/char/pl011.c         | 31 ++-----------------------------

>  2 files changed, 36 insertions(+), 29 deletions(-)

> 

> diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h

> index 83649324b6a..1b52bfd5c90 100644

> --- a/include/hw/char/pl011.h

> +++ b/include/hw/char/pl011.h

> @@ -15,6 +15,40 @@

>  #ifndef HW_PL011_H

>  #define HW_PL011_H

>  

> +#include "hw/sysbus.h"

> +#include "chardev/char-fe.h"

> +

> +#define TYPE_PL011 "pl011"

> +#define PL011(obj) OBJECT_CHECK(PL011State, (obj), TYPE_PL011)

> +

> +/* This shares the same struct (and cast macro) as the base pl011 device */

> +#define TYPE_PL011_LUMINARY "pl011_luminary"

> +

> +typedef struct PL011State {

> +    SysBusDevice parent_obj;

> +

> +    MemoryRegion iomem;

> +    uint32_t readbuff;

> +    uint32_t flags;

> +    uint32_t lcr;

> +    uint32_t rsr;

> +    uint32_t cr;

> +    uint32_t dmacr;

> +    uint32_t int_enabled;

> +    uint32_t int_level;

> +    uint32_t read_fifo[16];

> +    uint32_t ilpr;

> +    uint32_t ibrd;

> +    uint32_t fbrd;

> +    uint32_t ifl;

> +    int read_pos;

> +    int read_count;

> +    int read_trigger;

> +    CharBackend chr;

> +    qemu_irq irq;

> +    const unsigned char *id;

> +} PL011State;

> +

>  static inline DeviceState *pl011_create(hwaddr addr,

>                                          qemu_irq irq,

>                                          Chardev *chr)

> diff --git a/hw/char/pl011.c b/hw/char/pl011.c

> index 2aa277fc4f2..0c4711e4027 100644

> --- a/hw/char/pl011.c

> +++ b/hw/char/pl011.c

> @@ -8,39 +8,12 @@

>   */

>  

>  #include "qemu/osdep.h"

> +#include "hw/char/pl011.h"

>  #include "hw/sysbus.h"

>  #include "chardev/char-fe.h"

>  #include "qemu/log.h"

>  #include "trace.h"

>  

> -#define TYPE_PL011 "pl011"

> -#define PL011(obj) OBJECT_CHECK(PL011State, (obj), TYPE_PL011)

> -

> -typedef struct PL011State {

> -    SysBusDevice parent_obj;

> -

> -    MemoryRegion iomem;

> -    uint32_t readbuff;

> -    uint32_t flags;

> -    uint32_t lcr;

> -    uint32_t rsr;

> -    uint32_t cr;

> -    uint32_t dmacr;

> -    uint32_t int_enabled;

> -    uint32_t int_level;

> -    uint32_t read_fifo[16];

> -    uint32_t ilpr;

> -    uint32_t ibrd;

> -    uint32_t fbrd;

> -    uint32_t ifl;

> -    int read_pos;

> -    int read_count;

> -    int read_trigger;

> -    CharBackend chr;

> -    qemu_irq irq;

> -    const unsigned char *id;

> -} PL011State;

> -

>  #define PL011_INT_TX 0x20

>  #define PL011_INT_RX 0x10

>  

> @@ -357,7 +330,7 @@ static void pl011_luminary_init(Object *obj)

>  }

>  

>  static const TypeInfo pl011_luminary_info = {

> -    .name          = "pl011_luminary",

> +    .name          = TYPE_PL011_LUMINARY,

>      .parent        = TYPE_PL011,

>      .instance_init = pl011_luminary_init,

>  };

>
diff mbox series

Patch

diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h
index 83649324b6a..1b52bfd5c90 100644
--- a/include/hw/char/pl011.h
+++ b/include/hw/char/pl011.h
@@ -15,6 +15,40 @@ 
 #ifndef HW_PL011_H
 #define HW_PL011_H
 
+#include "hw/sysbus.h"
+#include "chardev/char-fe.h"
+
+#define TYPE_PL011 "pl011"
+#define PL011(obj) OBJECT_CHECK(PL011State, (obj), TYPE_PL011)
+
+/* This shares the same struct (and cast macro) as the base pl011 device */
+#define TYPE_PL011_LUMINARY "pl011_luminary"
+
+typedef struct PL011State {
+    SysBusDevice parent_obj;
+
+    MemoryRegion iomem;
+    uint32_t readbuff;
+    uint32_t flags;
+    uint32_t lcr;
+    uint32_t rsr;
+    uint32_t cr;
+    uint32_t dmacr;
+    uint32_t int_enabled;
+    uint32_t int_level;
+    uint32_t read_fifo[16];
+    uint32_t ilpr;
+    uint32_t ibrd;
+    uint32_t fbrd;
+    uint32_t ifl;
+    int read_pos;
+    int read_count;
+    int read_trigger;
+    CharBackend chr;
+    qemu_irq irq;
+    const unsigned char *id;
+} PL011State;
+
 static inline DeviceState *pl011_create(hwaddr addr,
                                         qemu_irq irq,
                                         Chardev *chr)
diff --git a/hw/char/pl011.c b/hw/char/pl011.c
index 2aa277fc4f2..0c4711e4027 100644
--- a/hw/char/pl011.c
+++ b/hw/char/pl011.c
@@ -8,39 +8,12 @@ 
  */
 
 #include "qemu/osdep.h"
+#include "hw/char/pl011.h"
 #include "hw/sysbus.h"
 #include "chardev/char-fe.h"
 #include "qemu/log.h"
 #include "trace.h"
 
-#define TYPE_PL011 "pl011"
-#define PL011(obj) OBJECT_CHECK(PL011State, (obj), TYPE_PL011)
-
-typedef struct PL011State {
-    SysBusDevice parent_obj;
-
-    MemoryRegion iomem;
-    uint32_t readbuff;
-    uint32_t flags;
-    uint32_t lcr;
-    uint32_t rsr;
-    uint32_t cr;
-    uint32_t dmacr;
-    uint32_t int_enabled;
-    uint32_t int_level;
-    uint32_t read_fifo[16];
-    uint32_t ilpr;
-    uint32_t ibrd;
-    uint32_t fbrd;
-    uint32_t ifl;
-    int read_pos;
-    int read_count;
-    int read_trigger;
-    CharBackend chr;
-    qemu_irq irq;
-    const unsigned char *id;
-} PL011State;
-
 #define PL011_INT_TX 0x20
 #define PL011_INT_RX 0x10
 
@@ -357,7 +330,7 @@  static void pl011_luminary_init(Object *obj)
 }
 
 static const TypeInfo pl011_luminary_info = {
-    .name          = "pl011_luminary",
+    .name          = TYPE_PL011_LUMINARY,
     .parent        = TYPE_PL011,
     .instance_init = pl011_luminary_init,
 };