From: Niek Linnenbank <nieklinnenbank@gmail.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: Beniamino Galvani <b.galvani@gmail.com>,
Peter Maydell <peter.maydell@linaro.org>,
qemu-arm <qemu-arm@nongnu.org>,
QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [RFC PATCH 11/13] hw/timer/allwinner: Introduce TYPE_AW_COMMON_PIT abstract device
Date: Fri, 20 Dec 2019 22:11:00 +0100 [thread overview]
Message-ID: <CAPan3WqvSFbuS8FwvVTby-gsQ1pmxJf=PUET39Ftu0oiN4GV1w@mail.gmail.com> (raw)
In-Reply-To: <20191219185127.24388-12-f4bug@amsat.org>
[-- Attachment #1: Type: text/plain, Size: 5026 bytes --]
Hi Philippe,
On Thu, Dec 19, 2019 at 7:51 PM Philippe Mathieu-Daudé <f4bug@amsat.org>
wrote:
> Extract the common code from the TYPE_AW_A10_PIT device into a new
> abstract device: TYPE_AW_COMMON_PIT, then use it as parent, so we
> inherit the same functionalities.
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> At this point, the only fields we can modify are the timer_count
> and the region_size. Not enough to implement the H3 timer, since
> we need to move the WDOG register. Still some progress, so Niek
> can continue ;)
> ---
> include/hw/timer/allwinner-a10-pit.h | 1 +
> hw/timer/allwinner-a10-pit.c | 50 +++++++++++++++++++++++-----
> 2 files changed, 43 insertions(+), 8 deletions(-)
>
> diff --git a/include/hw/timer/allwinner-a10-pit.h
> b/include/hw/timer/allwinner-a10-pit.h
> index 9e28c6697a..8453a62706 100644
> --- a/include/hw/timer/allwinner-a10-pit.h
> +++ b/include/hw/timer/allwinner-a10-pit.h
> @@ -4,6 +4,7 @@
> #include "hw/ptimer.h"
> #include "hw/sysbus.h"
>
> +#define TYPE_AW_COMMON_PIT "allwinner-timer-controller"
> #define TYPE_AW_A10_PIT "allwinner-A10-timer"
>
So for the Allwinner H3, that means we'll need another TYPE_AW_H3_PIT
definition?
>
> #define AW_PIT_TIMER_MAX 6
> diff --git a/hw/timer/allwinner-a10-pit.c b/hw/timer/allwinner-a10-pit.c
> index f2ac271e80..ad409b96a1 100644
> --- a/hw/timer/allwinner-a10-pit.c
> +++ b/hw/timer/allwinner-a10-pit.c
>
Perhaps we can rename the hw/timer/allwinner-a10-pit.c to a generic name,
for example hw/timer/allwinner-pit.c ?
> @@ -54,6 +54,20 @@
> #define AW_A10_PIT(obj) \
> OBJECT_CHECK(AllwinnerTmrCtrlState, (obj), TYPE_AW_A10_PIT)
>
> +typedef struct AllwinnerTmrCtrlClass {
> + /*< private >*/
> + SysBusDeviceClass parent_class;
> + /*< public >*/
> +
> + size_t timer_count;
> + size_t region_size;
> +} AllwinnerTmrCtrlClass;
> +
> +#define AW_TIMER_CLASS(klass) \
> + OBJECT_CLASS_CHECK(AllwinnerTmrCtrlClass, (klass),
> TYPE_AW_COMMON_PIT)
> +#define AW_TIMER_GET_CLASS(obj) \
> + OBJECT_GET_CLASS(AllwinnerTmrCtrlClass, (obj), TYPE_AW_COMMON_PIT)
> +
> static void a10_pit_update_irq(AllwinnerTmrCtrlState *s)
> {
> int i;
> @@ -303,19 +317,20 @@ static void a10_pit_timer_cb(void *opaque)
> }
> }
>
> -static void a10_pit_init(Object *obj)
> +static void aw_pit_instance_init(Object *obj)
> {
> AllwinnerTmrCtrlState *s = AW_A10_PIT(obj);
> + AllwinnerTmrCtrlClass *c = AW_TIMER_GET_CLASS(s);
> SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
> uint8_t i;
>
> - s->timer_count = AW_A10_PIT_TIMER_NR;
> + s->timer_count = c->timer_count;
>
> for (i = 0; i < s->timer_count; i++) {
> sysbus_init_irq(sbd, &s->timer[i].irq);
> }
> memory_region_init_io(&s->iomem, OBJECT(s), &a10_pit_ops, s,
>
I am curious how to support the different WDOG0 registers for the Allwinner
H3 while keeping
the A10 functionality also working :-) Will you give the TYPE_AW_H3_PIT
its own MemoryRegionOps with read/write?
> - TYPE_AW_A10_PIT, 0x400);
> + TYPE_AW_A10_PIT, c->region_size);
> sysbus_init_mmio(sbd, &s->iomem);
>
> for (i = 0; i < s->timer_count; i++) {
> @@ -328,26 +343,45 @@ static void a10_pit_init(Object *obj)
> }
> }
>
> -static void a10_pit_class_init(ObjectClass *klass, void *data)
> +static void aw_timer_class_init(ObjectClass *klass, void *data)
> {
> DeviceClass *dc = DEVICE_CLASS(klass);
>
> dc->reset = a10_pit_reset;
> dc->props = a10_pit_properties;
> - dc->desc = "allwinner a10 timer";
> + dc->desc = "Allwinner Timer Controller";
> dc->vmsd = &vmstate_a10_pit;
> }
>
> +static const TypeInfo allwinner_pit_info = {
> + .name = TYPE_AW_COMMON_PIT,
> + .parent = TYPE_SYS_BUS_DEVICE,
> + .instance_init = aw_pit_instance_init,
> + .instance_size = sizeof(AllwinnerTmrCtrlState),
> + .class_init = aw_timer_class_init,
> + .class_size = sizeof(AllwinnerTmrCtrlClass),
> + .abstract = true,
> +};
> +
> +static void a10_pit_class_init(ObjectClass *klass, void *data)
> +{
> + DeviceClass *dc = DEVICE_CLASS(klass);
> + AllwinnerTmrCtrlClass *atc = AW_TIMER_CLASS(klass);
> +
> + dc->desc = "Allwinner A10 Timer Controller";
> + atc->timer_count = AW_A10_PIT_TIMER_NR;
> + atc->region_size = 0x400;
> +}
> +
> static const TypeInfo a10_pit_info = {
> .name = TYPE_AW_A10_PIT,
> - .parent = TYPE_SYS_BUS_DEVICE,
> - .instance_size = sizeof(AllwinnerTmrCtrlState),
> - .instance_init = a10_pit_init,
> + .parent = TYPE_AW_COMMON_PIT,
> .class_init = a10_pit_class_init,
> };
>
> static void a10_register_types(void)
> {
> + type_register_static(&allwinner_pit_info);
> type_register_static(&a10_pit_info);
> }
>
> --
> 2.21.0
>
>
--
Niek Linnenbank
[-- Attachment #2: Type: text/html, Size: 6596 bytes --]
next prev parent reply other threads:[~2019-12-20 21:12 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-19 18:51 [RFC PATCH 00/13] hw/timer/allwinner: Make it reusable Philippe Mathieu-Daudé
2019-12-19 18:51 ` [PATCH 01/13] hw/timer/allwinner: Use the AW_A10_PIT_TIMER_NR definition Philippe Mathieu-Daudé
2019-12-20 21:19 ` Niek Linnenbank
2019-12-19 18:51 ` [PATCH 02/13] hw/timer/allwinner: Add AW_PIT_TIMER_MAX definition Philippe Mathieu-Daudé
2019-12-20 21:27 ` Niek Linnenbank
2019-12-19 18:51 ` [PATCH 03/13] hw/timer/allwinner: Remove unused definitions Philippe Mathieu-Daudé
2019-12-20 21:36 ` Niek Linnenbank
2019-12-19 18:51 ` [PATCH 04/13] hw/timer/allwinner: Move definitions from header to source Philippe Mathieu-Daudé
2019-12-20 21:41 ` Niek Linnenbank
2019-12-19 18:51 ` [RFC PATCH 05/13] hw/timer/allwinner: Rename the ptimer field Philippe Mathieu-Daudé
2019-12-19 18:51 ` [RFC PATCH 06/13] hw/timer/allwinner: Rename 'timer_context' as 'timer' Philippe Mathieu-Daudé
2019-12-19 18:51 ` [RFC PATCH 07/13] hw/timer/allwinner: Move timer specific fields into AwA10TimerContext Philippe Mathieu-Daudé
2019-12-19 18:51 ` [RFC PATCH 08/13] hw/timer/allwinner: Add a timer_count field Philippe Mathieu-Daudé
2019-12-19 18:51 ` [RFC PATCH 09/13] hw/timer/allwinner: Rename AwA10TimerContext as AllwinnerTmrState Philippe Mathieu-Daudé
2019-12-19 18:51 ` [RFC PATCH 10/13] hw/timer/allwinner: Rename AwA10PITState as AllwinnerTmrCtrlState Philippe Mathieu-Daudé
2019-12-19 18:51 ` [RFC PATCH 11/13] hw/timer/allwinner: Introduce TYPE_AW_COMMON_PIT abstract device Philippe Mathieu-Daudé
2019-12-20 21:11 ` Niek Linnenbank [this message]
2019-12-19 18:51 ` [RFC PATCH 12/13] hw/timer/allwinner: Rename AW_A10_PIT() as AW_TIMER_CTRL() Philippe Mathieu-Daudé
2019-12-19 18:51 ` [RFC PATCH 13/13] hw/timer/allwinner: Rename functions not specific to the A10 SoC Philippe Mathieu-Daudé
2019-12-20 20:53 ` [RFC PATCH 00/13] hw/timer/allwinner: Make it reusable Niek Linnenbank
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='CAPan3WqvSFbuS8FwvVTby-gsQ1pmxJf=PUET39Ftu0oiN4GV1w@mail.gmail.com' \
--to=nieklinnenbank@gmail.com \
--cc=b.galvani@gmail.com \
--cc=f4bug@amsat.org \
--cc=peter.maydell@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).