1181624Skmacy/******************************************************************************
2181624Skmacy * tpmif.h
3181624Skmacy *
4181624Skmacy * TPM I/O interface for Xen guest OSes.
5181624Skmacy *
6181624Skmacy * Permission is hereby granted, free of charge, to any person obtaining a copy
7181624Skmacy * of this software and associated documentation files (the "Software"), to
8181624Skmacy * deal in the Software without restriction, including without limitation the
9181624Skmacy * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10181624Skmacy * sell copies of the Software, and to permit persons to whom the Software is
11181624Skmacy * furnished to do so, subject to the following conditions:
12181624Skmacy *
13181624Skmacy * The above copyright notice and this permission notice shall be included in
14181624Skmacy * all copies or substantial portions of the Software.
15181624Skmacy *
16181624Skmacy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17181624Skmacy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18181624Skmacy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19181624Skmacy * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20181624Skmacy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21181624Skmacy * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22181624Skmacy * DEALINGS IN THE SOFTWARE.
23181624Skmacy *
24181624Skmacy * Copyright (c) 2005, IBM Corporation
25181624Skmacy *
26181624Skmacy * Author: Stefan Berger, stefanb@us.ibm.com
27181624Skmacy * Grant table support: Mahadevan Gomathisankaran
28181624Skmacy *
29181624Skmacy * This code has been derived from tools/libxc/xen/io/netif.h
30181624Skmacy *
31181624Skmacy * Copyright (c) 2003-2004, Keir Fraser
32181624Skmacy */
33181624Skmacy
34181624Skmacy#ifndef __XEN_PUBLIC_IO_TPMIF_H__
35181624Skmacy#define __XEN_PUBLIC_IO_TPMIF_H__
36181624Skmacy
37181624Skmacy#include "../grant_table.h"
38181624Skmacy
39181624Skmacystruct tpmif_tx_request {
40181624Skmacy    unsigned long addr;   /* Machine address of packet.   */
41181624Skmacy    grant_ref_t ref;      /* grant table access reference */
42181624Skmacy    uint16_t unused;
43181624Skmacy    uint16_t size;        /* Packet size in bytes.        */
44181624Skmacy};
45181624Skmacytypedef struct tpmif_tx_request tpmif_tx_request_t;
46181624Skmacy
47181624Skmacy/*
48181624Skmacy * The TPMIF_TX_RING_SIZE defines the number of pages the
49181624Skmacy * front-end and backend can exchange (= size of array).
50181624Skmacy */
51181624Skmacytypedef uint32_t TPMIF_RING_IDX;
52181624Skmacy
53181624Skmacy#define TPMIF_TX_RING_SIZE 1
54181624Skmacy
55181624Skmacy/* This structure must fit in a memory page. */
56181624Skmacy
57181624Skmacystruct tpmif_ring {
58181624Skmacy    struct tpmif_tx_request req;
59181624Skmacy};
60181624Skmacytypedef struct tpmif_ring tpmif_ring_t;
61181624Skmacy
62181624Skmacystruct tpmif_tx_interface {
63181624Skmacy    struct tpmif_ring ring[TPMIF_TX_RING_SIZE];
64181624Skmacy};
65181624Skmacytypedef struct tpmif_tx_interface tpmif_tx_interface_t;
66181624Skmacy
67288917Sroyger/******************************************************************************
68288917Sroyger * TPM I/O interface for Xen guest OSes, v2
69288917Sroyger *
70288917Sroyger * Author: Daniel De Graaf <dgdegra@tycho.nsa.gov>
71288917Sroyger *
72288917Sroyger * This protocol emulates the request/response behavior of a TPM using a Xen
73288917Sroyger * shared memory interface. All interaction with the TPM is at the direction
74288917Sroyger * of the frontend, since a TPM (hardware or virtual) is a passive device -
75288917Sroyger * the backend only processes commands as requested by the frontend.
76288917Sroyger *
77288917Sroyger * The frontend sends a request to the TPM by populating the shared page with
78288917Sroyger * the request packet, changing the state to TPMIF_STATE_SUBMIT, and sending
79288917Sroyger * and event channel notification. When the backend is finished, it will set
80288917Sroyger * the state to TPMIF_STATE_FINISH and send an event channel notification.
81288917Sroyger *
82288917Sroyger * In order to allow long-running commands to be canceled, the frontend can
83288917Sroyger * at any time change the state to TPMIF_STATE_CANCEL and send a notification.
84288917Sroyger * The TPM can either finish the command (changing state to TPMIF_STATE_FINISH)
85288917Sroyger * or can cancel the command and change the state to TPMIF_STATE_IDLE. The TPM
86288917Sroyger * can also change the state to TPMIF_STATE_IDLE instead of TPMIF_STATE_FINISH
87288917Sroyger * if another reason for cancellation is required - for example, a physical
88288917Sroyger * TPM may cancel a command if the interface is seized by another locality.
89288917Sroyger *
90288917Sroyger * The TPM command format is defined by the TCG, and is available at
91288917Sroyger * http://www.trustedcomputinggroup.org/resources/tpm_main_specification
92288917Sroyger */
93288917Sroyger
94288917Sroygerenum tpmif_state {
95288917Sroyger    TPMIF_STATE_IDLE,        /* no contents / vTPM idle / cancel complete */
96288917Sroyger    TPMIF_STATE_SUBMIT,      /* request ready / vTPM working */
97288917Sroyger    TPMIF_STATE_FINISH,      /* response ready / vTPM idle */
98288917Sroyger    TPMIF_STATE_CANCEL,      /* cancel requested / vTPM working */
99288917Sroyger};
100288917Sroyger/* Note: The backend should only change state to IDLE or FINISH, while the
101288917Sroyger * frontend should only change to SUBMIT or CANCEL. Status changes do not need
102288917Sroyger * to use atomic operations.
103288917Sroyger */
104288917Sroyger
105288917Sroyger
106288917Sroyger/* The shared page for vTPM request/response packets looks like:
107288917Sroyger *
108288917Sroyger *  Offset               Contents
109288917Sroyger *  =================================================
110288917Sroyger *  0                    struct tpmif_shared_page
111288917Sroyger *  16                   [optional] List of grant IDs
112288917Sroyger *  16+4*nr_extra_pages  TPM packet data
113288917Sroyger *
114288917Sroyger * If the TPM packet data extends beyond the end of a single page, the grant IDs
115288917Sroyger * defined in extra_pages are used as if they were mapped immediately following
116288917Sroyger * the primary shared page. The grants are allocated by the frontend and mapped
117288917Sroyger * by the backend. Before sending a request spanning multiple pages, the
118288917Sroyger * frontend should verify that the TPM supports such large requests by querying
119288917Sroyger * the TPM_CAP_PROP_INPUT_BUFFER property from the TPM.
120288917Sroyger */
121288917Sroygerstruct tpmif_shared_page {
122288917Sroyger    uint32_t length;         /* request/response length in bytes */
123288917Sroyger
124288917Sroyger    uint8_t state;           /* enum tpmif_state */
125288917Sroyger    uint8_t locality;        /* for the current request */
126288917Sroyger    uint8_t pad;             /* should be zero */
127288917Sroyger
128288917Sroyger    uint8_t nr_extra_pages;  /* extra pages for long packets; may be zero */
129288917Sroyger    uint32_t extra_pages[0]; /* grant IDs; length is actually nr_extra_pages */
130288917Sroyger};
131288917Sroygertypedef struct tpmif_shared_page tpmif_shared_page_t;
132288917Sroyger
133181624Skmacy#endif
134181624Skmacy
135181624Skmacy/*
136181624Skmacy * Local variables:
137181624Skmacy * mode: C
138288917Sroyger * c-file-style: "BSD"
139181624Skmacy * c-basic-offset: 4
140181624Skmacy * tab-width: 4
141181624Skmacy * indent-tabs-mode: nil
142181624Skmacy * End:
143181624Skmacy */
144