Angel Pons | b04c2f8 | 2020-04-03 01:23:20 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 2 | |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 3 | #include <console/console.h> |
Julien Viard de Galbert | ae6210e | 2018-02-22 14:22:15 +0100 | [diff] [blame] | 4 | #include <console/uart.h> |
Felix Held | 5f12b7b | 2021-09-16 22:00:24 +0200 | [diff] [blame] | 5 | #include <types.h> |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 6 | |
| 7 | #include "bmcinfo.h" |
| 8 | |
| 9 | typedef struct { |
| 10 | u32 magic0; // "BMCI" |
| 11 | u32 magic1; // "nfo0" |
| 12 | u16 length; |
| 13 | u16 chksum; |
| 14 | u8 uuid[16]; |
| 15 | u8 bmcSerial[9]; // as null terminated string |
| 16 | u8 slot; |
| 17 | u8 corebootVerbosityLevel; |
| 18 | u8 relaxSecurity; |
| 19 | u32 baudrate; |
| 20 | u8 bootOption; |
| 21 | u8 hwRev; // Note: Initial implementation ended here |
| 22 | u8 disableNic1; |
| 23 | u8 endMarker; // Insert new fields before |
| 24 | } biosBmcInfo_t; |
| 25 | |
| 26 | #define BIOSBMCINFO_MAGIC0 0x49434d42 |
| 27 | #define BIOSBMCINFO_MAGIC1 0x306f666e |
| 28 | |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 29 | #define BMC_INFO ((biosBmcInfo_t *)CONFIG_BMC_INFO_LOC) |
| 30 | |
| 31 | enum biosBmcInfoValidFlag_e { |
| 32 | BMCINFO_UNTESTED = 0, |
| 33 | BMCINFO_INVALID, |
| 34 | BMCINFO_INVALID_WARNED, |
| 35 | BMCINFO_VALID_NEED_WARN, |
| 36 | BMCINFO_VALID, |
| 37 | }; |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 38 | static bool bmcinfo_is_valid(size_t minsize) |
| 39 | { |
Kyösti Mälkki | 2f944f4 | 2019-08-18 22:10:51 +0300 | [diff] [blame] | 40 | static enum biosBmcInfoValidFlag_e biosBmcInfoValidFlag; |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 41 | const biosBmcInfo_t *bmc_info = BMC_INFO; |
Kyösti Mälkki | 2f944f4 | 2019-08-18 22:10:51 +0300 | [diff] [blame] | 42 | if (biosBmcInfoValidFlag == BMCINFO_UNTESTED) { |
| 43 | biosBmcInfoValidFlag = BMCINFO_INVALID; |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 44 | if ((bmc_info->magic0 == BIOSBMCINFO_MAGIC0) |
| 45 | && (bmc_info->magic1 == BIOSBMCINFO_MAGIC1) |
| 46 | && (bmc_info->length >= offsetof(biosBmcInfo_t, hwRev)) |
| 47 | && (bmc_info->length <= 0x1000)) { |
| 48 | u16 chksum = 0 - (bmc_info->chksum & 0xff) |
| 49 | - (bmc_info->chksum >> 8); |
| 50 | int i; |
| 51 | for (i = 0; i < bmc_info->length ; i++) |
| 52 | chksum += ((u8 *)bmc_info)[i]; |
| 53 | if (bmc_info->chksum == chksum) { |
| 54 | if (bmc_info->length >= offsetof(biosBmcInfo_t, |
| 55 | endMarker)) |
Kyösti Mälkki | 2f944f4 | 2019-08-18 22:10:51 +0300 | [diff] [blame] | 56 | biosBmcInfoValidFlag = BMCINFO_VALID; |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 57 | else |
Kyösti Mälkki | 2f944f4 | 2019-08-18 22:10:51 +0300 | [diff] [blame] | 58 | biosBmcInfoValidFlag = BMCINFO_VALID_NEED_WARN; |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 59 | } |
| 60 | } |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 61 | } |
Kyösti Mälkki | 2f944f4 | 2019-08-18 22:10:51 +0300 | [diff] [blame] | 62 | if (ENV_RAMSTAGE && biosBmcInfoValidFlag == BMCINFO_INVALID) { |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 63 | int length = offsetof(biosBmcInfo_t, endMarker); |
| 64 | printk(BIOS_CRIT, "WARNING bmcInfo struct" |
| 65 | "is not available please update your BMC.\n"); |
Kyösti Mälkki | 2f944f4 | 2019-08-18 22:10:51 +0300 | [diff] [blame] | 66 | biosBmcInfoValidFlag = BMCINFO_INVALID_WARNED; |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 67 | printk(BIOS_CRIT, "bmcInfo magic = \"%x-%x\"\n", |
| 68 | bmc_info->magic0, bmc_info->magic1); |
| 69 | printk(BIOS_CRIT, "bmcInfo length = %d expected = %d\"\n", |
| 70 | bmc_info->length, length); |
| 71 | u16 chksum = 0 - (bmc_info->chksum & 0xff) |
| 72 | - (bmc_info->chksum >> 8); |
| 73 | int i; |
| 74 | for (i = 0; i < bmc_info->length; i++) |
| 75 | chksum += ((u8 *)bmc_info)[i]; |
| 76 | printk(BIOS_CRIT, "bmcInfo chksum = 0x%x expected = 0x%x\"\n", |
| 77 | bmc_info->chksum, chksum); |
| 78 | } |
Kyösti Mälkki | 2f944f4 | 2019-08-18 22:10:51 +0300 | [diff] [blame] | 79 | if (ENV_RAMSTAGE && biosBmcInfoValidFlag == BMCINFO_VALID_NEED_WARN) { |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 80 | printk(BIOS_CRIT, "WARNING bmcInfo struct" |
| 81 | " is incomplete please update your BMC.\n"); |
| 82 | |
Kyösti Mälkki | 2f944f4 | 2019-08-18 22:10:51 +0300 | [diff] [blame] | 83 | biosBmcInfoValidFlag = BMCINFO_VALID; |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 84 | } |
Kyösti Mälkki | 2f944f4 | 2019-08-18 22:10:51 +0300 | [diff] [blame] | 85 | if (biosBmcInfoValidFlag < BMCINFO_VALID_NEED_WARN) |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 86 | return false; |
| 87 | return (bmc_info->length >= minsize); |
| 88 | } |
| 89 | |
| 90 | #define IS_BMC_INFO_FIELD_VALID(field) \ |
| 91 | (bmcinfo_is_valid(offsetof(biosBmcInfo_t, field) \ |
| 92 | + sizeof(((biosBmcInfo_t *)0)->field))) |
| 93 | |
| 94 | char *bmcinfo_serial(void) |
| 95 | { |
| 96 | if (IS_BMC_INFO_FIELD_VALID(bmcSerial)) |
Elyes Haouas | 486240f | 2022-11-18 15:21:03 +0100 | [diff] [blame^] | 97 | return (char *)BMC_INFO->bmcSerial; |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | u8 *bmcinfo_uuid(void) |
| 102 | { |
| 103 | if (IS_BMC_INFO_FIELD_VALID(uuid)) |
| 104 | return BMC_INFO->uuid; |
| 105 | return NULL; |
| 106 | } |
| 107 | |
Julien Viard de Galbert | 0e755d4 | 2018-03-07 15:48:54 +0100 | [diff] [blame] | 108 | int bmcinfo_slot(void) |
| 109 | { |
| 110 | if (IS_BMC_INFO_FIELD_VALID(slot)) |
| 111 | return BMC_INFO->slot; |
| 112 | return -1; |
| 113 | } |
| 114 | |
| 115 | int bmcinfo_hwrev(void) |
| 116 | { |
| 117 | if (IS_BMC_INFO_FIELD_VALID(hwRev)) |
| 118 | return BMC_INFO->hwRev; |
| 119 | return -1; |
| 120 | } |
| 121 | |
| 122 | u32 bmcinfo_baudrate(void) |
| 123 | { |
| 124 | if (IS_BMC_INFO_FIELD_VALID(baudrate)) |
| 125 | return BMC_INFO->baudrate; |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | int bmcinfo_coreboot_verbosity_level(void) |
| 130 | { |
| 131 | if (IS_BMC_INFO_FIELD_VALID(corebootVerbosityLevel)) |
| 132 | return BMC_INFO->corebootVerbosityLevel & 0xf; |
| 133 | return BIOS_CRIT; |
| 134 | } |
| 135 | |
| 136 | int bmcinfo_fsp_verbosity_level(void) |
| 137 | { |
| 138 | if (IS_BMC_INFO_FIELD_VALID(corebootVerbosityLevel)) |
| 139 | return BMC_INFO->corebootVerbosityLevel >> 4; |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | int bmcinfo_relax_security(void) |
| 144 | { |
| 145 | if (IS_BMC_INFO_FIELD_VALID(relaxSecurity)) |
| 146 | return BMC_INFO->relaxSecurity; |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | int bmcinfo_boot_option(void) |
| 151 | { |
| 152 | if (IS_BMC_INFO_FIELD_VALID(bootOption)) |
| 153 | return BMC_INFO->bootOption; |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | int bmcinfo_disable_nic1(void) |
| 158 | { |
| 159 | if (IS_BMC_INFO_FIELD_VALID(disableNic1)) |
| 160 | return BMC_INFO->disableNic1; |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | /* Add override functions below */ |
Julien Viard de Galbert | fad5c44 | 2018-03-07 15:50:22 +0100 | [diff] [blame] | 165 | |
Julien Viard de Galbert | ae6210e | 2018-02-22 14:22:15 +0100 | [diff] [blame] | 166 | /* Override default uart baudrate */ |
| 167 | unsigned int get_uart_baudrate(void) |
| 168 | { |
| 169 | int baudrate = bmcinfo_baudrate(); |
| 170 | if (baudrate) |
| 171 | return baudrate; |
| 172 | return 115200; |
| 173 | } |
| 174 | |
Julien Viard de Galbert | fad5c44 | 2018-03-07 15:50:22 +0100 | [diff] [blame] | 175 | #if __CONSOLE_ENABLE__ |
| 176 | /* Override default console loglevel */ |
| 177 | int get_console_loglevel(void) |
| 178 | { |
| 179 | return bmcinfo_coreboot_verbosity_level(); |
| 180 | } |
| 181 | #endif |