Sheetal Tigadoli | ad0943e | 2019-12-18 19:44:43 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016-2020, Broadcom |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef SOTP_H |
| 8 | #define SOTP_H |
| 9 | |
| 10 | #include <stddef.h> |
| 11 | #include <stdint.h> |
| 12 | |
| 13 | #include <platform_sotp.h> |
| 14 | |
| 15 | #define SOTP_ROW_NO_ECC 0 |
| 16 | #define SOTP_ROW_ECC 1 |
| 17 | |
| 18 | #define SOTP_STATUS_1 (SOTP_REGS_OTP_BASE + 0x001c) |
| 19 | #define SOTP_FAIL_BITS 0x18000000000 |
| 20 | #define SOTP_ECC_ERR_DETECT 0x8000000000000000 |
| 21 | |
| 22 | #define SOTP_REGS_SOTP_CHIP_STATES (SOTP_REGS_OTP_BASE + 0x0028) |
| 23 | #define SOTP_REGS_OTP_WR_LOCK (SOTP_REGS_OTP_BASE + 0x0038) |
| 24 | |
| 25 | #define SOTP_CHIP_STATES_MANU_DEBUG_MASK (1 << 8) |
| 26 | #define SOTP_DEVICE_SECURE_CFG0_OTP_ERASED_MASK (3 << 16) |
| 27 | #define SOTP_REGS_SOTP_CHIP_STATES_OTP_ERASED_MASK (1 << 16) |
| 28 | |
| 29 | #define SOTP_DEVICE_SECURE_CFG0_CID_MASK (3 << 2) |
| 30 | #define SOTP_DEVICE_SECURE_CFG0_AB_MASK (3 << 6) |
| 31 | #define SOTP_DEVICE_SECURE_CFG0_DEV_MASK (3 << 8) |
| 32 | |
| 33 | #define SOTP_BOOT_SOURCE_SHIFT 8 |
| 34 | /* bits 14 and 15 */ |
| 35 | #define SOTP_BOOT_SOURCE_ENABLE_MASK (0xC0 << SOTP_BOOT_SOURCE_SHIFT) |
| 36 | /* bits 8 to 13 */ |
| 37 | #define SOTP_BOOT_SOURCE_BITS0 (0x03 << SOTP_BOOT_SOURCE_SHIFT) |
| 38 | #define SOTP_BOOT_SOURCE_BITS1 (0x0C << SOTP_BOOT_SOURCE_SHIFT) |
| 39 | #define SOTP_BOOT_SOURCE_BITS2 (0x30 << SOTP_BOOT_SOURCE_SHIFT) |
| 40 | #define SOTP_BOOT_SOURCE_MASK (0x3F << SOTP_BOOT_SOURCE_SHIFT) |
| 41 | |
| 42 | #define SOTP_ATF_CFG_ROW_ID SOTP_DEVICE_SECURE_CFG2_ROW |
| 43 | /* bits 28 and 29 */ |
| 44 | #define SOTP_SBL_MASK (3 << 28) |
| 45 | /* bits 30 and 31 */ |
| 46 | #define SOTP_ATF_NVCOUNTER_ENABLE_MASK ((uint64_t)3 << 30) |
| 47 | /* bits 32 and 33 */ |
| 48 | #define SOTP_ATF_WATCHDOG_ENABLE_MASK ((uint64_t)3 << 32) |
| 49 | /* bits 34 and 35 */ |
| 50 | #define SOTP_ATF_PLL_ON ((uint64_t)3 << 34) |
| 51 | /* bits 36 and 37 */ |
| 52 | #define SOTP_ATF_RESET_RETRY ((uint64_t)3 << 36) |
| 53 | /* bits 38 to 40 */ |
| 54 | #define SOTP_ATF_LOG_LEVEL_SHIFT 38 |
| 55 | #define SOTP_ATF_LOG_LEVEL ((uint64_t)7 << SOTP_ATF_LOG_LEVEL_SHIFT) |
| 56 | |
| 57 | #define SOTP_ATF2_CFG_ROW_ID SOTP_DEVICE_SECURE_CFG3_ROW |
| 58 | /* bits 16 and 17 */ |
| 59 | #define SOTP_ROMKEY_MASK (3 << 16) |
| 60 | /* bits 18 and 19 */ |
| 61 | #define SOTP_EC_EN_MASK (3 << 18) |
| 62 | |
| 63 | #define SOTP_ENC_DEV_TYPE_AB_DEV ((uint64_t)0x19999800000) |
| 64 | #define SOTP_ENC_DEV_TYPE_MASK ((uint64_t)0x1ffff800000) |
| 65 | |
| 66 | uint64_t sotp_mem_read(uint32_t offset, uint32_t sotp_add_ecc); |
| 67 | void sotp_mem_write(uint32_t addr, uint32_t sotp_add_ecc, uint64_t wdata); |
| 68 | int sotp_read_key(uint8_t *key, size_t keysize, int start_row, int end_row); |
| 69 | int sotp_key_erased(void); |
| 70 | uint32_t sotp_redundancy_reduction(uint32_t sotp_row_data); |
| 71 | #endif |