From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552930882175610.6861091956816; Mon, 18 Mar 2019 10:41:22 -0700 (PDT) Received: from localhost ([127.0.0.1]:45114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wG6-0003tr-2R for importer@patchew.org; Mon, 18 Mar 2019 13:41:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4x-0003lK-JU for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrD-0003PL-2a for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36802) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrC-0003L0-LS for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9025188AAB for ; Mon, 18 Mar 2019 17:15:24 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA21A5D70E for ; Mon, 18 Mar 2019 17:15:23 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:09 +0100 Message-Id: <20190318171521.8524-2-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 18 Mar 2019 17:15:24 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/13] qgraph: allow extra_device_opts on bus nodes 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Allow choosing the bus that the device will be placed on, in case the machine has more than one. Otherwise, the bus may not match the base address of the controller we attach it to. Signed-off-by: Paolo Bonzini --- tests/qos-test.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/qos-test.c b/tests/qos-test.c index 6b1145eccc..c3b76d277d 100644 --- a/tests/qos-test.c +++ b/tests/qos-test.c @@ -340,7 +340,8 @@ static void walk_path(QOSGraphNode *orig_path, int len) char **path_vec =3D g_new0(char *, (QOS_PATH_MAX_ELEMENT_SIZE * 2)); int path_vec_size =3D 0; =20 - char *after_cmd =3D NULL, *before_cmd =3D NULL, *after_device =3D NULL; + char *after_cmd, *before_cmd, *after_device; + GString *after_device_str =3D g_string_new(""); char *node_name =3D orig_path->name, *path_str; =20 GString *cmd_line =3D g_string_new(""); @@ -363,9 +364,8 @@ static void walk_path(QOSGraphNode *orig_path, int len) /* append node command line + previous edge command line */ if (path->command_line && etype =3D=3D QEDGE_CONSUMED_BY) { g_string_append(cmd_line, path->command_line); - if (after_device) { - g_string_append(cmd_line, after_device); - } + g_string_append(cmd_line, after_device_str->str); + g_string_truncate(after_device_str, 0); } =20 path_vec[path_vec_size++] =3D qos_graph_edge_get_name(path->path_e= dge); @@ -382,12 +382,15 @@ static void walk_path(QOSGraphNode *orig_path, int le= n) if (after_cmd) { g_string_append(cmd_line2, after_cmd); } + if (after_device) { + g_string_append(after_device_str, after_device); + } } =20 path_vec[path_vec_size++] =3D NULL; - if (after_device) { - g_string_append(cmd_line, after_device); - } + g_string_append(cmd_line, after_device_str->str); + g_string_free(after_device_str, true); + g_string_append(cmd_line, cmd_line2->str); g_string_free(cmd_line2, true); =20 --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552930378036640.1753466406645; Mon, 18 Mar 2019 10:32:58 -0700 (PDT) Received: from localhost ([127.0.0.1]:44921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w86-00067Y-U7 for importer@patchew.org; Mon, 18 Mar 2019 13:32:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4x-0004C0-Jd for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrD-0003PU-3N for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41930) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrC-0003Np-LF for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B216D30833A6 for ; Mon, 18 Mar 2019 17:15:25 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0327F5D70E for ; Mon, 18 Mar 2019 17:15:24 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:10 +0100 Message-Id: <20190318171521.8524-3-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 18 Mar 2019 17:15:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/13] qgraph: fix qos_node_contains with options 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Currently, if qos_node_contains was passed options, it would still create an edge without any options. Instead, in that case NULL acts as a terminator. Signed-off-by: Paolo Bonzini --- tests/libqos/qgraph.c | 12 ++++++++---- tests/libqos/qgraph.h | 15 +++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/libqos/qgraph.c b/tests/libqos/qgraph.c index 122efc1b7b..9f738f1849 100644 --- a/tests/libqos/qgraph.c +++ b/tests/libqos/qgraph.c @@ -630,15 +630,19 @@ void qos_node_create_driver(const char *name, QOSCrea= teDriverFunc function) } =20 void qos_node_contains(const char *container, const char *contained, - ...) + QOSGraphEdgeOptions *opts, ...) { va_list va; - va_start(va, contained); - QOSGraphEdgeOptions *opts; =20 + if (opts =3D=3D NULL) { + add_edge(container, contained, QEDGE_CONTAINS, NULL); + return; + } + + va_start(va, contained); do { - opts =3D va_arg(va, QOSGraphEdgeOptions *); add_edge(container, contained, QEDGE_CONTAINS, opts); + opts =3D va_arg(va, QOSGraphEdgeOptions *); } while (opts !=3D NULL); =20 va_end(va); diff --git a/tests/libqos/qgraph.h b/tests/libqos/qgraph.h index ef0c73837a..ffe009445a 100644 --- a/tests/libqos/qgraph.h +++ b/tests/libqos/qgraph.h @@ -457,14 +457,16 @@ void qos_node_create_machine_args(const char *name, void qos_node_create_driver(const char *name, QOSCreateDriverFunc function= ); =20 /** - * qos_node_contains(): creates an edge of type QEDGE_CONTAINS and - * adds it to the edge list mapped to @container in the + * qos_node_contains(): creates one or more edges of type QEDGE_CONTAINS + * and adds them to the edge list mapped to @container in the * edge hash table. * - * This edge will have @container as source and @contained as destination. + * The edges will have @container as source and @contained as destination. * - * It also has the possibility to add optional NULL-terminated - * @opts parameters (see %QOSGraphEdgeOptions) + * If @opts is NULL, a single edge will be added with no options. + * If @opts is non-NULL, the arguments after @contained represent a + * NULL-terminated list of %QOSGraphEdgeOptions structs, and an + * edge will be added for each of them. * * This function can be useful when there are multiple devices * with the same node name contained in a machine/other node @@ -484,7 +486,8 @@ void qos_node_create_driver(const char *name, QOSCreate= DriverFunc function); * For contains, op1.arg and op1.size_arg represent the arg to pass * to @contained constructor to properly initialize it. */ -void qos_node_contains(const char *container, const char *contained, ...); +void qos_node_contains(const char *container, const char *contained, + QOSGraphEdgeOptions *opts, ...); =20 /** * qos_node_produces(): creates an edge of type QEDGE_PRODUCES and --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552931030008126.99368188823587; Mon, 18 Mar 2019 10:43:50 -0700 (PDT) Received: from localhost ([127.0.0.1]:45157 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wIa-0005ck-RJ for importer@patchew.org; Mon, 18 Mar 2019 13:43:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4x-0004CI-GM for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrH-0003Ro-Ni for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37500) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrE-0003PR-IF for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1AAA307D853 for ; Mon, 18 Mar 2019 17:15:26 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 224605D70E for ; Mon, 18 Mar 2019 17:15:25 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:11 +0100 Message-Id: <20190318171521.8524-4-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 18 Mar 2019 17:15:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 03/13] libqos: move common i2c code to libqos 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The functions to read/write 8-bit or 16-bit registers are the same in tmp105 and pca9552 tests, and in fact they are a special case of "read block"/"write block" functionality; read block in turn is used in ds1338-test. Move everything inside libqos-test, removing the duplication. Account for the small differences by adding to tmp105-test.c the "read register after writing" behavior that is specific to it. Signed-off-by: Paolo Bonzini --- tests/ds1338-test.c | 8 +---- tests/libqos/i2c.c | 47 ++++++++++++++++++++++++++ tests/libqos/i2c.h | 11 ++++++ tests/pca9552-test.c | 37 +++++--------------- tests/tmp105-test.c | 80 ++++++++++++-------------------------------- 5 files changed, 88 insertions(+), 95 deletions(-) diff --git a/tests/ds1338-test.c b/tests/ds1338-test.c index 742dad9113..88f829f241 100644 --- a/tests/ds1338-test.c +++ b/tests/ds1338-test.c @@ -35,17 +35,11 @@ static inline uint8_t bcd2bin(uint8_t x) =20 static void send_and_receive(void) { - uint8_t cmd[1]; uint8_t resp[7]; time_t now =3D time(NULL); struct tm *tm_ptr =3D gmtime(&now); =20 - /* reset the index in the RTC memory */ - cmd[0] =3D 0; - i2c_send(i2c, addr, cmd, 1); - - /* retrieve the date */ - i2c_recv(i2c, addr, resp, 7); + i2c_read_block(i2c, addr, 0, resp, sizeof(resp)); =20 /* check retrieved time againt local time */ g_assert_cmpuint(bcd2bin(resp[4]), =3D=3D , tm_ptr->tm_mday); diff --git a/tests/libqos/i2c.c b/tests/libqos/i2c.c index 23bc2a3eb2..daf9a96617 100644 --- a/tests/libqos/i2c.c +++ b/tests/libqos/i2c.c @@ -21,3 +21,50 @@ void i2c_recv(I2CAdapter *i2c, uint8_t addr, { i2c->recv(i2c, addr, buf, len); } + +void i2c_read_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + uint8_t *buf, uint16_t len) +{ + i2c_send(i2c, addr, ®, 1); + i2c_recv(i2c, addr, buf, len); +} + +void i2c_write_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + const uint8_t *buf, uint16_t len) +{ + uint8_t *cmd =3D g_malloc(len + 1); + cmd[0] =3D reg; + memcpy(&cmd[1], buf, len); + i2c_send(i2c, addr, cmd, len + 1); + g_free(cmd); +} + +uint8_t i2c_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg) +{ + uint8_t resp[1]; + i2c_read_block(i2c, addr, reg, resp, sizeof(resp)); + return resp[0]; +} + +uint16_t i2c_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg) +{ + uint8_t resp[2]; + i2c_read_block(i2c, addr, reg, resp, sizeof(resp)); + return (resp[0] << 8) | resp[1]; +} + +void i2c_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + uint8_t value) +{ + i2c_write_block(i2c, addr, reg, &value, 1); +} + +void i2c_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + uint16_t value) +{ + uint8_t data[2]; + + data[0] =3D value >> 8; + data[1] =3D value & 255; + i2c_write_block(i2c, addr, reg, data, sizeof(data)); +} diff --git a/tests/libqos/i2c.h b/tests/libqos/i2c.h index cc01358a9f..a462114597 100644 --- a/tests/libqos/i2c.h +++ b/tests/libqos/i2c.h @@ -28,6 +28,17 @@ void i2c_send(I2CAdapter *i2c, uint8_t addr, void i2c_recv(I2CAdapter *i2c, uint8_t addr, uint8_t *buf, uint16_t len); =20 +void i2c_read_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + uint8_t *buf, uint16_t len); +void i2c_write_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + const uint8_t *buf, uint16_t len); +uint8_t i2c_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg); +uint16_t i2c_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg); +void i2c_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + uint8_t value); +void i2c_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg, + uint16_t value); + /* libi2c-omap.c */ I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr); =20 diff --git a/tests/pca9552-test.c b/tests/pca9552-test.c index 5466a67ed7..06359b7435 100644 --- a/tests/pca9552-test.c +++ b/tests/pca9552-test.c @@ -18,27 +18,6 @@ =20 static I2CAdapter *i2c; =20 -static uint8_t pca9552_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg) -{ - uint8_t resp[1]; - i2c_send(i2c, addr, ®, 1); - i2c_recv(i2c, addr, resp, 1); - return resp[0]; -} - -static void pca9552_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg, - uint8_t value) -{ - uint8_t cmd[2]; - uint8_t resp[1]; - - cmd[0] =3D reg; - cmd[1] =3D value; - i2c_send(i2c, addr, cmd, 2); - i2c_recv(i2c, addr, resp, 1); - g_assert_cmphex(resp[0], =3D=3D, cmd[1]); -} - static void receive_autoinc(void) { uint8_t resp; @@ -67,26 +46,26 @@ static void send_and_receive(void) { uint8_t value; =20 - value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0); + value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0); g_assert_cmphex(value, =3D=3D, 0x55); =20 - value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0); + value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0); g_assert_cmphex(value, =3D=3D, 0x0); =20 /* Switch on LED 0 */ - pca9552_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54); - value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0); + i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54); + value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0); g_assert_cmphex(value, =3D=3D, 0x54); =20 - value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0); + value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0); g_assert_cmphex(value, =3D=3D, 0x01); =20 /* Switch on LED 12 */ - pca9552_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54); - value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3); + i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54); + value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3); g_assert_cmphex(value, =3D=3D, 0x54); =20 - value =3D pca9552_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT1); + value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT1); g_assert_cmphex(value, =3D=3D, 0x10); } =20 diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c index 34cae7a582..c86d2571e2 100644 --- a/tests/tmp105-test.c +++ b/tests/tmp105-test.c @@ -19,50 +19,6 @@ =20 static I2CAdapter *i2c; =20 -static uint16_t tmp105_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg) -{ - uint8_t resp[1]; - i2c_send(i2c, addr, ®, 1); - i2c_recv(i2c, addr, resp, 1); - return resp[0]; -} - -static uint16_t tmp105_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg) -{ - uint8_t resp[2]; - i2c_send(i2c, addr, ®, 1); - i2c_recv(i2c, addr, resp, 2); - return (resp[0] << 8) | resp[1]; -} - -static void tmp105_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg, - uint8_t value) -{ - uint8_t cmd[2]; - uint8_t resp[1]; - - cmd[0] =3D reg; - cmd[1] =3D value; - i2c_send(i2c, addr, cmd, 2); - i2c_recv(i2c, addr, resp, 1); - g_assert_cmphex(resp[0], =3D=3D, cmd[1]); -} - -static void tmp105_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg, - uint16_t value) -{ - uint8_t cmd[3]; - uint8_t resp[2]; - - cmd[0] =3D reg; - cmd[1] =3D value >> 8; - cmd[2] =3D value & 255; - i2c_send(i2c, addr, cmd, 3); - i2c_recv(i2c, addr, resp, 2); - g_assert_cmphex(resp[0], =3D=3D, cmd[1]); - g_assert_cmphex(resp[1], =3D=3D, cmd[2]); -} - static int qmp_tmp105_get_temperature(const char *id) { QDict *response; @@ -94,14 +50,14 @@ static void send_and_receive(void) value =3D qmp_tmp105_get_temperature(TMP105_TEST_ID); g_assert_cmpuint(value, =3D=3D, 0); =20 - value =3D tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0); =20 qmp_tmp105_set_temperature(TMP105_TEST_ID, 20000); value =3D qmp_tmp105_get_temperature(TMP105_TEST_ID); g_assert_cmpuint(value, =3D=3D, 20000); =20 - value =3D tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x1400); =20 qmp_tmp105_set_temperature(TMP105_TEST_ID, 20938); /* 20 + 15/16 */ @@ -110,24 +66,27 @@ static void send_and_receive(void) g_assert_cmpuint(value, <, 20938 + TMP105_PRECISION/2); =20 /* Set config */ - tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x60); - value =3D tmp105_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG); + i2c_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x60); + value =3D i2c_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG); g_assert_cmphex(value, =3D=3D, 0x60); =20 - value =3D tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x14f0); =20 /* Set precision to 9, 10, 11 bits. */ - tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x00); - value =3D tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + i2c_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x00); + g_assert_cmphex(i2c_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG), = =3D=3D, 0x00); + value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x1480); =20 - tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x20); - value =3D tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + i2c_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x20); + g_assert_cmphex(i2c_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG), = =3D=3D, 0x20); + value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x14c0); =20 - tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x40); - value =3D tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + i2c_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x40); + g_assert_cmphex(i2c_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG), = =3D=3D, 0x40); + value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x14e0); =20 /* stored precision remains the same */ @@ -135,12 +94,15 @@ static void send_and_receive(void) g_assert_cmpuint(value, >=3D, 20938 - TMP105_PRECISION/2); g_assert_cmpuint(value, <, 20938 + TMP105_PRECISION/2); =20 - tmp105_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x60); - value =3D tmp105_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + i2c_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x60); + g_assert_cmphex(i2c_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG), = =3D=3D, 0x60); + value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x14f0); =20 - tmp105_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_LOW, 0x1234); - tmp105_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_HIGH, 0x4231); + i2c_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_LOW, 0x1234); + g_assert_cmphex(i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_LOW), = =3D=3D, 0x1234); + i2c_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_HIGH, 0x4231); + g_assert_cmphex(i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_HIGH), = =3D=3D, 0x4231); } =20 int main(int argc, char **argv) --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552930711132341.94213124174655; Mon, 18 Mar 2019 10:38:31 -0700 (PDT) Received: from localhost ([127.0.0.1]:45063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wDU-0001mf-63 for importer@patchew.org; Mon, 18 Mar 2019 13:38:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4x-0004DZ-Hf for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrI-0003SA-Ee for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59336) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrG-0003Q7-HU for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB5C63092652 for ; Mon, 18 Mar 2019 17:15:27 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40CC85D70E for ; Mon, 18 Mar 2019 17:15:27 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:12 +0100 Message-Id: <20190318171521.8524-5-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 18 Mar 2019 17:15:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/13] libqos: fix omap-i2c receiving more than 4 bytes 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If more than 4 bytes are received, the FIFO cannot host the entire contents of the transfer and STP will be nonzero before entering the transfer loop. Also, CNT will contain the number of bytes left to be transferred instead of the total number of bytes in the transfer. (Reverse engineered from the omap_i2c.c source code; no available datasheet). This will fix ds1338-test for omap-i2c. Signed-off-by: Paolo Bonzini --- tests/libqos/i2c-omap.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/libqos/i2c-omap.c b/tests/libqos/i2c-omap.c index 1ef6e7b200..bb65336832 100644 --- a/tests/libqos/i2c-omap.c +++ b/tests/libqos/i2c-omap.c @@ -105,6 +105,7 @@ static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr, { OMAPI2C *s =3D (OMAPI2C *)i2c; uint16_t data, stat; + uint16_t orig_len =3D len; =20 omap_i2c_set_slave_addr(s, addr); =20 @@ -116,16 +117,24 @@ static void omap_i2c_recv(I2CAdapter *i2c, uint8_t ad= dr, OMAP_I2C_CON_STT | OMAP_I2C_CON_STP; qtest_writew(i2c->qts, s->addr + OMAP_I2C_CON, data); - data =3D qtest_readw(i2c->qts, s->addr + OMAP_I2C_CON); - g_assert((data & OMAP_I2C_CON_STP) =3D=3D 0); =20 data =3D qtest_readw(i2c->qts, s->addr + OMAP_I2C_STAT); g_assert((data & OMAP_I2C_STAT_NACK) =3D=3D 0); =20 - data =3D qtest_readw(i2c->qts, s->addr + OMAP_I2C_CNT); - g_assert_cmpuint(data, =3D=3D, len); - while (len > 0) { + data =3D qtest_readw(i2c->qts, s->addr + OMAP_I2C_CON); + if (len <=3D 4) { + g_assert((data & OMAP_I2C_CON_STP) =3D=3D 0); + + data =3D qtest_readw(i2c->qts, s->addr + OMAP_I2C_CNT); + g_assert_cmpuint(data, =3D=3D, orig_len); + } else { + g_assert((data & OMAP_I2C_CON_STP) !=3D 0); + + data =3D qtest_readw(i2c->qts, s->addr + OMAP_I2C_CNT); + g_assert_cmpuint(data, =3D=3D, len - 4); + } + data =3D qtest_readw(i2c->qts, s->addr + OMAP_I2C_STAT); g_assert((data & OMAP_I2C_STAT_RRDY) !=3D 0); g_assert((data & OMAP_I2C_STAT_ROVR) =3D=3D 0); --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552931313120372.2657753000252; Mon, 18 Mar 2019 10:48:33 -0700 (PDT) Received: from localhost ([127.0.0.1]:45264 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wNB-0000br-6p for importer@patchew.org; Mon, 18 Mar 2019 13:48:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4x-0003fV-DP for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrI-0003SX-Ou for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37882) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrH-0003Qm-Vg for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06261C0495A6 for ; Mon, 18 Mar 2019 17:15:29 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 548955D70E for ; Mon, 18 Mar 2019 17:15:28 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:13 +0100 Message-Id: <20190318171521.8524-6-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 18 Mar 2019 17:15:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 05/13] pca9552-test: do not rely on state across tests 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" receive_autoinc is relying on the LED state that is set by send_and_receive. Stop doing that, because qgraph resets the machine between tests. Signed-off-by: Paolo Bonzini Reviewed-by: Thomas Huth --- tests/pca9552-test.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/pca9552-test.c b/tests/pca9552-test.c index 06359b7435..89b4445e29 100644 --- a/tests/pca9552-test.c +++ b/tests/pca9552-test.c @@ -18,11 +18,20 @@ =20 static I2CAdapter *i2c; =20 +static void pca9552_init(I2CAdapter *i2c) +{ + /* Switch on LEDs 0 and 12 */ + i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54); + i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54); +} + static void receive_autoinc(void) { uint8_t resp; uint8_t reg =3D PCA9552_LS0 | PCA9552_AUTOINC; =20 + pca9552_init(i2cdev); + i2c_send(i2c, PCA9552_TEST_ADDR, ®, 1); =20 /* PCA9552_LS0 */ @@ -52,16 +61,14 @@ static void send_and_receive(void) value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0); g_assert_cmphex(value, =3D=3D, 0x0); =20 - /* Switch on LED 0 */ - i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54); + pca9552_init(i2cdev); + value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0); g_assert_cmphex(value, =3D=3D, 0x54); =20 value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0); g_assert_cmphex(value, =3D=3D, 0x01); =20 - /* Switch on LED 12 */ - i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54); value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3); g_assert_cmphex(value, =3D=3D, 0x54); =20 --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552930698762773.0478924819588; Mon, 18 Mar 2019 10:38:18 -0700 (PDT) Received: from localhost ([127.0.0.1]:45061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wDF-0001eP-Lq for importer@patchew.org; Mon, 18 Mar 2019 13:38:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4x-000454-FJ for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrI-0003SG-GT for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41974) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrH-0003RD-MP for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2EDB730832C8 for ; Mon, 18 Mar 2019 17:15:30 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EACF5D717 for ; Mon, 18 Mar 2019 17:15:29 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:14 +0100 Message-Id: <20190318171521.8524-7-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 18 Mar 2019 17:15:30 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/13] imx25-pdk: create ds1338 for qtest inside the test 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" There is no need to have a test device created by the board. Instead, create it in the qtest so that we will be able to run it on other boards too. Signed-off-by: Paolo Bonzini Reviewed-by: Thomas Huth --- hw/arm/imx25_pdk.c | 9 --------- tests/ds1338-test.c | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/hw/arm/imx25_pdk.c b/hw/arm/imx25_pdk.c index 9f3ee14739..65e1768663 100644 --- a/hw/arm/imx25_pdk.c +++ b/hw/arm/imx25_pdk.c @@ -132,15 +132,6 @@ static void imx25_pdk_init(MachineState *machine) */ if (!qtest_enabled()) { arm_load_kernel(&s->soc.cpu, &imx25_pdk_binfo); - } else { - /* - * This I2C device doesn't exist on the real board. - * We add it here (only on qtest usage) to be able to do a bit - * of simple qtest. See "make check" for details. - */ - i2c_create_slave((I2CBus *)qdev_get_child_bus(DEVICE(&s->soc.i2c[0= ]), - "i2c-bus.0"), - "ds1338", 0x68); } } =20 diff --git a/tests/ds1338-test.c b/tests/ds1338-test.c index 88f829f241..bd72a159cb 100644 --- a/tests/ds1338-test.c +++ b/tests/ds1338-test.c @@ -54,7 +54,7 @@ int main(int argc, char **argv) =20 g_test_init(&argc, &argv, NULL); =20 - s =3D qtest_start("-display none -machine imx25-pdk"); + s =3D qtest_start("-display none -machine imx25-pdk -device ds1338,add= ress=3D0x68"); i2c =3D imx_i2c_create(s, IMX25_I2C_0_BASE); addr =3D DS1338_ADDR; =20 --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155293087034638.88730541465998; Mon, 18 Mar 2019 10:41:10 -0700 (PDT) Received: from localhost ([127.0.0.1]:45109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wFy-0003i8-Cg for importer@patchew.org; Mon, 18 Mar 2019 13:41:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4x-0003ms-Ai for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrJ-0003Sw-0Y for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16765) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrI-0003Re-GY for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C71330821FA for ; Mon, 18 Mar 2019 17:15:31 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D2765D70E for ; Mon, 18 Mar 2019 17:15:30 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:15 +0100 Message-Id: <20190318171521.8524-8-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 18 Mar 2019 17:15:31 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 07/13] libqos: split I2CAdapter initialization and allocation 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Provide *_init functions that populate an I2CAdapter struct without allocating one, and make the existing *_create functions wrap them. Because in the new setup *_create might return a pointer inside the IMXI2C or OMAPI2C struct, create companion *_free functions to go back to the outer pointer. All this is temporary until allocation will be handled entirely by qgraph. Signed-off-by: Paolo Bonzini --- tests/libqos/i2c-imx.c | 37 ++++++++++++++++++++++--------------- tests/libqos/i2c-omap.c | 32 +++++++++++++++++++++----------- tests/libqos/i2c.h | 20 ++++++++++++++++++-- tests/pca9552-test.c | 2 +- tests/tmp105-test.c | 2 +- 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/tests/libqos/i2c-imx.c b/tests/libqos/i2c-imx.c index 0945f2ecdc..28289c521a 100644 --- a/tests/libqos/i2c-imx.c +++ b/tests/libqos/i2c-imx.c @@ -30,13 +30,6 @@ enum IMXI2CDirection { IMX_I2C_WRITE, }; =20 -typedef struct IMXI2C { - I2CAdapter parent; - - uint64_t addr; -} IMXI2C; - - static void imx_i2c_set_slave_addr(IMXI2C *s, uint8_t addr, enum IMXI2CDirection direction) { @@ -47,7 +40,7 @@ static void imx_i2c_set_slave_addr(IMXI2C *s, uint8_t add= r, static void imx_i2c_send(I2CAdapter *i2c, uint8_t addr, const uint8_t *buf, uint16_t len) { - IMXI2C *s =3D (IMXI2C *)i2c; + IMXI2C *s =3D container_of(i2c, IMXI2C, parent); uint8_t data; uint8_t status; uint16_t size =3D 0; @@ -107,7 +100,7 @@ static void imx_i2c_send(I2CAdapter *i2c, uint8_t addr, static void imx_i2c_recv(I2CAdapter *i2c, uint8_t addr, uint8_t *buf, uint16_t len) { - IMXI2C *s =3D (IMXI2C *)i2c; + IMXI2C *s =3D container_of(i2c, IMXI2C, parent); uint8_t data; uint8_t status; uint16_t size =3D 0; @@ -193,16 +186,30 @@ static void imx_i2c_recv(I2CAdapter *i2c, uint8_t add= r, g_assert((status & I2SR_IBB) =3D=3D 0); } =20 +void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr) +{ + s->addr =3D addr; + + s->parent.send =3D imx_i2c_send; + s->parent.recv =3D imx_i2c_recv; + s->parent.qts =3D qts; +} + I2CAdapter *imx_i2c_create(QTestState *qts, uint64_t addr) { IMXI2C *s =3D g_malloc0(sizeof(*s)); - I2CAdapter *i2c =3D (I2CAdapter *)s; =20 - s->addr =3D addr; + imx_i2c_init(s, qts, addr); + return &s->parent; +} =20 - i2c->send =3D imx_i2c_send; - i2c->recv =3D imx_i2c_recv; - i2c->qts =3D qts; +void imx_i2c_free(I2CAdapter *i2c) +{ + IMXI2C *s; =20 - return i2c; + if (!i2c) { + return; + } + s =3D container_of(i2c, IMXI2C, parent); + g_free(s); } diff --git a/tests/libqos/i2c-omap.c b/tests/libqos/i2c-omap.c index bb65336832..c7cbb9ecdd 100644 --- a/tests/libqos/i2c-omap.c +++ b/tests/libqos/i2c-omap.c @@ -40,12 +40,6 @@ enum OMAPI2CCONBits { OMAP_I2C_CON_I2C_EN =3D 1 << 15, }; =20 -typedef struct OMAPI2C { - I2CAdapter parent; - - uint64_t addr; -} OMAPI2C; - =20 static void omap_i2c_set_slave_addr(OMAPI2C *s, uint8_t addr) { @@ -59,7 +53,7 @@ static void omap_i2c_set_slave_addr(OMAPI2C *s, uint8_t a= ddr) static void omap_i2c_send(I2CAdapter *i2c, uint8_t addr, const uint8_t *buf, uint16_t len) { - OMAPI2C *s =3D (OMAPI2C *)i2c; + OMAPI2C *s =3D container_of(i2c, OMAPI2C, parent); uint16_t data; =20 omap_i2c_set_slave_addr(s, addr); @@ -103,7 +97,7 @@ static void omap_i2c_send(I2CAdapter *i2c, uint8_t addr, static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr, uint8_t *buf, uint16_t len) { - OMAPI2C *s =3D (OMAPI2C *)i2c; + OMAPI2C *s =3D container_of(i2c, OMAPI2C, parent); uint16_t data, stat; uint16_t orig_len =3D len; =20 @@ -161,9 +155,8 @@ static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr, g_assert((data & OMAP_I2C_CON_STP) =3D=3D 0); } =20 -I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr) +void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr) { - OMAPI2C *s =3D g_malloc0(sizeof(*s)); I2CAdapter *i2c =3D (I2CAdapter *)s; uint16_t data; =20 @@ -176,6 +169,23 @@ I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t = addr) /* verify the mmio address by looking for a known signature */ data =3D qtest_readw(qts, addr + OMAP_I2C_REV); g_assert_cmphex(data, =3D=3D, 0x34); +} + +I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr) +{ + OMAPI2C *s =3D g_malloc0(sizeof(*s)); + + omap_i2c_init(s, qts, addr); + return &s->parent; +} =20 - return i2c; +void omap_i2c_free(I2CAdapter *i2c) +{ + OMAPI2C *s; + + if (!i2c) { + return; + } + s =3D container_of(i2c, OMAPI2C, parent); + g_free(s); } diff --git a/tests/libqos/i2c.h b/tests/libqos/i2c.h index a462114597..877d2ab0e8 100644 --- a/tests/libqos/i2c.h +++ b/tests/libqos/i2c.h @@ -39,10 +39,26 @@ void i2c_set8(I2CAdapter *i2c, uint8_t addr, uint8_t re= g, void i2c_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg, uint16_t value); =20 -/* libi2c-omap.c */ +/* i2c-omap.c */ +typedef struct OMAPI2C { + I2CAdapter parent; + + uint64_t addr; +} OMAPI2C; + +void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr); I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr); +void omap_i2c_free(I2CAdapter *i2c); + +/* i2c-imx.c */ +typedef struct IMXI2C { + I2CAdapter parent; + + uint64_t addr; +} IMXI2C; =20 -/* libi2c-imx.c */ +void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr); I2CAdapter *imx_i2c_create(QTestState *qts, uint64_t addr); +void imx_i2c_free(I2CAdapter *i2c); =20 #endif diff --git a/tests/pca9552-test.c b/tests/pca9552-test.c index 89b4445e29..f9509324e2 100644 --- a/tests/pca9552-test.c +++ b/tests/pca9552-test.c @@ -96,7 +96,7 @@ int main(int argc, char **argv) if (s) { qtest_quit(s); } - g_free(i2c); + omap_i2c_free(i2c); =20 return ret; } diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c index c86d2571e2..25ea05f5fd 100644 --- a/tests/tmp105-test.c +++ b/tests/tmp105-test.c @@ -122,7 +122,7 @@ int main(int argc, char **argv) ret =3D g_test_run(); =20 qtest_quit(s); - g_free(i2c); + omap_i2c_free(i2c); =20 return ret; } --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552930713119299.5129970431957; Mon, 18 Mar 2019 10:38:33 -0700 (PDT) Received: from localhost ([127.0.0.1]:45065 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wDW-0001ou-3N for importer@patchew.org; Mon, 18 Mar 2019 13:38:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4u-0003lK-JD for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrJ-0003TZ-Jo for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10479) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrJ-0003SK-3n for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6A1A13082B69 for ; Mon, 18 Mar 2019 17:15:32 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id B46925D70E for ; Mon, 18 Mar 2019 17:15:31 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:16 +0100 Message-Id: <20190318171521.8524-9-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 18 Mar 2019 17:15:32 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/13] libqos: convert I2C to qgraph 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Create an i2c-bus interface, corresponding to the I2CAdapter struct. Wrap IMXI2C and OMAPI2C with a QOSGraphObject, and add the get_driver function to retrieve the I2CAdapter. The conversion is still not complete; for simplicity, i2c_recv and i2c_send (along with their wrappers) still take an adapter/address pair. Fixing that would be complicated until the tests are converted to qgraph, so it is left for after the conversion. Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 2 ++ tests/libqos/i2c-imx.c | 20 ++++++++++++++++++++ tests/libqos/i2c-omap.c | 40 ++++++++++++++++++++++++++++++++-------- tests/libqos/i2c.c | 8 ++++++++ tests/libqos/i2c.h | 21 +++++++++++++++++++++ 5 files changed, 83 insertions(+), 8 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 6b904d7430..44f77230c6 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -713,6 +713,8 @@ libqos-usb-obj-y =3D $(libqos-spapr-obj-y) $(libqos-pc-= obj-y) tests/libqos/usb.o qos-test-obj-y =3D tests/qos-test.o $(libqgraph-obj-y) qos-test-obj-y +=3D $(libqos-pc-obj-y) $(libqos-spapr-obj-y) qos-test-obj-y +=3D tests/libqos/e1000e.o +qos-test-obj-y +=3D $(libqos-imx-obj-y) +qos-test-obj-y +=3D $(libqos-omap-obj-y) qos-test-obj-y +=3D tests/libqos/sdhci.o qos-test-obj-y +=3D tests/libqos/tpci200.o qos-test-obj-y +=3D tests/libqos/virtio.o diff --git a/tests/libqos/i2c-imx.c b/tests/libqos/i2c-imx.c index 28289c521a..86d84a79e6 100644 --- a/tests/libqos/i2c-imx.c +++ b/tests/libqos/i2c-imx.c @@ -186,10 +186,22 @@ static void imx_i2c_recv(I2CAdapter *i2c, uint8_t add= r, g_assert((status & I2SR_IBB) =3D=3D 0); } =20 +static void *imx_i2c_get_driver(void *obj, const char *interface) +{ + IMXI2C *s =3D obj; + if (!g_strcmp0(interface, "i2c-bus")) { + return &s->parent; + } + fprintf(stderr, "%s not present in imx-i2c\n", interface); + g_assert_not_reached(); +} + void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr) { s->addr =3D addr; =20 + s->obj.get_driver =3D imx_i2c_get_driver; + s->parent.send =3D imx_i2c_send; s->parent.recv =3D imx_i2c_recv; s->parent.qts =3D qts; @@ -213,3 +225,11 @@ void imx_i2c_free(I2CAdapter *i2c) s =3D container_of(i2c, IMXI2C, parent); g_free(s); } + +static void imx_i2c_register_nodes(void) +{ + qos_node_create_driver("imx.i2c", NULL); + qos_node_produces("imx.i2c", "i2c-bus"); +} + +libqos_init(imx_i2c_register_nodes); diff --git a/tests/libqos/i2c-omap.c b/tests/libqos/i2c-omap.c index c7cbb9ecdd..f94956488c 100644 --- a/tests/libqos/i2c-omap.c +++ b/tests/libqos/i2c-omap.c @@ -155,20 +155,36 @@ static void omap_i2c_recv(I2CAdapter *i2c, uint8_t ad= dr, g_assert((data & OMAP_I2C_CON_STP) =3D=3D 0); } =20 -void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr) +static void *omap_i2c_get_driver(void *obj, const char *interface) +{ + OMAPI2C *s =3D obj; + if (!g_strcmp0(interface, "i2c-bus")) { + return &s->parent; + } + fprintf(stderr, "%s not present in omap_i2c\n", interface); + g_assert_not_reached(); +} + +static void omap_i2c_start_hw(QOSGraphObject *object) { - I2CAdapter *i2c =3D (I2CAdapter *)s; + OMAPI2C *s =3D (OMAPI2C *) object; uint16_t data; =20 + /* verify the mmio address by looking for a known signature */ + data =3D qtest_readw(s->parent.qts, s->addr + OMAP_I2C_REV); + g_assert_cmphex(data, =3D=3D, 0x34); +} + +void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr) +{ s->addr =3D addr; =20 - i2c->send =3D omap_i2c_send; - i2c->recv =3D omap_i2c_recv; - i2c->qts =3D qts; + s->obj.get_driver =3D omap_i2c_get_driver; + s->obj.start_hw =3D omap_i2c_start_hw; =20 - /* verify the mmio address by looking for a known signature */ - data =3D qtest_readw(qts, addr + OMAP_I2C_REV); - g_assert_cmphex(data, =3D=3D, 0x34); + s->parent.send =3D omap_i2c_send; + s->parent.recv =3D omap_i2c_recv; + s->parent.qts =3D qts; } =20 I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr) @@ -189,3 +205,11 @@ void omap_i2c_free(I2CAdapter *i2c) s =3D container_of(i2c, OMAPI2C, parent); g_free(s); } + +static void omap_i2c_register_nodes(void) +{ + qos_node_create_driver("omap_i2c", NULL); + qos_node_produces("omap_i2c", "i2c-bus"); +} + +libqos_init(omap_i2c_register_nodes); diff --git a/tests/libqos/i2c.c b/tests/libqos/i2c.c index daf9a96617..8117d13170 100644 --- a/tests/libqos/i2c.c +++ b/tests/libqos/i2c.c @@ -68,3 +68,11 @@ void i2c_set16(I2CAdapter *i2c, uint8_t addr, uint8_t re= g, data[1] =3D value & 255; i2c_write_block(i2c, addr, reg, data, sizeof(data)); } + +void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr) +{ + QI2CDevice *i2cdev =3D g_new0(QI2CDevice, 1); + + i2cdev->bus =3D i2c_bus; + return &i2cdev->obj; +} diff --git a/tests/libqos/i2c.h b/tests/libqos/i2c.h index 877d2ab0e8..0107cfc633 100644 --- a/tests/libqos/i2c.h +++ b/tests/libqos/i2c.h @@ -10,6 +10,7 @@ #define LIBQOS_I2C_H =20 #include "libqtest.h" +#include "libqos/qgraph.h" =20 typedef struct I2CAdapter I2CAdapter; struct I2CAdapter { @@ -21,8 +22,26 @@ struct I2CAdapter { QTestState *qts; }; =20 +typedef struct QI2CDevice QI2CDevice; +struct QI2CDevice { + /* + * For now, all devices are simple enough that there is no need for + * them to define their own constructor and get_driver functions. + * Therefore, QOSGraphObject is included directly in QI2CDevice; + * the tests expect to get a QI2CDevice rather than doing something + * like obj->get_driver("i2c-device"). + * + * In fact there is no i2c-device interface even, because there are + * no generic I2C tests. + */ + QOSGraphObject obj; + I2CAdapter *bus; +}; + #define OMAP2_I2C_1_BASE 0x48070000 =20 +void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr); + void i2c_send(I2CAdapter *i2c, uint8_t addr, const uint8_t *buf, uint16_t len); void i2c_recv(I2CAdapter *i2c, uint8_t addr, @@ -41,6 +60,7 @@ void i2c_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg, =20 /* i2c-omap.c */ typedef struct OMAPI2C { + QOSGraphObject obj; I2CAdapter parent; =20 uint64_t addr; @@ -52,6 +72,7 @@ void omap_i2c_free(I2CAdapter *i2c); =20 /* i2c-imx.c */ typedef struct IMXI2C { + QOSGraphObject obj; I2CAdapter parent; =20 uint64_t addr; --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552931189100172.05794065403643; Mon, 18 Mar 2019 10:46:29 -0700 (PDT) Received: from localhost ([127.0.0.1]:45236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wLB-0007bj-3e for importer@patchew.org; Mon, 18 Mar 2019 13:46:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4u-0004CI-Af for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrK-0003UT-Ni for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57504) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrK-0003Tj-8H for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 898B13082E64 for ; Mon, 18 Mar 2019 17:15:33 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id D21675D70E for ; Mon, 18 Mar 2019 17:15:32 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:17 +0100 Message-Id: <20190318171521.8524-10-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 18 Mar 2019 17:15:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 09/13] libqos: add ARM n800 machine object 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This is used to test omap_i2c. Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/arm-n800-machine.c | 92 +++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tests/libqos/arm-n800-machine.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 44f77230c6..53ac5c35c2 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -730,6 +730,7 @@ qos-test-obj-y +=3D tests/libqos/virtio-serial.o =20 # Machines qos-test-obj-y +=3D tests/libqos/aarch64-xlnx-zcu102-machine.o +qos-test-obj-y +=3D tests/libqos/arm-n800-machine.o qos-test-obj-y +=3D tests/libqos/arm-raspi2-machine.o qos-test-obj-y +=3D tests/libqos/arm-sabrelite-machine.o qos-test-obj-y +=3D tests/libqos/arm-smdkc210-machine.o diff --git a/tests/libqos/arm-n800-machine.c b/tests/libqos/arm-n800-machin= e.c new file mode 100644 index 0000000000..87279bdb26 --- /dev/null +++ b/tests/libqos/arm-n800-machine.c @@ -0,0 +1,92 @@ +/* + * libqos driver framework + * + * Copyright (c) 2019 Red Hat, Inc. + * + * Author: Paolo Bonzini + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/malloc.h" +#include "libqos/qgraph.h" +#include "libqos/i2c.h" + +#define ARM_PAGE_SIZE 4096 +#define N800_RAM_START 0x80000000 +#define N800_RAM_END 0x88000000 + +typedef struct QN800Machine QN800Machine; + +struct QN800Machine { + QOSGraphObject obj; + QGuestAllocator alloc; + OMAPI2C i2c_1; +}; + +static void *n800_get_driver(void *object, const char *interface) +{ + QN800Machine *machine =3D object; + if (!g_strcmp0(interface, "memory")) { + return &machine->alloc; + } + + fprintf(stderr, "%s not present in arm/n800\n", interface); + g_assert_not_reached(); +} + +static QOSGraphObject *n800_get_device(void *obj, const char *device) +{ + QN800Machine *machine =3D obj; + if (!g_strcmp0(device, "omap_i2c")) { + return &machine->i2c_1.obj; + } + + fprintf(stderr, "%s not present in arm/n800\n", device); + g_assert_not_reached(); +} + +static void n800_destructor(QOSGraphObject *obj) +{ + QN800Machine *machine =3D (QN800Machine *) obj; + alloc_destroy(&machine->alloc); +} + +static void *qos_create_machine_arm_n800(QTestState *qts) +{ + QN800Machine *machine =3D g_new0(QN800Machine, 1); + + alloc_init(&machine->alloc, 0, + N800_RAM_START, + N800_RAM_END, + ARM_PAGE_SIZE); + machine->obj.get_device =3D n800_get_device; + machine->obj.get_driver =3D n800_get_driver; + machine->obj.destructor =3D n800_destructor; + + omap_i2c_init(&machine->i2c_1, qts, 0x48070000); + return &machine->obj; +} + +static void n800_register_nodes(void) +{ + QOSGraphEdgeOptions edge =3D { + .extra_device_opts =3D "bus=3Di2c-bus.0" + }; + qos_node_create_machine("arm/n800", qos_create_machine_arm_n800); + qos_node_contains("arm/n800", "omap_i2c", &edge, NULL); +} + +libqos_init(n800_register_nodes); --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552930535143792.6305439530438; Mon, 18 Mar 2019 10:35:35 -0700 (PDT) Received: from localhost ([127.0.0.1]:44987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wAc-00086Y-6g for importer@patchew.org; Mon, 18 Mar 2019 13:35:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4u-0004DZ-92 for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrL-0003VD-Tf for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57172) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrL-0003Ud-Dj for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AAD2E2C971E for ; Mon, 18 Mar 2019 17:15:34 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2A745D70E for ; Mon, 18 Mar 2019 17:15:33 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:18 +0100 Message-Id: <20190318171521.8524-11-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 18 Mar 2019 17:15:34 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 10/13] libqos: add ARM imx25-pdk machine object 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This is used to test imx_i2c. Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/arm-imx25-pdk-machine.c | 92 ++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tests/libqos/arm-imx25-pdk-machine.c diff --git a/tests/Makefile.include b/tests/Makefile.include index 53ac5c35c2..31f9852b8b 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -730,6 +730,7 @@ qos-test-obj-y +=3D tests/libqos/virtio-serial.o =20 # Machines qos-test-obj-y +=3D tests/libqos/aarch64-xlnx-zcu102-machine.o +qos-test-obj-y +=3D tests/libqos/arm-imx25-pdk-machine.o qos-test-obj-y +=3D tests/libqos/arm-n800-machine.o qos-test-obj-y +=3D tests/libqos/arm-raspi2-machine.o qos-test-obj-y +=3D tests/libqos/arm-sabrelite-machine.o diff --git a/tests/libqos/arm-imx25-pdk-machine.c b/tests/libqos/arm-imx25-= pdk-machine.c new file mode 100644 index 0000000000..25066fb8a9 --- /dev/null +++ b/tests/libqos/arm-imx25-pdk-machine.c @@ -0,0 +1,92 @@ +/* + * libqos driver framework + * + * Copyright (c) 2019 Red Hat, Inc. + * + * Author: Paolo Bonzini + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/malloc.h" +#include "libqos/qgraph.h" +#include "libqos/i2c.h" + +#define ARM_PAGE_SIZE 4096 +#define IMX25_PDK_RAM_START 0x80000000 +#define IMX25_PDK_RAM_END 0x88000000 + +typedef struct QIMX25PDKMachine QIMX25PDKMachine; + +struct QIMX25PDKMachine { + QOSGraphObject obj; + QGuestAllocator alloc; + IMXI2C i2c_1; +}; + +static void *imx25_pdk_get_driver(void *object, const char *interface) +{ + QIMX25PDKMachine *machine =3D object; + if (!g_strcmp0(interface, "memory")) { + return &machine->alloc; + } + + fprintf(stderr, "%s not present in arm/imx25_pdk\n", interface); + g_assert_not_reached(); +} + +static QOSGraphObject *imx25_pdk_get_device(void *obj, const char *device) +{ + QIMX25PDKMachine *machine =3D obj; + if (!g_strcmp0(device, "imx.i2c")) { + return &machine->i2c_1.obj; + } + + fprintf(stderr, "%s not present in arm/imx25_pdk\n", device); + g_assert_not_reached(); +} + +static void imx25_pdk_destructor(QOSGraphObject *obj) +{ + QIMX25PDKMachine *machine =3D (QIMX25PDKMachine *) obj; + alloc_destroy(&machine->alloc); +} + +static void *qos_create_machine_arm_imx25_pdk(QTestState *qts) +{ + QIMX25PDKMachine *machine =3D g_new0(QIMX25PDKMachine, 1); + + alloc_init(&machine->alloc, 0, + IMX25_PDK_RAM_START, + IMX25_PDK_RAM_END, + ARM_PAGE_SIZE); + machine->obj.get_device =3D imx25_pdk_get_device; + machine->obj.get_driver =3D imx25_pdk_get_driver; + machine->obj.destructor =3D imx25_pdk_destructor; + + imx_i2c_init(&machine->i2c_1, qts, 0x43f80000); + return &machine->obj; +} + +static void imx25_pdk_register_nodes(void) +{ + QOSGraphEdgeOptions edge =3D { + .extra_device_opts =3D "bus=3Di2c-bus.0" + }; + qos_node_create_machine("arm/imx25-pdk", qos_create_machine_arm_imx25_= pdk); + qos_node_contains("arm/imx25-pdk", "imx.i2c", &edge, NULL); +} + +libqos_init(imx25_pdk_register_nodes); --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552930554682565.9873146743361; Mon, 18 Mar 2019 10:35:54 -0700 (PDT) Received: from localhost ([127.0.0.1]:45010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wAr-0008Kk-K9 for importer@patchew.org; Mon, 18 Mar 2019 13:35:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4u-0004Bv-8c for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrM-0003Vk-WD for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59426) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrM-0003VH-Gj for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D4359308FBA9 for ; Mon, 18 Mar 2019 17:15:35 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BC855D70E for ; Mon, 18 Mar 2019 17:15:34 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:19 +0100 Message-Id: <20190318171521.8524-12-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 18 Mar 2019 17:15:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 11/13] tests: convert OMAP i2c tests to qgraph 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This way, pca9952-test and tmp105-test will run for every machine that exposes an i2c-bus. Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 9 +++------ tests/libqos/i2c-omap.c | 19 ------------------ tests/libqos/i2c.h | 4 ---- tests/pca9552-test.c | 44 ++++++++++++++++++----------------------- tests/tmp105-test.c | 32 +++++++++++------------------- 5 files changed, 34 insertions(+), 74 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 31f9852b8b..54c1ecd668 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -255,8 +255,6 @@ check-qtest-sparc64-$(CONFIG_ISA_TESTDEV) =3D tests/end= ianness-test$(EXESUF) check-qtest-sparc64-y +=3D tests/prom-env-test$(EXESUF) check-qtest-sparc64-y +=3D tests/boot-serial-test$(EXESUF) =20 -check-qtest-arm-y +=3D tests/tmp105-test$(EXESUF) -check-qtest-arm-y +=3D tests/pca9552-test$(EXESUF) check-qtest-arm-y +=3D tests/ds1338-test$(EXESUF) check-qtest-arm-y +=3D tests/microbit-test$(EXESUF) check-qtest-arm-y +=3D tests/m25p80-test$(EXESUF) @@ -705,7 +703,6 @@ libqos-spapr-obj-y +=3D tests/libqos/pci-spapr.o libqos-pc-obj-y =3D $(libqos-obj-y) tests/libqos/pci-pc.o libqos-pc-obj-y +=3D tests/libqos/malloc-pc.o tests/libqos/libqos-pc.o libqos-pc-obj-y +=3D tests/libqos/ahci.o -libqos-omap-obj-y =3D $(libqos-obj-y) tests/libqos/i2c-omap.o libqos-imx-obj-y =3D $(libqos-obj-y) tests/libqos/i2c-imx.o libqos-usb-obj-y =3D $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos= /usb.o =20 @@ -714,7 +711,7 @@ qos-test-obj-y =3D tests/qos-test.o $(libqgraph-obj-y) qos-test-obj-y +=3D $(libqos-pc-obj-y) $(libqos-spapr-obj-y) qos-test-obj-y +=3D tests/libqos/e1000e.o qos-test-obj-y +=3D $(libqos-imx-obj-y) -qos-test-obj-y +=3D $(libqos-omap-obj-y) +qos-test-obj-y +=3D tests/libqos/i2c-omap.o qos-test-obj-y +=3D tests/libqos/sdhci.o qos-test-obj-y +=3D tests/libqos/tpci200.o qos-test-obj-y +=3D tests/libqos/virtio.o @@ -750,10 +747,12 @@ qos-test-obj-y +=3D tests/ipoctal232-test.o qos-test-obj-y +=3D tests/megasas-test.o qos-test-obj-y +=3D tests/ne2000-test.o qos-test-obj-y +=3D tests/nvme-test.o +qos-test-obj-y +=3D tests/pca9552-test.o qos-test-obj-y +=3D tests/pci-test.o qos-test-obj-y +=3D tests/pcnet-test.o qos-test-obj-y +=3D tests/sdhci-test.o qos-test-obj-y +=3D tests/spapr-phb-test.o +qos-test-obj-y +=3D tests/tmp105-test.o qos-test-obj-y +=3D tests/usb-hcd-ohci-test.o $(libqos-usb-obj-y) qos-test-obj-$(CONFIG_VHOST_NET_USER) +=3D tests/vhost-user-test.o $(chard= ev-obj-y) $(test-io-obj-y) qos-test-obj-y +=3D tests/virtio-test.o @@ -791,8 +790,6 @@ tests/boot-serial-test$(EXESUF): tests/boot-serial-test= .o $(libqos-obj-y) tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \ tests/boot-sector.o tests/acpi-utils.o $(libqos-obj-y) tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj= -y) -tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) -tests/pca9552-test$(EXESUF): tests/pca9552-test.o $(libqos-omap-obj-y) tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y) tests/microbit-test$(EXESUF): tests/microbit-test.o tests/m25p80-test$(EXESUF): tests/m25p80-test.o diff --git a/tests/libqos/i2c-omap.c b/tests/libqos/i2c-omap.c index f94956488c..9ae8214fa8 100644 --- a/tests/libqos/i2c-omap.c +++ b/tests/libqos/i2c-omap.c @@ -187,25 +187,6 @@ void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64= _t addr) s->parent.qts =3D qts; } =20 -I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr) -{ - OMAPI2C *s =3D g_malloc0(sizeof(*s)); - - omap_i2c_init(s, qts, addr); - return &s->parent; -} - -void omap_i2c_free(I2CAdapter *i2c) -{ - OMAPI2C *s; - - if (!i2c) { - return; - } - s =3D container_of(i2c, OMAPI2C, parent); - g_free(s); -} - static void omap_i2c_register_nodes(void) { qos_node_create_driver("omap_i2c", NULL); diff --git a/tests/libqos/i2c.h b/tests/libqos/i2c.h index 0107cfc633..66b0e0d06e 100644 --- a/tests/libqos/i2c.h +++ b/tests/libqos/i2c.h @@ -38,8 +38,6 @@ struct QI2CDevice { I2CAdapter *bus; }; =20 -#define OMAP2_I2C_1_BASE 0x48070000 - void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr); =20 void i2c_send(I2CAdapter *i2c, uint8_t addr, @@ -67,8 +65,6 @@ typedef struct OMAPI2C { } OMAPI2C; =20 void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr); -I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr); -void omap_i2c_free(I2CAdapter *i2c); =20 /* i2c-imx.c */ typedef struct IMXI2C { diff --git a/tests/pca9552-test.c b/tests/pca9552-test.c index f9509324e2..0598d0b1eb 100644 --- a/tests/pca9552-test.c +++ b/tests/pca9552-test.c @@ -10,23 +10,26 @@ #include "qemu/osdep.h" =20 #include "libqtest.h" +#include "libqos/qgraph.h" #include "libqos/i2c.h" #include "hw/misc/pca9552_regs.h" =20 #define PCA9552_TEST_ID "pca9552-test" #define PCA9552_TEST_ADDR 0x60 =20 -static I2CAdapter *i2c; - -static void pca9552_init(I2CAdapter *i2c) +static void pca9552_init(QI2CDevice *i2cdev) { + I2CAdapter *i2c =3D i2cdev->bus; + /* Switch on LEDs 0 and 12 */ i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54); i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54); } =20 -static void receive_autoinc(void) +static void receive_autoinc(void *obj, void *data, QGuestAllocator *alloc) { + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + I2CAdapter *i2c =3D i2cdev->bus; uint8_t resp; uint8_t reg =3D PCA9552_LS0 | PCA9552_AUTOINC; =20 @@ -51,8 +54,10 @@ static void receive_autoinc(void) g_assert_cmphex(resp, =3D=3D, 0x54); } =20 -static void send_and_receive(void) +static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc) { + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + I2CAdapter *i2c =3D i2cdev->bus; uint8_t value; =20 value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0); @@ -76,27 +81,16 @@ static void send_and_receive(void) g_assert_cmphex(value, =3D=3D, 0x10); } =20 -int main(int argc, char **argv) +static void pca9552_register_nodes(void) { - QTestState *s =3D NULL; - int ret; - - g_test_init(&argc, &argv, NULL); - - s =3D qtest_start("-machine n800 " - "-device pca9552,bus=3Di2c-bus.0,id=3D" PCA9552_TEST_ID - ",address=3D0x60"); - i2c =3D omap_i2c_create(s, OMAP2_I2C_1_BASE); - - qtest_add_func("/pca9552/tx-rx", send_and_receive); - qtest_add_func("/pca9552/rx-autoinc", receive_autoinc); - - ret =3D g_test_run(); + QOSGraphEdgeOptions opts =3D { + .extra_device_opts =3D "address=3D0x60" + }; =20 - if (s) { - qtest_quit(s); - } - omap_i2c_free(i2c); + qos_node_create_driver("pca9552", i2c_device_create); + qos_node_consumes("pca9552", "i2c-bus", &opts); =20 - return ret; + qos_add_test("tx-rx", "pca9552", send_and_receive, NULL); + qos_add_test("rx-autoinc", "pca9552", receive_autoinc, NULL); } +libqos_init(pca9552_register_nodes); diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c index 25ea05f5fd..4031876387 100644 --- a/tests/tmp105-test.c +++ b/tests/tmp105-test.c @@ -10,6 +10,7 @@ #include "qemu/osdep.h" =20 #include "libqtest.h" +#include "libqos/qgraph.h" #include "libqos/i2c.h" #include "qapi/qmp/qdict.h" #include "hw/misc/tmp105_regs.h" @@ -17,8 +18,6 @@ #define TMP105_TEST_ID "tmp105-test" #define TMP105_TEST_ADDR 0x49 =20 -static I2CAdapter *i2c; - static int qmp_tmp105_get_temperature(const char *id) { QDict *response; @@ -43,9 +42,11 @@ static void qmp_tmp105_set_temperature(const char *id, i= nt value) } =20 #define TMP105_PRECISION (1000/16) -static void send_and_receive(void) +static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc) { uint16_t value; + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + I2CAdapter *i2c =3D i2cdev->bus; =20 value =3D qmp_tmp105_get_temperature(TMP105_TEST_ID); g_assert_cmpuint(value, =3D=3D, 0); @@ -105,24 +106,15 @@ static void send_and_receive(void) g_assert_cmphex(i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_HIGH), = =3D=3D, 0x4231); } =20 -int main(int argc, char **argv) +static void tmp105_register_nodes(void) { - QTestState *s =3D NULL; - int ret; - - g_test_init(&argc, &argv, NULL); - - s =3D qtest_start("-machine n800 " - "-device tmp105,bus=3Di2c-bus.0,id=3D" TMP105_TEST_ID - ",address=3D0x49"); - i2c =3D omap_i2c_create(s, OMAP2_I2C_1_BASE); + QOSGraphEdgeOptions opts =3D { + .extra_device_opts =3D "id=3D" TMP105_TEST_ID ",address=3D0x49" + }; =20 - qtest_add_func("/tmp105/tx-rx", send_and_receive); + qos_node_create_driver("tmp105", i2c_device_create); + qos_node_consumes("tmp105", "i2c-bus", &opts); =20 - ret =3D g_test_run(); - - qtest_quit(s); - omap_i2c_free(i2c); - - return ret; + qos_add_test("tx-rx", "tmp105", send_and_receive, NULL); } +libqos_init(tmp105_register_nodes); --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552930877008962.4435076391186; Mon, 18 Mar 2019 10:41:17 -0700 (PDT) Received: from localhost ([127.0.0.1]:45116 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wG8-0003vh-U1 for importer@patchew.org; Mon, 18 Mar 2019 13:41:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4u-0004C0-4Q for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrO-0003Wb-3B for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59484) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrN-0003Vs-KK for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0912308FB8A for ; Mon, 18 Mar 2019 17:15:36 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F3605D70E for ; Mon, 18 Mar 2019 17:15:36 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:20 +0100 Message-Id: <20190318171521.8524-13-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 18 Mar 2019 17:15:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 12/13] tests: convert ds1338-test to qtest 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This way, ds1338-test will run for every machine that exposes an i2c-bus. Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 8 ++++---- tests/ds1338-test.c | 37 +++++++++++++------------------------ tests/libqos/i2c-imx.c | 19 ------------------- tests/libqos/i2c.h | 2 -- 4 files changed, 17 insertions(+), 49 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 54c1ecd668..67cf89bed8 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -695,7 +695,7 @@ libqgraph-obj-y =3D tests/libqos/qgraph.o =20 libqos-obj-y =3D $(libqgraph-obj-y) tests/libqos/pci.o tests/libqos/fw_cfg= .o libqos-obj-y +=3D tests/libqos/malloc.o -libqos-obj-y +=3D tests/libqos/i2c.o tests/libqos/libqos.o +libqos-obj-y +=3D tests/libqos/libqos.o libqos-spapr-obj-y =3D $(libqos-obj-y) tests/libqos/malloc-spapr.o libqos-spapr-obj-y +=3D tests/libqos/libqos-spapr.o libqos-spapr-obj-y +=3D tests/libqos/rtas.o @@ -703,14 +703,14 @@ libqos-spapr-obj-y +=3D tests/libqos/pci-spapr.o libqos-pc-obj-y =3D $(libqos-obj-y) tests/libqos/pci-pc.o libqos-pc-obj-y +=3D tests/libqos/malloc-pc.o tests/libqos/libqos-pc.o libqos-pc-obj-y +=3D tests/libqos/ahci.o -libqos-imx-obj-y =3D $(libqos-obj-y) tests/libqos/i2c-imx.o libqos-usb-obj-y =3D $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos= /usb.o =20 # Devices qos-test-obj-y =3D tests/qos-test.o $(libqgraph-obj-y) qos-test-obj-y +=3D $(libqos-pc-obj-y) $(libqos-spapr-obj-y) qos-test-obj-y +=3D tests/libqos/e1000e.o -qos-test-obj-y +=3D $(libqos-imx-obj-y) +qos-test-obj-y +=3D tests/libqos/i2c.o +qos-test-obj-y +=3D tests/libqos/i2c-imx.o qos-test-obj-y +=3D tests/libqos/i2c-omap.o qos-test-obj-y +=3D tests/libqos/sdhci.o qos-test-obj-y +=3D tests/libqos/tpci200.o @@ -739,6 +739,7 @@ qos-test-obj-y +=3D tests/libqos/x86_64_pc-machine.o =20 # Tests qos-test-obj-y +=3D tests/ac97-test.o +qos-test-obj-y +=3D tests/ds1338-test.o qos-test-obj-y +=3D tests/e1000-test.o qos-test-obj-y +=3D tests/e1000e-test.o qos-test-obj-y +=3D tests/eepro100-test.o @@ -790,7 +791,6 @@ tests/boot-serial-test$(EXESUF): tests/boot-serial-test= .o $(libqos-obj-y) tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \ tests/boot-sector.o tests/acpi-utils.o $(libqos-obj-y) tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj= -y) -tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y) tests/microbit-test$(EXESUF): tests/microbit-test.o tests/m25p80-test$(EXESUF): tests/m25p80-test.o tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y) diff --git a/tests/ds1338-test.c b/tests/ds1338-test.c index bd72a159cb..fd8fbad533 100644 --- a/tests/ds1338-test.c +++ b/tests/ds1338-test.c @@ -21,25 +21,23 @@ #include "libqtest.h" #include "libqos/i2c.h" =20 -#define IMX25_I2C_0_BASE 0x43F80000 - #define DS1338_ADDR 0x68 =20 -static I2CAdapter *i2c; -static uint8_t addr; - static inline uint8_t bcd2bin(uint8_t x) { return ((x) & 0x0f) + ((x) >> 4) * 10; } =20 -static void send_and_receive(void) +static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc) { + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + I2CAdapter *i2c =3D i2cdev->bus; + uint8_t resp[7]; time_t now =3D time(NULL); struct tm *tm_ptr =3D gmtime(&now); =20 - i2c_read_block(i2c, addr, 0, resp, sizeof(resp)); + i2c_read_block(i2c, DS1338_ADDR, 0, resp, sizeof(resp)); =20 /* check retrieved time againt local time */ g_assert_cmpuint(bcd2bin(resp[4]), =3D=3D , tm_ptr->tm_mday); @@ -47,23 +45,14 @@ static void send_and_receive(void) g_assert_cmpuint(2000 + bcd2bin(resp[6]), =3D=3D , 1900 + tm_ptr->tm_y= ear); } =20 -int main(int argc, char **argv) +static void ds1338_register_nodes(void) { - QTestState *s =3D NULL; - int ret; - - g_test_init(&argc, &argv, NULL); - - s =3D qtest_start("-display none -machine imx25-pdk -device ds1338,add= ress=3D0x68"); - i2c =3D imx_i2c_create(s, IMX25_I2C_0_BASE); - addr =3D DS1338_ADDR; - - qtest_add_func("/ds1338/tx-rx", send_and_receive); - - ret =3D g_test_run(); - - qtest_quit(s); - g_free(i2c); + QOSGraphEdgeOptions opts =3D { + .extra_device_opts =3D "address=3D0x68" + }; =20 - return ret; + qos_node_create_driver("ds1338", i2c_device_create); + qos_node_consumes("ds1338", "i2c-bus", &opts); + qos_add_test("tx-rx", "ds1338", send_and_receive, NULL); } +libqos_init(ds1338_register_nodes); diff --git a/tests/libqos/i2c-imx.c b/tests/libqos/i2c-imx.c index 86d84a79e6..f33ece55a3 100644 --- a/tests/libqos/i2c-imx.c +++ b/tests/libqos/i2c-imx.c @@ -207,25 +207,6 @@ void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t= addr) s->parent.qts =3D qts; } =20 -I2CAdapter *imx_i2c_create(QTestState *qts, uint64_t addr) -{ - IMXI2C *s =3D g_malloc0(sizeof(*s)); - - imx_i2c_init(s, qts, addr); - return &s->parent; -} - -void imx_i2c_free(I2CAdapter *i2c) -{ - IMXI2C *s; - - if (!i2c) { - return; - } - s =3D container_of(i2c, IMXI2C, parent); - g_free(s); -} - static void imx_i2c_register_nodes(void) { qos_node_create_driver("imx.i2c", NULL); diff --git a/tests/libqos/i2c.h b/tests/libqos/i2c.h index 66b0e0d06e..2c8cc3eab5 100644 --- a/tests/libqos/i2c.h +++ b/tests/libqos/i2c.h @@ -75,7 +75,5 @@ typedef struct IMXI2C { } IMXI2C; =20 void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr); -I2CAdapter *imx_i2c_create(QTestState *qts, uint64_t addr); -void imx_i2c_free(I2CAdapter *i2c); =20 #endif --=20 2.20.1 From nobody Wed May 1 11:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552931034958305.68316390932785; Mon, 18 Mar 2019 10:43:54 -0700 (PDT) Received: from localhost ([127.0.0.1]:45159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5wIg-0005fj-Ub for importer@patchew.org; Mon, 18 Mar 2019 13:43:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h5w4u-0003qS-0j for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h5vrR-0003YO-Tb for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50278) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h5vrR-0003Y0-HY for qemu-devel@nongnu.org; Mon, 18 Mar 2019 13:15:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDDDE81DE1 for ; Mon, 18 Mar 2019 17:15:40 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F5CB5D70E; Mon, 18 Mar 2019 17:15:37 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 18 Mar 2019 18:15:21 +0100 Message-Id: <20190318171521.8524-14-pbonzini@redhat.com> In-Reply-To: <20190318171521.8524-1-pbonzini@redhat.com> References: <20190318171521.8524-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 18 Mar 2019 17:15:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 13/13] libqos: i2c: move address into QI2CDevice 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: , Cc: Paolo BOnzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This removes the hardcoded I2C address from the tests. The address is passed via QOSGraphEdgeOptions to i2c_device_create and stored in the QI2CDevice. The i2c_send and i2c_recv functions, along with their wrappers, therefore, can be changed to take a QI2CDevice rather than an adapter/address pair. Signed-off-by: Paolo BOnzini --- tests/ds1338-test.c | 4 ++-- tests/libqos/i2c.c | 51 +++++++++++++++++++++++++------------------- tests/libqos/i2c.h | 27 ++++++++++++----------- tests/pca9552-test.c | 31 ++++++++++++--------------- tests/tmp105-test.c | 44 +++++++++++++++++++------------------- 5 files changed, 82 insertions(+), 75 deletions(-) diff --git a/tests/ds1338-test.c b/tests/ds1338-test.c index fd8fbad533..f6ade9a050 100644 --- a/tests/ds1338-test.c +++ b/tests/ds1338-test.c @@ -31,13 +31,12 @@ static inline uint8_t bcd2bin(uint8_t x) static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc) { QI2CDevice *i2cdev =3D (QI2CDevice *)obj; - I2CAdapter *i2c =3D i2cdev->bus; =20 uint8_t resp[7]; time_t now =3D time(NULL); struct tm *tm_ptr =3D gmtime(&now); =20 - i2c_read_block(i2c, DS1338_ADDR, 0, resp, sizeof(resp)); + i2c_read_block(i2cdev, 0, resp, sizeof(resp)); =20 /* check retrieved time againt local time */ g_assert_cmpuint(bcd2bin(resp[4]), =3D=3D , tm_ptr->tm_mday); @@ -50,6 +49,7 @@ static void ds1338_register_nodes(void) QOSGraphEdgeOptions opts =3D { .extra_device_opts =3D "address=3D0x68" }; + add_qi2c_address(&opts, &(QI2CAddress) { DS1338_ADDR }); =20 qos_node_create_driver("ds1338", i2c_device_create); qos_node_consumes("ds1338", "i2c-bus", &opts); diff --git a/tests/libqos/i2c.c b/tests/libqos/i2c.c index 8117d13170..156114e745 100644 --- a/tests/libqos/i2c.c +++ b/tests/libqos/i2c.c @@ -10,63 +10,59 @@ #include "libqos/i2c.h" #include "libqtest.h" =20 -void i2c_send(I2CAdapter *i2c, uint8_t addr, - const uint8_t *buf, uint16_t len) +void i2c_send(QI2CDevice *i2cdev, const uint8_t *buf, uint16_t len) { - i2c->send(i2c, addr, buf, len); + i2cdev->bus->send(i2cdev->bus, i2cdev->addr, buf, len); } =20 -void i2c_recv(I2CAdapter *i2c, uint8_t addr, - uint8_t *buf, uint16_t len) +void i2c_recv(QI2CDevice *i2cdev, uint8_t *buf, uint16_t len) { - i2c->recv(i2c, addr, buf, len); + i2cdev->bus->recv(i2cdev->bus, i2cdev->addr, buf, len); } =20 -void i2c_read_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg, - uint8_t *buf, uint16_t len) +void i2c_read_block(QI2CDevice *i2cdev, uint8_t reg, + uint8_t *buf, uint16_t len) { - i2c_send(i2c, addr, ®, 1); - i2c_recv(i2c, addr, buf, len); + i2c_send(i2cdev, ®, 1); + i2c_recv(i2cdev, buf, len); } =20 -void i2c_write_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg, +void i2c_write_block(QI2CDevice *i2cdev, uint8_t reg, const uint8_t *buf, uint16_t len) { uint8_t *cmd =3D g_malloc(len + 1); cmd[0] =3D reg; memcpy(&cmd[1], buf, len); - i2c_send(i2c, addr, cmd, len + 1); + i2c_send(i2cdev, cmd, len + 1); g_free(cmd); } =20 -uint8_t i2c_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg) +uint8_t i2c_get8(QI2CDevice *i2cdev, uint8_t reg) { uint8_t resp[1]; - i2c_read_block(i2c, addr, reg, resp, sizeof(resp)); + i2c_read_block(i2cdev, reg, resp, sizeof(resp)); return resp[0]; } =20 -uint16_t i2c_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg) +uint16_t i2c_get16(QI2CDevice *i2cdev, uint8_t reg) { uint8_t resp[2]; - i2c_read_block(i2c, addr, reg, resp, sizeof(resp)); + i2c_read_block(i2cdev, reg, resp, sizeof(resp)); return (resp[0] << 8) | resp[1]; } =20 -void i2c_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg, - uint8_t value) +void i2c_set8(QI2CDevice *i2cdev, uint8_t reg, uint8_t value) { - i2c_write_block(i2c, addr, reg, &value, 1); + i2c_write_block(i2cdev, reg, &value, 1); } =20 -void i2c_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg, - uint16_t value) +void i2c_set16(QI2CDevice *i2cdev, uint8_t reg, uint16_t value) { uint8_t data[2]; =20 data[0] =3D value >> 8; data[1] =3D value & 255; - i2c_write_block(i2c, addr, reg, data, sizeof(data)); + i2c_write_block(i2cdev, reg, data, sizeof(data)); } =20 void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr) @@ -74,5 +70,16 @@ void *i2c_device_create(void *i2c_bus, QGuestAllocator *= alloc, void *addr) QI2CDevice *i2cdev =3D g_new0(QI2CDevice, 1); =20 i2cdev->bus =3D i2c_bus; + if (addr) { + i2cdev->addr =3D ((QI2CAddress *)addr)->addr; + } return &i2cdev->obj; } + +void add_qi2c_address(QOSGraphEdgeOptions *opts, QI2CAddress *addr) +{ + g_assert(addr); + + opts->arg =3D addr; + opts->size_arg =3D sizeof(QI2CAddress); +} diff --git a/tests/libqos/i2c.h b/tests/libqos/i2c.h index 2c8cc3eab5..945b65b34c 100644 --- a/tests/libqos/i2c.h +++ b/tests/libqos/i2c.h @@ -22,6 +22,11 @@ struct I2CAdapter { QTestState *qts; }; =20 +typedef struct QI2CAddress QI2CAddress; +struct QI2CAddress { + uint8_t addr; +}; + typedef struct QI2CDevice QI2CDevice; struct QI2CDevice { /* @@ -36,25 +41,23 @@ struct QI2CDevice { */ QOSGraphObject obj; I2CAdapter *bus; + uint8_t addr; }; =20 void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr); +void add_qi2c_address(QOSGraphEdgeOptions *opts, QI2CAddress *addr); =20 -void i2c_send(I2CAdapter *i2c, uint8_t addr, - const uint8_t *buf, uint16_t len); -void i2c_recv(I2CAdapter *i2c, uint8_t addr, - uint8_t *buf, uint16_t len); +void i2c_send(QI2CDevice *dev, const uint8_t *buf, uint16_t len); +void i2c_recv(QI2CDevice *dev, uint8_t *buf, uint16_t len); =20 -void i2c_read_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg, +void i2c_read_block(QI2CDevice *dev, uint8_t reg, uint8_t *buf, uint16_t len); -void i2c_write_block(I2CAdapter *i2c, uint8_t addr, uint8_t reg, +void i2c_write_block(QI2CDevice *dev, uint8_t reg, const uint8_t *buf, uint16_t len); -uint8_t i2c_get8(I2CAdapter *i2c, uint8_t addr, uint8_t reg); -uint16_t i2c_get16(I2CAdapter *i2c, uint8_t addr, uint8_t reg); -void i2c_set8(I2CAdapter *i2c, uint8_t addr, uint8_t reg, - uint8_t value); -void i2c_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg, - uint16_t value); +uint8_t i2c_get8(QI2CDevice *dev, uint8_t reg); +uint16_t i2c_get16(QI2CDevice *dev, uint8_t reg); +void i2c_set8(QI2CDevice *dev, uint8_t reg, uint8_t value); +void i2c_set16(QI2CDevice *dev, uint8_t reg, uint16_t value); =20 /* i2c-omap.c */ typedef struct OMAPI2C { diff --git a/tests/pca9552-test.c b/tests/pca9552-test.c index 0598d0b1eb..4b800d3c3e 100644 --- a/tests/pca9552-test.c +++ b/tests/pca9552-test.c @@ -19,65 +19,61 @@ =20 static void pca9552_init(QI2CDevice *i2cdev) { - I2CAdapter *i2c =3D i2cdev->bus; - /* Switch on LEDs 0 and 12 */ - i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0, 0x54); - i2c_set8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3, 0x54); + i2c_set8(i2cdev, PCA9552_LS0, 0x54); + i2c_set8(i2cdev, PCA9552_LS3, 0x54); } =20 static void receive_autoinc(void *obj, void *data, QGuestAllocator *alloc) { QI2CDevice *i2cdev =3D (QI2CDevice *)obj; - I2CAdapter *i2c =3D i2cdev->bus; uint8_t resp; uint8_t reg =3D PCA9552_LS0 | PCA9552_AUTOINC; =20 pca9552_init(i2cdev); =20 - i2c_send(i2c, PCA9552_TEST_ADDR, ®, 1); + i2c_send(i2cdev, ®, 1); =20 /* PCA9552_LS0 */ - i2c_recv(i2c, PCA9552_TEST_ADDR, &resp, 1); + i2c_recv(i2cdev, &resp, 1); g_assert_cmphex(resp, =3D=3D, 0x54); =20 /* PCA9552_LS1 */ - i2c_recv(i2c, PCA9552_TEST_ADDR, &resp, 1); + i2c_recv(i2cdev, &resp, 1); g_assert_cmphex(resp, =3D=3D, 0x55); =20 /* PCA9552_LS2 */ - i2c_recv(i2c, PCA9552_TEST_ADDR, &resp, 1); + i2c_recv(i2cdev, &resp, 1); g_assert_cmphex(resp, =3D=3D, 0x55); =20 /* PCA9552_LS3 */ - i2c_recv(i2c, PCA9552_TEST_ADDR, &resp, 1); + i2c_recv(i2cdev, &resp, 1); g_assert_cmphex(resp, =3D=3D, 0x54); } =20 static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc) { QI2CDevice *i2cdev =3D (QI2CDevice *)obj; - I2CAdapter *i2c =3D i2cdev->bus; uint8_t value; =20 - value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0); + value =3D i2c_get8(i2cdev, PCA9552_LS0); g_assert_cmphex(value, =3D=3D, 0x55); =20 - value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0); + value =3D i2c_get8(i2cdev, PCA9552_INPUT0); g_assert_cmphex(value, =3D=3D, 0x0); =20 pca9552_init(i2cdev); =20 - value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS0); + value =3D i2c_get8(i2cdev, PCA9552_LS0); g_assert_cmphex(value, =3D=3D, 0x54); =20 - value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT0); + value =3D i2c_get8(i2cdev, PCA9552_INPUT0); g_assert_cmphex(value, =3D=3D, 0x01); =20 - value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_LS3); + value =3D i2c_get8(i2cdev, PCA9552_LS3); g_assert_cmphex(value, =3D=3D, 0x54); =20 - value =3D i2c_get8(i2c, PCA9552_TEST_ADDR, PCA9552_INPUT1); + value =3D i2c_get8(i2cdev, PCA9552_INPUT1); g_assert_cmphex(value, =3D=3D, 0x10); } =20 @@ -86,6 +82,7 @@ static void pca9552_register_nodes(void) QOSGraphEdgeOptions opts =3D { .extra_device_opts =3D "address=3D0x60" }; + add_qi2c_address(&opts, &(QI2CAddress) { 0x60 }); =20 qos_node_create_driver("pca9552", i2c_device_create); qos_node_consumes("pca9552", "i2c-bus", &opts); diff --git a/tests/tmp105-test.c b/tests/tmp105-test.c index 4031876387..f599309a4a 100644 --- a/tests/tmp105-test.c +++ b/tests/tmp105-test.c @@ -46,19 +46,18 @@ static void send_and_receive(void *obj, void *data, QGu= estAllocator *alloc) { uint16_t value; QI2CDevice *i2cdev =3D (QI2CDevice *)obj; - I2CAdapter *i2c =3D i2cdev->bus; =20 value =3D qmp_tmp105_get_temperature(TMP105_TEST_ID); g_assert_cmpuint(value, =3D=3D, 0); =20 - value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + value =3D i2c_get16(i2cdev, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0); =20 qmp_tmp105_set_temperature(TMP105_TEST_ID, 20000); value =3D qmp_tmp105_get_temperature(TMP105_TEST_ID); g_assert_cmpuint(value, =3D=3D, 20000); =20 - value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + value =3D i2c_get16(i2cdev, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x1400); =20 qmp_tmp105_set_temperature(TMP105_TEST_ID, 20938); /* 20 + 15/16 */ @@ -67,27 +66,27 @@ static void send_and_receive(void *obj, void *data, QGu= estAllocator *alloc) g_assert_cmpuint(value, <, 20938 + TMP105_PRECISION/2); =20 /* Set config */ - i2c_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x60); - value =3D i2c_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG); + i2c_set8(i2cdev, TMP105_REG_CONFIG, 0x60); + value =3D i2c_get8(i2cdev, TMP105_REG_CONFIG); g_assert_cmphex(value, =3D=3D, 0x60); =20 - value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + value =3D i2c_get16(i2cdev, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x14f0); =20 /* Set precision to 9, 10, 11 bits. */ - i2c_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x00); - g_assert_cmphex(i2c_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG), = =3D=3D, 0x00); - value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + i2c_set8(i2cdev, TMP105_REG_CONFIG, 0x00); + g_assert_cmphex(i2c_get8(i2cdev, TMP105_REG_CONFIG), =3D=3D, 0x00); + value =3D i2c_get16(i2cdev, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x1480); =20 - i2c_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x20); - g_assert_cmphex(i2c_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG), = =3D=3D, 0x20); - value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + i2c_set8(i2cdev, TMP105_REG_CONFIG, 0x20); + g_assert_cmphex(i2c_get8(i2cdev, TMP105_REG_CONFIG), =3D=3D, 0x20); + value =3D i2c_get16(i2cdev, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x14c0); =20 - i2c_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x40); - g_assert_cmphex(i2c_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG), = =3D=3D, 0x40); - value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + i2c_set8(i2cdev, TMP105_REG_CONFIG, 0x40); + g_assert_cmphex(i2c_get8(i2cdev, TMP105_REG_CONFIG), =3D=3D, 0x40); + value =3D i2c_get16(i2cdev, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x14e0); =20 /* stored precision remains the same */ @@ -95,15 +94,15 @@ static void send_and_receive(void *obj, void *data, QGu= estAllocator *alloc) g_assert_cmpuint(value, >=3D, 20938 - TMP105_PRECISION/2); g_assert_cmpuint(value, <, 20938 + TMP105_PRECISION/2); =20 - i2c_set8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG, 0x60); - g_assert_cmphex(i2c_get8(i2c, TMP105_TEST_ADDR, TMP105_REG_CONFIG), = =3D=3D, 0x60); - value =3D i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_TEMPERATURE); + i2c_set8(i2cdev, TMP105_REG_CONFIG, 0x60); + g_assert_cmphex(i2c_get8(i2cdev, TMP105_REG_CONFIG), =3D=3D, 0x60); + value =3D i2c_get16(i2cdev, TMP105_REG_TEMPERATURE); g_assert_cmphex(value, =3D=3D, 0x14f0); =20 - i2c_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_LOW, 0x1234); - g_assert_cmphex(i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_LOW), = =3D=3D, 0x1234); - i2c_set16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_HIGH, 0x4231); - g_assert_cmphex(i2c_get16(i2c, TMP105_TEST_ADDR, TMP105_REG_T_HIGH), = =3D=3D, 0x4231); + i2c_set16(i2cdev, TMP105_REG_T_LOW, 0x1234); + g_assert_cmphex(i2c_get16(i2cdev, TMP105_REG_T_LOW), =3D=3D, 0x1234); + i2c_set16(i2cdev, TMP105_REG_T_HIGH, 0x4231); + g_assert_cmphex(i2c_get16(i2cdev, TMP105_REG_T_HIGH), =3D=3D, 0x4231); } =20 static void tmp105_register_nodes(void) @@ -111,6 +110,7 @@ static void tmp105_register_nodes(void) QOSGraphEdgeOptions opts =3D { .extra_device_opts =3D "id=3D" TMP105_TEST_ID ",address=3D0x49" }; + add_qi2c_address(&opts, &(QI2CAddress) { 0x49 }); =20 qos_node_create_driver("tmp105", i2c_device_create); qos_node_consumes("tmp105", "i2c-bus", &opts); --=20 2.20.1