3232
3333static const char tpm_ibmvtpm_driver_name [] = "tpm_ibmvtpm" ;
3434
35- static struct vio_device_id tpm_ibmvtpm_device_table [] = {
35+ static const struct vio_device_id tpm_ibmvtpm_device_table [] = {
3636 { "IBM,vtpm" , "IBM,vtpm" },
3737 { "" , "" }
3838};
3939MODULE_DEVICE_TABLE (vio , tpm_ibmvtpm_device_table );
4040
4141/**
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+ *
4258 * ibmvtpm_send_crq - Send a CRQ request
4359 *
4460 * @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.
4788 *
4889 * Return:
49- * 0 -Sucess
90+ * 0 (H_SUCCESS) - Success
5091 * Non-zero - Failure
5192 */
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 )
5395{
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 );
5599}
56100
57101/**
@@ -109,8 +153,6 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
109153static int tpm_ibmvtpm_send (struct tpm_chip * chip , u8 * buf , size_t count )
110154{
111155 struct ibmvtpm_dev * ibmvtpm = dev_get_drvdata (& chip -> dev );
112- struct ibmvtpm_crq crq ;
113- __be64 * word = (__be64 * )& crq ;
114156 int rc , sig ;
115157
116158 if (!ibmvtpm -> rtce_buf ) {
@@ -137,19 +179,16 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
137179 spin_lock (& ibmvtpm -> rtce_lock );
138180 ibmvtpm -> res_len = 0 ;
139181 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 );
144182
145183 /*
146184 * set the processing flag before the Hcall, since we may get the
147185 * result (interrupt) before even being able to check rc.
148186 */
149187 ibmvtpm -> tpm_processing_cmd = true;
150188
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 );
153192 if (rc != H_SUCCESS ) {
154193 dev_err (ibmvtpm -> dev , "tpm_ibmvtpm_send failed rc=%d\n" , rc );
155194 rc = 0 ;
@@ -182,15 +221,10 @@ static u8 tpm_ibmvtpm_status(struct tpm_chip *chip)
182221 */
183222static int ibmvtpm_crq_get_rtce_size (struct ibmvtpm_dev * ibmvtpm )
184223{
185- struct ibmvtpm_crq crq ;
186- u64 * buf = (u64 * ) & crq ;
187224 int rc ;
188225
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 );
194228 if (rc != H_SUCCESS )
195229 dev_err (ibmvtpm -> dev ,
196230 "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)
210244 */
211245static int ibmvtpm_crq_get_version (struct ibmvtpm_dev * ibmvtpm )
212246{
213- struct ibmvtpm_crq crq ;
214- u64 * buf = (u64 * ) & crq ;
215247 int rc ;
216248
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 );
222251 if (rc != H_SUCCESS )
223252 dev_err (ibmvtpm -> dev ,
224253 "ibmvtpm_crq_get_version failed rc=%d\n" , rc );
@@ -238,7 +267,7 @@ static int ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm)
238267{
239268 int rc ;
240269
241- rc = ibmvtpm_send_crq (ibmvtpm -> vdev , INIT_CRQ_COMP_CMD , 0 );
270+ rc = ibmvtpm_send_crq_word (ibmvtpm -> vdev , INIT_CRQ_COMP_CMD );
242271 if (rc != H_SUCCESS )
243272 dev_err (ibmvtpm -> dev ,
244273 "ibmvtpm_crq_send_init_complete failed rc=%d\n" , rc );
@@ -258,7 +287,7 @@ static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm)
258287{
259288 int rc ;
260289
261- rc = ibmvtpm_send_crq (ibmvtpm -> vdev , INIT_CRQ_CMD , 0 );
290+ rc = ibmvtpm_send_crq_word (ibmvtpm -> vdev , INIT_CRQ_CMD );
262291 if (rc != H_SUCCESS )
263292 dev_err (ibmvtpm -> dev ,
264293 "ibmvtpm_crq_send_init failed rc=%d\n" , rc );
@@ -340,15 +369,10 @@ static int tpm_ibmvtpm_suspend(struct device *dev)
340369{
341370 struct tpm_chip * chip = dev_get_drvdata (dev );
342371 struct ibmvtpm_dev * ibmvtpm = dev_get_drvdata (& chip -> dev );
343- struct ibmvtpm_crq crq ;
344- u64 * buf = (u64 * ) & crq ;
345372 int rc = 0 ;
346373
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 );
352376 if (rc != H_SUCCESS )
353377 dev_err (ibmvtpm -> dev ,
354378 "tpm_ibmvtpm_suspend failed rc=%d\n" , rc );
0 commit comments