1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright 2022 Microsoft 4 * 5 * Definitions for the NXP LX2160A-series Security Fuse Processor (SFP) driver. 6 */ 7 8 #ifndef __DRIVERS_LS_SFP_H 9 #define __DRIVERS_LS_SFP_H 10 11 #include <drivers/ls_gpio.h> 12 #include <stdlib.h> 13 #include <tee_api_types.h> 14 15 /* SFP instruction register */ 16 /* SFP is big endian */ 17 #define SFP_INGR_PROGFB_CMD 0x2 18 #define SFP_INGR_ERROR_MASK 0x100 19 #define SFP_INGR_FUSE_TIMEOUT_US 150000 20 21 /* SFP configuration register */ 22 #define SFP_SFPCR_SB_MASK 0x20000000 23 #define SFP_SFPCR_SB_OFFSET 29 24 25 /* SFP OEM security policy register 0 */ 26 #define SFP_OSPR0_WP_MASK 0x1 27 #define SFP_OSPR0_ITS_MASK 0x4 28 #define SFP_OSPR0_ITS_OFFSET 0x2 29 30 /* SFP OEM security policy register 1 */ 31 #define SFP_OSPR1_DBLEV_MASK 0x7 32 #define SFP_OSPR1_DBLEV_OPEN 0x0 33 #define SFP_OSPR1_DBLEV_CLOSED_NOTIFY 0x1 34 #define SFP_OSPR1_DBLEV_CLOSED_SILENT 0x2 35 #define SFP_OSPR1_DBLEV_CLOSED 0x4 36 37 /** 38 * struct ls_sfp_data - Compact data struct of all SFP registers. 39 * @ingr: Instruction Register. 40 * @svhesr: Secret Value Hamming Error Status Register. 41 * @sfpcr: SFP Configuration Register. 42 * @version: SFP Version Register. 43 * @ospr0: OEM Security Policy Register 0. 44 * @ospr1: OEM Security Policy Register 1. 45 * @dcvr0: Debug Challenge Value Register 0. 46 * @dcvr1: Debug Challenge Value Register 1. 47 * @drvr0: Debug Response Value Register 0. 48 * @drvr1: Debug Response Value Register 1. 49 * @fswpr: Factory Section Write Protect Register. 50 * @fuidr0: Factory Unique ID Register 0. 51 * @fuidr1: Factory Unique ID Register 1. 52 * @isbccr: ISBC Configuration Register. 53 * @fspfr[0x3]: Factory Scratch Pad Fuse Registers. 54 * @otpmkr[0x8]: One Time Programmable Master Key. 55 * @srkhr[0x8]: Super Root Key Hash Register. 56 * @ouidr[0x5]: OEM Unique ID/Scratch Pad Fuse Registers. 57 */ 58 struct ls_sfp_data { 59 uint32_t ingr; 60 uint32_t svhesr; 61 uint32_t sfpcr; 62 uint32_t version; 63 uint32_t ospr0; 64 uint32_t ospr1; 65 uint32_t dcvr0; 66 uint32_t dcvr1; 67 uint32_t drvr0; 68 uint32_t drvr1; 69 uint32_t fswpr; 70 uint32_t fuidr0; 71 uint32_t fuidr1; 72 uint32_t isbccr; 73 uint32_t fspfr[0x3]; 74 uint32_t otpmkr[0x8]; 75 uint32_t srkhr[0x8]; 76 uint32_t ouidr[0x5]; 77 }; 78 79 /** 80 * ls_sfp_read() - Read a copy of the SFP register data if the SFP driver was 81 * successfully initialized. 82 * @data: Location to save SFP data. 83 * 84 * Return: TEE_SUCCESS or > 0 on error 85 */ 86 TEE_Result ls_sfp_read(struct ls_sfp_data *data); 87 88 /** 89 * ls_sfp_get_debug_level() - Read the last 3 bits of the SFP OSPR1 register 90 * which denotes the debug level. 91 * @dblev: Pointer location to store the read debug level. 92 * 93 * Return: TEE_SUCCESS or > 0 on error. 94 */ 95 TEE_Result ls_sfp_get_debug_level(uint32_t *dblev); 96 97 /** 98 * ls_sfp_get_its() - Read bit 29 of the SFP OSPR0 register which denotes the 99 * ITS flag. 100 * @its: Pointer location to store the ITS flag. 101 * 102 * Return: TEE_SUCCESS or > 0 on error. 103 */ 104 TEE_Result ls_sfp_get_its(uint32_t *its); 105 106 /** 107 * ls_sfp_get_ouid() - Read the SFP OUID register at the given index. 108 * @index: Index of the OUID register to read. 109 * @ouid: Pointer location to store the OIUD register value. 110 * 111 * Return: TEE_SUCCESS or > 0 on error. 112 */ 113 TEE_Result ls_sfp_get_ouid(uint32_t index, uint32_t *ouid); 114 115 /** 116 * ls_sfp_get_sb() - Read bit 2 of the SFP SFPCR register which denotes the 117 * secure boot flag. 118 * @sb: Pointer location to store the secure boot flag. 119 * 120 * Return: TEE_SUCCESS or > 0 on error. 121 */ 122 TEE_Result ls_sfp_get_sb(uint32_t *sb); 123 124 /** 125 * ls_sfp_get_srkh() - Read the SFP SRKH register at the given index. 126 * @index: Index of the SRKH register to read. 127 * @srkh: Pointer location to store the SRKH register value. 128 * 129 * Return: TEE_SUCCESS or > 0 on error. 130 */ 131 TEE_Result ls_sfp_get_srkh(uint32_t index, uint32_t *srkh); 132 133 /** 134 * ls_sfp_set_debug_level() - Set the last 3 bits of the SFP OSPR1 register 135 * which denotes the debug level. 136 * @dblev: Value to write into the SFP OSPR1 register. 137 * 138 * Return: TEE_SUCCESS or > 0 on error. 139 */ 140 TEE_Result ls_sfp_set_debug_level(uint32_t dblev); 141 142 /** 143 * ls_sfp_set_its_wp() - Set bits 29 and 31 of the SFP OSPR0 register which 144 * denote the ITS and write protect flags respectively. 145 * 146 * WARNING - Setting the ITS and write protect flags will lock the mirror 147 * registers and permanently prevent any further programming of the fuse block. 148 * The system will also be forced to always attempt to secure boot which 149 * requires signature validation and the absence of any hardware security 150 * violations when booting. 151 * 152 * Return: TEE_SUCCESS or > 0 on error. 153 */ 154 TEE_Result ls_sfp_set_its_wp(void); 155 156 /** 157 * ls_sfp_set_ouid() - Write to the SFP OUID register at the given index. 158 * @index: Index of the OUID register to write. 159 * @ouid: Value to write into the SFP OUID register. 160 * 161 * Return: TEE_SUCCESS or > 0 on error. 162 */ 163 TEE_Result ls_sfp_set_ouid(uint32_t index, uint32_t ouid); 164 165 /** 166 * ls_sfp_status() - Check if the SFP driver was initialized successfully. 167 * 168 * Return: TEE_SUCCESS or > 0 on error. 169 */ 170 TEE_Result ls_sfp_status(void); 171 172 #endif /* __DRIVERS_LS_SFP_H */ 173