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