| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpi.h> |
| 4 |
#include <acpi/acpigen.h> |
| 5 |
#include <bootstate.h> |
| 6 |
#include <cbmem.h> |
| 7 |
#include <console/console.h> |
| 8 |
#include <cpu/cpu.h> |
| 9 |
#include <crc_byte.h> |
| 10 |
#include <device/device.h> |
| 11 |
#include <device/dram/spd.h> |
| 12 |
#include <device/pci_ids.h> |
| 13 |
#include <drivers/intel/gma/opregion.h> |
| 14 |
#include <gpio.h> |
| 15 |
#include <intelblocks/gpio.h> |
| 16 |
#include <intelblocks/pmclib.h> |
| 17 |
#include <smbios.h> |
| 18 |
#include <soc/pm.h> |
| 19 |
#include <static.h> |
| 20 |
#include <stdio.h> |
| 21 |
#include <string.h> |
| 22 |
#include <types.h> |
| 23 |
|
| 24 |
#include "eeprom.h" |
| 25 |
#include "gpio.h" |
| 26 |
|
| 27 |
const char *mainboard_vbt_filename(void) |
| 28 |
{ |
| 29 |
const struct eeprom_bmc_settings *bmc_cfg = get_bmc_settings(); |
| 30 |
|
| 31 |
if (bmc_cfg && bmc_cfg->efp3_displayport) |
| 32 |
return "vbt-avalanche.bin"; |
| 33 |
else |
| 34 |
return "vbt.bin"; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
static void mb_configure_dp1_pwr(bool enable) |
| 40 |
{ |
| 41 |
gpio_output(GPP_K3, enable); |
| 42 |
} |
| 43 |
|
| 44 |
static void mb_configure_dp2_pwr(bool enable) |
| 45 |
{ |
| 46 |
gpio_output(GPP_K4, enable); |
| 47 |
} |
| 48 |
|
| 49 |
static void mb_configure_dp3_pwr(bool enable) |
| 50 |
{ |
| 51 |
gpio_output(GPP_K5, enable); |
| 52 |
} |
| 53 |
|
| 54 |
static void mb_hda_amp_enable(bool enable) |
| 55 |
{ |
| 56 |
gpio_output(GPP_C19, enable); |
| 57 |
} |
| 58 |
|
| 59 |
static void mb_usb31_rp1_pwr_enable(bool enable) |
| 60 |
{ |
| 61 |
gpio_output(GPP_G0, enable); |
| 62 |
} |
| 63 |
|
| 64 |
static void mb_usb31_rp2_pwr_enable(bool enable) |
| 65 |
{ |
| 66 |
gpio_output(GPP_G1, enable); |
| 67 |
} |
| 68 |
|
| 69 |
static void mb_usb31_fp_pwr_enable(bool enable) |
| 70 |
{ |
| 71 |
gpio_output(GPP_G2, enable); |
| 72 |
} |
| 73 |
|
| 74 |
static void mb_usb2_fp1_pwr_enable(bool enable) |
| 75 |
{ |
| 76 |
gpio_output(GPP_G3, enable); |
| 77 |
} |
| 78 |
|
| 79 |
static void mb_usb2_fp2_pwr_enable(bool enable) |
| 80 |
{ |
| 81 |
gpio_output(GPP_G4, enable); |
| 82 |
} |
| 83 |
|
| 84 |
static void copy_meminfo(const struct dimm_info *dimm, union eeprom_dimm_layout *l) |
| 85 |
{ |
| 86 |
memset(l, 0, sizeof(*l)); |
| 87 |
if (dimm->dimm_size == 0) |
| 88 |
return; |
| 89 |
|
| 90 |
strncpy(l->name, (char *)dimm->module_part_number, sizeof(l->name) - 1); |
| 91 |
l->capacity_mib = dimm->dimm_size; |
| 92 |
l->data_width_bits = 8 * (1 << (dimm->bus_width & 0x7)); |
| 93 |
l->bus_width_bits = l->data_width_bits + 8 * ((dimm->bus_width >> 3) & 0x3); |
| 94 |
l->ranks = dimm->rank_per_dimm; |
| 95 |
l->controller_id = 0; |
| 96 |
strncpy(l->manufacturer, spd_manufacturer_name(dimm->mod_id), |
| 97 |
sizeof(l->manufacturer) - 1); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
static void update_board_layout(void) |
| 105 |
{ |
| 106 |
struct eeprom_board_layout layout = {0}; |
| 107 |
|
| 108 |
printk(BIOS_INFO, "MB: Collecting Board Layout information\n"); |
| 109 |
|
| 110 |
|
| 111 |
for (struct device *cpu = all_devices; cpu; cpu = cpu->next) { |
| 112 |
if (!is_enabled_cpu(cpu)) |
| 113 |
continue; |
| 114 |
layout.cpu_count++; |
| 115 |
if (!layout.cpu_name[0]) |
| 116 |
strncpy(layout.cpu_name, cpu->name, sizeof(layout.cpu_name)); |
| 117 |
} |
| 118 |
|
| 119 |
if (cpuid_get_max_func() >= 0x16) |
| 120 |
layout.cpu_max_non_turbo_frequency = cpuid_eax(0x16); |
| 121 |
|
| 122 |
|
| 123 |
strcpy(layout.pch_name, "Cannonlake-H C246"); |
| 124 |
|
| 125 |
|
| 126 |
struct memory_info *meminfo = cbmem_find(CBMEM_ID_MEMINFO); |
| 127 |
if (meminfo) { |
| 128 |
const size_t meminfo_max = MIN(meminfo->dimm_cnt, ARRAY_SIZE(meminfo->dimm)); |
| 129 |
for (size_t i = 0; i < MIN(meminfo_max, ARRAY_SIZE(layout.dimm)); i++) |
| 130 |
copy_meminfo(&meminfo->dimm[i], &layout.dimm[i]); |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
layout.signature = CRC(layout.raw_layout, sizeof(layout.raw_layout), crc32_byte); |
| 135 |
|
| 136 |
printk(BIOS_DEBUG, "BOARD LAYOUT:\n"); |
| 137 |
printk(BIOS_DEBUG, " Signature : 0x%x\n", layout.signature); |
| 138 |
printk(BIOS_DEBUG, " CPU name : %s\n", layout.cpu_name); |
| 139 |
printk(BIOS_DEBUG, " CPU count : %u\n", layout.cpu_count); |
| 140 |
printk(BIOS_DEBUG, " CPU freq : %u\n", layout.cpu_max_non_turbo_frequency); |
| 141 |
printk(BIOS_DEBUG, " PCH name : %s\n", layout.pch_name); |
| 142 |
for (size_t i = 0; i < ARRAY_SIZE(layout.dimm); i++) |
| 143 |
printk(BIOS_DEBUG, " DRAM SIZE : %u\n", layout.dimm[i].capacity_mib); |
| 144 |
|
| 145 |
if (write_board_settings(&layout)) |
| 146 |
printk(BIOS_ERR, "MB: Failed to update Board Layout\n"); |
| 147 |
} |
| 148 |
|
| 149 |
static void mainboard_init(void *chip_info) |
| 150 |
{ |
| 151 |
|
| 152 |
if (get_board_settings()->front_panel_audio == 2) |
| 153 |
mb_hda_amp_enable(1); |
| 154 |
else |
| 155 |
mb_hda_amp_enable(0); |
| 156 |
} |
| 157 |
|
| 158 |
static void mainboard_final(struct device *dev) |
| 159 |
{ |
| 160 |
update_board_layout(); |
| 161 |
|
| 162 |
|
| 163 |
const bool on = !get_board_settings()->power_state_after_g3; |
| 164 |
|
| 165 |
pmc_soc_set_afterg3_en(on); |
| 166 |
} |
| 167 |
|
| 168 |
static const char *format_pn(const char *prefix, size_t offset) |
| 169 |
{ |
| 170 |
static char buffer[32 + HERMES_SN_PN_LENGTH] = { 0 }; |
| 171 |
|
| 172 |
const char *part_num = eeprom_read_serial(offset, "N/A"); |
| 173 |
|
| 174 |
snprintf(buffer, sizeof(buffer), "%s%s", prefix, part_num); |
| 175 |
|
| 176 |
return buffer; |
| 177 |
} |
| 178 |
|
| 179 |
static void mainboard_smbios_strings(struct device *dev, struct smbios_type11 *t) |
| 180 |
{ |
| 181 |
const size_t board_offset = offsetof(struct eeprom_layout, board_part_number); |
| 182 |
const size_t product_offset = offsetof(struct eeprom_layout, product_part_number); |
| 183 |
t->count = smbios_add_string(t->eos, format_pn("Board P/N: ", board_offset)); |
| 184 |
t->count = smbios_add_string(t->eos, format_pn("Product P/N: ", product_offset)); |
| 185 |
} |
| 186 |
|
| 187 |
#if CONFIG(HAVE_ACPI_TABLES) |
| 188 |
static void mainboard_acpi_fill_ssdt(const struct device *dev) |
| 189 |
{ |
| 190 |
const struct eeprom_board_settings *const board_cfg = get_board_settings(); |
| 191 |
|
| 192 |
const unsigned int usb_power_gpios[] = { GPP_G0, GPP_G1, GPP_G2, GPP_G3, GPP_G4 }; |
| 193 |
|
| 194 |
|
| 195 |
int (*acpigen_write_soc_gpio_op)(unsigned int gpio_num); |
| 196 |
|
| 197 |
if (board_cfg->usb_powered_in_s5) |
| 198 |
acpigen_write_soc_gpio_op = acpigen_soc_set_tx_gpio; |
| 199 |
else |
| 200 |
acpigen_write_soc_gpio_op = acpigen_soc_clear_tx_gpio; |
| 201 |
|
| 202 |
acpigen_write_method("\\_SB.MPTS", 1); |
| 203 |
{ |
| 204 |
acpigen_write_if_lequal_op_int(ARG0_OP, 5); |
| 205 |
{ |
| 206 |
for (size_t i = 0; i < ARRAY_SIZE(usb_power_gpios); i++) |
| 207 |
acpigen_write_soc_gpio_op(usb_power_gpios[i]); |
| 208 |
} |
| 209 |
acpigen_pop_len(); |
| 210 |
|
| 211 |
if (!board_cfg->wake_on_usb) { |
| 212 |
acpigen_write_if(); |
| 213 |
acpigen_emit_byte(LNOT_OP); |
| 214 |
acpigen_emit_byte(LLESS_OP); |
| 215 |
acpigen_emit_byte(ARG0_OP); |
| 216 |
acpigen_write_integer(ACPI_S3); |
| 217 |
{ |
| 218 |
acpigen_write_store_int_to_namestr(0, "\\_SB.PCI0.XHCI.PMEE"); |
| 219 |
} |
| 220 |
acpigen_pop_len(); |
| 221 |
} |
| 222 |
} |
| 223 |
acpigen_pop_len(); |
| 224 |
} |
| 225 |
#endif |
| 226 |
|
| 227 |
static void mainboard_enable(struct device *dev) |
| 228 |
{ |
| 229 |
|
| 230 |
mb_configure_dp1_pwr(1); |
| 231 |
mb_configure_dp2_pwr(1); |
| 232 |
mb_configure_dp3_pwr(1); |
| 233 |
|
| 234 |
mb_usb31_rp1_pwr_enable(1); |
| 235 |
mb_usb31_rp2_pwr_enable(1); |
| 236 |
mb_usb31_fp_pwr_enable(1); |
| 237 |
mb_usb2_fp1_pwr_enable(1); |
| 238 |
mb_usb2_fp2_pwr_enable(1); |
| 239 |
|
| 240 |
dev->ops->final = mainboard_final; |
| 241 |
dev->ops->get_smbios_strings = mainboard_smbios_strings; |
| 242 |
|
| 243 |
#if CONFIG(HAVE_ACPI_TABLES) |
| 244 |
dev->ops->acpi_fill_ssdt = mainboard_acpi_fill_ssdt; |
| 245 |
#endif |
| 246 |
} |
| 247 |
|
| 248 |
struct chip_operations mainboard_ops = { |
| 249 |
.init = mainboard_init, |
| 250 |
.enable_dev = mainboard_enable, |
| 251 |
}; |
| 252 |
|
| 253 |
static void log_reset_causes(void) |
| 254 |
{ |
| 255 |
struct chipset_power_state *ps = pmc_get_power_state(); |
| 256 |
|
| 257 |
if (!ps) { |
| 258 |
printk(BIOS_ERR, "chipset_power_state not found!\n"); |
| 259 |
return; |
| 260 |
} |
| 261 |
|
| 262 |
union { |
| 263 |
struct eeprom_reset_cause_regs regs; |
| 264 |
uint8_t raw[sizeof(struct eeprom_reset_cause_regs)]; |
| 265 |
} reset_cause = { |
| 266 |
.regs = { |
| 267 |
.gblrst_cause0 = ps->gblrst_cause[0], |
| 268 |
.gblrst_cause1 = ps->gblrst_cause[1], |
| 269 |
.hpr_cause0 = ps->hpr_cause0, |
| 270 |
}, |
| 271 |
}; |
| 272 |
|
| 273 |
const size_t base = offsetof(struct eeprom_layout, reset_cause_regs); |
| 274 |
for (size_t i = 0; i < ARRAY_SIZE(reset_cause.raw); i++) |
| 275 |
eeprom_write_byte(reset_cause.raw[i], base + i); |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
static void mainboard_early(void *unused) |
| 280 |
{ |
| 281 |
const struct eeprom_board_settings *const board_cfg = get_board_settings(); |
| 282 |
config_t *config = config_of_soc(); |
| 283 |
|
| 284 |
|
| 285 |
config->deep_s5_enable_ac = board_cfg->deep_sx_enabled; |
| 286 |
config->deep_s5_enable_dc = board_cfg->deep_sx_enabled; |
| 287 |
|
| 288 |
config->disable_vmx = board_cfg->vtx_disabled; |
| 289 |
|
| 290 |
if (check_signature(offsetof(struct eeprom_layout, supd), FSPS_UPD_SIGNATURE)) { |
| 291 |
struct { |
| 292 |
struct { |
| 293 |
u8 TurboMode; |
| 294 |
} FspsConfig; |
| 295 |
} supd = {0}; |
| 296 |
|
| 297 |
READ_EEPROM_FSP_S((&supd), FspsConfig.TurboMode); |
| 298 |
config->cpu_turbo_disable = !supd.FspsConfig.TurboMode; |
| 299 |
} |
| 300 |
|
| 301 |
log_reset_causes(); |
| 302 |
} |
| 303 |
|
| 304 |
BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT, mainboard_early, NULL); |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
static void mainboard_configure_internal_gfx(void *unused) |
| 313 |
{ |
| 314 |
struct device *dev; |
| 315 |
|
| 316 |
if (get_board_settings()->primary_video == PRIMARY_VIDEO_INTEL) { |
| 317 |
dev = dev_find_device(PCI_VID_ASPEED, PCI_DID_ASPEED_AST2050_VGA, NULL); |
| 318 |
dev->on_mainboard = false; |
| 319 |
dev->enabled = false; |
| 320 |
dev->ops->init = NULL; |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
BOOT_STATE_INIT_ENTRY(BS_DEV_RESOURCES, BS_ON_ENTRY, mainboard_configure_internal_gfx, NULL) |