blob: 625679de75cd637bf7e2189f96ac60c2813665fd [file] [log] [blame]
Stefan Reinauer7cb01e02013-08-29 16:05:02 -07001/*
2 * Copyright (C) 2011 Infineon Technologies
3 *
4 * Authors:
5 * Peter Huewe <huewe.external@infineon.com>
6 *
7 * Version: 2.1.1
8 *
9 * Description:
10 * Device driver for TCG/TCPA TPM (trusted platform module).
11 * Specifications at www.trustedcomputinggroup.org
12 *
13 * It is based on the Linux kernel driver tpm.c from Leendert van
14 * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall.
15 *
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070016 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation, version 2 of the
19 * License.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070025 */
26
27#ifndef __DRIVERS_TPM_SLB9635_I2C_TPM_H__
28#define __DRIVERS_TPM_SLB9635_I2C_TPM_H__
29
30#include <stdint.h>
31
32enum tpm_timeout {
33 TPM_TIMEOUT = 1, /* msecs */
34};
35
Julius Wernere6cf3c62014-12-19 14:38:51 -080036/* Size of external transmit buffer (used for stack buffer in tpm_sendrecv) */
37#define TPM_BUFSIZE 1260
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070038
39/* Index of fields in TPM command buffer */
40#define TPM_CMD_SIZE_BYTE 2
41#define TPM_CMD_ORDINAL_BYTE 6
42
43/* Index of Count field in TPM response buffer */
44#define TPM_RSP_SIZE_BYTE 2
45#define TPM_RSP_RC_BYTE 6
46
47struct tpm_chip;
48
49struct tpm_vendor_specific {
50 const uint8_t req_complete_mask;
51 const uint8_t req_complete_val;
52 const uint8_t req_canceled;
53 int irq;
54 int (*recv)(struct tpm_chip *, uint8_t *, size_t);
55 int (*send)(struct tpm_chip *, uint8_t *, size_t);
56 void (*cancel)(struct tpm_chip *);
57 uint8_t(*status)(struct tpm_chip *);
58 int locality;
59};
60
61struct tpm_chip {
62 int is_open;
63 struct tpm_vendor_specific vendor;
64};
65
66struct tpm_input_header {
67 uint16_t tag;
68 uint32_t length;
69 uint32_t ordinal;
70} __attribute__ ((packed));
71
72struct tpm_output_header {
73 uint16_t tag;
74 uint32_t length;
75 uint32_t return_code;
76} __attribute__ ((packed));
77
78struct timeout_t {
79 uint32_t a;
80 uint32_t b;
81 uint32_t c;
82 uint32_t d;
83} __attribute__ ((packed));
84
85struct duration_t {
86 uint32_t tpm_short;
87 uint32_t tpm_medium;
88 uint32_t tpm_long;
89} __attribute__ ((packed));
90
91typedef union {
92 struct timeout_t timeout;
93 struct duration_t duration;
94} cap_t;
95
96struct tpm_getcap_params_in {
97 uint32_t cap;
98 uint32_t subcap_size;
99 uint32_t subcap;
100} __attribute__ ((packed));
101
102struct tpm_getcap_params_out {
103 uint32_t cap_size;
104 cap_t cap;
105} __attribute__ ((packed));
106
107typedef union {
108 struct tpm_input_header in;
109 struct tpm_output_header out;
110} tpm_cmd_header;
111
112typedef union {
113 struct tpm_getcap_params_out getcap_out;
114 struct tpm_getcap_params_in getcap_in;
115} tpm_cmd_params;
116
117struct tpm_cmd_t {
118 tpm_cmd_header header;
119 tpm_cmd_params params;
120} __attribute__ ((packed));
121
Stefan Reinauer7cb01e02013-08-29 16:05:02 -0700122/* ---------- Interface for TPM vendor ------------ */
123
Stefan Reinauer7cb01e02013-08-29 16:05:02 -0700124int tpm_vendor_init(unsigned bus, uint32_t dev_addr);
125
126void tpm_vendor_cleanup(struct tpm_chip *chip);
127
Stefan Reinauer7cb01e02013-08-29 16:05:02 -0700128#endif /* __DRIVERS_TPM_SLB9635_I2C_TPM_H__ */