qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: BALATON Zoltan <balaton@eik.bme.hu>
To: Bernhard Beschow <shentey@gmail.com>
Cc: qemu-devel@nongnu.org, "Bin Meng" <bmeng.cn@gmail.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Andrey Smirnov" <andrew.smirnov@gmail.com>,
	"Jean-Christophe Dubois" <jcd@tribudubois.net>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	qemu-block@nongnu.org, "Laurent Vivier" <lvivier@redhat.com>,
	qemu-arm@nongnu.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: Re: [PATCH 04/14] hw/core: Introduce TYPE_SHARED_IRQ
Date: Wed, 8 Jan 2025 14:53:02 +0100 (CET)	[thread overview]
Message-ID: <8c12f28d-ee24-d4dc-f472-a6fe2e401dee@eik.bme.hu> (raw)
In-Reply-To: <20250108092538.11474-5-shentey@gmail.com>

On Wed, 8 Jan 2025, Bernhard Beschow wrote:
> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
> ---
> include/hw/core/shared-irq.h | 39 ++++++++++++++++
> hw/core/shared-irq.c         | 88 ++++++++++++++++++++++++++++++++++++
> hw/core/Kconfig              |  3 ++
> hw/core/meson.build          |  1 +
> 4 files changed, 131 insertions(+)
> create mode 100644 include/hw/core/shared-irq.h
> create mode 100644 hw/core/shared-irq.c
>
> diff --git a/include/hw/core/shared-irq.h b/include/hw/core/shared-irq.h
> new file mode 100644
> index 0000000000..803c303dd0
> --- /dev/null
> +++ b/include/hw/core/shared-irq.h
> @@ -0,0 +1,39 @@
> +/*
> + * IRQ sharing device.
> + *
> + * Copyright (c) 2025 Bernhard Beschow <shentey@gmail.com>
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +/*
> + * This is a simple device which has one GPIO output line and multiple GPIO
> + * input lines. The output line is active if at least one of the input lines is.

How is this different from TYPE_OR_IRQ. Also or-irq.h is in 
include/hw/or-irq.h not in include/hw/core/ where split-irq.h is so maybe 
these could all be moved to one place for consistency? Or-irq also has a 
reset method, do you need one in this device?

Regards,
BALATON Zoltan

> + *
> + * QEMU interface:
> + *  + N unnamed GPIO inputs: the input lines
> + *  + one unnamed GPIO output: the output line
> + *  + QOM property "num-lines": sets the number of input lines
> + */
> +#ifndef HW_SHARED_IRQ_H
> +#define HW_SHARED_IRQ_H
> +
> +#include "hw/sysbus.h"
> +#include "qom/object.h"
> +
> +#define TYPE_SHARED_IRQ "shared-irq"
> +
> +#define MAX_SHARED_LINES 16
> +
> +
> +OBJECT_DECLARE_SIMPLE_TYPE(SharedIRQ, SHARED_IRQ)
> +
> +struct SharedIRQ {
> +    DeviceState parent_obj;
> +
> +    qemu_irq out_irq;
> +    uint16_t irq_states;
> +    uint8_t num_lines;
> +};
> +
> +#endif
> diff --git a/hw/core/shared-irq.c b/hw/core/shared-irq.c
> new file mode 100644
> index 0000000000..b2a4ea4a66
> --- /dev/null
> +++ b/hw/core/shared-irq.c
> @@ -0,0 +1,88 @@
> +/*
> + * IRQ sharing device.
> + *
> + * Copyright (c) 2025 Bernhard Beschow <shentey@gmail.com>
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "qemu/osdep.h"
> +#include "hw/core/shared-irq.h"
> +#include "hw/irq.h"
> +#include "hw/qdev-properties.h"
> +#include "qapi/error.h"
> +#include "migration/vmstate.h"
> +
> +static void shared_irq_handler(void *opaque, int n, int level)
> +{
> +    SharedIRQ *s = opaque;
> +    uint16_t mask = BIT(n);
> +
> +    if (level) {
> +        s->irq_states |= mask;
> +    } else {
> +        s->irq_states &= ~mask;
> +    }
> +
> +    qemu_set_irq(s->out_irq, !!s->irq_states);
> +}
> +
> +static void shared_irq_init(Object *obj)
> +{
> +    SharedIRQ *s = SHARED_IRQ(obj);
> +
> +    qdev_init_gpio_out(DEVICE(s), &s->out_irq, 1);
> +}
> +
> +static void shared_irq_realize(DeviceState *dev, Error **errp)
> +{
> +    SharedIRQ *s = SHARED_IRQ(dev);
> +
> +    if (s->num_lines < 1 || s->num_lines >= MAX_SHARED_LINES) {
> +        error_setg(errp,
> +                   "IRQ shared number of lines %d must be between 1 and %d",
> +                   s->num_lines, MAX_SHARED_LINES);
> +        return;
> +    }
> +
> +    qdev_init_gpio_in(dev, shared_irq_handler, s->num_lines);
> +}
> +
> +static const Property shared_irq_properties[] = {
> +    DEFINE_PROP_UINT8("num-lines", SharedIRQ, num_lines, 1),
> +};
> +
> +static const VMStateDescription shared_irq_vmstate = {
> +    .name = TYPE_SHARED_IRQ,
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .fields = (const VMStateField[]) {
> +        VMSTATE_UINT16(irq_states, SharedIRQ),
> +        VMSTATE_END_OF_LIST()
> +    },
> +};
> +
> +static void shared_irq_class_init(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +
> +    /* No state to reset */
> +    device_class_set_props(dc, shared_irq_properties);
> +    dc->vmsd = &shared_irq_vmstate;
> +    dc->realize = shared_irq_realize;
> +
> +    /* Reason: Needs to be wired up to work */
> +    dc->user_creatable = false;
> +}
> +
> +static const TypeInfo shared_irq_types[] = {
> +    {
> +       .name = TYPE_SHARED_IRQ,
> +       .parent = TYPE_DEVICE,
> +       .instance_size = sizeof(SharedIRQ),
> +       .instance_init = shared_irq_init,
> +       .class_init = shared_irq_class_init,
> +    },
> +};
> +
> +DEFINE_TYPES(shared_irq_types)
> diff --git a/hw/core/Kconfig b/hw/core/Kconfig
> index d1bdf765ee..ddff977963 100644
> --- a/hw/core/Kconfig
> +++ b/hw/core/Kconfig
> @@ -32,6 +32,9 @@ config PLATFORM_BUS
> config REGISTER
>     bool
>
> +config SHARED_IRQ
> +    bool
> +
> config SPLIT_IRQ
>     bool
>
> diff --git a/hw/core/meson.build b/hw/core/meson.build
> index ce9dfa3f4b..6b5bdc8ec7 100644
> --- a/hw/core/meson.build
> +++ b/hw/core/meson.build
> @@ -21,6 +21,7 @@ system_ss.add(when: 'CONFIG_OR_IRQ', if_true: files('or-irq.c'))
> system_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('platform-bus.c'))
> system_ss.add(when: 'CONFIG_PTIMER', if_true: files('ptimer.c'))
> system_ss.add(when: 'CONFIG_REGISTER', if_true: files('register.c'))
> +system_ss.add(when: 'CONFIG_SHARED_IRQ', if_true: files('shared-irq.c'))
> system_ss.add(when: 'CONFIG_SPLIT_IRQ', if_true: files('split-irq.c'))
> system_ss.add(when: 'CONFIG_XILINX_AXI', if_true: files('stream.c'))
> system_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('sysbus-fdt.c'))
>


  reply	other threads:[~2025-01-08 13:54 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08  9:25 [PATCH 00/14] i.MX and SDHCI improvements Bernhard Beschow
2025-01-08  9:25 ` [PATCH 01/14] hw/sd/sdhci: Set SDHC_NIS_DMA bit when appropriate Bernhard Beschow
2025-01-09 12:10   ` Philippe Mathieu-Daudé
2025-01-08  9:25 ` [PATCH 02/14] hw/char/imx_serial: Fix reset value of UFCR register Bernhard Beschow
2025-01-08  9:25 ` [PATCH 03/14] hw/char/imx_serial: Update all state before restarting ageing timer Bernhard Beschow
2025-01-08  9:25 ` [PATCH 04/14] hw/core: Introduce TYPE_SHARED_IRQ Bernhard Beschow
2025-01-08 13:53   ` BALATON Zoltan [this message]
2025-01-09  9:14     ` Bernhard Beschow
2025-01-08 14:26   ` Bernhard Beschow
2025-01-09 11:43     ` David Woodhouse
2025-01-08  9:25 ` [PATCH 05/14] hw/pci-host/designware: Expose MSI IRQ Bernhard Beschow
2025-01-08  9:25 ` [PATCH 06/14] hw/gpio/imx_gpio: Don't clear input GPIO values upon reset Bernhard Beschow
2025-01-08  9:25 ` [PATCH 07/14] hw/sd/sd: Remove legacy sd_set_cb() in favor of GPIOs Bernhard Beschow
2025-01-09 11:37   ` Philippe Mathieu-Daudé
2025-01-08  9:25 ` [PATCH 08/14] hw/sd/sd: Allow for inverting polarities of presence and write-protect GPIOs Bernhard Beschow
2025-01-09 11:40   ` Philippe Mathieu-Daudé
2025-01-09 16:20     ` Bernhard Beschow
2025-01-12 18:06       ` Philippe Mathieu-Daudé
2025-01-16 23:20         ` Bernhard Beschow
2025-01-17 17:24           ` Philippe Mathieu-Daudé
2025-01-08  9:25 ` [PATCH 09/14] hw/char/imx_serial: Turn some DPRINTF() statements into trace events Bernhard Beschow
2025-01-09 11:42   ` Philippe Mathieu-Daudé
2025-01-08  9:25 ` [PATCH 10/14] hw/timer/imx_gpt: Remove unused define Bernhard Beschow
2025-01-08 16:21   ` Philippe Mathieu-Daudé
2025-01-08  9:25 ` [PATCH 11/14] tests/qtest/libqos: Reuse TYPE_IMX_I2C define Bernhard Beschow
2025-01-09 11:58   ` Philippe Mathieu-Daudé
2025-01-09 14:59   ` Fabiano Rosas
2025-01-08  9:25 ` [PATCH 12/14] hw/i2c/imx_i2c: Convert DPRINTF() to trace events Bernhard Beschow
2025-01-09 11:43   ` Philippe Mathieu-Daudé
2025-01-09 11:56     ` Philippe Mathieu-Daudé
2025-01-09 12:38       ` Philippe Mathieu-Daudé
2025-01-09 16:16         ` Bernhard Beschow
2025-01-08  9:25 ` [PATCH 13/14] hw/misc/imx6_src: " Bernhard Beschow
2025-01-09 11:44   ` Philippe Mathieu-Daudé
2025-01-08  9:25 ` [PATCH 14/14] hw/gpio/imx_gpio: Turn DPRINTF() into " Bernhard Beschow
2025-01-09 11:57   ` Philippe Mathieu-Daudé

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=8c12f28d-ee24-d4dc-f472-a6fe2e401dee@eik.bme.hu \
    --to=balaton@eik.bme.hu \
    --cc=andrew.smirnov@gmail.com \
    --cc=bmeng.cn@gmail.com \
    --cc=farosas@suse.de \
    --cc=jcd@tribudubois.net \
    --cc=linux@roeck-us.net \
    --cc=lvivier@redhat.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-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=shentey@gmail.com \
    /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).