Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 1 | /* |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 2 | * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved. |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 7 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <lib/mmio.h> |
| 10 | |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 11 | #include "rcar_def.h" |
| 12 | #include "rom_api.h" |
| 13 | |
Boyan Karatotev | 7a4db8b | 2022-11-22 12:24:10 +0000 | [diff] [blame] | 14 | typedef uint32_t(*rom_secure_boot_api_f) (uint32_t key, uint32_t cert, |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 15 | rom_read_flash_f pFuncReadFlash); |
| 16 | |
| 17 | typedef uint32_t(*rom_get_lcs_api_f) (uint32_t *lcs); |
| 18 | |
| 19 | #define OLD_API_TABLE1 (0U) /* H3 Ver.1.0/Ver.1.1 */ |
| 20 | #define OLD_API_TABLE2 (1U) /* H3 Ver.2.0 */ |
| 21 | #define OLD_API_TABLE3 (2U) /* M3 Ver.1.0 */ |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 22 | #define NEW_API_TABLE (3U) /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3, D3, V3M WS2.0 */ |
| 23 | #define NEW_API_TABLE2 (4U) /* V3M WS1.0 */ |
| 24 | #define API_TABLE_MAX (5U) /* table max */ |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 25 | /* Later than H3 Ver.2.0 */ |
| 26 | |
| 27 | static uint32_t get_table_index(void) |
| 28 | { |
| 29 | uint32_t product; |
| 30 | uint32_t cut_ver; |
| 31 | uint32_t index; |
| 32 | |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 33 | product = mmio_read_32(RCAR_PRR) & PRR_PRODUCT_MASK; |
| 34 | cut_ver = mmio_read_32(RCAR_PRR) & PRR_CUT_MASK; |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 35 | |
| 36 | switch (product) { |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 37 | case PRR_PRODUCT_H3: |
| 38 | if (cut_ver == PRR_PRODUCT_10) |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 39 | index = OLD_API_TABLE1; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 40 | else if (cut_ver == PRR_PRODUCT_11) |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 41 | index = OLD_API_TABLE1; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 42 | else if (cut_ver == PRR_PRODUCT_20) |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 43 | index = OLD_API_TABLE2; |
| 44 | else |
| 45 | /* Later than H3 Ver.2.0 */ |
| 46 | index = NEW_API_TABLE; |
| 47 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 48 | case PRR_PRODUCT_M3: |
| 49 | if (cut_ver == PRR_PRODUCT_10) |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 50 | index = OLD_API_TABLE3; |
| 51 | else |
| 52 | /* M3 Ver.1.1 or later */ |
| 53 | index = NEW_API_TABLE; |
| 54 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 55 | case PRR_PRODUCT_V3M: |
| 56 | if (cut_ver == PRR_PRODUCT_10) |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 57 | /* V3M WS1.0 */ |
| 58 | index = NEW_API_TABLE2; |
| 59 | else |
| 60 | /* V3M WS2.0 or later */ |
| 61 | index = NEW_API_TABLE; |
| 62 | break; |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 63 | default: |
| 64 | index = NEW_API_TABLE; |
| 65 | break; |
| 66 | } |
| 67 | |
| 68 | return index; |
| 69 | } |
| 70 | |
Boyan Karatotev | 7a4db8b | 2022-11-22 12:24:10 +0000 | [diff] [blame] | 71 | uint32_t rcar_rom_secure_boot_api(uint32_t key, uint32_t cert, |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 72 | rom_read_flash_f read_flash) |
| 73 | { |
| 74 | static const uintptr_t rom_api_table[API_TABLE_MAX] = { |
| 75 | 0xEB10DD64U, /* H3 Ver.1.0/Ver.1.1 */ |
| 76 | 0xEB116ED4U, /* H3 Ver.2.0 */ |
| 77 | 0xEB1102FCU, /* M3 Ver.1.0 */ |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 78 | 0xEB100180U, /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3, D3, V3M WS2.0 */ |
| 79 | 0xEB110128U, /* V3M WS1.0 */ |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 80 | }; |
| 81 | rom_secure_boot_api_f secure_boot; |
| 82 | uint32_t index; |
| 83 | |
| 84 | index = get_table_index(); |
| 85 | secure_boot = (rom_secure_boot_api_f) rom_api_table[index]; |
| 86 | |
| 87 | return secure_boot(key, cert, read_flash); |
| 88 | } |
| 89 | |
| 90 | uint32_t rcar_rom_get_lcs(uint32_t *lcs) |
| 91 | { |
| 92 | static const uintptr_t rom_get_lcs_table[API_TABLE_MAX] = { |
| 93 | 0xEB10DFE0U, /* H3 Ver.1.0/Ver.1.1 */ |
| 94 | 0xEB117150U, /* H3 Ver.2.0 */ |
| 95 | 0xEB110578U, /* M3 Ver.1.0 */ |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 96 | 0xEB10018CU, /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3, D3, V3M WS2.0 */ |
| 97 | 0xEB1103A4U, /* V3M WS1.0 */ |
Jorge Ramirez-Ortiz | 83b9d1a | 2018-09-23 09:41:21 +0200 | [diff] [blame] | 98 | }; |
| 99 | rom_get_lcs_api_f get_lcs; |
| 100 | uint32_t index; |
| 101 | |
| 102 | index = get_table_index(); |
| 103 | get_lcs = (rom_get_lcs_api_f) rom_get_lcs_table[index]; |
| 104 | |
| 105 | return get_lcs(lcs); |
| 106 | } |