forked from polarfire-soc/hart-software-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hss_init.c
220 lines (171 loc) · 5.74 KB
/
hss_init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*******************************************************************************
* Copyright 2017-2020 Microchip Corporation.
*
* SPDX-License-Identifier: MIT
*
* MPFS HSS Embedded Software
*
*/
/**
* \file HSS Software Initalization
* \brief Full System Initialization
*/
#include "config.h"
#include "hss_types.h"
#include <assert.h>
#include "hss_state_machine.h"
#include "ssmb_ipi.h"
#include "hss_debug.h"
#include "hss_registry.h"
#include "hss_atomic.h"
#include "hss_init.h"
#include "hss_version.h"
#if IS_ENABLED(CONFIG_SERVICE_TINYCLI)
# include "tinycli_service.h"
#endif
#include "csr_helper.h"
#if IS_ENABLED(CONFIG_SERVICE_BOOT)
# include "hss_boot_service.h"
#endif
#if IS_ENABLED(CONFIG_OPENSBI)
# include "sbi/riscv_asm.h"
# include "sbi/sbi_version.h"
#endif
#include "hss_sys_setup.h"
#include "mpfs_reg_map.h"
#include "hss_memcpy_via_pdma.h"
/**
* \brief Main Initialization Function
*
* All other initialization routines to be chained off this...
*/
/****************************************************************************/
#include <string.h>
#define mMEM_SIZE(REGION) (REGION##_END - REGION##_START + 1u)
extern const uint64_t __dtim_start, __dtim_end;
extern const uint64_t __e51itim_start, __e51itim_end;
extern const uint64_t __u54_1_itim_start, __u54_1_itim_end;
extern const uint64_t __u54_2_itim_start, __u54_2_itim_end;
extern const uint64_t __u54_3_itim_start, __u54_3_itim_end;
extern const uint64_t __u54_4_itim_start, __u54_4_itim_end;
extern const uint64_t __l2lim_start, __l2lim_end;
extern const uint64_t __ddr_start, __ddr_end;
#define E51_DTIM_START (&__dtim_start)
#define E51_DTIM_END (&__dtim_end)
#define E51_ITIM_START (&__e51itim_start)
#define E51_ITIM_END (&__e51itim_end)
#define U54_1_ITIM_START (&__u54_1_itim_start)
#define U54_1_ITIM_END (&__u54_1_itim_end)
#define U54_2_ITIM_START (&__u54_2_itim_start)
#define U54_2_ITIM_END (&__u54_2_itim_end)
#define U54_3_ITIM_START (&__u54_3_itim_start)
#define U54_3_ITIM_END (&__u54_3_itim_end)
#define U54_4_ITIM_START (&__u54_4_itim_start)
#define U54_4_ITIM_END (&__u54_4_itim_end)
#define L2LIM_START (&__l2lim_start)
#define L2LIM_END (&__l2lim_end)
#define L2_ZERO_DEVICE_START 0x0A000000u
#define L2_ZERO_DEVICE_END 0x0BFFFFFFu
#define DDR_START (&__ddr_start)
// can't access DDR_END without getting an error:
// R_RISCV_PCREL_HI20 against symbol `__ddr_end'
// solution is to use assembler instead as the symbol is constant at link time
//
// #define DDR_END (&__ddr_end)
asm(".align 3\n"
"hss_init_ddr_end: .quad (__ddr_end)\n"
".globl hss_init_ddr_end\n");
extern const uint64_t hss_init_ddr_end;
#define DDR_END (&hss_init_ddr_end)
#if IS_ENABLED(CONFIG_PLATFORM_MPFS)
# include "mss_sysreg.h"
#endif
#define CHUNK_SIZE 0x2000u
bool HSS_ZeroDDR(void)
{
#if IS_ENABLED(CONFIG_INITIALIZE_MEMORIES)
uint64_t volatile *pDWord = (uint64_t volatile *)DDR_START;
while (pDWord < (uint64_t volatile const * const)DDR_END) {
*pDWord = 0llu;
pDWord++;
}
#endif
mb();
mb_i();
return true;
}
/* Init memories.. */
bool HSS_ZeroTIMs(void)
{
#if IS_ENABLED(CONFIG_INITIALIZE_MEMORIES)
memset((void*)E51_DTIM_START, 0, E51_DTIM_END - E51_DTIM_START); /* 8KiB */
memset((void*)U54_1_ITIM_START, 0, U54_1_ITIM_END - U54_1_ITIM_START); /* 28KiB */
memset((void*)U54_2_ITIM_START, 0, U54_2_ITIM_END - U54_2_ITIM_START); /* 28KiB */
memset((void*)U54_3_ITIM_START, 0, U54_3_ITIM_END - U54_3_ITIM_START); /* 28KiB */
memset((void*)U54_4_ITIM_START, 0, U54_4_ITIM_END - U54_4_ITIM_START); /* 28KiB */
#endif
mb();
mb_i();
return true;
}
#include "system_startup.h"
bool HSS_Init_RWDATA_BSS(void)
{
//UART not setup at this point
//mHSS_DEBUG_PRINTF("Setting up RW Data and BSS sections" CRLF);
#if IS_ENABLED(CONFIG_PLATFORM_MPFS)
init_memory();
#endif
return true;
}
#if IS_ENABLED(CONFIG_CC_USE_GNU_BUILD_ID)
void HSS_PrintBuildId(void);
void HSS_PrintBuildId(void)
{
extern const struct {
uint32_t namesz;
uint32_t descsz;
uint32_t type;
uint8_t data[];
} gnu_build_id;
const size_t padding = sizeof(uint32_t) - 1u;
const size_t offset = (gnu_build_id.namesz + padding) & ~padding;
const uint8_t *pBuildId = (const uint8_t *)&(gnu_build_id.data[offset]);
mHSS_FANCY_PUTS(LOG_STATUS, "Build ID: ");
for (int i = 0; i < gnu_build_id.descsz; ++i) {
mHSS_PRINTF("%02x", pBuildId[i]);
}
mHSS_PRINTF(CRLF);
}
#endif
#if IS_ENABLED(CONFIG_DISPLAY_TOOL_VERSIONS)
#include "tool_versions.h"
void HSS_PrintToolVersions(void)
{
mHSS_FANCY_PUTS(LOG_STATUS, "Built with the following tools: " CRLF);
mHSS_PUTS(" - " CC_VERSION_STRING CRLF);
mHSS_PUTS(" - " LD_VERSION_STRING CRLF CRLF);
}
#endif
bool HSS_E51_Banner(void)
{
mHSS_FANCY_PRINTF(LOG_STATUS,
"PolarFire(R) SoC Hart Software Services (HSS) - version %d.%d.%d" CRLF
"(c) Copyright 2017-2020 Microchip Corporation." CRLF CRLF,
HSS_VERSION_MAJOR, HSS_VERSION_MINOR, HSS_VERSION_PATCH);
mHSS_FANCY_PRINTF(LOG_STATUS, "incorporating OpenSBI - version %d.%d" CRLF
"(c) Copyright 2019-2020 Western Digital Corporation." CRLF CRLF,
OPENSBI_VERSION_MAJOR, OPENSBI_VERSION_MINOR);
#if IS_ENABLED(CONFIG_CC_USE_GNU_BUILD_ID)
HSS_PrintBuildId();
#endif
#if IS_ENABLED(CONFIG_DISPLAY_TOOL_VERSIONS)
HSS_PrintToolVersions();
#endif
return true;
}
/****************************************************************************/
void HSS_Init(void)
{
RunInitFunctions(spanOfGlobalInitFunctions, globalInitFunctions);
}