From patchwork Thu Mar 31 16:57:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 12797474 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9AAF7C433F5 for ; Thu, 31 Mar 2022 17:02:41 +0000 (UTC) Received: from localhost ([::1]:34216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZyC0-0003V5-7U for qemu-devel@archiver.kernel.org; Thu, 31 Mar 2022 13:02:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZy7J-0000Se-R5; Thu, 31 Mar 2022 12:57:50 -0400 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:38583) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZy7H-0000tO-8Z; Thu, 31 Mar 2022 12:57:49 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id B730F3201F73; Thu, 31 Mar 2022 12:57:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 31 Mar 2022 12:57:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to; s=fm3; bh=1WRY1D6ylOonmR+UXUnHo7Y5sqkvfC yFsaIhwjq1Gdw=; b=H2a+5jpHpnii21qkEk3Ptj0wp7RWjJOY6STOnYpkk86v5Q np2dG6KjKo8ZpF/h0hGkU+jCNX/vHQsXqgeg4V26cJx/JXASKB6mpz0+DQHTFPmj 1H7MmwsRaLfXLeU6vKUngdGPJ+sV5eq7nLRV6Kpw+jAh5wKPwn2gMvd+5b6NVX7e AEIPAQbM3V6i2qKr3JzG7SulUq9Sn7KwftQNvyMK173cS+QSpbryR+isP499RHLd SwZHA821O3slsxA9CvqdtSlbGvZHGNtI/qVhF1/OarI/enrZ05eeLDVQ04LFYZ6w dRq5fTLB3AAAWzOPLuiujCWA7OqwDo4+87DEBFpQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=1WRY1D 6ylOonmR+UXUnHo7Y5sqkvfCyFsaIhwjq1Gdw=; b=MaQ9uEkM+mNVoliE/aBsIZ 2KhvxKFz4JcHEMaypkbsc84Lff+SrgnOO+yf8rwRoK2Q1nYy4lizTzjW2sa9AejE oyRsZZ5+hwT+WuJsAQj4u1PSMtHh4+ggAh1cGo3zpDcVp/MuYPb49BbkZdMNwSTQ 63CMcm76b5mnsX+EH5xSVlfEc3V/wQONIlBKVa65mvfZktkVTJiMXzYzHsB9QLDM YymgmONWfUyMjS5lz3fV5gxMvXzwLGNX+/PT2UCzr35h0bCOxj1T8P+lcM4ZRtzr ZGmJiOePVLnHdEO0ReGG0JknhTp47NEXfy6KGTYvEeJw5nGTzZOvAWzE/eQz374Q == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeigedguddtjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgtggfgsehtqhertdertdejnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeegudeghfdvgffgleevtdettefhhfdvieevffevgfelkeethfevteffhfeltddv ffenucffohhmrghinhepnhhvmhgvgihprhgvshhsrdhorhhgpdgumhhtfhdrohhrghdpsh hmsghushdrohhrghdpkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomhepihhtshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 31 Mar 2022 12:57:39 -0400 (EDT) From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [RFC PATCH 0/4] hw/i2c: i2c slave mode support Date: Thu, 31 Mar 2022 18:57:33 +0200 Message-Id: <20220331165737.1073520-1-its@irrelevant.dk> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Received-SPF: pass client-ip=64.147.123.20; envelope-from=its@irrelevant.dk; helo=wout4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Arun Kumar Kashinath Agasar , Corey Minyard , Andrew Jeffery , Klaus Jensen , =?utf-8?q?C=C3=A9dric_Le_Goater?= , qemu-arm@nongnu.org, Joel Stanley , Padmakar Kalghatgi , Matt Johnston , Jeremy Kerr Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Klaus Jensen Hi all, This RFC series adds I2C "slave mode" support for the Aspeed I2C controller as well as the necessary infrastructure in the i2c core to support this. Background ~~~~~~~~~~ We are working on an emulated NVM Express Management Interface[1] for testing and validation purposes. NVMe-MI is based on the MCTP protocol[2] which may use a variety of underlying transports. The one we are interested in is I2C[3]. The first general trickery here is that all MCTP transactions are based on the SMBus Block Write bus protocol[4]. This means that the slave must be able to master the bus to communicate. As you know, hw/i2c/core.c currently does not support this use case. The second issue is how to interact with these mastering devices. Jeremy and Matt (CC'ed) have been working on an MCTP stack for the Linux Kernel (already upstream) and an I2C binding driver[5] is currently under review. This binding driver relies on I2C slave mode support in the I2C controller. This series ~~~~~~~~~~~ Patch 1 adds support for multiple masters in the i2c core, allowing slaves to master the bus and safely issue i2c_send/recv(). Patch 2 adds an asynchronous send i2c_send_async(I2CBus *, uint8) on the bus that must be paired with an explicit ack using i2c_ack(I2CBus *). Patch 3 adds the slave mode functionality to the emulated Aspeed I2C controller. The implementation is probably buggy since I had to rely on the implementation of the kernel driver to reverse engineer the behavior of the controller slave mode (I do not have access to a spec sheet for the Aspeed, but maybe someone can help me out with that?). Finally, patch 4 adds an example device using this new API. The device is a simple "echo" device that upon being sent a set of bytes uses the first byte as the address of the slave to echo to. With this combined I am able to boot up Linux on an emulated Aspeed 2600 evaluation board and have the i2c echo device write into a Linux slave EEPROM. Assuming the echo device is on address 0x42: # echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-15/new_device i2c i2c-15: new_device: Instantiated device slave-24c02 at 0x64 # i2cset -y 15 0x42 0x64 0x00 0xaa i # hexdump /sys/bus/i2c/devices/15-1064/slave-eeprom 0000000 ffaa ffff ffff ffff ffff ffff ffff ffff 0000010 ffff ffff ffff ffff ffff ffff ffff ffff * 0000100 [1]: https://nvmexpress.org/developers/nvme-mi-specification/ [2]: https://www.dmtf.org/sites/default/files/standards/documents/DSP0236_1.3.1.pdf [3]: https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.2.0.pdf [4]: http://www.smbus.org/specs/SMBus_3_1_20180319.pdf [5]: https://lore.kernel.org/linux-i2c/20220218055106.1944485-1-matt@codeconstruct.com.au/ Klaus Jensen (4): hw/i2c: support multiple masters hw/i2c: add async send hw/i2c: add slave mode for aspeed_i2c hw/misc: add a toy i2c echo device hw/i2c/aspeed_i2c.c | 95 +++++++++++++++++++++--- hw/i2c/core.c | 57 +++++++++++++- hw/i2c/trace-events | 2 +- hw/misc/i2c-echo.c | 144 ++++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 2 + include/hw/i2c/aspeed_i2c.h | 8 ++ include/hw/i2c/i2c.h | 19 +++++ 7 files changed, 316 insertions(+), 11 deletions(-) create mode 100644 hw/misc/i2c-echo.c