xen-tpmfront.c (af782f339a5d6ea202652c9f06880e1a28c43813) xen-tpmfront.c (9e0d39d8a6a0a8805d05fba22e3fbe80b5c8c4cb)
1/*
2 * Implementation of the Xen vTPM device frontend
3 *
4 * Author: Daniel De Graaf <dgdegra@tycho.nsa.gov>
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 version 2,
8 * as published by the Free Software Foundation.

--- 27 unchanged lines hidden (view full) ---

36 VTPM_STATUS_RUNNING = 0x1,
37 VTPM_STATUS_IDLE = 0x2,
38 VTPM_STATUS_RESULT = 0x4,
39 VTPM_STATUS_CANCELED = 0x8,
40};
41
42static u8 vtpm_status(struct tpm_chip *chip)
43{
1/*
2 * Implementation of the Xen vTPM device frontend
3 *
4 * Author: Daniel De Graaf <dgdegra@tycho.nsa.gov>
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 version 2,
8 * as published by the Free Software Foundation.

--- 27 unchanged lines hidden (view full) ---

36 VTPM_STATUS_RUNNING = 0x1,
37 VTPM_STATUS_IDLE = 0x2,
38 VTPM_STATUS_RESULT = 0x4,
39 VTPM_STATUS_CANCELED = 0x8,
40};
41
42static u8 vtpm_status(struct tpm_chip *chip)
43{
44 struct tpm_private *priv = TPM_VPRIV(chip);
44 struct tpm_private *priv = dev_get_drvdata(&chip->dev);
45 switch (priv->shr->state) {
46 case VTPM_STATE_IDLE:
47 return VTPM_STATUS_IDLE | VTPM_STATUS_CANCELED;
48 case VTPM_STATE_FINISH:
49 return VTPM_STATUS_IDLE | VTPM_STATUS_RESULT;
50 case VTPM_STATE_SUBMIT:
51 case VTPM_STATE_CANCEL: /* cancel requested, not yet canceled */
52 return VTPM_STATUS_RUNNING;

--- 4 unchanged lines hidden (view full) ---

