Angel Pons | f23ae0b | 2020-04-02 23:48:12 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 3d0071b | 2013-01-18 14:32:50 -0600 | [diff] [blame] | 2 | |
Angel Pons | 45f448f | 2020-07-03 14:46:47 +0200 | [diff] [blame] | 3 | #include <arch/romstage.h> |
Aaron Durbin | 3d0071b | 2013-01-18 14:32:50 -0600 | [diff] [blame] | 4 | #include <console/console.h> |
Patrick Rudolph | 45022ae | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 5 | #include <cf9_reset.h> |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 6 | #include <timestamp.h> |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 7 | #include <cpu/x86/lapic.h> |
Kyösti Mälkki | 465eff6 | 2016-06-15 06:07:55 +0300 | [diff] [blame] | 8 | #include <cbmem.h> |
Elyes HAOUAS | d26844c | 2019-06-21 07:31:40 +0200 | [diff] [blame] | 9 | #include <commonlib/helpers.h> |
Aaron Durbin | bf396ff | 2013-02-11 21:50:35 -0600 | [diff] [blame] | 10 | #include <romstage_handoff.h> |
Angel Pons | 2e25ac6 | 2020-07-03 12:06:04 +0200 | [diff] [blame] | 11 | #include <cpu/intel/haswell/haswell.h> |
Elyes HAOUAS | 65bb543 | 2018-07-03 14:59:50 +0200 | [diff] [blame] | 12 | #include <northbridge/intel/haswell/haswell.h> |
| 13 | #include <northbridge/intel/haswell/raminit.h> |
| 14 | #include <southbridge/intel/lynxpoint/pch.h> |
| 15 | #include <southbridge/intel/lynxpoint/me.h> |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 16 | |
Angel Pons | 6eea191 | 2020-07-03 14:14:30 +0200 | [diff] [blame] | 17 | /* Copy SPD data for on-board memory */ |
| 18 | void __weak copy_spd(struct pei_data *peid) |
| 19 | { |
| 20 | } |
| 21 | |
Angel Pons | 73fa035 | 2020-07-03 12:29:03 +0200 | [diff] [blame] | 22 | void __weak mb_late_romstage_setup(void) |
| 23 | { |
| 24 | } |
| 25 | |
Angel Pons | d7bf3ad | 2020-07-03 20:31:39 +0200 | [diff] [blame] | 26 | /* |
| 27 | * 0 = leave channel enabled |
| 28 | * 1 = disable dimm 0 on channel |
| 29 | * 2 = disable dimm 1 on channel |
| 30 | * 3 = disable dimm 0+1 on channel |
| 31 | */ |
| 32 | static int make_channel_disabled_mask(const struct pei_data *pd, int ch) |
| 33 | { |
| 34 | return (!pd->spd_addresses[ch + ch] << 0) | (!pd->spd_addresses[ch + ch + 1] << 1); |
| 35 | } |
| 36 | |
Angel Pons | 45f448f | 2020-07-03 14:46:47 +0200 | [diff] [blame] | 37 | /* The romstage entry point for this platform is not mainboard-specific, hence the name */ |
| 38 | void mainboard_romstage_entry(void) |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 39 | { |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 40 | int wake_from_s3; |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 41 | |
Angel Pons | 45f448f | 2020-07-03 14:46:47 +0200 | [diff] [blame] | 42 | struct pei_data pei_data = { |
Angel Pons | dd7470c | 2020-07-03 18:19:29 +0200 | [diff] [blame] | 43 | .pei_version = PEI_VERSION, |
| 44 | .mchbar = (uintptr_t)DEFAULT_MCHBAR, |
| 45 | .dmibar = (uintptr_t)DEFAULT_DMIBAR, |
| 46 | .epbar = DEFAULT_EPBAR, |
| 47 | .pciexbar = CONFIG_MMCONF_BASE_ADDRESS, |
| 48 | .smbusbar = SMBUS_IO_BASE, |
| 49 | .hpet_address = HPET_ADDR, |
| 50 | .rcba = (uintptr_t)DEFAULT_RCBA, |
| 51 | .pmbase = DEFAULT_PMBASE, |
| 52 | .gpiobase = DEFAULT_GPIOBASE, |
| 53 | .temp_mmio_base = 0xfed08000, |
Angel Pons | 3ac92b7 | 2020-07-03 23:32:44 +0200 | [diff] [blame] | 54 | .system_type = get_pch_platform_type(), |
Angel Pons | dd7470c | 2020-07-03 18:19:29 +0200 | [diff] [blame] | 55 | .tseg_size = CONFIG_SMM_TSEG_SIZE, |
Angel Pons | 1be9f58 | 2020-07-03 21:31:17 +0200 | [diff] [blame] | 56 | .ddr_refresh_2x = CONFIG(ENABLE_DDR_2X_REFRESH), |
Angel Pons | 9a36971 | 2020-07-03 20:36:50 +0200 | [diff] [blame] | 57 | .max_ddr3_freq = 1600, |
Angel Pons | 45f448f | 2020-07-03 14:46:47 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | mainboard_fill_pei_data(&pei_data); |
| 61 | |
Kyösti Mälkki | 157b189 | 2019-08-16 14:02:25 +0300 | [diff] [blame] | 62 | enable_lapic(); |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 63 | |
Angel Pons | 03f0e43 | 2020-07-03 13:51:15 +0200 | [diff] [blame] | 64 | wake_from_s3 = early_pch_init(); |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 65 | |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 66 | /* Perform some early chipset initialization required |
| 67 | * before RAM initialization can work |
| 68 | */ |
Angel Pons | e816829 | 2020-07-03 11:42:22 +0200 | [diff] [blame] | 69 | haswell_early_initialization(); |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 70 | printk(BIOS_DEBUG, "Back from haswell_early_initialization()\n"); |
| 71 | |
| 72 | if (wake_from_s3) { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 73 | #if CONFIG(HAVE_ACPI_RESUME) |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 74 | printk(BIOS_DEBUG, "Resume from S3 detected.\n"); |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 75 | #else |
| 76 | printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n"); |
Aaron Durbin | bf396ff | 2013-02-11 21:50:35 -0600 | [diff] [blame] | 77 | wake_from_s3 = 0; |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 78 | #endif |
| 79 | } |
| 80 | |
| 81 | /* Prepare USB controller early in S3 resume */ |
Aaron Durbin | bf396ff | 2013-02-11 21:50:35 -0600 | [diff] [blame] | 82 | if (wake_from_s3) |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 83 | enable_usb_bar(); |
| 84 | |
| 85 | post_code(0x3a); |
Angel Pons | 284a547 | 2020-07-03 11:46:50 +0200 | [diff] [blame] | 86 | |
| 87 | /* MRC has hardcoded assumptions of 2 meaning S3 wake. Normalize it here. */ |
Angel Pons | 45f448f | 2020-07-03 14:46:47 +0200 | [diff] [blame] | 88 | pei_data.boot_mode = wake_from_s3 ? 2 : 0; |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 89 | |
Angel Pons | d37b7d8 | 2020-07-03 23:52:34 +0200 | [diff] [blame^] | 90 | /* Obtain the SPD addresses from mainboard code */ |
| 91 | mb_get_spd_map(pei_data.spd_addresses); |
| 92 | |
Angel Pons | d7bf3ad | 2020-07-03 20:31:39 +0200 | [diff] [blame] | 93 | /* Calculate unimplemented DIMM slots for each channel */ |
| 94 | pei_data.dimm_channel0_disabled = make_channel_disabled_mask(&pei_data, 0); |
| 95 | pei_data.dimm_channel1_disabled = make_channel_disabled_mask(&pei_data, 1); |
| 96 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 97 | timestamp_add_now(TS_BEFORE_INITRAM); |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 98 | |
| 99 | report_platform_info(); |
| 100 | |
Angel Pons | 45f448f | 2020-07-03 14:46:47 +0200 | [diff] [blame] | 101 | copy_spd(&pei_data); |
Aaron Durbin | c7633f4 | 2013-06-13 17:29:36 -0700 | [diff] [blame] | 102 | |
Angel Pons | 45f448f | 2020-07-03 14:46:47 +0200 | [diff] [blame] | 103 | sdram_initialize(&pei_data); |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 104 | |
Kyösti Mälkki | 3d45c40 | 2013-09-07 20:26:36 +0300 | [diff] [blame] | 105 | timestamp_add_now(TS_AFTER_INITRAM); |
| 106 | |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 107 | post_code(0x3b); |
| 108 | |
| 109 | intel_early_me_status(); |
| 110 | |
Aaron Durbin | c0cbd6e | 2013-03-13 13:51:20 -0500 | [diff] [blame] | 111 | if (!wake_from_s3) { |
| 112 | cbmem_initialize_empty(); |
| 113 | /* Save data returned from MRC on non-S3 resumes. */ |
Angel Pons | 45f448f | 2020-07-03 14:46:47 +0200 | [diff] [blame] | 114 | save_mrc_data(&pei_data); |
Aaron Durbin | 42e6856 | 2015-06-09 13:55:51 -0500 | [diff] [blame] | 115 | } else if (cbmem_initialize()) { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 116 | #if CONFIG(HAVE_ACPI_RESUME) |
Aaron Durbin | 42e6856 | 2015-06-09 13:55:51 -0500 | [diff] [blame] | 117 | /* Failed S3 resume, reset to come up cleanly */ |
Patrick Rudolph | 45022ae | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 118 | system_reset(); |
Aaron Durbin | 42e6856 | 2015-06-09 13:55:51 -0500 | [diff] [blame] | 119 | #endif |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 120 | } |
Aaron Durbin | bf396ff | 2013-02-11 21:50:35 -0600 | [diff] [blame] | 121 | |
Tristan Corrick | 334be32 | 2018-12-17 22:10:21 +1300 | [diff] [blame] | 122 | haswell_unhide_peg(); |
| 123 | |
Angel Pons | 45f448f | 2020-07-03 14:46:47 +0200 | [diff] [blame] | 124 | setup_sdram_meminfo(&pei_data); |
Matt DeVillier | 5aaa8ce | 2016-09-02 13:29:17 -0500 | [diff] [blame] | 125 | |
Aaron Durbin | 77e1399 | 2016-11-29 17:43:04 -0600 | [diff] [blame] | 126 | romstage_handoff_init(wake_from_s3); |
Aaron Durbin | bf396ff | 2013-02-11 21:50:35 -0600 | [diff] [blame] | 127 | |
Angel Pons | 73fa035 | 2020-07-03 12:29:03 +0200 | [diff] [blame] | 128 | mb_late_romstage_setup(); |
| 129 | |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 130 | post_code(0x3f); |
Aaron Durbin | a267161 | 2013-02-06 21:41:01 -0600 | [diff] [blame] | 131 | } |