blob: 6e4bb2a53b61fdf643ebd9ca74f6951c46afe093 [file] [log] [blame]
Patrick Georgi02363b52020-05-05 20:48:50 +02001/* This file is part of the coreboot project. */
Patrick Georgiac959032020-05-05 22:49:26 +02002/* SPDX-License-Identifier: GPL-2.0-or-later */
Andrey Petrov97389702016-02-25 14:15:37 -08003
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +02005#include <cf9_reset.h>
Andrey Petrov97389702016-02-25 14:15:37 -08006#include <console/console.h>
7#include <fsp/util.h>
Andrey Petrov97389702016-02-25 14:15:37 -08008#include <string.h>
Elyes HAOUASbd1683d2019-05-15 21:05:37 +02009#include <types.h>
Andrey Petrov97389702016-02-25 14:15:37 -080010
11static bool looks_like_fsp_header(const uint8_t *raw_hdr)
12{
13 if (memcmp(raw_hdr, FSP_HDR_SIGNATURE, 4)) {
14 printk(BIOS_ALERT, "Did not find a valid FSP signature\n");
15 return false;
16 }
17
18 if (read32(raw_hdr + 4) != FSP_HDR_LEN) {
19 printk(BIOS_ALERT, "FSP header has invalid length\n");
20 return false;
21 }
22
23 return true;
24}
25
26enum cb_err fsp_identify(struct fsp_header *hdr, const void *fsp_blob)
27{
28 const uint8_t *raw_hdr = fsp_blob;
29
30 if (!looks_like_fsp_header(raw_hdr))
31 return CB_ERR;
32
Andrey Petrovd5a6eb42016-05-04 17:30:16 -070033 hdr->spec_version = read8(raw_hdr + 10);
Andrey Petrov97389702016-02-25 14:15:37 -080034 hdr->revision = read8(raw_hdr + 11);
35 hdr->fsp_revision = read32(raw_hdr + 12);
36 memcpy(hdr->image_id, raw_hdr + 16, ARRAY_SIZE(hdr->image_id));
37 hdr->image_id[ARRAY_SIZE(hdr->image_id) - 1] = '\0';
38 hdr->image_size = read32(raw_hdr + 24);
39 hdr->image_base = read32(raw_hdr + 28);
Andrey Petrovd5a6eb42016-05-04 17:30:16 -070040 hdr->image_attribute = read16(raw_hdr + 32);
41 hdr->component_attribute = read16(raw_hdr + 34);
Andrey Petrov97389702016-02-25 14:15:37 -080042 hdr->cfg_region_offset = read32(raw_hdr + 36);
43 hdr->cfg_region_size = read32(raw_hdr + 40);
Brenton Dong0a5971c2016-10-18 11:35:15 -070044 hdr->temp_ram_init_entry = read32(raw_hdr + 48);
45 hdr->temp_ram_exit_entry = read32(raw_hdr + 64);
Andrey Petrov97389702016-02-25 14:15:37 -080046 hdr->notify_phase_entry_offset = read32(raw_hdr + 56);
47 hdr->memory_init_entry_offset = read32(raw_hdr + 60);
48 hdr->silicon_init_entry_offset = read32(raw_hdr + 68);
49
50 return CB_SUCCESS;
51}
52
Aaron Durbina413e5e2016-07-17 23:06:03 -050053enum cb_err fsp_validate_component(struct fsp_header *hdr,
54 const struct region_device *rdev)
55{
56 void *membase;
57
58 /* Map just enough of the file to be able to parse the header. */
59 membase = rdev_mmap(rdev, FSP_HDR_OFFSET, FSP_HDR_LEN);
60
61 if (membase == NULL) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -070062 printk(BIOS_CRIT, "Could not mmap() FSP header.\n");
Aaron Durbina413e5e2016-07-17 23:06:03 -050063 return CB_ERR;
64 }
65
66 if (fsp_identify(hdr, membase) != CB_SUCCESS) {
67 rdev_munmap(rdev, membase);
Lee Leahyb20d4ba2016-07-31 16:49:28 -070068 printk(BIOS_CRIT, "No valid FSP header\n");
Aaron Durbina413e5e2016-07-17 23:06:03 -050069 return CB_ERR;
70 }
71
72 rdev_munmap(rdev, membase);
73
Julius Wernercd49cce2019-03-05 16:53:33 -080074 if (CONFIG(DISPLAY_FSP_HEADER))
Lee Leahy37b5ef22016-07-31 14:15:49 -070075 fsp_print_header_info(hdr);
Aaron Durbina413e5e2016-07-17 23:06:03 -050076
77 /* Check if size specified in the header matches the cbfs file size */
78 if (region_device_sz(rdev) < hdr->image_size) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -070079 printk(BIOS_CRIT, "Component size bigger than cbfs file.\n");
Aaron Durbina413e5e2016-07-17 23:06:03 -050080 return CB_ERR;
81 }
82
83 return CB_SUCCESS;
84}
85
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070086static bool fsp_reset_requested(uint32_t status)
Andrey Petrov3a94a3b2016-07-18 00:15:41 -070087{
88 return (status >= FSP_STATUS_RESET_REQUIRED_COLD &&
89 status <= FSP_STATUS_RESET_REQUIRED_8);
90}
91
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070092void fsp_handle_reset(uint32_t status)
Andrey Petrov901e43c2016-06-22 19:22:30 -070093{
Andrey Petrov3a94a3b2016-07-18 00:15:41 -070094 if (!fsp_reset_requested(status))
95 return;
96
Lee Leahyb20d4ba2016-07-31 16:49:28 -070097 printk(BIOS_SPEW, "FSP: handling reset type %x\n", status);
Andrey Petrov3a94a3b2016-07-18 00:15:41 -070098
Lee Leahyb2b97a52017-03-10 08:40:18 -080099 switch (status) {
Andrey Petrov901e43c2016-06-22 19:22:30 -0700100 case FSP_STATUS_RESET_REQUIRED_COLD:
Patrick Rudolphf677d172018-10-01 19:17:11 +0200101 full_reset();
Andrey Petrov901e43c2016-06-22 19:22:30 -0700102 break;
103 case FSP_STATUS_RESET_REQUIRED_WARM:
Patrick Rudolphf677d172018-10-01 19:17:11 +0200104 system_reset();
Andrey Petrov901e43c2016-06-22 19:22:30 -0700105 break;
Andrey Petrov3a94a3b2016-07-18 00:15:41 -0700106 case FSP_STATUS_RESET_REQUIRED_3:
107 case FSP_STATUS_RESET_REQUIRED_4:
108 case FSP_STATUS_RESET_REQUIRED_5:
109 case FSP_STATUS_RESET_REQUIRED_6:
110 case FSP_STATUS_RESET_REQUIRED_7:
111 case FSP_STATUS_RESET_REQUIRED_8:
112 chipset_handle_reset(status);
Andrey Petrov901e43c2016-06-22 19:22:30 -0700113 break;
114 default:
115 break;
116 }
117}