From patchwork Thu Feb 21 18:57:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 158937 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp841076jaa; Thu, 21 Feb 2019 11:06:41 -0800 (PST) X-Google-Smtp-Source: AHgI3IYqN6cIEsK/hCNWCdUkSTDQtSA6REdGt0iAcnYy0+HkpBqGy+X17NfBN3/fQ/+PJLf3ODvj X-Received: by 2002:a25:8882:: with SMTP id d2mr19741ybl.381.1550776001867; Thu, 21 Feb 2019 11:06:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550776001; cv=none; d=google.com; s=arc-20160816; b=L4VIopnEOMs0XRoZQ8kSno7/29QwHDhit1s1WY9sH9rxqv80pHNWHrLsOTNLf5X2VP Q4lEY6V7Lr1uK5QEAShxrlSIAvZhbW8oAmjv7FwxkBVFrLAwXF3R+JOctKcagpwRoLGq zE0EqWxgiT38UK5IFAaSEpne/4CG5tRVxR+nym4/Bb1MMNK09LaUGCLOosUPG06Hjdf3 Et7b3Viyna+WDMVWh+XoSoUhtNn9yc/BtfFrpaNBzLGerk4FQB4sanZEMPHI237+SLzA 8MvOg2XMA2p2vRRmi5r+8jGVd763i2mXWbyDNg+dHXC0pAvEgssYVziDdAUOa4OGPLpF FGCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=tZqUEGNvILINRMPY/6sZaASJERHi2DEhIKWOky+926w=; b=hEhm1s1WuKafaxLFRwHJ1hodmmXvI3MLDp4C+GWCadEeQVGiIsGDR9YR94P63X4OTT xL/2N3hHckhohl2UjDCmziXmUE/ICkG2bM3Xm2fJsdqj+z2R77wjgQCqQS89k11YRjZc LCtHNWX/E8c9icoeCav0qe320TsjZH6pyVtFb6yqukB+IPKY0L7KX+fGS4v+pZiUAFRr EaXMFQsPq72Ip9ne93C18yn1XH/VC4nHLMPa+mYp8aGbTzdyslANn23IAQXoP5e7P0wz rYgnJxTLP6W6FXshVteTwZaAzJOAdeUeAyZSkC1a5buE/t/8I04bD1/3vxOK5wp3XJMu uWqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="e7I/vAsJ"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h18si13931346ybk.216.2019.02.21.11.06.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 21 Feb 2019 11:06:41 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="e7I/vAsJ"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:36958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwtg9-0007PZ-9z for patch@linaro.org; Thu, 21 Feb 2019 14:06:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwtXq-0008TS-8O for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:58:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwtXo-0007Ru-R6 for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:58:06 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:41445) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwtXn-0007Li-1F for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:58:03 -0500 Received: by mail-wr1-x42f.google.com with SMTP id n2so19643897wrw.8 for ; Thu, 21 Feb 2019 10:57:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=tZqUEGNvILINRMPY/6sZaASJERHi2DEhIKWOky+926w=; b=e7I/vAsJe43Enl7TWch3Mr0dM79gwD7ZZl8y/kk73xQ4WKGmBhbStFnWB/EvYq0Ozo P7AbF6UpFALEzysd5xCzLnyU4SiT2uvaTCX/JzLqRJzwbUsQe2MSWy4lAXpHQyKmtwpd ckBcIzeVnxmJzB1H6auNW61PvCmo2N/OrR4xVJOc0x5dI5On1ZSrTnH8ug4N4g3Xtfps x75o2pdoDnCHdOp8cPyKDpDys4tgA53mfi/lXrBJy4OUb1/ucgba/krCrUaxsKIMnaTK WGI8OYyws1IM1BlI1Gm0n46ksjGpjLUcVp2wfGwvrIoL4Q2WpZfLacia6Vwy5b+RrI9w wvbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tZqUEGNvILINRMPY/6sZaASJERHi2DEhIKWOky+926w=; b=IJJsrwJXM01yRKDnXoPuTT6tQxTKV/DmftIEFN0N915rqmudaB5mBRrWrzn1sZ0zga IueSWUYRp7n1Bqg/hRpZ5+z/h/yrSWYTZoDRcwtV0JVwOY3e7fYgxSdbhJYV6CCK844z BR687WnHL4cC9Ps8+YCeqjl0bp5FHcPfY1Wf4wGtHco9stEJn8D0zVSLgLCi4XTNzfVe KiFr0tJlj0r247Nxk2ag8J0/dI+Fig5gGo/5iCgTF0+cWDKTEJNHwnWuZyV1338DLrm1 d6aYMnYI5INruxQNnVtozg/Mzb9QxqoJd71CUYVRCMQH9Ws3EktiYcMUMLw8goQKguU4 FFTw== X-Gm-Message-State: AHQUAuaV/5/C4twVNhDtACzXYjq4JRu0mlcvQ6uIX9oHzhs8L/HZhKhe nhBcbB5sbUFfazp8W7qF9Y+E5o1tTOg= X-Received: by 2002:adf:e706:: with SMTP id c6mr6606wrm.278.1550775473239; Thu, 21 Feb 2019 10:57:53 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id c18sm29065085wre.32.2019.02.21.10.57.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 10:57:52 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 21 Feb 2019 18:57:26 +0000 Message-Id: <20190221185739.25362-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221185739.25362-1-peter.maydell@linaro.org> References: <20190221185739.25362-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42f Subject: [Qemu-devel] [PULL 08/21] 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.20.1 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 = { .endianness = DEVICE_LITTLE_ENDIAN, }; +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 = { + .valid.accepts = tz_ppc_dummy_accepts, +}; + static void tz_ppc_reset(DeviceState *dev) { TZPPC *s = TZ_PPC(dev); @@ -210,16 +225,33 @@ static void tz_ppc_realize(DeviceState *dev, Error **errp) SysBusDevice *sbd = SYS_BUS_DEVICE(dev); TZPPC *s = TZ_PPC(dev); int i; + int max_port = 0; /* 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 then. */ for (i = 0; i < TZ_NUM_PORTS; i++) { + if (s->port[i].downstream) { + max_port = i; + } + } + + for (i = 0; i <= max_port; i++) { TZPPCPort *port = &s->port[i]; char *name; uint64_t size; 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 = 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; }