spips
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Typedefs Groups Pages
xspips_tpm_polled_example.c File Reference

Overview

Implements a design example using the SPI driver (XSpiPs) in polled mode with a Trusted Platform Module device.

The example sends TPM commands to device based on user inputs and displays the response.

 MODIFICATION HISTORY:
 Ver   Who  Date     Changes


1.00 sg 04/02/21 Initial release 3.9 sb 07/05/23 Added support for system device-tree flow. pre 10/23/25 Fixed bug in TPM command transmission 3.14 vlt 12/18/25 Update Doxygen comments to include SDT flow details. 3.15 vn 08/26/26 Fix Doxygen warnings. 3.15 tb 09/30/26 Align Doxygen comments with AMD documentation standards

 
#include "xparameters.h"
#include "xspips.h"
#include "xil_printf.h"
#include <stdio.h>

Macros

#define TPM_SPI_SELECT   0x00
 TPM slave select. More...
 
#define XSPIPS_TPM_ACCESS   0x0000
 TPM access register. More...
 
#define XSPIPS_TPM_STS   0x0018
 TPM status register. More...
 
#define XSPIPS_TPM_DATA_FIFO   0x0024
 TPM data FIFO register. More...
 
#define XSPIPS_TPM_DID_VID   0x0F00
 TPM DID/VID register. More...
 
#define XSPIPS_TPM_RID   0x0F04
 TPM revision ID register. More...
 
#define XSPIPS_TPM_ACCESS_VALID   0x80
 Access valid bit. More...
 
#define XSPIPS_TPM_ACCESS_ACT_LOCAL   0x20
 Active locality bit. More...
 
#define XSPIPS_TPM_ACCESS_REQ_PEND   0x04
 Pending request bit. More...
 
#define XSPIPS_TPM_ACCESS_REQ_USE   0x02
 Request use bit. More...
 
#define XSPIPS_TPM_STS_VALID   0x80
 Status valid bit. More...
 
#define XSPIPS_TPM_STS_CMD_READY   0x40
 Command ready bit. More...
 
#define XSPIPS_TPM_STS_GO   0x20
 TPM go bit. More...
 
#define XSPIPS_TPM_STS_DATA_AVAIL   0x10
 Data available bit. More...
 
#define XSPIPS_TPM_STS_DATA_EXPECT   0x08
 Data expected bit. More...
 
#define XSPIPS_TPM_TX_HEAD_SIZE   4
 SPI request header size. More...
 
#define XSPIPS_TPM_RX_HEAD_SIZE   10
 TPM response header size. More...
 
#define XSPIPS_TPM_SPI_MAX_SIZE   64
 Max bytes per SPI transfer. More...
 
#define XSPIPS_TPM2_CMD_SELFTEST   0x01
 Selftest menu option. More...
 
#define XSPIPS_TPM2_CMD_STARTUP   0x02
 Startup menu option. More...
 
#define XSPIPS_TPM2_CMD_PCR_READ   0x03
 PCR read menu option. More...
 
#define XSPIPS_TPM2_CMD_PCR_RESET   0x04
 PCR reset menu option. More...
 
#define XSPIPS_TPM2_CMD_PCR_EXTEND   0x05
 PCR extend menu option. More...
 
#define XSPIPS_EXIT_CMD_LOOP   0x06
 Exit menu option. More...
 
#define XSPIPS_TPM_PCR_EXT_CMD_SIZE   33
 Size of the PCR extend command without the digest. More...
 
#define XSPIPS_TPM_SHA1_DIGEST_SIZE   20
 SHA1 digest size. More...
 
#define XSPIPS_TPM_SHA256_DIGEST_SIZE   32
 SHA256 digest size. More...
 
#define XSPIPS_TPM_RESP_MAX_SIZE   4096
 Maximum possible TPM response size in bytes. More...
 
#define XSPIPS_TPM_REQ_MAX_SIZE   1024
 Maximum possible TPM request size in bytes. More...
 

Functions

int SpiPsReadID (XSpiPs *SpiPtr)
 Reads vendor identification information. More...
 
int SpiPsTpmStatusGet (XSpiPs *SpiPtr, u8 *StatusPtr)
 Gets TPM status. More...
 
int SpiPsTpmStatusSet (XSpiPs *SpiPtr, u8 StatusVal)
 Sets the TPM status. More...
 
int SpiPsTpmAccessGet (XSpiPs *SpiPtr, u8 *AccessPtr)
 Gets TPM access configuration. More...
 
int SpiPsTpmAccessSet (XSpiPs *SpiPtr, u8 Access)
 Sets TPM access configuration. More...
 
int SpiPsTpmFifoRead (XSpiPs *SpiPtr, u8 *DataPtr, u8 ByteCount)
 Reads data from TPM FIFO. More...
 
int SpiPsTpmFifoWrite (XSpiPs *SpiPtr, u8 *DataPtr, u8 ByteCount)
 Writes the data to the TPM FIFO. More...
 
int SpiPsTpmTransfer (XSpiPs *SpiPtr, u32 Address, u8 *TxBuf, u8 *RxBuf, u16 Length)
 Transfers data to or from a TPM register. More...
 
int SpiPsTpmDataTransfer (XSpiPs *SpiPtr, u8 *TxBuf, u8 *RxBuf, u16 Txlen)
 Sends a TPM command and reads the TPM response. More...
 
int SpiPsTpmPolledExample (XSpiPs *SpiInstancePtr, UINTPTR BaseAddress)
 Illustrates how to use the XSpiPs device driver in polled mode with a TPM device. More...
 
int main (void)
 Calls the SPI TPM example. More...
 

Variables

u8 TpmTxBuffer [XSPIPS_TPM_REQ_MAX_SIZE+XSPIPS_TPM_TX_HEAD_SIZE]
 Buffer for the data sent on the SPI bus. More...
 
u8 TpmRxBuffer [XSPIPS_TPM_RESP_MAX_SIZE+XSPIPS_TPM_TX_HEAD_SIZE]
 Buffer for the data received on the SPI bus. More...
 
u8 TpmRespBuffer [XSPIPS_TPM_RESP_MAX_SIZE]
 Buffer for the TPM command response. More...