From patchwork Mon Feb 11 16:41:54 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: 219651 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 07FAB2C02F2 for ; Tue, 12 Feb 2013 04:25:12 +1100 (EST) Received: from localhost ([::1]:51368 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U4wSW-0006Ax-CW for incoming@patchwork.ozlabs.org; Mon, 11 Feb 2013 11:42:24 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U4wSC-00061j-5u for qemu-devel@nongnu.org; Mon, 11 Feb 2013 11:42:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U4wSA-0006ck-5e for qemu-devel@nongnu.org; Mon, 11 Feb 2013 11:42:04 -0500 Received: from cantor2.suse.de ([195.135.220.15]:39463 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U4wS9-0006cP-SV for qemu-devel@nongnu.org; Mon, 11 Feb 2013 11:42:02 -0500 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 5ADF5A3A4A; Mon, 11 Feb 2013 17:42:01 +0100 (CET) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Mon, 11 Feb 2013 17:41:54 +0100 Message-Id: <1360600914-5448-3-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1360600914-5448-1-git-send-email-afaerber@suse.de> References: <1360600914-5448-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 for-1.4 RESEND v2 2/2] libi2c-omap: Fix endianness dependency 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 From: Andreas Färber The libqos driver for omap_i2c currently does not work on Big Endian. Introduce helpers for reading from and writing to 16-bit armel registers. This fixes tmp105-test failures on ppc. To prepare for a QTest-level endianness solution, poison mem{read,write} and always use the helpers. Adopt the expected signatures. To avoid an unused variable warning, assert the STAT Single Byte Data bit but, due to it not getting cleared, only it being set when len == 1. Signed-off-by: Andreas Färber --- tests/libi2c-omap.c | 76 +++++++++++++++++++++++++++++++++++---------------- 1 Datei geändert, 53 Zeilen hinzugefügt(+), 23 Zeilen entfernt(-) diff --git a/tests/libi2c-omap.c b/tests/libi2c-omap.c index 9be57e9..b7b10b5 100644 --- a/tests/libi2c-omap.c +++ b/tests/libi2c-omap.c @@ -12,6 +12,7 @@ #include #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "libqtest.h" enum OMAPI2CRegisters { @@ -48,12 +49,35 @@ 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; - memwrite(s->addr + OMAP_I2C_SA, &data, 2); - memread(s->addr + OMAP_I2C_SA, &data, 2); + writew(s->addr + OMAP_I2C_SA, data); + data = readw(s->addr + OMAP_I2C_SA); g_assert_cmphex(data, ==, addr); } @@ -66,36 +90,38 @@ static void omap_i2c_send(I2CAdapter *i2c, uint8_t addr, omap_i2c_set_slave_addr(s, addr); data = len; - memwrite(s->addr + OMAP_I2C_CNT, &data, 2); + writew(s->addr + OMAP_I2C_CNT, data); data = OMAP_I2C_CON_I2C_EN | OMAP_I2C_CON_TRX | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT | OMAP_I2C_CON_STP; - memwrite(s->addr + OMAP_I2C_CON, &data, 2); - memread(s->addr + OMAP_I2C_CON, &data, 2); + writew(s->addr + OMAP_I2C_CON, data); + data = readw(s->addr + OMAP_I2C_CON); g_assert((data & OMAP_I2C_CON_STP) != 0); - memread(s->addr + OMAP_I2C_STAT, &data, 2); + data = readw(s->addr + OMAP_I2C_STAT); g_assert((data & OMAP_I2C_STAT_NACK) == 0); while (len > 1) { - memread(s->addr + OMAP_I2C_STAT, &data, 2); + data = readw(s->addr + OMAP_I2C_STAT); g_assert((data & OMAP_I2C_STAT_XRDY) != 0); - memwrite(s->addr + OMAP_I2C_DATA, buf, 2); + data = buf[0] | ((uint16_t)buf[1] << 8); + writew(s->addr + OMAP_I2C_DATA, data); buf = (uint8_t *)buf + 2; len -= 2; } if (len == 1) { - memread(s->addr + OMAP_I2C_STAT, &data, 2); + data = readw(s->addr + OMAP_I2C_STAT); g_assert((data & OMAP_I2C_STAT_XRDY) != 0); - memwrite(s->addr + OMAP_I2C_DATA, buf, 1); + data = buf[0]; + writew(s->addr + OMAP_I2C_DATA, data); } - memread(s->addr + OMAP_I2C_CON, &data, 2); + data = readw(s->addr + OMAP_I2C_CON); g_assert((data & OMAP_I2C_CON_STP) == 0); } @@ -108,42 +134,46 @@ static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr, omap_i2c_set_slave_addr(s, addr); data = len; - memwrite(s->addr + OMAP_I2C_CNT, &data, 2); + writew(s->addr + OMAP_I2C_CNT, data); data = OMAP_I2C_CON_I2C_EN | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT | OMAP_I2C_CON_STP; - memwrite(s->addr + OMAP_I2C_CON, &data, 2); - memread(s->addr + OMAP_I2C_CON, &data, 2); + writew(s->addr + OMAP_I2C_CON, data); + data = readw(s->addr + OMAP_I2C_CON); g_assert((data & OMAP_I2C_CON_STP) == 0); - memread(s->addr + OMAP_I2C_STAT, &data, 2); + data = readw(s->addr + OMAP_I2C_STAT); g_assert((data & OMAP_I2C_STAT_NACK) == 0); - memread(s->addr + OMAP_I2C_CNT, &data, 2); + data = readw(s->addr + OMAP_I2C_CNT); g_assert_cmpuint(data, ==, len); while (len > 0) { - memread(s->addr + OMAP_I2C_STAT, &data, 2); + data = readw(s->addr + OMAP_I2C_STAT); g_assert((data & OMAP_I2C_STAT_RRDY) != 0); g_assert((data & OMAP_I2C_STAT_ROVR) == 0); - memread(s->addr + OMAP_I2C_DATA, &data, 2); + data = readw(s->addr + OMAP_I2C_DATA); + + stat = readw(s->addr + OMAP_I2C_STAT); - memread(s->addr + OMAP_I2C_STAT, &stat, 2); if (unlikely(len == 1)) { - *buf = data & 0xf; + g_assert((stat & OMAP_I2C_STAT_SBD) != 0); + + buf[0] = data & 0xff; buf++; len--; } else { - memcpy(buf, &data, 2); + buf[0] = data & 0xff; + buf[1] = data >> 8; buf += 2; len -= 2; } } - memread(s->addr + OMAP_I2C_CON, &data, 2); + data = readw(s->addr + OMAP_I2C_CON); g_assert((data & OMAP_I2C_CON_STP) == 0); } @@ -159,7 +189,7 @@ I2CAdapter *omap_i2c_create(uint64_t addr) i2c->recv = omap_i2c_recv; /* verify the mmio address by looking for a known signature */ - memread(addr + OMAP_I2C_REV, &data, 2); + data = readw(addr + OMAP_I2C_REV); g_assert_cmphex(data, ==, 0x34); return i2c;