Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Improvements in tpm(4):



details:   https://anonhg.NetBSD.org/src/rev/505a0697bd38
branches:  trunk
changeset: 455126:505a0697bd38
user:      maxv <maxv%NetBSD.org@localhost>
date:      Tue Oct 08 18:43:02 2019 +0000

description:
Improvements in tpm(4):
 - Remove interrupt support, do polling only, avoids unnecessary trouble.
 - Simplify a few things.
 - Fix the suspend function, the SaveState command is 0x98, not 0x9C.
 - Make the driver MP-safe.
 - Sync the man page with reality.

diffstat:

 share/man/man4/tpm.4    |   68 ++++----
 sys/dev/acpi/tpm_acpi.c |   46 ++----
 sys/dev/ic/tpm.c        |  352 ++++++++++-------------------------------------
 sys/dev/ic/tpmreg.h     |    3 +-
 sys/dev/ic/tpmvar.h     |   41 +----
 sys/dev/isa/tpm_isa.c   |   83 ++++++----
 6 files changed, 179 insertions(+), 414 deletions(-)

diffs (truncated from 1059 to 300 lines):

diff -r 391c80bf5c2d -r 505a0697bd38 share/man/man4/tpm.4
--- a/share/man/man4/tpm.4      Tue Oct 08 18:02:46 2019 +0000
+++ b/share/man/man4/tpm.4      Tue Oct 08 18:43:02 2019 +0000
@@ -1,20 +1,33 @@
-.\"    $NetBSD: tpm.4,v 1.4 2018/02/22 01:40:49 pgoyette Exp $
-.\"
-.\" Copyright (c) 2010 Hans-Jörg Höxer, <Hans-Joerg.Hoexer%genua.de@localhost>
+.\"    $NetBSD: tpm.4,v 1.5 2019/10/08 18:43:03 maxv Exp $
 .\"
-.\" Permission to use, copy, modify, and distribute this software for any
-.\" purpose with or without fee is hereby granted, provided that the above
-.\" copyright notice and this permission notice appear in all copies.
+.\" Copyright (c) 2019 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Maxime Villard.
 .\"
-.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
 .\"
-.Dd February 22, 2018
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd October 6, 2019
 .Dt TPM 4
 .Os
 .Sh NAME
@@ -22,40 +35,22 @@
 .Nd Trusted Platform Module
 .Sh SYNOPSIS
 .Cd "tpm* at isa? iomem 0xfed40000"
-.Cd "tpm* at isa? iomem 0xfed40000 irq 7"
 .Cd "tpm* at acpi?"
 .Sh DESCRIPTION
 The
 .Nm
-driver provides support for various trusted platform modules (TPM) that can
-store cryptographic keys.
+driver provides support for various Trusted Platform Module (TPM) chips.
 .Pp
 Supported modules:
 .Pp
 .Bl -bullet -compact -offset indent
 .It
-Atmel 97SC3203
-.It
-Broadcom BCM0102
-.It
-Infineon IFX SLD 9630 TT 1.1 and IFX SLB 9635 TT 1.2
+TPM 2.0 chips over ACPI
 .It
-Intel INTC0102
-.It
-Sinosun SNS SSX35
-.It
-STM ST19WP18
-.It
-Winbond WEC WPCT200
+TPM 1.2 chips over ISA
 .El
 .Pp
-The driver can be configured to use an IRQ by providing a free ISA
-interrupt vector using the keyword
-.Em irq
-in the kernel configuration file or using
-.Xr config 1 .
-If not IRQ is specified, the driver uses polling.
-This is the default configuration.
+Note that the supported interface version is TIS1.2 in each case.
 .Sh SEE ALSO
 .Xr config 1 ,
 .Xr intro 4
@@ -64,6 +59,7 @@
 The
 .Nm
 driver was written by
+.An Maxime Villard ,
 .An Michael Shalayeff
 and
 .An Hans-Joerg Hoexer .
