blob: 875fcf218fc559f0adbbd3b018014747c5ed5dc0 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahyb5ad8272015-04-20 15:29:16 -07002
3#include <console/console.h>
Julius Werner53584672021-01-11 16:44:06 -08004#include <cbfs.h>
Lee Leahyb5ad8272015-04-20 15:29:16 -07005#include <cbmem.h>
Furquan Shaikhb0c2fe02016-05-09 12:23:01 -07006#include <commonlib/fsp.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -05007#include <fsp/util.h>
Lee Leahyb5ad8272015-04-20 15:29:16 -07008
Julius Werner53584672021-01-11 16:44:06 -08009int fsp_relocate(struct prog *fsp_relocd)
Lee Leahyb5ad8272015-04-20 15:29:16 -070010{
Aaron Durbin22ea0072015-08-05 10:17:33 -050011 void *fih;
Aaron Durbin8007c6b2015-09-10 21:19:25 -050012 ssize_t fih_offset;
Julius Werner53584672021-01-11 16:44:06 -080013 size_t size;
Lee Leahyb5ad8272015-04-20 15:29:16 -070014
Julius Werner53584672021-01-11 16:44:06 -080015 void *new_loc = cbfs_cbmem_alloc(prog_name(fsp_relocd),
16 CBMEM_ID_REFCODE, &size);
Lee Leahyb5ad8272015-04-20 15:29:16 -070017 if (new_loc == NULL) {
Julius Wernere9665952022-01-21 17:06:20 -080018 printk(BIOS_ERR, "Unable to load FSP into memory.\n");
Aaron Durbin22ea0072015-08-05 10:17:33 -050019 return -1;
Lee Leahyb5ad8272015-04-20 15:29:16 -070020 }
Aaron Durbin22ea0072015-08-05 10:17:33 -050021
Aaron Durbin8007c6b2015-09-10 21:19:25 -050022 fih_offset = fsp1_1_relocate((uintptr_t)new_loc, new_loc, size);
Aaron Durbin22ea0072015-08-05 10:17:33 -050023
Aaron Durbin8007c6b2015-09-10 21:19:25 -050024 if (fih_offset <= 0) {
Julius Wernere9665952022-01-21 17:06:20 -080025 printk(BIOS_ERR, "FSP relocation failure.\n");
Aaron Durbin22ea0072015-08-05 10:17:33 -050026 return -1;
27 }
28
Aaron Durbina5be7fa2015-09-10 22:52:27 -050029 fih = (void *)((uint8_t *)new_loc + fih_offset);
Aaron Durbin8007c6b2015-09-10 21:19:25 -050030
Aaron Durbin22ea0072015-08-05 10:17:33 -050031 prog_set_area(fsp_relocd, new_loc, size);
32 prog_set_entry(fsp_relocd, fih, NULL);
33
34 return 0;
Lee Leahyb5ad8272015-04-20 15:29:16 -070035}