blob: f670e6facd2fe0c730bbc1a2de1a8652af9ec7a7 [file] [log] [blame]
Andrey Petrov97389702016-02-25 14:15:37 -08001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy47bd2d92016-07-24 18:12:16 -07004 * Copyright (C) 2015-2016 Intel Corp.
Andrey Petrov97389702016-02-25 14:15:37 -08005 * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.)
6 * (Written by Andrey Petrov <andrey.petrov@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
Kyösti Mälkki13f66502019-03-03 08:01:05 +020014#include <device/mmio.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +020015#include <cf9_reset.h>
Andrey Petrov97389702016-02-25 14:15:37 -080016#include <console/console.h>
17#include <fsp/util.h>
Andrey Petrov97389702016-02-25 14:15:37 -080018#include <string.h>
Elyes HAOUASbd1683d2019-05-15 21:05:37 +020019#include <types.h>
Andrey Petrov97389702016-02-25 14:15:37 -080020
21static bool looks_like_fsp_header(const uint8_t *raw_hdr)
22{
23 if (memcmp(raw_hdr, FSP_HDR_SIGNATURE, 4)) {
24 printk(BIOS_ALERT, "Did not find a valid FSP signature\n");
25 return false;
26 }
27
28 if (read32(raw_hdr + 4) != FSP_HDR_LEN) {
29 printk(BIOS_ALERT, "FSP header has invalid length\n");
30 return false;
31 }
32
33 return true;
34}
35
36enum cb_err fsp_identify(struct fsp_header *hdr, const void *fsp_blob)
37{
38 const uint8_t *raw_hdr = fsp_blob;
39
40 if (!looks_like_fsp_header(raw_hdr))
41 return CB_ERR;
42
Andrey Petrovd5a6eb42016-05-04 17:30:16 -070043 hdr->spec_version = read8(raw_hdr + 10);
Andrey Petrov97389702016-02-25 14:15:37 -080044 hdr->revision = read8(raw_hdr + 11);
45 hdr->fsp_revision = read32(raw_hdr + 12);
46 memcpy(hdr->image_id, raw_hdr + 16, ARRAY_SIZE(hdr->image_id));
47 hdr->image_id[ARRAY_SIZE(hdr->image_id) - 1] = '\0';
48 hdr->image_size = read32(raw_hdr + 24);
49 hdr->image_base = read32(raw_hdr + 28);
Andrey Petrovd5a6eb42016-05-04 17:30:16 -070050 hdr->image_attribute = read16(raw_hdr + 32);
51 hdr->component_attribute = read16(raw_hdr + 34);
Andrey Petrov97389702016-02-25 14:15:37 -080052 hdr->cfg_region_offset = read32(raw_hdr + 36);
53 hdr->cfg_region_size = read32(raw_hdr + 40);
Brenton Dong0a5971c2016-10-18 11:35:15 -070054 hdr->temp_ram_init_entry = read32(raw_hdr + 48);
55 hdr->temp_ram_exit_entry = read32(raw_hdr + 64);
Andrey Petrov97389702016-02-25 14:15:37 -080056 hdr->notify_phase_entry_offset = read32(raw_hdr + 56);
57 hdr->memory_init_entry_offset = read32(raw_hdr + 60);
58 hdr->silicon_init_entry_offset = read32(raw_hdr + 68);
59
60 return CB_SUCCESS;
61}
62
Aaron Durbina413e5e2016-07-17 23:06:03 -050063enum cb_err fsp_validate_component(struct fsp_header *hdr,
64 const struct region_device *rdev)
65{
66 void *membase;
67
68 /* Map just enough of the file to be able to parse the header. */
69 membase = rdev_mmap(rdev, FSP_HDR_OFFSET, FSP_HDR_LEN);
70
71 if (membase == NULL) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -070072 printk(BIOS_CRIT, "Could not mmap() FSP header.\n");
Aaron Durbina413e5e2016-07-17 23:06:03 -050073 return CB_ERR;
74 }
75
76 if (fsp_identify(hdr, membase) != CB_SUCCESS) {
77 rdev_munmap(rdev, membase);
Lee Leahyb20d4ba2016-07-31 16:49:28 -070078 printk(BIOS_CRIT, "No valid FSP header\n");
Aaron Durbina413e5e2016-07-17 23:06:03 -050079 return CB_ERR;
80 }
81
82 rdev_munmap(rdev, membase);
83
Julius Wernercd49cce2019-03-05 16:53:33 -080084 if (CONFIG(DISPLAY_FSP_HEADER))
Lee Leahy37b5ef22016-07-31 14:15:49 -070085 fsp_print_header_info(hdr);
Aaron Durbina413e5e2016-07-17 23:06:03 -050086
87 /* Check if size specified in the header matches the cbfs file size */
88 if (region_device_sz(rdev) < hdr->image_size) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -070089 printk(BIOS_CRIT, "Component size bigger than cbfs file.\n");
Aaron Durbina413e5e2016-07-17 23:06:03 -050090 return CB_ERR;
91 }
92
93 return CB_SUCCESS;
94}
95
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -070096static bool fsp_reset_requested(uint32_t status)
Andrey Petrov3a94a3b2016-07-18 00:15:41 -070097{
98 return (status >= FSP_STATUS_RESET_REQUIRED_COLD &&
99 status <= FSP_STATUS_RESET_REQUIRED_8);
100}
101
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700102void fsp_handle_reset(uint32_t status)
Andrey Petrov901e43c2016-06-22 19:22:30 -0700103{
Andrey Petrov3a94a3b2016-07-18 00:15:41 -0700104 if (!fsp_reset_requested(status))
105 return;
106
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700107 printk(BIOS_SPEW, "FSP: handling reset type %x\n", status);
Andrey Petrov3a94a3b2016-07-18 00:15:41 -0700108
Lee Leahyb2b97a52017-03-10 08:40:18 -0800109 switch (status) {
Andrey Petrov901e43c2016-06-22 19:22:30 -0700110 case FSP_STATUS_RESET_REQUIRED_COLD:
Patrick Rudolphf677d172018-10-01 19:17:11 +0200111 full_reset();
Andrey Petrov901e43c2016-06-22 19:22:30 -0700112 break;
113 case FSP_STATUS_RESET_REQUIRED_WARM:
Patrick Rudolphf677d172018-10-01 19:17:11 +0200114 system_reset();
Andrey Petrov901e43c2016-06-22 19:22:30 -0700115 break;
Andrey Petrov3a94a3b2016-07-18 00:15:41 -0700116 case FSP_STATUS_RESET_REQUIRED_3:
117 case FSP_STATUS_RESET_REQUIRED_4:
118 case FSP_STATUS_RESET_REQUIRED_5:
119 case FSP_STATUS_RESET_REQUIRED_6:
120 case FSP_STATUS_RESET_REQUIRED_7:
121 case FSP_STATUS_RESET_REQUIRED_8:
122 chipset_handle_reset(status);
Andrey Petrov901e43c2016-06-22 19:22:30 -0700123 break;
124 default:
125 break;
126 }
127}