From nobody Sat Nov 8 10:40:44 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550149886163289.74923997973815; Thu, 14 Feb 2019 05:11:26 -0800 (PST) Received: from localhost ([127.0.0.1]:48390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guGnT-0001y5-1x for importer@patchew.org; Thu, 14 Feb 2019 08:11:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guGeU-00034b-Gp for qemu-devel@nongnu.org; Thu, 14 Feb 2019 08:02:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guGTx-0006RI-5N for qemu-devel@nongnu.org; Thu, 14 Feb 2019 07:51:14 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:53578) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1guGTw-0006QP-VO for qemu-devel@nongnu.org; Thu, 14 Feb 2019 07:51:13 -0500 Received: by mail-wm1-x343.google.com with SMTP id d15so6168294wmb.3 for ; Thu, 14 Feb 2019 04:51:12 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id j3sm1488073wmb.39.2019.02.14.04.51.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 04:51:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vaS39ErdvakXDhjr2AJlzEtf1NZBf73g6lMHeNCY3fs=; b=OlJCJtVB2LvWDyzuPYVS8RradArrRRjjE6HjgcFad8rjTF4UWhmyhuWB4cEW3ZrMHf nY6WCwuH2wpwu2cDv4vU46aBQxcRWKL0w9D5HH4/BKcfeL8WuCF2pUFJu9FsqpEghNgt TVPZVl2hEJrkeabRX64496eRmt3fPNDw/zrIg1x+pAPPVel5jDaz+AZKWoooxWBq+uc1 dl35LdhhAt//9+vR1Ep3O6bdSwQYnWUnEyRe+GzOD20uL7mmG+ZLaIKmvKCPh/CdzPEr 1WfFEsJ4Eh2JkfpqBKbGJDnh0X5Q9jYfEHQ7ixX/XKcC8dinpqI2l85Knd5B6rCha7up B8CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vaS39ErdvakXDhjr2AJlzEtf1NZBf73g6lMHeNCY3fs=; b=HPTMeR3v4CSWMpO5PO2FddmJDjaiEFHuF8i5g99V+5SWBNvTLD9WSUiqvtYMh7U/kp 6aGkOX7O4wLFEVupliyd5WQoBrq6JZNta6Ri20+Ywcz5sy2JeKfl4wIslSwjOOLIANcJ 18XzEll2vcnpfwbReHCx+K0bO1qRJRyfG2Fl09cDo3Vduvm/IJUArwOHblcM+95tk2da t6KXTmKDeLaAXZtfQorNFUYyw9lsMk/Y6G0w/WbPLKtKWeRzq2crbThlFRfsKpmdcHDV yjIEtoonUKKspSrWydwB69x3Eaif3qJQ8rw5QW9Ox9wnOprSfo1J32WzatK2EqbikxMq gekg== X-Gm-Message-State: AHQUAuZFE1DOd7Pbuk9Msx1FCjBSH4b0IuHPzy2syV06RKHyxP1uOLVk TBfYuQu0rjYiajl4lgTnc+mKbriNQ+Z74w== X-Google-Smtp-Source: AHgI3IZDB8EuCAWDOyL4YwwHVwqYG7PoDo/ZooCurJw8ESV2N3HAmVb6qnb3ddGWgRUxsUHJQDSrLg== X-Received: by 2002:a1c:f901:: with SMTP id x1mr2667013wmh.84.1550148671731; Thu, 14 Feb 2019 04:51:11 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Thu, 14 Feb 2019 12:50:55 +0000 Message-Id: <20190214125107.22178-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214125107.22178-1-peter.maydell@linaro.org> References: <20190214125107.22178-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PATCH 02/14] hw/misc/tz-ppc: Support having unused ports in the middle of the range X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The Peripheral Protection Controller's handling of unused ports is that if there is nothing connected to the port's downstream then it does not create the sysbus MMIO region for the upstream end of the port. This results in odd behaviour when there is an unused port in the middle of the range: since sysbus MMIO regions are implicitly consecutively allocated, any used ports above the unused ones end up with sysbus MMIO region numbers that don't match the port number. Avoid this numbering mismatch by creating dummy MMIO regions for the unused ports. This doesn't change anything for our existing boards, which don't have any gaps in the middle of the port ranges they use; but it will be needed for the Musca board. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- include/hw/misc/tz-ppc.h | 8 +++++++- hw/misc/tz-ppc.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/hw/misc/tz-ppc.h b/include/hw/misc/tz-ppc.h index fc8b806e4df..080d6e2ec17 100644 --- a/include/hw/misc/tz-ppc.h +++ b/include/hw/misc/tz-ppc.h @@ -38,7 +38,13 @@ * * QEMU interface: * + sysbus MMIO regions 0..15: MemoryRegions defining the upstream end - * of each of the 16 ports of the PPC + * of each of the 16 ports of the PPC. When a port is unused (i.e. no + * downstream MemoryRegion is connected to it) at the end of the 0..15 + * range then no sysbus MMIO region is created for its upstream. When an + * unused port lies in the middle of the range with other used ports at + * higher port numbers, a dummy MMIO region is created to ensure that + * port N's upstream is always sysbus MMIO region N. Dummy regions should + * not be mapped, and will assert if any access is made to them. * + Property "port[0..15]": MemoryRegion defining the downstream device(s) * for each of the 16 ports of the PPC * + Named GPIO inputs "cfg_nonsec[0..15]": set to 1 if the port should be diff --git a/hw/misc/tz-ppc.c b/hw/misc/tz-ppc.c index 3dd045c15f5..2e04837bea9 100644 --- a/hw/misc/tz-ppc.c +++ b/hw/misc/tz-ppc.c @@ -181,6 +181,21 @@ static const MemoryRegionOps tz_ppc_ops =3D { .endianness =3D DEVICE_LITTLE_ENDIAN, }; =20 +static bool tz_ppc_dummy_accepts(void *opaque, hwaddr addr, + unsigned size, bool is_write, + MemTxAttrs attrs) +{ + /* + * Board code should never map the upstream end of an unused port, + * so we should never try to make a memory access to it. + */ + g_assert_not_reached(); +} + +static const MemoryRegionOps tz_ppc_dummy_ops =3D { + .valid.accepts =3D tz_ppc_dummy_accepts, +}; + static void tz_ppc_reset(DeviceState *dev) { TZPPC *s =3D TZ_PPC(dev); @@ -210,16 +225,33 @@ static void tz_ppc_realize(DeviceState *dev, Error **= errp) SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); TZPPC *s =3D TZ_PPC(dev); int i; + int max_port =3D 0; =20 /* We can't create the upstream end of the port until realize, * as we don't know the size of the MR used as the downstream until th= en. */ for (i =3D 0; i < TZ_NUM_PORTS; i++) { + if (s->port[i].downstream) { + max_port =3D i; + } + } + + for (i =3D 0; i <=3D max_port; i++) { TZPPCPort *port =3D &s->port[i]; char *name; uint64_t size; =20 if (!port->downstream) { + /* + * Create dummy sysbus MMIO region so the sysbus region + * numbering doesn't get out of sync with the port numbers. + * The size is entirely arbitrary. + */ + name =3D g_strdup_printf("tz-ppc-dummy-port[%d]", i); + memory_region_init_io(&port->upstream, obj, &tz_ppc_dummy_ops, + port, name, 0x10000); + sysbus_init_mmio(sbd, &port->upstream); + g_free(name); continue; } =20 --=20 2.20.1