blob: 108457d7ddcd32aeb1e32e655d3db4f622dbdbf2 [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
14#include <arch/io.h>
15#include <cbfs.h>
16#include <console/console.h>
17#include <fsp/util.h>
18#include <lib.h>
Andrey Petrov901e43c2016-06-22 19:22:30 -070019#include <reset.h>
Andrey Petrov97389702016-02-25 14:15:37 -080020#include <string.h>
21
22static bool looks_like_fsp_header(const uint8_t *raw_hdr)
23{
24 if (memcmp(raw_hdr, FSP_HDR_SIGNATURE, 4)) {
25 printk(BIOS_ALERT, "Did not find a valid FSP signature\n");
26 return false;
27 }
28
29 if (read32(raw_hdr + 4) != FSP_HDR_LEN) {
30 printk(BIOS_ALERT, "FSP header has invalid length\n");
31 return false;
32 }
33
34 return true;
35}
36
37enum cb_err fsp_identify(struct fsp_header *hdr, const void *fsp_blob)
38{
39 const uint8_t *raw_hdr = fsp_blob;
40
41 if (!looks_like_fsp_header(raw_hdr))
42 return CB_ERR;
43
Andrey Petrovd5a6eb42016-05-04 17:30:16 -070044 hdr->spec_version = read8(raw_hdr + 10);
Andrey Petrov97389702016-02-25 14:15:37 -080045 hdr->revision = read8(raw_hdr + 11);
46 hdr->fsp_revision = read32(raw_hdr + 12);
47 memcpy(hdr->image_id, raw_hdr + 16, ARRAY_SIZE(hdr->image_id));
48 hdr->image_id[ARRAY_SIZE(hdr->image_id) - 1] = '\0';
49 hdr->image_size = read32(raw_hdr + 24);
50 hdr->image_base = read32(raw_hdr + 28);
Andrey Petrovd5a6eb42016-05-04 17:30:16 -070051 hdr->image_attribute = read16(raw_hdr + 32);
52 hdr->component_attribute = read16(raw_hdr + 34);
Andrey Petrov97389702016-02-25 14:15:37 -080053 hdr->cfg_region_offset = read32(raw_hdr + 36);
54 hdr->cfg_region_size = read32(raw_hdr + 40);
55 hdr->notify_phase_entry_offset = read32(raw_hdr + 56);
56 hdr->memory_init_entry_offset = read32(raw_hdr + 60);
57 hdr->silicon_init_entry_offset = read32(raw_hdr + 68);
58
59 return CB_SUCCESS;
60}
61
62void fsp_print_header_info(const struct fsp_header *hdr)
63{
Andrey Petrovd5a6eb42016-05-04 17:30:16 -070064 union {
65 uint32_t val;
66 struct {
67 uint8_t bld_num;
68 uint8_t revision;
69 uint8_t minor;
70 uint8_t major;
71 } rev;
72 } revision;
73
74 revision.val = hdr->fsp_revision;
75
76 printk(BIOS_DEBUG, "Spec version: v%u.%u\n", (hdr->spec_version >> 4 ),
77 hdr->spec_version & 0xf);
78 printk(BIOS_DEBUG, "Revision: %u.%u.%u, Build Number %u\n",
79 revision.rev.major,
80 revision.rev.minor,
81 revision.rev.revision,
82 revision.rev.bld_num);
83 printk(BIOS_DEBUG, "Type: %s/%s\n",
84 (hdr->component_attribute & 1 ) ? "release" : "debug",
85 (hdr->component_attribute & 2 ) ? "test" : "official");
86 printk(BIOS_DEBUG, "image ID: %s, base 0x%lx + 0x%zx\n",
87 hdr->image_id, hdr->image_base, hdr->image_size);
Andrey Petrov97389702016-02-25 14:15:37 -080088 printk(BIOS_DEBUG, "\tConfig region 0x%zx + 0x%zx\n",
89 hdr->cfg_region_offset, hdr->cfg_region_size);
90
Andrey Petrovd5a6eb42016-05-04 17:30:16 -070091 if ((hdr->component_attribute >> 12) == FSP_HDR_ATTRIB_FSPM) {
Andrey Petrov97389702016-02-25 14:15:37 -080092 printk(BIOS_DEBUG, "\tMemory init offset 0x%zx\n",
93 hdr->memory_init_entry_offset);
94 }
95
Andrey Petrovd5a6eb42016-05-04 17:30:16 -070096 if ((hdr->component_attribute >> 12) == FSP_HDR_ATTRIB_FSPS) {
Andrey Petrov97389702016-02-25 14:15:37 -080097 printk(BIOS_DEBUG, "\tSilicon init offset 0x%zx\n",
98 hdr->silicon_init_entry_offset);
99 printk(BIOS_DEBUG, "\tNotify phase offset 0x%zx\n",
100 hdr->notify_phase_entry_offset);
101 }
102
103}
104
Aaron Durbina413e5e2016-07-17 23:06:03 -0500105enum cb_err fsp_validate_component(struct fsp_header *hdr,
106 const struct region_device *rdev)
107{
108 void *membase;
109
110 /* Map just enough of the file to be able to parse the header. */
111 membase = rdev_mmap(rdev, FSP_HDR_OFFSET, FSP_HDR_LEN);
112
113 if (membase == NULL) {
114 printk(BIOS_ERR, "Could not mmap() FSP header.\n");
115 return CB_ERR;
116 }
117
118 if (fsp_identify(hdr, membase) != CB_SUCCESS) {
119 rdev_munmap(rdev, membase);
120 printk(BIOS_ERR, "No valid FSP header\n");
121 return CB_ERR;
122 }
123
124 rdev_munmap(rdev, membase);
125
126 fsp_print_header_info(hdr);
127
128 /* Check if size specified in the header matches the cbfs file size */
129 if (region_device_sz(rdev) < hdr->image_size) {
130 printk(BIOS_ERR, "Component size bigger than cbfs file.\n");
131 return CB_ERR;
132 }
133
134 return CB_SUCCESS;
135}
136
Andrey Petrov3a94a3b2016-07-18 00:15:41 -0700137static bool fsp_reset_requested(enum fsp_status status)
138{
139 return (status >= FSP_STATUS_RESET_REQUIRED_COLD &&
140 status <= FSP_STATUS_RESET_REQUIRED_8);
141}
142
Andrey Petrov901e43c2016-06-22 19:22:30 -0700143void fsp_handle_reset(enum fsp_status status)
144{
Andrey Petrov3a94a3b2016-07-18 00:15:41 -0700145 if (!fsp_reset_requested(status))
146 return;
147
148 printk(BIOS_DEBUG, "FSP: handling reset type %x\n", status);
149
Andrey Petrov901e43c2016-06-22 19:22:30 -0700150 switch(status) {
151 case FSP_STATUS_RESET_REQUIRED_COLD:
152 hard_reset();
153 break;
154 case FSP_STATUS_RESET_REQUIRED_WARM:
155 soft_reset();
156 break;
Andrey Petrov3a94a3b2016-07-18 00:15:41 -0700157 case FSP_STATUS_RESET_REQUIRED_3:
158 case FSP_STATUS_RESET_REQUIRED_4:
159 case FSP_STATUS_RESET_REQUIRED_5:
160 case FSP_STATUS_RESET_REQUIRED_6:
161 case FSP_STATUS_RESET_REQUIRED_7:
162 case FSP_STATUS_RESET_REQUIRED_8:
163 chipset_handle_reset(status);
Andrey Petrov901e43c2016-06-22 19:22:30 -0700164 break;
165 default:
166 break;
167 }
168}