blob: 4eede17ce9d89ea7b6714488563b3399167652ce [file] [log] [blame]
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +02001/*
Marek Vasut9cadc782019-08-06 19:13:22 +02002 * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +02007#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <lib/mmio.h>
10
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +020011#include "rcar_def.h"
12#include "rom_api.h"
13
Boyan Karatotev7a4db8b2022-11-22 12:24:10 +000014typedef uint32_t(*rom_secure_boot_api_f) (uint32_t key, uint32_t cert,
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +020015 rom_read_flash_f pFuncReadFlash);
16
17typedef 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 Barshakf2184142018-10-30 02:06:17 +030022#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-Ortiz83b9d1a2018-09-23 09:41:21 +020025 /* Later than H3 Ver.2.0 */
26
27static uint32_t get_table_index(void)
28{
29 uint32_t product;
30 uint32_t cut_ver;
31 uint32_t index;
32
Marek Vasut9cadc782019-08-06 19:13:22 +020033 product = mmio_read_32(RCAR_PRR) & PRR_PRODUCT_MASK;
34 cut_ver = mmio_read_32(RCAR_PRR) & PRR_CUT_MASK;
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +020035
36 switch (product) {
Marek Vasut9cadc782019-08-06 19:13:22 +020037 case PRR_PRODUCT_H3:
38 if (cut_ver == PRR_PRODUCT_10)
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +020039 index = OLD_API_TABLE1;
Marek Vasut9cadc782019-08-06 19:13:22 +020040 else if (cut_ver == PRR_PRODUCT_11)
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +020041 index = OLD_API_TABLE1;
Marek Vasut9cadc782019-08-06 19:13:22 +020042 else if (cut_ver == PRR_PRODUCT_20)
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +020043 index = OLD_API_TABLE2;
44 else
45 /* Later than H3 Ver.2.0 */
46 index = NEW_API_TABLE;
47 break;
Marek Vasut9cadc782019-08-06 19:13:22 +020048 case PRR_PRODUCT_M3:
49 if (cut_ver == PRR_PRODUCT_10)
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +020050 index = OLD_API_TABLE3;
51 else
52 /* M3 Ver.1.1 or later */
53 index = NEW_API_TABLE;
54 break;
Marek Vasut9cadc782019-08-06 19:13:22 +020055 case PRR_PRODUCT_V3M:
56 if (cut_ver == PRR_PRODUCT_10)
Valentine Barshakf2184142018-10-30 02:06:17 +030057 /* 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-Ortiz83b9d1a2018-09-23 09:41:21 +020063 default:
64 index = NEW_API_TABLE;
65 break;
66 }
67
68 return index;
69}
70
Boyan Karatotev7a4db8b2022-11-22 12:24:10 +000071uint32_t rcar_rom_secure_boot_api(uint32_t key, uint32_t cert,
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +020072 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 Barshakf2184142018-10-30 02:06:17 +030078 0xEB100180U, /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3, D3, V3M WS2.0 */
79 0xEB110128U, /* V3M WS1.0 */
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +020080 };
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
90uint32_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 Barshakf2184142018-10-30 02:06:17 +030096 0xEB10018CU, /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3, D3, V3M WS2.0 */
97 0xEB1103A4U, /* V3M WS1.0 */
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +020098 };
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}