blob: 405086284916f7d965008f1f67d13bb3fa70517a [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Andrey Petrov97389702016-02-25 14:15:37 -08002
Kyösti Mälkki13f66502019-03-03 08:01:05 +02003#include <device/mmio.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +02004#include <cf9_reset.h>
Andrey Petrov97389702016-02-25 14:15:37 -08005#include <console/console.h>
6#include <fsp/util.h>
Andrey Petrov97389702016-02-25 14:15:37 -08007#include <string.h>
Elyes HAOUASbd1683d2019-05-15 21:05:37 +02008#include <types.h>
Andrey Petrov97389702016-02-25 14:15:37 -08009
10static bool looks_like_fsp_header(const uint8_t *raw_hdr)
11{
12 if (memcmp(raw_hdr, FSP_HDR_SIGNATURE, 4)) {
13 printk(BIOS_ALERT, "Did not find a valid FSP signature\n");
14 return false;
15 }
16
17 if (read32(raw_hdr + 4) != FSP_HDR_LEN) {
18 printk(BIOS_ALERT, "FSP header has invalid length\n");
19 return false;
20 }
21
22 return true;
23}
24
25enum cb_err fsp_identify(struct fsp_header *hdr, const void *fsp_blob)
26{
27 const uint8_t *raw_hdr = fsp_blob;
28
29 if (!looks_like_fsp_header(raw_hdr))
30 return CB_ERR;
31
Andrey Petrovd5a6eb42016-05-04 17:30:16 -070032 hdr->spec_version = read8(raw_hdr + 10);
Andrey Petrov97389702016-02-25 14:15:37 -080033 hdr->revision = read8(raw_hdr + 11);
34 hdr->fsp_revision = read32(raw_hdr + 12);
35 memcpy(hdr->image_id, raw_hdr + 16, ARRAY_SIZE(hdr->image_id));
36 hdr->image_id[ARRAY_SIZE(hdr->image_id) - 1] = '\0';
37 hdr->image_size = read32(raw_hdr + 24);
38 hdr->image_base = read32(raw_hdr + 28);
Andrey Petrovd5a6eb42016-05-04 17:30:16 -070039 hdr->image_attribute = read16(raw_hdr + 32);
40 hdr->component_attribute = read16(raw_hdr + 34);
Andrey Petrov97389702016-02-25 14:15:37 -080041 hdr->cfg_region_offset = read32(raw_hdr + 36);
42 hdr->cfg_region_size = read32(raw_hdr + 40);
Brenton Dong0a5971c2016-10-18 11:35:15 -070043 hdr->temp_ram_init_entry = read32(raw_hdr + 48);
44 hdr->temp_ram_exit_entry = read32(raw_hdr + 64);
Andrey Petrov97389702016-02-25 14:15:37 -080045 hdr->notify_phase_entry_offset = read32(raw_hdr + 56);
46 hdr->memory_init_entry_offset = read32(raw_hdr + 60);
47 hdr->silicon_init_entry_offset = read32(raw_hdr + 68);
48
49 return CB_SUCCESS;
50}
51
Aaron Durbina413e5e2016-07-17 23:06:03 -050052enum cb_err fsp_validate_component(struct fsp_header *hdr,
53 const struct region_device *rdev)
54{
55 void *membase;
56
57 /* Map just enough of the file to be able to parse the header. */
58 membase = rdev_mmap(rdev, FSP_HDR_OFFSET, FSP_HDR_LEN);
59
60 if (membase == NULL) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -070061 printk(BIOS_CRIT, "Could not mmap() FSP header.\n");
Aaron Durbina413e5e2016-07-17 23:06:03 -050062 return CB_ERR;
63 }
64
65 if (fsp_identify(hdr, membase) != CB_SUCCESS) {
66 rdev_munmap(rdev, membase);
Lee Leahyb20d4ba2016-07-31 16:49:28 -070067 printk(BIOS_CRIT, "No valid FSP header\n");
Aaron Durbina413e5e2016-07-17 23:06:03 -050068 return CB_ERR;
69 }
70
71 rdev_munmap(rdev, membase);
72
Julius Wernercd49cce2019-03-05 16:53:33 -080073 if (CONFIG(DISPLAY_FSP_HEADER))
Lee Leahy37b5ef22016-07-31 14:15:49 -070074 fsp_print_header_info(hdr);
Aaron Durbina413e5e2016-07-17 23:06:03 -050075
76 /* Check if size specified in the header matches the cbfs file size */
77 if (region_device_sz(rdev) < hdr->image_size) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -070078 printk(BIOS_CRIT, "Component size bigger than cbfs file.\n");
Aaron Durbina413e5e2016-07-17 23:06:03 -050079 return CB_ERR;
80 }
81
82 return CB_SUCCESS;
83}
84
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070085static bool fsp_reset_requested(uint32_t status)
Andrey Petrov3a94a3b2016-07-18 00:15:41 -070086{
87 return (status >= FSP_STATUS_RESET_REQUIRED_COLD &&
88 status <= FSP_STATUS_RESET_REQUIRED_8);
89}
90
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070091void fsp_handle_reset(uint32_t status)
Andrey Petrov901e43c2016-06-22 19:22:30 -070092{
Andrey Petrov3a94a3b2016-07-18 00:15:41 -070093 if (!fsp_reset_requested(status))
94 return;
95
Lee Leahyb20d4ba2016-07-31 16:49:28 -070096 printk(BIOS_SPEW, "FSP: handling reset type %x\n", status);
Andrey Petrov3a94a3b2016-07-18 00:15:41 -070097
Lee Leahyb2b97a52017-03-10 08:40:18 -080098 switch (status) {
Andrey Petrov901e43c2016-06-22 19:22:30 -070099 case FSP_STATUS_RESET_REQUIRED_COLD:
Patrick Rudolphf677d172018-10-01 19:17:11 +0200100 full_reset();
Andrey Petrov901e43c2016-06-22 19:22:30 -0700101 break;
102 case FSP_STATUS_RESET_REQUIRED_WARM:
Patrick Rudolphf677d172018-10-01 19:17:11 +0200103 system_reset();
Andrey Petrov901e43c2016-06-22 19:22:30 -0700104 break;
Andrey Petrov3a94a3b2016-07-18 00:15:41 -0700105 case FSP_STATUS_RESET_REQUIRED_3:
106 case FSP_STATUS_RESET_REQUIRED_4:
107 case FSP_STATUS_RESET_REQUIRED_5:
108 case FSP_STATUS_RESET_REQUIRED_6:
109 case FSP_STATUS_RESET_REQUIRED_7:
110 case FSP_STATUS_RESET_REQUIRED_8:
111 chipset_handle_reset(status);
Andrey Petrov901e43c2016-06-22 19:22:30 -0700112 break;
113 default:
114 break;
115 }
116}