From nobody Tue Oct 28 12:12:51 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513973929227390.023951501787; Fri, 22 Dec 2017 12:18:49 -0800 (PST) Received: from localhost ([::1]:36999 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTmF-0002Jg-4x for importer@patchew.org; Fri, 22 Dec 2017 15:18:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTkH-00014f-41 for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSTkC-0000eL-53 for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:41 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40122) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSTkB-0000do-SF for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:36 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBMKGCmO068448 for ; Fri, 22 Dec 2017 15:16:34 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2f13bygqd0-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 22 Dec 2017 15:16:33 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Dec 2017 13:16:33 -0700 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Dec 2017 13:16:30 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBMKGUmQ7799148; Fri, 22 Dec 2017 13:16:30 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5008EBE03A; Fri, 22 Dec 2017 13:16:30 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 02E04BE044; Fri, 22 Dec 2017 13:16:29 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 15:16:16 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17122220-8235-0000-0000-00000CC5C557 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008245; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00964064; UDB=6.00487777; IPR=6.00744051; BA=6.00005755; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018678; XFM=3.00000015; UTC=2017-12-22 20:16:31 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122220-8236-0000-0000-00003EF2FEB1 Message-Id: <1513973785-14427-2-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712220285 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id vBMKGCmO068448 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL v1 01/10] tpm_emulator: Add a caching layer for the TPM Established flag 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: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a caching layer for the TPM established flag so that we don't need to go to the emulator every time the flag is read by accessing the REG_ACCESS register. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_emulator.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 38b6f17..35c78de 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -72,6 +72,9 @@ typedef struct TPMEmulator { Error *migration_blocker; =20 QemuMutex mutex; + + unsigned int established_flag:1; + unsigned int established_flag_cached:1; } TPMEmulator; =20 =20 @@ -349,16 +352,22 @@ static bool tpm_emulator_get_tpm_established_flag(TPM= Backend *tb) TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); ptm_est est; =20 - DPRINTF("%s", __func__); + if (tpm_emu->established_flag_cached) { + return tpm_emu->established_flag; + } + if (tpm_emulator_ctrlcmd(tpm_emu, CMD_GET_TPMESTABLISHED, &est, 0, sizeof(est)) < 0) { error_report("tpm-emulator: Could not get the TPM established flag= : %s", strerror(errno)); return false; } - DPRINTF("established flag: %0x", est.u.resp.bit); + DPRINTF("got established flag: %0x", est.u.resp.bit); + + tpm_emu->established_flag_cached =3D 1; + tpm_emu->established_flag =3D (est.u.resp.bit !=3D 0); =20 - return (est.u.resp.bit !=3D 0); + return tpm_emu->established_flag; } =20 static int tpm_emulator_reset_tpm_established_flag(TPMBackend *tb, @@ -389,6 +398,8 @@ static int tpm_emulator_reset_tpm_established_flag(TPMB= ackend *tb, return -1; } =20 + tpm_emu->established_flag_cached =3D 0; + return 0; } =20 --=20 2.5.5 From nobody Tue Oct 28 12:12:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513974263639806.0282870472931; Fri, 22 Dec 2017 12:24:23 -0800 (PST) Received: from localhost ([::1]:37097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTrY-00076t-Bj for importer@patchew.org; Fri, 22 Dec 2017 15:24:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTkJ-00015I-JU for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSTkE-0000fz-KX for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:43 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46704) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSTkE-0000fF-AT for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:38 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBMKG2Gi054954 for ; Fri, 22 Dec 2017 15:16:35 -0500 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 2f18sr897m-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 22 Dec 2017 15:16:35 -0500 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Dec 2017 13:16:34 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Dec 2017 13:16:32 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBMKGVDf6291772; Fri, 22 Dec 2017 13:16:31 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AC8A5BE03A; Fri, 22 Dec 2017 13:16:31 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 6781FBE03E; Fri, 22 Dec 2017 13:16:31 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 15:16:17 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17122220-0028-0000-0000-000008E35A9C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008245; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00964064; UDB=6.00487777; IPR=6.00744051; MB=3.00018678; MTD=3.00000007; XFM=3.00000015; UTC=2017-12-22 20:16:33 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122220-0029-0000-0000-000038D6F432 Message-Id: <1513973785-14427-3-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712220285 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id vBMKG2Gi054954 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL v1 02/10] tpm_tis: convert uint32_t to size_t 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: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index b8e811b..ac5f51f 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -974,7 +974,7 @@ static const MemoryRegionOps tpm_tis_memory_ops =3D { }, }; =20 -static int tpm_tis_do_startup_tpm(TPMState *s, uint32_t buffersize) +static int tpm_tis_do_startup_tpm(TPMState *s, size_t buffersize) { return tpm_backend_startup_tpm(s->be_driver, buffersize); } --=20 2.5.5 From nobody Tue Oct 28 12:12:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513974104251235.72663427661655; Fri, 22 Dec 2017 12:21:44 -0800 (PST) Received: from localhost ([::1]:37018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTp1-0004iv-4H for importer@patchew.org; Fri, 22 Dec 2017 15:21:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTkI-00014t-5G for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSTkD-0000er-6E for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:42 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:53408 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSTkD-0000ee-1G for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:37 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBMKETMY017432 for ; Fri, 22 Dec 2017 15:16:36 -0500 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0b-001b2d01.pphosted.com with ESMTP id 2f17h0u20m-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 22 Dec 2017 15:16:36 -0500 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Dec 2017 13:16:35 -0700 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Dec 2017 13:16:33 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBMKGXNs13697444; Fri, 22 Dec 2017 13:16:33 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 283B5BE03B; Fri, 22 Dec 2017 13:16:33 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id CD85BBE040; Fri, 22 Dec 2017 13:16:32 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 15:16:18 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17122220-0024-0000-0000-000017B19FEA X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008245; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00964064; UDB=6.00487777; IPR=6.00744051; BA=6.00005755; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018678; XFM=3.00000015; UTC=2017-12-22 20:16:34 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122220-0025-0000-0000-00004DFFCC63 Message-Id: <1513973785-14427-4-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712220285 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0b-001b2d01.pphosted.com id vBMKETMY017432 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL v1 03/10] tpm_tis: limit size of buffer from backend 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: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is a preparatory patch for the subsequent ones where we get rid of the flexibility of supporting any kind of buffer size that the backend may support. We keep the size at 4096, which is also the size the external emulator supports. So, limit the size of the buffer we can support and pass it back to the backend. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index ac5f51f..a6e2f6e 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -1012,7 +1012,8 @@ static void tpm_tis_reset(DeviceState *dev) int c; =20 s->be_tpm_version =3D tpm_backend_get_tpm_version(s->be_driver); - s->be_buffer_size =3D tpm_backend_get_buffer_size(s->be_driver); + s->be_buffer_size =3D MIN(tpm_backend_get_buffer_size(s->be_driver), + TPM_TIS_BUFFER_MAX); =20 tpm_backend_reset(s->be_driver); =20 @@ -1044,7 +1045,7 @@ static void tpm_tis_reset(DeviceState *dev) tpm_tis_realloc_buffer(&s->loc[c].r_buffer, s->be_buffer_size); } =20 - tpm_tis_do_startup_tpm(s, 0); + tpm_tis_do_startup_tpm(s, s->be_buffer_size); } =20 static const VMStateDescription vmstate_tpm_tis =3D { --=20 2.5.5 From nobody Tue Oct 28 12:12:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513974109084453.40297854618655; Fri, 22 Dec 2017 12:21:49 -0800 (PST) Received: from localhost ([::1]:37020 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTp6-0004np-OQ for importer@patchew.org; Fri, 22 Dec 2017 15:21:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41774) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTkJ-00015L-Jl for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSTkG-0000hT-HO for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:43 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46942) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSTkG-0000gf-99 for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:40 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBMKG2Go054954 for ; Fri, 22 Dec 2017 15:16:39 -0500 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2f18sr8994-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 22 Dec 2017 15:16:39 -0500 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Dec 2017 13:16:38 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Dec 2017 13:16:35 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBMKGYkN9503202; Fri, 22 Dec 2017 13:16:34 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 904AABE03E; Fri, 22 Dec 2017 13:16:34 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 3F917BE03A; Fri, 22 Dec 2017 13:16:34 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 15:16:19 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17122220-0008-0000-0000-0000091281D4 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008245; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00964064; UDB=6.00487777; IPR=6.00744051; BA=6.00005755; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018678; XFM=3.00000015; UTC=2017-12-22 20:16:36 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122220-0009-0000-0000-0000454214AD Message-Id: <1513973785-14427-5-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712220285 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id vBMKG2Go054954 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL v1 04/10] tpm_tis: remove TPMSizeBuffer usage 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: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Remove usage of TPMSizeBuffer. The size of the buffers is limited now by s->be_buffer_size, which is the size of the buffer the TIS has negotiated with the backend. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 68 ++++++++++++++++++++++++----------------------------= ---- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index a6e2f6e..624c269 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -64,8 +64,8 @@ typedef struct TPMLocality { =20 uint16_t w_offset; uint16_t r_offset; - TPMSizedBuffer w_buffer; - TPMSizedBuffer r_buffer; + unsigned char w_buffer[TPM_TIS_BUFFER_MAX]; + unsigned char r_buffer[TPM_TIS_BUFFER_MAX]; } TPMLocality; =20 typedef struct TPMState { @@ -215,23 +215,19 @@ static uint8_t tpm_tis_locality_from_addr(hwaddr addr) return (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7); } =20 -static uint32_t tpm_tis_get_size_from_buffer(const TPMSizedBuffer *sb) -{ - return tpm_cmd_get_size(sb->buffer); -} - -static void tpm_tis_show_buffer(const TPMSizedBuffer *sb, const char *stri= ng) +static void tpm_tis_show_buffer(const unsigned char *buffer, + size_t buffer_size, const char *string) { #ifdef DEBUG_TIS uint32_t len, i; =20 - len =3D tpm_tis_get_size_from_buffer(sb); + len =3D MIN(tpm_cmd_get_size(buffer), buffer_size); DPRINTF("tpm_tis: %s length =3D %d\n", string, len); for (i =3D 0; i < len; i++) { if (i && !(i % 16)) { DPRINTF("\n"); } - DPRINTF("%.2X ", sb->buffer[i]); + DPRINTF("%.2X ", buffer[i]); } DPRINTF("\n"); #endif @@ -263,7 +259,8 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { TPMLocality *locty_data =3D &s->loc[locty]; =20 - tpm_tis_show_buffer(&s->loc[locty].w_buffer, "tpm_tis: To TPM"); + tpm_tis_show_buffer(s->loc[locty].w_buffer, s->be_buffer_size, + "tpm_tis: To TPM"); =20 /* * w_offset serves as length indicator for length of data; @@ -273,10 +270,10 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t loc= ty) =20 s->cmd =3D (TPMBackendCmd) { .locty =3D locty, - .in =3D locty_data->w_buffer.buffer, + .in =3D locty_data->w_buffer, .in_len =3D locty_data->w_offset, - .out =3D locty_data->r_buffer.buffer, - .out_len =3D locty_data->r_buffer.size + .out =3D locty_data->r_buffer, + .out_len =3D s->be_buffer_size, }; =20 tpm_backend_deliver_request(s->be_driver, &s->cmd); @@ -427,7 +424,8 @@ static void tpm_tis_request_completed(TPMIf *ti) s->loc[locty].r_offset =3D 0; s->loc[locty].w_offset =3D 0; =20 - tpm_tis_show_buffer(&s->loc[locty].r_buffer, "tpm_tis: From TPM"); + tpm_tis_show_buffer(s->loc[locty].r_buffer, s->be_buffer_size, + "tpm_tis: From TPM"); =20 if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { tpm_tis_abort(s, locty); @@ -446,9 +444,10 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_t= locty) uint16_t len; =20 if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { - len =3D tpm_tis_get_size_from_buffer(&s->loc[locty].r_buffer); + len =3D MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), + s->be_buffer_size); =20 - ret =3D s->loc[locty].r_buffer.buffer[s->loc[locty].r_offset++]; + ret =3D s->loc[locty].r_buffer[s->loc[locty].r_offset++]; if (s->loc[locty].r_offset >=3D len) { /* got last byte */ tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); @@ -494,11 +493,12 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: result buffer : ", s->loc[locty].r_offset); for (idx =3D 0; - idx < tpm_tis_get_size_from_buffer(&s->loc[locty].r_buffer); + idx < MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), + s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].r_offset =3D=3D idx ? '>' : ' ', - s->loc[locty].r_buffer.buffer[idx], + s->loc[locty].r_buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n" @@ -506,11 +506,12 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: request buffer: ", s->loc[locty].w_offset); for (idx =3D 0; - idx < tpm_tis_get_size_from_buffer(&s->loc[locty].w_buffer); + idx < MIN(tpm_cmd_get_size(s->loc[locty].w_buffer), + s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].w_offset =3D=3D idx ? '>' : ' ', - s->loc[locty].w_buffer.buffer[idx], + s->loc[locty].w_buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n"); @@ -572,11 +573,11 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwadd= r addr, if (s->active_locty =3D=3D locty) { if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { val =3D TPM_TIS_BURST_COUNT( - tpm_tis_get_size_from_buffer(&s->loc[locty].r_buffe= r) + MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), + s->be_buffer_size) - s->loc[locty].r_offset) | s->loc[locty].sts; } else { - avail =3D s->loc[locty].w_buffer.size - - s->loc[locty].w_offset; + avail =3D s->be_buffer_size - s->loc[locty].w_offset; /* * byte-sized reads should not return 0x00 for 0x100 * available bytes. @@ -924,9 +925,9 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, } =20 while ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) { - if (s->loc[locty].w_offset < s->loc[locty].w_buffer.size) { - s->loc[locty].w_buffer. - buffer[s->loc[locty].w_offset++] =3D (uint8_t)val; + if (s->loc[locty].w_offset < s->be_buffer_size) { + s->loc[locty].w_buffer[s->loc[locty].w_offset++] =3D + (uint8_t)val; val >>=3D 8; size--; } else { @@ -940,7 +941,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, /* we have a packet length - see if we have all of it */ bool need_irq =3D !(s->loc[locty].sts & TPM_TIS_STS_VALID); =20 - len =3D tpm_tis_get_size_from_buffer(&s->loc[locty].w_buff= er); + len =3D tpm_cmd_get_size(&s->loc[locty].w_buffer); if (len > s->loc[locty].w_offset) { tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID= ); @@ -979,15 +980,6 @@ static int tpm_tis_do_startup_tpm(TPMState *s, size_t = buffersize) return tpm_backend_startup_tpm(s->be_driver, buffersize); } =20 -static void tpm_tis_realloc_buffer(TPMSizedBuffer *sb, - size_t wanted_size) -{ - if (sb->size !=3D wanted_size) { - sb->buffer =3D g_realloc(sb->buffer, wanted_size); - sb->size =3D wanted_size; - } -} - /* * Get the TPMVersion of the backend device being used */ @@ -1040,9 +1032,7 @@ static void tpm_tis_reset(DeviceState *dev) s->loc[c].state =3D TPM_TIS_STATE_IDLE; =20 s->loc[c].w_offset =3D 0; - tpm_tis_realloc_buffer(&s->loc[c].w_buffer, s->be_buffer_size); s->loc[c].r_offset =3D 0; - tpm_tis_realloc_buffer(&s->loc[c].r_buffer, s->be_buffer_size); } =20 tpm_tis_do_startup_tpm(s, s->be_buffer_size); --=20 2.5.5 From nobody Tue Oct 28 12:12:51 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513973938638272.27332838740324; Fri, 22 Dec 2017 12:18:58 -0800 (PST) Received: from localhost ([::1]:37000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTmL-0002Of-HW for importer@patchew.org; Fri, 22 Dec 2017 15:18:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTkJ-00015U-Qw for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSTkI-0000j2-Jf for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:43 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53528) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSTkI-0000iT-Be for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:42 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBMKF4O7029830 for ; Fri, 22 Dec 2017 15:16:39 -0500 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 2f12ch3du1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 22 Dec 2017 15:16:38 -0500 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Dec 2017 13:16:37 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Dec 2017 13:16:36 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBMKGaZP1966396; Fri, 22 Dec 2017 13:16:36 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0C875BE039; Fri, 22 Dec 2017 13:16:36 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id B16D0BE04A; Fri, 22 Dec 2017 13:16:35 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 15:16:20 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17122220-0028-0000-0000-000008E35AA0 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008245; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00964064; UDB=6.00487777; IPR=6.00744051; MB=3.00018678; MTD=3.00000007; XFM=3.00000015; UTC=2017-12-22 20:16:37 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122220-0029-0000-0000-000038D6F43F Message-Id: <1513973785-14427-6-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712220285 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id vBMKF4O7029830 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL v1 05/10] tpm_tis: move buffers from localities into common location 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: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" One read buffer and one write buffer is sufficient for all localities. The localities cannot all be active at the same time, and only the active locality can use the r/w buffers. Inactive localities will require the COMMAND_READY flag to be set on the STS register to move to the READY state, which then enables access to using the buffer for writing of a command, while all other localities are inactive. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 624c269..34bfc86 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -64,16 +64,14 @@ typedef struct TPMLocality { =20 uint16_t w_offset; uint16_t r_offset; - unsigned char w_buffer[TPM_TIS_BUFFER_MAX]; - unsigned char r_buffer[TPM_TIS_BUFFER_MAX]; } TPMLocality; =20 typedef struct TPMState { ISADevice busdev; MemoryRegion mmio; =20 - uint32_t offset; - uint8_t buf[TPM_TIS_BUFFER_MAX]; + unsigned char w_buffer[TPM_TIS_BUFFER_MAX]; + unsigned char r_buffer[TPM_TIS_BUFFER_MAX]; =20 uint8_t active_locty; uint8_t aborting_locty; @@ -259,7 +257,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { TPMLocality *locty_data =3D &s->loc[locty]; =20 - tpm_tis_show_buffer(s->loc[locty].w_buffer, s->be_buffer_size, + tpm_tis_show_buffer(s->w_buffer, s->be_buffer_size, "tpm_tis: To TPM"); =20 /* @@ -270,9 +268,9 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) =20 s->cmd =3D (TPMBackendCmd) { .locty =3D locty, - .in =3D locty_data->w_buffer, + .in =3D s->w_buffer, .in_len =3D locty_data->w_offset, - .out =3D locty_data->r_buffer, + .out =3D s->r_buffer, .out_len =3D s->be_buffer_size, }; =20 @@ -424,7 +422,7 @@ static void tpm_tis_request_completed(TPMIf *ti) s->loc[locty].r_offset =3D 0; s->loc[locty].w_offset =3D 0; =20 - tpm_tis_show_buffer(s->loc[locty].r_buffer, s->be_buffer_size, + tpm_tis_show_buffer(s->r_buffer, s->be_buffer_size, "tpm_tis: From TPM"); =20 if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { @@ -444,10 +442,10 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_= t locty) uint16_t len; =20 if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { - len =3D MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), + len =3D MIN(tpm_cmd_get_size(&s->r_buffer), s->be_buffer_size); =20 - ret =3D s->loc[locty].r_buffer[s->loc[locty].r_offset++]; + ret =3D s->r_buffer[s->loc[locty].r_offset++]; if (s->loc[locty].r_offset >=3D len) { /* got last byte */ tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); @@ -493,12 +491,11 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: result buffer : ", s->loc[locty].r_offset); for (idx =3D 0; - idx < MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), - s->be_buffer_size); + idx < MIN(tpm_cmd_get_size(&s->r_buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].r_offset =3D=3D idx ? '>' : ' ', - s->loc[locty].r_buffer[idx], + s->r_buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n" @@ -506,12 +503,11 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: request buffer: ", s->loc[locty].w_offset); for (idx =3D 0; - idx < MIN(tpm_cmd_get_size(s->loc[locty].w_buffer), - s->be_buffer_size); + idx < MIN(tpm_cmd_get_size(s->w_buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].w_offset =3D=3D idx ? '>' : ' ', - s->loc[locty].w_buffer[idx], + s->w_buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n"); @@ -573,7 +569,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, if (s->active_locty =3D=3D locty) { if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { val =3D TPM_TIS_BURST_COUNT( - MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), + MIN(tpm_cmd_get_size(&s->r_buffer), s->be_buffer_size) - s->loc[locty].r_offset) | s->loc[locty].sts; } else { @@ -926,7 +922,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, =20 while ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) { if (s->loc[locty].w_offset < s->be_buffer_size) { - s->loc[locty].w_buffer[s->loc[locty].w_offset++] =3D + s->w_buffer[s->loc[locty].w_offset++] =3D (uint8_t)val; val >>=3D 8; size--; @@ -941,7 +937,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, /* we have a packet length - see if we have all of it */ bool need_irq =3D !(s->loc[locty].sts & TPM_TIS_STS_VALID); =20 - len =3D tpm_cmd_get_size(&s->loc[locty].w_buffer); + len =3D tpm_cmd_get_size(&s->w_buffer); if (len > s->loc[locty].w_offset) { tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID= ); --=20 2.5.5 From nobody Tue Oct 28 12:12:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 15139741149261.6302888007490992; Fri, 22 Dec 2017 12:21:54 -0800 (PST) Received: from localhost ([::1]:37021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTpF-0004uK-NR for importer@patchew.org; Fri, 22 Dec 2017 15:21:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTkM-00018F-R5 for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSTkI-0000iv-CZ for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:46 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47130) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSTkI-0000iF-3g for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:42 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBMKGfnq056278 for ; Fri, 22 Dec 2017 15:16:41 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2f18sr89a7-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 22 Dec 2017 15:16:40 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Dec 2017 13:16:40 -0700 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Dec 2017 13:16:37 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBMKGbs16226248; Fri, 22 Dec 2017 13:16:37 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 722E4BE039; Fri, 22 Dec 2017 13:16:37 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 24171BE03B; Fri, 22 Dec 2017 13:16:37 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 15:16:21 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17122220-0016-0000-0000-000008038DE9 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008245; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00964064; UDB=6.00487777; IPR=6.00744051; BA=6.00005755; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018678; XFM=3.00000015; UTC=2017-12-22 20:16:38 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122220-0017-0000-0000-00003CC04851 Message-Id: <1513973785-14427-7-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712220285 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id vBMKGfnq056278 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL v1 06/10] tpm_tis: merge read and write buffer into single buffer 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: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since we can only be in read or write mode, we can merge the buffers into a single buffer. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 34bfc86..ad36347 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -70,8 +70,7 @@ typedef struct TPMState { ISADevice busdev; MemoryRegion mmio; =20 - unsigned char w_buffer[TPM_TIS_BUFFER_MAX]; - unsigned char r_buffer[TPM_TIS_BUFFER_MAX]; + unsigned char buffer[TPM_TIS_BUFFER_MAX]; =20 uint8_t active_locty; uint8_t aborting_locty; @@ -257,7 +256,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { TPMLocality *locty_data =3D &s->loc[locty]; =20 - tpm_tis_show_buffer(s->w_buffer, s->be_buffer_size, + tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: To TPM"); =20 /* @@ -268,9 +267,9 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) =20 s->cmd =3D (TPMBackendCmd) { .locty =3D locty, - .in =3D s->w_buffer, + .in =3D s->buffer, .in_len =3D locty_data->w_offset, - .out =3D s->r_buffer, + .out =3D s->buffer, .out_len =3D s->be_buffer_size, }; =20 @@ -422,7 +421,7 @@ static void tpm_tis_request_completed(TPMIf *ti) s->loc[locty].r_offset =3D 0; s->loc[locty].w_offset =3D 0; =20 - tpm_tis_show_buffer(s->r_buffer, s->be_buffer_size, + tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: From TPM"); =20 if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { @@ -442,10 +441,10 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_= t locty) uint16_t len; =20 if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { - len =3D MIN(tpm_cmd_get_size(&s->r_buffer), + len =3D MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); =20 - ret =3D s->r_buffer[s->loc[locty].r_offset++]; + ret =3D s->buffer[s->loc[locty].r_offset++]; if (s->loc[locty].r_offset >=3D len) { /* got last byte */ tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); @@ -491,11 +490,11 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: result buffer : ", s->loc[locty].r_offset); for (idx =3D 0; - idx < MIN(tpm_cmd_get_size(&s->r_buffer), s->be_buffer_size); + idx < MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].r_offset =3D=3D idx ? '>' : ' ', - s->r_buffer[idx], + s->buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n" @@ -503,11 +502,11 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: request buffer: ", s->loc[locty].w_offset); for (idx =3D 0; - idx < MIN(tpm_cmd_get_size(s->w_buffer), s->be_buffer_size); + idx < MIN(tpm_cmd_get_size(s->buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].w_offset =3D=3D idx ? '>' : ' ', - s->w_buffer[idx], + s->buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n"); @@ -569,7 +568,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, if (s->active_locty =3D=3D locty) { if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { val =3D TPM_TIS_BURST_COUNT( - MIN(tpm_cmd_get_size(&s->r_buffer), + MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size) - s->loc[locty].r_offset) | s->loc[locty].sts; } else { @@ -922,7 +921,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, =20 while ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) { if (s->loc[locty].w_offset < s->be_buffer_size) { - s->w_buffer[s->loc[locty].w_offset++] =3D + s->buffer[s->loc[locty].w_offset++] =3D (uint8_t)val; val >>=3D 8; size--; @@ -937,7 +936,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, /* we have a packet length - see if we have all of it */ bool need_irq =3D !(s->loc[locty].sts & TPM_TIS_STS_VALID); =20 - len =3D tpm_cmd_get_size(&s->w_buffer); + len =3D tpm_cmd_get_size(&s->buffer); if (len > s->loc[locty].w_offset) { tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID= ); --=20 2.5.5 From nobody Tue Oct 28 12:12:51 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513974289659189.92652986381574; Fri, 22 Dec 2017 12:24:49 -0800 (PST) Received: from localhost ([::1]:37099 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTrj-0007H2-FW for importer@patchew.org; Fri, 22 Dec 2017 15:24:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTkO-0001AR-Sn for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSTkK-0000kt-Ch for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:48 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38978) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSTkK-0000jl-3S for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:44 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBMKGXxJ049738 for ; Fri, 22 Dec 2017 15:16:43 -0500 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2f16dfx4j1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 22 Dec 2017 15:16:42 -0500 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Dec 2017 13:16:42 -0700 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Dec 2017 13:16:39 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBMKGdSS63897798; Fri, 22 Dec 2017 13:16:39 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E2ED9BE03A; Fri, 22 Dec 2017 13:16:38 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 89E5EBE039; Fri, 22 Dec 2017 13:16:38 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 15:16:22 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17122220-0008-0000-0000-0000091281D9 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008245; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00964064; UDB=6.00487777; IPR=6.00744051; BA=6.00005755; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018678; XFM=3.00000015; UTC=2017-12-22 20:16:40 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122220-0009-0000-0000-0000454214B7 Message-Id: <1513973785-14427-8-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712220285 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id vBMKGXxJ049738 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL v1 07/10] tpm_tis: move r/w_offsets to TPMState 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: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Now that we have a single buffer, we also only need a single set of read/write offsets into that buffer. This works since only one locality can be active. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 57 +++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index ad36347..45d7b8c 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -61,9 +61,6 @@ typedef struct TPMLocality { uint32_t iface_id; uint32_t inte; uint32_t ints; - - uint16_t w_offset; - uint16_t r_offset; } TPMLocality; =20 typedef struct TPMState { @@ -71,6 +68,8 @@ typedef struct TPMState { MemoryRegion mmio; =20 unsigned char buffer[TPM_TIS_BUFFER_MAX]; + uint16_t w_offset; + uint16_t r_offset; =20 uint8_t active_locty; uint8_t aborting_locty; @@ -254,8 +253,6 @@ static void tpm_tis_sts_set(TPMLocality *l, uint32_t fl= ags) */ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { - TPMLocality *locty_data =3D &s->loc[locty]; - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: To TPM"); =20 @@ -268,7 +265,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) s->cmd =3D (TPMBackendCmd) { .locty =3D locty, .in =3D s->buffer, - .in_len =3D locty_data->w_offset, + .in_len =3D s->w_offset, .out =3D s->buffer, .out_len =3D s->be_buffer_size, }; @@ -350,8 +347,8 @@ static void tpm_tis_new_active_locality(TPMState *s, ui= nt8_t new_active_locty) /* abort -- this function switches the locality */ static void tpm_tis_abort(TPMState *s, uint8_t locty) { - s->loc[locty].r_offset =3D 0; - s->loc[locty].w_offset =3D 0; + s->r_offset =3D 0; + s->w_offset =3D 0; =20 DPRINTF("tpm_tis: tis_abort: new active locality is %d\n", s->next_loc= ty); =20 @@ -418,8 +415,8 @@ static void tpm_tis_request_completed(TPMIf *ti) tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); s->loc[locty].state =3D TPM_TIS_STATE_COMPLETION; - s->loc[locty].r_offset =3D 0; - s->loc[locty].w_offset =3D 0; + s->r_offset =3D 0; + s->w_offset =3D 0; =20 tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: From TPM"); @@ -444,14 +441,14 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_= t locty) len =3D MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); =20 - ret =3D s->buffer[s->loc[locty].r_offset++]; - if (s->loc[locty].r_offset >=3D len) { + ret =3D s->buffer[s->r_offset++]; + if (s->r_offset >=3D len) { /* got last byte */ tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); } DPRINTF("tpm_tis: tpm_tis_data_read byte 0x%02x [%d]\n", - ret, s->loc[locty].r_offset - 1); + ret, s->r_offset - 1); } =20 return ret; @@ -488,24 +485,24 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) =20 DPRINTF("tpm_tis: read offset : %d\n" "tpm_tis: result buffer : ", - s->loc[locty].r_offset); + s->r_offset); for (idx =3D 0; idx < MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", - s->loc[locty].r_offset =3D=3D idx ? '>' : ' ', + s->r_offset =3D=3D idx ? '>' : ' ', s->buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n" "tpm_tis: write offset : %d\n" "tpm_tis: request buffer: ", - s->loc[locty].w_offset); + s->w_offset); for (idx =3D 0; idx < MIN(tpm_cmd_get_size(s->buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", - s->loc[locty].w_offset =3D=3D idx ? '>' : ' ', + s->w_offset =3D=3D idx ? '>' : ' ', s->buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } @@ -570,9 +567,9 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, val =3D TPM_TIS_BURST_COUNT( MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size) - - s->loc[locty].r_offset) | s->loc[locty].sts; + - s->r_offset) | s->loc[locty].sts; } else { - avail =3D s->be_buffer_size - s->loc[locty].w_offset; + avail =3D s->be_buffer_size - s->w_offset; /* * byte-sized reads should not return 0x00 for 0x100 * available bytes. @@ -836,8 +833,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, switch (s->loc[locty].state) { =20 case TPM_TIS_STATE_READY: - s->loc[locty].w_offset =3D 0; - s->loc[locty].r_offset =3D 0; + s->w_offset =3D 0; + s->r_offset =3D 0; break; =20 case TPM_TIS_STATE_IDLE: @@ -855,8 +852,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, break; =20 case TPM_TIS_STATE_COMPLETION: - s->loc[locty].w_offset =3D 0; - s->loc[locty].r_offset =3D 0; + s->w_offset =3D 0; + s->r_offset =3D 0; /* shortcut to ready state with C/R set */ s->loc[locty].state =3D TPM_TIS_STATE_READY; if (!(s->loc[locty].sts & TPM_TIS_STS_COMMAND_READY)) { @@ -882,7 +879,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, } else if (val =3D=3D TPM_TIS_STS_RESPONSE_RETRY) { switch (s->loc[locty].state) { case TPM_TIS_STATE_COMPLETION: - s->loc[locty].r_offset =3D 0; + s->r_offset =3D 0; tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID| TPM_TIS_STS_DATA_AVAILABLE); @@ -920,8 +917,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, } =20 while ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) { - if (s->loc[locty].w_offset < s->be_buffer_size) { - s->buffer[s->loc[locty].w_offset++] =3D + if (s->w_offset < s->be_buffer_size) { + s->buffer[s->w_offset++] =3D (uint8_t)val; val >>=3D 8; size--; @@ -931,13 +928,13 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, } =20 /* check for complete packet */ - if (s->loc[locty].w_offset > 5 && + if (s->w_offset > 5 && (s->loc[locty].sts & TPM_TIS_STS_EXPECT)) { /* we have a packet length - see if we have all of it */ bool need_irq =3D !(s->loc[locty].sts & TPM_TIS_STS_VALID); =20 len =3D tpm_cmd_get_size(&s->buffer); - if (len > s->loc[locty].w_offset) { + if (len > s->w_offset) { tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID= ); } else { @@ -1026,8 +1023,8 @@ static void tpm_tis_reset(DeviceState *dev) s->loc[c].ints =3D 0; s->loc[c].state =3D TPM_TIS_STATE_IDLE; =20 - s->loc[c].w_offset =3D 0; - s->loc[c].r_offset =3D 0; + s->w_offset =3D 0; + s->r_offset =3D 0; } =20 tpm_tis_do_startup_tpm(s, s->be_buffer_size); --=20 2.5.5 From nobody Tue Oct 28 12:12:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513974313148844.4297538285673; Fri, 22 Dec 2017 12:25:13 -0800 (PST) Received: from localhost ([::1]:37110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTsT-0007qy-Ud for importer@patchew.org; Fri, 22 Dec 2017 15:25:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTkN-00018w-AZ for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSTkK-0000kd-8n for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:47 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38854 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSTkK-0000kG-2k for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:44 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBMKESnZ139369 for ; Fri, 22 Dec 2017 15:16:43 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2f12mutd90-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 22 Dec 2017 15:16:42 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Dec 2017 13:16:42 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Dec 2017 13:16:40 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBMKGeoF5177836; Fri, 22 Dec 2017 13:16:40 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 54E99BE040; Fri, 22 Dec 2017 13:16:40 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 06095BE03B; Fri, 22 Dec 2017 13:16:39 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 15:16:23 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17122220-0016-0000-0000-000008038DED X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008245; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00964064; UDB=6.00487777; IPR=6.00744051; BA=6.00005755; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018678; XFM=3.00000015; UTC=2017-12-22 20:16:41 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122220-0017-0000-0000-00003CC04859 Message-Id: <1513973785-14427-9-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712220285 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id vBMKESnZ139369 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL v1 08/10] tpm_tis: merge r/w_offset into rw_offset 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: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We can now merge the r_offset and w_offset into a single rw_offset. This is possible since when the offset is used for writing in RECEPTION state then reads are ignore. Conversely, when the offset is used for reading when in COMPLETION state, then writes are ignored. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 60 ++++++++++++++++++++--------------------------------= ---- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 45d7b8c..ac5d5c6 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -68,8 +68,7 @@ typedef struct TPMState { MemoryRegion mmio; =20 unsigned char buffer[TPM_TIS_BUFFER_MAX]; - uint16_t w_offset; - uint16_t r_offset; + uint16_t rw_offset; =20 uint8_t active_locty; uint8_t aborting_locty; @@ -257,7 +256,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) "tpm_tis: To TPM"); =20 /* - * w_offset serves as length indicator for length of data; + * rw_offset serves as length indicator for length of data; * it's reset when the response comes back */ s->loc[locty].state =3D TPM_TIS_STATE_EXECUTION; @@ -265,7 +264,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) s->cmd =3D (TPMBackendCmd) { .locty =3D locty, .in =3D s->buffer, - .in_len =3D s->w_offset, + .in_len =3D s->rw_offset, .out =3D s->buffer, .out_len =3D s->be_buffer_size, }; @@ -347,8 +346,7 @@ static void tpm_tis_new_active_locality(TPMState *s, ui= nt8_t new_active_locty) /* abort -- this function switches the locality */ static void tpm_tis_abort(TPMState *s, uint8_t locty) { - s->r_offset =3D 0; - s->w_offset =3D 0; + s->rw_offset =3D 0; =20 DPRINTF("tpm_tis: tis_abort: new active locality is %d\n", s->next_loc= ty); =20 @@ -415,8 +413,7 @@ static void tpm_tis_request_completed(TPMIf *ti) tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); s->loc[locty].state =3D TPM_TIS_STATE_COMPLETION; - s->r_offset =3D 0; - s->w_offset =3D 0; + s->rw_offset =3D 0; =20 tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: From TPM"); @@ -441,14 +438,14 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_= t locty) len =3D MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); =20 - ret =3D s->buffer[s->r_offset++]; - if (s->r_offset >=3D len) { + ret =3D s->buffer[s->rw_offset++]; + if (s->rw_offset >=3D len) { /* got last byte */ tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); } DPRINTF("tpm_tis: tpm_tis_data_read byte 0x%02x [%d]\n", - ret, s->r_offset - 1); + ret, s->rw_offset - 1); } =20 return ret; @@ -483,26 +480,14 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) (int)tpm_tis_mmio_read(opaque, base + regs[idx], 4)); } =20 - DPRINTF("tpm_tis: read offset : %d\n" + DPRINTF("tpm_tis: r/w offset : %d\n" "tpm_tis: result buffer : ", - s->r_offset); + s->rw_offset); for (idx =3D 0; idx < MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", - s->r_offset =3D=3D idx ? '>' : ' ', - s->buffer[idx], - ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); - } - DPRINTF("\n" - "tpm_tis: write offset : %d\n" - "tpm_tis: request buffer: ", - s->w_offset); - for (idx =3D 0; - idx < MIN(tpm_cmd_get_size(s->buffer), s->be_buffer_size); - idx++) { - DPRINTF("%c%02x%s", - s->w_offset =3D=3D idx ? '>' : ' ', + s->rw_offset =3D=3D idx ? '>' : ' ', s->buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } @@ -567,9 +552,9 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, val =3D TPM_TIS_BURST_COUNT( MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size) - - s->r_offset) | s->loc[locty].sts; + - s->rw_offset) | s->loc[locty].sts; } else { - avail =3D s->be_buffer_size - s->w_offset; + avail =3D s->be_buffer_size - s->rw_offset; /* * byte-sized reads should not return 0x00 for 0x100 * available bytes. @@ -833,8 +818,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, switch (s->loc[locty].state) { =20 case TPM_TIS_STATE_READY: - s->w_offset =3D 0; - s->r_offset =3D 0; + s->rw_offset =3D 0; break; =20 case TPM_TIS_STATE_IDLE: @@ -852,8 +836,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, break; =20 case TPM_TIS_STATE_COMPLETION: - s->w_offset =3D 0; - s->r_offset =3D 0; + s->rw_offset =3D 0; /* shortcut to ready state with C/R set */ s->loc[locty].state =3D TPM_TIS_STATE_READY; if (!(s->loc[locty].sts & TPM_TIS_STS_COMMAND_READY)) { @@ -879,7 +862,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, } else if (val =3D=3D TPM_TIS_STS_RESPONSE_RETRY) { switch (s->loc[locty].state) { case TPM_TIS_STATE_COMPLETION: - s->r_offset =3D 0; + s->rw_offset =3D 0; tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID| TPM_TIS_STS_DATA_AVAILABLE); @@ -917,8 +900,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, } =20 while ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) { - if (s->w_offset < s->be_buffer_size) { - s->buffer[s->w_offset++] =3D + if (s->rw_offset < s->be_buffer_size) { + s->buffer[s->rw_offset++] =3D (uint8_t)val; val >>=3D 8; size--; @@ -928,13 +911,13 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, } =20 /* check for complete packet */ - if (s->w_offset > 5 && + if (s->rw_offset > 5 && (s->loc[locty].sts & TPM_TIS_STS_EXPECT)) { /* we have a packet length - see if we have all of it */ bool need_irq =3D !(s->loc[locty].sts & TPM_TIS_STS_VALID); =20 len =3D tpm_cmd_get_size(&s->buffer); - if (len > s->w_offset) { + if (len > s->rw_offset) { tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID= ); } else { @@ -1023,8 +1006,7 @@ static void tpm_tis_reset(DeviceState *dev) s->loc[c].ints =3D 0; s->loc[c].state =3D TPM_TIS_STATE_IDLE; =20 - s->w_offset =3D 0; - s->r_offset =3D 0; + s->rw_offset =3D 0; } =20 tpm_tis_do_startup_tpm(s, s->be_buffer_size); --=20 2.5.5 From nobody Tue Oct 28 12:12:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513973944781834.1893680117536; Fri, 22 Dec 2017 12:19:04 -0800 (PST) Received: from localhost ([::1]:37001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTmX-0002YI-NT for importer@patchew.org; Fri, 22 Dec 2017 15:19:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTkU-0001HN-Fe for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSTkP-0000oO-DI for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:54 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54994) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSTkP-0000ny-4Y for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:49 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBMKES7x111918 for ; Fri, 22 Dec 2017 15:16:46 -0500 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 2f13r0evfq-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 22 Dec 2017 15:16:45 -0500 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Dec 2017 13:16:45 -0700 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Dec 2017 13:16:42 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBMKGfBO8913194; Fri, 22 Dec 2017 13:16:41 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C41A7BE03B; Fri, 22 Dec 2017 13:16:41 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 75E0ABE038; Fri, 22 Dec 2017 13:16:41 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 15:16:24 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17122220-0028-0000-0000-000008E35AA3 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008245; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00964064; UDB=6.00487777; IPR=6.00744051; MB=3.00018678; MTD=3.00000007; XFM=3.00000015; UTC=2017-12-22 20:16:43 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122220-0029-0000-0000-000038D6F44B Message-Id: <1513973785-14427-10-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712220285 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id vBMKES7x111918 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL v1 09/10] tpm: Implement tpm_sized_buffer_reset 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: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move the definition of TPMSizedBuffer out of tpm_tis.c into tpm_util.h and implement tpm_sized_buffer_reset() for the following patches to use. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 5 ----- hw/tpm/tpm_util.c | 7 +++++++ hw/tpm/tpm_util.h | 7 +++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index ac5d5c6..561384c 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -48,11 +48,6 @@ typedef enum { TPM_TIS_STATE_RECEPTION, } TPMTISState; =20 -typedef struct TPMSizedBuffer { - uint32_t size; - uint8_t *buffer; -} TPMSizedBuffer; - /* locality data -- all fields are persisted */ typedef struct TPMLocality { TPMTISState state; diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c index 17cafbe..747075e 100644 --- a/hw/tpm/tpm_util.c +++ b/hw/tpm/tpm_util.c @@ -355,3 +355,10 @@ int tpm_util_get_buffer_size(int tpm_fd, TPMVersion tp= m_version, =20 return 0; } + +void tpm_sized_buffer_reset(TPMSizedBuffer *tsb) +{ + g_free(tsb->buffer); + tsb->buffer =3D NULL; + tsb->size =3D 0; +} diff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h index 2393b6b..19b2847 100644 --- a/hw/tpm/tpm_util.h +++ b/hw/tpm/tpm_util.h @@ -42,4 +42,11 @@ int tpm_util_get_buffer_size(int tpm_fd, TPMVersion tpm_= version, #define DEFINE_PROP_TPMBE(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_tpm, TPMBackend *) =20 +typedef struct TPMSizedBuffer { + uint32_t size; + uint8_t *buffer; +} TPMSizedBuffer; + +void tpm_sized_buffer_reset(TPMSizedBuffer *tsb); + #endif /* TPM_TPM_UTIL_H */ --=20 2.5.5 From nobody Tue Oct 28 12:12:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513974127314131.9168296904437; Fri, 22 Dec 2017 12:22:07 -0800 (PST) Received: from localhost ([::1]:37022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTpM-00050n-83 for importer@patchew.org; Fri, 22 Dec 2017 15:21:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTkR-0001Em-Sk for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSTkN-0000mx-9g for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:51 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:44922 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eSTkN-0000mj-4G for qemu-devel@nongnu.org; Fri, 22 Dec 2017 15:16:47 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBMKER6L136652 for ; Fri, 22 Dec 2017 15:16:46 -0500 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0b-001b2d01.pphosted.com with ESMTP id 2f15r102c3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 22 Dec 2017 15:16:46 -0500 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Dec 2017 13:16:45 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 22 Dec 2017 13:16:43 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBMKGhm19306558; Fri, 22 Dec 2017 13:16:43 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 366DABE038; Fri, 22 Dec 2017 13:16:43 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id DBE8EBE03B; Fri, 22 Dec 2017 13:16:42 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 22 Dec 2017 15:16:25 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1513973785-14427-1-git-send-email-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17122220-0028-0000-0000-000008E35AA7 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008245; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00964064; UDB=6.00487777; IPR=6.00744051; MB=3.00018678; MTD=3.00000007; XFM=3.00000015; UTC=2017-12-22 20:16:45 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17122220-0029-0000-0000-000038D6F450 Message-Id: <1513973785-14427-11-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712220285 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0b-001b2d01.pphosted.com id vBMKER6L136652 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL v1 10/10] acpi: Update TPM2 ACPI table to more recent specs 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: , Cc: peter.maydell@linaro.org, Stefan Berger <"Stefan Bergerstefanb"@linux.vnet.ibm.com> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Stefan Berger More recent specs of the TPM2 ACPI table add fields for the log area start address and the log area minimum size, which we already use for the TCPA table. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/i386/acpi-build.c | 19 ++++++++++++++----- include/hw/acpi/acpi-defs.h | 7 +++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 5a6dee0..18b939e 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2274,16 +2274,25 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *link= er, GArray *tcpalog) } =20 static void -build_tpm2(GArray *table_data, BIOSLinker *linker) +build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) { - Acpi20TPM2 *tpm2_ptr; - - tpm2_ptr =3D acpi_data_push(table_data, sizeof *tpm2_ptr); + Acpi20TPM2 *tpm2_ptr =3D acpi_data_push(table_data, sizeof *tpm2_ptr); + unsigned log_addr_size =3D sizeof(tpm2_ptr->log_area_start_address); + unsigned log_addr_offset =3D + (char *)&tpm2_ptr->log_area_start_address - table_data->data; =20 tpm2_ptr->platform_class =3D cpu_to_le16(TPM2_ACPI_CLASS_CLIENT); if (TPM_IS_TIS(tpm_find())) { tpm2_ptr->control_area_address =3D cpu_to_le64(0); tpm2_ptr->start_method =3D cpu_to_le32(TPM2_START_METHOD_MMIO); + + tpm2_ptr->log_area_minimum_length =3D + cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE); + + /* log area start address to be filled by Guest linker */ + bios_linker_loader_add_pointer(linker, + ACPI_BUILD_TABLE_FILE, log_addr_offset, log_addr_size, + ACPI_BUILD_TPMLOG_FILE, 0); } else { g_warn_if_reached(); } @@ -2695,7 +2704,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState= *machine) =20 if (misc.tpm_version =3D=3D TPM_VERSION_2_0) { acpi_add_table(table_offsets, tables_blob); - build_tpm2(tables_blob, tables->linker); + build_tpm2(tables_blob, tables->linker, tables->tcpalog); } } if (pcms->numa_nodes) { diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h index 72be675..80c8099 100644 --- a/include/hw/acpi/acpi-defs.h +++ b/include/hw/acpi/acpi-defs.h @@ -558,8 +558,8 @@ typedef struct Acpi20Tcpa Acpi20Tcpa; /* * TPM2 * - * Following Level 00, Rev 00.37 of specs: - * http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification + * Following Version 1.2, Revision 8 of specs: + * https://trustedcomputinggroup.org/tcg-acpi-specification/ */ struct Acpi20TPM2 { ACPI_TABLE_HEADER_DEF @@ -567,6 +567,9 @@ struct Acpi20TPM2 { uint16_t reserved; uint64_t control_area_address; uint32_t start_method; + uint8_t start_method_params[12]; + uint32_t log_area_minimum_length; + uint64_t log_area_start_address; } QEMU_PACKED; typedef struct Acpi20TPM2 Acpi20TPM2; =20 --=20 2.5.5