From patchwork Mon Feb 29 17:29:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 8456741 Return-Path: X-Original-To: patchwork-tpmdd-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 70796C0553 for ; Mon, 29 Feb 2016 17:46:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 897FB20115 for ; Mon, 29 Feb 2016 17:46:58 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 742952010C for ; Mon, 29 Feb 2016 17:46:57 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aaRuH-0003S5-GI; Mon, 29 Feb 2016 17:46:53 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aaRuF-0003Ry-Su for tpmdd-devel@lists.sourceforge.net; Mon, 29 Feb 2016 17:46:51 +0000 X-ACL-Warn: Received: from e17.ny.us.ibm.com ([129.33.205.207]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1aaRuE-0001KL-RV for tpmdd-devel@lists.sourceforge.net; Mon, 29 Feb 2016 17:46:51 +0000 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 Feb 2016 12:36:32 -0500 Received: from d01dlp02.pok.ibm.com (9.56.250.167) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 Feb 2016 12:36:29 -0500 X-IBM-Helo: d01dlp02.pok.ibm.com X-IBM-MailFrom: stefanb@linux.vnet.ibm.com X-IBM-RcptTo: tpmdd-devel@lists.sourceforge.net Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 3FD7C6E8047 for ; Mon, 29 Feb 2016 12:23:20 -0500 (EST) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u1THaTdV36634696 for ; Mon, 29 Feb 2016 17:36:29 GMT Received: from d01av03.pok.ibm.com (localhost [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u1THZsjn029600 for ; Mon, 29 Feb 2016 12:36:28 -0500 Received: from dhcp-9-2-140-43.watson.ibm.com (dhcp-9-2-140-28.watson.ibm.com [9.2.140.28]) by d01av03.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u1THU0B8012420; Mon, 29 Feb 2016 12:30:04 -0500 From: Stefan Berger To: tpmdd-devel@lists.sourceforge.net Date: Mon, 29 Feb 2016 12:29:53 -0500 Message-Id: <1456766996-9300-8-git-send-email-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1456766996-9300-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1456766996-9300-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16022917-0041-0000-0000-0000036A70F6 X-Spam-Score: -0.0 (/) X-Headers-End: 1aaRuE-0001KL-RV Subject: [tpmdd-devel] [PATCH v4 07/10] tpm: Introduce TPM_CHIP_FLAG_VIRTUAL X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, HK_RANDOM_ENVFROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce TPM_CHIP_FLAG_VIRTUAL to be used when the chip device has no parent device. Also adapt tpm_chip_alloc so that it can be called with parent device being NULL. Signed-off-by: Stefan Berger Reviewed-by: Jason Gunthorpe --- drivers/char/tpm/tpm-chip.c | 9 +++++---- drivers/char/tpm/tpm-sysfs.c | 15 +++++++++++---- drivers/char/tpm/tpm.h | 5 +++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index b5720c6..2bcd8cd 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -170,9 +170,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *dev, chip->dev.class = tpm_class; chip->dev.release = tpm_dev_release; chip->dev.parent = dev; -#ifdef CONFIG_ACPI chip->dev.groups = chip->groups; -#endif if (chip->dev_num == 0) chip->dev.devt = MKDEV(MISC_MAJOR, TPM_MINOR); @@ -183,6 +181,9 @@ struct tpm_chip *tpm_chip_alloc(struct device *dev, if (rc) goto out; + if (!dev) + chip->flags |= TPM_CHIP_FLAG_VIRTUAL; + cdev_init(&chip->cdev, &tpm_fops); chip->cdev.owner = THIS_MODULE; chip->cdev.kobj.parent = &chip->dev.kobj; @@ -330,7 +331,7 @@ int tpm_chip_register(struct tpm_chip *chip) chip->flags |= TPM_CHIP_FLAG_REGISTERED; - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { + if (!(chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL))) { rc = __compat_only_sysfs_link_entry_to_kobj( &chip->dev.parent->kobj, &chip->dev.kobj, "ppi"); if (rc && rc != -ENOENT) { @@ -361,7 +362,7 @@ void tpm_chip_unregister(struct tpm_chip *chip) if (!(chip->flags & TPM_CHIP_FLAG_REGISTERED)) return; - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) + if (!(chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL))) sysfs_remove_link(&chip->dev.parent->kobj, "ppi"); tpm1_chip_unregister(chip); diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c index 34e7fc7..9ee0f4d 100644 --- a/drivers/char/tpm/tpm-sysfs.c +++ b/drivers/char/tpm/tpm-sysfs.c @@ -283,9 +283,15 @@ static const struct attribute_group tpm_dev_group = { int tpm_sysfs_add_device(struct tpm_chip *chip) { - int err; - err = sysfs_create_group(&chip->dev.parent->kobj, - &tpm_dev_group); + int err = 0; + + if (!(chip->flags & TPM_CHIP_FLAG_VIRTUAL)) + err = sysfs_create_group(&chip->dev.parent->kobj, + &tpm_dev_group); + else { + dev_set_drvdata(&chip->dev, chip); + chip->groups[chip->groups_cnt++] = &tpm_dev_group; + } if (err) dev_err(&chip->dev, @@ -300,5 +306,6 @@ void tpm_sysfs_del_device(struct tpm_chip *chip) * synchronizes this removal so that no callbacks are running or can * run again */ - sysfs_remove_group(&chip->dev.parent->kobj, &tpm_dev_group); + if (!(chip->flags & TPM_CHIP_FLAG_VIRTUAL)) + sysfs_remove_group(&chip->dev.parent->kobj, &tpm_dev_group); } diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 928b47f..f197eef 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -164,6 +164,7 @@ struct tpm_vendor_specific { enum tpm_chip_flags { TPM_CHIP_FLAG_REGISTERED = BIT(0), TPM_CHIP_FLAG_TPM2 = BIT(1), + TPM_CHIP_FLAG_VIRTUAL = BIT(2), }; struct tpm_chip { @@ -189,9 +190,9 @@ struct tpm_chip { struct dentry **bios_dir; -#ifdef CONFIG_ACPI - const struct attribute_group *groups[2]; + const struct attribute_group *groups[3]; unsigned int groups_cnt; +#ifdef CONFIG_ACPI acpi_handle acpi_dev_handle; char ppi_version[TPM_PPI_VERSION_LEN + 1]; #endif /* CONFIG_ACPI */