From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Jiaxun Yang <jiaxun.yang@flygoat.com>, qemu-devel@nongnu.org
Cc: Huacai Chen <chenhuacai@kernel.org>
Subject: Re: [PATCH] hw/mips/loongson3_virt: Implement node counter timer
Date: Mon, 3 Jun 2024 17:32:21 +0200 [thread overview]
Message-ID: <6c1de896-c2fb-4772-b3f9-bd2b6175090e@linaro.org> (raw)
In-Reply-To: <20240512-loongson3_hpt-v1-1-5cb9cbae649b@flygoat.com>
Hi Jiaxun,
On 12/5/24 14:20, Jiaxun Yang wrote:
> Node counter is a timer presents on Loongson-3 chips, which runs
> as fast as CPU clock. It's being mapped into a MMIO location.
>
> Emulate this for loongson3_virt machine, in hope that kernel can
> use it as a better clock source.
>
> Hardware's behavior on 32-bit read/write is also emulated in case
> legacy kernel is trying to use it with hi/lo splitted read.
>
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
> hw/mips/loongson3_bootp.h | 1 +
> hw/mips/loongson3_virt.c | 38 ++++++++++++++++++++++++++++++++++----
> 2 files changed, 35 insertions(+), 4 deletions(-)
> +static uint64_t loongson3_nodecnt_read(void *opaque,
> + hwaddr addr, unsigned size)
> +{
> + LoongsonMachineState *s = opaque;
> + int64_t now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
> + uint64_t ticks = clock_ns_to_ticks(s->cpuclk, now_ns);
> +
> + if (addr == 0x4) {
> + return ticks >> 32;
Does that imply .endianness = DEVICE_BIG_ENDIAN?
It could be simpler to let the core MMIO code do the hi/lo
bits management using ".impl.min_access_size = 8".
> + }
> +
> + return ticks;
> +}
> +
> +static const MemoryRegionOps loongson3_nodecnt_ops = {
> + .read = loongson3_nodecnt_read,
> + .endianness = DEVICE_NATIVE_ENDIAN,
> + .valid.min_access_size = 4,
> + .valid.max_access_size = 8,
> + .impl.min_access_size = 4,
> + .impl.max_access_size = 8,
> +};
prev parent reply other threads:[~2024-06-03 15:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-12 12:20 [PATCH] hw/mips/loongson3_virt: Implement node counter timer Jiaxun Yang
2024-06-03 15:32 ` Philippe Mathieu-Daudé [this message]
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=6c1de896-c2fb-4772-b3f9-bd2b6175090e@linaro.org \
--to=philmd@linaro.org \
--cc=chenhuacai@kernel.org \
--cc=jiaxun.yang@flygoat.com \
--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).