qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-arm@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH 6/8] hw/char/cmsdk-apb-uart: Open-code cmsdk_apb_uart_create()
Date: Mon, 20 Feb 2023 15:33:00 +0000	[thread overview]
Message-ID: <87cz64s64x.fsf@linaro.org> (raw)
In-Reply-To: <20230220115114.25237-7-philmd@linaro.org>


Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> cmsdk_apb_uart_create() is only used twice in the same
> file. Open-code it.

Hmm, you could just as easily make cmsdk_apb_uart_create a private
static function and avoid any copy paste snafus if something needs
changing.

>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/arm/mps2.c                    | 41 +++++++++++++++++++++-----------
>  include/hw/char/cmsdk-apb-uart.h | 34 --------------------------
>  2 files changed, 27 insertions(+), 48 deletions(-)
>
> diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
> index a86a994dba..d92fd60684 100644
> --- a/hw/arm/mps2.c
> +++ b/hw/arm/mps2.c
> @@ -35,6 +35,7 @@
>  #include "hw/boards.h"
>  #include "exec/address-spaces.h"
>  #include "sysemu/sysemu.h"
> +#include "hw/qdev-properties.h"
>  #include "hw/misc/unimp.h"
>  #include "hw/char/cmsdk-apb-uart.h"
>  #include "hw/timer/cmsdk-apb-timer.h"
> @@ -282,6 +283,9 @@ static void mps2_common_init(MachineState *machine)
>          qdev_connect_gpio_out(orgate_dev, 0, qdev_get_gpio_in(armv7m, 12));
>  
>          for (i = 0; i < 5; i++) {
> +            DeviceState *dev;
> +            SysBusDevice *s;
> +
>              static const hwaddr uartbase[] = {0x40004000, 0x40005000,
>                                                0x40006000, 0x40007000,
>                                                0x40009000};
> @@ -294,12 +298,16 @@ static void mps2_common_init(MachineState *machine)
>                  rxovrint = qdev_get_gpio_in(orgate_dev, i * 2 + 1);
>              }
>  
> -            cmsdk_apb_uart_create(uartbase[i],
> -                                  qdev_get_gpio_in(armv7m, uartirq[i] + 1),
> -                                  qdev_get_gpio_in(armv7m, uartirq[i]),
> -                                  txovrint, rxovrint,
> -                                  NULL,
> -                                  serial_hd(i), SYSCLK_FRQ);
> +            dev = qdev_new(TYPE_CMSDK_APB_UART);
> +            s = SYS_BUS_DEVICE(dev);
> +            qdev_prop_set_chr(dev, "chardev", serial_hd(i));
> +            qdev_prop_set_uint32(dev, "pclk-frq", SYSCLK_FRQ);
> +            sysbus_realize_and_unref(s, &error_fatal);
> +            sysbus_mmio_map(s, 0, uartbase[i]);
> +            sysbus_connect_irq(s, 0, qdev_get_gpio_in(armv7m, uartirq[i] + 1));
> +            sysbus_connect_irq(s, 1, qdev_get_gpio_in(armv7m, uartirq[i]));
> +            sysbus_connect_irq(s, 2, txovrint);
> +            sysbus_connect_irq(s, 3, rxovrint);
>          }
>          break;
>      }
> @@ -324,7 +332,8 @@ static void mps2_common_init(MachineState *machine)
>                                                0x4002c000, 0x4002d000,
>                                                0x4002e000};
>              Object *txrx_orgate;
> -            DeviceState *txrx_orgate_dev;
> +            DeviceState *txrx_orgate_dev, *dev;
> +            SysBusDevice *s;
>  
>              txrx_orgate = object_new(TYPE_OR_IRQ);
>              object_property_set_int(txrx_orgate, "num-lines", 2, &error_fatal);
> @@ -332,13 +341,17 @@ static void mps2_common_init(MachineState *machine)
>              txrx_orgate_dev = DEVICE(txrx_orgate);
>              qdev_connect_gpio_out(txrx_orgate_dev, 0,
>                                    qdev_get_gpio_in(armv7m, uart_txrx_irqno[i]));
> -            cmsdk_apb_uart_create(uartbase[i],
> -                                  qdev_get_gpio_in(txrx_orgate_dev, 0),
> -                                  qdev_get_gpio_in(txrx_orgate_dev, 1),
> -                                  qdev_get_gpio_in(orgate_dev, i * 2),
> -                                  qdev_get_gpio_in(orgate_dev, i * 2 + 1),
> -                                  NULL,
> -                                  serial_hd(i), SYSCLK_FRQ);
> +
> +            dev = qdev_new(TYPE_CMSDK_APB_UART);
> +            s = SYS_BUS_DEVICE(dev);
> +            qdev_prop_set_chr(dev, "chardev", serial_hd(i));
> +            qdev_prop_set_uint32(dev, "pclk-frq", SYSCLK_FRQ);
> +            sysbus_realize_and_unref(s, &error_fatal);
> +            sysbus_mmio_map(s, 0, uartbase[i]);
> +            sysbus_connect_irq(s, 0, qdev_get_gpio_in(txrx_orgate_dev, 0));
> +            sysbus_connect_irq(s, 1, qdev_get_gpio_in(txrx_orgate_dev, 1));
> +            sysbus_connect_irq(s, 2, qdev_get_gpio_in(orgate_dev, i * 2));
> +            sysbus_connect_irq(s, 3, qdev_get_gpio_in(orgate_dev, i * 2 + 1));
>          }
>          break;
>      }
> diff --git a/include/hw/char/cmsdk-apb-uart.h b/include/hw/char/cmsdk-apb-uart.h
> index 64b0a3d534..7de8f8d1b9 100644
> --- a/include/hw/char/cmsdk-apb-uart.h
> +++ b/include/hw/char/cmsdk-apb-uart.h
> @@ -12,10 +12,8 @@
>  #ifndef CMSDK_APB_UART_H
>  #define CMSDK_APB_UART_H
>  
> -#include "hw/qdev-properties.h"
>  #include "hw/sysbus.h"
>  #include "chardev/char-fe.h"
> -#include "qapi/error.h"
>  #include "qom/object.h"
>  
>  #define TYPE_CMSDK_APB_UART "cmsdk-apb-uart"
> @@ -45,36 +43,4 @@ struct CMSDKAPBUART {
>      uint8_t rxbuf;
>  };
>  
> -/**
> - * cmsdk_apb_uart_create - convenience function to create TYPE_CMSDK_APB_UART
> - * @addr: location in system memory to map registers
> - * @chr: Chardev backend to connect UART to, or NULL if no backend
> - * @pclk_frq: frequency in Hz of the PCLK clock (used for calculating baud rate)
> - */
> -static inline DeviceState *cmsdk_apb_uart_create(hwaddr addr,
> -                                                 qemu_irq txint,
> -                                                 qemu_irq rxint,
> -                                                 qemu_irq txovrint,
> -                                                 qemu_irq rxovrint,
> -                                                 qemu_irq uartint,
> -                                                 Chardev *chr,
> -                                                 uint32_t pclk_frq)
> -{
> -    DeviceState *dev;
> -    SysBusDevice *s;
> -
> -    dev = qdev_new(TYPE_CMSDK_APB_UART);
> -    s = SYS_BUS_DEVICE(dev);
> -    qdev_prop_set_chr(dev, "chardev", chr);
> -    qdev_prop_set_uint32(dev, "pclk-frq", pclk_frq);
> -    sysbus_realize_and_unref(s, &error_fatal);
> -    sysbus_mmio_map(s, 0, addr);
> -    sysbus_connect_irq(s, 0, txint);
> -    sysbus_connect_irq(s, 1, rxint);
> -    sysbus_connect_irq(s, 2, txovrint);
> -    sysbus_connect_irq(s, 3, rxovrint);
> -    sysbus_connect_irq(s, 4, uartint);
> -    return dev;
> -}
> -
>  #endif


