Received: by 2002:a05:6512:1086:0:0:0:0 with SMTP id j6csp583180lfg; Thu, 28 Jul 2022 16:24:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sXSXfqT1ZwOqTLd6+sQi/K1tzg/dDuwQSaFy5KqitRMwky0m9Oiynkm963FDBrIH/QU2/4 X-Received: by 2002:a05:620a:2192:b0:6b5:d5f6:6a80 with SMTP id g18-20020a05620a219200b006b5d5f66a80mr945037qka.584.1659050652741; Thu, 28 Jul 2022 16:24:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659050652; cv=none; d=google.com; s=arc-20160816; b=ZzYJ8yJtMFCxhcAj1t7FiYuyiM/qYmC/CBTyFk9+piStIq+hNEYfU6V4oBl7n9jJ7g kA8Whgs5pOW27JLNGHonFej3SByNJmn5khfKD/CO4E/jbrydXI6OxG7G5F4HZPrYpiyB 1IlfGxJ0xc11dSZNL2p3I7aYFQP8VpK82Qa0kbsAKWeEmM2kjGHjUbEKfCIYApQ/QuC7 3eKdeJrXpKUx7xZezAHDkE36HNEMbkpwlz8FScdLUFYMsYMFBZmigenW4Xv+S7bxXncU vkSKT9c1ZgDMIkbCTu/116iXIPbJ30JdpFo9WnSssplVslk/IgHdQvAGWqT8kUArDEY6 hNng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=gZzEABBktv6NAd2k/Leql+AGIcbpwc2oVq6FpQ4WKtQ=; b=agEBIuX7h7OaxiXHJFDTDLXKBWrsEbuAbWcTrqhQbmWHbUr3LUsHyQMFcI5DsXFjt1 AWOgG8TX6IATlZiW1g5gqByLrBs6DFYmGcsYxqP40TBiClx7DdHO/4XICqO+Y3SxUAuZ 2J8/LCeAWgHWAB09GhLrva3OTWQK0RMC6kso7X1chWUwD1zFp96l9YPvP2YGitJEDJ8h zyOWcb1JA7vOQ/XKuJiUbvq5KZUNFBoP8sIysS329ygJK4cZ7ndGBovGffooSM2JUJXx H+VgBdYRtueLgohm2Wq70cll5cjGipz9Ot1OhlkTdbGoPy719SCGOyjnrS1iFiq1TW04 UMXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=m+XvSMst; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id kl29-20020a056214519d00b004744f380156si1147923qvb.139.2022.07.28.16.24.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jul 2022 16:24:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=m+XvSMst; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: from localhost ([::1]:33540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHCrT-0002VC-9v for alex.bennee@linaro.org; Thu, 28 Jul 2022 19:24:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHCr4-0002TS-P0; Thu, 28 Jul 2022 19:23:46 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:60750) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHCr2-0002ri-Lz; Thu, 28 Jul 2022 19:23:46 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26SKCgni032371; Thu, 28 Jul 2022 16:23:30 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=gZzEABBktv6NAd2k/Leql+AGIcbpwc2oVq6FpQ4WKtQ=; b=m+XvSMstaAJfCYUdb89RJokyYHrhBayMUlPqocieh2gN0oe09cyDThWLKpFx1akcbpsx 6o/bIkyPoo/YostbXKtUWrUp1EmrDZc6RbiNbCk8zN1f4uPdLNm47xEgdXfq1F0LTbhe SCWC0uUbH81z07DtBaYFw8DXzmc0L1Ucc40= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3hjw4ff758-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 28 Jul 2022 16:23:30 -0700 Received: from snc-exhub201.TheFacebook.com (2620:10d:c085:21d::7) by snc-exhub104.TheFacebook.com (2620:10d:c085:11d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 28 Jul 2022 16:23:28 -0700 Received: from localhost (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 28 Jul 2022 16:23:27 -0700 From: Iris Chen To: CC: , , , , , , , , , , , , , , , , , Subject: [RFC 0/3] Add Generic SPI GPIO model Date: Thu, 28 Jul 2022 16:23:19 -0700 Message-ID: <20220728232322.2921703-1-irischenlj@fb.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [2620:10d:c085:208::f] X-Proofpoint-ORIG-GUID: aoeI0_qCaKz9t8k0bq7QKCGh5yjyc_1v X-Proofpoint-GUID: aoeI0_qCaKz9t8k0bq7QKCGh5yjyc_1v X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-28_06,2022-07-28_02,2022-06-22_01 Received-SPF: pass client-ip=67.231.153.30; envelope-from=prvs=9208ef30ce=irischenlj@fb.com; helo=mx0b-00082601.pphosted.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: p65j2Cfgfr35 Hey everyone, I have been working on a project to add support for SPI-based TPMs in QEMU. Currently, most of our vboot platforms using a SPI-based TPM use the Linux SPI-GPIO driver to "bit-bang" the SPI protocol. This is because the Aspeed SPI controller (modeled in QEMU under hw/ssi/aspeed_smc.c) has an implementation deficiency that prevents bi-directional operations. Thus, in order to connect a TPM to this bus, my patch implements a QEMU SPI-GPIO driver (as the QEMU counterpart of the Linux SPI-GPIO driver). As we use SPI-based TPMs on many of our BMCs for the secure-boot implementation, I have already tested this implementation locally with our Yosemite-v3.5 platform and Facebook-OpenBMC. This model was tested by connecting a generic SPI-NOR (m25p80 for example) to the Yosemite-v3.5 SPI bus containing the TPM. This patch is an RFC because I have several questions about design. Although the model is working, I understand there are many areas where the design decision is not deal (ie. abstracting hard coded GPIO values). Below are some details of the patch and specific areas where I would appreciate feedback on how to make this better: hw/arm/aspeed.c: I am not sure where the best place is to instantiate the spi_gpio besides the aspeed_machine_init. Could we add the ability to instantiate it on the command line? m25p80_transfer8_ex in hw/block/m25p80.c: Existing SPI model assumed that the output byte is fully formed, can be passed to the SPI device, and the input byte can be returned, all in one operation. With SPI-GPIO we don't have the input byte until all 8 bits of the output have been shifted out, so we have to prime the MISO with bogus values (0xFF). MOSI pin in spi_gpio: the mosi pin is not included and we poll the realtime value of the gpio for input bits to prevent bugs with caching the mosi value. It was discovered during testing that when using the mosi pin as the input pin, the mosi value was not being updated due to a kernel and aspeed_gpio model optimization. Thus, here we are reading the value directly from the gpio controller instead of waiting for the push. I realize there are Aspeed specifics in the spi_gpio model. To make this extensible, is it preferred to make this into a base class and have our Aspeed SPI GPIO extend this or we could set up params to pass in the constructor? Thanks for your review and any direction here would be helpful :) Iris Chen (3): hw: m25p80: add prereading ability in transfer8 hw: spi_gpio: add spi gpio model hw: aspeed: hook up the spi gpio model hw/arm/Kconfig | 1 + hw/arm/aspeed.c | 5 ++ hw/block/m25p80.c | 29 ++++++- hw/ssi/Kconfig | 4 + hw/ssi/meson.build | 1 + hw/ssi/spi_gpio.c | 166 ++++++++++++++++++++++++++++++++++++++ hw/ssi/ssi.c | 4 - include/hw/ssi/spi_gpio.h | 38 +++++++++ include/hw/ssi/ssi.h | 5 ++ 9 files changed, 248 insertions(+), 5 deletions(-) create mode 100644 hw/ssi/spi_gpio.c create mode 100644 include/hw/ssi/spi_gpio.h -- 2.30.2