diff -r 391c80bf5c2d -r 505a0697bd38 sys/dev/acpi/tpm_acpi.c
--- a/sys/dev/acpi/tpm_acpi.c   Tue Oct 08 18:02:46 2019 +0000
+++ b/sys/dev/acpi/tpm_acpi.c   Tue Oct 08 18:43:02 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tpm_acpi.c,v 1.8 2019/06/22 12:57:40 maxv Exp $ */
+/* $NetBSD: tpm_acpi.c,v 1.9 2019/10/08 18:43:02 maxv Exp $ */
 
 /*
  * Copyright (c) 2012, 2019 The NetBSD Foundation, Inc.
@@ -30,10 +30,9 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.8 2019/06/22 12:57:40 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.9 2019/10/08 18:43:02 maxv Exp $");
 
 #include <sys/param.h>
-#include <sys/device.h>
 #include <sys/systm.h>
 #include <sys/device.h>
 #include <sys/bus.h>
@@ -45,8 +44,6 @@
 #include <dev/acpi/acpireg.h>
 #include <dev/acpi/acpivar.h>
 
-#include <dev/isa/isavar.h>
-
 #include "ioconf.h"
 
 #define _COMPONENT     ACPI_RESOURCE_COMPONENT
@@ -100,41 +97,41 @@
        struct acpi_attach_args *aa = aux;
        struct acpi_resources res;
        struct acpi_mem *mem;
-       struct acpi_irq *irq;
        bus_addr_t base;
        bus_addr_t size;
-       int rv, inum;
-
-       sc->sc_dev = self;
-       sc->sc_ver = TPM_2_0;
+       int rv;
 
        rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS", &res,
            &acpi_resource_parse_ops_default);
        if (ACPI_FAILURE(rv)) {
-               aprint_error_dev(sc->sc_dev, "cannot parse resources %d\n", rv);
+               aprint_error_dev(self, "cannot parse resources %d\n", rv);
                return;
        }
 
        mem = acpi_res_mem(&res, 0);
        if (mem == NULL) {
-               aprint_error_dev(sc->sc_dev, "cannot find mem\n");
+               aprint_error_dev(self, "cannot find mem\n");
                goto out;
        }
        if (mem->ar_length != TPM_SPACE_SIZE) {
-               aprint_error_dev(sc->sc_dev,
-                   "wrong size mem %"PRIu64" != %u\n",
+               aprint_error_dev(self, "wrong size mem %"PRIu64" != %u\n",
                    (uint64_t)mem->ar_length, TPM_SPACE_SIZE);
                goto out;
        }
 
-       base = mem->ar_base;
-       size = mem->ar_length;
-       sc->sc_bt = aa->aa_memt;
+       sc->sc_dev = self;
+       sc->sc_ver = TPM_2_0;
+       mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
+       sc->sc_busy = false;
        sc->sc_init = tpm_tis12_init;
        sc->sc_start = tpm_tis12_start;
        sc->sc_read = tpm_tis12_read;
        sc->sc_write = tpm_tis12_write;
        sc->sc_end = tpm_tis12_end;
+       sc->sc_bt = aa->aa_memt;
+
+       base = mem->ar_base;
+       size = mem->ar_length;
 
        if (bus_space_map(sc->sc_bt, base, size, 0, &sc->sc_bh)) {
                aprint_error_dev(sc->sc_dev, "cannot map registers\n");
@@ -146,24 +143,11 @@
                goto out1;
        }
 
-       irq = acpi_res_irq(&res, 0);
-       if (irq == NULL)
-               inum = -1;
-       else
-               inum = irq->ar_irq;
-
-       if ((rv = (*sc->sc_init)(sc, inum)) != 0) {
+       if ((*sc->sc_init)(sc) != 0) {
                aprint_error_dev(sc->sc_dev, "cannot init device %d\n", rv);
                goto out1;
        }
 
-       if (inum != -1 &&
-           (sc->sc_ih = isa_intr_establish(aa->aa_ic, irq->ar_irq,
-           IST_EDGE, IPL_TTY, tpm_intr, sc)) == NULL) {
-               aprint_error_dev(sc->sc_dev, "cannot establish interrupt\n");
-               goto out1;
-       }
-
        acpi_resource_cleanup(&res);
        return;
 
diff -r 391c80bf5c2d -r 505a0697bd38 sys/dev/ic/tpm.c
--- a/sys/dev/ic/tpm.c  Tue Oct 08 18:02:46 2019 +0000
+++ b/sys/dev/ic/tpm.c  Tue Oct 08 18:43:02 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tpm.c,v 1.13 2019/06/22 12:57:41 maxv Exp $    */
+/*     $NetBSD: tpm.c,v 1.14 2019/10/08 18:43:02 maxv Exp $    */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.13 2019/06/22 12:57:41 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.14 2019/10/08 18:43:02 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -67,6 +67,7 @@
 
 #define TPM_BUFSIZ     1024
 #define TPM_HDRSIZE    10
