From patchwork Mon Jul 17 12:44:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107923 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4472318qge; Mon, 17 Jul 2017 05:50:57 -0700 (PDT) X-Received: by 10.55.131.129 with SMTP id f123mr27910603qkd.188.1500295857408; Mon, 17 Jul 2017 05:50:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500295857; cv=none; d=google.com; s=arc-20160816; b=aMhRzGg9ocjIox8aMreLt7izmUZrYGUI8peTZAhRt+jCEhBtDjdVFTakDRPbiIBAIG MvCGsd5LNUrXWbxKinSiCnokJUZR7FSpCc/e5Jgda1k91yDRQ1GM2eLUphZwh/RkmHeR XvyvQXD52qOrCfvhZzyS1GDNge3CActbVNmlrcWxcMqwZQR4g24eUYb4h1TvEfWu011G Zf6n+kAIJYDei5CRBVXc/5lVjEDl3JZHGmKYwu/KTEWi3X9awHQzWwnn4TPKTZmbmIZj d/Leu5rWJYlUIZsZUwm0pJMdIYKAkCA4IJT6rvOfk5FFs63QREM9R2ix5f5gJeyR3kB1 Wgyg== 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:arc-authentication-results; bh=pi0CrlFVeSJ8x8gtJyJTwU0UqJSWbXRqAXkEDvfZeN8=; b=r2X4clADSOUsV3CjomLNttAu6vwidspEc5K9Q0M36xb2LEeg3SQNrW8RfYpQv6qlpi MVAFflOCMYB1a5AifK7uZ6+MzYpoUHMceRlzE2O3KyaE0/hOll7NT0O/ieKy5plH6SR4 LXUpI+07rwTiKyzgQUAToMOsyxLL41bb2P/BtAm2yTp8dZcK6oOm+1DvuDTkTpNqThDK Zo2Mnh26nWLRGYZIK4deb+eB1Z4iXn+ZfNLtatrqOkHnrOmjBUrarCr2B4c3ImrQhxzw 0gTN72Ib/p0EJLZhKJ1j0vwU5pAk4YRnd3uqyDQ6Z1OoMhtfRcZ6EPvtXb+ptnC71p70 N+zQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p185si15194356qkb.1.2017.07.17.05.50.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:50:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5UE-0003sT-RL for patch@linaro.org; Mon, 17 Jul 2017 08:50:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Oi-00081G-4X for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Oh-0002Lw-AQ for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:12 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37640) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Oh-0002Ci-4g for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:11 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OR-0003RN-LY for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:44:55 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:37 +0100 Message-Id: <1500295494-8991-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 01/18] qdev-properties.h: Explicitly set the default value for arraylen properties 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" In DEFINE_PROP_ARRAY, because we use a PropertyInfo (qdev_prop_arraylen) which has a .set_default_value member we will set the field to a default value. That default value will be zero, by the C rule that struct initialization sets unmentioned members to zero if at least one member is initialized. However it's clearer to state it explicitly. Signed-off-by: Peter Maydell Reviewed-by: Marc-André Lureau Message-id: 1499788408-10096-2-git-send-email-peter.maydell@linaro.org --- include/hw/qdev-properties.h | 1 + 1 file changed, 1 insertion(+) -- 2.7.4 diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index f6692d5..12c0c7b 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -111,6 +111,7 @@ extern const PropertyInfo qdev_prop_link; _arrayfield, _arrayprop, _arraytype) { \ .name = (PROP_ARRAY_LEN_PREFIX _name), \ .info = &(qdev_prop_arraylen), \ + .defval.u = 0, \ .offset = offsetof(_state, _field) \ + type_check(uint32_t, typeof_field(_state, _field)), \ .arrayinfo = &(_arrayprop), \ From patchwork Mon Jul 17 12:44:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107928 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4476412qge; Mon, 17 Jul 2017 05:54:42 -0700 (PDT) X-Received: by 10.237.47.132 with SMTP id m4mr25839037qtd.200.1500296082325; Mon, 17 Jul 2017 05:54:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500296082; cv=none; d=google.com; s=arc-20160816; b=zd5bnG7z3FRgOZjwLU2j5FrUjYLV3huMeJLyodAkEliPCsu1pGPYBD1u8TXja39hQE SuQ4leweJLCUn9sslwNvNnzhHu5ElkuKuF4L1rcD7xTy9kTNTfQaFj8N47BRWk5y2glR 69uljgy5oM7OYFm8n4EHq/dn1HvfrDVySgqlvTkVbi4T4haXLrSTHoPgk2Ja44ouNkSY BTicAsCE4y4oXsmVaDL+tSPWOr7R9IkPsBC/3h6baLAXbfLg2HS/EA9wPmCebGeCqbJX Jy5gHu1jxS5eNI/43YUQwSQ6ZkYBPPwJul9M0XjLd6PlBUG7Yw08XV10/93xzh7tsdW9 3ykA== 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:arc-authentication-results; bh=oK8EZVeXko5w/oBODiYdESwTg8mo3/E2OVk08JmySu4=; b=gFqv6drydEeF4c8qQ5yY3NqKFREOB88pbUXLzyyjJB4miL4E5SktyAc81jxG2bJezl GpJM4HxlGQIX4yNxbLiOYhoygjb/d1749PNyj3B//AQoeHQshiKss1xlfUWSTUATg8vq B+l1hjNGzg/Vgtyplu8Xf82z9TdiXNObQVGmLbURa2qs2lzt3W+9uo/2NDn07diRdWGQ /ti417Ns+WQ1gRczzDXTH8e0orU7P2/O6K/LbL+0N/RuKbHPptrgqgWLgnAtII+wjA/u GzWEfUQ33zlj1R5Seq4qZQuhP9ORgSTUqHAEW8q0tCVMWJlr4oZI3hjBtLg31Y0yrARp jX1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j14si14812819qtc.324.2017.07.17.05.54.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:54:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Xr-0007fd-Q7 for patch@linaro.org; Mon, 17 Jul 2017 08:54:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Oi-00081L-5t for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Oh-0002LR-1H for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:12 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Og-00029H-Oh for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:10 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OS-0003Rl-52 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:44:56 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:38 +0100 Message-Id: <1500295494-8991-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 02/18] qdev: support properties which don't set a default value 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" In some situations it's useful to have a qdev property which doesn't automatically set its default value when qdev_property_add_static is called (for instance when the default value is not constant). Support this by adding a flag to the Property struct indicating whether to set the default value. This replaces the existing test for whether the PropertyInfo set_default_value function pointer is NULL, and we set the .set_default field to true for all those cases of struct Property which use a PropertyInfo with a non-NULL set_default_value, so behaviour remains the same as before. This gives us the semantics of: * if .set_default is true, then .info->set_default_value must be not NULL, and .defval is used as the the default value of the property * otherwise, the property system does not set any default, and the field will retain whatever initial value it was given by the device's .instance_init method We define two new macros DEFINE_PROP_SIGNED_NODEFAULT and DEFINE_PROP_UNSIGNED_NODEFAULT, to cover the most plausible use cases of wanting to set an integer property with no default value. Suggested-by: Markus Armbruster Signed-off-by: Peter Maydell Reviewed-by: Marc-André Lureau Reviewed-by: Markus Armbruster Message-id: 1499788408-10096-3-git-send-email-peter.maydell@linaro.org --- include/hw/qdev-core.h | 10 ++++++++++ include/hw/qdev-properties.h | 20 ++++++++++++++++++++ hw/core/qdev.c | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 5348815..ae31728 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -221,11 +221,21 @@ struct BusState { QLIST_ENTRY(BusState) sibling; }; +/** + * Property: + * @set_default: true if the default value should be set from @defval, + * in which case @info->set_default_value must not be NULL + * (if false then no default value is set by the property system + * and the field retains whatever value it was given by instance_init). + * @defval: default value for the property. This is used only if @set_default + * is true. + */ struct Property { const char *name; const PropertyInfo *info; ptrdiff_t offset; uint8_t bitnr; + bool set_default; union { int64_t i; uint64_t u; diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 12c0c7b..3929796 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -44,15 +44,24 @@ extern const PropertyInfo qdev_prop_link; .info = &(_prop), \ .offset = offsetof(_state, _field) \ + type_check(_type,typeof_field(_state, _field)), \ + .set_default = true, \ .defval.i = (_type)_defval, \ } +#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \ + .name = (_name), \ + .info = &(_prop), \ + .offset = offsetof(_state, _field) \ + + type_check(_type, typeof_field(_state, _field)), \ + } + #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \ .name = (_name), \ .info = &(qdev_prop_bit), \ .bitnr = (_bit), \ .offset = offsetof(_state, _field) \ + type_check(uint32_t,typeof_field(_state, _field)), \ + .set_default = true, \ .defval.u = (bool)_defval, \ } @@ -61,15 +70,24 @@ extern const PropertyInfo qdev_prop_link; .info = &(_prop), \ .offset = offsetof(_state, _field) \ + type_check(_type, typeof_field(_state, _field)), \ + .set_default = true, \ .defval.u = (_type)_defval, \ } +#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \ + .name = (_name), \ + .info = &(_prop), \ + .offset = offsetof(_state, _field) \ + + type_check(_type, typeof_field(_state, _field)), \ + } + #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \ .name = (_name), \ .info = &(qdev_prop_bit64), \ .bitnr = (_bit), \ .offset = offsetof(_state, _field) \ + type_check(uint64_t, typeof_field(_state, _field)), \ + .set_default = true, \ .defval.u = (bool)_defval, \ } @@ -78,6 +96,7 @@ extern const PropertyInfo qdev_prop_link; .info = &(qdev_prop_bool), \ .offset = offsetof(_state, _field) \ + type_check(bool, typeof_field(_state, _field)), \ + .set_default = true, \ .defval.u = (bool)_defval, \ } @@ -111,6 +130,7 @@ extern const PropertyInfo qdev_prop_link; _arrayfield, _arrayprop, _arraytype) { \ .name = (PROP_ARRAY_LEN_PREFIX _name), \ .info = &(qdev_prop_arraylen), \ + .set_default = true, \ .defval.u = 0, \ .offset = offsetof(_state, _field) \ + type_check(uint32_t, typeof_field(_state, _field)), \ diff --git a/hw/core/qdev.c b/hw/core/qdev.c index ec63fe0..606ab53 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -800,7 +800,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, prop->info->description, &error_abort); - if (prop->info->set_default_value) { + if (prop->set_default) { prop->info->set_default_value(obj, prop); } } From patchwork Mon Jul 17 12:44:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107931 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4480735qge; Mon, 17 Jul 2017 05:58:59 -0700 (PDT) X-Received: by 10.200.54.210 with SMTP id b18mr6355887qtc.145.1500296339351; Mon, 17 Jul 2017 05:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500296339; cv=none; d=google.com; s=arc-20160816; b=IRrsB23uFW35Ub4gbbGcugQeuqBg3FvLuqlJzgPMDJXPr/V5xsEimAzc6xyGSoMoZO Lj2mVR60GsZAH7B5kKHJS0mmC1XCywzP58kZqCZQGTzqERMS9E9yimZBh791VQdv6Jt3 +wqBGUQ/mLIvDIt3pT21HZNXXgH1U7ZhpXZjYkDMsCXO6ONVgqYKmWNroMBPvKGJFt5S LeqSCHIU7P+AnScxfqEDmjCXug2bYLU2Ngt9FylMXWAPKr2tW96+/sSHqMO4mHNjZm1g e6VPnqyNyh8A0oIIdu93ORQ/B9yVeTWgyr3U5OKC6mmLdMsbUV+TIUS+snknYKGUlgBe 8ldA== 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:arc-authentication-results; bh=S6k8+rRJJRGBpw1Xi3R/0r2ThR/8/hJfdq8ai74CZnE=; b=VXnar4gD127yBUmBgn9/6Nf+jvmpkk10qzc5/YB+MQQWmU+iASJ7W60r9eTs2crbQt uhtEY4YcBzf0inTn2UFfAy94efGSdcdeevQe2mD4HWqNhOuUoUwWDQZ0CNA1UC9aJYBY Xm1PL+u8Gly/QU670dY70QdI75z1vVT5KUTGju6hSDopKyi7IQFmY8CDCC6cxDQIBsWx rsUPy1fgSuVbYAHX827wukOt9bc3CNqq9NuCRyu23E2VYA6HW6ZEoJ17epu+NQxOfNeF APDziUsHf5+DWrgaBsls6tBbboVvPeKh4Oj2FKGXbdx/5z63b6LHcwg0JfPdxlDB60EK iTxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f62si14400792qkb.197.2017.07.17.05.58.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:58:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5c1-0002EV-33 for patch@linaro.org; Mon, 17 Jul 2017 08:58:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Oh-00080C-NV for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Og-0002Ku-HT for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:11 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37640) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Og-0002Ci-BY for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:10 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OS-0003S8-LD for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:44:56 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:39 +0100 Message-Id: <1500295494-8991-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 03/18] target/arm: Make Cortex-M3 and M4 default to 8 PMSA regions 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 Cortex-M3 and M4 CPUs always have 8 PMSA MPU regions (this isn't a configurable option for the hardware). Make the default value of the pmsav7-dregion property be set per-cpu, so we don't need to have every user of these CPUs set it manually. (The existing default of 16 is correct for the other PMSAv7 core, the Cortex-R5.) This fixes a bug where we were creating the M3 and M4 with too many regions; most guest software would not notice or care, though, since it would just not use the registers associated with the unexpected extra regions. Signed-off-by: Peter Maydell Reviewed-by: Marc-André Lureau Message-id: 1499788408-10096-4-git-send-email-peter.maydell@linaro.org --- target/arm/cpu.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 28a9141..96d1f84 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -543,8 +543,15 @@ static Property arm_cpu_has_pmu_property = static Property arm_cpu_has_mpu_property = DEFINE_PROP_BOOL("has-mpu", ARMCPU, has_mpu, true); +/* This is like DEFINE_PROP_UINT32 but it doesn't set the default value, + * because the CPU initfn will have already set cpu->pmsav7_dregion to + * the right value for that particular CPU type, and we don't want + * to override that with an incorrect constant value. + */ static Property arm_cpu_pmsav7_dregion_property = - DEFINE_PROP_UINT32("pmsav7-dregion", ARMCPU, pmsav7_dregion, 16); + DEFINE_PROP_UNSIGNED_NODEFAULT("pmsav7-dregion", ARMCPU, + pmsav7_dregion, + qdev_prop_uint32, uint32_t); static void arm_cpu_post_init(Object *obj) { @@ -1054,6 +1061,7 @@ static void cortex_m3_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_V7); set_feature(&cpu->env, ARM_FEATURE_M); cpu->midr = 0x410fc231; + cpu->pmsav7_dregion = 8; } static void cortex_m4_initfn(Object *obj) @@ -1064,6 +1072,7 @@ static void cortex_m4_initfn(Object *obj) set_feature(&cpu->env, ARM_FEATURE_M); set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP); cpu->midr = 0x410fc240; /* r0p0 */ + cpu->pmsav7_dregion = 8; } static void arm_v7m_class_init(ObjectClass *oc, void *data) { @@ -1112,6 +1121,7 @@ static void cortex_r5_initfn(Object *obj) cpu->id_isar4 = 0x0010142; cpu->id_isar5 = 0x0; cpu->mp_is_up = true; + cpu->pmsav7_dregion = 16; define_arm_cp_regs(cpu, cortexr5_cp_reginfo); } From patchwork Mon Jul 17 12:44:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107921 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4471094qge; Mon, 17 Jul 2017 05:49:52 -0700 (PDT) X-Received: by 10.200.42.27 with SMTP id k27mr26337883qtk.40.1500295792165; Mon, 17 Jul 2017 05:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500295792; cv=none; d=google.com; s=arc-20160816; b=E3Jp94VflgXqCfeZ6FYkVhOlkNtNI3/1EDS4xMOt6J19j6GiBbk+zhgGXqB0DBBrZh q2lE7I8Erqt2U6tdgiUb5xtt6QgRLX+G6/v8HBewRzZRD3i/aPLXXOHB/X25VyHwINl8 oEaulPGpnwIvgkChjl8Do01ZQ84ASNHNLyrIaYEvBDAfs1t/j7/Wu59y5ULYsqVug8qd 0pM5W5O/n1/8XsS/rIOz9n1kyRHTwHxX693c7perH2NaaXipUQKkittUJ3JZ9tPu0+YF fdvFUbHbfa2Dxzz6m1qq0UMZq48D2DX5aiGdUgDEXyq99m9FtlTE+D/sqGxD0a8Jt8t9 c7DQ== 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:arc-authentication-results; bh=GSlpuZiWkWiUR7yaSFTCLKeDuefso4ELCr7NV+NEu8k=; b=xZyg9efNMasLufGBl8yMp5ohdfCD6jOAdoG0qSVIpOL0fQg9G+B77plcPZXKT6ZyaS vmoIoEEPcz19cssnsr75t7+z5CyFOlFihrjXUzYYJ6Ln8xaGH/4SX29pP3mK4yKW4NA5 xjKt7pRpbYe9+AgJta4QCytUjqeZN/7QqH39F8ncgn2pJhSeKHZwNlmtOLLZfAI3+oPp dR3Wmj7JcPbkXmP/lc7u/82TibZ0UQKpwvZ7DGMMW4HSl7Bsq6hnwoZsaL8eSmeKrq32 XzGV6jG8Tvk/v0TbZVjTjkvpd5/ifttXXZJEa6m9f+KFz1gE8qnJnvwnDlk4kHo224/H RZqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k87si15846747qkh.369.2017.07.17.05.49.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:49:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5TB-0002oR-Gj for patch@linaro.org; Mon, 17 Jul 2017 08:49:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Oh-0007yH-2Y for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Og-0002Kc-5D for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:11 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Of-00029H-TL for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:10 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OT-0003SV-4q for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:44:57 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:40 +0100 Message-Id: <1500295494-8991-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 04/18] include/exec/exec-all: document common exit conditions 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" From: Alex Bennée As a precursor to later patches attempt to come up with a more concrete wording for what each of the common exit cases would be. CC: Emilio G. Cota CC: Richard Henderson CC: Lluís Vilanova Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-id: 20170713141928.25419-2-alex.bennee@linaro.org Signed-off-by: Peter Maydell --- include/exec/exec-all.h | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index bf8da2a..6b6e287 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -35,11 +35,34 @@ typedef abi_ulong tb_page_addr_t; typedef ram_addr_t tb_page_addr_t; #endif -/* is_jmp field values */ +/* DisasContext is_jmp field values + * + * is_jmp starts as DISAS_NEXT. The translator will keep processing + * instructions until an exit condition is reached. If we reach the + * exit condition and is_jmp is still DISAS_NEXT (because of some + * other condition) we simply "jump" to the next address. + * The remaining exit cases are: + * + * DISAS_JUMP - Only the PC was modified dynamically (e.g computed) + * DISAS_TB_JUMP - Only the PC was modified statically (e.g. branch) + * + * In these cases as long as the PC is updated we can chain to the + * next TB either by exiting the loop or looking up the next TB via + * the loookup helper. + * + * DISAS_UPDATE - CPU State was modified dynamically + * + * This covers any other CPU state which necessities us exiting the + * TCG code to the main run-loop. Typically this includes anything + * that might change the interrupt state. + * + * Individual translators may define additional exit cases to deal + * with per-target special conditions. + */ #define DISAS_NEXT 0 /* next instruction can be analyzed */ #define DISAS_JUMP 1 /* only pc was modified dynamically */ -#define DISAS_UPDATE 2 /* cpu state was modified dynamically */ -#define DISAS_TB_JUMP 3 /* only pc was modified statically */ +#define DISAS_TB_JUMP 2 /* only pc was modified statically */ +#define DISAS_UPDATE 3 /* cpu state was modified dynamically */ #include "qemu/log.h" From patchwork Mon Jul 17 12:44:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107926 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4475091qge; Mon, 17 Jul 2017 05:53:27 -0700 (PDT) X-Received: by 10.55.140.71 with SMTP id o68mr25127099qkd.18.1500296007543; Mon, 17 Jul 2017 05:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500296007; cv=none; d=google.com; s=arc-20160816; b=CnluhXfWkgXfrP4EagZrh92ylSealEzLmZNWD7JETbiYmoKNysgfMKHGUeEXduOedV d6Vb/3hvwtUWNOL4plfJxbUYBsd34Us+k4m+2+2dZ/dir/WK1PvuInFFMB9fz+uwSUxv TNQZQp8EWVu775NGFL00duYTzbqH5vey1IrgmT//FQtF88moiKX+XfJsuhoIVptQsUe2 4XF6XLIPMBmsZ+YqZPoL0fQZVen1gmAPXS7hDvC4Q3/gFuGXgbnp532grhgE1Es1B154 oyvhEvuCkYCsBak5gzcxhi83+xAu4yAf2KuYc+ZXR7oDz0cB4AMnripdzdxbfsxugug3 wkbQ== 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:arc-authentication-results; bh=0jEmJ/QktPQsLmJm0ep81jL2HpBeQvlv5r5juaFBgqo=; b=LeBLOOb+XzPyNFDAe4kyy8PaFHofCQgUUv/oSM+q+ODMpvixemxCAeMnAAeNkRyip7 xYegKe9GjkA0Fx4heBXONOAv3GqS4/w4f6IDMylDoJksB5FGuFE3s5btEGOGCSo6pE54 1/lZbcrjc3rGVM4EdsAQPnXuQ2/ajtWHSiPQFV3aX6r5ECTFGjbAaLKufWApQwbd+AqT p+UPb/ZvZUdZJui0a1TRKYLhT3TBPiJAL+eVlqti679nqRiRx7/Ojk5owmBohxCpFSmd uB59p7TegkZX2C0Kd5xWDZPtcBHN97BGAfFTMXEZIzzTLhe1Riwlx3aFtupeCXT5i5AW /1Dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n1si1547163qtd.175.2017.07.17.05.53.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:53:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Wf-0006Bo-5K for patch@linaro.org; Mon, 17 Jul 2017 08:53:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Og-0007xR-NM for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Of-0002Jw-Od for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:10 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37640) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Of-0002Ci-HY for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:09 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OT-0003Ss-K0 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:44:57 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:41 +0100 Message-Id: <1500295494-8991-6-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 05/18] target/arm/translate: make DISAS_UPDATE match declared semantics 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" From: Alex Bennée DISAS_UPDATE should be used when the wider CPU state other than just the PC has been updated and we should therefore exit the TCG runtime and return to the main execution loop rather assuming DISAS_JUMP would do that. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-id: 20170713141928.25419-3-alex.bennee@linaro.org Signed-off-by: Peter Maydell --- target/arm/translate-a64.c | 14 +++++++------- target/arm/translate.c | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) -- 2.7.4 diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index e55547d..66139b6 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -11364,16 +11364,9 @@ void gen_intermediate_code_a64(ARMCPU *cpu, TranslationBlock *tb) case DISAS_NEXT: gen_goto_tb(dc, 1, dc->pc); break; - default: - case DISAS_UPDATE: - gen_a64_set_pc_im(dc->pc); - /* fall through */ case DISAS_JUMP: tcg_gen_lookup_and_goto_ptr(cpu_pc); break; - case DISAS_EXIT: - tcg_gen_exit_tb(0); - break; case DISAS_TB_JUMP: case DISAS_EXC: case DISAS_SWI: @@ -11397,6 +11390,13 @@ void gen_intermediate_code_a64(ARMCPU *cpu, TranslationBlock *tb) */ tcg_gen_exit_tb(0); break; + case DISAS_UPDATE: + gen_a64_set_pc_im(dc->pc); + /* fall through */ + case DISAS_EXIT: + default: + tcg_gen_exit_tb(0); + break; } } diff --git a/target/arm/translate.c b/target/arm/translate.c index 0862f9e..5f2cea8 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -12095,12 +12095,12 @@ void gen_intermediate_code(CPUARMState *env, TranslationBlock *tb) case DISAS_NEXT: gen_goto_tb(dc, 1, dc->pc); break; - case DISAS_UPDATE: - gen_set_pc_im(dc, dc->pc); - /* fall through */ case DISAS_JUMP: gen_goto_ptr(); break; + case DISAS_UPDATE: + gen_set_pc_im(dc, dc->pc); + /* fall through */ default: /* indicate that the hash table must be used to find the next TB */ tcg_gen_exit_tb(0); From patchwork Mon Jul 17 12:44:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107929 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4478253qge; Mon, 17 Jul 2017 05:56:30 -0700 (PDT) X-Received: by 10.237.43.199 with SMTP id e65mr29896775qtd.19.1500296190883; Mon, 17 Jul 2017 05:56:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500296190; cv=none; d=google.com; s=arc-20160816; b=D+lN/61h4M3/8FKDStlI+954c8iYzPZDqDx+1BqEekZkoe/AsSwKZnk3ix3gbTh3FB 4cdjSmiV+VNqh4IIUDqj8vFtrRYvvGfKyRgdcjno90w/ICCkoPgBjJa+dFlkBDpnmqpx I2T0+zkXCyZbsYll56EI87fA3FkELxwuQq9auNqWBpaMG7XH/j6ONF+Hck4hssaMjJ9R Ph48QG/537xQXOVFA+li0nFx+KD0t2+oEhR+aA+qqzf/KCUGqBfw25tDEwEQWlZ6Wbzy JlerdYz3FkdoLKSN3foWELvkz8KDLxlHfRekNtzJhGcrtYft0zhOfapNUtvp+frSSuXQ HKcQ== 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:arc-authentication-results; bh=ahn6p5BrDCdi06Rw46z/4qfuz9/1FUbAUScpO4Q2qUY=; b=fW+P6YSokz/JhMBVEArzKAZX+ZZakuREFfmBIfSDISbP/AJtHvH7u3a39hptK6IZWd ZHyJC35P5GzKAmIUcNNi9qeFwa9gvXzP7M/OC9183o9hAolktvAtZSx4GWkBKoiBVJ5G 0JMAK+Xq3pibdOqF1mDGjmTHfCAc+gH3481figg5GFxF4eJUqOATUX351ABu+vY30Fqs L+L+vCOm+6pN0xynd6GaOllI0jXxyThfxFlpw6KPMAl9RK2pho9aiqRFfWVmqmr7DHpu VuRYTLuWL22TFEpr4LGkX5BVPdf9BjCz7u6IJf6wtJPdeFcS/W9BseY2QasY9Cj7W6Tl 9/hw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id y3si1627162qkc.225.2017.07.17.05.56.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:56:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Zb-0000gA-VK for patch@linaro.org; Mon, 17 Jul 2017 08:56:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Og-0007wF-0v for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Of-0002JW-9P for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:10 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Of-00029H-3T for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:09 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OU-0003TG-7M for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:44:58 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:42 +0100 Message-Id: <1500295494-8991-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 06/18] target/arm/translate.h: expand comment on DISAS_EXIT 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" From: Alex Bennée We already have an exit condition, DISAS_UPDATE which will exit the run-loop. Expand on the difference with DISAS_EXIT in the comments. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-id: 20170713141928.25419-4-alex.bennee@linaro.org Signed-off-by: Peter Maydell --- target/arm/translate.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/target/arm/translate.h b/target/arm/translate.h index 15d383d..12fd79b 100644 --- a/target/arm/translate.h +++ b/target/arm/translate.h @@ -140,7 +140,10 @@ static void disas_set_insn_syndrome(DisasContext *s, uint32_t syn) */ #define DISAS_BX_EXCRET 11 /* For instructions which want an immediate exit to the main loop, - * as opposed to attempting to use lookup_and_goto_ptr. + * as opposed to attempting to use lookup_and_goto_ptr. Unlike + * DISAS_UPDATE this doesn't write the PC on exiting the translation + * loop so you need to ensure something (gen_a64_set_pc_im or runtime + * helper) has done so before we reach return from cpu_tb_exec. */ #define DISAS_EXIT 12 From patchwork Mon Jul 17 12:44:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107919 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4469294qge; Mon, 17 Jul 2017 05:48:08 -0700 (PDT) X-Received: by 10.55.40.218 with SMTP id o87mr24257613qko.50.1500295688128; Mon, 17 Jul 2017 05:48:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500295688; cv=none; d=google.com; s=arc-20160816; b=ho0RLAu6KjHEKPB89xGelWP4a/MJn/++4CSVf+iGMFKNX1apjAgS9DxOqKQ/IHZPMW 1aLwA/Y/BtUVxVJuM1Hs9GFgC6Wo7Uns4eTgfrDpGLE8E3hmZ4NVLsWJjKILWnKBciKr nueSCoHdh32dm5GxnOUqVJRpNc9HLBWCzDjbwzWUvrXL5OI1xFPyAWEf88ndSbpDO6OK Nk6xXyAMXkLsD3jctmKAG8BnSBn3lx/OsBuz9mZQyTuOugbFu2dXJIP9pX4Fc8MblCAZ maGWDZbdBFvlw+bNe0SGVnYMBAdS9RbbIgH6nQJ7poYkyGrt3OA8887rJVZahpEAeFc/ CnNA== 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:arc-authentication-results; bh=DFYz2baoA5jfhwjCl9eHfwPpApXLv3iQfJ9F89fOCnQ=; b=UIbBW+tLgzECbRJKqWDQ4/PyJUXsD3Nw8L9MrfGt7E7KpZUOYrMCb2Kb1Oru67UrGf BhPQdt6+qGHbGlfzfUEB/qmMctseTn7x6LmYZDfWoO3twwjnLVKLHHVzd/bSatTBTdgs sEzAuIQrnZ07k8F1lNr3LbGkKrqvP6N27iNOvVPsJ07MQf5Q7xUzRcg13wV5bV5BUiaF dn64Hhm1CHql1noC+a3Ld1h5Bd0WSOq+AE1UXTICxua5AMea7LuKOmmxs1wCQ5Y6f4+M velE8zoL9NEL+LeKNfsJoW6YJtTb9iEaf6IR9c+XJnRgBsA1NtQap+XDuWYemAgZgK9c ZD1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t188si6211983qkd.239.2017.07.17.05.48.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:48:08 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5RV-0001dD-Ic for patch@linaro.org; Mon, 17 Jul 2017 08:48:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Of-0007vp-RI for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Oe-0002J7-VI for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:09 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37640) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Oe-0002Ci-Op for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:08 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OU-0003Td-Lr for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:44:58 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:43 +0100 Message-Id: <1500295494-8991-8-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 07/18] target/arm/translate: ensure gen_goto_tb sets exit flags 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" From: Alex Bennée As the gen_goto_tb function can do both static and dynamic jumps it should also set the is_jmp field. This matches the behaviour of the a64 code. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-id: 20170713141928.25419-5-alex.bennee@linaro.org [tweak to multiline comment formatting] Signed-off-by: Peter Maydell --- target/arm/translate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/target/arm/translate.c b/target/arm/translate.c index 5f2cea8..bbae519 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -4158,6 +4158,10 @@ static void gen_goto_ptr(void) tcg_temp_free(addr); } +/* This will end the TB but doesn't guarantee we'll return to + * cpu_loop_exec. Any live exit_requests will be processed as we + * enter the next TB. + */ static void gen_goto_tb(DisasContext *s, int n, target_ulong dest) { if (use_goto_tb(s, dest)) { @@ -4168,6 +4172,7 @@ static void gen_goto_tb(DisasContext *s, int n, target_ulong dest) gen_set_pc_im(s, dest); gen_goto_ptr(); } + s->is_jmp = DISAS_TB_JUMP; } static inline void gen_jmp (DisasContext *s, uint32_t dest) @@ -4179,7 +4184,6 @@ static inline void gen_jmp (DisasContext *s, uint32_t dest) gen_bx_im(s, dest); } else { gen_goto_tb(s, 0, dest); - s->is_jmp = DISAS_TB_JUMP; } } From patchwork Mon Jul 17 12:44:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107924 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4474033qge; Mon, 17 Jul 2017 05:52:26 -0700 (PDT) X-Received: by 10.200.53.232 with SMTP id l37mr6339542qtb.7.1500295946606; Mon, 17 Jul 2017 05:52:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500295946; cv=none; d=google.com; s=arc-20160816; b=b0anTpk7mdmj1AKDyqF1DjbDR6uCP1zpE3engzCL7kNOv8t2riDHK+CzbrSI3az5s/ xbcIjomNVYK/5MCKe2iP/oLMhDsOZZpujUrJNMxgmeaKxHyvO/A3NhEzhoj6ncuMaQDa nFeoMdoJ7jBepHQ9lRyFkPXAzd/1aLMxudB9sCquncCGaz/YDlf5COY1EGio2cmO/pvi K4j+FjGDKD66bhIf9FSp6Cqfjh0zwppvsiQO3R6m6slVKd77ScqtEWh9Uk4fxp/wN529 4f3sQUVLgvWXOsl9AzEnsPFCyGdigSRbqTjDnOvupHt3+bC492/NJTQmGfRGlv23Kham b6GA== 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:arc-authentication-results; bh=fIFojjKj75i17YPmxwq7DUjOZyqBxtdY3Evo0ws1B4s=; b=qsCgKVqqfaX5B4F+9DhgDQ6dylY3yTiuEuDv/YlAxJ4Kk7zm9ErfOxCF2KaBL5byVn dE7dv6HFfsKdDYOIezzZRvpovNOd6PnCrwfBwVvVD/SqzdwQJB8W8NyK84VwtV4REbV6 G7pQ9aX/iowoFJD8xdQW9nfLSvm5Cnly7WzRBnI9gBzCm/SS5tem0ozaTRFI3DucvUg2 Njgx02kyQPBnfjVFbZbMia/NF5susojps1s0q5MDLZo3v62Qtrswqs5dVlTRKBff5lzW E1kqQvUgMaaXSnKx6rky4WSaFWJh1U4aE6l+X4Bi0w9XrWkTSDq2880tKCvoJfO8EEXW Op2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id w60si15085967qte.231.2017.07.17.05.52.26 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:52:26 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Vg-0004y2-6P for patch@linaro.org; Mon, 17 Jul 2017 08:52:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Of-0007vI-Ly for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Oe-0002IB-I4 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:09 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Oe-00029H-9r for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:08 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OV-0003U0-9F for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:44:59 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:44 +0100 Message-Id: <1500295494-8991-9-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 08/18] target/arm: use gen_goto_tb for ISB handling 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" From: Alex Bennée While an ISB will ensure any raised IRQs happen on the next instruction it doesn't cause any to get raised by itself. We can therefore use a simple tb exit for ISB instructions and rely on the exit_request check at the top of each TB to deal with exiting if needed. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-id: 20170713141928.25419-6-alex.bennee@linaro.org Signed-off-by: Peter Maydell --- target/arm/translate-a64.c | 2 +- target/arm/translate.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 66139b6..2ac565e 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -1393,7 +1393,7 @@ static void handle_sync(DisasContext *s, uint32_t insn, * a self-modified code correctly and also to take * any pending interrupts immediately. */ - s->is_jmp = DISAS_UPDATE; + gen_goto_tb(s, 0, s->pc); return; default: unallocated_encoding(s); diff --git a/target/arm/translate.c b/target/arm/translate.c index bbae519..75cdeca 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -8169,7 +8169,7 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn) * self-modifying code correctly and also to take * any pending interrupts immediately. */ - gen_lookup_tb(s); + gen_goto_tb(s, 0, s->pc & ~1); return; default: goto illegal_op; @@ -10562,7 +10562,7 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw * and also to take any pending interrupts * immediately. */ - gen_lookup_tb(s); + gen_goto_tb(s, 0, s->pc & ~1); break; default: goto illegal_op; From patchwork Mon Jul 17 12:44:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107932 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4481190qge; Mon, 17 Jul 2017 05:59:29 -0700 (PDT) X-Received: by 10.237.62.157 with SMTP id n29mr12020297qtf.0.1500296369787; Mon, 17 Jul 2017 05:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500296369; cv=none; d=google.com; s=arc-20160816; b=QHImsqbHxij4RsNqGQi9YIujPvtBSnd3jnaEuFurw8Mg9ORjAkwaJZ+ViWSJ3t+rZj 7iDSRvL/FthFrTFDloEGVsP1b5bI+xI4uFsPfAKRpFrGVRfsC1INv2TAPn5i3o/OBwPo Dms4fhmaRzm0HLdWtmzykNFFEvvvPGKjBniOQ0IUakgYKwmsLqxIuH6s2wZUpWIaklG5 PHlCIOqTX3ISFkd/CLjHoA1mi/IofA5byCdGcqF4tw8XHIkPh9A/EXUKHvZsmy40yqvQ hEgsNwBzvKkc/EaqEgM0LL6QeN/t5dkoBqQzb7KWXgugD/azJ3OY7PnRjyCM4+qIKwfL w8zw== 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:arc-authentication-results; bh=5zW2sexFpzukGuFe4vZpEkR4fU2AVc/io2UfDWdz+h0=; b=ll1+0nmXEQpHy1ZA3WWE50J41+eiKFVusTW153NrBuutJ3NvpfFpEHdOHSYC9BeQ5P 31ItzfHROy/vrod73AMIWkDoMFtqcdnu6Az0k2qc3xnXCevlvk6LvN90IjKL9z1mBzjr aLPwmVq3mP8D9SdnN8UHbF1d0Z1UoGFfM7be5zQWmJfNA0MF/TsHu3h1/8iuMybFnT3U InwoqKKLy0XMz7erYY0kxAR1AYoF/KKpAe6h8jZn0mLlvvzI1K3HK65SDVLeZ/d1vnwo RFM4QXF4V2Yqao0tLfxRSZxQ5cTokFrgGULNUs3N8riRr2Obcgp8aaTtsns4xQ/A6nlP A/cw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 43si15043526qtn.289.2017.07.17.05.59.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:59:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5cV-0002Xa-D5 for patch@linaro.org; Mon, 17 Jul 2017 08:59:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Of-0007uV-5S for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Oe-0002Hf-4C for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:09 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37640) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Od-0002Ci-Tn for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:08 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OV-0003UO-NW for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:44:59 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:45 +0100 Message-Id: <1500295494-8991-10-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 09/18] target/arm: use DISAS_EXIT for eret handling 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" From: Alex Bennée Previously DISAS_JUMP did ensure this but with the optimisation of 8a6b28c7 (optimize indirect branches) we might not leave the loop. This means if any pending interrupts are cleared by changing IRQ flags we might never get around to servicing them. You usually notice this by seeing the lookup_tb_ptr() helper gainfully chaining TBs together while cpu->interrupt_request remains high and the exit_request has not been set. This breaks amongst other things the OPTEE test suite which executes an eret from the secure world after a non-secure world IRQ has gone pending which then never gets serviced. Instead of using the previously implied semantics of DISAS_JUMP we use DISAS_EXIT which will always exit the run-loop. CC: Etienne Carriere CC: Joakim Bech CC: Jaroslaw Pelczar CC: Peter Maydell CC: Emilio G. Cota Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Message-id: 20170713141928.25419-7-alex.bennee@linaro.org Signed-off-by: Peter Maydell --- target/arm/translate-a64.c | 3 ++- target/arm/translate.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 2ac565e..3fa3902 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -1788,7 +1788,8 @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) return; } gen_helper_exception_return(cpu_env); - s->is_jmp = DISAS_JUMP; + /* Must exit loop to check un-masked IRQs */ + s->is_jmp = DISAS_EXIT; return; case 5: /* DRPS */ if (rn != 0x1f) { diff --git a/target/arm/translate.c b/target/arm/translate.c index 75cdeca..e27736c 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -4479,7 +4479,8 @@ static void gen_rfe(DisasContext *s, TCGv_i32 pc, TCGv_i32 cpsr) */ gen_helper_cpsr_write_eret(cpu_env, cpsr); tcg_temp_free_i32(cpsr); - s->is_jmp = DISAS_JUMP; + /* Must exit loop to check un-masked IRQs */ + s->is_jmp = DISAS_EXIT; } /* Generate an old-style exception return. Marks pc as dead. */ @@ -9523,7 +9524,8 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn) tmp = load_cpu_field(spsr); gen_helper_cpsr_write_eret(cpu_env, tmp); tcg_temp_free_i32(tmp); - s->is_jmp = DISAS_JUMP; + /* Must exit loop to check un-masked IRQs */ + s->is_jmp = DISAS_EXIT; } } break; From patchwork Mon Jul 17 12:44:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107922 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4472257qge; Mon, 17 Jul 2017 05:50:54 -0700 (PDT) X-Received: by 10.200.44.87 with SMTP id e23mr25985835qta.123.1500295854255; Mon, 17 Jul 2017 05:50:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500295854; cv=none; d=google.com; s=arc-20160816; b=B87V0e35CZWC/Mo703eQUoAmSPHCVuNk/01SUg9h9hSurnq3SdM4fj+kyswX1Kooiq t82CzTkg0J/tSy7QLxqIAEtosuZ8DIya+sYbuyb6J5yK6YX0/6/f0VuNwWIdY8gtodAK flEnWRR31kYjkffD5IfA6cHFLd7+IKPtAheDtQeOfLTED0ymc+v/hzoIEBmzYVwKifxo OKkkw9+pXr9wtIR8H9DZ7hgHECUpHj7NwFgjGdOinCvEiSRtkB9fhfLFufWgUu8G0C2E n7pxOenS2wkAzG8igG/PRHlqJ35PfVL4Prf5Ym2BKHTI0t2CSKBLsRMZGqncRMcDIFdK 4r9w== 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:arc-authentication-results; bh=AAI+T84PLep52rR7Lb83C1d9XVc0FEZwD/FbnBCqEzE=; b=0U9tI7R2BmCs6JNm10hBWGylSqgiOfizXo+JKBYSC9hy4ONx9FeZokLjjI1joE9bnl ItQIogppBGvImntaOG9N5NwG3qG+5irxRoQ1pP/fnUMP0QC59FmBSSFvcySbczcxvRD9 ZJ7Hf/wiRQCpBYre5l8TvEW9calMpaiKKW6gu5TKVDNfdDkrqK/dzdFqX0ETSzaupX5W 4yLmVl4ozAPC9n1HCN2mkI3PBYll+/9BKz+cBe6jM+rNwvKcrDPcwKWTUKgJAO1tcqOp XKstKCqAbjrA+Je+uCsnsF0vbAi5SPpITKi5cjEPFFK5fSkRdyNiOoGSWS4syGQIH3hE N1tA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b131si2214413qka.23.2017.07.17.05.50.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:50:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5UB-0003ox-9F for patch@linaro.org; Mon, 17 Jul 2017 08:50:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59135) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Of-0007v5-Ij for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Od-0002Gx-NJ for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:09 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Od-00029H-Cv for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:07 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OW-0003Ul-6T for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:45:00 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:46 +0100 Message-Id: <1500295494-8991-11-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 10/18] hw/arm/mps2: Implement skeleton mps2-an385 and mps2-an511 board models 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" Model the ARM MPS2/MPS2+ FPGA based development board. The MPS2 and MPS2+ dev boards are FPGA based (the 2+ has a bigger FPGA but is otherwise the same as the 2). Since the CPU itself and most of the devices are in the FPGA, the details of the board as seen by the guest depend significantly on the FPGA image. We model the following FPGA images: "mps2_an385" -- Cortex-M3 as documented in ARM Application Note AN385 "mps2_an511" -- Cortex-M3 'DesignStart' as documented in AN511 They are fairly similar but differ in the details for some peripherals. Signed-off-by: Peter Maydell Message-id: 1500029487-14822-2-git-send-email-peter.maydell@linaro.org Reviewed-by: Alex Bennée --- hw/arm/Makefile.objs | 1 + hw/arm/mps2.c | 270 ++++++++++++++++++++++++++++++++++++++++ default-configs/arm-softmmu.mak | 1 + 3 files changed, 272 insertions(+) create mode 100644 hw/arm/mps2.c -- 2.7.4 diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs index 4c5c4ee..a2e56ec 100644 --- a/hw/arm/Makefile.objs +++ b/hw/arm/Makefile.objs @@ -18,3 +18,4 @@ obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o +obj-$(CONFIG_MPS2) += mps2.o diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c new file mode 100644 index 0000000..22b33ff --- /dev/null +++ b/hw/arm/mps2.c @@ -0,0 +1,270 @@ +/* + * ARM V2M MPS2 board emulation. + * + * Copyright (c) 2017 Linaro Limited + * Written by Peter Maydell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or + * (at your option) any later version. + */ + +/* The MPS2 and MPS2+ dev boards are FPGA based (the 2+ has a bigger + * FPGA but is otherwise the same as the 2). Since the CPU itself + * and most of the devices are in the FPGA, the details of the board + * as seen by the guest depend significantly on the FPGA image. + * We model the following FPGA images: + * "mps2-an385" -- Cortex-M3 as documented in ARM Application Note AN385 + * "mps2-an511" -- Cortex-M3 'DesignStart' as documented in AN511 + * + * Links to the TRM for the board itself and to the various Application + * Notes which document the FPGA images can be found here: + * https://developer.arm.com/products/system-design/development-boards/cortex-m-prototyping-system + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/arm/arm.h" +#include "hw/arm/armv7m.h" +#include "hw/boards.h" +#include "exec/address-spaces.h" +#include "hw/misc/unimp.h" + +typedef enum MPS2FPGAType { + FPGA_AN385, + FPGA_AN511, +} MPS2FPGAType; + +typedef struct { + MachineClass parent; + MPS2FPGAType fpga_type; + const char *cpu_model; +} MPS2MachineClass; + +typedef struct { + MachineState parent; + + ARMv7MState armv7m; + MemoryRegion psram; + MemoryRegion ssram1; + MemoryRegion ssram1_m; + MemoryRegion ssram23; + MemoryRegion ssram23_m; + MemoryRegion blockram; + MemoryRegion blockram_m1; + MemoryRegion blockram_m2; + MemoryRegion blockram_m3; + MemoryRegion sram; +} MPS2MachineState; + +#define TYPE_MPS2_MACHINE "mps2" +#define TYPE_MPS2_AN385_MACHINE MACHINE_TYPE_NAME("mps2-an385") +#define TYPE_MPS2_AN511_MACHINE MACHINE_TYPE_NAME("mps2-an511") + +#define MPS2_MACHINE(obj) \ + OBJECT_CHECK(MPS2MachineState, obj, TYPE_MPS2_MACHINE) +#define MPS2_MACHINE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(MPS2MachineClass, obj, TYPE_MPS2_MACHINE) +#define MPS2_MACHINE_CLASS(klass) \ + OBJECT_CLASS_CHECK(MPS2MachineClass, klass, TYPE_MPS2_MACHINE) + +/* Main SYSCLK frequency in Hz */ +#define SYSCLK_FRQ 25000000 + +/* Initialize the auxiliary RAM region @mr and map it into + * the memory map at @base. + */ +static void make_ram(MemoryRegion *mr, const char *name, + hwaddr base, hwaddr size) +{ + memory_region_init_ram(mr, NULL, name, size, &error_fatal); + memory_region_add_subregion(get_system_memory(), base, mr); +} + +/* Create an alias of an entire original MemoryRegion @orig + * located at @base in the memory map. + */ +static void make_ram_alias(MemoryRegion *mr, const char *name, + MemoryRegion *orig, hwaddr base) +{ + memory_region_init_alias(mr, NULL, name, orig, 0, + memory_region_size(orig)); + memory_region_add_subregion(get_system_memory(), base, mr); +} + +static void mps2_common_init(MachineState *machine) +{ + MPS2MachineState *mms = MPS2_MACHINE(machine); + MPS2MachineClass *mmc = MPS2_MACHINE_GET_CLASS(machine); + MemoryRegion *system_memory = get_system_memory(); + DeviceState *armv7m; + + if (!machine->cpu_model) { + machine->cpu_model = mmc->cpu_model; + } + + if (strcmp(machine->cpu_model, mmc->cpu_model) != 0) { + error_report("This board can only be used with CPU %s", mmc->cpu_model); + exit(1); + } + + /* The FPGA images have an odd combination of different RAMs, + * because in hardware they are different implementations and + * connected to different buses, giving varying performance/size + * tradeoffs. For QEMU they're all just RAM, though. We arbitrarily + * call the 16MB our "system memory", as it's the largest lump. + * + * Common to both boards: + * 0x21000000..0x21ffffff : PSRAM (16MB) + * AN385 only: + * 0x00000000 .. 0x003fffff : ZBT SSRAM1 + * 0x00400000 .. 0x007fffff : mirror of ZBT SSRAM1 + * 0x20000000 .. 0x203fffff : ZBT SSRAM 2&3 + * 0x20400000 .. 0x207fffff : mirror of ZBT SSRAM 2&3 + * 0x01000000 .. 0x01003fff : block RAM (16K) + * 0x01004000 .. 0x01007fff : mirror of above + * 0x01008000 .. 0x0100bfff : mirror of above + * 0x0100c000 .. 0x0100ffff : mirror of above + * AN511 only: + * 0x00000000 .. 0x0003ffff : FPGA block RAM + * 0x00400000 .. 0x007fffff : ZBT SSRAM1 + * 0x20000000 .. 0x2001ffff : SRAM + * 0x20400000 .. 0x207fffff : ZBT SSRAM 2&3 + * + * The AN385 has a feature where the lowest 16K can be mapped + * either to the bottom of the ZBT SSRAM1 or to the block RAM. + * This is of no use for QEMU so we don't implement it (as if + * zbt_boot_ctrl is always zero). + */ + memory_region_allocate_system_memory(&mms->psram, + NULL, "mps.ram", 0x1000000); + memory_region_add_subregion(system_memory, 0x21000000, &mms->psram); + + switch (mmc->fpga_type) { + case FPGA_AN385: + make_ram(&mms->ssram1, "mps.ssram1", 0x0, 0x400000); + make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x400000); + make_ram(&mms->ssram23, "mps.ssram23", 0x20000000, 0x400000); + make_ram_alias(&mms->ssram23_m, "mps.ssram23_m", + &mms->ssram23, 0x20400000); + make_ram(&mms->blockram, "mps.blockram", 0x01000000, 0x4000); + make_ram_alias(&mms->blockram_m1, "mps.blockram_m1", + &mms->blockram, 0x01004000); + make_ram_alias(&mms->blockram_m2, "mps.blockram_m2", + &mms->blockram, 0x01008000); + make_ram_alias(&mms->blockram_m3, "mps.blockram_m3", + &mms->blockram, 0x0100c000); + break; + case FPGA_AN511: + make_ram(&mms->blockram, "mps.blockram", 0x0, 0x40000); + make_ram(&mms->ssram1, "mps.ssram1", 0x00400000, 0x00800000); + make_ram(&mms->sram, "mps.sram", 0x20000000, 0x20000); + make_ram(&mms->ssram23, "mps.ssram23", 0x20400000, 0x400000); + break; + default: + g_assert_not_reached(); + } + + object_initialize(&mms->armv7m, sizeof(mms->armv7m), TYPE_ARMV7M); + armv7m = DEVICE(&mms->armv7m); + qdev_set_parent_bus(armv7m, sysbus_get_default()); + switch (mmc->fpga_type) { + case FPGA_AN385: + qdev_prop_set_uint32(armv7m, "num-irq", 32); + break; + case FPGA_AN511: + qdev_prop_set_uint32(armv7m, "num-irq", 64); + break; + default: + g_assert_not_reached(); + } + qdev_prop_set_string(armv7m, "cpu-model", machine->cpu_model); + object_property_set_link(OBJECT(&mms->armv7m), OBJECT(system_memory), + "memory", &error_abort); + object_property_set_bool(OBJECT(&mms->armv7m), true, "realized", + &error_fatal); + + create_unimplemented_device("zbtsmram mirror", 0x00400000, 0x00400000); + create_unimplemented_device("RESERVED 1", 0x00800000, 0x00800000); + create_unimplemented_device("Block RAM", 0x01000000, 0x00010000); + create_unimplemented_device("RESERVED 2", 0x01010000, 0x1EFF0000); + create_unimplemented_device("RESERVED 3", 0x20800000, 0x00800000); + create_unimplemented_device("PSRAM", 0x21000000, 0x01000000); + /* These three ranges all cover multiple devices; we may implement + * some of them below (in which case the real device takes precedence + * over the unimplemented-region mapping). + */ + create_unimplemented_device("CMSDK APB peripheral region @0x40000000", + 0x40000000, 0x00010000); + create_unimplemented_device("CMSDK peripheral region @0x40010000", + 0x40010000, 0x00010000); + create_unimplemented_device("Extra peripheral region @0x40020000", + 0x40020000, 0x00010000); + create_unimplemented_device("RESERVED 4", 0x40030000, 0x001D0000); + create_unimplemented_device("Ethernet", 0x40200000, 0x00100000); + create_unimplemented_device("VGA", 0x41000000, 0x0200000); + + system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; + + armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, + 0x400000); +} + +static void mps2_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc = MACHINE_CLASS(oc); + + mc->init = mps2_common_init; + mc->max_cpus = 1; +} + +static void mps2_an385_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc = MACHINE_CLASS(oc); + MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc); + + mc->desc = "ARM MPS2 with AN385 FPGA image for Cortex-M3"; + mmc->fpga_type = FPGA_AN385; + mmc->cpu_model = "cortex-m3"; +} + +static void mps2_an511_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc = MACHINE_CLASS(oc); + MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc); + + mc->desc = "ARM MPS2 with AN511 DesignStart FPGA image for Cortex-M3"; + mmc->fpga_type = FPGA_AN511; + mmc->cpu_model = "cortex-m3"; +} + +static const TypeInfo mps2_info = { + .name = TYPE_MPS2_MACHINE, + .parent = TYPE_MACHINE, + .abstract = true, + .instance_size = sizeof(MPS2MachineState), + .class_size = sizeof(MPS2MachineClass), + .class_init = mps2_class_init, +}; + +static const TypeInfo mps2_an385_info = { + .name = TYPE_MPS2_AN385_MACHINE, + .parent = TYPE_MPS2_MACHINE, + .class_init = mps2_an385_class_init, +}; + +static const TypeInfo mps2_an511_info = { + .name = TYPE_MPS2_AN511_MACHINE, + .parent = TYPE_MPS2_MACHINE, + .class_init = mps2_an511_class_init, +}; + +static void mps2_machine_init(void) +{ + type_register_static(&mps2_info); + type_register_static(&mps2_an385_info); + type_register_static(&mps2_an511_info); +} + +type_init(mps2_machine_init); diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index 93e995d..bfd2a88 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -83,6 +83,7 @@ CONFIG_ONENAND=y CONFIG_TUSB6010=y CONFIG_IMX=y CONFIG_MAINSTONE=y +CONFIG_MPS2=y CONFIG_NSERIES=y CONFIG_RASPI=y CONFIG_REALVIEW=y From patchwork Mon Jul 17 12:44:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107930 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4478811qge; Mon, 17 Jul 2017 05:57:08 -0700 (PDT) X-Received: by 10.55.164.209 with SMTP id n200mr25614674qke.159.1500296228400; Mon, 17 Jul 2017 05:57:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500296228; cv=none; d=google.com; s=arc-20160816; b=Hu5Ib9/OmZ6u7alsENNwzkFjhQgb9Aq8CGyMFqTwbhOgN70R3kCQrmzrtrwg3vwM52 Afw1xs4/sHLFE/WzDa7S/+DZoBAeXaBoXj9WJHVQcSHjEbn/AerS9VXB2qwKYjyr1uO6 aLYMHUOATYR2AVCGaOXCRkq6DXduvU/aMDHHneolvw9JrxUT6Ga7ftrziTpRu9241fbg nB8YvCH9cO+kPKKFKySAG1tQ1jHx6ZfSXBod3XZ2NqF/2iX9QLGDOBkovayMSELEXXAx s32LjWKqE4rCR0AabqoAM0hTyE2t4LboZcwN09HA8PJP6721VG9ZoxVRDs4ArzmTYR7i vKgg== 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:arc-authentication-results; bh=BShHKPFzaL7VqmY+wssF9Qc/Sqm0HDbDZ0WlU/GEEJ0=; b=Uo0+f+WigThHsf0QPJJax1pLh7pd9+NyyYIvUsnxqkSgqDQPSAFae6uhKYjN8dP/iY owwdVQFCnN0TASQbLXx8Zf8pSSdpyFAZ5sm4Taw+LKSeubP6cGSrmNH+tj7nN2ikX6Qp hrRdteMJ2j4MIn9jRLIuI2oUjXVQas3McgxbjQ9NUQKZU/FVCrhMhA1W+hC69OfYPQLi MwxgrcYqDR04gjKts+ARNuUwkHsdYy3CKD6wz7o1JdsgWzYOgZyavyjghR3arT0fHala PxuWcH206HG09fy84GNj0lrPoFZhO0iO+tWagUlFfCfYuDa1Sql4twCLlkAQNUeUQHOC p4fQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q72si15000561qkl.261.2017.07.17.05.57.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:57:08 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5aD-0001B0-Ik for patch@linaro.org; Mon, 17 Jul 2017 08:57:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Of-0007vF-Li for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Od-0002FZ-9a for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:09 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37640) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Oc-0002Ci-U8 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:07 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OW-0003V8-L9 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:45:00 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:47 +0100 Message-Id: <1500295494-8991-12-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 11/18] hw/char/cmsdk-apb-uart.c: Implement CMSDK APB UART 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" Implement a model of the simple "APB UART" provided in the Cortex-M System Design Kit (CMSDK). Signed-off-by: Peter Maydell Message-id: 1500029487-14822-3-git-send-email-peter.maydell@linaro.org Reviewed-by: Alex Bennée --- hw/char/Makefile.objs | 1 + include/hw/char/cmsdk-apb-uart.h | 78 ++++++++ hw/char/cmsdk-apb-uart.c | 403 +++++++++++++++++++++++++++++++++++++++ default-configs/arm-softmmu.mak | 2 + hw/char/trace-events | 9 + 5 files changed, 493 insertions(+) create mode 100644 include/hw/char/cmsdk-apb-uart.h create mode 100644 hw/char/cmsdk-apb-uart.c -- 2.7.4 diff --git a/hw/char/Makefile.objs b/hw/char/Makefile.objs index 55fcb68..1bcd37e 100644 --- a/hw/char/Makefile.objs +++ b/hw/char/Makefile.objs @@ -19,6 +19,7 @@ obj-$(CONFIG_DIGIC) += digic-uart.o obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o obj-$(CONFIG_RASPI) += bcm2835_aux.o +common-obj-$(CONFIG_CMSDK_APB_UART) += cmsdk-apb-uart.o common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o common-obj-$(CONFIG_ISA_DEBUG) += debugcon.o common-obj-$(CONFIG_GRLIB) += grlib_apbuart.o diff --git a/include/hw/char/cmsdk-apb-uart.h b/include/hw/char/cmsdk-apb-uart.h new file mode 100644 index 0000000..c41fba9 --- /dev/null +++ b/include/hw/char/cmsdk-apb-uart.h @@ -0,0 +1,78 @@ +/* + * ARM CMSDK APB UART emulation + * + * Copyright (c) 2017 Linaro Limited + * Written by Peter Maydell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or + * (at your option) any later version. + */ + +#ifndef CMSDK_APB_UART_H +#define CMSDK_APB_UART_H + +#include "hw/sysbus.h" +#include "chardev/char-fe.h" + +#define TYPE_CMSDK_APB_UART "cmsdk-apb-uart" +#define CMSDK_APB_UART(obj) OBJECT_CHECK(CMSDKAPBUART, (obj), \ + TYPE_CMSDK_APB_UART) + +typedef struct { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + MemoryRegion iomem; + CharBackend chr; + qemu_irq txint; + qemu_irq rxint; + qemu_irq txovrint; + qemu_irq rxovrint; + qemu_irq uartint; + guint watch_tag; + uint32_t pclk_frq; + + uint32_t state; + uint32_t ctrl; + uint32_t intstatus; + uint32_t bauddiv; + /* This UART has no FIFO, only a 1-character buffer for each of Tx and Rx */ + uint8_t txbuf; + uint8_t rxbuf; +} CMSDKAPBUART; + +/** + * cmsdk_apb_uart_create - convenience function to create TYPE_CMSDK_APB_UART + * @addr: location in system memory to map registers + * @chr: Chardev backend to connect UART to, or NULL if no backend + * @pclk_frq: frequency in Hz of the PCLK clock (used for calculating baud rate) + */ +static inline DeviceState *cmsdk_apb_uart_create(hwaddr addr, + qemu_irq txint, + qemu_irq rxint, + qemu_irq txovrint, + qemu_irq rxovrint, + qemu_irq uartint, + Chardev *chr, + uint32_t pclk_frq) +{ + DeviceState *dev; + SysBusDevice *s; + + dev = qdev_create(NULL, TYPE_CMSDK_APB_UART); + s = SYS_BUS_DEVICE(dev); + qdev_prop_set_chr(dev, "chardev", chr); + qdev_prop_set_uint32(dev, "pclk-frq", pclk_frq); + qdev_init_nofail(dev); + sysbus_mmio_map(s, 0, addr); + sysbus_connect_irq(s, 0, txint); + sysbus_connect_irq(s, 1, rxint); + sysbus_connect_irq(s, 2, txovrint); + sysbus_connect_irq(s, 3, rxovrint); + sysbus_connect_irq(s, 4, uartint); + return dev; +} + +#endif diff --git a/hw/char/cmsdk-apb-uart.c b/hw/char/cmsdk-apb-uart.c new file mode 100644 index 0000000..ab34729 --- /dev/null +++ b/hw/char/cmsdk-apb-uart.c @@ -0,0 +1,403 @@ +/* + * ARM CMSDK APB UART emulation + * + * Copyright (c) 2017 Linaro Limited + * Written by Peter Maydell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or + * (at your option) any later version. + */ + +/* This is a model of the "APB UART" which is part of the Cortex-M + * System Design Kit (CMSDK) and documented in the Cortex-M System + * Design Kit Technical Reference Manual (ARM DDI0479C): + * https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "trace.h" +#include "hw/sysbus.h" +#include "hw/registerfields.h" +#include "chardev/char-fe.h" +#include "chardev/char-serial.h" +#include "hw/char/cmsdk-apb-uart.h" + +REG32(DATA, 0) +REG32(STATE, 4) + FIELD(STATE, TXFULL, 0, 1) + FIELD(STATE, RXFULL, 1, 1) + FIELD(STATE, TXOVERRUN, 2, 1) + FIELD(STATE, RXOVERRUN, 3, 1) +REG32(CTRL, 8) + FIELD(CTRL, TX_EN, 0, 1) + FIELD(CTRL, RX_EN, 1, 1) + FIELD(CTRL, TX_INTEN, 2, 1) + FIELD(CTRL, RX_INTEN, 3, 1) + FIELD(CTRL, TXO_INTEN, 4, 1) + FIELD(CTRL, RXO_INTEN, 5, 1) + FIELD(CTRL, HSTEST, 6, 1) +REG32(INTSTATUS, 0xc) + FIELD(INTSTATUS, TX, 0, 1) + FIELD(INTSTATUS, RX, 1, 1) + FIELD(INTSTATUS, TXO, 2, 1) + FIELD(INTSTATUS, RXO, 3, 1) +REG32(BAUDDIV, 0x10) +REG32(PID4, 0xFD0) +REG32(PID5, 0xFD4) +REG32(PID6, 0xFD8) +REG32(PID7, 0xFDC) +REG32(PID0, 0xFE0) +REG32(PID1, 0xFE4) +REG32(PID2, 0xFE8) +REG32(PID3, 0xFEC) +REG32(CID0, 0xFF0) +REG32(CID1, 0xFF4) +REG32(CID2, 0xFF8) +REG32(CID3, 0xFFC) + +/* PID/CID values */ +static const int uart_id[] = { + 0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */ + 0x21, 0xb8, 0x1b, 0x00, /* PID0..PID3 */ + 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */ +}; + +static bool uart_baudrate_ok(CMSDKAPBUART *s) +{ + /* The minimum permitted bauddiv setting is 16, so we just ignore + * settings below that (usually this means the device has just + * been reset and not yet programmed). + */ + return s->bauddiv >= 16 && s->bauddiv <= s->pclk_frq; +} + +static void uart_update_parameters(CMSDKAPBUART *s) +{ + QEMUSerialSetParams ssp; + + /* This UART is always 8N1 but the baud rate is programmable. */ + if (!uart_baudrate_ok(s)) { + return; + } + + ssp.data_bits = 8; + ssp.parity = 'N'; + ssp.stop_bits = 1; + ssp.speed = s->pclk_frq / s->bauddiv; + qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp); + trace_cmsdk_apb_uart_set_params(ssp.speed); +} + +static void cmsdk_apb_uart_update(CMSDKAPBUART *s) +{ + /* update outbound irqs, including handling the way the rxo and txo + * interrupt status bits are just logical AND of the overrun bit in + * STATE and the overrun interrupt enable bit in CTRL. + */ + uint32_t omask = (R_INTSTATUS_RXO_MASK | R_INTSTATUS_TXO_MASK); + s->intstatus &= ~omask; + s->intstatus |= (s->state & (s->ctrl >> 2) & omask); + + qemu_set_irq(s->txint, !!(s->intstatus & R_INTSTATUS_TX_MASK)); + qemu_set_irq(s->rxint, !!(s->intstatus & R_INTSTATUS_RX_MASK)); + qemu_set_irq(s->txovrint, !!(s->intstatus & R_INTSTATUS_TXO_MASK)); + qemu_set_irq(s->rxovrint, !!(s->intstatus & R_INTSTATUS_RXO_MASK)); + qemu_set_irq(s->uartint, !!(s->intstatus)); +} + +static int uart_can_receive(void *opaque) +{ + CMSDKAPBUART *s = CMSDK_APB_UART(opaque); + + /* We can take a char if RX is enabled and the buffer is empty */ + if (s->ctrl & R_CTRL_RX_EN_MASK && !(s->state & R_STATE_RXFULL_MASK)) { + return 1; + } + return 0; +} + +static void uart_receive(void *opaque, const uint8_t *buf, int size) +{ + CMSDKAPBUART *s = CMSDK_APB_UART(opaque); + + trace_cmsdk_apb_uart_receive(*buf); + + /* In fact uart_can_receive() ensures that we can't be + * called unless RX is enabled and the buffer is empty, + * but we include this logic as documentation of what the + * hardware does if a character arrives in these circumstances. + */ + if (!(s->ctrl & R_CTRL_RX_EN_MASK)) { + /* Just drop the character on the floor */ + return; + } + + if (s->state & R_STATE_RXFULL_MASK) { + s->state |= R_STATE_RXOVERRUN_MASK; + } + + s->rxbuf = *buf; + s->state |= R_STATE_RXFULL_MASK; + if (s->ctrl & R_CTRL_RX_INTEN_MASK) { + s->intstatus |= R_INTSTATUS_RX_MASK; + } + cmsdk_apb_uart_update(s); +} + +static uint64_t uart_read(void *opaque, hwaddr offset, unsigned size) +{ + CMSDKAPBUART *s = CMSDK_APB_UART(opaque); + uint64_t r; + + switch (offset) { + case A_DATA: + r = s->rxbuf; + s->state &= ~R_STATE_RXFULL_MASK; + cmsdk_apb_uart_update(s); + break; + case A_STATE: + r = s->state; + break; + case A_CTRL: + r = s->ctrl; + break; + case A_INTSTATUS: + r = s->intstatus; + break; + case A_BAUDDIV: + r = s->bauddiv; + break; + case A_PID4 ... A_CID3: + r = uart_id[(offset - A_PID4) / 4]; + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "CMSDK APB UART read: bad offset %x\n", (int) offset); + r = 0; + break; + } + trace_cmsdk_apb_uart_read(offset, r, size); + return r; +} + +/* Try to send tx data, and arrange to be called back later if + * we can't (ie the char backend is busy/blocking). + */ +static gboolean uart_transmit(GIOChannel *chan, GIOCondition cond, void *opaque) +{ + CMSDKAPBUART *s = CMSDK_APB_UART(opaque); + int ret; + + s->watch_tag = 0; + + if (!(s->ctrl & R_CTRL_TX_EN_MASK) || !(s->state & R_STATE_TXFULL_MASK)) { + return FALSE; + } + + ret = qemu_chr_fe_write(&s->chr, &s->txbuf, 1); + if (ret <= 0) { + s->watch_tag = qemu_chr_fe_add_watch(&s->chr, G_IO_OUT | G_IO_HUP, + uart_transmit, s); + if (!s->watch_tag) { + /* Most common reason to be here is "no chardev backend": + * just insta-drain the buffer, so the serial output + * goes into a void, rather than blocking the guest. + */ + goto buffer_drained; + } + /* Transmit pending */ + trace_cmsdk_apb_uart_tx_pending(); + return FALSE; + } + +buffer_drained: + /* Character successfully sent */ + trace_cmsdk_apb_uart_tx(s->txbuf); + s->state &= ~R_STATE_TXFULL_MASK; + /* Going from TXFULL set to clear triggers the tx interrupt */ + if (s->ctrl & R_CTRL_TX_INTEN_MASK) { + s->intstatus |= R_INTSTATUS_TX_MASK; + } + cmsdk_apb_uart_update(s); + return FALSE; +} + +static void uart_cancel_transmit(CMSDKAPBUART *s) +{ + if (s->watch_tag) { + g_source_remove(s->watch_tag); + s->watch_tag = 0; + } +} + +static void uart_write(void *opaque, hwaddr offset, uint64_t value, + unsigned size) +{ + CMSDKAPBUART *s = CMSDK_APB_UART(opaque); + + trace_cmsdk_apb_uart_write(offset, value, size); + + switch (offset) { + case A_DATA: + s->txbuf = value; + if (s->state & R_STATE_TXFULL_MASK) { + /* Buffer already full -- note the overrun and let the + * existing pending transmit callback handle the new char. + */ + s->state |= R_STATE_TXOVERRUN_MASK; + cmsdk_apb_uart_update(s); + } else { + s->state |= R_STATE_TXFULL_MASK; + uart_transmit(NULL, G_IO_OUT, s); + } + break; + case A_STATE: + /* Bits 0 and 1 are read only; bits 2 and 3 are W1C */ + s->state &= ~(value & + (R_STATE_TXOVERRUN_MASK | R_STATE_RXOVERRUN_MASK)); + cmsdk_apb_uart_update(s); + break; + case A_CTRL: + s->ctrl = value & 0x7f; + if ((s->ctrl & R_CTRL_TX_EN_MASK) && !uart_baudrate_ok(s)) { + qemu_log_mask(LOG_GUEST_ERROR, + "CMSDK APB UART: Tx enabled with invalid baudrate\n"); + } + cmsdk_apb_uart_update(s); + break; + case A_INTSTATUS: + /* All bits are W1C. Clearing the overrun interrupt bits really + * clears the overrun status bits in the STATE register (which + * is then reflected into the intstatus value by the update function). + */ + s->state &= ~(value & (R_INTSTATUS_TXO_MASK | R_INTSTATUS_RXO_MASK)); + cmsdk_apb_uart_update(s); + break; + case A_BAUDDIV: + s->bauddiv = value & 0xFFFFF; + uart_update_parameters(s); + break; + case A_PID4 ... A_CID3: + qemu_log_mask(LOG_GUEST_ERROR, + "CMSDK APB UART write: write to RO offset 0x%x\n", + (int)offset); + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "CMSDK APB UART write: bad offset 0x%x\n", (int) offset); + break; + } +} + +static const MemoryRegionOps uart_ops = { + .read = uart_read, + .write = uart_write, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + +static void cmsdk_apb_uart_reset(DeviceState *dev) +{ + CMSDKAPBUART *s = CMSDK_APB_UART(dev); + + trace_cmsdk_apb_uart_reset(); + uart_cancel_transmit(s); + s->state = 0; + s->ctrl = 0; + s->intstatus = 0; + s->bauddiv = 0; + s->txbuf = 0; + s->rxbuf = 0; +} + +static void cmsdk_apb_uart_init(Object *obj) +{ + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + CMSDKAPBUART *s = CMSDK_APB_UART(obj); + + memory_region_init_io(&s->iomem, obj, &uart_ops, s, "uart", 0x1000); + sysbus_init_mmio(sbd, &s->iomem); + sysbus_init_irq(sbd, &s->txint); + sysbus_init_irq(sbd, &s->rxint); + sysbus_init_irq(sbd, &s->txovrint); + sysbus_init_irq(sbd, &s->rxovrint); + sysbus_init_irq(sbd, &s->uartint); +} + +static void cmsdk_apb_uart_realize(DeviceState *dev, Error **errp) +{ + CMSDKAPBUART *s = CMSDK_APB_UART(dev); + + if (s->pclk_frq == 0) { + error_setg(errp, "CMSDK APB UART: pclk-frq property must be set"); + return; + } + + /* This UART has no flow control, so we do not need to register + * an event handler to deal with CHR_EVENT_BREAK. + */ + qemu_chr_fe_set_handlers(&s->chr, uart_can_receive, uart_receive, + NULL, s, NULL, true); +} + +static int cmsdk_apb_uart_post_load(void *opaque, int version_id) +{ + CMSDKAPBUART *s = CMSDK_APB_UART(opaque); + + /* If we have a pending character, arrange to resend it. */ + if (s->state & R_STATE_TXFULL_MASK) { + s->watch_tag = qemu_chr_fe_add_watch(&s->chr, G_IO_OUT | G_IO_HUP, + uart_transmit, s); + } + uart_update_parameters(s); + return 0; +} + +static const VMStateDescription cmsdk_apb_uart_vmstate = { + .name = "cmsdk-apb-uart", + .version_id = 1, + .minimum_version_id = 1, + .post_load = cmsdk_apb_uart_post_load, + .fields = (VMStateField[]) { + VMSTATE_UINT32(state, CMSDKAPBUART), + VMSTATE_UINT32(ctrl, CMSDKAPBUART), + VMSTATE_UINT32(intstatus, CMSDKAPBUART), + VMSTATE_UINT32(bauddiv, CMSDKAPBUART), + VMSTATE_UINT8(txbuf, CMSDKAPBUART), + VMSTATE_UINT8(rxbuf, CMSDKAPBUART), + VMSTATE_END_OF_LIST() + } +}; + +static Property cmsdk_apb_uart_properties[] = { + DEFINE_PROP_CHR("chardev", CMSDKAPBUART, chr), + DEFINE_PROP_UINT32("pclk-frq", CMSDKAPBUART, pclk_frq, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static void cmsdk_apb_uart_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->realize = cmsdk_apb_uart_realize; + dc->vmsd = &cmsdk_apb_uart_vmstate; + dc->reset = cmsdk_apb_uart_reset; + dc->props = cmsdk_apb_uart_properties; +} + +static const TypeInfo cmsdk_apb_uart_info = { + .name = TYPE_CMSDK_APB_UART, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(CMSDKAPBUART), + .instance_init = cmsdk_apb_uart_init, + .class_init = cmsdk_apb_uart_class_init, +}; + +static void cmsdk_apb_uart_register_types(void) +{ + type_register_static(&cmsdk_apb_uart_info); +} + +type_init(cmsdk_apb_uart_register_types); diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index bfd2a88..d128e9d 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -96,6 +96,8 @@ CONFIG_STM32F2XX_ADC=y CONFIG_STM32F2XX_SPI=y CONFIG_STM32F205_SOC=y +CONFIG_CMSDK_APB_UART=y + CONFIG_VERSATILE_PCI=y CONFIG_VERSATILE_I2C=y diff --git a/hw/char/trace-events b/hw/char/trace-events index 7fd48bb..daf4ee4 100644 --- a/hw/char/trace-events +++ b/hw/char/trace-events @@ -56,3 +56,12 @@ pl011_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR %08x read_count %d returning %d" pl011_put_fifo(uint32_t c, int read_count) "new char 0x%x read_count now %d" pl011_put_fifo_full(void) "FIFO now full, RXFF set" + +# hw/char/cmsdk_apb_uart.c +cmsdk_apb_uart_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB UART read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" +cmsdk_apb_uart_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB UART write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" +cmsdk_apb_uart_reset(void) "CMSDK APB UART: reset" +cmsdk_apb_uart_receive(uint8_t c) "CMSDK APB UART: got character 0x%x from backend" +cmsdk_apb_uart_tx_pending(void) "CMSDK APB UART: character send to backend pending" +cmsdk_apb_uart_tx(uint8_t c) "CMSDK APB UART: character 0x%x sent to backend" +cmsdk_apb_uart_set_params(int speed) "CMSDK APB UART: params set to %d 8N1" From patchwork Mon Jul 17 12:44:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107920 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4469361qge; Mon, 17 Jul 2017 05:48:11 -0700 (PDT) X-Received: by 10.55.100.206 with SMTP id y197mr10579019qkb.56.1500295691453; Mon, 17 Jul 2017 05:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500295691; cv=none; d=google.com; s=arc-20160816; b=dq2f6GMYHQIc+i2OETxWmxgq+/4zyMQ14on+dYYjyIDLADJzQIdoBguL6xLRLmLoiW vhLaUf7qnP/L8giLn2wtx03R/yaoZBz6NMYn0TehtA8x9X8WZI5qwfNO85q0kOJ9fQq8 bWhemiJeYGkTdA+gE3aToCXk4w6KgBKZRswnAa94z9Yf8sRUf2ewnG5yeHyTLhhOuHej THiqGLNHeIIVg9qGmng2KDM4Ehz6E+Km4yXdzRDI+KzD2UzM11YpdnzlMiqCPZ9Hqyt/ nEHthdvYq8qQLHxPRk6gGzvYAOEWSU4ksl7+wD0a9qU7RBhHFgAyURTeCsJsA8IW0hc4 LHZA== 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:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=Ja/tKJXXOPdC9OadYkBej9x5EqMES8F+BSkWuU9tDis=; b=TpgQm4ROpftgvxWOyrL6Ym/505ykEbzeCQMc/DG3lT+iBfSlLyhdVGvmJ5D5fAywjB Pakd2wHwz6Ul+Xpam2Jjif9Z29tzkfsHduvMjDQcriNcYgCOYRttflp/eSDHjoqoXf/j R4ikxuNpX2jrPBENZh34y/fQtNFaOZsxH+FX5kLkkxdAc5aROZNfA0+gHy7C0/YugV1K o+uHfbrlYt+mNViU4gu+tBSR+leLmOKQ9Hlv3JnEUlDyM5FBZAjgSdM5O9htXJlFY7D8 uRy5tIhX31qA5f50Q0aDZfRobc2KUlgkX5MZwQnP9JALFKtFPJLzNRZyDK3AePVFGeZt k15g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n30si944495qtf.153.2017.07.17.05.48.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:48:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5RY-0001gH-QR for patch@linaro.org; Mon, 17 Jul 2017 08:48:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Od-0007tJ-Pc for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Oc-0002Ef-NS for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:07 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Oc-00029H-Ew for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:06 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OX-0003VV-57 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:45:01 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:48 +0100 Message-Id: <1500295494-8991-13-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 12/18] hw/arm/mps2: Add UARTs 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" Add the UARTs to the MPS2 board models. Unfortunately the details of the wiring of the interrupts through various OR gates differ between AN511 and AN385 so this can't be purely a data-driven difference. Signed-off-by: Peter Maydell Reviewed-by: Alistair Francis Message-id: 1500029487-14822-4-git-send-email-peter.maydell@linaro.org --- hw/arm/mps2.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/char/cmsdk-apb-uart.c | 2 +- 2 files changed, 89 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c index 22b33ff..9c8fa77 100644 --- a/hw/arm/mps2.c +++ b/hw/arm/mps2.c @@ -27,9 +27,12 @@ #include "qemu/error-report.h" #include "hw/arm/arm.h" #include "hw/arm/armv7m.h" +#include "hw/or-irq.h" #include "hw/boards.h" #include "exec/address-spaces.h" +#include "sysemu/sysemu.h" #include "hw/misc/unimp.h" +#include "hw/char/cmsdk-apb-uart.h" typedef enum MPS2FPGAType { FPGA_AN385, @@ -205,6 +208,91 @@ static void mps2_common_init(MachineState *machine) create_unimplemented_device("Ethernet", 0x40200000, 0x00100000); create_unimplemented_device("VGA", 0x41000000, 0x0200000); + switch (mmc->fpga_type) { + case FPGA_AN385: + { + /* The overflow IRQs for UARTs 0, 1 and 2 are ORed together. + * Overflow for UARTs 4 and 5 doesn't trigger any interrupt. + */ + Object *orgate; + DeviceState *orgate_dev; + int i; + + orgate = object_new(TYPE_OR_IRQ); + object_property_set_int(orgate, 6, "num-lines", &error_fatal); + object_property_set_bool(orgate, true, "realized", &error_fatal); + orgate_dev = DEVICE(orgate); + qdev_connect_gpio_out(orgate_dev, 0, qdev_get_gpio_in(armv7m, 12)); + + for (i = 0; i < 5; i++) { + static const hwaddr uartbase[] = {0x40004000, 0x40005000, + 0x40006000, 0x40007000, + 0x40009000}; + Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL; + /* RX irq number; TX irq is always one greater */ + static const int uartirq[] = {0, 2, 4, 18, 20}; + qemu_irq txovrint = NULL, rxovrint = NULL; + + if (i < 3) { + txovrint = qdev_get_gpio_in(orgate_dev, i * 2); + rxovrint = qdev_get_gpio_in(orgate_dev, i * 2 + 1); + } + + cmsdk_apb_uart_create(uartbase[i], + qdev_get_gpio_in(armv7m, uartirq[i] + 1), + qdev_get_gpio_in(armv7m, uartirq[i]), + txovrint, rxovrint, + NULL, + uartchr, SYSCLK_FRQ); + } + break; + } + case FPGA_AN511: + { + /* The overflow IRQs for all UARTs are ORed together. + * Tx and Rx IRQs for each UART are ORed together. + */ + Object *orgate; + DeviceState *orgate_dev; + int i; + + orgate = object_new(TYPE_OR_IRQ); + object_property_set_int(orgate, 10, "num-lines", &error_fatal); + object_property_set_bool(orgate, true, "realized", &error_fatal); + orgate_dev = DEVICE(orgate); + qdev_connect_gpio_out(orgate_dev, 0, qdev_get_gpio_in(armv7m, 12)); + + for (i = 0; i < 5; i++) { + /* system irq numbers for the combined tx/rx for each UART */ + static const int uart_txrx_irqno[] = {0, 2, 45, 46, 56}; + static const hwaddr uartbase[] = {0x40004000, 0x40005000, + 0x4002c000, 0x4002d000, + 0x4002e000}; + Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL; + Object *txrx_orgate; + DeviceState *txrx_orgate_dev; + + txrx_orgate = object_new(TYPE_OR_IRQ); + object_property_set_int(txrx_orgate, 2, "num-lines", &error_fatal); + object_property_set_bool(txrx_orgate, true, "realized", + &error_fatal); + txrx_orgate_dev = DEVICE(txrx_orgate); + qdev_connect_gpio_out(txrx_orgate_dev, 0, + qdev_get_gpio_in(armv7m, uart_txrx_irqno[i])); + cmsdk_apb_uart_create(uartbase[i], + qdev_get_gpio_in(txrx_orgate_dev, 0), + qdev_get_gpio_in(txrx_orgate_dev, 1), + qdev_get_gpio_in(orgate_dev, 0), + qdev_get_gpio_in(orgate_dev, 1), + NULL, + uartchr, SYSCLK_FRQ); + } + break; + } + default: + g_assert_not_reached(); + } + system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, diff --git a/hw/char/cmsdk-apb-uart.c b/hw/char/cmsdk-apb-uart.c index ab34729..1ad1e14 100644 --- a/hw/char/cmsdk-apb-uart.c +++ b/hw/char/cmsdk-apb-uart.c @@ -339,7 +339,7 @@ static void cmsdk_apb_uart_realize(DeviceState *dev, Error **errp) * an event handler to deal with CHR_EVENT_BREAK. */ qemu_chr_fe_set_handlers(&s->chr, uart_can_receive, uart_receive, - NULL, s, NULL, true); + NULL, NULL, s, NULL, true); } static int cmsdk_apb_uart_post_load(void *opaque, int version_id) From patchwork Mon Jul 17 12:44:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107927 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4475153qge; Mon, 17 Jul 2017 05:53:31 -0700 (PDT) X-Received: by 10.200.3.213 with SMTP id z21mr28222600qtg.185.1500296011198; Mon, 17 Jul 2017 05:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500296011; cv=none; d=google.com; s=arc-20160816; b=AjzBZKiJWnKDNcf+aP/I+Cyp2F4xo8bJrU+zKKhdVmYxZBye00swCpgALPIH/ldoFj 0KocXdBocRN6txAQAmhEloHlqnCj+rsBJo7jvkY7vLIlBPmrzzyifxBxySx025yna44U QT3AnEW0KSY3VXESJ+O/Js6BadqXKc4KDPCFVV/3ZHgMKyA5qhuexPCOJ+zhIE1zr9gg 8Ju76og7C+rZJK4GbpBcEsDHde+XXyqxMnkiKYE0R/kqxb924+Id5JsvGmjsCXxmoQqQ 7J7HDAJQscae7AotuMqkA2Z/FIcOfQEAhboXpfHEabil+zJXdXblezocfuAx2AFOBH1p 1/8w== 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:arc-authentication-results; bh=iIN/0m3XaUAFiHrRG6Aj68HJm2k2lNudJmuvdGFFWog=; b=ltvGEKkaK+olu4OchP+pkXWxjp0PUP39dHJlb3MvD4MAGjGYwWIPxQ53vCuQMJ2v/F 8qCKZF0rmEcIoCHBIFps0Hc6LeA7bEtBscABhUl7WsyXoRGqZmjThjs8yCt2DfgPRa/i RrB9lqgti+Yyicp65TMtPMmGBLUvOPS8PjnghtTrlO+Ftc+br+pdpiFH8oLql5WDG08n xP6ZJXjBcJ6rqgCtfHnuPXzJNh0wIClULUo1JWOBeacyOiAAgnM/K6oM42WeCcoZ0Isf 35SG9UaJFKv1W+tBalGQZeciCfvx7HR+4VkNFRmxIXLHuOlshgcf8uGXMguclY43oQo7 X+4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j1si14734667qkd.269.2017.07.17.05.53.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:53:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Wi-0006E8-IG for patch@linaro.org; Mon, 17 Jul 2017 08:53:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Oe-0007tY-0I for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Oc-0002E6-AH for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:08 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37640) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Oc-0002Ci-01 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:06 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OX-0003Vs-Jw for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:45:01 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:49 +0100 Message-Id: <1500295494-8991-14-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 13/18] hw/char/cmsdk-apb-timer: Implement CMSDK APB timer device 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" Implement a model of the simple timer device found in the CMSDK. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-id: 1500029487-14822-5-git-send-email-peter.maydell@linaro.org --- hw/timer/Makefile.objs | 1 + include/hw/timer/cmsdk-apb-timer.h | 59 +++++++++ hw/timer/cmsdk-apb-timer.c | 253 +++++++++++++++++++++++++++++++++++++ default-configs/arm-softmmu.mak | 1 + hw/timer/trace-events | 5 + 5 files changed, 319 insertions(+) create mode 100644 include/hw/timer/cmsdk-apb-timer.h create mode 100644 hw/timer/cmsdk-apb-timer.c -- 2.7.4 diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs index dd6f27e..15cce1c 100644 --- a/hw/timer/Makefile.objs +++ b/hw/timer/Makefile.objs @@ -41,3 +41,4 @@ common-obj-$(CONFIG_STM32F2XX_TIMER) += stm32f2xx_timer.o common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o +common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o diff --git a/include/hw/timer/cmsdk-apb-timer.h b/include/hw/timer/cmsdk-apb-timer.h new file mode 100644 index 0000000..f21686d --- /dev/null +++ b/include/hw/timer/cmsdk-apb-timer.h @@ -0,0 +1,59 @@ +/* + * ARM CMSDK APB timer emulation + * + * Copyright (c) 2017 Linaro Limited + * Written by Peter Maydell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or + * (at your option) any later version. + */ + +#ifndef CMSDK_APB_TIMER_H +#define CMSDK_APB_TIMER_H + +#include "hw/sysbus.h" +#include "hw/ptimer.h" + +#define TYPE_CMSDK_APB_TIMER "cmsdk-apb-timer" +#define CMSDK_APB_TIMER(obj) OBJECT_CHECK(CMSDKAPBTIMER, (obj), \ + TYPE_CMSDK_APB_TIMER) + +typedef struct { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + MemoryRegion iomem; + qemu_irq timerint; + uint32_t pclk_frq; + struct ptimer_state *timer; + + uint32_t ctrl; + uint32_t value; + uint32_t reload; + uint32_t intstatus; +} CMSDKAPBTIMER; + +/** + * cmsdk_apb_timer_create - convenience function to create TYPE_CMSDK_APB_TIMER + * @addr: location in system memory to map registers + * @pclk_frq: frequency in Hz of the PCLK clock (used for calculating baud rate) + */ +static inline DeviceState *cmsdk_apb_timer_create(hwaddr addr, + qemu_irq timerint, + uint32_t pclk_frq) +{ + DeviceState *dev; + SysBusDevice *s; + + dev = qdev_create(NULL, TYPE_CMSDK_APB_TIMER); + s = SYS_BUS_DEVICE(dev); + qdev_prop_set_uint32(dev, "pclk-frq", pclk_frq); + qdev_init_nofail(dev); + sysbus_mmio_map(s, 0, addr); + sysbus_connect_irq(s, 0, timerint); + return dev; +} + +#endif diff --git a/hw/timer/cmsdk-apb-timer.c b/hw/timer/cmsdk-apb-timer.c new file mode 100644 index 0000000..9878746 --- /dev/null +++ b/hw/timer/cmsdk-apb-timer.c @@ -0,0 +1,253 @@ +/* + * ARM CMSDK APB timer emulation + * + * Copyright (c) 2017 Linaro Limited + * Written by Peter Maydell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or + * (at your option) any later version. + */ + +/* This is a model of the "APB timer" which is part of the Cortex-M + * System Design Kit (CMSDK) and documented in the Cortex-M System + * Design Kit Technical Reference Manual (ARM DDI0479C): + * https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit + * + * The hardware has an EXTIN input wire, which can be configured + * by the guest to act either as a 'timer enable' (timer does not run + * when EXTIN is low), or as a 'timer clock' (timer runs at frequency + * of EXTIN clock, not PCLK frequency). We don't model this. + * + * The documentation is not very clear about the exact behaviour; + * we choose to implement that the interrupt is triggered when + * the counter goes from 1 to 0, that the counter then holds at 0 + * for one clock cycle before reloading from the RELOAD register, + * and that if the RELOAD register is 0 this does not cause an + * interrupt (as there is no further 1->0 transition). + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/main-loop.h" +#include "qapi/error.h" +#include "trace.h" +#include "hw/sysbus.h" +#include "hw/registerfields.h" +#include "hw/timer/cmsdk-apb-timer.h" + +REG32(CTRL, 0) + FIELD(CTRL, EN, 0, 1) + FIELD(CTRL, SELEXTEN, 1, 1) + FIELD(CTRL, SELEXTCLK, 2, 1) + FIELD(CTRL, IRQEN, 3, 1) +REG32(VALUE, 4) +REG32(RELOAD, 8) +REG32(INTSTATUS, 0xc) + FIELD(INTSTATUS, IRQ, 0, 1) +REG32(PID4, 0xFD0) +REG32(PID5, 0xFD4) +REG32(PID6, 0xFD8) +REG32(PID7, 0xFDC) +REG32(PID0, 0xFE0) +REG32(PID1, 0xFE4) +REG32(PID2, 0xFE8) +REG32(PID3, 0xFEC) +REG32(CID0, 0xFF0) +REG32(CID1, 0xFF4) +REG32(CID2, 0xFF8) +REG32(CID3, 0xFFC) + +/* PID/CID values */ +static const int timer_id[] = { + 0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */ + 0x22, 0xb8, 0x1b, 0x00, /* PID0..PID3 */ + 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */ +}; + +static void cmsdk_apb_timer_update(CMSDKAPBTIMER *s) +{ + qemu_set_irq(s->timerint, !!(s->intstatus & R_INTSTATUS_IRQ_MASK)); +} + +static uint64_t cmsdk_apb_timer_read(void *opaque, hwaddr offset, unsigned size) +{ + CMSDKAPBTIMER *s = CMSDK_APB_TIMER(opaque); + uint64_t r; + + switch (offset) { + case A_CTRL: + r = s->ctrl; + break; + case A_VALUE: + r = ptimer_get_count(s->timer); + break; + case A_RELOAD: + r = ptimer_get_limit(s->timer); + break; + case A_INTSTATUS: + r = s->intstatus; + break; + case A_PID4 ... A_CID3: + r = timer_id[(offset - A_PID4) / 4]; + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "CMSDK APB timer read: bad offset %x\n", (int) offset); + r = 0; + break; + } + trace_cmsdk_apb_timer_read(offset, r, size); + return r; +} + +static void cmsdk_apb_timer_write(void *opaque, hwaddr offset, uint64_t value, + unsigned size) +{ + CMSDKAPBTIMER *s = CMSDK_APB_TIMER(opaque); + + trace_cmsdk_apb_timer_write(offset, value, size); + + switch (offset) { + case A_CTRL: + if (value & 6) { + /* Bits [1] and [2] enable using EXTIN as either clock or + * an enable line. We don't model this. + */ + qemu_log_mask(LOG_UNIMP, + "CMSDK APB timer: EXTIN input not supported\n"); + } + s->ctrl = value & 0xf; + if (s->ctrl & R_CTRL_EN_MASK) { + ptimer_run(s->timer, 0); + } else { + ptimer_stop(s->timer); + } + break; + case A_RELOAD: + /* Writing to reload also sets the current timer value */ + ptimer_set_limit(s->timer, value, 1); + break; + case A_VALUE: + ptimer_set_count(s->timer, value); + break; + case A_INTSTATUS: + /* Just one bit, which is W1C. */ + value &= 1; + s->intstatus &= ~value; + cmsdk_apb_timer_update(s); + break; + case A_PID4 ... A_CID3: + qemu_log_mask(LOG_GUEST_ERROR, + "CMSDK APB timer write: write to RO offset 0x%x\n", + (int)offset); + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "CMSDK APB timer write: bad offset 0x%x\n", (int) offset); + break; + } +} + +static const MemoryRegionOps cmsdk_apb_timer_ops = { + .read = cmsdk_apb_timer_read, + .write = cmsdk_apb_timer_write, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + +static void cmsdk_apb_timer_tick(void *opaque) +{ + CMSDKAPBTIMER *s = CMSDK_APB_TIMER(opaque); + + if (s->ctrl & R_CTRL_IRQEN_MASK) { + s->intstatus |= R_INTSTATUS_IRQ_MASK; + cmsdk_apb_timer_update(s); + } +} + +static void cmsdk_apb_timer_reset(DeviceState *dev) +{ + CMSDKAPBTIMER *s = CMSDK_APB_TIMER(dev); + + trace_cmsdk_apb_timer_reset(); + s->ctrl = 0; + s->intstatus = 0; + ptimer_stop(s->timer); + /* Set the limit and the count */ + ptimer_set_limit(s->timer, 0, 1); +} + +static void cmsdk_apb_timer_init(Object *obj) +{ + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + CMSDKAPBTIMER *s = CMSDK_APB_TIMER(obj); + + memory_region_init_io(&s->iomem, obj, &cmsdk_apb_timer_ops, + s, "cmsdk-apb-timer", 0x1000); + sysbus_init_mmio(sbd, &s->iomem); + sysbus_init_irq(sbd, &s->timerint); +} + +static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp) +{ + CMSDKAPBTIMER *s = CMSDK_APB_TIMER(dev); + QEMUBH *bh; + + if (s->pclk_frq == 0) { + error_setg(errp, "CMSDK APB timer: pclk-frq property must be set"); + return; + } + + bh = qemu_bh_new(cmsdk_apb_timer_tick, s); + s->timer = ptimer_init(bh, + PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD | + PTIMER_POLICY_NO_IMMEDIATE_TRIGGER | + PTIMER_POLICY_NO_IMMEDIATE_RELOAD | + PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); + + ptimer_set_freq(s->timer, s->pclk_frq); +} + +static const VMStateDescription cmsdk_apb_timer_vmstate = { + .name = "cmsdk-apb-timer", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_PTIMER(timer, CMSDKAPBTIMER), + VMSTATE_UINT32(ctrl, CMSDKAPBTIMER), + VMSTATE_UINT32(value, CMSDKAPBTIMER), + VMSTATE_UINT32(reload, CMSDKAPBTIMER), + VMSTATE_UINT32(intstatus, CMSDKAPBTIMER), + VMSTATE_END_OF_LIST() + } +}; + +static Property cmsdk_apb_timer_properties[] = { + DEFINE_PROP_UINT32("pclk-frq", CMSDKAPBTIMER, pclk_frq, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static void cmsdk_apb_timer_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->realize = cmsdk_apb_timer_realize; + dc->vmsd = &cmsdk_apb_timer_vmstate; + dc->reset = cmsdk_apb_timer_reset; + dc->props = cmsdk_apb_timer_properties; +} + +static const TypeInfo cmsdk_apb_timer_info = { + .name = TYPE_CMSDK_APB_TIMER, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(CMSDKAPBTIMER), + .instance_init = cmsdk_apb_timer_init, + .class_init = cmsdk_apb_timer_class_init, +}; + +static void cmsdk_apb_timer_register_types(void) +{ + type_register_static(&cmsdk_apb_timer_info); +} + +type_init(cmsdk_apb_timer_register_types); diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index d128e9d..c75f52c 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -96,6 +96,7 @@ CONFIG_STM32F2XX_ADC=y CONFIG_STM32F2XX_SPI=y CONFIG_STM32F205_SOC=y +CONFIG_CMSDK_APB_TIMER=y CONFIG_CMSDK_APB_UART=y CONFIG_VERSATILE_PCI=y diff --git a/hw/timer/trace-events b/hw/timer/trace-events index d17cfe6..fd8196b 100644 --- a/hw/timer/trace-events +++ b/hw/timer/trace-events @@ -55,3 +55,8 @@ systick_reload(void) "systick reload" systick_timer_tick(void) "systick reload" systick_read(uint64_t addr, uint32_t value, unsigned size) "systick read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u" systick_write(uint64_t addr, uint32_t value, unsigned size) "systick write addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u" + +# hw/char/cmsdk_apb_timer.c +cmsdk_apb_timer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" +cmsdk_apb_timer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" +cmsdk_apb_timer_reset(void) "CMSDK APB timer: reset" From patchwork Mon Jul 17 12:44:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107917 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4468316qge; Mon, 17 Jul 2017 05:47:08 -0700 (PDT) X-Received: by 10.233.223.68 with SMTP id t65mr9215194qkf.122.1500295628933; Mon, 17 Jul 2017 05:47:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500295628; cv=none; d=google.com; s=arc-20160816; b=p+BQLHYZhRPVsD2Sl3d7WK3R5bGvrKxdI/V5u88wGJSZTaed1/Q2K1KivN1YFScpLq ZIPYor6TY5UrhlO2zFpL8NpbbuSQwhQPsISBz6cipi9w2r7uSxhxOrRX9hueLIbOxBd0 fErvTAYsIqNqbA842c1dYRW/nFqEyyLYNkO81Q7ZiTp/94cCiuPtOpBGlPoiXHrBQ6oy t6gWiVyNZAXAU9Rhs8DPYFv7RK7/fY+u5njBIeOHCrF1mI9KMvuIkeif7cAM0AEnvUuy E1wT/fG3P/vQ7pxdiksVioPPmBFDwphFakkaBFHFIHVWmq8wYSAdX2/+svkbXpa3dSbq 8bIA== 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:arc-authentication-results; bh=QeN/CEdqQ2YbVZODZr5gJWyv8Fu0c+uATU0Yu8ql638=; b=j9XatZF163RRypFdOkMCsda1lZbocTg3j6zopBua+8DCgvtEmIBgXcVlwVMEceAUIp jc3ruQTTIiTxHIglCteLdlcB4XBSyYrFcvYJVJgA8PpCtAaH2pLmgJ06+lOH8lfsmIPk NzXy+GNMtI1bEagwtujYbbABBjDNn7B7LLunY6o8OmfRl1MT3lbJ4qjfyskytSbGQ1y5 yEcIxTT835s1guw4HhTpzJSr9GJni/6qE+6diRypWGgiCmJ5aUe3O7evx6Sk8s57cxwx Oe7KqI3mDMmbHTEFN1NVC+vZgz1SH8ENnBuWZKf+c5EEGb2SjNZ0rrnY21DgXeFGHTFG VwqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p3si15076946qkd.63.2017.07.17.05.47.08 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:47:08 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5QY-0000fk-CM for patch@linaro.org; Mon, 17 Jul 2017 08:47:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Oc-0007qy-GY for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Ob-0002Dt-OU for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:06 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Ob-00029H-Hs for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:05 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OY-0003WF-38 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:45:02 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:50 +0100 Message-Id: <1500295494-8991-15-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 14/18] hw/arm/mps2: Add timers 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" Add the CMSDK APB timers to the MPS2 board. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-id: 1500029487-14822-6-git-send-email-peter.maydell@linaro.org --- hw/arm/mps2.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.7.4 diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c index 9c8fa77..4121816 100644 --- a/hw/arm/mps2.c +++ b/hw/arm/mps2.c @@ -33,6 +33,7 @@ #include "sysemu/sysemu.h" #include "hw/misc/unimp.h" #include "hw/char/cmsdk-apb-uart.h" +#include "hw/timer/cmsdk-apb-timer.h" typedef enum MPS2FPGAType { FPGA_AN385, @@ -293,6 +294,9 @@ static void mps2_common_init(MachineState *machine) g_assert_not_reached(); } + cmsdk_apb_timer_create(0x40000000, qdev_get_gpio_in(armv7m, 8), SYSCLK_FRQ); + cmsdk_apb_timer_create(0x40001000, qdev_get_gpio_in(armv7m, 9), SYSCLK_FRQ); + system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, From patchwork Mon Jul 17 12:44:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107925 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4474238qge; Mon, 17 Jul 2017 05:52:37 -0700 (PDT) X-Received: by 10.233.235.3 with SMTP id b3mr27852668qkg.138.1500295957384; Mon, 17 Jul 2017 05:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500295957; cv=none; d=google.com; s=arc-20160816; b=oK8/piPpMS/QkJgoIwZ1IkTSmhnQ8MVrKYSpXu4t1tmF89m1rtWgyuxK/9uwa0Pp5l 2gWp0I0Ml+zZwctU79yE18xXGyDL3WBvMwhQT1Iy0Nbh9ODkeJi1Gr9kYFt0HF/wzivt JTo3i0SqyxBWIabN+bl2KOJWHNGfuc30eShO8J0T5K395Z+PNU5OoszDlixBojUXqNOP bbjLmXX49ONhoTdnLunyn4Gn91nXEdxsgZUAYfIRoQntiraXghIsoLfY8qqqmlFcu9EC DhiHDt6r4O14S7MoxyzcMMr40hGHMsNqi1j7MzYfaQ2q5cN1EmbF6jRBvSnZMGiEVIYz EuTQ== 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:arc-authentication-results; bh=K1tOYdtULeVZ7lPeUpkFkGfEULhRLCrj1GGSmLphjfg=; b=08YwvTpWxULFoPge2FUO2KiN0RSgDrz1thOux5NnNZD4gIoPWnfePv6kfyZicicG5l xCjMNC+WCW/LVkyDO1bqHqI98SIjX/xRu/vExbpMYFnx1Q1R5Ji/C78TCdjPu33UG+dP gKKCHtIPG8lsv6dN0tPs9L0jE312Pro4poOR8FbiNyvk1waz+NUjhuxSG6jprZFkWwi1 /eLlrPZkXp+BUcYjZN20X6++zX8D2lAZnOsZQD4Y3wwEoOZPJvdaklbqATg2fHuyutnK XU6b7932n+fXfWXL99gnn7/1QjpztbsJ3EHFp3possqsk/c1BUlGaf0FCHSqODioTb2D c4wA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 12si15392765qtf.152.2017.07.17.05.52.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:52:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50191 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Vq-00053h-Ip for patch@linaro.org; Mon, 17 Jul 2017 08:52:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Oc-0007rG-WD for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Oa-0002DL-Up for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:07 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Oa-00029H-Js for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:04 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OY-0003Wd-Hu for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:45:02 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:51 +0100 Message-Id: <1500295494-8991-16-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 15/18] hw/misc/mps2_scc: Implement MPS2 Serial Communication Controller 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" Implement a model of the Serial Communication Controller (SCC) found in MPS2 FPGA images. The primary purpose of this device is to communicate with the Motherboard Configuration Controller (MCC) which is located on the MPS board itself, outside the FPGA image. This is used for programming the MPS clock generators. The SCC also has some basic ID registers and an output for the board LEDs. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-id: 1500029487-14822-7-git-send-email-peter.maydell@linaro.org --- hw/misc/Makefile.objs | 1 + include/hw/misc/mps2-scc.h | 43 ++++++ hw/misc/mps2-scc.c | 310 ++++++++++++++++++++++++++++++++++++++++ default-configs/arm-softmmu.mak | 2 + hw/misc/trace-events | 8 ++ 5 files changed, 364 insertions(+) create mode 100644 include/hw/misc/mps2-scc.h create mode 100644 hw/misc/mps2-scc.c -- 2.7.4 diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index 7e373db..3b91d32 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -52,6 +52,7 @@ obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o obj-$(CONFIG_MIPS_CPS) += mips_cmgcr.o obj-$(CONFIG_MIPS_CPS) += mips_cpc.o obj-$(CONFIG_MIPS_ITU) += mips_itu.o +obj-$(CONFIG_MPS2_SCC) += mps2-scc.o obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o diff --git a/include/hw/misc/mps2-scc.h b/include/hw/misc/mps2-scc.h new file mode 100644 index 0000000..7045473 --- /dev/null +++ b/include/hw/misc/mps2-scc.h @@ -0,0 +1,43 @@ +/* + * ARM MPS2 SCC emulation + * + * Copyright (c) 2017 Linaro Limited + * Written by Peter Maydell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or + * (at your option) any later version. + */ + +#ifndef MPS2_SCC_H +#define MPS2_SCC_H + +#include "hw/sysbus.h" + +#define TYPE_MPS2_SCC "mps2-scc" +#define MPS2_SCC(obj) OBJECT_CHECK(MPS2SCC, (obj), TYPE_MPS2_SCC) + +#define NUM_OSCCLK 3 + +typedef struct { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + MemoryRegion iomem; + + uint32_t cfg0; + uint32_t cfg1; + uint32_t cfg4; + uint32_t cfgdata_rtn; + uint32_t cfgdata_out; + uint32_t cfgctrl; + uint32_t cfgstat; + uint32_t dll; + uint32_t aid; + uint32_t id; + uint32_t oscclk[NUM_OSCCLK]; + uint32_t oscclk_reset[NUM_OSCCLK]; +} MPS2SCC; + +#endif diff --git a/hw/misc/mps2-scc.c b/hw/misc/mps2-scc.c new file mode 100644 index 0000000..cc58d26 --- /dev/null +++ b/hw/misc/mps2-scc.c @@ -0,0 +1,310 @@ +/* + * ARM MPS2 SCC emulation + * + * Copyright (c) 2017 Linaro Limited + * Written by Peter Maydell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or + * (at your option) any later version. + */ + +/* This is a model of the SCC (Serial Communication Controller) + * found in the FPGA images of MPS2 development boards. + * + * Documentation of it can be found in the MPS2 TRM: + * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.100112_0100_03_en/index.html + * and also in the Application Notes documenting individual FPGA images. + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "trace.h" +#include "hw/sysbus.h" +#include "hw/registerfields.h" +#include "hw/misc/mps2-scc.h" + +REG32(CFG0, 0) +REG32(CFG1, 4) +REG32(CFG3, 0xc) +REG32(CFG4, 0x10) +REG32(CFGDATA_RTN, 0xa0) +REG32(CFGDATA_OUT, 0xa4) +REG32(CFGCTRL, 0xa8) + FIELD(CFGCTRL, DEVICE, 0, 12) + FIELD(CFGCTRL, RES1, 12, 8) + FIELD(CFGCTRL, FUNCTION, 20, 6) + FIELD(CFGCTRL, RES2, 26, 4) + FIELD(CFGCTRL, WRITE, 30, 1) + FIELD(CFGCTRL, START, 31, 1) +REG32(CFGSTAT, 0xac) + FIELD(CFGSTAT, DONE, 0, 1) + FIELD(CFGSTAT, ERROR, 1, 1) +REG32(DLL, 0x100) +REG32(AID, 0xFF8) +REG32(ID, 0xFFC) + +/* Handle a write via the SYS_CFG channel to the specified function/device. + * Return false on error (reported to guest via SYS_CFGCTRL ERROR bit). + */ +static bool scc_cfg_write(MPS2SCC *s, unsigned function, + unsigned device, uint32_t value) +{ + trace_mps2_scc_cfg_write(function, device, value); + + if (function != 1 || device >= NUM_OSCCLK) { + qemu_log_mask(LOG_GUEST_ERROR, + "MPS2 SCC config write: bad function %d device %d\n", + function, device); + return false; + } + + s->oscclk[device] = value; + return true; +} + +/* Handle a read via the SYS_CFG channel to the specified function/device. + * Return false on error (reported to guest via SYS_CFGCTRL ERROR bit), + * or set *value on success. + */ +static bool scc_cfg_read(MPS2SCC *s, unsigned function, + unsigned device, uint32_t *value) +{ + if (function != 1 || device >= NUM_OSCCLK) { + qemu_log_mask(LOG_GUEST_ERROR, + "MPS2 SCC config read: bad function %d device %d\n", + function, device); + return false; + } + + *value = s->oscclk[device]; + + trace_mps2_scc_cfg_read(function, device, *value); + return true; +} + +static uint64_t mps2_scc_read(void *opaque, hwaddr offset, unsigned size) +{ + MPS2SCC *s = MPS2_SCC(opaque); + uint64_t r; + + switch (offset) { + case A_CFG0: + r = s->cfg0; + break; + case A_CFG1: + r = s->cfg1; + break; + case A_CFG3: + /* These are user-settable DIP switches on the board. We don't + * model that, so just return zeroes. + */ + r = 0; + break; + case A_CFG4: + r = s->cfg4; + break; + case A_CFGDATA_RTN: + r = s->cfgdata_rtn; + break; + case A_CFGDATA_OUT: + r = s->cfgdata_out; + break; + case A_CFGCTRL: + r = s->cfgctrl; + break; + case A_CFGSTAT: + r = s->cfgstat; + break; + case A_DLL: + r = s->dll; + break; + case A_AID: + r = s->aid; + break; + case A_ID: + r = s->id; + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "MPS2 SCC read: bad offset %x\n", (int) offset); + r = 0; + break; + } + + trace_mps2_scc_read(offset, r, size); + return r; +} + +static void mps2_scc_write(void *opaque, hwaddr offset, uint64_t value, + unsigned size) +{ + MPS2SCC *s = MPS2_SCC(opaque); + + trace_mps2_scc_write(offset, value, size); + + switch (offset) { + case A_CFG0: + /* TODO on some boards bit 0 controls RAM remapping */ + s->cfg0 = value; + break; + case A_CFG1: + /* CFG1 bits [7:0] control the board LEDs. We don't currently have + * a mechanism for displaying this graphically, so use a trace event. + */ + trace_mps2_scc_leds(value & 0x80 ? '*' : '.', + value & 0x40 ? '*' : '.', + value & 0x20 ? '*' : '.', + value & 0x10 ? '*' : '.', + value & 0x08 ? '*' : '.', + value & 0x04 ? '*' : '.', + value & 0x02 ? '*' : '.', + value & 0x01 ? '*' : '.'); + s->cfg1 = value; + break; + case A_CFGDATA_OUT: + s->cfgdata_out = value; + break; + case A_CFGCTRL: + /* Writing to CFGCTRL clears SYS_CFGSTAT */ + s->cfgstat = 0; + s->cfgctrl = value & ~(R_CFGCTRL_RES1_MASK | + R_CFGCTRL_RES2_MASK | + R_CFGCTRL_START_MASK); + + if (value & R_CFGCTRL_START_MASK) { + /* Start bit set -- do a read or write (instantaneously) */ + int device = extract32(s->cfgctrl, R_CFGCTRL_DEVICE_SHIFT, + R_CFGCTRL_DEVICE_LENGTH); + int function = extract32(s->cfgctrl, R_CFGCTRL_FUNCTION_SHIFT, + R_CFGCTRL_FUNCTION_LENGTH); + + s->cfgstat = R_CFGSTAT_DONE_MASK; + if (s->cfgctrl & R_CFGCTRL_WRITE_MASK) { + if (!scc_cfg_write(s, function, device, s->cfgdata_out)) { + s->cfgstat |= R_CFGSTAT_ERROR_MASK; + } + } else { + uint32_t result; + if (!scc_cfg_read(s, function, device, &result)) { + s->cfgstat |= R_CFGSTAT_ERROR_MASK; + } else { + s->cfgdata_rtn = result; + } + } + } + break; + case A_DLL: + /* DLL stands for Digital Locked Loop. + * Bits [31:24] (DLL_LOCK_MASK) are writable, and indicate a + * mask of which of the DLL_LOCKED bits [16:23] should be ORed + * together to determine the ALL_UNMASKED_DLLS_LOCKED bit [0]. + * For QEMU, our DLLs are always locked, so we can leave bit 0 + * as 1 always and don't need to recalculate it. + */ + s->dll = deposit32(s->dll, 24, 8, extract32(value, 24, 8)); + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "MPS2 SCC write: bad offset 0x%x\n", (int) offset); + break; + } +} + +static const MemoryRegionOps mps2_scc_ops = { + .read = mps2_scc_read, + .write = mps2_scc_write, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + +static void mps2_scc_reset(DeviceState *dev) +{ + MPS2SCC *s = MPS2_SCC(dev); + int i; + + trace_mps2_scc_reset(); + s->cfg0 = 0; + s->cfg1 = 0; + s->cfgdata_rtn = 0; + s->cfgdata_out = 0; + s->cfgctrl = 0x100000; + s->cfgstat = 0; + s->dll = 0xffff0001; + for (i = 0; i < NUM_OSCCLK; i++) { + s->oscclk[i] = s->oscclk_reset[i]; + } +} + +static void mps2_scc_init(Object *obj) +{ + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + MPS2SCC *s = MPS2_SCC(obj); + + memory_region_init_io(&s->iomem, obj, &mps2_scc_ops, s, "mps2-scc", 0x1000); + sysbus_init_mmio(sbd, &s->iomem); +} + +static void mps2_scc_realize(DeviceState *dev, Error **errp) +{ +} + +static const VMStateDescription mps2_scc_vmstate = { + .name = "mps2-scc", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32(cfg0, MPS2SCC), + VMSTATE_UINT32(cfg1, MPS2SCC), + VMSTATE_UINT32(cfgdata_rtn, MPS2SCC), + VMSTATE_UINT32(cfgdata_out, MPS2SCC), + VMSTATE_UINT32(cfgctrl, MPS2SCC), + VMSTATE_UINT32(cfgstat, MPS2SCC), + VMSTATE_UINT32(dll, MPS2SCC), + VMSTATE_UINT32_ARRAY(oscclk, MPS2SCC, NUM_OSCCLK), + VMSTATE_END_OF_LIST() + } +}; + +static Property mps2_scc_properties[] = { + /* Values for various read-only ID registers (which are specific + * to the board model or FPGA image) + */ + DEFINE_PROP_UINT32("scc-cfg4", MPS2SCC, aid, 0), + DEFINE_PROP_UINT32("scc-aid", MPS2SCC, aid, 0), + DEFINE_PROP_UINT32("scc-id", MPS2SCC, aid, 0), + /* These are the initial settings for the source clocks on the board. + * In hardware they can be configured via a config file read by the + * motherboard configuration controller to suit the FPGA image. + * These default values are used by most of the standard FPGA images. + */ + DEFINE_PROP_UINT32("oscclk0", MPS2SCC, oscclk_reset[0], 50000000), + DEFINE_PROP_UINT32("oscclk1", MPS2SCC, oscclk_reset[1], 24576000), + DEFINE_PROP_UINT32("oscclk2", MPS2SCC, oscclk_reset[2], 25000000), + DEFINE_PROP_END_OF_LIST(), +}; + +static void mps2_scc_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->realize = mps2_scc_realize; + dc->vmsd = &mps2_scc_vmstate; + dc->reset = mps2_scc_reset; + dc->props = mps2_scc_properties; +} + +static const TypeInfo mps2_scc_info = { + .name = TYPE_MPS2_SCC, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(MPS2SCC), + .instance_init = mps2_scc_init, + .class_init = mps2_scc_class_init, +}; + +static void mps2_scc_register_types(void) +{ + type_register_static(&mps2_scc_info); +} + +type_init(mps2_scc_register_types); diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index c75f52c..bbdd3c1 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -99,6 +99,8 @@ CONFIG_STM32F205_SOC=y CONFIG_CMSDK_APB_TIMER=y CONFIG_CMSDK_APB_UART=y +CONFIG_MPS2_SCC=y + CONFIG_VERSATILE_PCI=y CONFIG_VERSATILE_I2C=y diff --git a/hw/misc/trace-events b/hw/misc/trace-events index 0cc556c..28b8cd1 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -53,3 +53,11 @@ milkymist_pfpu_pulse_irq(void) "Pulse IRQ" # hw/misc/aspeed_scu.c aspeed_scu_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 + +# hw/misc/mps2_scc.c +mps2_scc_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 SCC read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" +mps2_scc_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 SCC write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" +mps2_scc_reset(void) "MPS2 SCC: reset" +mps2_scc_leds(char led7, char led6, char led5, char led4, char led3, char led2, char led1, char led0) "MPS2 SCC LEDs: %c%c%c%c%c%c%c%c" +mps2_scc_cfg_write(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config write: function %d device %d data 0x%" PRIx32 +mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config read: function %d device %d data 0x%" PRIx32 From patchwork Mon Jul 17 12:44:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107916 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4468262qge; Mon, 17 Jul 2017 05:47:05 -0700 (PDT) X-Received: by 10.55.78.85 with SMTP id c82mr25854113qkb.154.1500295625937; Mon, 17 Jul 2017 05:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500295625; cv=none; d=google.com; s=arc-20160816; b=bkwV7/x+PPO5hQJpEt6BSNachmKOGC91+wjP7Znq+j8SeslsJzItmYsidI5k3DQTFa p1iIth+5O49h2tUhyEvX7rcj51dD59pG1iFp33lMM7qDa2dd6RxCDO0qf0IU9JSi896Y C4GOiCoT4P6htwPvkfmZSzjW0rIlOYDZbxzxjDxspmNWttfRpUeT19RCx++m3IW2Sh0p INtxWI+JimIjNBoF6AHqwV5FSyhnm8F6s9z7A6L+ZR8N2eSWsZ1IyARvBot8eZCW1ODn MqAhcy+IueyYlQcLo9U+6hp94fpIW7lRBEnUTAPushLipFjSYT0H+iBqIhaH4SYh1ouY POrg== 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:arc-authentication-results; bh=TkSFH3zjHQhbizyW1SaxfzJfGk3L+TR2sRcg05iiY7E=; b=QRT/0F9dOlGxCSfjk6hpF5KpTGuYIdwkurdmQZbhtN8JCx8Duo6LjBiiiNt9KpwXS4 pHKGEsQQxO9MV+tTwAdR7hRw7akz3svORRW5vgkCFUxBdrAq1055wf87gazNItWy2npk oXu4Mmcd3GMbWtrHy+lfA7xI/WuVsAfaGHqvWVJQYW5fh77LYyzZdwR3KY7UYXP3AVhH PDzp6zpZAHYKXX8uXF5w2rOuOgDl5X0GL8wc67y6rjCPoCW1Up63SkUPHyoCJG5Y7Lt5 e4YJz7FXBwcCDAvXU9qtMCPOFziuIBSTVpbRePF15sNWrhKVnbqVpyEaRRZMMiBRl3iF KIJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j6si15467532qti.143.2017.07.17.05.47.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:47:05 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5QV-0000db-Ck for patch@linaro.org; Mon, 17 Jul 2017 08:47:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Oa-0007qh-S9 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Oa-0002Ct-16 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:04 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5OZ-00029H-QG for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:03 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OY-0003X2-W7 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:45:03 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:52 +0100 Message-Id: <1500295494-8991-17-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 16/18] hw/arm/mps2: Add SCC 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" Add the SCC to the MPS2 board models. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-id: 1500029487-14822-8-git-send-email-peter.maydell@linaro.org --- hw/arm/mps2.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c index 4121816..80ee79e 100644 --- a/hw/arm/mps2.c +++ b/hw/arm/mps2.c @@ -34,6 +34,7 @@ #include "hw/misc/unimp.h" #include "hw/char/cmsdk-apb-uart.h" #include "hw/timer/cmsdk-apb-timer.h" +#include "hw/misc/mps2-scc.h" typedef enum MPS2FPGAType { FPGA_AN385, @@ -44,6 +45,7 @@ typedef struct { MachineClass parent; MPS2FPGAType fpga_type; const char *cpu_model; + uint32_t scc_id; } MPS2MachineClass; typedef struct { @@ -60,6 +62,7 @@ typedef struct { MemoryRegion blockram_m2; MemoryRegion blockram_m3; MemoryRegion sram; + MPS2SCC scc; } MPS2MachineState; #define TYPE_MPS2_MACHINE "mps2" @@ -102,7 +105,7 @@ static void mps2_common_init(MachineState *machine) MPS2MachineState *mms = MPS2_MACHINE(machine); MPS2MachineClass *mmc = MPS2_MACHINE_GET_CLASS(machine); MemoryRegion *system_memory = get_system_memory(); - DeviceState *armv7m; + DeviceState *armv7m, *sccdev; if (!machine->cpu_model) { machine->cpu_model = mmc->cpu_model; @@ -297,6 +300,16 @@ static void mps2_common_init(MachineState *machine) cmsdk_apb_timer_create(0x40000000, qdev_get_gpio_in(armv7m, 8), SYSCLK_FRQ); cmsdk_apb_timer_create(0x40001000, qdev_get_gpio_in(armv7m, 9), SYSCLK_FRQ); + object_initialize(&mms->scc, sizeof(mms->scc), TYPE_MPS2_SCC); + sccdev = DEVICE(&mms->scc); + qdev_set_parent_bus(armv7m, sysbus_get_default()); + qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2); + qdev_prop_set_uint32(sccdev, "scc-aid", 0x02000008); + qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id); + object_property_set_bool(OBJECT(&mms->scc), true, "realized", + &error_fatal); + sysbus_mmio_map(SYS_BUS_DEVICE(sccdev), 0, 0x4002f000); + system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, @@ -319,6 +332,7 @@ static void mps2_an385_class_init(ObjectClass *oc, void *data) mc->desc = "ARM MPS2 with AN385 FPGA image for Cortex-M3"; mmc->fpga_type = FPGA_AN385; mmc->cpu_model = "cortex-m3"; + mmc->scc_id = 0x41040000 | (385 << 4); } static void mps2_an511_class_init(ObjectClass *oc, void *data) @@ -329,6 +343,7 @@ static void mps2_an511_class_init(ObjectClass *oc, void *data) mc->desc = "ARM MPS2 with AN511 DesignStart FPGA image for Cortex-M3"; mmc->fpga_type = FPGA_AN511; mmc->cpu_model = "cortex-m3"; + mmc->scc_id = 0x4104000 | (511 << 4); } static const TypeInfo mps2_info = { From patchwork Mon Jul 17 12:44:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107915 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4466667qge; Mon, 17 Jul 2017 05:45:31 -0700 (PDT) X-Received: by 10.237.60.80 with SMTP id u16mr28642780qte.100.1500295531706; Mon, 17 Jul 2017 05:45:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500295531; cv=none; d=google.com; s=arc-20160816; b=G48ssZPH6RarXcVf1ZG8gJrMSEeJmi1TJ8J72RdamdW4edXc5Aazekdwzq4bqccp8n YKXequzdbwEg9GwnFMhrWmeCGKrwv0RgaphfdeHQXSo8j0i9HQC6Dy4gWrdccfyk197a tYzNHRP6kp8DWQlrUq3cCUkLs3y+gLn/G6+25XfwfUxYM0F55I5cbuZiJspN8neQgfF/ /VG0cfqe4zDGxlOpKdy4SAkeIk+ASiDf9vEO+O4vrngMr7c76k8yLX3bMkujQIOnMqCw 538QVHibK+TQB94zw4DKC0SNYlMnLM4HXR8RpW9cIoDNIlTTN98/TaBSN7nkOsNAEdOi K9xw== 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:arc-authentication-results; bh=Jf1sAXG+6dfFxDiguScHy0ANJebIetufxt8zJF/d3/I=; b=PvOaNFc9hhGm+Oa8qdmWROk6PaEYrbCMsg0Oqb7quxhhToQQdTaquJNXK0JFHsyW4m ftPG/cl3GvhajIS8U+cBDy4y/xXITnm0tXl8fdhG5JoUiNlkViPIBsh11nnUOjDGRQf7 xVVLB05fifyKAbuRZMZJh02Nf3WlU9AuW+0DK9cacNvFvADwwLJq7HqhX4KY8mzCSsK9 6GJYvPPkvimK29YqCd+trEKodHbUmnTgm5heyS5qVNSZgpkyUFg0SGZJVDKFQiEO2CNS azFkvNWp8COzQMNw4LZhksqbCEKT3m6L5YtqLFqjnGJVQG58kVXLS5d1V7jv1R/avfZE +EPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s29si15230031qkl.56.2017.07.17.05.45.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:45:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Oz-0007tM-5x for patch@linaro.org; Mon, 17 Jul 2017 08:45:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Ob-0007qm-EA for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Oa-0002D9-JA for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:05 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37640) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Oa-0002Ci-BV for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:04 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OZ-0003XV-Ee for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:45:03 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:53 +0100 Message-Id: <1500295494-8991-18-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 17/18] hw/arm/mps2: Add ethernet 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 MPS2 FPGA images support ethernet via a LAN9220. We use QEMU's LAN9118 model, which is software compatible except that it is missing the checksum-offload feature. Signed-off-by: Peter Maydell Message-id: 1500029487-14822-9-git-send-email-peter.maydell@linaro.org Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- hw/arm/mps2.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c index 80ee79e..f727b43 100644 --- a/hw/arm/mps2.c +++ b/hw/arm/mps2.c @@ -35,6 +35,8 @@ #include "hw/char/cmsdk-apb-uart.h" #include "hw/timer/cmsdk-apb-timer.h" #include "hw/misc/mps2-scc.h" +#include "hw/devices.h" +#include "net/net.h" typedef enum MPS2FPGAType { FPGA_AN385, @@ -209,7 +211,6 @@ static void mps2_common_init(MachineState *machine) create_unimplemented_device("Extra peripheral region @0x40020000", 0x40020000, 0x00010000); create_unimplemented_device("RESERVED 4", 0x40030000, 0x001D0000); - create_unimplemented_device("Ethernet", 0x40200000, 0x00100000); create_unimplemented_device("VGA", 0x41000000, 0x0200000); switch (mmc->fpga_type) { @@ -310,6 +311,13 @@ static void mps2_common_init(MachineState *machine) &error_fatal); sysbus_mmio_map(SYS_BUS_DEVICE(sccdev), 0, 0x4002f000); + /* In hardware this is a LAN9220; the LAN9118 is software compatible + * except that it doesn't support the checksum-offload feature. + */ + lan9118_init(&nd_table[0], 0x40200000, + qdev_get_gpio_in(armv7m, + mmc->fpga_type == FPGA_AN385 ? 13 : 47)); + system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, From patchwork Mon Jul 17 12:44:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 107918 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4469279qge; Mon, 17 Jul 2017 05:48:07 -0700 (PDT) X-Received: by 10.237.41.38 with SMTP id s35mr27229254qtd.199.1500295687697; Mon, 17 Jul 2017 05:48:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500295687; cv=none; d=google.com; s=arc-20160816; b=m3QH5yanJZK6+3rwJ41digje+3zwXzSSfRFIV6BAvbEHXl2b6NRRRPA0cFFGgXdXk6 vQ/RnVTBRjUFeHWJwFYuUWCF98/tCwcIncAqL0P/qexbEiR6Tk/SpQ1MtSCO7hS3gZ8U mJFzo2mXYirJE4w3mBjRM38kGkcG3+wepCOrpkkCwo8mlaEZlCcGUZLXKjCxs/9JLz65 JkanR88+VUBR2tyGLUuqf3/csKQnjcR92dZFGcYI4b/dl18R63EkvFWMT564fzfglub6 XIAd3pDJD0Iaye1urIL+ap9mYV/hOCDCrljU5wIiVapmLBxb33wRn4OQARBeJWmw8A2L 4SXQ== 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:arc-authentication-results; bh=9E1/9MeJ+A47CePWnFxONRuHwnCJwkBjYaVunULYZik=; b=Y6X5yCxxxMBD6sqkOxgpryg7P0FehE0AJPS2n6GmsobG9anmSywqo2qkJ4TDxlFamq QwWsd5B3LiPSyqLiltTFq4By4B3mJEVOfvMeh+pI6hgwSML9Uuw+MRqxu2yuioshs6lV O9BYGHZoeJuV7gN0B4bUASQOQI8VhKX7EQXZ++qcZiRteK86tz0BwTNLksK0AmKcs9al Qtdg7jsBlHTDTg3T9K8nFNjE+Fc53iHvCcT+J2SuwLtp/vG0VSVaPXKgE+VcRA/B5mNM K2NuVNvdjHuE71oKrR1l6vFxyWK4NKXXIronIZ5Z5ZQFyeu/gwcMrCEKvoi6Me+d0TmQ g97Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c77si14537934qkb.328.2017.07.17.05.48.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Jul 2017 05:48:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:50171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5RV-0001cm-9b for patch@linaro.org; Mon, 17 Jul 2017 08:48:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dX5Oc-0007r2-Kd for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dX5Ob-0002Df-Dz for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:06 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:37640) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dX5Ob-0002Ci-7G for qemu-devel@nongnu.org; Mon, 17 Jul 2017 08:45:05 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1dX5OZ-0003Xh-U6 for qemu-devel@nongnu.org; Mon, 17 Jul 2017 13:45:03 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jul 2017 13:44:54 +0100 Message-Id: <1500295494-8991-19-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> References: <1500295494-8991-1-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 18/18] MAINTAINERS: Add entries for MPS2 board 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" Add entries to the MAINTAINERS file for the new MPS2 board and devices. Since the CMSDK devices are not specific to the MPS2 board, extend the existing 'PrimeCell' section to cover CMSDK devices as well; in both cases these are devices implemented by ARM and provided as RTL that may be used in multiple SoCs and boards. Signed-off-by: Peter Maydell Message-id: 1500029487-14822-10-git-send-email-peter.maydell@linaro.org Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- MAINTAINERS | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/MAINTAINERS b/MAINTAINERS index b9aa878..5ea273f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -375,7 +375,7 @@ F: hw/*/allwinner* F: include/hw/*/allwinner* F: hw/arm/cubieboard.c -ARM PrimeCell +ARM PrimeCell and CMSDK devices M: Peter Maydell L: qemu-arm@nongnu.org S: Maintained @@ -389,6 +389,10 @@ F: hw/intc/pl190.c F: hw/sd/pl181.c F: hw/timer/pl031.c F: include/hw/arm/primecell.h +F: hw/timer/cmsdk-apb-timer.c +F: include/hw/timer/cmsdk-apb-timer.h +F: hw/char/cmsdk-apb-uart.c +F: include/hw/char/cmsdk-apb-uart.h ARM cores M: Peter Maydell @@ -450,6 +454,14 @@ S: Maintained F: hw/arm/integratorcp.c F: hw/misc/arm_integrator_debug.c +MPS2 +M: Peter Maydell +L: qemu-arm@nongnu.org +S: Maintained +F: hw/arm/mps2.c +F: hw/misc/mps2-scc.c +F: include/hw/misc/mps2-scc.h + Musicpal M: Jan Kiszka L: qemu-arm@nongnu.org