blob: 5363fdd3800201314e7bd2add4d18e75b19aa935 [file] [log] [blame]
Andrey Petrov465fc132016-02-25 14:16:33 -08001/*
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 * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <arch/io.h>
15#include <arch/cpu.h>
Aaron Durbin27928682016-07-15 22:32:28 -050016#include <cbmem.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080017#include <console/console.h>
18#include <fsp/api.h>
19#include <fsp/util.h>
20#include <memrange.h>
21#include <string.h>
22#include <timestamp.h>
23
24typedef asmlinkage enum fsp_status (*fsp_memory_init_fn)
25 (void *raminit_upd, void **hob_list);
26
27static enum fsp_status do_fsp_memory_init(void **hob_list_ptr,
28 struct fsp_header *hdr)
29{
30 enum fsp_status status;
31 fsp_memory_init_fn fsp_raminit;
32 struct FSPM_UPD fspm_upd, *upd;
33
34 post_code(0x34);
35
36 upd = (struct FSPM_UPD *)(hdr->cfg_region_offset + hdr->image_base);
37
38 if (upd->FspUpdHeader.Signature != FSPM_UPD_SIGNATURE) {
39 printk(BIOS_ERR, "Invalid FSPM signature\n");
40 return FSP_INCOMPATIBLE_VERSION;
41 }
42
43 /* Copy the default values from the UPD area */
44 memcpy(&fspm_upd, upd, sizeof(fspm_upd));
45
Aaron Durbin27928682016-07-15 22:32:28 -050046 /* Reserve enough memory under TOLUD to save CBMEM header */
47 fspm_upd.FspmArchUpd.BootLoaderTolumSize = cbmem_overhead_size();
48
Andrey Petrov465fc132016-02-25 14:16:33 -080049 /* Give SoC and mainboard a chance to update the UPD */
50 platform_fsp_memory_init_params_cb(&fspm_upd);
51
52 /* Call FspMemoryInit */
53 fsp_raminit = (void *)(hdr->image_base + hdr->memory_init_entry_offset);
54 printk(BIOS_DEBUG, "Calling FspMemoryInit: 0x%p\n", fsp_raminit);
55 printk(BIOS_SPEW, "\t%p: raminit_upd\n", &fspm_upd);
56 printk(BIOS_SPEW, "\t%p: hob_list ptr\n", hob_list_ptr);
57
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -070058 post_code(POST_FSP_MEMORY_INIT);
Andrey Petrov465fc132016-02-25 14:16:33 -080059 timestamp_add_now(TS_FSP_MEMORY_INIT_START);
60 status = fsp_raminit(&fspm_upd, hob_list_ptr);
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -070061 post_code(POST_FSP_MEMORY_INIT);
Andrey Petrov465fc132016-02-25 14:16:33 -080062 timestamp_add_now(TS_FSP_MEMORY_INIT_END);
63
64 printk(BIOS_DEBUG, "FspMemoryInit returned 0x%08x\n", status);
65
66 return status;
67}
68
69enum fsp_status fsp_memory_init(void **hob_list, struct range_entry *range)
70{
71 struct fsp_header hdr;
72
Andrey Petrov9be1a112016-05-14 16:32:39 -070073 if (fsp_load_binary(&hdr, CONFIG_FSP_M_CBFS, range) != CB_SUCCESS)
Andrey Petrov465fc132016-02-25 14:16:33 -080074 return FSP_NOT_FOUND;
75
76 return do_fsp_memory_init(hob_list, &hdr);
77}