From nobody Mon Feb 9 17:24:26 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; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1559582945; cv=none; d=zoho.com; s=zohoarc; b=DhEA5O2JIcP9BoM9h7d4O1f8vqejbWkGV2T8jeoha9KfQfz4uahHFaVM1ULOk5fYzZ0dVOVIX6lwNHTXR2+6+cRU3Tx2wBp2WrCuetwhb7d9uuCmXCY2Db3Zj9alZbE5yoh+w8f5qscX3ChXipzzsZg4kuUJIn0WZvwoJ92/RZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559582945; h=Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=uoQaRMWdBdep+YNnKReegUQC2lBBqvjSH/ITdZEowUI=; b=XsvpkpB0U0ad0L8HiJMoT/ykCSElwXuFe9NQR34sVftwbjDj7e6d/1xYDUJb98SjFXL+BxeHAUpkvqkJqgC/45uWHYI3r4/KN8uXo0uwRaNC7rYjxRXA9G/FaIpGGNPMzArS/7TKSJsVeo5wJp3hDKnBJeTqoG58ThAWV12ONjY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559582945208719.9551914750383; Mon, 3 Jun 2019 10:29:05 -0700 (PDT) Received: from localhost ([127.0.0.1]:38494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hXqlQ-0004Tg-3m for importer@patchew.org; Mon, 03 Jun 2019 13:28:52 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hXqUQ-0007LI-2J for qemu-devel@nongnu.org; Mon, 03 Jun 2019 13:11:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hXqUO-0004St-2c for qemu-devel@nongnu.org; Mon, 03 Jun 2019 13:11:17 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:53846) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hXqUN-00045w-Ps for qemu-devel@nongnu.org; Mon, 03 Jun 2019 13:11:15 -0400 Received: by mail-wm1-x341.google.com with SMTP id d17so4290234wmb.3 for ; Mon, 03 Jun 2019 10:11:02 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r131sm3325045wmf.4.2019.06.03.10.11.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2019 10:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=uoQaRMWdBdep+YNnKReegUQC2lBBqvjSH/ITdZEowUI=; b=bfmLulX6w/jMAYEgy1HkHwFmlvV3tN3sK8ng3erwovapyAkLK5ofVAV1cAjvFsLkb1 stTKR1LLllzeEhPdnbZ1bIxPrnVaNVk68V3o546vL7cBf2PE9PXrzRiWAfYAXtCnpmcz VA1ornolXIiUjZFsTbSsO40qM58Tuc70mjBtxDXiqipbfLBkVfJblBwIbpgoHBMmQY1u 44DPJH5QX3VCnCshMPtfxyPclAfaRrdxpgP7l0TuPkXGzgI/GIvBWZbXLv5/Go7uVyng 5ILbd6Bng79M4xsj26WTHFmFJbnESwJ7Zt0g0K8xQDupyKBS4nAGbb4ewf9KdkzlyGMA bkRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=uoQaRMWdBdep+YNnKReegUQC2lBBqvjSH/ITdZEowUI=; b=BBo+ELsxyoLERKJ2SkL47MJbv+6Q979VFMCRFSa2fxPFkBarBK/i5NblNQZ6R6584p a6Ius/iGgsMS/PFlWa1dBhXg4p0rCMz7cZHTQoxBmjesiB3qH0t8hUUt7hVvYeGnRASu DvkLYfxMyJ/YSmat9f8F4PBUQ/jqztBdjRQh9oOCtIHAdNJ/W9ukL1A4si48AXSD82UV AYW6wAq1a6iLsHNM5SFsfJ36Gb1fqUtyq+KINB6ZVfBv88x6TWfJCaJua6bzeD7wWHTX KNB3zChR+RB0GUtMYKJrFWw9QxYL3tNHAah2/7fhM7kzmjUI1HXKJg/WCkDMSwwez/f/ iGoQ== X-Gm-Message-State: APjAAAWnnb4F9yIsaqFBbMatF33zl51i5RujzT1Xi9o80Dg69CrvTT30 gAwSDEmySuPyi9itO+cHs4qj7PVC X-Google-Smtp-Source: APXvYqzyAKonLVWMKV2uDNSlbYewUd+j2k/H2HEUb0YkWqLxIjIMmWJmZ2IFlVQmO6C6sUgDqpoY8A== X-Received: by 2002:a1c:6c04:: with SMTP id h4mr14601664wmc.135.1559581861355; Mon, 03 Jun 2019 10:11:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 3 Jun 2019 19:10:34 +0200 Message-Id: <1559581843-3968-16-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1559581843-3968-1-git-send-email-pbonzini@redhat.com> References: <1559581843-3968-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PULL 15/24] 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 0945f2e..28289c5 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 bb65336..c7cbb9e 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 a462114..877d2ab 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 89b4445..f950932 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 c86d257..25ea05f 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 1.8.3.1