1*399cfdd4SNicolas Le Bayon /* 2*399cfdd4SNicolas Le Bayon * Copyright (c) 2025, STMicroelectronics - All Rights Reserved 3*399cfdd4SNicolas Le Bayon * 4*399cfdd4SNicolas Le Bayon * SPDX-License-Identifier: BSD-3-Clause 5*399cfdd4SNicolas Le Bayon */ 6*399cfdd4SNicolas Le Bayon 7*399cfdd4SNicolas Le Bayon #ifndef STM32MP2_RISAF_H 8*399cfdd4SNicolas Le Bayon #define STM32MP2_RISAF_H 9*399cfdd4SNicolas Le Bayon 10*399cfdd4SNicolas Le Bayon #include <stdint.h> 11*399cfdd4SNicolas Le Bayon 12*399cfdd4SNicolas Le Bayon #include <lib/utils_def.h> 13*399cfdd4SNicolas Le Bayon 14*399cfdd4SNicolas Le Bayon /* RISAF general registers (base relative) */ 15*399cfdd4SNicolas Le Bayon #define _RISAF_CR U(0x00) 16*399cfdd4SNicolas Le Bayon #define _RISAF_SR U(0x04) 17*399cfdd4SNicolas Le Bayon #define _RISAF_KEYR U(0x30) 18*399cfdd4SNicolas Le Bayon #define _RISAF_HWCFGR U(0xFF0) 19*399cfdd4SNicolas Le Bayon 20*399cfdd4SNicolas Le Bayon /* RISAF general register field description */ 21*399cfdd4SNicolas Le Bayon /* _RISAF_CR register fields */ 22*399cfdd4SNicolas Le Bayon #define _RISAF_CR_GLOCK BIT_32(0) 23*399cfdd4SNicolas Le Bayon /* _RISAF_SR register fields */ 24*399cfdd4SNicolas Le Bayon #define _RISAF_SR_KEYVALID BIT_32(0) 25*399cfdd4SNicolas Le Bayon #define _RISAF_SR_KEYRDY BIT_32(1) 26*399cfdd4SNicolas Le Bayon #define _RISAF_SR_ENCDIS BIT_32(2) 27*399cfdd4SNicolas Le Bayon /* _RISAF_HWCFGR register fields */ 28*399cfdd4SNicolas Le Bayon #define _RISAF_HWCFGR_CFG1_SHIFT 0 29*399cfdd4SNicolas Le Bayon #define _RISAF_HWCFGR_CFG1_MASK GENMASK_32(7, 0) 30*399cfdd4SNicolas Le Bayon #define _RISAF_HWCFGR_CFG2_SHIFT 8 31*399cfdd4SNicolas Le Bayon #define _RISAF_HWCFGR_CFG2_MASK GENMASK_32(15, 8) 32*399cfdd4SNicolas Le Bayon #define _RISAF_HWCFGR_CFG3_SHIFT 16 33*399cfdd4SNicolas Le Bayon #define _RISAF_HWCFGR_CFG3_MASK GENMASK_32(23, 16) 34*399cfdd4SNicolas Le Bayon #define _RISAF_HWCFGR_CFG4_SHIFT 24 35*399cfdd4SNicolas Le Bayon #define _RISAF_HWCFGR_CFG4_MASK GENMASK_32(31, 24) 36*399cfdd4SNicolas Le Bayon 37*399cfdd4SNicolas Le Bayon /* RISAF region registers (base relative) */ 38*399cfdd4SNicolas Le Bayon #define _RISAF_REG_BASE U(0x40) 39*399cfdd4SNicolas Le Bayon #define _RISAF_REG_SIZE U(0x40) 40*399cfdd4SNicolas Le Bayon #define _RISAF_REG(n) (_RISAF_REG_BASE + (((n) - 1) * _RISAF_REG_SIZE)) 41*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CFGR_OFFSET U(0x0) 42*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CFGR(n) (_RISAF_REG(n) + _RISAF_REG_CFGR_OFFSET) 43*399cfdd4SNicolas Le Bayon #define _RISAF_REG_STARTR_OFFSET U(0x4) 44*399cfdd4SNicolas Le Bayon #define _RISAF_REG_STARTR(n) (_RISAF_REG(n) + _RISAF_REG_STARTR_OFFSET) 45*399cfdd4SNicolas Le Bayon #define _RISAF_REG_ENDR_OFFSET U(0x8) 46*399cfdd4SNicolas Le Bayon #define _RISAF_REG_ENDR(n) (_RISAF_REG(n) + _RISAF_REG_ENDR_OFFSET) 47*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CIDCFGR_OFFSET U(0xC) 48*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CIDCFGR(n) (_RISAF_REG(n) + _RISAF_REG_CIDCFGR_OFFSET) 49*399cfdd4SNicolas Le Bayon 50*399cfdd4SNicolas Le Bayon /* RISAF region register field description */ 51*399cfdd4SNicolas Le Bayon /* _RISAF_REG_CFGR(n) register fields */ 52*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CFGR_BREN_SHIFT 0 53*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CFGR_BREN BIT_32(_RISAF_REG_CFGR_BREN_SHIFT) 54*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CFGR_SEC_SHIFT 8 55*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CFGR_SEC BIT_32(_RISAF_REG_CFGR_SEC_SHIFT) 56*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CFGR_ENC_SHIFT 15 57*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CFGR_ENC BIT_32(_RISAF_REG_CFGR_ENC_SHIFT) 58*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CFGR_PRIVC_SHIFT 16 59*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CFGR_PRIVC_MASK GENMASK_32(23, 16) 60*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CFGR_ALL_MASK (_RISAF_REG_CFGR_BREN | _RISAF_REG_CFGR_SEC | \ 61*399cfdd4SNicolas Le Bayon _RISAF_REG_CFGR_ENC | _RISAF_REG_CFGR_PRIVC_MASK) 62*399cfdd4SNicolas Le Bayon /* _RISAF_REG_CIDCFGR(n) register fields */ 63*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CIDCFGR_RDENC_SHIFT 0 64*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CIDCFGR_RDENC_MASK GENMASK_32(7, 0) 65*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CIDCFGR_WRENC_SHIFT 16 66*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CIDCFGR_WRENC_MASK GENMASK_32(23, 16) 67*399cfdd4SNicolas Le Bayon #define _RISAF_REG_CIDCFGR_ALL_MASK (_RISAF_REG_CIDCFGR_RDENC_MASK | \ 68*399cfdd4SNicolas Le Bayon _RISAF_REG_CIDCFGR_WRENC_MASK) 69*399cfdd4SNicolas Le Bayon 70*399cfdd4SNicolas Le Bayon /* Device Tree related definitions */ 71*399cfdd4SNicolas Le Bayon #define DT_RISAF_COMPAT "st,stm32-risaf" 72*399cfdd4SNicolas Le Bayon #define DT_RISAF_REG_ID_MASK U(0xF) 73*399cfdd4SNicolas Le Bayon #define DT_RISAF_EN_SHIFT 5 74*399cfdd4SNicolas Le Bayon #define DT_RISAF_EN_MASK BIT_32(DT_RISAF_EN_SHIFT) 75*399cfdd4SNicolas Le Bayon #define DT_RISAF_SEC_SHIFT 6 76*399cfdd4SNicolas Le Bayon #define DT_RISAF_SEC_MASK BIT_32(DT_RISAF_SEC_SHIFT) 77*399cfdd4SNicolas Le Bayon #define DT_RISAF_ENC_SHIFT 7 78*399cfdd4SNicolas Le Bayon #define DT_RISAF_ENC_MASK BIT_32(DT_RISAF_ENC_SHIFT) 79*399cfdd4SNicolas Le Bayon #define DT_RISAF_PRIV_SHIFT 8 80*399cfdd4SNicolas Le Bayon #define DT_RISAF_PRIV_MASK GENMASK_32(15, 8) 81*399cfdd4SNicolas Le Bayon #define DT_RISAF_READ_SHIFT 16 82*399cfdd4SNicolas Le Bayon #define DT_RISAF_READ_MASK GENMASK_32(23, 16) 83*399cfdd4SNicolas Le Bayon #define DT_RISAF_WRITE_SHIFT 24 84*399cfdd4SNicolas Le Bayon #define DT_RISAF_WRITE_MASK GENMASK_32(31, 24) 85*399cfdd4SNicolas Le Bayon 86*399cfdd4SNicolas Le Bayon /* RISAF max properties */ 87*399cfdd4SNicolas Le Bayon #define RISAF_REGION_REG_SIZE (4 * sizeof(uint32_t)) 88*399cfdd4SNicolas Le Bayon #define RISAF_REGION_PROTREG_SIZE (1 * sizeof(uint32_t)) 89*399cfdd4SNicolas Le Bayon #define RISAF_TIMEOUT_1MS_IN_US U(1000) 90*399cfdd4SNicolas Le Bayon 91*399cfdd4SNicolas Le Bayon /* RISAF encryption key size in bytes */ 92*399cfdd4SNicolas Le Bayon #define RISAF_ENCRYPTION_KEY_SIZE_IN_BYTES U(16) 93*399cfdd4SNicolas Le Bayon 94*399cfdd4SNicolas Le Bayon struct stm32mp2_risaf_region { 95*399cfdd4SNicolas Le Bayon int instance; 96*399cfdd4SNicolas Le Bayon uint32_t cfg; 97*399cfdd4SNicolas Le Bayon uintptr_t addr; 98*399cfdd4SNicolas Le Bayon size_t len; 99*399cfdd4SNicolas Le Bayon }; 100*399cfdd4SNicolas Le Bayon 101*399cfdd4SNicolas Le Bayon struct stm32mp2_risaf_platdata { 102*399cfdd4SNicolas Le Bayon uintptr_t *base; 103*399cfdd4SNicolas Le Bayon unsigned long *clock; 104*399cfdd4SNicolas Le Bayon uint32_t *granularity; 105*399cfdd4SNicolas Le Bayon struct stm32mp2_risaf_region *region; 106*399cfdd4SNicolas Le Bayon int nregions; 107*399cfdd4SNicolas Le Bayon }; 108*399cfdd4SNicolas Le Bayon 109*399cfdd4SNicolas Le Bayon int stm32mp2_risaf_write_encryption_key(int instance, uint8_t *key); 110*399cfdd4SNicolas Le Bayon int stm32mp2_risaf_lock(int instance); 111*399cfdd4SNicolas Le Bayon int stm32mp2_risaf_is_locked(int instance, bool *state); 112*399cfdd4SNicolas Le Bayon int stm32mp2_risaf_init(void); 113*399cfdd4SNicolas Le Bayon 114*399cfdd4SNicolas Le Bayon #endif /* STM32MP2_RISAF_H */ 115