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