* [Qemu-devel] [RFC PATCH 0/3] Implement Pysical Presence Interface for TPM 1.2 and 2 @ 2018-01-10 18:35 Stefan Berger 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 1/3] tpm: Implement virtual memory device for TPM PPI Stefan Berger ` (2 more replies) 0 siblings, 3 replies; 16+ messages in thread From: Stefan Berger @ 2018-01-10 18:35 UTC (permalink / raw) To: qemu-devel; +Cc: mst, stefanb, kevin, marcandre.lureau The following patches implement the TPM Physical Presence Interface that allows a user to set a command via ACPI (sysfs entry in Linux) that, upon the next reboot, the firmware (BIOS, UEFI) looks for an acts upon by sending sequences of commands to the TPM 1.2 or 2. My first goal is to get the virtual memory device accepted since it extends the TPM TIS (and TPM CRB) interface's internal data structure with another 256 bytes that would have to be written out when suspending the VM. So this patch would have to come before we support VM with TPM suspend and resume. The device supports 256 bytes at address 0xffff0000. This is the address that EDK2 uses and that I have patches for for SeaBIOS support. Regards, Stefan Stefan Berger (3): tpm: Implement virtual memory device for TPM PPI acpi: implement aml_lless_equal acpi: Build TPM Physical Presence interface hw/acpi/aml-build.c | 10 ++ hw/i386/acpi-build.c | 227 ++++++++++++++++++++++++++++++++++++++++++++ hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_ppi.c | 79 +++++++++++++++ hw/tpm/tpm_ppi.h | 25 +++++ hw/tpm/tpm_tis.c | 5 + include/hw/acpi/aml-build.h | 1 + include/hw/acpi/tpm.h | 21 ++++ 8 files changed, 369 insertions(+), 1 deletion(-) create mode 100644 hw/tpm/tpm_ppi.c create mode 100644 hw/tpm/tpm_ppi.h -- 2.5.5 ^ permalink raw reply [flat|nested] 16+ messages in thread
* [Qemu-devel] [RFC PATCH 1/3] tpm: Implement virtual memory device for TPM PPI 2018-01-10 18:35 [Qemu-devel] [RFC PATCH 0/3] Implement Pysical Presence Interface for TPM 1.2 and 2 Stefan Berger @ 2018-01-10 18:35 ` Stefan Berger 2018-01-12 14:55 ` Marc-André Lureau 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 2/3] acpi: implement aml_lless_equal Stefan Berger 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 3/3] acpi: Build TPM Physical Presence interface Stefan Berger 2 siblings, 1 reply; 16+ messages in thread From: Stefan Berger @ 2018-01-10 18:35 UTC (permalink / raw) To: qemu-devel; +Cc: mst, stefanb, kevin, marcandre.lureau Implement a virtual memory device for the TPM physical presence interface. The memory is located at 0xffff0000 and used by ACPI to send messages to the firmware (BIOS). This device should be used by all TPM interfaces on x86 and can be added through by calling tpm_ppi_init_io(). Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> --- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_ppi.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/tpm/tpm_ppi.h | 25 ++++++++++++++++ hw/tpm/tpm_tis.c | 5 ++++ include/hw/acpi/tpm.h | 6 ++++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 hw/tpm/tpm_ppi.c create mode 100644 hw/tpm/tpm_ppi.h diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs index 7a93b24..3eb0558 100644 --- a/hw/tpm/Makefile.objs +++ b/hw/tpm/Makefile.objs @@ -1,4 +1,4 @@ -common-obj-y += tpm_util.o +common-obj-y += tpm_util.o tpm_ppi.o common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_EMULATOR) += tpm_emulator.o diff --git a/hw/tpm/tpm_ppi.c b/hw/tpm/tpm_ppi.c new file mode 100644 index 0000000..fa8c3c3 --- /dev/null +++ b/hw/tpm/tpm_ppi.c @@ -0,0 +1,79 @@ +/* + * tpm_ppi.c - TPM Physical Presence Interface + * + * Copyright (C) 2018 IBM Corporation + * + * Authors: + * Stefan Berger <stefanb@us.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "exec/memory.h" +#include "exec/address-spaces.h" + +#include "tpm_ppi.h" + +#define DEBUG_PPI 1 + +#define DPRINTF(fmt, ...) do { \ + if (DEBUG_PPI) { \ + printf(fmt, ## __VA_ARGS__); \ + } \ +} while (0); + +static uint64_t tpm_ppi_mmio_read(void *opaque, hwaddr addr, + unsigned size) +{ + TPMPPI *s = opaque; + uint32_t val = 0; + int c; + + for (c = size - 1; c >= 0; c--) { + val <<= 8; + val |= s->ram[addr + c]; + } + + DPRINTF("tpm_ppi: read.%u(%08x) = %08x\n", size, + (unsigned int)addr, (unsigned int)val); + + return val; +} + +static void tpm_ppi_mmio_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + TPMPPI *s = opaque; + int c; + + DPRINTF("tpm_ppi: write.%u(%08x) = %08x\n", size, + (unsigned int)addr, (unsigned int)val); + + for (c = 0; c <= size - 1; c++) { + s->ram[addr + c] = val; + val >>= 8; + } +} + +static const MemoryRegionOps tpm_ppi_memory_ops = { + .read = tpm_ppi_mmio_read, + .write = tpm_ppi_mmio_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid = { + .min_access_size = 1, + .max_access_size = 4, + }, +}; + +void tpm_ppi_init_io(TPMPPI *tpmppi, Object *obj) +{ + memory_region_init_io(&tpmppi->mmio, obj, &tpm_ppi_memory_ops, + tpmppi, "tpm-ppi-mmio", + TPM_PPI_ADDR_SIZE); + + memory_region_add_subregion(get_system_memory(), + TPM_PPI_ADDR_BASE, &tpmppi->mmio); +} diff --git a/hw/tpm/tpm_ppi.h b/hw/tpm/tpm_ppi.h new file mode 100644 index 0000000..8959912 --- /dev/null +++ b/hw/tpm/tpm_ppi.h @@ -0,0 +1,25 @@ +/* + * TPM Physical Presence Interface + * + * Copyright (C) 2018 IBM Corporation + * + * Authors: + * Stefan Berger <stefanb@us.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#ifndef TPM_TPM_PPI_H +#define TPM_TPM_PPI_H + +#include "hw/acpi/tpm.h" + +typedef struct TPMPPI { + MemoryRegion mmio; + + uint8_t ram[TPM_PPI_ADDR_SIZE]; +} TPMPPI; + +void tpm_ppi_init_io(TPMPPI *tpmppi, Object *obj); + +#endif /* TPM_TPM_PPI_H */ diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 561384c..f980972 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -31,6 +31,7 @@ #include "sysemu/tpm_backend.h" #include "tpm_int.h" #include "tpm_util.h" +#include "tpm_ppi.h" #define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ #define TPM_TIS_LOCALITY_SHIFT 12 @@ -80,6 +81,8 @@ typedef struct TPMState { TPMVersion be_tpm_version; size_t be_buffer_size; + + TPMPPI ppi; } TPMState; #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) @@ -1050,6 +1053,8 @@ static void tpm_tis_initfn(Object *obj) memory_region_init_io(&s->mmio, OBJECT(s), &tpm_tis_memory_ops, s, "tpm-tis-mmio", TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT); + + tpm_ppi_init_io(&s->ppi, obj); } static void tpm_tis_class_init(ObjectClass *klass, void *data) diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h index 6d516c6..d9b7452 100644 --- a/include/hw/acpi/tpm.h +++ b/include/hw/acpi/tpm.h @@ -31,4 +31,10 @@ #define TPM2_START_METHOD_MMIO 6 +/* + * Physical Presence Interface + */ +#define TPM_PPI_ADDR_SIZE 0x100 +#define TPM_PPI_ADDR_BASE 0xffff0000 + #endif /* HW_ACPI_TPM_H */ -- 2.5.5 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 1/3] tpm: Implement virtual memory device for TPM PPI 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 1/3] tpm: Implement virtual memory device for TPM PPI Stefan Berger @ 2018-01-12 14:55 ` Marc-André Lureau 2018-01-12 16:29 ` Eric Blake ` (2 more replies) 0 siblings, 3 replies; 16+ messages in thread From: Marc-André Lureau @ 2018-01-12 14:55 UTC (permalink / raw) To: Stefan Berger; +Cc: QEMU, kevin, Michael S. Tsirkin Hi On Wed, Jan 10, 2018 at 7:35 PM, Stefan Berger <stefanb@linux.vnet.ibm.com> wrote: > Implement a virtual memory device for the TPM physical > presence interface. The memory is located at 0xffff0000 > and used by ACPI to send messages to the firmware (BIOS). > > This device should be used by all TPM interfaces on x86 and > can be added through by calling tpm_ppi_init_io(). > I haven't followed closely the current design discussion on seabios ML, so this is just a quick review: > Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> > --- > hw/tpm/Makefile.objs | 2 +- > hw/tpm/tpm_ppi.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ > hw/tpm/tpm_ppi.h | 25 ++++++++++++++++ > hw/tpm/tpm_tis.c | 5 ++++ > include/hw/acpi/tpm.h | 6 ++++ > 5 files changed, 116 insertions(+), 1 deletion(-) > create mode 100644 hw/tpm/tpm_ppi.c > create mode 100644 hw/tpm/tpm_ppi.h > > diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs > index 7a93b24..3eb0558 100644 > --- a/hw/tpm/Makefile.objs > +++ b/hw/tpm/Makefile.objs > @@ -1,4 +1,4 @@ > -common-obj-y += tpm_util.o > +common-obj-y += tpm_util.o tpm_ppi.o > common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o > common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o > common-obj-$(CONFIG_TPM_EMULATOR) += tpm_emulator.o > diff --git a/hw/tpm/tpm_ppi.c b/hw/tpm/tpm_ppi.c > new file mode 100644 > index 0000000..fa8c3c3 > --- /dev/null > +++ b/hw/tpm/tpm_ppi.c > @@ -0,0 +1,79 @@ > +/* > + * tpm_ppi.c - TPM Physical Presence Interface > + * > + * Copyright (C) 2018 IBM Corporation > + * > + * Authors: > + * Stefan Berger <stefanb@us.ibm.com> > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or later. > + * See the COPYING file in the top-level directory. > + * > + */ > + > +#include "qemu/osdep.h" > +#include "exec/memory.h" > +#include "exec/address-spaces.h" > + > +#include "tpm_ppi.h" > + > +#define DEBUG_PPI 1 to be switched to 0 > + > +#define DPRINTF(fmt, ...) do { \ > + if (DEBUG_PPI) { \ > + printf(fmt, ## __VA_ARGS__); \ > + } \ > +} while (0); > + > +static uint64_t tpm_ppi_mmio_read(void *opaque, hwaddr addr, > + unsigned size) > +{ > + TPMPPI *s = opaque; > + uint32_t val = 0; > + int c; > + > + for (c = size - 1; c >= 0; c--) { I would rather put the -1, > + val <<= 8; > + val |= s->ram[addr + c]; ^ here, ymmv > + } > + > + DPRINTF("tpm_ppi: read.%u(%08x) = %08x\n", size, > + (unsigned int)addr, (unsigned int)val); > + > + return val; > +} > + > +static void tpm_ppi_mmio_write(void *opaque, hwaddr addr, > + uint64_t val, unsigned size) > +{ > + TPMPPI *s = opaque; > + int c; > + > + DPRINTF("tpm_ppi: write.%u(%08x) = %08x\n", size, > + (unsigned int)addr, (unsigned int)val); > + > + for (c = 0; c <= size - 1; c++) { same (alternatively, why not cast the addr pointer?) > + s->ram[addr + c] = val; > + val >>= 8; > + } > +} > + > +static const MemoryRegionOps tpm_ppi_memory_ops = { > + .read = tpm_ppi_mmio_read, > + .write = tpm_ppi_mmio_write, > + .endianness = DEVICE_LITTLE_ENDIAN, Shouldn't it be native endian? > + .valid = { > + .min_access_size = 1, > + .max_access_size = 4, > + }, > +}; > + > +void tpm_ppi_init_io(TPMPPI *tpmppi, Object *obj) > +{ > + memory_region_init_io(&tpmppi->mmio, obj, &tpm_ppi_memory_ops, > + tpmppi, "tpm-ppi-mmio", > + TPM_PPI_ADDR_SIZE); > + > + memory_region_add_subregion(get_system_memory(), > + TPM_PPI_ADDR_BASE, &tpmppi->mmio); > +} > diff --git a/hw/tpm/tpm_ppi.h b/hw/tpm/tpm_ppi.h > new file mode 100644 > index 0000000..8959912 > --- /dev/null > +++ b/hw/tpm/tpm_ppi.h > @@ -0,0 +1,25 @@ > +/* > + * TPM Physical Presence Interface > + * > + * Copyright (C) 2018 IBM Corporation > + * > + * Authors: > + * Stefan Berger <stefanb@us.ibm.com> > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or later. > + * See the COPYING file in the top-level directory. > + */ > +#ifndef TPM_TPM_PPI_H > +#define TPM_TPM_PPI_H > + > +#include "hw/acpi/tpm.h" > + > +typedef struct TPMPPI { > + MemoryRegion mmio; > + > + uint8_t ram[TPM_PPI_ADDR_SIZE]; > +} TPMPPI; > + > +void tpm_ppi_init_io(TPMPPI *tpmppi, Object *obj); > + > +#endif /* TPM_TPM_PPI_H */ > diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c > index 561384c..f980972 100644 > --- a/hw/tpm/tpm_tis.c > +++ b/hw/tpm/tpm_tis.c > @@ -31,6 +31,7 @@ > #include "sysemu/tpm_backend.h" > #include "tpm_int.h" > #include "tpm_util.h" > +#include "tpm_ppi.h" > > #define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ > #define TPM_TIS_LOCALITY_SHIFT 12 > @@ -80,6 +81,8 @@ typedef struct TPMState { > TPMVersion be_tpm_version; > > size_t be_buffer_size; > + > + TPMPPI ppi; > } TPMState; > > #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) > @@ -1050,6 +1053,8 @@ static void tpm_tis_initfn(Object *obj) > memory_region_init_io(&s->mmio, OBJECT(s), &tpm_tis_memory_ops, > s, "tpm-tis-mmio", > TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT); > + > + tpm_ppi_init_io(&s->ppi, obj); I suggest to pass the device isa address space there (instead of hooking the PPI only on system_memory). > } > > static void tpm_tis_class_init(ObjectClass *klass, void *data) > diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h > index 6d516c6..d9b7452 100644 > --- a/include/hw/acpi/tpm.h > +++ b/include/hw/acpi/tpm.h > @@ -31,4 +31,10 @@ > > #define TPM2_START_METHOD_MMIO 6 > > +/* > + * Physical Presence Interface > + */ > +#define TPM_PPI_ADDR_SIZE 0x100 > +#define TPM_PPI_ADDR_BASE 0xffff0000 > + > #endif /* HW_ACPI_TPM_H */ > -- > 2.5.5 > > -- Marc-André Lureau ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 1/3] tpm: Implement virtual memory device for TPM PPI 2018-01-12 14:55 ` Marc-André Lureau @ 2018-01-12 16:29 ` Eric Blake 2018-01-12 17:24 ` Stefan Berger 2018-01-12 18:23 ` Stefan Berger 2018-01-15 14:49 ` Stefan Berger 2 siblings, 1 reply; 16+ messages in thread From: Eric Blake @ 2018-01-12 16:29 UTC (permalink / raw) To: Marc-André Lureau, Stefan Berger; +Cc: kevin, QEMU, Michael S. Tsirkin [-- Attachment #1: Type: text/plain, Size: 1081 bytes --] On 01/12/2018 08:55 AM, Marc-André Lureau wrote: > Hi > > On Wed, Jan 10, 2018 at 7:35 PM, Stefan Berger > <stefanb@linux.vnet.ibm.com> wrote: >> Implement a virtual memory device for the TPM physical >> presence interface. The memory is located at 0xffff0000 >> and used by ACPI to send messages to the firmware (BIOS). >> >> This device should be used by all TPM interfaces on x86 and >> can be added through by calling tpm_ppi_init_io(). >> >> +#define DEBUG_PPI 1 > > to be switched to 0 > >> + >> +#define DPRINTF(fmt, ...) do { \ >> + if (DEBUG_PPI) { \ >> + printf(fmt, ## __VA_ARGS__); \ >> + } \ >> +} while (0); Also, this falls foul of my pending patch to forbid trailing semicolons in do/while(0) macros: https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg00246.html But even though it is not a trace point, at least you made sure -Wformat will avoid bit-rotting debug statements. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 619 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 1/3] tpm: Implement virtual memory device for TPM PPI 2018-01-12 16:29 ` Eric Blake @ 2018-01-12 17:24 ` Stefan Berger 0 siblings, 0 replies; 16+ messages in thread From: Stefan Berger @ 2018-01-12 17:24 UTC (permalink / raw) To: Eric Blake, Marc-André Lureau; +Cc: kevin, QEMU, Michael S. Tsirkin On 01/12/2018 11:29 AM, Eric Blake wrote: > On 01/12/2018 08:55 AM, Marc-André Lureau wrote: >> Hi >> >> On Wed, Jan 10, 2018 at 7:35 PM, Stefan Berger >> <stefanb@linux.vnet.ibm.com> wrote: >>> Implement a virtual memory device for the TPM physical >>> presence interface. The memory is located at 0xffff0000 >>> and used by ACPI to send messages to the firmware (BIOS). >>> >>> This device should be used by all TPM interfaces on x86 and >>> can be added through by calling tpm_ppi_init_io(). >>> >>> +#define DEBUG_PPI 1 >> to be switched to 0 >> >>> + >>> +#define DPRINTF(fmt, ...) do { \ >>> + if (DEBUG_PPI) { \ >>> + printf(fmt, ## __VA_ARGS__); \ >>> + } \ >>> +} while (0); > Also, this falls foul of my pending patch to forbid trailing semicolons > in do/while(0) macros: > https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg00246.html > > But even though it is not a trace point, at least you made sure -Wformat > will avoid bit-rotting debug statements. > Fixing it. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 1/3] tpm: Implement virtual memory device for TPM PPI 2018-01-12 14:55 ` Marc-André Lureau 2018-01-12 16:29 ` Eric Blake @ 2018-01-12 18:23 ` Stefan Berger 2018-01-15 14:49 ` Stefan Berger 2 siblings, 0 replies; 16+ messages in thread From: Stefan Berger @ 2018-01-12 18:23 UTC (permalink / raw) To: Marc-André Lureau; +Cc: kevin, QEMU, Michael S. Tsirkin On 01/12/2018 09:55 AM, Marc-André Lureau wrote: > Hi > > On Wed, Jan 10, 2018 at 7:35 PM, Stefan Berger > <stefanb@linux.vnet.ibm.com> wrote: >> Implement a virtual memory device for the TPM physical >> presence interface. The memory is located at 0xffff0000 >> and used by ACPI to send messages to the firmware (BIOS). >> >> This device should be used by all TPM interfaces on x86 and >> can be added through by calling tpm_ppi_init_io(). >> > I haven't followed closely the current design discussion on seabios > ML, so this is just a quick review: I think what I should add is an ACPI table called QEMU that holds the address of this device so that we can move this device later on. SeaBIOS would find this table and use the address it finds there rather than the #define. > >> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> >> --- >> hw/tpm/Makefile.objs | 2 +- >> hw/tpm/tpm_ppi.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ >> hw/tpm/tpm_ppi.h | 25 ++++++++++++++++ >> hw/tpm/tpm_tis.c | 5 ++++ >> include/hw/acpi/tpm.h | 6 ++++ >> 5 files changed, 116 insertions(+), 1 deletion(-) >> create mode 100644 hw/tpm/tpm_ppi.c >> create mode 100644 hw/tpm/tpm_ppi.h >> >> diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs >> index 7a93b24..3eb0558 100644 >> --- a/hw/tpm/Makefile.objs >> +++ b/hw/tpm/Makefile.objs >> @@ -1,4 +1,4 @@ >> -common-obj-y += tpm_util.o >> +common-obj-y += tpm_util.o tpm_ppi.o >> common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o >> common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o >> common-obj-$(CONFIG_TPM_EMULATOR) += tpm_emulator.o >> diff --git a/hw/tpm/tpm_ppi.c b/hw/tpm/tpm_ppi.c >> new file mode 100644 >> index 0000000..fa8c3c3 >> --- /dev/null >> +++ b/hw/tpm/tpm_ppi.c >> @@ -0,0 +1,79 @@ >> +/* >> + * tpm_ppi.c - TPM Physical Presence Interface >> + * >> + * Copyright (C) 2018 IBM Corporation >> + * >> + * Authors: >> + * Stefan Berger <stefanb@us.ibm.com> >> + * >> + * This work is licensed under the terms of the GNU GPL, version 2 or later. >> + * See the COPYING file in the top-level directory. >> + * >> + */ >> + >> +#include "qemu/osdep.h" >> +#include "exec/memory.h" >> +#include "exec/address-spaces.h" >> + >> +#include "tpm_ppi.h" >> + >> +#define DEBUG_PPI 1 > to be switched to 0 Done. > >> + >> +#define DPRINTF(fmt, ...) do { \ >> + if (DEBUG_PPI) { \ >> + printf(fmt, ## __VA_ARGS__); \ >> + } \ >> +} while (0); >> + >> +static uint64_t tpm_ppi_mmio_read(void *opaque, hwaddr addr, >> + unsigned size) >> +{ >> + TPMPPI *s = opaque; >> + uint32_t val = 0; >> + int c; >> + >> + for (c = size - 1; c >= 0; c--) { > I would rather put the -1, > >> + val <<= 8; >> + val |= s->ram[addr + c]; > ^ here, ymmv you mean val |= s->ram[addr + c - 1]? > >> + } >> + >> + DPRINTF("tpm_ppi: read.%u(%08x) = %08x\n", size, >> + (unsigned int)addr, (unsigned int)val); >> + >> + return val; >> +} >> + >> +static void tpm_ppi_mmio_write(void *opaque, hwaddr addr, >> + uint64_t val, unsigned size) >> +{ >> + TPMPPI *s = opaque; >> + int c; >> + >> + DPRINTF("tpm_ppi: write.%u(%08x) = %08x\n", size, >> + (unsigned int)addr, (unsigned int)val); >> + >> + for (c = 0; c <= size - 1; c++) { > same > > (alternatively, why not cast the addr pointer?) You mean write 16 bits and 32bits directly into the array? I have to see what happens when one writes beyond the end of the array... > >> + s->ram[addr + c] = val; >> + val >>= 8; >> + } >> +} >> + >> +static const MemoryRegionOps tpm_ppi_memory_ops = { >> + .read = tpm_ppi_mmio_read, >> + .write = tpm_ppi_mmio_write, >> + .endianness = DEVICE_LITTLE_ENDIAN, > Shouldn't it be native endian? Have to figure out what that means... >> + .valid = { >> + .min_access_size = 1, >> + .max_access_size = 4, >> + }, >> +}; >> + >> +void tpm_ppi_init_io(TPMPPI *tpmppi, Object *obj) >> +{ >> + memory_region_init_io(&tpmppi->mmio, obj, &tpm_ppi_memory_ops, >> + tpmppi, "tpm-ppi-mmio", >> + TPM_PPI_ADDR_SIZE); >> + >> + memory_region_add_subregion(get_system_memory(), >> + TPM_PPI_ADDR_BASE, &tpmppi->mmio); >> +} >> diff --git a/hw/tpm/tpm_ppi.h b/hw/tpm/tpm_ppi.h >> new file mode 100644 >> index 0000000..8959912 >> --- /dev/null >> +++ b/hw/tpm/tpm_ppi.h >> @@ -0,0 +1,25 @@ >> +/* >> + * TPM Physical Presence Interface >> + * >> + * Copyright (C) 2018 IBM Corporation >> + * >> + * Authors: >> + * Stefan Berger <stefanb@us.ibm.com> >> + * >> + * This work is licensed under the terms of the GNU GPL, version 2 or later. >> + * See the COPYING file in the top-level directory. >> + */ >> +#ifndef TPM_TPM_PPI_H >> +#define TPM_TPM_PPI_H >> + >> +#include "hw/acpi/tpm.h" >> + >> +typedef struct TPMPPI { >> + MemoryRegion mmio; >> + >> + uint8_t ram[TPM_PPI_ADDR_SIZE]; >> +} TPMPPI; >> + >> +void tpm_ppi_init_io(TPMPPI *tpmppi, Object *obj); >> + >> +#endif /* TPM_TPM_PPI_H */ >> diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c >> index 561384c..f980972 100644 >> --- a/hw/tpm/tpm_tis.c >> +++ b/hw/tpm/tpm_tis.c >> @@ -31,6 +31,7 @@ >> #include "sysemu/tpm_backend.h" >> #include "tpm_int.h" >> #include "tpm_util.h" >> +#include "tpm_ppi.h" >> >> #define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ >> #define TPM_TIS_LOCALITY_SHIFT 12 >> @@ -80,6 +81,8 @@ typedef struct TPMState { >> TPMVersion be_tpm_version; >> >> size_t be_buffer_size; >> + >> + TPMPPI ppi; >> } TPMState; >> >> #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) >> @@ -1050,6 +1053,8 @@ static void tpm_tis_initfn(Object *obj) >> memory_region_init_io(&s->mmio, OBJECT(s), &tpm_tis_memory_ops, >> s, "tpm-tis-mmio", >> TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT); >> + >> + tpm_ppi_init_io(&s->ppi, obj); > I suggest to pass the device isa address space there (instead of > hooking the PPI only on system_memory). I can do that. For my education, I wonder why, though. > >> } >> >> static void tpm_tis_class_init(ObjectClass *klass, void *data) >> diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h >> index 6d516c6..d9b7452 100644 >> --- a/include/hw/acpi/tpm.h >> +++ b/include/hw/acpi/tpm.h >> @@ -31,4 +31,10 @@ >> >> #define TPM2_START_METHOD_MMIO 6 >> >> +/* >> + * Physical Presence Interface >> + */ >> +#define TPM_PPI_ADDR_SIZE 0x100 >> +#define TPM_PPI_ADDR_BASE 0xffff0000 >> + >> #endif /* HW_ACPI_TPM_H */ >> -- >> 2.5.5 >> >> > > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 1/3] tpm: Implement virtual memory device for TPM PPI 2018-01-12 14:55 ` Marc-André Lureau 2018-01-12 16:29 ` Eric Blake 2018-01-12 18:23 ` Stefan Berger @ 2018-01-15 14:49 ` Stefan Berger 2 siblings, 0 replies; 16+ messages in thread From: Stefan Berger @ 2018-01-15 14:49 UTC (permalink / raw) To: Marc-André Lureau; +Cc: QEMU, kevin, Michael S. Tsirkin On 01/12/2018 09:55 AM, Marc-André Lureau wrote: > Hi > > On Wed, Jan 10, 2018 at 7:35 PM, Stefan Berger > <stefanb@linux.vnet.ibm.com> wrote: > >> } >> >> static void tpm_tis_class_init(ObjectClass *klass, void *data) >> diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h >> index 6d516c6..d9b7452 100644 >> --- a/include/hw/acpi/tpm.h >> +++ b/include/hw/acpi/tpm.h >> @@ -31,4 +31,10 @@ >> >> #define TPM2_START_METHOD_MMIO 6 >> >> +/* >> + * Physical Presence Interface >> + */ >> +#define TPM_PPI_ADDR_SIZE 0x100 >> +#define TPM_PPI_ADDR_BASE 0xffff0000 I tried to extend the memory size to be able to store per opcode flags into this area to de-couple the ACPI code from the firmware code as far as possible. I ended up seeing crashes. The following comment is in SeaBIOS: ./src/fw/shadow.c:// On the emulators, the bios at 0xf0000 is also at 0xffff0000 Following this, I am moving this base address to 0xfffe_f000 and extending it to 0x400 bytes. Besides that there will be a QEMU ACPI table with OEM 'QEMU' and oem_table_id 'CONF' for which the firmware has to look for. It holds the base address and the TPM version. Stefan ^ permalink raw reply [flat|nested] 16+ messages in thread
* [Qemu-devel] [RFC PATCH 2/3] acpi: implement aml_lless_equal 2018-01-10 18:35 [Qemu-devel] [RFC PATCH 0/3] Implement Pysical Presence Interface for TPM 1.2 and 2 Stefan Berger 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 1/3] tpm: Implement virtual memory device for TPM PPI Stefan Berger @ 2018-01-10 18:35 ` Stefan Berger 2018-01-12 15:17 ` Marc-André Lureau 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 3/3] acpi: Build TPM Physical Presence interface Stefan Berger 2 siblings, 1 reply; 16+ messages in thread From: Stefan Berger @ 2018-01-10 18:35 UTC (permalink / raw) To: qemu-devel; +Cc: mst, stefanb, kevin, marcandre.lureau LLessEqualOp = LNotOp LGreaterOp Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> --- hw/acpi/aml-build.c | 10 ++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 11 insertions(+) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 36a6cc4..597a58d 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -568,6 +568,16 @@ Aml *aml_lless(Aml *arg1, Aml *arg2) return var; } +Aml *aml_lless_equal(Aml *arg1, Aml *arg2) +{ + /* LLessEqualOp := LNotOp LGreaterOp */ + Aml *var = aml_opcode(0x92 /* LNotOp */); + build_append_byte(var->buf, 0x94 /* LGreaterOp */); + aml_append(var, arg1); + aml_append(var, arg2); + return var; +} + /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAdd */ Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst) { diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 88d0738..c4398cc 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -267,6 +267,7 @@ Aml *aml_lor(Aml *arg1, Aml *arg2); Aml *aml_shiftleft(Aml *arg1, Aml *count); Aml *aml_shiftright(Aml *arg1, Aml *count, Aml *dst); Aml *aml_lless(Aml *arg1, Aml *arg2); +Aml *aml_lless_equal(Aml *arg1, Aml *arg2); Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst); Aml *aml_subtract(Aml *arg1, Aml *arg2, Aml *dst); Aml *aml_increment(Aml *arg); -- 2.5.5 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 2/3] acpi: implement aml_lless_equal 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 2/3] acpi: implement aml_lless_equal Stefan Berger @ 2018-01-12 15:17 ` Marc-André Lureau 2018-01-12 19:42 ` Stefan Berger 0 siblings, 1 reply; 16+ messages in thread From: Marc-André Lureau @ 2018-01-12 15:17 UTC (permalink / raw) To: Stefan Berger; +Cc: QEMU, kevin, Michael S. Tsirkin 2018-01-10 19:35 GMT+01:00 Stefan Berger <stefanb@linux.vnet.ibm.com>: > LLessEqualOp = LNotOp LGreaterOp > > Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> > --- > hw/acpi/aml-build.c | 10 ++++++++++ > include/hw/acpi/aml-build.h | 1 + > 2 files changed, 11 insertions(+) > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c > index 36a6cc4..597a58d 100644 > --- a/hw/acpi/aml-build.c > +++ b/hw/acpi/aml-build.c > @@ -568,6 +568,16 @@ Aml *aml_lless(Aml *arg1, Aml *arg2) > return var; > } > > +Aml *aml_lless_equal(Aml *arg1, Aml *arg2) > +{ > + /* LLessEqualOp := LNotOp LGreaterOp */ > + Aml *var = aml_opcode(0x92 /* LNotOp */); > + build_append_byte(var->buf, 0x94 /* LGreaterOp */); > + aml_append(var, arg1); > + aml_append(var, arg2); > + return var; > +} > + > /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAdd */ > Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst) > { > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h > index 88d0738..c4398cc 100644 > --- a/include/hw/acpi/aml-build.h > +++ b/include/hw/acpi/aml-build.h > @@ -267,6 +267,7 @@ Aml *aml_lor(Aml *arg1, Aml *arg2); > Aml *aml_shiftleft(Aml *arg1, Aml *count); > Aml *aml_shiftright(Aml *arg1, Aml *count, Aml *dst); > Aml *aml_lless(Aml *arg1, Aml *arg2); > +Aml *aml_lless_equal(Aml *arg1, Aml *arg2); > Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst); > Aml *aml_subtract(Aml *arg1, Aml *arg2, Aml *dst); > Aml *aml_increment(Aml *arg); > -- > 2.5.5 > > -- Marc-André Lureau ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 2/3] acpi: implement aml_lless_equal 2018-01-12 15:17 ` Marc-André Lureau @ 2018-01-12 19:42 ` Stefan Berger 2018-01-15 14:31 ` Igor Mammedov 0 siblings, 1 reply; 16+ messages in thread From: Stefan Berger @ 2018-01-12 19:42 UTC (permalink / raw) To: Marc-André Lureau; +Cc: kevin, QEMU, Michael S. Tsirkin On 01/12/2018 10:17 AM, Marc-André Lureau wrote: > 2018-01-10 19:35 GMT+01:00 Stefan Berger <stefanb@linux.vnet.ibm.com>: >> LLessEqualOp = LNotOp LGreaterOp >> >> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> > Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Thanks. I added a comment line above the function now: /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLLessEqual */ > > >> --- >> hw/acpi/aml-build.c | 10 ++++++++++ >> include/hw/acpi/aml-build.h | 1 + >> 2 files changed, 11 insertions(+) >> >> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c >> index 36a6cc4..597a58d 100644 >> --- a/hw/acpi/aml-build.c >> +++ b/hw/acpi/aml-build.c >> @@ -568,6 +568,16 @@ Aml *aml_lless(Aml *arg1, Aml *arg2) >> return var; >> } >> >> +Aml *aml_lless_equal(Aml *arg1, Aml *arg2) >> +{ >> + /* LLessEqualOp := LNotOp LGreaterOp */ >> + Aml *var = aml_opcode(0x92 /* LNotOp */); >> + build_append_byte(var->buf, 0x94 /* LGreaterOp */); >> + aml_append(var, arg1); >> + aml_append(var, arg2); >> + return var; >> +} >> + >> /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAdd */ >> Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst) >> { >> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h >> index 88d0738..c4398cc 100644 >> --- a/include/hw/acpi/aml-build.h >> +++ b/include/hw/acpi/aml-build.h >> @@ -267,6 +267,7 @@ Aml *aml_lor(Aml *arg1, Aml *arg2); >> Aml *aml_shiftleft(Aml *arg1, Aml *count); >> Aml *aml_shiftright(Aml *arg1, Aml *count, Aml *dst); >> Aml *aml_lless(Aml *arg1, Aml *arg2); >> +Aml *aml_lless_equal(Aml *arg1, Aml *arg2); >> Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst); >> Aml *aml_subtract(Aml *arg1, Aml *arg2, Aml *dst); >> Aml *aml_increment(Aml *arg); >> -- >> 2.5.5 >> >> > > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 2/3] acpi: implement aml_lless_equal 2018-01-12 19:42 ` Stefan Berger @ 2018-01-15 14:31 ` Igor Mammedov 0 siblings, 0 replies; 16+ messages in thread From: Igor Mammedov @ 2018-01-15 14:31 UTC (permalink / raw) To: Stefan Berger; +Cc: Marc-André Lureau, kevin, QEMU, Michael S. Tsirkin On Fri, 12 Jan 2018 14:42:14 -0500 Stefan Berger <stefanb@linux.vnet.ibm.com> wrote: > On 01/12/2018 10:17 AM, Marc-André Lureau wrote: > > 2018-01-10 19:35 GMT+01:00 Stefan Berger <stefanb@linux.vnet.ibm.com>: > >> LLessEqualOp = LNotOp LGreaterOp > >> > >> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> > > Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> > > Thanks. I added a comment line above the function now: > > /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLLessEqual */ Reviewed-by: Igor Mammedov <imammedo@redhat.com> > > > > > >> --- > >> hw/acpi/aml-build.c | 10 ++++++++++ > >> include/hw/acpi/aml-build.h | 1 + > >> 2 files changed, 11 insertions(+) > >> > >> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c > >> index 36a6cc4..597a58d 100644 > >> --- a/hw/acpi/aml-build.c > >> +++ b/hw/acpi/aml-build.c > >> @@ -568,6 +568,16 @@ Aml *aml_lless(Aml *arg1, Aml *arg2) > >> return var; > >> } > >> > >> +Aml *aml_lless_equal(Aml *arg1, Aml *arg2) > >> +{ > >> + /* LLessEqualOp := LNotOp LGreaterOp */ > >> + Aml *var = aml_opcode(0x92 /* LNotOp */); > >> + build_append_byte(var->buf, 0x94 /* LGreaterOp */); > >> + aml_append(var, arg1); > >> + aml_append(var, arg2); > >> + return var; > >> +} > >> + > >> /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAdd */ > >> Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst) > >> { > >> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h > >> index 88d0738..c4398cc 100644 > >> --- a/include/hw/acpi/aml-build.h > >> +++ b/include/hw/acpi/aml-build.h > >> @@ -267,6 +267,7 @@ Aml *aml_lor(Aml *arg1, Aml *arg2); > >> Aml *aml_shiftleft(Aml *arg1, Aml *count); > >> Aml *aml_shiftright(Aml *arg1, Aml *count, Aml *dst); > >> Aml *aml_lless(Aml *arg1, Aml *arg2); > >> +Aml *aml_lless_equal(Aml *arg1, Aml *arg2); > >> Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst); > >> Aml *aml_subtract(Aml *arg1, Aml *arg2, Aml *dst); > >> Aml *aml_increment(Aml *arg); > >> -- > >> 2.5.5 > >> > >> > > > > > > ^ permalink raw reply [flat|nested] 16+ messages in thread
* [Qemu-devel] [RFC PATCH 3/3] acpi: Build TPM Physical Presence interface 2018-01-10 18:35 [Qemu-devel] [RFC PATCH 0/3] Implement Pysical Presence Interface for TPM 1.2 and 2 Stefan Berger 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 1/3] tpm: Implement virtual memory device for TPM PPI Stefan Berger 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 2/3] acpi: implement aml_lless_equal Stefan Berger @ 2018-01-10 18:35 ` Stefan Berger 2018-01-10 18:49 ` Stefan Berger 2 siblings, 1 reply; 16+ messages in thread From: Stefan Berger @ 2018-01-10 18:35 UTC (permalink / raw) To: qemu-devel; +Cc: mst, stefanb, kevin, marcandre.lureau The TPM Physical Presence interface consists of an ACPI part, a shared memory part, and code in the firmware. Users can send messages to the firmware by writing a code into the shared memory through invoking the ACPI code. When a reboot happens, the firmware looks for the code and acts on it by sending sequences of commands to the TPM. This patch adds the ACPI code. It is similar to the one in EDK2 but doesn't assume that SMIs are necessary to use. Besides that it tests the code entered by the user and checks whether it is supported. The range of codes supported matches the range of codes supported in SeaBIOS. It uses the same datastructure for the shared memory as EDK2 does so that EDK2 and SeaBIOS could both make use of the shared memory. The underlying TCG specification is accessible from the following page. https://trustedcomputinggroup.org/tcg-physical-presence-interface-specification/ This patch implements version 1.20. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> --- hw/i386/acpi-build.c | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/tpm.h | 15 ++++ 2 files changed, 242 insertions(+) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 18b939e..e3905a3 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -42,6 +42,7 @@ #include "hw/acpi/memory_hotplug.h" #include "sysemu/tpm.h" #include "hw/acpi/tpm.h" +#include "hw/tpm/tpm_ppi.h" #include "hw/acpi/vmgenid.h" #include "sysemu/tpm_backend.h" #include "hw/timer/mc146818rtc_regs.h" @@ -1860,6 +1861,231 @@ static Aml *build_q35_osc_method(void) } static void +build_tpm_ppi(Aml *dev, TPMVersion tpm_version) +{ + Aml *method, *field, *ifctx, *ifctx2, *ifctx3, *pak; + + aml_append(dev, + aml_operation_region("TPPI", AML_SYSTEM_MEMORY, + aml_int(TPM_PPI_ADDR_BASE), + TPM_PPI_STRUCT_SIZE)); + + field = aml_field("TPPI", AML_ANY_ACC, AML_NOLOCK, AML_PRESERVE); + aml_append(field, aml_named_field("PPIN", + sizeof(uint8_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("PPIP", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("PPRP", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("PPRQ", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("PPRM", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("LPPR", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("FRET", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("RES1", + sizeof(uint8_t) * BITS_PER_BYTE)); + aml_append(field, aml_named_field("RES2", + sizeof(uint32_t) * BITS_PER_BYTE * 4)); + aml_append(field, aml_named_field("FAIL", + sizeof(uint32_t) * BITS_PER_BYTE)); + aml_append(dev, field); + + /* + * Write the given operations code into 'PPRQ'. + */ + method = aml_method("WRAM", 2, AML_SERIALIZED); + { + aml_append(method, aml_store(aml_arg(0), aml_name("PPRQ"))); + aml_append(method, aml_store(aml_arg(1), aml_name("PPRM"))); + /* 0 = Success */ + aml_append(method, aml_return(aml_int(0))); + } + aml_append(dev, method); + + /* + * CKOP: Check whether the opcode is valid + */ + if (tpm_version == TPM_VERSION_1_2) { + method = aml_method("CKOP", 1, AML_NOTSERIALIZED); + { + ifctx = aml_if( + aml_or( + aml_or( + aml_and( + aml_lgreater_equal(aml_arg(0), aml_int(0)), + aml_lless_equal(aml_arg(0), aml_int(11)), + NULL + ), + aml_equal(aml_arg(0), aml_int(14)), + NULL + ), + aml_and( + aml_lgreater_equal(aml_arg(0), aml_int(21)), + aml_lless_equal(aml_arg(0), aml_int(22)), + NULL + ), + NULL + ) + ); + { + aml_append(ifctx, aml_return(aml_int(1))); + } + aml_append(method, ifctx); + + aml_append(method, aml_return(aml_int(0))); + } + } else { + method = aml_method("CKOP", 1, AML_NOTSERIALIZED); + { + ifctx = aml_if( + aml_equal(aml_arg(0), aml_int(0)) + ); + { + aml_append(ifctx, aml_return(aml_int(1))); + } + aml_append(method, ifctx); + + aml_append(method, aml_return(aml_int(0))); + } + } + aml_append(dev, method); + + method = aml_method("_DSM", 4, AML_SERIALIZED); + { + uint8_t zerobyte[1] = { 0 }; + + ifctx = aml_if( + aml_equal(aml_arg(0), + aml_touuid("3DDDFAA6-361B-4EB4-A424-8D10089D1653")) + ); + { + aml_append(ifctx, + aml_store(aml_to_integer(aml_arg(2)), aml_local(0))); + + /* standard DSM query function */ + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(0))); + { + uint8_t byte_list[2] = { 0xff, 0x01 }; + aml_append(ifctx2, aml_return(aml_buffer(2, byte_list))); + } + aml_append(ifctx, ifctx2); + + /* interface version: 1.2 */ + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(1))); + { + aml_append(ifctx2, aml_return(aml_string("1.2"))); + } + aml_append(ifctx, ifctx2); + + /* submit TPM operation */ + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(2))); + { + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_arg(3), + aml_int(0))), + aml_local(0))); + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); + { + aml_append(ifctx3, + aml_return(aml_call2("WRAM", + aml_local(0), + aml_int(0)))); + } + aml_append(ifctx2, ifctx3); + aml_append(ifctx2, aml_return(aml_int(1))); + } + aml_append(ifctx, ifctx2); + + /* get pending TPM operation */ + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(3))); + { + pak = aml_package(2); + aml_append(pak, aml_int(0)); + aml_append(pak, aml_name("PPRQ")); + aml_append(ifctx2, aml_return(pak)); + } + aml_append(ifctx, ifctx2); + + /* get platform-specific action to transition to pre-OS env. */ + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(4))); + { + /* 2 = reboot */ + aml_append(ifctx2, aml_return(aml_int(2))); + } + aml_append(ifctx, ifctx2); + + /* get TPM operation response */ + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(5))); + { + pak = aml_package(3); + + aml_append(pak, aml_name("FAIL")); + aml_append(pak, aml_name("LPPR")); + aml_append(pak, aml_name("PPRP")); + + aml_append(ifctx2, aml_return(pak)); + } + aml_append(ifctx, ifctx2); + + /* submit preferred user language */ + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(6))); + { + /* 3 = not implemented */ + aml_append(ifctx2, aml_return(aml_int(3))); + } + aml_append(ifctx, ifctx2); + + /* submit TPM operation v2 */ + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(7))); + { + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_arg(3), + aml_int(0))), + aml_local(0))); + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); + { + aml_append(ifctx3, + aml_store(aml_call2("WRAM", + aml_local(0), + aml_int(0)), + aml_local(1))); + aml_append(ifctx3, aml_return(aml_local(1))); + } + aml_append(ifctx2, ifctx3); + /* 1 = requested operation not implemented */ + aml_append(ifctx2, aml_return(aml_int(1))); + } + aml_append(ifctx, ifctx2); + + /* get user confirmation status for operation */ + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(8))); + { + aml_append(ifctx2, + aml_store(aml_derefof(aml_index(aml_arg(3), + aml_int(0))), + aml_local(0))); + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); + { + /* 4 = Allowed and physically present user not required */ + aml_append(ifctx3, aml_return(aml_int(4))); + } + aml_append(ifctx2, ifctx3); + /* 0 = requested operation not implemented */ + aml_append(ifctx2, aml_return(aml_int(0))); + } + aml_append(ifctx, ifctx2); + + aml_append(ifctx, aml_return(aml_buffer(1, zerobyte))); + } + aml_append(method, ifctx); + } + aml_append(dev, method); +} + +static void build_dsdt(GArray *table_data, BIOSLinker *linker, AcpiPmInfo *pm, AcpiMiscInfo *misc, Range *pci_hole, Range *pci_hole64, MachineState *machine) @@ -2218,6 +2444,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, */ /* aml_append(crs, aml_irq_no_flags(TPM_TIS_IRQ)); */ aml_append(dev, aml_name_decl("_CRS", crs)); + build_tpm_ppi(dev, misc->tpm_version); aml_append(scope, dev); } diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h index d9b7452..23f5da1 100644 --- a/include/hw/acpi/tpm.h +++ b/include/hw/acpi/tpm.h @@ -37,4 +37,19 @@ #define TPM_PPI_ADDR_SIZE 0x100 #define TPM_PPI_ADDR_BASE 0xffff0000 +struct tpm_ppi { + uint8_t ppin; /* set by BIOS; currently initialization flag */ + uint32_t ppip; /* set by ACPI; not used */ + uint32_t pprp; /* response from TPM; set by BIOS */ + uint32_t pprq; /* opcode; set by ACPI */ + uint32_t pprm; /* parameter for opcode; set by ACPI */ + uint32_t lppr; /* last opcode; set by BIOS */ + uint32_t fret; /* set by ACPI; not used*/ + uint32_t res1; /* reserved */ + uint32_t res2[4]; /* reserved */ + uint32_t fail; /* set by BIOS (0 = success) */ +} QEMU_PACKED; + +#define TPM_PPI_STRUCT_SIZE sizeof(struct tpm_ppi) + #endif /* HW_ACPI_TPM_H */ -- 2.5.5 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 3/3] acpi: Build TPM Physical Presence interface 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 3/3] acpi: Build TPM Physical Presence interface Stefan Berger @ 2018-01-10 18:49 ` Stefan Berger 2018-01-12 16:07 ` Marc-André Lureau 0 siblings, 1 reply; 16+ messages in thread From: Stefan Berger @ 2018-01-10 18:49 UTC (permalink / raw) To: qemu-devel; +Cc: mst, kevin, marcandre.lureau On 01/10/2018 01:35 PM, Stefan Berger wrote: > The TPM Physical Presence interface consists of an ACPI part, a shared > memory part, and code in the firmware. Users can send messages to the > firmware by writing a code into the shared memory through invoking the > ACPI code. When a reboot happens, the firmware looks for the code and > acts on it by sending sequences of commands to the TPM. > > This patch adds the ACPI code. It is similar to the one in EDK2 but doesn't > assume that SMIs are necessary to use. Besides that it tests the code > entered by the user and checks whether it is supported. The range of codes > supported matches the range of codes supported in SeaBIOS. It uses the same > datastructure for the shared memory as EDK2 does so that EDK2 and SeaBIOS > could both make use of the shared memory. > > The underlying TCG specification is accessible from the following page. > > https://trustedcomputinggroup.org/tcg-physical-presence-interface-specification/ > > This patch implements version 1.20. The below ACPI code is partly a translation to C from a previous posted patch: https://lists.gnu.org/archive/html/qemu-devel/2015-05/msg05353.html Stefan > > Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> > --- > hw/i386/acpi-build.c | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++ > include/hw/acpi/tpm.h | 15 ++++ > 2 files changed, 242 insertions(+) > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c > index 18b939e..e3905a3 100644 > --- a/hw/i386/acpi-build.c > +++ b/hw/i386/acpi-build.c > @@ -42,6 +42,7 @@ > #include "hw/acpi/memory_hotplug.h" > #include "sysemu/tpm.h" > #include "hw/acpi/tpm.h" > +#include "hw/tpm/tpm_ppi.h" > #include "hw/acpi/vmgenid.h" > #include "sysemu/tpm_backend.h" > #include "hw/timer/mc146818rtc_regs.h" > @@ -1860,6 +1861,231 @@ static Aml *build_q35_osc_method(void) > } > > static void > +build_tpm_ppi(Aml *dev, TPMVersion tpm_version) > +{ > + Aml *method, *field, *ifctx, *ifctx2, *ifctx3, *pak; > + > + aml_append(dev, > + aml_operation_region("TPPI", AML_SYSTEM_MEMORY, > + aml_int(TPM_PPI_ADDR_BASE), > + TPM_PPI_STRUCT_SIZE)); > + > + field = aml_field("TPPI", AML_ANY_ACC, AML_NOLOCK, AML_PRESERVE); > + aml_append(field, aml_named_field("PPIN", > + sizeof(uint8_t) * BITS_PER_BYTE)); > + aml_append(field, aml_named_field("PPIP", > + sizeof(uint32_t) * BITS_PER_BYTE)); > + aml_append(field, aml_named_field("PPRP", > + sizeof(uint32_t) * BITS_PER_BYTE)); > + aml_append(field, aml_named_field("PPRQ", > + sizeof(uint32_t) * BITS_PER_BYTE)); > + aml_append(field, aml_named_field("PPRM", > + sizeof(uint32_t) * BITS_PER_BYTE)); > + aml_append(field, aml_named_field("LPPR", > + sizeof(uint32_t) * BITS_PER_BYTE)); > + aml_append(field, aml_named_field("FRET", > + sizeof(uint32_t) * BITS_PER_BYTE)); > + aml_append(field, aml_named_field("RES1", > + sizeof(uint8_t) * BITS_PER_BYTE)); > + aml_append(field, aml_named_field("RES2", > + sizeof(uint32_t) * BITS_PER_BYTE * 4)); > + aml_append(field, aml_named_field("FAIL", > + sizeof(uint32_t) * BITS_PER_BYTE)); > + aml_append(dev, field); > + > + /* > + * Write the given operations code into 'PPRQ'. > + */ > + method = aml_method("WRAM", 2, AML_SERIALIZED); > + { > + aml_append(method, aml_store(aml_arg(0), aml_name("PPRQ"))); > + aml_append(method, aml_store(aml_arg(1), aml_name("PPRM"))); > + /* 0 = Success */ > + aml_append(method, aml_return(aml_int(0))); > + } > + aml_append(dev, method); > + > + /* > + * CKOP: Check whether the opcode is valid > + */ > + if (tpm_version == TPM_VERSION_1_2) { > + method = aml_method("CKOP", 1, AML_NOTSERIALIZED); > + { > + ifctx = aml_if( > + aml_or( > + aml_or( > + aml_and( > + aml_lgreater_equal(aml_arg(0), aml_int(0)), > + aml_lless_equal(aml_arg(0), aml_int(11)), > + NULL > + ), > + aml_equal(aml_arg(0), aml_int(14)), > + NULL > + ), > + aml_and( > + aml_lgreater_equal(aml_arg(0), aml_int(21)), > + aml_lless_equal(aml_arg(0), aml_int(22)), > + NULL > + ), > + NULL > + ) > + ); > + { > + aml_append(ifctx, aml_return(aml_int(1))); > + } > + aml_append(method, ifctx); > + > + aml_append(method, aml_return(aml_int(0))); > + } > + } else { > + method = aml_method("CKOP", 1, AML_NOTSERIALIZED); > + { > + ifctx = aml_if( > + aml_equal(aml_arg(0), aml_int(0)) > + ); > + { > + aml_append(ifctx, aml_return(aml_int(1))); > + } > + aml_append(method, ifctx); > + > + aml_append(method, aml_return(aml_int(0))); > + } > + } > + aml_append(dev, method); > + > + method = aml_method("_DSM", 4, AML_SERIALIZED); > + { > + uint8_t zerobyte[1] = { 0 }; > + > + ifctx = aml_if( > + aml_equal(aml_arg(0), > + aml_touuid("3DDDFAA6-361B-4EB4-A424-8D10089D1653")) > + ); > + { > + aml_append(ifctx, > + aml_store(aml_to_integer(aml_arg(2)), aml_local(0))); > + > + /* standard DSM query function */ > + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(0))); > + { > + uint8_t byte_list[2] = { 0xff, 0x01 }; > + aml_append(ifctx2, aml_return(aml_buffer(2, byte_list))); > + } > + aml_append(ifctx, ifctx2); > + > + /* interface version: 1.2 */ > + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(1))); > + { > + aml_append(ifctx2, aml_return(aml_string("1.2"))); > + } > + aml_append(ifctx, ifctx2); > + > + /* submit TPM operation */ > + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(2))); > + { > + aml_append(ifctx2, > + aml_store(aml_derefof(aml_index(aml_arg(3), > + aml_int(0))), > + aml_local(0))); > + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); > + { > + aml_append(ifctx3, > + aml_return(aml_call2("WRAM", > + aml_local(0), > + aml_int(0)))); > + } > + aml_append(ifctx2, ifctx3); > + aml_append(ifctx2, aml_return(aml_int(1))); > + } > + aml_append(ifctx, ifctx2); > + > + /* get pending TPM operation */ > + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(3))); > + { > + pak = aml_package(2); > + aml_append(pak, aml_int(0)); > + aml_append(pak, aml_name("PPRQ")); > + aml_append(ifctx2, aml_return(pak)); > + } > + aml_append(ifctx, ifctx2); > + > + /* get platform-specific action to transition to pre-OS env. */ > + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(4))); > + { > + /* 2 = reboot */ > + aml_append(ifctx2, aml_return(aml_int(2))); > + } > + aml_append(ifctx, ifctx2); > + > + /* get TPM operation response */ > + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(5))); > + { > + pak = aml_package(3); > + > + aml_append(pak, aml_name("FAIL")); > + aml_append(pak, aml_name("LPPR")); > + aml_append(pak, aml_name("PPRP")); > + > + aml_append(ifctx2, aml_return(pak)); > + } > + aml_append(ifctx, ifctx2); > + > + /* submit preferred user language */ > + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(6))); > + { > + /* 3 = not implemented */ > + aml_append(ifctx2, aml_return(aml_int(3))); > + } > + aml_append(ifctx, ifctx2); > + > + /* submit TPM operation v2 */ > + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(7))); > + { > + aml_append(ifctx2, > + aml_store(aml_derefof(aml_index(aml_arg(3), > + aml_int(0))), > + aml_local(0))); > + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); > + { > + aml_append(ifctx3, > + aml_store(aml_call2("WRAM", > + aml_local(0), > + aml_int(0)), > + aml_local(1))); > + aml_append(ifctx3, aml_return(aml_local(1))); > + } > + aml_append(ifctx2, ifctx3); > + /* 1 = requested operation not implemented */ > + aml_append(ifctx2, aml_return(aml_int(1))); > + } > + aml_append(ifctx, ifctx2); > + > + /* get user confirmation status for operation */ > + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(8))); > + { > + aml_append(ifctx2, > + aml_store(aml_derefof(aml_index(aml_arg(3), > + aml_int(0))), > + aml_local(0))); > + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); > + { > + /* 4 = Allowed and physically present user not required */ > + aml_append(ifctx3, aml_return(aml_int(4))); > + } > + aml_append(ifctx2, ifctx3); > + /* 0 = requested operation not implemented */ > + aml_append(ifctx2, aml_return(aml_int(0))); > + } > + aml_append(ifctx, ifctx2); > + > + aml_append(ifctx, aml_return(aml_buffer(1, zerobyte))); > + } > + aml_append(method, ifctx); > + } > + aml_append(dev, method); > +} > + > +static void > build_dsdt(GArray *table_data, BIOSLinker *linker, > AcpiPmInfo *pm, AcpiMiscInfo *misc, > Range *pci_hole, Range *pci_hole64, MachineState *machine) > @@ -2218,6 +2444,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, > */ > /* aml_append(crs, aml_irq_no_flags(TPM_TIS_IRQ)); */ > aml_append(dev, aml_name_decl("_CRS", crs)); > + build_tpm_ppi(dev, misc->tpm_version); > aml_append(scope, dev); > } > > diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h > index d9b7452..23f5da1 100644 > --- a/include/hw/acpi/tpm.h > +++ b/include/hw/acpi/tpm.h > @@ -37,4 +37,19 @@ > #define TPM_PPI_ADDR_SIZE 0x100 > #define TPM_PPI_ADDR_BASE 0xffff0000 > > +struct tpm_ppi { > + uint8_t ppin; /* set by BIOS; currently initialization flag */ > + uint32_t ppip; /* set by ACPI; not used */ > + uint32_t pprp; /* response from TPM; set by BIOS */ > + uint32_t pprq; /* opcode; set by ACPI */ > + uint32_t pprm; /* parameter for opcode; set by ACPI */ > + uint32_t lppr; /* last opcode; set by BIOS */ > + uint32_t fret; /* set by ACPI; not used*/ > + uint32_t res1; /* reserved */ > + uint32_t res2[4]; /* reserved */ > + uint32_t fail; /* set by BIOS (0 = success) */ > +} QEMU_PACKED; > + > +#define TPM_PPI_STRUCT_SIZE sizeof(struct tpm_ppi) > + > #endif /* HW_ACPI_TPM_H */ ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 3/3] acpi: Build TPM Physical Presence interface 2018-01-10 18:49 ` Stefan Berger @ 2018-01-12 16:07 ` Marc-André Lureau 2018-01-12 17:00 ` Stefan Berger 2018-01-12 20:16 ` Stefan Berger 0 siblings, 2 replies; 16+ messages in thread From: Marc-André Lureau @ 2018-01-12 16:07 UTC (permalink / raw) To: Stefan Berger; +Cc: QEMU, kevin, Michael S. Tsirkin Hi On Wed, Jan 10, 2018 at 7:49 PM, Stefan Berger <stefanb@linux.vnet.ibm.com> wrote: > On 01/10/2018 01:35 PM, Stefan Berger wrote: >> >> The TPM Physical Presence interface consists of an ACPI part, a shared >> memory part, and code in the firmware. Users can send messages to the >> firmware by writing a code into the shared memory through invoking the >> ACPI code. When a reboot happens, the firmware looks for the code and >> acts on it by sending sequences of commands to the TPM. >> >> This patch adds the ACPI code. It is similar to the one in EDK2 but >> doesn't >> assume that SMIs are necessary to use. Besides that it tests the code >> entered by the user and checks whether it is supported. The range of codes >> supported matches the range of codes supported in SeaBIOS. It uses the >> same >> datastructure for the shared memory as EDK2 does so that EDK2 and SeaBIOS >> could both make use of the shared memory. >> >> The underlying TCG specification is accessible from the following page. >> >> >> https://trustedcomputinggroup.org/tcg-physical-presence-interface-specification/ >> >> This patch implements version 1.20. > > > The below ACPI code is partly a translation to C from a previous posted > patch: > > https://lists.gnu.org/archive/html/qemu-devel/2015-05/msg05353.html > > And fwiw, this is the acpi dump disassembled: Device (ISA.TPM) { Name (_HID, EisaId ("PNP0C31")) // _HID: Hardware ID Name (_STA, 0x0F) // _STA: Status Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings { Memory32Fixed (ReadWrite, 0xFED40000, // Address Base 0x00005000, // Address Length ) }) OperationRegion (TPPI, SystemMemory, 0xFFFF0000, 0x31) Field (TPPI, AnyAcc, NoLock, Preserve) { PPIN, 8, PPIP, 32, PPRP, 32, PPRQ, 32, PPRM, 32, LPPR, 32, FRET, 32, RES1, 8, RES2, 128, FAIL, 32 } Method (WRAM, 2, Serialized) { PPRQ = Arg0 PPRM = Arg1 Return (Zero) } Method (CKOP, 1, NotSerialized) { If ((Arg0 == Zero)) { Return (One) } Return (Zero) } Method (_DSM, 4, Serialized) // _DSM: Device-Specific Method { If ((Arg0 == ToUUID ("3dddfaa6-361b-4eb4-a424-8d10089d1653") /* Physical Presence Interface */)) { Local0 = ToInteger (Arg2) If ((Local0 == Zero)) { Return (Buffer (0x02) { 0xFF, 0x01 // .. }) } If ((Local0 == One)) { Return ("1.2") } If ((Local0 == 0x02)) { Local0 = DerefOf (Arg3 [Zero]) If (CKOP (Local0)) { Return (WRAM (Local0, Zero)) } Return (One) } If ((Local0 == 0x03)) { Return (Package (0x02) { Zero, PPRQ }) } If ((Local0 == 0x04)) { Return (0x02) } If ((Local0 == 0x05)) { Return (Package (0x03) { FAIL, LPPR, PPRP }) } If ((Local0 == 0x06)) { Return (0x03) } If ((Local0 == 0x07)) { Local0 = DerefOf (Arg3 [Zero]) If (CKOP (Local0)) { Local1 = WRAM (Local0, Zero) Return (Local1) } Return (One) } If ((Local0 == 0x08)) { Local0 = DerefOf (Arg3 [Zero]) If (CKOP (Local0)) { Return (0x04) } Return (Zero) } Return (Buffer (One) { 0x00 // . }) } } Linux PPI driver seems to be happy about it, looking at /sys/devices/pnp0/00\:06/tpm/tpm0/ppi/. I haven't done further testing. Is there anything using this on Linux? tpm2-tools doesn't seem to use it. I suppose I should be able to write something to /sys/devices/pnp0/00\:06/tpm/tpm0/ppi/request. Any help appreciated :) > Stefan > >> >> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> >> --- >> hw/i386/acpi-build.c | 227 >> ++++++++++++++++++++++++++++++++++++++++++++++++++ >> include/hw/acpi/tpm.h | 15 ++++ >> 2 files changed, 242 insertions(+) >> >> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c >> index 18b939e..e3905a3 100644 >> --- a/hw/i386/acpi-build.c >> +++ b/hw/i386/acpi-build.c >> @@ -42,6 +42,7 @@ >> #include "hw/acpi/memory_hotplug.h" >> #include "sysemu/tpm.h" >> #include "hw/acpi/tpm.h" >> +#include "hw/tpm/tpm_ppi.h" >> #include "hw/acpi/vmgenid.h" >> #include "sysemu/tpm_backend.h" >> #include "hw/timer/mc146818rtc_regs.h" >> @@ -1860,6 +1861,231 @@ static Aml *build_q35_osc_method(void) >> } >> >> static void >> +build_tpm_ppi(Aml *dev, TPMVersion tpm_version) >> +{ >> + Aml *method, *field, *ifctx, *ifctx2, *ifctx3, *pak; >> + >> + aml_append(dev, >> + aml_operation_region("TPPI", AML_SYSTEM_MEMORY, >> + aml_int(TPM_PPI_ADDR_BASE), >> + TPM_PPI_STRUCT_SIZE)); >> + >> + field = aml_field("TPPI", AML_ANY_ACC, AML_NOLOCK, AML_PRESERVE); >> + aml_append(field, aml_named_field("PPIN", >> + sizeof(uint8_t) * BITS_PER_BYTE)); >> + aml_append(field, aml_named_field("PPIP", >> + sizeof(uint32_t) * BITS_PER_BYTE)); >> + aml_append(field, aml_named_field("PPRP", >> + sizeof(uint32_t) * BITS_PER_BYTE)); >> + aml_append(field, aml_named_field("PPRQ", >> + sizeof(uint32_t) * BITS_PER_BYTE)); >> + aml_append(field, aml_named_field("PPRM", >> + sizeof(uint32_t) * BITS_PER_BYTE)); >> + aml_append(field, aml_named_field("LPPR", >> + sizeof(uint32_t) * BITS_PER_BYTE)); >> + aml_append(field, aml_named_field("FRET", >> + sizeof(uint32_t) * BITS_PER_BYTE)); >> + aml_append(field, aml_named_field("RES1", >> + sizeof(uint8_t) * BITS_PER_BYTE)); >> + aml_append(field, aml_named_field("RES2", >> + sizeof(uint32_t) * BITS_PER_BYTE * 4)); >> + aml_append(field, aml_named_field("FAIL", >> + sizeof(uint32_t) * BITS_PER_BYTE)); >> + aml_append(dev, field); >> + >> + /* >> + * Write the given operations code into 'PPRQ'. >> + */ >> + method = aml_method("WRAM", 2, AML_SERIALIZED); >> + { >> + aml_append(method, aml_store(aml_arg(0), aml_name("PPRQ"))); >> + aml_append(method, aml_store(aml_arg(1), aml_name("PPRM"))); >> + /* 0 = Success */ >> + aml_append(method, aml_return(aml_int(0))); >> + } >> + aml_append(dev, method); >> + >> + /* >> + * CKOP: Check whether the opcode is valid >> + */ >> + if (tpm_version == TPM_VERSION_1_2) { >> + method = aml_method("CKOP", 1, AML_NOTSERIALIZED); >> + { >> + ifctx = aml_if( >> + aml_or( >> + aml_or( >> + aml_and( >> + aml_lgreater_equal(aml_arg(0), aml_int(0)), >> + aml_lless_equal(aml_arg(0), aml_int(11)), >> + NULL >> + ), >> + aml_equal(aml_arg(0), aml_int(14)), >> + NULL >> + ), >> + aml_and( >> + aml_lgreater_equal(aml_arg(0), aml_int(21)), >> + aml_lless_equal(aml_arg(0), aml_int(22)), >> + NULL >> + ), >> + NULL >> + ) >> + ); >> + { >> + aml_append(ifctx, aml_return(aml_int(1))); >> + } >> + aml_append(method, ifctx); >> + >> + aml_append(method, aml_return(aml_int(0))); >> + } >> + } else { >> + method = aml_method("CKOP", 1, AML_NOTSERIALIZED); >> + { >> + ifctx = aml_if( >> + aml_equal(aml_arg(0), aml_int(0)) >> + ); >> + { >> + aml_append(ifctx, aml_return(aml_int(1))); >> + } >> + aml_append(method, ifctx); >> + >> + aml_append(method, aml_return(aml_int(0))); >> + } >> + } >> + aml_append(dev, method); >> + >> + method = aml_method("_DSM", 4, AML_SERIALIZED); >> + { >> + uint8_t zerobyte[1] = { 0 }; >> + >> + ifctx = aml_if( >> + aml_equal(aml_arg(0), >> + >> aml_touuid("3DDDFAA6-361B-4EB4-A424-8D10089D1653")) >> + ); >> + { >> + aml_append(ifctx, >> + aml_store(aml_to_integer(aml_arg(2)), >> aml_local(0))); >> + >> + /* standard DSM query function */ >> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(0))); >> + { >> + uint8_t byte_list[2] = { 0xff, 0x01 }; >> + aml_append(ifctx2, aml_return(aml_buffer(2, byte_list))); >> + } >> + aml_append(ifctx, ifctx2); >> + >> + /* interface version: 1.2 */ >> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(1))); >> + { >> + aml_append(ifctx2, aml_return(aml_string("1.2"))); >> + } >> + aml_append(ifctx, ifctx2); >> + >> + /* submit TPM operation */ >> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(2))); >> + { >> + aml_append(ifctx2, >> + aml_store(aml_derefof(aml_index(aml_arg(3), >> + aml_int(0))), >> + aml_local(0))); >> + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); >> + { >> + aml_append(ifctx3, >> + aml_return(aml_call2("WRAM", >> + aml_local(0), >> + aml_int(0)))); >> + } >> + aml_append(ifctx2, ifctx3); >> + aml_append(ifctx2, aml_return(aml_int(1))); >> + } >> + aml_append(ifctx, ifctx2); >> + >> + /* get pending TPM operation */ >> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(3))); >> + { >> + pak = aml_package(2); >> + aml_append(pak, aml_int(0)); >> + aml_append(pak, aml_name("PPRQ")); >> + aml_append(ifctx2, aml_return(pak)); >> + } >> + aml_append(ifctx, ifctx2); >> + >> + /* get platform-specific action to transition to pre-OS env. >> */ >> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(4))); >> + { >> + /* 2 = reboot */ >> + aml_append(ifctx2, aml_return(aml_int(2))); >> + } >> + aml_append(ifctx, ifctx2); >> + >> + /* get TPM operation response */ >> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(5))); >> + { >> + pak = aml_package(3); >> + >> + aml_append(pak, aml_name("FAIL")); >> + aml_append(pak, aml_name("LPPR")); >> + aml_append(pak, aml_name("PPRP")); >> + >> + aml_append(ifctx2, aml_return(pak)); >> + } >> + aml_append(ifctx, ifctx2); >> + >> + /* submit preferred user language */ >> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(6))); >> + { >> + /* 3 = not implemented */ >> + aml_append(ifctx2, aml_return(aml_int(3))); >> + } >> + aml_append(ifctx, ifctx2); >> + >> + /* submit TPM operation v2 */ >> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(7))); >> + { >> + aml_append(ifctx2, >> + aml_store(aml_derefof(aml_index(aml_arg(3), >> + aml_int(0))), >> + aml_local(0))); >> + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); >> + { >> + aml_append(ifctx3, >> + aml_store(aml_call2("WRAM", >> + aml_local(0), >> + aml_int(0)), >> + aml_local(1))); >> + aml_append(ifctx3, aml_return(aml_local(1))); >> + } >> + aml_append(ifctx2, ifctx3); >> + /* 1 = requested operation not implemented */ >> + aml_append(ifctx2, aml_return(aml_int(1))); >> + } >> + aml_append(ifctx, ifctx2); >> + >> + /* get user confirmation status for operation */ >> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(8))); >> + { >> + aml_append(ifctx2, >> + aml_store(aml_derefof(aml_index(aml_arg(3), >> + aml_int(0))), >> + aml_local(0))); >> + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); >> + { >> + /* 4 = Allowed and physically present user not >> required */ >> + aml_append(ifctx3, aml_return(aml_int(4))); >> + } >> + aml_append(ifctx2, ifctx3); >> + /* 0 = requested operation not implemented */ >> + aml_append(ifctx2, aml_return(aml_int(0))); >> + } >> + aml_append(ifctx, ifctx2); >> + >> + aml_append(ifctx, aml_return(aml_buffer(1, zerobyte))); >> + } >> + aml_append(method, ifctx); >> + } >> + aml_append(dev, method); >> +} >> + >> +static void >> build_dsdt(GArray *table_data, BIOSLinker *linker, >> AcpiPmInfo *pm, AcpiMiscInfo *misc, >> Range *pci_hole, Range *pci_hole64, MachineState *machine) >> @@ -2218,6 +2444,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, >> */ >> /* aml_append(crs, aml_irq_no_flags(TPM_TIS_IRQ)); */ >> aml_append(dev, aml_name_decl("_CRS", crs)); >> + build_tpm_ppi(dev, misc->tpm_version); >> aml_append(scope, dev); >> } >> >> diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h >> index d9b7452..23f5da1 100644 >> --- a/include/hw/acpi/tpm.h >> +++ b/include/hw/acpi/tpm.h >> @@ -37,4 +37,19 @@ >> #define TPM_PPI_ADDR_SIZE 0x100 >> #define TPM_PPI_ADDR_BASE 0xffff0000 >> >> +struct tpm_ppi { >> + uint8_t ppin; /* set by BIOS; currently initialization >> flag */ >> + uint32_t ppip; /* set by ACPI; not used */ >> + uint32_t pprp; /* response from TPM; set by BIOS */ >> + uint32_t pprq; /* opcode; set by ACPI */ >> + uint32_t pprm; /* parameter for opcode; set by ACPI */ >> + uint32_t lppr; /* last opcode; set by BIOS */ >> + uint32_t fret; /* set by ACPI; not used*/ >> + uint32_t res1; /* reserved */ >> + uint32_t res2[4]; /* reserved */ >> + uint32_t fail; /* set by BIOS (0 = success) */ >> +} QEMU_PACKED; >> + >> +#define TPM_PPI_STRUCT_SIZE sizeof(struct tpm_ppi) >> + >> #endif /* HW_ACPI_TPM_H */ > > > > otherwise, patch looks good. -- Marc-André Lureau ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 3/3] acpi: Build TPM Physical Presence interface 2018-01-12 16:07 ` Marc-André Lureau @ 2018-01-12 17:00 ` Stefan Berger 2018-01-12 20:16 ` Stefan Berger 1 sibling, 0 replies; 16+ messages in thread From: Stefan Berger @ 2018-01-12 17:00 UTC (permalink / raw) To: Marc-André Lureau; +Cc: QEMU, kevin, Michael S. Tsirkin On 01/12/2018 11:07 AM, Marc-André Lureau wrote: > Hi > > On Wed, Jan 10, 2018 at 7:49 PM, Stefan Berger > <stefanb@linux.vnet.ibm.com> wrote: >> On 01/10/2018 01:35 PM, Stefan Berger wrote: >>> The TPM Physical Presence interface consists of an ACPI part, a shared >>> memory part, and code in the firmware. Users can send messages to the >>> firmware by writing a code into the shared memory through invoking the >>> ACPI code. When a reboot happens, the firmware looks for the code and >>> acts on it by sending sequences of commands to the TPM. >>> >>> This patch adds the ACPI code. It is similar to the one in EDK2 but >>> doesn't >>> assume that SMIs are necessary to use. Besides that it tests the code >>> entered by the user and checks whether it is supported. The range of codes >>> supported matches the range of codes supported in SeaBIOS. It uses the >>> same >>> datastructure for the shared memory as EDK2 does so that EDK2 and SeaBIOS >>> could both make use of the shared memory. >>> >>> The underlying TCG specification is accessible from the following page. >>> >>> >>> https://trustedcomputinggroup.org/tcg-physical-presence-interface-specification/ >>> >>> This patch implements version 1.20. >> >> The below ACPI code is partly a translation to C from a previous posted >> patch: >> >> https://lists.gnu.org/archive/html/qemu-devel/2015-05/msg05353.html >> >> > And fwiw, this is the acpi dump disassembled: > > Device (ISA.TPM) > { > Name (_HID, EisaId ("PNP0C31")) // _HID: Hardware ID > Name (_STA, 0x0F) // _STA: Status > Name (_CRS, ResourceTemplate () // _CRS: Current > Resource Settings > { > Memory32Fixed (ReadWrite, > 0xFED40000, // Address Base > 0x00005000, // Address Length > ) > }) > OperationRegion (TPPI, SystemMemory, 0xFFFF0000, 0x31) > Field (TPPI, AnyAcc, NoLock, Preserve) > { > PPIN, 8, > PPIP, 32, > PPRP, 32, > PPRQ, 32, > PPRM, 32, > LPPR, 32, > FRET, 32, > RES1, 8, > RES2, 128, > FAIL, 32 > } > > Method (WRAM, 2, Serialized) > { > PPRQ = Arg0 > PPRM = Arg1 > Return (Zero) > } > > Method (CKOP, 1, NotSerialized) > { > If ((Arg0 == Zero)) > { > Return (One) > } > > Return (Zero) > } > > Method (_DSM, 4, Serialized) // _DSM: Device-Specific Method > { > If ((Arg0 == ToUUID > ("3dddfaa6-361b-4eb4-a424-8d10089d1653") /* Physical Presence > Interface */)) > { > Local0 = ToInteger (Arg2) > If ((Local0 == Zero)) > { > Return (Buffer (0x02) > { > 0xFF, 0x01 > // .. > }) > } > > If ((Local0 == One)) > { > Return ("1.2") > } > > If ((Local0 == 0x02)) > { > Local0 = DerefOf (Arg3 [Zero]) > If (CKOP (Local0)) > { > Return (WRAM (Local0, Zero)) > } > > Return (One) > } > > If ((Local0 == 0x03)) > { > Return (Package (0x02) > { > Zero, > PPRQ > }) > } > > If ((Local0 == 0x04)) > { > Return (0x02) > } > > If ((Local0 == 0x05)) > { > Return (Package (0x03) > { > FAIL, > LPPR, > PPRP > }) > } > > If ((Local0 == 0x06)) > { > Return (0x03) > } > > If ((Local0 == 0x07)) > { > Local0 = DerefOf (Arg3 [Zero]) > If (CKOP (Local0)) > { > Local1 = WRAM (Local0, Zero) > Return (Local1) > } > > Return (One) > } > > If ((Local0 == 0x08)) > { > Local0 = DerefOf (Arg3 [Zero]) > If (CKOP (Local0)) > { > Return (0x04) > } > > Return (Zero) > } > > Return (Buffer (One) > { > 0x00 > // . > }) > } > } > > Linux PPI driver seems to be happy about it, looking at > /sys/devices/pnp0/00\:06/tpm/tpm0/ppi/. > > I haven't done further testing. Is there anything using this on Linux? > tpm2-tools doesn't seem to use it. I suppose I should be able to write > something to /sys/devices/pnp0/00\:06/tpm/tpm0/ppi/request. > > Any help appreciated :) To deacativate and disable the TPM 1.2 (!) write a '7' into the request. echo 7 > request cat ../enabled ../active # should show two 1s indicating that it's currently enabled and active cat request # should show 7 now Do a reboot. Linux may complain that it cannot extend a PCR. This is expected when the TPM is deactivated and disabled. To enable and activate it after reboot do: echo 6 > request cat request # should show 6 now cat response # should show that 7 succeeded cat ../enable ../active # should show two zeros reboot Now the TPM 1.2 is enabled and active again, no more error message from Linux should occur. cat ../enabled ../active # should show two 1s cat response # should show that 6 succeeded PPI isn't used much probably. I mainly want the device for suspending the state of it along with the TIS state. I suppose that once we do that it 'nails the coffin' on the device state we write out and future extensions of fields to write out only cause issues later. So better have it now. Stefan > >> Stefan >> >>> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> >>> --- >>> hw/i386/acpi-build.c | 227 >>> ++++++++++++++++++++++++++++++++++++++++++++++++++ >>> include/hw/acpi/tpm.h | 15 ++++ >>> 2 files changed, 242 insertions(+) >>> >>> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c >>> index 18b939e..e3905a3 100644 >>> --- a/hw/i386/acpi-build.c >>> +++ b/hw/i386/acpi-build.c >>> @@ -42,6 +42,7 @@ >>> #include "hw/acpi/memory_hotplug.h" >>> #include "sysemu/tpm.h" >>> #include "hw/acpi/tpm.h" >>> +#include "hw/tpm/tpm_ppi.h" >>> #include "hw/acpi/vmgenid.h" >>> #include "sysemu/tpm_backend.h" >>> #include "hw/timer/mc146818rtc_regs.h" >>> @@ -1860,6 +1861,231 @@ static Aml *build_q35_osc_method(void) >>> } >>> >>> static void >>> +build_tpm_ppi(Aml *dev, TPMVersion tpm_version) >>> +{ >>> + Aml *method, *field, *ifctx, *ifctx2, *ifctx3, *pak; >>> + >>> + aml_append(dev, >>> + aml_operation_region("TPPI", AML_SYSTEM_MEMORY, >>> + aml_int(TPM_PPI_ADDR_BASE), >>> + TPM_PPI_STRUCT_SIZE)); >>> + >>> + field = aml_field("TPPI", AML_ANY_ACC, AML_NOLOCK, AML_PRESERVE); >>> + aml_append(field, aml_named_field("PPIN", >>> + sizeof(uint8_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("PPIP", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("PPRP", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("PPRQ", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("PPRM", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("LPPR", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("FRET", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("RES1", >>> + sizeof(uint8_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("RES2", >>> + sizeof(uint32_t) * BITS_PER_BYTE * 4)); >>> + aml_append(field, aml_named_field("FAIL", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(dev, field); >>> + >>> + /* >>> + * Write the given operations code into 'PPRQ'. >>> + */ >>> + method = aml_method("WRAM", 2, AML_SERIALIZED); >>> + { >>> + aml_append(method, aml_store(aml_arg(0), aml_name("PPRQ"))); >>> + aml_append(method, aml_store(aml_arg(1), aml_name("PPRM"))); >>> + /* 0 = Success */ >>> + aml_append(method, aml_return(aml_int(0))); >>> + } >>> + aml_append(dev, method); >>> + >>> + /* >>> + * CKOP: Check whether the opcode is valid >>> + */ >>> + if (tpm_version == TPM_VERSION_1_2) { >>> + method = aml_method("CKOP", 1, AML_NOTSERIALIZED); >>> + { >>> + ifctx = aml_if( >>> + aml_or( >>> + aml_or( >>> + aml_and( >>> + aml_lgreater_equal(aml_arg(0), aml_int(0)), >>> + aml_lless_equal(aml_arg(0), aml_int(11)), >>> + NULL >>> + ), >>> + aml_equal(aml_arg(0), aml_int(14)), >>> + NULL >>> + ), >>> + aml_and( >>> + aml_lgreater_equal(aml_arg(0), aml_int(21)), >>> + aml_lless_equal(aml_arg(0), aml_int(22)), >>> + NULL >>> + ), >>> + NULL >>> + ) >>> + ); >>> + { >>> + aml_append(ifctx, aml_return(aml_int(1))); >>> + } >>> + aml_append(method, ifctx); >>> + >>> + aml_append(method, aml_return(aml_int(0))); >>> + } >>> + } else { >>> + method = aml_method("CKOP", 1, AML_NOTSERIALIZED); >>> + { >>> + ifctx = aml_if( >>> + aml_equal(aml_arg(0), aml_int(0)) >>> + ); >>> + { >>> + aml_append(ifctx, aml_return(aml_int(1))); >>> + } >>> + aml_append(method, ifctx); >>> + >>> + aml_append(method, aml_return(aml_int(0))); >>> + } >>> + } >>> + aml_append(dev, method); >>> + >>> + method = aml_method("_DSM", 4, AML_SERIALIZED); >>> + { >>> + uint8_t zerobyte[1] = { 0 }; >>> + >>> + ifctx = aml_if( >>> + aml_equal(aml_arg(0), >>> + >>> aml_touuid("3DDDFAA6-361B-4EB4-A424-8D10089D1653")) >>> + ); >>> + { >>> + aml_append(ifctx, >>> + aml_store(aml_to_integer(aml_arg(2)), >>> aml_local(0))); >>> + >>> + /* standard DSM query function */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(0))); >>> + { >>> + uint8_t byte_list[2] = { 0xff, 0x01 }; >>> + aml_append(ifctx2, aml_return(aml_buffer(2, byte_list))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* interface version: 1.2 */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(1))); >>> + { >>> + aml_append(ifctx2, aml_return(aml_string("1.2"))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* submit TPM operation */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(2))); >>> + { >>> + aml_append(ifctx2, >>> + aml_store(aml_derefof(aml_index(aml_arg(3), >>> + aml_int(0))), >>> + aml_local(0))); >>> + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); >>> + { >>> + aml_append(ifctx3, >>> + aml_return(aml_call2("WRAM", >>> + aml_local(0), >>> + aml_int(0)))); >>> + } >>> + aml_append(ifctx2, ifctx3); >>> + aml_append(ifctx2, aml_return(aml_int(1))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* get pending TPM operation */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(3))); >>> + { >>> + pak = aml_package(2); >>> + aml_append(pak, aml_int(0)); >>> + aml_append(pak, aml_name("PPRQ")); >>> + aml_append(ifctx2, aml_return(pak)); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* get platform-specific action to transition to pre-OS env. >>> */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(4))); >>> + { >>> + /* 2 = reboot */ >>> + aml_append(ifctx2, aml_return(aml_int(2))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* get TPM operation response */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(5))); >>> + { >>> + pak = aml_package(3); >>> + >>> + aml_append(pak, aml_name("FAIL")); >>> + aml_append(pak, aml_name("LPPR")); >>> + aml_append(pak, aml_name("PPRP")); >>> + >>> + aml_append(ifctx2, aml_return(pak)); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* submit preferred user language */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(6))); >>> + { >>> + /* 3 = not implemented */ >>> + aml_append(ifctx2, aml_return(aml_int(3))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* submit TPM operation v2 */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(7))); >>> + { >>> + aml_append(ifctx2, >>> + aml_store(aml_derefof(aml_index(aml_arg(3), >>> + aml_int(0))), >>> + aml_local(0))); >>> + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); >>> + { >>> + aml_append(ifctx3, >>> + aml_store(aml_call2("WRAM", >>> + aml_local(0), >>> + aml_int(0)), >>> + aml_local(1))); >>> + aml_append(ifctx3, aml_return(aml_local(1))); >>> + } >>> + aml_append(ifctx2, ifctx3); >>> + /* 1 = requested operation not implemented */ >>> + aml_append(ifctx2, aml_return(aml_int(1))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* get user confirmation status for operation */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(8))); >>> + { >>> + aml_append(ifctx2, >>> + aml_store(aml_derefof(aml_index(aml_arg(3), >>> + aml_int(0))), >>> + aml_local(0))); >>> + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); >>> + { >>> + /* 4 = Allowed and physically present user not >>> required */ >>> + aml_append(ifctx3, aml_return(aml_int(4))); >>> + } >>> + aml_append(ifctx2, ifctx3); >>> + /* 0 = requested operation not implemented */ >>> + aml_append(ifctx2, aml_return(aml_int(0))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + aml_append(ifctx, aml_return(aml_buffer(1, zerobyte))); >>> + } >>> + aml_append(method, ifctx); >>> + } >>> + aml_append(dev, method); >>> +} >>> + >>> +static void >>> build_dsdt(GArray *table_data, BIOSLinker *linker, >>> AcpiPmInfo *pm, AcpiMiscInfo *misc, >>> Range *pci_hole, Range *pci_hole64, MachineState *machine) >>> @@ -2218,6 +2444,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, >>> */ >>> /* aml_append(crs, aml_irq_no_flags(TPM_TIS_IRQ)); */ >>> aml_append(dev, aml_name_decl("_CRS", crs)); >>> + build_tpm_ppi(dev, misc->tpm_version); >>> aml_append(scope, dev); >>> } >>> >>> diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h >>> index d9b7452..23f5da1 100644 >>> --- a/include/hw/acpi/tpm.h >>> +++ b/include/hw/acpi/tpm.h >>> @@ -37,4 +37,19 @@ >>> #define TPM_PPI_ADDR_SIZE 0x100 >>> #define TPM_PPI_ADDR_BASE 0xffff0000 >>> >>> +struct tpm_ppi { >>> + uint8_t ppin; /* set by BIOS; currently initialization >>> flag */ >>> + uint32_t ppip; /* set by ACPI; not used */ >>> + uint32_t pprp; /* response from TPM; set by BIOS */ >>> + uint32_t pprq; /* opcode; set by ACPI */ >>> + uint32_t pprm; /* parameter for opcode; set by ACPI */ >>> + uint32_t lppr; /* last opcode; set by BIOS */ >>> + uint32_t fret; /* set by ACPI; not used*/ >>> + uint32_t res1; /* reserved */ >>> + uint32_t res2[4]; /* reserved */ >>> + uint32_t fail; /* set by BIOS (0 = success) */ >>> +} QEMU_PACKED; >>> + >>> +#define TPM_PPI_STRUCT_SIZE sizeof(struct tpm_ppi) >>> + >>> #endif /* HW_ACPI_TPM_H */ >> >> >> > otherwise, patch looks good. > ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [RFC PATCH 3/3] acpi: Build TPM Physical Presence interface 2018-01-12 16:07 ` Marc-André Lureau 2018-01-12 17:00 ` Stefan Berger @ 2018-01-12 20:16 ` Stefan Berger 1 sibling, 0 replies; 16+ messages in thread From: Stefan Berger @ 2018-01-12 20:16 UTC (permalink / raw) To: Marc-André Lureau Cc: QEMU, kevin, Michael S. Tsirkin, Laszlo Ersek, Igor Mammedov On 01/12/2018 11:07 AM, Marc-André Lureau wrote: > Hi > > On Wed, Jan 10, 2018 at 7:49 PM, Stefan Berger > <stefanb@linux.vnet.ibm.com> wrote: >> On 01/10/2018 01:35 PM, Stefan Berger wrote: >>> The TPM Physical Presence interface consists of an ACPI part, a shared >>> memory part, and code in the firmware. Users can send messages to the >>> firmware by writing a code into the shared memory through invoking the >>> ACPI code. When a reboot happens, the firmware looks for the code and >>> acts on it by sending sequences of commands to the TPM. >>> >>> This patch adds the ACPI code. It is similar to the one in EDK2 but >>> doesn't >>> assume that SMIs are necessary to use. Besides that it tests the code >>> entered by the user and checks whether it is supported. The range of codes >>> supported matches the range of codes supported in SeaBIOS. It uses the >>> same >>> datastructure for the shared memory as EDK2 does so that EDK2 and SeaBIOS >>> could both make use of the shared memory. >>> >>> The underlying TCG specification is accessible from the following page. >>> >>> >>> https://trustedcomputinggroup.org/tcg-physical-presence-interface-specification/ >>> >>> This patch implements version 1.20. >> >> The below ACPI code is partly a translation to C from a previous posted >> patch: >> >> https://lists.gnu.org/archive/html/qemu-devel/2015-05/msg05353.html >> >> > And fwiw, this is the acpi dump disassembled: > > Device (ISA.TPM) > { > Name (_HID, EisaId ("PNP0C31")) // _HID: Hardware ID > Name (_STA, 0x0F) // _STA: Status > Name (_CRS, ResourceTemplate () // _CRS: Current > Resource Settings > { > Memory32Fixed (ReadWrite, > 0xFED40000, // Address Base > 0x00005000, // Address Length > ) > }) > OperationRegion (TPPI, SystemMemory, 0xFFFF0000, 0x31) > Field (TPPI, AnyAcc, NoLock, Preserve) > { > PPIN, 8, > PPIP, 32, > PPRP, 32, > PPRQ, 32, > PPRM, 32, > LPPR, 32, > FRET, 32, > RES1, 8, > RES2, 128, > FAIL, 32 > } > > Method (WRAM, 2, Serialized) > { > PPRQ = Arg0 > PPRM = Arg1 > Return (Zero) > } > > Method (CKOP, 1, NotSerialized) > { > If ((Arg0 == Zero)) > { > Return (One) > } > > Return (Zero) > } > > Method (_DSM, 4, Serialized) // _DSM: Device-Specific Method > { > If ((Arg0 == ToUUID > ("3dddfaa6-361b-4eb4-a424-8d10089d1653") /* Physical Presence > Interface */)) > { > Local0 = ToInteger (Arg2) > If ((Local0 == Zero)) > { > Return (Buffer (0x02) > { > 0xFF, 0x01 > // .. > }) > } > > If ((Local0 == One)) > { > Return ("1.2") > } > > If ((Local0 == 0x02)) > { > Local0 = DerefOf (Arg3 [Zero]) > If (CKOP (Local0)) > { > Return (WRAM (Local0, Zero)) > } > > Return (One) > } > > If ((Local0 == 0x03)) > { > Return (Package (0x02) > { > Zero, > PPRQ > }) > } > > If ((Local0 == 0x04)) > { > Return (0x02) > } > > If ((Local0 == 0x05)) > { > Return (Package (0x03) > { > FAIL, > LPPR, > PPRP > }) > } > > If ((Local0 == 0x06)) > { > Return (0x03) > } > > If ((Local0 == 0x07)) > { > Local0 = DerefOf (Arg3 [Zero]) > If (CKOP (Local0)) > { > Local1 = WRAM (Local0, Zero) > Return (Local1) > } > > Return (One) > } > > If ((Local0 == 0x08)) > { > Local0 = DerefOf (Arg3 [Zero]) > If (CKOP (Local0)) > { > Return (0x04) > } > > Return (Zero) > } > > Return (Buffer (One) > { > 0x00 > // . > }) > } > } > > Linux PPI driver seems to be happy about it, looking at > /sys/devices/pnp0/00\:06/tpm/tpm0/ppi/. > > I haven't done further testing. Is there anything using this on Linux? > tpm2-tools doesn't seem to use it. I suppose I should be able to write > something to /sys/devices/pnp0/00\:06/tpm/tpm0/ppi/request. > > Any help appreciated :) > >> Stefan >> >>> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> >>> --- >>> hw/i386/acpi-build.c | 227 >>> ++++++++++++++++++++++++++++++++++++++++++++++++++ >>> include/hw/acpi/tpm.h | 15 ++++ >>> 2 files changed, 242 insertions(+) >>> >>> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c >>> index 18b939e..e3905a3 100644 >>> --- a/hw/i386/acpi-build.c >>> +++ b/hw/i386/acpi-build.c >>> @@ -42,6 +42,7 @@ >>> #include "hw/acpi/memory_hotplug.h" >>> #include "sysemu/tpm.h" >>> #include "hw/acpi/tpm.h" >>> +#include "hw/tpm/tpm_ppi.h" >>> #include "hw/acpi/vmgenid.h" >>> #include "sysemu/tpm_backend.h" >>> #include "hw/timer/mc146818rtc_regs.h" >>> @@ -1860,6 +1861,231 @@ static Aml *build_q35_osc_method(void) >>> } >>> >>> static void >>> +build_tpm_ppi(Aml *dev, TPMVersion tpm_version) >>> +{ >>> + Aml *method, *field, *ifctx, *ifctx2, *ifctx3, *pak; >>> + >>> + aml_append(dev, >>> + aml_operation_region("TPPI", AML_SYSTEM_MEMORY, >>> + aml_int(TPM_PPI_ADDR_BASE), >>> + TPM_PPI_STRUCT_SIZE)); >>> + >>> + field = aml_field("TPPI", AML_ANY_ACC, AML_NOLOCK, AML_PRESERVE); >>> + aml_append(field, aml_named_field("PPIN", >>> + sizeof(uint8_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("PPIP", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("PPRP", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("PPRQ", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("PPRM", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("LPPR", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("FRET", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("RES1", >>> + sizeof(uint8_t) * BITS_PER_BYTE)); >>> + aml_append(field, aml_named_field("RES2", >>> + sizeof(uint32_t) * BITS_PER_BYTE * 4)); >>> + aml_append(field, aml_named_field("FAIL", >>> + sizeof(uint32_t) * BITS_PER_BYTE)); >>> + aml_append(dev, field); >>> + >>> + /* >>> + * Write the given operations code into 'PPRQ'. >>> + */ >>> + method = aml_method("WRAM", 2, AML_SERIALIZED); >>> + { >>> + aml_append(method, aml_store(aml_arg(0), aml_name("PPRQ"))); >>> + aml_append(method, aml_store(aml_arg(1), aml_name("PPRM"))); >>> + /* 0 = Success */ >>> + aml_append(method, aml_return(aml_int(0))); >>> + } >>> + aml_append(dev, method); >>> + >>> + /* >>> + * CKOP: Check whether the opcode is valid >>> + */ >>> + if (tpm_version == TPM_VERSION_1_2) { >>> + method = aml_method("CKOP", 1, AML_NOTSERIALIZED); >>> + { >>> + ifctx = aml_if( >>> + aml_or( >>> + aml_or( >>> + aml_and( >>> + aml_lgreater_equal(aml_arg(0), aml_int(0)), >>> + aml_lless_equal(aml_arg(0), aml_int(11)), >>> + NULL >>> + ), >>> + aml_equal(aml_arg(0), aml_int(14)), >>> + NULL >>> + ), >>> + aml_and( >>> + aml_lgreater_equal(aml_arg(0), aml_int(21)), >>> + aml_lless_equal(aml_arg(0), aml_int(22)), >>> + NULL >>> + ), >>> + NULL >>> + ) >>> + ); >>> + { >>> + aml_append(ifctx, aml_return(aml_int(1))); >>> + } >>> + aml_append(method, ifctx); >>> + >>> + aml_append(method, aml_return(aml_int(0))); >>> + } >>> + } else { >>> + method = aml_method("CKOP", 1, AML_NOTSERIALIZED); >>> + { >>> + ifctx = aml_if( >>> + aml_equal(aml_arg(0), aml_int(0)) >>> + ); >>> + { >>> + aml_append(ifctx, aml_return(aml_int(1))); >>> + } >>> + aml_append(method, ifctx); >>> + >>> + aml_append(method, aml_return(aml_int(0))); >>> + } >>> + } >>> + aml_append(dev, method); >>> + CKOP checks whether the firmware implements a certain code. Function 8 returns a number 0 - 4 for a certain code, 0 meaning 'Not implemented'. Maybe the firmware should fill an array and put the numbers in that function 8 expects and CKOP can use that also to see whether functions are supported. That may 'loosen' the ACPI a bit from the firmware. Comments? Is that better than hard coding in the ACPI what the firmware supports? specs: https://trustedcomputinggroup.org/wp-content/uploads/Physical_Presence_Interface_1-20_0-100.pdf >>> + method = aml_method("_DSM", 4, AML_SERIALIZED); >>> + { >>> + uint8_t zerobyte[1] = { 0 }; >>> + >>> + ifctx = aml_if( >>> + aml_equal(aml_arg(0), >>> + >>> aml_touuid("3DDDFAA6-361B-4EB4-A424-8D10089D1653")) >>> + ); >>> + { >>> + aml_append(ifctx, >>> + aml_store(aml_to_integer(aml_arg(2)), >>> aml_local(0))); >>> + >>> + /* standard DSM query function */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(0))); >>> + { >>> + uint8_t byte_list[2] = { 0xff, 0x01 }; >>> + aml_append(ifctx2, aml_return(aml_buffer(2, byte_list))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* interface version: 1.2 */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(1))); >>> + { >>> + aml_append(ifctx2, aml_return(aml_string("1.2"))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* submit TPM operation */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(2))); >>> + { >>> + aml_append(ifctx2, >>> + aml_store(aml_derefof(aml_index(aml_arg(3), >>> + aml_int(0))), >>> + aml_local(0))); >>> + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); >>> + { >>> + aml_append(ifctx3, >>> + aml_return(aml_call2("WRAM", >>> + aml_local(0), >>> + aml_int(0)))); >>> + } >>> + aml_append(ifctx2, ifctx3); >>> + aml_append(ifctx2, aml_return(aml_int(1))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* get pending TPM operation */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(3))); >>> + { >>> + pak = aml_package(2); >>> + aml_append(pak, aml_int(0)); >>> + aml_append(pak, aml_name("PPRQ")); >>> + aml_append(ifctx2, aml_return(pak)); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* get platform-specific action to transition to pre-OS env. >>> */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(4))); >>> + { >>> + /* 2 = reboot */ >>> + aml_append(ifctx2, aml_return(aml_int(2))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* get TPM operation response */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(5))); >>> + { >>> + pak = aml_package(3); >>> + >>> + aml_append(pak, aml_name("FAIL")); >>> + aml_append(pak, aml_name("LPPR")); >>> + aml_append(pak, aml_name("PPRP")); >>> + >>> + aml_append(ifctx2, aml_return(pak)); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* submit preferred user language */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(6))); >>> + { >>> + /* 3 = not implemented */ >>> + aml_append(ifctx2, aml_return(aml_int(3))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* submit TPM operation v2 */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(7))); >>> + { >>> + aml_append(ifctx2, >>> + aml_store(aml_derefof(aml_index(aml_arg(3), >>> + aml_int(0))), >>> + aml_local(0))); >>> + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); >>> + { >>> + aml_append(ifctx3, >>> + aml_store(aml_call2("WRAM", >>> + aml_local(0), >>> + aml_int(0)), >>> + aml_local(1))); >>> + aml_append(ifctx3, aml_return(aml_local(1))); >>> + } >>> + aml_append(ifctx2, ifctx3); >>> + /* 1 = requested operation not implemented */ >>> + aml_append(ifctx2, aml_return(aml_int(1))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + /* get user confirmation status for operation */ >>> + ifctx2 = aml_if(aml_equal(aml_local(0), aml_int(8))); >>> + { >>> + aml_append(ifctx2, >>> + aml_store(aml_derefof(aml_index(aml_arg(3), >>> + aml_int(0))), >>> + aml_local(0))); >>> + ifctx3 = aml_if(aml_call1("CKOP", aml_local(0))); >>> + { >>> + /* 4 = Allowed and physically present user not >>> required */ >>> + aml_append(ifctx3, aml_return(aml_int(4))); >>> + } >>> + aml_append(ifctx2, ifctx3); >>> + /* 0 = requested operation not implemented */ >>> + aml_append(ifctx2, aml_return(aml_int(0))); >>> + } >>> + aml_append(ifctx, ifctx2); >>> + >>> + aml_append(ifctx, aml_return(aml_buffer(1, zerobyte))); >>> + } >>> + aml_append(method, ifctx); >>> + } >>> + aml_append(dev, method); >>> +} >>> + >>> +static void >>> build_dsdt(GArray *table_data, BIOSLinker *linker, >>> AcpiPmInfo *pm, AcpiMiscInfo *misc, >>> Range *pci_hole, Range *pci_hole64, MachineState *machine) >>> @@ -2218,6 +2444,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, >>> */ >>> /* aml_append(crs, aml_irq_no_flags(TPM_TIS_IRQ)); */ >>> aml_append(dev, aml_name_decl("_CRS", crs)); >>> + build_tpm_ppi(dev, misc->tpm_version); >>> aml_append(scope, dev); >>> } >>> >>> diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h >>> index d9b7452..23f5da1 100644 >>> --- a/include/hw/acpi/tpm.h >>> +++ b/include/hw/acpi/tpm.h >>> @@ -37,4 +37,19 @@ >>> #define TPM_PPI_ADDR_SIZE 0x100 >>> #define TPM_PPI_ADDR_BASE 0xffff0000 >>> >>> +struct tpm_ppi { >>> + uint8_t ppin; /* set by BIOS; currently initialization >>> flag */ >>> + uint32_t ppip; /* set by ACPI; not used */ >>> + uint32_t pprp; /* response from TPM; set by BIOS */ >>> + uint32_t pprq; /* opcode; set by ACPI */ >>> + uint32_t pprm; /* parameter for opcode; set by ACPI */ >>> + uint32_t lppr; /* last opcode; set by BIOS */ >>> + uint32_t fret; /* set by ACPI; not used*/ >>> + uint32_t res1; /* reserved */ >>> + uint32_t res2[4]; /* reserved */ >>> + uint32_t fail; /* set by BIOS (0 = success) */ >>> +} QEMU_PACKED; >>> + >>> +#define TPM_PPI_STRUCT_SIZE sizeof(struct tpm_ppi) >>> + >>> #endif /* HW_ACPI_TPM_H */ >> >> >> > otherwise, patch looks good. > ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2018-01-15 14:49 UTC | newest] Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-01-10 18:35 [Qemu-devel] [RFC PATCH 0/3] Implement Pysical Presence Interface for TPM 1.2 and 2 Stefan Berger 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 1/3] tpm: Implement virtual memory device for TPM PPI Stefan Berger 2018-01-12 14:55 ` Marc-André Lureau 2018-01-12 16:29 ` Eric Blake 2018-01-12 17:24 ` Stefan Berger 2018-01-12 18:23 ` Stefan Berger 2018-01-15 14:49 ` Stefan Berger 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 2/3] acpi: implement aml_lless_equal Stefan Berger 2018-01-12 15:17 ` Marc-André Lureau 2018-01-12 19:42 ` Stefan Berger 2018-01-15 14:31 ` Igor Mammedov 2018-01-10 18:35 ` [Qemu-devel] [RFC PATCH 3/3] acpi: Build TPM Physical Presence interface Stefan Berger 2018-01-10 18:49 ` Stefan Berger 2018-01-12 16:07 ` Marc-André Lureau 2018-01-12 17:00 ` Stefan Berger 2018-01-12 20:16 ` Stefan Berger
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.