Lines Matching +full:locality +full:- +full:specific
1 // SPDX-License-Identifier: GPL-2.0-only
8 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
41 #define STATE_DRIVER_COMMAND BIT(3) /* sending a driver specific command */
62 * vtpm_proxy_fops_read - Read TPM commands on 'server side'
75 struct proxy_dev *proxy_dev = filp->private_data; in vtpm_proxy_fops_read()
79 sig = wait_event_interruptible(proxy_dev->wq, in vtpm_proxy_fops_read()
80 proxy_dev->req_len != 0 || in vtpm_proxy_fops_read()
81 !(proxy_dev->state & STATE_OPENED_FLAG)); in vtpm_proxy_fops_read()
83 return -EINTR; in vtpm_proxy_fops_read()
85 mutex_lock(&proxy_dev->buf_lock); in vtpm_proxy_fops_read()
87 if (!(proxy_dev->state & STATE_OPENED_FLAG)) { in vtpm_proxy_fops_read()
88 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_fops_read()
89 return -EPIPE; in vtpm_proxy_fops_read()
92 len = proxy_dev->req_len; in vtpm_proxy_fops_read()
94 if (count < len || len > sizeof(proxy_dev->buffer)) { in vtpm_proxy_fops_read()
95 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_fops_read()
98 return -EIO; in vtpm_proxy_fops_read()
101 rc = copy_to_user(buf, proxy_dev->buffer, len); in vtpm_proxy_fops_read()
102 memset(proxy_dev->buffer, 0, len); in vtpm_proxy_fops_read()
103 proxy_dev->req_len = 0; in vtpm_proxy_fops_read()
106 proxy_dev->state |= STATE_WAIT_RESPONSE_FLAG; in vtpm_proxy_fops_read()
108 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_fops_read()
111 return -EFAULT; in vtpm_proxy_fops_read()
117 * vtpm_proxy_fops_write - Write TPM responses on 'server side'
130 struct proxy_dev *proxy_dev = filp->private_data; in vtpm_proxy_fops_write()
132 mutex_lock(&proxy_dev->buf_lock); in vtpm_proxy_fops_write()
134 if (!(proxy_dev->state & STATE_OPENED_FLAG)) { in vtpm_proxy_fops_write()
135 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_fops_write()
136 return -EPIPE; in vtpm_proxy_fops_write()
139 if (count > sizeof(proxy_dev->buffer) || in vtpm_proxy_fops_write()
140 !(proxy_dev->state & STATE_WAIT_RESPONSE_FLAG)) { in vtpm_proxy_fops_write()
141 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_fops_write()
142 return -EIO; in vtpm_proxy_fops_write()
145 proxy_dev->state &= ~STATE_WAIT_RESPONSE_FLAG; in vtpm_proxy_fops_write()
147 proxy_dev->req_len = 0; in vtpm_proxy_fops_write()
149 if (copy_from_user(proxy_dev->buffer, buf, count)) { in vtpm_proxy_fops_write()
150 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_fops_write()
151 return -EFAULT; in vtpm_proxy_fops_write()
154 proxy_dev->resp_len = count; in vtpm_proxy_fops_write()
156 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_fops_write()
158 wake_up_interruptible(&proxy_dev->wq); in vtpm_proxy_fops_write()
164 * vtpm_proxy_fops_poll - Poll status on 'server side'
173 struct proxy_dev *proxy_dev = filp->private_data; in vtpm_proxy_fops_poll()
176 poll_wait(filp, &proxy_dev->wq, wait); in vtpm_proxy_fops_poll()
180 mutex_lock(&proxy_dev->buf_lock); in vtpm_proxy_fops_poll()
182 if (proxy_dev->req_len) in vtpm_proxy_fops_poll()
185 if (!(proxy_dev->state & STATE_OPENED_FLAG)) in vtpm_proxy_fops_poll()
188 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_fops_poll()
194 * vtpm_proxy_fops_open - Open vTPM device on 'server side'
202 struct proxy_dev *proxy_dev = filp->private_data; in vtpm_proxy_fops_open()
204 proxy_dev->state |= STATE_OPENED_FLAG; in vtpm_proxy_fops_open()
208 * vtpm_proxy_fops_undo_open - counter-part to vtpm_fops_open
215 mutex_lock(&proxy_dev->buf_lock); in vtpm_proxy_fops_undo_open()
217 proxy_dev->state &= ~STATE_OPENED_FLAG; in vtpm_proxy_fops_undo_open()
219 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_fops_undo_open()
221 /* no more TPM responses -- wake up anyone waiting for them */ in vtpm_proxy_fops_undo_open()
222 wake_up_interruptible(&proxy_dev->wq); in vtpm_proxy_fops_undo_open()
226 * vtpm_proxy_fops_release - Close 'server side'
235 struct proxy_dev *proxy_dev = filp->private_data; in vtpm_proxy_fops_release()
237 filp->private_data = NULL; in vtpm_proxy_fops_release()
268 struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); in vtpm_proxy_tpm_op_recv()
272 mutex_lock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_recv()
274 if (!(proxy_dev->state & STATE_OPENED_FLAG)) { in vtpm_proxy_tpm_op_recv()
275 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_recv()
276 return -EPIPE; in vtpm_proxy_tpm_op_recv()
279 len = proxy_dev->resp_len; in vtpm_proxy_tpm_op_recv()
281 dev_err(&chip->dev, in vtpm_proxy_tpm_op_recv()
284 len = -EIO; in vtpm_proxy_tpm_op_recv()
288 memcpy(buf, proxy_dev->buffer, len); in vtpm_proxy_tpm_op_recv()
289 proxy_dev->resp_len = 0; in vtpm_proxy_tpm_op_recv()
292 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_recv()
305 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in vtpm_proxy_is_driver_command()
306 switch (be32_to_cpu(hdr->ordinal)) { in vtpm_proxy_is_driver_command()
311 switch (be32_to_cpu(hdr->ordinal)) { in vtpm_proxy_is_driver_command()
331 struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); in vtpm_proxy_tpm_op_send()
333 if (count > sizeof(proxy_dev->buffer)) { in vtpm_proxy_tpm_op_send()
334 dev_err(&chip->dev, in vtpm_proxy_tpm_op_send()
336 count, sizeof(proxy_dev->buffer)); in vtpm_proxy_tpm_op_send()
337 return -EIO; in vtpm_proxy_tpm_op_send()
340 if (!(proxy_dev->state & STATE_DRIVER_COMMAND) && in vtpm_proxy_tpm_op_send()
342 return -EFAULT; in vtpm_proxy_tpm_op_send()
344 mutex_lock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_send()
346 if (!(proxy_dev->state & STATE_OPENED_FLAG)) { in vtpm_proxy_tpm_op_send()
347 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_send()
348 return -EPIPE; in vtpm_proxy_tpm_op_send()
351 proxy_dev->resp_len = 0; in vtpm_proxy_tpm_op_send()
353 proxy_dev->req_len = count; in vtpm_proxy_tpm_op_send()
354 memcpy(proxy_dev->buffer, buf, count); in vtpm_proxy_tpm_op_send()
356 proxy_dev->state &= ~STATE_WAIT_RESPONSE_FLAG; in vtpm_proxy_tpm_op_send()
358 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_send()
360 wake_up_interruptible(&proxy_dev->wq); in vtpm_proxy_tpm_op_send()
372 struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); in vtpm_proxy_tpm_op_status()
374 if (proxy_dev->resp_len) in vtpm_proxy_tpm_op_status()
382 struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); in vtpm_proxy_tpm_req_canceled()
385 mutex_lock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_req_canceled()
387 ret = !(proxy_dev->state & STATE_OPENED_FLAG); in vtpm_proxy_tpm_req_canceled()
389 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_req_canceled()
394 static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality) in vtpm_proxy_request_locality() argument
399 struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); in vtpm_proxy_request_locality()
401 if (chip->flags & TPM_CHIP_FLAG_TPM2) in vtpm_proxy_request_locality()
409 tpm_buf_append_u8(&buf, locality); in vtpm_proxy_request_locality()
411 proxy_dev->state |= STATE_DRIVER_COMMAND; in vtpm_proxy_request_locality()
413 rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to set locality"); in vtpm_proxy_request_locality()
415 proxy_dev->state &= ~STATE_DRIVER_COMMAND; in vtpm_proxy_request_locality()
418 locality = rc; in vtpm_proxy_request_locality()
423 rc = be32_to_cpu(header->return_code); in vtpm_proxy_request_locality()
425 locality = -1; in vtpm_proxy_request_locality()
430 return locality; in vtpm_proxy_request_locality()
456 rc = tpm_chip_register(proxy_dev->chip); in vtpm_proxy_work()
460 proxy_dev->state |= STATE_REGISTERED_FLAG; in vtpm_proxy_work()
472 flush_work(&proxy_dev->work); in vtpm_proxy_work_stop()
480 queue_work(workqueue, &proxy_dev->work); in vtpm_proxy_work_start()
494 return ERR_PTR(-ENOMEM); in vtpm_proxy_create_proxy_dev()
496 init_waitqueue_head(&proxy_dev->wq); in vtpm_proxy_create_proxy_dev()
497 mutex_init(&proxy_dev->buf_lock); in vtpm_proxy_create_proxy_dev()
498 INIT_WORK(&proxy_dev->work, vtpm_proxy_work); in vtpm_proxy_create_proxy_dev()
505 dev_set_drvdata(&chip->dev, proxy_dev); in vtpm_proxy_create_proxy_dev()
507 proxy_dev->chip = chip; in vtpm_proxy_create_proxy_dev()
522 put_device(&proxy_dev->chip->dev); /* frees chip */ in vtpm_proxy_delete_proxy_dev()
539 if (vtpm_new_dev->flags & ~VTPM_PROXY_FLAGS_ALL) in vtpm_proxy_create_device()
540 return ERR_PTR(-EOPNOTSUPP); in vtpm_proxy_create_device()
546 proxy_dev->flags = vtpm_new_dev->flags; in vtpm_proxy_create_device()
548 /* setup an anonymous file for the server-side */ in vtpm_proxy_create_device()
566 if (proxy_dev->flags & VTPM_PROXY_FLAG_TPM2) in vtpm_proxy_create_device()
567 proxy_dev->chip->flags |= TPM_CHIP_FLAG_TPM2; in vtpm_proxy_create_device()
571 vtpm_new_dev->fd = fd; in vtpm_proxy_create_device()
572 vtpm_new_dev->major = MAJOR(proxy_dev->chip->dev.devt); in vtpm_proxy_create_device()
573 vtpm_new_dev->minor = MINOR(proxy_dev->chip->dev.devt); in vtpm_proxy_create_device()
574 vtpm_new_dev->tpm_num = proxy_dev->chip->dev_num; in vtpm_proxy_create_device()
601 if (proxy_dev->state & STATE_REGISTERED_FLAG) in vtpm_proxy_delete_device()
602 tpm_chip_unregister(proxy_dev->chip); in vtpm_proxy_delete_device()
612 * vtpmx_ioc_new_dev - handler for the %VTPM_PROXY_IOC_NEW_DEV ioctl
632 return -EPERM; in vtpmx_ioc_new_dev()
638 return -EFAULT; in vtpmx_ioc_new_dev()
648 return -EFAULT; in vtpmx_ioc_new_dev()
668 return -ENOIOCTLCMD; in vtpmx_fops_ioctl()
689 workqueue = create_workqueue("tpm-vtpm"); in vtpm_module_init()
692 return -ENOMEM; in vtpm_module_init()