blob: c14de55b6a314b614c4efab13d4deee6dcc6f408 [file] [log] [blame]
Jorge Ramirez-Ortiz83b9d1a2018-09-23 09:41:21 +02001/*
2 * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <mmio.h>
8#include <stdint.h>
9#include "rcar_def.h"
10#include "rom_api.h"
11
12typedef uint32_t(*rom_secure_boot_api_f) (uint32_t *key, uint32_t *cert,
13 rom_read_flash_f pFuncReadFlash);
14
15typedef uint32_t(*rom_get_lcs_api_f) (uint32_t *lcs);
16
17#define OLD_API_TABLE1 (0U) /* H3 Ver.1.0/Ver.1.1 */
18#define OLD_API_TABLE2 (1U) /* H3 Ver.2.0 */
19#define OLD_API_TABLE3 (2U) /* M3 Ver.1.0 */
20#define NEW_API_TABLE (3U) /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3 */
21#define API_TABLE_MAX (4U) /* table max */
22 /* Later than H3 Ver.2.0 */
23
24static uint32_t get_table_index(void)
25{
26 uint32_t product;
27 uint32_t cut_ver;
28 uint32_t index;
29
30 product = mmio_read_32(RCAR_PRR) & RCAR_PRODUCT_MASK;
31 cut_ver = mmio_read_32(RCAR_PRR) & RCAR_CUT_MASK;
32
33 switch (product) {
34 case RCAR_PRODUCT_H3:
35 if (cut_ver == RCAR_CUT_VER10)
36 index = OLD_API_TABLE1;
37 else if (cut_ver == RCAR_CUT_VER11)
38 index = OLD_API_TABLE1;
39 else if (cut_ver == RCAR_CUT_VER20)
40 index = OLD_API_TABLE2;
41 else
42 /* Later than H3 Ver.2.0 */
43 index = NEW_API_TABLE;
44 break;
45 case RCAR_PRODUCT_M3:
46 if (cut_ver == RCAR_CUT_VER10)
47 index = OLD_API_TABLE3;
48 else
49 /* M3 Ver.1.1 or later */
50 index = NEW_API_TABLE;
51 break;
52 default:
53 index = NEW_API_TABLE;
54 break;
55 }
56
57 return index;
58}
59
60uint32_t rcar_rom_secure_boot_api(uint32_t *key, uint32_t *cert,
61 rom_read_flash_f read_flash)
62{
63 static const uintptr_t rom_api_table[API_TABLE_MAX] = {
64 0xEB10DD64U, /* H3 Ver.1.0/Ver.1.1 */
65 0xEB116ED4U, /* H3 Ver.2.0 */
66 0xEB1102FCU, /* M3 Ver.1.0 */
67 0xEB100180U /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3 */
68 };
69 rom_secure_boot_api_f secure_boot;
70 uint32_t index;
71
72 index = get_table_index();
73 secure_boot = (rom_secure_boot_api_f) rom_api_table[index];
74
75 return secure_boot(key, cert, read_flash);
76}
77
78uint32_t rcar_rom_get_lcs(uint32_t *lcs)
79{
80 static const uintptr_t rom_get_lcs_table[API_TABLE_MAX] = {
81 0xEB10DFE0U, /* H3 Ver.1.0/Ver.1.1 */
82 0xEB117150U, /* H3 Ver.2.0 */
83 0xEB110578U, /* M3 Ver.1.0 */
84 0xEB10018CU /* H3 Ver.3.0, M3 Ver.1.1 or later, M3N, E3 */
85 };
86 rom_get_lcs_api_f get_lcs;
87 uint32_t index;
88
89 index = get_table_index();
90 get_lcs = (rom_get_lcs_api_f) rom_get_lcs_table[index];
91
92 return get_lcs(lcs);
93}