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