From patchwork Fri Mar 6 17:13:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Richter X-Patchwork-Id: 1250473 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48Yvbv4DMfz9sNg for ; Sat, 7 Mar 2020 04:23:55 +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 48Yvbv3YQLzDsNx for ; Sat, 7 Mar 2020 04:23:55 +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 48YvMt1w1jzDr6b for ; Sat, 7 Mar 2020 04:13:29 +1100 (AEDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 026GxS8W104874 for ; Fri, 6 Mar 2020 12:13:24 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ykatayrbb-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 06 Mar 2020 12:13:24 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 6 Mar 2020 17:13:22 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 6 Mar 2020 17:13:20 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 026HDJvA28966980 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 6 Mar 2020 17:13:19 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2E049A4054; Fri, 6 Mar 2020 17:13:19 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E29FA405B; Fri, 6 Mar 2020 17:13:18 +0000 (GMT) Received: from ceres.ibmuc.com (unknown [9.80.224.179]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 6 Mar 2020 17:13:17 +0000 (GMT) From: Eric Richter To: skiboot@lists.ozlabs.org Date: Fri, 6 Mar 2020 11:13:16 -0600 X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20030617-0012-0000-0000-0000038DD727 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20030617-0013-0000-0000-000021CA9A4E Message-Id: <20200306171316.13998-1-erichte@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-06_05:2020-03-06, 2020-03-06 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 suspectscore=3 clxscore=1015 lowpriorityscore=0 priorityscore=1501 mlxlogscore=540 malwarescore=0 phishscore=0 mlxscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2003060111 Subject: [Skiboot] [PATCH v2] 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 --- V2: - split multi-line conditional into two separate checks - errors break loop and disable node rather than continuing - s/TPM_650_VENDOR_ID/TPM_NUVOTON_650_ID libstb/drivers/tpm_i2c_nuvoton.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstb/drivers/tpm_i2c_nuvoton.c b/libstb/drivers/tpm_i2c_nuvoton.c index 3679ddaf..b6dde324 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_NUVOTON_650_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,16 @@ 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))) { + prlog(PR_ERR, "NUVOTON: i2c device inaccessible\n"); + goto disable; + } + if ((vendor & TPM_VENDOR_ID_MASK) != TPM_NUVOTON_650_ID) { + prlog(PR_ERR, "NUVOTON: expected vendor id mismatch\n"); + goto disable; + } if (tpm_register_chip(node, tpm_device, &tpm_i2c_nuvoton_driver)) { free(tpm_device);