security/tpm: Drop CAR_GLOBAL_MIGRATION support
Change-Id: I1c09eda6164efb390de4626f52aafba59962f9c4 Signed-off-by: Arthur Heymans <arthur@aheymans.xyz> Reviewed-on: https://review.coreboot.org/c/coreboot/+/37029 Reviewed-by: HAOUAS Elyes <ehaouas@noos.fr> Reviewed-by: Patrick Georgi <pgeorgi@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
committed by
Patrick Georgi
parent
344e86bb3b
commit
0ca944b16f
@@ -27,7 +27,6 @@
|
||||
* instead of just reading header and determining the remainder
|
||||
*/
|
||||
|
||||
#include <arch/early_variables.h>
|
||||
#include <commonlib/endian.h>
|
||||
#include <string.h>
|
||||
#include <types.h>
|
||||
@@ -55,15 +54,15 @@ struct tpm_inf_dev {
|
||||
uint8_t buf[CR50_MAX_BUFSIZE + sizeof(uint8_t)];
|
||||
};
|
||||
|
||||
static struct tpm_inf_dev g_tpm_dev CAR_GLOBAL;
|
||||
static struct tpm_inf_dev g_tpm_dev;
|
||||
|
||||
__weak int tis_plat_irq_status(void)
|
||||
{
|
||||
static int warning_displayed CAR_GLOBAL;
|
||||
static int warning_displayed;
|
||||
|
||||
if (!car_get_var(warning_displayed)) {
|
||||
if (!warning_displayed) {
|
||||
printk(BIOS_WARNING, "WARNING: tis_plat_irq_status() not implemented, wasting 20ms to wait on Cr50!\n");
|
||||
car_set_var(warning_displayed, 1);
|
||||
warning_displayed = 1;
|
||||
}
|
||||
mdelay(CR50_TIMEOUT_NOIRQ_MS);
|
||||
|
||||
@@ -102,16 +101,14 @@ static int cr50_i2c_wait_tpm_ready(struct tpm_chip *chip)
|
||||
static int cr50_i2c_read(struct tpm_chip *chip, uint8_t addr,
|
||||
uint8_t *buffer, size_t len)
|
||||
{
|
||||
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
|
||||
|
||||
if (tpm_dev->addr == 0)
|
||||
if (g_tpm_dev.addr == 0)
|
||||
return -1;
|
||||
|
||||
/* Clear interrupt before starting transaction */
|
||||
tis_plat_irq_status();
|
||||
|
||||
/* Send the register address byte to the TPM */
|
||||
if (i2c_write_raw(tpm_dev->bus, tpm_dev->addr, &addr, 1)) {
|
||||
if (i2c_write_raw(g_tpm_dev.bus, g_tpm_dev.addr, &addr, 1)) {
|
||||
printk(BIOS_ERR, "%s: Address write failed\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
@@ -121,7 +118,7 @@ static int cr50_i2c_read(struct tpm_chip *chip, uint8_t addr,
|
||||
return -1;
|
||||
|
||||
/* Read response data from the TPM */
|
||||
if (i2c_read_raw(tpm_dev->bus, tpm_dev->addr, buffer, len)) {
|
||||
if (i2c_read_raw(g_tpm_dev.bus, g_tpm_dev.addr, buffer, len)) {
|
||||
printk(BIOS_ERR, "%s: Read response failed\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
@@ -146,22 +143,20 @@ static int cr50_i2c_read(struct tpm_chip *chip, uint8_t addr,
|
||||
static int cr50_i2c_write(struct tpm_chip *chip,
|
||||
uint8_t addr, uint8_t *buffer, size_t len)
|
||||
{
|
||||
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
|
||||
|
||||
if (tpm_dev->addr == 0)
|
||||
if (g_tpm_dev.addr == 0)
|
||||
return -1;
|
||||
if (len > CR50_MAX_BUFSIZE)
|
||||
return -1;
|
||||
|
||||
/* Prepend the 'register address' to the buffer */
|
||||
tpm_dev->buf[0] = addr;
|
||||
memcpy(tpm_dev->buf + 1, buffer, len);
|
||||
g_tpm_dev.buf[0] = addr;
|
||||
memcpy(g_tpm_dev.buf + 1, buffer, len);
|
||||
|
||||
/* Clear interrupt before starting transaction */
|
||||
tis_plat_irq_status();
|
||||
|
||||
/* Send write request buffer with address */
|
||||
if (i2c_write_raw(tpm_dev->bus, tpm_dev->addr, tpm_dev->buf, len + 1)) {
|
||||
if (i2c_write_raw(g_tpm_dev.bus, g_tpm_dev.addr, g_tpm_dev.buf, len + 1)) {
|
||||
printk(BIOS_ERR, "%s: Error writing to TPM\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
@@ -492,7 +487,6 @@ static int cr50_i2c_probe(struct tpm_chip *chip, uint32_t *did_vid)
|
||||
|
||||
int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
|
||||
{
|
||||
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
|
||||
uint32_t did_vid = 0;
|
||||
|
||||
if (dev_addr == 0) {
|
||||
@@ -500,8 +494,8 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
tpm_dev->bus = bus;
|
||||
tpm_dev->addr = dev_addr;
|
||||
g_tpm_dev.bus = bus;
|
||||
g_tpm_dev.addr = dev_addr;
|
||||
|
||||
cr50_vendor_init(chip);
|
||||
|
||||
|
@@ -12,7 +12,6 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <arch/early_variables.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
@@ -27,25 +26,24 @@
|
||||
#include "tpm.h"
|
||||
|
||||
/* global structure for tpm chip data */
|
||||
static struct tpm_chip g_chip CAR_GLOBAL;
|
||||
static struct tpm_chip g_chip;
|
||||
|
||||
#define TPM_CMD_COUNT_BYTE 2
|
||||
#define TPM_CMD_ORDINAL_BYTE 6
|
||||
|
||||
int tis_open(void)
|
||||
{
|
||||
struct tpm_chip *chip = car_get_var_ptr(&g_chip);
|
||||
int rc;
|
||||
|
||||
if (chip->is_open) {
|
||||
if (g_chip.is_open) {
|
||||
printk(BIOS_DEBUG, "tis_open() called twice.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = tpm_vendor_init(chip, CONFIG_DRIVER_TPM_I2C_BUS,
|
||||
rc = tpm_vendor_init(&g_chip, CONFIG_DRIVER_TPM_I2C_BUS,
|
||||
CONFIG_DRIVER_TPM_I2C_ADDR);
|
||||
if (rc < 0)
|
||||
chip->is_open = 0;
|
||||
g_chip.is_open = 0;
|
||||
|
||||
if (rc)
|
||||
return -1;
|
||||
@@ -55,11 +53,9 @@ int tis_open(void)
|
||||
|
||||
int tis_close(void)
|
||||
{
|
||||
struct tpm_chip *chip = car_get_var_ptr(&g_chip);
|
||||
|
||||
if (chip->is_open) {
|
||||
tpm_vendor_cleanup(chip);
|
||||
chip->is_open = 0;
|
||||
if (g_chip.is_open) {
|
||||
tpm_vendor_cleanup(&g_chip);
|
||||
g_chip.is_open = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -76,12 +72,11 @@ static ssize_t tpm_transmit(const uint8_t *sbuf, size_t sbufsiz, void *rbuf,
|
||||
{
|
||||
int rc;
|
||||
uint32_t count;
|
||||
struct tpm_chip *chip = car_get_var_ptr(&g_chip);
|
||||
|
||||
memcpy(&count, sbuf + TPM_CMD_COUNT_BYTE, sizeof(count));
|
||||
count = be32_to_cpu(count);
|
||||
|
||||
if (!chip->vendor.send || !chip->vendor.status || !chip->vendor.cancel)
|
||||
if (!g_chip.vendor.send || !g_chip.vendor.status || !g_chip.vendor.cancel)
|
||||
return -1;
|
||||
|
||||
if (count == 0) {
|
||||
@@ -94,8 +89,8 @@ static ssize_t tpm_transmit(const uint8_t *sbuf, size_t sbufsiz, void *rbuf,
|
||||
return -1;
|
||||
}
|
||||
|
||||
ASSERT(chip->vendor.send);
|
||||
rc = chip->vendor.send(chip, (uint8_t *) sbuf, count);
|
||||
ASSERT(g_chip.vendor.send);
|
||||
rc = g_chip.vendor.send(&g_chip, (uint8_t *) sbuf, count);
|
||||
if (rc < 0) {
|
||||
printk(BIOS_DEBUG, "tpm_transmit: tpm_send error\n");
|
||||
goto out;
|
||||
@@ -103,14 +98,14 @@ static ssize_t tpm_transmit(const uint8_t *sbuf, size_t sbufsiz, void *rbuf,
|
||||
|
||||
int timeout = 2 * 60 * 1000; /* two minutes timeout */
|
||||
while (timeout) {
|
||||
ASSERT(chip->vendor.status);
|
||||
uint8_t status = chip->vendor.status(chip);
|
||||
if ((status & chip->vendor.req_complete_mask) ==
|
||||
chip->vendor.req_complete_val) {
|
||||
ASSERT(g_chip.vendor.status);
|
||||
uint8_t status = g_chip.vendor.status(&g_chip);
|
||||
if ((status & g_chip.vendor.req_complete_mask) ==
|
||||
g_chip.vendor.req_complete_val) {
|
||||
goto out_recv;
|
||||
}
|
||||
|
||||
if (status == chip->vendor.req_canceled) {
|
||||
if (status == g_chip.vendor.req_canceled) {
|
||||
printk(BIOS_DEBUG,
|
||||
"tpm_transmit: Operation Canceled\n");
|
||||
rc = -1;
|
||||
@@ -120,15 +115,15 @@ static ssize_t tpm_transmit(const uint8_t *sbuf, size_t sbufsiz, void *rbuf,
|
||||
timeout--;
|
||||
}
|
||||
|
||||
ASSERT(chip->vendor.cancel);
|
||||
chip->vendor.cancel(chip);
|
||||
ASSERT(g_chip.vendor.cancel);
|
||||
g_chip.vendor.cancel(&g_chip);
|
||||
printk(BIOS_DEBUG, "tpm_transmit: Operation Timed out\n");
|
||||
rc = -1; //ETIME;
|
||||
goto out;
|
||||
|
||||
out_recv:
|
||||
|
||||
rc = chip->vendor.recv(chip, (uint8_t *) rbuf, rbufsiz);
|
||||
rc = g_chip.vendor.recv(&g_chip, (uint8_t *) rbuf, rbufsiz);
|
||||
if (rc < 0)
|
||||
printk(BIOS_DEBUG, "tpm_transmit: tpm_recv: error %d\n", rc);
|
||||
out:
|
||||
|
@@ -12,7 +12,6 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <arch/early_variables.h>
|
||||
#include <assert.h>
|
||||
#include <commonlib/endian.h>
|
||||
#include <console/console.h>
|
||||
|
@@ -28,7 +28,6 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <arch/early_variables.h>
|
||||
#include <commonlib/endian.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
@@ -81,7 +80,7 @@ struct tpm_inf_dev {
|
||||
enum i2c_chip_type chip_type;
|
||||
};
|
||||
|
||||
static struct tpm_inf_dev g_tpm_dev CAR_GLOBAL;
|
||||
static struct tpm_inf_dev g_tpm_dev;
|
||||
|
||||
/*
|
||||
* iic_tpm_read() - read from TPM register
|
||||
@@ -99,24 +98,23 @@ static struct tpm_inf_dev g_tpm_dev CAR_GLOBAL;
|
||||
*/
|
||||
static int iic_tpm_read(uint8_t addr, uint8_t *buffer, size_t len)
|
||||
{
|
||||
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
|
||||
int rc;
|
||||
int count;
|
||||
|
||||
if (tpm_dev->addr == 0)
|
||||
if (g_tpm_dev.addr == 0)
|
||||
return -1;
|
||||
|
||||
switch (tpm_dev->chip_type) {
|
||||
switch (g_tpm_dev.chip_type) {
|
||||
case SLB9635:
|
||||
case UNKNOWN:
|
||||
/* slb9635 protocol should work in both cases */
|
||||
for (count = 0; count < MAX_COUNT; count++) {
|
||||
rc = i2c_write_raw(tpm_dev->bus, tpm_dev->addr,
|
||||
rc = i2c_write_raw(g_tpm_dev.bus, g_tpm_dev.addr,
|
||||
&addr, 1);
|
||||
if (rc == 0)
|
||||
break; /* success, break to skip sleep */
|
||||
|
||||
udelay(tpm_dev->sleep_short);
|
||||
udelay(g_tpm_dev.sleep_short);
|
||||
}
|
||||
|
||||
if (rc)
|
||||
@@ -127,8 +125,8 @@ static int iic_tpm_read(uint8_t addr, uint8_t *buffer, size_t len)
|
||||
* retrieving the data
|
||||
*/
|
||||
for (count = 0; count < MAX_COUNT; count++) {
|
||||
udelay(tpm_dev->sleep_short);
|
||||
rc = i2c_read_raw(tpm_dev->bus, tpm_dev->addr,
|
||||
udelay(g_tpm_dev.sleep_short);
|
||||
rc = i2c_read_raw(g_tpm_dev.bus, g_tpm_dev.addr,
|
||||
buffer, len);
|
||||
if (rc == 0)
|
||||
break; /* success, break to skip sleep */
|
||||
@@ -144,23 +142,23 @@ static int iic_tpm_read(uint8_t addr, uint8_t *buffer, size_t len)
|
||||
* retries should usually not be needed, but are kept just to
|
||||
* be safe on the safe side.
|
||||
*/
|
||||
struct i2c_msg aseg = { .flags = 0, .slave = tpm_dev->addr,
|
||||
struct i2c_msg aseg = { .flags = 0, .slave = g_tpm_dev.addr,
|
||||
.buf = &addr, .len = 1 };
|
||||
struct i2c_msg dseg = { .flags = I2C_M_RD,
|
||||
.slave = tpm_dev->addr,
|
||||
.slave = g_tpm_dev.addr,
|
||||
.buf = buffer, .len = len };
|
||||
for (count = 0; count < MAX_COUNT; count++) {
|
||||
rc = i2c_transfer(tpm_dev->bus, &aseg, 1) ||
|
||||
i2c_transfer(tpm_dev->bus, &dseg, 1);
|
||||
rc = i2c_transfer(g_tpm_dev.bus, &aseg, 1) ||
|
||||
i2c_transfer(g_tpm_dev.bus, &dseg, 1);
|
||||
if (rc == 0)
|
||||
break; /* break here to skip sleep */
|
||||
udelay(tpm_dev->sleep_short);
|
||||
udelay(g_tpm_dev.sleep_short);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* take care of 'guard time' */
|
||||
udelay(tpm_dev->sleep_short);
|
||||
udelay(g_tpm_dev.sleep_short);
|
||||
if (rc)
|
||||
return -1;
|
||||
|
||||
@@ -171,7 +169,6 @@ static int iic_tpm_write_generic(uint8_t addr, uint8_t *buffer, size_t len,
|
||||
unsigned int sleep_time,
|
||||
uint8_t max_count)
|
||||
{
|
||||
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
|
||||
int rc = 0;
|
||||
int count;
|
||||
|
||||
@@ -182,14 +179,14 @@ static int iic_tpm_write_generic(uint8_t addr, uint8_t *buffer, size_t len,
|
||||
}
|
||||
|
||||
/* prepare send buffer */
|
||||
tpm_dev->buf[0] = addr;
|
||||
memcpy(&(tpm_dev->buf[1]), buffer, len);
|
||||
g_tpm_dev.buf[0] = addr;
|
||||
memcpy(&(g_tpm_dev.buf[1]), buffer, len);
|
||||
|
||||
if (tpm_dev->addr == 0)
|
||||
if (g_tpm_dev.addr == 0)
|
||||
return -1;
|
||||
for (count = 0; count < max_count; count++) {
|
||||
rc = i2c_write_raw(tpm_dev->bus, tpm_dev->addr,
|
||||
tpm_dev->buf, len + 1);
|
||||
rc = i2c_write_raw(g_tpm_dev.bus, g_tpm_dev.addr,
|
||||
g_tpm_dev.buf, len + 1);
|
||||
if (rc == 0)
|
||||
break; /* success, break to skip sleep */
|
||||
|
||||
@@ -197,7 +194,7 @@ static int iic_tpm_write_generic(uint8_t addr, uint8_t *buffer, size_t len,
|
||||
}
|
||||
|
||||
/* take care of 'guard time' */
|
||||
udelay(tpm_dev->sleep_short);
|
||||
udelay(g_tpm_dev.sleep_short);
|
||||
if (rc)
|
||||
return -1;
|
||||
|
||||
@@ -222,8 +219,7 @@ static int iic_tpm_write_generic(uint8_t addr, uint8_t *buffer, size_t len,
|
||||
*/
|
||||
static int iic_tpm_write(uint8_t addr, uint8_t *buffer, size_t len)
|
||||
{
|
||||
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
|
||||
return iic_tpm_write_generic(addr, buffer, len, tpm_dev->sleep_short,
|
||||
return iic_tpm_write_generic(addr, buffer, len, g_tpm_dev.sleep_short,
|
||||
MAX_COUNT);
|
||||
}
|
||||
|
||||
@@ -233,8 +229,7 @@ static int iic_tpm_write(uint8_t addr, uint8_t *buffer, size_t len)
|
||||
* */
|
||||
static int iic_tpm_write_long(uint8_t addr, uint8_t *buffer, size_t len)
|
||||
{
|
||||
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
|
||||
return iic_tpm_write_generic(addr, buffer, len, tpm_dev->sleep_long,
|
||||
return iic_tpm_write_generic(addr, buffer, len, g_tpm_dev.sleep_long,
|
||||
MAX_COUNT_LONG);
|
||||
}
|
||||
|
||||
@@ -479,17 +474,16 @@ out_err:
|
||||
|
||||
int tpm_vendor_probe(unsigned int bus, uint32_t addr)
|
||||
{
|
||||
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
|
||||
struct stopwatch sw;
|
||||
uint8_t buf = 0;
|
||||
int ret;
|
||||
long sw_run_duration = SLEEP_DURATION_PROBE_MS;
|
||||
|
||||
tpm_dev->chip_type = UNKNOWN;
|
||||
tpm_dev->bus = bus;
|
||||
tpm_dev->addr = addr;
|
||||
tpm_dev->sleep_short = SLEEP_DURATION;
|
||||
tpm_dev->sleep_long = SLEEP_DURATION_LONG;
|
||||
g_tpm_dev.chip_type = UNKNOWN;
|
||||
g_tpm_dev.bus = bus;
|
||||
g_tpm_dev.addr = addr;
|
||||
g_tpm_dev.sleep_short = SLEEP_DURATION;
|
||||
g_tpm_dev.sleep_long = SLEEP_DURATION_LONG;
|
||||
|
||||
/*
|
||||
* Probe TPM. Check if the TPM_ACCESS register's ValidSts bit is set(1)
|
||||
@@ -521,7 +515,6 @@ int tpm_vendor_probe(unsigned int bus, uint32_t addr)
|
||||
|
||||
int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
|
||||
{
|
||||
struct tpm_inf_dev *tpm_dev = car_get_var_ptr(&g_tpm_dev);
|
||||
uint32_t vendor;
|
||||
|
||||
if (dev_addr == 0) {
|
||||
@@ -529,11 +522,11 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
tpm_dev->chip_type = UNKNOWN;
|
||||
tpm_dev->bus = bus;
|
||||
tpm_dev->addr = dev_addr;
|
||||
tpm_dev->sleep_short = SLEEP_DURATION;
|
||||
tpm_dev->sleep_long = SLEEP_DURATION_LONG;
|
||||
g_tpm_dev.chip_type = UNKNOWN;
|
||||
g_tpm_dev.bus = bus;
|
||||
g_tpm_dev.addr = dev_addr;
|
||||
g_tpm_dev.sleep_short = SLEEP_DURATION;
|
||||
g_tpm_dev.sleep_long = SLEEP_DURATION_LONG;
|
||||
|
||||
memset(&chip->vendor, 0, sizeof(struct tpm_vendor_specific));
|
||||
chip->is_open = 1;
|
||||
@@ -554,9 +547,9 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
|
||||
goto out_err;
|
||||
|
||||
if (vendor == TPM_TIS_I2C_DID_VID_9645) {
|
||||
tpm_dev->chip_type = SLB9645;
|
||||
g_tpm_dev.chip_type = SLB9645;
|
||||
} else if (be32_to_cpu(vendor) == TPM_TIS_I2C_DID_VID_9635) {
|
||||
tpm_dev->chip_type = SLB9635;
|
||||
g_tpm_dev.chip_type = SLB9635;
|
||||
} else {
|
||||
printk(BIOS_DEBUG, "Vendor ID 0x%08x not recognized.\n",
|
||||
vendor);
|
||||
@@ -564,8 +557,8 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
|
||||
}
|
||||
|
||||
printk(BIOS_DEBUG, "I2C TPM %u:%02x (chip type %s device-id 0x%X)\n",
|
||||
tpm_dev->bus, tpm_dev->addr,
|
||||
chip_name[tpm_dev->chip_type], vendor >> 16);
|
||||
g_tpm_dev.bus, g_tpm_dev.addr,
|
||||
chip_name[g_tpm_dev.chip_type], vendor >> 16);
|
||||
|
||||
/*
|
||||
* A timeout query to TPM can be placed here.
|
||||
|
Reference in New Issue
Block a user