Esempio n. 1
0
/*
 * Send all queued requests.
 */
static int _vtpm_send_queued(struct tpm_chip *chip)
{
	int rc;
	int error = 0;
	long flags;
	unsigned char buffer[1];
	struct vtpm_state *vtpms;
	vtpms = (struct vtpm_state *)chip_get_private(chip);

	spin_lock_irqsave(&vtpms->req_list_lock, flags);

	while (!list_empty(&vtpms->queued_requests)) {
		/*
		 * Need to dequeue them.
		 * Read the result into a dummy buffer.
		 */
		struct transmission *qt = (struct transmission *)
		                          vtpms->queued_requests.next;
		list_del(&qt->next);
		vtpms->current_request = qt;
		spin_unlock_irqrestore(&vtpms->req_list_lock, flags);

		rc = vtpm_vd_send(vtpms->tpm_private,
		                  qt->request,
		                  qt->request_len,
		                  qt);

		if (rc < 0) {
			spin_lock_irqsave(&vtpms->req_list_lock, flags);
			if ((qt = vtpms->current_request) != NULL) {
				/*
				 * requeue it at the beginning
				 * of the list
				 */
				list_add(&qt->next,
				         &vtpms->queued_requests);
			}
			vtpms->current_request = NULL;
			error = 1;
			break;
		}
		/*
		 * After this point qt is not valid anymore!
		 * It is freed when the front-end is delivering
		 * the data by calling tpm_recv
		 */
		/*
		 * Receive response into provided dummy buffer
		 */
		rc = vtpm_recv(chip, buffer, sizeof(buffer));
		spin_lock_irqsave(&vtpms->req_list_lock, flags);
	}

	spin_unlock_irqrestore(&vtpms->req_list_lock, flags);

	return error;
}
static int tpm_xenstubdoms_unix_transfer(const TPMLocality *locty_data)
{
    size_t rlen;
    struct XenDevice *xendev;

    xendev = xen_find_xendev("vtpm", xen_domid, xenstore_dev);
    if (xendev == NULL) {
        xen_be_printf(xendev, 0, "Con not find vtpm device\n");
        return -1;
    }
    vtpm_send(xendev, locty_data->w_buffer.buffer, locty_data->w_offset);
    vtpm_recv(xendev, locty_data->r_buffer.buffer, &rlen);
    return 0;
}