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()
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()
269 struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); in vtpm_proxy_tpm_op_recv()
273 mutex_lock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_recv()
275 if (!(proxy_dev->state & STATE_OPENED_FLAG)) { in vtpm_proxy_tpm_op_recv()
276 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_recv()
277 return -EPIPE; in vtpm_proxy_tpm_op_recv()
280 len = proxy_dev->resp_len; in vtpm_proxy_tpm_op_recv()
282 dev_err(&chip->dev, in vtpm_proxy_tpm_op_recv()
285 len = -EIO; in vtpm_proxy_tpm_op_recv()
289 memcpy(buf, proxy_dev->buffer, len); in vtpm_proxy_tpm_op_recv()
290 proxy_dev->resp_len = 0; in vtpm_proxy_tpm_op_recv()
293 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_recv()
306 if (chip->flags & TPM_CHIP_FLAG_TPM2) { in vtpm_proxy_is_driver_command()
307 switch (be32_to_cpu(hdr->ordinal)) { in vtpm_proxy_is_driver_command()
312 switch (be32_to_cpu(hdr->ordinal)) { in vtpm_proxy_is_driver_command()
332 struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); in vtpm_proxy_tpm_op_send()
334 if (count > sizeof(proxy_dev->buffer)) { in vtpm_proxy_tpm_op_send()
335 dev_err(&chip->dev, in vtpm_proxy_tpm_op_send()
337 count, sizeof(proxy_dev->buffer)); in vtpm_proxy_tpm_op_send()
338 return -EIO; in vtpm_proxy_tpm_op_send()
341 if (!(proxy_dev->state & STATE_DRIVER_COMMAND) && in vtpm_proxy_tpm_op_send()
343 return -EFAULT; in vtpm_proxy_tpm_op_send()
345 mutex_lock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_send()
347 if (!(proxy_dev->state & STATE_OPENED_FLAG)) { in vtpm_proxy_tpm_op_send()
348 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_send()
349 return -EPIPE; in vtpm_proxy_tpm_op_send()
352 proxy_dev->resp_len = 0; in vtpm_proxy_tpm_op_send()
354 proxy_dev->req_len = count; in vtpm_proxy_tpm_op_send()
355 memcpy(proxy_dev->buffer, buf, count); in vtpm_proxy_tpm_op_send()
357 proxy_dev->state &= ~STATE_WAIT_RESPONSE_FLAG; in vtpm_proxy_tpm_op_send()
359 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_op_send()
361 wake_up_interruptible(&proxy_dev->wq); in vtpm_proxy_tpm_op_send()
373 struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); in vtpm_proxy_tpm_op_status()
375 if (proxy_dev->resp_len) in vtpm_proxy_tpm_op_status()
383 struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); in vtpm_proxy_tpm_req_canceled()
386 mutex_lock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_req_canceled()
388 ret = !(proxy_dev->state & STATE_OPENED_FLAG); in vtpm_proxy_tpm_req_canceled()
390 mutex_unlock(&proxy_dev->buf_lock); in vtpm_proxy_tpm_req_canceled()
395 static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality) in vtpm_proxy_request_locality() argument
400 struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); in vtpm_proxy_request_locality()
402 if (chip->flags & TPM_CHIP_FLAG_TPM2) in vtpm_proxy_request_locality()
410 tpm_buf_append_u8(&buf, locality); in vtpm_proxy_request_locality()
412 proxy_dev->state |= STATE_DRIVER_COMMAND; in vtpm_proxy_request_locality()
414 rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to set locality"); in vtpm_proxy_request_locality()
416 proxy_dev->state &= ~STATE_DRIVER_COMMAND; in vtpm_proxy_request_locality()
419 locality = rc; in vtpm_proxy_request_locality()
424 rc = be32_to_cpu(header->return_code); in vtpm_proxy_request_locality()
426 locality = -1; in vtpm_proxy_request_locality()
431 return locality; in vtpm_proxy_request_locality()
457 rc = tpm_chip_register(proxy_dev->chip); in vtpm_proxy_work()
461 proxy_dev->state |= STATE_REGISTERED_FLAG; in vtpm_proxy_work()
473 flush_work(&proxy_dev->work); in vtpm_proxy_work_stop()
481 queue_work(workqueue, &proxy_dev->work); in vtpm_proxy_work_start()
495 return ERR_PTR(-ENOMEM); in vtpm_proxy_create_proxy_dev()
497 init_waitqueue_head(&proxy_dev->wq); in vtpm_proxy_create_proxy_dev()
498 mutex_init(&proxy_dev->buf_lock); in vtpm_proxy_create_proxy_dev()
499 INIT_WORK(&proxy_dev->work, vtpm_proxy_work); in vtpm_proxy_create_proxy_dev()
506 dev_set_drvdata(&chip->dev, proxy_dev); in vtpm_proxy_create_proxy_dev()
508 proxy_dev->chip = chip; in vtpm_proxy_create_proxy_dev()
523 put_device(&proxy_dev->chip->dev); /* frees chip */ in vtpm_proxy_delete_proxy_dev()
540 if (vtpm_new_dev->flags & ~VTPM_PROXY_FLAGS_ALL) in vtpm_proxy_create_device()
541 return ERR_PTR(-EOPNOTSUPP); in vtpm_proxy_create_device()
547 proxy_dev->flags = vtpm_new_dev->flags; in vtpm_proxy_create_device()
549 /* setup an anonymous file for the server-side */ in vtpm_proxy_create_device()
567 if (proxy_dev->flags & VTPM_PROXY_FLAG_TPM2) in vtpm_proxy_create_device()
568 proxy_dev->chip->flags |= TPM_CHIP_FLAG_TPM2; in vtpm_proxy_create_device()
572 vtpm_new_dev->fd = fd; in vtpm_proxy_create_device()
573 vtpm_new_dev->major = MAJOR(proxy_dev->chip->dev.devt); in vtpm_proxy_create_device()
574 vtpm_new_dev->minor = MINOR(proxy_dev->chip->dev.devt); in vtpm_proxy_create_device()
575 vtpm_new_dev->tpm_num = proxy_dev->chip->dev_num; in vtpm_proxy_create_device()
602 if (proxy_dev->state & STATE_REGISTERED_FLAG) in vtpm_proxy_delete_device()
603 tpm_chip_unregister(proxy_dev->chip); in vtpm_proxy_delete_device()
613 * vtpmx_ioc_new_dev - handler for the %VTPM_PROXY_IOC_NEW_DEV ioctl
633 return -EPERM; in vtpmx_ioc_new_dev()
639 return -EFAULT; in vtpmx_ioc_new_dev()
649 return -EFAULT; in vtpmx_ioc_new_dev()
669 return -ENOIOCTLCMD; in vtpmx_fops_ioctl()
706 workqueue = create_workqueue("tpm-vtpm"); in vtpm_module_init()
709 rc = -ENOMEM; in vtpm_module_init()