blob: 6d0da8d4115004313277c3e3dc32191a76d24dc3 [file] [log] [blame]
Christian Walterb646e282020-01-09 15:42:42 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
Angel Pons05df1082023-02-08 21:33:44 +01003#include <acpi/acpi.h>
Angel Pons20ca7eb2020-12-21 18:59:09 +01004#include <acpi/acpigen.h>
Angel Pons0b697a242021-11-25 13:34:11 +01005#include <bootstate.h>
Patrick Rudolph35f0a8f2020-11-12 16:41:57 +01006#include <cbmem.h>
7#include <console/console.h>
Elyes Haouas1bd23e32022-10-31 13:13:37 +01008#include <cpu/cpu.h>
Patrick Rudolph35f0a8f2020-11-12 16:41:57 +01009#include <crc_byte.h>
Christian Walterb646e282020-01-09 15:42:42 +010010#include <device/device.h>
Patrick Rudolph35f0a8f2020-11-12 16:41:57 +010011#include <device/dram/spd.h>
Arthur Heymansf5575312022-03-07 17:39:53 +010012#include <device/pci_ids.h>
Angel Pons4a0dee22021-12-02 11:45:50 +010013#include <drivers/intel/gma/opregion.h>
Angel Ponse81560c2021-11-25 13:15:07 +010014#include <gpio.h>
Angel Pons0b697a242021-11-25 13:34:11 +010015#include <intelblocks/gpio.h>
Angel Pons20ca7eb2020-12-21 18:59:09 +010016#include <intelblocks/pmclib.h>
Angel Pons0b697a242021-11-25 13:34:11 +010017#include <smbios.h>
Angel Pons373517c2022-09-09 15:15:22 +020018#include <soc/pm.h>
Elyes Haouasbdd03c22024-05-27 11:20:07 +020019#include <stdio.h>
Angel Ponsc9605642022-09-21 13:30:34 +020020#include <string.h>
Angel Pons20ca7eb2020-12-21 18:59:09 +010021#include <types.h>
Angel Ponse81560c2021-11-25 13:15:07 +010022
23#include "eeprom.h"
Christian Walterb646e282020-01-09 15:42:42 +010024#include "gpio.h"
25
Angel Pons4a0dee22021-12-02 11:45:50 +010026const char *mainboard_vbt_filename(void)
27{
28 const struct eeprom_bmc_settings *bmc_cfg = get_bmc_settings();
29
30 if (bmc_cfg && bmc_cfg->efp3_displayport)
31 return "vbt-avalanche.bin";
32 else
33 return "vbt.bin"; /* Poseidon */
34}
35
Christian Walterb646e282020-01-09 15:42:42 +010036/* FIXME: Example code below */
37
38static void mb_configure_dp1_pwr(bool enable)
39{
40 gpio_output(GPP_K3, enable);
41}
42
43static void mb_configure_dp2_pwr(bool enable)
44{
45 gpio_output(GPP_K4, enable);
46}
47
48static void mb_configure_dp3_pwr(bool enable)
49{
50 gpio_output(GPP_K5, enable);
51}
52
Christian Walterb646e282020-01-09 15:42:42 +010053static void mb_hda_amp_enable(bool enable)
54{
55 gpio_output(GPP_C19, enable);
56}
57
58static void mb_usb31_rp1_pwr_enable(bool enable)
59{
60 gpio_output(GPP_G0, enable);
61}
62
63static void mb_usb31_rp2_pwr_enable(bool enable)
64{
65 gpio_output(GPP_G1, enable);
66}
67
68static void mb_usb31_fp_pwr_enable(bool enable)
69{
70 gpio_output(GPP_G2, enable);
71}
72
73static void mb_usb2_fp1_pwr_enable(bool enable)
74{
75 gpio_output(GPP_G3, enable);
76}
77
78static void mb_usb2_fp2_pwr_enable(bool enable)
79{
80 gpio_output(GPP_G4, enable);
81}
82
Patrick Rudolph35f0a8f2020-11-12 16:41:57 +010083static void copy_meminfo(const struct dimm_info *dimm, union eeprom_dimm_layout *l)
84{
85 memset(l, 0, sizeof(*l));
86 if (dimm->dimm_size == 0)
87 return;
88
89 strncpy(l->name, (char *)dimm->module_part_number, sizeof(l->name) - 1);
90 l->capacity_mib = dimm->dimm_size;
91 l->data_width_bits = 8 * (1 << (dimm->bus_width & 0x7));
92 l->bus_width_bits = l->data_width_bits + 8 * ((dimm->bus_width >> 3) & 0x3);
93 l->ranks = dimm->rank_per_dimm;
94 l->controller_id = 0;
95 strncpy(l->manufacturer, spd_manufacturer_name(dimm->mod_id),
96 sizeof(l->manufacturer) - 1);
97}
98
99/*
100 * Collect board specific settings and update the CFG EEPROM if necessary.
101 * This allows the BMC webui to display the current hardware configuration.
102 */
103static void update_board_layout(void)
104{
105 struct eeprom_board_layout layout = {0};
106
107 printk(BIOS_INFO, "MB: Collecting Board Layout information\n");
108
109 /* Update CPU fields */
110 for (struct device *cpu = all_devices; cpu; cpu = cpu->next) {
Fabio Aiuto45aae7f2022-09-23 16:51:34 +0200111 if (!is_enabled_cpu(cpu))
Patrick Rudolph35f0a8f2020-11-12 16:41:57 +0100112 continue;
113 layout.cpu_count++;
114 if (!layout.cpu_name[0])
Martin Roth27b4a602023-10-23 19:47:32 -0600115 strncpy(layout.cpu_name, cpu->name, sizeof(layout.cpu_name));
Patrick Rudolph35f0a8f2020-11-12 16:41:57 +0100116 }
117
118 if (cpuid_get_max_func() >= 0x16)
119 layout.cpu_max_non_turbo_frequency = cpuid_eax(0x16);
120
121 /* PCH */
122 strcpy(layout.pch_name, "Cannonlake-H C246");
123
124 /* DRAM */
125 struct memory_info *meminfo = cbmem_find(CBMEM_ID_MEMINFO);
126 if (meminfo) {
127 const size_t meminfo_max = MIN(meminfo->dimm_cnt, ARRAY_SIZE(meminfo->dimm));
128 for (size_t i = 0; i < MIN(meminfo_max, ARRAY_SIZE(layout.dimm)); i++)
129 copy_meminfo(&meminfo->dimm[i], &layout.dimm[i]);
130 }
131
132 /* Update CRC */
133 layout.signature = CRC(layout.raw_layout, sizeof(layout.raw_layout), crc32_byte);
134
135 printk(BIOS_DEBUG, "BOARD LAYOUT:\n");
136 printk(BIOS_DEBUG, " Signature : 0x%x\n", layout.signature);
137 printk(BIOS_DEBUG, " CPU name : %s\n", layout.cpu_name);
138 printk(BIOS_DEBUG, " CPU count : %u\n", layout.cpu_count);
139 printk(BIOS_DEBUG, " CPU freq : %u\n", layout.cpu_max_non_turbo_frequency);
140 printk(BIOS_DEBUG, " PCH name : %s\n", layout.pch_name);
141 for (size_t i = 0; i < ARRAY_SIZE(layout.dimm); i++)
142 printk(BIOS_DEBUG, " DRAM SIZE : %u\n", layout.dimm[i].capacity_mib);
143
144 if (write_board_settings(&layout))
145 printk(BIOS_ERR, "MB: Failed to update Board Layout\n");
146}
147
Angel Pons20ca7eb2020-12-21 18:59:09 +0100148static void mainboard_init(void *chip_info)
149{
Patrick Rudolph082f0b92021-02-08 08:50:46 +0100150 /* Enable internal speaker amplifier */
Angel Pons73e63182023-05-11 15:38:04 +0200151 if (get_board_settings()->front_panel_audio == 2)
Patrick Rudolph082f0b92021-02-08 08:50:46 +0100152 mb_hda_amp_enable(1);
153 else
154 mb_hda_amp_enable(0);
Angel Pons20ca7eb2020-12-21 18:59:09 +0100155}
156
157static void mainboard_final(struct device *dev)
158{
Patrick Rudolph35f0a8f2020-11-12 16:41:57 +0100159 update_board_layout();
160
Angel Pons20ca7eb2020-12-21 18:59:09 +0100161 /* Encoding: 0 -> S0, 1 -> S5 */
Angel Pons73e63182023-05-11 15:38:04 +0200162 const bool on = !get_board_settings()->power_state_after_g3;
Angel Pons20ca7eb2020-12-21 18:59:09 +0100163
164 pmc_soc_set_afterg3_en(on);
165}
166
Angel Ponsc9605642022-09-21 13:30:34 +0200167static const char *format_pn(const char *prefix, size_t offset)
168{
169 static char buffer[32 + HERMES_SN_PN_LENGTH] = { 0 };
170
171 const char *part_num = eeprom_read_serial(offset, "N/A");
172
Angel Ponsbf541422022-10-11 21:45:30 +0200173 snprintf(buffer, sizeof(buffer), "%s%s", prefix, part_num);
Angel Ponsc9605642022-09-21 13:30:34 +0200174
175 return buffer;
176}
177
178static void mainboard_smbios_strings(struct device *dev, struct smbios_type11 *t)
179{
180 const size_t board_offset = offsetof(struct eeprom_layout, board_part_number);
181 const size_t product_offset = offsetof(struct eeprom_layout, product_part_number);
182 t->count = smbios_add_string(t->eos, format_pn("Board P/N: ", board_offset));
183 t->count = smbios_add_string(t->eos, format_pn("Product P/N: ", product_offset));
184}
185
Angel Pons20ca7eb2020-12-21 18:59:09 +0100186#if CONFIG(HAVE_ACPI_TABLES)
187static void mainboard_acpi_fill_ssdt(const struct device *dev)
188{
189 const struct eeprom_board_settings *const board_cfg = get_board_settings();
190
Angel Pons20ca7eb2020-12-21 18:59:09 +0100191 const unsigned int usb_power_gpios[] = { GPP_G0, GPP_G1, GPP_G2, GPP_G3, GPP_G4 };
192
193 /* Function pointer to write STXS or CTXS according to EEPROM board setting */
194 int (*acpigen_write_soc_gpio_op)(unsigned int gpio_num);
195
196 if (board_cfg->usb_powered_in_s5)
197 acpigen_write_soc_gpio_op = acpigen_soc_set_tx_gpio;
198 else
199 acpigen_write_soc_gpio_op = acpigen_soc_clear_tx_gpio;
200
Patrick Rudolph4b29c4a2021-04-15 16:28:57 +0200201 acpigen_write_method("\\_SB.MPTS", 1);
Angel Pons20ca7eb2020-12-21 18:59:09 +0100202 {
Patrick Rudolph4b29c4a2021-04-15 16:28:57 +0200203 acpigen_write_if_lequal_op_int(ARG0_OP, 5);
Angel Pons20ca7eb2020-12-21 18:59:09 +0100204 {
Patrick Rudolph4b29c4a2021-04-15 16:28:57 +0200205 for (size_t i = 0; i < ARRAY_SIZE(usb_power_gpios); i++)
206 acpigen_write_soc_gpio_op(usb_power_gpios[i]);
Angel Pons20ca7eb2020-12-21 18:59:09 +0100207 }
208 acpigen_pop_len();
Angel Pons05df1082023-02-08 21:33:44 +0100209
210 if (!board_cfg->wake_on_usb) {
211 acpigen_write_if();
212 acpigen_emit_byte(LNOT_OP);
213 acpigen_emit_byte(LLESS_OP);
214 acpigen_emit_byte(ARG0_OP);
215 acpigen_write_integer(ACPI_S3);
216 {
217 acpigen_write_store_int_to_namestr(0, "\\_SB.PCI0.XHCI.PMEE");
218 }
219 acpigen_pop_len();
220 }
Angel Pons20ca7eb2020-12-21 18:59:09 +0100221 }
222 acpigen_pop_len();
223}
224#endif
225
Christian Walterb646e282020-01-09 15:42:42 +0100226static void mainboard_enable(struct device *dev)
227{
228 /* FIXME: Do runtime configuration once the board is production ready */
229 mb_configure_dp1_pwr(1);
230 mb_configure_dp2_pwr(1);
231 mb_configure_dp3_pwr(1);
Patrick Rudolph6c2f34a2021-02-08 08:49:06 +0100232
Christian Walterb646e282020-01-09 15:42:42 +0100233 mb_usb31_rp1_pwr_enable(1);
234 mb_usb31_rp2_pwr_enable(1);
235 mb_usb31_fp_pwr_enable(1);
236 mb_usb2_fp1_pwr_enable(1);
237 mb_usb2_fp2_pwr_enable(1);
Angel Pons20ca7eb2020-12-21 18:59:09 +0100238
239 dev->ops->final = mainboard_final;
Angel Ponsc9605642022-09-21 13:30:34 +0200240 dev->ops->get_smbios_strings = mainboard_smbios_strings;
Angel Pons20ca7eb2020-12-21 18:59:09 +0100241
242#if CONFIG(HAVE_ACPI_TABLES)
243 dev->ops->acpi_fill_ssdt = mainboard_acpi_fill_ssdt;
244#endif
Christian Walterb646e282020-01-09 15:42:42 +0100245}
246
247struct chip_operations mainboard_ops = {
Angel Pons20ca7eb2020-12-21 18:59:09 +0100248 .init = mainboard_init,
Christian Walterb646e282020-01-09 15:42:42 +0100249 .enable_dev = mainboard_enable,
250};
Patrick Rudolph52ef8692021-02-16 13:16:25 +0100251
Angel Pons373517c2022-09-09 15:15:22 +0200252static void log_reset_causes(void)
253{
254 struct chipset_power_state *ps = pmc_get_power_state();
255
256 if (!ps) {
257 printk(BIOS_ERR, "chipset_power_state not found!\n");
258 return;
259 }
260
261 union {
262 struct eeprom_reset_cause_regs regs;
263 uint8_t raw[sizeof(struct eeprom_reset_cause_regs)];
264 } reset_cause = {
265 .regs = {
266 .gblrst_cause0 = ps->gblrst_cause[0],
267 .gblrst_cause1 = ps->gblrst_cause[1],
268 .hpr_cause0 = ps->hpr_cause0,
269 },
270 };
271
272 const size_t base = offsetof(struct eeprom_layout, reset_cause_regs);
273 for (size_t i = 0; i < ARRAY_SIZE(reset_cause.raw); i++)
274 eeprom_write_byte(reset_cause.raw[i], base + i);
275}
276
Patrick Rudolph52ef8692021-02-16 13:16:25 +0100277/* Must happen before MPinit */
278static void mainboard_early(void *unused)
279{
280 const struct eeprom_board_settings *const board_cfg = get_board_settings();
281 config_t *config = config_of_soc();
282
Angel Pons73e63182023-05-11 15:38:04 +0200283 /* Set Deep Sx */
284 config->deep_s5_enable_ac = board_cfg->deep_sx_enabled;
285 config->deep_s5_enable_dc = board_cfg->deep_sx_enabled;
Angel Pons7a3c4162022-01-31 17:45:04 +0100286
Angel Pons73e63182023-05-11 15:38:04 +0200287 config->disable_vmx = board_cfg->vtx_disabled;
Patrick Rudolph52ef8692021-02-16 13:16:25 +0100288
289 if (check_signature(offsetof(struct eeprom_layout, supd), FSPS_UPD_SIGNATURE)) {
290 struct {
291 struct {
292 u8 TurboMode;
293 } FspsConfig;
294 } supd = {0};
295
296 READ_EEPROM_FSP_S((&supd), FspsConfig.TurboMode);
297 config->cpu_turbo_disable = !supd.FspsConfig.TurboMode;
298 }
Angel Pons373517c2022-09-09 15:15:22 +0200299
300 log_reset_causes();
Patrick Rudolph52ef8692021-02-16 13:16:25 +0100301}
302
303BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT, mainboard_early, NULL);
Arthur Heymansf5575312022-03-07 17:39:53 +0100304
305/*
306 * coreboot only exposes the last framebuffer that is set up.
307 * The ASPEED BMC will always be initialized after the IGD due to its higher
308 * bus number. To have coreboot only expose the IGD framebuffer skip the init
309 * function on the ASPEED.
310 */
311static void mainboard_configure_internal_gfx(void *unused)
312{
313 struct device *dev;
Arthur Heymansf5575312022-03-07 17:39:53 +0100314
Angel Pons73e63182023-05-11 15:38:04 +0200315 if (get_board_settings()->primary_video == PRIMARY_VIDEO_INTEL) {
Arthur Heymansf5575312022-03-07 17:39:53 +0100316 dev = dev_find_device(PCI_VID_ASPEED, PCI_DID_ASPEED_AST2050_VGA, NULL);
317 dev->on_mainboard = false;
318 dev->enabled = false;
319 dev->ops->init = NULL;
320 }
321}
322
323BOOT_STATE_INIT_ENTRY(BS_DEV_RESOURCES, BS_ON_ENTRY, mainboard_configure_internal_gfx, NULL)