|
| 1 | +/* fsp_tgl.c |
| 2 | + * |
| 3 | + * Copyright (C) 2023 wolfSSL Inc. |
| 4 | + * |
| 5 | + * This file is part of wolfBoot. |
| 6 | + * |
| 7 | + * wolfBoot is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * wolfBoot is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 20 | + */ |
| 21 | +#include <x86/fsp/FspCommon.h> |
| 22 | +#include <stage2_params.h> |
| 23 | +#include <x86/common.h> |
| 24 | +#include <pci.h> |
| 25 | +#include <printf.h> |
| 26 | + |
| 27 | +#define FSP_INFO_HEADER_OFFSET 0x94 |
| 28 | +#define EFI_SUCCESS 0x0 |
| 29 | + |
| 30 | +#ifndef FSP_S_PARAM_SIZE |
| 31 | +#define FSP_S_PARAM_SIZE 0xee0 |
| 32 | +#endif |
| 33 | + |
| 34 | +#define PCI_DEVICE_CONTROLLER_TO_PEX 0x6 |
| 35 | + |
| 36 | + |
| 37 | +int fsp_machine_update_s_parameters(uint8_t *default_s_params); |
| 38 | +int fsp_pre_silicon_init_cb(void); |
| 39 | +/*! |
| 40 | + * \brief Check if the FSP info header is valid. |
| 41 | + * |
| 42 | + * This static function checks if the given FSP info header is valid by verifying |
| 43 | + * its signature. |
| 44 | + * |
| 45 | + * \param hdr Pointer to the FSP info header structure. |
| 46 | + * \return 1j if the FSP info header is valid, 0 otherwise. |
| 47 | + */ |
| 48 | +int fsp_info_header_is_ok(struct fsp_info_header *hdr) |
| 49 | +{ |
| 50 | + uint8_t *raw_signature; |
| 51 | + |
| 52 | + raw_signature = (uint8_t *)&hdr->Signature; |
| 53 | + if (raw_signature[0] != 'F' || raw_signature[1] != 'S' || |
| 54 | + raw_signature[2] != 'P' || raw_signature[3] != 'H') { |
| 55 | + return 0; |
| 56 | + } |
| 57 | + return 1; |
| 58 | +} |
| 59 | + |
| 60 | +int fsp_get_image_revision(struct fsp_info_header *h, int *build, |
| 61 | + int *rev, int *maj, int *min) |
| 62 | +{ |
| 63 | + uint16_t ext_revision; |
| 64 | + uint32_t revision; |
| 65 | + |
| 66 | + if (!fsp_info_header_is_ok(h)) { |
| 67 | + wolfBoot_printf("Wrong FSP Header\r\n"); |
| 68 | + return -1; |
| 69 | + } |
| 70 | + |
| 71 | + revision = h->ImageRevision; |
| 72 | + |
| 73 | + *build = revision & 0xff; |
| 74 | + *rev = (revision >> 8) & 0xff; |
| 75 | + *min = (revision >> 16) & 0xff; |
| 76 | + *maj = (revision >> 24) & 0xff; |
| 77 | + |
| 78 | + if (h->HeaderRevision >= 6) { |
| 79 | + *build = *build | ((h->ExtendedImageRevision & 0xff) << 8); |
| 80 | + *rev = *rev | (h->ExtendedImageRevision & 0xff00); |
| 81 | + } |
| 82 | + |
| 83 | + return 0; |
| 84 | +} |
| 85 | + |
| 86 | +void print_fsp_image_revision(struct fsp_info_header *h) |
| 87 | +{ |
| 88 | + int build, rev, maj, min; |
| 89 | + int r; |
| 90 | + r = fsp_get_image_revision(h, &build, &rev, &maj, &min); |
| 91 | + if (r != 0) { |
| 92 | + wolfBoot_printf("failed to get fsp image revision\r\n"); |
| 93 | + return; |
| 94 | + } |
| 95 | + wolfBoot_printf("%x.%x.%x build %x\r\n", maj, min, rev, build); |
| 96 | +} |
0 commit comments