version 1.6, 2018/02/22 01:50:26 |
version 1.6.4.2, 2020/04/13 08:04:18 |
|
|
/* $NetBSD$ */ |
/* $NetBSD$ */ |
|
|
/*- |
/* |
* Copyright (c) 2012 The NetBSD Foundation, Inc. |
* Copyright (c) 2012, 2019 The NetBSD Foundation, Inc. |
* All rights reserved. |
* All rights reserved. |
* |
* |
* This code is derived from software contributed to The NetBSD Foundation |
* 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 |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* modification, are permitted provided that the following conditions |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
* POSSIBILITY OF SUCH DAMAGE. |
* POSSIBILITY OF SUCH DAMAGE. |
*/ |
*/ |
/* |
|
* Copyright (c) 2008, 2009 Michael Shalayeff |
|
* Copyright (c) 2009, 2010 Hans-Jg Her |
|
* 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> |
#include <sys/cdefs.h> |
__KERNEL_RCSID(0, "$NetBSD$"); |
__KERNEL_RCSID(0, "$NetBSD$"); |
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/device.h> |
|
#include <sys/systm.h> |
#include <sys/systm.h> |
#include <sys/device.h> |
#include <sys/device.h> |
#include <sys/bus.h> |
#include <sys/bus.h> |
Line 67 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 44 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <dev/acpi/acpireg.h> |
#include <dev/acpi/acpireg.h> |
#include <dev/acpi/acpivar.h> |
#include <dev/acpi/acpivar.h> |
|
|
#include <dev/isa/isavar.h> |
|
|
|
#include "ioconf.h" |
#include "ioconf.h" |
|
|
#define _COMPONENT ACPI_RESOURCE_COMPONENT |
#define _COMPONENT ACPI_RESOURCE_COMPONENT |
ACPI_MODULE_NAME ("tpm_acpi") |
ACPI_MODULE_NAME ("tpm_acpi") |
|
|
static int tpm_acpi_match(device_t, cfdata_t, void *); |
static int tpm_acpi_match(device_t, cfdata_t, void *); |
static void tpm_acpi_attach(device_t, device_t, void *); |
static void tpm_acpi_attach(device_t, device_t, void *); |
|
|
|
|
CFATTACH_DECL_NEW(tpm_acpi, sizeof(struct tpm_softc), tpm_acpi_match, |
CFATTACH_DECL_NEW(tpm_acpi, sizeof(struct tpm_softc), tpm_acpi_match, |
tpm_acpi_attach, NULL, NULL); |
tpm_acpi_attach, NULL, NULL); |
|
|
/* |
/* |
* Supported device IDs |
* Supported TPM 2.0 devices. |
*/ |
*/ |
|
static const char * const tpm2_acpi_ids[] = { |
#ifdef notyet |
"MSFT0101", |
static const char * const tpm_acpi_ids[] = { |
|
"IFX0101", |
|
"IFX0102", |
|
NULL |
NULL |
}; |
}; |
#endif |
|
|
|
static int |
static int |
tpm_acpi_match(device_t parent, cfdata_t match, void *aux) |
tpm_acpi_match(device_t parent, cfdata_t match, void *aux) |
{ |
{ |
struct acpi_attach_args *aa = aux; |
struct acpi_attach_args *aa = aux; |
|
ACPI_TABLE_TPM2 *tpm2; |
|
ACPI_STATUS rv; |
|
|
if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) |
if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) |
return 0; |
return 0; |
|
|
/* There can be only one. */ |
/* We support only one TPM. */ |
if (tpm_cd.cd_devs && tpm_cd.cd_devs[0]) |
if (tpm_cd.cd_devs && tpm_cd.cd_devs[0]) |
return 0; |
return 0; |
#ifdef notyet |
|
return acpi_match_hid(aa->aa_node->ad_devinfo, tpm_acpi_ids); |
if (!acpi_match_hid(aa->aa_node->ad_devinfo, tpm2_acpi_ids)) |
#else |
return 0; |
return 0; |
|
#endif |
/* 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 |
static void |
Line 117 tpm_acpi_attach(device_t parent, device_ |
|
Line 96 tpm_acpi_attach(device_t parent, device_ |
|
struct tpm_softc *sc = device_private(self); |
struct tpm_softc *sc = device_private(self); |
struct acpi_attach_args *aa = aux; |
struct acpi_attach_args *aa = aux; |
struct acpi_resources res; |
struct acpi_resources res; |
struct acpi_io *io; |
|
struct acpi_mem *mem; |
struct acpi_mem *mem; |
struct acpi_irq *irq; |
|
bus_addr_t base; |
bus_addr_t base; |
bus_addr_t size; |
bus_addr_t size; |
int rv, inum; |
int rv; |
|
|
sc->sc_dev = self; |
rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS", &res, |
|
&acpi_resource_parse_ops_default); |
|
if (ACPI_FAILURE(rv)) { |
|
aprint_error_dev(self, "cannot parse resources %d\n", rv); |
|
return; |
|
} |
|
|
/* Parse our resources */ |
mem = acpi_res_mem(&res, 0); |
rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS", &res, |
if (mem == NULL) { |
&acpi_resource_parse_ops_default); |
aprint_error_dev(self, "cannot find mem\n"); |
|
goto out; |
if (ACPI_FAILURE(rv)) { |
} |
aprint_error_dev(sc->sc_dev, "cannot parse resources %d\n", rv); |
if (mem->ar_length != TPM_SPACE_SIZE) { |
return; |
aprint_error_dev(self, "wrong size mem %"PRIu64" != %u\n", |
} |
(uint64_t)mem->ar_length, TPM_SPACE_SIZE); |
|
goto out; |
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 %u != %u\n", |
|
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; |
|
} |
} |
|
base = mem->ar_base; |
|
size = mem->ar_length; |
|
|
|
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_intf = &tpm_intf_tis12; |
|
sc->sc_bt = aa->aa_memt; |
if (bus_space_map(sc->sc_bt, base, size, 0, &sc->sc_bh)) { |
if (bus_space_map(sc->sc_bt, base, size, 0, &sc->sc_bh)) { |
aprint_error_dev(sc->sc_dev, "cannot map registers\n"); |
aprint_error_dev(sc->sc_dev, "cannot map registers\n"); |
goto out; |
goto out; |
} |
} |
|
|
if (mem && !tpm_tis12_probe(sc->sc_bt, sc->sc_bh)) { |
if ((rv = (*sc->sc_intf->probe)(sc->sc_bt, sc->sc_bh)) != 0) { |
aprint_error_dev(sc->sc_dev, "1.2 probe failed\n"); |
aprint_error_dev(sc->sc_dev, "probe failed, rv=%d\n", rv); |
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, device_xname(sc->sc_dev))) != 0) { |
|
aprint_error_dev(sc->sc_dev, "cannot init device %d\n", rv); |
|
goto out1; |
goto out1; |
} |
} |
|
if ((rv = (*sc->sc_intf->init)(sc)) != 0) { |
if (inum != -1 && |
aprint_error_dev(sc->sc_dev, "cannot init device, rv=%d\n", rv); |
(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; |
goto out1; |
} |
} |
|
|
if (!pmf_device_register(sc->sc_dev, tpm_suspend, tpm_resume)) |
if (!pmf_device_register(self, tpm_suspend, tpm_resume)) |
aprint_error_dev(sc->sc_dev, "Cannot set power mgmt handler\n"); |
aprint_error_dev(self, "couldn't establish power handler\n"); |
|
acpi_resource_cleanup(&res); |
return; |
return; |
|
|
out1: |
out1: |
bus_space_unmap(sc->sc_bt, sc->sc_bh, size); |
bus_space_unmap(sc->sc_bt, sc->sc_bh, size); |
out: |
out: |