Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2015 Intel Corp. |
| 5 | * (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 Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame^] | 15 | #include <cbmem.h> |
| 16 | #include <commonlib/fsp.h> |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 17 | #include <console/console.h> |
| 18 | #include <fsp/api.h> |
| 19 | #include <fsp/util.h> |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame^] | 20 | #include <program_loading.h> |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 21 | #include <string.h> |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 22 | #include <timestamp.h> |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 23 | |
| 24 | struct fsp_header fsps_hdr; |
| 25 | |
| 26 | typedef asmlinkage enum fsp_status (*fsp_silicon_init_fn) |
| 27 | (void *silicon_upd); |
| 28 | |
| 29 | static enum fsp_status do_silicon_init(struct fsp_header *hdr) |
| 30 | { |
| 31 | struct FSPS_UPD upd, *supd; |
| 32 | fsp_silicon_init_fn silicon_init; |
| 33 | enum fsp_status status; |
| 34 | |
| 35 | supd = (struct FSPS_UPD *) (hdr->cfg_region_offset + hdr->image_base); |
| 36 | |
| 37 | if (supd->FspUpdHeader.Signature != FSPS_UPD_SIGNATURE) { |
| 38 | printk(BIOS_ERR, "Invalid FSPS signature\n"); |
| 39 | return FSP_INCOMPATIBLE_VERSION; |
| 40 | } |
| 41 | |
| 42 | memcpy(&upd, supd, sizeof(upd)); |
| 43 | |
| 44 | /* Give SoC/mainboard a chance to populate entries */ |
| 45 | platform_fsp_silicon_init_params_cb(&upd); |
| 46 | |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 47 | timestamp_add_now(TS_FSP_SILICON_INIT_START); |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 48 | post_code(POST_FSP_SILICON_INIT); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 49 | silicon_init = (void *) (hdr->image_base + |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 50 | hdr->silicon_init_entry_offset); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 51 | status = silicon_init(&upd); |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 52 | timestamp_add_now(TS_FSP_SILICON_INIT_END); |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 53 | post_code(POST_FSP_SILICON_INIT); |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 54 | |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 55 | printk(BIOS_DEBUG, "FspSiliconInit returned 0x%08x\n", status); |
| 56 | return status; |
| 57 | } |
| 58 | |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame^] | 59 | enum fsp_status fsp_silicon_init(void) |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 60 | { |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame^] | 61 | struct fsp_header *hdr = &fsps_hdr; |
| 62 | struct cbfsf file_desc; |
| 63 | struct region_device rdev; |
| 64 | const char *name = CONFIG_FSP_S_CBFS; |
| 65 | void *dest; |
| 66 | size_t size; |
| 67 | |
| 68 | if (cbfs_boot_locate(&file_desc, name, NULL)) { |
| 69 | printk(BIOS_ERR, "Could not locate %s in CBFS\n", name); |
| 70 | return FSP_NOT_FOUND; |
| 71 | } |
| 72 | |
| 73 | cbfs_file_data(&rdev, &file_desc); |
| 74 | |
| 75 | /* Load and relocate into CBMEM. */ |
| 76 | size = region_device_sz(&rdev); |
| 77 | dest = cbmem_add(CBMEM_ID_REFCODE, size); |
| 78 | |
| 79 | if (dest == NULL) { |
| 80 | printk(BIOS_ERR, "Could not add FSPS to CBMEM.\n"); |
| 81 | return FSP_NOT_FOUND; |
| 82 | } |
| 83 | |
| 84 | if (rdev_readat(&rdev, dest, 0, size) < 0) |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 85 | return FSP_NOT_FOUND; |
| 86 | |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame^] | 87 | if (fsp_component_relocate((uintptr_t)dest, dest, size) < 0) { |
| 88 | printk(BIOS_ERR, "Unable to relocate FSPS.\n"); |
| 89 | return FSP_NOT_FOUND; |
| 90 | } |
| 91 | |
| 92 | /* Create new region device in memory after relocation. */ |
| 93 | rdev_chain(&rdev, &addrspace_32bit.rdev, (uintptr_t)dest, size); |
| 94 | |
| 95 | if (fsp_validate_component(hdr, &rdev) != CB_SUCCESS) |
| 96 | return FSP_NOT_FOUND; |
| 97 | |
| 98 | /* Signal that FSP component has been loaded. */ |
| 99 | prog_segment_loaded(hdr->image_base, hdr->image_size, SEG_FINAL); |
| 100 | |
| 101 | return do_silicon_init(hdr); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 102 | } |