Home | History | Annotate | Download | only in ic
History log of /src/sys/dev/ic/tpm.c
RevisionDateAuthorComments
 1.29  14-May-2024  riastradh tpm(4): device_printf needs \n.

Observed in PR 58255.
 1.28  04-Jul-2023  riastradh tpm(4): Switch tsleep to kpause.

Nothing is interrupt-driven here, so no need for condvars to allow
more prompt wakeups.
 1.27  25-Sep-2022  thorpej Remove unnecessary include of <sys/malloc.h>.
 1.26  07-Sep-2022  khorben tpm(4): add missing newline character in device_printf()

Observed with on a Sun Ultra 24, NetBSD/amd64:

tpm0 at acpi0 (TPM, IFX0102-1): io 0x4e-0x4f,0x4700-0x470b mem 0xfed40000-0xfed44fff
tpm0: device 0x000b15d1 rev 0x10
tpm0: read 8 bytes, expected 10tpm0: deactivating entropy source
 1.25  29-Jan-2022  riastradh tpm(4): Nix TPM_BE16/TPM_BE32. Just use sys/endian.h.
 1.24  16-Jan-2022  riastradh tpm(4): Fix suspend and rework I/O transaction lock.

Use sc->sc_lock over individual I/O transactions, not open/close of
the whole device. This way there is a bounded time before the tpm is
unbusied even if userland is getting at it, so userland can't hold up
suspend indefinitely. Of course, the tpm might be suspended and
resumed in the middle of the user's session this way -- tough.

This limits the response buffer to 1024 bytes -- which is already a
bit hefty to have on the stack (but it's probably not very deep on
the stack from userland so maybe not a big deal). If it turns out we
need more, we can use kmem to allocate a buffer on the heap, with the
caveat that it might fail. This is necessary so that suspend doesn't
block indefinitely on uiomove in tpmread.
 1.23  20-Dec-2021  riastradh tpm(4): Fix disabling of rnd source if tpm is deactivated.

Nothing prevents a second worker from being queued when the first one
is about to do rnd_detach_source. Instead, just set a flag so future
requests don't bother running a new thread; if there's a concurrent
one that's already been scheduled on another CPU, well, too bad, we
get a couple extra log messages but that's fine.

A better way to do this would probably be to detect whether the tpm
is deactivated at attach time, but that requires reading more of the
tpm spec than I care to do when there are alternative ways to
procrastinate like scrubbing the toilet.
 1.22  02-Jun-2021  riastradh tpm(4): Preserve error if any on ending commands.

This way we don't spuriously suppress an error, such as
TPM_DEACTIVATED, in a loop where we rely on it.
 1.21  29-May-2021  riastradh branches: 1.21.2;
tpm(4): Handle TPM 2.0 random source too, and loop on short reads.

Tested on ThinkPad T480.
 1.20  22-May-2021  thorpej Remove extra newline from boot messages (isa and acpi front-ends
already provide the newline).
 1.19  04-Jan-2021  riastradh branches: 1.19.4; 1.19.6;
dev/ic/tpm: Take advantage of entropy source if available.

If the tpm is deactivated, though, detach the entropy source so we
don't continue to try polling it -- it can't be activated without a
reboot anyway.
 1.18  04-Jan-2021  riastradh dev/ic/tpm: Add missing line break in attach output.
 1.17  04-Jan-2021  riastradh dev/ic/tpm: Tidy up headers.

- Add include guards.
- Add necessary includes.
- Sort includes.
- Use _BYTE_ORDER, not BYTE_ORDER, for public header.
 1.16  09-Oct-2019  maxv branches: 1.16.8;
Provide a better abstraction for the TPM interface. Report it in the ioctl.
 1.15  09-Oct-2019  maxv Add suspend support for TPM 2.0 chips. Check the TPM response also for 1.2
chips. Unfortunately I cannot really test this change since ACPI suspend
does not work on any of my laptops.
 1.14  08-Oct-2019  maxv 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.
 1.13  22-Jun-2019  maxv branches: 1.13.2;
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.
 1.12  28-Oct-2017  riastradh branches: 1.12.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.11  25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.10  16-Mar-2014  dholland branches: 1.10.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.9  17-Oct-2013  christos - remove unused variables
- move variables inside ifdef sections
- ifdef notdef unused code
- use __USE for debugging variables
 1.8  14-Sep-2013  joerg GC unused functions and variables.
 1.7  06-Feb-2012  christos branches: 1.7.4; 1.7.6; 1.7.10; 1.7.14;
PR/45932: Pierre Pronchery: Fix the return values of the suspend and resume
functions.
 1.6  03-Feb-2012  christos shutup debug.
 1.5  03-Feb-2012  christos don't try to write in a const buffer.
 1.4  23-Jan-2012  christos reduce the polling interval to 2 seconds, and try harder to get interrupts
