Add tpm(4) driver for Trusted Platform Module.

You may want to look at http://bsssd.sourceforge.net/ .

Submitted by: Hans-Joerg Hoexer <Hans-Joerg_Hoexer@genua.de>
This commit is contained in:
Takanori Watanabe 2010-08-12 00:16:18 +00:00
parent 60c7b36b7a
commit 97f24f666f
8 changed files with 1822 additions and 0 deletions

74
share/man/man4/tpm.4 Normal file
View file

@ -0,0 +1,74 @@
.\"
.\" Copyright (c) 2010 Hans-J
.\"
.\" 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 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.
.\"
.\" $FreeBSD$
.\"
.Dd March 8, 2010
.Dt TPM 4
.Os
.Sh NAME
.Nm tpm
.Nd Trusted Platform Module
.Sh SYNOPSIS
.Cd "device tpm"
.Pp
In
.Pa /boot/device.hints :
.Cd hint.tpm.0.at="isa"
.Cd hint.tpm.0.maddr="0xfed40000"
.Cd hint.tpm.0.msize="0x5000"
.Cd hint.tpm.1.at="isa"
.Cd hint.tpm.1.maddr="0xfed40000"
.Cd hint.tpm.1.msize="0x1000"
.Sh DESCRIPTION
The
.Nm
driver provides support for various trusted platfrom modules (TPM) that can
store cryptographic keys.
.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
.It
Intel INTC0102
.It
Sinosun SNS SSX35
.It
STM ST19WP18
.It
Winbond WEC WPCT200
.El
.Pp
The driver can be configured to use an IRQ by providing a free ISA
interrupt vector in
.Pa /boot/device.hints .
.Sh SEE ALSO
.Xr intro 4 ,
.Xr files.conf 5,
.Xr config 8
.Sh AUTHORS
.An -nosplit
The
.Nm
driver was written by
.An Michael Shalayeff
and
.An Hans-Joerg Hoexer .

View file

@ -231,6 +231,9 @@ dev/syscons/scterm-teken.c optional sc
dev/syscons/scvesactl.c optional sc vga vesa
dev/syscons/scvgarndr.c optional sc vga
dev/syscons/scvtb.c optional sc
dev/tpm/tpm.c optional tpm
dev/tpm/tpm_acpi.c optional tpm acpi
dev/tpm/tpm_isa.c optional tpm isa
dev/uart/uart_cpu_i386.c optional uart
dev/acpica/acpi_if.m standard
dev/acpi_support/acpi_wmi_if.m standard

1492
sys/dev/tpm/tpm.c Normal file

File diff suppressed because it is too large Load diff

81
sys/dev/tpm/tpm_acpi.c Normal file
View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 2008, 2009 Michael Shalayeff
* Copyright (c) 2009, 2010 Hans-Joerg Hoexer
* 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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <sys/conf.h>
#include <sys/uio.h>
#include <sys/bus.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>
#include <machine/md_var.h>
#include <isa/isareg.h>
#include <isa/isavar.h>
#include "tpmvar.h"
#include "opt_acpi.h"
#include <contrib/dev/acpica/include/acpi.h>
#include <contrib/dev/acpica/include/accommon.h>
#include <dev/acpica/acpivar.h>
char *tpm_ids[] = {"ATM1200", "BCM0102", "INTC0102", "SNO3504", "WEC1000",
"PNP0C31", NULL};
static int
tpm_acpi_probe(device_t dev)
{
if (ACPI_ID_PROBE(device_get_parent(dev), dev, tpm_ids) != NULL) {
device_set_desc(dev, "Trusted Platform Module");
return BUS_PROBE_DEFAULT;
}
return ENXIO;
}
static device_method_t tpm_acpi_methods[] = {
#if 0
/*In some case, TPM existance is found only in TPCA header*/
DEVMETHOD(device_identify, tpm_acpi_identify),
#endif
DEVMETHOD(device_probe, tpm_acpi_probe),
DEVMETHOD(device_attach, tpm_attach),
DEVMETHOD(device_detach, tpm_detach),
DEVMETHOD(device_suspend, tpm_suspend),
DEVMETHOD(device_resume, tpm_resume),
{ 0, 0 }
};
static driver_t tpm_acpi_driver = {
"tpm", tpm_acpi_methods, sizeof(struct tpm_softc),
};
devclass_t tpm_devclass;
DRIVER_MODULE(tpm, acpi, tpm_acpi_driver, tpm_devclass, 0, 0);

