From patchwork Thu Mar 5 18:54:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Richter X-Patchwork-Id: 1249824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48YKgR2cdZz9sPK for ; Fri, 6 Mar 2020 05:54:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48YKgQ5H2fzDqQf for ; Fri, 6 Mar 2020 05:54:58 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=erichte@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 48YKgD51DszDqQG for ; Fri, 6 Mar 2020 05:54:41 +1100 (AEDT) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 025IomLE068255 for ; Thu, 5 Mar 2020 13:54:38 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0b-001b2d01.pphosted.com with ESMTP id 2yhsv5g157-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 05 Mar 2020 13:54:38 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 5 Mar 2020 18:54:36 -0000 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 5 Mar 2020 18:54:35 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 025IrYXX45875676 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 5 Mar 2020 18:53:34 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4DFB5A4060; Thu, 5 Mar 2020 18:54:33 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 31025A4054; Thu, 5 Mar 2020 18:54:32 +0000 (GMT) Received: from ceres.ibmuc.com (unknown [9.80.238.178]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 5 Mar 2020 18:54:31 +0000 (GMT) From: Eric Richter To: skiboot@lists.ozlabs.org Date: Thu, 5 Mar 2020 12:54:30 -0600 X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20030518-4275-0000-0000-000003A8BDDC X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20030518-4276-0000-0000-000038BDCEBC Message-Id: <20200305185430.31566-1-erichte@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-05_06:2020-03-05, 2020-03-05 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxscore=0 clxscore=1011 mlxlogscore=673 impostorscore=0 malwarescore=0 adultscore=0 phishscore=0 suspectscore=3 spamscore=0 lowpriorityscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2003050111 Subject: [Skiboot] [PATCH] tpm_i2c_nuvoton: check TPM vendor id register during probe X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nayna@linux.ibm.com Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The driver for the nuvoton i2c TPM does not currently check if there is a functional TPM at the bus and address given by the device tree. This patch adds a simple check of the TPM vendor id register, compares against the known expected value for the chip, skips registering it if the chip is inaccessible or returns an unexpected id. Signed-off-by: Eric Richter --- libstb/drivers/tpm_i2c_nuvoton.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libstb/drivers/tpm_i2c_nuvoton.c b/libstb/drivers/tpm_i2c_nuvoton.c index 3679ddaf..882018e4 100644 --- a/libstb/drivers/tpm_i2c_nuvoton.c +++ b/libstb/drivers/tpm_i2c_nuvoton.c @@ -30,6 +30,7 @@ #define TPM_BURST_COUNT 0x01 #define TPM_DATA_FIFO_W 0x20 #define TPM_DATA_FIFO_R 0x40 +#define TPM_VID_DID 0x60 /* Bit masks for the TPM STATUS register */ #define TPM_STS_VALID 0x80 @@ -42,6 +43,8 @@ /* TPM Driver values */ #define MAX_STSVALID_POLLS 5 #define TPM_TIMEOUT_INTERVAL 10 +#define TPM_650_VENDOR_ID 0x5010FE00 +#define TPM_VENDOR_ID_MASK 0xFFFFFF00 static struct tpm_dev *tpm_device = NULL; @@ -552,6 +555,7 @@ void tpm_i2c_nuvoton_probe(void) struct dt_node *node = NULL; struct i2c_bus *bus; const char *name; + uint32_t vendor = 0; dt_for_each_compatible(dt_root, node, "nuvoton,npct650") { if (!dt_node_is_enabled(node)) @@ -588,6 +592,19 @@ void tpm_i2c_nuvoton_probe(void) "found, tpm node parent %p\n", node->parent); goto disable; } + /* ensure there's really the TPM we expect at that address */ + if (tpm_i2c_request_send(tpm_device, SMBUS_READ, TPM_VID_DID, + 1, &vendor, sizeof(vendor)) || + (vendor & TPM_VENDOR_ID_MASK) != TPM_650_VENDOR_ID) { + prlog(PR_ERR, "NUVOTON: i2c device inaccessible, or " + "expected vendor id mismatch\n"); + if (vendor) { + prlog(PR_ERR, "NUVOTON: expected 0x%X, " + "got 0x%X\n", TPM_650_VENDOR_ID, vendor); + } + free(tpm_device); + continue; + } if (tpm_register_chip(node, tpm_device, &tpm_i2c_nuvoton_driver)) { free(tpm_device);