Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 1 | // 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 Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 13 | #include <bootstage.h> |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 14 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 16 | #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> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 21 | |
| 22 | int fsp_silicon_init(bool s3wake, bool use_spi_flash) |
| 23 | { |
| 24 | struct fsps_upd upd, *fsp_upd; |
| 25 | fsp_silicon_init_func func; |
| 26 | struct fsp_header *hdr; |
| 27 | struct binman_entry entry; |
| 28 | struct udevice *dev; |
| 29 | ulong rom_offset = 0; |
Simon Glass | ec7c2b6 | 2020-09-22 12:45:37 -0600 | [diff] [blame] | 30 | u32 init_addr; |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 31 | int ret; |
| 32 | |
Simon Glass | ec7c2b6 | 2020-09-22 12:45:37 -0600 | [diff] [blame] | 33 | log_debug("Locating FSP\n"); |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 34 | ret = fsp_locate_fsp(FSP_S, &entry, use_spi_flash, &dev, &hdr, |
| 35 | &rom_offset); |
| 36 | if (ret) |
| 37 | return log_msg_ret("locate FSP", ret); |
Simon Glass | 5e40c05 | 2020-07-07 21:32:25 -0600 | [diff] [blame] | 38 | binman_set_rom_offset(rom_offset); |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 39 | gd->arch.fsp_s_hdr = hdr; |
| 40 | |
| 41 | /* Copy over the default config */ |
| 42 | fsp_upd = (struct fsps_upd *)(hdr->img_base + hdr->cfg_region_off); |
| 43 | if (fsp_upd->header.signature != FSPS_UPD_SIGNATURE) |
| 44 | return log_msg_ret("Bad UPD signature", -EPERM); |
| 45 | memcpy(&upd, fsp_upd, sizeof(upd)); |
| 46 | |
| 47 | ret = fsps_update_config(dev, rom_offset, &upd); |
| 48 | if (ret) |
| 49 | return log_msg_ret("Could not setup config", ret); |
Simon Glass | ec7c2b6 | 2020-09-22 12:45:37 -0600 | [diff] [blame] | 50 | log_debug("Silicon init @ %x...", init_addr); |
Simon Glass | ea6a609 | 2020-05-10 11:39:59 -0600 | [diff] [blame] | 51 | bootstage_start(BOOTSTAGE_ID_ACCUM_FSP_S, "fsp-s"); |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 52 | func = (fsp_silicon_init_func)(hdr->img_base + hdr->fsp_silicon_init); |
| 53 | ret = func(&upd); |
Simon Glass | ea6a609 | 2020-05-10 11:39:59 -0600 | [diff] [blame] | 54 | bootstage_accum(BOOTSTAGE_ID_ACCUM_FSP_S); |
Simon Glass | 466c785 | 2019-12-06 21:42:18 -0700 | [diff] [blame] | 55 | if (ret) |
| 56 | return log_msg_ret("Silicon init fail\n", ret); |
| 57 | log_debug("done\n"); |
| 58 | |
| 59 | return 0; |
| 60 | } |