TPM TIS SPI Support
v7 cover TPM TIS SPI Support
*** BLURB HERE ***
Version 7 summary:
- tpm/tpm_tis_spi: Support TPM for SPI
- Reduce SPI wait states to improve performace. Although the real SPI buses have four wait states to accommodate the timing of various slave devices, there is no need to emulate that for this behavior model.
Version 6 summary:
1/3 tpm/tpm_tis_spi: Support TPM for SPI
- amend commit description
- amend hw/tpm/tpm_tis_spi.c prolog to reflect the generic nature of the implementation
- remove irrelevant define of IBM_PONQ
- correct the function names to comply with the convention of beginning with tpm_tis_spi_xxxx()
3/3 tests/qtest/tpm: add unit test to tis-spi
- changed sleep(0.x) to g_usleep(G_USEC_PER_SEC / y) and adjust the timeouts
Version 5 summary:
1/3 tpm/tpm_tis_spi: Support TPM for SPI
- removed DEFINE_PROP_UINT32("irq", TPMStateSPI, tpm_state.irq_num, 0) from tpm_tis_spi_properties
- In tpm.rst document, under section 'The QEMU TPM emulator device', moved the 'PowerNV machine' section to immeidately below 'pSeriese machine'.
3/3 tests/qtest/tpm: add unit test to tis-spi
- modified tpm_reg_readl() by
- removing the special case for TPM_TIS_REG_DID_VID.
- however, I did not use the more efficient 32bit access due to the SPI bus master implementation. The 16bit register still require special treatment with the SPI RWX bits.
- correcting tpm_reg_readb() with uint16_t reg
- tpm_set_verify_loc() added checking for TPM_TIS_CAPABILITIES_SUPPORTED2_0
- test_spi_tpm_transmit_test() added
- TPM_TIS_STS_TPM_FAMILY2_0 check in status register
- TPM responses verification
- fixed the PowerNV stdout msg from running qtest-ppc64/tpm-tis-spi-pnv-test
Revision 4 summary:
- fold v3 commit 4/5 into 1/5
- fold v3 commit 5/5 into 3/5
Revision 3 summary:
device support:
- moved variable tis_addr from TPMStateSPI struct to local
- added the VM suspend/resume support:
- added vmstate_tpm_tis_spi declaration
- added tpm_tis_spi_pre_save() function
- fixed trace formatting string
qtest:
- removed the function prototypes declaration
- fixed code format to comply with convention
- changed function names and variable names to be the same as the tpm-tis-i2c test.
- change hard coded numbers to #define's with meaningful names that are identifiable with spec documentation
Version 2 summary,
addressed the following review comments:
- break up patch into 3 separate commits;
- add more details in the commit logs;
- I added links to the TCG TPM standard documents as this device model communicates to the TPM device (hw / swtpm) via tpm_tis_commom.c which is standard compliant;
- the TPM SPI model implementation in itself is not platform specific. However, the SPI interface is via the PowerNV SPI bus master, thus it is only supported on the PowerNV platform
- change all qemu_log() calls to trace events;
- move static global variables to the TPMStateSPI struct;
- fixed code formatting (verified by scripts/checkpatch.pl);
- per requests, make the code more readable by using self- explanatory #defines and adding comments;
- added some documentation support (tpm.rst);
- beefed up the unit test exercising major supported locality functionality
dan tan (3):
tpm/tpm_tis_spi: Support TPM for SPI (Serial Peripheral Interface) tpm/tpm_tis_spi: activation for the PowerNV machines tests/qtest/tpm: add unit test to tis-spi
docs/specs/tpm.rst | 15 + include/sysemu/tpm.h | 3 + hw/tpm/tpm_tis_spi.c | 359 +++++++++++++++ tests/qtest/tpm-tis-spi-pnv-test.c | 712 +++++++++++++++++++++++++++++ hw/ppc/Kconfig | 1 + hw/tpm/Kconfig | 6 + hw/tpm/meson.build | 1 + hw/tpm/trace-events | 7 + tests/qtest/meson.build | 2 + 9 files changed, 1106 insertions(+) create mode 100644 hw/tpm/tpm_tis_spi.c create mode 100644 tests/qtest/tpm-tis-spi-pnv-test.c
Signature · 1 line
2.39.5
PATCH v7 1/1 tpm/tpm_tis_spi: Support TPM for SPI (Serial Peripheral Interface)
Implement support for TPM via SPI interface. The SPI bus master is provided by PowerNV SPI device which is an SSI peripheral. It can uses the tpm_emulator driver backend with the external swtpm.
---
v3:
- moved variable tis_addr from TPMStateSPI struct to local
- added the VM suspend/resume support:
- added vmstate_tpm_tis_spi declaration
- added tpm_tis_spi_pre_save() function
- fixed trace formatting string
v4:
- git commit amend only
v5:
- removed DEFINE_PROP_UINT32("irq", TPMStateSPI, tpm_state.irq_num, 0) from tpm_tis_spi_properties
- In tpm.rst document, under section 'The QEMU TPM emulator device', moved the 'PowerNV machine' section to immeidately below 'pSeriese machine'.
v6:
- amend commit description
- amend hw/tpm/tpm_tis_spi.c prolog to reflect the generic nature of the implementation
- remove irrelevant define of IBM_PONQ
- correct the function names to comply with the convention of beginning with tpm_tis_spi_xxxx()
v7:
- Reduce SPI wait states to improve performace. Although the real SPI buses have four wait states to accommodate the timing of various slave devices, there is no need to emulate that for this behavior model.
--- docs/specs/tpm.rst | 15 ++ include/sysemu/tpm.h | 3 + hw/tpm/tpm_tis_spi.c | 359 +++++++++++++++++++++++++++++++++++++++++++ hw/tpm/Kconfig | 6 + hw/tpm/meson.build | 1 + hw/tpm/trace-events | 7 + 6 files changed, 391 insertions(+) create mode 100644 hw/tpm/tpm_tis_spi.c
docs/specs/tpm.rst +15 -0
@@ -24,6 +24,7 @@ QEMU files related to TPM TIS interface: - ``hw/tpm/tpm_tis_isa.c`` - ``hw/tpm/tpm_tis_sysbus.c`` - ``hw/tpm/tpm_tis_i2c.c`` + - ``hw/tpm/tpm_tis_spi.c`` - ``hw/tpm/tpm_tis.h`` Both an ISA device and a sysbus device are available. The former is
@@ -33,6 +34,9 @@ Arm virt machine. An I2C device support is also provided which can be instantiated in the Arm based emulation machines. This device only supports the TPM 2 protocol. +A Serial Peripheral Interface (SPI) device support has been added to the +PowerNV emulation machines. This device only supports the TPM 2 protocol. + CRB interface -------------
@@ -339,6 +343,17 @@ In case a pSeries machine is emulated, use the following command line: -device virtio-blk-pci,bus=pci.0,addr=0x3,drive=drive-virtio-disk0,id=virtio-disk0 \ -drive file=test.img,format=raw,if=none,id=drive-virtio-disk0 +In case a PowerNV machine is emulated and you want to use a TPM device +attached to SPI bus, use the following command line (SPI bus master is +provided by PowerNV SPI device): + +.. code-block:: console + + qemu-system-ppc64 -m 2G -machine powernv10 -nographic \ + -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ + -tpmdev emulator,id=tpm0,chardev=chrtpm \ + -device tpm-tis-spi,tpmdev=tpm0,bus=pnv-spi-bus.4 + In case an Arm virt machine is emulated, use the following command line: .. code-block:: console
include/sysemu/tpm.h +3 -0
@@ -49,6 +49,7 @@ struct TPMIfClass {#define TYPE_TPM_CRB "tpm-crb"#define TYPE_TPM_SPAPR "tpm-spapr"#define TYPE_TPM_TIS_I2C "tpm-tis-i2c" +#define TYPE_TPM_TIS_SPI "tpm-tis-spi"#define TPM_IS_TIS_ISA (chr) \ object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA)
@@ -60,6 +61,8 @@ struct TPMIfClass { object_dynamic_cast(OBJECT(chr), TYPE_TPM_SPAPR)#define TPM_IS_TIS_I2C (chr) \ object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_I2C) +#define TPM_IS_TIS_SPI (chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SPI)/* returns NULL unless there is exactly one TPM device */ static inline TPMIf *tpm_find (void )
hw/tpm/tpm_tis_spi.c new file +359 -0
359 lines not on this page · raw message
hw/tpm/Kconfig +6 -0
@@ -5,6 +5,12 @@ config TPM_TIS_I2C select I2C select TPM_TIS +config TPM_TIS_SPI + bool + depends on TPM + select TPM_BACKEND + select TPM_TIS + config TPM_TIS_ISA bool depends on TPM && ISA_BUS
hw/tpm/meson.build +1 -0
@@ -2,6 +2,7 @@ system_ss.add(when: 'CONFIG_TPM_TIS', if_true: files('tpm_tis_common.c')) system_ss.add(when: 'CONFIG_TPM_TIS_ISA', if_true: files('tpm_tis_isa.c')) system_ss.add(when: 'CONFIG_TPM_TIS_SYSBUS', if_true: files('tpm_tis_sysbus.c')) system_ss.add(when: 'CONFIG_TPM_TIS_I2C', if_true: files('tpm_tis_i2c.c')) +system_ss.add(when: 'CONFIG_TPM_TIS_SPI', if_true: files('tpm_tis_spi.c')) system_ss.add(when: 'CONFIG_TPM_CRB', if_true: files('tpm_crb.c')) system_ss.add(when: 'CONFIG_TPM_TIS', if_true: files('tpm_ppi.c')) system_ss.add(when: 'CONFIG_TPM_CRB', if_true: files('tpm_ppi.c'))
hw/tpm/trace-events +7 -0
@@ -42,3 +42,10 @@ tpm_tis_i2c_recv(uint8_t data) "TPM I2C read: 0x%X" tpm_tis_i2c_send(uint8_t data) "TPM I2C write: 0x%X" tpm_tis_i2c_event(const char *event) "TPM I2C event: %s" tpm_tis_i2c_send_reg(const char *name, int reg) "TPM I2C write register: %s(0x%X)" + +# tpm_tis_spi.c +tpm_tis_spi_write(uint32_t addr, uint8_t val) "TPM SPI write - addr:0x%08X 0x%02x" +tpm_tis_spi_read(uint32_t addr, uint8_t val) "TPM SPI read - addr:0x%08X 0x%02x" +tpm_tis_spi_transfer_event(const char *event) "TPM SPI XFER event: %s" +tpm_tis_spi_transfer_data(const char *name, uint8_t val) "TPM SPI XFER: %s = 0x%02x" +tpm_tis_spi_transfer_addr(const char *name, uint32_t addr) "TPM SPI XFER: %s = 0x%08x"
Signature · 1 line
2.39.5