Lines Matching +full:no +full:- +full:tick +full:- +full:in +full:- +full:suspend
1 /*-
6 * Redistribution and use in source and binary forms, with or without
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48 static int tpm20_save_state(device_t dev, bool suspend);
74 sc = (struct tpm_sc *)dev->si_drv1; in tpm20_read()
76 callout_stop(&sc->discard_buffer_callout); in tpm20_read()
77 sx_xlock(&sc->dev_lock); in tpm20_read()
78 if (sc->owner_tid != uio->uio_td->td_tid) { in tpm20_read()
79 sx_xunlock(&sc->dev_lock); in tpm20_read()
83 bytes_to_transfer = MIN(sc->pending_data_length, uio->uio_resid); in tpm20_read()
84 offset = sc->total_length - sc->pending_data_length; in tpm20_read()
86 result = uiomove((caddr_t) sc->buf + offset, bytes_to_transfer, uio); in tpm20_read()
87 sc->pending_data_length -= bytes_to_transfer; in tpm20_read()
88 cv_signal(&sc->buf_cv); in tpm20_read()
93 sx_xunlock(&sc->dev_lock); in tpm20_read()
105 sc = (struct tpm_sc *)dev->si_drv1; in tpm20_write()
107 byte_count = uio->uio_resid; in tpm20_write()
109 device_printf(sc->dev, in tpm20_write()
115 device_printf(sc->dev, in tpm20_write()
120 sx_xlock(&sc->dev_lock); in tpm20_write()
122 while (sc->pending_data_length != 0) in tpm20_write()
123 cv_wait(&sc->buf_cv, &sc->dev_lock); in tpm20_write()
125 result = uiomove(sc->buf, byte_count, uio); in tpm20_write()
127 sx_xunlock(&sc->dev_lock); in tpm20_write()
131 result = TPM_TRANSMIT(sc->dev, byte_count); in tpm20_write()
134 callout_reset(&sc->discard_buffer_callout, in tpm20_write()
135 TPM_READ_TIMEOUT / tick, tpm20_discard_buffer, sc); in tpm20_write()
136 sc->owner_tid = uio->uio_td->td_tid; in tpm20_write()
139 sx_xunlock(&sc->dev_lock); in tpm20_write()
149 if (callout_pending(&sc->discard_buffer_callout)) in tpm20_discard_buffer()
152 sx_xlock(&sc->dev_lock); in tpm20_discard_buffer()
154 memset(sc->buf, 0, TPM_BUFSIZE); in tpm20_discard_buffer()
155 sc->pending_data_length = 0; in tpm20_discard_buffer()
156 sc->total_length = 0; in tpm20_discard_buffer()
158 cv_signal(&sc->buf_cv); in tpm20_discard_buffer()
159 sx_xunlock(&sc->dev_lock); in tpm20_discard_buffer()
161 device_printf(sc->dev, in tpm20_discard_buffer()
162 "User failed to read buffer in time\n"); in tpm20_discard_buffer()
193 cv_init(&sc->buf_cv, "TPM buffer cv"); in tpm20_init()
194 callout_init(&sc->discard_buffer_callout, 1); in tpm20_init()
195 sc->pending_data_length = 0; in tpm20_init()
196 sc->total_length = 0; in tpm20_init()
204 result = make_dev_s(&args, &sc->sc_cdev, TPM_CDEV_NAME); in tpm20_init()
210 TIMEOUT_TASK_INIT(taskqueue_thread, &sc->harvest_task, 0, in tpm20_init()
212 taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task, 0); in tpm20_init()
224 if (device_is_attached(sc->dev)) in tpm20_release()
225 taskqueue_drain_timeout(taskqueue_thread, &sc->harvest_task); in tpm20_release()
229 if (sc->buf != NULL) in tpm20_release()
230 free(sc->buf, M_TPM20); in tpm20_release()
232 sx_destroy(&sc->dev_lock); in tpm20_release()
233 cv_destroy(&sc->buf_cv); in tpm20_release()
234 if (sc->sc_cdev != NULL) in tpm20_release()
235 destroy_dev(sc->sc_cdev); in tpm20_release()
270 sx_xlock(&sc->dev_lock); in tpm20_harvest()
271 while (sc->pending_data_length != 0) in tpm20_harvest()
272 cv_wait(&sc->buf_cv, &sc->dev_lock); in tpm20_harvest()
274 memcpy(sc->buf, cmd, sizeof(cmd)); in tpm20_harvest()
275 result = TPM_TRANSMIT(sc->dev, sizeof(cmd)); in tpm20_harvest()
277 sx_xunlock(&sc->dev_lock); in tpm20_harvest()
282 sc->pending_data_length = 0; in tpm20_harvest()
283 sc->total_length = 0; in tpm20_harvest()
286 entropy_size = (uint16_t) sc->buf[TPM_HEADER_SIZE + 1]; in tpm20_harvest()
290 sc->buf + TPM_HEADER_SIZE + sizeof(uint16_t), in tpm20_harvest()
294 sx_xunlock(&sc->dev_lock); in tpm20_harvest()
298 taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task, in tpm20_harvest()
304 tpm20_save_state(device_t dev, bool suspend) in tpm20_save_state() argument
317 * Inform the TPM whether we are going to suspend or reboot/shutdown. in tpm20_save_state()
319 if (suspend) in tpm20_save_state()
322 if (sc == NULL || sc->buf == NULL) in tpm20_save_state()
325 sx_xlock(&sc->dev_lock); in tpm20_save_state()
327 memcpy(sc->buf, save_cmd, sizeof(save_cmd)); in tpm20_save_state()
328 TPM_TRANSMIT(sc->dev, sizeof(save_cmd)); in tpm20_save_state()
330 sx_xunlock(&sc->dev_lock); in tpm20_save_state()