Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Lee Leahy | 47bd2d9 | 2016-07-24 18:12:16 -0700 | [diff] [blame] | 4 | * Copyright (C) 2015-2016 Intel Corp. |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 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 | |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 26 | static enum fsp_status do_silicon_init(struct fsp_header *hdr) |
| 27 | { |
| 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) { |
| 35 | printk(BIOS_ERR, "Invalid FSPS signature\n"); |
| 36 | return FSP_INCOMPATIBLE_VERSION; |
| 37 | } |
| 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 Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame^] | 44 | /* Call SiliconInit */ |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 45 | silicon_init = (void *) (hdr->image_base + |
Alexandru Gagniuc | 010225c | 2016-05-06 08:22:45 -0700 | [diff] [blame] | 46 | hdr->silicon_init_entry_offset); |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame^] | 47 | 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 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 | |
Lee Leahy | 672df16 | 2016-07-24 18:21:13 -0700 | [diff] [blame^] | 55 | fsp_debug_after_silicon_init(status); |
Aaron Durbin | 35d42c7 | 2016-07-18 12:41:09 -0500 | [diff] [blame] | 56 | |
| 57 | /* Handle any resets requested by FSPS. */ |
| 58 | fsp_handle_reset(status); |
| 59 | |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 60 | return status; |
| 61 | } |
| 62 | |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 63 | enum fsp_status fsp_silicon_init(void) |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 64 | { |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 65 | struct fsp_header *hdr = &fsps_hdr; |
| 66 | struct cbfsf file_desc; |
| 67 | struct region_device rdev; |
| 68 | const char *name = CONFIG_FSP_S_CBFS; |
| 69 | void *dest; |
| 70 | size_t size; |
| 71 | |
| 72 | if (cbfs_boot_locate(&file_desc, name, NULL)) { |
| 73 | printk(BIOS_ERR, "Could not locate %s in CBFS\n", name); |
| 74 | return FSP_NOT_FOUND; |
| 75 | } |
| 76 | |
| 77 | cbfs_file_data(&rdev, &file_desc); |
| 78 | |
| 79 | /* Load and relocate into CBMEM. */ |
| 80 | size = region_device_sz(&rdev); |
| 81 | dest = cbmem_add(CBMEM_ID_REFCODE, size); |
| 82 | |
| 83 | if (dest == NULL) { |
| 84 | printk(BIOS_ERR, "Could not add FSPS to CBMEM.\n"); |
| 85 | return FSP_NOT_FOUND; |
| 86 | } |
| 87 | |
| 88 | if (rdev_readat(&rdev, dest, 0, size) < 0) |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 89 | return FSP_NOT_FOUND; |
| 90 | |
Aaron Durbin | 32ac018 | 2016-07-18 00:35:42 -0500 | [diff] [blame] | 91 | if (fsp_component_relocate((uintptr_t)dest, dest, size) < 0) { |
| 92 | printk(BIOS_ERR, "Unable to relocate FSPS.\n"); |
| 93 | return FSP_NOT_FOUND; |
| 94 | } |
| 95 | |
| 96 | /* Create new region device in memory after relocation. */ |
| 97 | rdev_chain(&rdev, &addrspace_32bit.rdev, (uintptr_t)dest, size); |
| 98 | |
| 99 | if (fsp_validate_component(hdr, &rdev) != CB_SUCCESS) |
| 100 | return FSP_NOT_FOUND; |
| 101 | |
| 102 | /* Signal that FSP component has been loaded. */ |
| 103 | prog_segment_loaded(hdr->image_base, hdr->image_size, SEG_FINAL); |
| 104 | |
| 105 | return do_silicon_init(hdr); |
Andrey Petrov | 42c4e88 | 2016-02-25 14:17:45 -0800 | [diff] [blame] | 106 | } |