1711b20b4SStefan Berger /* 2711b20b4SStefan Berger * tpm.h - TPM ACPI definitions 3711b20b4SStefan Berger * 4711b20b4SStefan Berger * Copyright (C) 2014 IBM Corporation 5711b20b4SStefan Berger * 6711b20b4SStefan Berger * Authors: 7711b20b4SStefan Berger * Stefan Berger <stefanb@us.ibm.com> 8711b20b4SStefan Berger * 9711b20b4SStefan Berger * This work is licensed under the terms of the GNU GPL, version 2 or later. 10711b20b4SStefan Berger * See the COPYING file in the top-level directory. 11711b20b4SStefan Berger * 12711b20b4SStefan Berger * Implementation of the TIS interface according to specs found at 13711b20b4SStefan Berger * http://www.trustedcomputinggroup.org 14711b20b4SStefan Berger * 15711b20b4SStefan Berger */ 16711b20b4SStefan Berger #ifndef HW_ACPI_TPM_H 17711b20b4SStefan Berger #define HW_ACPI_TPM_H 18711b20b4SStefan Berger 193d779b93SPhilippe Mathieu-Daudé #include "qemu/units.h" 204ab6cb4cSMarc-André Lureau #include "hw/registerfields.h" 21ac6dd31eSStefan Berger #include "hw/acpi/aml-build.h" 22ac6dd31eSStefan Berger #include "sysemu/tpm.h" 234ab6cb4cSMarc-André Lureau 24295f7dcbSStefan Berger #ifdef CONFIG_TPM 25295f7dcbSStefan Berger 26711b20b4SStefan Berger #define TPM_TIS_ADDR_BASE 0xFED40000 27711b20b4SStefan Berger #define TPM_TIS_ADDR_SIZE 0x5000 28711b20b4SStefan Berger 29711b20b4SStefan Berger #define TPM_TIS_IRQ 5 30711b20b4SStefan Berger 31adb0e917SStefan Berger #define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ 32adb0e917SStefan Berger #define TPM_TIS_LOCALITY_SHIFT 12 33adb0e917SStefan Berger 34adb0e917SStefan Berger /* tis registers */ 35adb0e917SStefan Berger #define TPM_TIS_REG_ACCESS 0x00 36adb0e917SStefan Berger #define TPM_TIS_REG_INT_ENABLE 0x08 37adb0e917SStefan Berger #define TPM_TIS_REG_INT_VECTOR 0x0c 38adb0e917SStefan Berger #define TPM_TIS_REG_INT_STATUS 0x10 39adb0e917SStefan Berger #define TPM_TIS_REG_INTF_CAPABILITY 0x14 40adb0e917SStefan Berger #define TPM_TIS_REG_STS 0x18 41adb0e917SStefan Berger #define TPM_TIS_REG_DATA_FIFO 0x24 42adb0e917SStefan Berger #define TPM_TIS_REG_INTERFACE_ID 0x30 43adb0e917SStefan Berger #define TPM_TIS_REG_DATA_XFIFO 0x80 44adb0e917SStefan Berger #define TPM_TIS_REG_DATA_XFIFO_END 0xbc 45adb0e917SStefan Berger #define TPM_TIS_REG_DID_VID 0xf00 46adb0e917SStefan Berger #define TPM_TIS_REG_RID 0xf04 47adb0e917SStefan Berger 48adb0e917SStefan Berger /* vendor-specific registers */ 49adb0e917SStefan Berger #define TPM_TIS_REG_DEBUG 0xf90 50adb0e917SStefan Berger 51adb0e917SStefan Berger #define TPM_TIS_STS_TPM_FAMILY_MASK (0x3 << 26)/* TPM 2.0 */ 52adb0e917SStefan Berger #define TPM_TIS_STS_TPM_FAMILY1_2 (0 << 26) /* TPM 2.0 */ 53adb0e917SStefan Berger #define TPM_TIS_STS_TPM_FAMILY2_0 (1 << 26) /* TPM 2.0 */ 54adb0e917SStefan Berger #define TPM_TIS_STS_RESET_ESTABLISHMENT_BIT (1 << 25) /* TPM 2.0 */ 55adb0e917SStefan Berger #define TPM_TIS_STS_COMMAND_CANCEL (1 << 24) /* TPM 2.0 */ 56adb0e917SStefan Berger 57adb0e917SStefan Berger #define TPM_TIS_STS_VALID (1 << 7) 58adb0e917SStefan Berger #define TPM_TIS_STS_COMMAND_READY (1 << 6) 59adb0e917SStefan Berger #define TPM_TIS_STS_TPM_GO (1 << 5) 60adb0e917SStefan Berger #define TPM_TIS_STS_DATA_AVAILABLE (1 << 4) 61adb0e917SStefan Berger #define TPM_TIS_STS_EXPECT (1 << 3) 62adb0e917SStefan Berger #define TPM_TIS_STS_SELFTEST_DONE (1 << 2) 63adb0e917SStefan Berger #define TPM_TIS_STS_RESPONSE_RETRY (1 << 1) 64adb0e917SStefan Berger 65adb0e917SStefan Berger #define TPM_TIS_BURST_COUNT_SHIFT 8 66adb0e917SStefan Berger #define TPM_TIS_BURST_COUNT(X) \ 67adb0e917SStefan Berger ((X) << TPM_TIS_BURST_COUNT_SHIFT) 68adb0e917SStefan Berger 69adb0e917SStefan Berger #define TPM_TIS_ACCESS_TPM_REG_VALID_STS (1 << 7) 70adb0e917SStefan Berger #define TPM_TIS_ACCESS_ACTIVE_LOCALITY (1 << 5) 71adb0e917SStefan Berger #define TPM_TIS_ACCESS_BEEN_SEIZED (1 << 4) 72adb0e917SStefan Berger #define TPM_TIS_ACCESS_SEIZE (1 << 3) 73adb0e917SStefan Berger #define TPM_TIS_ACCESS_PENDING_REQUEST (1 << 2) 74adb0e917SStefan Berger #define TPM_TIS_ACCESS_REQUEST_USE (1 << 1) 75adb0e917SStefan Berger #define TPM_TIS_ACCESS_TPM_ESTABLISHMENT (1 << 0) 76adb0e917SStefan Berger 77adb0e917SStefan Berger #define TPM_TIS_INT_ENABLED (1 << 31) 78adb0e917SStefan Berger #define TPM_TIS_INT_DATA_AVAILABLE (1 << 0) 79adb0e917SStefan Berger #define TPM_TIS_INT_STS_VALID (1 << 1) 80adb0e917SStefan Berger #define TPM_TIS_INT_LOCALITY_CHANGED (1 << 2) 81adb0e917SStefan Berger #define TPM_TIS_INT_COMMAND_READY (1 << 7) 82adb0e917SStefan Berger 83adb0e917SStefan Berger #define TPM_TIS_INT_POLARITY_MASK (3 << 3) 84adb0e917SStefan Berger #define TPM_TIS_INT_POLARITY_LOW_LEVEL (1 << 3) 85adb0e917SStefan Berger 86adb0e917SStefan Berger #define TPM_TIS_INTERRUPTS_SUPPORTED (TPM_TIS_INT_LOCALITY_CHANGED | \ 87adb0e917SStefan Berger TPM_TIS_INT_DATA_AVAILABLE | \ 88adb0e917SStefan Berger TPM_TIS_INT_STS_VALID | \ 89adb0e917SStefan Berger TPM_TIS_INT_COMMAND_READY) 90adb0e917SStefan Berger 91adb0e917SStefan Berger #define TPM_TIS_CAP_INTERFACE_VERSION1_3 (2 << 28) 92adb0e917SStefan Berger #define TPM_TIS_CAP_INTERFACE_VERSION1_3_FOR_TPM2_0 (3 << 28) 93adb0e917SStefan Berger #define TPM_TIS_CAP_DATA_TRANSFER_64B (3 << 9) 94adb0e917SStefan Berger #define TPM_TIS_CAP_DATA_TRANSFER_LEGACY (0 << 9) 95adb0e917SStefan Berger #define TPM_TIS_CAP_BURST_COUNT_DYNAMIC (0 << 8) 96*e919515fSNinad Palsule #define TPM_TIS_CAP_BURST_COUNT_STATIC (1 << 8) 97adb0e917SStefan Berger #define TPM_TIS_CAP_INTERRUPT_LOW_LEVEL (1 << 4) /* support is mandatory */ 98adb0e917SStefan Berger #define TPM_TIS_CAPABILITIES_SUPPORTED1_3 \ 99adb0e917SStefan Berger (TPM_TIS_CAP_INTERRUPT_LOW_LEVEL | \ 100adb0e917SStefan Berger TPM_TIS_CAP_BURST_COUNT_DYNAMIC | \ 101adb0e917SStefan Berger TPM_TIS_CAP_DATA_TRANSFER_64B | \ 102adb0e917SStefan Berger TPM_TIS_CAP_INTERFACE_VERSION1_3 | \ 103adb0e917SStefan Berger TPM_TIS_INTERRUPTS_SUPPORTED) 104adb0e917SStefan Berger 105adb0e917SStefan Berger #define TPM_TIS_CAPABILITIES_SUPPORTED2_0 \ 106adb0e917SStefan Berger (TPM_TIS_CAP_INTERRUPT_LOW_LEVEL | \ 107adb0e917SStefan Berger TPM_TIS_CAP_BURST_COUNT_DYNAMIC | \ 108adb0e917SStefan Berger TPM_TIS_CAP_DATA_TRANSFER_64B | \ 109adb0e917SStefan Berger TPM_TIS_CAP_INTERFACE_VERSION1_3_FOR_TPM2_0 | \ 110adb0e917SStefan Berger TPM_TIS_INTERRUPTS_SUPPORTED) 111adb0e917SStefan Berger 112adb0e917SStefan Berger #define TPM_TIS_IFACE_ID_INTERFACE_TIS1_3 (0xf) /* TPM 2.0 */ 113adb0e917SStefan Berger #define TPM_TIS_IFACE_ID_INTERFACE_FIFO (0x0) /* TPM 2.0 */ 114adb0e917SStefan Berger #define TPM_TIS_IFACE_ID_INTERFACE_VER_FIFO (0 << 4) /* TPM 2.0 */ 115adb0e917SStefan Berger #define TPM_TIS_IFACE_ID_CAP_5_LOCALITIES (1 << 8) /* TPM 2.0 */ 116adb0e917SStefan Berger #define TPM_TIS_IFACE_ID_CAP_TIS_SUPPORTED (1 << 13) /* TPM 2.0 */ 117adb0e917SStefan Berger #define TPM_TIS_IFACE_ID_INT_SEL_LOCK (1 << 19) /* TPM 2.0 */ 118adb0e917SStefan Berger 119adb0e917SStefan Berger #define TPM_TIS_IFACE_ID_SUPPORTED_FLAGS1_3 \ 120adb0e917SStefan Berger (TPM_TIS_IFACE_ID_INTERFACE_TIS1_3 | \ 121adb0e917SStefan Berger (~0u << 4)/* all of it is don't care */) 122adb0e917SStefan Berger 123adb0e917SStefan Berger /* if backend was a TPM 2.0: */ 124adb0e917SStefan Berger #define TPM_TIS_IFACE_ID_SUPPORTED_FLAGS2_0 \ 125adb0e917SStefan Berger (TPM_TIS_IFACE_ID_INTERFACE_FIFO | \ 126adb0e917SStefan Berger TPM_TIS_IFACE_ID_INTERFACE_VER_FIFO | \ 127adb0e917SStefan Berger TPM_TIS_IFACE_ID_CAP_5_LOCALITIES | \ 128adb0e917SStefan Berger TPM_TIS_IFACE_ID_CAP_TIS_SUPPORTED) 129adb0e917SStefan Berger 130adb0e917SStefan Berger #define TPM_TIS_TPM_DID 0x0001 131adb0e917SStefan Berger #define TPM_TIS_TPM_VID PCI_VENDOR_ID_IBM 132adb0e917SStefan Berger #define TPM_TIS_TPM_RID 0x0001 133adb0e917SStefan Berger 134adb0e917SStefan Berger #define TPM_TIS_NO_DATA_BYTE 0xff 135adb0e917SStefan Berger 136adb0e917SStefan Berger 1374ab6cb4cSMarc-André Lureau REG32(CRB_LOC_STATE, 0x00) 1384ab6cb4cSMarc-André Lureau FIELD(CRB_LOC_STATE, tpmEstablished, 0, 1) 1394ab6cb4cSMarc-André Lureau FIELD(CRB_LOC_STATE, locAssigned, 1, 1) 1404ab6cb4cSMarc-André Lureau FIELD(CRB_LOC_STATE, activeLocality, 2, 3) 1414ab6cb4cSMarc-André Lureau FIELD(CRB_LOC_STATE, reserved, 5, 2) 1424ab6cb4cSMarc-André Lureau FIELD(CRB_LOC_STATE, tpmRegValidSts, 7, 1) 1434ab6cb4cSMarc-André Lureau REG32(CRB_LOC_CTRL, 0x08) 1444ab6cb4cSMarc-André Lureau REG32(CRB_LOC_STS, 0x0C) 1454ab6cb4cSMarc-André Lureau FIELD(CRB_LOC_STS, Granted, 0, 1) 1464ab6cb4cSMarc-André Lureau FIELD(CRB_LOC_STS, beenSeized, 1, 1) 1474ab6cb4cSMarc-André Lureau REG32(CRB_INTF_ID, 0x30) 1484ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, InterfaceType, 0, 4) 1494ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, InterfaceVersion, 4, 4) 1504ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, CapLocality, 8, 1) 1514ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, CapCRBIdleBypass, 9, 1) 1524ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, Reserved1, 10, 1) 1534ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, CapDataXferSizeSupport, 11, 2) 1544ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, CapFIFO, 13, 1) 1554ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, CapCRB, 14, 1) 1564ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, CapIFRes, 15, 2) 1574ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, InterfaceSelector, 17, 2) 1584ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, IntfSelLock, 19, 1) 1594ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, Reserved2, 20, 4) 1604ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID, RID, 24, 8) 1614ab6cb4cSMarc-André Lureau REG32(CRB_INTF_ID2, 0x34) 1624ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID2, VID, 0, 16) 1634ab6cb4cSMarc-André Lureau FIELD(CRB_INTF_ID2, DID, 16, 16) 1644ab6cb4cSMarc-André Lureau REG32(CRB_CTRL_EXT, 0x38) 1654ab6cb4cSMarc-André Lureau REG32(CRB_CTRL_REQ, 0x40) 1664ab6cb4cSMarc-André Lureau REG32(CRB_CTRL_STS, 0x44) 1674ab6cb4cSMarc-André Lureau FIELD(CRB_CTRL_STS, tpmSts, 0, 1) 1684ab6cb4cSMarc-André Lureau FIELD(CRB_CTRL_STS, tpmIdle, 1, 1) 1694ab6cb4cSMarc-André Lureau REG32(CRB_CTRL_CANCEL, 0x48) 1704ab6cb4cSMarc-André Lureau REG32(CRB_CTRL_START, 0x4C) 1714ab6cb4cSMarc-André Lureau REG32(CRB_INT_ENABLED, 0x50) 1724ab6cb4cSMarc-André Lureau REG32(CRB_INT_STS, 0x54) 1734ab6cb4cSMarc-André Lureau REG32(CRB_CTRL_CMD_SIZE, 0x58) 1744ab6cb4cSMarc-André Lureau REG32(CRB_CTRL_CMD_LADDR, 0x5C) 1754ab6cb4cSMarc-André Lureau REG32(CRB_CTRL_CMD_HADDR, 0x60) 1764ab6cb4cSMarc-André Lureau REG32(CRB_CTRL_RSP_SIZE, 0x64) 1774ab6cb4cSMarc-André Lureau REG32(CRB_CTRL_RSP_ADDR, 0x68) 1784ab6cb4cSMarc-André Lureau REG32(CRB_DATA_BUFFER, 0x80) 1794ab6cb4cSMarc-André Lureau 1804ab6cb4cSMarc-André Lureau #define TPM_CRB_ADDR_BASE 0xFED40000 1814ab6cb4cSMarc-André Lureau #define TPM_CRB_ADDR_SIZE 0x1000 1824ab6cb4cSMarc-André Lureau #define TPM_CRB_ADDR_CTRL (TPM_CRB_ADDR_BASE + A_CRB_CTRL_REQ) 1834ab6cb4cSMarc-André Lureau #define TPM_CRB_R_MAX R_CRB_DATA_BUFFER 1844ab6cb4cSMarc-André Lureau 1853d779b93SPhilippe Mathieu-Daudé #define TPM_LOG_AREA_MINIMUM_SIZE (64 * KiB) 186711b20b4SStefan Berger 187711b20b4SStefan Berger #define TPM_TCPA_ACPI_CLASS_CLIENT 0 188711b20b4SStefan Berger #define TPM_TCPA_ACPI_CLASS_SERVER 1 189711b20b4SStefan Berger 1905cb18b3dSStefan Berger #define TPM2_ACPI_CLASS_CLIENT 0 1915cb18b3dSStefan Berger #define TPM2_ACPI_CLASS_SERVER 1 1925cb18b3dSStefan Berger 1935cb18b3dSStefan Berger #define TPM2_START_METHOD_MMIO 6 1944ab6cb4cSMarc-André Lureau #define TPM2_START_METHOD_CRB 7 1955cb18b3dSStefan Berger 1963b97c01eSStefan Berger /* 1973b97c01eSStefan Berger * Physical Presence Interface 1983b97c01eSStefan Berger */ 1993b97c01eSStefan Berger #define TPM_PPI_ADDR_SIZE 0x400 2003b97c01eSStefan Berger #define TPM_PPI_ADDR_BASE 0xFED45000 2013b97c01eSStefan Berger 2020fe24669SStefan Berger #define TPM_PPI_VERSION_NONE 0 2030fe24669SStefan Berger #define TPM_PPI_VERSION_1_30 1 2040fe24669SStefan Berger 205ac6dd31eSStefan Berger /* whether function is blocked by BIOS settings; bits 0, 1, 2 */ 206ac6dd31eSStefan Berger #define TPM_PPI_FUNC_NOT_IMPLEMENTED (0 << 0) 207ac6dd31eSStefan Berger #define TPM_PPI_FUNC_BIOS_ONLY (1 << 0) 208ac6dd31eSStefan Berger #define TPM_PPI_FUNC_BLOCKED (2 << 0) 209ac6dd31eSStefan Berger #define TPM_PPI_FUNC_ALLOWED_USR_REQ (3 << 0) 210ac6dd31eSStefan Berger #define TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ (4 << 0) 211ac6dd31eSStefan Berger #define TPM_PPI_FUNC_MASK (7 << 0) 212ac6dd31eSStefan Berger 213*e919515fSNinad Palsule /* TPM TIS I2C registers */ 214*e919515fSNinad Palsule #define TPM_I2C_REG_LOC_SEL 0x00 215*e919515fSNinad Palsule #define TPM_I2C_REG_ACCESS 0x04 216*e919515fSNinad Palsule #define TPM_I2C_REG_INT_ENABLE 0x08 217*e919515fSNinad Palsule #define TPM_I2C_REG_INT_CAPABILITY 0x14 218*e919515fSNinad Palsule #define TPM_I2C_REG_STS 0x18 219*e919515fSNinad Palsule #define TPM_I2C_REG_DATA_FIFO 0x24 220*e919515fSNinad Palsule #define TPM_I2C_REG_INTF_CAPABILITY 0x30 221*e919515fSNinad Palsule #define TPM_I2C_REG_I2C_DEV_ADDRESS 0x38 222*e919515fSNinad Palsule #define TPM_I2C_REG_DATA_CSUM_ENABLE 0x40 223*e919515fSNinad Palsule #define TPM_I2C_REG_DATA_CSUM_GET 0x44 224*e919515fSNinad Palsule #define TPM_I2C_REG_DID_VID 0x48 225*e919515fSNinad Palsule #define TPM_I2C_REG_RID 0x4c 226*e919515fSNinad Palsule #define TPM_I2C_REG_UNKNOWN 0xff 227*e919515fSNinad Palsule 228*e919515fSNinad Palsule /* I2C specific interface capabilities */ 229*e919515fSNinad Palsule #define TPM_I2C_CAP_INTERFACE_TYPE (0x2 << 0) /* FIFO interface */ 230*e919515fSNinad Palsule #define TPM_I2C_CAP_INTERFACE_VER (0x0 << 4) /* TCG I2C intf 1.0 */ 231*e919515fSNinad Palsule #define TPM_I2C_CAP_TPM2_FAMILY (0x1 << 7) /* TPM 2.0 family. */ 232*e919515fSNinad Palsule #define TPM_I2C_CAP_DEV_ADDR_CHANGE (0x0 << 27) /* No dev addr chng */ 233*e919515fSNinad Palsule #define TPM_I2C_CAP_BURST_COUNT_STATIC (0x1 << 29) /* Burst count static */ 234*e919515fSNinad Palsule #define TPM_I2C_CAP_LOCALITY_CAP (0x1 << 25) /* 0-5 locality */ 235*e919515fSNinad Palsule #define TPM_I2C_CAP_BUS_SPEED (3 << 21) /* std and fast mode */ 236*e919515fSNinad Palsule 237*e919515fSNinad Palsule /* 238*e919515fSNinad Palsule * TPM_I2C_STS masks for read/writing bits from/to TIS 239*e919515fSNinad Palsule * TPM_STS mask for read bits 31:26 must be zero 240*e919515fSNinad Palsule */ 241*e919515fSNinad Palsule #define TPM_I2C_STS_READ_MASK 0x00ffffdd 242*e919515fSNinad Palsule #define TPM_I2C_STS_WRITE_MASK 0x03000062 243*e919515fSNinad Palsule 244*e919515fSNinad Palsule /* Checksum enabled. */ 245*e919515fSNinad Palsule #define TPM_DATA_CSUM_ENABLED 0x1 246*e919515fSNinad Palsule 247*e919515fSNinad Palsule /* 248*e919515fSNinad Palsule * TPM_I2C_INT_ENABLE mask. Linux kernel does not support 249*e919515fSNinad Palsule * interrupts hence setting it to 0. 250*e919515fSNinad Palsule */ 251*e919515fSNinad Palsule #define TPM_I2C_INT_ENABLE_MASK 0x0 252*e919515fSNinad Palsule 253ac6dd31eSStefan Berger void tpm_build_ppi_acpi(TPMIf *tpm, Aml *dev); 254ac6dd31eSStefan Berger 255295f7dcbSStefan Berger #endif /* CONFIG_TPM */ 256295f7dcbSStefan Berger 257711b20b4SStefan Berger #endif /* HW_ACPI_TPM_H */ 258