From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Hao Wu <wuhaotsh@google.com>, peter.maydell@linaro.org
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, venture@google.com,
Avi.Fishman@nuvoton.com, kfting@nuvoton.com,
hskinnemoen@google.com, titusr@google.com,
chli30@nuvoton.corp-partner.google.com
Subject: Re: [PATCH v3 09/17] hw/misc: Support 8-bytes memop in NPCM GCR module
Date: Thu, 6 Feb 2025 10:19:40 +0100 [thread overview]
Message-ID: <7d50d81c-982f-45f0-81eb-1c842b3c55cc@linaro.org> (raw)
In-Reply-To: <20250206013105.3228344-10-wuhaotsh@google.com>
On 6/2/25 02:30, Hao Wu wrote:
> The NPCM8xx GCR device can be accessed with 64-bit memory operations.
> This patch supports that.
>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Hao Wu <wuhaotsh@google.com>
> ---
> hw/misc/npcm_gcr.c | 94 +++++++++++++++++++++++++++++++++-----------
> hw/misc/trace-events | 4 +-
> 2 files changed, 74 insertions(+), 24 deletions(-)
>
> diff --git a/hw/misc/npcm_gcr.c b/hw/misc/npcm_gcr.c
> index 820b730606..654e048048 100644
> --- a/hw/misc/npcm_gcr.c
> +++ b/hw/misc/npcm_gcr.c
> @@ -201,6 +201,7 @@ static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size)
> uint32_t reg = offset / sizeof(uint32_t);
> NPCMGCRState *s = opaque;
> NPCMGCRClass *c = NPCM_GCR_GET_CLASS(s);
> + uint64_t value;
>
> if (reg >= c->nr_regs) {
> qemu_log_mask(LOG_GUEST_ERROR,
> @@ -209,9 +210,21 @@ static uint64_t npcm_gcr_read(void *opaque, hwaddr offset, unsigned size)
> return 0;
> }
>
> - trace_npcm_gcr_read(offset, s->regs[reg]);
> + switch (size) {
> + case 4:
> + value = s->regs[reg];
> + break;
> +
> + case 8:
Should we assert(!(reg & 1)) in case someone want to enable unaligned
accesses?
> + value = deposit64(s->regs[reg], 32, 32, s->regs[reg + 1]);
> + break;
> +
> + default:
> + g_assert_not_reached();
> + }
>
> - return s->regs[reg];
> + trace_npcm_gcr_read(offset, value);
> + return value;
> }
>
> static void npcm_gcr_write(void *opaque, hwaddr offset,
> @@ -231,29 +244,65 @@ static void npcm_gcr_write(void *opaque, hwaddr offset,
> return;
> }
>
> - switch (reg) {
> - case NPCM7XX_GCR_PDID:
> - case NPCM7XX_GCR_PWRON:
> - case NPCM7XX_GCR_INTSR:
> - qemu_log_mask(LOG_GUEST_ERROR,
> - "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
> - __func__, offset);
> - return;
> -
> - case NPCM7XX_GCR_RESSR:
> - case NPCM7XX_GCR_CP2BST:
> - /* Write 1 to clear */
> - value = s->regs[reg] & ~value;
> + switch (size) {
> + case 4:
> + switch (reg) {
> + case NPCM7XX_GCR_PDID:
> + case NPCM7XX_GCR_PWRON:
> + case NPCM7XX_GCR_INTSR:
> + qemu_log_mask(LOG_GUEST_ERROR,
> + "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
> + __func__, offset);
> + return;
> +
> + case NPCM7XX_GCR_RESSR:
> + case NPCM7XX_GCR_CP2BST:
> + /* Write 1 to clear */
> + value = s->regs[reg] & ~value;
> + break;
> +
> + case NPCM7XX_GCR_RLOCKR1:
> + case NPCM7XX_GCR_MDLR:
> + /* Write 1 to set */
> + value |= s->regs[reg];
> + break;
> + };
> + s->regs[reg] = value;
> break;
>
> - case NPCM7XX_GCR_RLOCKR1:
> - case NPCM7XX_GCR_MDLR:
> - /* Write 1 to set */
> - value |= s->regs[reg];
> + case 8:
Ditto.
> + s->regs[reg] = value;
> + s->regs[reg + 1] = extract64(v, 32, 32);
> break;
> - };
>
> - s->regs[reg] = value;
> + default:
> + g_assert_not_reached();
> + }
> +}
> +
> +static bool npcm_gcr_check_mem_op(void *opaque, hwaddr offset,
> + unsigned size, bool is_write,
> + MemTxAttrs attrs)
> +{
> + NPCMGCRClass *c = NPCM_GCR_GET_CLASS(opaque);
> +
> + if (offset >= c->nr_regs * sizeof(uint32_t)) {
> + return false;
> + }
> +
> + switch (size) {
> + case 4:
> + return true;
> + case 8:
> + if (offset >= NPCM8XX_GCR_SCRPAD_00 * sizeof(uint32_t) &&
> + offset < (NPCM8XX_GCR_NR_REGS - 1) * sizeof(uint32_t)) {
> + return true;
> + } else {
> + return false;
> + }
> + default:
> + return false;
> + }
> }
>
> static const struct MemoryRegionOps npcm_gcr_ops = {
> @@ -262,7 +311,8 @@ static const struct MemoryRegionOps npcm_gcr_ops = {
> .endianness = DEVICE_LITTLE_ENDIAN,
> .valid = {
> .min_access_size = 4,
> - .max_access_size = 4,
> + .max_access_size = 8,
> + .accepts = npcm_gcr_check_mem_op,
> .unaligned = false,
> },
> };
> diff --git a/hw/misc/trace-events b/hw/misc/trace-events
> index 0f7204a237..f25dbd6030 100644
> --- a/hw/misc/trace-events
> +++ b/hw/misc/trace-events
> @@ -135,8 +135,8 @@ npcm7xx_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " valu
> npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
>
> # npcm_gcr.c
> -npcm_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
> -npcm_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
> +npcm_gcr_read(uint64_t offset, uint64_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx64
> +npcm_gcr_write(uint64_t offset, uint64_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx64
>
> # npcm7xx_mft.c
> npcm7xx_mft_read(const char *name, uint64_t offset, uint16_t value) "%s: offset: 0x%04" PRIx64 " value: 0x%04" PRIx16
next prev parent reply other threads:[~2025-02-06 9:20 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 1:30 [PATCH v3 00/17] hw/arm: Add NPCM8XX Support Hao Wu
2025-02-06 1:30 ` [PATCH v3 01/17] roms: Update vbootrom to 1287b6e Hao Wu
2025-02-06 1:30 ` [PATCH v3 02/17] pc-bios: Add NPCM8XX vBootrom Hao Wu
2025-02-06 1:30 ` [PATCH v3 03/17] hw/ssi: Make flash size a property in NPCM7XX FIU Hao Wu
2025-02-06 9:06 ` Philippe Mathieu-Daudé
2025-02-06 1:30 ` [PATCH v3 04/17] hw/misc: Rename npcm7xx_gcr to npcm_gcr Hao Wu
2025-02-06 1:30 ` [PATCH v3 05/17] hw/misc: Move NPCM7XX GCR to NPCM GCR Hao Wu
2025-02-06 1:30 ` [PATCH v3 06/17] hw/misc: Add nr_regs and cold_reset_values " Hao Wu
2025-02-06 1:30 ` [PATCH v3 07/17] hw/misc: Add support for NPCM8XX GCR Hao Wu
2025-02-06 9:13 ` Philippe Mathieu-Daudé
2025-02-06 1:30 ` [PATCH v3 08/17] hw/misc: Store DRAM size in NPCM8XX GCR Module Hao Wu
2025-02-06 1:30 ` [PATCH v3 09/17] hw/misc: Support 8-bytes memop in NPCM GCR module Hao Wu
2025-02-06 9:19 ` Philippe Mathieu-Daudé [this message]
2025-02-06 1:30 ` [PATCH v3 10/17] hw/misc: Rename npcm7xx_clk to npcm_clk Hao Wu
2025-02-06 1:30 ` [PATCH v3 11/17] hw/misc: Move NPCM7XX CLK to NPCM CLK Hao Wu
2025-02-06 1:31 ` [PATCH v3 12/17] hw/misc: Add nr_regs and cold_reset_values " Hao Wu
2025-02-06 9:22 ` Philippe Mathieu-Daudé
2025-02-06 1:31 ` [PATCH v3 13/17] hw/misc: Support NPCM8XX CLK Module Registers Hao Wu
2025-02-06 9:24 ` Philippe Mathieu-Daudé
2025-02-06 1:31 ` [PATCH v3 14/17] hw/net: Add NPCM8XX PCS Module Hao Wu
2025-02-06 1:31 ` [PATCH v3 15/17] hw/arm: Add NPCM8XX SoC Hao Wu
2025-02-06 1:31 ` [PATCH v3 16/17] hw/arm: Add NPCM845 Evaluation board Hao Wu
2025-02-06 9:27 ` Philippe Mathieu-Daudé
2025-02-06 1:31 ` [PATCH v3 17/17] docs/system/arm: Add Description for NPCM8XX SoC Hao Wu
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=7d50d81c-982f-45f0-81eb-1c842b3c55cc@linaro.org \
--to=philmd@linaro.org \
--cc=Avi.Fishman@nuvoton.com \
--cc=chli30@nuvoton.corp-partner.google.com \
--cc=hskinnemoen@google.com \
--cc=kfting@nuvoton.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=titusr@google.com \
--cc=venture@google.com \
--cc=wuhaotsh@google.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).