Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 3 | |
| 4 | #include <console/console.h> |
| 5 | #include <cbmem.h> |
Furquan Shaikh | b0c2fe0 | 2016-05-09 12:23:01 -0700 | [diff] [blame] | 6 | #include <commonlib/fsp.h> |
Aaron Durbin | 789f2b6 | 2015-09-09 17:05:06 -0500 | [diff] [blame] | 7 | #include <fsp/util.h> |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 8 | |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 9 | int fsp_relocate(struct prog *fsp_relocd, const struct region_device *fsp_src) |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 10 | { |
| 11 | void *new_loc; |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 12 | void *fih; |
Aaron Durbin | 8007c6b | 2015-09-10 21:19:25 -0500 | [diff] [blame] | 13 | ssize_t fih_offset; |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 14 | size_t size = region_device_sz(fsp_src); |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 15 | |
| 16 | new_loc = cbmem_add(CBMEM_ID_REFCODE, size); |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 17 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 18 | if (new_loc == NULL) { |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 19 | printk(BIOS_ERR, "ERROR: Unable to load FSP into memory.\n"); |
| 20 | return -1; |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 21 | } |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 22 | |
| 23 | if (rdev_readat(fsp_src, new_loc, 0, size) != size) { |
| 24 | printk(BIOS_ERR, "ERROR: Can't read FSP's region device.\n"); |
| 25 | return -1; |
| 26 | } |
| 27 | |
Aaron Durbin | 8007c6b | 2015-09-10 21:19:25 -0500 | [diff] [blame] | 28 | fih_offset = fsp1_1_relocate((uintptr_t)new_loc, new_loc, size); |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 29 | |
Aaron Durbin | 8007c6b | 2015-09-10 21:19:25 -0500 | [diff] [blame] | 30 | if (fih_offset <= 0) { |
Wim | fb758d4 | 2018-08-28 11:59:38 +0200 | [diff] [blame] | 31 | printk(BIOS_ERR, "ERROR: FSP relocation failure.\n"); |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 32 | return -1; |
| 33 | } |
| 34 | |
Aaron Durbin | a5be7fa | 2015-09-10 22:52:27 -0500 | [diff] [blame] | 35 | fih = (void *)((uint8_t *)new_loc + fih_offset); |
Aaron Durbin | 8007c6b | 2015-09-10 21:19:25 -0500 | [diff] [blame] | 36 | |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 37 | prog_set_area(fsp_relocd, new_loc, size); |
| 38 | prog_set_entry(fsp_relocd, fih, NULL); |
| 39 | |
| 40 | return 0; |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 41 | } |