blob: e6464aa3df905a3ba94a7f17c45c0b84ef2e1417 [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
13#include <arch/cpu.h>
14#include <cbfs.h>
Aaron Durbin32ac0182016-07-18 00:35:42 -050015#include <cbmem.h>
16#include <commonlib/fsp.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>
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -080021#include <stage_cache.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080022#include <string.h>
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070023#include <timestamp.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080024
25struct fsp_header fsps_hdr;
26
Lee Leahy9671faa2016-07-24 18:18:52 -070027static void do_silicon_init(struct fsp_header *hdr)
Andrey Petrov42c4e882016-02-25 14:17:45 -080028{
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070029 FSPS_UPD upd, *supd;
Andrey Petrov42c4e882016-02-25 14:17:45 -080030 fsp_silicon_init_fn silicon_init;
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070031 uint32_t status;
Andrey Petrov42c4e882016-02-25 14:17:45 -080032
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070033 supd = (FSPS_UPD *) (hdr->cfg_region_offset + hdr->image_base);
Andrey Petrov42c4e882016-02-25 14:17:45 -080034
35 if (supd->FspUpdHeader.Signature != FSPS_UPD_SIGNATURE) {
Lee Leahy9671faa2016-07-24 18:18:52 -070036 die("Invalid FSPS signature\n");
Andrey Petrov42c4e882016-02-25 14:17:45 -080037 }
38
39 memcpy(&upd, supd, sizeof(upd));
40
41 /* Give SoC/mainboard a chance to populate entries */
42 platform_fsp_silicon_init_params_cb(&upd);
43
Lee Leahy672df162016-07-24 18:21:13 -070044 /* Call SiliconInit */
Andrey Petrov42c4e882016-02-25 14:17:45 -080045 silicon_init = (void *) (hdr->image_base +
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070046 hdr->silicon_init_entry_offset);
Lee Leahy672df162016-07-24 18:21:13 -070047 fsp_debug_before_silicon_init(silicon_init, supd, &upd);
48
49 timestamp_add_now(TS_FSP_SILICON_INIT_START);
50 post_code(POST_FSP_SILICON_INIT);
Andrey Petrov42c4e882016-02-25 14:17:45 -080051 status = silicon_init(&upd);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070052 timestamp_add_now(TS_FSP_SILICON_INIT_END);
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -070053 post_code(POST_FSP_SILICON_INIT);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070054
Lee Leahy672df162016-07-24 18:21:13 -070055 fsp_debug_after_silicon_init(status);
Aaron Durbin35d42c72016-07-18 12:41:09 -050056
Lee Leahy9671faa2016-07-24 18:18:52 -070057 /* Handle any errors returned by FspSiliconInit */
Aaron Durbin35d42c72016-07-18 12:41:09 -050058 fsp_handle_reset(status);
Lee Leahy9671faa2016-07-24 18:18:52 -070059 if (status != FSP_SUCCESS) {
60 printk(BIOS_SPEW, "FspSiliconInit returned 0x%08x\n", status);
61 die("FspSiliconINit returned an error!\n");
62 }
Andrey Petrov42c4e882016-02-25 14:17:45 -080063}
64
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -080065void fsp_silicon_init(bool s3wake)
Andrey Petrov42c4e882016-02-25 14:17:45 -080066{
Aaron Durbin32ac0182016-07-18 00:35:42 -050067 struct fsp_header *hdr = &fsps_hdr;
68 struct cbfsf file_desc;
69 struct region_device rdev;
70 const char *name = CONFIG_FSP_S_CBFS;
71 void *dest;
72 size_t size;
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -080073 struct prog fsps = PROG_INIT(PROG_REFCODE, name);
74
75 if (s3wake && !IS_ENABLED(CONFIG_NO_STAGE_CACHE)) {
76 printk(BIOS_DEBUG, "Loading FSPS from stage_cache\n");
77 stage_cache_load_stage(STAGE_REFCODE, &fsps);
78 if (fsp_validate_component(hdr, prog_rdev(&fsps)) != CB_SUCCESS)
79 die("On resume fsps header is invalid\n");
80 do_silicon_init(hdr);
81 return;
82 }
83
Aaron Durbin32ac0182016-07-18 00:35:42 -050084
85 if (cbfs_boot_locate(&file_desc, name, NULL)) {
86 printk(BIOS_ERR, "Could not locate %s in CBFS\n", name);
Lee Leahy9671faa2016-07-24 18:18:52 -070087 die("FSPS not available!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -050088 }
89
90 cbfs_file_data(&rdev, &file_desc);
91
92 /* Load and relocate into CBMEM. */
93 size = region_device_sz(&rdev);
94 dest = cbmem_add(CBMEM_ID_REFCODE, size);
95
96 if (dest == NULL) {
Lee Leahy9671faa2016-07-24 18:18:52 -070097 die("Could not add FSPS to CBMEM!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -050098 }
99
100 if (rdev_readat(&rdev, dest, 0, size) < 0)
Lee Leahy9671faa2016-07-24 18:18:52 -0700101 die("Failed to read FSPS!\n");
Andrey Petrov42c4e882016-02-25 14:17:45 -0800102
Aaron Durbin32ac0182016-07-18 00:35:42 -0500103 if (fsp_component_relocate((uintptr_t)dest, dest, size) < 0) {
Lee Leahy9671faa2016-07-24 18:18:52 -0700104 die("Unable to relocate FSPS!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500105 }
106
107 /* Create new region device in memory after relocation. */
108 rdev_chain(&rdev, &addrspace_32bit.rdev, (uintptr_t)dest, size);
109
110 if (fsp_validate_component(hdr, &rdev) != CB_SUCCESS)
Lee Leahy9671faa2016-07-24 18:18:52 -0700111 die("Invalid FSPS header!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500112
Brandon Breitensteinc6ec8dd2016-11-17 12:23:04 -0800113 prog_set_area(&fsps, dest, size);
114
115 stage_cache_add(STAGE_REFCODE, &fsps);
116
Aaron Durbin32ac0182016-07-18 00:35:42 -0500117 /* Signal that FSP component has been loaded. */
118 prog_segment_loaded(hdr->image_base, hdr->image_size, SEG_FINAL);
119
Lee Leahy9671faa2016-07-24 18:18:52 -0700120 do_silicon_init(hdr);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800121}