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 | |
John Su | bac90c0 | 2018-06-28 14:29:23 +0800 | [diff] [blame] | 36 | static uint32_t get_pl2(uint32_t sku_id) |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 37 | { |
John Su | bac90c0 | 2018-06-28 14:29:23 +0800 | [diff] [blame] | 38 | if ((sku_id == SKU_0_SONA) || (sku_id == SKU_1_SONA)) { |
| 39 | if (cpuid_eax(1) == CPUID_KABYLAKE_Y0) |
| 40 | return PL2_DEFAULT; |
| 41 | |
| 42 | return PL2_KBL_R; |
| 43 | } |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 44 | if (cpuid_eax(1) == CPUID_KABYLAKE_Y0) |
| 45 | return PL2_I7_SKU; |
| 46 | |
| 47 | return PL2_DEFAULT; |
| 48 | } |
| 49 | |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 50 | uint32_t variant_board_sku(void) |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 51 | { |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 52 | static uint32_t sku_id = SKU_UNKNOWN; |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 53 | uint32_t id; |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 54 | |
| 55 | if (sku_id != SKU_UNKNOWN) |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 56 | return sku_id; |
| 57 | if (google_chromeec_cbi_get_sku_id(&id)) |
| 58 | return SKU_UNKNOWN; |
| 59 | sku_id = id; |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 60 | |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 61 | return sku_id; |
| 62 | } |
| 63 | |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 64 | /* Override dev tree settings per board */ |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 65 | void variant_devtree_update(void) |
| 66 | { |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 67 | uint32_t sku_id = variant_board_sku(); |
Elyes HAOUAS | d129d43 | 2018-05-04 20:23:33 +0200 | [diff] [blame] | 68 | struct device *root = SA_DEV_ROOT; |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 69 | config_t *cfg = root->chip_info; |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 70 | |
| 71 | /* Update PL2 based on SKU. */ |
John Su | bac90c0 | 2018-06-28 14:29:23 +0800 | [diff] [blame] | 72 | cfg->tdp_pl2_override = get_pl2(sku_id); |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 73 | |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 74 | switch (sku_id) { |
Van Chen | a51ff07 | 2018-06-05 11:47:42 +0800 | [diff] [blame] | 75 | case SKU_0_VAYNE: |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 76 | case SKU_1_VAYNE: |
Amanda Huang | 7024e66 | 2018-04-10 14:09:36 +0800 | [diff] [blame] | 77 | case SKU_2_VAYNE: |
Amanda Huang | cd27b8d5 | 2018-06-06 14:50:29 +0800 | [diff] [blame] | 78 | case SKU_0_PANTHEON: |
| 79 | case SKU_1_PANTHEON: |
| 80 | case SKU_2_PANTHEON: |
Amanda Huang | 07a803d | 2018-06-06 14:57:25 +0800 | [diff] [blame] | 81 | case SKU_0_SONA: |
| 82 | case SKU_1_SONA: |
Furquan Shaikh | e301145 | 2018-05-23 21:27:33 -0700 | [diff] [blame] | 83 | /* Disable unused port USB port */ |
| 84 | cfg->usb2_ports[5].enable = 0; |
amanda_hwang | b3b47e1 | 2018-03-08 11:04:40 +0800 | [diff] [blame] | 85 | break; |
| 86 | default: |
| 87 | break; |
| 88 | } |
| 89 | } |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 90 | |
| 91 | const char *smbios_mainboard_sku(void) |
| 92 | { |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 93 | static char sku_str[14]; /* sku{0..4294967295} */ |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 94 | |
Zhuohao Lee | f7b5955 | 2018-03-17 05:00:49 +0800 | [diff] [blame] | 95 | snprintf(sku_str, sizeof(sku_str), "sku%u", variant_board_sku()); |
Shelley Chen | 467cce4 | 2018-03-07 14:22:28 -0800 | [diff] [blame] | 96 | |
| 97 | return sku_str; |
| 98 | } |
Furquan Shaikh | f5b7e80 | 2018-05-07 14:42:27 -0700 | [diff] [blame] | 99 | |
| 100 | #define OEM_UNKNOWN 0xff |
| 101 | |
| 102 | /* |
| 103 | * Read OEM ID from EC using cbi commands. |
| 104 | * Return value: |
| 105 | * Success = OEM ID read from EC |
| 106 | * Failure = OEM_UNKNOWN (0xff) |
| 107 | */ |
| 108 | static uint8_t read_oem_id(void) |
| 109 | { |
| 110 | static uint8_t oem_id = OEM_UNKNOWN; |
| 111 | uint32_t id; |
| 112 | |
| 113 | if (oem_id != OEM_UNKNOWN) |
| 114 | return oem_id; |
| 115 | |
| 116 | if (google_chromeec_cbi_get_oem_id(&id)) |
| 117 | return OEM_UNKNOWN; |
| 118 | |
| 119 | if (id > OEM_UNKNOWN) { |
| 120 | printk(BIOS_ERR, "%s: OEM ID too big %u!\n", __func__, id); |
| 121 | return OEM_UNKNOWN; |
| 122 | } |
| 123 | |
| 124 | oem_id = id; |
| 125 | printk(BIOS_DEBUG, "%s: OEM ID=%d\n", __func__, oem_id); |
| 126 | |
| 127 | return oem_id; |
| 128 | } |
| 129 | |
| 130 | /* "oem.bin" in cbfs contains array of records using the following structure. */ |
| 131 | struct oem_mapping { |
| 132 | uint8_t oem_id; |
| 133 | char oem_name[10]; |
| 134 | } __packed; |
| 135 | |
| 136 | /* Local buffer to read "oem.bin" */ |
| 137 | static char oem_bin_data[200]; |
| 138 | |
| 139 | const char *smbios_mainboard_manufacturer(void) |
| 140 | { |
| 141 | uint8_t oem_id = read_oem_id(); |
| 142 | const struct oem_mapping *oem_entry = (void *)&oem_bin_data; |
| 143 | size_t oem_data_size; |
| 144 | size_t curr = 0; |
| 145 | static const char *manuf; |
| 146 | |
| 147 | if (manuf) |
| 148 | return manuf; |
| 149 | |
| 150 | /* If OEM ID cannot be determined, return default manuf string. */ |
| 151 | if (oem_id == OEM_UNKNOWN) |
| 152 | return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER; |
| 153 | |
| 154 | oem_data_size = cbfs_boot_load_file("oem.bin", oem_bin_data, |
| 155 | sizeof(oem_bin_data), |
| 156 | CBFS_TYPE_RAW); |
| 157 | |
| 158 | while ((curr < oem_data_size) && |
| 159 | ((oem_data_size - curr) >= sizeof(*oem_entry))) { |
| 160 | if (oem_id == oem_entry->oem_id) { |
| 161 | manuf = oem_entry->oem_name; |
| 162 | break; |
| 163 | } |
| 164 | curr += sizeof(*oem_entry); |
| 165 | oem_entry++; |
| 166 | } |
| 167 | |
| 168 | if (manuf == NULL) |
| 169 | manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER; |
| 170 | |
| 171 | return manuf; |
| 172 | } |
Furquan Shaikh | c6141b9 | 2018-05-10 21:58:39 -0700 | [diff] [blame] | 173 | |
| 174 | const char *mainboard_vbt_filename(void) |
| 175 | { |
| 176 | uint32_t sku_id = variant_board_sku(); |
| 177 | |
| 178 | switch (sku_id) { |
Ivy Jian | faafbfb | 2018-05-14 09:38:20 +0800 | [diff] [blame] | 179 | case SKU_0_PANTHEON: |
| 180 | case SKU_1_PANTHEON: |
Ivy Jian | 457253c | 2018-07-11 14:15:29 +0800 | [diff] [blame^] | 181 | case SKU_2_PANTHEON: |
Ivy Jian | faafbfb | 2018-05-14 09:38:20 +0800 | [diff] [blame] | 182 | return "vbt-pantheon.bin"; |
Ivy Jian | 8bd5c5f | 2018-06-01 15:43:56 +0800 | [diff] [blame] | 183 | case SKU_0_VAYNE: |
| 184 | case SKU_1_VAYNE: |
| 185 | case SKU_2_VAYNE: |
| 186 | return "vbt-vayne.bin"; |
Furquan Shaikh | c6141b9 | 2018-05-10 21:58:39 -0700 | [diff] [blame] | 187 | default: |
| 188 | return "vbt.bin"; |
| 189 | break; |
| 190 | } |
| 191 | } |