+
 #define TPM_PARAM_SIZE 0x0001  /* that's a flag */
 
 /* Timeouts. */
@@ -79,23 +80,6 @@
        (TPM_INTF_DATA_AVAIL_INT|TPM_INTF_LOCALITY_CHANGE_INT| \
         TPM_INTF_INT_LEVEL_LOW)
 
-static const struct {
-       uint32_t devid;
-       const char *name;
-       int flags;
-#define TPM_DEV_NOINTS 0x0001
-} tpm_devs[] = {
-       { 0x000615d1, "IFX SLD 9630 TT 1.1", 0 },
-       { 0x000b15d1, "IFX SLB 9635 TT 1.2", 0 },
-       { 0x100214e4, "Broadcom BCM0102", TPM_DEV_NOINTS },
-       { 0x00fe1050, "WEC WPCT200", 0 },
-       { 0x687119fa, "SNS SSX35", 0 },
-       { 0x2e4d5453, "STM ST19WP18", 0 },
-       { 0x32021114, "ATML 97SC3203", TPM_DEV_NOINTS },
-       { 0x10408086, "INTEL INTC0102", 0 },
-       { 0, "", TPM_DEV_NOINTS },
-};
-
 static inline int
 tpm_tmotohz(int tmo)
 {
@@ -129,7 +113,7 @@
        while ((r = bus_space_read_1(sc->sc_bt, sc->sc_bh, TPM_ACCESS) &
            (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY)) !=
            (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY) && to--) {
-               rv = tsleep(sc->sc_init, PRIBIO | PCATCH, "tpm_locality", 1);
+               rv = tsleep(sc->sc_init, PCATCH, "tpm_locality", 1);
                if (rv && rv != EWOULDBLOCK) {
                        return rv;
                }
@@ -161,7 +145,7 @@
                if (burst)
                        return burst;
 
-               rv = tsleep(sc, PRIBIO | PCATCH, "tpm_getburst", 1);
+               rv = tsleep(sc, PCATCH, "tpm_getburst", 1);
                if (rv && rv != EWOULDBLOCK) {
                        return 0;
                }
@@ -189,9 +173,9 @@
 {
        struct tpm_softc *sc = device_private(dev);
        static const uint8_t command[] = {
-               0, 193,         /* TPM_TAG_RQU_COMMAND */
+               0, 0xC1,        /* TPM_TAG_RQU_COMMAND */
                0, 0, 0, 10,    /* Length in bytes */
-               0, 0, 0, 156    /* TPM_ORD_SaveStates */
+               0, 0, 0, 0x98   /* TPM_ORD_SaveState */
        };
        uint8_t scratch[sizeof(command)];
 
@@ -209,16 +193,13 @@
 
 /* -------------------------------------------------------------------------- */
 
-/*
- * Wait for given status bits using polling.



Home | Main Index | Thread Index | Old Index