From patchwork Sat Feb 16 21:44:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 221039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 240782C008C for ; Sun, 17 Feb 2013 08:45:03 +1100 (EST) Received: from localhost ([::1]:59352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6pZ7-0001Lm-8S for incoming@patchwork.ozlabs.org; Sat, 16 Feb 2013 16:45:01 -0500 Received: from eggs.gnu.org ([208.118.235.92]:48994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6pYb-0000Z6-Ky for qemu-devel@nongnu.org; Sat, 16 Feb 2013 16:44:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U6pYS-00038a-R5 for qemu-devel@nongnu.org; Sat, 16 Feb 2013 16:44:29 -0500 Received: from cantor2.suse.de ([195.135.220.15]:50185 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6pYS-000388-9d for qemu-devel@nongnu.org; Sat, 16 Feb 2013 16:44:20 -0500 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id AD78CA3A49; Sat, 16 Feb 2013 22:44:19 +0100 (CET) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Sat, 16 Feb 2013 22:44:03 +0100 Message-Id: <1361051043-27944-4-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1361051043-27944-1-git-send-email-afaerber@suse.de> References: <1361051043-27944-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , anthony@codemonkey.ws Subject: [Qemu-devel] [PATCH v4 3/3] qtest: Add MMIO support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Introduce [qtest_]{read,write}[bwlq]() libqtest functions and corresponding QTest protocol commands to replace local versions in libi2c-omap.c. Also convert m48t59-test's cmos_{read,write}_mmio() to {read,write}b(). Signed-off-by: Andreas Färber --- Makefile.objs | 1 - Makefile.target | 1 + qtest.c | 81 ++++++++++++++++++++++ tests/libi2c-omap.c | 23 ------- tests/libqtest.c | 62 +++++++++++++++++ tests/libqtest.h | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/m48t59-test.c | 7 +- 7 Dateien geändert, 332 Zeilen hinzugefügt(+), 29 Zeilen entfernt(-) diff --git a/Makefile.objs b/Makefile.objs index 21e9c91..a68cdac 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -72,7 +72,6 @@ common-obj-y += ui/ common-obj-y += bt-host.o bt-vhci.o common-obj-y += dma-helpers.o -common-obj-y += qtest.o common-obj-y += vl.o common-obj-$(CONFIG_SLIRP) += slirp/ diff --git a/Makefile.target b/Makefile.target index 760da1e..ca657b3 100644 --- a/Makefile.target +++ b/Makefile.target @@ -109,6 +109,7 @@ CONFIG_NO_GET_MEMORY_MAPPING = $(if $(subst n,,$(CONFIG_HAVE_GET_MEMORY_MAPPING) CONFIG_NO_CORE_DUMP = $(if $(subst n,,$(CONFIG_HAVE_CORE_DUMP)),n,y) obj-y += arch_init.o cpus.o monitor.o gdbstub.o balloon.o ioport.o +obj-y += qtest.o obj-y += hw/ obj-$(CONFIG_KVM) += kvm-all.o obj-$(CONFIG_NO_KVM) += kvm-stub.o diff --git a/qtest.c b/qtest.c index 4663a38..5e0e9ec 100644 --- a/qtest.c +++ b/qtest.c @@ -87,6 +87,30 @@ static bool qtest_opened; * > inl ADDR * < OK VALUE * + * > writeb ADDR VALUE + * < OK + * + * > writew ADDR VALUE + * < OK + * + * > writel ADDR VALUE + * < OK + * + * > writeq ADDR VALUE + * < OK + * + * > readb ADDR + * < OK VALUE + * + * > readw ADDR + * < OK VALUE + * + * > readl ADDR + * < OK VALUE + * + * > readq ADDR + * < OK VALUE + * * > read ADDR SIZE * < OK DATA * @@ -277,6 +301,63 @@ static void qtest_process_command(CharDriverState *chr, gchar **words) } qtest_send_prefix(chr); qtest_send(chr, "OK 0x%04x\n", value); + } else if (strcmp(words[0], "writeb") == 0 || + strcmp(words[0], "writew") == 0 || + strcmp(words[0], "writel") == 0 || + strcmp(words[0], "writeq") == 0) { + uint64_t addr; + uint64_t value; + + g_assert(words[1] && words[2]); + addr = strtoull(words[1], NULL, 0); + value = strtoull(words[2], NULL, 0); + + if (words[0][5] == 'b') { + uint8_t data = value; + cpu_physical_memory_write(addr, &data, 1); + } else if (words[0][5] == 'w') { + uint16_t data = value; + tswap16s(&data); + cpu_physical_memory_write(addr, &data, 2); + } else if (words[0][5] == 'l') { + uint32_t data = value; + tswap32s(&data); + cpu_physical_memory_write(addr, &data, 4); + } else if (words[0][5] == 'q') { + uint64_t data = value; + tswap64s(&data); + cpu_physical_memory_write(addr, &data, 8); + } + qtest_send_prefix(chr); + qtest_send(chr, "OK\n"); + } else if (strcmp(words[0], "readb") == 0 || + strcmp(words[0], "readw") == 0 || + strcmp(words[0], "readl") == 0 || + strcmp(words[0], "readq") == 0) { + uint64_t addr; + uint64_t value = UINT64_C(-1); + + g_assert(words[1]); + addr = strtoull(words[1], NULL, 0); + + if (words[0][4] == 'b') { + uint8_t data; + cpu_physical_memory_read(addr, &data, 1); + value = data; + } else if (words[0][4] == 'w') { + uint16_t data; + cpu_physical_memory_read(addr, &data, 2); + value = tswap16(data); + } else if (words[0][4] == 'l') { + uint32_t data; + cpu_physical_memory_read(addr, &data, 4); + value = tswap32(data); + } else if (words[0][4] == 'q') { + cpu_physical_memory_read(addr, &value, 8); + tswap64s(&value); + } + qtest_send_prefix(chr); + qtest_send(chr, "OK 0x%016" PRIx64 "\n", value); } else if (strcmp(words[0], "read") == 0) { uint64_t addr, len, i; uint8_t *data; diff --git a/tests/libi2c-omap.c b/tests/libi2c-omap.c index b7b10b5..c52458c 100644 --- a/tests/libi2c-omap.c +++ b/tests/libi2c-omap.c @@ -49,29 +49,6 @@ typedef struct OMAPI2C { } OMAPI2C; -/* FIXME Use TBD readw qtest API */ -static inline uint16_t readw(uint64_t addr) -{ - uint16_t data; - - memread(addr, &data, 2); - return le16_to_cpu(data); -} - -/* FIXME Use TBD writew qtest API */ -static inline void writew(uint64_t addr, uint16_t data) -{ - data = cpu_to_le16(data); - memwrite(addr, &data, 2); -} - -#ifdef __GNUC__ -#undef memread -#undef memwrite -#pragma GCC poison memread -#pragma GCC poison memwrite -#endif - static void omap_i2c_set_slave_addr(OMAPI2C *s, uint8_t addr) { uint16_t data = addr; diff --git a/tests/libqtest.c b/tests/libqtest.c index da58ff5..389596a 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -3,10 +3,12 @@ * * Copyright IBM, Corp. 2012 * Copyright Red Hat, Inc. 2012 + * Copyright SUSE LINUX Products GmbH 2013 * * Authors: * Anthony Liguori * Paolo Bonzini + * Andreas Färber * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. @@ -437,6 +439,66 @@ uint32_t qtest_inl(QTestState *s, uint16_t addr) return qtest_in(s, "inl", addr); } +static void qtest_write(QTestState *s, const char *cmd, uint64_t addr, + uint64_t value) +{ + qtest_sendf(s, "%s 0x%" PRIx64 " 0x%" PRIx64 "\n", cmd, addr, value); + qtest_rsp(s, 0); +} + +void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value) +{ + qtest_write(s, "writeb", addr, value); +} + +void qtest_writew(QTestState *s, uint64_t addr, uint16_t value) +{ + qtest_write(s, "writew", addr, value); +} + +void qtest_writel(QTestState *s, uint64_t addr, uint32_t value) +{ + qtest_write(s, "writel", addr, value); +} + +void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value) +{ + qtest_write(s, "writeq", addr, value); +} + +static uint64_t qtest_read(QTestState *s, const char *cmd, uint64_t addr) +{ + gchar **args; + uint64_t value; + + qtest_sendf(s, "%s 0x%" PRIx64 "\n", cmd, addr); + args = qtest_rsp(s, 2); + value = strtoull(args[1], NULL, 0); + g_strfreev(args); + + return value; +} + +uint8_t qtest_readb(QTestState *s, uint64_t addr) +{ + return qtest_read(s, "readb", addr); +} + +uint16_t qtest_readw(QTestState *s, uint64_t addr) +{ + return qtest_read(s, "readw", addr); +} + +uint32_t qtest_readl(QTestState *s, uint64_t addr) +{ + return qtest_read(s, "readl", addr); +} + +uint64_t qtest_readq(QTestState *s, uint64_t addr) +{ + return qtest_read(s, "readq", addr); +} + static int hex2nib(char ch) { if (ch >= '0' && ch <= '9') { diff --git a/tests/libqtest.h b/tests/libqtest.h index f5c6e21..437bda3 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -3,10 +3,12 @@ * * Copyright IBM, Corp. 2012 * Copyright Red Hat, Inc. 2012 + * Copyright SUSE LINUX Products GmbH 2013 * * Authors: * Anthony Liguori * Paolo Bonzini + * Andreas Färber * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. @@ -146,6 +148,90 @@ uint16_t qtest_inw(QTestState *s, uint16_t addr); uint32_t qtest_inl(QTestState *s, uint16_t addr); /** + * qtest_writeb: + * @s: #QTestState instance to operate on. + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes an 8-bit value to memory. + */ +void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value); + +/** + * qtest_writew: + * @s: #QTestState instance to operate on. + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 16-bit value to memory. + */ +void qtest_writew(QTestState *s, uint64_t addr, uint16_t value); + +/** + * qtest_writel: + * @s: #QTestState instance to operate on. + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 32-bit value to memory. + */ +void qtest_writel(QTestState *s, uint64_t addr, uint32_t value); + +/** + * qtest_writeq: + * @s: #QTestState instance to operate on. + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 64-bit value to memory. + */ +void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value); + +/** + * qtest_readb: + * @s: #QTestState instance to operate on. + * @addr: Guest address to read from. + * + * Reads an 8-bit value from memory. + * + * Returns: Value read. + */ +uint8_t qtest_readb(QTestState *s, uint64_t addr); + +/** + * qtest_readw: + * @s: #QTestState instance to operate on. + * @addr: Guest address to read from. + * + * Reads a 16-bit value from memory. + * + * Returns: Value read. + */ +uint16_t qtest_readw(QTestState *s, uint64_t addr); + +/** + * qtest_readl: + * @s: #QTestState instance to operate on. + * @addr: Guest address to read from. + * + * Reads a 32-bit value from memory. + * + * Returns: Value read. + */ +uint32_t qtest_readl(QTestState *s, uint64_t addr); + +/** + * qtest_readq: + * @s: #QTestState instance to operate on. + * @addr: Guest address to read from. + * + * Reads a 64-bit value from memory. + * + * Returns: Value read. + */ +uint64_t qtest_readq(QTestState *s, uint64_t addr); + +/** * qtest_memread: * @s: #QTestState instance to operate on. * @addr: Guest address to read from. @@ -358,6 +444,106 @@ static inline uint32_t inl(uint16_t addr) } /** + * writeb: + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes an 8-bit value to guest memory. + */ +static inline void writeb(uint64_t addr, uint8_t value) +{ + qtest_writeb(global_qtest, addr, value); +} + +/** + * writew: + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 16-bit value to guest memory. + */ +static inline void writew(uint64_t addr, uint16_t value) +{ + qtest_writew(global_qtest, addr, value); +} + +/** + * writel: + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 32-bit value to guest memory. + */ +static inline void writel(uint64_t addr, uint32_t value) +{ + qtest_writel(global_qtest, addr, value); +} + +/** + * writeq: + * @addr: Guest address to write to. + * @value: Value being written. + * + * Writes a 64-bit value to guest memory. + */ +static inline void writeq(uint64_t addr, uint64_t value) +{ + qtest_writeq(global_qtest, addr, value); +} + +/** + * readb: + * @addr: Guest address to read from. + * + * Reads an 8-bit value from guest memory. + * + * Returns: Value read. + */ +static inline uint8_t readb(uint64_t addr) +{ + return qtest_readb(global_qtest, addr); +} + +/** + * readw: + * @addr: Guest address to read from. + * + * Reads a 16-bit value from guest memory. + * + * Returns: Value read. + */ +static inline uint16_t readw(uint64_t addr) +{ + return qtest_readw(global_qtest, addr); +} + +/** + * readl: + * @addr: Guest address to read from. + * + * Reads a 32-bit value from guest memory. + * + * Returns: Value read. + */ +static inline uint32_t readl(uint64_t addr) +{ + return qtest_readl(global_qtest, addr); +} + +/** + * readq: + * @addr: Guest address to read from. + * + * Reads a 64-bit value from guest memory. + * + * Returns: Value read. + */ +static inline uint64_t readq(uint64_t addr) +{ + return qtest_readq(global_qtest, addr); +} + +/** * memread: * @addr: Guest address to read from. * @data: Pointer to where memory contents will be stored. diff --git a/tests/m48t59-test.c b/tests/m48t59-test.c index 77d69b3..4081a5f 100644 --- a/tests/m48t59-test.c +++ b/tests/m48t59-test.c @@ -35,17 +35,14 @@ static bool use_mmio; static uint8_t cmos_read_mmio(uint8_t reg) { - uint8_t data; - - memread(base + (uint32_t)reg_base + (uint32_t)reg, &data, 1); - return data; + return readb(base + (uint32_t)reg_base + (uint32_t)reg); } static void cmos_write_mmio(uint8_t reg, uint8_t val) { uint8_t data = val; - memwrite(base + (uint32_t)reg_base + (uint32_t)reg, &data, 1); + writeb(base + (uint32_t)reg_base + (uint32_t)reg, data); } static uint8_t cmos_read_ioio(uint8_t reg)