blob: ead3493de824ae2f6f53dced8bb359cc0b070b0e [file] [log] [blame]
Simon Glass466c7852019-12-06 21:42:18 -07001// SPDX-License-Identifier: Intel
2/*
3 * Copyright (C) 2015-2016 Intel Corp.
4 * (Written by Andrey Petrov <andrey.petrov@intel.com> for Intel Corp.)
5 *
6 * Mostly taken from coreboot fsp2_0/silicon_init.c
7 */
8
9#define LOG_CATEGORY UCLASS_NORTHBRIDGE
10
11#include <common.h>
12#include <binman.h>
Simon Glass1ea97892020-05-10 11:40:00 -060013#include <bootstage.h>
Simon Glass466c7852019-12-06 21:42:18 -070014#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060015#include <log.h>
Simon Glass466c7852019-12-06 21:42:18 -070016#include <asm/arch/fsp/fsp_configs.h>
17#include <asm/arch/fsp/fsp_s_upd.h>
18#include <asm/fsp/fsp_infoheader.h>
19#include <asm/fsp2/fsp_internal.h>
20
21int fsp_silicon_init(bool s3wake, bool use_spi_flash)
22{
23 struct fsps_upd upd, *fsp_upd;
24 fsp_silicon_init_func func;
25 struct fsp_header *hdr;
26 struct binman_entry entry;
27 struct udevice *dev;
28 ulong rom_offset = 0;
Simon Glassec7c2b62020-09-22 12:45:37 -060029 u32 init_addr;
Simon Glass466c7852019-12-06 21:42:18 -070030 int ret;
31
Simon Glassec7c2b62020-09-22 12:45:37 -060032 log_debug("Locating FSP\n");
Simon Glass466c7852019-12-06 21:42:18 -070033 ret = fsp_locate_fsp(FSP_S, &entry, use_spi_flash, &dev, &hdr,
34 &rom_offset);
35 if (ret)
36 return log_msg_ret("locate FSP", ret);
Simon Glass5e40c052020-07-07 21:32:25 -060037 binman_set_rom_offset(rom_offset);
Simon Glass466c7852019-12-06 21:42:18 -070038 gd->arch.fsp_s_hdr = hdr;
39
40 /* Copy over the default config */
41 fsp_upd = (struct fsps_upd *)(hdr->img_base + hdr->cfg_region_off);
42 if (fsp_upd->header.signature != FSPS_UPD_SIGNATURE)
43 return log_msg_ret("Bad UPD signature", -EPERM);
44 memcpy(&upd, fsp_upd, sizeof(upd));
45
46 ret = fsps_update_config(dev, rom_offset, &upd);
47 if (ret)
48 return log_msg_ret("Could not setup config", ret);
Simon Glassec7c2b62020-09-22 12:45:37 -060049 log_debug("Silicon init @ %x...", init_addr);
Simon Glassea6a6092020-05-10 11:39:59 -060050 bootstage_start(BOOTSTAGE_ID_ACCUM_FSP_S, "fsp-s");
Simon Glass466c7852019-12-06 21:42:18 -070051 func = (fsp_silicon_init_func)(hdr->img_base + hdr->fsp_silicon_init);
52 ret = func(&upd);
Simon Glassea6a6092020-05-10 11:39:59 -060053 bootstage_accum(BOOTSTAGE_ID_ACCUM_FSP_S);
Simon Glass466c7852019-12-06 21:42:18 -070054 if (ret)
55 return log_msg_ret("Silicon init fail\n", ret);
56 log_debug("done\n");
57
58 return 0;
59}