28 #define PREFIX "lpc_tpm: "
31 #define TPM_DEBUG(fmt, args...) \
32 if (CONFIG(DEBUG_TPM)) { \
33 printk(BIOS_DEBUG, PREFIX); \
34 printk(BIOS_DEBUG, fmt, ##args); \
36 #define TPM_DEBUG_IO_READ(reg_, val_) \
37 TPM_DEBUG("Read reg 0x%x returns 0x%x\n", (reg_), (val_))
38 #define TPM_DEBUG_IO_WRITE(reg_, val_) \
39 TPM_DEBUG("Write reg 0x%x with 0x%x\n", (reg_), (val_))
40 #define printf(x...) printk(BIOS_ERR, x)
45 #define TIS_REG(LOCALITY, REG) \
46 (void *)(uintptr_t)(CONFIG_TPM_TIS_BASE_ADDRESS + (LOCALITY << 12) + REG)
49 #define TIS_REG_ACCESS 0x0
50 #define TIS_REG_INT_ENABLE 0x8
51 #define TIS_REG_INT_VECTOR 0xc
52 #define TIS_REG_INT_STATUS 0x10
53 #define TIS_REG_INTF_CAPABILITY 0x14
54 #define TIS_REG_STS 0x18
55 #define TIS_REG_BURST_COUNT 0x19
56 #define TIS_REG_DATA_FIFO 0x24
57 #define TIS_REG_DID_VID 0xf00
58 #define TIS_REG_RID 0xf04
61 #define TIS_STS_VALID (1 << 7)
62 #define TIS_STS_COMMAND_READY (1 << 6)
63 #define TIS_STS_TPM_GO (1 << 5)
64 #define TIS_STS_DATA_AVAILABLE (1 << 4)
65 #define TIS_STS_EXPECT (1 << 3)
66 #define TIS_STS_RESPONSE_RETRY (1 << 1)
68 #define TIS_ACCESS_TPM_REG_VALID_STS (1 << 7)
69 #define TIS_ACCESS_ACTIVE_LOCALITY (1 << 5)
70 #define TIS_ACCESS_BEEN_SEIZED (1 << 4)
71 #define TIS_ACCESS_SEIZE (1 << 3)
72 #define TIS_ACCESS_PENDING_REQUEST (1 << 2)
73 #define TIS_ACCESS_REQUEST_USE (1 << 1)
74 #define TIS_ACCESS_TPM_ESTABLISHMENT (1 << 0)
82 #define TPM_TIMEOUT_ERR (~0)
85 #define TPM_DRIVER_ERR (~0)
88 #define MAX_DELAY_US USECS_PER_SEC
107 {0x3204,
"AT97SC3204"},
112 {0x000b,
"SLB9635 TT 1.2"},
114 {0x001a,
"SLB9665 TT 2.0"},
115 {0x001b,
"SLB9670 TT 2.0"},
117 {0x001a,
"SLB9660 TT 1.2"},
118 {0x001b,
"SLB9670 TT 1.2"},
124 {0x00fe,
"NPCT420AA V2"},
129 {0x0000,
"ST33ZP24" },
135 {0x0001,
"SwTPM 2.0" },
398 if (!didvid || (didvid == 0xffffffff)) {
399 printf(
"%s: No TPM device found\n", __func__);
405 vid = didvid & 0xffff;
406 did = (didvid >> 16) & 0xffff;
416 while ((known_did = dev->
dev_id) != 0xffff) {
417 if (known_did ==
did) {
449 printf(
"%s:%d - failed to get 'command_ready' status\n",
463 printf(
"%s:%d failed to feed %u bytes of %u\n",
464 __FILE__, __LINE__, len -
offset, len);
485 printf(
"%s:%d TPM command feed overflow\n",
491 if ((
offset == (len - 1)) && burst)
508 printf(
"%s:%d unexpected TPM status 0x%x\n",
536 u32 expected_count = *len;
541 printf(
"%s:%d failed processing command\n", __FILE__, __LINE__);
548 printf(
"%s:%d TPM stuck on read\n",
557 while (burst_count-- && (
offset < expected_count)) {
570 sizeof(real_length));
571 expected_count = be32_to_cpu(real_length);
573 if ((expected_count <
offset) ||
574 (expected_count > *len)) {
575 printf(
"%s:%d bad response size %u\n",
585 printf(
"%s:%d failed to read response\n",
590 if (
offset == expected_count)
598 if (
CONFIG(TPM_RDRESP_NEED_DELAY))
605 printf(
"%s:%d wrong receive status: %x %u bytes left\n",
652 printf(
"%s:%d - failed to lock locality %u\n",
653 __FILE__, __LINE__, locality);
679 printf(
"%s:%d - failed to release locality %u\n",
680 __FILE__, __LINE__, locality);
701 uint8_t *recvbuf,
size_t *recv_len)
704 printf(
"%s:%d failed sending data to TPM\n",
752 mmio_resource(dev, 0, CONFIG_TPM_TIS_BASE_ADDRESS >> 10, 0x5000 >> 10);
779 #if CONFIG(HAVE_ACPI_TABLES)
780 static void lpc_tpm_fill_ssdt(
const struct device *dev)
783 const char *path =
"\\_SB_.PCI0";
803 if (did_vid > 0 && did_vid < 0xffffffff)
817 if (CONFIG_TPM_PIRQ) {
857 static const char *lpc_tpm_acpi_name(
const struct device *dev)
866 #if CONFIG(HAVE_ACPI_TABLES)
867 .acpi_name = lpc_tpm_acpi_name,
868 .acpi_fill_ssdt = lpc_tpm_fill_ssdt,
void acpi_device_write_uid(const struct device *dev)
void acpi_device_write_interrupt(const struct acpi_irq *irq)
const char * acpi_device_name(const struct device *dev)
@ ACPI_IRQ_EDGE_TRIGGERED
@ ACPI_IRQ_LEVEL_TRIGGERED
#define ACPI_IRQ_LEVEL_LOW(x)
void acpigen_pop_len(void)
void acpigen_write_scope(const char *name)
void acpigen_write_resourcetemplate_footer(void)
void acpigen_write_STA(uint8_t status)
void acpigen_write_resourcetemplate_header(void)
void acpigen_write_mem32fixed(int readwrite, u32 base, u32 size)
void acpigen_emit_eisaid(const char *eisaid)
void acpigen_write_device(const char *name)
void acpigen_write_io16(u16 min, u16 max, u8 align, u8 len, u8 decode16)
void acpigen_write_name(const char *name)
void acpigen_write_name_string(const char *name, const char *string)
static void write8(void *addr, uint8_t val)
static void write32(void *addr, uint32_t val)
static uint32_t read32(const void *addr)
static uint8_t read8(const void *addr)
void * memcpy(void *dest, const void *src, size_t n)
#define printk(level,...)
int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, uint8_t *recvbuf, size_t *rbuf_len)
void report_resource_stored(struct device *dev, const struct resource *resource, const char *comment)
Print the resource that was just stored.
const char * dev_path(const struct device *dev)
#define ACPI_STATUS_DEVICE_ALL_ON
#define ACPI_STATUS_DEVICE_ALL_OFF
#define mmio_resource(dev, idx, basek, sizek)
static int stopwatch_expired(struct stopwatch *sw)
static void stopwatch_init_usecs_expire(struct stopwatch *sw, long us)
#define BIOS_INFO
BIOS_INFO - Expected events.
#define TIS_REG(LOCALITY, REG)
static void lpc_tpm_set_resources(struct device *dev)
static int tis_wait_ready(int locality)
#define TIS_REG_DATA_FIFO
#define TPM_DEBUG_IO_READ(reg_, val_)
static u8 tpm_read_access(int locality)
static void tis_drop_access(int locality)
static void tpm_write_int_vector(int vector, int locality)
static int tis_setup_interrupt(int vector, int polarity)
static void lpc_tpm_read_resources(struct device *dev)
static u32 tis_readresponse(u8 *buffer, size_t *len)
static const struct device_name stmicro_devices[]
#define TIS_REG_INT_ENABLE
static int tis_wait_sts(int locality, u8 mask, u8 expected)
#define TIS_REG_INT_VECTOR
static int tis_wait_access(int locality, u8 mask, u8 expected)
static struct device_operations lpc_tpm_ops
static int tis_wait_dropped_access(int locality)
static const struct device_name nuvoton_devices[]
static void enable_dev(struct device *dev)
#define TIS_ACCESS_REQUEST_USE
static u16 tpm_read_burst_count(int locality)
static int tis_expect_data(int locality)
static int tis_command_ready(u8 locality)
static int tis_has_access(int locality)
#define TIS_STS_COMMAND_READY
static struct pnp_info pnp_dev_info[]
static void tpm_write_status(u8 sts, int locality)
static const struct vendor_name vendor_names[]
static const struct device_name infineon_devices[]
static u8 tpm_read_int_vector(int locality)
#define TIS_STS_DATA_AVAILABLE
static u8 tpm_read_data(int locality)
static void tis_request_access(int locality)
static u32 tis_senddata(const u8 *const data, u32 len)
static int tis_has_valid_data(int locality)
static int tis_wait_valid_data(int locality)
struct chip_operations drivers_pc80_tpm_ops
static u8 tpm_read_status(int locality)
static void tpm_write_access(u8 data, int locality)
#define TPM_DEBUG_IO_WRITE(reg_, val_)
static int tis_wait_valid(int locality)
static int tis_wait_received_access(int locality)
static void tpm_write_int_polarity(int polarity, int locality)
static u32 tpm_read_int_polarity(int locality)
static const struct device_name atmel_devices[]
#define TIS_REG_BURST_COUNT
static void tpm_write_data(u8 data, int locality)
#define TIS_ACCESS_ACTIVE_LOCALITY
static u32 tis_probe(void)
static u32 tpm_read_did_vid(int locality)
static const struct device_name swtpm_devices[]
void pnp_enable_devices(struct device *base_dev, struct device_operations *ops, unsigned int functions, struct pnp_info *info)
void tpm_ppi_acpi_fill_ssdt(const struct device *dev)
u8 buffer[C2P_BUFFER_MAXSIZE]
#define IORESOURCE_STORED
#define IORESOURCE_ASSIGNED
enum acpi_irq_polarity polarity
const char *const dev_name
void(* read_resources)(struct device *dev)
struct chip_operations * chip_ops
DEVTREE_CONST struct resource * resource_list
DEVTREE_CONST void * chip_info
DEVTREE_CONST struct resource * next
const struct device_name * dev_names