mirror of https://gitee.com/openkylin/qemu.git
libqos: convert I2C to qgraph
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 <pbonzini@redhat.com>
This commit is contained in:
parent
732c919cf0
commit
c0825c63cf
|
@ -694,6 +694,8 @@ libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o
|
||||||
qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y)
|
qos-test-obj-y = tests/qos-test.o $(libqgraph-obj-y)
|
||||||
qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
|
qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y)
|
||||||
qos-test-obj-y += tests/libqos/e1000e.o
|
qos-test-obj-y += tests/libqos/e1000e.o
|
||||||
|
qos-test-obj-y += $(libqos-imx-obj-y)
|
||||||
|
qos-test-obj-y += $(libqos-omap-obj-y)
|
||||||
qos-test-obj-y += tests/libqos/sdhci.o
|
qos-test-obj-y += tests/libqos/sdhci.o
|
||||||
qos-test-obj-y += tests/libqos/tpci200.o
|
qos-test-obj-y += tests/libqos/tpci200.o
|
||||||
qos-test-obj-y += tests/libqos/virtio.o
|
qos-test-obj-y += tests/libqos/virtio.o
|
||||||
|
|
|
@ -186,10 +186,22 @@ static void imx_i2c_recv(I2CAdapter *i2c, uint8_t addr,
|
||||||
g_assert((status & I2SR_IBB) == 0);
|
g_assert((status & I2SR_IBB) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *imx_i2c_get_driver(void *obj, const char *interface)
|
||||||
|
{
|
||||||
|
IMXI2C *s = 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)
|
void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr)
|
||||||
{
|
{
|
||||||
s->addr = addr;
|
s->addr = addr;
|
||||||
|
|
||||||
|
s->obj.get_driver = imx_i2c_get_driver;
|
||||||
|
|
||||||
s->parent.send = imx_i2c_send;
|
s->parent.send = imx_i2c_send;
|
||||||
s->parent.recv = imx_i2c_recv;
|
s->parent.recv = imx_i2c_recv;
|
||||||
s->parent.qts = qts;
|
s->parent.qts = qts;
|
||||||
|
@ -213,3 +225,11 @@ void imx_i2c_free(I2CAdapter *i2c)
|
||||||
s = container_of(i2c, IMXI2C, parent);
|
s = container_of(i2c, IMXI2C, parent);
|
||||||
g_free(s);
|
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);
|
||||||
|
|
|
@ -155,20 +155,36 @@ static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr,
|
||||||
g_assert((data & OMAP_I2C_CON_STP) == 0);
|
g_assert((data & OMAP_I2C_CON_STP) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr)
|
static void *omap_i2c_get_driver(void *obj, const char *interface)
|
||||||
{
|
{
|
||||||
I2CAdapter *i2c = (I2CAdapter *)s;
|
OMAPI2C *s = 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)
|
||||||
|
{
|
||||||
|
OMAPI2C *s = (OMAPI2C *) object;
|
||||||
uint16_t data;
|
uint16_t data;
|
||||||
|
|
||||||
|
/* verify the mmio address by looking for a known signature */
|
||||||
|
data = qtest_readw(s->parent.qts, s->addr + OMAP_I2C_REV);
|
||||||
|
g_assert_cmphex(data, ==, 0x34);
|
||||||
|
}
|
||||||
|
|
||||||
|
void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr)
|
||||||
|
{
|
||||||
s->addr = addr;
|
s->addr = addr;
|
||||||
|
|
||||||
i2c->send = omap_i2c_send;
|
s->obj.get_driver = omap_i2c_get_driver;
|
||||||
i2c->recv = omap_i2c_recv;
|
s->obj.start_hw = omap_i2c_start_hw;
|
||||||
i2c->qts = qts;
|
|
||||||
|
|
||||||
/* verify the mmio address by looking for a known signature */
|
s->parent.send = omap_i2c_send;
|
||||||
data = qtest_readw(qts, addr + OMAP_I2C_REV);
|
s->parent.recv = omap_i2c_recv;
|
||||||
g_assert_cmphex(data, ==, 0x34);
|
s->parent.qts = qts;
|
||||||
}
|
}
|
||||||
|
|
||||||
I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr)
|
I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr)
|
||||||
|
@ -189,3 +205,11 @@ void omap_i2c_free(I2CAdapter *i2c)
|
||||||
s = container_of(i2c, OMAPI2C, parent);
|
s = container_of(i2c, OMAPI2C, parent);
|
||||||
g_free(s);
|
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);
|
||||||
|
|
|
@ -68,3 +68,11 @@ void i2c_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
|
||||||
data[1] = value & 255;
|
data[1] = value & 255;
|
||||||
i2c_write_block(i2c, addr, reg, data, sizeof(data));
|
i2c_write_block(i2c, addr, reg, data, sizeof(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr)
|
||||||
|
{
|
||||||
|
QI2CDevice *i2cdev = g_new0(QI2CDevice, 1);
|
||||||
|
|
||||||
|
i2cdev->bus = i2c_bus;
|
||||||
|
return &i2cdev->obj;
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#define LIBQOS_I2C_H
|
#define LIBQOS_I2C_H
|
||||||
|
|
||||||
#include "libqtest.h"
|
#include "libqtest.h"
|
||||||
|
#include "libqos/qgraph.h"
|
||||||
|
|
||||||
typedef struct I2CAdapter I2CAdapter;
|
typedef struct I2CAdapter I2CAdapter;
|
||||||
struct I2CAdapter {
|
struct I2CAdapter {
|
||||||
|
@ -21,8 +22,26 @@ struct I2CAdapter {
|
||||||
QTestState *qts;
|
QTestState *qts;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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
|
#define OMAP2_I2C_1_BASE 0x48070000
|
||||||
|
|
||||||
|
void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr);
|
||||||
|
|
||||||
void i2c_send(I2CAdapter *i2c, uint8_t addr,
|
void i2c_send(I2CAdapter *i2c, uint8_t addr,
|
||||||
const uint8_t *buf, uint16_t len);
|
const uint8_t *buf, uint16_t len);
|
||||||
void i2c_recv(I2CAdapter *i2c, uint8_t addr,
|
void i2c_recv(I2CAdapter *i2c, uint8_t addr,
|
||||||
|
@ -41,6 +60,7 @@ void i2c_set16(I2CAdapter *i2c, uint8_t addr, uint8_t reg,
|
||||||
|
|
||||||
/* i2c-omap.c */
|
/* i2c-omap.c */
|
||||||
typedef struct OMAPI2C {
|
typedef struct OMAPI2C {
|
||||||
|
QOSGraphObject obj;
|
||||||
I2CAdapter parent;
|
I2CAdapter parent;
|
||||||
|
|
||||||
uint64_t addr;
|
uint64_t addr;
|
||||||
|
@ -52,6 +72,7 @@ void omap_i2c_free(I2CAdapter *i2c);
|
||||||
|
|
||||||
/* i2c-imx.c */
|
/* i2c-imx.c */
|
||||||
typedef struct IMXI2C {
|
typedef struct IMXI2C {
|
||||||
|
QOSGraphObject obj;
|
||||||
I2CAdapter parent;
|
I2CAdapter parent;
|
||||||
|
|
||||||
uint64_t addr;
|
uint64_t addr;
|
||||||
|
|
Loading…
Reference in New Issue