blob: 562fec58442b905fd44fa2aa8300c6a138a5b094 [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>
Andrey Petrov42c4e882016-02-25 14:17:45 -080021#include <string.h>
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070022#include <timestamp.h>
Andrey Petrov42c4e882016-02-25 14:17:45 -080023
24struct fsp_header fsps_hdr;
25
Lee Leahy9671faa2016-07-24 18:18:52 -070026static void do_silicon_init(struct fsp_header *hdr)
Andrey Petrov42c4e882016-02-25 14:17:45 -080027{
28 struct FSPS_UPD upd, *supd;
29 fsp_silicon_init_fn silicon_init;
30 enum fsp_status status;
31
32 supd = (struct FSPS_UPD *) (hdr->cfg_region_offset + hdr->image_base);
33
34 if (supd->FspUpdHeader.Signature != FSPS_UPD_SIGNATURE) {
Lee Leahy9671faa2016-07-24 18:18:52 -070035 die("Invalid FSPS signature\n");
Andrey Petrov42c4e882016-02-25 14:17:45 -080036 }
37
38 memcpy(&upd, supd, sizeof(upd));
39
40 /* Give SoC/mainboard a chance to populate entries */
41 platform_fsp_silicon_init_params_cb(&upd);
42
Lee Leahy672df162016-07-24 18:21:13 -070043 /* Call SiliconInit */
Andrey Petrov42c4e882016-02-25 14:17:45 -080044 silicon_init = (void *) (hdr->image_base +
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070045 hdr->silicon_init_entry_offset);
Lee Leahy672df162016-07-24 18:21:13 -070046 fsp_debug_before_silicon_init(silicon_init, supd, &upd);
47
48 timestamp_add_now(TS_FSP_SILICON_INIT_START);
49 post_code(POST_FSP_SILICON_INIT);
Andrey Petrov42c4e882016-02-25 14:17:45 -080050 status = silicon_init(&upd);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070051 timestamp_add_now(TS_FSP_SILICON_INIT_END);
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -070052 post_code(POST_FSP_SILICON_INIT);
Alexandru Gagniuc010225c2016-05-06 08:22:45 -070053
Lee Leahy672df162016-07-24 18:21:13 -070054 fsp_debug_after_silicon_init(status);
Aaron Durbin35d42c72016-07-18 12:41:09 -050055
Lee Leahy9671faa2016-07-24 18:18:52 -070056 /* Handle any errors returned by FspSiliconInit */
Aaron Durbin35d42c72016-07-18 12:41:09 -050057 fsp_handle_reset(status);
Lee Leahy9671faa2016-07-24 18:18:52 -070058 if (status != FSP_SUCCESS) {
59 printk(BIOS_SPEW, "FspSiliconInit returned 0x%08x\n", status);
60 die("FspSiliconINit returned an error!\n");
61 }
Andrey Petrov42c4e882016-02-25 14:17:45 -080062}
63
Lee Leahy9671faa2016-07-24 18:18:52 -070064void fsp_silicon_init(void)
Andrey Petrov42c4e882016-02-25 14:17:45 -080065{
Aaron Durbin32ac0182016-07-18 00:35:42 -050066 struct fsp_header *hdr = &fsps_hdr;
67 struct cbfsf file_desc;
68 struct region_device rdev;
69 const char *name = CONFIG_FSP_S_CBFS;
70 void *dest;
71 size_t size;
72
73 if (cbfs_boot_locate(&file_desc, name, NULL)) {
74 printk(BIOS_ERR, "Could not locate %s in CBFS\n", name);
Lee Leahy9671faa2016-07-24 18:18:52 -070075 die("FSPS not available!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -050076 }
77
78 cbfs_file_data(&rdev, &file_desc);
79
80 /* Load and relocate into CBMEM. */
81 size = region_device_sz(&rdev);
82 dest = cbmem_add(CBMEM_ID_REFCODE, size);
83
84 if (dest == NULL) {
Lee Leahy9671faa2016-07-24 18:18:52 -070085 die("Could not add FSPS to CBMEM!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -050086 }
87
88 if (rdev_readat(&rdev, dest, 0, size) < 0)
Lee Leahy9671faa2016-07-24 18:18:52 -070089 die("Failed to read FSPS!\n");
Andrey Petrov42c4e882016-02-25 14:17:45 -080090
Aaron Durbin32ac0182016-07-18 00:35:42 -050091 if (fsp_component_relocate((uintptr_t)dest, dest, size) < 0) {
Lee Leahy9671faa2016-07-24 18:18:52 -070092 die("Unable to relocate FSPS!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -050093 }
94
95 /* Create new region device in memory after relocation. */
96 rdev_chain(&rdev, &addrspace_32bit.rdev, (uintptr_t)dest, size);
97
98 if (fsp_validate_component(hdr, &rdev) != CB_SUCCESS)
Lee Leahy9671faa2016-07-24 18:18:52 -070099 die("Invalid FSPS header!\n");
Aaron Durbin32ac0182016-07-18 00:35:42 -0500100
101 /* Signal that FSP component has been loaded. */
102 prog_segment_loaded(hdr->image_base, hdr->image_size, SEG_FINAL);
103
Lee Leahy9671faa2016-07-24 18:18:52 -0700104 do_silicon_init(hdr);
Andrey Petrov42c4e882016-02-25 14:17:45 -0800105}