96
sys/dev/tpm/tpm_isa.c Normal file
View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 2008, 2009 Michael Shalayeff
* Copyright (c) 2009, 2010 Hans-Joerg Hoexer
* 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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/proc.h>
#ifdef __FreeBSD__
#include <sys/module.h>
#include <sys/conf.h>
#include <sys/uio.h>
#include <sys/bus.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>
#include <machine/md_var.h>
#include <isa/isareg.h>
#include <isa/isavar.h>
#else
#include <sys/device.h>
#include <machine/cpu.h>
#include <machine/bus.h>
#include <machine/intr.h>
#include <machine/conf.h>
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
#endif
#include "tpmvar.h"
static int
tpm_isa_probe(device_t dev)
{
bus_space_tag_t iot;
bus_space_handle_t ioh;
struct resource *mem_res;
int rv, mem_rid;
mem_rid = 0;
mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &mem_rid,
RF_ACTIVE);
if (mem_res == NULL)
return (ENXIO);
iot = rman_get_bustag(mem_res);
ioh = rman_get_bushandle(mem_res);
if ((rv = tpm_tis12_probe(iot, ioh)))
device_set_desc(dev, "Trusted Platform Module");
bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
return rv ? 0 : ENXIO;
}
static device_method_t tpm_methods[] = {
#if 0
DEVMETHOD(device_identify, tpm_identify),
#endif
DEVMETHOD(device_probe, tpm_isa_probe),
DEVMETHOD(device_attach, tpm_attach),
DEVMETHOD(device_detach, tpm_detach),
DEVMETHOD(device_suspend, tpm_suspend),
DEVMETHOD(device_resume, tpm_resume),
{ 0, 0 }
};
static driver_t tpm_driver = {
"tpm", tpm_methods, sizeof(struct tpm_softc),
};
static devclass_t tpm_devclass;
DRIVER_MODULE(tpm, isa, tpm_driver, tpm_devclass, 0, 0);

66
sys/dev/tpm/tpmvar.h Normal file
View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2008, 2009 Michael Shalayeff
* Copyright (c) 2009, 2010 Hans-Joerg Hoexer
* 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.
*
* $FreeBSD$
*/
#ifndef _TPMVAR_H
#define _TPMVAR_H
struct tpm_softc {
#ifndef __FreeBSD__
struct device sc_dev;
#endif
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 *, int, size_t *, int);
int (*sc_write)(struct tpm_softc *, void *, int);
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;
int sc_flags;
#define TPM_OPEN 0x0001
int sc_vector;
#ifdef __FreeBSD__
void *intr_cookie;
int mem_rid, irq_rid;
struct resource *mem_res, *irq_res;
struct cdev *sc_cdev;
#endif
#ifndef __FreeBSD__
void *sc_powerhook;
#endif
int sc_suspend;
};
int tpm_tis12_probe(bus_space_tag_t iot, bus_space_handle_t ioh);
int tpm_attach(device_t dev);
int tpm_detach(device_t dev);
int tpm_suspend(device_t dev);
int tpm_resume(device_t dev);
#endif

View file

@ -283,6 +283,7 @@ SUBDIR= ${_3dfx} \
ti \
tl \
tmpfs \
tpm \
trm \
${_twa} \
twe \

9
sys/modules/tpm/Makefile Normal file
View file

@ -0,0 +1,9 @@
# $FreeBSD$
.PATH: ${.CURDIR}/../../dev/tpm
KMOD= tpm
SRCS= tpm.c tpm_isa.c tpm_acpi.c isa_if.h opt_acpi.h acpi_if.h \
bus_if.h device_if.h
.include <bsd.kmod.mk>