blob: 33d15afad69c9f976e56f855e5542a971c17fb97 [file] [log] [blame]
Andrey Petrov42c4e882016-02-25 14:17:45 -08001/*
2 * This file is part of the coreboot project.
3 *
Andrey Petrov42c4e882016-02-25 14:17:45 -08004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
Martin Rothcddd6002019-09-23 17:38:27 -06008 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Andrey Petrov42c4e882016-02-25 14:17:45 -080013 */
14
Andrey Petrov42c4e882016-02-25 14:17:45 -080015#include <cbfs.h>
Aaron Durbin32ac0182016-07-18 00:35:42 -050016#include <cbmem.h>
17#include <commonlib/fsp.h>
Subrata Banik44ffb5d2018-05-24 10:51:29 +053018#include <commonlib/stdlib.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080019#include <console/console.h>
20#include <fsp/api.h>
21#include <fsp/util.h>
Aaron Durbin32ac0182016-07-18 00:35:42 -050022#include <program_loading.h>
Keith Shortc58e3bd2019-05-10 11:14:31 -060023#include <soc/intel/common/vbt.h>
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -080024#include <stage_cache.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080025#include <string.h>
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070026#include <timestamp.h>
Elyes HAOUASbd1683d2019-05-15 21:05:37 +020027#include <types.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080028
29struct fsp_header fsps_hdr;
30
Lee Leahy9671faa2016-07-24 18:18:52 -070031static void do_silicon_init(struct fsp_header *hdr)
Andrey Petrov42c4e882016-02-25 14:17:45 -080032{
Subrata Banik44ffb5d2018-05-24 10:51:29 +053033 FSPS_UPD *upd, *supd;
Andrey Petrov42c4e882016-02-25 14:17:45 -080034 fsp_silicon_init_fn silicon_init;
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070035 uint32_t status;
Keith Shortc58e3bd2019-05-10 11:14:31 -060036 uint8_t postcode;
Wim Vervoornd1371502019-12-17 14:10:16 +010037 const struct cbmem_entry *logo_entry = NULL;
Andrey Petrov42c4e882016-02-25 14:17:45 -080038
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070039 supd = (FSPS_UPD *) (hdr->cfg_region_offset + hdr->image_base);
Andrey Petrov42c4e882016-02-25 14:17:45 -080040
Lee Leahye686ee82017-03-10 08:45:30 -080041 if (supd->FspUpdHeader.Signature != FSPS_UPD_SIGNATURE)
Keith Shortbb41aba2019-05-16 14:07:43 -060042 die_with_post_code(POST_INVALID_VENDOR_BINARY,
43 "Invalid FSPS signature\n");
Andrey Petrov42c4e882016-02-25 14:17:45 -080044
Marshall Dawson71dbcf12019-09-11 14:02:34 -060045 /* Disallow invalid config regions. Default settings are likely bad
46 * choices for coreboot, and different sized UPD from what the region
47 * allows is potentially a build problem.
48 */
49 if (!hdr->cfg_region_size || hdr->cfg_region_size != sizeof(FSPS_UPD))
50 die_with_post_code(POST_INVALID_VENDOR_BINARY,
51 "Invalid FSPS UPD region\n");
Subrata Banik44ffb5d2018-05-24 10:51:29 +053052
Marshall Dawson71dbcf12019-09-11 14:02:34 -060053 upd = xmalloc(hdr->cfg_region_size);
54
55 memcpy(upd, supd, hdr->cfg_region_size);
Andrey Petrov42c4e882016-02-25 14:17:45 -080056
57 /* Give SoC/mainboard a chance to populate entries */
Subrata Banik44ffb5d2018-05-24 10:51:29 +053058 platform_fsp_silicon_init_params_cb(upd);
Andrey Petrov42c4e882016-02-25 14:17:45 -080059
Wim Vervoornd1371502019-12-17 14:10:16 +010060 /* Populate logo related entries */
61 if (CONFIG(FSP2_0_DISPLAY_LOGO))
62 logo_entry = soc_load_logo(upd);
Wim Vervoorncbc878d22019-11-28 14:45:12 +010063
Lee Leahy672df162016-07-24 18:21:13 -070064 /* Call SiliconInit */
Andrey Petrov42c4e882016-02-25 14:17:45 -080065 silicon_init = (void *) (hdr->image_base +
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070066 hdr->silicon_init_entry_offset);
Subrata Banik44ffb5d2018-05-24 10:51:29 +053067 fsp_debug_before_silicon_init(silicon_init, supd, upd);
Lee Leahy672df162016-07-24 18:21:13 -070068
69 timestamp_add_now(TS_FSP_SILICON_INIT_START);
70 post_code(POST_FSP_SILICON_INIT);
Subrata Banik44ffb5d2018-05-24 10:51:29 +053071 status = silicon_init(upd);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070072 timestamp_add_now(TS_FSP_SILICON_INIT_END);
Subrata Banik0755ab92017-07-12 15:31:06 +053073 post_code(POST_FSP_SILICON_EXIT);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070074
Wim Vervoornd1371502019-12-17 14:10:16 +010075 if (logo_entry)
Wim Vervoorncbc878d22019-11-28 14:45:12 +010076 cbmem_entry_remove(logo_entry);
77
Lee Leahy672df162016-07-24 18:21:13 -070078 fsp_debug_after_silicon_init(status);
Aaron Durbin35d42c72016-07-18 12:41:09 -050079
Lee Leahy9671faa2016-07-24 18:18:52 -070080 /* Handle any errors returned by FspSiliconInit */
Aaron Durbin35d42c72016-07-18 12:41:09 -050081 fsp_handle_reset(status);
Lee Leahy9671faa2016-07-24 18:18:52 -070082 if (status != FSP_SUCCESS) {
Marshall Dawson7a9e8942019-10-17 07:58:27 -060083 /* Assume video failure if attempted to initialize graphics */
84 if (CONFIG(RUN_FSP_GOP) && vbt_get())
Keith Shortc58e3bd2019-05-10 11:14:31 -060085 postcode = POST_VIDEO_FAILURE;
Marshall Dawson7a9e8942019-10-17 07:58:27 -060086 else
87 postcode = POST_HW_INIT_FAILURE; /* else generic */
88
Lee Leahy9671faa2016-07-24 18:18:52 -070089 printk(BIOS_SPEW, "FspSiliconInit returned 0x%08x\n", status);
Keith Shortc58e3bd2019-05-10 11:14:31 -060090 die_with_post_code(postcode,
Subrata Banikab032b82019-05-29 13:59:14 +053091 "FspSiliconInit returned an error!\n");
Lee Leahy9671faa2016-07-24 18:18:52 -070092 }
Andrey Petrov42c4e882016-02-25 14:17:45 -080093}
94
Furquan Shaikhf4b20af2017-02-20 13:33:32 -080095void fsps_load(bool s3wake)
Andrey Petrov42c4e882016-02-25 14:17:45 -080096{
Aaron Durbin32ac0182016-07-18 00:35:42 -050097 struct fsp_header *hdr = &fsps_hdr;
98 struct cbfsf file_desc;
99 struct region_device rdev;
100 const char *name = CONFIG_FSP_S_CBFS;
101 void *dest;
102 size_t size;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800103 struct prog fsps = PROG_INIT(PROG_REFCODE, name);
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800104 static int load_done;
105
106 if (load_done)
107 return;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800108
Julius Wernercd49cce2019-03-05 16:53:33 -0800109 if (s3wake && !CONFIG(NO_STAGE_CACHE)) {
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800110 printk(BIOS_DEBUG, "Loading FSPS from stage_cache\n");
111 stage_cache_load_stage(STAGE_REFCODE, &fsps);
112 if (fsp_validate_component(hdr, prog_rdev(&fsps)) != CB_SUCCESS)
113 die("On resume fsps header is invalid\n");
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800114 load_done = 1;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800115 return;
116 }
117
Aaron Durbin32ac0182016-07-18 00:35:42 -0500118 if (cbfs_boot_locate(&file_desc, name, NULL)) {
119 printk(BIOS_ERR, "Could not locate %s in CBFS\n", name);
Lee Leahy9671faa2016-07-24 18:18:52 -0700120 die("FSPS not available!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500121 }
122
123 cbfs_file_data(&rdev, &file_desc);
124
125 /* Load and relocate into CBMEM. */
126 size = region_device_sz(&rdev);
127 dest = cbmem_add(CBMEM_ID_REFCODE, size);
128
Lee Leahye686ee82017-03-10 08:45:30 -0800129 if (dest == NULL)
Lee Leahy9671faa2016-07-24 18:18:52 -0700130 die("Could not add FSPS to CBMEM!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500131
132 if (rdev_readat(&rdev, dest, 0, size) < 0)
Lee Leahy9671faa2016-07-24 18:18:52 -0700133 die("Failed to read FSPS!\n");
Andrey Petrov42c4e882016-02-25 14:17:45 -0800134
Lee Leahye686ee82017-03-10 08:45:30 -0800135 if (fsp_component_relocate((uintptr_t)dest, dest, size) < 0)
Lee Leahy9671faa2016-07-24 18:18:52 -0700136 die("Unable to relocate FSPS!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500137
138 /* Create new region device in memory after relocation. */
139 rdev_chain(&rdev, &addrspace_32bit.rdev, (uintptr_t)dest, size);
140
141 if (fsp_validate_component(hdr, &rdev) != CB_SUCCESS)
Lee Leahy9671faa2016-07-24 18:18:52 -0700142 die("Invalid FSPS header!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500143
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800144 prog_set_area(&fsps, dest, size);
145
146 stage_cache_add(STAGE_REFCODE, &fsps);
147
Aaron Durbin32ac0182016-07-18 00:35:42 -0500148 /* Signal that FSP component has been loaded. */
149 prog_segment_loaded(hdr->image_base, hdr->image_size, SEG_FINAL);
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800150 load_done = 1;
151}
Aaron Durbin32ac0182016-07-18 00:35:42 -0500152
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800153void fsp_silicon_init(bool s3wake)
154{
155 fsps_load(s3wake);
156 do_silicon_init(&fsps_hdr);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800157}
Wim Vervoornd1371502019-12-17 14:10:16 +0100158
159/* Load bmp and set FSP parameters, fsp_load_logo can be used */
160__weak const struct cbmem_entry *soc_load_logo(FSPS_UPD *supd)
161{
162 return NULL;
163}