From: Laurent Vivier <laurent@vivier.eu>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>,
Alessandro Zummo <a.zummo@towertech.it>,
linux-rtc@vger.kernel.org, Stephen Boyd <sboyd@kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
linux-m68k@lists.linux-m68k.org,
Geert Uytterhoeven <geert@linux-m68k.org>,
Thomas Gleixner <tglx@linutronix.de>,
John Stultz <john.stultz@linaro.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v15 4/5] clocksource/drivers: Add a goldfish-timer clocksource
Date: Wed, 6 Apr 2022 13:26:33 +0200 [thread overview]
Message-ID: <465da893-4e7b-33e4-2859-032724bae42f@vivier.eu> (raw)
In-Reply-To: <768c4fe5-fd36-8e4a-a9c2-1c799af3ed44@linaro.org>
Le 06/04/2022 à 12:27, Daniel Lezcano a écrit :
>
> Hi Laurent,
>
>
> On 01/04/2022 12:20, Laurent Vivier wrote:
>>
>> Daniel ?
>>
>> Thanks,
>> Laurent
>>
>> Le 10/03/2022 à 10:00, Laurent Vivier a écrit :
>>> Add a clocksource based on the goldfish-rtc device.
>>>
>>> Move the timer register definition to <clocksource/timer-goldfish.h>
>>>
>>> This kernel implementation is based on the QEMU upstream implementation:
>>>
>>> https://git.qemu.org/?p=qemu.git;a=blob_plain;f=hw/rtc/goldfish_rtc.c
>>>
>>> goldfish-timer is a high-precision signed 64-bit nanosecond timer.
>>> It is part of the 'goldfish' virtual hardware platform used to run
>>> some emulated Android systems under QEMU.
>>> This timer only supports oneshot event.
>>>
>>> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
>>> ---
>>> drivers/clocksource/Kconfig | 7 ++
>>> drivers/clocksource/Makefile | 1 +
>>> drivers/clocksource/timer-goldfish.c | 153 +++++++++++++++++++++++++++
>>> drivers/rtc/rtc-goldfish.c | 13 +--
>>> include/clocksource/timer-goldfish.h | 31 ++++++
>>> 5 files changed, 193 insertions(+), 12 deletions(-)
>>> create mode 100644 drivers/clocksource/timer-goldfish.c
>>> create mode 100644 include/clocksource/timer-goldfish.h
>>>
>>> diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
>>> index cfb8ea0df3b1..94f00374cebb 100644
>>> --- a/drivers/clocksource/Kconfig
>>> +++ b/drivers/clocksource/Kconfig
>>> @@ -721,4 +721,11 @@ config MICROCHIP_PIT64B
>>> modes and high resolution. It is used as a clocksource
>>> and a clockevent.
>>> +config GOLDFISH_TIMER
>>> + bool "Clocksource using goldfish-rtc"
>>> + depends on M68K || COMPILE_TEST
>>> + depends on RTC_DRV_GOLDFISH
>>> + help
>>> + Support for the timer/counter of goldfish-rtc
>>> +
>>> endmenu
>>> diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
>>> index fa5f624eadb6..12f5d7e8cc2d 100644
>>> --- a/drivers/clocksource/Makefile
>>> +++ b/drivers/clocksource/Makefile
>>> @@ -89,3 +89,4 @@ obj-$(CONFIG_GX6605S_TIMER) += timer-gx6605s.o
>>> obj-$(CONFIG_HYPERV_TIMER) += hyperv_timer.o
>>> obj-$(CONFIG_MICROCHIP_PIT64B) += timer-microchip-pit64b.o
>>> obj-$(CONFIG_MSC313E_TIMER) += timer-msc313e.o
>>> +obj-$(CONFIG_GOLDFISH_TIMER) += timer-goldfish.o
>>> diff --git a/drivers/clocksource/timer-goldfish.c b/drivers/clocksource/timer-goldfish.c
>>> new file mode 100644
>>> index 000000000000..0512d5eabc82
>>> --- /dev/null
>>> +++ b/drivers/clocksource/timer-goldfish.c
>>> @@ -0,0 +1,153 @@
>>> +// SPDX-License-Identifier: GPL-2.0
>>> +
>>> +#include <linux/interrupt.h>
>>> +#include <linux/ioport.h>
>>> +#include <linux/clocksource.h>
>>> +#include <linux/clockchips.h>
>>> +#include <linux/module.h>
>>> +#include <linux/slab.h>
>>> +#include <linux/goldfish.h>
>
> Not related to this patch: would it make sense to move it to linux/soc/... ?
I don't know. goldfish is not really a soc. I didn't really find a good place where it should be.
>
>
>>> +#include <clocksource/timer-goldfish.h>
>>> +
>>> +struct goldfish_timer {
>>> + struct clocksource cs;
>>> + struct clock_event_device ced;
>>> + struct resource res;
>>> + void __iomem *base;
>>> +};
>>> +
>>> +static struct goldfish_timer *ced_to_gf(struct clock_event_device *ced)
>>> +{
>>> + return container_of(ced, struct goldfish_timer, ced);
>>> +}
>>> +
>>> +static struct goldfish_timer *cs_to_gf(struct clocksource *cs)
>>> +{
>>> + return container_of(cs, struct goldfish_timer, cs);
>>> +}
>>> +
>>> +static u64 goldfish_timer_read(struct clocksource *cs)
>>> +{
>>> + struct goldfish_timer *timerdrv = cs_to_gf(cs);
>>> + void __iomem *base = timerdrv->base;
>>> + u32 time_low, time_high;
>>> + u64 ticks;
>>> +
>>> + /*
>>> + * time_low: get low bits of current time and update time_high
>>> + * time_high: get high bits of time at last time_low read
>>> + */
>>> + time_low = gf_ioread32(base + TIMER_TIME_LOW);
>>> + time_high = gf_ioread32(base + TIMER_TIME_HIGH);
>
> There is a risk here to have the counter rolling over between low and high reading, no ?
No, because value of high is frozen when we read low, so the 64bit value doesn't move between the
two ioread32().
Thanks,
Laurent
next prev parent reply other threads:[~2022-04-06 14:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-10 9:00 [PATCH v15 0/5] m68k: Add Virtual M68k Machine Laurent Vivier
2022-03-10 9:00 ` [PATCH v15 1/5] m68k: add asm/config.h Laurent Vivier
2022-03-10 12:14 ` Geert Uytterhoeven
2022-03-10 9:00 ` [PATCH v15 2/5] tty: goldfish: introduce gf_ioread32()/gf_iowrite32() Laurent Vivier
2022-03-10 12:16 ` Geert Uytterhoeven
2022-03-10 12:21 ` Geert Uytterhoeven
2022-03-10 9:00 ` [PATCH v15 3/5] rtc: goldfish: use gf_ioread32()/gf_iowrite32() Laurent Vivier
2022-03-10 12:16 ` Geert Uytterhoeven
2022-03-10 9:00 ` [PATCH v15 4/5] clocksource/drivers: Add a goldfish-timer clocksource Laurent Vivier
2022-04-01 10:20 ` Laurent Vivier
2022-04-06 10:27 ` Daniel Lezcano
2022-04-06 11:26 ` Laurent Vivier [this message]
2022-04-06 11:32 ` Daniel Lezcano
2022-04-06 15:07 ` John Paul Adrian Glaubitz
2022-03-10 9:00 ` [PATCH v15 5/5] m68k: introduce a virtual m68k machine Laurent Vivier
2022-03-10 12:18 ` Geert Uytterhoeven
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=465da893-4e7b-33e4-2859-032724bae42f@vivier.eu \
--to=laurent@vivier.eu \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@bootlin.com \
--cc=arnd@arndb.de \
--cc=daniel.lezcano@linaro.org \
--cc=geert@linux-m68k.org \
--cc=jiaxun.yang@flygoat.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-rtc@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®