working.
 1.3  22-Jan-2012  christos cosmetic fixes
 1.2  22-Jan-2012  christos as jared noted, this is not mpsafe.
 1.1  22-Jan-2012  christos add a tpm driver from bsssd.sourceforge.net
 1.7.14.1  18-May-2014  rmind sync with head
 1.7.10.2  03-Dec-2017  jdolecek update from HEAD
 1.7.10.1  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.6.3  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.6.2  17-Apr-2012  yamt sync with head
 1.7.6.1  06-Feb-2012  yamt file tpm.c was added on branch yamt-pagecache on 2012-04-17 00:07:37 +0000
 1.7.4.2  18-Feb-2012  mrg merge to -current.
 1.7.4.1  06-Feb-2012  mrg file tpm.c was added on branch jmcneill-usbmp on 2012-02-18 07:34:24 +0000
 1.10.2.1  10-Aug-2014  tls Rebase.
 1.12.4.1  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13.2.3  29-Aug-2022  martin Pull up following revision(s) (requested by riastradh in ticket #1505):

sys/dev/isa/tpm_isa.c: revision 1.8
sys/dev/ic/tpm.c: revision 1.20

Add missing printing-of-newlines in the attach routine.

Remove extra newline from boot messages (isa and acpi front-ends
already provide the newline).
 1.13.2.2  03-Aug-2022  martin Pull up following revision(s) (requested by riastradh in ticket #1495):

share/man/man4/tpm.4: revision 1.7
sys/dev/ic/tpm.c: revision 1.17
sys/dev/ic/tpmvar.h: revision 1.10
sys/dev/ic/tpm.c: revision 1.18
sys/dev/ic/tpm.c: revision 1.19
sys/dev/acpi/tpm_acpi.c: revision 1.14
sys/dev/ic/tpmreg.h: revision 1.10
sys/dev/ic/tpmreg.h: revision 1.11
sys/dev/ic/tpm.c: revision 1.21
sys/dev/ic/tpm.c: revision 1.22
sys/dev/ic/tpm.c: revision 1.23
sys/dev/ic/tpm.c: revision 1.24
sys/dev/ic/tpm.c: revision 1.25
sys/dev/ic/tpmreg.h: revision 1.7
sys/dev/ic/tpmreg.h: revision 1.8
sys/dev/ic/tpmreg.h: revision 1.9
sys/dev/ic/tpmvar.h: revision 1.8
sys/dev/ic/tpmvar.h: revision 1.9

dev/ic/tpm: Tidy up headers.
- Add include guards.
- Add necessary includes.
- Sort includes.
- Use _BYTE_ORDER, not BYTE_ORDER, for public header.

dev/ic/tpm: Add missing line break in attach output.

dev/ic/tpm: Take advantage of entropy source if available.

If the tpm is deactivated, though, detach the entropy source so we
don't continue to try polling it -- it can't be activated without a
reboot anyway.

Add note about enabling TPM and rnd(4) source.

tpm(4): Handle TPM 2.0 random source too, and loop on short reads.
Tested on ThinkPad T480.

tpm(4): Preserve error if any on ending commands.
This way we don't spuriously suppress an error, such as
TPM_DEACTIVATED, in a loop where we rely on it.

tpm@acpi: Require only one locality's worth of register space.
We don't actually use the registers for the other localities, and
some older TPMs only have the first locality exposed via ACPI.


tpm(4): Fix disabling of rnd source if tpm is deactivated.

Nothing prevents a second worker from being queued when the first one
is about to do rnd_detach_source. Instead, just set a flag so future
requests don't bother running a new thread; if there's a concurrent
one that's already been scheduled on another CPU, well, too bad, we
get a couple extra log messages but that's fine.

A better way to do this would probably be to detect whether the tpm
is deactivated at attach time, but that requires reading more of the
tpm spec than I care to do when there are alternative ways to
procrastinate like scrubbing the toilet.


tpm(4): Fix suspend and rework I/O transaction lock.

Use sc->sc_lock over individual I/O transactions, not open/close of
the whole device. This way there is a bounded time before the tpm is
unbusied even if userland is getting at it, so userland can't hold up
suspend indefinitely. Of course, the tpm might be suspended and
resumed in the middle of the user's session this way -- tough.

This limits the response buffer to 1024 bytes -- which is already a
bit hefty to have on the stack (but it's probably not very deep on
the stack from userland so maybe not a big deal). If it turns out we
need more, we can use kmem to allocate a buffer on the heap, with the
caveat that it might fail. This is necessary so that suspend doesn't
block indefinitely on uiomove in tpmread.


tpm(4): Nix TPM_BE16/TPM_BE32. Just use sys/endian.h.
 1.13.2.1  16-Oct-2019  martin Pull up following revision(s) (requested by maxv in ticket #336):

sys/dev/isa/tpm_isa.c: revision 1.6
sys/dev/ic/tpm.c: revision 1.16
sys/dev/isa/tpm_isa.c: revision 1.7
sys/dev/acpi/tpm_acpi.c: revision 1.10
sys/dev/acpi/tpm_acpi.c: revision 1.11
sys/dev/ic/tpmreg.h: revision 1.5
sys/dev/ic/tpmreg.h: revision 1.6
sys/dev/acpi/tpm_acpi.c: revision 1.9
sys/dev/ic/tpmvar.h: revision 1.5
sys/dev/ic/tpmvar.h: revision 1.6
sys/dev/ic/tpmvar.h: revision 1.7
sys/dev/ic/tpm.c: revision 1.14
share/man/man4/tpm.4: revision 1.5
sys/dev/isa/tpm_isa.c: revision 1.5
sys/dev/ic/tpm.c: revision 1.15

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.

-

Add suspend support for TPM 2.0 chips. Check the TPM response also for 1.2
chips. Unfortunately I cannot really test this change since ACPI suspend
does not work on any of my laptops.

-

Provide a better abstraction for the TPM interface. Report it in the ioctl.
 1.16.8.1  03-Apr-2021  thorpej Sync with HEAD.
 1.19.6.1  31-May-2021  cjep sync with head
 1.19.4.1  17-Jun-2021  thorpej Sync w/ HEAD.
 1.21.2.1  06-Jun-2021  cjep sync with head

RSS XML Feed