Andrey Petrov | 9738970 | 2016-02-25 14:15:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Lee Leahy | 47bd2d9 | 2016-07-24 18:12:16 -0700 | [diff] [blame] | 4 | * Copyright (C) 2015-2016 Intel Corp. |
Andrey Petrov | 9738970 | 2016-02-25 14:15:37 -0800 | [diff] [blame] | 5 | * (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> |
Patrick Rudolph | f677d17 | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 15 | #include <cf9_reset.h> |
Andrey Petrov | 9738970 | 2016-02-25 14:15:37 -0800 | [diff] [blame] | 16 | #include <console/console.h> |
| 17 | #include <fsp/util.h> |
Andrey Petrov | 9738970 | 2016-02-25 14:15:37 -0800 | [diff] [blame] | 18 | #include <string.h> |
| 19 | |
| 20 | static bool looks_like_fsp_header(const uint8_t *raw_hdr) |
| 21 | { |
| 22 | if (memcmp(raw_hdr, FSP_HDR_SIGNATURE, 4)) { |
| 23 | printk(BIOS_ALERT, "Did not find a valid FSP signature\n"); |
| 24 | return false; |
| 25 | } |
| 26 | |
| 27 | if (read32(raw_hdr + 4) != FSP_HDR_LEN) { |
| 28 | printk(BIOS_ALERT, "FSP header has invalid length\n"); |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | enum cb_err fsp_identify(struct fsp_header *hdr, const void *fsp_blob) |
| 36 | { |
| 37 | const uint8_t *raw_hdr = fsp_blob; |
| 38 | |
| 39 | if (!looks_like_fsp_header(raw_hdr)) |
| 40 | return CB_ERR; |
| 41 | |
Andrey Petrov | d5a6eb4 | 2016-05-04 17:30:16 -0700 | [diff] [blame] | 42 | hdr->spec_version = read8(raw_hdr + 10); |
Andrey Petrov | 9738970 | 2016-02-25 14:15:37 -0800 | [diff] [blame] | 43 | hdr->revision = read8(raw_hdr + 11); |
| 44 | hdr->fsp_revision = read32(raw_hdr + 12); |
| 45 | memcpy(hdr->image_id, raw_hdr + 16, ARRAY_SIZE(hdr->image_id)); |
| 46 | hdr->image_id[ARRAY_SIZE(hdr->image_id) - 1] = '\0'; |
| 47 | hdr->image_size = read32(raw_hdr + 24); |
| 48 | hdr->image_base = read32(raw_hdr + 28); |
Andrey Petrov | d5a6eb4 | 2016-05-04 17:30:16 -0700 | [diff] [blame] | 49 | hdr->image_attribute = read16(raw_hdr + 32); |
| 50 | hdr->component_attribute = read16(raw_hdr + 34); |
Andrey Petrov | 9738970 | 2016-02-25 14:15:37 -0800 | [diff] [blame] | 51 | hdr->cfg_region_offset = read32(raw_hdr + 36); |
| 52 | hdr->cfg_region_size = read32(raw_hdr + 40); |
Brenton Dong | 0a5971c | 2016-10-18 11:35:15 -0700 | [diff] [blame] | 53 | hdr->temp_ram_init_entry = read32(raw_hdr + 48); |
| 54 | hdr->temp_ram_exit_entry = read32(raw_hdr + 64); |
Andrey Petrov | 9738970 | 2016-02-25 14:15:37 -0800 | [diff] [blame] | 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 | |
Aaron Durbin | a413e5e | 2016-07-17 23:06:03 -0500 | [diff] [blame] | 62 | enum cb_err fsp_validate_component(struct fsp_header *hdr, |
| 63 | const struct region_device *rdev) |
| 64 | { |
| 65 | void *membase; |
| 66 | |
| 67 | /* Map just enough of the file to be able to parse the header. */ |
| 68 | membase = rdev_mmap(rdev, FSP_HDR_OFFSET, FSP_HDR_LEN); |
| 69 | |
| 70 | if (membase == NULL) { |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame] | 71 | printk(BIOS_CRIT, "Could not mmap() FSP header.\n"); |
Aaron Durbin | a413e5e | 2016-07-17 23:06:03 -0500 | [diff] [blame] | 72 | return CB_ERR; |
| 73 | } |
| 74 | |
| 75 | if (fsp_identify(hdr, membase) != CB_SUCCESS) { |
| 76 | rdev_munmap(rdev, membase); |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame] | 77 | printk(BIOS_CRIT, "No valid FSP header\n"); |
Aaron Durbin | a413e5e | 2016-07-17 23:06:03 -0500 | [diff] [blame] | 78 | return CB_ERR; |
| 79 | } |
| 80 | |
| 81 | rdev_munmap(rdev, membase); |
| 82 | |
Lee Leahy | 37b5ef2 | 2016-07-31 14:15:49 -0700 | [diff] [blame] | 83 | if (IS_ENABLED(CONFIG_DISPLAY_FSP_HEADER)) |
| 84 | fsp_print_header_info(hdr); |
Aaron Durbin | a413e5e | 2016-07-17 23:06:03 -0500 | [diff] [blame] | 85 | |
| 86 | /* Check if size specified in the header matches the cbfs file size */ |
| 87 | if (region_device_sz(rdev) < hdr->image_size) { |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame] | 88 | printk(BIOS_CRIT, "Component size bigger than cbfs file.\n"); |
Aaron Durbin | a413e5e | 2016-07-17 23:06:03 -0500 | [diff] [blame] | 89 | return CB_ERR; |
| 90 | } |
| 91 | |
| 92 | return CB_SUCCESS; |
| 93 | } |
| 94 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 95 | static bool fsp_reset_requested(uint32_t status) |
Andrey Petrov | 3a94a3b | 2016-07-18 00:15:41 -0700 | [diff] [blame] | 96 | { |
| 97 | return (status >= FSP_STATUS_RESET_REQUIRED_COLD && |
| 98 | status <= FSP_STATUS_RESET_REQUIRED_8); |
| 99 | } |
| 100 | |
Brandon Breitenstein | c31ba0e | 2016-07-27 17:34:45 -0700 | [diff] [blame] | 101 | void fsp_handle_reset(uint32_t status) |
Andrey Petrov | 901e43c | 2016-06-22 19:22:30 -0700 | [diff] [blame] | 102 | { |
Andrey Petrov | 3a94a3b | 2016-07-18 00:15:41 -0700 | [diff] [blame] | 103 | if (!fsp_reset_requested(status)) |
| 104 | return; |
| 105 | |
Lee Leahy | b20d4ba | 2016-07-31 16:49:28 -0700 | [diff] [blame] | 106 | printk(BIOS_SPEW, "FSP: handling reset type %x\n", status); |
Andrey Petrov | 3a94a3b | 2016-07-18 00:15:41 -0700 | [diff] [blame] | 107 | |
Lee Leahy | b2b97a5 | 2017-03-10 08:40:18 -0800 | [diff] [blame] | 108 | switch (status) { |
Andrey Petrov | 901e43c | 2016-06-22 19:22:30 -0700 | [diff] [blame] | 109 | case FSP_STATUS_RESET_REQUIRED_COLD: |
Patrick Rudolph | f677d17 | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 110 | full_reset(); |
Andrey Petrov | 901e43c | 2016-06-22 19:22:30 -0700 | [diff] [blame] | 111 | break; |
| 112 | case FSP_STATUS_RESET_REQUIRED_WARM: |
Patrick Rudolph | f677d17 | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 113 | system_reset(); |
Andrey Petrov | 901e43c | 2016-06-22 19:22:30 -0700 | [diff] [blame] | 114 | break; |
Andrey Petrov | 3a94a3b | 2016-07-18 00:15:41 -0700 | [diff] [blame] | 115 | case FSP_STATUS_RESET_REQUIRED_3: |
| 116 | case FSP_STATUS_RESET_REQUIRED_4: |
| 117 | case FSP_STATUS_RESET_REQUIRED_5: |
| 118 | case FSP_STATUS_RESET_REQUIRED_6: |
| 119 | case FSP_STATUS_RESET_REQUIRED_7: |
| 120 | case FSP_STATUS_RESET_REQUIRED_8: |
| 121 | chipset_handle_reset(status); |
Andrey Petrov | 901e43c | 2016-06-22 19:22:30 -0700 | [diff] [blame] | 122 | break; |
| 123 | default: |
| 124 | break; |
| 125 | } |
| 126 | } |