blob: 8fdd178d797804d830dc0b602cd1b830ed866687 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Andrey Petrovb37fd672016-03-01 16:25:38 -08002
3#ifndef _FSP2_0_UTIL_H_
4#define _FSP2_0_UTIL_H_
5
6#include <boot/coreboot_tables.h>
Julius Werner8205ce62021-03-10 17:25:01 -08007#include <cbfs.h>
Aaron Durbina413e5e2016-07-17 23:06:03 -05008#include <commonlib/region.h>
Elyes Haouas5318d9c2022-10-31 14:06:21 +01009#include <cpu/cpu.h>
Andrey Petrov901e43c2016-06-22 19:22:30 -070010#include <fsp/api.h>
Anil Kumar0dd03682021-11-24 14:31:04 -080011#include <efi/efi_datatype.h>
Andrey Petrovb37fd672016-03-01 16:25:38 -080012#include <fsp/info_header.h>
Andrey Petrovb37fd672016-03-01 16:25:38 -080013#include <memrange.h>
Aaron Durbina85febc2020-05-15 15:09:10 -060014#include <program_loading.h>
Elyes HAOUASbd1683d2019-05-15 21:05:37 +020015#include <types.h>
Andrey Petrovb37fd672016-03-01 16:25:38 -080016
Johnny Linb8899ef2020-05-28 14:04:58 +080017#define FSP_VER_LEN 30
18
Lean Sheng Tanfefc2ea2021-06-15 23:44:20 -070019/* Macro for checking and loading array type configs into array type UPDs */
20#define FSP_ARRAY_LOAD(dst, src) \
21do { \
22 _Static_assert(ARRAY_SIZE(dst) >= ARRAY_SIZE(src), "copy buffer overflow!"); \
23 memcpy(dst, src, sizeof(src)); \
24} while (0)
25
Lee Leahy672df162016-07-24 18:21:13 -070026struct hob_header {
27 uint16_t type;
28 uint16_t length;
Stefan Reinauer6a001132017-07-13 02:20:27 +020029} __packed;
Lee Leahy672df162016-07-24 18:21:13 -070030
Anil Kumar0dd03682021-11-24 14:31:04 -080031struct fsp_nvs_hob2_data_region_header {
32 efi_physical_address nvs_data_ptr;
33 uint64_t nvs_data_length;
34};
35
Lee Leahy672df162016-07-24 18:21:13 -070036struct fsp_notify_params {
37 enum fsp_notify_phase phase;
38};
39
Subrata Banik33d9c4a2020-05-26 18:26:54 +053040enum fsp_multi_phase_action {
41 GET_NUMBER_OF_PHASES = 0,
42 EXECUTE_PHASE = 1
43};
44
45struct fsp_multi_phase_params {
46 enum fsp_multi_phase_action multi_phase_action;
47 uint32_t phase_index;
48 void *multi_phase_param_ptr;
49};
50
Lee Leahyac3b0a62016-07-27 07:40:25 -070051struct hob_resource {
52 uint8_t owner_guid[16];
53 uint32_t type;
54 uint32_t attribute_type;
55 uint64_t addr;
56 uint64_t length;
Stefan Reinauer6a001132017-07-13 02:20:27 +020057} __packed;
Lee Leahyac3b0a62016-07-27 07:40:25 -070058
Johnny Lin5b47d772020-11-13 17:21:25 +080059union fsp_revision {
60 uint32_t val;
61 struct {
62 uint8_t bld_num;
63 uint8_t revision;
64 uint8_t minor;
65 uint8_t major;
66 } rev;
67};
68
Anil Kumar57309d32021-11-11 18:56:21 -080069union extended_fsp_revision {
70 uint16_t val;
71 struct {
72 uint8_t bld_num;
73 uint8_t revision;
74 } rev;
75};
76
Martin Roth09202cc2023-08-24 17:19:03 -060077#if CONFIG_UDK_VERSION < 2017
Lee Leahy5a9ca4d2016-09-28 17:15:00 -070078enum resource_type {
79 EFI_RESOURCE_SYSTEM_MEMORY = 0,
80 EFI_RESOURCE_MEMORY_MAPPED_IO = 1,
81 EFI_RESOURCE_IO = 2,
82 EFI_RESOURCE_FIRMWARE_DEVICE = 3,
83 EFI_RESOURCE_MEMORY_MAPPED_IO_PORT = 4,
84 EFI_RESOURCE_MEMORY_RESERVED = 5,
85 EFI_RESOURCE_IO_RESERVED = 6,
86 EFI_RESOURCE_MAX_MEMORY_TYPE = 7,
87};
Subrata Banik491728f2018-01-22 16:30:56 +053088#endif
Lee Leahy5a9ca4d2016-09-28 17:15:00 -070089
Lee Leahyac3b0a62016-07-27 07:40:25 -070090enum hob_type {
91 HOB_TYPE_HANDOFF = 0x0001,
92 HOB_TYPE_MEMORY_ALLOCATION = 0x0002,
93 HOB_TYPE_RESOURCE_DESCRIPTOR = 0x0003,
94 HOB_TYPE_GUID_EXTENSION = 0x0004,
95 HOB_TYPE_FV = 0x0005,
96 HOB_TYPE_CPU = 0x0006,
97 HOB_TYPE_MEMORY_POOL = 0x0007,
98 HOB_TYPE_FV2 = 0x0009,
99 HOB_TYPE_LOAD_PEIM_UNUSED = 0x000A,
100 HOB_TYPE_UCAPSULE = 0x000B,
101 HOB_TYPE_UNUSED = 0xFFFE,
102 HOB_TYPE_END_OF_HOB_LIST = 0xFFFF,
103};
104
Lee Leahy52d0c682016-08-01 15:47:42 -0700105extern const uint8_t fsp_bootloader_tolum_guid[16];
Lee Leahyac3b0a62016-07-27 07:40:25 -0700106extern const uint8_t fsp_nv_storage_guid[16];
107extern const uint8_t fsp_reserved_memory_guid[16];
108
Felix Held79db9872022-11-09 16:09:17 +0100109/*
110 * Functions to iterate over the HOBs and get resource structs or extension HOB data. It's
111 * required to initialize the hob_iterator struct by a fsp_hob_iterator_init call before
112 * passing the fsp_hob_iterator_get_next_* functions. The fsp_hob_iterator_get_next_* functions
113 * will update the hob_iterator to point to the next HOB header, so the iterators can be called
114 * multiple times to get the data from multiple HOB instances.
115 */
116enum cb_err fsp_hob_iterator_init(const struct hob_header **hob_iterator);
117enum cb_err fsp_hob_iterator_get_next_resource(const struct hob_header **hob_iterator,
118 const struct hob_resource **res);
119enum cb_err fsp_hob_iterator_get_next_guid_resource(const struct hob_header **hob_iterator,
120 const uint8_t guid[16],
121 const struct hob_resource **res);
122enum cb_err fsp_hob_iterator_get_next_guid_extension(const struct hob_header **hob_iterator,
123 const uint8_t guid[16],
124 const void **data, size_t *size);
125
Subrata Banik6de1d9f2022-03-20 19:50:38 +0530126/* Function to extract the FSP timestamp from FPDT Hob and display */
127void fsp_display_timestamp(void);
Andrey Petrovb37fd672016-03-01 16:25:38 -0800128const void *fsp_get_hob_list(void);
Lee Leahyac3b0a62016-07-27 07:40:25 -0700129void *fsp_get_hob_list_ptr(void);
130const void *fsp_find_extension_hob_by_guid(const uint8_t *guid, size_t *size);
Hannah Williams3503b3f2016-03-04 12:14:52 -0800131const void *fsp_find_nv_storage_data(size_t *size);
Felix Held1aa094a2023-03-29 15:58:36 +0200132enum cb_err fsp_find_range_hob(struct range_entry *re, const uint8_t guid[16]);
Subrata Banik73b67dc2018-01-23 16:31:03 +0530133void fsp_display_fvi_version_hob(void);
Michael Niewöhnerbc1dbb32019-10-24 22:58:25 +0200134void fsp_find_reserved_memory(struct range_entry *re);
Lee Leahyac3b0a62016-07-27 07:40:25 -0700135const struct hob_resource *fsp_hob_header_to_resource(
136 const struct hob_header *hob);
137const struct hob_header *fsp_next_hob(const struct hob_header *parent);
138bool fsp_guid_compare(const uint8_t guid1[16], const uint8_t guid2[16]);
Michael Niewöhnerbc1dbb32019-10-24 22:58:25 +0200139void fsp_find_bootloader_tolum(struct range_entry *re);
Ray Han Lim, Ng65b72192022-01-21 14:33:11 +0800140bool fsp_display_error_info(void);
141void display_fsp_error_info_hob(const void *hob);
Johnny Linb8899ef2020-05-28 14:04:58 +0800142void fsp_get_version(char *buf);
Felix Held88995982021-01-28 22:43:52 +0100143/* fsp_verify_upd_header_signature calls die() on signature mismatch */
144void fsp_verify_upd_header_signature(uint64_t upd_signature, uint64_t expected_signature);
Johnny Linb8899ef2020-05-28 14:04:58 +0800145void lb_string_platform_blob_version(struct lb_header *header);
Arthur Heymans5a663342020-10-28 14:03:14 +0100146void report_fspt_output(void);
Felix Held42df9af2021-08-24 19:26:56 +0200147void soc_validate_fspm_header(const struct fsp_header *hdr);
Pratikkumar Prajapatif5f756d2023-02-01 17:25:07 -0800148/*
149 * This function finds the FSP resource HOB for the given GUID.
150 * Returns the pointer to the HOB if found, otherwise NULL
151 */
152const void *fsp_find_resource_hob_by_guid(const uint8_t *guid);
Andrey Petrovb37fd672016-03-01 16:25:38 -0800153
Julius Werner43c9d702021-04-12 17:00:16 -0700154/* Fill in header and validate a loaded FSP component. */
155enum cb_err fsp_validate_component(struct fsp_header *hdr, void *fsp_blob, size_t size);
Aaron Durbina413e5e2016-07-17 23:06:03 -0500156
Aaron Durbina85febc2020-05-15 15:09:10 -0600157struct fsp_load_descriptor {
158 /* fsp_prog object will have region_device initialized to final
159 * load location in memory. */
160 struct prog fsp_prog;
Julius Werner8205ce62021-03-10 17:25:01 -0800161 /* CBFS allocator to place loaded FSP. NULL to map flash directly. */
162 cbfs_allocator_t alloc;
Aaron Durbinecbfa992020-05-15 17:01:58 -0600163 /* Optional argument to be utilized by get_destination() callback. */
164 void *arg;
Aaron Durbina85febc2020-05-15 15:09:10 -0600165};
166
167/* Load the FSP component described by fsp_load_descriptor from cbfs. The FSP
168 * header object will be validated and filled in on successful load. */
169enum cb_err fsp_load_component(struct fsp_load_descriptor *fspld, struct fsp_header *hdr);
170
Andrey Petrov3a94a3b2016-07-18 00:15:41 -0700171/*
172 * Handle FSP reboot request status. Chipset/soc is expected to provide
173 * chipset_handle_reset() that deals with reset type codes specific to given
174 * SoC. If the requested status is not a reboot status or unhandled, this
175 * function does nothing.
176 */
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700177void fsp_handle_reset(uint32_t status);
Andrey Petrov3a94a3b2016-07-18 00:15:41 -0700178
179/* SoC/chipset must provide this to handle platform-specific reset codes */
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700180void chipset_handle_reset(uint32_t status);
Andrey Petrov901e43c2016-06-22 19:22:30 -0700181
Brenton Dong0a5971c2016-10-18 11:35:15 -0700182typedef asmlinkage uint32_t (*temp_ram_exit_fn)(void *param);
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700183typedef asmlinkage uint32_t (*fsp_memory_init_fn)
Lee Leahy672df162016-07-24 18:21:13 -0700184 (void *raminit_upd, void **hob_list);
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700185typedef asmlinkage uint32_t (*fsp_silicon_init_fn)(void *silicon_upd);
Subrata Banik33d9c4a2020-05-26 18:26:54 +0530186typedef asmlinkage uint32_t (*fsp_multi_phase_si_init_fn)(struct fsp_multi_phase_params *);
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700187typedef asmlinkage uint32_t (*fsp_notify_fn)(struct fsp_notify_params *);
Lee Leahy672df162016-07-24 18:21:13 -0700188#include <fsp/debug.h>
189
Andrey Petrovb37fd672016-03-01 16:25:38 -0800190#endif /* _FSP2_0_UTIL_H_ */