Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2010 coresystems GmbH |
| 5 | * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <string.h> |
| 23 | #include <lib.h> |
| 24 | #include <timestamp.h> |
| 25 | #include <arch/io.h> |
| 26 | #include <arch/romcc_io.h> |
| 27 | #include <device/pci_def.h> |
| 28 | #include <device/pnp_def.h> |
| 29 | #include <cpu/x86/lapic.h> |
| 30 | #include <pc80/mc146818rtc.h> |
| 31 | #include <cbmem.h> |
| 32 | #include <console/console.h> |
Aaron Durbin | 3d0071b | 2013-01-18 14:32:50 -0600 | [diff] [blame] | 33 | #include "cpu/intel/haswell/haswell.h" |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 34 | #include "northbridge/intel/haswell/haswell.h" |
| 35 | #include "northbridge/intel/haswell/raminit.h" |
| 36 | #include "southbridge/intel/lynxpoint/pch.h" |
Aaron Durbin | 239c2e8 | 2012-12-19 11:31:17 -0600 | [diff] [blame] | 37 | #include "southbridge/intel/lynxpoint/me.h" |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 38 | #include <arch/cpu.h> |
| 39 | #include <cpu/x86/bist.h> |
| 40 | #include <cpu/x86/msr.h> |
| 41 | #include "gpio.h" |
| 42 | #if CONFIG_CHROMEOS |
| 43 | #include <vendorcode/google/chromeos/chromeos.h> |
| 44 | #endif |
| 45 | |
Aaron Durbin | 239c2e8 | 2012-12-19 11:31:17 -0600 | [diff] [blame] | 46 | const struct rcba_config_instruction rcba_config[] = { |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 47 | /* |
| 48 | * GFX INTA -> PIRQA (MSI) |
| 49 | * D28IP_P1IP WLAN INTA -> PIRQB |
| 50 | * D28IP_P4IP ETH0 INTB -> PIRQC |
| 51 | * D29IP_E1P EHCI1 INTA -> PIRQD |
| 52 | * D26IP_E2P EHCI2 INTA -> PIRQE |
| 53 | * D31IP_SIP SATA INTA -> PIRQF (MSI) |
| 54 | * D31IP_SMIP SMBUS INTB -> PIRQG |
| 55 | * D31IP_TTIP THRT INTC -> PIRQH |
| 56 | * D27IP_ZIP HDA INTA -> PIRQG (MSI) |
| 57 | */ |
| 58 | |
| 59 | /* Device interrupt pin register (board specific) */ |
Aaron Durbin | 239c2e8 | 2012-12-19 11:31:17 -0600 | [diff] [blame] | 60 | RCBA_SET_REG_32(D31IP, (INTC << D31IP_TTIP) | (NOINT << D31IP_SIP2) | |
| 61 | (INTB << D31IP_SMIP) | (INTA << D31IP_SIP)), |
| 62 | RCBA_SET_REG_32(D30IP, (NOINT << D30IP_PIP)), |
| 63 | RCBA_SET_REG_32(D29IP, (INTA << D29IP_E1P)), |
| 64 | RCBA_SET_REG_32(D28IP, (INTA << D28IP_P1IP) | (INTC << D28IP_P3IP) | |
| 65 | (INTB << D28IP_P4IP)), |
| 66 | RCBA_SET_REG_32(D27IP, (INTA << D27IP_ZIP)), |
| 67 | RCBA_SET_REG_32(D26IP, (INTA << D26IP_E2P)), |
| 68 | RCBA_SET_REG_32(D25IP, (NOINT << D25IP_LIP)), |
| 69 | RCBA_SET_REG_32(D22IP, (NOINT << D22IP_MEI1IP)), |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 70 | |
| 71 | /* Device interrupt route registers */ |
Aaron Durbin | 239c2e8 | 2012-12-19 11:31:17 -0600 | [diff] [blame] | 72 | RCBA_SET_REG_32(D31IR, DIR_ROUTE(PIRQF, PIRQG, PIRQH, PIRQA)), |
| 73 | RCBA_SET_REG_32(D29IR, DIR_ROUTE(PIRQD, PIRQE, PIRQF, PIRQG)), |
| 74 | RCBA_SET_REG_32(D28IR, DIR_ROUTE(PIRQB, PIRQC, PIRQD, PIRQE)), |
| 75 | RCBA_SET_REG_32(D27IR, DIR_ROUTE(PIRQG, PIRQH, PIRQA, PIRQB)), |
| 76 | RCBA_SET_REG_32(D26IR, DIR_ROUTE(PIRQE, PIRQF, PIRQG, PIRQH)), |
| 77 | RCBA_SET_REG_32(D25IR, DIR_ROUTE(PIRQA, PIRQB, PIRQC, PIRQD)), |
| 78 | RCBA_SET_REG_32(D22IR, DIR_ROUTE(PIRQA, PIRQB, PIRQC, PIRQD)), |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 79 | |
| 80 | /* Disable unused devices (board specific) */ |
Aaron Durbin | 239c2e8 | 2012-12-19 11:31:17 -0600 | [diff] [blame] | 81 | RCBA_RMW_REG_32(FD, ~0, PCH_DISABLE_ALWAYS), |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 82 | |
Aaron Durbin | 239c2e8 | 2012-12-19 11:31:17 -0600 | [diff] [blame] | 83 | RCBA_END_CONFIG, |
| 84 | }; |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 85 | |
Aaron Durbin | 3d0071b | 2013-01-18 14:32:50 -0600 | [diff] [blame] | 86 | void romstage_main(unsigned long bist) |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 87 | { |
| 88 | int boot_mode = 0; |
Aaron Durbin | 239c2e8 | 2012-12-19 11:31:17 -0600 | [diff] [blame] | 89 | int wake_from_s3; |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 90 | int cbmem_was_initted; |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 91 | |
| 92 | #if CONFIG_COLLECT_TIMESTAMPS |
| 93 | tsc_t start_romstage_time; |
| 94 | tsc_t before_dram_time; |
| 95 | tsc_t after_dram_time; |
| 96 | tsc_t base_time = { |
| 97 | .lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc), |
| 98 | .hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) |
| 99 | }; |
| 100 | #endif |
| 101 | struct pei_data pei_data = { |
| 102 | pei_version: PEI_VERSION, |
| 103 | mchbar: DEFAULT_MCHBAR, |
| 104 | dmibar: DEFAULT_DMIBAR, |
| 105 | epbar: DEFAULT_EPBAR, |
Aaron Durbin | f72ad02 | 2012-11-02 09:19:43 -0500 | [diff] [blame] | 106 | pciexbar: DEFAULT_PCIEXBAR, |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 107 | smbusbar: SMBUS_IO_BASE, |
| 108 | wdbbar: 0x4000000, |
| 109 | wdbsize: 0x1000, |
| 110 | hpet_address: HPET_ADDR, |
| 111 | rcba: DEFAULT_RCBA, |
| 112 | pmbase: DEFAULT_PMBASE, |
| 113 | gpiobase: DEFAULT_GPIOBASE, |
Aaron Durbin | 8256a9b | 2012-11-29 17:18:53 -0600 | [diff] [blame] | 114 | temp_mmio_base: 0xfed08000, |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 115 | system_type: 0, // 0 Mobile, 1 Desktop/Server |
| 116 | tseg_size: CONFIG_SMM_TSEG_SIZE, |
Aaron Durbin | 68724fd | 2012-12-07 09:47:16 -0600 | [diff] [blame] | 117 | spd_addresses: { 0xa0, 0xa2, 0xa4, 0xa6 }, |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 118 | ec_present: 0, |
| 119 | // 0 = leave channel enabled |
| 120 | // 1 = disable dimm 0 on channel |
| 121 | // 2 = disable dimm 1 on channel |
| 122 | // 3 = disable dimm 0+1 on channel |
Aaron Durbin | 68724fd | 2012-12-07 09:47:16 -0600 | [diff] [blame] | 123 | dimm_channel0_disabled: 0, |
| 124 | dimm_channel1_disabled: 0, |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 125 | max_ddr3_freq: 1600, |
| 126 | usb_port_config: { |
Aaron Durbin | 68724fd | 2012-12-07 09:47:16 -0600 | [diff] [blame] | 127 | { 1, 0, 0x0040 }, /* P0: Back USB3 port (OC0) */ |
| 128 | { 1, 0, 0x0040 }, /* P1: Back USB3 port (OC0) */ |
| 129 | { 1, 1, 0x0040 }, /* P2: Flex Port on bottom (OC1) */ |
| 130 | { 1, 8, 0x0040 }, /* P3: Docking connector (no OC) */ |
| 131 | { 1, 8, 0x0040 }, /* P4: Mini PCIE (no OC) */ |
| 132 | { 1, 1, 0x0040 }, /* P5: USB eSATA header (OC1) */ |
| 133 | { 1, 3, 0x0040 }, /* P6: Front Header J8H2 (OC3) */ |
| 134 | { 1, 3, 0x0040 }, /* P7: Front Header J8H2 (OC3) */ |
| 135 | { 1, 4, 0x0040 }, /* P8: USB/LAN Jack (OC4) */ |
| 136 | { 1, 4, 0x0040 }, /* P9: USB/LAN Jack (OC4) */ |
| 137 | { 1, 5, 0x0040 }, /* P10: Front Header J7H3 (OC5) */ |
| 138 | { 1, 5, 0x0040 }, /* P11: Front Header J7H3 (OC5) */ |
| 139 | { 1, 6, 0x0040 }, /* P12: USB/DP Jack (OC6) */ |
| 140 | { 1, 6, 0x0040 }, /* P13: USB/DP Jack (OC6) */ |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 141 | }, |
| 142 | }; |
| 143 | |
| 144 | #if CONFIG_COLLECT_TIMESTAMPS |
| 145 | start_romstage_time = rdtsc(); |
| 146 | #endif |
| 147 | |
| 148 | if (bist == 0) |
| 149 | enable_lapic(); |
| 150 | |
Aaron Durbin | 239c2e8 | 2012-12-19 11:31:17 -0600 | [diff] [blame] | 151 | wake_from_s3 = early_pch_init(&mainboard_gpio_map, &rcba_config[0]); |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 152 | |
| 153 | /* Halt if there was a built in self test failure */ |
| 154 | report_bist_failure(bist); |
| 155 | |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 156 | /* Perform some early chipset initialization required |
| 157 | * before RAM initialization can work |
| 158 | */ |
| 159 | haswell_early_initialization(HASWELL_MOBILE); |
| 160 | printk(BIOS_DEBUG, "Back from haswell_early_initialization()\n"); |
| 161 | |
Aaron Durbin | 239c2e8 | 2012-12-19 11:31:17 -0600 | [diff] [blame] | 162 | if (wake_from_s3) { |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 163 | #if CONFIG_HAVE_ACPI_RESUME |
| 164 | printk(BIOS_DEBUG, "Resume from S3 detected.\n"); |
| 165 | boot_mode = 2; |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 166 | #else |
| 167 | printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n"); |
| 168 | #endif |
| 169 | } |
| 170 | |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 171 | /* Prepare USB controller early in S3 resume */ |
| 172 | if (boot_mode == 2) |
| 173 | enable_usb_bar(); |
| 174 | |
| 175 | post_code(0x3a); |
| 176 | pei_data.boot_mode = boot_mode; |
| 177 | #if CONFIG_COLLECT_TIMESTAMPS |
| 178 | before_dram_time = rdtsc(); |
| 179 | #endif |
Aaron Durbin | 239c2e8 | 2012-12-19 11:31:17 -0600 | [diff] [blame] | 180 | |
| 181 | report_platform_info(); |
| 182 | |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 183 | sdram_initialize(&pei_data); |
| 184 | |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 185 | #if CONFIG_COLLECT_TIMESTAMPS |
| 186 | after_dram_time = rdtsc(); |
| 187 | #endif |
| 188 | post_code(0x3b); |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 189 | |
Aaron Durbin | 239c2e8 | 2012-12-19 11:31:17 -0600 | [diff] [blame] | 190 | intel_early_me_status(); |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 191 | |
| 192 | quick_ram_check(); |
| 193 | post_code(0x3e); |
| 194 | |
| 195 | MCHBAR16(SSKPD) = 0xCAFE; |
| 196 | #if CONFIG_EARLY_CBMEM_INIT |
| 197 | cbmem_was_initted = !cbmem_initialize(); |
| 198 | #else |
| 199 | cbmem_was_initted = cbmem_reinit((uint64_t) (get_top_of_ram() |
| 200 | - HIGH_MEMORY_SIZE)); |
| 201 | #endif |
| 202 | |
| 203 | #if CONFIG_HAVE_ACPI_RESUME |
| 204 | /* If there is no high memory area, we didn't boot before, so |
| 205 | * this is not a resume. In that case we just create the cbmem toc. |
| 206 | */ |
| 207 | |
| 208 | *(u32 *)CBMEM_BOOT_MODE = 0; |
| 209 | *(u32 *)CBMEM_RESUME_BACKUP = 0; |
| 210 | |
| 211 | if ((boot_mode == 2) && cbmem_was_initted) { |
| 212 | void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME); |
| 213 | if (resume_backup_memory) { |
| 214 | *(u32 *)CBMEM_BOOT_MODE = boot_mode; |
| 215 | *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory; |
| 216 | } |
| 217 | /* Magic for S3 resume */ |
| 218 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d); |
| 219 | } else if (boot_mode == 2) { |
| 220 | /* Failed S3 resume, reset to come up cleanly */ |
| 221 | outb(0x6, 0xcf9); |
| 222 | while (1) { |
| 223 | hlt(); |
| 224 | } |
| 225 | } else { |
| 226 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe); |
| 227 | } |
| 228 | #endif |
| 229 | post_code(0x3f); |
| 230 | #if CONFIG_CHROMEOS |
| 231 | init_chromeos(boot_mode); |
| 232 | #endif |
| 233 | #if CONFIG_COLLECT_TIMESTAMPS |
| 234 | timestamp_init(base_time); |
| 235 | timestamp_add(TS_START_ROMSTAGE, start_romstage_time ); |
| 236 | timestamp_add(TS_BEFORE_INITRAM, before_dram_time ); |
| 237 | timestamp_add(TS_AFTER_INITRAM, after_dram_time ); |
| 238 | timestamp_add_now(TS_END_ROMSTAGE); |
| 239 | #endif |
Aaron Durbin | f6933a6 | 2012-10-30 09:09:39 -0500 | [diff] [blame] | 240 | } |
Aaron Durbin | 3d0071b | 2013-01-18 14:32:50 -0600 | [diff] [blame] | 241 | |