From nobody Thu Apr 2 01:08:58 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1774983219; cv=none; d=zohomail.com; s=zohoarc; b=DdzFIOlvuDVEon4NIW/r+zYIq3NaCg4UBpN30NOBq5IcnWRT029ny+7dx3QMVtuRgCCV6HaXms/RaZzrnc2a7Z8hgiuAz5YzCJvkLL0tIXzTXf8X0Gx9gabD+JvfFYwujgpBDHOyZkdNRJY+smjdLgcBGdrVc77cuYruNoN3lOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774983219; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FFwgsyxpc+06BvRMXO3kIzR0tR3GDMyEg/itbfXsKtM=; b=N6+bNtB+kPwm9Ae1gmLX1+PSaqpslCmF9Wg0X4FvNnMRfMhEMYx40REiyH8Ze9i0STC+WBctnKV8uh3hjssOBBcJHKtvDNqs+eDEdO9OA5vUeir2jBBun12c7TJ/yt4uz/a9MJ9b4s4rhTZ0fHRlW1dzm5zlo4kTdFWhP/tC0eg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774983219322562.0123234614571; Tue, 31 Mar 2026 11:53:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w7eCW-0000Cf-Hg; Tue, 31 Mar 2026 14:52:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w7eCU-0000Bz-Hp for qemu-devel@nongnu.org; Tue, 31 Mar 2026 14:52:30 -0400 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w7eCT-0001XX-1j for qemu-devel@nongnu.org; Tue, 31 Mar 2026 14:52:30 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 61234600AD; Tue, 31 Mar 2026 18:52:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31F5CC19423; Tue, 31 Mar 2026 18:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774983148; bh=MSh2k1y7oTk1fTpRYev8xiXj57dzEDFrCo0wWi7Vuyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K8BEqOo/CAGiAWR26yId4trlB5gN2rZQ/FsxTcwAsdMTBs0U254lGowEDGxQ9IZ6l UW5w/I/q9LXQ3f0i+RfAOwXjGuVK0OYwqdu9ibfq8im8pbD52Wb8lQsK0jDN8Syx/B MevaiWjJWqZiS+dnOa1fFJs8df5eGM/S8RiNy/DZAOjvGBu6VjlrgiDgmxVBHqEddM H/eXJkAoLZHet6shGppHLrR6A8VMI8mD1k97UADr/ich2THmiQunSJ1xmmi6qpbM35 rjoRUtkoGEhaKSvT1e5bPbwLHQSTvudfxF52ZgPR3uL3+Qq+VjWFiZisyPfPnG6iGQ tGgE+GEQgjDlQ== From: Helge Deller To: qemu-devel@nongnu.org Cc: Helge Deller , Richard Henderson Subject: [PULL 4/8] hw/pci-host/astro: Fix LMMIO DIRECT mappings Date: Tue, 31 Mar 2026 20:52:15 +0200 Message-ID: <20260331185219.12187-5-deller@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260331185219.12187-1-deller@kernel.org> References: <20260331185219.12187-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=172.105.4.254; envelope-from=deller@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1774983220645158500 Content-Type: text/plain; charset="utf-8" From: Helge Deller 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 --- 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; =20 + /* each LMMIO may access from 1 MB up to 64 MB */ + const unsigned int lmmio_mask =3D ~(1 * MiB - 1); + const unsigned int lmmio_max_size =3D 64 * MiB; + /* pointer to LMMIO_DIRECT entry */ lmmio_index =3D reg_index / 3; lmmio_alias =3D &s->lmmio_direct[lmmio_index]; @@ -622,31 +626,38 @@ static void adjust_LMMIO_DIRECT_mapping(AstroState *s= , unsigned int reg_index) map_route &=3D (ELROY_NUM - 1); elroy =3D s->elroy[map_route]; =20 + /* make sure the lmmio region is initially turned off */ if (lmmio_alias->enabled) { memory_region_set_enabled(lmmio_alias, false); } =20 + /* do sanity checks and calculate mmio size */ + map_enabled =3D map_addr & 1; + map_addr &=3D lmmio_mask; + map_size &=3D lmmio_mask; + map_size =3D MIN(map_size, lmmio_max_size); map_addr =3D F_EXTEND(map_addr); - map_addr &=3D TARGET_PAGE_MASK; - map_size =3D (~map_size) + 1; - map_size &=3D TARGET_PAGE_MASK; =20 - /* 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; } =20 - 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); } =20 static MemTxResult astro_chip_read_with_attrs(void *opaque, hwaddr addr, --=20 2.53.0