From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMJyj-0005js-KG for qemu-devel@nongnu.org; Mon, 12 Nov 2018 16:42:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gMJyh-0002ZO-RK for qemu-devel@nongnu.org; Mon, 12 Nov 2018 16:42:41 -0500 Received: from steffen-goertz.de ([88.198.119.201]:35460) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gMJyf-0002Vl-JT for qemu-devel@nongnu.org; Mon, 12 Nov 2018 16:42:39 -0500 From: =?UTF-8?q?Steffen=20G=C3=B6rtz?= Date: Mon, 12 Nov 2018 16:42:11 -0500 Message-Id: <20181112214224.31560-2-contrib@steffen-goertz.de> In-Reply-To: <20181112214224.31560-1-contrib@steffen-goertz.de> References: <20181112214224.31560-1-contrib@steffen-goertz.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v5 01/14] qtest: Add set_irq_in command to set IRQ/GPIO level List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Joel Stanley , Jim Mussared , Julia Suvorova , Peter Maydell , Thomas Huth , Laurent Vivier , =?UTF-8?q?Steffen=20G=C3=B6rtz?= , Paolo Bonzini Adds a new qtest command "set_irq_in" which allows to set qemu gpio lines to a given level. Based on https://lists.gnu.org/archive/html/qemu-devel/2012-12/msg02363.h= tml which never got merged. Signed-off-by: Steffen G=C3=B6rtz Originally-by: Matthew Ogilvie Reviewed-by: Stefan Hajnoczi --- qtest.c | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/libqtest.c | 10 ++++++++++ tests/libqtest.h | 13 +++++++++++++ 3 files changed, 66 insertions(+) diff --git a/qtest.c b/qtest.c index 69b9e9962b..451696b5da 100644 --- a/qtest.c +++ b/qtest.c @@ -164,6 +164,17 @@ static bool qtest_opened; * where NUM is an IRQ number. For the PC, interrupts can be intercepte= d * simply with "irq_intercept_in ioapic" (note that IRQ0 comes out with * NUM=3D0 even though it is remapped to GSI 2). + * + * Setting interrupt level: + * + * > set_irq_in QOM-PATH NAME NUM LEVEL + * < OK + * + * where NAME is the name of the irq/gpio list, NUM is an IRQ number an= d + * LEVEL is an signed integer IRQ level. + * + * Forcibly set the given interrupt pin to the given level. + * */ =20 static int hex2nib(char ch) @@ -326,7 +337,39 @@ static void qtest_process_command(CharBackend *chr, = gchar **words) irq_intercept_dev =3D dev; qtest_send_prefix(chr); qtest_send(chr, "OK\n"); + } else if (strcmp(words[0], "set_irq_in") =3D=3D 0) { + DeviceState *dev; + qemu_irq irq; + char *name; + int ret; + int num; + int level; =20 + g_assert(words[1] && words[2] && words[3] && words[4]); + + dev =3D DEVICE(object_resolve_path(words[1], NULL)); + if (!dev) { + qtest_send_prefix(chr); + qtest_send(chr, "FAIL Unknown device\n"); + return; + } + + if (strcmp(words[2], "unnamed-gpio-in") =3D=3D 0) { + name =3D NULL; + } else { + name =3D words[2]; + } + + ret =3D qemu_strtoi(words[3], NULL, 0, &num); + g_assert(!ret); + ret =3D qemu_strtoi(words[4], NULL, 0, &level); + g_assert(!ret); + + irq =3D qdev_get_gpio_in_named(dev, name, num); + + qemu_set_irq(irq, level); + qtest_send_prefix(chr); + qtest_send(chr, "OK\n"); } else if (strcmp(words[0], "outb") =3D=3D 0 || strcmp(words[0], "outw") =3D=3D 0 || strcmp(words[0], "outl") =3D=3D 0) { diff --git a/tests/libqtest.c b/tests/libqtest.c index 44ce118cfc..1cbde0d91a 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -732,6 +732,16 @@ void qtest_irq_intercept_in(QTestState *s, const cha= r *qom_path) qtest_rsp(s, 0); } =20 +void qtest_set_irq_in(QTestState *s, const char *qom_path, const char *n= ame, + int num, int level) +{ + if (!name) { + name =3D "unnamed-gpio-in"; + } + qtest_sendf(s, "set_irq_in %s %s %d %d\n", qom_path, name, num, leve= l); + qtest_rsp(s, 0); +} + static void qtest_out(QTestState *s, const char *cmd, uint16_t addr, uin= t32_t value) { qtest_sendf(s, "%s 0x%x 0x%x\n", cmd, addr, value); diff --git a/tests/libqtest.h b/tests/libqtest.h index ed88ff99d5..ab99c5dd85 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -232,6 +232,19 @@ void qtest_irq_intercept_in(QTestState *s, const cha= r *string); */ void qtest_irq_intercept_out(QTestState *s, const char *string); =20 +/** + * qtest_set_irq_in: + * @s: QTestState instance to operate on. + * @string: QOM path of a device + * @name: IRQ name + * @irq: IRQ number + * @level: IRQ level + * + * Force given device/irq GPIO-in pin to the given level. + */ +void qtest_set_irq_in(QTestState *s, const char *string, const char *nam= e, + int irq, int level); + /** * qtest_outb: * @s: #QTestState instance to operate on. --=20 2.19.1