Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 2 | |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 3 | #include <cbfs.h> |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 4 | #include <cbmem.h> |
| 5 | #include <commonlib/fsp.h> |
Subrata Banik | 44ffb5d | 2018-05-24 10:51:29 +0530 | [diff] [blame] | 6 | #include <commonlib/stdlib.h> |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 7 | #include <console/console.h> |
| 8 | #include <fsp/api.h> |
| 9 | #include <fsp/util.h> |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 10 | #include <program_loading.h> |
Keith Short | c58e3bd | 2019-05-10 11:14:31 -0600 | [diff] [blame] | 11 | #include <soc/intel/common/vbt.h> |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 12 | #include <stage_cache.h> |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 13 | #include <string.h> |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 14 | #include <timestamp.h> |
Elyes HAOUAS | bd1683d | 2019-05-15 21:05:37 +0200 | [diff] [blame] | 15 | #include <types.h> |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 16 | |
| 17 | struct fsp_header fsps_hdr; |
| 18 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 19 | static void do_silicon_init(struct fsp_header *hdr) |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 20 | { |
Subrata Banik | 44ffb5d | 2018-05-24 10:51:29 +0530 | [diff] [blame] | 21 | FSPS_UPD *upd, *supd; |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 22 | fsp_silicon_init_fn silicon_init; |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 23 | uint32_t status; |
Keith Short | c58e3bd | 2019-05-10 11:14:31 -0600 | [diff] [blame] | 24 | uint8_t postcode; |
Wim Vervoorn | d137150 | 2019-12-17 14:10:16 +0100 | [diff] [blame] | 25 | const struct cbmem_entry *logo_entry = NULL; |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 26 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 27 | supd = (FSPS_UPD *) (hdr->cfg_region_offset + hdr->image_base); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 28 | |
Lee Leahy | e686ee8 | 2017-03-10 08:45:30 -0800 | [diff] [blame] | 29 | if (supd->FspUpdHeader.Signature != FSPS_UPD_SIGNATURE) |
Keith Short | bb41aba | 2019-05-16 14:07:43 -0600 | [diff] [blame] | 30 | die_with_post_code(POST_INVALID_VENDOR_BINARY, |
| 31 | "Invalid FSPS signature\n"); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 32 | |
Marshall Dawson | 71dbcf1 | 2019-09-11 14:02:34 -0600 | [diff] [blame] | 33 | /* Disallow invalid config regions. Default settings are likely bad |
| 34 | * choices for coreboot, and different sized UPD from what the region |
| 35 | * allows is potentially a build problem. |
| 36 | */ |
| 37 | if (!hdr->cfg_region_size || hdr->cfg_region_size != sizeof(FSPS_UPD)) |
| 38 | die_with_post_code(POST_INVALID_VENDOR_BINARY, |
| 39 | "Invalid FSPS UPD region\n"); |
Subrata Banik | 44ffb5d | 2018-05-24 10:51:29 +0530 | [diff] [blame] | 40 | |
Marshall Dawson | 71dbcf1 | 2019-09-11 14:02:34 -0600 | [diff] [blame] | 41 | upd = xmalloc(hdr->cfg_region_size); |
| 42 | |
| 43 | memcpy(upd, supd, hdr->cfg_region_size); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 44 | |
| 45 | /* Give SoC/mainboard a chance to populate entries */ |
Subrata Banik | 44ffb5d | 2018-05-24 10:51:29 +0530 | [diff] [blame] | 46 | platform_fsp_silicon_init_params_cb(upd); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 47 | |
Wim Vervoorn | d137150 | 2019-12-17 14:10:16 +0100 | [diff] [blame] | 48 | /* Populate logo related entries */ |
| 49 | if (CONFIG(FSP2_0_DISPLAY_LOGO)) |
| 50 | logo_entry = soc_load_logo(upd); |
Wim Vervoorn | cbc878d2 | 2019-11-28 14:45:12 +0100 | [diff] [blame] | 51 | |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 52 | /* Call SiliconInit */ |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 53 | silicon_init = (void *) (hdr->image_base + |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 54 | hdr->silicon_init_entry_offset); |
Subrata Banik | 44ffb5d | 2018-05-24 10:51:29 +0530 | [diff] [blame] | 55 | fsp_debug_before_silicon_init(silicon_init, supd, upd); |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 56 | |
| 57 | timestamp_add_now(TS_FSP_SILICON_INIT_START); |
| 58 | post_code(POST_FSP_SILICON_INIT); |
Subrata Banik | 44ffb5d | 2018-05-24 10:51:29 +0530 | [diff] [blame] | 59 | status = silicon_init(upd); |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 60 | timestamp_add_now(TS_FSP_SILICON_INIT_END); |
Subrata Banik | 0755ab9 | 2017-07-12 15:31:06 +0530 | [diff] [blame] | 61 | post_code(POST_FSP_SILICON_EXIT); |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 62 | |
Wim Vervoorn | d137150 | 2019-12-17 14:10:16 +0100 | [diff] [blame] | 63 | if (logo_entry) |
Wim Vervoorn | cbc878d2 | 2019-11-28 14:45:12 +0100 | [diff] [blame] | 64 | cbmem_entry_remove(logo_entry); |
| 65 | |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame] | 66 | fsp_debug_after_silicon_init(status); |
Aaron Durbin | 35d42c7 | 2016-07-18 12:41:09 -0500 | [diff] [blame] | 67 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 68 | /* Handle any errors returned by FspSiliconInit */ |
Aaron Durbin | 35d42c7 | 2016-07-18 12:41:09 -0500 | [diff] [blame] | 69 | fsp_handle_reset(status); |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 70 | if (status != FSP_SUCCESS) { |
Marshall Dawson | 7a9e894 | 2019-10-17 07:58:27 -0600 | [diff] [blame] | 71 | /* Assume video failure if attempted to initialize graphics */ |
| 72 | if (CONFIG(RUN_FSP_GOP) && vbt_get()) |
Keith Short | c58e3bd | 2019-05-10 11:14:31 -0600 | [diff] [blame] | 73 | postcode = POST_VIDEO_FAILURE; |
Marshall Dawson | 7a9e894 | 2019-10-17 07:58:27 -0600 | [diff] [blame] | 74 | else |
| 75 | postcode = POST_HW_INIT_FAILURE; /* else generic */ |
| 76 | |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 77 | printk(BIOS_SPEW, "FspSiliconInit returned 0x%08x\n", status); |
Keith Short | c58e3bd | 2019-05-10 11:14:31 -0600 | [diff] [blame] | 78 | die_with_post_code(postcode, |
Subrata Banik | ab032b8 | 2019-05-29 13:59:14 +0530 | [diff] [blame] | 79 | "FspSiliconInit returned an error!\n"); |
Lee Leahy | 9671faa | 2016-07-24 18:18:52 -0700 | [diff] [blame] | 80 | } |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame^] | 83 | static int fsps_get_dest(const struct fsp_load_descriptor *fspld, void **dest, |
| 84 | size_t size, const struct region_device *source) |
| 85 | { |
| 86 | *dest = cbmem_add(CBMEM_ID_REFCODE, size); |
| 87 | |
| 88 | if (*dest == NULL) |
| 89 | return -1; |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Furquan Shaikh | f4b20af | 2017-02-20 13:33:32 -0800 | [diff] [blame] | 94 | void fsps_load(bool s3wake) |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 95 | { |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame^] | 96 | struct fsp_load_descriptor fspld = { |
| 97 | .fsp_prog = PROG_INIT(PROG_REFCODE, CONFIG_FSP_S_CBFS), |
| 98 | .get_destination = fsps_get_dest, |
| 99 | }; |
| 100 | struct prog *fsps = &fspld.fsp_prog; |
Furquan Shaikh | f4b20af | 2017-02-20 13:33:32 -0800 | [diff] [blame] | 101 | static int load_done; |
| 102 | |
| 103 | if (load_done) |
| 104 | return; |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 105 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 106 | if (s3wake && !CONFIG(NO_STAGE_CACHE)) { |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 107 | printk(BIOS_DEBUG, "Loading FSPS from stage_cache\n"); |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame^] | 108 | stage_cache_load_stage(STAGE_REFCODE, fsps); |
| 109 | if (fsp_validate_component(&fsps_hdr, prog_rdev(fsps)) != CB_SUCCESS) |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 110 | die("On resume fsps header is invalid\n"); |
Furquan Shaikh | f4b20af | 2017-02-20 13:33:32 -0800 | [diff] [blame] | 111 | load_done = 1; |
Brandon Breitenstein | c6ec8dd | 2016-11-17 12:23:04 -0800 | [diff] [blame] | 112 | return; |
| 113 | } |
| 114 | |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame^] | 115 | if (fsp_load_component(&fspld, &fsps_hdr) != CB_SUCCESS) |
| 116 | die("FSP-S failed to load\n"); |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 117 | |
Aaron Durbin | a85febc | 2020-05-15 15:09:10 -0600 | [diff] [blame^] | 118 | stage_cache_add(STAGE_REFCODE, fsps); |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 119 | |
Furquan Shaikh | f4b20af | 2017-02-20 13:33:32 -0800 | [diff] [blame] | 120 | load_done = 1; |
| 121 | } |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 122 | |
Furquan Shaikh | f4b20af | 2017-02-20 13:33:32 -0800 | [diff] [blame] | 123 | void fsp_silicon_init(bool s3wake) |
| 124 | { |
| 125 | fsps_load(s3wake); |
| 126 | do_silicon_init(&fsps_hdr); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 127 | } |
Wim Vervoorn | d137150 | 2019-12-17 14:10:16 +0100 | [diff] [blame] | 128 | |
| 129 | /* Load bmp and set FSP parameters, fsp_load_logo can be used */ |
| 130 | __weak const struct cbmem_entry *soc_load_logo(FSPS_UPD *supd) |
| 131 | { |
| 132 | return NULL; |
| 133 | } |