57
58static bool vtpm_req_canceled(struct tpm_chip *chip, u8 status)
59{
60 return status & VTPM_STATUS_CANCELED;
61}
62
63static void vtpm_cancel(struct tpm_chip *chip)
64{
45 switch (priv->shr->state) {
46 case VTPM_STATE_IDLE:
47 return VTPM_STATUS_IDLE | VTPM_STATUS_CANCELED;
48 case VTPM_STATE_FINISH:
49 return VTPM_STATUS_IDLE | VTPM_STATUS_RESULT;
50 case VTPM_STATE_SUBMIT:
51 case VTPM_STATE_CANCEL: /* cancel requested, not yet canceled */
52 return VTPM_STATUS_RUNNING;

--- 4 unchanged lines hidden (view full) ---

57
58static bool vtpm_req_canceled(struct tpm_chip *chip, u8 status)
59{
60 return status & VTPM_STATUS_CANCELED;
61}
62
63static void vtpm_cancel(struct tpm_chip *chip)
64{
65 struct tpm_private *priv = TPM_VPRIV(chip);
65 struct tpm_private *priv = dev_get_drvdata(&chip->dev);
66 priv->shr->state = VTPM_STATE_CANCEL;
67 wmb();
68 notify_remote_via_evtchn(priv->evtchn);
69}
70
71static unsigned int shr_data_offset(struct vtpm_shared_page *shr)
72{
73 return sizeof(*shr) + sizeof(u32) * shr->nr_extra_pages;
74}
75
76static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
77{
66 priv->shr->state = VTPM_STATE_CANCEL;
67 wmb();
68 notify_remote_via_evtchn(priv->evtchn);
69}
70
71static unsigned int shr_data_offset(struct vtpm_shared_page *shr)
72{
73 return sizeof(*shr) + sizeof(u32) * shr->nr_extra_pages;
74}
75
76static int vtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
77{
78 struct tpm_private *priv = TPM_VPRIV(chip);
78 struct tpm_private *priv = dev_get_drvdata(&chip->dev);
79 struct vtpm_shared_page *shr = priv->shr;
80 unsigned int offset = shr_data_offset(shr);
81
82 u32 ordinal;
83 unsigned long duration;
84
85 if (offset > PAGE_SIZE)
86 return -EINVAL;

--- 25 unchanged lines hidden (view full) ---

112 return -ETIME;
113 }
114
115 return count;
116}
117
118static int vtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
119{
79 struct vtpm_shared_page *shr = priv->shr;
80 unsigned int offset = shr_data_offset(shr);
81
82 u32 ordinal;
83 unsigned long duration;
84
85 if (offset > PAGE_SIZE)
86 return -EINVAL;

--- 25 unchanged lines hidden (view full) ---

112 return -ETIME;
113 }
114
115 return count;
116}
117
118static int vtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
119{
120 struct tpm_private *priv = TPM_VPRIV(chip);
120 struct tpm_private *priv = dev_get_drvdata(&chip->dev);
121 struct vtpm_shared_page *shr = priv->shr;
122 unsigned int offset = shr_data_offset(shr);
123 size_t length = shr->length;
124
125 if (shr->state == VTPM_STATE_IDLE)
126 return -ECANCELED;
127
128 /* In theory the wait at the end of _send makes this one unnecessary */

--- 50 unchanged lines hidden (view full) ---

179
180 chip = tpmm_chip_alloc(dev, &tpm_vtpm);
181 if (IS_ERR(chip))
182 return PTR_ERR(chip);
183
184 init_waitqueue_head(&priv->read_queue);
185
186 priv->chip = chip;
121 struct vtpm_shared_page *shr = priv->shr;
122 unsigned int offset = shr_data_offset(shr);
123 size_t length = shr->length;
124
125 if (shr->state == VTPM_STATE_IDLE)
126 return -ECANCELED;
127
128 /* In theory the wait at the end of _send makes this one unnecessary */

--- 50 unchanged lines hidden (view full) ---

179
180 chip = tpmm_chip_alloc(dev, &tpm_vtpm);
181 if (IS_ERR(chip))
182 return PTR_ERR(chip);
183
184 init_waitqueue_head(&priv->read_queue);
185
186 priv->chip = chip;
187 TPM_VPRIV(chip) = priv;
187 dev_set_drvdata(&chip->dev, priv);
188
189 return 0;
190}
191
192/* caller must clean up in case of errors */
193static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv)
194{
195 struct xenbus_transaction xbt;

--- 119 unchanged lines hidden (view full) ---

315 tpm_get_timeouts(priv->chip);
316
317 return tpm_chip_register(priv->chip);
318}
319
320static int tpmfront_remove(struct xenbus_device *dev)
321{
322 struct tpm_chip *chip = dev_get_drvdata(&dev->dev);
188
189 return 0;
190}
191
192/* caller must clean up in case of errors */
193static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv)
194{
195 struct xenbus_transaction xbt;

--- 119 unchanged lines hidden (view full) ---

315 tpm_get_timeouts(priv->chip);
316
317 return tpm_chip_register(priv->chip);
318}
319
320static int tpmfront_remove(struct xenbus_device *dev)
321{
322 struct tpm_chip *chip = dev_get_drvdata(&dev->dev);
323 struct tpm_private *priv = TPM_VPRIV(chip);
323 struct tpm_private *priv = dev_get_drvdata(&chip->dev);
324 tpm_chip_unregister(chip);
325 ring_free(priv);
324 tpm_chip_unregister(chip);
325 ring_free(priv);
326 TPM_VPRIV(chip) = NULL;
326 dev_set_drvdata(&chip->dev, NULL);
327 return 0;
328}
329
330static int tpmfront_resume(struct xenbus_device *dev)
331{
332 /* A suspend/resume/migrate will interrupt a vTPM anyway */
333 tpmfront_remove(dev);
334 return tpmfront_probe(dev, NULL);

--- 69 unchanged lines hidden ---
327 return 0;
328}
329
330static int tpmfront_resume(struct xenbus_device *dev)
331{
332 /* A suspend/resume/migrate will interrupt a vTPM anyway */
333 tpmfront_remove(dev);
334 return tpmfront_probe(dev, NULL);

--- 69 unchanged lines hidden ---