Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 The Chromium OS Authors. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * The code in this file has been heavily based on the article "Writing a TPM |
| 18 | * Device Driver" published on http://ptgmedia.pearsoncmg.com and the |
| 19 | * submission by Stefan Berger on Qemu-devel mailing list. |
| 20 | * |
| 21 | * One principal difference is that in the simplest config the other than 0 |
| 22 | * TPM localities do not get mapped by some devices (for instance, by |
| 23 | * Infineon slb9635), so this driver provides access to locality 0 only. |
| 24 | */ |
| 25 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <delay.h> |
| 29 | #include <arch/io.h> |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 30 | #include <console/console.h> |
Stefan Reinauer | d518c7a | 2013-11-04 17:38:32 -0800 | [diff] [blame] | 31 | #include <tpm.h> |
Stefan Reinauer | fd4f413 | 2013-06-19 12:25:44 -0700 | [diff] [blame] | 32 | #include <arch/early_variables.h> |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 33 | #include <device/pnp.h> |
| 34 | #include "chip.h" |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 35 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 36 | #define PREFIX "lpc_tpm: " |
| 37 | |
| 38 | /* coreboot wrapper for TPM driver (start) */ |
| 39 | #define TPM_DEBUG(fmt, args...) \ |
Denis 'GNUtoo' Carikli | 0e92bb0 | 2016-02-20 17:32:03 +0100 | [diff] [blame] | 40 | if (IS_ENABLED(CONFIG_DEBUG_TPM)) { \ |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 41 | printk(BIOS_DEBUG, PREFIX); \ |
| 42 | printk(BIOS_DEBUG, fmt , ##args); \ |
| 43 | } |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 44 | #define TPM_DEBUG_IO_READ(reg_, val_) \ |
| 45 | TPM_DEBUG("Read reg 0x%x returns 0x%x\n", (reg_), (val_)) |
| 46 | #define TPM_DEBUG_IO_WRITE(reg_, val_) \ |
| 47 | TPM_DEBUG("Write reg 0x%x with 0x%x\n", (reg_), (val_)) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 48 | #define printf(x...) printk(BIOS_ERR, x) |
| 49 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 50 | /* coreboot wrapper for TPM driver (end) */ |
| 51 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 52 | /* the macro accepts the locality value, but only locality 0 is operational */ |
| 53 | #define TIS_REG(LOCALITY, REG) \ |
| 54 | (void *)(CONFIG_TPM_TIS_BASE_ADDRESS + (LOCALITY << 12) + REG) |
| 55 | |
| 56 | /* hardware registers' offsets */ |
| 57 | #define TIS_REG_ACCESS 0x0 |
| 58 | #define TIS_REG_INT_ENABLE 0x8 |
| 59 | #define TIS_REG_INT_VECTOR 0xc |
| 60 | #define TIS_REG_INT_STATUS 0x10 |
| 61 | #define TIS_REG_INTF_CAPABILITY 0x14 |
| 62 | #define TIS_REG_STS 0x18 |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 63 | #define TIS_REG_BURST_COUNT 0x19 |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 64 | #define TIS_REG_DATA_FIFO 0x24 |
| 65 | #define TIS_REG_DID_VID 0xf00 |
| 66 | #define TIS_REG_RID 0xf04 |
| 67 | |
| 68 | /* Some registers' bit field definitions */ |
| 69 | #define TIS_STS_VALID (1 << 7) /* 0x80 */ |
| 70 | #define TIS_STS_COMMAND_READY (1 << 6) /* 0x40 */ |
| 71 | #define TIS_STS_TPM_GO (1 << 5) /* 0x20 */ |
| 72 | #define TIS_STS_DATA_AVAILABLE (1 << 4) /* 0x10 */ |
| 73 | #define TIS_STS_EXPECT (1 << 3) /* 0x08 */ |
| 74 | #define TIS_STS_RESPONSE_RETRY (1 << 1) /* 0x02 */ |
| 75 | |
| 76 | #define TIS_ACCESS_TPM_REG_VALID_STS (1 << 7) /* 0x80 */ |
| 77 | #define TIS_ACCESS_ACTIVE_LOCALITY (1 << 5) /* 0x20 */ |
| 78 | #define TIS_ACCESS_BEEN_SEIZED (1 << 4) /* 0x10 */ |
| 79 | #define TIS_ACCESS_SEIZE (1 << 3) /* 0x08 */ |
| 80 | #define TIS_ACCESS_PENDING_REQUEST (1 << 2) /* 0x04 */ |
| 81 | #define TIS_ACCESS_REQUEST_USE (1 << 1) /* 0x02 */ |
| 82 | #define TIS_ACCESS_TPM_ESTABLISHMENT (1 << 0) /* 0x01 */ |
| 83 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 84 | /* |
| 85 | * Error value returned if a tpm register does not enter the expected state |
| 86 | * after continuous polling. No actual TPM register reading ever returns ~0, |
| 87 | * so this value is a safe error indication to be mixed with possible status |
| 88 | * register values. |
| 89 | */ |
| 90 | #define TPM_TIMEOUT_ERR (~0) |
| 91 | |
| 92 | /* Error value returned on various TPM driver errors */ |
| 93 | #define TPM_DRIVER_ERR (~0) |
| 94 | |
| 95 | /* 1 second is plenty for anything TPM does.*/ |
| 96 | #define MAX_DELAY_US (1000 * 1000) |
| 97 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 98 | /* |
| 99 | * Structures defined below allow creating descriptions of TPM vendor/device |
| 100 | * ID information for run time discovery. The only device the system knows |
| 101 | * about at this time is Infineon slb9635 |
| 102 | */ |
| 103 | struct device_name { |
| 104 | u16 dev_id; |
| 105 | const char * const dev_name; |
| 106 | }; |
| 107 | |
| 108 | struct vendor_name { |
| 109 | u16 vendor_id; |
| 110 | const char * vendor_name; |
Stefan Reinauer | c668af7 | 2011-10-27 21:28:25 +0000 | [diff] [blame] | 111 | const struct device_name* dev_names; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 114 | static const struct device_name atmel_devices[] = { |
| 115 | {0x3204, "AT97SC3204"}, |
| 116 | {0xffff} |
| 117 | }; |
| 118 | |
Stefan Reinauer | c668af7 | 2011-10-27 21:28:25 +0000 | [diff] [blame] | 119 | static const struct device_name infineon_devices[] = { |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 120 | {0x000b, "SLB9635 TT 1.2"}, |
Subrata | f4d6587 | 2015-05-14 14:38:07 +0530 | [diff] [blame] | 121 | {0x001a, "SLB9660 TT 1.2"}, |
Subrata Banik | 5b8c4a7 | 2016-11-11 09:28:45 +0530 | [diff] [blame] | 122 | #if IS_ENABLED(CONFIG_TPM2) |
| 123 | {0x001b, "SLB9670 TT 2.0"}, |
| 124 | #else |
Wenkai Du | 641529b | 2015-05-29 10:54:27 -0700 | [diff] [blame] | 125 | {0x001b, "SLB9670 TT 1.2"}, |
Subrata Banik | 5b8c4a7 | 2016-11-11 09:28:45 +0530 | [diff] [blame] | 126 | #endif |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 127 | {0xffff} |
| 128 | }; |
| 129 | |
| 130 | static const struct device_name nuvoton_devices[] = { |
| 131 | {0x00fe, "NPCT420AA V2"}, |
| 132 | {0xffff} |
| 133 | }; |
| 134 | |
| 135 | static const struct device_name stmicro_devices[] = { |
| 136 | {0x0000, "ST33ZP24" }, |
| 137 | {0xffff} |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static const struct vendor_name vendor_names[] = { |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 141 | {0x1114, "Atmel", atmel_devices}, |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 142 | {0x15d1, "Infineon", infineon_devices}, |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 143 | {0x1050, "Nuvoton", nuvoton_devices}, |
| 144 | {0x104a, "ST Microelectronics", stmicro_devices}, |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | /* |
| 148 | * Cached vendor/device ID pair to indicate that the device has been already |
| 149 | * discovered |
| 150 | */ |
Stefan Reinauer | c668af7 | 2011-10-27 21:28:25 +0000 | [diff] [blame] | 151 | static u32 vendor_dev_id CAR_GLOBAL; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 152 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 153 | static inline u8 tpm_read_status(int locality) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 154 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 155 | u8 value = read8(TIS_REG(locality, TIS_REG_STS)); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 156 | TPM_DEBUG_IO_READ(TIS_REG_STS, value); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 157 | return value; |
| 158 | } |
| 159 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 160 | static inline void tpm_write_status(u8 sts, int locality) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 161 | { |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 162 | TPM_DEBUG_IO_WRITE(TIS_REG_STS, sts); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 163 | write8(TIS_REG(locality, TIS_REG_STS), sts); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 164 | } |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 165 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 166 | static inline u8 tpm_read_data(int locality) |
| 167 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 168 | u8 value = read8(TIS_REG(locality, TIS_REG_DATA_FIFO)); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 169 | TPM_DEBUG_IO_READ(TIS_REG_DATA_FIFO, value); |
| 170 | return value; |
| 171 | } |
| 172 | |
| 173 | static inline void tpm_write_data(u8 data, int locality) |
| 174 | { |
| 175 | TPM_DEBUG_IO_WRITE(TIS_REG_STS, data); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 176 | write8(TIS_REG(locality, TIS_REG_DATA_FIFO), data); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static inline u16 tpm_read_burst_count(int locality) |
| 180 | { |
| 181 | u16 count; |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 182 | count = read8(TIS_REG(locality, TIS_REG_BURST_COUNT)); |
| 183 | count |= read8(TIS_REG(locality, TIS_REG_BURST_COUNT + 1)) << 8; |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 184 | TPM_DEBUG_IO_READ(TIS_REG_BURST_COUNT, count); |
| 185 | return count; |
| 186 | } |
| 187 | |
| 188 | static inline u8 tpm_read_access(int locality) |
| 189 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 190 | u8 value = read8(TIS_REG(locality, TIS_REG_ACCESS)); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 191 | TPM_DEBUG_IO_READ(TIS_REG_ACCESS, value); |
| 192 | return value; |
| 193 | } |
| 194 | |
| 195 | static inline void tpm_write_access(u8 data, int locality) |
| 196 | { |
| 197 | TPM_DEBUG_IO_WRITE(TIS_REG_ACCESS, data); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 198 | write8(TIS_REG(locality, TIS_REG_ACCESS), data); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static inline u32 tpm_read_did_vid(int locality) |
| 202 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 203 | u32 value = read32(TIS_REG(locality, TIS_REG_DID_VID)); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 204 | TPM_DEBUG_IO_READ(TIS_REG_DID_VID, value); |
| 205 | return value; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 208 | static inline void tpm_write_int_vector(int vector, int locality) |
| 209 | { |
| 210 | TPM_DEBUG_IO_WRITE(TIS_REG_INT_VECTOR, vector); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 211 | write8(TIS_REG(locality, TIS_REG_INT_VECTOR), vector & 0xf); |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static inline void tpm_write_int_polarity(int polarity, int locality) |
| 215 | { |
| 216 | /* Set polarity and leave all other bits at 0 */ |
| 217 | u32 value = (polarity & 0x3) << 3; |
| 218 | TPM_DEBUG_IO_WRITE(TIS_REG_INT_ENABLE, value); |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 219 | write32(TIS_REG(locality, TIS_REG_INT_ENABLE), value); |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 222 | /* |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 223 | * tis_wait_sts() |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 224 | * |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 225 | * Wait for at least a second for a status to change its state to match the |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 226 | * expected state. Normally the transition happens within microseconds. |
| 227 | * |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 228 | * @locality - locality |
| 229 | * @mask - bitmask for the bitfield(s) to watch |
| 230 | * @expected - value the field(s) are supposed to be set to |
| 231 | * |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 232 | * Returns 0 on success or TPM_TIMEOUT_ERR on timeout. |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 233 | */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 234 | static int tis_wait_sts(int locality, u8 mask, u8 expected) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 235 | { |
| 236 | u32 time_us = MAX_DELAY_US; |
| 237 | while (time_us > 0) { |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 238 | u8 value = tpm_read_status(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 239 | if ((value & mask) == expected) |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 240 | return 0; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 241 | udelay(1); /* 1 us */ |
| 242 | time_us--; |
| 243 | } |
| 244 | return TPM_TIMEOUT_ERR; |
| 245 | } |
| 246 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 247 | static inline int tis_wait_ready(int locality) |
| 248 | { |
| 249 | return tis_wait_sts(locality, TIS_STS_COMMAND_READY, |
| 250 | TIS_STS_COMMAND_READY); |
| 251 | } |
| 252 | |
| 253 | static inline int tis_wait_valid(int locality) |
| 254 | { |
| 255 | return tis_wait_sts(locality, TIS_STS_VALID, TIS_STS_VALID); |
| 256 | } |
| 257 | |
| 258 | static inline int tis_wait_valid_data(int locality) |
| 259 | { |
| 260 | const u8 has_data = TIS_STS_DATA_AVAILABLE | TIS_STS_VALID; |
| 261 | return tis_wait_sts(locality, has_data, has_data); |
| 262 | } |
| 263 | |
| 264 | static inline int tis_has_valid_data(int locality) |
| 265 | { |
| 266 | const u8 has_data = TIS_STS_DATA_AVAILABLE | TIS_STS_VALID; |
| 267 | return (tpm_read_status(locality) & has_data) == has_data; |
| 268 | } |
| 269 | |
| 270 | static inline int tis_expect_data(int locality) |
| 271 | { |
| 272 | return !!(tpm_read_status(locality) & TIS_STS_EXPECT); |
| 273 | } |
| 274 | |
| 275 | /* |
| 276 | * tis_wait_access() |
| 277 | * |
| 278 | * Wait for at least a second for a access to change its state to match the |
| 279 | * expected state. Normally the transition happens within microseconds. |
| 280 | * |
| 281 | * @locality - locality |
| 282 | * @mask - bitmask for the bitfield(s) to watch |
| 283 | * @expected - value the field(s) are supposed to be set to |
| 284 | * |
| 285 | * Returns 0 on success or TPM_TIMEOUT_ERR on timeout. |
| 286 | */ |
| 287 | static int tis_wait_access(int locality, u8 mask, u8 expected) |
| 288 | { |
| 289 | u32 time_us = MAX_DELAY_US; |
| 290 | while (time_us > 0) { |
| 291 | u8 value = tpm_read_access(locality); |
| 292 | if ((value & mask) == expected) |
| 293 | return 0; |
| 294 | udelay(1); /* 1 us */ |
| 295 | time_us--; |
| 296 | } |
| 297 | return TPM_TIMEOUT_ERR; |
| 298 | } |
| 299 | |
| 300 | static inline int tis_wait_dropped_access(int locality) |
| 301 | { |
| 302 | return tis_wait_access(locality, TIS_ACCESS_ACTIVE_LOCALITY, 0); |
| 303 | } |
| 304 | |
| 305 | static inline int tis_wait_received_access(int locality) |
| 306 | { |
| 307 | return tis_wait_access(locality, TIS_ACCESS_ACTIVE_LOCALITY, |
| 308 | TIS_ACCESS_ACTIVE_LOCALITY); |
| 309 | } |
| 310 | |
| 311 | static inline int tis_has_access(int locality) |
| 312 | { |
| 313 | return !!(tpm_read_access(locality) & TIS_ACCESS_ACTIVE_LOCALITY); |
| 314 | } |
| 315 | |
| 316 | static inline void tis_request_access(int locality) |
| 317 | { |
| 318 | tpm_write_access(TIS_ACCESS_REQUEST_USE, locality); |
| 319 | } |
| 320 | |
| 321 | static inline void tis_drop_access(int locality) |
| 322 | { |
| 323 | tpm_write_access(TIS_ACCESS_ACTIVE_LOCALITY, locality); |
| 324 | } |
| 325 | |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 326 | /* |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 327 | * PC Client Specific TPM Interface Specification section 11.2.12: |
| 328 | * |
| 329 | * Software must be prepared to send two writes of a "1" to command ready |
| 330 | * field: the first to indicate successful read of all the data, thus |
| 331 | * clearing the data from the ReadFIFO and freeing the TPM's resources, |
| 332 | * and the second to indicate to the TPM it is about to send a new command. |
| 333 | * |
| 334 | * In practice not all TPMs behave the same so it is necessary to be |
| 335 | * flexible when trying to set command ready. |
| 336 | * |
| 337 | * Returns 0 on success if the TPM is ready for transactions. |
| 338 | * Returns TPM_TIMEOUT_ERR if the command ready bit does not get set. |
| 339 | */ |
| 340 | static int tis_command_ready(u8 locality) |
| 341 | { |
| 342 | u32 status; |
| 343 | |
| 344 | /* 1st attempt to set command ready */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 345 | tpm_write_status(TIS_STS_COMMAND_READY, locality); |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 346 | |
| 347 | /* Wait for response */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 348 | status = tpm_read_status(locality); |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 349 | |
| 350 | /* Check if command ready is set yet */ |
| 351 | if (status & TIS_STS_COMMAND_READY) |
| 352 | return 0; |
| 353 | |
| 354 | /* 2nd attempt to set command ready */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 355 | tpm_write_status(TIS_STS_COMMAND_READY, locality); |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 356 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 357 | return tis_wait_ready(locality); |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /* |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 361 | * Probe the TPM device and try determining its manufacturer/device name. |
| 362 | * |
| 363 | * Returns 0 on success (the device is found or was found during an earlier |
| 364 | * invocation) or TPM_DRIVER_ERR if the device is not found. |
| 365 | */ |
| 366 | static u32 tis_probe(void) |
| 367 | { |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 368 | const char *device_name = "unknown"; |
| 369 | const char *vendor_name = device_name; |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 370 | const struct device_name *dev; |
| 371 | u32 didvid; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 372 | u16 vid, did; |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 373 | int i; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 374 | |
Aaron Durbin | cb997d3 | 2013-05-10 00:40:56 -0500 | [diff] [blame] | 375 | if (car_get_var(vendor_dev_id)) |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 376 | return 0; /* Already probed. */ |
| 377 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 378 | didvid = tpm_read_did_vid(0); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 379 | if (!didvid || (didvid == 0xffffffff)) { |
| 380 | printf("%s: No TPM device found\n", __FUNCTION__); |
| 381 | return TPM_DRIVER_ERR; |
| 382 | } |
| 383 | |
Aaron Durbin | cb997d3 | 2013-05-10 00:40:56 -0500 | [diff] [blame] | 384 | car_set_var(vendor_dev_id, didvid); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 385 | |
| 386 | vid = didvid & 0xffff; |
| 387 | did = (didvid >> 16) & 0xffff; |
| 388 | for (i = 0; i < ARRAY_SIZE(vendor_names); i++) { |
| 389 | int j = 0; |
| 390 | u16 known_did; |
| 391 | if (vid == vendor_names[i].vendor_id) { |
| 392 | vendor_name = vendor_names[i].vendor_name; |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 393 | } else { |
| 394 | continue; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 395 | } |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 396 | dev = &vendor_names[i].dev_names[j]; |
| 397 | while ((known_did = dev->dev_id) != 0xffff) { |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 398 | if (known_did == did) { |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 399 | device_name = dev->dev_name; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 400 | break; |
| 401 | } |
| 402 | j++; |
Subrata | 41b08d9 | 2015-05-14 14:38:07 +0530 | [diff] [blame] | 403 | dev = &vendor_names[i].dev_names[j]; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 404 | } |
| 405 | break; |
| 406 | } |
| 407 | /* this will have to be converted into debug printout */ |
Duncan Laurie | 17ba944 | 2015-09-03 16:00:49 -0700 | [diff] [blame] | 408 | printk(BIOS_INFO, "Found TPM %s by %s\n", device_name, vendor_name); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | /* |
| 413 | * tis_senddata() |
| 414 | * |
| 415 | * send the passed in data to the TPM device. |
| 416 | * |
| 417 | * @data - address of the data to send, byte by byte |
| 418 | * @len - length of the data to send |
| 419 | * |
| 420 | * Returns 0 on success, TPM_DRIVER_ERR on error (in case the device does |
| 421 | * not accept the entire command). |
| 422 | */ |
| 423 | static u32 tis_senddata(const u8 * const data, u32 len) |
| 424 | { |
| 425 | u32 offset = 0; |
| 426 | u16 burst = 0; |
| 427 | u32 max_cycles = 0; |
| 428 | u8 locality = 0; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 429 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 430 | if (tis_wait_ready(locality)) { |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 431 | printf("%s:%d - failed to get 'command_ready' status\n", |
| 432 | __FILE__, __LINE__); |
| 433 | return TPM_DRIVER_ERR; |
| 434 | } |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 435 | burst = tpm_read_burst_count(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 436 | |
| 437 | while (1) { |
| 438 | unsigned count; |
| 439 | |
| 440 | /* Wait till the device is ready to accept more data. */ |
| 441 | while (!burst) { |
| 442 | if (max_cycles++ == MAX_DELAY_US) { |
| 443 | printf("%s:%d failed to feed %d bytes of %d\n", |
| 444 | __FILE__, __LINE__, len - offset, len); |
| 445 | return TPM_DRIVER_ERR; |
| 446 | } |
| 447 | udelay(1); |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 448 | burst = tpm_read_burst_count(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | max_cycles = 0; |
| 452 | |
| 453 | /* |
| 454 | * Calculate number of bytes the TPM is ready to accept in one |
| 455 | * shot. |
| 456 | * |
| 457 | * We want to send the last byte outside of the loop (hence |
| 458 | * the -1 below) to make sure that the 'expected' status bit |
| 459 | * changes to zero exactly after the last byte is fed into the |
| 460 | * FIFO. |
| 461 | */ |
| 462 | count = min(burst, len - offset - 1); |
| 463 | while (count--) |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 464 | tpm_write_data(data[offset++], locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 465 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 466 | if (tis_wait_valid(locality) || !tis_expect_data(locality)) { |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 467 | printf("%s:%d TPM command feed overflow\n", |
| 468 | __FILE__, __LINE__); |
| 469 | return TPM_DRIVER_ERR; |
| 470 | } |
| 471 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 472 | burst = tpm_read_burst_count(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 473 | if ((offset == (len - 1)) && burst) |
| 474 | /* |
| 475 | * We need to be able to send the last byte to the |
| 476 | * device, so burst size must be nonzero before we |
| 477 | * break out. |
| 478 | */ |
| 479 | break; |
| 480 | } |
| 481 | |
| 482 | /* Send the last byte. */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 483 | tpm_write_data(data[offset++], locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 484 | |
| 485 | /* |
| 486 | * Verify that TPM does not expect any more data as part of this |
| 487 | * command. |
| 488 | */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 489 | if (tis_wait_valid(locality) || tis_expect_data(locality)) { |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 490 | printf("%s:%d unexpected TPM status 0x%x\n", |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 491 | __FILE__, __LINE__, tpm_read_status(locality)); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 492 | return TPM_DRIVER_ERR; |
| 493 | } |
| 494 | |
| 495 | /* OK, sitting pretty, let's start the command execution. */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 496 | tpm_write_status(TIS_STS_TPM_GO, locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | /* |
| 502 | * tis_readresponse() |
| 503 | * |
| 504 | * read the TPM device response after a command was issued. |
| 505 | * |
| 506 | * @buffer - address where to read the response, byte by byte. |
| 507 | * @len - pointer to the size of buffer |
| 508 | * |
| 509 | * On success stores the number of received bytes to len and returns 0. On |
| 510 | * errors (misformatted TPM data or synchronization problems) returns |
| 511 | * TPM_DRIVER_ERR. |
| 512 | */ |
| 513 | static u32 tis_readresponse(u8 *buffer, size_t *len) |
| 514 | { |
| 515 | u16 burst_count; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 516 | u32 offset = 0; |
| 517 | u8 locality = 0; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 518 | u32 expected_count = *len; |
| 519 | int max_cycles = 0; |
| 520 | |
| 521 | /* Wait for the TPM to process the command */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 522 | if (tis_wait_valid_data(locality)) { |
| 523 | printf("%s:%d failed processing command\n", __FILE__, __LINE__); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 524 | return TPM_DRIVER_ERR; |
| 525 | } |
| 526 | |
| 527 | do { |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 528 | while ((burst_count = tpm_read_burst_count(locality)) == 0) { |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 529 | if (max_cycles++ == MAX_DELAY_US) { |
| 530 | printf("%s:%d TPM stuck on read\n", |
| 531 | __FILE__, __LINE__); |
| 532 | return TPM_DRIVER_ERR; |
| 533 | } |
| 534 | udelay(1); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | max_cycles = 0; |
| 538 | |
| 539 | while (burst_count-- && (offset < expected_count)) { |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 540 | buffer[offset++] = tpm_read_data(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 541 | if (offset == 6) { |
| 542 | /* |
| 543 | * We got the first six bytes of the reply, |
| 544 | * let's figure out how many bytes to expect |
| 545 | * total - it is stored as a 4 byte number in |
| 546 | * network order, starting with offset 2 into |
| 547 | * the body of the reply. |
| 548 | */ |
| 549 | u32 real_length; |
| 550 | memcpy(&real_length, |
| 551 | buffer + 2, |
| 552 | sizeof(real_length)); |
| 553 | expected_count = be32_to_cpu(real_length); |
| 554 | |
| 555 | if ((expected_count < offset) || |
| 556 | (expected_count > *len)) { |
| 557 | printf("%s:%d bad response size %d\n", |
| 558 | __FILE__, __LINE__, |
| 559 | expected_count); |
| 560 | return TPM_DRIVER_ERR; |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | /* Wait for the next portion */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 566 | if (tis_wait_valid(locality)) { |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 567 | printf("%s:%d failed to read response\n", |
| 568 | __FILE__, __LINE__); |
| 569 | return TPM_DRIVER_ERR; |
| 570 | } |
| 571 | |
| 572 | if (offset == expected_count) |
| 573 | break; /* We got all we need */ |
| 574 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 575 | } while (tis_has_valid_data(locality)); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 576 | |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 577 | /* * Make sure we indeed read all there was. */ |
| 578 | if (tis_has_valid_data(locality)) { |
| 579 | printf("%s:%d wrong receive status: %x %d bytes left\n", |
| 580 | __FILE__, __LINE__, tpm_read_status(locality), |
| 581 | tpm_read_burst_count(locality)); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 582 | return TPM_DRIVER_ERR; |
| 583 | } |
| 584 | |
| 585 | /* Tell the TPM that we are done. */ |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 586 | if (tis_command_ready(locality) == TPM_TIMEOUT_ERR) |
| 587 | return TPM_DRIVER_ERR; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 588 | |
| 589 | *len = offset; |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | /* |
| 594 | * tis_init() |
| 595 | * |
| 596 | * Initialize the TPM device. Returns 0 on success or TPM_DRIVER_ERR on |
| 597 | * failure (in case device probing did not succeed). |
| 598 | */ |
| 599 | int tis_init(void) |
| 600 | { |
| 601 | if (tis_probe()) |
| 602 | return TPM_DRIVER_ERR; |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | /* |
| 607 | * tis_open() |
| 608 | * |
| 609 | * Requests access to locality 0 for the caller. After all commands have been |
| 610 | * completed the caller is supposed to call tis_close(). |
| 611 | * |
| 612 | * Returns 0 on success, TPM_DRIVER_ERR on failure. |
| 613 | */ |
| 614 | int tis_open(void) |
| 615 | { |
| 616 | u8 locality = 0; /* we use locality zero for everything */ |
| 617 | |
| 618 | if (tis_close()) |
| 619 | return TPM_DRIVER_ERR; |
| 620 | |
| 621 | /* now request access to locality */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 622 | tis_request_access(locality); |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 623 | |
| 624 | /* did we get a lock? */ |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 625 | if (tis_wait_received_access(locality)) { |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 626 | printf("%s:%d - failed to lock locality %d\n", |
| 627 | __FILE__, __LINE__, locality); |
| 628 | return TPM_DRIVER_ERR; |
| 629 | } |
| 630 | |
Stefan Reinauer | c908fc7 | 2012-04-30 16:33:44 -0700 | [diff] [blame] | 631 | /* Certain TPMs seem to need some delay here or they hang... */ |
| 632 | udelay(10); |
| 633 | |
| 634 | if (tis_command_ready(locality) == TPM_TIMEOUT_ERR) |
| 635 | return TPM_DRIVER_ERR; |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 636 | |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | /* |
| 641 | * tis_close() |
| 642 | * |
Martin Roth | 5688979 | 2013-07-09 21:39:46 -0600 | [diff] [blame] | 643 | * terminate the current session with the TPM by releasing the locked |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 644 | * locality. Returns 0 on success of TPM_DRIVER_ERR on failure (in case lock |
| 645 | * removal did not succeed). |
| 646 | */ |
| 647 | int tis_close(void) |
| 648 | { |
| 649 | u8 locality = 0; |
Aaron Durbin | c422002 | 2013-07-24 16:02:14 -0500 | [diff] [blame] | 650 | if (tis_has_access(locality)) { |
| 651 | tis_drop_access(locality); |
| 652 | if (tis_wait_dropped_access(locality)) { |
Stefan Reinauer | 3008bbad | 2011-10-11 14:46:25 -0700 | [diff] [blame] | 653 | printf("%s:%d - failed to release locality %d\n", |
| 654 | __FILE__, __LINE__, locality); |
| 655 | return TPM_DRIVER_ERR; |
| 656 | } |
| 657 | } |
| 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | /* |
| 662 | * tis_sendrecv() |
| 663 | * |
| 664 | * Send the requested data to the TPM and then try to get its response |
| 665 | * |
| 666 | * @sendbuf - buffer of the data to send |
| 667 | * @send_size size of the data to send |
| 668 | * @recvbuf - memory to save the response to |
| 669 | * @recv_len - pointer to the size of the response buffer |
| 670 | * |
| 671 | * Returns 0 on success (and places the number of response bytes at recv_len) |
| 672 | * or TPM_DRIVER_ERR on failure. |
| 673 | */ |
| 674 | int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, |
| 675 | uint8_t *recvbuf, size_t *recv_len) |
| 676 | { |
| 677 | if (tis_senddata(sendbuf, send_size)) { |
| 678 | printf("%s:%d failed sending data to TPM\n", |
| 679 | __FILE__, __LINE__); |
| 680 | return TPM_DRIVER_ERR; |
| 681 | } |
| 682 | |
| 683 | return tis_readresponse(recvbuf, recv_len); |
| 684 | } |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 685 | |
| 686 | #ifdef __RAMSTAGE__ |
| 687 | |
| 688 | /* |
| 689 | * tis_setup_interrupt() |
| 690 | * |
| 691 | * Set up the interrupt vector and polarity for locality 0 and |
| 692 | * disable all interrupts so they are unused in firmware but can |
| 693 | * be enabled by the OS. |
| 694 | * |
| 695 | * The values used here must match what is passed in the TPM ACPI |
| 696 | * device if ACPI is used on the platform. |
| 697 | * |
| 698 | * @vector - TPM interrupt vector |
| 699 | * @polarity - TPM interrupt polarity |
| 700 | * |
| 701 | * Returns 0 on success, TPM_DRIVER_ERR on failure. |
| 702 | */ |
| 703 | static int tis_setup_interrupt(int vector, int polarity) |
| 704 | { |
| 705 | u8 locality = 0; |
| 706 | int has_access = tis_has_access(locality); |
| 707 | |
| 708 | /* Open connection and request access if not already granted */ |
| 709 | if (!has_access && tis_open() < 0) |
| 710 | return TPM_DRIVER_ERR; |
| 711 | |
| 712 | /* Set TPM interrupt vector */ |
| 713 | tpm_write_int_vector(vector, locality); |
| 714 | |
| 715 | /* Set TPM interupt polarity and disable interrupts */ |
| 716 | tpm_write_int_polarity(polarity, locality); |
| 717 | |
| 718 | /* Close connection if it was opened */ |
| 719 | if (!has_access && tis_close() < 0) |
| 720 | return TPM_DRIVER_ERR; |
| 721 | |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | static void lpc_tpm_read_resources(struct device *dev) |
| 726 | { |
| 727 | /* Static 5K memory region specified in Kconfig */ |
| 728 | mmio_resource(dev, 0, CONFIG_TPM_TIS_BASE_ADDRESS >> 10, 0x5000 >> 10); |
| 729 | } |
| 730 | |
| 731 | static void lpc_tpm_set_resources(struct device *dev) |
| 732 | { |
| 733 | tpm_config_t *config = (tpm_config_t *)dev->chip_info; |
| 734 | struct resource *res; |
| 735 | |
| 736 | for (res = dev->resource_list; res; res = res->next) { |
| 737 | if (!(res->flags & IORESOURCE_ASSIGNED)) |
| 738 | continue; |
| 739 | |
| 740 | if (res->flags & IORESOURCE_IRQ) { |
| 741 | /* Set interrupt vector */ |
| 742 | tis_setup_interrupt((int)res->base, |
| 743 | config->irq_polarity); |
| 744 | } else { |
Duncan Laurie | dd281ed | 2014-10-30 15:20:19 -0700 | [diff] [blame] | 745 | continue; |
| 746 | } |
| 747 | |
| 748 | res->flags |= IORESOURCE_STORED; |
| 749 | report_resource_stored(dev, res, " <tpm>"); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | static struct device_operations lpc_tpm_ops = { |
| 754 | .read_resources = &lpc_tpm_read_resources, |
| 755 | .set_resources = &lpc_tpm_set_resources, |
| 756 | }; |
| 757 | |
| 758 | static struct pnp_info pnp_dev_info[] = { |
| 759 | { .flags = PNP_IRQ0 } |
| 760 | }; |
| 761 | |
| 762 | static void enable_dev(struct device *dev) |
| 763 | { |
| 764 | pnp_enable_devices(dev, &lpc_tpm_ops, |
| 765 | ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
| 766 | } |
| 767 | |
| 768 | struct chip_operations drivers_pc80_tpm_ops = { |
| 769 | CHIP_NAME("LPC TPM") |
| 770 | .enable_dev = enable_dev |
| 771 | }; |
| 772 | |
| 773 | #endif /* __RAMSTAGE__ */ |