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