From patchwork Fri Jul 2 10:40:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 469511 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1255155jao; Fri, 2 Jul 2021 03:46:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCBMlbagn2uDKhDo1HiyeGb6zpoW1bVLNQ1aCzjWqG0FwiFWksbXKLL1p06W8l5/C1rCD0 X-Received: by 2002:ac8:7b42:: with SMTP id m2mr3021193qtu.225.1625222801589; Fri, 02 Jul 2021 03:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625222801; cv=none; d=google.com; s=arc-20160816; b=pN8ZIGa9zv7iniHMrDD2W+NGtgGtUckS7+vQbV/a2rMr90JDp/NXKV7ptFteLcKvZ0 PS5WAfy0LPeDG0DnkFW53jAtJNQMTPpET6jwUY17DdHe5MvtQSq3CzY/CvOFxrALoogx 80CO9if1zWSI6ewlDkLw7+xlaE0MKhGCfYcfeXIAYpAG6hjdmFQS6aSB7N5P00rw+mEX a3cZnaDtZ/BWQj2BtBVDv/nc9+O+uMGa8GTFhThKVYQJbXykZxScuzabcvpZaJBHCQFa mkmiRxWCNG3Y0SYVKArHKSLZIQ7oxhFCWTuf9+7iH0WCtcvvYjO6Hn/uanBudy9qNkhu DWow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=OHxj/xUOSn5B7Ujk/a1aY2KoAO5Tcc5/XFJvO0oLWf4=; b=TrfbSj/U+NnDlLhZ1Z6uijXDqcop+CYo9hxSm4H+TVc8H7mKYOj8YIpTwcMsnRNWrD MLqhc8ieqrf7qXyKP9dj7X8WUZ2eVd9AztS1enPRv6HTJ4e8yqeqDhjZNG84rDXZ1ABL YeOPMAtwesbYDhTLtUDIlWlhEVFVzjAO0o6Vdd0lRbxUQFbGP6sAc4seyIWU5y+0H8Dc gJZIsDA9podTARfCWHaDC1uZg+ljeRZX/xqoIyUPg1g/Zp00WE73ApuvNQ/5GsX4HE/S fSaeyqAb3HqUt8JOLC3L0GuIQIj6AQ2QwkGEKkw3ULG9w+L8UTCMMDbnUsRwiQ8iMMR5 PCuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pKfNGLE8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p12si2288792qkh.56.2021.07.02.03.46.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 02 Jul 2021 03:46:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pKfNGLE8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lzGgy-0006yu-Uu for patch@linaro.org; Fri, 02 Jul 2021 06:46:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lzGb2-0004j7-8B for qemu-devel@nongnu.org; Fri, 02 Jul 2021 06:40:32 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:38664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lzGax-0006dT-A2 for qemu-devel@nongnu.org; Fri, 02 Jul 2021 06:40:31 -0400 Received: by mail-wr1-x434.google.com with SMTP id a8so218443wrp.5 for ; Fri, 02 Jul 2021 03:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OHxj/xUOSn5B7Ujk/a1aY2KoAO5Tcc5/XFJvO0oLWf4=; b=pKfNGLE80XJP6BdmjqJu83DHv/hT0/LRl/xezT6oIy5lof2rbz2iCvfGumKzWaudet TGA8SIWrvJ3MmRrk3u4FsrhDE7Qef2jJcSeVyUKQY45c2o5jk4OZ7wcxMLkPPNKfXQot bTz6G2h0Xbw55PQuF3qQ9bOLOpD8s0xz/Y4cGjGlztfwddZINmDks8M4/B0TaRtI2Lwn Hst+POFYWA58yyyfF7s/GSzBaifKrIbiECU/l/zwN8ICik5NkQFrRqYBXrAYkO7/DNjB i7hA2d4YkU/ZygiUhCNOXb0i8f9WSaGjSpiSwpcS3+lB0e0yC+her/pMNf61snjm4JPd cDxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OHxj/xUOSn5B7Ujk/a1aY2KoAO5Tcc5/XFJvO0oLWf4=; b=En4c6CgLnqI7zmeRdJza0w91ZU2Zl62Wk6Xi+IgwdcmrqBZG9iW4zDFBbOy7LKJFwR PxK4oFFb9kFt7ZKWU4XI8Ci6LQyyjYQm69xsNMKe9bxRSvy8LHxjTFjctboD0xTcPZAN h7s4Atdo1JhfcGHts08BQWT45BJcqkmyQYT0KNNZPoJJP6V/+xhPy2cGWocBK1S14n9W vqeDF+M00HJCvMHZicwK87+lR5sYpGD07/00qt+/bj/Telij8UJ49EnxzcWO6/FpLxJJ RPwI5YcF/sMhv1DQQShy9hnlaB1wVW60x3TqJnVnNkCSZ3QVKkdB416ncXb14YBef2fx ddHw== X-Gm-Message-State: AOAM530xSJ9cVwW+69r/4ZlctmEg0kB2CWpkg8H0NHxdYlpb/RKUFzzN kHgsEiqq5pWOIlqu/zrR/C0rSA== X-Received: by 2002:adf:eece:: with SMTP id a14mr5043230wrp.313.1625222426063; Fri, 02 Jul 2021 03:40:26 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id p16sm2745810wrs.52.2021.07.02.03.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jul 2021 03:40:25 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 07/11] hw/gpio/pl061: Make pullup/pulldown of outputs configurable Date: Fri, 2 Jul 2021 11:40:14 +0100 Message-Id: <20210702104018.19881-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210702104018.19881-1-peter.maydell@linaro.org> References: <20210702104018.19881-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxim Uvarov Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The PL061 GPIO does not itself include pullup or pulldown resistors to set the value of a GPIO line treated as an output when it is configured as an input (ie when the PL061 itself is not driving it). In real hardware it is up to the board to add suitable pullups or pulldowns. Currently our implementation hardwires this to "outputs pulled high", which is correct for some boards (eg the realview ones: see figure 3-29 in the "RealView Platform Baseboard for ARM926EJ-S User Guide" DUI0224I), but wrong for others. In particular, the wiring in the 'virt' board and the gpio-pwr device assumes that wires should be pulled low, because otherwise the pull-to-high will trigger a shutdown or reset action. (The only reason this doesn't happen immediately on startup is due to another bug in the PL061, where we don't assert the GPIOs to the correct value on reset, but will do so as soon as the guest touches a register and pl061_update() gets called.) Add properties to the pl061 so the board can configure whether it wants GPIO lines to have pullup, pulldown, or neither. Signed-off-by: Peter Maydell --- hw/gpio/pl061.c | 51 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) -- 2.20.1 Reviewed-by: Richard Henderson diff --git a/hw/gpio/pl061.c b/hw/gpio/pl061.c index 44bed56fef0..bb496a19ade 100644 --- a/hw/gpio/pl061.c +++ b/hw/gpio/pl061.c @@ -13,12 +13,28 @@ * + unnamed GPIO inputs 0..7: inputs to connect to the emulated GPIO lines * + unnamed GPIO outputs 0..7: the emulated GPIO lines, considered as * outputs + * + QOM property "pullups": an integer defining whether non-floating lines + * configured as inputs should be pulled up to logical 1 (ie whether in + * real hardware they have a pullup resistor on the line out of the PL061). + * This should be an 8-bit value, where bit 0 is 1 if GPIO line 0 should + * be pulled high, bit 1 configures line 1, and so on. The default is 0xff, + * indicating that all GPIO lines are pulled up to logical 1. + * + QOM property "pulldowns": an integer defining whether non-floating lines + * configured as inputs should be pulled down to logical 0 (ie whether in + * real hardware they have a pulldown resistor on the line out of the PL061). + * This should be an 8-bit value, where bit 0 is 1 if GPIO line 0 should + * be pulled low, bit 1 configures line 1, and so on. The default is 0x0. + * It is an error to set a bit in both "pullups" and "pulldowns". If a bit + * is 0 in both, then the line is considered to be floating, and it will + * not have qemu_set_irq() called on it when it is configured as an input. */ #include "qemu/osdep.h" #include "hw/irq.h" #include "hw/sysbus.h" +#include "hw/qdev-properties.h" #include "migration/vmstate.h" +#include "qapi/error.h" #include "qemu/log.h" #include "qemu/module.h" #include "qom/object.h" @@ -62,6 +78,9 @@ struct PL061State { qemu_irq irq; qemu_irq out[N_GPIOS]; const unsigned char *id; + /* Properties, for non-Luminary PL061 */ + uint32_t pullups; + uint32_t pulldowns; }; static const VMStateDescription vmstate_pl061 = { @@ -109,8 +128,7 @@ static uint8_t pl061_floating(PL061State *s) */ floating = ~(s->pur | s->pdr); } else { - /* Assume outputs are pulled high. FIXME: this is board dependent. */ - floating = 0; + floating = ~(s->pullups | s->pulldowns); } return floating & ~s->dir; } @@ -131,8 +149,7 @@ static uint8_t pl061_pullups(PL061State *s) */ pullups = s->pur; } else { - /* Assume outputs are pulled high. FIXME: this is board dependent. */ - pullups = 0xff; + pullups = s->pullups; } return pullups & ~s->dir; } @@ -501,12 +518,38 @@ static void pl061_init(Object *obj) qdev_init_gpio_out(dev, s->out, N_GPIOS); } +static void pl061_realize(DeviceState *dev, Error **errp) +{ + PL061State *s = PL061(dev); + + if (s->pullups > 0xff) { + error_setg(errp, "pullups property must be between 0 and 0xff"); + return; + } + if (s->pulldowns > 0xff) { + error_setg(errp, "pulldowns property must be between 0 and 0xff"); + return; + } + if (s->pullups & s->pulldowns) { + error_setg(errp, "no bit may be set both in pullups and pulldowns"); + return; + } +} + +static Property pl061_props[] = { + DEFINE_PROP_UINT32("pullups", PL061State, pullups, 0xff), + DEFINE_PROP_UINT32("pulldowns", PL061State, pulldowns, 0x0), + DEFINE_PROP_END_OF_LIST() +}; + static void pl061_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); dc->vmsd = &vmstate_pl061; dc->reset = &pl061_reset; + dc->realize = pl061_realize; + device_class_set_props(dc, pl061_props); } static const TypeInfo pl061_info = {