Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
Julius Werner | 5358467 | 2021-01-11 16:44:06 -0800 | [diff] [blame^] | 4 | #include <cbfs.h> |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 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 | |
Julius Werner | 5358467 | 2021-01-11 16:44:06 -0800 | [diff] [blame^] | 9 | int fsp_relocate(struct prog *fsp_relocd) |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 10 | { |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 11 | void *fih; |
Aaron Durbin | 8007c6b | 2015-09-10 21:19:25 -0500 | [diff] [blame] | 12 | ssize_t fih_offset; |
Julius Werner | 5358467 | 2021-01-11 16:44:06 -0800 | [diff] [blame^] | 13 | size_t size; |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 14 | |
Julius Werner | 5358467 | 2021-01-11 16:44:06 -0800 | [diff] [blame^] | 15 | void *new_loc = cbfs_cbmem_alloc(prog_name(fsp_relocd), |
| 16 | CBMEM_ID_REFCODE, &size); |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 17 | if (new_loc == NULL) { |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 18 | printk(BIOS_ERR, "ERROR: Unable to load FSP into memory.\n"); |
| 19 | return -1; |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 20 | } |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 21 | |
Aaron Durbin | 8007c6b | 2015-09-10 21:19:25 -0500 | [diff] [blame] | 22 | fih_offset = fsp1_1_relocate((uintptr_t)new_loc, new_loc, size); |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 23 | |
Aaron Durbin | 8007c6b | 2015-09-10 21:19:25 -0500 | [diff] [blame] | 24 | if (fih_offset <= 0) { |
Wim | fb758d4 | 2018-08-28 11:59:38 +0200 | [diff] [blame] | 25 | printk(BIOS_ERR, "ERROR: FSP relocation failure.\n"); |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 26 | return -1; |
| 27 | } |
| 28 | |
Aaron Durbin | a5be7fa | 2015-09-10 22:52:27 -0500 | [diff] [blame] | 29 | fih = (void *)((uint8_t *)new_loc + fih_offset); |
Aaron Durbin | 8007c6b | 2015-09-10 21:19:25 -0500 | [diff] [blame] | 30 | |
Aaron Durbin | 22ea007 | 2015-08-05 10:17:33 -0500 | [diff] [blame] | 31 | prog_set_area(fsp_relocd, new_loc, size); |
| 32 | prog_set_entry(fsp_relocd, fih, NULL); |
| 33 | |
| 34 | return 0; |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 35 | } |