Revamp the TPM driver

* Fix several bugs, and clean up.
 * Drop the "legacy" interface, it relied on an undocumented global
   variable that was never initialized. It likely had never been tested
   either, so good riddance.
 * Add support for TPM 2.0 chips via ACPI. For these we use the TIS1.2
   interface, same as TPM 1.2.
 * Provide an ioctl to fetch TPM information from the driver.

Tested on a Lenovo desktop with ACPI-TPM2.0, an HP laptop ACPI-TPM2.0, a
Dell laptop with ISA-TPM1.2.
This commit is contained in:
maxv 2019-06-22 12:57:40 +00:00
parent 5aa91c9ffd
commit d894e04d60
5 changed files with 581 additions and 942 deletions

View File

@ -1,11 +1,11 @@
/* $NetBSD: tpm_acpi.c,v 1.7 2018/12/09 11:12:58 jdolecek Exp $ */
/* $NetBSD: tpm_acpi.c,v 1.8 2019/06/22 12:57:40 maxv Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
/*
* Copyright (c) 2012, 2019 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
* by Christos Zoulas and Maxime Villard.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -28,31 +28,9 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 2008, 2009 Michael Shalayeff
* Copyright (c) 2009, 2010 Hans-Jörg Höxer
* All rights reserved.
*
* 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.
*
* 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 MIND, 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.
*/
/*
* ACPI attachment for the Infineon SLD 9630 TT 1.1 and SLB 9635 TT 1.2
* trusted platform module. See www.trustedcomputinggroup.org
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.7 2018/12/09 11:12:58 jdolecek Exp $");
__KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.8 2019/06/22 12:57:40 maxv Exp $");
#include <sys/param.h>
#include <sys/device.h>
@ -71,44 +49,48 @@ __KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.7 2018/12/09 11:12:58 jdolecek Exp $"
#include "ioconf.h"
#define _COMPONENT ACPI_RESOURCE_COMPONENT
ACPI_MODULE_NAME ("tpm_acpi")
#define _COMPONENT ACPI_RESOURCE_COMPONENT
ACPI_MODULE_NAME ("tpm_acpi")
static int tpm_acpi_match(device_t, cfdata_t, void *);
static void tpm_acpi_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(tpm_acpi, sizeof(struct tpm_softc), tpm_acpi_match,
tpm_acpi_attach, NULL, NULL);
/*
* Supported device IDs
* Supported TPM 2.0 devices.
*/
#ifdef notyet
static const char * const tpm_acpi_ids[] = {
"IFX0101",
"IFX0102",
static const char * const tpm2_acpi_ids[] = {
"MSFT0101",
NULL
};
#endif
static int
tpm_acpi_match(device_t parent, cfdata_t match, void *aux)
{
struct acpi_attach_args *aa = aux;
ACPI_TABLE_TPM2 *tpm2;
ACPI_STATUS rv;
if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
return 0;
/* There can be only one. */
/* We support only one TPM. */
if (tpm_cd.cd_devs && tpm_cd.cd_devs[0])
return 0;
#ifdef notyet
return acpi_match_hid(aa->aa_node->ad_devinfo, tpm_acpi_ids);
#else
return 0;
#endif
if (!acpi_match_hid(aa->aa_node->ad_devinfo, tpm2_acpi_ids))
return 0;
/* Make sure it uses TIS, and not CRB. */
rv = AcpiGetTable(ACPI_SIG_TPM2, 1, (ACPI_TABLE_HEADER **)&tpm2);
if (ACPI_FAILURE(rv))
return 0;
if (tpm2->StartMethod != ACPI_TPM2_MEMORY_MAPPED)
return 0;
return 1;
}
static void
@ -117,7 +99,6 @@ tpm_acpi_attach(device_t parent, device_t self, void *aux)
struct tpm_softc *sc = device_private(self);
struct acpi_attach_args *aa = aux;
struct acpi_resources res;
struct acpi_io *io;
struct acpi_mem *mem;
struct acpi_irq *irq;
bus_addr_t base;
@ -125,59 +106,43 @@ tpm_acpi_attach(device_t parent, device_t self, void *aux)
int rv, inum;
sc->sc_dev = self;
sc->sc_ver = TPM_2_0;
/* Parse our resources */
rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS", &res,
&acpi_resource_parse_ops_default);
if (ACPI_FAILURE(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);
return;
return;
}
io = acpi_res_io(&res, 0);
if (io && tpm_legacy_probe(aa->aa_iot, io->ar_base)) {
sc->sc_bt = aa->aa_iot;
base = io->ar_base;
size = io->ar_length;
sc->sc_batm = aa->aa_iot;
sc->sc_init = tpm_legacy_init;
sc->sc_start = tpm_legacy_start;
sc->sc_read = tpm_legacy_read;
sc->sc_write = tpm_legacy_write;
sc->sc_end = tpm_legacy_end;
mem = NULL;
} else {
mem = acpi_res_mem(&res, 0);
if (mem == NULL) {
aprint_error_dev(sc->sc_dev, "cannot find mem\n");
goto out;
}
if (mem->ar_length != TPM_SIZE) {
aprint_error_dev(sc->sc_dev,
"wrong size mem %"PRIu64" != %u\n",
(uint64_t)mem->ar_length, TPM_SIZE);
goto out;
}
base = mem->ar_base;
size = mem->ar_length;
sc->sc_bt = aa->aa_memt;
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;
mem = acpi_res_mem(&res, 0);
if (mem == NULL) {
aprint_error_dev(sc->sc_dev, "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",
(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_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;
if (bus_space_map(sc->sc_bt, base, size, 0, &sc->sc_bh)) {
aprint_error_dev(sc->sc_dev, "cannot map registers\n");
goto out;
}
if (mem && !tpm_tis12_probe(sc->sc_bt, sc->sc_bh)) {
aprint_error_dev(sc->sc_dev, "1.2 probe failed\n");
if (!tpm_tis12_probe(sc->sc_bt, sc->sc_bh)) {
aprint_error_dev(sc->sc_dev, "TIS1.2 probe failed\n");
goto out1;
}
@ -187,7 +152,7 @@ tpm_acpi_attach(device_t parent, device_t self, void *aux)
else
inum = irq->ar_irq;
if ((rv = (*sc->sc_init)(sc, inum, device_xname(sc->sc_dev))) != 0) {
if ((rv = (*sc->sc_init)(sc, inum)) != 0) {
aprint_error_dev(sc->sc_dev, "cannot init device %d\n", rv);
goto out1;
}
@ -199,9 +164,9 @@ tpm_acpi_attach(device_t parent, device_t self, void *aux)
goto out1;
}
if (!pmf_device_register(sc->sc_dev, tpm_suspend, tpm_resume))
aprint_error_dev(sc->sc_dev, "Cannot set power mgmt handler\n");
acpi_resource_cleanup(&res);
return;
out1:
bus_space_unmap(sc->sc_bt, sc->sc_bh, size);
out:

File diff suppressed because it is too large Load Diff

View File

@ -1,100 +1,90 @@
/* $NetBSD: tpmreg.h,v 1.3 2012/01/23 04:12:26 christos Exp $ */
/* $NetBSD: tpmreg.h,v 1.4 2019/06/22 12:57:41 maxv Exp $ */
/*
* Copyright (c) 2008, 2009 Michael Shalayeff
* Copyright (c) 2009, 2010 Hans-Jörg Höxer
* Copyright (c) 2019 The NetBSD Foundation, Inc.
* All rights reserved.
*
* 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.
* 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 MIND, 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.
*
* 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.
*/
#define TPM_BUFSIZ 1024
/*
* TPM Interface Specification 1.2 (TIS12).
*/
#define TPM_HDRSIZE 10
#define TPM_ACCESS 0x0000 /* 8bit register */
#define TPM_ACCESS_VALID __BIT(7)
#define TPM_ACCESS_ACTIVE_LOCALITY __BIT(5)
#define TPM_ACCESS_BEEN_SEIZED __BIT(4)
#define TPM_ACCESS_SEIZE __BIT(3)
#define TPM_ACCESS_PENDING_REQUEST __BIT(2)
#define TPM_ACCESS_REQUEST_USE __BIT(1)
#define TPM_ACCESS_ESTABLISHMENT __BIT(0)
#define TPM_PARAM_SIZE 0x0001
#define TPM_INT_ENABLE 0x0008 /* 32bit register */
#define TPM_GLOBAL_INT_ENABLE __BIT(31)
#define TPM_CMD_READY_INT __BIT(7)
#define TPM_TYPE_POLARITY __BITS(4,3)
#define TPM_INT_LEVEL_HIGH __SHIFTIN(0, TPM_TYPE_POLARITY)
#define TPM_INT_LEVEL_LOW __SHIFTIN(1, TPM_TYPE_POLARITY)
#define TPM_INT_EDGE_RISING __SHIFTIN(2, TPM_TYPE_POLARITY)
#define TPM_INT_EDGE_FALLING __SHIFTIN(3, TPM_TYPE_POLARITY)
#define TPM_LOCALITY_CHANGE_INT __BIT(2)
#define TPM_STS_VALID_INT __BIT(1)
#define TPM_DATA_AVAIL_INT __BIT(0)
#define TPM_ACCESS 0x0000 /* access register */
#define TPM_ACCESS_ESTABLISHMENT 0x01 /* establishment */
#define TPM_ACCESS_REQUEST_USE 0x02 /* request using locality */
#define TPM_ACCESS_REQUEST_PENDING 0x04 /* pending request */
#define TPM_ACCESS_SEIZE 0x08 /* request locality seize */
#define TPM_ACCESS_SEIZED 0x10 /* locality has been seized */
#define TPM_ACCESS_ACTIVE_LOCALITY 0x20 /* locality is active */
#define TPM_ACCESS_VALID 0x80 /* bits are valid */
#define TPM_ACCESS_BITS \
"\020\01EST\02REQ\03PEND\04SEIZE\05SEIZED\06ACT\010VALID"
#define TPM_INT_VECTOR 0x000c /* 8bit register */
#define TPM_INT_STATUS 0x0010 /* 32bit register */
#define TPM_INTERRUPT_ENABLE 0x0008
#define TPM_GLOBAL_INT_ENABLE 0x80000000 /* enable ints */
#define TPM_CMD_READY_INT 0x00000080 /* cmd ready enable */
#define TPM_INT_EDGE_FALLING 0x00000018
#define TPM_INT_EDGE_RISING 0x00000010
#define TPM_INT_LEVEL_LOW 0x00000008
#define TPM_INT_LEVEL_HIGH 0x00000000
#define TPM_LOCALITY_CHANGE_INT 0x00000004 /* locality change enable */
#define TPM_STS_VALID_INT 0x00000002 /* int on TPM_STS_VALID is set */
#define TPM_DATA_AVAIL_INT 0x00000001 /* int on TPM_STS_DATA_AVAIL is set */
#define TPM_INTERRUPT_ENABLE_BITS \
"\177\020b\0DRDY\0b\1STSVALID\0b\2LOCCHG\0" \
"F\3\2:\0HIGH\0:\1LOW\0:\2RISE\0:\3FALL\0" \
"b\7IRDY\0b\x1fGIENABLE\0"
#define TPM_INTF_CAPABILITY 0x0014 /* 32bit register */
#define TPM_INTF_BURST_COUNT_STATIC __BIT(8)
#define TPM_INTF_CMD_READY_INT __BIT(7)
#define TPM_INTF_INT_EDGE_FALLING __BIT(6)
#define TPM_INTF_INT_EDGE_RISING __BIT(5)
#define TPM_INTF_INT_LEVEL_LOW __BIT(4)
#define TPM_INTF_INT_LEVEL_HIGH __BIT(3)
#define TPM_INTF_LOCALITY_CHANGE_INT __BIT(2)
#define TPM_INTF_STS_VALID_INT __BIT(1)
#define TPM_INTF_DATA_AVAIL_INT __BIT(0)
#define TPM_INTF_CAPABILITY_BITS \
"\020\01IDRDY\02ISTSV\03ILOCH\04IHIGH\05ILOW\06IRISE\07IFALL\010IRDY\011BCST"
#define TPM_INT_VECTOR 0x000c /* 8 bit reg for 4 bit irq vector */
#define TPM_INT_STATUS 0x0010 /* bits are & 0x87 from TPM_INTERRUPT_ENABLE */
#define TPM_STS 0x0018 /* 24bit register */
#define TPM_STS_BURST_COUNT __BITS(23,8)
#define TPM_STS_STATUS_BITS __BITS(7,0)
#define TPM_STS_VALID __BIT(7)
#define TPM_STS_CMD_READY __BIT(6)
#define TPM_STS_GO __BIT(5)
#define TPM_STS_DATA_AVAIL __BIT(4)
#define TPM_STS_DATA_EXPECT __BIT(3)
#define TPM_STS_RESP_RETRY __BIT(1)
#define TPM_INTF_CAPABILITIES 0x0014 /* capability register */
#define TPM_INTF_BURST_COUNT_STATIC 0x0100 /* TPM_STS_BMASK static */
#define TPM_INTF_CMD_READY_INT 0x0080 /* int on ready supported */
#define TPM_INTF_INT_EDGE_FALLING 0x0040 /* falling edge ints supported */
#define TPM_INTF_INT_EDGE_RISING 0x0020 /* rising edge ints supported */
#define TPM_INTF_INT_LEVEL_LOW 0x0010 /* level-low ints supported */
#define TPM_INTF_INT_LEVEL_HIGH 0x0008 /* level-high ints supported */
#define TPM_INTF_LOCALITY_CHANGE_INT 0x0004 /* locality-change int (mb 1) */
#define TPM_INTF_STS_VALID_INT 0x0002 /* TPM_STS_VALID int supported */
#define TPM_INTF_DATA_AVAIL_INT 0x0001 /* TPM_STS_DATA_AVAIL int supported (mb 1) */
#define TPM_CAPSREQ \
(TPM_INTF_DATA_AVAIL_INT|TPM_INTF_LOCALITY_CHANGE_INT|TPM_INTF_INT_LEVEL_LOW)
#define TPM_CAPBITS \
"\020\01IDRDY\02ISTSV\03ILOCH\04IHIGH\05ILOW\06IRISE\07IFALL\010IRDY\011BCST"
#define TPM_DATA 0x0024 /* 32bit register */
#define TPM_ID 0x0f00 /* 32bit register */
#define TPM_REV 0x0f04 /* 8bit register */
#define TPM_STS 0x0018 /* status register */
#define TPM_STS_MASK 0x000000ff /* status bits */
#define TPM_STS_BMASK 0x00ffff00 /* ro io burst size */
#define TPM_STS_VALID 0x00000080 /* ro other bits are valid */
#define TPM_STS_CMD_READY 0x00000040 /* rw chip/signal ready */
#define TPM_STS_GO 0x00000020 /* wo start the command */
#define TPM_STS_DATA_AVAIL 0x00000010 /* ro data available */
#define TPM_STS_DATA_EXPECT 0x00000008 /* ro more data to be written */
#define TPM_STS_RESP_RETRY 0x00000002 /* wo resend the response */
#define TPM_STS_BITS "\020\010VALID\07RDY\06GO\05DRDY\04EXPECT\02RETRY"
#define TPM_DATA 0x0024
#define TPM_ID 0x0f00
#define TPM_REV 0x0f04
#define TPM_SIZE 0x5000 /* five pages of the above */
#define TPM_ACCESS_TMO 2000 /* 2sec */
#define TPM_READY_TMO 2000 /* 2sec */
#define TPM_READ_TMO 2000 /* 2sec */
#define TPM_BURST_TMO 2000 /* 2sec */
#define TPM_LEGACY_BUSY 0x01
#define TPM_LEGACY_ABRT 0x01
#define TPM_LEGACY_DA 0x02
#define TPM_LEGACY_RE 0x04
#define TPM_LEGACY_LAST 0x04
#define TPM_LEGACY_BITS "\020\01BUSY\2DA\3RE\4LAST"
#define TPM_LEGACY_TMO (2*60) /* sec */
#define TPM_LEGACY_SLEEP 5 /* ticks */
#define TPM_LEGACY_DELAY 100
/*
* Five localities, 4K per locality.
*/
#define TPM_SPACE_SIZE 0x5000

View File

@ -1,7 +1,37 @@
/* $NetBSD: tpmvar.h,v 1.3 2012/10/27 17:18:23 chs Exp $ */
/* $NetBSD: tpmvar.h,v 1.4 2019/06/22 12:57:41 maxv Exp $ */
/*
* Copyright (c) 2019 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Maxime Villard.
*
* 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.
*
* 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.
*/
/*
* Copyright (c) 2008, 2009 Michael Shalayeff
* Copyright (c) 2009, 2010 Hans-Jörg Höxer
* Copyright (c) 2009, 2010 Hans-Joerg Hoexer
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software for any
@ -17,45 +47,61 @@
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#define TPM_API_VERSION 1
enum tpm_version {
TPM_1_2,
TPM_2_0
};
struct tpm_ioc_getinfo {
uint32_t api_version;
uint32_t tpm_version;
uint32_t device_id;
uint32_t device_rev;
uint32_t device_caps;
};
#define TPM_IOC_GETINFO _IOR ('N', 0, struct tpm_ioc_getinfo)
#ifdef _KERNEL
struct tpm_softc {
device_t sc_dev;
enum tpm_version sc_ver;
void *sc_ih;
int (*sc_init)(struct tpm_softc *, int, const char *);
int (*sc_start)(struct tpm_softc *, int);
int (*sc_read)(struct tpm_softc *, void *, size_t, size_t *, int);
int (*sc_write)(struct tpm_softc *, const void *, size_t);
int (*sc_end)(struct tpm_softc *, int, int);
int (*sc_init)(struct tpm_softc *, int);
int (*sc_start)(struct tpm_softc *, int);
int (*sc_read)(struct tpm_softc *, void *, size_t, size_t *, int);
int (*sc_write)(struct tpm_softc *, const void *, size_t);
int (*sc_end)(struct tpm_softc *, int, int);
bus_space_tag_t sc_bt, sc_batm;
bus_space_handle_t sc_bh, sc_bahm;
u_int32_t sc_devid;
u_int32_t sc_rev;
u_int32_t sc_stat;
u_int32_t sc_capabilities;
uint32_t sc_devid;
uint32_t sc_rev;
uint32_t sc_status;
uint32_t sc_capabilities;
int sc_flags;
#define TPM_OPEN 0x0001
int sc_vector;
int sc_vector;
};
int tpm_intr(void *);
bool tpm_suspend(device_t, const pmf_qual_t *);
bool tpm_resume(device_t, const pmf_qual_t *);
bool tpm12_suspend(device_t, const pmf_qual_t *);
bool tpm12_resume(device_t, const pmf_qual_t *);
int tpm_tis12_probe(bus_space_tag_t, bus_space_handle_t);
int tpm_tis12_init(struct tpm_softc *, int, const char *);
int tpm_tis12_init(struct tpm_softc *, int);
int tpm_tis12_start(struct tpm_softc *, int);
int tpm_tis12_read(struct tpm_softc *, void *, size_t, size_t *, int);
int tpm_tis12_write(struct tpm_softc *, const void *, size_t);
int tpm_tis12_end(struct tpm_softc *, int, int);
int tpm_legacy_probe(bus_space_tag_t, bus_addr_t);
int tpm_legacy_init(struct tpm_softc *, int, const char *);
int tpm_legacy_start(struct tpm_softc *, int);
int tpm_legacy_read(struct tpm_softc *, void *, size_t, size_t *, int);
int tpm_legacy_write(struct tpm_softc *, const void *, size_t);
int tpm_legacy_end(struct tpm_softc *, int, int);
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: tpm_isa.c,v 1.3 2017/04/27 10:01:53 msaitoh Exp $ */
/* $NetBSD: tpm_isa.c,v 1.4 2019/06/22 12:57:41 maxv Exp $ */
/*
* Copyright (c) 2008, 2009 Michael Shalayeff
@ -19,7 +19,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tpm_isa.c,v 1.3 2017/04/27 10:01:53 msaitoh Exp $");
__KERNEL_RCSID(0, "$NetBSD: tpm_isa.c,v 1.4 2019/06/22 12:57:41 maxv Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -56,27 +56,22 @@ tpm_isa_match(device_t parent, cfdata_t match, void *aux)
if (tpm_cd.cd_devs && tpm_cd.cd_devs[0])
return 0;
if (tpm_legacy_probe(ia->ia_iot, ia->ia_io[0].ir_addr)) {
ia->ia_io[0].ir_size = 2;
return 1;
}
if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM)
return 0;
/* XXX: integer locator sign extension */
if (bus_space_map(bt, (unsigned int)ia->ia_iomem[0].ir_addr, TPM_SIZE,
if (bus_space_map(bt, (unsigned int)ia->ia_iomem[0].ir_addr, TPM_SPACE_SIZE,
0, &bh))
return 0;
if ((rv = tpm_tis12_probe(bt, bh))) {
ia->ia_nio = 0;
ia->ia_io[0].ir_size = 0;
ia->ia_iomem[0].ir_size = TPM_SIZE;
ia->ia_iomem[0].ir_size = TPM_SPACE_SIZE;
}
ia->ia_ndrq = 0;
bus_space_unmap(bt, bh, TPM_SIZE);
bus_space_unmap(bt, bh, TPM_SPACE_SIZE);
return rv;
}
@ -90,35 +85,23 @@ tpm_isa_attach(device_t parent, device_t self, void *aux)
int rv;
sc->sc_dev = self;
sc->sc_ver = TPM_1_2;
if (tpm_legacy_probe(ia->ia_iot, ia->ia_io[0].ir_addr)) {
sc->sc_bt = ia->ia_iot;
iobase = (unsigned int)ia->ia_io[0].ir_addr;
size = ia->ia_io[0].ir_size;
sc->sc_batm = ia->ia_iot;
sc->sc_init = tpm_legacy_init;
sc->sc_start = tpm_legacy_start;
sc->sc_read = tpm_legacy_read;
sc->sc_write = tpm_legacy_write;
sc->sc_end = tpm_legacy_end;
} else {
sc->sc_bt = ia->ia_memt;
iobase = (unsigned int)ia->ia_iomem[0].ir_addr;
size = TPM_SIZE;
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 = ia->ia_memt;
iobase = (unsigned int)ia->ia_iomem[0].ir_addr;
size = TPM_SPACE_SIZE;
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;
if (bus_space_map(sc->sc_bt, iobase, size, 0, &sc->sc_bh)) {
aprint_error_dev(sc->sc_dev, "cannot map registers\n");
return;
}
if ((rv = (*sc->sc_init)(sc, ia->ia_irq[0].ir_irq,
device_xname(sc->sc_dev))) != 0) {
if ((rv = (*sc->sc_init)(sc, ia->ia_irq[0].ir_irq)) != 0) {
bus_space_unmap(sc->sc_bt, sc->sc_bh, size);
return;
}
@ -132,11 +115,11 @@ tpm_isa_attach(device_t parent, device_t self, void *aux)
(sc->sc_ih = isa_intr_establish_xname(ia->ia_ic,
ia->ia_irq[0].ir_irq, IST_EDGE, IPL_TTY, tpm_intr, sc,
device_xname(sc->sc_dev))) == NULL) {
bus_space_unmap(sc->sc_bt, sc->sc_bh, TPM_SIZE);
bus_space_unmap(sc->sc_bt, sc->sc_bh, TPM_SPACE_SIZE);
aprint_error_dev(sc->sc_dev, "cannot establish interrupt\n");
return;
}
if (!pmf_device_register(sc->sc_dev, tpm_suspend, tpm_resume))
aprint_error_dev(sc->sc_dev, "Cannot set power mgmt handler\n");
if (!pmf_device_register(sc->sc_dev, tpm12_suspend, tpm12_resume))
aprint_error_dev(sc->sc_dev, "cannot set power mgmt handler\n");
}