@@ -6531,6 +6531,14 @@
This will guarantee that all the other pcrs
are saved.
+ tpm.sleep_locality_preserve= [HW,TPM]
+ Format: { -1 | 0 | 1 }
+ Defines the locality behavior of the TPM chip before suspend/shutdown.
+ 0 -- Force normal behavior (relinquish before sleep)
+ 1 -- Force locality to be preserved before sleep
+ -1 -- Automatically set based on known buggy boards
+ Default: -1
+
tpm_tis.interrupts= [HW,TPM]
Enable interrupts for the MMIO based physical layer
for the FIFO interface. By default it is set to false
@@ -137,6 +137,12 @@ EXPORT_SYMBOL_GPL(tpm_chip_start);
*/
void tpm_chip_stop(struct tpm_chip *chip)
{
+ if (chip->flags & TPM_CHIP_FLAG_PRESERVE_LOCALITY) {
+ if (chip->locality != 0)
+ tpm_request_locality(chip);
+ return;
+ }
+
tpm_go_idle(chip);
tpm_relinquish_locality(chip);
tpm_clk_disable(chip);
@@ -291,6 +297,9 @@ int tpm_class_shutdown(struct device *dev)
{
struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev);
+ if (tpm_sleep_locality_preserve)
+ chip->flags |= TPM_CHIP_FLAG_PRESERVE_LOCALITY;
+
down_write(&chip->ops_sem);
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
if (!tpm_chip_start(chip)) {
@@ -668,6 +677,9 @@ EXPORT_SYMBOL_GPL(tpm_chip_register);
*/
void tpm_chip_unregister(struct tpm_chip *chip)
{
+ if (tpm_sleep_locality_preserve)
+ chip->flags |= TPM_CHIP_FLAG_PRESERVE_LOCALITY;
+
tpm_del_legacy_sysfs(chip);
if (tpm_is_hwrng_enabled(chip))
hwrng_unregister(&chip->hwrng);
@@ -26,6 +26,7 @@
#include <linux/suspend.h>
#include <linux/freezer.h>
#include <linux/tpm_eventlog.h>
+#include <linux/dmi.h>
#include "tpm.h"
@@ -382,6 +383,38 @@ int tpm_auto_startup(struct tpm_chip *chip)
return rc;
}
+/*
+ * Bug workaround - some boards expect the TPM to be on Locality 0
+ * before suspend/shutdown, halting the system otherwise before
+ * suspend and shutdown. Change suspend behavior for these cases.
+ */
+int tpm_sleep_locality_preserve = -1;
+module_param_named(sleep_locality_preserve, tpm_sleep_locality_preserve, int, 0644);
+MODULE_PARM_DESC(sleep_locality_preserve,
+ "Locality before sleep/shutdown (0: relinquish, 1: preserve, -1: auto)");
+
+static int __init tpm_set_sleep_locality_preserve(const struct dmi_system_id *system_id)
+{
+ if (tpm_sleep_locality_preserve < 0) {
+ pr_info("Board %s: TPM locality preserved before suspend/shutdown.\n",
+ system_id->ident);
+ tpm_sleep_locality_preserve = 1;
+ }
+
+ return 0;
+}
+
+static const struct dmi_system_id tpm_board_quirks[] __initconst = {
+ {
+ .ident = "TUF GAMING B460M-PLUS",
+ .matches = {
+ DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK COMPUTER INC."),
+ DMI_MATCH(DMI_BOARD_NAME, "TUF GAMING B460M-PLUS"),
+ },
+ .callback = tpm_set_sleep_locality_preserve,
+ },
+};
+
/*
* We are about to suspend. Save the TPM state
* so that it can be restored.
@@ -394,6 +427,9 @@ int tpm_pm_suspend(struct device *dev)
if (!chip)
return -ENODEV;
+ if (tpm_sleep_locality_preserve)
+ chip->flags |= TPM_CHIP_FLAG_PRESERVE_LOCALITY;
+
if (chip->flags & TPM_CHIP_FLAG_ALWAYS_POWERED)
goto suspended;
@@ -431,6 +467,7 @@ int tpm_pm_resume(struct device *dev)
if (chip == NULL)
return -ENODEV;
+ chip->flags &= ~TPM_CHIP_FLAG_PRESERVE_LOCALITY;
chip->flags &= ~TPM_CHIP_FLAG_SUSPENDED;
/*
@@ -476,6 +513,10 @@ static int __init tpm_init(void)
{
int rc;
+ dmi_check_system(tpm_board_quirks);
+ if (tpm_sleep_locality_preserve < 0)
+ tpm_sleep_locality_preserve = 0;
+
rc = class_register(&tpm_class);
if (rc) {
pr_err("couldn't create tpm class\n");
@@ -236,6 +236,7 @@ extern dev_t tpm_devt;
extern const struct file_operations tpm_fops;
extern const struct file_operations tpmrm_fops;
extern struct idr dev_nums_idr;
+extern int tpm_sleep_locality_preserve;
ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz);
int tpm_get_timeouts(struct tpm_chip *);
@@ -284,6 +284,7 @@ enum tpm_chip_flags {
TPM_CHIP_FLAG_FIRMWARE_UPGRADE = BIT(7),
TPM_CHIP_FLAG_SUSPENDED = BIT(8),
TPM_CHIP_FLAG_HWRNG_DISABLED = BIT(9),
+ TPM_CHIP_FLAG_PRESERVE_LOCALITY = BIT(10),
};
#define to_tpm_chip(d) container_of(d, struct tpm_chip, dev)