amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2018 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 16 | #include <arch/cpu.h> |
| 17 | #include <assert.h> |
| 18 | #include <baseboard/variants.h> |
Furquan Shaikh | f5b7e80 | 2018-05-07 14:42:27 -0700 | [diff] [blame] | 19 | #include <cbfs.h> |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 20 | #include <chip.h> |
Furquan Shaikh | f5b7e80 | 2018-05-07 14:42:27 -0700 | [diff] [blame] | 21 | #include <commonlib/cbfs_serialized.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 22 | #include <console/console.h> |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 23 | #include <device/device.h> |
Furquan Shaikh | c6141b9 | 2018-05-10 21:58:39 -0700 | [diff] [blame] | 24 | #include <drivers/intel/gma/opregion.h> |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 25 | #include <ec/google/chromeec/ec.h> |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 26 | #include <intelblocks/mp_init.h> |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 27 | #include <smbios.h> |
| 28 | #include <soc/ramstage.h> |
| 29 | #include <string.h> |
amanda_hwang | 04ccd5f | 2018-03-16 13:43:52 +0800 | [diff] [blame] | 30 | #include <variant/sku.h> |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 31 | |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 32 | #define PL2_I7_SKU 44 |
| 33 | #define PL2_DEFAULT 29 |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 34 | #define PL2_KBL_U 25 |
| 35 | |
| 36 | /* PL2 ID define*/ |
| 37 | #define PL2_ID_DEFAULT 0 |
| 38 | #define PL2_ID_SONA_SYNDRA 1 |
Ren Kuo | a355b16 | 2018-12-12 14:39:36 +0800 | [diff] [blame] | 39 | #define PL2_ID_BARD_EKKO 2 |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 40 | |
| 41 | static const struct pl2_config { |
| 42 | uint32_t cpuid_y0_pl2; |
| 43 | uint32_t cpuid_non_y0_pl2; |
| 44 | } pl2_config_table[] = { |
| 45 | [PL2_ID_DEFAULT] = { PL2_I7_SKU, PL2_DEFAULT }, |
| 46 | [PL2_ID_SONA_SYNDRA] = { PL2_DEFAULT, PL2_KBL_U }, |
Ren Kuo | a355b16 | 2018-12-12 14:39:36 +0800 | [diff] [blame] | 47 | [PL2_ID_BARD_EKKO] = { PL2_DEFAULT, PL2_KBL_U }, |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 48 | }; |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 49 | |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 50 | /* Variant for AKALI */ |
| 51 | #define AKALI_SA_AC_LOADLINE 1100 |
| 52 | #define AKALI_SA_DC_LOADLINE 1028 |
| 53 | #define AKALI_IA_AC_LOADLINE 272 |
| 54 | #define AKALI_IA_DC_LOADLINE 247 |
| 55 | #define AKALI_GT_AC_LOADLINE 314 |
| 56 | #define AKALI_GT_DC_LOADLINE 321 |
| 57 | |
| 58 | /* We only have Akali and Nami default settings so far */ |
| 59 | enum project_sku { |
| 60 | PRJ_AKALI = 1, |
| 61 | }; |
| 62 | |
| 63 | static const struct { |
| 64 | enum project_sku sku; |
| 65 | int ac_loadline[NUM_VR_DOMAINS]; |
| 66 | int dc_loadline[NUM_VR_DOMAINS]; |
| 67 | } sku_overwrite_mapping[] = { |
| 68 | { |
| 69 | .sku = PRJ_AKALI, |
| 70 | .ac_loadline = { |
| 71 | AKALI_SA_AC_LOADLINE, |
| 72 | AKALI_IA_AC_LOADLINE, |
| 73 | AKALI_GT_AC_LOADLINE, |
| 74 | AKALI_GT_AC_LOADLINE |
| 75 | }, |
| 76 | .dc_loadline = { |
| 77 | AKALI_SA_DC_LOADLINE, |
| 78 | AKALI_IA_DC_LOADLINE, |
| 79 | AKALI_GT_DC_LOADLINE, |
| 80 | AKALI_GT_DC_LOADLINE |
| 81 | } |
| 82 | }, |
| 83 | }; |
| 84 | |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 85 | static uint32_t get_pl2(int pl2_id) |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 86 | { |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 87 | assert(pl2_id < ARRAY_SIZE(pl2_config_table)); |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 88 | if (cpuid_eax(1) == CPUID_KABYLAKE_Y0) |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 89 | return pl2_config_table[pl2_id].cpuid_y0_pl2; |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 90 | |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 91 | return pl2_config_table[pl2_id].cpuid_non_y0_pl2; |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 94 | uint32_t variant_board_sku(void) |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 95 | { |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 96 | static uint32_t sku_id = SKU_UNKNOWN; |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 97 | uint32_t id; |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 98 | |
| 99 | if (sku_id != SKU_UNKNOWN) |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 100 | return sku_id; |
| 101 | if (google_chromeec_cbi_get_sku_id(&id)) |
| 102 | return SKU_UNKNOWN; |
| 103 | sku_id = id; |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 104 | |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 105 | return sku_id; |
| 106 | } |
| 107 | |
Nico Huber | ebd8a4f | 2017-11-01 09:49:16 +0100 | [diff] [blame] | 108 | const char *smbios_system_sku(void) |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 109 | { |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 110 | static char sku_str[14]; /* sku{0..4294967295} */ |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 111 | |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 112 | snprintf(sku_str, sizeof(sku_str), "sku%u", variant_board_sku()); |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 113 | |
| 114 | return sku_str; |
| 115 | } |
Furquan Shaikh | f5b7e80 | 2018-05-07 14:42:27 -0700 | [diff] [blame] | 116 | |
| 117 | #define OEM_UNKNOWN 0xff |
| 118 | |
| 119 | /* |
| 120 | * Read OEM ID from EC using cbi commands. |
| 121 | * Return value: |
| 122 | * Success = OEM ID read from EC |
| 123 | * Failure = OEM_UNKNOWN (0xff) |
| 124 | */ |
| 125 | static uint8_t read_oem_id(void) |
| 126 | { |
| 127 | static uint8_t oem_id = OEM_UNKNOWN; |
| 128 | uint32_t id; |
| 129 | |
| 130 | if (oem_id != OEM_UNKNOWN) |
| 131 | return oem_id; |
| 132 | |
| 133 | if (google_chromeec_cbi_get_oem_id(&id)) |
| 134 | return OEM_UNKNOWN; |
| 135 | |
| 136 | if (id > OEM_UNKNOWN) { |
| 137 | printk(BIOS_ERR, "%s: OEM ID too big %u!\n", __func__, id); |
| 138 | return OEM_UNKNOWN; |
| 139 | } |
| 140 | |
| 141 | oem_id = id; |
| 142 | printk(BIOS_DEBUG, "%s: OEM ID=%d\n", __func__, oem_id); |
| 143 | |
| 144 | return oem_id; |
| 145 | } |
| 146 | |
| 147 | /* "oem.bin" in cbfs contains array of records using the following structure. */ |
| 148 | struct oem_mapping { |
| 149 | uint8_t oem_id; |
| 150 | char oem_name[10]; |
| 151 | } __packed; |
| 152 | |
| 153 | /* Local buffer to read "oem.bin" */ |
| 154 | static char oem_bin_data[200]; |
| 155 | |
| 156 | const char *smbios_mainboard_manufacturer(void) |
| 157 | { |
| 158 | uint8_t oem_id = read_oem_id(); |
| 159 | const struct oem_mapping *oem_entry = (void *)&oem_bin_data; |
| 160 | size_t oem_data_size; |
| 161 | size_t curr = 0; |
| 162 | static const char *manuf; |
| 163 | |
| 164 | if (manuf) |
| 165 | return manuf; |
| 166 | |
| 167 | /* If OEM ID cannot be determined, return default manuf string. */ |
| 168 | if (oem_id == OEM_UNKNOWN) |
| 169 | return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER; |
| 170 | |
| 171 | oem_data_size = cbfs_boot_load_file("oem.bin", oem_bin_data, |
| 172 | sizeof(oem_bin_data), |
| 173 | CBFS_TYPE_RAW); |
| 174 | |
| 175 | while ((curr < oem_data_size) && |
| 176 | ((oem_data_size - curr) >= sizeof(*oem_entry))) { |
| 177 | if (oem_id == oem_entry->oem_id) { |
| 178 | manuf = oem_entry->oem_name; |
| 179 | break; |
| 180 | } |
| 181 | curr += sizeof(*oem_entry); |
| 182 | oem_entry++; |
| 183 | } |
| 184 | |
| 185 | if (manuf == NULL) |
| 186 | manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER; |
| 187 | |
| 188 | return manuf; |
| 189 | } |
Furquan Shaikh | c6141b9 | 2018-05-10 21:58:39 -0700 | [diff] [blame] | 190 | |
| 191 | const char *mainboard_vbt_filename(void) |
| 192 | { |
| 193 | uint32_t sku_id = variant_board_sku(); |
| 194 | |
| 195 | switch (sku_id) { |
Ivy Jian | faafbfb | 2018-05-14 09:38:20 +0800 | [diff] [blame] | 196 | case SKU_0_PANTHEON: |
| 197 | case SKU_1_PANTHEON: |
Ivy Jian | 457253c | 2018-07-11 14:15:29 +0800 | [diff] [blame] | 198 | case SKU_2_PANTHEON: |
John Su | c2209e4 | 2019-03-05 10:41:46 +0800 | [diff] [blame] | 199 | case SKU_3_PANTHEON: |
| 200 | case SKU_4_PANTHEON: |
Ivy Jian | faafbfb | 2018-05-14 09:38:20 +0800 | [diff] [blame] | 201 | return "vbt-pantheon.bin"; |
Ivy Jian | 8bd5c5f | 2018-06-01 15:43:56 +0800 | [diff] [blame] | 202 | case SKU_0_VAYNE: |
| 203 | case SKU_1_VAYNE: |
| 204 | case SKU_2_VAYNE: |
| 205 | return "vbt-vayne.bin"; |
T.H. Lin | 770b034 | 2018-07-17 16:09:04 +0800 | [diff] [blame] | 206 | case SKU_0_AKALI: |
| 207 | case SKU_1_AKALI: |
| 208 | case SKU_0_AKALI360: |
| 209 | case SKU_1_AKALI360: |
| 210 | return "vbt-akali.bin"; |
Ren Kuo | 337afb0 | 2018-12-22 15:04:56 +0800 | [diff] [blame] | 211 | case SKU_0_BARD: |
| 212 | case SKU_1_BARD: |
| 213 | case SKU_2_BARD: |
| 214 | case SKU_3_BARD: |
Ren Kuo | deab64d | 2019-07-19 11:10:10 +0800 | [diff] [blame^] | 215 | case SKU_4_BARD: |
| 216 | case SKU_5_BARD: |
Ren Kuo | 337afb0 | 2018-12-22 15:04:56 +0800 | [diff] [blame] | 217 | return "vbt-bard.bin"; |
Furquan Shaikh | c6141b9 | 2018-05-10 21:58:39 -0700 | [diff] [blame] | 218 | default: |
| 219 | return "vbt.bin"; |
Furquan Shaikh | c6141b9 | 2018-05-10 21:58:39 -0700 | [diff] [blame] | 220 | } |
| 221 | } |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 222 | |
| 223 | static int find_sku_mapping(const uint8_t oem_id) |
| 224 | { |
| 225 | /* Check if this OEM ID has a mapping table entry. */ |
| 226 | for (int i = 0; i < ARRAY_SIZE(sku_overwrite_mapping); i++) |
| 227 | if (oem_id == sku_overwrite_mapping[i].sku) |
| 228 | return i; |
| 229 | |
| 230 | return -1; |
| 231 | } |
| 232 | |
| 233 | /* Override dev tree settings per board */ |
| 234 | void variant_devtree_update(void) |
| 235 | { |
| 236 | uint32_t sku_id = variant_board_sku(); |
| 237 | uint32_t i; |
| 238 | int oem_index; |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 239 | uint8_t pl2_id = PL2_ID_DEFAULT; |
Ivy Jian | b80d132 | 2019-05-27 11:19:44 +0800 | [diff] [blame] | 240 | struct device *spi_fpmcu = PCH_DEV_GSPI1; |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 241 | |
Kyösti Mälkki | 28dc7dc | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 242 | config_t *cfg = config_of_path(SA_DEVFN_ROOT); |
| 243 | |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 244 | switch (sku_id) { |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 245 | case SKU_0_SONA: |
| 246 | case SKU_1_SONA: |
Amanda Huang | f7b57d0 | 2018-10-11 11:39:37 +0800 | [diff] [blame] | 247 | case SKU_0_SYNDRA: |
| 248 | case SKU_1_SYNDRA: |
| 249 | case SKU_2_SYNDRA: |
| 250 | case SKU_3_SYNDRA: |
Amanda Huang | 3080fe0 | 2018-12-17 13:25:03 +0800 | [diff] [blame] | 251 | case SKU_4_SYNDRA: |
| 252 | case SKU_5_SYNDRA: |
| 253 | case SKU_6_SYNDRA: |
| 254 | case SKU_7_SYNDRA: |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 255 | pl2_id = PL2_ID_SONA_SYNDRA; |
Jacob Garber | 38b7445 | 2019-05-31 14:43:19 -0600 | [diff] [blame] | 256 | /* fallthrough */ |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 257 | case SKU_0_VAYNE: |
| 258 | case SKU_1_VAYNE: |
| 259 | case SKU_2_VAYNE: |
| 260 | case SKU_0_PANTHEON: |
| 261 | case SKU_1_PANTHEON: |
| 262 | case SKU_2_PANTHEON: |
Frank Wu | d0cc3bc | 2018-12-24 11:25:36 +0800 | [diff] [blame] | 263 | case SKU_3_PANTHEON: |
| 264 | case SKU_4_PANTHEON: |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 265 | cfg->usb2_ports[5].enable = 0; |
Ivy Jian | b80d132 | 2019-05-27 11:19:44 +0800 | [diff] [blame] | 266 | spi_fpmcu->enabled = 0; |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 267 | break; |
Ren Kuo | a355b16 | 2018-12-12 14:39:36 +0800 | [diff] [blame] | 268 | case SKU_0_BARD: |
| 269 | case SKU_1_BARD: |
| 270 | case SKU_2_BARD: |
| 271 | case SKU_3_BARD: |
Ren Kuo | deab64d | 2019-07-19 11:10:10 +0800 | [diff] [blame^] | 272 | case SKU_4_BARD: |
| 273 | case SKU_5_BARD: |
Ren Kuo | a355b16 | 2018-12-12 14:39:36 +0800 | [diff] [blame] | 274 | case SKU_0_EKKO: |
| 275 | case SKU_1_EKKO: |
| 276 | case SKU_2_EKKO: |
| 277 | case SKU_3_EKKO: |
| 278 | pl2_id = PL2_ID_BARD_EKKO; |
Ren Kuo | 03f654c | 2019-01-18 17:12:33 +0800 | [diff] [blame] | 279 | cfg->usb2_ports[5].enable = 0; |
| 280 | cfg->usb2_ports[7].enable = 0; |
| 281 | cfg->usb2_ports[8].enable = 0; |
| 282 | cfg->usb2_ports[9].enable = 0; |
Ren Kuo | a355b16 | 2018-12-12 14:39:36 +0800 | [diff] [blame] | 283 | break; |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 284 | default: |
| 285 | break; |
| 286 | } |
| 287 | |
John Su | 2257a35 | 2018-10-25 19:21:15 +0800 | [diff] [blame] | 288 | /* Update PL2 based on SKU. */ |
| 289 | cfg->tdp_pl2_override = get_pl2(pl2_id); |
| 290 | |
Gaggery Tsai | 7062777 | 2018-07-26 00:14:09 -0700 | [diff] [blame] | 291 | /* Overwrite settings for different projects based on OEM ID*/ |
| 292 | oem_index = find_sku_mapping(read_oem_id()); |
| 293 | |
| 294 | /* Return if the OEM ID is not supported or no changes are required */ |
| 295 | if (oem_index < 0) |
| 296 | return; |
| 297 | |
| 298 | for (i = 0; i < ARRAY_SIZE(cfg->domain_vr_config); i++) { |
| 299 | cfg->domain_vr_config[i].ac_loadline = |
| 300 | sku_overwrite_mapping[oem_index].ac_loadline[i]; |
| 301 | cfg->domain_vr_config[i].dc_loadline = |
| 302 | sku_overwrite_mapping[oem_index].dc_loadline[i]; |
| 303 | } |
| 304 | } |