-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  reply	other threads:[~2023-02-20 15:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-20 11:51 [PATCH 0/8] hw/arm: Cleanups around QOM style Philippe Mathieu-Daudé
2023-02-20 11:51 ` [PATCH 1/8] hw/gpio/max7310: Simplify max7310_realize() Philippe Mathieu-Daudé
2023-02-20 18:49   ` Richard Henderson
2023-02-20 11:51 ` [PATCH 2/8] hw/char/pl011: Un-inline pl011_create() Philippe Mathieu-Daudé
2023-02-20 15:30   ` Alex Bennée
2023-02-20 18:50   ` Richard Henderson
2023-02-20 11:51 ` [PATCH 3/8] hw/char/pl011: Open-code pl011_luminary_create() Philippe Mathieu-Daudé
2023-02-20 15:31   ` Alex Bennée
2023-02-20 18:51   ` Richard Henderson
2023-02-20 11:51 ` [PATCH 4/8] hw/char/xilinx_uartlite: Expose XILINX_UARTLITE QOM type Philippe Mathieu-Daudé
2023-02-20 15:32   ` Alex Bennée
2023-02-20 18:53   ` Richard Henderson
2023-02-20 11:51 ` [PATCH 5/8] hw/char/xilinx_uartlite: Open-code xilinx_uartlite_create() Philippe Mathieu-Daudé
2023-02-20 15:32   ` Alex Bennée
2023-02-20 18:56   ` Richard Henderson
2023-02-20 11:51 ` [PATCH 6/8] hw/char/cmsdk-apb-uart: Open-code cmsdk_apb_uart_create() Philippe Mathieu-Daudé
2023-02-20 15:33   ` Alex Bennée [this message]
2023-02-21 16:49     ` Peter Maydell
2023-02-20 11:51 ` [PATCH 7/8] hw/timer/cmsdk-apb-timer: Remove unused 'qdev-properties.h' header Philippe Mathieu-Daudé
2023-02-20 15:34   ` Alex Bennée
2023-02-20 11:51 ` [PATCH 8/8] hw/intc/armv7m_nvic: Use QOM cast CPU() macro Philippe Mathieu-Daudé
2023-02-20 15:34   ` Alex Bennée
2023-02-21 17:45 ` [PATCH 0/8] hw/arm: Cleanups around QOM style Peter Maydell

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=87cz64s64x.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=alistair@alistair23.me \
    --cc=armbru@redhat.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).