Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 1 | /* |
| 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 Durbin | 2792868 | 2016-07-15 22:32:28 -0500 | [diff] [blame^] | 16 | #include <cbmem.h> |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 17 | #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 | |
| 24 | typedef asmlinkage enum fsp_status (*fsp_memory_init_fn) |
| 25 | (void *raminit_upd, void **hob_list); |
| 26 | |
| 27 | static 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 Durbin | 2792868 | 2016-07-15 22:32:28 -0500 | [diff] [blame^] | 46 | /* Reserve enough memory under TOLUD to save CBMEM header */ |
| 47 | fspm_upd.FspmArchUpd.BootLoaderTolumSize = cbmem_overhead_size(); |
| 48 | |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 49 | /* 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 Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 58 | post_code(POST_FSP_MEMORY_INIT); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 59 | timestamp_add_now(TS_FSP_MEMORY_INIT_START); |
| 60 | status = fsp_raminit(&fspm_upd, hob_list_ptr); |
Alexandru Gagniuc | c4ea8f7 | 2016-05-23 12:16:58 -0700 | [diff] [blame] | 61 | post_code(POST_FSP_MEMORY_INIT); |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 62 | 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 | |
| 69 | enum fsp_status fsp_memory_init(void **hob_list, struct range_entry *range) |
| 70 | { |
| 71 | struct fsp_header hdr; |
| 72 | |
Andrey Petrov | 9be1a11 | 2016-05-14 16:32:39 -0700 | [diff] [blame] | 73 | if (fsp_load_binary(&hdr, CONFIG_FSP_M_CBFS, range) != CB_SUCCESS) |
Andrey Petrov | 465fc13 | 2016-02-25 14:16:33 -0800 | [diff] [blame] | 74 | return FSP_NOT_FOUND; |
| 75 | |
| 76 | return do_fsp_memory_init(hob_list, &hdr); |
| 77 | } |