1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <security/tpm/tis.h>
5 #include <acpi/acpigen.h>
6 #include <device/device.h>
7 #include <drivers/intel/ptt/ptt.h>
8 #include <drivers/tpm/tpm_ppi.h>
9 #include <security/tpm/tss.h>
17 static unsigned int tpm_is_open
;
22 const char *device_name
;
24 {0x1ae0, 0x0028, "CR50"},
25 {0xa13a, 0x8086, "Intel iTPM"}
28 static const char *tis_get_dev_name(struct tpm2_info
*info
)
32 for (i
= 0; i
< ARRAY_SIZE(dev_map
); i
++)
33 if ((dev_map
[i
].vid
== info
->vendor_id
) && (dev_map
[i
].did
== info
->device_id
))
34 return dev_map
[i
].device_name
;
41 printk(BIOS_ERR
, "%s called twice.\n", __func__
);
45 if (CONFIG(HAVE_INTEL_PTT
)) {
47 printk(BIOS_ERR
, "%s: Intel PTT is not active.\n", __func__
);
50 printk(BIOS_DEBUG
, "%s: Intel PTT is active.\n", __func__
);
58 struct tpm2_info info
;
60 // Wake TPM up (if necessary)
66 printk(BIOS_INFO
, "Initialized TPM device %s revision %d\n", tis_get_dev_name(&info
),
72 int tis_sendrecv(const uint8_t *sendbuf
, size_t sbuf_size
, uint8_t *recvbuf
, size_t *rbuf_len
)
74 int len
= tpm2_process_command(sendbuf
, sbuf_size
, recvbuf
, *rbuf_len
);
84 static void crb_tpm_fill_ssdt(const struct device
*dev
)
86 const char *path
= acpi_device_path(dev
);
89 printk(BIOS_DEBUG
, "Using default TPM2 ACPI path: '%s'\n", path
);
93 acpigen_write_device(path
);
95 acpigen_write_name_string("_HID", "MSFT0101");
96 acpigen_write_name_string("_CID", "MSFT0101");
98 acpi_device_write_uid(dev
);
100 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON
);
103 acpigen_write_name("_CRS");
104 acpigen_write_resourcetemplate_header();
105 acpigen_write_mem32fixed(1, TPM_CRB_BASE_ADDRESS
, 0x5000);
107 acpigen_write_resourcetemplate_footer();
109 if (!CONFIG(CHROMEOS
) && CONFIG(TPM_PPI
))
110 tpm_ppi_acpi_fill_ssdt(dev
);
112 acpigen_pop_len(); /* Device */
115 static const char *crb_tpm_acpi_name(const struct device
*dev
)
120 #if CONFIG(GENERATE_SMBIOS_TABLES) && CONFIG(TPM2)
121 static int tpm_get_cap(uint32_t property
, uint32_t *value
)
123 TPMS_CAPABILITY_DATA cap_data
;
130 status
= tlcl_get_capability(TPM_CAP_TPM_PROPERTIES
, property
, 1, &cap_data
);
135 for (i
= 0 ; i
< cap_data
.data
.tpmProperties
.count
; i
++) {
136 if (cap_data
.data
.tpmProperties
.tpmProperty
[i
].property
== property
) {
137 *value
= cap_data
.data
.tpmProperties
.tpmProperty
[i
].value
;
145 static int smbios_write_type43_tpm(struct device
*dev
, int *handle
, unsigned long *current
)
147 struct tpm2_info info
;
148 uint32_t tpm_manuf
, tpm_family
;
149 uint32_t fw_ver1
, fw_ver2
;
150 uint8_t major_spec_ver
, minor_spec_ver
;
152 tpm2_get_info(&info
);
154 /* If any of these have invalid values, assume TPM not present or disabled */
155 if (info
.vendor_id
== 0 || info
.vendor_id
== 0xFFFF ||
156 info
.device_id
== 0 || info
.device_id
== 0xFFFF) {
157 printk(BIOS_DEBUG
, "%s: Invalid Vendor ID/Device ID\n", __func__
);
161 /* Vendor ID is the value returned by TPM2_GetCapabiltiy TPM_PT_MANUFACTURER */
162 if (tpm_get_cap(TPM_PT_MANUFACTURER
, &tpm_manuf
)) {
163 printk(BIOS_DEBUG
, "TPM2_GetCap TPM_PT_MANUFACTURER failed\n");
167 tpm_manuf
= be32toh(tpm_manuf
);
169 if (tpm_get_cap(TPM_PT_FIRMWARE_VERSION_1
, &fw_ver1
)) {
170 printk(BIOS_DEBUG
, "TPM2_GetCap TPM_PT_FIRMWARE_VERSION_1 failed\n");
174 if (tpm_get_cap(TPM_PT_FIRMWARE_VERSION_2
, &fw_ver2
)) {
175 printk(BIOS_DEBUG
, "TPM2_GetCap TPM_PT_FIRMWARE_VERSION_2 failed\n");
179 if (tpm_get_cap(TPM_PT_FAMILY_INDICATOR
, &tpm_family
)) {
180 printk(BIOS_DEBUG
, "TPM2_GetCap TPM_PT_FAMILY_INDICATOR failed\n");
184 tpm_family
= be32toh(tpm_family
);
186 if (!strncmp((char *)&tpm_family
, "2.0", 4)) {
190 printk(BIOS_ERR
, "%s: Invalid TPM family\n", __func__
);
194 return smbios_write_type43(current
, handle
, tpm_manuf
, major_spec_ver
, minor_spec_ver
,
195 fw_ver1
, fw_ver2
, tis_get_dev_name(&info
),
196 SMBIOS_TPM_DEVICE_CHARACTERISTICS_NOT_SUPPORTED
, 0);
200 static struct device_operations __maybe_unused crb_ops
= {
201 .read_resources
= noop_read_resources
,
202 .set_resources
= noop_set_resources
,
203 #if CONFIG(HAVE_ACPI_TABLES)
204 .acpi_name
= crb_tpm_acpi_name
,
205 .acpi_fill_ssdt
= crb_tpm_fill_ssdt
,
207 #if CONFIG(GENERATE_SMBIOS_TABLES) && CONFIG(TPM2)
208 .get_smbios_data
= smbios_write_type43_tpm
,
212 static void enable_dev(struct device
*dev
)
219 struct chip_operations drivers_crb_ops
= {
221 .enable_dev
= enable_dev