1 /*
2  * Copyright (C) 2013, Intel Corporation
3  * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
4  *
5  * SPDX-License-Identifier:	Intel
6  */
7 
8 #ifndef __FSP_SUPPORT_H__
9 #define __FSP_SUPPORT_H__
10 
11 #include "fsp_types.h"
12 #include "fsp_fv.h"
13 #include "fsp_ffs.h"
14 #include "fsp_api.h"
15 #include "fsp_hob.h"
16 #include "fsp_infoheader.h"
17 #include "fsp_bootmode.h"
18 #include <asm/arch/fsp/fsp_vpd.h>
19 #include <asm/arch/fsp/fsp_configs.h>
20 
21 #define FSP_LOWMEM_BASE		0x100000UL
22 #define FSP_HIGHMEM_BASE	0x100000000ULL
23 #define UPD_TERMINATOR		0x55AA
24 
25 
26 /**
27  * FSP Continuation assembly helper routine
28  *
29  * This routine jumps to the C version of FSP continuation function
30  */
31 void asm_continuation(void);
32 
33 /**
34  * FSP initialization complete
35  *
36  * This is the function that indicates FSP initialization is complete and jumps
37  * back to the bootloader with HOB list pointer as the parameter.
38  *
39  * @hob_list:    HOB list pointer
40  */
41 void fsp_init_done(void *hob_list);
42 
43 /**
44  * FSP Continuation function
45  *
46  * @status:      Always 0
47  * @hob_list:    HOB list pointer
48  *
49  * @retval:      Never returns
50  */
51 void fsp_continue(u32 status, void *hob_list);
52 
53 /**
54  * Find FSP header offset in FSP image
55  *
56  * @retval: the offset of FSP header. If signature is invalid, returns 0.
57  */
58 struct fsp_header *find_fsp_header(void);
59 
60 /**
61  * FSP initialization wrapper function.
62  *
63  * @stack_top: bootloader stack top address
64  * @boot_mode: boot mode defined in fsp_bootmode.h
65  * @nvs_buf:   Non-volatile memory buffer pointer
66  */
67 void fsp_init(u32 stack_top, u32 boot_mode, void *nvs_buf);
68 
69 /**
70  * FSP notification wrapper function
71  *
72  * @fsp_hdr: Pointer to FSP information header
73  * @phase:   FSP initialization phase defined in enum fsp_phase
74  *
75  * @retval:  compatible status code with EFI_STATUS defined in PI spec
76  */
77 u32 fsp_notify(struct fsp_header *fsp_hdr, u32 phase);
78 
79 /**
80  * This function retrieves the top of usable low memory.
81  *
82  * @hob_list: A HOB list pointer.
83  *
84  * @retval:   Usable low memory top.
85  */
86 u32 fsp_get_usable_lowmem_top(const void *hob_list);
87 
88 /**
89  * This function retrieves the top of usable high memory.
90  *
91  * @hob_list: A HOB list pointer.
92  *
93  * @retval:   Usable high memory top.
94  */
95 u64 fsp_get_usable_highmem_top(const void *hob_list);
96 
97 /**
98  * This function retrieves a special reserved memory region.
99  *
100  * @hob_list: A HOB list pointer.
101  * @len:      A pointer to the GUID HOB data buffer length.
102  *            If the GUID HOB is located, the length will be updated.
103  * @guid:     A pointer to the owner guild.
104  *
105  * @retval:   Reserved region start address.
106  *            0 if this region does not exist.
107  */
108 u64 fsp_get_reserved_mem_from_guid(const void *hob_list,
109 				   u64 *len, struct efi_guid *guid);
110 
111 /**
112  * This function retrieves the FSP reserved normal memory.
113  *
114  * @hob_list: A HOB list pointer.
115  * @len:      A pointer to the FSP reserved memory length buffer.
116  *            If the GUID HOB is located, the length will be updated.
117  * @retval:   FSP reserved memory base
118  *            0 if this region does not exist.
119  */
120 u32 fsp_get_fsp_reserved_mem(const void *hob_list, u32 *len);
121 
122 /**
123  * This function retrieves the TSEG reserved normal memory.
124  *
125  * @hob_list:      A HOB list pointer.
126  * @len:           A pointer to the TSEG reserved memory length buffer.
127  *                 If the GUID HOB is located, the length will be updated.
128  *
129  * @retval NULL:   Failed to find the TSEG reserved memory.
130  * @retval others: TSEG reserved memory base.
131  */
132 u32 fsp_get_tseg_reserved_mem(const void *hob_list, u32 *len);
133 
134 /**
135  * Returns the next instance of a HOB type from the starting HOB.
136  *
137  * @type:     HOB type to search
138  * @hob_list: A pointer to the HOB list
139  *
140  * @retval:   A HOB object with matching type; Otherwise NULL.
141  */
142 const struct hob_header *fsp_get_next_hob(uint type, const void *hob_list);
143 
144 /**
145  * Returns the next instance of the matched GUID HOB from the starting HOB.
146  *
147  * @guid:     GUID to search
148  * @hob_list: A pointer to the HOB list
149  *
150  * @retval:   A HOB object with matching GUID; Otherwise NULL.
151  */
152 const struct hob_header *fsp_get_next_guid_hob(const struct efi_guid *guid,
153 					       const void *hob_list);
154 
155 /**
156  * This function retrieves a GUID HOB data buffer and size.
157  *
158  * @hob_list:      A HOB list pointer.
159  * @len:           A pointer to the GUID HOB data buffer length.
160  *                 If the GUID HOB is located, the length will be updated.
161  * @guid           A pointer to HOB GUID.
162  *
163  * @retval NULL:   Failed to find the GUID HOB.
164  * @retval others: GUID HOB data buffer pointer.
165  */
166 void *fsp_get_guid_hob_data(const void *hob_list, u32 *len,
167 			    struct efi_guid *guid);
168 
169 /**
170  * This function retrieves FSP Non-volatile Storage HOB buffer and size.
171  *
172  * @hob_list:      A HOB list pointer.
173  * @len:           A pointer to the NVS data buffer length.
174  *                 If the HOB is located, the length will be updated.
175  *
176  * @retval NULL:   Failed to find the NVS HOB.
177  * @retval others: FSP NVS data buffer pointer.
178  */
179 void *fsp_get_nvs_data(const void *hob_list, u32 *len);
180 
181 /**
182  * This function retrieves Bootloader temporary stack buffer and size.
183  *
184  * @hob_list:      A HOB list pointer.
185  * @len:           A pointer to the bootloader temporary stack length.
186  *                 If the HOB is located, the length will be updated.
187  *
188  * @retval NULL:   Failed to find the bootloader temporary stack HOB.
189  * @retval others: Bootloader temporary stackbuffer pointer.
190  */
191 void *fsp_get_bootloader_tmp_mem(const void *hob_list, u32 *len);
192 
193 /**
194  * This function retrieves graphics information.
195  *
196  * @hob_list:      A HOB list pointer.
197  * @len:           A pointer to the graphics info HOB length.
198  *                 If the HOB is located, the length will be updated.
199  *
200  * @retval NULL:   Failed to find the graphics info HOB.
201  * @retval others: A pointer to struct hob_graphics_info.
202  */
203 void *fsp_get_graphics_info(const void *hob_list, u32 *len);
204 
205 /**
206  * This function overrides the default configurations of FSP.
207  *
208  * @config:  A pointer to the FSP configuration data structure
209  * @rt_buf:  A pointer to the FSP runtime buffer data structure
210  *
211  * @return:  None
212  */
213 void update_fsp_configs(struct fsp_config_data *config,
214 			struct fspinit_rtbuf *rt_buf);
215 
216 /**
217  * fsp_init_phase_pci() - Tell the FSP that we have completed PCI init
218  *
219  * @return 0 if OK, -EPERM if the FSP gave an error.
220  */
221 int fsp_init_phase_pci(void);
222 
223 #endif
224