From nobody Tue Feb 10 01:16:15 2026 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