@@ -39,19 +39,63 @@ static const struct vio_device_id tpm_ibmvtpm_device_table[] = {
39
39
MODULE_DEVICE_TABLE (vio , tpm_ibmvtpm_device_table );
40
40
41
41
/**
42
+ *
43
+ * ibmvtpm_send_crq_word - Send a CRQ request
44
+ * @vdev: vio device struct
45
+ * @w1: pre-constructed first word of tpm crq (second word is reserved)
46
+ *
47
+ * Return:
48
+ * 0 - Success
49
+ * Non-zero - Failure
50
+ */
51
+ static int ibmvtpm_send_crq_word (struct vio_dev * vdev , u64 w1 )
52
+ {
53
+ return plpar_hcall_norets (H_SEND_CRQ , vdev -> unit_address , w1 , 0 );
54
+ }
55
+
56
+ /**
57
+ *
42
58
* ibmvtpm_send_crq - Send a CRQ request
43
59
*
44
60
* @vdev: vio device struct
45
- * @w1: first word
46
- * @w2: second word
61
+ * @valid: Valid field
62
+ * @msg: Type field
63
+ * @len: Length field
64
+ * @data: Data field
65
+ *
66
+ * The ibmvtpm crq is defined as follows:
67
+ *
68
+ * Byte | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
69
+ * -----------------------------------------------------------------------
70
+ * Word0 | Valid | Type | Length | Data
71
+ * -----------------------------------------------------------------------
72
+ * Word1 | Reserved
73
+ * -----------------------------------------------------------------------
74
+ *
75
+ * Which matches the following structure (on bigendian host):
76
+ *
77
+ * struct ibmvtpm_crq {
78
+ * u8 valid;
79
+ * u8 msg;
80
+ * __be16 len;
81
+ * __be32 data;
82
+ * __be64 reserved;
83
+ * } __attribute__((packed, aligned(8)));
84
+ *
85
+ * However, the value is passed in a register so just compute the numeric value
86
+ * to load into the register avoiding byteswap altogether. Endian only affects
87
+ * memory loads and stores - registers are internally represented the same.
47
88
*
48
89
* Return:
49
- * 0 -Sucess
90
+ * 0 (H_SUCCESS) - Success
50
91
* Non-zero - Failure
51
92
*/
52
- static int ibmvtpm_send_crq (struct vio_dev * vdev , u64 w1 , u64 w2 )
93
+ static int ibmvtpm_send_crq (struct vio_dev * vdev ,
94
+ u8 valid , u8 msg , u16 len , u32 data )
53
95
{
54
- return plpar_hcall_norets (H_SEND_CRQ , vdev -> unit_address , w1 , w2 );
96
+ u64 w1 = ((u64 )valid << 56 ) | ((u64 )msg << 48 ) | ((u64 )len << 32 ) |
97
+ (u64 )data ;
98
+ return ibmvtpm_send_crq_word (vdev , w1 );
55
99
}
56
100
57
101
/**
@@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
109
153
static int tpm_ibmvtpm_send (struct tpm_chip * chip , u8 * buf , size_t count )
110
154
{
111
155
struct ibmvtpm_dev * ibmvtpm = dev_get_drvdata (& chip -> dev );
112
- struct ibmvtpm_crq crq ;
113
- __be64 * word = (__be64 * )& crq ;
114
156
int rc , sig ;
115
157
116
158
if (!ibmvtpm -> rtce_buf ) {
@@ -137,19 +179,16 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
137
179
spin_lock (& ibmvtpm -> rtce_lock );
138
180
ibmvtpm -> res_len = 0 ;
139
181
memcpy ((void * )ibmvtpm -> rtce_buf , (void * )buf , count );
140
- crq .valid = (u8 )IBMVTPM_VALID_CMD ;
141
- crq .msg = (u8 )VTPM_TPM_COMMAND ;
142
- crq .len = cpu_to_be16 (count );
143
- crq .data = cpu_to_be32 (ibmvtpm -> rtce_dma_handle );
144
182
145
183
/*
146
184
* set the processing flag before the Hcall, since we may get the
147
185
* result (interrupt) before even being able to check rc.
148
186
*/
149
187
ibmvtpm -> tpm_processing_cmd = true;
150
188
151
- rc = ibmvtpm_send_crq (ibmvtpm -> vdev , be64_to_cpu (word [0 ]),
152
- be64_to_cpu (word [1 ]));
189
+ rc = ibmvtpm_send_crq (ibmvtpm -> vdev ,
190
+ IBMVTPM_VALID_CMD , VTPM_TPM_COMMAND ,
191
+ count , ibmvtpm -> rtce_dma_handle );
153
192
if (rc != H_SUCCESS ) {
154
193
dev_err (ibmvtpm -> dev , "tpm_ibmvtpm_send failed rc=%d\n" , rc );
155
194
rc = 0 ;
@@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip *chip)
182
221
*/
183
222
static int ibmvtpm_crq_get_rtce_size (struct ibmvtpm_dev * ibmvtpm )
184
223
{
185
- struct ibmvtpm_crq crq ;
186
- u64 * buf = (u64 * ) & crq ;
187
224
int rc ;
188
225
189
- crq .valid = (u8 )IBMVTPM_VALID_CMD ;
190
- crq .msg = (u8 )VTPM_GET_RTCE_BUFFER_SIZE ;
191
-
192
- rc = ibmvtpm_send_crq (ibmvtpm -> vdev , cpu_to_be64 (buf [0 ]),
193
- cpu_to_be64 (buf [1 ]));
226
+ rc = ibmvtpm_send_crq (ibmvtpm -> vdev ,
227
+ IBMVTPM_VALID_CMD , VTPM_GET_RTCE_BUFFER_SIZE , 0 , 0 );
194
228
if (rc != H_SUCCESS )
195
229
dev_err (ibmvtpm -> dev ,
196
230
"ibmvtpm_crq_get_rtce_size failed rc=%d\n" , rc );
@@ -210,15 +244,10 @@ static int ibmvtpm_crq_get_rtce_size(struct ibmvtpm_dev *ibmvtpm)
210
244
*/
211
245
static int ibmvtpm_crq_get_version (struct ibmvtpm_dev * ibmvtpm )
212
246
{
213
- struct ibmvtpm_crq crq ;
214
- u64 * buf = (u64 * ) & crq ;
215
247
int rc ;
216
248
217
- crq .valid = (u8 )IBMVTPM_VALID_CMD ;
218
- crq .msg = (u8 )VTPM_GET_VERSION ;
219
-
220
- rc = ibmvtpm_send_crq (ibmvtpm -> vdev , cpu_to_be64 (buf [0 ]),
221
- cpu_to_be64 (buf [1 ]));
249
+ rc = ibmvtpm_send_crq (ibmvtpm -> vdev ,
250
+ IBMVTPM_VALID_CMD , VTPM_GET_VERSION , 0 , 0 );
222
251
if (rc != H_SUCCESS )
223
252
dev_err (ibmvtpm -> dev ,
224
253
"ibmvtpm_crq_get_version failed rc=%d\n" , rc );
@@ -238,7 +267,7 @@ static int ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm)
238
267
{
239
268
int rc ;
240
269
241
- rc = ibmvtpm_send_crq (ibmvtpm -> vdev , INIT_CRQ_COMP_CMD , 0 );
270
+ rc = ibmvtpm_send_crq_word (ibmvtpm -> vdev , INIT_CRQ_COMP_CMD );
242
271
if (rc != H_SUCCESS )
243
272
dev_err (ibmvtpm -> dev ,
244
273
"ibmvtpm_crq_send_init_complete failed rc=%d\n" , rc );
@@ -258,7 +287,7 @@ static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm)
258
287
{
259
288
int rc ;
260
289
261
- rc = ibmvtpm_send_crq (ibmvtpm -> vdev , INIT_CRQ_CMD , 0 );
290
+ rc = ibmvtpm_send_crq_word (ibmvtpm -> vdev , INIT_CRQ_CMD );
262
291
if (rc != H_SUCCESS )
263
292
dev_err (ibmvtpm -> dev ,
264
293
"ibmvtpm_crq_send_init failed rc=%d\n" , rc );
@@ -340,15 +369,10 @@ static int tpm_ibmvtpm_suspend(struct device *dev)
340
369
{
341
370
struct tpm_chip * chip = dev_get_drvdata (dev );
342
371
struct ibmvtpm_dev * ibmvtpm = dev_get_drvdata (& chip -> dev );
343
- struct ibmvtpm_crq crq ;
344
- u64 * buf = (u64 * ) & crq ;
345
372
int rc = 0 ;
346
373
347
- crq .valid = (u8 )IBMVTPM_VALID_CMD ;
348
- crq .msg = (u8 )VTPM_PREPARE_TO_SUSPEND ;
349
-
350
- rc = ibmvtpm_send_crq (ibmvtpm -> vdev , cpu_to_be64 (buf [0 ]),
351
- cpu_to_be64 (buf [1 ]));
374
+ rc = ibmvtpm_send_crq (ibmvtpm -> vdev ,
375
+ IBMVTPM_VALID_CMD , VTPM_PREPARE_TO_SUSPEND , 0 , 0 );
352
376
if (rc != H_SUCCESS )
353
377
dev_err (ibmvtpm -> dev ,
354
378
"tpm_ibmvtpm_suspend failed rc=%d\n" , rc );
0 commit comments