blob: 8080c9492123ecdbee657964604e05b926bdf32a [file] [log] [blame]
amanda_hwangb3b47e12018-03-08 11:04:40 +08001/*
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 Chen467cce42018-03-07 14:22:28 -080016#include <arch/cpu.h>
17#include <assert.h>
18#include <baseboard/variants.h>
Furquan Shaikhf5b7e802018-05-07 14:42:27 -070019#include <cbfs.h>
amanda_hwangb3b47e12018-03-08 11:04:40 +080020#include <chip.h>
Furquan Shaikhf5b7e802018-05-07 14:42:27 -070021#include <commonlib/cbfs_serialized.h>
22#include <compiler.h>
amanda_hwangb3b47e12018-03-08 11:04:40 +080023#include <device/device.h>
Furquan Shaikhc6141b92018-05-10 21:58:39 -070024#include <drivers/intel/gma/opregion.h>
amanda_hwangb3b47e12018-03-08 11:04:40 +080025#include <ec/google/chromeec/ec.h>
Furquan Shaikhe3011452018-05-23 21:27:33 -070026#include <intelblocks/mp_init.h>
Shelley Chen467cce42018-03-07 14:22:28 -080027#include <smbios.h>
28#include <soc/ramstage.h>
29#include <string.h>
amanda_hwang04ccd5f2018-03-16 13:43:52 +080030#include <variant/sku.h>
amanda_hwangb3b47e12018-03-08 11:04:40 +080031
Furquan Shaikhe3011452018-05-23 21:27:33 -070032#define PL2_I7_SKU 44
33#define PL2_DEFAULT 29
John Subac90c02018-06-28 14:29:23 +080034#define PL2_KBL_R 25
Furquan Shaikhe3011452018-05-23 21:27:33 -070035
John Subac90c02018-06-28 14:29:23 +080036static uint32_t get_pl2(uint32_t sku_id)
Furquan Shaikhe3011452018-05-23 21:27:33 -070037{
John Subac90c02018-06-28 14:29:23 +080038 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 Shaikhe3011452018-05-23 21:27:33 -070044 if (cpuid_eax(1) == CPUID_KABYLAKE_Y0)
45 return PL2_I7_SKU;
46
47 return PL2_DEFAULT;
48}
49
Zhuohao Leef7b59552018-03-17 05:00:49 +080050uint32_t variant_board_sku(void)
amanda_hwangb3b47e12018-03-08 11:04:40 +080051{
Zhuohao Leef7b59552018-03-17 05:00:49 +080052 static uint32_t sku_id = SKU_UNKNOWN;
amanda_hwangb3b47e12018-03-08 11:04:40 +080053 uint32_t id;
Zhuohao Leef7b59552018-03-17 05:00:49 +080054
55 if (sku_id != SKU_UNKNOWN)
amanda_hwangb3b47e12018-03-08 11:04:40 +080056 return sku_id;
57 if (google_chromeec_cbi_get_sku_id(&id))
58 return SKU_UNKNOWN;
59 sku_id = id;
Zhuohao Leef7b59552018-03-17 05:00:49 +080060
amanda_hwangb3b47e12018-03-08 11:04:40 +080061 return sku_id;
62}
63
Furquan Shaikhe3011452018-05-23 21:27:33 -070064/* Override dev tree settings per board */
amanda_hwangb3b47e12018-03-08 11:04:40 +080065void variant_devtree_update(void)
66{
Zhuohao Leef7b59552018-03-17 05:00:49 +080067 uint32_t sku_id = variant_board_sku();
Elyes HAOUASd129d432018-05-04 20:23:33 +020068 struct device *root = SA_DEV_ROOT;
amanda_hwangb3b47e12018-03-08 11:04:40 +080069 config_t *cfg = root->chip_info;
Furquan Shaikhe3011452018-05-23 21:27:33 -070070
71 /* Update PL2 based on SKU. */
John Subac90c02018-06-28 14:29:23 +080072 cfg->tdp_pl2_override = get_pl2(sku_id);
Furquan Shaikhe3011452018-05-23 21:27:33 -070073
amanda_hwangb3b47e12018-03-08 11:04:40 +080074 switch (sku_id) {
Van Chena51ff072018-06-05 11:47:42 +080075 case SKU_0_VAYNE:
amanda_hwangb3b47e12018-03-08 11:04:40 +080076 case SKU_1_VAYNE:
Amanda Huang7024e662018-04-10 14:09:36 +080077 case SKU_2_VAYNE:
Amanda Huangcd27b8d52018-06-06 14:50:29 +080078 case SKU_0_PANTHEON:
79 case SKU_1_PANTHEON:
80 case SKU_2_PANTHEON:
Amanda Huang07a803d2018-06-06 14:57:25 +080081 case SKU_0_SONA:
82 case SKU_1_SONA:
Furquan Shaikhe3011452018-05-23 21:27:33 -070083 /* Disable unused port USB port */
84 cfg->usb2_ports[5].enable = 0;
amanda_hwangb3b47e12018-03-08 11:04:40 +080085 break;
86 default:
87 break;
88 }
89}
Shelley Chen467cce42018-03-07 14:22:28 -080090
91const char *smbios_mainboard_sku(void)
92{
Zhuohao Leef7b59552018-03-17 05:00:49 +080093 static char sku_str[14]; /* sku{0..4294967295} */
Shelley Chen467cce42018-03-07 14:22:28 -080094
Zhuohao Leef7b59552018-03-17 05:00:49 +080095 snprintf(sku_str, sizeof(sku_str), "sku%u", variant_board_sku());
Shelley Chen467cce42018-03-07 14:22:28 -080096
97 return sku_str;
98}
Furquan Shaikhf5b7e802018-05-07 14:42:27 -070099
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 */
108static 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. */
131struct oem_mapping {
132 uint8_t oem_id;
133 char oem_name[10];
134} __packed;
135
136/* Local buffer to read "oem.bin" */
137static char oem_bin_data[200];
138
139const 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 Shaikhc6141b92018-05-10 21:58:39 -0700173
174const char *mainboard_vbt_filename(void)
175{
176 uint32_t sku_id = variant_board_sku();
177
178 switch (sku_id) {
Ivy Jianfaafbfb2018-05-14 09:38:20 +0800179 case SKU_0_PANTHEON:
180 case SKU_1_PANTHEON:
Ivy Jian457253c2018-07-11 14:15:29 +0800181 case SKU_2_PANTHEON:
Ivy Jianfaafbfb2018-05-14 09:38:20 +0800182 return "vbt-pantheon.bin";
Ivy Jian8bd5c5f2018-06-01 15:43:56 +0800183 case SKU_0_VAYNE:
184 case SKU_1_VAYNE:
185 case SKU_2_VAYNE:
186 return "vbt-vayne.bin";
Furquan Shaikhc6141b92018-05-10 21:58:39 -0700187 default:
188 return "vbt.bin";
189 break;
190 }
191}