From: Helge Deller <deller@kernel.org>
To: qemu-devel@nongnu.org
Cc: Helge Deller <deller@gmx.de>,
Richard Henderson <richard.henderson@linaro.org>
Subject: [PULL 4/8] hw/pci-host/astro: Fix LMMIO DIRECT mappings
Date: Tue, 31 Mar 2026 20:52:15 +0200 [thread overview]
Message-ID: <20260331185219.12187-5-deller@kernel.org> (raw)
In-Reply-To: <20260331185219.12187-1-deller@kernel.org>
From: Helge Deller <deller@gmx.de>
Fix the existing code which has the mask wrong.
Implement the direct mapping via overlapping subregion with priority 3
to make sure the direct mapping gets precedence over the LMMIO region.
Signed-off-by: Helge Deller <deller@gmx.de>
---
hw/pci-host/astro.c | 39 +++++++++++++++++++++++++--------------
1 file changed, 25 insertions(+), 14 deletions(-)
diff --git a/hw/pci-host/astro.c b/hw/pci-host/astro.c
index a0afa09198..b7760c4b32 100644
--- a/hw/pci-host/astro.c
+++ b/hw/pci-host/astro.c
@@ -607,9 +607,13 @@ static void adjust_LMMIO_DIRECT_mapping(AstroState *s, unsigned int reg_index)
MemoryRegion *lmmio_alias;
unsigned int lmmio_index, map_route;
hwaddr map_addr;
- uint32_t map_size;
+ uint32_t map_size, map_enabled;
struct ElroyState *elroy;
+ /* each LMMIO may access from 1 MB up to 64 MB */
+ const unsigned int lmmio_mask = ~(1 * MiB - 1);
+ const unsigned int lmmio_max_size = 64 * MiB;
+
/* pointer to LMMIO_DIRECT entry */
lmmio_index = reg_index / 3;
lmmio_alias = &s->lmmio_direct[lmmio_index];
@@ -622,31 +626,38 @@ static void adjust_LMMIO_DIRECT_mapping(AstroState *s, unsigned int reg_index)
map_route &= (ELROY_NUM - 1);
elroy = s->elroy[map_route];
+ /* make sure the lmmio region is initially turned off */
if (lmmio_alias->enabled) {
memory_region_set_enabled(lmmio_alias, false);
}
+ /* do sanity checks and calculate mmio size */
+ map_enabled = map_addr & 1;
+ map_addr &= lmmio_mask;
+ map_size &= lmmio_mask;
+ map_size = MIN(map_size, lmmio_max_size);
map_addr = F_EXTEND(map_addr);
- map_addr &= TARGET_PAGE_MASK;
- map_size = (~map_size) + 1;
- map_size &= TARGET_PAGE_MASK;
- /* exit if disabled or zero map size */
- if (!(map_addr & 1) || !map_size) {
+ /* exit if disabled or has zero size. */
+ if (!map_enabled || !map_size) {
return;
}
- if (!memory_region_size(lmmio_alias)) {
+ if (!lmmio_alias->name) {
+ char lmmio_name[32];
+ snprintf(lmmio_name, sizeof(lmmio_name),
+ "LMMIO-DIRECT-%u", lmmio_index);
memory_region_init_alias(lmmio_alias, OBJECT(elroy),
- "pci-lmmmio-alias", &elroy->pci_mmio,
+ lmmio_name, &elroy->pci_mmio,
(uint32_t) map_addr, map_size);
- memory_region_add_subregion(get_system_memory(), map_addr,
- lmmio_alias);
- } else {
- memory_region_set_alias_offset(lmmio_alias, map_addr);
- memory_region_set_size(lmmio_alias, map_size);
- memory_region_set_enabled(lmmio_alias, true);
+ memory_region_add_subregion_overlap(get_system_memory(),
+ map_addr, lmmio_alias, 3);
}
+
+ memory_region_set_address(lmmio_alias, map_addr);
+ memory_region_set_alias_offset(lmmio_alias, (uint32_t) map_addr);
+ memory_region_set_size(lmmio_alias, map_size);
+ memory_region_set_enabled(lmmio_alias, true);
}
static MemTxResult astro_chip_read_with_attrs(void *opaque, hwaddr addr,
--
2.53.0
next prev parent reply other threads:[~2026-03-31 18:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 18:52 [PULL 0/8] Hppa more v11 fixes patches Helge Deller
2026-03-31 18:52 ` [PULL 1/8] hw/pci-host/astro: Make astro address arrays accessible for other users Helge Deller
2026-03-31 18:52 ` [PULL 2/8] hw/pci-host/astro: Fix initial addresses in IOC Helge Deller
2026-03-31 18:52 ` [PULL 3/8] hw/pci-host/astro: Implement LMMIO registers Helge Deller
2026-03-31 18:52 ` Helge Deller [this message]
2026-03-31 18:52 ` [PULL 5/8] hw/pci-host/astro: Add GMMIO mapping Helge Deller
2026-03-31 18:52 ` [PULL 6/8] target/hppa: Fix TOC handler for 64-bit CPUs Helge Deller
2026-03-31 18:52 ` [PULL 7/8] hw/hppa: Implement memory ranges Helge Deller
2026-03-31 18:52 ` [PULL 8/8] target/hppa: Update SeaBIOS-hppa to version 24 Helge Deller
2026-03-31 21:23 ` [PULL 0/8] Hppa more v11 fixes patches Peter Maydell
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=20260331185219.12187-5-deller@kernel.org \
--to=deller@kernel.org \
--cc=deller@gmx.de \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.