From nobody Fri May 10 20:39:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1628293899; cv=none; d=zohomail.com; s=zohoarc; b=ZmnTXkwMqHLPYhNVnJEjbuCaiYA2sy5abhQjuxm17pWsWN3WhgvNJ34xfRF47FmfEwbg1lFV6pcYRaRb4/5zfl6c/GgnpQpHIlk+3nCQsXVzzjdZJcXf10nnr4zxB4SmGEUF4U4+078qA9ENP+kDGdOsd5LOmnwS+FcXScIVLBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628293899; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pScfXTzd1F7hEhd63X3i506fl3OGOhBilrzIlNVPX4U=; b=clwAKD23SrBA6/EoGktmoAaV4P7wZHLhDcoEojfAkcQflj83YTo2Z796wbDwyicxwq7+KMYMKENWTKZMzvgrDIfkJJr7QRYV++yPgV39iZn9BWYfPfEToKU4azuTnoeYc3vW1cZESwH5Y4nC4V82LUJTEAhTrgBzs4pyAeoFXSU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162829389988164.6747335866063; Fri, 6 Aug 2021 16:51:39 -0700 (PDT) Received: from localhost ([::1]:45654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mC9co-0001yd-OD for importer@patchew.org; Fri, 06 Aug 2021 19:51:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3gsoNYQUKCl0NOH5JBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--stmao.bounces.google.com>) id 1mC9aj-0005Oc-5U for qemu-devel@nongnu.org; Fri, 06 Aug 2021 19:49:29 -0400 Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]:34591) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3gsoNYQUKCl0NOH5JBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--stmao.bounces.google.com>) id 1mC9ad-0002s9-S6 for qemu-devel@nongnu.org; Fri, 06 Aug 2021 19:49:27 -0400 Received: by mail-qk1-x74a.google.com with SMTP id o2-20020a05620a1102b02903b9ade0af31so2985828qkk.1 for ; Fri, 06 Aug 2021 16:49:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=pScfXTzd1F7hEhd63X3i506fl3OGOhBilrzIlNVPX4U=; b=cw/njWdWyvlcg+LE7YZxEaWAAi4If3SSthfWQpTiOIinv6I47jpgVcrjmDtC5ezqRu lD30jHl1upmBht5dsifqIw0Q8G38+uOCwodX/n45uLU0SwXyZ/RRTfndZgromhJuSyaw 9NoQi9JTBkpLYmJjmLsMjD08Hgnu4x/Pc5VzTbKwAXlUeAMRW0ONDtBis0r6owElvtvE hBF/KOO8SdkueZnVNpgEUPWOWH/qUJqTwWpgc1r0M0IdgWHqRKRE6LdaNhmn9Z7r9gBs HVy16vy9ETeR6ZXBW7WiHlqctBVvnOcl0mS1ndoyL5ohqSWsSftwX3KDkxjuqNyCe49K 2PaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=pScfXTzd1F7hEhd63X3i506fl3OGOhBilrzIlNVPX4U=; b=Z+IDlVkEigxHTz6X2bkMkiZUj01H7m0K6EMq//V6rWFPjCNISmSCWLXBUUOeVyqSYv FTxpzY0Lj+CuOK3FtzYZOXX3zdcMY/JIVM7c6NqzQdGRxc+nr2vqG5rYQ6sjyO8BIdK0 olAMz8q66yhXf0kqTujnCI66qge5ps/HJfghxGvcYsPx4cCH8SHZWwzhFxdC7XTBMVz1 jBFvYMjDn7Aat2n6Y/Q/17Ussv9g0x1xgtcxINHmyVN/PlRxSiTw5abio4N4Kbj6kl2q vR8q4p3ptrg/hzNrQ8y31YFvb2QEQRtdf9g84xw02m7F71xQCMrvgg8j/YgO1KG3BE4s J/+w== X-Gm-Message-State: AOAM530O1T506Av3AyMW/trY3eQupjZ6ittGT+6CZnNfbdnnp/0moSzq yJb87emvhYa/+2tCMD/L6js4uHQzJA== X-Google-Smtp-Source: ABdhPJyW8WSVp99Hh3f/kIsGOOMoF7s06JlDsWAvNDPFfE5i/t3qHdnxNTLscMVNbrO7X8kmP+kPyES5jA== X-Received: from smvm.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2d5f]) (user=stmao job=sendgmr) by 2002:ad4:4312:: with SMTP id c18mr2476675qvs.54.1628293762103; Fri, 06 Aug 2021 16:49:22 -0700 (PDT) Date: Fri, 6 Aug 2021 23:49:17 +0000 In-Reply-To: <20210806234918.122457-1-stmao@google.com> Message-Id: <20210806234918.122457-2-stmao@google.com> Mime-Version: 1.0 References: <20210806234918.122457-1-stmao@google.com> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog Subject: [PATCH v4 1/2] hw/i2c: add remote I2C device From: Shengtan Mao To: cminyard@mvista.com Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, crauer@google.com, wuhaotsh@google.com, venture@google.com, maoshengtan2011@gmail.com, Shengtan Mao Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::74a; envelope-from=3gsoNYQUKCl0NOH5JBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--stmao.bounces.google.com; helo=mail-qk1-x74a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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: pass (identity @google.com) X-ZM-MESSAGEID: 1628293901623100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch adds the remote I2C device, which supports the usage of external I2C devices. Signed-off-by: Shengtan Mao --- hw/arm/Kconfig | 1 + hw/i2c/Kconfig | 4 + hw/i2c/meson.build | 1 + hw/i2c/remote-i2c.c | 117 ++++++++++++++++++ tests/qtest/meson.build | 1 + tests/qtest/remote-i2c-test.c | 216 ++++++++++++++++++++++++++++++++++ 6 files changed, 340 insertions(+) create mode 100644 hw/i2c/remote-i2c.c create mode 100644 tests/qtest/remote-i2c-test.c diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 4ba0aca067..922a3efdcc 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -393,6 +393,7 @@ config NPCM7XX select MAX34451 select PL310 # cache controller select PMBUS + select REMOTE_I2C select SERIAL select SSI select UNIMP diff --git a/hw/i2c/Kconfig b/hw/i2c/Kconfig index 8217cb5041..278156991d 100644 --- a/hw/i2c/Kconfig +++ b/hw/i2c/Kconfig @@ -1,6 +1,10 @@ config I2C bool =20 +config REMOTE_I2C + bool + select I2C + config SMBUS bool select I2C diff --git a/hw/i2c/meson.build b/hw/i2c/meson.build index d3df273251..ba0215db61 100644 --- a/hw/i2c/meson.build +++ b/hw/i2c/meson.build @@ -6,6 +6,7 @@ i2c_ss.add(when: 'CONFIG_ACPI_X86_ICH', if_true: files('smb= us_ich9.c')) i2c_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_i2c.c')) i2c_ss.add(when: 'CONFIG_BITBANG_I2C', if_true: files('bitbang_i2c.c')) i2c_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_i2c.c')) +i2c_ss.add(when: 'CONFIG_REMOTE_I2C', if_true: files('remote-i2c.c')) i2c_ss.add(when: 'CONFIG_IMX_I2C', if_true: files('imx_i2c.c')) i2c_ss.add(when: 'CONFIG_MPC_I2C', if_true: files('mpc_i2c.c')) i2c_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('microbit_i2c.c')) diff --git a/hw/i2c/remote-i2c.c b/hw/i2c/remote-i2c.c new file mode 100644 index 0000000000..083eaf2210 --- /dev/null +++ b/hw/i2c/remote-i2c.c @@ -0,0 +1,117 @@ +/* + * Remote I2C Device + * + * Copyright (c) 2021 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" + +#include "chardev/char-fe.h" +#include "hw/i2c/i2c.h" +#include "hw/qdev-properties-system.h" + +#define TYPE_REMOTE_I2C "remote-i2c" +#define REMOTE_I2C(obj) OBJECT_CHECK(RemoteI2CState, (obj), TYPE_REMOTE_I2= C) +#define ONE_BYTE 1 + +typedef struct { + I2CSlave parent_obj; + CharBackend chr; +} RemoteI2CState; + +typedef enum { + REMOTE_I2C_START_RECV =3D 0, + REMOTE_I2C_START_SEND =3D 1, + REMOTE_I2C_FINISH =3D 2, + REMOTE_I2C_NACK =3D 3, + REMOTE_I2C_RECV =3D 4, + REMOTE_I2C_SEND =3D 5, +} RemoteI2CCommand; + +static uint8_t remote_i2c_recv(I2CSlave *s) +{ + RemoteI2CState *i2c =3D REMOTE_I2C(s); + uint8_t resp =3D 0; + uint8_t type =3D REMOTE_I2C_RECV; + qemu_chr_fe_write_all(&i2c->chr, &type, ONE_BYTE); + + qemu_chr_fe_read_all(&i2c->chr, &resp, ONE_BYTE); + return resp; +} + +static int remote_i2c_send(I2CSlave *s, uint8_t data) +{ + RemoteI2CState *i2c =3D REMOTE_I2C(s); + uint8_t type =3D REMOTE_I2C_SEND; + uint8_t resp =3D 1; + qemu_chr_fe_write_all(&i2c->chr, &type, ONE_BYTE); + qemu_chr_fe_write_all(&i2c->chr, &data, ONE_BYTE); + + qemu_chr_fe_read_all(&i2c->chr, &resp, ONE_BYTE); + return resp ? -1 : 0; +} + +/* Returns non-zero when no response from the device. */ +static int remote_i2c_event(I2CSlave *s, enum i2c_event event) +{ + RemoteI2CState *i2c =3D REMOTE_I2C(s); + uint8_t type; + uint8_t resp =3D 1; + switch (event) { + case I2C_START_RECV: + type =3D REMOTE_I2C_START_RECV; + break; + case I2C_START_SEND: + type =3D REMOTE_I2C_START_SEND; + break; + case I2C_FINISH: + type =3D REMOTE_I2C_FINISH; + break; + case I2C_NACK: + type =3D REMOTE_I2C_NACK; + } + qemu_chr_fe_write_all(&i2c->chr, &type, ONE_BYTE); + qemu_chr_fe_read_all(&i2c->chr, &resp, ONE_BYTE); + return resp ? -1 : 0; +} + +static Property remote_i2c_props[] =3D { + DEFINE_PROP_CHR("chardev", RemoteI2CState, chr), + DEFINE_PROP_END_OF_LIST(), +}; + +static void remote_i2c_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + I2CSlaveClass *k =3D I2C_SLAVE_CLASS(klass); + + k->recv =3D &remote_i2c_recv; + k->send =3D &remote_i2c_send; + k->event =3D &remote_i2c_event; + device_class_set_props(dc, remote_i2c_props); +} + +static const TypeInfo remote_i2c_type =3D { + .name =3D TYPE_REMOTE_I2C, + .parent =3D TYPE_I2C_SLAVE, + .instance_size =3D sizeof(RemoteI2CState), + .class_size =3D sizeof(I2CSlaveClass), + .class_init =3D remote_i2c_class_init, +}; + +static void remote_i2c_register(void) +{ + type_register_static(&remote_i2c_type); +} + +type_init(remote_i2c_register) diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index e22a0792c5..95faa2c379 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -218,6 +218,7 @@ qos_test_ss.add( 'pca9552-test.c', 'pci-test.c', 'pcnet-test.c', + 'remote-i2c-test.c', 'sdhci-test.c', 'spapr-phb-test.c', 'tmp105-test.c', diff --git a/tests/qtest/remote-i2c-test.c b/tests/qtest/remote-i2c-test.c new file mode 100644 index 0000000000..b6ab210e4c --- /dev/null +++ b/tests/qtest/remote-i2c-test.c @@ -0,0 +1,216 @@ +/* + * QTests for Remote I2C Device + * + * Copyright (c) 2021 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" + +#include "qemu/config-file.h" +#include "sysemu/sysemu.h" +#include "libqos/qgraph.h" +#include "libqos/i2c.h" + +#include + +#define TEST_ID "remote-i2c-test" +#define TEST_ADDR (0x62) +#define QEMU_CMD_CHR = \ + " -chardev socket,id=3Di2c-chardev,host=3Dlocalhost,port=3D%d,reconnec= t=3D10" + +typedef enum { + REMOTE_I2C_START_RECV =3D 0, + REMOTE_I2C_START_SEND =3D 1, + REMOTE_I2C_FINISH =3D 2, + REMOTE_I2C_NACK =3D 3, + REMOTE_I2C_RECV =3D 4, + REMOTE_I2C_SEND =3D 5, +} RemoteI2CCommand; + +static int setup_fd(int *sock) +{ + fd_set readfds; + int fd; + + FD_ZERO(&readfds); + FD_SET(*sock, &readfds); + g_assert(select((*sock) + 1, &readfds, NULL, NULL, NULL) =3D=3D 1); + + fd =3D accept(*sock, NULL, 0); + g_assert(fd >=3D 0); + + return fd; +} + +static void test_recv(QI2CDevice *i2cdev, int fd, uint8_t *msg, uint16_t l= en) +{ + uint16_t buf_size =3D len + 2; + uint8_t *buf =3D g_new(uint8_t, buf_size); + uint16_t bytes_read =3D 0; + uint8_t zero =3D 0; + ssize_t rv; + + /* write device responses to socket */ + rv =3D write(fd, &zero, 1); + g_assert_cmpint(rv, =3D=3D, 1); + rv =3D write(fd, msg, len); + g_assert_cmpint(rv, =3D=3D, len); + rv =3D write(fd, &zero, 1); + g_assert_cmpint(rv, =3D=3D, 1); + + /* check received value */ + qi2c_recv(i2cdev, buf, len); + for (int i =3D 0; i < len; ++i) { + g_assert_cmphex(buf[i], =3D=3D, msg[i]); + } + + /* check controller writes to chardev */ + do { + bytes_read +=3D read(fd, buf + bytes_read, buf_size - bytes_read); + } while (bytes_read < buf_size); + + g_assert_cmphex(buf[0], =3D=3D, REMOTE_I2C_START_RECV); + for (int i =3D 1; i < len - 1; ++i) { + g_assert_cmphex(buf[i], =3D=3D, REMOTE_I2C_RECV); + } + g_assert_cmphex(buf[buf_size - 1], =3D=3D, REMOTE_I2C_FINISH); + + g_free(buf); +} + +static void test_send(QI2CDevice *i2cdev, int fd, uint8_t *msg, uint16_t l= en) +{ + uint16_t buf_size =3D len * 2 + 2; + uint8_t *buf =3D g_new0(uint8_t, buf_size); + uint16_t bytes_read =3D 0; + ssize_t rv; + int j =3D 0; + + /* write device ACKs to socket*/ + rv =3D write(fd, buf, len + 2); + g_assert_cmpint(rv, =3D=3D, len + 2); + + qi2c_send(i2cdev, msg, len); + + /* check controller writes to chardev */ + do { + bytes_read +=3D read(fd, buf + bytes_read, buf_size - bytes_read); + } while (bytes_read < buf_size); + + g_assert_cmphex(buf[0], =3D=3D, REMOTE_I2C_START_SEND); + for (int i =3D 1; i < buf_size - 1; i +=3D 2) { + g_assert_cmphex(buf[i], =3D=3D, REMOTE_I2C_SEND); + g_assert_cmphex(buf[i + 1], =3D=3D, msg[j++]); + } + g_assert_cmphex(buf[buf_size - 1], =3D=3D, REMOTE_I2C_FINISH); + + g_free(buf); +} + +static void test_remote_i2c_recv(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + int *sock =3D (int *)data; + int fd =3D setup_fd(sock); + + uint8_t msg[] =3D {0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4= F}; + + test_recv(i2cdev, fd, msg, 1); + test_recv(i2cdev, fd, msg, 2); + test_recv(i2cdev, fd, msg, 3); + test_recv(i2cdev, fd, msg, 4); + test_recv(i2cdev, fd, msg, 5); + test_recv(i2cdev, fd, msg, 6); + test_recv(i2cdev, fd, msg, 7); + test_recv(i2cdev, fd, msg, 8); + test_recv(i2cdev, fd, msg, 9); +} + +static void test_remote_i2c_send(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + QI2CDevice *i2cdev =3D (QI2CDevice *)obj; + int *sock =3D (int *)data; + int fd =3D setup_fd(sock); + + uint8_t msg[] =3D {0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4= F}; + + test_send(i2cdev, fd, msg, 1); + test_send(i2cdev, fd, msg, 2); + test_send(i2cdev, fd, msg, 3); + test_send(i2cdev, fd, msg, 4); + test_send(i2cdev, fd, msg, 5); + test_send(i2cdev, fd, msg, 6); + test_send(i2cdev, fd, msg, 7); + test_send(i2cdev, fd, msg, 8); + test_send(i2cdev, fd, msg, 9); +} + +static in_port_t open_socket(int *sock) +{ + struct sockaddr_in myaddr; + socklen_t addrlen; + + myaddr.sin_family =3D AF_INET; + myaddr.sin_addr.s_addr =3D htonl(INADDR_LOOPBACK); + myaddr.sin_port =3D 0; + + *sock =3D socket(AF_INET, SOCK_STREAM, 0); + g_assert(*sock !=3D -1); + g_assert(bind(*sock, (struct sockaddr *)&myaddr, sizeof(myaddr)) !=3D = -1); + + addrlen =3D sizeof(myaddr); + g_assert(getsockname(*sock, (struct sockaddr *)&myaddr, &addrlen) !=3D= -1); + g_assert(listen(*sock, 1) !=3D -1); + + return ntohs(myaddr.sin_port); +} + +static void remote_i2c_test_cleanup(void *socket) +{ + int *s =3D socket; + + close(*s); + qos_invalidate_command_line(); + g_free(s); +} + +static void *remote_i2c_test_setup(GString *cmd_line, void *arg) +{ + int *sock =3D g_new(int, 1); + + g_string_append_printf(cmd_line, QEMU_CMD_CHR, open_socket(sock)); + g_test_queue_destroy(remote_i2c_test_cleanup, sock); + return sock; +} + +static void register_remote_i2c_test(void) +{ + QOSGraphEdgeOptions edge =3D { + .extra_device_opts =3D "id=3D" TEST_ID ",address=3D0x62,chardev=3D= i2c-chardev"}; + add_qi2c_address(&edge, &(QI2CAddress){TEST_ADDR}); + + qos_node_create_driver("remote-i2c", i2c_device_create); + qos_node_consumes("remote-i2c", "i2c-bus", &edge); + + QOSGraphTestOptions opts =3D { + .before =3D remote_i2c_test_setup, + }; + qemu_add_opts(&qemu_chardev_opts); + qos_add_test("test_remote_i2c_recv", "remote-i2c", test_remote_i2c_rec= v, + &opts); + qos_add_test("test_remote_i2c_send", "remote-i2c", test_remote_i2c_sen= d, + &opts); +} +libqos_init(register_remote_i2c_test); --=20 2.32.0.605.g8dce9f2422-goog From nobody Fri May 10 20:39:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1628293826; cv=none; d=zohomail.com; s=zohoarc; b=XwBK28W5QGHAuhqb+149N50AA45iNJiY2tQnfu9UuDJZMGxLdA7cjT/WsunTOf7F2MoOcEZe3rr8ZEWbziAZS4iLjd4SG5zhXLuBK442s393wHjA5cIMuVqMhceWA8QDlfXD4CsCm6tYRG3lf+wxGfyT8g2ojxDqH7ZJyYYy+EM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628293826; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XqtZouX1dsK0xt45rvjPAiwNwuBYfTyHPKY1ulqPTHQ=; b=k/7gM1wsXx7xtdbA/XD9/TlZ8WjU7K8rx+0HW0iAxfXvXXvUH0p8JPnqfjjeRi1rlXrR04snaAtvJGOG/ybrqn7+usWUsG0FaLJPjS1jbIhlLEpfDoYcpyqjot5wVn2j6LDqTkvG04uJ4npBjwLZ0SsAIFN35NN5bpxz5TA2i0s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162829382629178.15721374730924; Fri, 6 Aug 2021 16:50:26 -0700 (PDT) Received: from localhost ([::1]:41028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mC9bc-00073T-Ii for importer@patchew.org; Fri, 06 Aug 2021 19:50:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3gsoNYQUKCl0NOH5JBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--stmao.bounces.google.com>) id 1mC9ag-0005M6-Ab for qemu-devel@nongnu.org; Fri, 06 Aug 2021 19:49:26 -0400 Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]:36390) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3gsoNYQUKCl0NOH5JBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--stmao.bounces.google.com>) id 1mC9ae-0002su-33 for qemu-devel@nongnu.org; Fri, 06 Aug 2021 19:49:26 -0400 Received: by mail-qk1-x74a.google.com with SMTP id q9-20020a05620a0c89b02903ba3e0f08d7so7496339qki.3 for ; Fri, 06 Aug 2021 16:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=XqtZouX1dsK0xt45rvjPAiwNwuBYfTyHPKY1ulqPTHQ=; b=IxYduGmb/iRg2VKUziNtsrYOhCUqJ/g/WsB1BWUCEoiHskwJpxuWWYRzmJuyA5RApz r+dFXdZSOW4J0T7xxWgSf+sd0/CEUc6Fkw0K5xmFKQkmVS7lRSoXxaR6r592M1qjWuMV tNmyu0MBjRzORnNOus8NgRCmGo41mDplm7icx8/vfpPELjArnJzUXwN1mE2Rsh6GvNgO saNn41p/MRpKf4WWor9MAm5NVJk24OpCCoA2NO6z40i6k9TxIH3LC2C5gaD81F3onzVG zZuqlypernJBI+P05G7R32iZEfx6d39EWGPgEhTw/2cgxmYfOFRXa30NBY4hzFx3+h0y gRXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XqtZouX1dsK0xt45rvjPAiwNwuBYfTyHPKY1ulqPTHQ=; b=owFjPN2k7rwUNdrfJZ/imgNGaUnwBSKq6us8Cff77P2s2qbUhe++mhKLnCoXQhb7eM qvyFhpp8to9rdfisAo9t2nxbpYGM7PqHmJV2yJt/Y9qx7aM9ULalvy9no303AHGx+Wp0 n3bPC8pfIoB2guMmakVEGE3b/+Lyb72ITYqfyB/pDphx68ezZcrb1w0IoekS2FJv8hPo Ql1OasVCGU5Q7f0u19Gs1/pWguGXGMJ83okwQj67vB5DUDXOx/yID6BjcfsuI3KGiBH9 ND7r9mrKBW5NO6QSOq0xbZaiPjXVM60QXWOTwCFh5q4TilaYkvfJbevukHyWohw15KDU QjgA== X-Gm-Message-State: AOAM532mDieltHibQsiTH4XBT9EObEGPYfOlKnhPj3ZmJx+950QHSlFy nDBI05+MmD54GKjMHb7sObhJiLIGsA== X-Google-Smtp-Source: ABdhPJz1NaT5aPj9HWxVvPjfjR5+klEEJTj801tF03jXnQXchAvagY8LLNIA3XKwR2jFV7RRn7IS494Jgg== X-Received: from smvm.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2d5f]) (user=stmao job=sendgmr) by 2002:a05:6214:226b:: with SMTP id gs11mr191005qvb.36.1628293762886; Fri, 06 Aug 2021 16:49:22 -0700 (PDT) Date: Fri, 6 Aug 2021 23:49:18 +0000 In-Reply-To: <20210806234918.122457-1-stmao@google.com> Message-Id: <20210806234918.122457-3-stmao@google.com> Mime-Version: 1.0 References: <20210806234918.122457-1-stmao@google.com> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog Subject: [PATCH v4 2/2] docs/specs: add remote i2c docs From: Shengtan Mao To: cminyard@mvista.com Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, crauer@google.com, wuhaotsh@google.com, venture@google.com, maoshengtan2011@gmail.com, Shengtan Mao Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::74a; envelope-from=3gsoNYQUKCl0NOH5JBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--stmao.bounces.google.com; helo=mail-qk1-x74a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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: pass (identity @google.com) X-ZM-MESSAGEID: 1628293827385100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Change-Id: I4ef1e31c326dbb4f741bf65d9212ff10fc3c98c3 --- docs/specs/index.rst | 1 + docs/specs/remote-i2c.rst | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 docs/specs/remote-i2c.rst diff --git a/docs/specs/index.rst b/docs/specs/index.rst index b7b08ea30d..ac496fb8b8 100644 --- a/docs/specs/index.rst +++ b/docs/specs/index.rst @@ -13,3 +13,4 @@ guest hardware that is specific to QEMU. acpi_hw_reduced_hotplug tpm acpi_hest_ghes + remote-i2c diff --git a/docs/specs/remote-i2c.rst b/docs/specs/remote-i2c.rst new file mode 100644 index 0000000000..7f3b1e46bb --- /dev/null +++ b/docs/specs/remote-i2c.rst @@ -0,0 +1,51 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Remote I2C Device +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The remote I2C device is connected directly to the I2C controller inside Q= EMU, +and the external I2C device is outside of QEMU. The communication between = the +external and remote I2C devices is done through the character device provi= ded +by QEMU and follows the remote I2C protocol. + +Remote I2C Protocol +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +The remote I2C device implements three functions of the struct I2CSlaveCla= ss: + +* event +* recv +* send + +Exactly one byte is written or read from the character device at a time, +so these functions may read/write to the character device multiple times. +Each byte may be a command or a data byte. The command are outlined +in enum RemoteI2CCommand. The protocol describes the expected behavior +of the external I2C device in response to the the commands. + +event +=3D=3D=3D=3D=3D +A subset of the RemoteI2CCommand corresponds exactly to the enum i2c_event. +They are: + +* REMOTE_I2C_START_RECV +* REMOTE_I2C_START_SEND +* REMOTE_I2C_FINISH +* REMOTE_I2C_NACK + +The event function of remote I2C writes the command to the external I2C de= vice. +The external device should call its event function to process the command = as +an event and write back the return value to remote I2C. This value is then +returned by the event function of remote I2C. + +recv +=3D=3D=3D=3D +The recv function of remote I2C writes the RemoteI2CCommand REMOTE_I2C_REC= V to +the external I2C device. The external device should call its recv function +and write back the return value to remote I2C. This value is then returned= by +the recv function of remote I2C. + +send +=3D=3D=3D=3D +The send function of remote I2C writes the RemoteI2CCommand REMOTE_I2C_SEND +followed by the data to the external I2C device. The external device should +call its send function to process the data and write the return value back= to +remote I2C. This value is then returned by the send function of remote I2C. --=20 2.32.0.605.g8dce9f2422-goog