riscv: Add option to print registers on exception
[oweals/u-boot.git] / include / init.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * (C) Copyright 2000-2009
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  *
6  * Copy the startup prototype, previously defined in common.h
7  * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
8  */
9
10 #ifndef __INIT_H_
11 #define __INIT_H_       1
12
13 #include <linux/types.h>
14
15 struct global_data;
16
17 #ifndef __ASSEMBLY__            /* put C only stuff in this section */
18
19 /* Avoid using CONFIG_EFI_STUB directly as we may boot from other loaders */
20 #ifdef CONFIG_EFI_STUB
21 #define ll_boot_init()  false
22 #else
23 #define ll_boot_init()  true
24 #endif
25
26 /*
27  * Function Prototypes
28  */
29
30 /* common/board_f.c */
31 void board_init_f(ulong dummy);
32
33 /**
34  * arch_cpu_init() - basic cpu-dependent setup for an architecture
35  *
36  * This is called after early malloc is available. It should handle any
37  * CPU- or SoC- specific init needed to continue the init sequence. See
38  * board_f.c for where it is called. If this is not provided, a default
39  * version (which does nothing) will be used.
40  *
41  * Return: 0 on success, otherwise error
42  */
43 int arch_cpu_init(void);
44
45 /**
46  * arch_cpu_init_dm() - init CPU after driver model is available
47  *
48  * This is called immediately after driver model is available before
49  * relocation. This is similar to arch_cpu_init() but is able to reference
50  * devices
51  *
52  * Return: 0 if OK, -ve on error
53  */
54 int arch_cpu_init_dm(void);
55
56 /**
57  * mach_cpu_init() - SoC/machine dependent CPU setup
58  *
59  * This is called after arch_cpu_init(). It should handle any
60  * SoC or machine specific init needed to continue the init sequence. See
61  * board_f.c for where it is called. If this is not provided, a default
62  * version (which does nothing) will be used.
63  *
64  * Return: 0 on success, otherwise error
65  */
66 int mach_cpu_init(void);
67
68 /**
69  * arch_fsp_init() - perform firmware support package init
70  *
71  * Where U-Boot relies on binary blobs to handle part of the system init, this
72  * function can be used to set up the blobs. This is used on some Intel
73  * platforms.
74  *
75  * Return: 0
76  */
77 int arch_fsp_init(void);
78
79 /**
80  * arch_fsp_init() - perform post-relocation firmware support package init
81  *
82  * Where U-Boot relies on binary blobs to handle part of the system init, this
83  * function can be used to set up the blobs. This is used on some Intel
84  * platforms.
85  *
86  * Return: 0
87  */
88 int arch_fsp_init_r(void);
89
90 int dram_init(void);
91
92 /**
93  * dram_init_banksize() - Set up DRAM bank sizes
94  *
95  * This can be implemented by boards to set up the DRAM bank information in
96  * gd->bd->bi_dram(). It is called just before relocation, after dram_init()
97  * is called.
98  *
99  * If this is not provided, a default implementation will try to set up a
100  * single bank. It will do this if CONFIG_NR_DRAM_BANKS and
101  * CONFIG_SYS_SDRAM_BASE are set. The bank will have a start address of
102  * CONFIG_SYS_SDRAM_BASE and the size will be determined by a call to
103  * get_effective_memsize().
104  *
105  * Return: 0 if OK, -ve on error
106  */
107 int dram_init_banksize(void);
108
109 long get_ram_size(long *base, long size);
110 phys_size_t get_effective_memsize(void);
111
112 int testdram(void);
113
114 /**
115  * arch_reserve_stacks() - Reserve all necessary stacks
116  *
117  * This is used in generic board init sequence in common/board_f.c. Each
118  * architecture could provide this function to tailor the required stacks.
119  *
120  * On entry gd->start_addr_sp is pointing to the suggested top of the stack.
121  * The callee ensures gd->start_add_sp is 16-byte aligned, so architectures
122  * require only this can leave it untouched.
123  *
124  * On exit gd->start_addr_sp and gd->irq_sp should be set to the respective
125  * positions of the stack. The stack pointer(s) will be set to this later.
126  * gd->irq_sp is only required, if the architecture needs it.
127  *
128  * Return: 0 if no error
129  */
130 int arch_reserve_stacks(void);
131
132 /**
133  * init_cache_f_r() - Turn on the cache in preparation for relocation
134  *
135  * Return: 0 if OK, -ve on error
136  */
137 int init_cache_f_r(void);
138
139 #if !CONFIG_IS_ENABLED(CPU)
140 /**
141  * print_cpuinfo() - Display information about the CPU
142  *
143  * Return: 0 if OK, -ve on error
144  */
145 int print_cpuinfo(void);
146 #endif
147 int timer_init(void);
148 int reserve_mmu(void);
149 int misc_init_f(void);
150
151 #if defined(CONFIG_DTB_RESELECT)
152 int embedded_dtb_select(void);
153 #endif
154
155 /* common/init/board_init.c */
156 extern ulong monitor_flash_len;
157
158 /**
159  * ulong board_init_f_alloc_reserve - allocate reserved area
160  * @top: top of the reserve area, growing down.
161  *
162  * This function is called by each architecture very early in the start-up
163  * code to allow the C runtime to reserve space on the stack for writable
164  * 'globals' such as GD and the malloc arena.
165  *
166  * Return: bottom of reserved area
167  */
168 ulong board_init_f_alloc_reserve(ulong top);
169
170 /**
171  * board_init_f_init_reserve - initialize the reserved area(s)
172  * @base:       top from which reservation was done
173  *
174  * This function is called once the C runtime has allocated the reserved
175  * area on the stack. It must initialize the GD at the base of that area.
176  */
177 void board_init_f_init_reserve(ulong base);
178
179 struct global_data;
180
181 /**
182  * arch_setup_gd() - Set up the global_data pointer
183  * @gd_ptr: Pointer to global data
184  *
185  * This pointer is special in some architectures and cannot easily be assigned
186  * to. For example on x86 it is implemented by adding a specific record to its
187  * Global Descriptor Table! So we we provide a function to carry out this task.
188  * For most architectures this can simply be:
189  *
190  *    gd = gd_ptr;
191  */
192 void arch_setup_gd(struct global_data *gd_ptr);
193
194 /* common/board_r.c */
195 void board_init_r(struct global_data *id, ulong dest_addr)
196         __attribute__ ((noreturn));
197
198 int cpu_init_r(void);
199 int last_stage_init(void);
200 int mac_read_from_eeprom(void);
201 int set_cpu_clk_info(void);
202 int update_flash_size(int flash_size);
203 int arch_early_init_r(void);
204 void pci_init(void);
205 int misc_init_r(void);
206 #if defined(CONFIG_VID)
207 int init_func_vid(void);
208 #endif
209
210 /* common/board_info.c */
211 int checkboard(void);
212 int show_board_info(void);
213
214 /**
215  * Get the uppermost pointer that is valid to access
216  *
217  * Some systems may not map all of their address space. This function allows
218  * boards to indicate what their highest support pointer value is for DRAM
219  * access.
220  *
221  * @param total_size    Size of U-Boot (unused?)
222  */
223 ulong board_get_usable_ram_top(ulong total_size);
224
225 int board_early_init_f(void);
226
227 /* manipulate the U-Boot fdt before its relocation */
228 int board_fix_fdt(void *rw_fdt_blob);
229 int board_late_init(void);
230 int board_postclk_init(void); /* after clocks/timebase, before env/serial */
231 int board_early_init_r(void);
232
233 /* TODO(sjg@chromium.org): Drop this when DM_PCI migration is completed */
234 void pci_init_board(void);
235
236 void trap_init(unsigned long reloc_addr);
237
238 /**
239  * main_loop() - Enter the main loop of U-Boot
240  *
241  * This normally runs the command line.
242  */
243 void main_loop(void);
244
245 #if defined(CONFIG_ARM)
246 void relocate_code(ulong addr_moni);
247 #else
248 void relocate_code(ulong start_addr_sp, struct global_data *new_gd,
249                    ulong relocaddr)
250         __attribute__ ((noreturn));
251 #endif
252
253 #endif  /* __ASSEMBLY__ */
254 /* Put only stuff here that the assembler can digest */
255
256 #endif  /* __INIT_H_ */