blob: ecc6e96ace868528113837a361ac1460e717144e [file] [log] [blame]
Andrey Petrov42c4e882016-02-25 14:17:45 -08001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy47bd2d92016-07-24 18:12:16 -07004 * Copyright (C) 2015-2016 Intel Corp.
Andrey Petrov42c4e882016-02-25 14:17:45 -08005 * (Written by Andrey Petrov <andrey.petrov@intel.com> for Intel Corp.)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
Andrey Petrov42c4e882016-02-25 14:17:45 -080013#include <cbfs.h>
Aaron Durbin32ac0182016-07-18 00:35:42 -050014#include <cbmem.h>
15#include <commonlib/fsp.h>
Subrata Banik44ffb5d2018-05-24 10:51:29 +053016#include <commonlib/stdlib.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080017#include <console/console.h>
18#include <fsp/api.h>
19#include <fsp/util.h>
Aaron Durbin32ac0182016-07-18 00:35:42 -050020#include <program_loading.h>
Keith Shortc58e3bd2019-05-10 11:14:31 -060021#include <soc/intel/common/vbt.h>
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -080022#include <stage_cache.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080023#include <string.h>
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070024#include <timestamp.h>
Elyes HAOUASbd1683d2019-05-15 21:05:37 +020025#include <types.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080026
27struct fsp_header fsps_hdr;
28
Lee Leahy9671faa2016-07-24 18:18:52 -070029static void do_silicon_init(struct fsp_header *hdr)
Andrey Petrov42c4e882016-02-25 14:17:45 -080030{
Subrata Banik44ffb5d2018-05-24 10:51:29 +053031 FSPS_UPD *upd, *supd;
Andrey Petrov42c4e882016-02-25 14:17:45 -080032 fsp_silicon_init_fn silicon_init;
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070033 uint32_t status;
Keith Shortc58e3bd2019-05-10 11:14:31 -060034 uint8_t postcode;
Andrey Petrov42c4e882016-02-25 14:17:45 -080035
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070036 supd = (FSPS_UPD *) (hdr->cfg_region_offset + hdr->image_base);
Andrey Petrov42c4e882016-02-25 14:17:45 -080037
Lee Leahye686ee82017-03-10 08:45:30 -080038 if (supd->FspUpdHeader.Signature != FSPS_UPD_SIGNATURE)
Keith Shortbb41aba2019-05-16 14:07:43 -060039 die_with_post_code(POST_INVALID_VENDOR_BINARY,
40 "Invalid FSPS signature\n");
Andrey Petrov42c4e882016-02-25 14:17:45 -080041
Marshall Dawson71dbcf12019-09-11 14:02:34 -060042 /* Disallow invalid config regions. Default settings are likely bad
43 * choices for coreboot, and different sized UPD from what the region
44 * allows is potentially a build problem.
45 */
46 if (!hdr->cfg_region_size || hdr->cfg_region_size != sizeof(FSPS_UPD))
47 die_with_post_code(POST_INVALID_VENDOR_BINARY,
48 "Invalid FSPS UPD region\n");
Subrata Banik44ffb5d2018-05-24 10:51:29 +053049
Marshall Dawson71dbcf12019-09-11 14:02:34 -060050 upd = xmalloc(hdr->cfg_region_size);
51
52 memcpy(upd, supd, hdr->cfg_region_size);
Andrey Petrov42c4e882016-02-25 14:17:45 -080053
54 /* Give SoC/mainboard a chance to populate entries */
Subrata Banik44ffb5d2018-05-24 10:51:29 +053055 platform_fsp_silicon_init_params_cb(upd);
Andrey Petrov42c4e882016-02-25 14:17:45 -080056
Lee Leahy672df162016-07-24 18:21:13 -070057 /* Call SiliconInit */
Andrey Petrov42c4e882016-02-25 14:17:45 -080058 silicon_init = (void *) (hdr->image_base +
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070059 hdr->silicon_init_entry_offset);
Subrata Banik44ffb5d2018-05-24 10:51:29 +053060 fsp_debug_before_silicon_init(silicon_init, supd, upd);
Lee Leahy672df162016-07-24 18:21:13 -070061
62 timestamp_add_now(TS_FSP_SILICON_INIT_START);
63 post_code(POST_FSP_SILICON_INIT);
Subrata Banik44ffb5d2018-05-24 10:51:29 +053064 status = silicon_init(upd);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070065 timestamp_add_now(TS_FSP_SILICON_INIT_END);
Subrata Banik0755ab92017-07-12 15:31:06 +053066 post_code(POST_FSP_SILICON_EXIT);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070067
Lee Leahy672df162016-07-24 18:21:13 -070068 fsp_debug_after_silicon_init(status);
Aaron Durbin35d42c72016-07-18 12:41:09 -050069
Lee Leahy9671faa2016-07-24 18:18:52 -070070 /* Handle any errors returned by FspSiliconInit */
Aaron Durbin35d42c72016-07-18 12:41:09 -050071 fsp_handle_reset(status);
Lee Leahy9671faa2016-07-24 18:18:52 -070072 if (status != FSP_SUCCESS) {
Keith Shortc58e3bd2019-05-10 11:14:31 -060073 if (vbt_get()) {
74 /* Attempted to initialize graphics. Assume failure
75 * is related to a video failure.
76 */
77 postcode = POST_VIDEO_FAILURE;
78 } else {
79 /* Other silicon initialization failed */
80 postcode = POST_HW_INIT_FAILURE;
81 }
Lee Leahy9671faa2016-07-24 18:18:52 -070082 printk(BIOS_SPEW, "FspSiliconInit returned 0x%08x\n", status);
Keith Shortc58e3bd2019-05-10 11:14:31 -060083 die_with_post_code(postcode,
Subrata Banikab032b82019-05-29 13:59:14 +053084 "FspSiliconInit returned an error!\n");
Lee Leahy9671faa2016-07-24 18:18:52 -070085 }
Andrey Petrov42c4e882016-02-25 14:17:45 -080086}
87
Furquan Shaikhf4b20af2017-02-20 13:33:32 -080088void fsps_load(bool s3wake)
Andrey Petrov42c4e882016-02-25 14:17:45 -080089{
Aaron Durbin32ac0182016-07-18 00:35:42 -050090 struct fsp_header *hdr = &fsps_hdr;
91 struct cbfsf file_desc;
92 struct region_device rdev;
93 const char *name = CONFIG_FSP_S_CBFS;
94 void *dest;
95 size_t size;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -080096 struct prog fsps = PROG_INIT(PROG_REFCODE, name);
Furquan Shaikhf4b20af2017-02-20 13:33:32 -080097 static int load_done;
98
99 if (load_done)
100 return;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800101
Julius Wernercd49cce2019-03-05 16:53:33 -0800102 if (s3wake && !CONFIG(NO_STAGE_CACHE)) {
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800103 printk(BIOS_DEBUG, "Loading FSPS from stage_cache\n");
104 stage_cache_load_stage(STAGE_REFCODE, &fsps);
105 if (fsp_validate_component(hdr, prog_rdev(&fsps)) != CB_SUCCESS)
106 die("On resume fsps header is invalid\n");
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800107 load_done = 1;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800108 return;
109 }
110
Aaron Durbin32ac0182016-07-18 00:35:42 -0500111 if (cbfs_boot_locate(&file_desc, name, NULL)) {
112 printk(BIOS_ERR, "Could not locate %s in CBFS\n", name);
Lee Leahy9671faa2016-07-24 18:18:52 -0700113 die("FSPS not available!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500114 }
115
116 cbfs_file_data(&rdev, &file_desc);
117
118 /* Load and relocate into CBMEM. */
119 size = region_device_sz(&rdev);
120 dest = cbmem_add(CBMEM_ID_REFCODE, size);
121
Lee Leahye686ee82017-03-10 08:45:30 -0800122 if (dest == NULL)
Lee Leahy9671faa2016-07-24 18:18:52 -0700123 die("Could not add FSPS to CBMEM!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500124
125 if (rdev_readat(&rdev, dest, 0, size) < 0)
Lee Leahy9671faa2016-07-24 18:18:52 -0700126 die("Failed to read FSPS!\n");
Andrey Petrov42c4e882016-02-25 14:17:45 -0800127
Lee Leahye686ee82017-03-10 08:45:30 -0800128 if (fsp_component_relocate((uintptr_t)dest, dest, size) < 0)
Lee Leahy9671faa2016-07-24 18:18:52 -0700129 die("Unable to relocate FSPS!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500130
131 /* Create new region device in memory after relocation. */
132 rdev_chain(&rdev, &addrspace_32bit.rdev, (uintptr_t)dest, size);
133
134 if (fsp_validate_component(hdr, &rdev) != CB_SUCCESS)
Lee Leahy9671faa2016-07-24 18:18:52 -0700135 die("Invalid FSPS header!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500136
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800137 prog_set_area(&fsps, dest, size);
138
139 stage_cache_add(STAGE_REFCODE, &fsps);
140
Aaron Durbin32ac0182016-07-18 00:35:42 -0500141 /* Signal that FSP component has been loaded. */
142 prog_segment_loaded(hdr->image_base, hdr->image_size, SEG_FINAL);
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800143 load_done = 1;
144}
Aaron Durbin32ac0182016-07-18 00:35:42 -0500145
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800146void fsp_silicon_init(bool s3wake)
147{
148 fsps_load(s3wake);
149 do_silicon_init(&fsps_hdr);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800150}