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