From patchwork Thu Feb 14 12:50:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 158367 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1325745jaa; Thu, 14 Feb 2019 04:51:12 -0800 (PST) X-Received: by 2002:adf:d4cd:: with SMTP id w13mr2735346wrk.35.1550148672405; Thu, 14 Feb 2019 04:51:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550148672; cv=none; d=google.com; s=arc-20160816; b=KKJMD1BfL72qGmgGAgGeKjBRN3WXxJNe2oeiL0lp5tWBRyUMkG2CxE5JDqmGRYVXS4 E1M7RJjBtye71OfM4ZVcp3Lz3btquN6geyqIHQ9GvPJH2E0LXbp8hok0qbSo0BbZry4S w40Ktm8ugwzjDupbfJPH/R07wrLyEOz7cuIr0+R0HiGfqzTll18LnWHcwpCccIUFn34q mcD+UrkJMOGWAyLg2N10qlPyElYPHUVAKkUqZfTjtzTS2opR9tBEZUXH7PVxgPzFueIr /K/i5OOgS9Wy3Lk3KpE8MApzXDXHnAFtAx8DJWX4d20At6f6mTJaatqeRR88EIoOsxai o4LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=vaS39ErdvakXDhjr2AJlzEtf1NZBf73g6lMHeNCY3fs=; b=vLqbUck9x1qTJ/oyzQ+28N2jiTnKGJGwuWrqVhnMF1/iWJlojVzWF7uu1SKH3ldvQJ fMcZvrL8Wd9XEfvn1tWLpApsn63AOlt2G979Dn5KBV03NzyHdygkeziQHqi9i/Uh28sG g3AveTTbqkFkcSa5k18Uo56EgO1Xx7ZGm2Zon6GlKb8RN9J0yor88IpLyhYq2DurXSDt gLFeDbW/NknCMhRjOsKUVZJzCwv3vwCNnwXN7XHx5qrOFCl/cLVCLSYOBFp2DSaOAyoh P28q5YhXlPR3k2wEuucQIQ1C7iOA3Bk6rKUNM+3v4Bua3AuoQ4nGMQFthslDyQsVx8cB w9dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OlJCJtVB; spf=pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x10sor1548795wmc.25.2019.02.14.04.51.12 for (Google Transport Security); Thu, 14 Feb 2019 04:51:12 -0800 (PST) Received-SPF: pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OlJCJtVB; spf=pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=Jr0tzAn8vnjFbPewEHYTfm1f7IqUzPA/MEJdauiwVH5S8O/6TofOgSURXgt8rQKEGB NMG/Iv8JRl7rbfXmCieKJfTK89IOihnYOSmr73JsEDT8NIuOhyaQMgkzA1emCtl7kI51 KQXjZKOXiv+gkDONk45vaIf6g1CQz3AWuiO8IrefvJyl33IJGTx8ABIEDkk+mlyPnlqj hFw3PMxrPXyirWlgf7+gBcRHNc8Ou9INsEuMOxSyCFsn9xpJVRlG+Qad1O+3n3mjHoX0 CW8te6OQYF1LTO8s+wwZPAv6JGdJsGs6WlHpMtPw9vhjKQjxR54NjxWh0Lj/wjjz4XWb eoiQ== X-Gm-Message-State: AHQUAubIN1JMobX1WfuwJMDYbinhx2NhcB+OhGBa9SKIISHvBY6glJjS yWMVxcB2uXYNucx0X0vmUq/cIlwu 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) Return-Path: 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) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: patches@linaro.org Subject: [PATCH 02/14] hw/misc/tz-ppc: Support having unused ports in the middle of the range 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 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 --- include/hw/misc/tz-ppc.h | 8 +++++++- hw/misc/tz-ppc.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) -- 2.20.1 Reviewed-by: Richard Henderson 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; }