1*3a9fd824SRoger Pau Monné /****************************************************************************** 2*3a9fd824SRoger Pau Monné * tpmif.h 3*3a9fd824SRoger Pau Monné * 4*3a9fd824SRoger Pau Monné * TPM I/O interface for Xen guest OSes. 5*3a9fd824SRoger Pau Monné * 6*3a9fd824SRoger Pau Monné * Permission is hereby granted, free of charge, to any person obtaining a copy 7*3a9fd824SRoger Pau Monné * of this software and associated documentation files (the "Software"), to 8*3a9fd824SRoger Pau Monné * deal in the Software without restriction, including without limitation the 9*3a9fd824SRoger Pau Monné * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10*3a9fd824SRoger Pau Monné * sell copies of the Software, and to permit persons to whom the Software is 11*3a9fd824SRoger Pau Monné * furnished to do so, subject to the following conditions: 12*3a9fd824SRoger Pau Monné * 13*3a9fd824SRoger Pau Monné * The above copyright notice and this permission notice shall be included in 14*3a9fd824SRoger Pau Monné * all copies or substantial portions of the Software. 15*3a9fd824SRoger Pau Monné * 16*3a9fd824SRoger Pau Monné * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17*3a9fd824SRoger Pau Monné * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18*3a9fd824SRoger Pau Monné * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19*3a9fd824SRoger Pau Monné * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20*3a9fd824SRoger Pau Monné * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21*3a9fd824SRoger Pau Monné * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22*3a9fd824SRoger Pau Monné * DEALINGS IN THE SOFTWARE. 23*3a9fd824SRoger Pau Monné * 24*3a9fd824SRoger Pau Monné * Copyright (c) 2005, IBM Corporation 25*3a9fd824SRoger Pau Monné * 26*3a9fd824SRoger Pau Monné * Author: Stefan Berger, stefanb@us.ibm.com 27*3a9fd824SRoger Pau Monné * Grant table support: Mahadevan Gomathisankaran 28*3a9fd824SRoger Pau Monné * 29*3a9fd824SRoger Pau Monné * This code has been derived from tools/libxc/xen/io/netif.h 30*3a9fd824SRoger Pau Monné * 31*3a9fd824SRoger Pau Monné * Copyright (c) 2003-2004, Keir Fraser 32*3a9fd824SRoger Pau Monné */ 33*3a9fd824SRoger Pau Monné 34*3a9fd824SRoger Pau Monné #ifndef __XEN_PUBLIC_IO_TPMIF_H__ 35*3a9fd824SRoger Pau Monné #define __XEN_PUBLIC_IO_TPMIF_H__ 36*3a9fd824SRoger Pau Monné 37*3a9fd824SRoger Pau Monné #include "../grant_table.h" 38*3a9fd824SRoger Pau Monné 39*3a9fd824SRoger Pau Monné struct tpmif_tx_request { 40*3a9fd824SRoger Pau Monné unsigned long addr; /* Machine address of packet. */ 41*3a9fd824SRoger Pau Monné grant_ref_t ref; /* grant table access reference */ 42*3a9fd824SRoger Pau Monné uint16_t unused; 43*3a9fd824SRoger Pau Monné uint16_t size; /* Packet size in bytes. */ 44*3a9fd824SRoger Pau Monné }; 45*3a9fd824SRoger Pau Monné typedef struct tpmif_tx_request tpmif_tx_request_t; 46*3a9fd824SRoger Pau Monné 47*3a9fd824SRoger Pau Monné /* 48*3a9fd824SRoger Pau Monné * The TPMIF_TX_RING_SIZE defines the number of pages the 49*3a9fd824SRoger Pau Monné * front-end and backend can exchange (= size of array). 50*3a9fd824SRoger Pau Monné */ 51*3a9fd824SRoger Pau Monné typedef uint32_t TPMIF_RING_IDX; 52*3a9fd824SRoger Pau Monné 53*3a9fd824SRoger Pau Monné #define TPMIF_TX_RING_SIZE 1 54*3a9fd824SRoger Pau Monné 55*3a9fd824SRoger Pau Monné /* This structure must fit in a memory page. */ 56*3a9fd824SRoger Pau Monné 57*3a9fd824SRoger Pau Monné struct tpmif_ring { 58*3a9fd824SRoger Pau Monné struct tpmif_tx_request req; 59*3a9fd824SRoger Pau Monné }; 60*3a9fd824SRoger Pau Monné typedef struct tpmif_ring tpmif_ring_t; 61*3a9fd824SRoger Pau Monné 62*3a9fd824SRoger Pau Monné struct tpmif_tx_interface { 63*3a9fd824SRoger Pau Monné struct tpmif_ring ring[TPMIF_TX_RING_SIZE]; 64*3a9fd824SRoger Pau Monné }; 65*3a9fd824SRoger Pau Monné typedef struct tpmif_tx_interface tpmif_tx_interface_t; 66*3a9fd824SRoger Pau Monné 67*3a9fd824SRoger Pau Monné /****************************************************************************** 68*3a9fd824SRoger Pau Monné * TPM I/O interface for Xen guest OSes, v2 69*3a9fd824SRoger Pau Monné * 70*3a9fd824SRoger Pau Monné * Author: Daniel De Graaf <dgdegra@tycho.nsa.gov> 71*3a9fd824SRoger Pau Monné * 72*3a9fd824SRoger Pau Monné * This protocol emulates the request/response behavior of a TPM using a Xen 73*3a9fd824SRoger Pau Monné * shared memory interface. All interaction with the TPM is at the direction 74*3a9fd824SRoger Pau Monné * of the frontend, since a TPM (hardware or virtual) is a passive device - 75*3a9fd824SRoger Pau Monné * the backend only processes commands as requested by the frontend. 76*3a9fd824SRoger Pau Monné * 77*3a9fd824SRoger Pau Monné * The frontend sends a request to the TPM by populating the shared page with 78*3a9fd824SRoger Pau Monné * the request packet, changing the state to TPMIF_STATE_SUBMIT, and sending 79*3a9fd824SRoger Pau Monné * and event channel notification. When the backend is finished, it will set 80*3a9fd824SRoger Pau Monné * the state to TPMIF_STATE_FINISH and send an event channel notification. 81*3a9fd824SRoger Pau Monné * 82*3a9fd824SRoger Pau Monné * In order to allow long-running commands to be canceled, the frontend can 83*3a9fd824SRoger Pau Monné * at any time change the state to TPMIF_STATE_CANCEL and send a notification. 84*3a9fd824SRoger Pau Monné * The TPM can either finish the command (changing state to TPMIF_STATE_FINISH) 85*3a9fd824SRoger Pau Monné * or can cancel the command and change the state to TPMIF_STATE_IDLE. The TPM 86*3a9fd824SRoger Pau Monné * can also change the state to TPMIF_STATE_IDLE instead of TPMIF_STATE_FINISH 87*3a9fd824SRoger Pau Monné * if another reason for cancellation is required - for example, a physical 88*3a9fd824SRoger Pau Monné * TPM may cancel a command if the interface is seized by another locality. 89*3a9fd824SRoger Pau Monné * 90*3a9fd824SRoger Pau Monné * The TPM command format is defined by the TCG, and is available at 91*3a9fd824SRoger Pau Monné * http://www.trustedcomputinggroup.org/resources/tpm_main_specification 92*3a9fd824SRoger Pau Monné */ 93*3a9fd824SRoger Pau Monné 94*3a9fd824SRoger Pau Monné enum tpmif_state { 95*3a9fd824SRoger Pau Monné TPMIF_STATE_IDLE, /* no contents / vTPM idle / cancel complete */ 96*3a9fd824SRoger Pau Monné TPMIF_STATE_SUBMIT, /* request ready / vTPM working */ 97*3a9fd824SRoger Pau Monné TPMIF_STATE_FINISH, /* response ready / vTPM idle */ 98*3a9fd824SRoger Pau Monné TPMIF_STATE_CANCEL, /* cancel requested / vTPM working */ 99*3a9fd824SRoger Pau Monné }; 100*3a9fd824SRoger Pau Monné /* Note: The backend should only change state to IDLE or FINISH, while the 101*3a9fd824SRoger Pau Monné * frontend should only change to SUBMIT or CANCEL. Status changes do not need 102*3a9fd824SRoger Pau Monné * to use atomic operations. 103*3a9fd824SRoger Pau Monné */ 104*3a9fd824SRoger Pau Monné 105*3a9fd824SRoger Pau Monné 106*3a9fd824SRoger Pau Monné /* The shared page for vTPM request/response packets looks like: 107*3a9fd824SRoger Pau Monné * 108*3a9fd824SRoger Pau Monné * Offset Contents 109*3a9fd824SRoger Pau Monné * ================================================= 110*3a9fd824SRoger Pau Monné * 0 struct tpmif_shared_page 111*3a9fd824SRoger Pau Monné * 16 [optional] List of grant IDs 112*3a9fd824SRoger Pau Monné * 16+4*nr_extra_pages TPM packet data 113*3a9fd824SRoger Pau Monné * 114*3a9fd824SRoger Pau Monné * If the TPM packet data extends beyond the end of a single page, the grant IDs 115*3a9fd824SRoger Pau Monné * defined in extra_pages are used as if they were mapped immediately following 116*3a9fd824SRoger Pau Monné * the primary shared page. The grants are allocated by the frontend and mapped 117*3a9fd824SRoger Pau Monné * by the backend. Before sending a request spanning multiple pages, the 118*3a9fd824SRoger Pau Monné * frontend should verify that the TPM supports such large requests by querying 119*3a9fd824SRoger Pau Monné * the TPM_CAP_PROP_INPUT_BUFFER property from the TPM. 120*3a9fd824SRoger Pau Monné */ 121*3a9fd824SRoger Pau Monné struct tpmif_shared_page { 122*3a9fd824SRoger Pau Monné uint32_t length; /* request/response length in bytes */ 123*3a9fd824SRoger Pau Monné 124*3a9fd824SRoger Pau Monné uint8_t state; /* enum tpmif_state */ 125*3a9fd824SRoger Pau Monné uint8_t locality; /* for the current request */ 126*3a9fd824SRoger Pau Monné uint8_t pad; /* should be zero */ 127*3a9fd824SRoger Pau Monné 128*3a9fd824SRoger Pau Monné uint8_t nr_extra_pages; /* extra pages for long packets; may be zero */ 129*3a9fd824SRoger Pau Monné uint32_t extra_pages[0]; /* grant IDs; length is actually nr_extra_pages */ 130*3a9fd824SRoger Pau Monné }; 131*3a9fd824SRoger Pau Monné typedef struct tpmif_shared_page tpmif_shared_page_t; 132*3a9fd824SRoger Pau Monné 133*3a9fd824SRoger Pau Monné #endif 134*3a9fd824SRoger Pau Monné 135*3a9fd824SRoger Pau Monné /* 136*3a9fd824SRoger Pau Monné * Local variables: 137*3a9fd824SRoger Pau Monné * mode: C 138*3a9fd824SRoger Pau Monné * c-file-style: "BSD" 139*3a9fd824SRoger Pau Monné * c-basic-offset: 4 140*3a9fd824SRoger Pau Monné * tab-width: 4 141*3a9fd824SRoger Pau Monné * indent-tabs-mode: nil 142*3a9fd824SRoger Pau Monné * End: 143*3a9fd824SRoger Pau Monné */ 144